Backed out changeset e334b3139e2a (bug 831224)
authorEd Morley <emorley@mozilla.com>
Thu, 08 Aug 2013 09:59:45 -0700
changeset 154790 99e7a2a7029e7f217561865723562d7b88fe1856
parent 154789 4f70ae91d84e0079a2767d127169ecf50c74bdb6
child 154791 3ee2edd9e015847323f2a4fd46901b8bcaef11b2
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs831224
milestone26.0a1
backs oute334b3139e2afc7034c2fc4bd9468e08b96d31be
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
Backed out changeset e334b3139e2a (bug 831224)
content/media/MediaDecoderReader.h
content/media/omx/MediaOmxReader.cpp
content/media/omx/MediaOmxReader.h
content/media/omx/OmxDecoder.cpp
content/media/omx/OmxDecoder.h
--- a/content/media/MediaDecoderReader.h
+++ b/content/media/MediaDecoderReader.h
@@ -514,18 +514,18 @@ public:
   };
 
   virtual int64_t AudioQueueMemoryInUse() {
     AudioQueueMemoryFunctor functor;
     mAudioQueue.LockedForEach(functor);
     return functor.mResult;
   }
 
-  // Only used by WebMReader and MediaOmxReader for now, so stub here rather
-  // than in every reader than inherits from MediaDecoderReader.
+  // Only used by WebMReader for now, so stub here rather than in every
+  // reader than inherits from MediaDecoderReader.
   virtual void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset) {}
 
   virtual MediaQueue<AudioData>& AudioQueue() { return mAudioQueue; }
   virtual MediaQueue<VideoData>& VideoQueue() { return mVideoQueue; }
 
   // Returns a pointer to the decoder.
   AbstractMediaDecoder* GetDecoder() {
     return mDecoder;
--- a/content/media/omx/MediaOmxReader.cpp
+++ b/content/media/omx/MediaOmxReader.cpp
@@ -265,25 +265,16 @@ bool MediaOmxReader::DecodeVideoFrame(bo
     mVideoQueue.Push(v);
 
     break;
   }
 
   return true;
 }
 
-void MediaOmxReader::NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset)
-{
-  android::OmxDecoder *omxDecoder = mOmxDecoder.get();
-
-  if (omxDecoder) {
-    omxDecoder->NotifyDataArrived(aBuffer, aLength, aOffset);
-  }
-}
-
 bool MediaOmxReader::DecodeAudioData()
 {
   NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
 
   // This is the approximate byte position in the stream.
   int64_t pos = mDecoder->GetResource()->Tell();
 
   // Read next frame
--- a/content/media/omx/MediaOmxReader.h
+++ b/content/media/omx/MediaOmxReader.h
@@ -35,18 +35,16 @@ class MediaOmxReader : public MediaDecod
   int32_t mSkipCount;
 public:
   MediaOmxReader(AbstractMediaDecoder* aDecoder);
   ~MediaOmxReader();
 
   virtual nsresult Init(MediaDecoderReader* aCloneDonor);
   virtual nsresult ResetDecode();
 
-  virtual void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset);
-
   virtual bool DecodeAudioData();
   virtual bool DecodeVideoFrame(bool &aKeyframeSkip,
                                 int64_t aTimeThreshold);
 
   virtual bool HasAudio()
   {
     return mHasAudio;
   }
--- a/content/media/omx/OmxDecoder.cpp
+++ b/content/media/omx/OmxDecoder.cpp
@@ -13,18 +13,16 @@
 #include <stagefright/MediaExtractor.h>
 #include <stagefright/MetaData.h>
 #include <stagefright/OMXClient.h>
 #include <stagefright/OMXCodec.h>
 #include <OMX.h>
 
 #include "mozilla/Preferences.h"
 #include "mozilla/Types.h"
-#include "mozilla/Monitor.h"
-#include "nsMimeTypes.h"
 #include "MPAPI.h"
 #include "prlog.h"
 
 #include "GonkNativeWindow.h"
 #include "GonkNativeWindowClient.h"
 #include "OMXCodecProxy.h"
 #include "OmxDecoder.h"
 
@@ -34,124 +32,16 @@ PRLogModuleInfo *gOmxDecoderLog;
 #else
 #define LOG(x...)
 #endif
 
 using namespace MPAPI;
 using namespace mozilla;
 
 namespace mozilla {
-
-// When loading an MP3 stream from a file, we need to parse the file's
-// content to find its duration. We must do this from within the decode
-// thread, but parsing itself must be done in the main thread.
-//
-// After we read the file's content in the decode thread, an instance
-// of this class is scheduled to the main thread for parsing the MP3
-// stream. We then wait until it has returned.
-
-class OmxDecoderNotifyDataArrivedRunnable : public nsRunnable
-{
-public:
-  OmxDecoderNotifyDataArrivedRunnable(android::OmxDecoder* aOmxDecoder, const char* aBuffer, uint64_t aLength, int64_t aOffset)
-  : mOmxDecoder(aOmxDecoder),
-    mBuffer(aBuffer),
-    mLength(aLength),
-    mOffset(aOffset),
-    mCompletedMonitor("OmxDecoderNotifyDataArrived.mCompleted"),
-    mCompleted(false)
-  {
-    MOZ_ASSERT(mOmxDecoder.get());
-    MOZ_ASSERT(mBuffer.get() || !mLength);
-  }
-
-  NS_IMETHOD Run()
-  {
-    NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
-
-    const char* buffer = mBuffer.get();
-
-    while (mLength) {
-      uint32_t length = std::min<uint64_t>(mLength, UINT32_MAX);
-      mOmxDecoder->NotifyDataArrived(mBuffer.get(), mLength, mOffset);
-
-      buffer  += length;
-      mLength -= length;
-      mOffset += length;
-    }
-
-    Completed();
-
-    return NS_OK;
-  }
-
-  void WaitForCompletion()
-  {
-    MOZ_ASSERT(!NS_IsMainThread());
-
-    MonitorAutoLock mon(mCompletedMonitor);
-    if (!mCompleted) {
-      mCompletedMonitor.Wait();
-    }
-  }
-
-  static nsresult ProcessCachedData(android::OmxDecoder* aOmxDecoder);
-
-private:
-  // Call this function at the end of Run() to notify waiting
-  // threads.
-  void Completed()
-  {
-    MonitorAutoLock mon(mCompletedMonitor);
-    MOZ_ASSERT(!mCompleted);
-    mCompleted = true;
-    mCompletedMonitor.Notify();
-  }
-
-  android::sp<android::OmxDecoder> mOmxDecoder;
-  nsAutoArrayPtr<const char>       mBuffer;
-  uint64_t                         mLength;
-  int64_t                          mOffset;
-
-  Monitor mCompletedMonitor;
-  bool    mCompleted;
-};
-
-nsresult OmxDecoderNotifyDataArrivedRunnable::ProcessCachedData(android::OmxDecoder* aOmxDecoder)
-{
-  MOZ_ASSERT(aOmxDecoder);
-
-  NS_ASSERTION(!NS_IsMainThread(), "Should not be on main thread.");
-
-  MediaResource* resource = aOmxDecoder->GetResource();
-  MOZ_ASSERT(resource);
-
-  int64_t length = resource->GetCachedDataEnd(0);
-  NS_ENSURE_TRUE(length >= 0, NS_ERROR_UNEXPECTED);
-
-  if (!length) {
-    return NS_OK; // Cache is empty, nothing to do
-  }
-
-  nsAutoArrayPtr<char> buffer(new char[length]);
-
-  nsresult rv = resource->ReadFromCache(buffer.get(), 0, length);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsRefPtr<OmxDecoderNotifyDataArrivedRunnable> runnable(
-    new OmxDecoderNotifyDataArrivedRunnable(aOmxDecoder, buffer.forget(), length, 0));
-
-  rv = NS_DispatchToMainThread(runnable.get());
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  runnable->WaitForCompletion();
-
-  return NS_OK;
-}
-
 namespace layers {
 
 VideoGraphicBuffer::VideoGraphicBuffer(const android::wp<android::OmxDecoder> aOmxDecoder,
                                        android::MediaBuffer *aBuffer,
                                        SurfaceDescriptor& aDescriptor)
   : GraphicBufferLocked(aDescriptor),
     mMediaBuffer(aBuffer),
     mOmxDecoder(aOmxDecoder)
@@ -252,17 +142,16 @@ OmxDecoder::OmxDecoder(MediaResource *aR
   mVideoHeight(0),
   mVideoColorFormat(0),
   mVideoStride(0),
   mVideoSliceHeight(0),
   mVideoRotation(0),
   mAudioChannels(-1),
   mAudioSampleRate(-1),
   mDurationUs(-1),
-  mMP3FrameParser(aResource->GetLength()),
   mVideoBuffer(nullptr),
   mAudioBuffer(nullptr),
   mIsVideoSeeking(false),
   mAudioMetadataRead(false),
   mAudioPaused(false),
   mVideoPaused(false)
 {
   mLooper = new ALooper;
@@ -380,39 +269,19 @@ bool OmxDecoder::TryLoad() {
 
   // calculate duration
   int64_t totalDurationUs = 0;
   int64_t durationUs = 0;
   if (mVideoTrack.get() && mVideoTrack->getFormat()->findInt64(kKeyDuration, &durationUs)) {
     if (durationUs > totalDurationUs)
       totalDurationUs = durationUs;
   }
-  if (mAudioTrack.get()) {
-    durationUs = -1;
-    const char* audioMime;
-    sp<MetaData> meta = mAudioTrack->getFormat();
-
-    if (meta->findCString(kKeyMIMEType, &audioMime) && !strcasecmp(audioMime, AUDIO_MP3)) {
-      // Feed MP3 parser with cached data. Local files will be fully
-      // cached already, network streams will update with sucessive
-      // calls to NotifyDataArrived.
-      nsresult rv = OmxDecoderNotifyDataArrivedRunnable::ProcessCachedData(this);
-
-      if (rv == NS_OK) {
-        durationUs = mMP3FrameParser.GetDuration();
-        if (durationUs > totalDurationUs) {
-          totalDurationUs = durationUs;
-        }
-      }
-    }
-    if ((durationUs == -1) && meta->findInt64(kKeyDuration, &durationUs)) {
-      if (durationUs > totalDurationUs) {
-        totalDurationUs = durationUs;
-      }
-    }
+  if (mAudioTrack.get() && mAudioTrack->getFormat()->findInt64(kKeyDuration, &durationUs)) {
+    if (durationUs > totalDurationUs)
+      totalDurationUs = durationUs;
   }
   mDurationUs = totalDurationUs;
 
   // read video metadata
   if (mVideoSource.get() && !SetVideoFormat()) {
     NS_WARNING("Couldn't set OMX video format");
     return false;
   }
@@ -611,35 +480,16 @@ bool OmxDecoder::SetAudioFormat() {
   }
 
   LOG(PR_LOG_DEBUG, "channelCount: %d sampleRate: %d",
       mAudioChannels, mAudioSampleRate);
 
   return true;
 }
 
-void OmxDecoder::NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset)
-{
-  if (!mMP3FrameParser.IsMP3()) {
-    return;
-  }
-
-  mMP3FrameParser.NotifyDataArrived(aBuffer, aLength, aOffset);
-
-  int64_t durationUs = mMP3FrameParser.GetDuration();
-
-  if (durationUs != mDurationUs) {
-    mDurationUs = durationUs;
-
-    MOZ_ASSERT(mDecoder);
-    ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
-    mDecoder->UpdateMediaDuration(mDurationUs);
-  }
-}
-
 void OmxDecoder::ReleaseVideoBuffer() {
   if (mVideoBuffer) {
     mVideoBuffer->release();
     mVideoBuffer = nullptr;
   }
 }
 
 void OmxDecoder::ReleaseAudioBuffer() {
--- a/content/media/omx/OmxDecoder.h
+++ b/content/media/omx/OmxDecoder.h
@@ -4,17 +4,16 @@
 #include <stagefright/MediaSource.h>
 #include <stagefright/DataSource.h>
 #include <stagefright/MediaSource.h>
 #include <utils/RefBase.h>
 
 #include "GonkNativeWindow.h"
 #include "GonkNativeWindowClient.h"
 #include "GrallocImages.h"
-#include "MP3FrameParser.h"
 #include "MPAPI.h"
 #include "MediaResource.h"
 #include "AbstractMediaDecoder.h"
 #include "OMXCodecProxy.h"
 
 namespace android {
 class OmxDecoder;
 };
@@ -72,17 +71,16 @@ public:
 private:
   MediaStreamSource(const MediaStreamSource &);
   MediaStreamSource &operator=(const MediaStreamSource &);
 };
 
 class OmxDecoder : public OMXCodecProxy::EventListener {
   typedef MPAPI::AudioFrame AudioFrame;
   typedef MPAPI::VideoFrame VideoFrame;
-  typedef mozilla::MP3FrameParser MP3FrameParser;
   typedef mozilla::MediaResource MediaResource;
   typedef mozilla::AbstractMediaDecoder AbstractMediaDecoder;
 
   enum {
     kPreferSoftwareCodecs = 1,
     kSoftwareCodecsOnly = 8,
     kHardwareCodecsOnly = 16,
   };
@@ -106,17 +104,16 @@ class OmxDecoder : public OMXCodecProxy:
   int32_t mVideoStride;
   int32_t mVideoSliceHeight;
   int32_t mVideoRotation;
   int32_t mAudioChannels;
   int32_t mAudioSampleRate;
   int64_t mDurationUs;
   VideoFrame mVideoFrame;
   AudioFrame mAudioFrame;
-  MP3FrameParser mMP3FrameParser;
 
   // Lifetime of these should be handled by OMXCodec, as long as we release
   //   them after use: see ReleaseVideoBuffer(), ReleaseAudioBuffer()
   MediaBuffer *mVideoBuffer;
   MediaBuffer *mAudioBuffer;
 
   // Hold video's MediaBuffers that are released during video seeking.
   // The holded MediaBuffers are released soon after seek completion.
@@ -175,18 +172,16 @@ public:
   bool TryLoad();
   bool IsDormantNeeded();
   bool IsWaitingMediaResources();
   bool AllocateMediaResources();
   void ReleaseMediaResources();
   bool SetVideoFormat();
   bool SetAudioFormat();
 
-  void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset);
-
   void GetDuration(int64_t *durationUs) {
     *durationUs = mDurationUs;
   }
 
   void GetVideoParameters(int32_t *width, int32_t *height) {
     *width = mVideoWidth;
     *height = mVideoHeight;
   }