Bug 911059 - Move WebAudio's BufferDecoder to its own file so it can be shared with MSE. r=cpearce
authorMatthew Gregan <kinetik@flim.org>
Wed, 04 Sep 2013 15:08:11 +1200
changeset 145409 d5b67c93e1a0
parent 145408 122fae1d279e
child 145410 cc6f66e761d8
push id25211
push useremorley@mozilla.com
push dateWed, 04 Sep 2013 11:55:04 +0000
treeherdermozilla-central@44b0383e1063 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs911059
milestone26.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 911059 - Move WebAudio's BufferDecoder to its own file so it can be shared with MSE. r=cpearce
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,192 @@
+/* -*- 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::UpdateMediaDuration(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,88 @@
+/* -*- 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 UpdateMediaDuration(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
@@ -55,16 +55,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',
@@ -100,16 +101,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
@@ -1,18 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* 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 "mozilla/dom/AudioContextBinding.h"
 #include <speex/speex_resampler.h>
 #include "nsXPCOMCIDInternal.h"
 #include "nsComponentManagerUtils.h"
 #include "MediaDecoderReader.h"
 #include "BufferMediaResource.h"
 #include "DecoderTraits.h"
 #include "AudioContext.h"
@@ -46,261 +44,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 UpdateMediaDuration(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::UpdateMediaDuration(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)