Bug 911059 - Move WebAudio's BufferDecoder to its own file so it can be shared with MSE. r=cpearce, a=webaudio
authorMatthew Gregan <kinetik@flim.org>
Thu, 05 Sep 2013 11:59:34 +1200
changeset 149244 0618521e6e13
parent 149243 acc893e11f2b
child 149245 923719705762
push id4211
push userryanvm@gmail.com
push dateThu, 05 Sep 2013 00:50:22 +0000
treeherdermozilla-aurora@c403d63667fe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce, webaudio
bugs911059
milestone25.0a2
Bug 911059 - Move WebAudio's BufferDecoder to its own file so it can be shared with MSE. r=cpearce, a=webaudio
content/media/BufferDecoder.cpp
content/media/BufferDecoder.h
content/media/moz.build
content/media/webaudio/MediaBufferDecoder.cpp
new file mode 100644
--- /dev/null
+++ b/content/media/BufferDecoder.cpp
@@ -0,0 +1,186 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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 "BufferDecoder.h"
+
+#include "nsISupports.h"
+#include "MediaResource.h"
+
+namespace mozilla {
+
+#ifdef PR_LOGGING
+extern PRLogModuleInfo* gMediaDecoderLog;
+#endif
+
+NS_IMPL_ISUPPORTS0(BufferDecoder)
+
+BufferDecoder::BufferDecoder(MediaResource* aResource)
+  : mReentrantMonitor("BufferDecoder")
+  , mResource(aResource)
+{
+  MOZ_ASSERT(NS_IsMainThread());
+  MOZ_COUNT_CTOR(BufferDecoder);
+#ifdef PR_LOGGING
+  if (!gMediaDecoderLog) {
+    gMediaDecoderLog = PR_NewLogModule("MediaDecoder");
+  }
+#endif
+}
+
+BufferDecoder::~BufferDecoder()
+{
+  // The dtor may run on any thread, we cannot be sure.
+  MOZ_COUNT_DTOR(BufferDecoder);
+}
+
+void
+BufferDecoder::BeginDecoding(nsIThread* aDecodeThread)
+{
+  MOZ_ASSERT(!mDecodeThread && aDecodeThread);
+  mDecodeThread = aDecodeThread;
+}
+
+ReentrantMonitor&
+BufferDecoder::GetReentrantMonitor()
+{
+  return mReentrantMonitor;
+}
+
+bool
+BufferDecoder::IsShutdown() const
+{
+  // BufferDecoder cannot be shut down.
+  return false;
+}
+
+bool
+BufferDecoder::OnStateMachineThread() const
+{
+  // BufferDecoder doesn't have the concept of a state machine.
+  return true;
+}
+
+bool
+BufferDecoder::OnDecodeThread() const
+{
+  MOZ_ASSERT(mDecodeThread, "Forgot to call BeginDecoding?");
+  return IsCurrentThread(mDecodeThread);
+}
+
+MediaResource*
+BufferDecoder::GetResource() const
+{
+  return mResource;
+}
+
+void
+BufferDecoder::NotifyBytesConsumed(int64_t aBytes)
+{
+  // ignore
+}
+
+void
+BufferDecoder::NotifyDecodedFrames(uint32_t aParsed, uint32_t aDecoded)
+{
+  // ignore
+}
+
+int64_t
+BufferDecoder::GetEndMediaTime() const
+{
+  // unknown
+  return -1;
+}
+
+int64_t
+BufferDecoder::GetMediaDuration()
+{
+  // unknown
+  return -1;
+}
+
+void
+BufferDecoder::SetMediaDuration(int64_t aDuration)
+{
+  // ignore
+}
+
+void
+BufferDecoder::SetMediaSeekable(bool aMediaSeekable)
+{
+  // ignore
+}
+
+void
+BufferDecoder::SetTransportSeekable(bool aTransportSeekable)
+{
+  // ignore
+}
+
+VideoFrameContainer*
+BufferDecoder::GetVideoFrameContainer()
+{
+  // no video frame
+  return nullptr;
+}
+
+layers::ImageContainer*
+BufferDecoder::GetImageContainer()
+{
+  // no image container
+  return nullptr;
+}
+
+bool
+BufferDecoder::IsTransportSeekable()
+{
+  return false;
+}
+
+bool
+BufferDecoder::IsMediaSeekable()
+{
+  return false;
+}
+
+void
+BufferDecoder::MetadataLoaded(int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags)
+{
+  // ignore
+}
+
+void
+BufferDecoder::QueueMetadata(int64_t aTime, int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags)
+{
+  // ignore
+}
+
+void
+BufferDecoder::SetMediaEndTime(int64_t aTime)
+{
+  // ignore
+}
+
+void
+BufferDecoder::UpdatePlaybackPosition(int64_t aTime)
+{
+  // ignore
+}
+
+void
+BufferDecoder::OnReadMetadataCompleted()
+{
+  // ignore
+}
+
+MediaDecoderOwner*
+BufferDecoder::GetOwner()
+{
+  // unknown
+  return nullptr;
+}
+
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/content/media/BufferDecoder.h
@@ -0,0 +1,86 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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/. */
+
+#ifndef BUFFER_DECODER_H_
+#define BUFFER_DECODER_H_
+
+#include "AbstractMediaDecoder.h"
+#include "mozilla/Attributes.h"
+#include "mozilla/ReentrantMonitor.h"
+
+namespace mozilla {
+
+/**
+ * This class provides a decoder object which decodes a media file that lives in
+ * a memory buffer.
+ */
+class BufferDecoder : public AbstractMediaDecoder
+{
+public:
+  // This class holds a weak pointer to MediaResouce.  It's the responsibility
+  // of the caller to manage the memory of the MediaResource object.
+  explicit BufferDecoder(MediaResource* aResource);
+  virtual ~BufferDecoder();
+
+  NS_DECL_THREADSAFE_ISUPPORTS
+
+  // This has to be called before decoding begins
+  void BeginDecoding(nsIThread* aDecodeThread);
+
+  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;
+
+  void NotifyBytesConsumed(int64_t aBytes) 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;
+
+  void SetMediaDuration(int64_t aDuration) MOZ_OVERRIDE;
+
+  void SetMediaSeekable(bool aMediaSeekable) MOZ_OVERRIDE;
+
+  void SetTransportSeekable(bool aTransportSeekable) MOZ_OVERRIDE;
+
+  VideoFrameContainer* GetVideoFrameContainer() MOZ_FINAL MOZ_OVERRIDE;
+  layers::ImageContainer* GetImageContainer() MOZ_OVERRIDE;
+
+  bool IsTransportSeekable() MOZ_FINAL MOZ_OVERRIDE;
+
+  bool IsMediaSeekable() MOZ_FINAL MOZ_OVERRIDE;
+
+  void MetadataLoaded(int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags) MOZ_FINAL MOZ_OVERRIDE;
+  void QueueMetadata(int64_t aTime, int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags) MOZ_FINAL MOZ_OVERRIDE;
+
+  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:
+  // 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;
+};
+
+} // namespace mozilla
+
+#endif /* BUFFER_DECODER_H_ */
--- a/content/media/moz.build
+++ b/content/media/moz.build
@@ -53,16 +53,17 @@ EXPORTS += [
     'AudioChannelFormat.h',
     'AudioEventTimeline.h',
     'AudioNodeEngine.h',
     'AudioNodeExternalInputStream.h',
     'AudioNodeStream.h',
     'AudioSampleFormat.h',
     'AudioSegment.h',
     'AudioStream.h',
+    'BufferDecoder.h',
     'BufferMediaResource.h',
     'DOMMediaStream.h',
     'DecoderTraits.h',
     'EncodedBufferCache.h',
     'FileBlockCache.h',
     'MediaCache.h',
     'MediaDecoder.h',
     'MediaDecoderOwner.h',
@@ -98,16 +99,17 @@ CPP_SOURCES += [
     'AudioAvailableEventManager.cpp',
     'AudioChannelFormat.cpp',
     'AudioNodeEngine.cpp',
     'AudioNodeExternalInputStream.cpp',
     'AudioNodeStream.cpp',
     'AudioSegment.cpp',
     'AudioStream.cpp',
     'AudioStreamTrack.cpp',
+    'BufferDecoder.cpp',
     'DOMMediaStream.cpp',
     'DecoderTraits.cpp',
     'EncodedBufferCache.cpp',
     'FileBlockCache.cpp',
     'MediaCache.cpp',
     'MediaDecoder.cpp',
     'MediaDecoderReader.cpp',
     'MediaDecoderStateMachine.cpp',
--- a/content/media/webaudio/MediaBufferDecoder.cpp
+++ b/content/media/webaudio/MediaBufferDecoder.cpp
@@ -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/. */
 
 #include "MediaBufferDecoder.h"
 #include "AbstractMediaDecoder.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/ReentrantMonitor.h"
+#include "BufferDecoder.h"
 #include <speex/speex_resampler.h>
 #include "nsXPCOMCIDInternal.h"
 #include "nsComponentManagerUtils.h"
 #include "MediaDecoderReader.h"
 #include "BufferMediaResource.h"
 #include "DecoderTraits.h"
 #include "AudioContext.h"
 #include "AudioBuffer.h"
@@ -47,253 +48,16 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(Web
   NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mArrayBuffer)
 NS_IMPL_CYCLE_COLLECTION_TRACE_END
 
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebAudioDecodeJob, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebAudioDecodeJob, Release)
 
 using namespace dom;
 
-#ifdef PR_LOGGING
-extern PRLogModuleInfo* gMediaDecoderLog;
-#endif
-
-/**
- * This class provides a decoder object which decodes a media file that lives in
- * a memory buffer.
- */
-class BufferDecoder : public AbstractMediaDecoder
-{
-public:
-  // This class holds a weak pointer to MediaResouce.  It's the responsibility
-  // of the caller to manage the memory of the MediaResource object.
-  explicit BufferDecoder(MediaResource* aResource);
-  virtual ~BufferDecoder();
-
-  NS_DECL_THREADSAFE_ISUPPORTS
-
-  // This has to be called before decoding begins
-  void BeginDecoding(nsIThread* aDecodeThread)
-  {
-    MOZ_ASSERT(!mDecodeThread && aDecodeThread);
-    mDecodeThread = aDecodeThread;
-  }
-
-  virtual ReentrantMonitor& GetReentrantMonitor() MOZ_FINAL MOZ_OVERRIDE;
-
-  virtual bool IsShutdown() const MOZ_FINAL MOZ_OVERRIDE;
-
-  virtual bool OnStateMachineThread() const MOZ_FINAL MOZ_OVERRIDE;
-
-  virtual bool OnDecodeThread() const MOZ_FINAL MOZ_OVERRIDE;
-
-  virtual MediaResource* GetResource() const MOZ_FINAL MOZ_OVERRIDE;
-
-  virtual void NotifyBytesConsumed(int64_t aBytes) MOZ_FINAL MOZ_OVERRIDE;
-
-  virtual void NotifyDecodedFrames(uint32_t aParsed, uint32_t aDecoded) MOZ_FINAL MOZ_OVERRIDE;
-
-  virtual int64_t GetEndMediaTime() const MOZ_FINAL MOZ_OVERRIDE;
-
-  virtual int64_t GetMediaDuration() MOZ_FINAL MOZ_OVERRIDE;
-
-  virtual void SetMediaDuration(int64_t aDuration) MOZ_FINAL MOZ_OVERRIDE;
-
-  virtual void SetMediaSeekable(bool aMediaSeekable) MOZ_OVERRIDE;
-
-  virtual void SetTransportSeekable(bool aTransportSeekable) MOZ_FINAL MOZ_OVERRIDE;
-
-  virtual VideoFrameContainer* GetVideoFrameContainer() MOZ_FINAL MOZ_OVERRIDE;
-  virtual mozilla::layers::ImageContainer* GetImageContainer() MOZ_FINAL MOZ_OVERRIDE;
-
-  virtual bool IsTransportSeekable() MOZ_FINAL MOZ_OVERRIDE;
-
-  virtual bool IsMediaSeekable() MOZ_FINAL MOZ_OVERRIDE;
-
-  virtual void MetadataLoaded(int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags) MOZ_FINAL MOZ_OVERRIDE;
-  virtual void QueueMetadata(int64_t aTime, int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags) MOZ_FINAL MOZ_OVERRIDE;
-
-  virtual void SetMediaEndTime(int64_t aTime) MOZ_FINAL MOZ_OVERRIDE;
-
-  virtual void UpdatePlaybackPosition(int64_t aTime) MOZ_FINAL MOZ_OVERRIDE;
-
-  virtual void OnReadMetadataCompleted() MOZ_FINAL MOZ_OVERRIDE;
-
-  virtual MediaDecoderOwner* GetOwner() MOZ_FINAL MOZ_OVERRIDE;
-
-private:
-  // 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;
-};
-
-NS_IMPL_ISUPPORTS0(BufferDecoder)
-
-BufferDecoder::BufferDecoder(MediaResource* aResource)
-  : mReentrantMonitor("BufferDecoder")
-  , mResource(aResource)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_COUNT_CTOR(BufferDecoder);
-#ifdef PR_LOGGING
-  if (!gMediaDecoderLog) {
-    gMediaDecoderLog = PR_NewLogModule("MediaDecoder");
-  }
-#endif
-}
-
-BufferDecoder::~BufferDecoder()
-{
-  // The dtor may run on any thread, we cannot be sure.
-  MOZ_COUNT_DTOR(BufferDecoder);
-}
-
-ReentrantMonitor&
-BufferDecoder::GetReentrantMonitor()
-{
-  return mReentrantMonitor;
-}
-
-bool
-BufferDecoder::IsShutdown() const
-{
-  // BufferDecoder cannot be shut down.
-  return false;
-}
-
-bool
-BufferDecoder::OnStateMachineThread() const
-{
-  // BufferDecoder doesn't have the concept of a state machine.
-  return true;
-}
-
-bool
-BufferDecoder::OnDecodeThread() const
-{
-  MOZ_ASSERT(mDecodeThread, "Forgot to call BeginDecoding?");
-  return IsCurrentThread(mDecodeThread);
-}
-
-MediaResource*
-BufferDecoder::GetResource() const
-{
-  return mResource;
-}
-
-void
-BufferDecoder::NotifyBytesConsumed(int64_t aBytes)
-{
-  // ignore
-}
-
-void
-BufferDecoder::NotifyDecodedFrames(uint32_t aParsed, uint32_t aDecoded)
-{
-  // ignore
-}
-
-int64_t
-BufferDecoder::GetEndMediaTime() const
-{
-  // unknown
-  return -1;
-}
-
-int64_t
-BufferDecoder::GetMediaDuration()
-{
-  // unknown
-  return -1;
-}
-
-void
-BufferDecoder::SetMediaDuration(int64_t aDuration)
-{
-  // ignore
-}
-
-void
-BufferDecoder::SetMediaSeekable(bool aMediaSeekable)
-{
-  // ignore
-}
-
-void
-BufferDecoder::SetTransportSeekable(bool aTransportSeekable)
-{
-  // ignore
-}
-
-VideoFrameContainer*
-BufferDecoder::GetVideoFrameContainer()
-{
-  // no video frame
-  return nullptr;
-}
-
-layers::ImageContainer*
-BufferDecoder::GetImageContainer()
-{
-  // no image container
-  return nullptr;
-}
-
-bool
-BufferDecoder::IsTransportSeekable()
-{
-  return false;
-}
-
-bool
-BufferDecoder::IsMediaSeekable()
-{
-  return false;
-}
-
-void
-BufferDecoder::MetadataLoaded(int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags)
-{
-  // ignore
-}
-
-void
-BufferDecoder::QueueMetadata(int64_t aTime, int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags)
-{
-  // ignore
-}
-
-void
-BufferDecoder::SetMediaEndTime(int64_t aTime)
-{
-  // ignore
-}
-
-void
-BufferDecoder::UpdatePlaybackPosition(int64_t aTime)
-{
-  // ignore
-}
-
-void
-BufferDecoder::OnReadMetadataCompleted()
-{
-  // ignore
-}
-
-MediaDecoderOwner*
-BufferDecoder::GetOwner()
-{
-  // unknown
-  return nullptr;
-}
-
 class ReportResultTask : public nsRunnable
 {
 public:
   ReportResultTask(WebAudioDecodeJob& aDecodeJob,
                    WebAudioDecodeJob::ResultFn aFunction,
                    WebAudioDecodeJob::ErrorCode aErrorCode)
     : mDecodeJob(aDecodeJob)
     , mFunction(aFunction)