gecko/content/media/nsDOMMediaStream.cpp
Robert O'Callahan 727fa86a21 Bug 779715. Part 6: Rework capturing MediaStreams from media elements to use TrackUnionStreams. r=cpearce,jesup
Moves to a new setup where a decoder manages a single SourceMediaStream internally. Each stream
returned from mozCaptureStream(UntilEnded) is a TrackUnionStream which is fed by the
decoder's SourceMediaStream.
We want the captured streams to be blocked while the media element is not playing. We do that
by blocking any captured stream that has no SourceMediaStream feeding into it, and blocking
any SourceMediaStream while its decoder is not playing.
We arrange for the decoders's PlaybackEnded to be delayed until its SourceMediaStream has
finished according to the media stream graph. This ensures the state of captured media streams
corresponds more closely to the media element state.

--HG--
extra : rebase_source : 3324ff0e9bdce9c71a23c0f5f2032815e9046081
2012-08-01 00:17:22 +12:00

68 lines
1.9 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
/* 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_CLASS(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
nsDOMMediaStream::~nsDOMMediaStream()
{
if (mStream) {
mStream->Destroy();
}
}
NS_IMETHODIMP
nsDOMMediaStream::GetCurrentTime(double *aCurrentTime)
{
*aCurrentTime = mStream ? MediaTimeToSeconds(mStream->GetCurrentTime()) : 0.0;
return NS_OK;
}
already_AddRefed<nsDOMMediaStream>
nsDOMMediaStream::CreateInputStream()
{
nsRefPtr<nsDOMMediaStream> stream = new nsDOMMediaStream();
MediaStreamGraph* gm = MediaStreamGraph::GetInstance();
stream->mStream = gm->CreateInputStream(stream);
return stream.forget();
}
already_AddRefed<nsDOMMediaStream>
nsDOMMediaStream::CreateTrackUnionStream()
{
nsRefPtr<nsDOMMediaStream> stream = new nsDOMMediaStream();
MediaStreamGraph* gm = MediaStreamGraph::GetInstance();
stream->mStream = gm->CreateTrackUnionStream(stream);
return stream.forget();
}
bool
nsDOMMediaStream::CombineWithPrincipal(nsIPrincipal* aPrincipal)
{
return nsContentUtils::CombineResourcePrincipals(&mPrincipal, aPrincipal);
}