Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 395575ab authored by Jason Simmons's avatar Jason Simmons Committed by Mike Lockwood
Browse files

Hold the AAHDecoderPump ThreadWrapper in a ref-counting pointer

Change-Id: Iff840dbd9e1f79a07e62c1481b2b0797f30247cb
parent 1a5e6b1f
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -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<MetaData> 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());
+2 −1
Original line number Diff line number Diff line
@@ -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<ThreadWrapper>   thread_;
    Condition           thread_cond_;
    Mutex               thread_lock_;
    status_t            thread_status_;
+3 −0
Original line number Diff line number Diff line
@@ -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.