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

Function avcodec_open2

libavcodec/avcodec.c:144–379  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

142}
143
144int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
145{
146 int ret = 0;
147 AVCodecInternal *avci;
148 const FFCodec *codec2;
149 const AVDictionaryEntry *e;
150
151 if (avcodec_is_open(avctx))
152 return 0;
153
154 if (!codec && !avctx->codec) {
155 av_log(avctx, AV_LOG_ERROR, "No codec provided to avcodec_open2()\n");
156 return AVERROR(EINVAL);
157 }
158 if (codec && avctx->codec && codec != avctx->codec) {
159 av_log(avctx, AV_LOG_ERROR, "This AVCodecContext was allocated for %s, "
160 "but %s passed to avcodec_open2()\n", avctx->codec->name, codec->name);
161 return AVERROR(EINVAL);
162 }
163 if (!codec)
164 codec = avctx->codec;
165 codec2 = ffcodec(codec);
166
167 if ((avctx->codec_type != AVMEDIA_TYPE_UNKNOWN && avctx->codec_type != codec->type) ||
168 (avctx->codec_id != AV_CODEC_ID_NONE && avctx->codec_id != codec->id)) {
169 av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n");
170 return AVERROR(EINVAL);
171 }
172
173 avctx->codec_type = codec->type;
174 avctx->codec_id = codec->id;
175 avctx->codec = codec;
176
177 if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)
178 return AVERROR(EINVAL);
179
180 // set the whitelist from provided options dict,
181 // so we can check it immediately
182 e = options ? av_dict_get(*options, "codec_whitelist", NULL, 0) : NULL;
183 if (e) {
184 ret = av_opt_set(avctx, e->key, e->value, 0);
185 if (ret < 0)
186 return ret;
187 }
188
189 if (avctx->codec_whitelist && av_match_list(codec->name, avctx->codec_whitelist, ',') <= 0) {
190 av_log(avctx, AV_LOG_ERROR, "Codec (%s) not on whitelist \'%s\'\n", codec->name, avctx->codec_whitelist);
191 return AVERROR(EINVAL);
192 }
193
194 avci = ff_codec_is_decoder(codec) ?
195 ff_decode_internal_alloc() :
196 ff_encode_internal_alloc();
197 if (!avci) {
198 ret = AVERROR(ENOMEM);
199 goto end;
200 }
201 avctx->internal = avci;

Callers 15

LLVMFuzzerTestOneInputFunction · 0.85
process_frameFunction · 0.85
LLVMFuzzerTestOneInputFunction · 0.85
ds_runFunction · 0.85
try_decode_frameFunction · 0.85
enc_openFunction · 0.85
stream_component_openFunction · 0.85
dec_openFunction · 0.85
open_input_fileFunction · 0.85
cri_decode_initFunction · 0.85
imm5_initFunction · 0.85

Calls 15

avcodec_is_openFunction · 0.85
av_logFunction · 0.85
ffcodecFunction · 0.85
av_dict_getFunction · 0.85
av_opt_setFunction · 0.85
av_match_listFunction · 0.85
ff_codec_is_decoderFunction · 0.85
ff_decode_internal_allocFunction · 0.85
ff_encode_internal_allocFunction · 0.85
av_frame_allocFunction · 0.85
av_packet_allocFunction · 0.85
av_opt_set_defaultsFunction · 0.85

Tested by 8

process_frameFunction · 0.68
mainFunction · 0.68
video_decodeFunction · 0.68
seek_testFunction · 0.68
dump_stream_metaFunction · 0.68
init_encoderFunction · 0.68
init_decoderFunction · 0.68
video_decode_exampleFunction · 0.68