2012-05-11 17:35:36 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
|
2012-04-30 03:11:34 +00: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 08:01:58 +00:00
|
|
|
#include "DOMMediaStream.h"
|
2012-04-30 03:11:34 +00:00
|
|
|
#include "nsContentUtils.h"
|
2015-02-19 17:59:00 +00:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2015-09-30 01:32:06 +00:00
|
|
|
#include "nsIScriptError.h"
|
2015-02-19 17:59:00 +00:00
|
|
|
#include "nsIUUIDGenerator.h"
|
2015-09-30 01:32:06 +00:00
|
|
|
#include "nsPIDOMWindow.h"
|
2013-02-15 08:04:11 +00:00
|
|
|
#include "mozilla/dom/MediaStreamBinding.h"
|
|
|
|
#include "mozilla/dom/LocalMediaStreamBinding.h"
|
2013-05-21 19:17:47 +00:00
|
|
|
#include "mozilla/dom/AudioNode.h"
|
2015-08-25 08:29:51 +00:00
|
|
|
#include "AudioChannelAgent.h"
|
2014-05-23 09:34:14 +00:00
|
|
|
#include "mozilla/dom/AudioTrack.h"
|
|
|
|
#include "mozilla/dom/AudioTrackList.h"
|
|
|
|
#include "mozilla/dom/VideoTrack.h"
|
|
|
|
#include "mozilla/dom/VideoTrackList.h"
|
2015-05-13 06:04:30 +00:00
|
|
|
#include "mozilla/dom/HTMLCanvasElement.h"
|
2015-12-01 20:27:26 +00:00
|
|
|
#include "mozilla/dom/MediaStreamError.h"
|
2013-02-15 08:04:11 +00:00
|
|
|
#include "MediaStreamGraph.h"
|
2013-04-17 05:18:24 +00:00
|
|
|
#include "AudioStreamTrack.h"
|
|
|
|
#include "VideoStreamTrack.h"
|
2015-06-17 22:21:00 +00:00
|
|
|
#include "Layers.h"
|
2012-04-30 03:11:34 +00:00
|
|
|
|
2015-09-30 01:31:54 +00:00
|
|
|
#ifdef LOG
|
|
|
|
#undef LOG
|
|
|
|
#endif
|
|
|
|
|
2012-04-30 03:11:34 +00:00
|
|
|
using namespace mozilla;
|
2013-04-17 05:18:24 +00:00
|
|
|
using namespace mozilla::dom;
|
2015-06-17 22:21:00 +00:00
|
|
|
using namespace mozilla::layers;
|
|
|
|
|
2015-11-15 13:49:01 +00:00
|
|
|
static LazyLogModule gMediaStreamLog("MediaStream");
|
|
|
|
#define LOG(type, msg) MOZ_LOG(gMediaStreamLog, type, msg)
|
|
|
|
|
2015-06-17 22:21:00 +00:00
|
|
|
const TrackID TRACK_VIDEO_PRIMARY = 1;
|
2012-04-30 03:11:34 +00:00
|
|
|
|
2015-10-22 04:36:22 +00:00
|
|
|
|
|
|
|
DOMMediaStream::TrackPort::TrackPort(MediaInputPort* aInputPort,
|
|
|
|
MediaStreamTrack* aTrack,
|
|
|
|
const InputPortOwnership aOwnership)
|
|
|
|
: mInputPort(aInputPort)
|
|
|
|
, mTrack(aTrack)
|
|
|
|
, mOwnership(aOwnership)
|
2015-09-30 01:31:54 +00:00
|
|
|
{
|
2015-10-22 04:36:23 +00:00
|
|
|
// XXX Bug 1124630. nsDOMCameraControl requires adding a track without and
|
|
|
|
// input port.
|
|
|
|
// MOZ_ASSERT(mInputPort);
|
2015-10-22 04:36:22 +00:00
|
|
|
MOZ_ASSERT(mTrack);
|
2015-09-30 01:31:54 +00:00
|
|
|
|
2015-10-22 04:36:22 +00:00
|
|
|
MOZ_COUNT_CTOR(TrackPort);
|
|
|
|
}
|
2015-09-30 01:31:54 +00:00
|
|
|
|
2015-10-22 04:36:22 +00:00
|
|
|
DOMMediaStream::TrackPort::~TrackPort()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(TrackPort);
|
2015-09-30 01:31:54 +00:00
|
|
|
|
2015-10-22 04:36:22 +00:00
|
|
|
if (mOwnership == InputPortOwnership::OWNED && mInputPort) {
|
|
|
|
mInputPort->Destroy();
|
|
|
|
mInputPort = nullptr;
|
2015-09-30 01:31:54 +00:00
|
|
|
}
|
2015-10-22 04:36:22 +00:00
|
|
|
}
|
2015-09-30 01:31:54 +00:00
|
|
|
|
2015-10-22 04:36:22 +00:00
|
|
|
void
|
|
|
|
DOMMediaStream::TrackPort::DestroyInputPort()
|
|
|
|
{
|
|
|
|
if (mInputPort) {
|
|
|
|
mInputPort->Destroy();
|
|
|
|
mInputPort = nullptr;
|
2015-09-30 01:31:54 +00:00
|
|
|
}
|
2015-10-22 04:36:22 +00:00
|
|
|
}
|
2015-09-30 01:31:54 +00:00
|
|
|
|
2015-10-22 04:36:22 +00:00
|
|
|
MediaStream*
|
|
|
|
DOMMediaStream::TrackPort::GetSource() const
|
|
|
|
{
|
|
|
|
return mInputPort ? mInputPort->GetSource() : nullptr;
|
|
|
|
}
|
2015-09-30 01:32:05 +00:00
|
|
|
|
2015-10-22 04:36:22 +00:00
|
|
|
TrackID
|
|
|
|
DOMMediaStream::TrackPort::GetSourceTrackId() const
|
|
|
|
{
|
|
|
|
return mInputPort ? mInputPort->GetSourceTrackId() : TRACK_INVALID;
|
|
|
|
}
|
2015-09-30 01:31:54 +00:00
|
|
|
|
2015-10-22 04:36:22 +00:00
|
|
|
void
|
|
|
|
DOMMediaStream::TrackPort::BlockTrackId(TrackID aTrackId)
|
|
|
|
{
|
|
|
|
if (mInputPort) {
|
|
|
|
mInputPort->BlockTrackId(aTrackId);
|
|
|
|
}
|
|
|
|
}
|
2015-09-30 01:31:54 +00:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION(DOMMediaStream::TrackPort, mTrack)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(DOMMediaStream::TrackPort, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(DOMMediaStream::TrackPort, Release)
|
|
|
|
|
2015-10-22 04:36:22 +00:00
|
|
|
|
2015-09-30 01:31:54 +00:00
|
|
|
/**
|
2015-09-30 01:31:54 +00:00
|
|
|
* Listener registered on the Owned stream to detect added and ended owned
|
|
|
|
* tracks for keeping the list of MediaStreamTracks in sync with the tracks
|
|
|
|
* added and ended directly at the source.
|
2015-09-30 01:31:54 +00:00
|
|
|
*/
|
2015-09-30 01:31:54 +00:00
|
|
|
class DOMMediaStream::OwnedStreamListener : public MediaStreamListener {
|
2013-04-17 05:18:24 +00:00
|
|
|
public:
|
2015-09-30 01:31:54 +00:00
|
|
|
explicit OwnedStreamListener(DOMMediaStream* aStream)
|
2013-04-17 05:18:24 +00:00
|
|
|
: mStream(aStream)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void Forget() { mStream = nullptr; }
|
2015-09-30 01:31:54 +00:00
|
|
|
|
|
|
|
void DoNotifyTrackCreated(TrackID aTrackId, MediaSegment::Type aType)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (!mStream) {
|
|
|
|
return;
|
2013-04-17 05:18:24 +00:00
|
|
|
}
|
|
|
|
|
2015-09-30 01:31:54 +00:00
|
|
|
MediaStreamTrack* track = mStream->FindOwnedDOMTrack(
|
|
|
|
mStream->GetOwnedStream(), aTrackId);
|
|
|
|
if (track) {
|
|
|
|
// This track has already been manually created. Abort.
|
|
|
|
return;
|
2013-04-17 05:18:24 +00:00
|
|
|
}
|
|
|
|
|
2015-09-30 01:31:54 +00:00
|
|
|
NS_WARN_IF_FALSE(!mStream->mTracks.IsEmpty(),
|
|
|
|
"A new track was detected on the input stream; creating a corresponding MediaStreamTrack. "
|
|
|
|
"Initial tracks should be added manually to immediately and synchronously be available to JS.");
|
2016-01-16 12:39:00 +00:00
|
|
|
mStream->CreateOwnDOMTrack(aTrackId, aType, nsString());
|
2015-09-30 01:31:54 +00:00
|
|
|
}
|
2015-09-25 15:23:18 +00:00
|
|
|
|
2015-09-30 01:31:54 +00:00
|
|
|
void DoNotifyTrackEnded(TrackID aTrackId)
|
2015-09-25 15:23:18 +00:00
|
|
|
{
|
2015-09-30 01:31:54 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (!mStream) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<MediaStreamTrack> track =
|
2015-09-30 01:31:54 +00:00
|
|
|
mStream->FindOwnedDOMTrack(mStream->GetOwnedStream(), aTrackId);
|
|
|
|
NS_ASSERTION(track, "Owned MediaStreamTracks must be known by the DOMMediaStream");
|
|
|
|
if (track) {
|
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p MediaStreamTrack %p ended at the source. Marking it ended.",
|
|
|
|
mStream, track.get()));
|
|
|
|
track->NotifyEnded();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID,
|
|
|
|
StreamTime aTrackOffset, uint32_t aTrackEvents,
|
|
|
|
const MediaSegment& aQueuedMedia,
|
|
|
|
MediaStream* aInputStream,
|
|
|
|
TrackID aInputTrackID) override
|
|
|
|
{
|
|
|
|
if (aTrackEvents & TRACK_EVENT_CREATED) {
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
|
|
|
NS_NewRunnableMethodWithArgs<TrackID, MediaSegment::Type>(
|
|
|
|
this, &OwnedStreamListener::DoNotifyTrackCreated,
|
|
|
|
aID, aQueuedMedia.GetType());
|
|
|
|
aGraph->DispatchToMainThreadAfterStreamStateUpdate(runnable.forget());
|
|
|
|
} else if (aTrackEvents & TRACK_EVENT_ENDED) {
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
|
|
|
NS_NewRunnableMethodWithArgs<TrackID>(
|
|
|
|
this, &OwnedStreamListener::DoNotifyTrackEnded, aID);
|
2014-11-20 18:10:00 +00:00
|
|
|
aGraph->DispatchToMainThreadAfterStreamStateUpdate(runnable.forget());
|
2013-04-17 05:18:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-30 01:31:54 +00:00
|
|
|
private:
|
|
|
|
// These fields may only be accessed on the main thread
|
|
|
|
DOMMediaStream* mStream;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Listener registered on the Playback stream to detect when tracks end and when
|
|
|
|
* all new tracks this iteration have been created - for when several tracks are
|
|
|
|
* queued by the source and committed all at once.
|
|
|
|
*/
|
|
|
|
class DOMMediaStream::PlaybackStreamListener : public MediaStreamListener {
|
|
|
|
public:
|
|
|
|
explicit PlaybackStreamListener(DOMMediaStream* aStream)
|
|
|
|
: mStream(aStream)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void Forget()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mStream = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoNotifyTrackEnded(MediaStream* aInputStream,
|
|
|
|
TrackID aInputTrackID)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (!mStream) {
|
|
|
|
return;
|
2015-02-06 09:38:11 +00:00
|
|
|
}
|
|
|
|
|
2015-09-30 01:31:54 +00:00
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p Track %u of stream %p ended",
|
|
|
|
mStream, aInputTrackID, aInputStream));
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<MediaStreamTrack> track =
|
2015-09-30 01:31:54 +00:00
|
|
|
mStream->FindPlaybackDOMTrack(aInputStream, aInputTrackID);
|
2015-09-30 01:31:54 +00:00
|
|
|
if (!track) {
|
2015-09-30 01:31:54 +00:00
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p Not a playback track.", mStream));
|
2015-09-30 01:31:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p Playback track; notifying stream listeners.",
|
|
|
|
mStream));
|
|
|
|
mStream->NotifyTrackRemoved(track);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<TrackPort> endedPort = mStream->FindPlaybackTrackPort(*track);
|
2015-09-30 01:31:54 +00:00
|
|
|
NS_ASSERTION(endedPort, "Playback track should have a TrackPort");
|
|
|
|
if (endedPort &&
|
|
|
|
endedPort->GetSourceTrackId() != TRACK_ANY &&
|
|
|
|
endedPort->GetSourceTrackId() != TRACK_INVALID &&
|
|
|
|
endedPort->GetSourceTrackId() != TRACK_NONE) {
|
|
|
|
// If a track connected to a locked-track input port ends, we destroy the
|
|
|
|
// port to allow our playback stream to finish.
|
|
|
|
// XXX (bug 1208316) This should not be necessary when MediaStreams don't
|
|
|
|
// finish but instead become inactive.
|
|
|
|
endedPort->DestroyInputPort();
|
2015-09-30 01:31:54 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-25 15:23:18 +00:00
|
|
|
|
2015-09-30 01:31:54 +00:00
|
|
|
void DoNotifyFinishedTrackCreation()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-09-25 15:23:18 +00:00
|
|
|
|
2015-09-30 01:31:54 +00:00
|
|
|
if (!mStream) {
|
|
|
|
return;
|
2015-09-25 15:23:18 +00:00
|
|
|
}
|
2015-02-06 09:38:11 +00:00
|
|
|
|
2015-09-30 01:31:54 +00:00
|
|
|
mStream->NotifyTracksCreated();
|
|
|
|
}
|
|
|
|
|
|
|
|
// The methods below are called on the MediaStreamGraph thread.
|
2015-09-25 15:23:18 +00:00
|
|
|
|
2015-09-30 01:31:54 +00:00
|
|
|
void NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID,
|
|
|
|
StreamTime aTrackOffset, uint32_t aTrackEvents,
|
|
|
|
const MediaSegment& aQueuedMedia,
|
|
|
|
MediaStream* aInputStream,
|
|
|
|
TrackID aInputTrackID) override
|
2015-09-25 15:23:18 +00:00
|
|
|
{
|
2015-09-30 01:31:54 +00:00
|
|
|
if (aTrackEvents & TRACK_EVENT_ENDED) {
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
|
|
|
NS_NewRunnableMethodWithArgs<StorensRefPtrPassByPtr<MediaStream>, TrackID>(
|
|
|
|
this, &PlaybackStreamListener::DoNotifyTrackEnded, aInputStream, aInputTrackID);
|
|
|
|
aGraph->DispatchToMainThreadAfterStreamStateUpdate(runnable.forget());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NotifyFinishedTrackCreation(MediaStreamGraph* aGraph) override
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
|
|
|
NS_NewRunnableMethod(this, &PlaybackStreamListener::DoNotifyFinishedTrackCreation);
|
2015-02-06 09:38:11 +00:00
|
|
|
aGraph->DispatchToMainThreadAfterStreamStateUpdate(runnable.forget());
|
|
|
|
}
|
|
|
|
|
2013-04-17 05:18:24 +00:00
|
|
|
private:
|
|
|
|
// These fields may only be accessed on the main thread
|
|
|
|
DOMMediaStream* mStream;
|
|
|
|
};
|
|
|
|
|
2014-11-01 23:56:10 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(DOMMediaStream)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(DOMMediaStream,
|
|
|
|
DOMEventTargetHelper)
|
2014-11-10 15:26:00 +00:00
|
|
|
tmp->Destroy();
|
2014-11-01 23:56:10 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow)
|
2015-09-30 01:31:54 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mOwnedTracks)
|
2014-11-01 23:56:10 +00:00
|
|
|
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)
|
2015-09-30 01:31:54 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOwnedTracks)
|
2014-11-01 23:56:10 +00:00
|
|
|
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 05:18:24 +00:00
|
|
|
DOMMediaStream::DOMMediaStream()
|
2015-09-30 01:31:54 +00:00
|
|
|
: mLogicalStreamStartTime(0), mInputStream(nullptr), mOwnedStream(nullptr),
|
|
|
|
mPlaybackStream(nullptr), mOwnedPort(nullptr), mPlaybackPort(nullptr),
|
|
|
|
mTracksCreated(false), mNotifiedOfMediaStreamGraphShutdown(false),
|
|
|
|
mCORSMode(CORS_NONE)
|
2013-04-17 05:18:24 +00:00
|
|
|
{
|
2015-02-19 17:59:00 +00: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 05:18:24 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 08:01:58 +00:00
|
|
|
DOMMediaStream::~DOMMediaStream()
|
2013-05-01 11:24:16 +00:00
|
|
|
{
|
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMMediaStream::Destroy()
|
2012-04-30 03:11:34 +00:00
|
|
|
{
|
2015-09-30 01:31:54 +00:00
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p Being destroyed.", this));
|
2015-09-30 01:31:54 +00:00
|
|
|
if (mOwnedListener) {
|
|
|
|
mOwnedListener->Forget();
|
|
|
|
mOwnedListener = nullptr;
|
|
|
|
}
|
|
|
|
if (mPlaybackListener) {
|
|
|
|
mPlaybackListener->Forget();
|
|
|
|
mPlaybackListener = nullptr;
|
2015-09-25 15:23:18 +00:00
|
|
|
}
|
2015-09-30 01:31:54 +00:00
|
|
|
if (mPlaybackPort) {
|
|
|
|
mPlaybackPort->Destroy();
|
|
|
|
mPlaybackPort = nullptr;
|
|
|
|
}
|
|
|
|
if (mOwnedPort) {
|
|
|
|
mOwnedPort->Destroy();
|
|
|
|
mOwnedPort = nullptr;
|
|
|
|
}
|
|
|
|
if (mPlaybackStream) {
|
|
|
|
mPlaybackStream->Destroy();
|
|
|
|
mPlaybackStream = nullptr;
|
|
|
|
}
|
|
|
|
if (mOwnedStream) {
|
|
|
|
mOwnedStream->Destroy();
|
|
|
|
mOwnedStream = nullptr;
|
|
|
|
}
|
|
|
|
if (mInputStream) {
|
|
|
|
mInputStream->Destroy();
|
|
|
|
mInputStream = nullptr;
|
2012-04-30 03:11:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-15 08:04:11 +00: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 14:13:33 +00:00
|
|
|
DOMMediaStream::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2012-04-30 03:11:34 +00: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 14:13:33 +00:00
|
|
|
return dom::MediaStreamBinding::Wrap(aCx, this, aGivenProto);
|
2012-04-30 03:11:34 +00:00
|
|
|
}
|
|
|
|
|
2015-10-14 17:08:33 +00:00
|
|
|
/* static */ already_AddRefed<DOMMediaStream>
|
|
|
|
DOMMediaStream::Constructor(const GlobalObject& aGlobal,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
Sequence<OwningNonNull<MediaStreamTrack>> emptyTrackSeq;
|
|
|
|
return Constructor(aGlobal, emptyTrackSeq, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ already_AddRefed<DOMMediaStream>
|
|
|
|
DOMMediaStream::Constructor(const GlobalObject& aGlobal,
|
|
|
|
const DOMMediaStream& aStream,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
nsTArray<RefPtr<MediaStreamTrack>> tracks;
|
2015-10-14 17:08:33 +00:00
|
|
|
aStream.GetTracks(tracks);
|
|
|
|
|
|
|
|
Sequence<OwningNonNull<MediaStreamTrack>> nonNullTrackSeq;
|
|
|
|
if (!nonNullTrackSeq.SetLength(tracks.Length(), fallible)) {
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < tracks.Length(); ++i) {
|
|
|
|
nonNullTrackSeq[i] = tracks[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return Constructor(aGlobal, nonNullTrackSeq, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ already_AddRefed<DOMMediaStream>
|
|
|
|
DOMMediaStream::Constructor(const GlobalObject& aGlobal,
|
|
|
|
const Sequence<OwningNonNull<MediaStreamTrack>>& aTracks,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMWindow> ownerWindow = do_QueryInterface(aGlobal.GetAsSupports());
|
|
|
|
if (!ownerWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DOMMediaStream> newStream = new DOMMediaStream();
|
2015-10-14 17:08:33 +00:00
|
|
|
newStream->mWindow = ownerWindow;
|
|
|
|
|
|
|
|
for (MediaStreamTrack& track : aTracks) {
|
|
|
|
if (!newStream->GetPlaybackStream()) {
|
|
|
|
MOZ_RELEASE_ASSERT(track.GetStream());
|
|
|
|
MOZ_RELEASE_ASSERT(track.GetStream()->GetPlaybackStream());
|
|
|
|
MOZ_RELEASE_ASSERT(track.GetStream()->GetPlaybackStream()->Graph());
|
|
|
|
MediaStreamGraph* graph = track.GetStream()->GetPlaybackStream()->Graph();
|
|
|
|
newStream->InitPlaybackStreamCommon(graph);
|
|
|
|
}
|
|
|
|
newStream->AddTrack(track);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!newStream->GetPlaybackStream()) {
|
|
|
|
MOZ_ASSERT(aTracks.IsEmpty());
|
|
|
|
MediaStreamGraph* graph =
|
|
|
|
MediaStreamGraph::GetInstance(MediaStreamGraph::SYSTEM_THREAD_DRIVER,
|
|
|
|
AudioChannel::Normal);
|
|
|
|
newStream->InitPlaybackStreamCommon(graph);
|
|
|
|
}
|
|
|
|
|
|
|
|
return newStream.forget();
|
|
|
|
}
|
|
|
|
|
2013-02-15 08:04:11 +00:00
|
|
|
double
|
|
|
|
DOMMediaStream::CurrentTime()
|
2013-01-07 02:31:34 +00:00
|
|
|
{
|
2015-09-30 01:31:54 +00:00
|
|
|
if (!mPlaybackStream) {
|
2013-05-03 05:07:37 +00:00
|
|
|
return 0.0;
|
|
|
|
}
|
2015-09-30 01:31:54 +00:00
|
|
|
return mPlaybackStream->
|
|
|
|
StreamTimeToSeconds(mPlaybackStream->GetCurrentTime() - mLogicalStreamStartTime);
|
2013-01-07 02:31:34 +00:00
|
|
|
}
|
|
|
|
|
2015-02-05 16:03:00 +00:00
|
|
|
void
|
|
|
|
DOMMediaStream::GetId(nsAString& aID) const
|
|
|
|
{
|
|
|
|
aID = mID;
|
|
|
|
}
|
|
|
|
|
2013-04-17 05:18:37 +00:00
|
|
|
void
|
2015-10-18 05:24:48 +00:00
|
|
|
DOMMediaStream::GetAudioTracks(nsTArray<RefPtr<AudioStreamTrack> >& aTracks) const
|
2013-04-17 05:18:37 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
for (const RefPtr<TrackPort>& info : mTracks) {
|
2015-09-30 01:31:54 +00:00
|
|
|
AudioStreamTrack* t = info->GetTrack()->AsAudioStreamTrack();
|
2013-04-17 05:18:37 +00:00
|
|
|
if (t) {
|
|
|
|
aTracks.AppendElement(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-10-18 05:24:48 +00:00
|
|
|
DOMMediaStream::GetVideoTracks(nsTArray<RefPtr<VideoStreamTrack> >& aTracks) const
|
2013-04-17 05:18:37 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
for (const RefPtr<TrackPort>& info : mTracks) {
|
2015-09-30 01:31:54 +00:00
|
|
|
VideoStreamTrack* t = info->GetTrack()->AsVideoStreamTrack();
|
2013-04-17 05:18:37 +00:00
|
|
|
if (t) {
|
|
|
|
aTracks.AppendElement(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-14 01:40:54 +00:00
|
|
|
void
|
2015-10-18 05:24:48 +00:00
|
|
|
DOMMediaStream::GetTracks(nsTArray<RefPtr<MediaStreamTrack> >& aTracks) const
|
2014-08-14 01:40:54 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
for (const RefPtr<TrackPort>& info : mTracks) {
|
2015-09-30 01:31:54 +00:00
|
|
|
aTracks.AppendElement(info->GetTrack());
|
|
|
|
}
|
2014-08-14 01:40:54 +00:00
|
|
|
}
|
|
|
|
|
2015-09-30 01:32:05 +00:00
|
|
|
void
|
|
|
|
DOMMediaStream::AddTrack(MediaStreamTrack& aTrack)
|
|
|
|
{
|
2015-10-14 17:08:32 +00:00
|
|
|
MOZ_RELEASE_ASSERT(mPlaybackStream);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ProcessedMediaStream> dest = mPlaybackStream->AsProcessedStream();
|
2015-09-30 01:32:05 +00:00
|
|
|
MOZ_ASSERT(dest);
|
|
|
|
if (!dest) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(LogLevel::Info, ("DOMMediaStream %p Adding track %p (from stream %p with ID %d)",
|
|
|
|
this, &aTrack, aTrack.GetStream(), aTrack.GetTrackID()));
|
|
|
|
|
2015-10-14 17:08:33 +00:00
|
|
|
if (mPlaybackStream->Graph() !=
|
|
|
|
aTrack.GetStream()->mPlaybackStream->Graph()) {
|
|
|
|
NS_ASSERTION(false, "Cannot combine tracks from different MediaStreamGraphs");
|
|
|
|
LOG(LogLevel::Error, ("DOMMediaStream %p Own MSG %p != aTrack's MSG %p",
|
|
|
|
this, mPlaybackStream->Graph(),
|
|
|
|
aTrack.GetStream()->mPlaybackStream->Graph()));
|
|
|
|
|
|
|
|
nsAutoString trackId;
|
|
|
|
aTrack.GetId(trackId);
|
|
|
|
const char16_t* params[] = { trackId.get() };
|
|
|
|
nsCOMPtr<nsPIDOMWindow> pWindow = do_QueryInterface(GetParentObject());
|
|
|
|
nsIDocument* document = pWindow ? pWindow->GetExtantDoc() : nullptr;
|
|
|
|
nsContentUtils::ReportToConsole(nsIScriptError::errorFlag,
|
|
|
|
NS_LITERAL_CSTRING("Media"),
|
|
|
|
document,
|
|
|
|
nsContentUtils::eDOM_PROPERTIES,
|
|
|
|
"MediaStreamAddTrackDifferentAudioChannel",
|
|
|
|
params, ArrayLength(params));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-30 01:32:05 +00:00
|
|
|
if (HasTrack(aTrack)) {
|
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p already contains track %p", this, &aTrack));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DOMMediaStream> addedDOMStream = aTrack.GetStream();
|
2015-09-30 01:32:05 +00:00
|
|
|
MOZ_RELEASE_ASSERT(addedDOMStream);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<MediaStream> owningStream = addedDOMStream->GetOwnedStream();
|
2015-09-30 01:32:05 +00:00
|
|
|
MOZ_RELEASE_ASSERT(owningStream);
|
|
|
|
|
|
|
|
CombineWithPrincipal(addedDOMStream->mPrincipal);
|
|
|
|
|
|
|
|
// Hook up the underlying track with our underlying playback stream.
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<MediaInputPort> inputPort =
|
2015-09-30 01:32:05 +00:00
|
|
|
GetPlaybackStream()->AllocateInputPort(owningStream, aTrack.GetTrackID());
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<TrackPort> trackPort =
|
2015-09-30 01:32:05 +00:00
|
|
|
new TrackPort(inputPort, &aTrack, TrackPort::InputPortOwnership::OWNED);
|
|
|
|
mTracks.AppendElement(trackPort.forget());
|
2015-09-30 01:32:06 +00:00
|
|
|
NotifyTrackAdded(&aTrack);
|
2015-09-30 01:32:05 +00:00
|
|
|
|
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p Added track %p", this, &aTrack));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMMediaStream::RemoveTrack(MediaStreamTrack& aTrack)
|
|
|
|
{
|
|
|
|
LOG(LogLevel::Info, ("DOMMediaStream %p Removing track %p (from stream %p with ID %d)",
|
|
|
|
this, &aTrack, aTrack.GetStream(), aTrack.GetTrackID()));
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<TrackPort> toRemove = FindPlaybackTrackPort(aTrack);
|
2015-09-30 01:32:05 +00:00
|
|
|
if (!toRemove) {
|
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p does not contain track %p", this, &aTrack));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the track comes from a TRACK_ANY input port (i.e., mOwnedPort), we need
|
|
|
|
// to block it in the port. Doing this for a locked track is still OK as it
|
|
|
|
// will first block the track, then destroy the port. Both cause the track to
|
|
|
|
// end.
|
|
|
|
toRemove->BlockTrackId(aTrack.GetTrackID());
|
|
|
|
|
|
|
|
DebugOnly<bool> removed = mTracks.RemoveElement(toRemove);
|
|
|
|
MOZ_ASSERT(removed);
|
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p Removed track %p", this, &aTrack));
|
|
|
|
}
|
|
|
|
|
2014-08-14 01:40:54 +00:00
|
|
|
bool
|
|
|
|
DOMMediaStream::HasTrack(const MediaStreamTrack& aTrack) const
|
|
|
|
{
|
2015-09-30 01:32:05 +00:00
|
|
|
return !!FindPlaybackTrackPort(aTrack);
|
2015-09-30 01:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DOMMediaStream::OwnsTrack(const MediaStreamTrack& aTrack) const
|
|
|
|
{
|
|
|
|
return (aTrack.GetStream() == this) && HasTrack(aTrack);
|
2014-08-14 01:40:54 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 08:04:11 +00:00
|
|
|
bool
|
|
|
|
DOMMediaStream::IsFinished()
|
2012-10-24 23:21:32 +00:00
|
|
|
{
|
2015-09-30 01:31:54 +00:00
|
|
|
return !mPlaybackStream || mPlaybackStream->IsFinished();
|
2012-10-24 23:21:32 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 08:04:11 +00:00
|
|
|
void
|
2015-03-31 02:14:00 +00:00
|
|
|
DOMMediaStream::InitSourceStream(nsIDOMWindow* aWindow,
|
|
|
|
MediaStreamGraph* aGraph)
|
2012-04-30 03:11:40 +00:00
|
|
|
{
|
2013-02-15 08:04:11 +00:00
|
|
|
mWindow = aWindow;
|
2015-10-14 17:08:32 +00:00
|
|
|
InitInputStreamCommon(aGraph->CreateSourceStream(nullptr), aGraph);
|
|
|
|
InitOwnedStreamCommon(aGraph);
|
|
|
|
InitPlaybackStreamCommon(aGraph);
|
2012-04-30 03:11:40 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 08:04:11 +00:00
|
|
|
void
|
2015-03-31 02:14:00 +00:00
|
|
|
DOMMediaStream::InitTrackUnionStream(nsIDOMWindow* aWindow,
|
|
|
|
MediaStreamGraph* aGraph)
|
2012-10-24 23:21:32 +00:00
|
|
|
{
|
2013-02-15 08:04:11 +00:00
|
|
|
mWindow = aWindow;
|
2015-10-14 17:08:32 +00:00
|
|
|
InitInputStreamCommon(aGraph->CreateTrackUnionStream(nullptr), aGraph);
|
|
|
|
InitOwnedStreamCommon(aGraph);
|
|
|
|
InitPlaybackStreamCommon(aGraph);
|
2013-04-17 05:18:24 +00:00
|
|
|
}
|
|
|
|
|
2015-07-24 12:28:16 +00:00
|
|
|
void
|
|
|
|
DOMMediaStream::InitAudioCaptureStream(nsIDOMWindow* aWindow,
|
|
|
|
MediaStreamGraph* aGraph)
|
|
|
|
{
|
|
|
|
mWindow = aWindow;
|
|
|
|
|
2015-09-30 01:31:53 +00:00
|
|
|
const TrackID AUDIO_TRACK = 1;
|
|
|
|
|
2015-10-14 17:08:32 +00:00
|
|
|
InitInputStreamCommon(aGraph->CreateAudioCaptureStream(this, AUDIO_TRACK), aGraph);
|
|
|
|
InitOwnedStreamCommon(aGraph);
|
|
|
|
InitPlaybackStreamCommon(aGraph);
|
2016-01-16 12:39:00 +00:00
|
|
|
CreateOwnDOMTrack(AUDIO_TRACK, MediaSegment::AUDIO, nsString());
|
2015-07-24 12:28:16 +00:00
|
|
|
}
|
|
|
|
|
2013-04-17 05:18:24 +00:00
|
|
|
void
|
2015-10-14 17:08:32 +00:00
|
|
|
DOMMediaStream::InitInputStreamCommon(MediaStream* aStream,
|
|
|
|
MediaStreamGraph* aGraph)
|
2013-04-17 05:18:24 +00:00
|
|
|
{
|
2015-10-14 17:08:32 +00:00
|
|
|
MOZ_ASSERT(!mOwnedStream, "Input stream must be initialized before owned stream");
|
|
|
|
|
2015-09-30 01:31:54 +00:00
|
|
|
mInputStream = aStream;
|
2015-10-14 17:08:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMMediaStream::InitOwnedStreamCommon(MediaStreamGraph* aGraph)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mPlaybackStream, "Owned stream must be initialized before playback stream");
|
2015-09-30 01:31:54 +00:00
|
|
|
|
|
|
|
// We pass null as the wrapper since it is only used to signal finished
|
|
|
|
// streams. This is only needed for the playback stream.
|
|
|
|
mOwnedStream = aGraph->CreateTrackUnionStream(nullptr);
|
|
|
|
mOwnedStream->SetAutofinish(true);
|
2015-10-14 17:08:32 +00:00
|
|
|
if (mInputStream) {
|
|
|
|
mOwnedPort = mOwnedStream->AllocateInputPort(mInputStream);
|
|
|
|
}
|
2015-09-30 01:31:54 +00:00
|
|
|
|
2015-09-30 01:31:54 +00:00
|
|
|
// Setup track listeners
|
|
|
|
mOwnedListener = new OwnedStreamListener(this);
|
|
|
|
mOwnedStream->AddListener(mOwnedListener);
|
2015-10-14 17:08:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMMediaStream::InitPlaybackStreamCommon(MediaStreamGraph* aGraph)
|
|
|
|
{
|
|
|
|
mPlaybackStream = aGraph->CreateTrackUnionStream(this);
|
|
|
|
mPlaybackStream->SetAutofinish(true);
|
|
|
|
if (mOwnedStream) {
|
|
|
|
mPlaybackPort = mPlaybackStream->AllocateInputPort(mOwnedStream);
|
|
|
|
}
|
|
|
|
|
2015-09-30 01:31:54 +00:00
|
|
|
mPlaybackListener = new PlaybackStreamListener(this);
|
|
|
|
mPlaybackStream->AddListener(mPlaybackListener);
|
2015-10-14 17:08:32 +00:00
|
|
|
|
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p Initiated with mInputStream=%p, mOwnedStream=%p, mPlaybackStream=%p",
|
|
|
|
this, mInputStream, mOwnedStream, mPlaybackStream));
|
2012-10-24 23:21:32 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 08:01:58 +00:00
|
|
|
already_AddRefed<DOMMediaStream>
|
2015-03-31 02:14:00 +00:00
|
|
|
DOMMediaStream::CreateSourceStream(nsIDOMWindow* aWindow,
|
|
|
|
MediaStreamGraph* aGraph)
|
2012-07-31 12:17:22 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DOMMediaStream> stream = new DOMMediaStream();
|
2015-03-31 02:14:00 +00:00
|
|
|
stream->InitSourceStream(aWindow, aGraph);
|
2012-07-31 12:17:22 +00:00
|
|
|
return stream.forget();
|
|
|
|
}
|
|
|
|
|
2013-02-15 08:04:11 +00:00
|
|
|
already_AddRefed<DOMMediaStream>
|
2015-03-31 02:14:00 +00:00
|
|
|
DOMMediaStream::CreateTrackUnionStream(nsIDOMWindow* aWindow,
|
|
|
|
MediaStreamGraph* aGraph)
|
2012-10-24 23:21:32 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DOMMediaStream> stream = new DOMMediaStream();
|
2015-03-31 02:14:00 +00:00
|
|
|
stream->InitTrackUnionStream(aWindow, aGraph);
|
2012-10-24 23:21:32 +00:00
|
|
|
return stream.forget();
|
|
|
|
}
|
|
|
|
|
2015-07-24 12:28:16 +00:00
|
|
|
already_AddRefed<DOMMediaStream>
|
|
|
|
DOMMediaStream::CreateAudioCaptureStream(nsIDOMWindow* aWindow,
|
|
|
|
MediaStreamGraph* aGraph)
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DOMMediaStream> stream = new DOMMediaStream();
|
2015-07-24 12:28:16 +00:00
|
|
|
stream->InitAudioCaptureStream(aWindow, aGraph);
|
|
|
|
return stream.forget();
|
|
|
|
}
|
|
|
|
|
2013-08-26 06:07:19 +00:00
|
|
|
void
|
|
|
|
DOMMediaStream::SetTrackEnabled(TrackID aTrackID, bool aEnabled)
|
|
|
|
{
|
2015-10-30 06:13:15 +00:00
|
|
|
// XXX Bug 1208371 - This enables/disables the track across clones.
|
|
|
|
if (mInputStream) {
|
|
|
|
mInputStream->SetTrackEnabled(aTrackID, aEnabled);
|
2013-08-26 06:07:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-27 05:03:49 +00:00
|
|
|
void
|
|
|
|
DOMMediaStream::StopTrack(TrackID aTrackID)
|
|
|
|
{
|
2015-09-30 01:31:54 +00:00
|
|
|
if (mInputStream && mInputStream->AsSourceStream()) {
|
|
|
|
mInputStream->AsSourceStream()->EndTrack(aTrackID);
|
2014-08-27 05:03:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-20 22:45:57 +00:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
DOMMediaStream::ApplyConstraintsToTrack(TrackID aTrackID,
|
|
|
|
const MediaTrackConstraints& aConstraints,
|
|
|
|
ErrorResult &aRv)
|
|
|
|
{
|
2015-12-01 20:27:26 +00:00
|
|
|
nsCOMPtr<nsIGlobalObject> go = do_QueryInterface(mWindow);
|
|
|
|
RefPtr<Promise> promise = Promise::Create(go, aRv);
|
|
|
|
MOZ_RELEASE_ASSERT(!aRv.Failed());
|
|
|
|
|
|
|
|
promise->MaybeReject(new MediaStreamError(
|
|
|
|
static_cast<nsPIDOMWindow*>(mWindow.get()),
|
|
|
|
NS_LITERAL_STRING("OverconstrainedError"),
|
|
|
|
NS_LITERAL_STRING(""),
|
|
|
|
NS_LITERAL_STRING("")));
|
|
|
|
return promise.forget();
|
2015-09-20 22:45:57 +00:00
|
|
|
}
|
|
|
|
|
2012-04-30 03:11:34 +00:00
|
|
|
bool
|
2013-02-15 08:01:58 +00:00
|
|
|
DOMMediaStream::CombineWithPrincipal(nsIPrincipal* aPrincipal)
|
2012-04-30 03:11:34 +00:00
|
|
|
{
|
2014-04-25 14:30:00 +00:00
|
|
|
bool changed =
|
|
|
|
nsContentUtils::CombineResourcePrincipals(&mPrincipal, aPrincipal);
|
|
|
|
if (changed) {
|
|
|
|
NotifyPrincipalChanged();
|
|
|
|
}
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMMediaStream::SetPrincipal(nsIPrincipal* aPrincipal)
|
|
|
|
{
|
|
|
|
mPrincipal = aPrincipal;
|
|
|
|
NotifyPrincipalChanged();
|
|
|
|
}
|
|
|
|
|
2014-12-17 17:03:34 +00:00
|
|
|
void
|
|
|
|
DOMMediaStream::SetCORSMode(CORSMode aCORSMode)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mCORSMode = aCORSMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
CORSMode
|
|
|
|
DOMMediaStream::GetCORSMode()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
return mCORSMode;
|
|
|
|
}
|
|
|
|
|
2014-04-25 14:30:00 +00: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 03:11:34 +00:00
|
|
|
}
|
2013-02-15 08:04:11 +00:00
|
|
|
|
2013-04-17 05:18:24 +00:00
|
|
|
MediaStreamTrack*
|
2016-01-16 12:39:00 +00:00
|
|
|
DOMMediaStream::CreateOwnDOMTrack(TrackID aTrackID, MediaSegment::Type aType, const nsString& aLabel)
|
2013-04-17 05:18:24 +00:00
|
|
|
{
|
2015-10-14 17:08:32 +00:00
|
|
|
MOZ_RELEASE_ASSERT(mInputStream);
|
|
|
|
MOZ_RELEASE_ASSERT(mOwnedStream);
|
|
|
|
|
2015-09-30 01:31:54 +00:00
|
|
|
MOZ_ASSERT(FindOwnedDOMTrack(GetOwnedStream(), aTrackID) == nullptr);
|
|
|
|
|
2013-04-17 05:18:24 +00:00
|
|
|
MediaStreamTrack* track;
|
|
|
|
switch (aType) {
|
|
|
|
case MediaSegment::AUDIO:
|
2016-01-16 12:39:00 +00:00
|
|
|
track = new AudioStreamTrack(this, aTrackID, aLabel);
|
2013-04-17 05:18:24 +00:00
|
|
|
break;
|
|
|
|
case MediaSegment::VIDEO:
|
2016-01-16 12:39:00 +00:00
|
|
|
track = new VideoStreamTrack(this, aTrackID, aLabel);
|
2013-04-17 05:18:24 +00:00
|
|
|
break;
|
|
|
|
default:
|
2013-06-29 01:38:30 +00:00
|
|
|
MOZ_CRASH("Unhandled track type");
|
2013-04-17 05:18:24 +00:00
|
|
|
}
|
2013-05-03 05:02:55 +00:00
|
|
|
|
2015-09-30 01:31:54 +00:00
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p Created new track %p with ID %u", this, track, aTrackID));
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<TrackPort> ownedTrackPort =
|
2015-09-30 01:31:54 +00:00
|
|
|
new TrackPort(mOwnedPort, track, TrackPort::InputPortOwnership::EXTERNAL);
|
|
|
|
mOwnedTracks.AppendElement(ownedTrackPort.forget());
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<TrackPort> playbackTrackPort =
|
2015-09-30 01:31:54 +00:00
|
|
|
new TrackPort(mPlaybackPort, track, TrackPort::InputPortOwnership::EXTERNAL);
|
|
|
|
mTracks.AppendElement(playbackTrackPort.forget());
|
|
|
|
|
2015-09-30 01:32:06 +00:00
|
|
|
NotifyTrackAdded(track);
|
2014-10-13 03:13:36 +00:00
|
|
|
return track;
|
|
|
|
}
|
2013-05-03 05:02:55 +00:00
|
|
|
|
2014-10-13 03:13:36 +00:00
|
|
|
MediaStreamTrack*
|
2015-09-30 01:31:54 +00:00
|
|
|
DOMMediaStream::FindOwnedDOMTrack(MediaStream* aOwningStream, TrackID aTrackID) const
|
2014-10-13 03:13:36 +00:00
|
|
|
{
|
2015-10-14 17:08:32 +00:00
|
|
|
MOZ_RELEASE_ASSERT(mOwnedStream);
|
|
|
|
|
2015-09-30 01:31:54 +00:00
|
|
|
if (aOwningStream != mOwnedStream) {
|
|
|
|
return nullptr;
|
2014-10-13 03:13:36 +00:00
|
|
|
}
|
2015-09-30 01:31:54 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
for (const RefPtr<TrackPort>& info : mOwnedTracks) {
|
2015-09-30 01:31:54 +00:00
|
|
|
if (info->GetTrack()->GetTrackID() == aTrackID) {
|
|
|
|
return info->GetTrack();
|
2014-10-13 03:13:36 +00:00
|
|
|
}
|
2015-09-25 20:08:55 +00:00
|
|
|
}
|
2015-09-30 01:31:54 +00:00
|
|
|
return nullptr;
|
2013-04-17 05:18:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MediaStreamTrack*
|
2015-09-30 01:31:54 +00:00
|
|
|
DOMMediaStream::FindPlaybackDOMTrack(MediaStream* aInputStream, TrackID aInputTrackID) const
|
|
|
|
{
|
2015-10-14 17:08:32 +00:00
|
|
|
MOZ_RELEASE_ASSERT(mPlaybackStream);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
for (const RefPtr<TrackPort>& info : mTracks) {
|
2015-09-30 01:31:54 +00:00
|
|
|
if (info->GetInputPort() == mPlaybackPort &&
|
|
|
|
aInputStream == mOwnedStream &&
|
|
|
|
aInputTrackID == info->GetTrack()->GetTrackID()) {
|
|
|
|
// This track is in our owned and playback streams.
|
|
|
|
return info->GetTrack();
|
|
|
|
}
|
2015-10-14 17:08:33 +00:00
|
|
|
if (info->GetInputPort() &&
|
|
|
|
info->GetInputPort()->GetSource() == aInputStream &&
|
2015-09-30 01:31:54 +00:00
|
|
|
info->GetSourceTrackId() == aInputTrackID) {
|
|
|
|
// This track is owned externally but in our playback stream.
|
|
|
|
MOZ_ASSERT(aInputTrackID != TRACK_NONE);
|
|
|
|
MOZ_ASSERT(aInputTrackID != TRACK_INVALID);
|
|
|
|
MOZ_ASSERT(aInputTrackID != TRACK_ANY);
|
|
|
|
return info->GetTrack();
|
2013-04-17 05:18:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-09-30 01:32:05 +00:00
|
|
|
DOMMediaStream::TrackPort*
|
|
|
|
DOMMediaStream::FindPlaybackTrackPort(const MediaStreamTrack& aTrack) const
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
for (const RefPtr<TrackPort>& info : mTracks) {
|
2015-09-30 01:32:05 +00:00
|
|
|
if (info->GetTrack() == &aTrack) {
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-05-03 05:02:55 +00:00
|
|
|
void
|
|
|
|
DOMMediaStream::NotifyMediaStreamGraphShutdown()
|
|
|
|
{
|
|
|
|
// No more tracks will ever be added, so just clear these callbacks now
|
|
|
|
// to prevent leaks.
|
|
|
|
mNotifiedOfMediaStreamGraphShutdown = true;
|
|
|
|
mRunOnTracksAvailable.Clear();
|
2015-09-30 01:32:06 +00:00
|
|
|
mTrackListeners.Clear();
|
2013-07-25 02:07:34 +00:00
|
|
|
mConsumersToKeepAlive.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-05-11 14:07:24 +00:00
|
|
|
DOMMediaStream::NotifyStreamFinished()
|
2013-07-25 02:07:34 +00:00
|
|
|
{
|
2015-05-11 14:07:24 +00:00
|
|
|
MOZ_ASSERT(IsFinished());
|
|
|
|
mConsumersToKeepAlive.Clear();
|
2013-05-03 05:02:55 +00: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 09:38:11 +00:00
|
|
|
void
|
2015-09-30 01:32:06 +00:00
|
|
|
DOMMediaStream::NotifyTracksCreated()
|
2015-02-06 09:38:11 +00:00
|
|
|
{
|
|
|
|
mTracksCreated = true;
|
|
|
|
CheckTracksAvailable();
|
|
|
|
}
|
|
|
|
|
2013-05-03 05:02:55 +00:00
|
|
|
void
|
|
|
|
DOMMediaStream::CheckTracksAvailable()
|
|
|
|
{
|
2015-02-06 09:38:11 +00:00
|
|
|
if (!mTracksCreated) {
|
2013-11-22 20:14:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-05-03 05:02:55 +00:00
|
|
|
nsTArray<nsAutoPtr<OnTracksAvailableCallback> > callbacks;
|
|
|
|
callbacks.SwapElements(mRunOnTracksAvailable);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < callbacks.Length(); ++i) {
|
2015-02-09 07:23:34 +00:00
|
|
|
callbacks[i]->NotifyTracksAvailable(this);
|
2013-05-03 05:02:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-30 01:31:54 +00:00
|
|
|
void
|
2015-09-30 01:32:06 +00:00
|
|
|
DOMMediaStream::RegisterTrackListener(TrackListener* aListener)
|
2015-09-30 01:31:54 +00:00
|
|
|
{
|
2015-09-30 01:32:06 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-09-25 20:08:44 +00:00
|
|
|
|
2015-09-30 01:32:06 +00:00
|
|
|
if (mNotifiedOfMediaStreamGraphShutdown) {
|
|
|
|
// No more tracks will ever be added, so just do nothing.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mTrackListeners.AppendElement(aListener);
|
2014-05-23 09:34:14 +00:00
|
|
|
}
|
|
|
|
|
2015-09-30 01:32:06 +00:00
|
|
|
void
|
|
|
|
DOMMediaStream::UnregisterTrackListener(TrackListener* aListener)
|
2014-05-23 09:34:14 +00:00
|
|
|
{
|
2015-09-30 01:32:06 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mTrackListeners.RemoveElement(aListener);
|
2014-05-23 09:34:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-09-30 01:32:06 +00:00
|
|
|
DOMMediaStream::NotifyTrackAdded(
|
2015-10-18 05:24:48 +00:00
|
|
|
const RefPtr<MediaStreamTrack>& aTrack)
|
2014-05-23 09:34:14 +00:00
|
|
|
{
|
2015-09-30 01:32:06 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-09-25 20:08:44 +00:00
|
|
|
|
2015-09-30 01:32:06 +00:00
|
|
|
for (int32_t i = mTrackListeners.Length() - 1; i >= 0; --i) {
|
2015-10-18 05:24:48 +00:00
|
|
|
const RefPtr<TrackListener>& listener = mTrackListeners[i];
|
2015-09-30 01:32:06 +00:00
|
|
|
listener->NotifyTrackAdded(aTrack);
|
2014-10-03 21:29:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-23 09:34:14 +00:00
|
|
|
void
|
2015-09-30 01:32:06 +00:00
|
|
|
DOMMediaStream::NotifyTrackRemoved(
|
2015-10-18 05:24:48 +00:00
|
|
|
const RefPtr<MediaStreamTrack>& aTrack)
|
2014-05-23 09:34:14 +00:00
|
|
|
{
|
2015-09-30 01:32:06 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-12-12 03:54:12 +00:00
|
|
|
|
2015-09-30 01:32:06 +00:00
|
|
|
for (int32_t i = mTrackListeners.Length() - 1; i >= 0; --i) {
|
2015-10-18 05:24:48 +00:00
|
|
|
const RefPtr<TrackListener>& listener = mTrackListeners[i];
|
2015-09-30 01:32:06 +00:00
|
|
|
listener->NotifyTrackRemoved(aTrack);
|
2014-05-23 09:34:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-09-30 01:32:06 +00:00
|
|
|
DOMMediaStream::CreateAndAddPlaybackStreamListener(MediaStream* aStream)
|
2014-05-23 09:34:14 +00:00
|
|
|
{
|
2015-09-30 01:32:06 +00:00
|
|
|
MOZ_ASSERT(GetCameraStream(), "I'm a hack. Only DOMCameraControl may use me.");
|
|
|
|
mPlaybackListener = new PlaybackStreamListener(this);
|
|
|
|
aStream->AddListener(mPlaybackListener);
|
2014-05-23 09:34:14 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 08:04:11 +00:00
|
|
|
DOMLocalMediaStream::~DOMLocalMediaStream()
|
|
|
|
{
|
2015-09-30 01:31:54 +00:00
|
|
|
if (mInputStream) {
|
2013-02-15 08:04:11 +00:00
|
|
|
// Make sure Listeners of this stream know it's going away
|
2015-09-30 01:32:06 +00:00
|
|
|
StopImpl();
|
2013-02-15 08:04:11 +00: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 14:13:33 +00:00
|
|
|
DOMLocalMediaStream::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-02-15 08:04:11 +00: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 14:13:33 +00:00
|
|
|
return dom::LocalMediaStreamBinding::Wrap(aCx, this, aGivenProto);
|
2013-02-15 08:04:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMLocalMediaStream::Stop()
|
2015-09-30 01:32:06 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> pWindow = do_QueryInterface(GetParentObject());
|
|
|
|
nsIDocument* document = pWindow ? pWindow->GetExtantDoc() : nullptr;
|
|
|
|
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
|
|
|
|
NS_LITERAL_CSTRING("Media"),
|
|
|
|
document,
|
|
|
|
nsContentUtils::eDOM_PROPERTIES,
|
|
|
|
"MediaStreamStopDeprecatedWarning");
|
|
|
|
|
|
|
|
StopImpl();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMLocalMediaStream::StopImpl()
|
2013-02-15 08:04:11 +00:00
|
|
|
{
|
2015-09-30 01:31:54 +00:00
|
|
|
if (mInputStream && mInputStream->AsSourceStream()) {
|
|
|
|
mInputStream->AsSourceStream()->EndAllTrackAndFinish();
|
2013-02-15 08:04:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMLocalMediaStream>
|
2015-03-31 02:14:00 +00:00
|
|
|
DOMLocalMediaStream::CreateSourceStream(nsIDOMWindow* aWindow,
|
|
|
|
MediaStreamGraph* aGraph)
|
2013-02-15 08:04:11 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DOMLocalMediaStream> stream = new DOMLocalMediaStream();
|
2015-03-31 02:14:00 +00:00
|
|
|
stream->InitSourceStream(aWindow, aGraph);
|
2013-02-15 08:04:11 +00:00
|
|
|
return stream.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMLocalMediaStream>
|
2015-03-31 02:14:00 +00:00
|
|
|
DOMLocalMediaStream::CreateTrackUnionStream(nsIDOMWindow* aWindow,
|
|
|
|
MediaStreamGraph* aGraph)
|
2013-02-15 08:04:11 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DOMLocalMediaStream> stream = new DOMLocalMediaStream();
|
2015-03-31 02:14:00 +00:00
|
|
|
stream->InitTrackUnionStream(aWindow, aGraph);
|
2013-02-15 08:04:11 +00:00
|
|
|
return stream.forget();
|
|
|
|
}
|
2013-05-21 19:17:47 +00:00
|
|
|
|
2015-07-24 12:28:16 +00:00
|
|
|
already_AddRefed<DOMLocalMediaStream>
|
|
|
|
DOMLocalMediaStream::CreateAudioCaptureStream(nsIDOMWindow* aWindow,
|
|
|
|
MediaStreamGraph* aGraph)
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DOMLocalMediaStream> stream = new DOMLocalMediaStream();
|
2015-07-24 12:28:16 +00:00
|
|
|
stream->InitAudioCaptureStream(aWindow, aGraph);
|
|
|
|
return stream.forget();
|
|
|
|
}
|
|
|
|
|
2013-05-21 19:17:47 +00:00
|
|
|
DOMAudioNodeMediaStream::DOMAudioNodeMediaStream(AudioNode* aNode)
|
|
|
|
: mStreamNode(aNode)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-06-24 14:21:21 +00:00
|
|
|
DOMAudioNodeMediaStream::~DOMAudioNodeMediaStream()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-21 19:17:47 +00:00
|
|
|
already_AddRefed<DOMAudioNodeMediaStream>
|
|
|
|
DOMAudioNodeMediaStream::CreateTrackUnionStream(nsIDOMWindow* aWindow,
|
2015-03-31 02:14:00 +00:00
|
|
|
AudioNode* aNode,
|
|
|
|
MediaStreamGraph* aGraph)
|
2013-05-21 19:17:47 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DOMAudioNodeMediaStream> stream = new DOMAudioNodeMediaStream(aNode);
|
2015-03-31 02:14:00 +00:00
|
|
|
stream->InitTrackUnionStream(aWindow, aGraph);
|
2013-05-21 19:17:47 +00:00
|
|
|
return stream.forget();
|
|
|
|
}
|
2015-05-13 06:04:30 +00:00
|
|
|
|
2015-06-17 22:21:00 +00:00
|
|
|
DOMHwMediaStream::DOMHwMediaStream()
|
|
|
|
{
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2015-12-29 09:07:33 +00:00
|
|
|
mImageContainer = LayerManager::CreateImageContainer(ImageContainer::ASYNCHRONOUS);
|
2015-11-17 08:09:01 +00:00
|
|
|
mOverlayImage = mImageContainer->CreateOverlayImage();
|
2015-07-06 21:58:18 +00:00
|
|
|
nsAutoTArray<ImageContainer::NonOwningImage,1> images;
|
2015-11-17 08:09:01 +00:00
|
|
|
images.AppendElement(ImageContainer::NonOwningImage(mOverlayImage));
|
2015-07-06 21:58:18 +00:00
|
|
|
mImageContainer->SetCurrentImages(images);
|
2015-06-17 22:21:00 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHwMediaStream::~DOMHwMediaStream()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMHwMediaStream>
|
|
|
|
DOMHwMediaStream::CreateHwStream(nsIDOMWindow* aWindow)
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DOMHwMediaStream> stream = new DOMHwMediaStream();
|
2015-08-25 08:29:51 +00:00
|
|
|
|
|
|
|
MediaStreamGraph* graph =
|
|
|
|
MediaStreamGraph::GetInstance(MediaStreamGraph::SYSTEM_THREAD_DRIVER,
|
|
|
|
AudioChannel::Normal);
|
|
|
|
stream->InitSourceStream(aWindow, graph);
|
2015-09-30 01:31:54 +00:00
|
|
|
stream->Init(stream->GetInputStream());
|
2015-06-17 22:21:00 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Image> image = static_cast<Image*>(mOverlayImage.get());
|
2015-06-17 22:21:00 +00:00
|
|
|
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 01:11:00 +00: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
|
|
|
|
|
2015-09-30 01:31:54 +00:00
|
|
|
SourceMediaStream* srcStream = GetInputStream()->AsSourceStream();
|
2015-06-15 01:11:00 +00:00
|
|
|
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;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Image> image = static_cast<Image*>(mOverlayImage.get());
|
2015-06-15 01:11:00 +00:00
|
|
|
mozilla::gfx::IntSize size = image->GetSize();
|
|
|
|
VideoSegment segment;
|
|
|
|
|
|
|
|
segment.AppendFrame(image.forget(), delta, size);
|
|
|
|
srcStream->AppendToTrack(TRACK_VIDEO_PRIMARY, &segment);
|
|
|
|
#endif
|
|
|
|
}
|
2015-06-17 22:21:00 +00: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
|
|
|
|
}
|