void avcodec_get_context_defaults2(AVCodecContext *s, enum AVMediaType codec_type){ int flags=0; memset(s, 0, sizeof(AVCodecContext)); s->av_class= &av_codec_context_class; s->codec_type = codec_type; if(codec_type == AVMEDIA_TYPE_AUDIO) flags= AV_OPT_FLAG_AUDIO_PARAM; else if(codec_type == AVMEDIA_TYPE_VIDEO) flags= AV_OPT_FLAG_VIDEO_PARAM; else if(codec_type == AVMEDIA_TYPE_SUBTITLE) flags= AV_OPT_FLAG_SUBTITLE_PARAM; av_opt_set_defaults2(s, flags, flags); s->time_base= (AVRational){0,1}; s->get_buffer= avcodec_default_get_buffer; s->release_buffer= avcodec_default_release_buffer; s->get_format= avcodec_default_get_format; s->execute= avcodec_default_execute; s->execute2= avcodec_default_execute2; s->sample_aspect_ratio= (AVRational){0,1}; s->pix_fmt= PIX_FMT_NONE; s->sample_fmt= AV_SAMPLE_FMT_NONE; s->palctrl = NULL; s->reget_buffer= avcodec_default_reget_buffer; s->reordered_opaque= AV_NOPTS_VALUE; }
void avcodec_get_context_defaults2(AVCodecContext *s, enum CodecType codec_type){ int flags=0; memset(s, 0, sizeof(AVCodecContext)); s->av_class= &av_codec_context_class; s->codec_type = codec_type; if(codec_type == CODEC_TYPE_AUDIO) flags= AV_OPT_FLAG_AUDIO_PARAM; else if(codec_type == CODEC_TYPE_VIDEO) flags= AV_OPT_FLAG_VIDEO_PARAM; else if(codec_type == CODEC_TYPE_SUBTITLE) flags= AV_OPT_FLAG_SUBTITLE_PARAM; av_opt_set_defaults2(s, flags, flags); s->time_base= (AVRational){0,1}; s->get_buffer= avcodec_default_get_buffer; s->release_buffer= avcodec_default_release_buffer; s->get_format= avcodec_default_get_format; s->execute= avcodec_default_execute; s->sample_aspect_ratio= (AVRational){0,1}; s->pix_fmt= PIX_FMT_NONE; s->sample_fmt= SAMPLE_FMT_S16; // FIXME: set to NONE s->palctrl = NULL; s->reget_buffer= avcodec_default_reget_buffer; }
int avcodec_get_context_defaults3(AVCodecContext *s, const AVCodec *codec) { int flags=0; memset(s, 0, sizeof(AVCodecContext)); s->av_class = &av_codec_context_class; s->codec_type = codec ? codec->type : AVMEDIA_TYPE_UNKNOWN; if (codec) s->codec_id = codec->id; if(s->codec_type == AVMEDIA_TYPE_AUDIO) flags= AV_OPT_FLAG_AUDIO_PARAM; else if(s->codec_type == AVMEDIA_TYPE_VIDEO) flags= AV_OPT_FLAG_VIDEO_PARAM; else if(s->codec_type == AVMEDIA_TYPE_SUBTITLE) flags= AV_OPT_FLAG_SUBTITLE_PARAM; av_opt_set_defaults2(s, flags, flags); s->time_base = (AVRational){0,1}; s->get_buffer2 = avcodec_default_get_buffer2; s->get_format = avcodec_default_get_format; s->execute = avcodec_default_execute; s->execute2 = avcodec_default_execute2; s->sample_aspect_ratio = (AVRational){0,1}; s->pix_fmt = AV_PIX_FMT_NONE; s->sample_fmt = AV_SAMPLE_FMT_NONE; s->timecode_frame_start = -1; s->reordered_opaque = AV_NOPTS_VALUE; if(codec && codec->priv_data_size){ if(!s->priv_data){ s->priv_data= av_mallocz(codec->priv_data_size); if (!s->priv_data) { return AVERROR(ENOMEM); } } if(codec->priv_class){ *(const AVClass**)s->priv_data = codec->priv_class; av_opt_set_defaults(s->priv_data); } } if (codec && codec->defaults) { int ret; const AVCodecDefault *d = codec->defaults; while (d->key) { ret = av_opt_set(s, d->key, d->value, 0); av_assert0(ret >= 0); d++; } } // ==> Start patch MPC s->using_dxva = 0; s->entangled_thread_counter = 0; s->ff_avcodec_locked = 0; // ==> End patch MPC return 0; }
SwrContext *swr_alloc(void){ SwrContext *s= av_mallocz(sizeof(SwrContext)); if(s){ s->av_class= &av_class; av_opt_set_defaults2(s, 0, 0); } return s; }
void avcodec_get_context_defaults2(AVCodecContext *s, enum AVMediaType codec_type) { /* 参数: 1、 返回: 1、 说明: 1、分配一个AVCodecContext 类型的内存 2、此函数被调用的过程: 1、avcodec_alloc_context() ==> avcodec_alloc_context2() ==> avcodec_get_context_defaults2() 2、avcodec_alloc_context3() ==> avcodec_get_context_defaults3() ==> avcodec_get_context_defaults3 */ int flags=0; memset(s, 0, sizeof(AVCodecContext)); s->av_class= &av_codec_context_class; s->codec_type = codec_type; if(codec_type == AVMEDIA_TYPE_AUDIO) flags= AV_OPT_FLAG_AUDIO_PARAM; else if(codec_type == AVMEDIA_TYPE_VIDEO) flags= AV_OPT_FLAG_VIDEO_PARAM; else if(codec_type == AVMEDIA_TYPE_SUBTITLE) flags= AV_OPT_FLAG_SUBTITLE_PARAM; av_opt_set_defaults2(s, flags, flags); s->time_base = (AVRational){0,1}; s->get_buffer = avcodec_default_get_buffer; /* buffer 分配函数,按照ffmpeg 的说明,解码数据包的时候,当一个包开始一帧的时候,ffmpeg 就会调用这个函数为帧分配内存*/ s->release_buffer = avcodec_default_release_buffer; /* buffer 释放函数*/ s->get_format = avcodec_default_get_format; /* 视频格式获取函数*/ s->execute = avcodec_default_execute; /* */ s->execute2 = avcodec_default_execute2; /* */ s->sample_aspect_ratio = (AVRational){0,1}; /* */ s->pix_fmt = PIX_FMT_NONE; /* */ s->sample_fmt = AV_SAMPLE_FMT_NONE; /* */ s->palctrl = NULL; /* */ s->reget_buffer = avcodec_default_reget_buffer; /* */ s->reordered_opaque= AV_NOPTS_VALUE; }
void av_opt_set_defaults(void *s){ av_opt_set_defaults2(s, 0, 0); }