OBS图形及渲染
+ -

输出格式video_output_open

2024-10-16 22 0

video_output_open中创建并初始化video_t结构体:

  1. struct video_output {
  2. struct video_output_info info;
  3. pthread_t thread;
  4. pthread_mutex_t data_mutex;
  5. bool stop;
  6. os_sem_t *update_semaphore;
  7. uint64_t frame_time;
  8. volatile long skipped_frames;
  9. volatile long total_frames;
  10. bool initialized;
  11. pthread_mutex_t input_mutex;
  12. DARRAY(struct video_input) inputs;
  13. size_t available_frames;
  14. size_t first_added;
  15. size_t last_added;
  16. struct cached_frame_info cache[MAX_CACHE_SIZE];//16个
  17. volatile bool raw_active;
  18. volatile long gpu_refs;
  19. };
  20. struct video_output;
  21. typedef struct video_output video_t;

初始化后信息如下
video_output

缓冲帧cache的初始化如下:

  1. static inline void init_cache(struct video_output *video)
  2. {
  3. if (video->info.cache_size > MAX_CACHE_SIZE)
  4. video->info.cache_size = MAX_CACHE_SIZE;
  5. for (size_t i = 0; i < video->info.cache_size; i++)
  6. {
  7. struct video_frame* frame =(struct video_frame *)&video->cache[i];
  8. video_frame_init(frame, video->info.format, video->info.width, video->info.height);
  9. }
  10. video->available_frames = video->info.cache_size;
  11. }

video_frame_init中根据格式和宽度进行初始化每个FRAME,这里至少一个(如RGB)或者三个(I420:YUV)或者二个(NV12:Y UV)

  1. struct video_frame {
  2. uint8_t *data[MAX_AV_PLANES];
  3. uint32_t linesize[MAX_AV_PLANES];
  4. };

如I420的代码格式如下:

  1. case VIDEO_FORMAT_I420: {
  2. size = width * height;
  3. ALIGN_SIZE(size, alignment);//32字节的整数倍速对齐
  4. offsets[0] = size;
  5. const uint32_t half_width = (width + 1) / 2;
  6. const uint32_t half_height = (height + 1) / 2;
  7. const uint32_t quarter_area = half_width * half_height;
  8. size += quarter_area;
  9. ALIGN_SIZE(size, alignment); //u起始地址32对齐
  10. offsets[1] = size;
  11. size += quarter_area;
  12. ALIGN_SIZE(size, alignment);/v起始地址32对齐
  13. frame->data[0] = bmalloc(size);
  14. frame->data[1] = (uint8_t *)frame->data[0] + offsets[0];
  15. frame->data[2] = (uint8_t *)frame->data[0] + offsets[1];
  16. frame->linesize[0] = width;
  17. frame->linesize[1] = half_width;
  18. frame->linesize[2] = half_width;
  19. break;
  20. }

32地址的对齐我记得是GPU的要求,所以这为了CPU和GPU之间进行地址映射方便。

0 篇笔记 写笔记

输出格式video_output_open
video_output_open中创建并初始化video_t结构体:struct video_output { struct video_output_info info; pthread_t thread; pthread_mutex_t data_mutex; ......
作者信息
我爱内核
Windows驱动开发,网站开发
好好学习,天天向上。
取消
感谢您的支持,我会继续努力的!
扫码支持
扫码打赏,你说多少就多少

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

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