切入点:
video_thread线程主循环,只要video->stop为false,会循环调用video_output_cur_frame来捕捉当前屏幕。
//碧麟标注裁剪版本
static void *video_thread(void *param)
{
struct video_output *video = param;
//设置线程名字
os_set_thread_name("video-io: video thread");
//线程主循环
while (os_sem_wait(video->update_semaphore) == 0) {
if (video->stop)
break;
//循环调用video_output_cur_frame获取当前屏幕
while (!video->stop && !video_output_cur_frame(video)) {
os_atomic_inc_long(&video->total_frames);
}
}
return NULL;
}
这里用到video_output核心结构体 ,结构体定义如下
捕捉当前帧核心逻辑
//捕捉当前帧
static inline bool video_output_cur_frame(struct video_output *video)
{
//帧信息
struct cached_frame_info *frame_info;
bool complete;
bool skipped;
/* -------------------------------- */
pthread_mutex_lock(&video->data_mutex);
frame_info = &video->cache[video->first_added];
pthread_mutex_unlock(&video->data_mutex);
/* -------------------------------- */
pthread_mutex_lock(&video->input_mutex);
for (size_t i = 0; i < video->inputs.num; i++) {
struct video_input *input = video->inputs.array + i;
struct video_data frame = frame_info->frame;
if (scale_video_output(input, &frame))
input->callback(input->param, &frame);
}
pthread_mutex_unlock(&video->input_mutex);
/* -------------------------------- */
pthread_mutex_lock(&video->data_mutex);
frame_info->frame.timestamp += video->frame_time;
complete = --frame_info->count == 0;
skipped = frame_info->skipped > 0;
if (complete) {
if (++video->first_added == video->info.cache_size)
video->first_added = 0;
if (++video->available_frames == video->info.cache_size)
video->last_added = video->first_added;
} else if (skipped) {
--frame_info->skipped;
os_atomic_inc_long(&video->skipped_frames);
}
pthread_mutex_unlock(&video->data_mutex);
/* -------------------------------- */
return complete;
}
标签:info,input,lib,frame,mutex,output,video,屏幕,obs From: https://www.cnblogs.com/billin/p/17223814.html