diff options
Diffstat (limited to 'media')
| -rw-r--r-- | media/libmediaplayerservice/StagefrightPlayer.cpp | 6 | ||||
| -rw-r--r-- | media/libmediaplayerservice/nuplayer/NuPlayer.cpp | 6 | ||||
| -rw-r--r-- | media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp | 45 | ||||
| -rw-r--r-- | media/libstagefright/AACExtractor.cpp | 33 | ||||
| -rw-r--r-- | media/libstagefright/ACodec.cpp | 26 | ||||
| -rw-r--r-- | media/libstagefright/AwesomePlayer.cpp | 27 | ||||
| -rwxr-xr-x | media/libstagefright/MPEG4Writer.cpp | 4 | ||||
| -rw-r--r-- | media/libstagefright/SurfaceMediaSource.cpp | 8 | ||||
| -rw-r--r-- | media/libstagefright/include/AwesomePlayer.h | 6 | 
9 files changed, 110 insertions, 51 deletions
diff --git a/media/libmediaplayerservice/StagefrightPlayer.cpp b/media/libmediaplayerservice/StagefrightPlayer.cpp index 40e055c..cd4b1ef 100644 --- a/media/libmediaplayerservice/StagefrightPlayer.cpp +++ b/media/libmediaplayerservice/StagefrightPlayer.cpp @@ -72,16 +72,14 @@ status_t StagefrightPlayer::setDataSource(const sp<IStreamSource> &source) {  status_t StagefrightPlayer::setVideoSurface(const sp<Surface> &surface) {      LOGV("setVideoSurface"); -    mPlayer->setSurface(surface); -    return OK; +    return mPlayer->setSurface(surface);  }  status_t StagefrightPlayer::setVideoSurfaceTexture(          const sp<ISurfaceTexture> &surfaceTexture) {      LOGV("setVideoSurfaceTexture"); -    mPlayer->setSurfaceTexture(surfaceTexture); -    return OK; +    return mPlayer->setSurfaceTexture(surfaceTexture);  }  status_t StagefrightPlayer::prepare() { diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp index 7fb141a..1f08a91 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp +++ b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp @@ -316,9 +316,11 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {                                  &cropLeft, &cropTop, &cropRight, &cropBottom));                      LOGV("Video output format changed to %d x %d " -                         "(crop: %d, %d, %d, %d)", +                         "(crop: %d x %d @ (%d, %d))",                           width, height, -                         cropLeft, cropTop, cropRight, cropBottom); +                         (cropRight - cropLeft + 1), +                         (cropBottom - cropTop + 1), +                         cropLeft, cropTop);                      notifyListener(                              MEDIA_SET_VIDEO_SIZE, diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp index 35ed43f..8f213da 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp +++ b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp @@ -395,29 +395,40 @@ void NuPlayer::Renderer::onQueueBuffer(const sp<AMessage> &msg) {          postDrainVideoQueue();      } -    if (mSyncQueues && !mAudioQueue.empty() && !mVideoQueue.empty()) { -        int64_t firstAudioTimeUs; -        int64_t firstVideoTimeUs; -        CHECK((*mAudioQueue.begin()).mBuffer->meta() -                ->findInt64("timeUs", &firstAudioTimeUs)); -        CHECK((*mVideoQueue.begin()).mBuffer->meta() -                ->findInt64("timeUs", &firstVideoTimeUs)); +    if (!mSyncQueues || mAudioQueue.empty() || mVideoQueue.empty()) { +        return; +    } -        int64_t diff = firstVideoTimeUs - firstAudioTimeUs; +    sp<ABuffer> firstAudioBuffer = (*mAudioQueue.begin()).mBuffer; +    sp<ABuffer> firstVideoBuffer = (*mVideoQueue.begin()).mBuffer; -        LOGV("queueDiff = %.2f secs", diff / 1E6); +    if (firstAudioBuffer == NULL || firstVideoBuffer == NULL) { +        // EOS signalled on either queue. +        syncQueuesDone(); +        return; +    } -        if (diff > 100000ll) { -            // Audio data starts More than 0.1 secs before video. -            // Drop some audio. +    int64_t firstAudioTimeUs; +    int64_t firstVideoTimeUs; +    CHECK(firstAudioBuffer->meta() +            ->findInt64("timeUs", &firstAudioTimeUs)); +    CHECK(firstVideoBuffer->meta() +            ->findInt64("timeUs", &firstVideoTimeUs)); -            (*mAudioQueue.begin()).mNotifyConsumed->post(); -            mAudioQueue.erase(mAudioQueue.begin()); -            return; -        } +    int64_t diff = firstVideoTimeUs - firstAudioTimeUs; -        syncQueuesDone(); +    LOGV("queueDiff = %.2f secs", diff / 1E6); + +    if (diff > 100000ll) { +        // Audio data starts More than 0.1 secs before video. +        // Drop some audio. + +        (*mAudioQueue.begin()).mNotifyConsumed->post(); +        mAudioQueue.erase(mAudioQueue.begin()); +        return;      } + +    syncQueuesDone();  }  void NuPlayer::Renderer::syncQueuesDone() { diff --git a/media/libstagefright/AACExtractor.cpp b/media/libstagefright/AACExtractor.cpp index a5a6b64..52b1200 100644 --- a/media/libstagefright/AACExtractor.cpp +++ b/media/libstagefright/AACExtractor.cpp @@ -33,8 +33,6 @@  namespace android { -#define ADTS_HEADER_LENGTH 7 -  class AACSource : public MediaSource {  public:      AACSource(const sp<DataSource> &source, @@ -88,7 +86,16 @@ uint32_t get_sample_rate(const uint8_t sf_index)      return 0;  } -static size_t getFrameSize(const sp<DataSource> &source, off64_t offset) { +// Returns the frame length in bytes as described in an ADTS header starting at the given offset, +//     or 0 if the size can't be read due to an error in the header or a read failure. +// The returned value is the AAC frame size with the ADTS header length (regardless of +//     the presence of the CRC). +// If headerSize is non-NULL, it will be used to return the size of the header of this ADTS frame. +static size_t getAdtsFrameLength(const sp<DataSource> &source, off64_t offset, size_t* headerSize) { + +    const size_t kAdtsHeaderLengthNoCrc = 7; +    const size_t kAdtsHeaderLengthWithCrc = 9; +      size_t frameSize = 0;      uint8_t syncword[2]; @@ -111,7 +118,15 @@ static size_t getFrameSize(const sp<DataSource> &source, off64_t offset) {      }      frameSize = (header[0] & 0x3) << 11 | header[1] << 3 | header[2] >> 5; -    frameSize += ADTS_HEADER_LENGTH + protectionAbsent ? 0 : 2; + +    // protectionAbsent is 0 if there is CRC +    size_t headSize = protectionAbsent ? kAdtsHeaderLengthNoCrc : kAdtsHeaderLengthWithCrc; +    if (headSize > frameSize) { +        return 0; +    } +    if (headerSize != NULL) { +        *headerSize = headSize; +    }      return frameSize;  } @@ -148,7 +163,7 @@ AACExtractor::AACExtractor(const sp<DataSource> &source)      if (mDataSource->getSize(&streamSize) == OK) {           while (offset < streamSize) { -            if ((frameSize = getFrameSize(source, offset)) == 0) { +            if ((frameSize = getAdtsFrameLength(source, offset, NULL)) == 0) {                  return;              } @@ -268,8 +283,8 @@ status_t AACSource::read(          }      } -    size_t frameSize, frameSizeWithoutHeader; -    if ((frameSize = getFrameSize(mDataSource, mOffset)) == 0) { +    size_t frameSize, frameSizeWithoutHeader, headerSize; +    if ((frameSize = getAdtsFrameLength(mDataSource, mOffset, &headerSize)) == 0) {          return ERROR_END_OF_STREAM;      } @@ -279,8 +294,8 @@ status_t AACSource::read(          return err;      } -    frameSizeWithoutHeader = frameSize - ADTS_HEADER_LENGTH; -    if (mDataSource->readAt(mOffset + ADTS_HEADER_LENGTH, buffer->data(), +    frameSizeWithoutHeader = frameSize - headerSize; +    if (mDataSource->readAt(mOffset + headerSize, buffer->data(),                  frameSizeWithoutHeader) != (ssize_t)frameSizeWithoutHeader) {          buffer->release();          buffer = NULL; diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp index 5d91f6a..e9dc61c 100644 --- a/media/libstagefright/ACodec.cpp +++ b/media/libstagefright/ACodec.cpp @@ -1738,7 +1738,17 @@ ACodec::LoadedToIdleState::LoadedToIdleState(ACodec *codec)  void ACodec::LoadedToIdleState::stateEntered() {      LOGV("[%s] Now Loaded->Idle", mCodec->mComponentName.c_str()); -    CHECK_EQ(allocateBuffers(), (status_t)OK); +    status_t err; +    if ((err = allocateBuffers()) != OK) { +        LOGE("Failed to allocate buffers after transitioning to IDLE state " +             "(error 0x%08x)", +             err); + +        sp<AMessage> notify = mCodec->mNotify->dup(); +        notify->setInt32("what", ACodec::kWhatError); +        notify->setInt32("omx-error", OMX_ErrorUndefined); +        notify->post(); +    }  }  status_t ACodec::LoadedToIdleState::allocateBuffers() { @@ -2046,8 +2056,18 @@ bool ACodec::OutputPortSettingsChangedState::onOMXEvent(                              mCodec->mNode, OMX_CommandPortEnable, kPortIndexOutput),                           (status_t)OK); -                CHECK_EQ(mCodec->allocateBuffersOnPort(kPortIndexOutput), -                         (status_t)OK); +                status_t err; +                if ((err = mCodec->allocateBuffersOnPort( +                                kPortIndexOutput)) != OK) { +                    LOGE("Failed to allocate output port buffers after " +                         "port reconfiguration (error 0x%08x)", +                         err); + +                    sp<AMessage> notify = mCodec->mNotify->dup(); +                    notify->setInt32("what", ACodec::kWhatError); +                    notify->setInt32("omx-error", OMX_ErrorUndefined); +                    notify->post(); +                }                  return true;              } else if (data1 == (OMX_U32)OMX_CommandPortEnable) { diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp index bc42a42..142dda0 100644 --- a/media/libstagefright/AwesomePlayer.cpp +++ b/media/libstagefright/AwesomePlayer.cpp @@ -1152,22 +1152,26 @@ bool AwesomePlayer::isPlaying() const {      return (mFlags & PLAYING) || (mFlags & CACHE_UNDERRUN);  } -void AwesomePlayer::setSurface(const sp<Surface> &surface) { +status_t AwesomePlayer::setSurface(const sp<Surface> &surface) {      Mutex::Autolock autoLock(mLock);      mSurface = surface; -    setNativeWindow_l(surface); +    return setNativeWindow_l(surface);  } -void AwesomePlayer::setSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture) { +status_t AwesomePlayer::setSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture) {      Mutex::Autolock autoLock(mLock);      mSurface.clear(); + +    status_t err;      if (surfaceTexture != NULL) { -        setNativeWindow_l(new SurfaceTextureClient(surfaceTexture)); +        err = setNativeWindow_l(new SurfaceTextureClient(surfaceTexture));      } else { -        setNativeWindow_l(NULL); +        err = setNativeWindow_l(NULL);      } + +    return err;  }  void AwesomePlayer::shutdownVideoDecoder_l() { @@ -1190,11 +1194,11 @@ void AwesomePlayer::shutdownVideoDecoder_l() {      LOGI("video decoder shutdown completed");  } -void AwesomePlayer::setNativeWindow_l(const sp<ANativeWindow> &native) { +status_t AwesomePlayer::setNativeWindow_l(const sp<ANativeWindow> &native) {      mNativeWindow = native;      if (mVideoSource == NULL) { -        return; +        return OK;      }      LOGI("attempting to reconfigure to use new surface"); @@ -1206,7 +1210,12 @@ void AwesomePlayer::setNativeWindow_l(const sp<ANativeWindow> &native) {      shutdownVideoDecoder_l(); -    CHECK_EQ(initVideoDecoder(), (status_t)OK); +    status_t err = initVideoDecoder(); + +    if (err != OK) { +        LOGE("failed to reinstantiate video decoder after surface change."); +        return err; +    }      if (mLastVideoTimeUs >= 0) {          mSeeking = SEEK; @@ -1217,6 +1226,8 @@ void AwesomePlayer::setNativeWindow_l(const sp<ANativeWindow> &native) {      if (wasPlaying) {          play_l();      } + +    return OK;  }  void AwesomePlayer::setAudioSink( 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/include/AwesomePlayer.h b/media/libstagefright/include/AwesomePlayer.h index 14476d3..24cf77c 100644 --- a/media/libstagefright/include/AwesomePlayer.h +++ b/media/libstagefright/include/AwesomePlayer.h @@ -84,8 +84,8 @@ struct AwesomePlayer {      bool isPlaying() const; -    void setSurface(const sp<Surface> &surface); -    void setSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture); +    status_t setSurface(const sp<Surface> &surface); +    status_t setSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture);      void setAudioSink(const sp<MediaPlayerBase::AudioSink> &audioSink);      status_t setLooping(bool shouldLoop); @@ -298,7 +298,7 @@ private:      void postAudioSeekComplete_l();      void shutdownVideoDecoder_l(); -    void setNativeWindow_l(const sp<ANativeWindow> &native); +    status_t setNativeWindow_l(const sp<ANativeWindow> &native);      bool isStreamingHTTP() const;      void sendCacheStats();  | 
