streamserver.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:ddmbot 作者: Budovi 项目源码 文件源码
def run(self):
        loops = 0  # loop counter
        input_not_ready = False  # to control log spam
        data_requested = self._frame_len  # to keep the alignment intact

        # capture the starting time
        start_time = time.clock_gettime(time.CLOCK_MONOTONIC_RAW)
        while not self._end.is_set():
            # increment loop counter
            loops += 1

            # try to read a frame from the input -- should be there all the time
            try:
                data = os.read(self._pipe_fd, data_requested)
                # so we apparently got some data, clear the flag and calculate things
                input_not_ready = False
                data_len = len(data)
                if data_len != 0 and data_len != self._frame_len:
                    log.warning('AacProcessor: Got partial buffer of size {}'.format(data_len))

                # call the callback
                self._play(data)

                # calculate requested size for the next iteration
                data_requested -= data_len
                if data_requested == 0:
                    data_requested = self._frame_len
            except OSError as e:
                if e.errno == errno.EAGAIN:
                    # prevent spamming the log with megabytes of text
                    if not input_not_ready:
                        log.error('AacProcessor: Buffer not ready')
                        input_not_ready = True
                else:
                    raise

            # calculate next transmission time
            next_time = start_time + self._frame_period * loops
            sleep_time = max(0, self._frame_period + (next_time - time.clock_gettime(time.CLOCK_MONOTONIC_RAW)))
            time.sleep(sleep_time)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号