From 6b2b2ee5c86277cb16192d19eb00ea7dcdb1a6a7 Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Tue, 25 Sep 2012 15:25:43 +1200 Subject: [PATCH] Bug 792675. Part 7: Add support for MediaStream URIs to media elements. r=cpearce --HG-- extra : rebase_source : 1c27fa7038dcdd3ab4e7eac6219b2ed5a6affa4a --- .../html/content/public/nsHTMLMediaElement.h | 4 +- .../html/content/src/nsHTMLMediaElement.cpp | 25 ++++++-- ...reams_element_capture_createObjectURL.html | 62 +++++++++++++++++++ 3 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 content/media/test/test_streams_element_capture_createObjectURL.html diff --git a/content/html/content/public/nsHTMLMediaElement.h b/content/html/content/public/nsHTMLMediaElement.h index 028be6bf1b3..7b721cfe1a0 100644 --- a/content/html/content/public/nsHTMLMediaElement.h +++ b/content/html/content/public/nsHTMLMediaElement.h @@ -429,9 +429,9 @@ protected: void SetPlayedOrSeeked(bool aValue); /** - * Initialize the media element for playback of mSrcAttrStream + * Initialize the media element for playback of aStream */ - void SetupSrcMediaStreamPlayback(); + void SetupSrcMediaStreamPlayback(nsDOMMediaStream* aStream); /** * Stop playback on mSrcStream. */ diff --git a/content/html/content/src/nsHTMLMediaElement.cpp b/content/html/content/src/nsHTMLMediaElement.cpp index a8db13231c8..20a31ad785a 100644 --- a/content/html/content/src/nsHTMLMediaElement.cpp +++ b/content/html/content/src/nsHTMLMediaElement.cpp @@ -64,6 +64,7 @@ #include "MediaStreamGraph.h" #include "nsDOMMediaStream.h" #include "nsIScriptError.h" +#include "nsHostObjectProtocolHandler.h" #include "nsCSSParser.h" #include "nsIMediaList.h" @@ -758,7 +759,7 @@ void nsHTMLMediaElement::SelectResource() // If we have a 'src' attribute, use that exclusively. nsAutoString src; if (mSrcAttrStream) { - SetupSrcMediaStreamPlayback(); + SetupSrcMediaStreamPlayback(mSrcAttrStream); } else if (GetAttr(kNameSpaceID_None, nsGkAtoms::src, src)) { nsCOMPtr uri; nsresult rv = NewURIFromString(src, getter_AddRefs(uri)); @@ -766,6 +767,7 @@ void nsHTMLMediaElement::SelectResource() LOG(PR_LOG_DEBUG, ("%p Trying load from src=%s", this, NS_ConvertUTF16toUTF8(src).get())); NS_ASSERTION(!mIsLoadingFromSourceChildren, "Should think we're not loading from source children by default"); + mLoadingSrc = uri; if (mPreloadAction == nsHTMLMediaElement::PRELOAD_NONE) { // preload:none media, suspend the load here before we make any @@ -1035,7 +1037,7 @@ nsresult nsHTMLMediaElement::LoadResource() mCORSMode = AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin)); nsHTMLMediaElement* other = LookupMediaElementURITable(mLoadingSrc); - if (other) { + if (other && other->mDecoder) { // Clone it. nsresult rv = InitializeDecoderAsClone(other->mDecoder); // Get the mimetype from the element we clone, since we will not get it via @@ -1062,6 +1064,21 @@ nsresult nsHTMLMediaElement::LoadResource() return NS_ERROR_FAILURE; } + if (IsMediaStreamURI(mLoadingSrc)) { + nsCOMPtr stream; + rv = NS_GetStreamForMediaStreamURI(mLoadingSrc, getter_AddRefs(stream)); + if (NS_FAILED(rv)) { + nsCString specUTF8; + mLoadingSrc->GetSpec(specUTF8); + NS_ConvertUTF8toUTF16 spec(specUTF8); + const PRUnichar* params[] = { spec.get() }; + ReportLoadError("MediaLoadInvalidURI", params, ArrayLength(params)); + return rv; + } + SetupSrcMediaStreamPlayback(static_cast(stream.get())); + return NS_OK; + } + nsCOMPtr loadGroup = GetDocumentLoadGroup(); // check for a Content Security Policy to pass down to the channel @@ -2765,11 +2782,11 @@ private: bool mDidHaveCurrentData; }; -void nsHTMLMediaElement::SetupSrcMediaStreamPlayback() +void nsHTMLMediaElement::SetupSrcMediaStreamPlayback(nsDOMMediaStream* aStream) { NS_ASSERTION(!mSrcStream && !mSrcStreamListener, "Should have been ended already"); - mSrcStream = mSrcAttrStream; + mSrcStream = aStream; // XXX if we ever support capturing the output of a media element which is // playing a stream, we'll need to add a CombineWithPrincipal call here. mSrcStreamListener = new StreamListener(this); diff --git a/content/media/test/test_streams_element_capture_createObjectURL.html b/content/media/test/test_streams_element_capture_createObjectURL.html new file mode 100644 index 00000000000..d33a8f080ea --- /dev/null +++ b/content/media/test/test_streams_element_capture_createObjectURL.html @@ -0,0 +1,62 @@ + + + + Test that a MediaStream captured from one element plays back in another + + + + + +
+
+
+ +