| 493 | } |
| 494 | |
| 495 | void FFMS_AudioSource::OpenFile() { |
| 496 | avcodec_free_context(&CodecContext); |
| 497 | avformat_close_input(&FormatContext); |
| 498 | |
| 499 | LAVFOpenFile(SourceFile.c_str(), FormatContext, TrackNumber, LAVFOpts); |
| 500 | |
| 501 | auto *Codec = avcodec_find_decoder(FormatContext->streams[TrackNumber]->codecpar->codec_id); |
| 502 | if (Codec == nullptr) |
| 503 | throw FFMS_Exception(FFMS_ERROR_DECODING, FFMS_ERROR_CODEC, |
| 504 | "Audio codec not found"); |
| 505 | |
| 506 | CodecContext = avcodec_alloc_context3(Codec); |
| 507 | if (CodecContext == nullptr) |
| 508 | throw FFMS_Exception(FFMS_ERROR_DECODING, FFMS_ERROR_ALLOCATION_FAILED, |
| 509 | "Could not allocate audio decoding context"); |
| 510 | |
| 511 | if (avcodec_parameters_to_context(CodecContext, FormatContext->streams[TrackNumber]->codecpar) < 0) |
| 512 | throw FFMS_Exception(FFMS_ERROR_DECODING, FFMS_ERROR_CODEC, |
| 513 | "Could not copy audio codec parameters"); |
| 514 | |
| 515 | AVDictionary *CodecDict = nullptr; |
| 516 | if (Codec->id == AV_CODEC_ID_AC3 || Codec->id == AV_CODEC_ID_EAC3) |
| 517 | av_dict_set(&CodecDict, "drc_scale", std::to_string(DrcScale).c_str(), 0); |
| 518 | |
| 519 | if (avcodec_open2(CodecContext, Codec, &CodecDict) < 0) |
| 520 | throw FFMS_Exception(FFMS_ERROR_DECODING, FFMS_ERROR_CODEC, |
| 521 | "Could not open audio codec"); |
| 522 | |
| 523 | av_dict_free(&CodecDict); |
| 524 | } |
| 525 | |
| 526 | void FFMS_AudioSource::Free() { |
| 527 | av_frame_free(&DecodeFrame); |
nothing calls this directly
no test coverage detected