Bug 881512 - Hide MediaSourceResource implementation details from HTMLMediaElement. r=cajbir
authorMatthew Gregan <kinetik@flim.org>
Mon, 14 Apr 2014 23:24:00 +1200
changeset 180737 f8ece490919dd18b8f736e910d771ec3f7573fe3
parent 180736 d978fe16633a715172f74b08a0feb8f522e83c2b
child 180738 18754facd070edefc3bee658e8a690136e448357
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewerscajbir
bugs881512
milestone31.0a1
Bug 881512 - Hide MediaSourceResource implementation details from HTMLMediaElement. r=cajbir
content/html/content/src/HTMLMediaElement.cpp
content/media/mediasource/MediaSourceDecoder.cpp
content/media/mediasource/MediaSourceDecoder.h
content/media/mediasource/MediaSourceResource.h
--- a/content/html/content/src/HTMLMediaElement.cpp
+++ b/content/html/content/src/HTMLMediaElement.cpp
@@ -1127,17 +1127,17 @@ nsresult HTMLMediaElement::LoadResource(
     nsRefPtr<MediaSourceDecoder> decoder = new MediaSourceDecoder(this);
     if (!source->Attach(decoder)) {
       // TODO: Handle failure: run "If the media data cannot be fetched at
       // all, due to network errors, causing the user agent to give up
       // trying to fetch the resource" section of resource fetch algorithm.
       return NS_ERROR_FAILURE;
     }
     mMediaSource = source.forget();
-    nsRefPtr<MediaResource> resource = new MediaSourceResource();
+    nsRefPtr<MediaResource> resource = MediaSourceDecoder::CreateResource();
     return FinishDecoderSetup(decoder, resource, nullptr, nullptr);
   }
 
   nsCOMPtr<nsILoadGroup> loadGroup = GetDocumentLoadGroup();
 
   // check for a Content Security Policy to pass down to the channel
   // created to load the media content
   nsCOMPtr<nsIChannelPolicy> channelPolicy;
--- a/content/media/mediasource/MediaSourceDecoder.cpp
+++ b/content/media/mediasource/MediaSourceDecoder.cpp
@@ -1,14 +1,14 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* -*- 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 "MediaSourceResource.h"
 #include "MediaSourceDecoder.h"
 
 #include "AbstractMediaDecoder.h"
 #include "MediaDecoderReader.h"
 #include "MediaDecoderStateMachine.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/FloatingPoint.h"
 #include "mozilla/dom/HTMLMediaElement.h"
@@ -173,16 +173,23 @@ MediaSourceDecoder::GetSeekable(dom::Tim
     GetBuffered(bufferedRanges);
     aSeekable->Add(0, bufferedRanges->GetFinalEndTime());
   } else {
     aSeekable->Add(0, duration);
   }
   return NS_OK;
 }
 
+/*static*/
+already_AddRefed<MediaResource>
+MediaSourceDecoder::CreateResource()
+{
+  return nsRefPtr<MediaResource>(new MediaSourceResource()).forget();
+}
+
 void
 MediaSourceDecoder::AttachMediaSource(dom::MediaSource* aMediaSource)
 {
   MOZ_ASSERT(!mMediaSource && !mDecoderStateMachine);
   mMediaSource = aMediaSource;
 }
 
 void
--- a/content/media/mediasource/MediaSourceDecoder.h
+++ b/content/media/mediasource/MediaSourceDecoder.h
@@ -4,32 +4,32 @@
  * 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_MEDIASOURCEDECODER_H_
 #define MOZILLA_MEDIASOURCEDECODER_H_
 
 #include "MediaCache.h"
 #include "MediaDecoder.h"
-#include "MediaResource.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/ReentrantMonitor.h"
 #include "nsCOMPtr.h"
 #include "nsError.h"
 #include "nsStringGlue.h"
 #include "nsTArray.h"
 
-class nsIPrincipal;
 class nsIStreamListener;
 
 namespace mozilla {
 
+class MediaResource;
 class MediaDecoderReader;
 class MediaDecoderStateMachine;
 class SubBufferDecoder;
+class MediaSourceReader;
 
 namespace dom {
 
 class HTMLMediaElement;
 class MediaSource;
 
 } // namespace dom
 
@@ -38,16 +38,18 @@ class MediaSourceDecoder : public MediaD
 public:
   MediaSourceDecoder(dom::HTMLMediaElement* aElement);
 
   virtual MediaDecoder* Clone() MOZ_OVERRIDE;
   virtual MediaDecoderStateMachine* CreateStateMachine() MOZ_OVERRIDE;
   virtual nsresult Load(nsIStreamListener**, MediaDecoder*) MOZ_OVERRIDE;
   virtual nsresult GetSeekable(dom::TimeRanges* aSeekable) MOZ_OVERRIDE;
 
+  static already_AddRefed<MediaResource> CreateResource();
+
   void AttachMediaSource(dom::MediaSource* aMediaSource);
   void DetachMediaSource();
 
   SubBufferDecoder* CreateSubDecoder(const nsACString& aType);
 
   const nsTArray<MediaDecoderReader*>& GetReaders()
   {
     ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
@@ -88,70 +90,11 @@ private:
 
   nsTArray<nsRefPtr<SubBufferDecoder> > mDecoders;
   nsTArray<MediaDecoderReader*> mReaders; // Readers owned by Decoders.
 
   MediaDecoderReader* mVideoReader;
   MediaDecoderReader* mAudioReader;
 };
 
-class MediaSourceResource MOZ_FINAL : public MediaResource
-{
-public:
-  MediaSourceResource() {}
-
-  virtual nsresult Close() MOZ_OVERRIDE { return NS_OK; }
-  virtual void Suspend(bool aCloseImmediately) MOZ_OVERRIDE {}
-  virtual void Resume() MOZ_OVERRIDE {}
-  virtual already_AddRefed<nsIPrincipal> GetCurrentPrincipal() MOZ_OVERRIDE { return nullptr; }
-  virtual bool CanClone() MOZ_OVERRIDE { return false; }
-  virtual already_AddRefed<MediaResource> CloneData(MediaDecoder* aDecoder) MOZ_OVERRIDE { return nullptr; }
-  virtual void SetReadMode(MediaCacheStream::ReadMode aMode) MOZ_OVERRIDE {}
-  virtual void SetPlaybackRate(uint32_t aBytesPerSecond) MOZ_OVERRIDE  {}
-  virtual nsresult Read(char* aBuffer, uint32_t aCount, uint32_t* aBytes) MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
-  virtual nsresult ReadAt(int64_t aOffset, char* aBuffer, uint32_t aCount, uint32_t* aBytes) MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
-  virtual nsresult Seek(int32_t aWhence, int64_t aOffset) MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
-  virtual void StartSeekingForMetadata() MOZ_OVERRIDE {}
-  virtual void EndSeekingForMetadata() MOZ_OVERRIDE {}
-  virtual int64_t Tell() MOZ_OVERRIDE { return -1; }
-  virtual void Pin() MOZ_OVERRIDE {}
-  virtual void Unpin() MOZ_OVERRIDE {}
-  virtual double GetDownloadRate(bool* aIsReliable) MOZ_OVERRIDE { return 0; }
-  virtual int64_t GetLength() MOZ_OVERRIDE { return -1; }
-  virtual int64_t GetNextCachedData(int64_t aOffset) MOZ_OVERRIDE { return aOffset; }
-  virtual int64_t GetCachedDataEnd(int64_t aOffset) MOZ_OVERRIDE { return GetLength(); }
-  virtual bool IsDataCachedToEndOfResource(int64_t aOffset) MOZ_OVERRIDE { return true; }
-  virtual bool IsSuspendedByCache() MOZ_OVERRIDE { return false; }
-  virtual bool IsSuspended() MOZ_OVERRIDE { return false; }
-  virtual nsresult ReadFromCache(char* aBuffer, int64_t aOffset, uint32_t aCount) MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
-  virtual nsresult Open(nsIStreamListener** aStreamListener) MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
-
-  virtual nsresult GetCachedRanges(nsTArray<MediaByteRange>& aRanges) MOZ_OVERRIDE
-  {
-    aRanges.AppendElement(MediaByteRange(0, GetLength()));
-    return NS_OK;
-  }
-
-  virtual bool IsTransportSeekable() MOZ_OVERRIDE { return true; }
-  virtual const nsCString& GetContentType() const MOZ_OVERRIDE { return mType; }
-
-  virtual size_t SizeOfExcludingThis(
-                      MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE
-  {
-    size_t size = MediaResource::SizeOfExcludingThis(aMallocSizeOf);
-    size += mType.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
-
-    return size;
-  }
-
-  virtual size_t SizeOfIncludingThis(
-                      MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE
-  {
-    return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
-  }
-
-private:
-  const nsAutoCString mType;
-};
-
 } // namespace mozilla
 
 #endif /* MOZILLA_MEDIASOURCEDECODER_H_ */
new file mode 100644
--- /dev/null
+++ b/content/media/mediasource/MediaSourceResource.h
@@ -0,0 +1,73 @@
+/* -*- 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 MOZILLA_MEDIASOURCERESOURCE_H_
+#define MOZILLA_MEDIASOURCERESOURCE_H_
+
+#include "MediaResource.h"
+
+namespace mozilla {
+
+class MediaSourceResource MOZ_FINAL : public MediaResource
+{
+public:
+  MediaSourceResource() {}
+
+  virtual nsresult Close() MOZ_OVERRIDE { return NS_OK; }
+  virtual void Suspend(bool aCloseImmediately) MOZ_OVERRIDE {}
+  virtual void Resume() MOZ_OVERRIDE {}
+  virtual already_AddRefed<nsIPrincipal> GetCurrentPrincipal() MOZ_OVERRIDE { return nullptr; }
+  virtual bool CanClone() MOZ_OVERRIDE { return false; }
+  virtual already_AddRefed<MediaResource> CloneData(MediaDecoder* aDecoder) MOZ_OVERRIDE { return nullptr; }
+  virtual void SetReadMode(MediaCacheStream::ReadMode aMode) MOZ_OVERRIDE {}
+  virtual void SetPlaybackRate(uint32_t aBytesPerSecond) MOZ_OVERRIDE  {}
+  virtual nsresult Read(char* aBuffer, uint32_t aCount, uint32_t* aBytes) MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
+  virtual nsresult ReadAt(int64_t aOffset, char* aBuffer, uint32_t aCount, uint32_t* aBytes) MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
+  virtual nsresult Seek(int32_t aWhence, int64_t aOffset) MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
+  virtual void StartSeekingForMetadata() MOZ_OVERRIDE {}
+  virtual void EndSeekingForMetadata() MOZ_OVERRIDE {}
+  virtual int64_t Tell() MOZ_OVERRIDE { return -1; }
+  virtual void Pin() MOZ_OVERRIDE {}
+  virtual void Unpin() MOZ_OVERRIDE {}
+  virtual double GetDownloadRate(bool* aIsReliable) MOZ_OVERRIDE { return 0; }
+  virtual int64_t GetLength() MOZ_OVERRIDE { return -1; }
+  virtual int64_t GetNextCachedData(int64_t aOffset) MOZ_OVERRIDE { return aOffset; }
+  virtual int64_t GetCachedDataEnd(int64_t aOffset) MOZ_OVERRIDE { return GetLength(); }
+  virtual bool IsDataCachedToEndOfResource(int64_t aOffset) MOZ_OVERRIDE { return true; }
+  virtual bool IsSuspendedByCache() MOZ_OVERRIDE { return false; }
+  virtual bool IsSuspended() MOZ_OVERRIDE { return false; }
+  virtual nsresult ReadFromCache(char* aBuffer, int64_t aOffset, uint32_t aCount) MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
+  virtual nsresult Open(nsIStreamListener** aStreamListener) MOZ_OVERRIDE { return NS_ERROR_FAILURE; }
+
+  virtual nsresult GetCachedRanges(nsTArray<MediaByteRange>& aRanges) MOZ_OVERRIDE
+  {
+    aRanges.AppendElement(MediaByteRange(0, GetLength()));
+    return NS_OK;
+  }
+
+  virtual bool IsTransportSeekable() MOZ_OVERRIDE { return true; }
+  virtual const nsCString& GetContentType() const MOZ_OVERRIDE { return mType; }
+
+private:
+  virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE
+  {
+    size_t size = MediaResource::SizeOfExcludingThis(aMallocSizeOf);
+    size += mType.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
+
+    return size;
+  }
+
+  virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE
+  {
+    return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
+  }
+
+  const nsAutoCString mType;
+};
+
+} // namespace mozilla
+
+#endif /* MOZILLA_MEDIASOURCERESOURCE_H_ */