MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / init_context_defaults

Function init_context_defaults

libavcodec/options.c:90–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88};
89
90static int init_context_defaults(AVCodecContext *s, const AVCodec *codec)
91{
92 const FFCodec *const codec2 = ffcodec(codec);
93 int flags=0;
94 memset(s, 0, sizeof(AVCodecContext));
95
96 s->av_class = &av_codec_context_class;
97
98 s->codec_type = codec ? codec->type : AVMEDIA_TYPE_UNKNOWN;
99 if (codec) {
100 s->codec = codec;
101 s->codec_id = codec->id;
102 }
103
104 if(s->codec_type == AVMEDIA_TYPE_AUDIO)
105 flags= AV_OPT_FLAG_AUDIO_PARAM;
106 else if(s->codec_type == AVMEDIA_TYPE_VIDEO)
107 flags= AV_OPT_FLAG_VIDEO_PARAM;
108 else if(s->codec_type == AVMEDIA_TYPE_SUBTITLE)
109 flags= AV_OPT_FLAG_SUBTITLE_PARAM;
110 av_opt_set_defaults2(s, flags, flags);
111
112 av_channel_layout_uninit(&s->ch_layout);
113
114 s->time_base = (AVRational){0,1};
115 s->framerate = (AVRational){ 0, 1 };
116 s->pkt_timebase = (AVRational){ 0, 1 };
117 s->get_buffer2 = avcodec_default_get_buffer2;
118 s->get_format = avcodec_default_get_format;
119 s->get_encode_buffer = avcodec_default_get_encode_buffer;
120 s->execute = avcodec_default_execute;
121 s->execute2 = avcodec_default_execute2;
122 s->sample_aspect_ratio = (AVRational){0,1};
123 s->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
124 s->pix_fmt = AV_PIX_FMT_NONE;
125 s->sw_pix_fmt = AV_PIX_FMT_NONE;
126 s->sample_fmt = AV_SAMPLE_FMT_NONE;
127
128 if(codec && codec2->priv_data_size){
129 s->priv_data = av_mallocz(codec2->priv_data_size);
130 if (!s->priv_data)
131 return AVERROR(ENOMEM);
132 if(codec->priv_class){
133 *(const AVClass**)s->priv_data = codec->priv_class;
134 av_opt_set_defaults(s->priv_data);
135 }
136 }
137 if (codec && codec2->defaults) {
138 int ret;
139 const FFCodecDefault *d = codec2->defaults;
140 while (d->key) {
141 ret = av_opt_set(s, d->key, d->value, 0);
142 av_assert0(ret >= 0);
143 d++;
144 }
145 }
146 return 0;
147}

Callers 1

avcodec_alloc_context3Function · 0.85

Calls 6

ffcodecFunction · 0.85
av_opt_set_defaults2Function · 0.85
av_channel_layout_uninitFunction · 0.85
av_opt_set_defaultsFunction · 0.85
av_opt_setFunction · 0.85
av_malloczFunction · 0.50

Tested by

no test coverage detected