FFmepg 多线程解码历程 - 6:frame_thread_init
来源:互联网 发布:centos pptp安装教程 编辑:程序博客网 时间:2024/05/16 05:34
//ff_thread_init选择帧线程初始化,就会进入frame_thread_init
static int frame_thread_init(AVCodecContext *avctx)
{int thread_count = avctx->thread_count;
const AVCodec *codec = avctx->codec;
AVCodecContext *src = avctx;
FrameThreadContext *fctx;
int i, err = 0;
//如果我们在初始化codec的时候没有设置thread_count或者设置为0,则就会自动根据手机设备来获取
if (!thread_count) {
int nb_cpus = ff_get_logical_cpus(avctx);
if ((avctx->debug & (FF_DEBUG_VIS_QP | FF_DEBUG_VIS_MB_TYPE)) || avctx->debug_mv)
nb_cpus = 1;
// use number of cores + 1 as thread count if there is more than one
if (nb_cpus > 1)
thread_count = avctx->thread_count = FFMIN(nb_cpus + 1, MAX_AUTO_THREADS); //#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
else
thread_count = avctx->thread_count = 1;
}
if (thread_count <= 1) { //如果thread_count <= 1那么即使进入帧级线程初始化,在解码的时候也不会调用帧级解码函数的
avctx->active_thread_type = 0;
return 0;
}
avctx->thread_opaque = fctx = av_mallocz(sizeof(FrameThreadContext));
fctx->threads = av_mallocz(sizeof(PerThreadContext) * thread_count); //相当与初始化线程池,个数就是thread_count
pthread_mutex_init(&fctx->buffer_mutex, NULL);
fctx->delaying = 1;
for (i = 0; i < thread_count; i++) {
AVCodecContext *copy = av_malloc(sizeof(AVCodecContext));
PerThreadContext *p = &fctx->threads[i];
pthread_mutex_init(&p->mutex, NULL);
pthread_mutex_init(&p->progress_mutex, NULL);
pthread_cond_init(&p->input_cond, NULL);
pthread_cond_init(&p->progress_cond, NULL);
pthread_cond_init(&p->output_cond, NULL);
p->parent = fctx;
p->avctx = copy;
if (!copy) {
err = AVERROR(ENOMEM);
goto error;
}
*copy = *src;
copy->thread_opaque = p;
copy->pkt = &p->avpkt;
if (!i) {
src = copy;
if (codec->init)
err = codec->init(copy);
//更新下一个线程的AVCodecContext参考线程的上下文中的值
update_context_from_thread(avctx, copy, 1);
} else {
copy->priv_data = av_malloc(codec->priv_data_size);
if (!copy->priv_data) {
err = AVERROR(ENOMEM);
goto error;
}
memcpy(copy->priv_data, src->priv_data, codec->priv_data_size);
copy->internal = av_malloc(sizeof(AVCodecInternal));
if (!copy->internal) {
err = AVERROR(ENOMEM);
goto error;
}
*copy->internal = *src->internal;
copy->internal->is_copy = 1;
if (codec->init_thread_copy)
err = codec->init_thread_copy(copy);
}
if (err) goto error;
///下面出创建线程,调用frame_worker_thread
err = AVERROR(pthread_create(&p->thread, NULL, frame_worker_thread, p));
p->thread_init= !err;
if(!p->thread_init)
goto error;
}
return 0;
error:
frame_thread_free(avctx, i+1);
return err;
}
0 0
- FFmepg 多线程解码历程 - 6:frame_thread_init
- FFmepg 多线程解码历程 - 6:frame_thread_init
- FFmepg 多线程解码历程
- FFmepg 多线程解码历程
- FFmepg 多线程解码历程 - 1:validate_thread_parameters
- FFmepg 多线程解码历程 - 2 :avcodec_decode_video2
- FFmepg 多线程解码历程 - 3: int ff_thread_decode_frame
- FFmepg 多线程解码历程 - 4:avcodec_open2
- FFmepg 多线程解码历程 - 5: ff_thread_init
- FFmepg 多线程解码历程 - 7:submit_packet
- FFmepg 多线程解码历程 - 1:validate_thread_parameters
- FFmepg 多线程解码历程 - 2 :avcodec_decode_video2
- FFmepg 多线程解码历程 - 3: int ff_thread_decode_frame
- FFmepg 多线程解码历程 - 4:avcodec_open2
- FFmepg 多线程解码历程 - 5: ff_thread_init
- FFmepg 多线程解码历程 - 7:submit_packet
- ffmepg开发历程
- FFMEPG avs2 解码支持
- 将DataTable插入数据库
- quick-cocos2dx在eclipse下的lua调试
- Deep Learning(深度学习)学习笔记整理系列之(三)
- html5 css3关于网页字体设置
- oracle 11g安装图解
- FFmepg 多线程解码历程 - 6:frame_thread_init
- 【问题解决】Project facet Java version 1.7 is not supported.
- grails配置文件扩展
- UVa 216 - Getting in Line 递归回溯
- 解决umount: /home: device is busy
- 微信公众号自定义转发窗口时如何判断用户点击的是“取消”还是“发送”
- mount: can't find /dev/cdrom in /etc/fstab or /etc/mtab问题解决
- ps教程。(磨皮)
- PHP的命名空间