Bug 1049321 - Move SubBufferDecoder to a new file. r=cajbir
authorMatthew Gregan <kinetik@flim.org>
Mon, 11 Aug 2014 14:05:06 +1200
changeset 198817 ad31e026b098da534ce0dc48a5218c959153609f
parent 198816 9d08e8efdd42b77deb77ec700c2802097de5ad4c
child 198818 a3ce4466a3daa2d76cd218bdc2831b994c1fa35a
push id27286
push usernigelbabu@gmail.com
push dateMon, 11 Aug 2014 06:26:45 +0000
treeherdermozilla-central@8c4a1b3a2a8b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscajbir
bugs1049321
milestone34.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 1049321 - Move SubBufferDecoder to a new file. r=cajbir
content/media/mediasource/SourceBuffer.cpp
content/media/mediasource/SubBufferDecoder.cpp
content/media/mediasource/SubBufferDecoder.h
content/media/mediasource/moz.build
--- a/content/media/mediasource/SourceBuffer.cpp
+++ b/content/media/mediasource/SourceBuffer.cpp
@@ -34,101 +34,16 @@ extern PRLogModuleInfo* GetMediaSourceAP
 #define MSE_API(...) PR_LOG(GetMediaSourceAPILog(), PR_LOG_DEBUG, (__VA_ARGS__))
 #else
 #define MSE_DEBUG(...)
 #define MSE_API(...)
 #endif
 
 namespace mozilla {
 
-class MediaResource;
-class ReentrantMonitor;
-
-namespace layers {
-
-class ImageContainer;
-
-} // namespace layers
-
-ReentrantMonitor&
-SubBufferDecoder::GetReentrantMonitor()
-{
-  return mParentDecoder->GetReentrantMonitor();
-}
-
-bool
-SubBufferDecoder::OnStateMachineThread() const
-{
-  return mParentDecoder->OnStateMachineThread();
-}
-
-bool
-SubBufferDecoder::OnDecodeThread() const
-{
-  return mParentDecoder->OnDecodeThread();
-}
-
-SourceBufferResource*
-SubBufferDecoder::GetResource() const
-{
-  return static_cast<SourceBufferResource*>(mResource.get());
-}
-
-void
-SubBufferDecoder::NotifyDecodedFrames(uint32_t aParsed, uint32_t aDecoded)
-{
-  return mParentDecoder->NotifyDecodedFrames(aParsed, aDecoded);
-}
-
-void
-SubBufferDecoder::SetMediaDuration(int64_t aDuration)
-{
-  mMediaDuration = aDuration;
-}
-
-void
-SubBufferDecoder::UpdateEstimatedMediaDuration(int64_t aDuration)
-{
-  MSE_DEBUG("SubBufferDecoder(%p)::UpdateEstimatedMediaDuration(aDuration=%lld)", this, aDuration);
-}
-
-void
-SubBufferDecoder::SetMediaSeekable(bool aMediaSeekable)
-{
-  MSE_DEBUG("SubBufferDecoder(%p)::SetMediaSeekable(aMediaSeekable=%d)", this, aMediaSeekable);
-}
-
-layers::ImageContainer*
-SubBufferDecoder::GetImageContainer()
-{
-  return mParentDecoder->GetImageContainer();
-}
-
-MediaDecoderOwner*
-SubBufferDecoder::GetOwner()
-{
-  return mParentDecoder->GetOwner();
-}
-
-int64_t
-SubBufferDecoder::ConvertToByteOffset(double aTime)
-{
-  // Uses a conversion based on (aTime/duration) * length.  For the
-  // purposes of eviction this should be adequate since we have the
-  // byte threshold as well to ensure data actually gets evicted and
-  // we ensure we don't evict before the current playable point.
-  if (mMediaDuration == -1) {
-    return -1;
-  }
-  int64_t length = GetResource()->GetLength();
-  MOZ_ASSERT(length > 0);
-  int64_t offset = (aTime / (double(mMediaDuration) / USECS_PER_S)) * length;
-  return offset;
-}
-
 class ContainerParser {
 public:
   virtual ~ContainerParser() {}
 
   virtual bool IsInitSegmentPresent(const uint8_t* aData, uint32_t aLength)
   {
     MSE_DEBUG("ContainerParser: aLength=%u [%x%x%x%x]",
               aLength,
new file mode 100644
--- /dev/null
+++ b/content/media/mediasource/SubBufferDecoder.cpp
@@ -0,0 +1,127 @@
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* 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/. */
+
+#include "SubBufferDecoder.h"
+#include "MediaSourceDecoder.h"
+#include "MediaDecoderReader.h"
+
+#ifdef PR_LOGGING
+extern PRLogModuleInfo* GetMediaSourceLog();
+extern PRLogModuleInfo* GetMediaSourceAPILog();
+
+#define MSE_DEBUG(...) PR_LOG(GetMediaSourceLog(), PR_LOG_DEBUG, (__VA_ARGS__))
+#define MSE_API(...) PR_LOG(GetMediaSourceAPILog(), PR_LOG_DEBUG, (__VA_ARGS__))
+#else
+#define MSE_DEBUG(...)
+#define MSE_API(...)
+#endif
+
+namespace mozilla {
+
+class ReentrantMonitor;
+
+namespace layers {
+
+class ImageContainer;
+
+} // namespace layers
+
+
+ReentrantMonitor&
+SubBufferDecoder::GetReentrantMonitor()
+{
+  return mParentDecoder->GetReentrantMonitor();
+}
+
+bool
+SubBufferDecoder::OnStateMachineThread() const
+{
+  return mParentDecoder->OnStateMachineThread();
+}
+
+bool
+SubBufferDecoder::OnDecodeThread() const
+{
+  return mParentDecoder->OnDecodeThread();
+}
+
+SourceBufferResource*
+SubBufferDecoder::GetResource() const
+{
+  return static_cast<SourceBufferResource*>(mResource.get());
+}
+
+void
+SubBufferDecoder::NotifyDecodedFrames(uint32_t aParsed, uint32_t aDecoded)
+{
+  return mParentDecoder->NotifyDecodedFrames(aParsed, aDecoded);
+}
+
+void
+SubBufferDecoder::SetMediaDuration(int64_t aDuration)
+{
+  mMediaDuration = aDuration;
+}
+
+void
+SubBufferDecoder::UpdateEstimatedMediaDuration(int64_t aDuration)
+{
+  MSE_DEBUG("SubBufferDecoder(%p)::UpdateEstimatedMediaDuration(aDuration=%lld)", this, aDuration);
+}
+
+void
+SubBufferDecoder::SetMediaSeekable(bool aMediaSeekable)
+{
+  MSE_DEBUG("SubBufferDecoder(%p)::SetMediaSeekable(aMediaSeekable=%d)", this, aMediaSeekable);
+}
+
+layers::ImageContainer*
+SubBufferDecoder::GetImageContainer()
+{
+  return mParentDecoder->GetImageContainer();
+}
+
+MediaDecoderOwner*
+SubBufferDecoder::GetOwner()
+{
+  return mParentDecoder->GetOwner();
+}
+
+void
+SubBufferDecoder::NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset)
+{
+  mReader->NotifyDataArrived(aBuffer, aLength, aOffset);
+
+  // XXX: Params make no sense to parent decoder as it relates to a
+  // specific SubBufferDecoder's data stream.  Pass bogus values here to
+  // force parent decoder's state machine to recompute end time for
+  // infinite length media.
+  mParentDecoder->NotifyDataArrived(nullptr, 0, 0);
+}
+
+nsresult
+SubBufferDecoder::GetBuffered(dom::TimeRanges* aBuffered)
+{
+  // XXX: Need mStartTime (from StateMachine) instead of passing 0.
+  return mReader->GetBuffered(aBuffered, 0);
+}
+
+int64_t
+SubBufferDecoder::ConvertToByteOffset(double aTime)
+{
+  // Uses a conversion based on (aTime/duration) * length.  For the
+  // purposes of eviction this should be adequate since we have the
+  // byte threshold as well to ensure data actually gets evicted and
+  // we ensure we don't evict before the current playable point.
+  if (mMediaDuration == -1) {
+    return -1;
+  }
+  int64_t length = GetResource()->GetLength();
+  MOZ_ASSERT(length > 0);
+  int64_t offset = (aTime / (double(mMediaDuration) / USECS_PER_S)) * length;
+  return offset;
+}
+
+} // namespace mozilla
--- a/content/media/mediasource/SubBufferDecoder.h
+++ b/content/media/mediasource/SubBufferDecoder.h
@@ -7,17 +7,25 @@
 #ifndef MOZILLA_SUBBUFFERDECODER_H_
 #define MOZILLA_SUBBUFFERDECODER_H_
 
 #include "BufferDecoder.h"
 #include "SourceBufferResource.h"
 
 namespace mozilla {
 
+class MediaResource;
 class MediaSourceDecoder;
+class MediaDecoderReader;
+
+namespace dom {
+
+class TimeRanges;
+
+} // namespace dom
 
 class SubBufferDecoder : public BufferDecoder
 {
 public:
   // This class holds a weak pointer to MediaResource.  It's the responsibility
   // of the caller to manage the memory of the MediaResource object.
   SubBufferDecoder(MediaResource* aResource, MediaSourceDecoder* aParentDecoder)
     : BufferDecoder(aResource), mParentDecoder(aParentDecoder), mReader(nullptr)
@@ -42,32 +50,20 @@ public:
   virtual SourceBufferResource* GetResource() const MOZ_OVERRIDE;
   virtual void NotifyDecodedFrames(uint32_t aParsed, uint32_t aDecoded) MOZ_OVERRIDE;
   virtual void SetMediaDuration(int64_t aDuration) MOZ_OVERRIDE;
   virtual void UpdateEstimatedMediaDuration(int64_t aDuration) MOZ_OVERRIDE;
   virtual void SetMediaSeekable(bool aMediaSeekable) MOZ_OVERRIDE;
   virtual layers::ImageContainer* GetImageContainer() MOZ_OVERRIDE;
   virtual MediaDecoderOwner* GetOwner() MOZ_OVERRIDE;
 
-  void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset)
-  {
-    mReader->NotifyDataArrived(aBuffer, aLength, aOffset);
-
-    // XXX: Params make no sense to parent decoder as it relates to a
-    // specific SubBufferDecoder's data stream.  Pass bogus values here to
-    // force parent decoder's state machine to recompute end time for
-    // infinite length media.
-    mParentDecoder->NotifyDataArrived(nullptr, 0, 0);
-  }
-
-  nsresult GetBuffered(dom::TimeRanges* aBuffered)
-  {
-    // XXX: Need mStartTime (from StateMachine) instead of passing 0.
-    return mReader->GetBuffered(aBuffered, 0);
-  }
+  // Warning: these mirror calls from MediaDecoder, but this class's base is
+  // AbstractMediaDecoder, which does not supply this interface.
+  void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset);
+  nsresult GetBuffered(dom::TimeRanges* aBuffered);
 
   // Given a time convert it into an approximate byte offset from the
   // cached data. Returns -1 if no such value is computable.
   int64_t ConvertToByteOffset(double aTime);
 
   int64_t GetMediaDuration() MOZ_OVERRIDE
   {
     return mMediaDuration;
--- a/content/media/mediasource/moz.build
+++ b/content/media/mediasource/moz.build
@@ -17,13 +17,14 @@ EXPORTS.mozilla.dom += [
 ]
 
 UNIFIED_SOURCES += [
     'MediaSource.cpp',
     'MediaSourceDecoder.cpp',
     'SourceBuffer.cpp',
     'SourceBufferList.cpp',
     'SourceBufferResource.cpp',
+    'SubBufferDecoder.cpp',
 ]
 
 FAIL_ON_WARNINGS = True
 
 FINAL_LIBRARY = 'xul'