From 4edce7243baab45bcedfa58ecedb39c74041d02a Mon Sep 17 00:00:00 2001 From: philippegorley <philippe.gorley@savoirfairelinux.com> Date: Wed, 25 Jul 2018 15:10:36 -0400 Subject: [PATCH] decoder: don't set channels and sample rate in dictionary This is redundant, the information can already be found in the AVStream object and is set by avcodec_parameters_to_context. Let FFmpeg take care of these details. Change-Id: I199de87a852caeef34047e4f906ccd21dcb696c4 Reviewed-by: Sebastien Blin <sebastien.blin@savoirfairelinux.com> --- src/media/audio/audio_rtp_session.cpp | 4 ++-- src/media/media_decoder.cpp | 9 +-------- src/media/media_decoder.h | 2 +- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/media/audio/audio_rtp_session.cpp b/src/media/audio/audio_rtp_session.cpp index 8082949c34..e8f95109b2 100644 --- a/src/media/audio/audio_rtp_session.cpp +++ b/src/media/audio/audio_rtp_session.cpp @@ -304,7 +304,7 @@ AudioReceiveThread::setup() // Now replace our custom AVIOContext with one that will read packets audioDecoder_->setIOContext(demuxContext_.get()); - EXIT_IF_FAIL(not audioDecoder_->setupFromAudioData(format_), + EXIT_IF_FAIL(not audioDecoder_->setupFromAudioData(), "decoder IO startup failed"); ringbuffer_ = Manager::instance().getRingBufferPool().getRingBuffer(id_); @@ -347,7 +347,7 @@ AudioReceiveThread::process() loop_.stop(); break; } - if (not audioDecoder_->setupFromAudioData(format_)) { + if (not audioDecoder_->setupFromAudioData()) { RING_ERR("fatal error, a-decoder setup failed"); loop_.stop(); break; diff --git a/src/media/media_decoder.cpp b/src/media/media_decoder.cpp index 96678dc519..1f1a8366d9 100644 --- a/src/media/media_decoder.cpp +++ b/src/media/media_decoder.cpp @@ -144,11 +144,8 @@ void MediaDecoder::setInterruptCallback(int (*cb)(void*), void *opaque) void MediaDecoder::setIOContext(MediaIOHandle *ioctx) { inputCtx_->pb = ioctx->getContext(); } -int MediaDecoder::setupFromAudioData(const AudioFormat format) +int MediaDecoder::setupFromAudioData() { - // Use AVDictionary to send extra arguments to setupStream, since video setup doesn't need them - av_dict_set_int(&options_, "nb_channels", format.nb_channels, 0); - av_dict_set_int(&options_, "sample_rate", format.sample_rate, 0); return setupStream(AVMEDIA_TYPE_AUDIO); } @@ -197,10 +194,6 @@ MediaDecoder::setupStream(AVMediaType mediaType) decoderCtx_->framerate = avStream_->avg_frame_rate; decoderCtx_->thread_count = std::max(1u, std::min(8u, std::thread::hardware_concurrency()/2)); - if (mediaType == AVMEDIA_TYPE_AUDIO) { - decoderCtx_->channels = std::stoi(av_dict_get(options_, "nb_channels", nullptr, 0)->value); - decoderCtx_->sample_rate = std::stoi(av_dict_get(options_, "sample_rate", nullptr, 0)->value); - } if (emulateRate_) RING_DBG() << "Using framerate emulation"; diff --git a/src/media/media_decoder.h b/src/media/media_decoder.h index f1b4a10c4e..df051508ca 100644 --- a/src/media/media_decoder.h +++ b/src/media/media_decoder.h @@ -84,7 +84,7 @@ class MediaDecoder { Status flush(VideoFrame&); #endif // RING_VIDEO - int setupFromAudioData(const AudioFormat format); + int setupFromAudioData(); Status decode(const AudioFrame&); void writeToRingBuffer(const AudioFrame&, RingBuffer&, const AudioFormat); -- GitLab