Bug 905513 - Don't clobber audio VideoInfo fields when accepting video configuration. r=doublec
authorMatthew Gregan <kinetik@flim.org>
Fri, 27 Sep 2013 17:22:38 +1200
changeset 148941 1a134e410e123bd145fe8a6239ca50114282e8fe
parent 148940 935ab0a88dde1354384790b4c709c35bd1f7d0e9
child 148942 a98471699e919ec06e6f6d555e9e7608862fbc93
push id25366
push userkwierso@gmail.com
push dateSat, 28 Sep 2013 02:13:38 +0000
treeherdermozilla-central@e1914e294152 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdoublec
bugs905513
milestone27.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 905513 - Don't clobber audio VideoInfo fields when accepting video configuration. r=doublec
content/media/BufferDecoder.h
content/media/mediasource/MediaSourceDecoder.cpp
content/media/mediasource/SourceBuffer.cpp
content/media/mediasource/SubBufferDecoder.h
--- a/content/media/BufferDecoder.h
+++ b/content/media/BufferDecoder.h
@@ -33,17 +33,17 @@ public:
   ReentrantMonitor& GetReentrantMonitor() MOZ_OVERRIDE;
 
   bool IsShutdown() const MOZ_FINAL MOZ_OVERRIDE;
 
   bool OnStateMachineThread() const MOZ_OVERRIDE;
 
   bool OnDecodeThread() const MOZ_OVERRIDE;
 
-  MediaResource* GetResource() const MOZ_FINAL MOZ_OVERRIDE;
+  MediaResource* GetResource() const MOZ_OVERRIDE;
 
   void NotifyBytesConsumed(int64_t aBytes, int64_t aOffset) MOZ_FINAL MOZ_OVERRIDE;
 
   void NotifyDecodedFrames(uint32_t aParsed, uint32_t aDecoded) MOZ_FINAL MOZ_OVERRIDE;
 
   int64_t GetEndMediaTime() const MOZ_FINAL MOZ_OVERRIDE;
 
   int64_t GetMediaDuration() MOZ_FINAL MOZ_OVERRIDE;
@@ -69,17 +69,17 @@ public:
   void SetMediaEndTime(int64_t aTime) MOZ_FINAL MOZ_OVERRIDE;
 
   void UpdatePlaybackPosition(int64_t aTime) MOZ_FINAL MOZ_OVERRIDE;
 
   void OnReadMetadataCompleted() MOZ_FINAL MOZ_OVERRIDE;
 
   MediaDecoderOwner* GetOwner() MOZ_FINAL MOZ_OVERRIDE;
 
-private:
+protected:
   // This monitor object is not really used to synchronize access to anything.
   // It's just there in order for us to be able to override
   // GetReentrantMonitor correctly.
   ReentrantMonitor mReentrantMonitor;
   nsCOMPtr<nsIThread> mDecodeThread;
   nsRefPtr<MediaResource> mResource;
 };
 
--- a/content/media/mediasource/MediaSourceDecoder.cpp
+++ b/content/media/mediasource/MediaSourceDecoder.cpp
@@ -30,17 +30,17 @@ namespace dom {
 
 class TimeRanges;
 
 } // namespace dom
 
 class MediaSourceReader : public MediaDecoderReader
 {
 public:
-  MediaSourceReader(AbstractMediaDecoder* aDecoder)
+  MediaSourceReader(MediaSourceDecoder* aDecoder)
     : MediaDecoderReader(aDecoder)
   {
   }
 
   nsresult Init(MediaDecoderReader* aCloneDonor) MOZ_OVERRIDE
   {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
@@ -179,37 +179,35 @@ MediaSourceDecoder::CreateSubDecoder(con
 nsresult
 MediaSourceReader::ReadMetadata(VideoInfo* aInfo, MetadataTags** aTags)
 {
   mDecoder->SetMediaSeekable(true);
   mDecoder->SetTransportSeekable(false);
 
   MediaSourceDecoder* decoder = static_cast<MediaSourceDecoder*>(mDecoder);
   const nsTArray<MediaDecoderReader*>& readers = decoder->GetReaders();
-  bool gotVideo = false;
-  bool gotAudio = false;
   for (uint32_t i = 0; i < readers.Length(); ++i) {
     MediaDecoderReader* reader = readers[i];
     VideoInfo vi;
     nsresult rv = reader->ReadMetadata(&vi, aTags);
     LOG(PR_LOG_DEBUG, ("ReadMetadata on SB reader %p", reader));
     if (NS_FAILED(rv)) {
       return rv;
     }
-    if (vi.mHasVideo && !gotVideo) {
-      mInfo = vi;
+    if (vi.mHasVideo && !mInfo.mHasVideo) {
+      mInfo.mDisplay = vi.mDisplay;
+      mInfo.mStereoMode = vi.mStereoMode;
+      mInfo.mHasVideo = true;
       decoder->SetVideoReader(reader);
-      gotVideo = true;
     }
-    if (vi.mHasAudio && !gotAudio) {
+    if (vi.mHasAudio && !mInfo.mHasAudio) {
       mInfo.mAudioRate = vi.mAudioRate;
       mInfo.mAudioChannels = vi.mAudioChannels;
       mInfo.mHasAudio = true;
       decoder->SetAudioReader(reader);
-      gotAudio = true;
     }
   }
   *aInfo = mInfo;
 
   return NS_OK;
 }
 
 } // namespace mozilla
--- a/content/media/mediasource/SourceBuffer.cpp
+++ b/content/media/mediasource/SourceBuffer.cpp
@@ -55,16 +55,22 @@ SubBufferDecoder::OnStateMachineThread()
 }
 
 bool
 SubBufferDecoder::OnDecodeThread() const
 {
   return mParentDecoder->OnDecodeThread();
 }
 
+SourceBufferResource*
+SubBufferDecoder::GetResource() const
+{
+  return static_cast<SourceBufferResource*>(mResource.get());
+}
+
 void
 SubBufferDecoder::SetMediaDuration(int64_t aDuration)
 {
   mParentDecoder->SetMediaDuration(aDuration);
 }
 
 void
 SubBufferDecoder::UpdateEstimatedMediaDuration(int64_t aDuration)
@@ -221,17 +227,17 @@ SourceBuffer::Detach()
   Ended();
   mDecoder = nullptr;
   mMediaSource = nullptr;
 }
 
 void
 SourceBuffer::Ended()
 {
-  static_cast<SourceBufferResource*>(mDecoder->GetResource())->Ended();
+  mDecoder->GetResource()->Ended();
 }
 
 SourceBuffer::SourceBuffer(MediaSource* aMediaSource, const nsACString& aType)
   : nsDOMEventTargetHelper(aMediaSource->GetParentObject())
   , mMediaSource(aMediaSource)
   , mAppendWindowStart(0)
   , mAppendWindowEnd(PositiveInfinity())
   , mTimestampOffset(0)
@@ -242,17 +248,17 @@ SourceBuffer::SourceBuffer(MediaSource* 
   MediaSourceDecoder* parentDecoder = aMediaSource->GetDecoder();
   mDecoder = parentDecoder->CreateSubDecoder(aType);
   MOZ_ASSERT(mDecoder);
 }
 
 SourceBuffer::~SourceBuffer()
 {
   if (mDecoder) {
-    static_cast<SourceBufferResource*>(mDecoder->GetResource())->Ended();
+    mDecoder->GetResource()->Ended();
   }
 }
 
 MediaSource*
 SourceBuffer::GetParentObject() const
 {
   return mMediaSource;
 }
@@ -316,19 +322,19 @@ SourceBuffer::AppendData(const uint8_t* 
   }
   // TODO: Run coded frame eviction algorithm.
   // TODO: Test buffer full flag.
   LOG(PR_LOG_DEBUG, ("%p Append(ArrayBuffer=%u)", this, aLength));
   StartUpdating();
   // XXX: For future reference: NDA call must run on the main thread.
   mDecoder->NotifyDataArrived(reinterpret_cast<const char*>(aData),
                               aLength,
-                              static_cast<SourceBufferResource*>(mDecoder->GetResource())->GetLength());
+                              mDecoder->GetResource()->GetLength());
   // TODO: Run buffer append algorithm asynchronously (would call StopUpdating()).
-  static_cast<SourceBufferResource*>(mDecoder->GetResource())->AppendData(aData, aLength);
+  mDecoder->GetResource()->AppendData(aData, aLength);
   StopUpdating();
 }
 
 NS_IMPL_CYCLE_COLLECTION_INHERITED_1(SourceBuffer, nsDOMEventTargetHelper, mMediaSource)
 
 NS_IMPL_ADDREF_INHERITED(SourceBuffer, nsDOMEventTargetHelper)
 NS_IMPL_RELEASE_INHERITED(SourceBuffer, nsDOMEventTargetHelper)
 
--- a/content/media/mediasource/SubBufferDecoder.h
+++ b/content/media/mediasource/SubBufferDecoder.h
@@ -3,16 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_SUBBUFFERDECODER_H_
 #define MOZILLA_SUBBUFFERDECODER_H_
 
 #include "BufferDecoder.h"
+#include "SourceBufferResource.h"
 
 namespace mozilla {
 
 class MediaSourceDecoder;
 
 class SubBufferDecoder : public BufferDecoder
 {
 public:
@@ -27,16 +28,17 @@ public:
   {
     MOZ_ASSERT(!mReader);
     mReader = aReader;
   }
 
   ReentrantMonitor& GetReentrantMonitor() MOZ_OVERRIDE;
   bool OnStateMachineThread() const MOZ_OVERRIDE;
   bool OnDecodeThread() const MOZ_OVERRIDE;
+  SourceBufferResource* GetResource() const MOZ_OVERRIDE;
   void SetMediaDuration(int64_t aDuration) MOZ_OVERRIDE;
   void UpdateEstimatedMediaDuration(int64_t aDuration) MOZ_OVERRIDE;
   void SetMediaSeekable(bool aMediaSeekable) MOZ_OVERRIDE;
   void SetTransportSeekable(bool aTransportSeekable) MOZ_OVERRIDE;
   layers::ImageContainer* GetImageContainer() MOZ_OVERRIDE;
 
   void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset)
   {