2012-05-11 21:35:36 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
|
2012-04-30 07:11:34 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
2013-02-15 12:01:58 +04:00
|
|
|
#include "DOMMediaStream.h"
|
2012-04-30 07:11:34 +04:00
|
|
|
#include "nsContentUtils.h"
|
2015-02-19 20:59:00 +03:00
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsIUUIDGenerator.h"
|
2013-02-15 12:04:11 +04:00
|
|
|
#include "mozilla/dom/MediaStreamBinding.h"
|
|
|
|
#include "mozilla/dom/LocalMediaStreamBinding.h"
|
2013-05-21 23:17:47 +04:00
|
|
|
#include "mozilla/dom/AudioNode.h"
|
2015-08-25 11:29:51 +03:00
|
|
|
#include "AudioChannelAgent.h"
|
2014-05-23 13:34:14 +04:00
|
|
|
#include "mozilla/dom/AudioTrack.h"
|
|
|
|
#include "mozilla/dom/AudioTrackList.h"
|
|
|
|
#include "mozilla/dom/VideoTrack.h"
|
|
|
|
#include "mozilla/dom/VideoTrackList.h"
|
2015-05-13 09:04:30 +03:00
|
|
|
#include "mozilla/dom/HTMLCanvasElement.h"
|
2013-02-15 12:04:11 +04:00
|
|
|
#include "MediaStreamGraph.h"
|
2013-04-17 09:18:24 +04:00
|
|
|
#include "AudioStreamTrack.h"
|
|
|
|
#include "VideoStreamTrack.h"
|
2015-06-18 01:21:00 +03:00
|
|
|
#include "Layers.h"
|
2012-04-30 07:11:34 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2013-04-17 09:18:24 +04:00
|
|
|
using namespace mozilla::dom;
|
2015-06-18 01:21:00 +03:00
|
|
|
using namespace mozilla::layers;
|
|
|
|
|
|
|
|
const TrackID TRACK_VIDEO_PRIMARY = 1;
|
2012-04-30 07:11:34 +04:00
|
|
|
|
2013-04-17 09:18:24 +04:00
|
|
|
class DOMMediaStream::StreamListener : public MediaStreamListener {
|
|
|
|
public:
|
2014-09-01 07:50:23 +04:00
|
|
|
explicit StreamListener(DOMMediaStream* aStream)
|
2013-04-17 09:18:24 +04:00
|
|
|
: mStream(aStream)
|
|
|
|
{}
|
|
|
|
|
|
|
|
// Main thread only
|
|
|
|
void Forget() { mStream = nullptr; }
|
|
|
|
DOMMediaStream* GetStream() { return mStream; }
|
|
|
|
|
|
|
|
class TrackChange : public nsRunnable {
|
|
|
|
public:
|
|
|
|
TrackChange(StreamListener* aListener,
|
2014-09-18 09:20:43 +04:00
|
|
|
TrackID aID, StreamTime aTrackOffset,
|
2015-09-25 18:23:17 +03:00
|
|
|
uint32_t aEvents, MediaSegment::Type aType,
|
|
|
|
MediaStream* aInputStream, TrackID aInputTrackID)
|
2013-04-17 09:18:24 +04:00
|
|
|
: mListener(aListener), mID(aID), mEvents(aEvents), mType(aType)
|
2015-09-25 18:23:17 +03:00
|
|
|
, mInputStream(aInputStream), mInputTrackID(aInputTrackID)
|
2013-04-17 09:18:24 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "main thread only");
|
|
|
|
|
|
|
|
DOMMediaStream* stream = mListener->GetStream();
|
|
|
|
if (!stream) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<MediaStreamTrack> track;
|
|
|
|
if (mEvents & MediaStreamListener::TRACK_EVENT_CREATED) {
|
2014-10-13 07:13:36 +04:00
|
|
|
track = stream->BindDOMTrack(mID, mType);
|
|
|
|
if (!track) {
|
|
|
|
stream->CreateDOMTrack(mID, mType);
|
|
|
|
track = stream->BindDOMTrack(mID, mType);
|
|
|
|
}
|
2014-11-25 01:53:00 +03:00
|
|
|
stream->NotifyMediaStreamTrackCreated(track);
|
2013-04-17 09:18:24 +04:00
|
|
|
} else {
|
|
|
|
track = stream->GetDOMTrackFor(mID);
|
|
|
|
}
|
|
|
|
if (mEvents & MediaStreamListener::TRACK_EVENT_ENDED) {
|
2014-10-03 12:18:00 +04:00
|
|
|
if (track) {
|
|
|
|
track->NotifyEnded();
|
|
|
|
stream->NotifyMediaStreamTrackEnded(track);
|
|
|
|
} else {
|
|
|
|
NS_ERROR("track ended but not found");
|
|
|
|
}
|
2013-04-17 09:18:24 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
StreamTime mEndTime;
|
|
|
|
nsRefPtr<StreamListener> mListener;
|
|
|
|
TrackID mID;
|
|
|
|
uint32_t mEvents;
|
|
|
|
MediaSegment::Type mType;
|
2015-09-25 18:23:17 +03:00
|
|
|
nsRefPtr<MediaStream> mInputStream;
|
|
|
|
TrackID mInputTrackID;
|
2013-04-17 09:18:24 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify that changes to one of the stream tracks have been queued.
|
|
|
|
* aTrackEvents can be any combination of TRACK_EVENT_CREATED and
|
|
|
|
* TRACK_EVENT_ENDED. aQueuedMedia is the data being added to the track
|
|
|
|
* at aTrackOffset (relative to the start of the stream).
|
|
|
|
* aQueuedMedia can be null if there is no output.
|
|
|
|
*/
|
|
|
|
virtual void NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID,
|
2014-09-18 09:20:43 +04:00
|
|
|
StreamTime aTrackOffset,
|
2013-04-17 09:18:24 +04:00
|
|
|
uint32_t aTrackEvents,
|
2015-09-25 18:23:17 +03:00
|
|
|
const MediaSegment& aQueuedMedia,
|
|
|
|
MediaStream* aInputStream,
|
|
|
|
TrackID aInputTrackID) override
|
2013-04-17 09:18:24 +04:00
|
|
|
{
|
|
|
|
if (aTrackEvents & (TRACK_EVENT_CREATED | TRACK_EVENT_ENDED)) {
|
|
|
|
nsRefPtr<TrackChange> runnable =
|
|
|
|
new TrackChange(this, aID, aTrackOffset, aTrackEvents,
|
2015-09-25 18:23:17 +03:00
|
|
|
aQueuedMedia.GetType(), aInputStream, aInputTrackID);
|
2014-11-20 21:10:00 +03:00
|
|
|
aGraph->DispatchToMainThreadAfterStreamStateUpdate(runnable.forget());
|
2013-04-17 09:18:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-06 12:38:11 +03:00
|
|
|
class TracksCreatedRunnable : public nsRunnable {
|
|
|
|
public:
|
|
|
|
explicit TracksCreatedRunnable(StreamListener* aListener)
|
|
|
|
: mListener(aListener)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
DOMMediaStream* stream = mListener->GetStream();
|
|
|
|
if (!stream) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
stream->TracksCreated();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<StreamListener> mListener;
|
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void NotifyFinishedTrackCreation(MediaStreamGraph* aGraph) override
|
2015-02-06 12:38:11 +03:00
|
|
|
{
|
|
|
|
nsRefPtr<TracksCreatedRunnable> runnable = new TracksCreatedRunnable(this);
|
|
|
|
aGraph->DispatchToMainThreadAfterStreamStateUpdate(runnable.forget());
|
|
|
|
}
|
|
|
|
|
2013-04-17 09:18:24 +04:00
|
|
|
private:
|
|
|
|
// These fields may only be accessed on the main thread
|
|
|
|
DOMMediaStream* mStream;
|
|
|
|
};
|
|
|
|
|
2014-11-02 02:56:10 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(DOMMediaStream)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(DOMMediaStream,
|
|
|
|
DOMEventTargetHelper)
|
2014-11-10 18:26:00 +03:00
|
|
|
tmp->Destroy();
|
2014-11-02 02:56:10 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mTracks)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mConsumersToKeepAlive)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(DOMMediaStream,
|
|
|
|
DOMEventTargetHelper)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTracks)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mConsumersToKeepAlive)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(DOMMediaStream, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(DOMMediaStream, DOMEventTargetHelper)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DOMMediaStream)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(DOMMediaStream)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(DOMLocalMediaStream, DOMMediaStream)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(DOMLocalMediaStream, DOMMediaStream)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(DOMLocalMediaStream)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(DOMLocalMediaStream)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMMediaStream)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(DOMAudioNodeMediaStream, DOMMediaStream,
|
|
|
|
mStreamNode)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(DOMAudioNodeMediaStream, DOMMediaStream)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(DOMAudioNodeMediaStream, DOMMediaStream)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DOMAudioNodeMediaStream)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMMediaStream)
|
|
|
|
|
2013-04-17 09:18:24 +04:00
|
|
|
DOMMediaStream::DOMMediaStream()
|
2013-05-03 09:07:37 +04:00
|
|
|
: mLogicalStreamStartTime(0),
|
2015-02-06 12:38:11 +03:00
|
|
|
mStream(nullptr), mTracksCreated(false),
|
2014-12-17 20:03:34 +03:00
|
|
|
mNotifiedOfMediaStreamGraphShutdown(false), mCORSMode(CORS_NONE)
|
2013-04-17 09:18:24 +04:00
|
|
|
{
|
2015-02-19 20:59:00 +03:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIUUIDGenerator> uuidgen =
|
|
|
|
do_GetService("@mozilla.org/uuid-generator;1", &rv);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && uuidgen) {
|
|
|
|
nsID uuid;
|
|
|
|
memset(&uuid, 0, sizeof(uuid));
|
|
|
|
rv = uuidgen->GenerateUUIDInPlace(&uuid);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
char buffer[NSID_LENGTH];
|
|
|
|
uuid.ToProvidedString(buffer);
|
|
|
|
mID = NS_ConvertASCIItoUTF16(buffer);
|
|
|
|
}
|
|
|
|
}
|
2013-04-17 09:18:24 +04:00
|
|
|
}
|
|
|
|
|
2013-02-15 12:01:58 +04:00
|
|
|
DOMMediaStream::~DOMMediaStream()
|
2013-05-01 15:24:16 +04:00
|
|
|
{
|
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMMediaStream::Destroy()
|
2012-04-30 07:11:34 +04:00
|
|
|
{
|
2013-04-17 09:18:24 +04:00
|
|
|
if (mListener) {
|
|
|
|
mListener->Forget();
|
2013-05-01 15:24:16 +04:00
|
|
|
mListener = nullptr;
|
2013-04-17 09:18:24 +04:00
|
|
|
}
|
2012-04-30 07:11:34 +04:00
|
|
|
if (mStream) {
|
|
|
|
mStream->Destroy();
|
2013-05-01 15:24:16 +04:00
|
|
|
mStream = nullptr;
|
2012-04-30 07:11:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-15 12:04:11 +04:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
DOMMediaStream::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2012-04-30 07:11:34 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return dom::MediaStreamBinding::Wrap(aCx, this, aGivenProto);
|
2012-04-30 07:11:34 +04:00
|
|
|
}
|
|
|
|
|
2013-02-15 12:04:11 +04:00
|
|
|
double
|
|
|
|
DOMMediaStream::CurrentTime()
|
2013-01-07 06:31:34 +04:00
|
|
|
{
|
2013-05-03 09:07:37 +04:00
|
|
|
if (!mStream) {
|
|
|
|
return 0.0;
|
|
|
|
}
|
2014-06-12 08:44:58 +04:00
|
|
|
return mStream->
|
|
|
|
StreamTimeToSeconds(mStream->GetCurrentTime() - mLogicalStreamStartTime);
|
2013-01-07 06:31:34 +04:00
|
|
|
}
|
|
|
|
|
2015-02-05 19:03:00 +03:00
|
|
|
void
|
|
|
|
DOMMediaStream::GetId(nsAString& aID) const
|
|
|
|
{
|
|
|
|
aID = mID;
|
|
|
|
}
|
|
|
|
|
2013-04-17 09:18:37 +04:00
|
|
|
void
|
|
|
|
DOMMediaStream::GetAudioTracks(nsTArray<nsRefPtr<AudioStreamTrack> >& aTracks)
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mTracks.Length(); ++i) {
|
|
|
|
AudioStreamTrack* t = mTracks[i]->AsAudioStreamTrack();
|
|
|
|
if (t) {
|
|
|
|
aTracks.AppendElement(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMMediaStream::GetVideoTracks(nsTArray<nsRefPtr<VideoStreamTrack> >& aTracks)
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mTracks.Length(); ++i) {
|
|
|
|
VideoStreamTrack* t = mTracks[i]->AsVideoStreamTrack();
|
|
|
|
if (t) {
|
|
|
|
aTracks.AppendElement(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-14 05:40:54 +04:00
|
|
|
void
|
|
|
|
DOMMediaStream::GetTracks(nsTArray<nsRefPtr<MediaStreamTrack> >& aTracks)
|
|
|
|
{
|
|
|
|
aTracks.AppendElements(mTracks);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DOMMediaStream::HasTrack(const MediaStreamTrack& aTrack) const
|
|
|
|
{
|
|
|
|
return mTracks.Contains(&aTrack);
|
|
|
|
}
|
|
|
|
|
2013-02-15 12:04:11 +04:00
|
|
|
bool
|
|
|
|
DOMMediaStream::IsFinished()
|
2012-10-25 03:21:32 +04:00
|
|
|
{
|
2013-02-15 12:04:11 +04:00
|
|
|
return !mStream || mStream->IsFinished();
|
2012-10-25 03:21:32 +04:00
|
|
|
}
|
|
|
|
|
2013-02-15 12:04:11 +04:00
|
|
|
void
|
2015-03-31 05:14:00 +03:00
|
|
|
DOMMediaStream::InitSourceStream(nsIDOMWindow* aWindow,
|
|
|
|
MediaStreamGraph* aGraph)
|
2012-04-30 07:11:40 +04:00
|
|
|
{
|
2013-02-15 12:04:11 +04:00
|
|
|
mWindow = aWindow;
|
2015-03-31 05:14:00 +03:00
|
|
|
InitStreamCommon(aGraph->CreateSourceStream(this));
|
2012-04-30 07:11:40 +04:00
|
|
|
}
|
|
|
|
|
2013-02-15 12:04:11 +04:00
|
|
|
void
|
2015-03-31 05:14:00 +03:00
|
|
|
DOMMediaStream::InitTrackUnionStream(nsIDOMWindow* aWindow,
|
|
|
|
MediaStreamGraph* aGraph)
|
2012-10-25 03:21:32 +04:00
|
|
|
{
|
2013-02-15 12:04:11 +04:00
|
|
|
mWindow = aWindow;
|
2015-03-31 05:14:00 +03:00
|
|
|
|
|
|
|
InitStreamCommon(aGraph->CreateTrackUnionStream(this));
|
2013-04-17 09:18:24 +04:00
|
|
|
}
|
|
|
|
|
2015-07-24 15:28:16 +03:00
|
|
|
void
|
|
|
|
DOMMediaStream::InitAudioCaptureStream(nsIDOMWindow* aWindow,
|
|
|
|
MediaStreamGraph* aGraph)
|
|
|
|
{
|
|
|
|
mWindow = aWindow;
|
|
|
|
|
|
|
|
InitStreamCommon(aGraph->CreateAudioCaptureStream(this));
|
|
|
|
}
|
|
|
|
|
2013-04-17 09:18:24 +04:00
|
|
|
void
|
|
|
|
DOMMediaStream::InitStreamCommon(MediaStream* aStream)
|
|
|
|
{
|
|
|
|
mStream = aStream;
|
|
|
|
|
|
|
|
// Setup track listener
|
|
|
|
mListener = new StreamListener(this);
|
|
|
|
aStream->AddListener(mListener);
|
2012-10-25 03:21:32 +04:00
|
|
|
}
|
|
|
|
|
2013-02-15 12:01:58 +04:00
|
|
|
already_AddRefed<DOMMediaStream>
|
2015-03-31 05:14:00 +03:00
|
|
|
DOMMediaStream::CreateSourceStream(nsIDOMWindow* aWindow,
|
|
|
|
MediaStreamGraph* aGraph)
|
2012-07-31 16:17:22 +04:00
|
|
|
{
|
2013-02-15 12:01:58 +04:00
|
|
|
nsRefPtr<DOMMediaStream> stream = new DOMMediaStream();
|
2015-03-31 05:14:00 +03:00
|
|
|
stream->InitSourceStream(aWindow, aGraph);
|
2012-07-31 16:17:22 +04:00
|
|
|
return stream.forget();
|
|
|
|
}
|
|
|
|
|
2013-02-15 12:04:11 +04:00
|
|
|
already_AddRefed<DOMMediaStream>
|
2015-03-31 05:14:00 +03:00
|
|
|
DOMMediaStream::CreateTrackUnionStream(nsIDOMWindow* aWindow,
|
|
|
|
MediaStreamGraph* aGraph)
|
2012-10-25 03:21:32 +04:00
|
|
|
{
|
2013-02-15 12:04:11 +04:00
|
|
|
nsRefPtr<DOMMediaStream> stream = new DOMMediaStream();
|
2015-03-31 05:14:00 +03:00
|
|
|
stream->InitTrackUnionStream(aWindow, aGraph);
|
2012-10-25 03:21:32 +04:00
|
|
|
return stream.forget();
|
|
|
|
}
|
|
|
|
|
2015-07-24 15:28:16 +03:00
|
|
|
already_AddRefed<DOMMediaStream>
|
|
|
|
DOMMediaStream::CreateAudioCaptureStream(nsIDOMWindow* aWindow,
|
|
|
|
MediaStreamGraph* aGraph)
|
|
|
|
{
|
|
|
|
nsRefPtr<DOMMediaStream> stream = new DOMMediaStream();
|
|
|
|
stream->InitAudioCaptureStream(aWindow, aGraph);
|
|
|
|
return stream.forget();
|
|
|
|
}
|
|
|
|
|
2013-08-26 10:07:19 +04:00
|
|
|
void
|
|
|
|
DOMMediaStream::SetTrackEnabled(TrackID aTrackID, bool aEnabled)
|
|
|
|
{
|
|
|
|
if (mStream) {
|
|
|
|
mStream->SetTrackEnabled(aTrackID, aEnabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-27 09:03:49 +04:00
|
|
|
void
|
|
|
|
DOMMediaStream::StopTrack(TrackID aTrackID)
|
|
|
|
{
|
|
|
|
if (mStream && mStream->AsSourceStream()) {
|
|
|
|
mStream->AsSourceStream()->EndTrack(aTrackID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-21 01:45:57 +03:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
DOMMediaStream::ApplyConstraintsToTrack(TrackID aTrackID,
|
|
|
|
const MediaTrackConstraints& aConstraints,
|
|
|
|
ErrorResult &aRv)
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-04-30 07:11:34 +04:00
|
|
|
bool
|
2013-02-15 12:01:58 +04:00
|
|
|
DOMMediaStream::CombineWithPrincipal(nsIPrincipal* aPrincipal)
|
2012-04-30 07:11:34 +04:00
|
|
|
{
|
2014-04-25 18:30:00 +04:00
|
|
|
bool changed =
|
|
|
|
nsContentUtils::CombineResourcePrincipals(&mPrincipal, aPrincipal);
|
|
|
|
if (changed) {
|
|
|
|
NotifyPrincipalChanged();
|
|
|
|
}
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMMediaStream::SetPrincipal(nsIPrincipal* aPrincipal)
|
|
|
|
{
|
|
|
|
mPrincipal = aPrincipal;
|
|
|
|
NotifyPrincipalChanged();
|
|
|
|
}
|
|
|
|
|
2014-12-17 20:03:34 +03:00
|
|
|
void
|
|
|
|
DOMMediaStream::SetCORSMode(CORSMode aCORSMode)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mCORSMode = aCORSMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
CORSMode
|
|
|
|
DOMMediaStream::GetCORSMode()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
return mCORSMode;
|
|
|
|
}
|
|
|
|
|
2014-04-25 18:30:00 +04:00
|
|
|
void
|
|
|
|
DOMMediaStream::NotifyPrincipalChanged()
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mPrincipalChangeObservers.Length(); ++i) {
|
|
|
|
mPrincipalChangeObservers[i]->PrincipalChanged(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
DOMMediaStream::AddPrincipalChangeObserver(PrincipalChangeObserver* aObserver)
|
|
|
|
{
|
|
|
|
return mPrincipalChangeObservers.AppendElement(aObserver) != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DOMMediaStream::RemovePrincipalChangeObserver(PrincipalChangeObserver* aObserver)
|
|
|
|
{
|
|
|
|
return mPrincipalChangeObservers.RemoveElement(aObserver);
|
2012-04-30 07:11:34 +04:00
|
|
|
}
|
2013-02-15 12:04:11 +04:00
|
|
|
|
2013-04-17 09:18:24 +04:00
|
|
|
MediaStreamTrack*
|
|
|
|
DOMMediaStream::CreateDOMTrack(TrackID aTrackID, MediaSegment::Type aType)
|
|
|
|
{
|
|
|
|
MediaStreamTrack* track;
|
|
|
|
switch (aType) {
|
|
|
|
case MediaSegment::AUDIO:
|
|
|
|
track = new AudioStreamTrack(this, aTrackID);
|
|
|
|
break;
|
|
|
|
case MediaSegment::VIDEO:
|
|
|
|
track = new VideoStreamTrack(this, aTrackID);
|
|
|
|
break;
|
|
|
|
default:
|
2013-06-29 05:38:30 +04:00
|
|
|
MOZ_CRASH("Unhandled track type");
|
2013-04-17 09:18:24 +04:00
|
|
|
}
|
2013-05-05 13:51:47 +04:00
|
|
|
mTracks.AppendElement(track);
|
2013-05-03 09:02:55 +04:00
|
|
|
|
2014-10-13 07:13:36 +04:00
|
|
|
return track;
|
|
|
|
}
|
2013-05-03 09:02:55 +04:00
|
|
|
|
2014-10-13 07:13:36 +04:00
|
|
|
MediaStreamTrack*
|
|
|
|
DOMMediaStream::BindDOMTrack(TrackID aTrackID, MediaSegment::Type aType)
|
|
|
|
{
|
|
|
|
MediaStreamTrack* track = nullptr;
|
2014-12-12 06:54:12 +03:00
|
|
|
bool bindSuccess = false;
|
2014-10-13 07:13:36 +04:00
|
|
|
switch (aType) {
|
|
|
|
case MediaSegment::AUDIO: {
|
|
|
|
for (size_t i = 0; i < mTracks.Length(); ++i) {
|
|
|
|
track = mTracks[i]->AsAudioStreamTrack();
|
2014-12-12 06:54:12 +03:00
|
|
|
if (track && track->GetTrackID() == aTrackID) {
|
|
|
|
bindSuccess = true;
|
2014-10-13 07:13:36 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MediaSegment::VIDEO: {
|
|
|
|
for (size_t i = 0; i < mTracks.Length(); ++i) {
|
|
|
|
track = mTracks[i]->AsVideoStreamTrack();
|
2014-12-12 06:54:12 +03:00
|
|
|
if (track && track->GetTrackID() == aTrackID) {
|
|
|
|
bindSuccess = true;
|
2014-10-13 07:13:36 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unhandled track type");
|
|
|
|
}
|
2014-12-12 06:54:12 +03:00
|
|
|
return bindSuccess ? track : nullptr;
|
2013-04-17 09:18:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
MediaStreamTrack*
|
|
|
|
DOMMediaStream::GetDOMTrackFor(TrackID aTrackID)
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mTracks.Length(); ++i) {
|
|
|
|
MediaStreamTrack* t = mTracks[i];
|
|
|
|
// We may add streams to our track list that are actually owned by
|
|
|
|
// a different DOMMediaStream. Ignore those.
|
|
|
|
if (t->GetTrackID() == aTrackID && t->GetStream() == this) {
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-05-03 09:02:55 +04:00
|
|
|
void
|
|
|
|
DOMMediaStream::NotifyMediaStreamGraphShutdown()
|
|
|
|
{
|
|
|
|
// No more tracks will ever be added, so just clear these callbacks now
|
|
|
|
// to prevent leaks.
|
|
|
|
mNotifiedOfMediaStreamGraphShutdown = true;
|
|
|
|
mRunOnTracksAvailable.Clear();
|
2013-07-25 06:07:34 +04:00
|
|
|
|
|
|
|
mConsumersToKeepAlive.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-05-11 17:07:24 +03:00
|
|
|
DOMMediaStream::NotifyStreamFinished()
|
2013-07-25 06:07:34 +04:00
|
|
|
{
|
2015-05-11 17:07:24 +03:00
|
|
|
MOZ_ASSERT(IsFinished());
|
|
|
|
mConsumersToKeepAlive.Clear();
|
2013-05-03 09:02:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMMediaStream::OnTracksAvailable(OnTracksAvailableCallback* aRunnable)
|
|
|
|
{
|
|
|
|
if (mNotifiedOfMediaStreamGraphShutdown) {
|
|
|
|
// No more tracks will ever be added, so just delete the callback now.
|
|
|
|
delete aRunnable;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mRunOnTracksAvailable.AppendElement(aRunnable);
|
|
|
|
CheckTracksAvailable();
|
|
|
|
}
|
|
|
|
|
2015-02-06 12:38:11 +03:00
|
|
|
void
|
|
|
|
DOMMediaStream::TracksCreated()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mTracks.IsEmpty());
|
|
|
|
mTracksCreated = true;
|
|
|
|
CheckTracksAvailable();
|
|
|
|
}
|
|
|
|
|
2013-05-03 09:02:55 +04:00
|
|
|
void
|
|
|
|
DOMMediaStream::CheckTracksAvailable()
|
|
|
|
{
|
2015-02-06 12:38:11 +03:00
|
|
|
if (!mTracksCreated) {
|
2013-11-23 00:14:29 +04:00
|
|
|
return;
|
|
|
|
}
|
2013-05-03 09:02:55 +04:00
|
|
|
nsTArray<nsAutoPtr<OnTracksAvailableCallback> > callbacks;
|
|
|
|
callbacks.SwapElements(mRunOnTracksAvailable);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < callbacks.Length(); ++i) {
|
2015-02-09 10:23:34 +03:00
|
|
|
callbacks[i]->NotifyTracksAvailable(this);
|
2013-05-03 09:02:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-23 13:34:14 +04:00
|
|
|
already_AddRefed<AudioTrack>
|
|
|
|
DOMMediaStream::CreateAudioTrack(AudioStreamTrack* aStreamTrack)
|
|
|
|
{
|
|
|
|
nsAutoString id;
|
|
|
|
nsAutoString label;
|
|
|
|
aStreamTrack->GetId(id);
|
|
|
|
aStreamTrack->GetLabel(label);
|
|
|
|
|
|
|
|
return MediaTrackList::CreateAudioTrack(id, NS_LITERAL_STRING("main"),
|
|
|
|
label, EmptyString(),
|
|
|
|
aStreamTrack->Enabled());
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<VideoTrack>
|
|
|
|
DOMMediaStream::CreateVideoTrack(VideoStreamTrack* aStreamTrack)
|
|
|
|
{
|
|
|
|
nsAutoString id;
|
|
|
|
nsAutoString label;
|
|
|
|
aStreamTrack->GetId(id);
|
|
|
|
aStreamTrack->GetLabel(label);
|
|
|
|
|
|
|
|
return MediaTrackList::CreateVideoTrack(id, NS_LITERAL_STRING("main"),
|
|
|
|
label, EmptyString());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMMediaStream::ConstructMediaTracks(AudioTrackList* aAudioTrackList,
|
|
|
|
VideoTrackList* aVideoTrackList)
|
|
|
|
{
|
2015-02-09 10:23:34 +03:00
|
|
|
MediaTrackListListener audioListener(aAudioTrackList);
|
|
|
|
mMediaTrackListListeners.AppendElement(audioListener);
|
|
|
|
MediaTrackListListener videoListener(aVideoTrackList);
|
|
|
|
mMediaTrackListListeners.AppendElement(videoListener);
|
2014-05-23 13:34:14 +04:00
|
|
|
|
|
|
|
int firstEnabledVideo = -1;
|
|
|
|
for (uint32_t i = 0; i < mTracks.Length(); ++i) {
|
|
|
|
if (AudioStreamTrack* t = mTracks[i]->AsAudioStreamTrack()) {
|
|
|
|
nsRefPtr<AudioTrack> track = CreateAudioTrack(t);
|
|
|
|
aAudioTrackList->AddTrack(track);
|
|
|
|
} else if (VideoStreamTrack* t = mTracks[i]->AsVideoStreamTrack()) {
|
|
|
|
nsRefPtr<VideoTrack> track = CreateVideoTrack(t);
|
|
|
|
aVideoTrackList->AddTrack(track);
|
|
|
|
firstEnabledVideo = (t->Enabled() && firstEnabledVideo < 0)
|
|
|
|
? (aVideoTrackList->Length() - 1)
|
|
|
|
: firstEnabledVideo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aVideoTrackList->Length() > 0) {
|
|
|
|
// If media resource does not indicate a particular set of video tracks to
|
|
|
|
// enable, the one that is listed first in the element's videoTracks object
|
|
|
|
// must be selected.
|
|
|
|
int index = firstEnabledVideo >= 0 ? firstEnabledVideo : 0;
|
|
|
|
(*aVideoTrackList)[index]->SetEnabledInternal(true, MediaTrack::FIRE_NO_EVENTS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-04 01:29:29 +04:00
|
|
|
void
|
|
|
|
DOMMediaStream::DisconnectTrackListListeners(const AudioTrackList* aAudioTrackList,
|
|
|
|
const VideoTrackList* aVideoTrackList)
|
|
|
|
{
|
|
|
|
for (auto i = mMediaTrackListListeners.Length(); i > 0; ) { // unsigned!
|
|
|
|
--i; // 0 ... Length()-1 range
|
|
|
|
if (mMediaTrackListListeners[i].mMediaTrackList == aAudioTrackList ||
|
|
|
|
mMediaTrackListListeners[i].mMediaTrackList == aVideoTrackList) {
|
|
|
|
mMediaTrackListListeners.RemoveElementAt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-23 13:34:14 +04:00
|
|
|
void
|
|
|
|
DOMMediaStream::NotifyMediaStreamTrackCreated(MediaStreamTrack* aTrack)
|
|
|
|
{
|
2014-12-12 06:54:12 +03:00
|
|
|
MOZ_ASSERT(aTrack);
|
|
|
|
|
2014-05-23 13:34:14 +04:00
|
|
|
for (uint32_t i = 0; i < mMediaTrackListListeners.Length(); ++i) {
|
|
|
|
if (AudioStreamTrack* t = aTrack->AsAudioStreamTrack()) {
|
|
|
|
nsRefPtr<AudioTrack> track = CreateAudioTrack(t);
|
|
|
|
mMediaTrackListListeners[i].NotifyMediaTrackCreated(track);
|
|
|
|
} else if (VideoStreamTrack* t = aTrack->AsVideoStreamTrack()) {
|
|
|
|
nsRefPtr<VideoTrack> track = CreateVideoTrack(t);
|
|
|
|
mMediaTrackListListeners[i].NotifyMediaTrackCreated(track);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMMediaStream::NotifyMediaStreamTrackEnded(MediaStreamTrack* aTrack)
|
|
|
|
{
|
2014-12-12 06:54:12 +03:00
|
|
|
MOZ_ASSERT(aTrack);
|
|
|
|
|
2014-05-23 13:34:14 +04:00
|
|
|
nsAutoString id;
|
|
|
|
aTrack->GetId(id);
|
|
|
|
for (uint32_t i = 0; i < mMediaTrackListListeners.Length(); ++i) {
|
|
|
|
mMediaTrackListListeners[i].NotifyMediaTrackEnded(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-15 12:04:11 +04:00
|
|
|
DOMLocalMediaStream::~DOMLocalMediaStream()
|
|
|
|
{
|
|
|
|
if (mStream) {
|
|
|
|
// Make sure Listeners of this stream know it's going away
|
|
|
|
Stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
DOMLocalMediaStream::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-02-15 12:04:11 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return dom::LocalMediaStreamBinding::Wrap(aCx, this, aGivenProto);
|
2013-02-15 12:04:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMLocalMediaStream::Stop()
|
|
|
|
{
|
|
|
|
if (mStream && mStream->AsSourceStream()) {
|
|
|
|
mStream->AsSourceStream()->EndAllTrackAndFinish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMLocalMediaStream>
|
2015-03-31 05:14:00 +03:00
|
|
|
DOMLocalMediaStream::CreateSourceStream(nsIDOMWindow* aWindow,
|
|
|
|
MediaStreamGraph* aGraph)
|
2013-02-15 12:04:11 +04:00
|
|
|
{
|
|
|
|
nsRefPtr<DOMLocalMediaStream> stream = new DOMLocalMediaStream();
|
2015-03-31 05:14:00 +03:00
|
|
|
stream->InitSourceStream(aWindow, aGraph);
|
2013-02-15 12:04:11 +04:00
|
|
|
return stream.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMLocalMediaStream>
|
2015-03-31 05:14:00 +03:00
|
|
|
DOMLocalMediaStream::CreateTrackUnionStream(nsIDOMWindow* aWindow,
|
|
|
|
MediaStreamGraph* aGraph)
|
2013-02-15 12:04:11 +04:00
|
|
|
{
|
|
|
|
nsRefPtr<DOMLocalMediaStream> stream = new DOMLocalMediaStream();
|
2015-03-31 05:14:00 +03:00
|
|
|
stream->InitTrackUnionStream(aWindow, aGraph);
|
2013-02-15 12:04:11 +04:00
|
|
|
return stream.forget();
|
|
|
|
}
|
2013-05-21 23:17:47 +04:00
|
|
|
|
2015-07-24 15:28:16 +03:00
|
|
|
already_AddRefed<DOMLocalMediaStream>
|
|
|
|
DOMLocalMediaStream::CreateAudioCaptureStream(nsIDOMWindow* aWindow,
|
|
|
|
MediaStreamGraph* aGraph)
|
|
|
|
{
|
|
|
|
nsRefPtr<DOMLocalMediaStream> stream = new DOMLocalMediaStream();
|
|
|
|
stream->InitAudioCaptureStream(aWindow, aGraph);
|
|
|
|
return stream.forget();
|
|
|
|
}
|
|
|
|
|
2013-05-21 23:17:47 +04:00
|
|
|
DOMAudioNodeMediaStream::DOMAudioNodeMediaStream(AudioNode* aNode)
|
|
|
|
: mStreamNode(aNode)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-06-24 18:21:21 +04:00
|
|
|
DOMAudioNodeMediaStream::~DOMAudioNodeMediaStream()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-21 23:17:47 +04:00
|
|
|
already_AddRefed<DOMAudioNodeMediaStream>
|
|
|
|
DOMAudioNodeMediaStream::CreateTrackUnionStream(nsIDOMWindow* aWindow,
|
2015-03-31 05:14:00 +03:00
|
|
|
AudioNode* aNode,
|
|
|
|
MediaStreamGraph* aGraph)
|
2013-05-21 23:17:47 +04:00
|
|
|
{
|
|
|
|
nsRefPtr<DOMAudioNodeMediaStream> stream = new DOMAudioNodeMediaStream(aNode);
|
2015-03-31 05:14:00 +03:00
|
|
|
stream->InitTrackUnionStream(aWindow, aGraph);
|
2013-05-21 23:17:47 +04:00
|
|
|
return stream.forget();
|
|
|
|
}
|
2015-05-13 09:04:30 +03:00
|
|
|
|
2015-06-18 01:21:00 +03:00
|
|
|
DOMHwMediaStream::DOMHwMediaStream()
|
|
|
|
{
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
mImageContainer = LayerManager::CreateImageContainer(ImageContainer::ASYNCHRONOUS_OVERLAY);
|
|
|
|
nsRefPtr<Image> img = mImageContainer->CreateImage(ImageFormat::OVERLAY_IMAGE);
|
|
|
|
mOverlayImage = static_cast<layers::OverlayImage*>(img.get());
|
2015-07-07 00:58:18 +03:00
|
|
|
nsAutoTArray<ImageContainer::NonOwningImage,1> images;
|
|
|
|
images.AppendElement(ImageContainer::NonOwningImage(img));
|
|
|
|
mImageContainer->SetCurrentImages(images);
|
2015-06-18 01:21:00 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHwMediaStream::~DOMHwMediaStream()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMHwMediaStream>
|
|
|
|
DOMHwMediaStream::CreateHwStream(nsIDOMWindow* aWindow)
|
|
|
|
{
|
|
|
|
nsRefPtr<DOMHwMediaStream> stream = new DOMHwMediaStream();
|
2015-08-25 11:29:51 +03:00
|
|
|
|
|
|
|
MediaStreamGraph* graph =
|
|
|
|
MediaStreamGraph::GetInstance(MediaStreamGraph::SYSTEM_THREAD_DRIVER,
|
|
|
|
AudioChannel::Normal);
|
|
|
|
stream->InitSourceStream(aWindow, graph);
|
2015-06-18 01:21:00 +03:00
|
|
|
stream->Init(stream->GetStream());
|
|
|
|
|
|
|
|
return stream.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMHwMediaStream::Init(MediaStream* stream)
|
|
|
|
{
|
|
|
|
SourceMediaStream* srcStream = stream->AsSourceStream();
|
|
|
|
|
|
|
|
if (srcStream) {
|
|
|
|
VideoSegment segment;
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
const StreamTime delta = STREAM_TIME_MAX; // Because MediaStreamGraph will run out frames in non-autoplay mode,
|
|
|
|
// we must give it bigger frame length to cover this situation.
|
|
|
|
mImageData.mOverlayId = DEFAULT_IMAGE_ID;
|
|
|
|
mImageData.mSize.width = DEFAULT_IMAGE_WIDTH;
|
|
|
|
mImageData.mSize.height = DEFAULT_IMAGE_HEIGHT;
|
|
|
|
mOverlayImage->SetData(mImageData);
|
|
|
|
|
|
|
|
nsRefPtr<Image> image = static_cast<Image*>(mOverlayImage.get());
|
|
|
|
mozilla::gfx::IntSize size = image->GetSize();
|
|
|
|
|
|
|
|
segment.AppendFrame(image.forget(), delta, size);
|
|
|
|
#endif
|
|
|
|
srcStream->AddTrack(TRACK_VIDEO_PRIMARY, 0, new VideoSegment());
|
|
|
|
srcStream->AppendToTrack(TRACK_VIDEO_PRIMARY, &segment);
|
|
|
|
srcStream->FinishAddTracks();
|
|
|
|
srcStream->AdvanceKnownTracksTime(STREAM_TIME_MAX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
DOMHwMediaStream::RequestOverlayId()
|
|
|
|
{
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
return mOverlayImage->GetOverlayId();
|
|
|
|
#else
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-06-15 04:11:00 +03:00
|
|
|
void
|
|
|
|
DOMHwMediaStream::SetImageSize(uint32_t width, uint32_t height)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
OverlayImage::Data imgData;
|
|
|
|
|
|
|
|
imgData.mOverlayId = mOverlayImage->GetOverlayId();
|
|
|
|
imgData.mSize = IntSize(width, height);
|
|
|
|
mOverlayImage->SetData(imgData);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
SourceMediaStream* srcStream = GetStream()->AsSourceStream();
|
|
|
|
StreamBuffer::Track* track = srcStream->FindTrack(TRACK_VIDEO_PRIMARY);
|
|
|
|
|
|
|
|
if (!track || !track->GetSegment()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
// Clear the old segment.
|
|
|
|
// Changing the existing content of segment is a Very BAD thing, and this way will
|
|
|
|
// confuse consumers of MediaStreams.
|
|
|
|
// It is only acceptable for DOMHwMediaStream
|
|
|
|
// because DOMHwMediaStream doesn't have consumers of TV streams currently.
|
|
|
|
track->GetSegment()->Clear();
|
|
|
|
|
|
|
|
// Change the image size.
|
|
|
|
const StreamTime delta = STREAM_TIME_MAX;
|
|
|
|
nsRefPtr<Image> image = static_cast<Image*>(mOverlayImage.get());
|
|
|
|
mozilla::gfx::IntSize size = image->GetSize();
|
|
|
|
VideoSegment segment;
|
|
|
|
|
|
|
|
segment.AppendFrame(image.forget(), delta, size);
|
|
|
|
srcStream->AppendToTrack(TRACK_VIDEO_PRIMARY, &segment);
|
|
|
|
#endif
|
|
|
|
}
|
2015-06-18 01:21:00 +03:00
|
|
|
void
|
|
|
|
DOMHwMediaStream::SetOverlayId(int32_t aOverlayId)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
OverlayImage::Data imgData;
|
|
|
|
|
|
|
|
imgData.mOverlayId = aOverlayId;
|
|
|
|
imgData.mSize = mOverlayImage->GetSize();
|
|
|
|
|
|
|
|
mOverlayImage->SetData(imgData);
|
|
|
|
#endif
|
|
|
|
}
|