obs_source_frame
+ -

get_closest_frame

2026-03-27 7 0

get_closest_frame由async_tick调用,用于准备该时段的数据。

static void async_tick(obs_source_t *source)
{
    //从缓冲区中获取该时标对应的帧数据
    source->cur_async_frame = get_closest_frame(source, sys_time);

    //更新当前帧的系统时间
    source->last_sys_timestamp = sys_time;

    //纹理格式尺寸是否变化了
    if (source->cur_async_frame)
        source->async_update_texture = set_async_texture_size(source, source->cur_async_frame);
}

obs_source_frame中:

  • 如果缓冲区没有帧数据,则直接退出。
  • 如果该obs_source_t第一次获取帧数据,则直接使用第一帧数据,并将该帧的last_frame_ts置为该帧的时间戳
  • 如果不是第一次,则调用ready_async_frame来获取帧数据(实际上是过早的数据从缓冲区队列中清除掉,这样第一个就是符合该时间戳的帧了。
static inline struct obs_source_frame *get_closest_frame(obs_source_t *source,
                             uint64_t sys_time)
{
    if (!source->async_frames.num)
        return NULL;

    if (!source->last_frame_ts || ready_async_frame(source, sys_time)) {
        struct obs_source_frame *frame = source->async_frames.array[0];
        da_erase(source->async_frames, 0);

        if (!source->last_frame_ts)
            source->last_frame_ts = frame->timestamp;

        return frame;
    }

    return NULL;
}

0 篇笔记 写笔记

作者信息
我爱内核
Windows驱动开发,网站开发
好好学习,天天向上。
取消
感谢您的支持,我会继续努力的!
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

您的支持,是我们前进的动力!