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/. */
|
|
|
|
|
|
|
|
#include "nsDOMMediaStream.h"
|
|
|
|
#include "nsDOMClassInfoID.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
|
|
|
DOMCI_DATA(MediaStream, nsDOMMediaStream)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMMediaStream)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMediaStream)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MediaStream)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMMediaStream)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMMediaStream)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDOMMediaStream)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMMediaStream)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2012-10-24 16:21:32 -07:00
|
|
|
// LocalMediaStream currently is the same C++ class as MediaStream;
|
|
|
|
// they may eventually split
|
|
|
|
DOMCI_DATA(LocalMediaStream, nsDOMLocalMediaStream)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMLocalMediaStream)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMLocalMediaStream)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMMediaStream, nsDOMMediaStream)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMLocalMediaStream)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(LocalMediaStream)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMLocalMediaStream)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMLocalMediaStream)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDOMLocalMediaStream)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMLocalMediaStream)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
|
2012-04-29 20:11:34 -07:00
|
|
|
nsDOMMediaStream::~nsDOMMediaStream()
|
|
|
|
{
|
|
|
|
if (mStream) {
|
|
|
|
mStream->Destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMMediaStream::GetCurrentTime(double *aCurrentTime)
|
|
|
|
{
|
|
|
|
*aCurrentTime = mStream ? MediaTimeToSeconds(mStream->GetCurrentTime()) : 0.0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-06 18:31:34 -08:00
|
|
|
nsDOMLocalMediaStream::~nsDOMLocalMediaStream()
|
|
|
|
{
|
|
|
|
if (mStream) {
|
|
|
|
// Make sure Listeners of this stream know it's going away
|
|
|
|
Stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-24 16:21:32 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMLocalMediaStream::Stop()
|
|
|
|
{
|
|
|
|
if (mStream && mStream->AsSourceStream()) {
|
|
|
|
mStream->AsSourceStream()->EndAllTrackAndFinish();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-29 20:11:40 -07:00
|
|
|
already_AddRefed<nsDOMMediaStream>
|
2012-10-28 21:36:31 -07:00
|
|
|
nsDOMMediaStream::CreateSourceStream(uint32_t aHintContents)
|
2012-04-29 20:11:40 -07:00
|
|
|
{
|
|
|
|
nsRefPtr<nsDOMMediaStream> stream = new nsDOMMediaStream();
|
2013-01-04 09:16:32 -08:00
|
|
|
stream->InitSourceStream(aHintContents);
|
2012-04-29 20:11:40 -07:00
|
|
|
return stream.forget();
|
|
|
|
}
|
|
|
|
|
2012-10-24 16:21:32 -07:00
|
|
|
already_AddRefed<nsDOMLocalMediaStream>
|
2012-10-28 21:36:31 -07:00
|
|
|
nsDOMLocalMediaStream::CreateSourceStream(uint32_t aHintContents)
|
2012-10-24 16:21:32 -07:00
|
|
|
{
|
|
|
|
nsRefPtr<nsDOMLocalMediaStream> stream = new nsDOMLocalMediaStream();
|
2013-01-04 09:16:32 -08:00
|
|
|
stream->InitSourceStream(aHintContents);
|
2012-10-24 16:21:32 -07:00
|
|
|
return stream.forget();
|
|
|
|
}
|
|
|
|
|
2012-07-31 05:17:22 -07:00
|
|
|
already_AddRefed<nsDOMMediaStream>
|
2012-12-18 23:07:37 -08:00
|
|
|
nsDOMMediaStream::CreateTrackUnionStream(uint32_t aHintContents)
|
2012-07-31 05:17:22 -07:00
|
|
|
{
|
|
|
|
nsRefPtr<nsDOMMediaStream> stream = new nsDOMMediaStream();
|
2013-01-04 09:16:32 -08:00
|
|
|
stream->InitTrackUnionStream(aHintContents);
|
2012-07-31 05:17:22 -07:00
|
|
|
return stream.forget();
|
|
|
|
}
|
|
|
|
|
2012-10-24 16:21:32 -07:00
|
|
|
already_AddRefed<nsDOMLocalMediaStream>
|
2012-12-18 23:07:37 -08:00
|
|
|
nsDOMLocalMediaStream::CreateTrackUnionStream(uint32_t aHintContents)
|
2012-10-24 16:21:32 -07:00
|
|
|
{
|
|
|
|
nsRefPtr<nsDOMLocalMediaStream> stream = new nsDOMLocalMediaStream();
|
2013-01-04 09:16:32 -08:00
|
|
|
stream->InitTrackUnionStream(aHintContents);
|
2012-10-24 16:21:32 -07:00
|
|
|
return stream.forget();
|
|
|
|
}
|
|
|
|
|
2012-04-29 20:11:34 -07:00
|
|
|
bool
|
|
|
|
nsDOMMediaStream::CombineWithPrincipal(nsIPrincipal* aPrincipal)
|
|
|
|
{
|
|
|
|
return nsContentUtils::CombineResourcePrincipals(&mPrincipal, aPrincipal);
|
|
|
|
}
|