diff options
Diffstat (limited to 'media')
| -rw-r--r-- | media/libstagefright/AudioPlayer.cpp | 2 | ||||
| -rwxr-xr-x | media/libstagefright/MPEG4Writer.cpp | 4 | ||||
| -rw-r--r-- | media/libstagefright/SurfaceMediaSource.cpp | 8 | ||||
| -rw-r--r-- | media/libstagefright/foundation/ALooperRoster.cpp | 49 | ||||
| -rw-r--r-- | media/libstagefright/foundation/AMessage.cpp | 25 | 
5 files changed, 77 insertions, 11 deletions
diff --git a/media/libstagefright/AudioPlayer.cpp b/media/libstagefright/AudioPlayer.cpp index dd69e6b..d41ab1b 100644 --- a/media/libstagefright/AudioPlayer.cpp +++ b/media/libstagefright/AudioPlayer.cpp @@ -180,6 +180,8 @@ void AudioPlayer::pause(bool playPendingSamples) {          } else {              mAudioTrack->stop();          } + +        mNumFramesPlayed = 0;      } else {          if (mAudioSink.get() != NULL) {              mAudioSink->pause(); diff --git a/media/libstagefright/MPEG4Writer.cpp b/media/libstagefright/MPEG4Writer.cpp index 5f58090..46d87df 100755 --- a/media/libstagefright/MPEG4Writer.cpp +++ b/media/libstagefright/MPEG4Writer.cpp @@ -1173,7 +1173,7 @@ void MPEG4Writer::Track::addOneSttsTableEntry(          size_t sampleCount, int32_t duration) {      if (duration == 0) { -        LOGW("%d 0-duration samples found: %d", sampleCount); +        LOGW("0-duration samples found: %d", sampleCount);      }      SttsTableEntry sttsEntry(sampleCount, duration);      mSttsTableEntries.push_back(sttsEntry); @@ -1304,7 +1304,7 @@ void MPEG4Writer::bufferChunk(const Chunk& chunk) {  void MPEG4Writer::writeChunkToFile(Chunk* chunk) {      LOGV("writeChunkToFile: %lld from %s track", -        chunk.mTimestampUs, chunk.mTrack->isAudio()? "audio": "video"); +        chunk->mTimeStampUs, chunk->mTrack->isAudio()? "audio": "video");      int32_t isFirstSample = true;      while (!chunk->mSamples.empty()) { diff --git a/media/libstagefright/SurfaceMediaSource.cpp b/media/libstagefright/SurfaceMediaSource.cpp index c2e6707..91b81c2 100644 --- a/media/libstagefright/SurfaceMediaSource.cpp +++ b/media/libstagefright/SurfaceMediaSource.cpp @@ -179,9 +179,11 @@ status_t SurfaceMediaSource::dequeueBuffer(int *outBuf, uint32_t w, uint32_t h,      // TODO: Currently just uses mDefaultWidth/Height. In the future      // we might declare mHeight and mWidth and check against those here.      if ((w != 0) || (h != 0)) { -        LOGE("dequeuebuffer: invalid buffer size! Req: %dx%d, Found: %dx%d", -                mDefaultWidth, mDefaultHeight, w, h); -        return BAD_VALUE; +        if ((w != mDefaultWidth) || (h != mDefaultHeight)) { +            LOGE("dequeuebuffer: invalid buffer size! Req: %dx%d, Found: %dx%d", +                    mDefaultWidth, mDefaultHeight, w, h); +            return BAD_VALUE; +        }      }      status_t returnFlags(OK); diff --git a/media/libstagefright/foundation/ALooperRoster.cpp b/media/libstagefright/foundation/ALooperRoster.cpp index 8aa1b15..e399f2f 100644 --- a/media/libstagefright/foundation/ALooperRoster.cpp +++ b/media/libstagefright/foundation/ALooperRoster.cpp @@ -27,7 +27,8 @@  namespace android {  ALooperRoster::ALooperRoster() -    : mNextHandlerID(1) { +    : mNextHandlerID(1), +      mNextReplyID(1) {  }  ALooper::handler_id ALooperRoster::registerHandler( @@ -70,15 +71,19 @@ void ALooperRoster::unregisterHandler(ALooper::handler_id handlerID) {      mHandlers.removeItemsAt(index);  } -void ALooperRoster::postMessage( +status_t ALooperRoster::postMessage(          const sp<AMessage> &msg, int64_t delayUs) {      Mutex::Autolock autoLock(mLock); +    return postMessage_l(msg, delayUs); +} +status_t ALooperRoster::postMessage_l( +        const sp<AMessage> &msg, int64_t delayUs) {      ssize_t index = mHandlers.indexOfKey(msg->target());      if (index < 0) {          LOGW("failed to post message. Target handler not registered."); -        return; +        return -ENOENT;      }      const HandlerInfo &info = mHandlers.valueAt(index); @@ -91,10 +96,12 @@ void ALooperRoster::postMessage(               msg->target());          mHandlers.removeItemsAt(index); -        return; +        return -ENOENT;      }      looper->post(msg, delayUs); + +    return OK;  }  void ALooperRoster::deliverMessage(const sp<AMessage> &msg) { @@ -145,4 +152,38 @@ sp<ALooper> ALooperRoster::findLooper(ALooper::handler_id handlerID) {      return looper;  } +status_t ALooperRoster::postAndAwaitResponse( +        const sp<AMessage> &msg, sp<AMessage> *response) { +    Mutex::Autolock autoLock(mLock); + +    uint32_t replyID = mNextReplyID++; + +    msg->setInt32("replyID", replyID); + +    status_t err = postMessage_l(msg, 0 /* delayUs */); + +    if (err != OK) { +        response->clear(); +        return err; +    } + +    ssize_t index; +    while ((index = mReplies.indexOfKey(replyID)) < 0) { +        mRepliesCondition.wait(mLock); +    } + +    *response = mReplies.valueAt(index); +    mReplies.removeItemsAt(index); + +    return OK; +} + +void ALooperRoster::postReply(uint32_t replyID, const sp<AMessage> &reply) { +    Mutex::Autolock autoLock(mLock); + +    CHECK(mReplies.indexOfKey(replyID) < 0); +    mReplies.add(replyID, reply); +    mRepliesCondition.broadcast(); +} +  }  // namespace android diff --git a/media/libstagefright/foundation/AMessage.cpp b/media/libstagefright/foundation/AMessage.cpp index b592c3f..582bdba 100644 --- a/media/libstagefright/foundation/AMessage.cpp +++ b/media/libstagefright/foundation/AMessage.cpp @@ -27,6 +27,8 @@  namespace android { +extern ALooperRoster gLooperRoster; +  AMessage::AMessage(uint32_t what, ALooper::handler_id target)      : mWhat(what),        mTarget(target), @@ -227,11 +229,30 @@ bool AMessage::findRect(  }  void AMessage::post(int64_t delayUs) { -    extern ALooperRoster gLooperRoster; -      gLooperRoster.postMessage(this, delayUs);  } +status_t AMessage::postAndAwaitResponse(sp<AMessage> *response) { +    return gLooperRoster.postAndAwaitResponse(this, response); +} + +void AMessage::postReply(uint32_t replyID) { +    gLooperRoster.postReply(replyID, this); +} + +bool AMessage::senderAwaitsResponse(uint32_t *replyID) const { +    int32_t tmp; +    bool found = findInt32("replyID", &tmp); + +    if (!found) { +        return false; +    } + +    *replyID = static_cast<uint32_t>(tmp); + +    return true; +} +  sp<AMessage> AMessage::dup() const {      sp<AMessage> msg = new AMessage(mWhat, mTarget);      msg->mNumItems = mNumItems;  | 
