From 4f26d8ee7cfee16936a266d5ce1c46f5d31d0824 Mon Sep 17 00:00:00 2001 From: philippegorley <philippe.gorley@savoirfairelinux.com> Date: Thu, 29 Nov 2018 12:28:20 -0500 Subject: [PATCH] audio: make receiver observable Matches the video receive thread, video input and audio input. Change-Id: I77d3d4286301c75ebeabeeab6e6d882656020fba --- src/media/audio/audio_receive_thread.cpp | 14 +++++--------- src/media/audio/audio_receive_thread.h | 3 ++- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/media/audio/audio_receive_thread.cpp b/src/media/audio/audio_receive_thread.cpp index 9e8826c759..f320a8b7c9 100644 --- a/src/media/audio/audio_receive_thread.cpp +++ b/src/media/audio/audio_receive_thread.cpp @@ -93,20 +93,18 @@ void AudioReceiveThread::process() { AudioFormat mainBuffFormat = Manager::instance().getRingBufferPool().getInternalAudioFormat(); - AudioFrame decodedFrame; - - switch (audioDecoder_->decode(decodedFrame)) { - + auto decodedFrame = std::make_shared<AudioFrame>(); + switch (audioDecoder_->decode(*decodedFrame)) { case MediaDecoder::Status::FrameFinished: { auto rec = recorder_.lock(); if (rec && rec->isRecording()) - rec->recordData(decodedFrame.pointer(), audioDecoder_->getStream("a:remote")); + rec->recordData(decodedFrame->pointer(), audioDecoder_->getStream("a:remote")); } - audioDecoder_->writeToRingBuffer(decodedFrame, *ringbuffer_, + audioDecoder_->writeToRingBuffer(*decodedFrame, *ringbuffer_, mainBuffFormat); + notify(decodedFrame); return; - case MediaDecoder::Status::DecodeError: RING_WARN("decoding failure, trying to reset decoder..."); if (not setup()) { @@ -117,12 +115,10 @@ AudioReceiveThread::process() loop_.stop(); } break; - case MediaDecoder::Status::ReadError: RING_ERR("fatal error, read failed"); loop_.stop(); break; - case MediaDecoder::Status::Success: case MediaDecoder::Status::EOFError: default: diff --git a/src/media/audio/audio_receive_thread.h b/src/media/audio/audio_receive_thread.h index 4f6572f8a6..38a75a6a1d 100644 --- a/src/media/audio/audio_receive_thread.h +++ b/src/media/audio/audio_receive_thread.h @@ -23,6 +23,7 @@ #include "media_buffer.h" #include "media_device.h" #include "noncopyable.h" +#include "observer.h" #include "socket_pair.h" #include "threadloop.h" @@ -35,7 +36,7 @@ class MediaIOHandle; class MediaRecorder; class RingBuffer; -class AudioReceiveThread +class AudioReceiveThread : Observable<std::shared_ptr<AudioFrame>> { public: AudioReceiveThread(const std::string &id, -- GitLab