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

Function avcodec_open

libavcodec/utils.c:462–534  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

460}
461
462int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
463{
464 int ret= -1;
465
466 /* If there is a user-supplied mutex locking routine, call it. */
467 if (ff_lockmgr_cb) {
468 if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
469 return -1;
470 }
471
472 entangled_thread_counter++;
473 if(entangled_thread_counter != 1){
474 av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
475 goto end;
476 }
477
478 if(avctx->codec || !codec)
479 goto end;
480
481 if (codec->priv_data_size > 0) {
482 avctx->priv_data = av_mallocz(codec->priv_data_size);
483 if (!avctx->priv_data) {
484 ret = AVERROR(ENOMEM);
485 goto end;
486 }
487 } else {
488 avctx->priv_data = NULL;
489 }
490
491 if(avctx->coded_width && avctx->coded_height)
492 avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
493 else if(avctx->width && avctx->height)
494 avcodec_set_dimensions(avctx, avctx->width, avctx->height);
495
496#define SANE_NB_CHANNELS 128U
497 if (((avctx->coded_width || avctx->coded_height)
498 && avcodec_check_dimensions(avctx, avctx->coded_width, avctx->coded_height))
499 || avctx->channels > SANE_NB_CHANNELS) {
500 ret = AVERROR(EINVAL);
501 goto free_and_end;
502 }
503
504 avctx->codec = codec;
505 if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&
506 avctx->codec_id == CODEC_ID_NONE) {
507 avctx->codec_type = codec->type;
508 avctx->codec_id = codec->id;
509 }
510 if(avctx->codec_id != codec->id || avctx->codec_type != codec->type){
511 av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n");
512 goto free_and_end;
513 }
514 avctx->frame_number = 0;
515 if(avctx->codec->init){
516 ret = avctx->codec->init(avctx);
517 if (ret < 0) {
518 goto free_and_end;
519 }

Callers 13

av_transcodeFunction · 0.85
stream_component_openFunction · 0.85
open_input_fileFunction · 0.85
open_parserFunction · 0.85
try_decode_frameFunction · 0.85
av_find_stream_infoFunction · 0.85
open_audioFunction · 0.85
open_videoFunction · 0.85
audio_encode_exampleFunction · 0.85
audio_decode_exampleFunction · 0.85
video_encode_exampleFunction · 0.85
video_decode_exampleFunction · 0.85

Calls 5

av_logFunction · 0.85
av_malloczFunction · 0.85
avcodec_set_dimensionsFunction · 0.85
avcodec_check_dimensionsFunction · 0.85
av_freepFunction · 0.85

Tested by

no test coverage detected