Bug 862182 - Hold references to MediaResource in nsRefPtrs (content/media/omx), and fix some omx compiler warnings. r=doublec
authorChris Pearce <cpearce@mozilla.com>
Wed, 01 May 2013 11:23:46 +1200
changeset 141375 5378db8362f54a94fb8bc8360990e04f70996bb9
parent 141374 64d208186331e6bf17ea8b712354ca02f01b6013
child 141376 cc82e1599dd0d7542b1164dbb64cd79680e5ff30
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdoublec
bugs862182
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 862182 - Hold references to MediaResource in nsRefPtrs (content/media/omx), and fix some omx compiler warnings. r=doublec
content/media/omx/MPAPI.h
content/media/omx/MediaOmxReader.cpp
content/media/omx/OmxDecoder.cpp
content/media/omx/OmxDecoder.h
--- a/content/media/omx/MPAPI.h
+++ b/content/media/omx/MPAPI.h
@@ -17,17 +17,16 @@ struct VideoPlane {
   int32_t mWidth;
   int32_t mHeight;
   int32_t mOffset;
   int32_t mSkip;
 };
 
 struct VideoFrame {
   int64_t mTimeUs;
-  int64_t mEndTimeUs;
   bool mKeyFrame;
   bool mShouldSkip;
   void *mData;
   size_t mSize;
   int32_t mStride;
   int32_t mSliceHeight;
   int32_t mRotation;
   VideoPlane Y;
--- a/content/media/omx/MediaOmxReader.cpp
+++ b/content/media/omx/MediaOmxReader.cpp
@@ -38,17 +38,17 @@ MediaOmxReader::~MediaOmxReader()
 }
 
 nsresult MediaOmxReader::Init(MediaDecoderReader* aCloneDonor)
 {
   return NS_OK;
 }
 
 nsresult MediaOmxReader::ReadMetadata(VideoInfo* aInfo,
-                                        MetadataTags** aTags)
+                                      MetadataTags** aTags)
 {
   NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
 
   *aTags = nullptr;
 
   if (!mOmxDecoder.get()) {
     mOmxDecoder = new OmxDecoder(mDecoder->GetResource(), mDecoder);
     if (!mOmxDecoder->Init()) {
@@ -113,17 +113,17 @@ nsresult MediaOmxReader::ResetDecode()
     container->ClearCurrentFrame();
   }
 
   mOmxDecoder.clear();
   return NS_OK;
 }
 
 bool MediaOmxReader::DecodeVideoFrame(bool &aKeyframeSkip,
-                                        int64_t aTimeThreshold)
+                                      int64_t aTimeThreshold)
 {
   // Record number of frames decoded and parsed. Automatically update the
   // stats counters using the AutoNotifyDecoded stack-based class.
   uint32_t parsed = 0, decoded = 0;
   AbstractMediaDecoder::AutoNotifyDecoded autoNotify(mDecoder, parsed, decoded);
 
   bool doSeek = mVideoSeekTimeUs != -1;
   if (doSeek) {
@@ -334,15 +334,15 @@ nsresult MediaOmxReader::GetBuffered(moz
 void MediaOmxReader::OnDecodeThreadFinish() {
   if (mOmxDecoder.get()) {
     mOmxDecoder->Pause();
   }
 }
 
 void MediaOmxReader::OnDecodeThreadStart() {
   if (mOmxDecoder.get()) {
-    nsresult result = mOmxDecoder->Play();
+    DebugOnly<nsresult> result = mOmxDecoder->Play();
     NS_ASSERTION(result == NS_OK, "OmxDecoder should be in play state to continue decoding");
   }
 }
 
 } // namespace mozilla
 
--- a/content/media/omx/OmxDecoder.cpp
+++ b/content/media/omx/OmxDecoder.cpp
@@ -34,18 +34,18 @@ using namespace mozilla;
 
 namespace mozilla {
 namespace layers {
 
 VideoGraphicBuffer::VideoGraphicBuffer(const android::wp<android::OmxDecoder> aOmxDecoder,
                                        android::MediaBuffer *aBuffer,
                                        SurfaceDescriptor *aDescriptor)
   : GraphicBufferLocked(*aDescriptor),
-    mOmxDecoder(aOmxDecoder),
-    mMediaBuffer(aBuffer)
+    mMediaBuffer(aBuffer),
+    mOmxDecoder(aOmxDecoder)
 {
   mMediaBuffer->add_ref();
 }
 
 VideoGraphicBuffer::~VideoGraphicBuffer()
 {
   if (mMediaBuffer) {
     mMediaBuffer->release();
@@ -69,17 +69,17 @@ VideoGraphicBuffer::Unlock()
 
 }
 }
 
 namespace android {
 
 MediaStreamSource::MediaStreamSource(MediaResource *aResource,
                                      AbstractMediaDecoder *aDecoder) :
-  mDecoder(aDecoder), mResource(aResource)
+  mResource(aResource), mDecoder(aDecoder)
 {
 }
 
 MediaStreamSource::~MediaStreamSource()
 {
 }
 
 status_t MediaStreamSource::initCheck() const
@@ -122,32 +122,32 @@ status_t MediaStreamSource::getSize(off6
 }
 
 }  // namespace android
 
 using namespace android;
 
 OmxDecoder::OmxDecoder(MediaResource *aResource,
                        AbstractMediaDecoder *aDecoder) :
+  mDecoder(aDecoder),
   mResource(aResource),
-  mDecoder(aDecoder),
   mVideoWidth(0),
   mVideoHeight(0),
   mVideoColorFormat(0),
   mVideoStride(0),
   mVideoSliceHeight(0),
   mVideoRotation(0),
   mAudioChannels(-1),
   mAudioSampleRate(-1),
   mDurationUs(-1),
   mVideoBuffer(nullptr),
   mAudioBuffer(nullptr),
   mIsVideoSeeking(false),
-  mPaused(false),
-  mAudioMetadataRead(false)
+  mAudioMetadataRead(false),
+  mPaused(false)
 {
 }
 
 OmxDecoder::~OmxDecoder()
 {
   ReleaseVideoBuffer();
   ReleaseAudioBuffer();
 
@@ -229,17 +229,17 @@ bool OmxDecoder::Init() {
   int64_t totalDurationUs = 0;
 
   mNativeWindow = new GonkNativeWindow();
   mNativeWindowClient = new GonkNativeWindowClient(mNativeWindow);
 
   // OMXClient::connect() always returns OK and abort's fatally if
   // it can't connect.
   OMXClient client;
-  status_t err = client.connect();
+  DebugOnly<status_t> err = client.connect();
   NS_ASSERTION(err == OK, "Failed to connect to OMX in mediaserver.");
   sp<IOMX> omx = client.interface();
 
   sp<MediaSource> videoTrack;
   sp<MediaSource> videoSource;
   if (videoTrackIndex != -1 && (videoTrack = extractor->getTrack(videoTrackIndex)) != nullptr) {
     // Experience with OMX codecs is that only the HW decoders are
     // worth bothering with, at least on the platforms where this code
@@ -507,17 +507,16 @@ bool OmxDecoder::ReadVideo(VideoFrame *a
       ReleaseAllPendingVideoBuffersLocked();
     }
   } else {
     err = mVideoSource->read(&mVideoBuffer);
   }
 
   if (err == OK && mVideoBuffer->range_length() > 0) {
     int64_t timeUs;
-    int64_t durationUs;
     int32_t unreadable;
     int32_t keyFrame;
 
     if (!mVideoBuffer->meta_data()->findInt64(kKeyTime, &timeUs) ) {
       NS_WARNING("OMX decoder did not return frame time");
       return false;
     }
 
@@ -540,33 +539,30 @@ bool OmxDecoder::ReadVideo(VideoFrame *a
       // See Bug 850566.
       const mozilla::layers::SurfaceDescriptorGralloc& grallocDesc = descriptor->get_SurfaceDescriptorGralloc();
       mozilla::layers::SurfaceDescriptor newDescriptor = mozilla::layers::SurfaceDescriptorGralloc(grallocDesc.bufferParent(),
                                                                grallocDesc.bufferChild(), nsIntSize(mVideoWidth, mVideoHeight), grallocDesc.external());
 
       aFrame->mGraphicBuffer = new mozilla::layers::VideoGraphicBuffer(this, mVideoBuffer, &newDescriptor);
       aFrame->mRotation = mVideoRotation;
       aFrame->mTimeUs = timeUs;
-      aFrame->mEndTimeUs = timeUs + durationUs;
       aFrame->mKeyFrame = keyFrame;
       aFrame->Y.mWidth = mVideoWidth;
       aFrame->Y.mHeight = mVideoHeight;
     } else {
       char *data = static_cast<char *>(mVideoBuffer->data()) + mVideoBuffer->range_offset();
       size_t length = mVideoBuffer->range_length();
 
       if (unreadable) {
         LOG(PR_LOG_DEBUG, "video frame is unreadable");
       }
 
       if (!ToVideoFrame(aFrame, timeUs, data, length, keyFrame)) {
         return false;
       }
-
-      aFrame->mEndTimeUs = timeUs + durationUs;
     }
 
     if (aKeyframeSkip && timeUs < aTimeUs) {
       aFrame->mShouldSkip = true;
     }
 
   }
   else if (err == INFO_FORMAT_CHANGED) {
@@ -691,8 +687,9 @@ void OmxDecoder::Pause() {
     mVideoSource->pause();
   }
 
   if (mAudioSource.get()) {
     mAudioSource->pause();
   }
   mPaused = true;
 }
+
--- a/content/media/omx/OmxDecoder.h
+++ b/content/media/omx/OmxDecoder.h
@@ -33,20 +33,20 @@ class VideoGraphicBuffer : public Graphi
 
 namespace android {
 
 // MediaStreamSource is a DataSource that reads from a MPAPI media stream.
 class MediaStreamSource : public DataSource {
   typedef mozilla::MediaResource MediaResource;
   typedef mozilla::AbstractMediaDecoder AbstractMediaDecoder;
 
-  MediaResource *mResource;
+  nsRefPtr<MediaResource> mResource;
   AbstractMediaDecoder *mDecoder;
 public:
-  MediaStreamSource(MediaResource *aResource,
+  MediaStreamSource(MediaResource* aResource,
                     AbstractMediaDecoder *aDecoder);
 
   virtual status_t initCheck() const;
   virtual ssize_t readAt(off64_t offset, void *data, size_t size);
   virtual ssize_t readAt(off_t offset, void *data, size_t size) {
     return readAt(static_cast<off64_t>(offset), data, size);
   }
   virtual status_t getSize(off_t *size) {
@@ -75,17 +75,17 @@ class OmxDecoder : public RefBase {
 
   enum {
     kPreferSoftwareCodecs = 1,
     kSoftwareCodecsOnly = 8,
     kHardwareCodecsOnly = 16,
   };
 
   AbstractMediaDecoder *mDecoder;
-  MediaResource *mResource;
+  nsRefPtr<MediaResource> mResource;
   sp<GonkNativeWindow> mNativeWindow;
   sp<GonkNativeWindowClient> mNativeWindowClient;
   sp<MediaSource> mVideoTrack;
   sp<MediaSource> mVideoSource;
   sp<MediaSource> mAudioTrack;
   sp<MediaSource> mAudioSource;
   int32_t mVideoWidth;
   int32_t mVideoHeight;