FFmepg 多线程解码历程 - 1:validate_thread_parameters

来源:互联网 发布:重庆网络机柜 编辑:程序博客网 时间:2024/05/16 06:10
/**
 * Set the threading algorithms used.//设置线程的使用算法
 * Threading requires more than one thread.//需要一个以上的线程
 * Frame threading requires entire frames to be passed to the codec,//帧线程需要整个帧被传递到编码解码器
 * and introduces extra decoding delay, so is incompatible with low_delay.// 并引入了额外的解码延迟,所以是不符合low_delay
 * @param avctx The context.
 */

 //有效的线程参数

static void validate_thread_parameters(AVCodecContext *avctx)
{

    //实现帧线程支持,需要在配置codec的时候设置codec的capabilities,flags,flags2
    int frame_threading_supported = (avctx->codec->capabilities & CODEC_CAP_FRAME_THREADS)
                                && !(avctx->flags & CODEC_FLAG_TRUNCATED)
                                && !(avctx->flags & CODEC_FLAG_LOW_DELAY)
                                && !(avctx->flags2 & CODEC_FLAG2_CHUNKS);
    if (avctx->thread_count == 1) {    //多线程要在双核以上的机器上才行
        avctx->active_thread_type = 0;
    } else if (frame_threading_supported && (avctx->thread_type & FF_THREAD_FRAME)) {//  在codec初始化的时候设置avctx->thread_type |=FF_THREAD_FRAME
        avctx->active_thread_type = FF_THREAD_FRAME;   //线程的类型设置为帧并行
    } else if (avctx->codec->capabilities & CODEC_CAP_SLICE_THREADS &&
               avctx->thread_type & FF_THREAD_SLICE) {  //同样的要实现片级并行则需要在codec初始化的时候设置条件
        avctx->active_thread_type = FF_THREAD_SLICE;
    } else if (!(avctx->codec->capabilities & CODEC_CAP_AUTO_THREADS)) {
        avctx->thread_count       = 1;
        avctx->active_thread_type = 0;
    }

    if (avctx->thread_count > MAX_AUTO_THREADS)
        av_log(avctx, AV_LOG_WARNING,
               "Application has requested %d threads. Using a thread count greater than %d is not recommended.\n",
               avctx->thread_count, MAX_AUTO_THREADS);
}

注释:

如果不知到帧与片 可以查看之前的转载文章  http://blog.csdn.net/jwzhangjie/article/details/8739139

原创粉丝点击