From ee5e1bf2da75bec4efca3c56ef698a1ac987043c Mon Sep 17 00:00:00 2001 From: Chris Double Date: Thu, 29 Jan 2015 15:35:55 +1300 Subject: [PATCH] Bug 1112424 Part 1 - Add moz specific methods to retrieve debug data to media object IDL - r=bz Bug 1112424 adds an about:media page that gives debug information about HTMLMediaElements and in particular MediaSource objects that are live inside tabs. This patch adds methods to the MediaSource and HTMLMediaElement object to return the debug data as a string that gets displayed directly in the about:media page, inside a
 element.

---
 dom/html/HTMLMediaElement.cpp         | 10 ++++++++++
 dom/html/HTMLMediaElement.h           |  1 +
 dom/media/mediasource/MediaSource.cpp |  6 ++++++
 dom/media/mediasource/MediaSource.h   |  4 ++++
 dom/webidl/HTMLMediaElement.webidl    |  2 ++
 dom/webidl/MediaSource.webidl         |  2 ++
 6 files changed, 25 insertions(+)

diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp
index ed16efa84a3..81e86992d81 100644
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -515,6 +515,16 @@ HTMLMediaElement::IsVideo()
   return false;
 }
 
+already_AddRefed
+HTMLMediaElement::GetMozMediaSourceObject() const
+{
+  nsRefPtr source;
+  if (IsMediaSourceURI(mLoadingSrc)) {
+    NS_GetSourceForMediaSourceURI(mLoadingSrc, getter_AddRefs(source));
+  }
+  return source.forget();
+}
+
 already_AddRefed
 HTMLMediaElement::GetMozSrcObject() const
 {
diff --git a/dom/html/HTMLMediaElement.h b/dom/html/HTMLMediaElement.h
index 2245ef350b1..d29fced6467 100644
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -533,6 +533,7 @@ public:
     mIsCasting = aShow;
   }
 
+  already_AddRefed GetMozMediaSourceObject() const;
   already_AddRefed GetMozSrcObject() const;
 
   void SetMozSrcObject(DOMMediaStream& aValue);
diff --git a/dom/media/mediasource/MediaSource.cpp b/dom/media/mediasource/MediaSource.cpp
index 96c123cf392..328f3dbad3c 100644
--- a/dom/media/mediasource/MediaSource.cpp
+++ b/dom/media/mediasource/MediaSource.cpp
@@ -540,6 +540,12 @@ MediaSource::Dump(const char* aPath)
 }
 #endif
 
+void
+MediaSource::GetMozDebugReaderData(nsAString& aString)
+{
+  mDecoder->GetMozDebugReaderData(aString);
+}
+
 nsPIDOMWindow*
 MediaSource::GetParentObject() const
 {
diff --git a/dom/media/mediasource/MediaSource.h b/dom/media/mediasource/MediaSource.h
index c6ddcaf7779..7eccca92734 100644
--- a/dom/media/mediasource/MediaSource.h
+++ b/dom/media/mediasource/MediaSource.h
@@ -114,6 +114,10 @@ public:
   void Dump(const char* aPath);
 #endif
 
+  // Returns a string describing the state of the MediaSource internal
+  // buffered data. Used for debugging purposes.
+  void GetMozDebugReaderData(nsAString& aString);
+
 private:
   // MediaSourceDecoder uses DurationChange to set the duration
   // without hitting the checks in SetDuration.
diff --git a/dom/webidl/HTMLMediaElement.webidl b/dom/webidl/HTMLMediaElement.webidl
index 00ef15ca31d..2eb4096740a 100644
--- a/dom/webidl/HTMLMediaElement.webidl
+++ b/dom/webidl/HTMLMediaElement.webidl
@@ -102,6 +102,8 @@ interface HTMLMediaElement : HTMLElement {
 
 // Mozilla extensions:
 partial interface HTMLMediaElement {
+  [ChromeOnly]
+  readonly attribute MediaSource? mozMediaSourceObject;
   attribute MediaStream? mozSrcObject;
   attribute boolean mozPreservesPitch;
   readonly attribute boolean mozAutoplayEnabled;
diff --git a/dom/webidl/MediaSource.webidl b/dom/webidl/MediaSource.webidl
index ca822f7886c..562f8ebb8b7 100644
--- a/dom/webidl/MediaSource.webidl
+++ b/dom/webidl/MediaSource.webidl
@@ -35,4 +35,6 @@ interface MediaSource : EventTarget {
   [Throws]
   void endOfStream(optional MediaSourceEndOfStreamError error);
   static boolean isTypeSupported(DOMString type);
+  [ChromeOnly]
+  readonly attribute DOMString mozDebugReaderData;
 };