Bug 1280445 - Remove wrapper from MediaStream. r=jesup, r=padenot

MozReview-Commit-ID: CTCFloIUXKa

--HG--
extra : rebase_source : b1c2073c638bb65c19a0f40e8d17e9a5bae15c98
extra : source : c6d854b3209e7de7d97153c0bfc492c1d5f1e6b5
This commit is contained in:
Andreas Pehrson 2016-06-29 12:27:13 +02:00
parent cdb03c0dcd
commit e028368c0f
19 changed files with 71 additions and 122 deletions

View File

@ -28,8 +28,8 @@ FakeMediaStreamGraph::DispatchToMainThreadAfterStreamStateUpdate(already_AddRefe
NS_DispatchToMainThread(task);
}
CameraPreviewMediaStream::CameraPreviewMediaStream(DOMMediaStream* aWrapper)
: ProcessedMediaStream(aWrapper)
CameraPreviewMediaStream::CameraPreviewMediaStream()
: ProcessedMediaStream()
, mMutex("mozilla::camera::CameraPreviewMediaStream")
, mInvalidatePending(0)
, mDiscardedFrames(0)

View File

@ -40,7 +40,7 @@ class CameraPreviewMediaStream : public ProcessedMediaStream
typedef mozilla::layers::Image Image;
public:
explicit CameraPreviewMediaStream(DOMMediaStream* aWrapper);
CameraPreviewMediaStream();
virtual void AddAudioOutput(void* aKey) override;
virtual void SetAudioOutputVolume(void* aKey, float aVolume) override;

View File

@ -259,7 +259,7 @@ nsDOMCameraControl::nsDOMCameraControl(uint32_t aCameraId,
, mSetInitialConfig(false)
{
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
mInput = new CameraPreviewMediaStream(this);
mInput = new CameraPreviewMediaStream();
mOwnedStream = mInput;
BindToOwner(aWindow);

View File

@ -4985,6 +4985,18 @@ void HTMLMediaElement::FireTimeUpdate(bool aPeriodic)
}
}
MediaStream* HTMLMediaElement::GetSrcMediaStream() const
{
if (!mSrcStream) {
return nullptr;
}
if (mSrcStream->GetCameraStream()) {
// XXX Remove this check with CameraPreviewMediaStream per bug 1124630.
return mSrcStream->GetCameraStream();
}
return mSrcStream->GetPlaybackStream();
}
void HTMLMediaElement::GetCurrentSpec(nsCString& aString)
{
if (mLoadingSrc) {

View File

@ -55,6 +55,8 @@ class TextTrack;
class TimeRanges;
class WakeLock;
class MediaTrack;
class MediaStreamTrack;
class VideoStreamTrack;
} // namespace dom
} // namespace mozilla
@ -403,17 +405,7 @@ public:
* null but its GetPlaybackStream() returns null --- which can happen during
* cycle collection unlinking!
*/
MediaStream* GetSrcMediaStream() const
{
if (!mSrcStream) {
return nullptr;
}
if (mSrcStream->GetCameraStream()) {
// XXX Remove this check with CameraPreviewMediaStream per bug 1124630.
return mSrcStream->GetCameraStream();
}
return mSrcStream->GetPlaybackStream();
}
MediaStream* GetSrcMediaStream() const;
// WebIDL

View File

@ -29,8 +29,8 @@ namespace mozilla
// We are mixing to mono until PeerConnection can accept stereo
static const uint32_t MONO = 1;
AudioCaptureStream::AudioCaptureStream(DOMMediaStream* aWrapper, TrackID aTrackId)
: ProcessedMediaStream(aWrapper), mTrackId(aTrackId), mStarted(false), mTrackCreated(false)
AudioCaptureStream::AudioCaptureStream(TrackID aTrackId)
: ProcessedMediaStream(), mTrackId(aTrackId), mStarted(false), mTrackCreated(false)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_COUNT_CTOR(AudioCaptureStream);

View File

@ -23,7 +23,7 @@ class AudioCaptureStream : public ProcessedMediaStream,
public MixerCallbackReceiver
{
public:
explicit AudioCaptureStream(DOMMediaStream* aWrapper, TrackID aTrackId);
explicit AudioCaptureStream(TrackID aTrackId);
virtual ~AudioCaptureStream();
void Start();

View File

@ -416,6 +416,8 @@ DOMMediaStream::Destroy()
mInputStream->UnregisterUser();
mInputStream = nullptr;
}
mRunOnTracksAvailable.Clear();
mTrackListeners.Clear();
}
JSObject*
@ -781,7 +783,7 @@ DOMMediaStream::IsFinished()
void
DOMMediaStream::InitSourceStream(MediaStreamGraph* aGraph)
{
InitInputStreamCommon(aGraph->CreateSourceStream(nullptr), aGraph);
InitInputStreamCommon(aGraph->CreateSourceStream(), aGraph);
InitOwnedStreamCommon(aGraph);
InitPlaybackStreamCommon(aGraph);
}
@ -789,7 +791,7 @@ DOMMediaStream::InitSourceStream(MediaStreamGraph* aGraph)
void
DOMMediaStream::InitTrackUnionStream(MediaStreamGraph* aGraph)
{
InitInputStreamCommon(aGraph->CreateTrackUnionStream(nullptr), aGraph);
InitInputStreamCommon(aGraph->CreateTrackUnionStream(), aGraph);
InitOwnedStreamCommon(aGraph);
InitPlaybackStreamCommon(aGraph);
}
@ -803,7 +805,7 @@ DOMMediaStream::InitAudioCaptureStream(nsIPrincipal* aPrincipal, MediaStreamGrap
new BasicUnstoppableTrackSource(aPrincipal, MediaSourceEnum::AudioCapture);
AudioCaptureStream* audioCaptureStream =
static_cast<AudioCaptureStream*>(aGraph->CreateAudioCaptureStream(this, AUDIO_TRACK));
static_cast<AudioCaptureStream*>(aGraph->CreateAudioCaptureStream(AUDIO_TRACK));
InitInputStreamCommon(audioCaptureStream, aGraph);
InitOwnedStreamCommon(aGraph);
InitPlaybackStreamCommon(aGraph);
@ -826,9 +828,7 @@ DOMMediaStream::InitOwnedStreamCommon(MediaStreamGraph* aGraph)
{
MOZ_ASSERT(!mPlaybackStream, "Owned stream must be initialized before playback stream");
// We pass null as the wrapper since it is only used to signal finished
// streams. This is only needed for the playback stream.
mOwnedStream = aGraph->CreateTrackUnionStream(nullptr);
mOwnedStream = aGraph->CreateTrackUnionStream();
mOwnedStream->SetAutofinish(true);
mOwnedStream->RegisterUser();
if (mInputStream) {
@ -843,7 +843,7 @@ DOMMediaStream::InitOwnedStreamCommon(MediaStreamGraph* aGraph)
void
DOMMediaStream::InitPlaybackStreamCommon(MediaStreamGraph* aGraph)
{
mPlaybackStream = aGraph->CreateTrackUnionStream(this);
mPlaybackStream = aGraph->CreateTrackUnionStream();
mPlaybackStream->SetAutofinish(true);
mPlaybackStream->RegisterUser();
if (mOwnedStream) {
@ -1130,24 +1130,6 @@ DOMMediaStream::FindPlaybackTrackPort(const MediaStreamTrack& aTrack) const
return FindTrackPortAmongTracks(aTrack, mTracks);
}
void
DOMMediaStream::NotifyMediaStreamGraphShutdown()
{
// No more tracks will ever be added, so just clear these callbacks now
// to prevent leaks.
mNotifiedOfMediaStreamGraphShutdown = true;
mRunOnTracksAvailable.Clear();
mTrackListeners.Clear();
mConsumersToKeepAlive.Clear();
}
void
DOMMediaStream::NotifyStreamFinished()
{
MOZ_ASSERT(IsFinished());
mConsumersToKeepAlive.Clear();
}
void
DOMMediaStream::OnTracksAvailable(OnTracksAvailableCallback* aRunnable)
{

View File

@ -478,17 +478,6 @@ public:
*/
bool RemovePrincipalChangeObserver(dom::PrincipalChangeObserver<DOMMediaStream>* aObserver);
/**
* Called when this stream's MediaStreamGraph has been shut down. Normally
* MSGs are only shut down when all streams have been removed, so this
* will only be called during a forced shutdown due to application exit.
*/
void NotifyMediaStreamGraphShutdown();
/**
* Called when the main-thread state of the MediaStream goes to finished.
*/
void NotifyStreamFinished();
// Webrtc allows the remote side to name a stream whatever it wants, and we
// need to surface this to content.
void AssignId(const nsAString& aID) { mID = aID; }
@ -555,13 +544,11 @@ public:
/**
* Add an nsISupports object that this stream will keep alive as long as
* the stream is not finished.
* the stream itself is alive.
*/
void AddConsumerToKeepAlive(nsISupports* aConsumer)
{
if (!IsFinished() && !mNotifiedOfMediaStreamGraphShutdown) {
mConsumersToKeepAlive.AppendElement(aConsumer);
}
mConsumersToKeepAlive.AppendElement(aConsumer);
}
// Registers a track listener to this MediaStream, for listening to changes
@ -685,7 +672,12 @@ protected:
// track sources.
RefPtr<MediaStreamTrackSourceGetter> mTrackSourceGetter;
// Listener tracking changes to mOwnedStream. We use this to notify the
// MediaStreamTracks we own about state changes.
RefPtr<OwnedStreamListener> mOwnedListener;
// Listener tracking changes to mPlaybackStream. This drives state changes
// in this DOMMediaStream and notifications to mTrackListeners.
RefPtr<PlaybackStreamListener> mPlaybackListener;
nsTArray<nsAutoPtr<OnTracksAvailableCallback> > mRunOnTracksAvailable;
@ -695,8 +687,8 @@ protected:
nsString mID;
// Keep these alive until the stream finishes
nsTArray<nsCOMPtr<nsISupports> > mConsumersToKeepAlive;
// Keep these alive while the stream is alive.
nsTArray<nsCOMPtr<nsISupports>> mConsumersToKeepAlive;
bool mNotifiedOfMediaStreamGraphShutdown;

View File

@ -837,7 +837,7 @@ public:
domStream =
DOMMediaStream::CreateAudioCaptureStreamAsInput(window, principal, msg);
stream = msg->CreateSourceStream(nullptr); // Placeholder
stream = msg->CreateSourceStream(); // Placeholder
msg->RegisterCaptureStreamForWindow(
mWindowID, domStream->GetInputStream()->AsProcessedStream());
window->SetAudioCapture(true);

View File

@ -467,7 +467,7 @@ public:
// Create a Track Union Stream
MediaStreamGraph* gm = mRecorder->GetSourceMediaStream()->Graph();
mTrackUnionStream = gm->CreateTrackUnionStream(nullptr);
mTrackUnionStream = gm->CreateTrackUnionStream();
MOZ_ASSERT(mTrackUnionStream, "CreateTrackUnionStream failed");
mTrackUnionStream->SetAutofinish(true);

View File

@ -25,7 +25,6 @@
#include "mozilla/dom/AudioContextBinding.h"
#include "mozilla/media/MediaUtils.h"
#include <algorithm>
#include "DOMMediaStream.h"
#include "GeckoProfiler.h"
#include "mozilla/unused.h"
#include "mozilla/media/MediaUtils.h"
@ -1622,10 +1621,6 @@ MediaStreamGraphImpl::ApplyStreamUpdate(StreamUpdate* aUpdate)
stream->mMainThreadFinished = aUpdate->mNextMainThreadFinished;
if (stream->ShouldNotifyStreamFinished()) {
if (stream->mWrapper) {
stream->mWrapper->NotifyStreamFinished();
}
stream->NotifyMainThreadListeners();
}
}
@ -1699,12 +1694,6 @@ public:
// delete it.
NS_ASSERTION(mGraph->mForceShutDown || !mGraph->mRealtime,
"Not in forced shutdown?");
for (MediaStream* stream : mGraph->AllStreams()) {
DOMMediaStream* s = stream->GetWrapper();
if (s) {
s->NotifyMediaStreamGraphShutdown();
}
}
mGraph->mLifecycleState =
MediaStreamGraphImpl::LIFECYCLE_WAITING_FOR_STREAM_DESTRUCTION;
@ -1983,7 +1972,7 @@ MediaStreamGraphImpl::AppendMessage(UniquePtr<ControlMessage> aMessage)
EnsureRunInStableState();
}
MediaStream::MediaStream(DOMMediaStream* aWrapper)
MediaStream::MediaStream()
: mTracksStartTime(0)
, mStartBlocking(GRAPH_TIME_MAX)
, mSuspendedCount(0)
@ -1992,7 +1981,6 @@ MediaStream::MediaStream(DOMMediaStream* aWrapper)
, mNotifiedBlocked(false)
, mHasCurrentData(false)
, mNotifiedHasCurrentData(false)
, mWrapper(aWrapper)
, mMainThreadCurrentTime(0)
, mMainThreadFinished(false)
, mFinishedNotificationSent(false)
@ -2002,11 +1990,6 @@ MediaStream::MediaStream(DOMMediaStream* aWrapper)
, mAudioChannelType(dom::AudioChannel::Normal)
{
MOZ_COUNT_CTOR(MediaStream);
// aWrapper should not already be connected to a MediaStream! It needs
// to be hooked up to this stream, and since this stream is only just
// being created now, aWrapper must not be connected to anything.
NS_ASSERTION(!aWrapper || !aWrapper->GetPlaybackStream(),
"Wrapper already has another media stream hooked up to it!");
}
size_t
@ -2018,7 +2001,6 @@ MediaStream::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
// - mGraph - Not reported here
// - mConsumers - elements
// Future:
// - mWrapper
// - mVideoOutputs - elements
// - mLastPlayedVideoFrame
// - mListeners - elements
@ -2165,7 +2147,6 @@ MediaStream::Destroy()
void RunDuringShutdown() override
{ Run(); }
};
mWrapper = nullptr;
GraphImpl()->AppendMessage(MakeUnique<Message>(this));
// Message::RunDuringShutdown may have removed this stream from the graph,
// but our kungFuDeathGrip above will have kept this stream alive if
@ -3552,26 +3533,25 @@ MediaStreamGraphImpl::CollectReports(nsIHandleReportCallback* aHandleReport,
}
SourceMediaStream*
MediaStreamGraph::CreateSourceStream(DOMMediaStream* aWrapper)
MediaStreamGraph::CreateSourceStream()
{
SourceMediaStream* stream = new SourceMediaStream(aWrapper);
SourceMediaStream* stream = new SourceMediaStream();
AddStream(stream);
return stream;
}
ProcessedMediaStream*
MediaStreamGraph::CreateTrackUnionStream(DOMMediaStream* aWrapper)
MediaStreamGraph::CreateTrackUnionStream()
{
TrackUnionStream* stream = new TrackUnionStream(aWrapper);
TrackUnionStream* stream = new TrackUnionStream();
AddStream(stream);
return stream;
}
ProcessedMediaStream*
MediaStreamGraph::CreateAudioCaptureStream(DOMMediaStream* aWrapper,
TrackID aTrackId)
MediaStreamGraph::CreateAudioCaptureStream(TrackID aTrackId)
{
AudioCaptureStream* stream = new AudioCaptureStream(aWrapper, aTrackId);
AudioCaptureStream* stream = new AudioCaptureStream(aTrackId);
AddStream(stream);
return stream;
}

View File

@ -23,7 +23,6 @@
#include "nsAutoPtr.h"
#include "nsAutoRef.h"
#include <speex/speex_resampler.h>
#include "DOMMediaStream.h"
class nsIRunnable;
@ -79,7 +78,16 @@ namespace media {
* reprocess it. This is triggered automatically by the MediaStreamGraph.
*/
class AudioNodeEngine;
class AudioNodeExternalInputStream;
class AudioNodeStream;
class CameraPreviewMediaStream;
class MediaInputPort;
class MediaStream;
class MediaStreamGraph;
class MediaStreamGraphImpl;
class ProcessedMediaStream;
class SourceMediaStream;
/**
* This is a base class for media graph thread listener callbacks.
@ -439,15 +447,6 @@ struct AudioNodeSizes
nsCString mNodeType;
};
class MediaStreamGraphImpl;
class SourceMediaStream;
class ProcessedMediaStream;
class MediaInputPort;
class AudioNodeEngine;
class AudioNodeExternalInputStream;
class AudioNodeStream;
class CameraPreviewMediaStream;
/**
* Helper struct for binding a track listener to a specific TrackID.
*/
@ -533,7 +532,7 @@ class MediaStream : public mozilla::LinkedListElement<MediaStream>
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaStream)
explicit MediaStream(DOMMediaStream* aWrapper);
MediaStream();
protected:
// Protected destructor, to discourage deletion outside of Release():
@ -798,12 +797,6 @@ public:
virtual void ApplyTrackDisabling(TrackID aTrackID, MediaSegment* aSegment, MediaSegment* aRawSegment = nullptr);
DOMMediaStream* GetWrapper()
{
NS_ASSERTION(NS_IsMainThread(), "Only use DOMMediaStream on main thread");
return mWrapper;
}
// Return true if the main thread needs to observe updates from this stream.
virtual bool MainThreadNeedsUpdates() const
{
@ -938,8 +931,6 @@ protected:
*/
bool mNotifiedHasCurrentData;
// This state is only used on the main thread.
DOMMediaStream* mWrapper;
// Main-thread views of state
StreamTime mMainThreadCurrentTime;
bool mMainThreadFinished;
@ -962,8 +953,8 @@ protected:
class SourceMediaStream : public MediaStream
{
public:
explicit SourceMediaStream(DOMMediaStream* aWrapper) :
MediaStream(aWrapper),
explicit SourceMediaStream() :
MediaStream(),
mMutex("mozilla::media::SourceMediaStream"),
mUpdateKnownTracksTime(0),
mPullEnabled(false),
@ -1385,8 +1376,8 @@ private:
class ProcessedMediaStream : public MediaStream
{
public:
explicit ProcessedMediaStream(DOMMediaStream* aWrapper)
: MediaStream(aWrapper), mAutofinish(false), mCycleMarker(0)
explicit ProcessedMediaStream()
: MediaStream(), mAutofinish(false), mCycleMarker(0)
{}
// Control API.
@ -1545,7 +1536,7 @@ public:
* Create a stream that a media decoder (or some other source of
* media data, such as a camera) can write to.
*/
SourceMediaStream* CreateSourceStream(DOMMediaStream* aWrapper);
SourceMediaStream* CreateSourceStream();
/**
* Create a stream that will form the union of the tracks of its input
* streams.
@ -1560,12 +1551,11 @@ public:
* TODO at some point we will probably need to add API to select
* particular tracks of each input stream.
*/
ProcessedMediaStream* CreateTrackUnionStream(DOMMediaStream* aWrapper);
ProcessedMediaStream* CreateTrackUnionStream();
/**
* Create a stream that will mix all its audio input.
*/
ProcessedMediaStream* CreateAudioCaptureStream(DOMMediaStream* aWrapper,
TrackID aTrackId);
ProcessedMediaStream* CreateAudioCaptureStream(TrackID aTrackId);
/**
* Add a new stream to the graph. Main thread.

View File

@ -17,6 +17,7 @@
#include "nsIRunnable.h"
#include "nsIAsyncShutdown.h"
#include "Latency.h"
#include "mozilla/Services.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/WeakPtr.h"
#include "GraphDriver.h"

View File

@ -45,8 +45,8 @@ namespace mozilla {
LazyLogModule gTrackUnionStreamLog("TrackUnionStream");
#define STREAM_LOG(type, msg) MOZ_LOG(gTrackUnionStreamLog, type, msg)
TrackUnionStream::TrackUnionStream(DOMMediaStream* aWrapper) :
ProcessedMediaStream(aWrapper), mNextAvailableTrackID(1)
TrackUnionStream::TrackUnionStream() :
ProcessedMediaStream(), mNextAvailableTrackID(1)
{
}

View File

@ -17,7 +17,7 @@ namespace mozilla {
*/
class TrackUnionStream : public ProcessedMediaStream {
public:
explicit TrackUnionStream(DOMMediaStream* aWrapper);
explicit TrackUnionStream();
void RemoveInput(MediaInputPort* aPort) override;
void ProcessInput(GraphTime aFrom, GraphTime aTo, uint32_t aFlags) override;

View File

@ -162,7 +162,7 @@ DecodedStreamData::DecodedStreamData(OutputStreamManager* aOutputStreamManager,
, mHaveSentFinish(false)
, mHaveSentFinishAudio(false)
, mHaveSentFinishVideo(false)
, mStream(aOutputStreamManager->Graph()->CreateSourceStream(nullptr))
, mStream(aOutputStreamManager->Graph()->CreateSourceStream())
// DecodedStreamGraphListener will resolve this promise.
, mListener(new DecodedStreamGraphListener(mStream, Move(aPromise)))
// mPlaying is initially true because MDSM won't start playback until playing

View File

@ -29,7 +29,7 @@ namespace mozilla {
AudioNodeStream::AudioNodeStream(AudioNodeEngine* aEngine,
Flags aFlags,
TrackRate aSampleRate)
: ProcessedMediaStream(nullptr),
: ProcessedMediaStream(),
mEngine(aEngine),
mSampleRate(aSampleRate),
mFlags(aFlags),

View File

@ -162,7 +162,7 @@ nsSpeechTask::InitDirectAudio()
{
mStream = MediaStreamGraph::GetInstance(MediaStreamGraph::AUDIO_THREAD_DRIVER,
AudioChannel::Normal)->
CreateSourceStream(nullptr);
CreateSourceStream();
mIndirectAudio = false;
mInited = true;
}