2012-05-11 10:35:36 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
|
2012-04-29 20:11:34 -07: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 00:01:58 -08:00
|
|
|
#include "DOMMediaStream.h"
|
2012-04-29 20:11:34 -07:00
|
|
|
#include "nsDOMClassInfoID.h"
|
|
|
|
#include "nsContentUtils.h"
|
2013-02-15 00:04:11 -08:00
|
|
|
#include "mozilla/dom/MediaStreamBinding.h"
|
|
|
|
#include "mozilla/dom/LocalMediaStreamBinding.h"
|
|
|
|
#include "MediaStreamGraph.h"
|
2012-04-29 20:11:34 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
2013-02-15 00:01:58 -08:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMMediaStream)
|
2013-02-15 00:04:11 -08:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2012-04-29 20:11:34 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMediaStream)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-02-15 00:01:58 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMMediaStream)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMMediaStream)
|
2013-02-15 00:04:11 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(DOMMediaStream, mWindow)
|
2012-10-24 16:21:32 -07:00
|
|
|
|
2013-02-07 02:19:08 -08:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(DOMLocalMediaStream, DOMMediaStream,
|
|
|
|
nsIDOMLocalMediaStream)
|
2012-10-24 16:21:32 -07:00
|
|
|
|
2013-02-15 00:01:58 -08:00
|
|
|
DOMMediaStream::~DOMMediaStream()
|
2012-04-29 20:11:34 -07:00
|
|
|
{
|
|
|
|
if (mStream) {
|
|
|
|
mStream->Destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-15 00:04:11 -08:00
|
|
|
JSObject*
|
|
|
|
DOMMediaStream::WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap)
|
2012-04-29 20:11:34 -07:00
|
|
|
{
|
2013-02-15 00:04:11 -08:00
|
|
|
return dom::MediaStreamBinding::Wrap(aCx, aScope, this, aTriedToWrap);
|
2012-04-29 20:11:34 -07:00
|
|
|
}
|
|
|
|
|
2013-02-15 00:04:11 -08:00
|
|
|
double
|
|
|
|
DOMMediaStream::CurrentTime()
|
2013-01-06 18:31:34 -08:00
|
|
|
{
|
2013-02-15 00:04:11 -08:00
|
|
|
return mStream ? MediaTimeToSeconds(mStream->GetCurrentTime()) : 0.0;
|
2013-01-06 18:31:34 -08:00
|
|
|
}
|
|
|
|
|
2013-02-15 00:04:11 -08:00
|
|
|
bool
|
|
|
|
DOMMediaStream::IsFinished()
|
2012-10-24 16:21:32 -07:00
|
|
|
{
|
2013-02-15 00:04:11 -08:00
|
|
|
return !mStream || mStream->IsFinished();
|
2012-10-24 16:21:32 -07:00
|
|
|
}
|
|
|
|
|
2013-02-15 00:04:11 -08:00
|
|
|
void
|
|
|
|
DOMMediaStream::InitSourceStream(nsIDOMWindow* aWindow, uint32_t aHintContents)
|
2012-04-29 20:11:40 -07:00
|
|
|
{
|
2013-02-15 00:04:11 -08:00
|
|
|
mWindow = aWindow;
|
|
|
|
SetHintContents(aHintContents);
|
|
|
|
MediaStreamGraph* gm = MediaStreamGraph::GetInstance();
|
|
|
|
mStream = gm->CreateSourceStream(this);
|
2012-04-29 20:11:40 -07:00
|
|
|
}
|
|
|
|
|
2013-02-15 00:04:11 -08:00
|
|
|
void
|
|
|
|
DOMMediaStream::InitTrackUnionStream(nsIDOMWindow* aWindow, uint32_t aHintContents)
|
2012-10-24 16:21:32 -07:00
|
|
|
{
|
2013-02-15 00:04:11 -08:00
|
|
|
mWindow = aWindow;
|
|
|
|
SetHintContents(aHintContents);
|
|
|
|
MediaStreamGraph* gm = MediaStreamGraph::GetInstance();
|
|
|
|
mStream = gm->CreateTrackUnionStream(this);
|
2012-10-24 16:21:32 -07:00
|
|
|
}
|
|
|
|
|
2013-02-15 00:01:58 -08:00
|
|
|
already_AddRefed<DOMMediaStream>
|
2013-02-15 00:04:11 -08:00
|
|
|
DOMMediaStream::CreateSourceStream(nsIDOMWindow* aWindow, uint32_t aHintContents)
|
2012-07-31 05:17:22 -07:00
|
|
|
{
|
2013-02-15 00:01:58 -08:00
|
|
|
nsRefPtr<DOMMediaStream> stream = new DOMMediaStream();
|
2013-02-15 00:04:11 -08:00
|
|
|
stream->InitSourceStream(aWindow, aHintContents);
|
2012-07-31 05:17:22 -07:00
|
|
|
return stream.forget();
|
|
|
|
}
|
|
|
|
|
2013-02-15 00:04:11 -08:00
|
|
|
already_AddRefed<DOMMediaStream>
|
|
|
|
DOMMediaStream::CreateTrackUnionStream(nsIDOMWindow* aWindow, uint32_t aHintContents)
|
2012-10-24 16:21:32 -07:00
|
|
|
{
|
2013-02-15 00:04:11 -08:00
|
|
|
nsRefPtr<DOMMediaStream> stream = new DOMMediaStream();
|
|
|
|
stream->InitTrackUnionStream(aWindow, aHintContents);
|
2012-10-24 16:21:32 -07:00
|
|
|
return stream.forget();
|
|
|
|
}
|
|
|
|
|
2012-04-29 20:11:34 -07:00
|
|
|
bool
|
2013-02-15 00:01:58 -08:00
|
|
|
DOMMediaStream::CombineWithPrincipal(nsIPrincipal* aPrincipal)
|
2012-04-29 20:11:34 -07:00
|
|
|
{
|
|
|
|
return nsContentUtils::CombineResourcePrincipals(&mPrincipal, aPrincipal);
|
|
|
|
}
|
2013-02-15 00:04:11 -08:00
|
|
|
|
|
|
|
DOMLocalMediaStream::~DOMLocalMediaStream()
|
|
|
|
{
|
|
|
|
if (mStream) {
|
|
|
|
// Make sure Listeners of this stream know it's going away
|
|
|
|
Stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
|
|
|
DOMLocalMediaStream::WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap)
|
|
|
|
{
|
|
|
|
return dom::LocalMediaStreamBinding::Wrap(aCx, aScope, this, aTriedToWrap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMLocalMediaStream::Stop()
|
|
|
|
{
|
|
|
|
if (mStream && mStream->AsSourceStream()) {
|
|
|
|
mStream->AsSourceStream()->EndAllTrackAndFinish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMLocalMediaStream>
|
|
|
|
DOMLocalMediaStream::CreateSourceStream(nsIDOMWindow* aWindow, uint32_t aHintContents)
|
|
|
|
{
|
|
|
|
nsRefPtr<DOMLocalMediaStream> stream = new DOMLocalMediaStream();
|
|
|
|
stream->InitSourceStream(aWindow, aHintContents);
|
|
|
|
return stream.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMLocalMediaStream>
|
|
|
|
DOMLocalMediaStream::CreateTrackUnionStream(nsIDOMWindow* aWindow, uint32_t aHintContents)
|
|
|
|
{
|
|
|
|
nsRefPtr<DOMLocalMediaStream> stream = new DOMLocalMediaStream();
|
|
|
|
stream->InitTrackUnionStream(aWindow, aHintContents);
|
|
|
|
return stream.forget();
|
|
|
|
}
|