From a4ce78b7e7403f529c78cf4113db12b62a2c356e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com>
Date: Mon, 3 Dec 2018 11:14:01 -0500
Subject: [PATCH] rtp session: write to ringbuffer directly

Change-Id: I0de9d73d38e865f736e64c6a1adb1139d96cd641
---
 src/media/audio/audio_receive_thread.cpp |  9 +++------
 src/media/media_decoder.cpp              | 15 ---------------
 src/media/media_decoder.h                |  6 ------
 3 files changed, 3 insertions(+), 27 deletions(-)

diff --git a/src/media/audio/audio_receive_thread.cpp b/src/media/audio/audio_receive_thread.cpp
index 7fd31bb2c7..69a2d5e492 100644
--- a/src/media/audio/audio_receive_thread.cpp
+++ b/src/media/audio/audio_receive_thread.cpp
@@ -92,14 +92,11 @@ AudioReceiveThread::setup()
 void
 AudioReceiveThread::process()
 {
-    AudioFormat mainBuffFormat = Manager::instance().getRingBufferPool().getInternalAudioFormat();
-    auto decodedFrame = std::make_unique<AudioFrame>();
-    auto sharedFrame = std::make_shared<AudioFrame>();
+    auto decodedFrame = std::make_shared<AudioFrame>();
     switch (audioDecoder_->decode(*decodedFrame)) {
         case MediaDecoder::Status::FrameFinished:
-            sharedFrame->copyFrom(*decodedFrame);
-            audioDecoder_->writeToRingBuffer(std::move(decodedFrame), *ringbuffer_, mainBuffFormat);
-            notify(std::static_pointer_cast<MediaFrame>(sharedFrame));
+            notify(std::static_pointer_cast<MediaFrame>(decodedFrame));
+            ringbuffer_->put(std::move(decodedFrame));
             return;
         case MediaDecoder::Status::DecodeError:
             RING_WARN("decoding failure, trying to reset decoder...");
diff --git a/src/media/media_decoder.cpp b/src/media/media_decoder.cpp
index ccdaf2ddf1..75c3a51d05 100644
--- a/src/media/media_decoder.cpp
+++ b/src/media/media_decoder.cpp
@@ -466,21 +466,6 @@ MediaDecoder::getTimeBase() const
 int MediaDecoder::getPixelFormat() const
 { return decoderCtx_->pix_fmt; }
 
-void
-MediaDecoder::writeToRingBuffer(std::unique_ptr<AudioFrame>&& decodedFrame,
-                                RingBuffer& rb, const AudioFormat outFormat)
-{
-    AudioFormat format (decoderCtx_->sample_rate, decoderCtx_->channels, decoderCtx_->sample_fmt);
-    if (format != outFormat) {
-        if (not resampler_) {
-            RING_DBG("Creating audio resampler");
-            resampler_.reset(new Resampler);
-        }
-        decodedFrame = resampler_->resample(std::move(decodedFrame), outFormat);
-    }
-    rb.put(std::move(decodedFrame));
-}
-
 int
 MediaDecoder::correctPixFmt(int input_pix_fmt) {
 
diff --git a/src/media/media_decoder.h b/src/media/media_decoder.h
index 5781777275..3350873057 100644
--- a/src/media/media_decoder.h
+++ b/src/media/media_decoder.h
@@ -90,7 +90,6 @@ class MediaDecoder {
 
         int setupFromAudioData();
         Status decode(AudioFrame&);
-        void writeToRingBuffer(std::unique_ptr<AudioFrame>&& decodedFrame, RingBuffer&, const AudioFormat);
 
         int getWidth() const;
         int getHeight() const;
@@ -115,7 +114,6 @@ class MediaDecoder {
         AVCodecContext *decoderCtx_ = nullptr;
         AVFormatContext *inputCtx_ = nullptr;
         AVStream *avStream_ = nullptr;
-        std::unique_ptr<Resampler> resampler_;
         int streamIndex_ = -1;
         bool emulateRate_ = false;
         int64_t startTime_;
@@ -123,10 +121,6 @@ class MediaDecoder {
 
         DeviceParams inputParams_;
 
-        AudioBuffer decBuff_;
-        AudioBuffer resamplingBuff_;
-
-        void extract(const std::map<std::string, std::string>& map, const std::string& key);
         int correctPixFmt(int input_pix_fmt);
         int setupStream(AVMediaType mediaType);
         int selectStream(AVMediaType type);
-- 
GitLab