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"
|
2015-09-30 04:32:06 +03:00
|
|
|
#include "nsIScriptError.h"
|
2015-02-19 20:59:00 +03:00
|
|
|
#include "nsIUUIDGenerator.h"
|
2015-09-30 04:32:06 +03:00
|
|
|
#include "nsPIDOMWindow.h"
|
2013-02-15 12:04:11 +04:00
|
|
|
#include "mozilla/dom/MediaStreamBinding.h"
|
2016-05-31 10:29:52 +03:00
|
|
|
#include "mozilla/dom/MediaStreamTrackEvent.h"
|
2013-02-15 12:04:11 +04:00
|
|
|
#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"
|
2016-03-16 18:00:34 +03:00
|
|
|
#include "mozilla/media/MediaUtils.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
|
|
|
|
2016-03-19 05:21:23 +03:00
|
|
|
// GetCurrentTime is defined in winbase.h as zero argument macro forwarding to
|
|
|
|
// GetTickCount() and conflicts with NS_DECL_NSIDOMMEDIASTREAM, containing
|
|
|
|
// currentTime getter.
|
|
|
|
#ifdef GetCurrentTime
|
|
|
|
#undef GetCurrentTime
|
|
|
|
#endif
|
|
|
|
|
2015-09-30 04:31:54 +03:00
|
|
|
#ifdef LOG
|
|
|
|
#undef LOG
|
|
|
|
#endif
|
|
|
|
|
2016-01-22 12:23:10 +03:00
|
|
|
// GetCurrentTime is defined in winbase.h as zero argument macro forwarding to
|
|
|
|
// GetTickCount() and conflicts with MediaStream::GetCurrentTime.
|
|
|
|
#ifdef GetCurrentTime
|
|
|
|
#undef GetCurrentTime
|
|
|
|
#endif
|
|
|
|
|
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;
|
2016-03-16 18:00:34 +03:00
|
|
|
using namespace mozilla::media;
|
2015-06-18 01:21:00 +03:00
|
|
|
|
2015-11-15 16:49:01 +03:00
|
|
|
static LazyLogModule gMediaStreamLog("MediaStream");
|
|
|
|
#define LOG(type, msg) MOZ_LOG(gMediaStreamLog, type, msg)
|
|
|
|
|
2015-06-18 01:21:00 +03:00
|
|
|
const TrackID TRACK_VIDEO_PRIMARY = 1;
|
2012-04-30 07:11:34 +04:00
|
|
|
|
2016-09-15 15:18:22 +03:00
|
|
|
static bool
|
|
|
|
ContainsLiveTracks(nsTArray<RefPtr<DOMMediaStream::TrackPort>>& aTracks)
|
|
|
|
{
|
|
|
|
for (auto& port : aTracks) {
|
|
|
|
if (port->GetTrack()->ReadyState() == MediaStreamTrackState::Live) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-22 07:36:22 +03:00
|
|
|
|
|
|
|
DOMMediaStream::TrackPort::TrackPort(MediaInputPort* aInputPort,
|
|
|
|
MediaStreamTrack* aTrack,
|
|
|
|
const InputPortOwnership aOwnership)
|
|
|
|
: mInputPort(aInputPort)
|
|
|
|
, mTrack(aTrack)
|
|
|
|
, mOwnership(aOwnership)
|
2015-09-30 04:31:54 +03:00
|
|
|
{
|
2016-10-04 21:16:28 +03:00
|
|
|
MOZ_ASSERT(mInputPort);
|
2015-10-22 07:36:22 +03:00
|
|
|
MOZ_ASSERT(mTrack);
|
2015-09-30 04:31:54 +03:00
|
|
|
|
2015-10-22 07:36:22 +03:00
|
|
|
MOZ_COUNT_CTOR(TrackPort);
|
|
|
|
}
|
2015-09-30 04:31:54 +03:00
|
|
|
|
2015-10-22 07:36:22 +03:00
|
|
|
DOMMediaStream::TrackPort::~TrackPort()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(TrackPort);
|
2015-09-30 04:31:54 +03:00
|
|
|
|
2016-04-25 06:48:10 +03:00
|
|
|
if (mOwnership == InputPortOwnership::OWNED) {
|
|
|
|
DestroyInputPort();
|
2015-09-30 04:31:54 +03:00
|
|
|
}
|
2015-10-22 07:36:22 +03:00
|
|
|
}
|
2015-09-30 04:31:54 +03:00
|
|
|
|
2015-10-22 07:36:22 +03:00
|
|
|
void
|
|
|
|
DOMMediaStream::TrackPort::DestroyInputPort()
|
|
|
|
{
|
|
|
|
if (mInputPort) {
|
|
|
|
mInputPort->Destroy();
|
|
|
|
mInputPort = nullptr;
|
2015-09-30 04:31:54 +03:00
|
|
|
}
|
2015-10-22 07:36:22 +03:00
|
|
|
}
|
2015-09-30 04:31:54 +03:00
|
|
|
|
2015-10-22 07:36:22 +03:00
|
|
|
MediaStream*
|
|
|
|
DOMMediaStream::TrackPort::GetSource() const
|
|
|
|
{
|
|
|
|
return mInputPort ? mInputPort->GetSource() : nullptr;
|
|
|
|
}
|
2015-09-30 04:32:05 +03:00
|
|
|
|
2015-10-22 07:36:22 +03:00
|
|
|
TrackID
|
|
|
|
DOMMediaStream::TrackPort::GetSourceTrackId() const
|
|
|
|
{
|
|
|
|
return mInputPort ? mInputPort->GetSourceTrackId() : TRACK_INVALID;
|
|
|
|
}
|
2015-09-30 04:31:54 +03:00
|
|
|
|
2016-03-16 18:00:34 +03:00
|
|
|
already_AddRefed<Pledge<bool>>
|
2016-06-07 17:20:29 +03:00
|
|
|
DOMMediaStream::TrackPort::BlockSourceTrackId(TrackID aTrackId, BlockingMode aBlockingMode)
|
2015-10-22 07:36:22 +03:00
|
|
|
{
|
|
|
|
if (mInputPort) {
|
2016-06-07 17:20:29 +03:00
|
|
|
return mInputPort->BlockSourceTrackId(aTrackId, aBlockingMode);
|
2015-10-22 07:36:22 +03:00
|
|
|
}
|
2016-03-16 18:00:34 +03:00
|
|
|
RefPtr<Pledge<bool>> rejected = new Pledge<bool>();
|
|
|
|
rejected->Reject(NS_ERROR_FAILURE);
|
|
|
|
return rejected.forget();
|
2015-10-22 07:36:22 +03:00
|
|
|
}
|
2015-09-30 04:31:54 +03: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)
|
|
|
|
|
2016-01-05 05:16:21 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(MediaStreamTrackSourceGetter)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(MediaStreamTrackSourceGetter)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MediaStreamTrackSourceGetter)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_0(MediaStreamTrackSourceGetter)
|
2015-10-22 07:36:22 +03:00
|
|
|
|
2015-09-30 04:31:54 +03:00
|
|
|
/**
|
2015-09-30 04:31:54 +03: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 04:31:54 +03:00
|
|
|
*/
|
2015-09-30 04:31:54 +03:00
|
|
|
class DOMMediaStream::OwnedStreamListener : public MediaStreamListener {
|
2013-04-17 09:18:24 +04:00
|
|
|
public:
|
2015-09-30 04:31:54 +03:00
|
|
|
explicit OwnedStreamListener(DOMMediaStream* aStream)
|
2013-04-17 09:18:24 +04:00
|
|
|
: mStream(aStream)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void Forget() { mStream = nullptr; }
|
2015-09-30 04:31:54 +03:00
|
|
|
|
2016-01-05 05:16:22 +03:00
|
|
|
void DoNotifyTrackCreated(TrackID aTrackID, MediaSegment::Type aType,
|
|
|
|
MediaStream* aInputStream, TrackID aInputTrackID)
|
2015-09-30 04:31:54 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (!mStream) {
|
|
|
|
return;
|
2013-04-17 09:18:24 +04:00
|
|
|
}
|
|
|
|
|
2016-01-05 05:16:22 +03:00
|
|
|
MediaStreamTrack* track =
|
2016-05-24 14:26:25 +03:00
|
|
|
mStream->FindOwnedDOMTrack(aInputStream, aInputTrackID, aTrackID);
|
2016-08-23 18:51:50 +03:00
|
|
|
|
|
|
|
if (track) {
|
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p Track %d from owned stream %p "
|
|
|
|
"bound to MediaStreamTrack %p.",
|
|
|
|
mStream, aTrackID, aInputStream, track));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Track had not been created on main thread before, create it now.
|
2016-09-01 08:01:16 +03:00
|
|
|
NS_WARNING_ASSERTION(
|
|
|
|
!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-08-23 18:51:50 +03:00
|
|
|
RefPtr<MediaStreamTrackSource> source;
|
|
|
|
if (mStream->mTrackSourceGetter) {
|
|
|
|
source = mStream->mTrackSourceGetter->GetMediaStreamTrackSource(aTrackID);
|
2013-04-17 09:18:24 +04:00
|
|
|
}
|
2016-08-23 18:51:50 +03:00
|
|
|
if (!source) {
|
|
|
|
NS_ASSERTION(false, "Dynamic track created without an explicit TrackSource");
|
|
|
|
nsPIDOMWindowInner* window = mStream->GetParentObject();
|
|
|
|
nsIDocument* doc = window ? window->GetExtantDoc() : nullptr;
|
|
|
|
nsIPrincipal* principal = doc ? doc->NodePrincipal() : nullptr;
|
2016-09-16 16:19:28 +03:00
|
|
|
source = new BasicTrackSource(principal);
|
2016-08-23 18:51:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<MediaStreamTrack> newTrack =
|
|
|
|
mStream->CreateDOMTrack(aTrackID, aType, source);
|
2016-08-22 13:23:37 +03:00
|
|
|
NS_DispatchToMainThread(NewRunnableMethod<RefPtr<MediaStreamTrack>>(
|
|
|
|
mStream, &DOMMediaStream::AddTrackInternal, newTrack));
|
2015-09-30 04:31:54 +03:00
|
|
|
}
|
2015-09-25 18:23:18 +03:00
|
|
|
|
2016-05-24 14:26:25 +03:00
|
|
|
void DoNotifyTrackEnded(MediaStream* aInputStream, TrackID aInputTrackID,
|
|
|
|
TrackID aTrackID)
|
2015-09-25 18:23:18 +03:00
|
|
|
{
|
2015-09-30 04:31:54 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (!mStream) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MediaStreamTrack> track =
|
2016-05-24 14:26:25 +03:00
|
|
|
mStream->FindOwnedDOMTrack(aInputStream, aInputTrackID, aTrackID);
|
2015-09-30 04:31:54 +03:00
|
|
|
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()));
|
2016-09-08 12:06:21 +03:00
|
|
|
track->OverrideEnded();
|
2015-09-30 04:31:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID,
|
2016-06-30 10:07:48 +03:00
|
|
|
StreamTime aTrackOffset, TrackEventCommand aTrackEvents,
|
2015-09-30 04:31:54 +03:00
|
|
|
const MediaSegment& aQueuedMedia,
|
|
|
|
MediaStream* aInputStream,
|
|
|
|
TrackID aInputTrackID) override
|
|
|
|
{
|
2016-06-30 10:07:48 +03:00
|
|
|
if (aTrackEvents & TrackEventCommand::TRACK_EVENT_CREATED) {
|
2015-09-30 04:31:54 +03:00
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
2016-08-18 19:24:50 +03:00
|
|
|
NewRunnableMethod<TrackID, MediaSegment::Type, RefPtr<MediaStream>, TrackID>(
|
2015-09-30 04:31:54 +03:00
|
|
|
this, &OwnedStreamListener::DoNotifyTrackCreated,
|
2016-01-05 05:16:22 +03:00
|
|
|
aID, aQueuedMedia.GetType(), aInputStream, aInputTrackID);
|
2015-09-30 04:31:54 +03:00
|
|
|
aGraph->DispatchToMainThreadAfterStreamStateUpdate(runnable.forget());
|
2016-06-30 10:07:48 +03:00
|
|
|
} else if (aTrackEvents & TrackEventCommand::TRACK_EVENT_ENDED) {
|
2015-09-30 04:31:54 +03:00
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
2016-08-18 19:24:50 +03:00
|
|
|
NewRunnableMethod<RefPtr<MediaStream>, TrackID, TrackID>(
|
2016-01-05 05:16:22 +03:00
|
|
|
this, &OwnedStreamListener::DoNotifyTrackEnded,
|
2016-05-24 14:26:25 +03:00
|
|
|
aInputStream, aInputTrackID, aID);
|
2014-11-20 21:10:00 +03:00
|
|
|
aGraph->DispatchToMainThreadAfterStreamStateUpdate(runnable.forget());
|
2013-04-17 09:18:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-30 04:31:54 +03: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;
|
|
|
|
}
|
|
|
|
|
2016-09-23 18:03:13 +03:00
|
|
|
void DoNotifyFinishedTrackCreation()
|
2015-09-30 04:31:54 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (!mStream) {
|
|
|
|
return;
|
2015-02-06 12:38:11 +03:00
|
|
|
}
|
|
|
|
|
2016-09-23 18:03:13 +03:00
|
|
|
// The owned stream listener adds its tracks after another main thread
|
|
|
|
// dispatch. We have to do the same to notify of created tracks to stay
|
|
|
|
// in sync. (Or NotifyTracksCreated is called before tracks are added).
|
|
|
|
NS_DispatchToMainThread(
|
|
|
|
NewRunnableMethod(mStream, &DOMMediaStream::NotifyTracksCreated));
|
2015-09-30 04:31:54 +03:00
|
|
|
}
|
2015-09-25 18:23:18 +03:00
|
|
|
|
2016-09-23 18:03:13 +03:00
|
|
|
void DoNotifyFinished()
|
2015-09-30 04:31:54 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-09-25 18:23:18 +03:00
|
|
|
|
2015-09-30 04:31:54 +03:00
|
|
|
if (!mStream) {
|
|
|
|
return;
|
2015-09-25 18:23:18 +03:00
|
|
|
}
|
2015-02-06 12:38:11 +03:00
|
|
|
|
2016-09-23 18:03:13 +03:00
|
|
|
mStream->NotifyFinished();
|
2015-09-30 04:31:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// The methods below are called on the MediaStreamGraph thread.
|
2015-09-25 18:23:18 +03:00
|
|
|
|
2015-09-30 04:31:54 +03:00
|
|
|
void NotifyFinishedTrackCreation(MediaStreamGraph* aGraph) override
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
2016-05-05 11:45:00 +03:00
|
|
|
NewRunnableMethod(this, &PlaybackStreamListener::DoNotifyFinishedTrackCreation);
|
2015-02-06 12:38:11 +03:00
|
|
|
aGraph->DispatchToMainThreadAfterStreamStateUpdate(runnable.forget());
|
|
|
|
}
|
|
|
|
|
2016-09-15 15:18:22 +03:00
|
|
|
|
|
|
|
void NotifyEvent(MediaStreamGraph* aGraph,
|
|
|
|
MediaStreamGraphEvent event) override
|
|
|
|
{
|
|
|
|
if (event == MediaStreamGraphEvent::EVENT_FINISHED) {
|
|
|
|
aGraph->DispatchToMainThreadAfterStreamStateUpdate(
|
|
|
|
NewRunnableMethod(this, &PlaybackStreamListener::DoNotifyFinished));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-17 09:18:24 +04:00
|
|
|
private:
|
|
|
|
// These fields may only be accessed on the main thread
|
|
|
|
DOMMediaStream* mStream;
|
|
|
|
};
|
|
|
|
|
2016-09-23 18:03:13 +03:00
|
|
|
class DOMMediaStream::PlaybackTrackListener : public MediaStreamTrackConsumer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit PlaybackTrackListener(DOMMediaStream* aStream) :
|
|
|
|
mStream(aStream) {}
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PlaybackTrackListener,
|
|
|
|
MediaStreamTrackConsumer)
|
|
|
|
|
|
|
|
void NotifyEnded(MediaStreamTrack* aTrack) override
|
|
|
|
{
|
|
|
|
if (!mStream) {
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aTrack) {
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(mStream->HasTrack(*aTrack));
|
|
|
|
mStream->NotifyTrackRemoved(aTrack);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~PlaybackTrackListener() {}
|
|
|
|
|
|
|
|
RefPtr<DOMMediaStream> mStream;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(DOMMediaStream::PlaybackTrackListener,
|
|
|
|
MediaStreamTrackConsumer)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(DOMMediaStream::PlaybackTrackListener,
|
|
|
|
MediaStreamTrackConsumer)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DOMMediaStream::PlaybackTrackListener)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(MediaStreamTrackConsumer)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(DOMMediaStream::PlaybackTrackListener,
|
|
|
|
MediaStreamTrackConsumer,
|
|
|
|
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)
|
2015-09-30 04:31:54 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mOwnedTracks)
|
2014-11-02 02:56:10 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mTracks)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mConsumersToKeepAlive)
|
2016-01-05 05:16:21 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mTrackSourceGetter)
|
2016-09-23 18:03:13 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPlaybackTrackListener)
|
2016-03-16 18:00:34 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPrincipal)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mVideoPrincipal)
|
2014-11-02 02:56:10 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(DOMMediaStream,
|
|
|
|
DOMEventTargetHelper)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
|
2015-09-30 04:31:54 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOwnedTracks)
|
2014-11-02 02:56:10 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTracks)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mConsumersToKeepAlive)
|
2016-01-05 05:16:21 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTrackSourceGetter)
|
2016-09-23 18:03:13 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPlaybackTrackListener)
|
2016-03-16 18:00:34 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPrincipal)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVideoPrincipal)
|
2014-11-02 02:56:10 +03:00
|
|
|
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)
|
|
|
|
|
2016-01-05 05:16:21 +03:00
|
|
|
DOMMediaStream::DOMMediaStream(nsPIDOMWindowInner* aWindow,
|
|
|
|
MediaStreamTrackSourceGetter* aTrackSourceGetter)
|
2016-01-05 05:16:20 +03:00
|
|
|
: mLogicalStreamStartTime(0), mWindow(aWindow),
|
|
|
|
mInputStream(nullptr), mOwnedStream(nullptr), mPlaybackStream(nullptr),
|
2016-03-16 18:00:34 +03:00
|
|
|
mTracksPendingRemoval(0), mTrackSourceGetter(aTrackSourceGetter),
|
2016-09-23 18:03:13 +03:00
|
|
|
mPlaybackTrackListener(MakeAndAddRef<PlaybackTrackListener>(this)),
|
2016-09-08 14:44:49 +03:00
|
|
|
mTracksCreated(false), mNotifiedOfMediaStreamGraphShutdown(false),
|
2016-09-15 15:18:22 +03:00
|
|
|
mActive(false), mSetInactiveOnFinish(false)
|
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
|
|
|
{
|
2015-09-30 04:31:54 +03:00
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p Being destroyed.", this));
|
2015-09-30 04:31:54 +03:00
|
|
|
if (mOwnedListener) {
|
|
|
|
mOwnedListener->Forget();
|
|
|
|
mOwnedListener = nullptr;
|
|
|
|
}
|
|
|
|
if (mPlaybackListener) {
|
|
|
|
mPlaybackListener->Forget();
|
|
|
|
mPlaybackListener = nullptr;
|
2015-09-25 18:23:18 +03:00
|
|
|
}
|
2016-03-16 18:08:43 +03:00
|
|
|
for (const RefPtr<TrackPort>& info : mTracks) {
|
|
|
|
// We must remove ourselves from each track's principal change observer list
|
|
|
|
// before we die. CC may have cleared info->mTrack so guard against it.
|
2016-09-23 18:03:13 +03:00
|
|
|
MediaStreamTrack* track = info->GetTrack();
|
|
|
|
if (track) {
|
|
|
|
track->RemovePrincipalChangeObserver(this);
|
|
|
|
if (!track->Ended()) {
|
|
|
|
track->RemoveConsumer(mPlaybackTrackListener);
|
|
|
|
}
|
2016-03-16 18:08:43 +03:00
|
|
|
}
|
|
|
|
}
|
2015-09-30 04:31:54 +03:00
|
|
|
if (mPlaybackPort) {
|
|
|
|
mPlaybackPort->Destroy();
|
|
|
|
mPlaybackPort = nullptr;
|
|
|
|
}
|
|
|
|
if (mOwnedPort) {
|
|
|
|
mOwnedPort->Destroy();
|
|
|
|
mOwnedPort = nullptr;
|
|
|
|
}
|
|
|
|
if (mPlaybackStream) {
|
2016-01-22 11:51:37 +03:00
|
|
|
mPlaybackStream->UnregisterUser();
|
2015-09-30 04:31:54 +03:00
|
|
|
mPlaybackStream = nullptr;
|
|
|
|
}
|
|
|
|
if (mOwnedStream) {
|
2016-01-22 11:51:37 +03:00
|
|
|
mOwnedStream->UnregisterUser();
|
2015-09-30 04:31:54 +03:00
|
|
|
mOwnedStream = nullptr;
|
|
|
|
}
|
|
|
|
if (mInputStream) {
|
2016-01-22 11:51:37 +03:00
|
|
|
mInputStream->UnregisterUser();
|
2015-09-30 04:31:54 +03:00
|
|
|
mInputStream = nullptr;
|
2012-04-30 07:11:34 +04:00
|
|
|
}
|
2016-06-29 13:27:13 +03:00
|
|
|
mRunOnTracksAvailable.Clear();
|
|
|
|
mTrackListeners.Clear();
|
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
|
|
|
}
|
|
|
|
|
2015-10-14 20:08:33 +03: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 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<MediaStreamTrack>> tracks;
|
2015-10-14 20:08:33 +03: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)
|
|
|
|
{
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> ownerWindow = do_QueryInterface(aGlobal.GetAsSupports());
|
2015-10-14 20:08:33 +03:00
|
|
|
if (!ownerWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-01-05 05:16:21 +03:00
|
|
|
// Streams created from JS cannot have dynamically created tracks.
|
|
|
|
MediaStreamTrackSourceGetter* getter = nullptr;
|
|
|
|
RefPtr<DOMMediaStream> newStream = new DOMMediaStream(ownerWindow, getter);
|
2015-10-14 20:08:33 +03:00
|
|
|
|
|
|
|
for (MediaStreamTrack& track : aTracks) {
|
|
|
|
if (!newStream->GetPlaybackStream()) {
|
2016-01-05 05:16:23 +03:00
|
|
|
MOZ_RELEASE_ASSERT(track.Graph());
|
|
|
|
newStream->InitPlaybackStreamCommon(track.Graph());
|
2015-10-14 20:08:33 +03:00
|
|
|
}
|
|
|
|
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 12:04:11 +04:00
|
|
|
double
|
|
|
|
DOMMediaStream::CurrentTime()
|
2013-01-07 06:31:34 +04:00
|
|
|
{
|
2015-09-30 04:31:54 +03:00
|
|
|
if (!mPlaybackStream) {
|
2013-05-03 09:07:37 +04:00
|
|
|
return 0.0;
|
|
|
|
}
|
2015-09-30 04:31:54 +03:00
|
|
|
return mPlaybackStream->
|
|
|
|
StreamTimeToSeconds(mPlaybackStream->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
|
2015-10-18 08:24:48 +03:00
|
|
|
DOMMediaStream::GetAudioTracks(nsTArray<RefPtr<AudioStreamTrack> >& aTracks) const
|
2013-04-17 09:18:37 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
for (const RefPtr<TrackPort>& info : mTracks) {
|
2015-09-30 04:31:54 +03:00
|
|
|
AudioStreamTrack* t = info->GetTrack()->AsAudioStreamTrack();
|
2013-04-17 09:18:37 +04:00
|
|
|
if (t) {
|
|
|
|
aTracks.AppendElement(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-10-18 08:24:48 +03:00
|
|
|
DOMMediaStream::GetVideoTracks(nsTArray<RefPtr<VideoStreamTrack> >& aTracks) const
|
2013-04-17 09:18:37 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
for (const RefPtr<TrackPort>& info : mTracks) {
|
2015-09-30 04:31:54 +03:00
|
|
|
VideoStreamTrack* t = info->GetTrack()->AsVideoStreamTrack();
|
2013-04-17 09:18:37 +04:00
|
|
|
if (t) {
|
|
|
|
aTracks.AppendElement(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-14 05:40:54 +04:00
|
|
|
void
|
2015-10-18 08:24:48 +03:00
|
|
|
DOMMediaStream::GetTracks(nsTArray<RefPtr<MediaStreamTrack> >& aTracks) const
|
2014-08-14 05:40:54 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
for (const RefPtr<TrackPort>& info : mTracks) {
|
2015-09-30 04:31:54 +03:00
|
|
|
aTracks.AppendElement(info->GetTrack());
|
|
|
|
}
|
2014-08-14 05:40:54 +04:00
|
|
|
}
|
|
|
|
|
2015-09-30 04:32:05 +03:00
|
|
|
void
|
|
|
|
DOMMediaStream::AddTrack(MediaStreamTrack& aTrack)
|
|
|
|
{
|
2015-10-14 20:08:32 +03:00
|
|
|
MOZ_RELEASE_ASSERT(mPlaybackStream);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ProcessedMediaStream> dest = mPlaybackStream->AsProcessedStream();
|
2015-09-30 04:32:05 +03:00
|
|
|
MOZ_ASSERT(dest);
|
|
|
|
if (!dest) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(LogLevel::Info, ("DOMMediaStream %p Adding track %p (from stream %p with ID %d)",
|
2016-02-01 17:48:05 +03:00
|
|
|
this, &aTrack, aTrack.mOwningStream.get(), aTrack.mTrackID));
|
2015-09-30 04:32:05 +03:00
|
|
|
|
2016-01-05 05:16:23 +03:00
|
|
|
if (mPlaybackStream->Graph() != aTrack.Graph()) {
|
2015-10-14 20:08:33 +03:00
|
|
|
NS_ASSERTION(false, "Cannot combine tracks from different MediaStreamGraphs");
|
|
|
|
LOG(LogLevel::Error, ("DOMMediaStream %p Own MSG %p != aTrack's MSG %p",
|
2016-01-05 05:16:23 +03:00
|
|
|
this, mPlaybackStream->Graph(), aTrack.Graph()));
|
2015-10-14 20:08:33 +03:00
|
|
|
|
|
|
|
nsAutoString trackId;
|
|
|
|
aTrack.GetId(trackId);
|
|
|
|
const char16_t* params[] = { trackId.get() };
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> pWindow = GetParentObject();
|
2015-10-14 20:08:33 +03:00
|
|
|
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 04:32:05 +03:00
|
|
|
if (HasTrack(aTrack)) {
|
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p already contains track %p", this, &aTrack));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hook up the underlying track with our underlying playback stream.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MediaInputPort> inputPort =
|
2016-03-16 18:08:43 +03:00
|
|
|
GetPlaybackStream()->AllocateInputPort(aTrack.GetOwnedStream(),
|
2016-02-01 17:48:05 +03:00
|
|
|
aTrack.mTrackID);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TrackPort> trackPort =
|
2015-09-30 04:32:05 +03:00
|
|
|
new TrackPort(inputPort, &aTrack, TrackPort::InputPortOwnership::OWNED);
|
|
|
|
mTracks.AppendElement(trackPort.forget());
|
2015-09-30 04:32:06 +03:00
|
|
|
NotifyTrackAdded(&aTrack);
|
2015-09-30 04:32:05 +03: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)",
|
2016-02-01 17:48:05 +03:00
|
|
|
this, &aTrack, aTrack.mOwningStream.get(), aTrack.mTrackID));
|
2015-09-30 04:32:05 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TrackPort> toRemove = FindPlaybackTrackPort(aTrack);
|
2015-09-30 04:32:05 +03: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.
|
2016-05-31 15:55:51 +03:00
|
|
|
// If the track has already ended, it's input port might be gone, so in those
|
|
|
|
// cases blocking the underlying track should be avoided.
|
|
|
|
if (!aTrack.Ended()) {
|
|
|
|
BlockPlaybackTrack(toRemove);
|
2016-03-16 18:08:43 +03:00
|
|
|
|
2016-09-08 14:44:49 +03:00
|
|
|
bool removed = mTracks.RemoveElement(toRemove);
|
|
|
|
if (removed) {
|
|
|
|
NotifyTrackRemoved(&aTrack);
|
|
|
|
}
|
|
|
|
}
|
2016-03-16 18:08:43 +03:00
|
|
|
|
2015-09-30 04:32:05 +03:00
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p Removed track %p", this, &aTrack));
|
|
|
|
}
|
|
|
|
|
2016-01-22 11:51:37 +03:00
|
|
|
class ClonedStreamSourceGetter :
|
|
|
|
public MediaStreamTrackSourceGetter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ClonedStreamSourceGetter,
|
|
|
|
MediaStreamTrackSourceGetter)
|
|
|
|
|
|
|
|
explicit ClonedStreamSourceGetter(DOMMediaStream* aStream)
|
|
|
|
: mStream(aStream) {}
|
|
|
|
|
|
|
|
already_AddRefed<MediaStreamTrackSource>
|
|
|
|
GetMediaStreamTrackSource(TrackID aInputTrackID) override
|
|
|
|
{
|
|
|
|
MediaStreamTrack* sourceTrack =
|
|
|
|
mStream->FindOwnedDOMTrack(mStream->GetOwnedStream(), aInputTrackID);
|
|
|
|
MOZ_RELEASE_ASSERT(sourceTrack);
|
|
|
|
|
|
|
|
return do_AddRef(&sourceTrack->GetSource());
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~ClonedStreamSourceGetter() {}
|
|
|
|
|
|
|
|
RefPtr<DOMMediaStream> mStream;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(ClonedStreamSourceGetter,
|
|
|
|
MediaStreamTrackSourceGetter)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(ClonedStreamSourceGetter,
|
|
|
|
MediaStreamTrackSourceGetter)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ClonedStreamSourceGetter)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(MediaStreamTrackSourceGetter)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(ClonedStreamSourceGetter,
|
|
|
|
MediaStreamTrackSourceGetter,
|
|
|
|
mStream)
|
|
|
|
|
|
|
|
already_AddRefed<DOMMediaStream>
|
|
|
|
DOMMediaStream::Clone()
|
|
|
|
{
|
|
|
|
return CloneInternal(TrackForwardingOption::CURRENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMMediaStream>
|
|
|
|
DOMMediaStream::CloneInternal(TrackForwardingOption aForwarding)
|
|
|
|
{
|
|
|
|
RefPtr<DOMMediaStream> newStream =
|
|
|
|
new DOMMediaStream(GetParentObject(), new ClonedStreamSourceGetter(this));
|
|
|
|
|
|
|
|
LOG(LogLevel::Info, ("DOMMediaStream %p created clone %p, forwarding %s tracks",
|
|
|
|
this, newStream.get(),
|
|
|
|
aForwarding == TrackForwardingOption::ALL
|
|
|
|
? "all" : "current"));
|
|
|
|
|
|
|
|
MOZ_RELEASE_ASSERT(mPlaybackStream);
|
|
|
|
MOZ_RELEASE_ASSERT(mPlaybackStream->Graph());
|
|
|
|
MediaStreamGraph* graph = mPlaybackStream->Graph();
|
|
|
|
|
|
|
|
// We initiate the owned and playback streams first, since we need to create
|
|
|
|
// all existing DOM tracks before we add the generic input port from
|
|
|
|
// mInputStream to mOwnedStream (see AllocateInputPort wrt. destination
|
|
|
|
// TrackID as to why).
|
|
|
|
newStream->InitOwnedStreamCommon(graph);
|
|
|
|
newStream->InitPlaybackStreamCommon(graph);
|
|
|
|
|
|
|
|
// Set up existing DOM tracks.
|
|
|
|
TrackID allocatedTrackID = 1;
|
|
|
|
for (const RefPtr<TrackPort>& info : mTracks) {
|
|
|
|
MediaStreamTrack& track = *info->GetTrack();
|
|
|
|
|
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p forwarding external track %p to clone %p",
|
|
|
|
this, &track, newStream.get()));
|
|
|
|
RefPtr<MediaStreamTrack> trackClone =
|
2016-01-05 05:16:26 +03:00
|
|
|
newStream->CloneDOMTrack(track, allocatedTrackID++);
|
2016-01-22 11:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aForwarding == TrackForwardingOption::ALL) {
|
|
|
|
// Set up an input port from our input stream to the new DOM stream's owned
|
|
|
|
// stream, to allow for dynamically added tracks at the source to appear in
|
|
|
|
// the clone. The clone may treat mInputStream as its own mInputStream but
|
|
|
|
// ownership remains with us.
|
|
|
|
newStream->mInputStream = mInputStream;
|
|
|
|
if (mInputStream) {
|
|
|
|
// We have already set up track-locked input ports for all existing DOM
|
|
|
|
// tracks, so now we need to block those in the generic input port to
|
|
|
|
// avoid ending up with double instances of them.
|
|
|
|
nsTArray<TrackID> tracksToBlock;
|
|
|
|
for (const RefPtr<TrackPort>& info : mOwnedTracks) {
|
|
|
|
tracksToBlock.AppendElement(info->GetTrack()->mTrackID);
|
|
|
|
}
|
|
|
|
|
|
|
|
newStream->mInputStream->RegisterUser();
|
|
|
|
newStream->mOwnedPort =
|
|
|
|
newStream->mOwnedStream->AllocateInputPort(mInputStream,
|
|
|
|
TRACK_ANY, TRACK_ANY, 0, 0,
|
|
|
|
&tracksToBlock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return newStream.forget();
|
|
|
|
}
|
|
|
|
|
2016-09-08 14:44:49 +03:00
|
|
|
bool
|
|
|
|
DOMMediaStream::Active() const
|
|
|
|
{
|
|
|
|
return mActive;
|
|
|
|
}
|
|
|
|
|
2016-01-05 05:16:23 +03:00
|
|
|
MediaStreamTrack*
|
2016-05-20 14:01:30 +03:00
|
|
|
DOMMediaStream::GetTrackById(const nsAString& aId) const
|
2016-01-05 05:16:23 +03:00
|
|
|
{
|
|
|
|
for (const RefPtr<TrackPort>& info : mTracks) {
|
|
|
|
nsString id;
|
|
|
|
info->GetTrack()->GetId(id);
|
|
|
|
if (id == aId) {
|
|
|
|
return info->GetTrack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaStreamTrack*
|
2016-05-20 14:01:30 +03:00
|
|
|
DOMMediaStream::GetOwnedTrackById(const nsAString& aId)
|
2016-01-05 05:16:23 +03:00
|
|
|
{
|
|
|
|
for (const RefPtr<TrackPort>& info : mOwnedTracks) {
|
|
|
|
nsString id;
|
|
|
|
info->GetTrack()->GetId(id);
|
|
|
|
if (id == aId) {
|
|
|
|
return info->GetTrack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-08-14 05:40:54 +04:00
|
|
|
bool
|
|
|
|
DOMMediaStream::HasTrack(const MediaStreamTrack& aTrack) const
|
|
|
|
{
|
2015-09-30 04:32:05 +03:00
|
|
|
return !!FindPlaybackTrackPort(aTrack);
|
2015-09-30 04:31:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DOMMediaStream::OwnsTrack(const MediaStreamTrack& aTrack) const
|
|
|
|
{
|
2016-01-05 05:16:25 +03:00
|
|
|
return !!FindOwnedTrackPort(aTrack);
|
2014-08-14 05:40:54 +04:00
|
|
|
}
|
|
|
|
|
2016-01-24 11:05:16 +03:00
|
|
|
bool
|
2016-04-29 06:45:25 +03:00
|
|
|
DOMMediaStream::AddDirectListener(DirectMediaStreamListener* aListener)
|
2016-01-24 11:05:16 +03:00
|
|
|
{
|
|
|
|
if (GetInputStream() && GetInputStream()->AsSourceStream()) {
|
|
|
|
GetInputStream()->AsSourceStream()->AddDirectListener(aListener);
|
|
|
|
return true; // application should ignore NotifyQueuedTrackData
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-04-29 06:45:25 +03:00
|
|
|
DOMMediaStream::RemoveDirectListener(DirectMediaStreamListener* aListener)
|
2016-01-24 11:05:16 +03:00
|
|
|
{
|
|
|
|
if (GetInputStream() && GetInputStream()->AsSourceStream()) {
|
|
|
|
GetInputStream()->AsSourceStream()->RemoveDirectListener(aListener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-15 12:04:11 +04:00
|
|
|
bool
|
2016-09-15 15:18:22 +03:00
|
|
|
DOMMediaStream::IsFinished() const
|
2012-10-25 03:21:32 +04:00
|
|
|
{
|
2015-09-30 04:31:54 +03:00
|
|
|
return !mPlaybackStream || mPlaybackStream->IsFinished();
|
2012-10-25 03:21:32 +04:00
|
|
|
}
|
|
|
|
|
2016-09-15 15:18:22 +03:00
|
|
|
void
|
|
|
|
DOMMediaStream::SetInactiveOnFinish()
|
|
|
|
{
|
|
|
|
mSetInactiveOnFinish = true;
|
|
|
|
}
|
|
|
|
|
2013-02-15 12:04:11 +04:00
|
|
|
void
|
2016-01-05 05:16:20 +03:00
|
|
|
DOMMediaStream::InitSourceStream(MediaStreamGraph* aGraph)
|
2012-04-30 07:11:40 +04:00
|
|
|
{
|
2016-06-29 13:27:13 +03:00
|
|
|
InitInputStreamCommon(aGraph->CreateSourceStream(), aGraph);
|
2015-10-14 20:08:32 +03:00
|
|
|
InitOwnedStreamCommon(aGraph);
|
|
|
|
InitPlaybackStreamCommon(aGraph);
|
2012-04-30 07:11:40 +04:00
|
|
|
}
|
|
|
|
|
2013-02-15 12:04:11 +04:00
|
|
|
void
|
2016-01-05 05:16:20 +03:00
|
|
|
DOMMediaStream::InitTrackUnionStream(MediaStreamGraph* aGraph)
|
2012-10-25 03:21:32 +04:00
|
|
|
{
|
2016-06-29 13:27:13 +03:00
|
|
|
InitInputStreamCommon(aGraph->CreateTrackUnionStream(), aGraph);
|
2015-10-14 20:08:32 +03:00
|
|
|
InitOwnedStreamCommon(aGraph);
|
|
|
|
InitPlaybackStreamCommon(aGraph);
|
2013-04-17 09:18:24 +04:00
|
|
|
}
|
|
|
|
|
2015-07-24 15:28:16 +03:00
|
|
|
void
|
2016-02-01 17:46:34 +03:00
|
|
|
DOMMediaStream::InitAudioCaptureStream(nsIPrincipal* aPrincipal, MediaStreamGraph* aGraph)
|
2015-07-24 15:28:16 +03:00
|
|
|
{
|
2015-09-30 04:31:53 +03:00
|
|
|
const TrackID AUDIO_TRACK = 1;
|
|
|
|
|
2016-09-16 16:19:28 +03:00
|
|
|
RefPtr<BasicTrackSource> audioCaptureSource =
|
|
|
|
new BasicTrackSource(aPrincipal, MediaSourceEnum::AudioCapture);
|
2016-04-06 15:46:56 +03:00
|
|
|
|
2016-03-03 19:26:31 +03:00
|
|
|
AudioCaptureStream* audioCaptureStream =
|
2016-06-29 13:27:13 +03:00
|
|
|
static_cast<AudioCaptureStream*>(aGraph->CreateAudioCaptureStream(AUDIO_TRACK));
|
2016-03-03 19:26:31 +03:00
|
|
|
InitInputStreamCommon(audioCaptureStream, aGraph);
|
2015-10-14 20:08:32 +03:00
|
|
|
InitOwnedStreamCommon(aGraph);
|
|
|
|
InitPlaybackStreamCommon(aGraph);
|
2016-08-12 14:50:41 +03:00
|
|
|
RefPtr<MediaStreamTrack> track =
|
|
|
|
CreateDOMTrack(AUDIO_TRACK, MediaSegment::AUDIO, audioCaptureSource);
|
|
|
|
AddTrackInternal(track);
|
|
|
|
|
2016-03-03 19:26:31 +03:00
|
|
|
audioCaptureStream->Start();
|
2015-07-24 15:28:16 +03:00
|
|
|
}
|
|
|
|
|
2013-04-17 09:18:24 +04:00
|
|
|
void
|
2015-10-14 20:08:32 +03:00
|
|
|
DOMMediaStream::InitInputStreamCommon(MediaStream* aStream,
|
|
|
|
MediaStreamGraph* aGraph)
|
2013-04-17 09:18:24 +04:00
|
|
|
{
|
2015-10-14 20:08:32 +03:00
|
|
|
MOZ_ASSERT(!mOwnedStream, "Input stream must be initialized before owned stream");
|
|
|
|
|
2015-09-30 04:31:54 +03:00
|
|
|
mInputStream = aStream;
|
2016-01-22 11:51:37 +03:00
|
|
|
mInputStream->RegisterUser();
|
2015-10-14 20:08:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMMediaStream::InitOwnedStreamCommon(MediaStreamGraph* aGraph)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mPlaybackStream, "Owned stream must be initialized before playback stream");
|
2015-09-30 04:31:54 +03:00
|
|
|
|
2016-06-29 13:27:13 +03:00
|
|
|
mOwnedStream = aGraph->CreateTrackUnionStream();
|
2015-09-30 04:31:54 +03:00
|
|
|
mOwnedStream->SetAutofinish(true);
|
2016-01-22 11:51:37 +03:00
|
|
|
mOwnedStream->RegisterUser();
|
2015-10-14 20:08:32 +03:00
|
|
|
if (mInputStream) {
|
|
|
|
mOwnedPort = mOwnedStream->AllocateInputPort(mInputStream);
|
|
|
|
}
|
2015-09-30 04:31:54 +03:00
|
|
|
|
2015-09-30 04:31:54 +03:00
|
|
|
// Setup track listeners
|
|
|
|
mOwnedListener = new OwnedStreamListener(this);
|
|
|
|
mOwnedStream->AddListener(mOwnedListener);
|
2015-10-14 20:08:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMMediaStream::InitPlaybackStreamCommon(MediaStreamGraph* aGraph)
|
|
|
|
{
|
2016-06-29 13:27:13 +03:00
|
|
|
mPlaybackStream = aGraph->CreateTrackUnionStream();
|
2015-10-14 20:08:32 +03:00
|
|
|
mPlaybackStream->SetAutofinish(true);
|
2016-01-22 11:51:37 +03:00
|
|
|
mPlaybackStream->RegisterUser();
|
2015-10-14 20:08:32 +03:00
|
|
|
if (mOwnedStream) {
|
|
|
|
mPlaybackPort = mPlaybackStream->AllocateInputPort(mOwnedStream);
|
|
|
|
}
|
|
|
|
|
2015-09-30 04:31:54 +03:00
|
|
|
mPlaybackListener = new PlaybackStreamListener(this);
|
|
|
|
mPlaybackStream->AddListener(mPlaybackListener);
|
2015-10-14 20:08:32 +03:00
|
|
|
|
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p Initiated with mInputStream=%p, mOwnedStream=%p, mPlaybackStream=%p",
|
|
|
|
this, mInputStream, mOwnedStream, mPlaybackStream));
|
2012-10-25 03:21:32 +04:00
|
|
|
}
|
|
|
|
|
2013-02-15 12:01:58 +04:00
|
|
|
already_AddRefed<DOMMediaStream>
|
2016-04-25 06:43:27 +03:00
|
|
|
DOMMediaStream::CreateSourceStreamAsInput(nsPIDOMWindowInner* aWindow,
|
|
|
|
MediaStreamGraph* aGraph,
|
|
|
|
MediaStreamTrackSourceGetter* aTrackSourceGetter)
|
2012-07-31 16:17:22 +04:00
|
|
|
{
|
2016-01-05 05:16:21 +03:00
|
|
|
RefPtr<DOMMediaStream> stream = new DOMMediaStream(aWindow, aTrackSourceGetter);
|
2016-01-05 05:16:20 +03:00
|
|
|
stream->InitSourceStream(aGraph);
|
2012-07-31 16:17:22 +04:00
|
|
|
return stream.forget();
|
|
|
|
}
|
|
|
|
|
2013-02-15 12:04:11 +04:00
|
|
|
already_AddRefed<DOMMediaStream>
|
2016-04-25 06:43:27 +03:00
|
|
|
DOMMediaStream::CreateTrackUnionStreamAsInput(nsPIDOMWindowInner* aWindow,
|
|
|
|
MediaStreamGraph* aGraph,
|
|
|
|
MediaStreamTrackSourceGetter* aTrackSourceGetter)
|
2012-10-25 03:21:32 +04:00
|
|
|
{
|
2016-01-05 05:16:21 +03:00
|
|
|
RefPtr<DOMMediaStream> stream = new DOMMediaStream(aWindow, aTrackSourceGetter);
|
2016-01-05 05:16:20 +03:00
|
|
|
stream->InitTrackUnionStream(aGraph);
|
2012-10-25 03:21:32 +04:00
|
|
|
return stream.forget();
|
|
|
|
}
|
|
|
|
|
2015-07-24 15:28:16 +03:00
|
|
|
already_AddRefed<DOMMediaStream>
|
2016-04-25 06:43:27 +03:00
|
|
|
DOMMediaStream::CreateAudioCaptureStreamAsInput(nsPIDOMWindowInner* aWindow,
|
|
|
|
nsIPrincipal* aPrincipal,
|
|
|
|
MediaStreamGraph* aGraph)
|
2015-07-24 15:28:16 +03:00
|
|
|
{
|
2016-02-01 17:46:34 +03:00
|
|
|
// Audio capture doesn't create tracks dynamically
|
2016-01-05 05:16:21 +03:00
|
|
|
MediaStreamTrackSourceGetter* getter = nullptr;
|
|
|
|
RefPtr<DOMMediaStream> stream = new DOMMediaStream(aWindow, getter);
|
2016-02-01 17:46:34 +03:00
|
|
|
stream->InitAudioCaptureStream(aPrincipal, aGraph);
|
2015-07-24 15:28:16 +03:00
|
|
|
return stream.forget();
|
|
|
|
}
|
|
|
|
|
2016-03-16 18:08:43 +03:00
|
|
|
void
|
|
|
|
DOMMediaStream::PrincipalChanged(MediaStreamTrack* aTrack)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aTrack);
|
|
|
|
NS_ASSERTION(HasTrack(*aTrack), "Principal changed for an unknown track");
|
|
|
|
LOG(LogLevel::Info, ("DOMMediaStream %p Principal changed for track %p",
|
|
|
|
this, aTrack));
|
|
|
|
RecomputePrincipal();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMMediaStream::RecomputePrincipal()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPrincipal> previousPrincipal = mPrincipal.forget();
|
2016-01-26 10:36:52 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> previousVideoPrincipal = mVideoPrincipal.forget();
|
2016-03-16 18:00:34 +03:00
|
|
|
|
|
|
|
if (mTracksPendingRemoval > 0) {
|
|
|
|
LOG(LogLevel::Info, ("DOMMediaStream %p RecomputePrincipal() Cannot "
|
|
|
|
"recompute stream principal with tracks pending "
|
|
|
|
"removal.", this));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p Recomputing principal. "
|
|
|
|
"Old principal was %p.", this, previousPrincipal.get()));
|
|
|
|
|
|
|
|
// mPrincipal is recomputed based on all current tracks, and tracks that have
|
|
|
|
// not ended in our playback stream.
|
2016-03-16 18:08:43 +03:00
|
|
|
for (const RefPtr<TrackPort>& info : mTracks) {
|
2016-01-26 10:36:52 +03:00
|
|
|
if (info->GetTrack()->Ended()) {
|
|
|
|
continue;
|
|
|
|
}
|
2016-03-16 18:00:34 +03:00
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p Taking live track %p with "
|
|
|
|
"principal %p into account.", this,
|
|
|
|
info->GetTrack(), info->GetTrack()->GetPrincipal()));
|
2016-03-16 18:08:43 +03:00
|
|
|
nsContentUtils::CombineResourcePrincipals(&mPrincipal,
|
|
|
|
info->GetTrack()->GetPrincipal());
|
2016-01-26 10:36:52 +03:00
|
|
|
if (info->GetTrack()->AsVideoStreamTrack()) {
|
|
|
|
nsContentUtils::CombineResourcePrincipals(&mVideoPrincipal,
|
|
|
|
info->GetTrack()->GetPrincipal());
|
|
|
|
}
|
2016-03-16 18:08:43 +03:00
|
|
|
}
|
2016-01-26 10:36:52 +03:00
|
|
|
|
2016-03-16 18:00:34 +03:00
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p new principal is %p.",
|
|
|
|
this, mPrincipal.get()));
|
|
|
|
|
2016-01-26 10:36:52 +03:00
|
|
|
if (previousPrincipal != mPrincipal ||
|
|
|
|
previousVideoPrincipal != mVideoPrincipal) {
|
2016-03-16 18:08:43 +03:00
|
|
|
NotifyPrincipalChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-25 18:30:00 +04:00
|
|
|
void
|
|
|
|
DOMMediaStream::NotifyPrincipalChanged()
|
|
|
|
{
|
2016-03-16 18:08:43 +03:00
|
|
|
if (!mPrincipal) {
|
|
|
|
// When all tracks are removed, mPrincipal will change to nullptr.
|
|
|
|
LOG(LogLevel::Info, ("DOMMediaStream %p Principal changed to nothing.",
|
|
|
|
this));
|
|
|
|
} else {
|
|
|
|
LOG(LogLevel::Info, ("DOMMediaStream %p Principal changed. Now: "
|
|
|
|
"null=%d, codebase=%d, expanded=%d, system=%d", this,
|
|
|
|
mPrincipal->GetIsNullPrincipal(),
|
|
|
|
mPrincipal->GetIsCodebasePrincipal(),
|
|
|
|
mPrincipal->GetIsExpandedPrincipal(),
|
|
|
|
mPrincipal->GetIsSystemPrincipal()));
|
|
|
|
}
|
|
|
|
|
2014-04-25 18:30:00 +04:00
|
|
|
for (uint32_t i = 0; i < mPrincipalChangeObservers.Length(); ++i) {
|
|
|
|
mPrincipalChangeObservers[i]->PrincipalChanged(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2016-01-22 07:10:41 +03:00
|
|
|
DOMMediaStream::AddPrincipalChangeObserver(
|
|
|
|
PrincipalChangeObserver<DOMMediaStream>* aObserver)
|
2014-04-25 18:30:00 +04:00
|
|
|
{
|
|
|
|
return mPrincipalChangeObservers.AppendElement(aObserver) != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-01-22 07:10:41 +03:00
|
|
|
DOMMediaStream::RemovePrincipalChangeObserver(
|
|
|
|
PrincipalChangeObserver<DOMMediaStream>* aObserver)
|
2014-04-25 18:30:00 +04:00
|
|
|
{
|
|
|
|
return mPrincipalChangeObservers.RemoveElement(aObserver);
|
2012-04-30 07:11:34 +04:00
|
|
|
}
|
2013-02-15 12:04:11 +04:00
|
|
|
|
2016-08-12 14:50:41 +03:00
|
|
|
void
|
|
|
|
DOMMediaStream::AddTrackInternal(MediaStreamTrack* aTrack)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aTrack->mOwningStream == this);
|
|
|
|
MOZ_ASSERT(FindOwnedDOMTrack(aTrack->GetInputStream(),
|
|
|
|
aTrack->mInputTrackID,
|
|
|
|
aTrack->mTrackID));
|
|
|
|
MOZ_ASSERT(!FindPlaybackDOMTrack(aTrack->GetOwnedStream(),
|
|
|
|
aTrack->mTrackID));
|
|
|
|
|
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p Adding owned track %p", this, aTrack));
|
|
|
|
|
|
|
|
mTracks.AppendElement(
|
|
|
|
new TrackPort(mPlaybackPort, aTrack, TrackPort::InputPortOwnership::EXTERNAL));
|
|
|
|
|
|
|
|
NotifyTrackAdded(aTrack);
|
|
|
|
|
|
|
|
DispatchTrackEvent(NS_LITERAL_STRING("addtrack"), aTrack);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<MediaStreamTrack>
|
2016-01-05 05:16:26 +03:00
|
|
|
DOMMediaStream::CreateDOMTrack(TrackID aTrackID, MediaSegment::Type aType,
|
2015-11-25 07:42:26 +03:00
|
|
|
MediaStreamTrackSource* aSource,
|
|
|
|
const MediaTrackConstraints& aConstraints)
|
2013-04-17 09:18:24 +04:00
|
|
|
{
|
2015-10-14 20:08:32 +03:00
|
|
|
MOZ_RELEASE_ASSERT(mInputStream);
|
|
|
|
MOZ_RELEASE_ASSERT(mOwnedStream);
|
|
|
|
|
2016-01-05 05:16:22 +03:00
|
|
|
MOZ_ASSERT(FindOwnedDOMTrack(GetInputStream(), aTrackID) == nullptr);
|
2015-09-30 04:31:54 +03:00
|
|
|
|
2016-08-12 14:50:41 +03:00
|
|
|
RefPtr<MediaStreamTrack> track;
|
2013-04-17 09:18:24 +04:00
|
|
|
switch (aType) {
|
|
|
|
case MediaSegment::AUDIO:
|
2015-11-25 07:42:26 +03:00
|
|
|
track = new AudioStreamTrack(this, aTrackID, aTrackID, aSource, aConstraints);
|
2013-04-17 09:18:24 +04:00
|
|
|
break;
|
|
|
|
case MediaSegment::VIDEO:
|
2015-11-25 07:42:26 +03:00
|
|
|
track = new VideoStreamTrack(this, aTrackID, aTrackID, aSource, aConstraints);
|
2013-04-17 09:18:24 +04:00
|
|
|
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-03 09:02:55 +04:00
|
|
|
|
2016-08-12 14:50:41 +03:00
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p Created new track %p with ID %u",
|
|
|
|
this, track.get(), aTrackID));
|
2015-09-30 04:31:54 +03:00
|
|
|
|
2016-01-22 11:27:51 +03:00
|
|
|
mOwnedTracks.AppendElement(
|
|
|
|
new TrackPort(mOwnedPort, track, TrackPort::InputPortOwnership::EXTERNAL));
|
2015-09-30 04:31:54 +03:00
|
|
|
|
2016-08-12 14:50:41 +03:00
|
|
|
return track.forget();
|
2014-10-13 07:13:36 +04:00
|
|
|
}
|
2013-05-03 09:02:55 +04:00
|
|
|
|
2016-01-22 11:27:51 +03:00
|
|
|
already_AddRefed<MediaStreamTrack>
|
2016-01-05 05:16:26 +03:00
|
|
|
DOMMediaStream::CloneDOMTrack(MediaStreamTrack& aTrack,
|
|
|
|
TrackID aCloneTrackID)
|
2016-01-22 11:27:51 +03:00
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(mOwnedStream);
|
|
|
|
MOZ_RELEASE_ASSERT(mPlaybackStream);
|
|
|
|
MOZ_RELEASE_ASSERT(IsTrackIDExplicit(aCloneTrackID));
|
|
|
|
|
|
|
|
TrackID inputTrackID = aTrack.mInputTrackID;
|
|
|
|
MediaStream* inputStream = aTrack.GetInputStream();
|
|
|
|
|
|
|
|
RefPtr<MediaStreamTrack> newTrack = aTrack.CloneInternal(this, aCloneTrackID);
|
|
|
|
|
|
|
|
newTrack->mOriginalTrack =
|
|
|
|
aTrack.mOriginalTrack ? aTrack.mOriginalTrack.get() : &aTrack;
|
|
|
|
|
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p Created new track %p cloned from stream %p track %d",
|
|
|
|
this, newTrack.get(), inputStream, inputTrackID));
|
|
|
|
|
|
|
|
RefPtr<MediaInputPort> inputPort =
|
|
|
|
mOwnedStream->AllocateInputPort(inputStream, inputTrackID, aCloneTrackID);
|
|
|
|
|
|
|
|
mOwnedTracks.AppendElement(
|
|
|
|
new TrackPort(inputPort, newTrack, TrackPort::InputPortOwnership::OWNED));
|
|
|
|
|
|
|
|
mTracks.AppendElement(
|
|
|
|
new TrackPort(mPlaybackPort, newTrack, TrackPort::InputPortOwnership::EXTERNAL));
|
|
|
|
|
|
|
|
NotifyTrackAdded(newTrack);
|
|
|
|
|
|
|
|
newTrack->SetEnabled(aTrack.Enabled());
|
2016-05-10 18:03:37 +03:00
|
|
|
newTrack->SetReadyState(aTrack.ReadyState());
|
|
|
|
|
|
|
|
if (aTrack.Ended()) {
|
|
|
|
// For extra suspenders, make sure that we don't forward data by mistake
|
|
|
|
// to the clone when the original has already ended.
|
2016-06-07 17:20:29 +03:00
|
|
|
// We only block END_EXISTING to allow any pending clones to end.
|
2016-05-10 18:03:37 +03:00
|
|
|
RefPtr<Pledge<bool, nsresult>> blockingPledge =
|
2016-06-07 17:20:29 +03:00
|
|
|
inputPort->BlockSourceTrackId(inputTrackID,
|
|
|
|
BlockingMode::END_EXISTING);
|
2016-05-10 18:03:37 +03:00
|
|
|
Unused << blockingPledge;
|
|
|
|
}
|
2016-01-22 11:27:51 +03:00
|
|
|
|
|
|
|
return newTrack.forget();
|
|
|
|
}
|
|
|
|
|
2016-01-21 14:05:53 +03:00
|
|
|
static DOMMediaStream::TrackPort*
|
|
|
|
FindTrackPortAmongTracks(const MediaStreamTrack& aTrack,
|
|
|
|
const nsTArray<RefPtr<DOMMediaStream::TrackPort>>& aTracks)
|
|
|
|
{
|
|
|
|
for (const RefPtr<DOMMediaStream::TrackPort>& info : aTracks) {
|
|
|
|
if (info->GetTrack() == &aTrack) {
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-10-13 07:13:36 +04:00
|
|
|
MediaStreamTrack*
|
2016-01-05 05:16:22 +03:00
|
|
|
DOMMediaStream::FindOwnedDOMTrack(MediaStream* aInputStream,
|
2016-05-24 14:26:25 +03:00
|
|
|
TrackID aInputTrackID,
|
|
|
|
TrackID aTrackID) const
|
2014-10-13 07:13:36 +04:00
|
|
|
{
|
2015-10-14 20:08:32 +03:00
|
|
|
MOZ_RELEASE_ASSERT(mOwnedStream);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
for (const RefPtr<TrackPort>& info : mOwnedTracks) {
|
2016-01-05 05:16:22 +03:00
|
|
|
if (info->GetInputPort() &&
|
|
|
|
info->GetInputPort()->GetSource() == aInputStream &&
|
2016-05-24 14:26:25 +03:00
|
|
|
info->GetTrack()->mInputTrackID == aInputTrackID &&
|
|
|
|
(aTrackID == TRACK_ANY || info->GetTrack()->mTrackID == aTrackID)) {
|
2016-01-05 05:16:22 +03:00
|
|
|
// This track is owned externally but in our playback stream.
|
2015-09-30 04:31:54 +03:00
|
|
|
return info->GetTrack();
|
2014-10-13 07:13:36 +04:00
|
|
|
}
|
2015-09-25 23:08:55 +03:00
|
|
|
}
|
2015-09-30 04:31:54 +03:00
|
|
|
return nullptr;
|
2013-04-17 09:18:24 +04:00
|
|
|
}
|
|
|
|
|
2016-01-05 05:16:25 +03:00
|
|
|
DOMMediaStream::TrackPort*
|
|
|
|
DOMMediaStream::FindOwnedTrackPort(const MediaStreamTrack& aTrack) const
|
|
|
|
{
|
2016-01-21 14:05:53 +03:00
|
|
|
return FindTrackPortAmongTracks(aTrack, mOwnedTracks);
|
2016-01-05 05:16:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-17 09:18:24 +04:00
|
|
|
MediaStreamTrack*
|
2015-09-30 04:31:54 +03:00
|
|
|
DOMMediaStream::FindPlaybackDOMTrack(MediaStream* aInputStream, TrackID aInputTrackID) const
|
|
|
|
{
|
2016-01-22 11:27:51 +03:00
|
|
|
if (!mPlaybackStream) {
|
|
|
|
// One would think we can assert mPlaybackStream here, but track clones have
|
|
|
|
// a dummy DOMMediaStream that doesn't have a playback stream, so we can't.
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-10-14 20:08:32 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
for (const RefPtr<TrackPort>& info : mTracks) {
|
2015-09-30 04:31:54 +03:00
|
|
|
if (info->GetInputPort() == mPlaybackPort &&
|
|
|
|
aInputStream == mOwnedStream &&
|
2016-02-01 17:48:05 +03:00
|
|
|
info->GetTrack()->mInputTrackID == aInputTrackID) {
|
2015-09-30 04:31:54 +03:00
|
|
|
// This track is in our owned and playback streams.
|
|
|
|
return info->GetTrack();
|
|
|
|
}
|
2015-10-14 20:08:33 +03:00
|
|
|
if (info->GetInputPort() &&
|
|
|
|
info->GetInputPort()->GetSource() == aInputStream &&
|
2015-09-30 04:31:54 +03:00
|
|
|
info->GetSourceTrackId() == aInputTrackID) {
|
|
|
|
// This track is owned externally but in our playback stream.
|
2016-01-05 05:16:22 +03:00
|
|
|
MOZ_ASSERT(IsTrackIDExplicit(aInputTrackID));
|
2015-09-30 04:31:54 +03:00
|
|
|
return info->GetTrack();
|
2013-04-17 09:18:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-09-30 04:32:05 +03:00
|
|
|
DOMMediaStream::TrackPort*
|
|
|
|
DOMMediaStream::FindPlaybackTrackPort(const MediaStreamTrack& aTrack) const
|
|
|
|
{
|
2016-01-21 14:05:53 +03:00
|
|
|
return FindTrackPortAmongTracks(aTrack, mTracks);
|
2015-09-30 04:32:05 +03:00
|
|
|
}
|
|
|
|
|
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
|
2015-09-30 04:32:06 +03:00
|
|
|
DOMMediaStream::NotifyTracksCreated()
|
2015-02-06 12:38:11 +03:00
|
|
|
{
|
|
|
|
mTracksCreated = true;
|
|
|
|
CheckTracksAvailable();
|
|
|
|
}
|
|
|
|
|
2016-09-15 15:18:22 +03:00
|
|
|
void
|
|
|
|
DOMMediaStream::NotifyFinished()
|
|
|
|
{
|
|
|
|
if (!mSetInactiveOnFinish) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mActive) {
|
|
|
|
// This can happen if the stream never became active.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(!ContainsLiveTracks(mTracks));
|
|
|
|
mActive = false;
|
|
|
|
NotifyInactive();
|
|
|
|
}
|
|
|
|
|
2016-09-08 14:44:49 +03:00
|
|
|
void
|
|
|
|
DOMMediaStream::NotifyActive()
|
|
|
|
{
|
|
|
|
LOG(LogLevel::Info, ("DOMMediaStream %p NotifyActive(). ", this));
|
|
|
|
|
|
|
|
MOZ_ASSERT(mActive);
|
|
|
|
for (int32_t i = mTrackListeners.Length() - 1; i >= 0; --i) {
|
|
|
|
mTrackListeners[i]->NotifyActive();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMMediaStream::NotifyInactive()
|
|
|
|
{
|
|
|
|
LOG(LogLevel::Info, ("DOMMediaStream %p NotifyInactive(). ", this));
|
|
|
|
|
|
|
|
MOZ_ASSERT(!mActive);
|
|
|
|
for (int32_t i = mTrackListeners.Length() - 1; i >= 0; --i) {
|
|
|
|
mTrackListeners[i]->NotifyInactive();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-30 04:31:54 +03:00
|
|
|
void
|
2015-09-30 04:32:06 +03:00
|
|
|
DOMMediaStream::RegisterTrackListener(TrackListener* aListener)
|
2015-09-30 04:31:54 +03:00
|
|
|
{
|
2015-09-30 04:32:06 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-09-25 23:08:44 +03:00
|
|
|
|
2015-09-30 04:32:06 +03:00
|
|
|
if (mNotifiedOfMediaStreamGraphShutdown) {
|
|
|
|
// No more tracks will ever be added, so just do nothing.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mTrackListeners.AppendElement(aListener);
|
2014-05-23 13:34:14 +04:00
|
|
|
}
|
|
|
|
|
2015-09-30 04:32:06 +03:00
|
|
|
void
|
|
|
|
DOMMediaStream::UnregisterTrackListener(TrackListener* aListener)
|
2014-05-23 13:34:14 +04:00
|
|
|
{
|
2015-09-30 04:32:06 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mTrackListeners.RemoveElement(aListener);
|
2014-05-23 13:34:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-21 14:05:53 +03:00
|
|
|
DOMMediaStream::NotifyTrackAdded(const RefPtr<MediaStreamTrack>& aTrack)
|
2014-05-23 13:34:14 +04:00
|
|
|
{
|
2015-09-30 04:32:06 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-09-25 23:08:44 +03:00
|
|
|
|
2016-03-16 18:00:34 +03:00
|
|
|
if (mTracksPendingRemoval > 0) {
|
|
|
|
// If there are tracks pending removal we may not degrade the current
|
|
|
|
// principals until those tracks have been confirmed removed from the
|
|
|
|
// playback stream. Instead combine with the new track and the (potentially)
|
|
|
|
// degraded principal will be calculated when it's safe.
|
|
|
|
nsContentUtils::CombineResourcePrincipals(&mPrincipal,
|
|
|
|
aTrack->GetPrincipal());
|
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p saw a track get added. Combining "
|
|
|
|
"its principal %p into our while waiting for pending "
|
|
|
|
"tracks to be removed. New principal is %p.",
|
|
|
|
this, aTrack->GetPrincipal(), mPrincipal.get()));
|
|
|
|
if (aTrack->AsVideoStreamTrack()) {
|
|
|
|
nsContentUtils::CombineResourcePrincipals(&mVideoPrincipal,
|
|
|
|
aTrack->GetPrincipal());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p saw a track get added. "
|
|
|
|
"Recomputing principal.", this));
|
|
|
|
RecomputePrincipal();
|
|
|
|
}
|
2016-03-16 18:08:43 +03:00
|
|
|
|
|
|
|
aTrack->AddPrincipalChangeObserver(this);
|
2016-09-23 18:03:13 +03:00
|
|
|
aTrack->AddConsumer(mPlaybackTrackListener);
|
2016-03-16 18:08:43 +03:00
|
|
|
|
2015-09-30 04:32:06 +03:00
|
|
|
for (int32_t i = mTrackListeners.Length() - 1; i >= 0; --i) {
|
2016-01-05 05:16:28 +03:00
|
|
|
mTrackListeners[i]->NotifyTrackAdded(aTrack);
|
2014-10-04 01:29:29 +04:00
|
|
|
}
|
2016-09-08 14:44:49 +03:00
|
|
|
|
|
|
|
if (mActive) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if we became active.
|
2016-09-15 15:18:22 +03:00
|
|
|
if (ContainsLiveTracks(mTracks)) {
|
2016-09-08 14:44:49 +03:00
|
|
|
mActive = true;
|
|
|
|
NotifyActive();
|
|
|
|
}
|
2014-10-04 01:29:29 +04:00
|
|
|
}
|
|
|
|
|
2014-05-23 13:34:14 +04:00
|
|
|
void
|
2016-01-21 14:05:53 +03:00
|
|
|
DOMMediaStream::NotifyTrackRemoved(const RefPtr<MediaStreamTrack>& aTrack)
|
2014-05-23 13:34:14 +04:00
|
|
|
{
|
2015-09-30 04:32:06 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-12-12 06:54:12 +03:00
|
|
|
|
2016-09-23 18:03:13 +03:00
|
|
|
aTrack->RemoveConsumer(mPlaybackTrackListener);
|
2016-03-16 18:08:43 +03:00
|
|
|
aTrack->RemovePrincipalChangeObserver(this);
|
|
|
|
|
2015-09-30 04:32:06 +03:00
|
|
|
for (int32_t i = mTrackListeners.Length() - 1; i >= 0; --i) {
|
2016-01-05 05:16:28 +03:00
|
|
|
mTrackListeners[i]->NotifyTrackRemoved(aTrack);
|
2016-09-08 14:44:49 +03:00
|
|
|
|
2014-05-23 13:34:14 +04:00
|
|
|
}
|
2016-03-16 18:08:43 +03:00
|
|
|
|
2016-03-16 18:00:34 +03:00
|
|
|
// Don't call RecomputePrincipal here as the track may still exist in the
|
|
|
|
// playback stream in the MediaStreamGraph. It will instead be called when the
|
|
|
|
// track has been confirmed removed by the graph. See BlockPlaybackTrack().
|
2016-09-08 14:44:49 +03:00
|
|
|
|
|
|
|
if (!mActive) {
|
|
|
|
NS_ASSERTION(false, "Shouldn't remove a live track if already inactive");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-15 15:18:22 +03:00
|
|
|
if (mSetInactiveOnFinish) {
|
|
|
|
// For compatibility with mozCaptureStream we in some cases do not go
|
|
|
|
// inactive until the playback stream finishes.
|
|
|
|
return;
|
2016-09-08 14:44:49 +03:00
|
|
|
}
|
|
|
|
|
2016-09-15 15:18:22 +03:00
|
|
|
// Check if we became inactive.
|
|
|
|
if (!ContainsLiveTracks(mTracks)) {
|
2016-09-08 14:44:49 +03:00
|
|
|
mActive = false;
|
|
|
|
NotifyInactive();
|
|
|
|
}
|
2014-05-23 13:34:14 +04:00
|
|
|
}
|
|
|
|
|
2016-05-31 10:29:52 +03:00
|
|
|
nsresult
|
|
|
|
DOMMediaStream::DispatchTrackEvent(const nsAString& aName,
|
|
|
|
const RefPtr<MediaStreamTrack>& aTrack)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aName == NS_LITERAL_STRING("addtrack"),
|
|
|
|
"Only 'addtrack' is supported at this time");
|
|
|
|
|
|
|
|
MediaStreamTrackEventInit init;
|
|
|
|
init.mTrack = aTrack;
|
|
|
|
|
|
|
|
RefPtr<MediaStreamTrackEvent> event =
|
|
|
|
MediaStreamTrackEvent::Constructor(this, aName, init);
|
|
|
|
|
|
|
|
return DispatchTrustedEvent(event);
|
|
|
|
}
|
|
|
|
|
2016-03-16 18:00:34 +03:00
|
|
|
void
|
|
|
|
DOMMediaStream::BlockPlaybackTrack(TrackPort* aTrack)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aTrack);
|
|
|
|
++mTracksPendingRemoval;
|
2016-06-07 17:20:29 +03:00
|
|
|
RefPtr<Pledge<bool>> p =
|
|
|
|
aTrack->BlockSourceTrackId(aTrack->GetTrack()->mTrackID,
|
|
|
|
BlockingMode::CREATION);
|
2016-03-16 18:00:34 +03:00
|
|
|
RefPtr<DOMMediaStream> self = this;
|
|
|
|
p->Then([self] (const bool& aIgnore) { self->NotifyPlaybackTrackBlocked(); },
|
|
|
|
[] (const nsresult& aIgnore) { NS_ERROR("Could not remove track from MSG"); }
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMMediaStream::NotifyPlaybackTrackBlocked()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mTracksPendingRemoval > 0,
|
|
|
|
"A track reported finished blocking more times than we asked for");
|
|
|
|
if (--mTracksPendingRemoval == 0) {
|
|
|
|
// The MediaStreamGraph has reported a track was blocked and we are not
|
|
|
|
// waiting for any further tracks to get blocked. It is now safe to
|
|
|
|
// recompute the principal based on our main thread track set state.
|
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p saw all tracks pending removal "
|
|
|
|
"finish. Recomputing principal.", this));
|
|
|
|
RecomputePrincipal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-15 12:04:11 +04:00
|
|
|
DOMLocalMediaStream::~DOMLocalMediaStream()
|
|
|
|
{
|
2015-09-30 04:31:54 +03:00
|
|
|
if (mInputStream) {
|
2013-02-15 12:04:11 +04:00
|
|
|
// Make sure Listeners of this stream know it's going away
|
2015-09-30 04:32:06 +03:00
|
|
|
StopImpl();
|
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
|
|
|
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()
|
2015-09-30 04:32:06 +03:00
|
|
|
{
|
2016-08-23 18:51:50 +03:00
|
|
|
LOG(LogLevel::Debug, ("DOMMediaStream %p Stop()", this));
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> pWindow = GetParentObject();
|
2015-09-30 04:32:06 +03:00
|
|
|
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 12:04:11 +04:00
|
|
|
{
|
2015-09-30 04:31:54 +03:00
|
|
|
if (mInputStream && mInputStream->AsSourceStream()) {
|
|
|
|
mInputStream->AsSourceStream()->EndAllTrackAndFinish();
|
2013-02-15 12:04:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMLocalMediaStream>
|
2016-04-25 06:43:27 +03:00
|
|
|
DOMLocalMediaStream::CreateSourceStreamAsInput(nsPIDOMWindowInner* aWindow,
|
|
|
|
MediaStreamGraph* aGraph,
|
|
|
|
MediaStreamTrackSourceGetter* aTrackSourceGetter)
|
2013-02-15 12:04:11 +04:00
|
|
|
{
|
2016-01-05 05:16:21 +03:00
|
|
|
RefPtr<DOMLocalMediaStream> stream =
|
|
|
|
new DOMLocalMediaStream(aWindow, aTrackSourceGetter);
|
2016-01-05 05:16:20 +03:00
|
|
|
stream->InitSourceStream(aGraph);
|
2013-02-15 12:04:11 +04:00
|
|
|
return stream.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMLocalMediaStream>
|
2016-04-25 06:43:27 +03:00
|
|
|
DOMLocalMediaStream::CreateTrackUnionStreamAsInput(nsPIDOMWindowInner* aWindow,
|
|
|
|
MediaStreamGraph* aGraph,
|
|
|
|
MediaStreamTrackSourceGetter* aTrackSourceGetter)
|
2013-02-15 12:04:11 +04:00
|
|
|
{
|
2016-01-05 05:16:21 +03:00
|
|
|
RefPtr<DOMLocalMediaStream> stream =
|
|
|
|
new DOMLocalMediaStream(aWindow, aTrackSourceGetter);
|
2016-01-05 05:16:20 +03:00
|
|
|
stream->InitTrackUnionStream(aGraph);
|
2013-02-15 12:04:11 +04:00
|
|
|
return stream.forget();
|
|
|
|
}
|
2013-05-21 23:17:47 +04:00
|
|
|
|
2016-01-05 05:16:20 +03:00
|
|
|
DOMAudioNodeMediaStream::DOMAudioNodeMediaStream(nsPIDOMWindowInner* aWindow, AudioNode* aNode)
|
2016-01-05 05:16:21 +03:00
|
|
|
: DOMMediaStream(aWindow, nullptr),
|
2016-01-05 05:16:20 +03:00
|
|
|
mStreamNode(aNode)
|
2013-05-21 23:17:47 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-06-24 18:21:21 +04:00
|
|
|
DOMAudioNodeMediaStream::~DOMAudioNodeMediaStream()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-21 23:17:47 +04:00
|
|
|
already_AddRefed<DOMAudioNodeMediaStream>
|
2016-04-25 06:43:27 +03:00
|
|
|
DOMAudioNodeMediaStream::CreateTrackUnionStreamAsInput(nsPIDOMWindowInner* aWindow,
|
|
|
|
AudioNode* aNode,
|
|
|
|
MediaStreamGraph* aGraph)
|
2013-05-21 23:17:47 +04:00
|
|
|
{
|
2016-01-05 05:16:20 +03:00
|
|
|
RefPtr<DOMAudioNodeMediaStream> stream = new DOMAudioNodeMediaStream(aWindow, aNode);
|
|
|
|
stream->InitTrackUnionStream(aGraph);
|
2013-05-21 23:17:47 +04:00
|
|
|
return stream.forget();
|
|
|
|
}
|
2015-05-13 09:04:30 +03:00
|
|
|
|
2016-01-05 05:16:20 +03:00
|
|
|
DOMHwMediaStream::DOMHwMediaStream(nsPIDOMWindowInner* aWindow)
|
2016-01-05 05:16:21 +03:00
|
|
|
: DOMLocalMediaStream(aWindow, nullptr)
|
2015-06-18 01:21:00 +03:00
|
|
|
{
|
2016-04-06 15:56:44 +03:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
if (!mWindow) {
|
|
|
|
NS_ERROR("Expected window here.");
|
2016-04-12 17:54:41 +03:00
|
|
|
mPrincipalHandle = PRINCIPAL_HANDLE_NONE;
|
2016-04-06 15:56:44 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-04-12 17:54:41 +03:00
|
|
|
nsIDocument* doc = mWindow->GetExtantDoc();
|
2016-04-06 15:56:44 +03:00
|
|
|
if (!doc) {
|
|
|
|
NS_ERROR("Expected document here.");
|
2016-04-12 17:54:41 +03:00
|
|
|
mPrincipalHandle = PRINCIPAL_HANDLE_NONE;
|
2016-04-06 15:56:44 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-04-12 17:54:41 +03:00
|
|
|
mPrincipalHandle = MakePrincipalHandle(doc->NodePrincipal());
|
2016-04-06 15:56:44 +03:00
|
|
|
#endif
|
2015-06-18 01:21:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
DOMHwMediaStream::~DOMHwMediaStream()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMHwMediaStream>
|
2016-01-30 20:05:36 +03:00
|
|
|
DOMHwMediaStream::CreateHwStream(nsPIDOMWindowInner* aWindow,
|
|
|
|
OverlayImage* aImage)
|
2015-06-18 01:21:00 +03:00
|
|
|
{
|
2016-01-05 05:16:20 +03:00
|
|
|
RefPtr<DOMHwMediaStream> stream = new DOMHwMediaStream(aWindow);
|
2015-08-25 11:29:51 +03:00
|
|
|
|
|
|
|
MediaStreamGraph* graph =
|
|
|
|
MediaStreamGraph::GetInstance(MediaStreamGraph::SYSTEM_THREAD_DRIVER,
|
|
|
|
AudioChannel::Normal);
|
2016-01-05 05:16:20 +03:00
|
|
|
stream->InitSourceStream(graph);
|
2016-01-26 13:01:43 +03:00
|
|
|
stream->Init(stream->GetInputStream(), aImage);
|
2015-06-18 01:21:00 +03:00
|
|
|
|
|
|
|
return stream.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-26 13:01:43 +03:00
|
|
|
DOMHwMediaStream::Init(MediaStream* stream, OverlayImage* aImage)
|
2015-06-18 01:21:00 +03:00
|
|
|
{
|
|
|
|
SourceMediaStream* srcStream = stream->AsSourceStream();
|
|
|
|
|
2016-01-26 13:01:43 +03:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
if (aImage) {
|
|
|
|
mOverlayImage = aImage;
|
|
|
|
} else {
|
|
|
|
Data imageData;
|
|
|
|
imageData.mOverlayId = DEFAULT_IMAGE_ID;
|
|
|
|
imageData.mSize.width = DEFAULT_IMAGE_WIDTH;
|
|
|
|
imageData.mSize.height = DEFAULT_IMAGE_HEIGHT;
|
|
|
|
|
|
|
|
mOverlayImage = new OverlayImage();
|
|
|
|
mOverlayImage->SetData(imageData);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-06-18 01:21:00 +03:00
|
|
|
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.
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Image> image = static_cast<Image*>(mOverlayImage.get());
|
2015-06-18 01:21:00 +03:00
|
|
|
mozilla::gfx::IntSize size = image->GetSize();
|
|
|
|
|
2016-04-06 15:56:44 +03:00
|
|
|
segment.AppendFrame(image.forget(), delta, size, mPrincipalHandle);
|
2015-06-18 01:21:00 +03:00
|
|
|
#endif
|
|
|
|
srcStream->AddTrack(TRACK_VIDEO_PRIMARY, 0, new VideoSegment());
|
|
|
|
srcStream->AppendToTrack(TRACK_VIDEO_PRIMARY, &segment);
|
|
|
|
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
|
2016-01-26 13:01:43 +03:00
|
|
|
if (mOverlayImage->GetSidebandStream().IsValid()) {
|
|
|
|
OverlayImage::SidebandStreamData imgData;
|
|
|
|
imgData.mStream = mOverlayImage->GetSidebandStream();
|
|
|
|
imgData.mSize = IntSize(width, height);
|
|
|
|
mOverlayImage->SetData(imgData);
|
|
|
|
} else {
|
|
|
|
OverlayImage::Data imgData;
|
|
|
|
imgData.mOverlayId = mOverlayImage->GetOverlayId();
|
|
|
|
imgData.mSize = IntSize(width, height);
|
|
|
|
mOverlayImage->SetData(imgData);
|
|
|
|
}
|
|
|
|
#endif
|
2015-06-15 04:11:00 +03:00
|
|
|
|
2016-01-26 13:01:43 +03:00
|
|
|
SourceMediaStream* srcStream = GetInputStream()->AsSourceStream();
|
2016-01-26 05:49:01 +03:00
|
|
|
StreamTracks::Track* track = srcStream->FindTrack(TRACK_VIDEO_PRIMARY);
|
2016-01-26 13:01:43 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
RefPtr<Image> image = static_cast<Image*>(mOverlayImage.get());
|
|
|
|
mozilla::gfx::IntSize size = image->GetSize();
|
|
|
|
VideoSegment segment;
|
|
|
|
|
2016-04-12 17:54:41 +03:00
|
|
|
segment.AppendFrame(image.forget(), delta, size, mPrincipalHandle);
|
2016-01-26 13:01:43 +03:00
|
|
|
srcStream->AppendToTrack(TRACK_VIDEO_PRIMARY, &segment);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMHwMediaStream::SetOverlayImage(OverlayImage* aImage)
|
|
|
|
{
|
|
|
|
if (!aImage) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
mOverlayImage = aImage;
|
2015-06-15 04:11:00 +03:00
|
|
|
#endif
|
|
|
|
|
2015-09-30 04:31:54 +03:00
|
|
|
SourceMediaStream* srcStream = GetInputStream()->AsSourceStream();
|
2016-01-26 05:49:01 +03:00
|
|
|
StreamTracks::Track* track = srcStream->FindTrack(TRACK_VIDEO_PRIMARY);
|
2015-06-15 04:11:00 +03:00
|
|
|
|
|
|
|
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 08:24:48 +03:00
|
|
|
RefPtr<Image> image = static_cast<Image*>(mOverlayImage.get());
|
2015-06-15 04:11:00 +03:00
|
|
|
mozilla::gfx::IntSize size = image->GetSize();
|
|
|
|
VideoSegment segment;
|
|
|
|
|
2016-04-12 17:54:41 +03:00
|
|
|
segment.AppendFrame(image.forget(), delta, size, mPrincipalHandle);
|
2015-06-15 04:11:00 +03:00
|
|
|
srcStream->AppendToTrack(TRACK_VIDEO_PRIMARY, &segment);
|
|
|
|
#endif
|
|
|
|
}
|
2016-01-26 13:01:43 +03:00
|
|
|
|
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
|
|
|
|
}
|