Bug 922334 - Add zero division check and prevent unncecessary mp3 parsing. r=doublec, a=koi+
authorSotaro Ikeda <sikeda@mozilla.com>
Thu, 03 Oct 2013 10:53:21 +0200
changeset 160559 74e15e692c0de8a8df18ae2e39ec19e13e7f6971
parent 160558 14a9e13e8c653875c1fb78f71761f6ef4bf0e774
child 160560 8b4152d366c3010d512b281f58661a5883283ac8
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)
reviewersdoublec, koi
bugs922334
milestone26.0a2
Bug 922334 - Add zero division check and prevent unncecessary mp3 parsing. r=doublec, a=koi+
content/media/MP3FrameParser.cpp
content/media/omx/OmxDecoder.cpp
content/media/omx/OmxDecoder.h
--- a/content/media/MP3FrameParser.cpp
+++ b/content/media/MP3FrameParser.cpp
@@ -457,17 +457,17 @@ void MP3FrameParser::Parse(const char* a
     mLength = mOffset;
   }
 }
 
 int64_t MP3FrameParser::GetDuration()
 {
   MutexAutoLock mon(mLock);
 
-  if (!mNumFrames) {
+  if (!mNumFrames || !mSampleRate) {
     return -1; // Not a single frame decoded yet
   }
 
   // Estimate the total number of frames in the file from the average frame
   // size we've seen so far, and the length of the file.
   double avgFrameSize = (double)mTotalFrameSize / mNumFrames;
 
   // Need to cut out the header here. Ignore everything up to the first MP3
--- a/content/media/omx/OmxDecoder.cpp
+++ b/content/media/omx/OmxDecoder.cpp
@@ -256,16 +256,17 @@ OmxDecoder::OmxDecoder(MediaResource *aR
   mVideoColorFormat(0),
   mVideoStride(0),
   mVideoSliceHeight(0),
   mVideoRotation(0),
   mAudioChannels(-1),
   mAudioSampleRate(-1),
   mDurationUs(-1),
   mMP3FrameParser(aResource->GetLength()),
+  mIsMp3(false),
   mVideoBuffer(nullptr),
   mAudioBuffer(nullptr),
   mIsVideoSeeking(false),
   mAudioMetadataRead(false),
   mAudioPaused(false),
   mVideoPaused(false)
 {
   mLooper = new ALooper;
@@ -324,16 +325,22 @@ bool OmxDecoder::Init() {
   mResource->SetReadMode(MediaCacheStream::MODE_METADATA);
 
   sp<MediaExtractor> extractor = MediaExtractor::Create(dataSource);
   if (extractor == nullptr) {
     NS_WARNING("Could not create MediaExtractor");
     return false;
   }
 
+  const char* extractorMime;
+  sp<MetaData> meta = extractor->getMetaData();
+  if (meta->findCString(kKeyMIMEType, &extractorMime) && !strcasecmp(extractorMime, AUDIO_MP3)) {
+    mIsMp3 = true;
+  }
+
   ssize_t audioTrackIndex = -1;
   ssize_t videoTrackIndex = -1;
 
   for (size_t i = 0; i < extractor->countTracks(); ++i) {
     sp<MetaData> meta = extractor->getTrackMetaData(i);
 
     int32_t bitRate;
     if (!meta->findInt32(kKeyBitRate, &bitRate))
@@ -618,17 +625,17 @@ 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()) {
+  if (!mAudioTrack.get() || !mIsMp3 || !mMP3FrameParser.IsMP3()) {
     return;
   }
 
   mMP3FrameParser.Parse(aBuffer, aLength, aOffset);
 
   int64_t durationUs = mMP3FrameParser.GetDuration();
 
   if (durationUs != mDurationUs) {
--- a/content/media/omx/OmxDecoder.h
+++ b/content/media/omx/OmxDecoder.h
@@ -107,16 +107,17 @@ class OmxDecoder : public OMXCodecProxy:
   int32_t mVideoSliceHeight;
   int32_t mVideoRotation;
   int32_t mAudioChannels;
   int32_t mAudioSampleRate;
   int64_t mDurationUs;
   VideoFrame mVideoFrame;
   AudioFrame mAudioFrame;
   MP3FrameParser mMP3FrameParser;
+  bool mIsMp3;
 
   // 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.