mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-26 23:23:33 +00:00
Bug 837034. Part 2: Convert DOMMediaStream to use WebIDL. r=peterv,jesup
--HG-- rename : content/media/nsDOMMediaStream.cpp => content/media/DOMMediaStream.cpp rename : content/media/nsDOMMediaStream.h => content/media/DOMMediaStream.h extra : rebase_source : 483fca748444db20ed0d35cb586485f277e1808c
This commit is contained in:
parent
a019386f6d
commit
2c25988734
@ -1603,8 +1603,13 @@ NS_IMETHODIMP nsHTMLMediaElement::SetMuted(bool aMuted)
|
||||
already_AddRefed<DOMMediaStream>
|
||||
nsHTMLMediaElement::CaptureStreamInternal(bool aFinishWhenEnded)
|
||||
{
|
||||
nsIDOMWindow* window = OwnerDoc()->GetInnerWindow();
|
||||
if (!window) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
OutputMediaStream* out = mOutputStreams.AppendElement();
|
||||
out->mStream = DOMMediaStream::CreateTrackUnionStream();
|
||||
out->mStream = DOMMediaStream::CreateTrackUnionStream(window);
|
||||
nsRefPtr<nsIPrincipal> principal = GetCurrentPrincipal();
|
||||
out->mStream->CombineWithPrincipal(principal);
|
||||
out->mFinishWhenEnded = aFinishWhenEnded;
|
||||
@ -1626,12 +1631,18 @@ nsHTMLMediaElement::CaptureStreamInternal(bool aFinishWhenEnded)
|
||||
NS_IMETHODIMP nsHTMLMediaElement::MozCaptureStream(nsIDOMMediaStream** aStream)
|
||||
{
|
||||
*aStream = CaptureStreamInternal(false).get();
|
||||
if (!*aStream) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLMediaElement::MozCaptureStreamUntilEnded(nsIDOMMediaStream** aStream)
|
||||
{
|
||||
*aStream = CaptureStreamInternal(true).get();
|
||||
if (!*aStream) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -6,46 +6,29 @@
|
||||
#include "DOMMediaStream.h"
|
||||
#include "nsDOMClassInfoID.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "mozilla/dom/MediaStreamBinding.h"
|
||||
#include "mozilla/dom/LocalMediaStreamBinding.h"
|
||||
#include "MediaStreamGraph.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
DOMCI_DATA(MediaStream, DOMMediaStream)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMMediaStream)
|
||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMMediaStream)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MediaStream)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMMediaStream)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMMediaStream)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(DOMMediaStream)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(DOMMediaStream)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
// LocalMediaStream currently is the same C++ class as MediaStream;
|
||||
// they may eventually split
|
||||
DOMCI_DATA(LocalMediaStream, DOMLocalMediaStream)
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(DOMMediaStream, mWindow)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMLocalMediaStream)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMLocalMediaStream)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMMediaStream, DOMMediaStream)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMLocalMediaStream)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(LocalMediaStream)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMLocalMediaStream)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMLocalMediaStream)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(DOMLocalMediaStream)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(DOMLocalMediaStream)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
NS_INTERFACE_MAP_END_INHERITING(DOMMediaStream)
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(DOMLocalMediaStream, DOMMediaStream)
|
||||
NS_IMPL_RELEASE_INHERITED(DOMLocalMediaStream, DOMMediaStream)
|
||||
NS_IMPL_CYCLE_COLLECTION_INHERITED_0(DOMLocalMediaStream, DOMMediaStream)
|
||||
|
||||
DOMMediaStream::~DOMMediaStream()
|
||||
{
|
||||
@ -54,11 +37,62 @@ DOMMediaStream::~DOMMediaStream()
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DOMMediaStream::GetCurrentTime(double *aCurrentTime)
|
||||
JSObject*
|
||||
DOMMediaStream::WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap)
|
||||
{
|
||||
*aCurrentTime = mStream ? MediaTimeToSeconds(mStream->GetCurrentTime()) : 0.0;
|
||||
return NS_OK;
|
||||
return dom::MediaStreamBinding::Wrap(aCx, aScope, this, aTriedToWrap);
|
||||
}
|
||||
|
||||
double
|
||||
DOMMediaStream::CurrentTime()
|
||||
{
|
||||
return mStream ? MediaTimeToSeconds(mStream->GetCurrentTime()) : 0.0;
|
||||
}
|
||||
|
||||
bool
|
||||
DOMMediaStream::IsFinished()
|
||||
{
|
||||
return !mStream || mStream->IsFinished();
|
||||
}
|
||||
|
||||
void
|
||||
DOMMediaStream::InitSourceStream(nsIDOMWindow* aWindow, uint32_t aHintContents)
|
||||
{
|
||||
mWindow = aWindow;
|
||||
SetHintContents(aHintContents);
|
||||
MediaStreamGraph* gm = MediaStreamGraph::GetInstance();
|
||||
mStream = gm->CreateSourceStream(this);
|
||||
}
|
||||
|
||||
void
|
||||
DOMMediaStream::InitTrackUnionStream(nsIDOMWindow* aWindow, uint32_t aHintContents)
|
||||
{
|
||||
mWindow = aWindow;
|
||||
SetHintContents(aHintContents);
|
||||
MediaStreamGraph* gm = MediaStreamGraph::GetInstance();
|
||||
mStream = gm->CreateTrackUnionStream(this);
|
||||
}
|
||||
|
||||
already_AddRefed<DOMMediaStream>
|
||||
DOMMediaStream::CreateSourceStream(nsIDOMWindow* aWindow, uint32_t aHintContents)
|
||||
{
|
||||
nsRefPtr<DOMMediaStream> stream = new DOMMediaStream();
|
||||
stream->InitSourceStream(aWindow, aHintContents);
|
||||
return stream.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<DOMMediaStream>
|
||||
DOMMediaStream::CreateTrackUnionStream(nsIDOMWindow* aWindow, uint32_t aHintContents)
|
||||
{
|
||||
nsRefPtr<DOMMediaStream> stream = new DOMMediaStream();
|
||||
stream->InitTrackUnionStream(aWindow, aHintContents);
|
||||
return stream.forget();
|
||||
}
|
||||
|
||||
bool
|
||||
DOMMediaStream::CombineWithPrincipal(nsIPrincipal* aPrincipal)
|
||||
{
|
||||
return nsContentUtils::CombineResourcePrincipals(&mPrincipal, aPrincipal);
|
||||
}
|
||||
|
||||
DOMLocalMediaStream::~DOMLocalMediaStream()
|
||||
@ -69,49 +103,32 @@ DOMLocalMediaStream::~DOMLocalMediaStream()
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
JSObject*
|
||||
DOMLocalMediaStream::WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap)
|
||||
{
|
||||
return dom::LocalMediaStreamBinding::Wrap(aCx, aScope, this, aTriedToWrap);
|
||||
}
|
||||
|
||||
void
|
||||
DOMLocalMediaStream::Stop()
|
||||
{
|
||||
if (mStream && mStream->AsSourceStream()) {
|
||||
mStream->AsSourceStream()->EndAllTrackAndFinish();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<DOMMediaStream>
|
||||
DOMMediaStream::CreateSourceStream(uint32_t aHintContents)
|
||||
already_AddRefed<DOMLocalMediaStream>
|
||||
DOMLocalMediaStream::CreateSourceStream(nsIDOMWindow* aWindow, uint32_t aHintContents)
|
||||
{
|
||||
nsRefPtr<DOMMediaStream> stream = new DOMMediaStream();
|
||||
stream->InitSourceStream(aHintContents);
|
||||
nsRefPtr<DOMLocalMediaStream> stream = new DOMLocalMediaStream();
|
||||
stream->InitSourceStream(aWindow, aHintContents);
|
||||
return stream.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<DOMLocalMediaStream>
|
||||
DOMLocalMediaStream::CreateSourceStream(uint32_t aHintContents)
|
||||
DOMLocalMediaStream::CreateTrackUnionStream(nsIDOMWindow* aWindow, uint32_t aHintContents)
|
||||
{
|
||||
nsRefPtr<DOMLocalMediaStream> stream = new DOMLocalMediaStream();
|
||||
stream->InitSourceStream(aHintContents);
|
||||
stream->InitTrackUnionStream(aWindow, aHintContents);
|
||||
return stream.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<DOMMediaStream>
|
||||
DOMMediaStream::CreateTrackUnionStream(uint32_t aHintContents)
|
||||
{
|
||||
nsRefPtr<DOMMediaStream> stream = new DOMMediaStream();
|
||||
stream->InitTrackUnionStream(aHintContents);
|
||||
return stream.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<DOMLocalMediaStream>
|
||||
DOMLocalMediaStream::CreateTrackUnionStream(uint32_t aHintContents)
|
||||
{
|
||||
nsRefPtr<DOMLocalMediaStream> stream = new DOMLocalMediaStream();
|
||||
stream->InitTrackUnionStream(aHintContents);
|
||||
return stream.forget();
|
||||
}
|
||||
|
||||
bool
|
||||
DOMMediaStream::CombineWithPrincipal(nsIPrincipal* aPrincipal)
|
||||
{
|
||||
return nsContentUtils::CombineResourcePrincipals(&mPrincipal, aPrincipal);
|
||||
}
|
||||
|
@ -7,9 +7,10 @@
|
||||
#define NSDOMMEDIASTREAM_H_
|
||||
|
||||
#include "nsIDOMMediaStream.h"
|
||||
#include "MediaStreamGraph.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsIPrincipal.h"
|
||||
#include "nsWrapperCache.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
|
||||
class nsXPCClassInfo;
|
||||
|
||||
@ -19,27 +20,42 @@ class nsXPCClassInfo;
|
||||
#ifdef GetCurrentTime
|
||||
#undef GetCurrentTime
|
||||
#endif
|
||||
// X11 has a #define for CurrentTime. Unbelievable :-(.
|
||||
#ifdef CurrentTime
|
||||
#undef CurrentTime
|
||||
#endif
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class MediaStream;
|
||||
|
||||
/**
|
||||
* DOM wrapper for MediaStreams.
|
||||
*/
|
||||
class DOMMediaStream : public nsIDOMMediaStream
|
||||
class DOMMediaStream : public nsIDOMMediaStream,
|
||||
public nsWrapperCache
|
||||
{
|
||||
friend class DOMLocalMediaStream;
|
||||
|
||||
public:
|
||||
DOMMediaStream() : mStream(nullptr), mHintContents(0) {}
|
||||
DOMMediaStream() : mStream(nullptr), mHintContents(0)
|
||||
{
|
||||
SetIsDOMBinding();
|
||||
}
|
||||
virtual ~DOMMediaStream();
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS(DOMMediaStream)
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMMediaStream)
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
|
||||
NS_DECL_NSIDOMMEDIASTREAM
|
||||
nsIDOMWindow* GetParentObject() const
|
||||
{
|
||||
return mWindow;
|
||||
}
|
||||
virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap);
|
||||
|
||||
double CurrentTime();
|
||||
MediaStream* GetStream() { return mStream; }
|
||||
bool IsFinished() { return !mStream || mStream->IsFinished(); }
|
||||
bool IsFinished();
|
||||
/**
|
||||
* Returns a principal indicating who may access this stream. The stream contents
|
||||
* can only be accessed by principals subsuming this principal.
|
||||
@ -57,7 +73,8 @@ public:
|
||||
/**
|
||||
* Create an nsDOMMediaStream whose underlying stream is a SourceMediaStream.
|
||||
*/
|
||||
static already_AddRefed<DOMMediaStream> CreateSourceStream(uint32_t aHintContents);
|
||||
static already_AddRefed<DOMMediaStream>
|
||||
CreateSourceStream(nsIDOMWindow* aWindow, uint32_t aHintContents);
|
||||
|
||||
// Hints to tell the SDP generator about whether this
|
||||
// MediaStream probably has audio and/or video
|
||||
@ -71,21 +88,15 @@ public:
|
||||
/**
|
||||
* Create an nsDOMMediaStream whose underlying stream is a TrackUnionStream.
|
||||
*/
|
||||
static already_AddRefed<DOMMediaStream> CreateTrackUnionStream(uint32_t aHintContents = 0);
|
||||
static already_AddRefed<DOMMediaStream>
|
||||
CreateTrackUnionStream(nsIDOMWindow* aWindow, uint32_t aHintContents = 0);
|
||||
|
||||
protected:
|
||||
void InitSourceStream(uint32_t aHintContents)
|
||||
{
|
||||
SetHintContents(aHintContents);
|
||||
MediaStreamGraph* gm = MediaStreamGraph::GetInstance();
|
||||
mStream = gm->CreateSourceStream(this);
|
||||
}
|
||||
void InitTrackUnionStream(uint32_t aHintContents)
|
||||
{
|
||||
SetHintContents(aHintContents);
|
||||
MediaStreamGraph* gm = MediaStreamGraph::GetInstance();
|
||||
mStream = gm->CreateTrackUnionStream(this);
|
||||
}
|
||||
void InitSourceStream(nsIDOMWindow* aWindow, uint32_t aHintContents);
|
||||
void InitTrackUnionStream(nsIDOMWindow* aWindow, uint32_t aHintContents);
|
||||
|
||||
// We need this to track our parent object.
|
||||
nsCOMPtr<nsIDOMWindow> mWindow;
|
||||
|
||||
// MediaStream is owned by the graph, but we tell it when to die, and it won't
|
||||
// die until we let it.
|
||||
@ -108,19 +119,22 @@ public:
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DOMLocalMediaStream, DOMMediaStream)
|
||||
NS_DECL_NSIDOMLOCALMEDIASTREAM
|
||||
|
||||
NS_FORWARD_NSIDOMMEDIASTREAM(DOMMediaStream::)
|
||||
virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap);
|
||||
|
||||
virtual void Stop();
|
||||
|
||||
/**
|
||||
* Create an nsDOMLocalMediaStream whose underlying stream is a SourceMediaStream.
|
||||
*/
|
||||
static already_AddRefed<DOMLocalMediaStream> CreateSourceStream(uint32_t aHintContents);
|
||||
static already_AddRefed<DOMLocalMediaStream>
|
||||
CreateSourceStream(nsIDOMWindow* aWindow, uint32_t aHintContents);
|
||||
|
||||
/**
|
||||
* Create an nsDOMLocalMediaStream whose underlying stream is a TrackUnionStream.
|
||||
*/
|
||||
static already_AddRefed<DOMLocalMediaStream> CreateTrackUnionStream(uint32_t aHintContents = 0);
|
||||
static already_AddRefed<DOMLocalMediaStream>
|
||||
CreateTrackUnionStream(nsIDOMWindow* aWindow, uint32_t aHintContents = 0);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "nsGlobalWindow.h"
|
||||
#include "nsIDOMFile.h"
|
||||
#include "nsIDOMMediaStream.h"
|
||||
#include "DOMMediaStream.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIPrincipal.h"
|
||||
#include "nsContentUtils.h"
|
||||
@ -28,12 +28,12 @@ URL::CreateObjectURL(const GlobalObject& aGlobal, nsIDOMBlob* aBlob,
|
||||
}
|
||||
|
||||
void
|
||||
URL::CreateObjectURL(const GlobalObject& aGlobal, nsIDOMMediaStream* aStream,
|
||||
URL::CreateObjectURL(const GlobalObject& aGlobal, DOMMediaStream& aStream,
|
||||
const mozilla::dom::objectURLOptions& aOptions,
|
||||
nsString& aResult,
|
||||
ErrorResult& aError)
|
||||
{
|
||||
CreateObjectURLInternal(aGlobal.Get(), aStream,
|
||||
CreateObjectURLInternal(aGlobal.Get(), &aStream,
|
||||
NS_LITERAL_CSTRING(MEDIASTREAMURI_SCHEME), aOptions,
|
||||
aResult, aError);
|
||||
}
|
||||
|
@ -9,9 +9,11 @@
|
||||
#include "mozilla/dom/URLBinding.h"
|
||||
|
||||
class nsIDOMBlob;
|
||||
class nsIDOMMediaStream;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class DOMMediaStream;
|
||||
|
||||
namespace dom {
|
||||
|
||||
class URL MOZ_FINAL
|
||||
@ -23,7 +25,7 @@ public:
|
||||
nsString& aResult,
|
||||
ErrorResult& aError);
|
||||
static void CreateObjectURL(const GlobalObject& aGlobal,
|
||||
nsIDOMMediaStream* aStream,
|
||||
DOMMediaStream& aStream,
|
||||
const mozilla::dom::objectURLOptions& aOptions,
|
||||
nsString& aResult,
|
||||
mozilla::ErrorResult& aError);
|
||||
|
@ -264,9 +264,6 @@
|
||||
#include "nsIDOMHTMLSourceElement.h"
|
||||
#include "nsIDOMHTMLVideoElement.h"
|
||||
#include "nsIDOMHTMLAudioElement.h"
|
||||
#if defined (MOZ_MEDIA)
|
||||
#include "nsIDOMMediaStream.h"
|
||||
#endif
|
||||
#include "nsIDOMProgressEvent.h"
|
||||
#include "nsIDOMCSSCharsetRule.h"
|
||||
#include "nsIDOMCSSImportRule.h"
|
||||
@ -1262,10 +1259,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
|
||||
ELEMENT_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CLASSINFO_DATA(TimeRanges, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CLASSINFO_DATA(MediaStream, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CLASSINFO_DATA(LocalMediaStream, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
#endif
|
||||
|
||||
// DOM Traversal NodeIterator class
|
||||
@ -3330,14 +3323,6 @@ nsDOMClassInfo::Init()
|
||||
DOM_CLASSINFO_MAP_BEGIN(TimeRanges, nsIDOMTimeRanges)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMTimeRanges)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN(MediaStream, nsIDOMMediaStream)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMediaStream)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN(LocalMediaStream, nsIDOMLocalMediaStream)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMLocalMediaStream)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
#endif
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN(DataTransfer, nsIDOMDataTransfer)
|
||||
|
@ -323,10 +323,6 @@ DOMCI_CLASS(HTMLSourceElement)
|
||||
DOMCI_CLASS(MediaError)
|
||||
DOMCI_CLASS(HTMLAudioElement)
|
||||
DOMCI_CLASS(TimeRanges)
|
||||
|
||||
// Media streams
|
||||
DOMCI_CLASS(MediaStream)
|
||||
DOMCI_CLASS(LocalMediaStream)
|
||||
#endif
|
||||
|
||||
// DOM Traversal NodeIterator class
|
||||
|
@ -606,7 +606,8 @@ DOMInterfaces = {
|
||||
},
|
||||
|
||||
'MediaStream': [{
|
||||
'nativeType': 'nsIDOMMediaStream',
|
||||
'headerFile': 'DOMMediaStream.h',
|
||||
'nativeType': 'mozilla::DOMMediaStream'
|
||||
},
|
||||
{
|
||||
'nativeType': 'JSObject',
|
||||
@ -614,6 +615,11 @@ DOMInterfaces = {
|
||||
'skipGen': True
|
||||
}],
|
||||
|
||||
'LocalMediaStream': {
|
||||
'headerFile': 'DOMMediaStream.h',
|
||||
'nativeType': 'mozilla::DOMLocalMediaStream'
|
||||
},
|
||||
|
||||
'MediaStreamList': {
|
||||
'headerFile': 'MediaStreamList.h',
|
||||
'wrapperCache': False,
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "CameraRecorderProfiles.h"
|
||||
#include "CameraControlImpl.h"
|
||||
#include "CameraCommon.h"
|
||||
#include "nsGlobalWindow.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
@ -420,8 +421,11 @@ GetPreviewStreamResult::Run()
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsCOMPtr<nsICameraPreviewStreamCallback> onSuccess = mOnSuccessCb.get();
|
||||
if (onSuccess && nsDOMCameraManager::IsWindowStillActive(mWindowId)) {
|
||||
nsCOMPtr<nsIDOMMediaStream> stream = new DOMCameraPreview(mCameraControl, mWidth, mHeight, mWindowId, mFramesPerSecond);
|
||||
nsGlobalWindow* window = nsGlobalWindow::GetInnerWindowWithId(mWindowId);
|
||||
if (onSuccess && nsDOMCameraManager::IsWindowStillActive(mWindowId) && window) {
|
||||
nsCOMPtr<nsIDOMMediaStream> stream =
|
||||
new DOMCameraPreview(window, mCameraControl, mWidth, mHeight,
|
||||
mFramesPerSecond);
|
||||
onSuccess->HandleEvent(stream);
|
||||
}
|
||||
return NS_OK;
|
||||
|
@ -26,7 +26,9 @@ public:
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS(nsDOMCameraControl)
|
||||
NS_DECL_NSICAMERACONTROL
|
||||
|
||||
nsDOMCameraControl(uint32_t aCameraId, nsIThread* aCameraThread, nsICameraGetCameraCallback* onSuccess, nsICameraErrorCallback* onError, uint64_t aWindowId);
|
||||
nsDOMCameraControl(uint32_t aCameraId, nsIThread* aCameraThread,
|
||||
nsICameraGetCameraCallback* onSuccess,
|
||||
nsICameraErrorCallback* onError, uint64_t aWindowId);
|
||||
nsresult Result(nsresult aResult, nsICameraGetCameraCallback* onSuccess, nsICameraErrorCallback* onError, uint64_t aWindowId);
|
||||
|
||||
void Shutdown();
|
||||
|
@ -52,7 +52,7 @@ protected:
|
||||
~nsDOMCameraManager();
|
||||
|
||||
private:
|
||||
nsDOMCameraManager();
|
||||
nsDOMCameraManager() MOZ_DELETE;
|
||||
nsDOMCameraManager(uint64_t aWindowId);
|
||||
nsDOMCameraManager(const nsDOMCameraManager&) MOZ_DELETE;
|
||||
nsDOMCameraManager& operator=(const nsDOMCameraManager&) MOZ_DELETE;
|
||||
|
@ -140,7 +140,10 @@ protected:
|
||||
DOMCameraPreview* mDOMPreview;
|
||||
};
|
||||
|
||||
DOMCameraPreview::DOMCameraPreview(ICameraControl* aCameraControl, uint32_t aWidth, uint32_t aHeight, uint64_t aWindowId, uint32_t aFrameRate)
|
||||
DOMCameraPreview::DOMCameraPreview(nsGlobalWindow* aWindow,
|
||||
ICameraControl* aCameraControl,
|
||||
uint32_t aWidth, uint32_t aHeight,
|
||||
uint32_t aFrameRate)
|
||||
: DOMMediaStream()
|
||||
, mState(STOPPED)
|
||||
, mWidth(aWidth)
|
||||
@ -154,6 +157,7 @@ DOMCameraPreview::DOMCameraPreview(ICameraControl* aCameraControl, uint32_t aWid
|
||||
mImageContainer = LayerManager::CreateImageContainer();
|
||||
MediaStreamGraph* gm = MediaStreamGraph::GetInstance();
|
||||
mStream = gm->CreateSourceStream(this);
|
||||
mWindow = aWindow;
|
||||
mInput = GetStream()->AsSourceStream();
|
||||
|
||||
mListener = new DOMCameraPreviewListener(this);
|
||||
@ -162,10 +166,8 @@ DOMCameraPreview::DOMCameraPreview(ICameraControl* aCameraControl, uint32_t aWid
|
||||
mInput->AddTrack(TRACK_VIDEO, mFramesPerSecond, 0, new VideoSegment());
|
||||
mInput->AdvanceKnownTracksTime(MEDIA_TIME_MAX);
|
||||
|
||||
nsPIDOMWindow *window = static_cast<nsPIDOMWindow*>
|
||||
(nsGlobalWindow::GetInnerWindowWithId(aWindowId));
|
||||
if (window && window->GetExtantDoc()) {
|
||||
this->CombineWithPrincipal(window->GetExtantDoc()->NodePrincipal());
|
||||
if (aWindow->GetExtantDoc()) {
|
||||
CombineWithPrincipal(aWindow->GetExtantDoc()->NodePrincipal());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,13 +12,17 @@
|
||||
#include "DOMMediaStream.h"
|
||||
#include "CameraCommon.h"
|
||||
|
||||
class nsGlobalWindow;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
typedef void (*FrameBuilder)(mozilla::layers::Image* aImage, void* aBuffer, uint32_t aWidth, uint32_t aHeight);
|
||||
|
||||
/**
|
||||
* DOMCameraPreview is only exposed to the DOM as an nsDOMMediaStream,
|
||||
* which is a cycle-collection participant already.
|
||||
* which is a cycle-collection participant already, and we don't
|
||||
* add any traceable fields here, so we don't need to declare any
|
||||
* more cycle-collection goop.
|
||||
*/
|
||||
class DOMCameraPreview : public DOMMediaStream
|
||||
{
|
||||
@ -26,15 +30,12 @@ protected:
|
||||
enum { TRACK_VIDEO = 1 };
|
||||
|
||||
public:
|
||||
DOMCameraPreview(ICameraControl* aCameraControl, uint32_t aWidth, uint32_t aHeight, uint64_t aWindowId, uint32_t aFramesPerSecond = 30);
|
||||
DOMCameraPreview(nsGlobalWindow* aWindow, ICameraControl* aCameraControl,
|
||||
uint32_t aWidth, uint32_t aHeight, uint32_t aFramesPerSecond = 30);
|
||||
|
||||
bool ReceiveFrame(void* aBuffer, ImageFormat aFormat, mozilla::FrameBuilder aBuilder);
|
||||
bool HaveEnoughBuffered();
|
||||
|
||||
NS_IMETHODIMP
|
||||
GetCurrentTime(double* aCurrentTime) {
|
||||
return DOMMediaStream::GetCurrentTime(aCurrentTime);
|
||||
}
|
||||
|
||||
void Start(); // called by the MediaStreamListener to start preview
|
||||
void Started(); // called by the CameraControl when preview is started
|
||||
void StopPreview(); // called by the MediaStreamListener to stop preview
|
||||
|
@ -261,10 +261,10 @@ class nsDOMUserMediaStream : public DOMLocalMediaStream
|
||||
{
|
||||
public:
|
||||
static already_AddRefed<nsDOMUserMediaStream>
|
||||
CreateTrackUnionStream(uint32_t aHintContents)
|
||||
CreateTrackUnionStream(nsIDOMWindow* aWindow, uint32_t aHintContents)
|
||||
{
|
||||
nsRefPtr<nsDOMUserMediaStream> stream = new nsDOMUserMediaStream();
|
||||
stream->InitTrackUnionStream(aHintContents);
|
||||
stream->InitTrackUnionStream(aWindow, aHintContents);
|
||||
return stream.forget();
|
||||
}
|
||||
|
||||
@ -280,12 +280,11 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP Stop()
|
||||
virtual void Stop()
|
||||
{
|
||||
if (mSourceStream) {
|
||||
mSourceStream->EndAllTrackAndFinish();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// The actual MediaStream is a TrackUnionStream. But these resources need to be
|
||||
@ -332,11 +331,13 @@ public:
|
||||
Run()
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
|
||||
nsPIDOMWindow *window = static_cast<nsPIDOMWindow*>
|
||||
(nsGlobalWindow::GetInnerWindowWithId(mWindowID));
|
||||
|
||||
// We're on main-thread, and the windowlist can only
|
||||
// be invalidated from the main-thread (see OnNavigation)
|
||||
StreamListeners* listeners = mManager->GetWindowListeners(mWindowID);
|
||||
if (!listeners) {
|
||||
if (!listeners || !window || !window->GetExtantDoc()) {
|
||||
// This window is no longer live. mListener has already been removed
|
||||
return NS_OK;
|
||||
}
|
||||
@ -346,7 +347,7 @@ public:
|
||||
hints |= (mVideoSource ? DOMMediaStream::HINT_CONTENTS_VIDEO : 0);
|
||||
|
||||
nsRefPtr<nsDOMUserMediaStream> trackunion =
|
||||
nsDOMUserMediaStream::CreateTrackUnionStream(hints);
|
||||
nsDOMUserMediaStream::CreateTrackUnionStream(window, hints);
|
||||
if (!trackunion) {
|
||||
nsCOMPtr<nsIDOMGetUserMediaErrorCallback> error(mError);
|
||||
LOG(("Returning error for getUserMedia() - no stream"));
|
||||
@ -364,11 +365,7 @@ public:
|
||||
trackunion->mSourceStream = stream;
|
||||
trackunion->mPort = port.forget();
|
||||
|
||||
nsPIDOMWindow *window = static_cast<nsPIDOMWindow*>
|
||||
(nsGlobalWindow::GetInnerWindowWithId(mWindowID));
|
||||
if (window && window->GetExtantDoc()) {
|
||||
trackunion->CombineWithPrincipal(window->GetExtantDoc()->NodePrincipal());
|
||||
}
|
||||
trackunion->CombineWithPrincipal(window->GetExtantDoc()->NodePrincipal());
|
||||
|
||||
// The listener was added at the begining in an inactive state.
|
||||
// Activate our listener. We'll call Start() on the source when get a callback
|
||||
|
@ -12,15 +12,16 @@
|
||||
#endif
|
||||
%}
|
||||
|
||||
[scriptable, builtinclass, uuid(f37c2871-4cb7-4672-bb28-c2d601f7cc9e)]
|
||||
[scriptable, builtinclass, uuid(3ef760bb-ff19-4dbb-b552-af27ab84b9b8)]
|
||||
interface nsIDOMMediaStream : nsISupports
|
||||
{
|
||||
readonly attribute double currentTime;
|
||||
/* Placeholder interface only; will be removed after further WebIDL conversion.
|
||||
Do not add anything here. */
|
||||
};
|
||||
|
||||
[scriptable, builtinclass, uuid(210a16e3-2a38-4ae9-b0f6-0fb5a8252814)]
|
||||
[scriptable, builtinclass, uuid(dd37150a-9823-4605-ac4c-3516629a8aaf)]
|
||||
interface nsIDOMLocalMediaStream : nsIDOMMediaStream
|
||||
{
|
||||
void stop();
|
||||
/* Placeholder interface only; will be removed after further WebIDL conversion.
|
||||
Do not add anything here. */
|
||||
};
|
||||
|
||||
|
15
dom/webidl/LocalMediaStream.webidl
Normal file
15
dom/webidl/LocalMediaStream.webidl
Normal file
@ -0,0 +1,15 @@
|
||||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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/.
|
||||
*
|
||||
* The origins of this IDL file are
|
||||
* http://dev.w3.org/2011/webrtc/editor/getusermedia.html
|
||||
*
|
||||
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
|
||||
* liability, trademark and document use rules apply.
|
||||
*/
|
||||
|
||||
interface LocalMediaStream : MediaStream {
|
||||
void stop();
|
||||
};
|
25
dom/webidl/MediaStream.webidl
Normal file
25
dom/webidl/MediaStream.webidl
Normal file
@ -0,0 +1,25 @@
|
||||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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/.
|
||||
*
|
||||
* The origins of this IDL file are
|
||||
* http://dev.w3.org/2011/webrtc/editor/getusermedia.html
|
||||
*
|
||||
* Copyright <20> 2012 W3C<33> (MIT, ERCIM, Keio), All Rights Reserved. W3C
|
||||
* liability, trademark and document use rules apply.
|
||||
*/
|
||||
|
||||
interface MediaStream : EventTarget {
|
||||
// readonly attribute DOMString id;
|
||||
// sequence<MediaStreamTrack> getAudioTracks ();
|
||||
// sequence<MediaStreamTrack> getVideoTracks ();
|
||||
// MediaStreamTrack getTrackById (DOMString trackId);
|
||||
// void addTrack (MediaStreamTrack track);
|
||||
// void removeTrack (MediaStreamTrack track);
|
||||
// attribute boolean ended;
|
||||
// attribute EventHandler onended;
|
||||
// attribute EventHandler onaddtrack;
|
||||
// attribute EventHandler onremovetrack;
|
||||
readonly attribute double currentTime;
|
||||
};
|
@ -4,8 +4,6 @@
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
interface MediaStream;
|
||||
|
||||
[NoInterfaceObject]
|
||||
interface MediaStreamList {
|
||||
getter MediaStream? (unsigned long index);
|
||||
|
@ -11,8 +11,6 @@
|
||||
* liability, trademark and document use rules apply.
|
||||
*/
|
||||
|
||||
interface MediaStream;
|
||||
|
||||
interface URL {
|
||||
[Throws]
|
||||
static DOMString? createObjectURL(Blob blob, optional objectURLOptions options);
|
||||
|
@ -107,7 +107,9 @@ webidl_files = \
|
||||
HTMLUListElement.webidl \
|
||||
ImageData.webidl \
|
||||
LinkStyle.webidl \
|
||||
LocalMediaStream.webidl \
|
||||
Location.webidl \
|
||||
MediaStream.webidl \
|
||||
MutationObserver.webidl \
|
||||
Node.webidl \
|
||||
NodeFilter.webidl \
|
||||
|
@ -218,6 +218,15 @@ URL::CreateObjectURL(const WorkerGlobalObject& aGlobal, JSObject* aBlob,
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
void
|
||||
URL::CreateObjectURL(const WorkerGlobalObject& aGlobal, JSObject& aBlob,
|
||||
const mozilla::dom::objectURLOptionsWorkers& aOptions,
|
||||
nsString& aResult, mozilla::ErrorResult& aRv)
|
||||
{
|
||||
return CreateObjectURL(aGlobal, &aBlob, aOptions, aResult, aRv);
|
||||
}
|
||||
|
||||
// static
|
||||
void
|
||||
URL::RevokeObjectURL(const WorkerGlobalObject& aGlobal, const nsAString& aUrl)
|
||||
|
@ -21,6 +21,11 @@ public: // Methods for WebIDL
|
||||
JSObject* aArg, const objectURLOptionsWorkers& aOptions,
|
||||
nsString& aResult, ErrorResult& aRv);
|
||||
|
||||
static void
|
||||
CreateObjectURL(const WorkerGlobalObject& aGlobal,
|
||||
JSObject& aArg, const objectURLOptionsWorkers& aOptions,
|
||||
nsString& aResult, ErrorResult& aRv);
|
||||
|
||||
static void
|
||||
RevokeObjectURL(const WorkerGlobalObject& aGlobal, const nsAString& aUrl);
|
||||
};
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "FakeMediaStreams.h"
|
||||
#else
|
||||
#include "DOMMediaStream.h"
|
||||
#include "MediaStreamGraph.h"
|
||||
#endif
|
||||
#include "MediaConduitInterface.h"
|
||||
#include "AudioSegment.h"
|
||||
|
@ -50,7 +50,7 @@ MediaStreamList::WrapObject(JSContext* cx, ErrorResult& error)
|
||||
}
|
||||
|
||||
template<class T>
|
||||
static nsIDOMMediaStream*
|
||||
static DOMMediaStream*
|
||||
GetStreamFromInfo(T* info, bool& found)
|
||||
{
|
||||
if (!info) {
|
||||
@ -62,7 +62,7 @@ GetStreamFromInfo(T* info, bool& found)
|
||||
return info->GetMediaStream();
|
||||
}
|
||||
|
||||
nsIDOMMediaStream*
|
||||
DOMMediaStream*
|
||||
MediaStreamList::IndexedGetter(uint32_t index, bool& found)
|
||||
{
|
||||
if (mType == Local) {
|
||||
|
@ -11,7 +11,12 @@
|
||||
#include "jspubtd.h"
|
||||
#include "mozilla/dom/NonRefcountedDOMObject.h"
|
||||
|
||||
class nsIDOMMediaStream;
|
||||
#ifdef USE_FAKE_MEDIA_STREAMS
|
||||
#include "FakeMediaStreams.h"
|
||||
#else
|
||||
#include "DOMMediaStream.h"
|
||||
#endif
|
||||
|
||||
namespace sipcc {
|
||||
class PeerConnectionImpl;
|
||||
} // namespace sipcc
|
||||
@ -32,7 +37,7 @@ public:
|
||||
|
||||
JSObject* WrapObject(JSContext* cx, ErrorResult& error);
|
||||
|
||||
nsIDOMMediaStream* IndexedGetter(uint32_t index, bool& found);
|
||||
DOMMediaStream* IndexedGetter(uint32_t index, bool& found);
|
||||
uint32_t Length();
|
||||
|
||||
private:
|
||||
|
@ -280,11 +280,13 @@ PeerConnectionImpl::~PeerConnectionImpl()
|
||||
|
||||
// One level of indirection so we can use WrapRunnable in CreateMediaStream.
|
||||
nsresult
|
||||
PeerConnectionImpl::MakeMediaStream(uint32_t aHint, nsIDOMMediaStream** aRetval)
|
||||
PeerConnectionImpl::MakeMediaStream(nsIDOMWindow* aWindow,
|
||||
uint32_t aHint, nsIDOMMediaStream** aRetval)
|
||||
{
|
||||
MOZ_ASSERT(aRetval);
|
||||
|
||||
nsRefPtr<DOMMediaStream> stream = DOMMediaStream::CreateSourceStream(aHint);
|
||||
nsRefPtr<DOMMediaStream> stream =
|
||||
DOMMediaStream::CreateSourceStream(aWindow, aHint);
|
||||
NS_ADDREF(*aRetval = stream);
|
||||
|
||||
CSFLogDebugS(logTag, "Created media stream " << static_cast<void*>(stream)
|
||||
@ -306,7 +308,7 @@ PeerConnectionImpl::CreateRemoteSourceStreamInfo(nsRefPtr<RemoteSourceStreamInfo
|
||||
// needs to actually propagate a hint for local streams.
|
||||
// TODO(ekr@rtfm.com): Clean up when we have explicit track lists.
|
||||
// See bug 834835.
|
||||
nsresult res = MakeMediaStream(0, &stream);
|
||||
nsresult res = MakeMediaStream(mWindow, 0, &stream);
|
||||
if (NS_FAILED(res)) {
|
||||
return res;
|
||||
}
|
||||
@ -589,10 +591,10 @@ PeerConnectionImpl::CreateFakeMediaStream(uint32_t aHint, nsIDOMMediaStream** aR
|
||||
|
||||
nsresult res;
|
||||
if (!mThread || NS_IsMainThread()) {
|
||||
res = MakeMediaStream(aHint, aRetval);
|
||||
res = MakeMediaStream(mWindow, aHint, aRetval);
|
||||
} else {
|
||||
mThread->Dispatch(WrapRunnableNMRet(
|
||||
&PeerConnectionImpl::MakeMediaStream, aHint, aRetval, &res
|
||||
&PeerConnectionImpl::MakeMediaStream, mWindow, aHint, aRetval, &res
|
||||
), NS_DISPATCH_SYNC);
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,8 @@ public:
|
||||
RTCConfiguration *aDst, JSContext* aCx);
|
||||
static nsresult ConvertConstraints(
|
||||
const JS::Value& aConstraints, MediaConstraints* aObj, JSContext* aCx);
|
||||
static nsresult MakeMediaStream(uint32_t aHint, nsIDOMMediaStream** aStream);
|
||||
static nsresult MakeMediaStream(nsIDOMWindow* aWindow,
|
||||
uint32_t aHint, nsIDOMMediaStream** aStream);
|
||||
|
||||
Role GetRole() const {
|
||||
PC_AUTO_ENTER_API_CALL_NO_CHECK();
|
||||
|
@ -23,6 +23,8 @@
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "nsIDOMMediaStream.h"
|
||||
|
||||
class nsIDOMWindow;
|
||||
|
||||
namespace mozilla {
|
||||
class MediaStreamGraph;
|
||||
class MediaSegment;
|
||||
@ -186,11 +188,10 @@ public:
|
||||
mMediaStream->Stop();
|
||||
}
|
||||
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDOMMEDIASTREAM
|
||||
|
||||
static already_AddRefed<Fake_DOMMediaStream> CreateSourceStream(uint32_t aHintContents) {
|
||||
static already_AddRefed<Fake_DOMMediaStream>
|
||||
CreateSourceStream(nsIDOMWindow* aWindow, uint32_t aHintContents) {
|
||||
Fake_SourceMediaStream *source = new Fake_SourceMediaStream();
|
||||
|
||||
Fake_DOMMediaStream *ds = new Fake_DOMMediaStream(source);
|
||||
|
Loading…
x
Reference in New Issue
Block a user