From aacf4e980181edab0c03e1c96fe1e6b0aa1f0493 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Mon, 12 Sep 2011 16:58:07 -0700 Subject: [PATCH] Hold the AAHDecoderPump ThreadWrapper in a ref-counting pointer Change-Id: I8929905a7bf07a751b5deb4c74875172a33d874d --- media/libaah_rtp/aah_decoder_pump.cpp | 23 ++++++++++++++++------- media/libaah_rtp/aah_decoder_pump.h | 3 ++- media/libaah_rtp/aah_rx_player_substream.cpp | 3 +++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/media/libaah_rtp/aah_decoder_pump.cpp b/media/libaah_rtp/aah_decoder_pump.cpp index cde9be4a6f..b2efbe634c 100644 --- a/media/libaah_rtp/aah_decoder_pump.cpp +++ b/media/libaah_rtp/aah_decoder_pump.cpp @@ -37,19 +37,28 @@ namespace android { AAH_DecoderPump::AAH_DecoderPump(OMXClient& omx) : omx_(omx) - , thread_(this) , thread_status_(OK) , renderer_(NULL) , last_queued_pts_valid_(false) , last_queued_pts_(0) , last_ts_transform_valid_(false) , last_volume_(0xFF) { + thread_ = new ThreadWrapper(this); } AAH_DecoderPump::~AAH_DecoderPump() { shutdown(); } +status_t AAH_DecoderPump::initCheck() { + if (thread_ == NULL) { + LOGE("Failed to allocate thread"); + return NO_MEMORY; + } + + return OK; +} + status_t AAH_DecoderPump::queueForDecode(MediaBuffer* buf) { if (NULL == buf) { return BAD_VALUE; @@ -281,7 +290,7 @@ void* AAH_DecoderPump::workThread() { return NULL; } - while (!thread_.exitPending()) { + while (!thread_->exitPending()) { status_t res; MediaBuffer* bufOut = NULL; @@ -365,7 +374,7 @@ status_t AAH_DecoderPump::init(sp params) { // Fire up the pump thread. It will take care of starting and stopping the // decoder. - ret_val = thread_.run("aah_decode_pump", ANDROID_PRIORITY_AUDIO); + ret_val = thread_->run("aah_decode_pump", ANDROID_PRIORITY_AUDIO); if (OK != ret_val) { LOGE("Failed to start work thread in %s (res = %d)", __PRETTY_FUNCTION__, ret_val); @@ -387,9 +396,9 @@ status_t AAH_DecoderPump::shutdown() { } status_t AAH_DecoderPump::shutdown_l() { - thread_.requestExit(); + thread_->requestExit(); thread_cond_.signal(); - thread_.requestExitAndWait(); + thread_->requestExitAndWait(); MBQueue::iterator I; for (I = in_queue_.begin(); I != in_queue_.end(); ++I) { @@ -417,12 +426,12 @@ status_t AAH_DecoderPump::read(MediaBuffer **buffer, // While its not time to shut down, and we have no data to process, wait. AutoMutex lock(&thread_lock_); - while (!thread_.exitPending() && in_queue_.empty()) + while (!thread_->exitPending() && in_queue_.empty()) thread_cond_.wait(thread_lock_); // At this point, if its not time to shutdown then we must have something to // process. Go ahead and pop the front of the queue for processing. - if (!thread_.exitPending()) { + if (!thread_->exitPending()) { CHECK(!in_queue_.empty()); *buffer = *(in_queue_.begin()); diff --git a/media/libaah_rtp/aah_decoder_pump.h b/media/libaah_rtp/aah_decoder_pump.h index f5e7d03f56..c9b35cde85 100644 --- a/media/libaah_rtp/aah_decoder_pump.h +++ b/media/libaah_rtp/aah_decoder_pump.h @@ -33,6 +33,7 @@ class TimedAudioTrack; class AAH_DecoderPump : public MediaSource { public: explicit AAH_DecoderPump(OMXClient& omx); + status_t initCheck(); status_t queueForDecode(MediaBuffer* buf); @@ -79,7 +80,7 @@ class AAH_DecoderPump : public MediaSource { OMXClient& omx_; Mutex init_lock_; - ThreadWrapper thread_; + sp thread_; Condition thread_cond_; Mutex thread_lock_; status_t thread_status_; diff --git a/media/libaah_rtp/aah_rx_player_substream.cpp b/media/libaah_rtp/aah_rx_player_substream.cpp index b015fc976c..708ea36d46 100644 --- a/media/libaah_rtp/aah_rx_player_substream.cpp +++ b/media/libaah_rtp/aah_rx_player_substream.cpp @@ -42,6 +42,9 @@ AAH_RXPlayer::Substream::Substream(uint32_t ssrc, OMXClient& omx) { if (decoder_ == NULL) { LOGE("%s failed to allocate decoder pump!", __PRETTY_FUNCTION__); } + if (OK != decoder_->initCheck()) { + LOGE("%s failed to initialize decoder pump!", __PRETTY_FUNCTION__); + } // cleanupBufferInProgress will reset most of the internal state variables. // Just need to make sure that buffer_in_progress_ is NULL before calling. -- 2.11.0