From 6d0f634bfc9dffc548fade14ba0d538e2e80f83f Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 3 Jan 2024 18:49:48 -0500 Subject: [PATCH] Cleanup audio_in opening frmo setup_resampler, and open audio_in_ctx with the correct parameters --- src/zm_videostore.cpp | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/zm_videostore.cpp b/src/zm_videostore.cpp index dfc139158..125ba4bdf 100644 --- a/src/zm_videostore.cpp +++ b/src/zm_videostore.cpp @@ -452,14 +452,25 @@ bool VideoStore::open() { if (!audio_out_codec) { Error("Could not find codec for AAC"); } else { - audio_in_ctx = avcodec_alloc_context3(audio_out_codec); + // Newer ffmpeg wants to keep everything separate... so have to lookup our own + // decoder, can't reuse the one from the camera. + audio_in_codec = avcodec_find_decoder(audio_in_stream->codecpar->codec_id); + audio_in_ctx = avcodec_alloc_context3(audio_in_codec); + // ctx already allocated at this point + // Copy params from instream to ctx ret = avcodec_parameters_to_context(audio_in_ctx, audio_in_stream->codecpar); - if (ret < 0) - Error("Failure from avcodec_parameters_to_context %s", + if (ret < 0) { + Error("Unable to copy audio params to ctx %s", av_make_error_string(ret).c_str()); - + } audio_in_ctx->time_base = audio_in_stream->time_base; + // if the codec is already open, nothing is done. + if ((ret = avcodec_open2(audio_in_ctx, audio_in_codec, nullptr)) < 0) { + Error("Can't open audio in codec!"); + return false; + } + audio_out_ctx = avcodec_alloc_context3(audio_out_codec); if (!audio_out_ctx) { Error("could not allocate codec ctx for AAC"); @@ -776,22 +787,6 @@ VideoStore::~VideoStore() { bool VideoStore::setup_resampler() { int ret; - // Newer ffmpeg wants to keep everything separate... so have to lookup our own - // decoder, can't reuse the one from the camera. - audio_in_codec = avcodec_find_decoder(audio_in_stream->codecpar->codec_id); - // ctx already allocated at this point - // Copy params from instream to ctx - ret = avcodec_parameters_to_context(audio_in_ctx, audio_in_stream->codecpar); - if (ret < 0) { - Error("Unable to copy audio params to ctx %s", - av_make_error_string(ret).c_str()); - } - - // if the codec is already open, nothing is done. - if ((ret = avcodec_open2(audio_in_ctx, audio_in_codec, nullptr)) < 0) { - Error("Can't open audio in codec!"); - return false; - } Debug(2, "Got something other than AAC (%s)", audio_in_codec->name);