| 460 | } |
| 461 | |
| 462 | int 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 | } |
no test coverage detected