Bug 1247395 - use UniquePtr for control messages in MediaStreamGraphImpl; r=roc

This commit is contained in:
Nathan Froyd 2016-01-20 16:14:33 -05:00
parent 05c5f9a9b1
commit 4be833cfe1
4 changed files with 51 additions and 51 deletions

View File

@ -985,7 +985,7 @@ MediaStreamGraphImpl::OpenAudioInput(CubebUtils::AudioDeviceID aID,
CubebUtils::AudioDeviceID mID;
RefPtr<AudioDataListener> mListener;
};
this->AppendMessage(new Message(this, aID, aListener));
this->AppendMessage(MakeUnique<Message>(this, aID, aListener));
return NS_OK;
}
@ -1052,7 +1052,7 @@ MediaStreamGraphImpl::CloseAudioInput(AudioDataListener *aListener)
MediaStreamGraphImpl *mGraph;
RefPtr<AudioDataListener> mListener;
};
this->AppendMessage(new Message(this, aListener));
this->AppendMessage(MakeUnique<Message>(this, aListener));
}
@ -1166,7 +1166,7 @@ MediaStreamGraphImpl::AllFinishedStreamsNotified()
}
void
MediaStreamGraphImpl::RunMessageAfterProcessing(nsAutoPtr<ControlMessage> aMessage)
MediaStreamGraphImpl::RunMessageAfterProcessing(UniquePtr<ControlMessage> aMessage)
{
MOZ_ASSERT(CurrentDriver()->OnThread());
@ -1186,7 +1186,7 @@ MediaStreamGraphImpl::RunMessagesInQueue()
// batch corresponding to an event loop task). This isolates the performance
// of different scripts to some extent.
for (uint32_t i = 0; i < mFrontMessageQueue.Length(); ++i) {
nsTArray<nsAutoPtr<ControlMessage> >& messages = mFrontMessageQueue[i].mMessages;
nsTArray<UniquePtr<ControlMessage>>& messages = mFrontMessageQueue[i].mMessages;
for (uint32_t j = 0; j < messages.Length(); ++j) {
messages[j]->Run();
@ -1543,7 +1543,7 @@ MediaStreamGraphImpl::RunInStableState(bool aSourceIsMSG)
// When we're doing a forced shutdown, pending control messages may be
// run on the main thread via RunDuringShutdown. Those messages must
// run without the graph monitor being held. So, we collect them here.
nsTArray<nsAutoPtr<ControlMessage> > controlMessagesToRunDuringShutdown;
nsTArray<UniquePtr<ControlMessage>> controlMessagesToRunDuringShutdown;
{
MonitorAutoLock lock(mMonitor);
@ -1721,7 +1721,7 @@ MediaStreamGraphImpl::EnsureStableStateEventPosted()
}
void
MediaStreamGraphImpl::AppendMessage(ControlMessage* aMessage)
MediaStreamGraphImpl::AppendMessage(UniquePtr<ControlMessage> aMessage)
{
MOZ_ASSERT(NS_IsMainThread(), "main thread only");
MOZ_ASSERT(!aMessage->GetStream() ||
@ -1744,7 +1744,6 @@ MediaStreamGraphImpl::AppendMessage(ControlMessage* aMessage)
#ifdef DEBUG
mCanRunMessagesSynchronously = true;
#endif
delete aMessage;
if (IsEmpty() &&
mLifecycleState >= LIFECYCLE_WAITING_FOR_STREAM_DESTRUCTION) {
@ -1758,7 +1757,7 @@ MediaStreamGraphImpl::AppendMessage(ControlMessage* aMessage)
return;
}
mCurrentTaskMessageQueue.AppendElement(aMessage);
mCurrentTaskMessageQueue.AppendElement(Move(aMessage));
EnsureRunInStableState();
}
@ -1936,7 +1935,7 @@ MediaStream::Destroy()
{ Run(); }
};
mWrapper = nullptr;
GraphImpl()->AppendMessage(new Message(this));
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
// necessary.
@ -1955,7 +1954,7 @@ MediaStream::AddAudioOutput(void* aKey)
}
void* mKey;
};
GraphImpl()->AppendMessage(new Message(this, aKey));
GraphImpl()->AppendMessage(MakeUnique<Message>(this, aKey));
}
void
@ -1984,7 +1983,7 @@ MediaStream::SetAudioOutputVolume(void* aKey, float aVolume)
void* mKey;
float mVolume;
};
GraphImpl()->AppendMessage(new Message(this, aKey, aVolume));
GraphImpl()->AppendMessage(MakeUnique<Message>(this, aKey, aVolume));
}
void
@ -2022,7 +2021,7 @@ MediaStream::RemoveAudioOutput(void* aKey)
}
void* mKey;
};
GraphImpl()->AppendMessage(new Message(this, aKey));
GraphImpl()->AppendMessage(MakeUnique<Message>(this, aKey));
}
void
@ -2058,7 +2057,7 @@ MediaStream::AddVideoOutput(VideoFrameContainer* aContainer)
}
RefPtr<VideoFrameContainer> mContainer;
};
GraphImpl()->AppendMessage(new Message(this, aContainer));
GraphImpl()->AppendMessage(MakeUnique<Message>(this, aContainer));
}
void
@ -2074,7 +2073,7 @@ MediaStream::RemoveVideoOutput(VideoFrameContainer* aContainer)
}
RefPtr<VideoFrameContainer> mContainer;
};
GraphImpl()->AppendMessage(new Message(this, aContainer));
GraphImpl()->AppendMessage(MakeUnique<Message>(this, aContainer));
}
void
@ -2095,7 +2094,7 @@ MediaStream::Suspend()
if (mMainThreadDestroyed) {
return;
}
GraphImpl()->AppendMessage(new Message(this));
GraphImpl()->AppendMessage(MakeUnique<Message>(this));
}
void
@ -2116,7 +2115,7 @@ MediaStream::Resume()
if (mMainThreadDestroyed) {
return;
}
GraphImpl()->AppendMessage(new Message(this));
GraphImpl()->AppendMessage(MakeUnique<Message>(this));
}
void
@ -2146,7 +2145,7 @@ MediaStream::AddListener(MediaStreamListener* aListener)
}
RefPtr<MediaStreamListener> mListener;
};
GraphImpl()->AppendMessage(new Message(this, aListener));
GraphImpl()->AppendMessage(MakeUnique<Message>(this, aListener));
}
void
@ -2174,7 +2173,7 @@ MediaStream::RemoveListener(MediaStreamListener* aListener)
// If the stream is destroyed the Listeners have or will be
// removed.
if (!IsDestroyed()) {
GraphImpl()->AppendMessage(new Message(this, aListener));
GraphImpl()->AppendMessage(MakeUnique<Message>(this, aListener));
}
}
@ -2214,7 +2213,7 @@ MediaStream::RunAfterPendingUpdates(already_AddRefed<nsIRunnable> aRunnable)
nsCOMPtr<nsIRunnable> mRunnable;
};
graph->AppendMessage(new Message(this, runnable.forget()));
graph->AppendMessage(MakeUnique<Message>(this, runnable.forget()));
}
void
@ -2243,7 +2242,7 @@ MediaStream::SetTrackEnabled(TrackID aTrackID, bool aEnabled)
TrackID mTrackID;
bool mEnabled;
};
GraphImpl()->AppendMessage(new Message(this, aTrackID, aEnabled));
GraphImpl()->AppendMessage(MakeUnique<Message>(this, aTrackID, aEnabled));
}
void
@ -2450,7 +2449,7 @@ SourceMediaStream::NotifyListenersEvent(MediaStreamListener::MediaStreamGraphEve
}
MediaStreamListener::MediaStreamGraphEvent mEvent;
};
GraphImpl()->AppendMessage(new Message(this, aNewEvent));
GraphImpl()->AppendMessage(MakeUnique<Message>(this, aNewEvent));
}
void
@ -2622,7 +2621,7 @@ MediaInputPort::Destroy()
}
MediaInputPort* mPort;
};
GraphImpl()->AppendMessage(new Message(this));
GraphImpl()->AppendMessage(MakeUnique<Message>(this));
}
MediaStreamGraphImpl*
@ -2672,7 +2671,7 @@ MediaInputPort::BlockTrackId(TrackID aTrackId)
MOZ_ASSERT(aTrackId != TRACK_NONE && aTrackId != TRACK_INVALID && aTrackId != TRACK_ANY,
"Only explicit TrackID is allowed");
GraphImpl()->AppendMessage(new Message(this, aTrackId));
GraphImpl()->AppendMessage(MakeUnique<Message>(this, aTrackId));
}
already_AddRefed<MediaInputPort>
@ -2706,7 +2705,7 @@ ProcessedMediaStream::AllocateInputPort(MediaStream* aStream, TrackID aTrackID,
RefPtr<MediaInputPort> port = new MediaInputPort(aStream, aTrackID, this,
aInputNumber, aOutputNumber);
port->SetGraphImpl(GraphImpl());
GraphImpl()->AppendMessage(new Message(port));
GraphImpl()->AppendMessage(MakeUnique<Message>(port));
return port.forget();
}
@ -2722,7 +2721,7 @@ ProcessedMediaStream::Finish()
mStream->GraphImpl()->FinishStream(mStream);
}
};
GraphImpl()->AppendMessage(new Message(this));
GraphImpl()->AppendMessage(MakeUnique<Message>(this));
}
void
@ -2738,7 +2737,7 @@ ProcessedMediaStream::SetAutofinish(bool aAutofinish)
}
bool mAutofinish;
};
GraphImpl()->AppendMessage(new Message(this, aAutofinish));
GraphImpl()->AppendMessage(MakeUnique<Message>(this, aAutofinish));
}
void
@ -3026,7 +3025,7 @@ MediaStreamGraph::AddStream(MediaStream* aStream)
NS_ADDREF(aStream);
MediaStreamGraphImpl* graph = static_cast<MediaStreamGraphImpl*>(this);
aStream->SetGraphImpl(graph);
graph->AppendMessage(new CreateMessage(aStream));
graph->AppendMessage(MakeUnique<CreateMessage>(aStream));
}
class GraphStartedRunnable final : public nsRunnable
@ -3083,7 +3082,7 @@ MediaStreamGraph::NotifyWhenGraphStarted(AudioNodeStream* aStream)
if (!aStream->IsDestroyed()) {
MediaStreamGraphImpl* graphImpl = static_cast<MediaStreamGraphImpl*>(this);
graphImpl->AppendMessage(new GraphStartedNotificationControlMessage(aStream));
graphImpl->AppendMessage(MakeUnique<GraphStartedNotificationControlMessage>(aStream));
}
}
@ -3302,8 +3301,8 @@ MediaStreamGraph::ApplyAudioContextOperation(MediaStream* aDestinationStream,
MediaStreamGraphImpl* graphImpl = static_cast<MediaStreamGraphImpl*>(this);
graphImpl->AppendMessage(
new AudioContextOperationControlMessage(aDestinationStream, aStreams,
aOperation, aPromise));
MakeUnique<AudioContextOperationControlMessage>(aDestinationStream, aStreams,
aOperation, aPromise));
}
bool

View File

@ -15,6 +15,7 @@
#include "nsIRunnable.h"
#include "nsIAsyncShutdown.h"
#include "Latency.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/WeakPtr.h"
#include "GraphDriver.h"
#include "AudioMixer.h"
@ -80,7 +81,7 @@ protected:
class MessageBlock
{
public:
nsTArray<nsAutoPtr<ControlMessage> > mMessages;
nsTArray<UniquePtr<ControlMessage>> mMessages;
};
/**
@ -139,7 +140,7 @@ public:
* Append a ControlMessage to the message queue. This queue is drained
* during RunInStableState; the messages will run on the graph thread.
*/
void AppendMessage(ControlMessage* aMessage);
void AppendMessage(UniquePtr<ControlMessage> aMessage);
// Shutdown helpers.
@ -293,7 +294,7 @@ public:
* Schedules |aMessage| to run after processing, at a time when graph state
* can be changed. Graph thread.
*/
void RunMessageAfterProcessing(nsAutoPtr<ControlMessage> aMessage);
void RunMessageAfterProcessing(UniquePtr<ControlMessage> aMessage);
/**
* Called when a suspend/resume/close operation has been completed, on the
@ -748,7 +749,7 @@ public:
* immediately because we want all messages between stable states to be
* processed as an atomic batch.
*/
nsTArray<nsAutoPtr<ControlMessage> > mCurrentTaskMessageQueue;
nsTArray<UniquePtr<ControlMessage>> mCurrentTaskMessageQueue;
/**
* True when RunInStableState has determined that mLifecycleState is >
* LIFECYCLE_RUNNING. Since only the main thread can reset mLifecycleState to

View File

@ -147,9 +147,9 @@ AudioNodeStream::SetStreamTimeParameter(uint32_t aIndex, AudioContext* aContext,
uint32_t mIndex;
};
GraphImpl()->AppendMessage(new Message(this, aIndex,
aContext->DestinationStream(),
aStreamTime));
GraphImpl()->AppendMessage(MakeUnique<Message>(this, aIndex,
aContext->DestinationStream(),
aStreamTime));
}
void
@ -178,7 +178,7 @@ AudioNodeStream::SetDoubleParameter(uint32_t aIndex, double aValue)
uint32_t mIndex;
};
GraphImpl()->AppendMessage(new Message(this, aIndex, aValue));
GraphImpl()->AppendMessage(MakeUnique<Message>(this, aIndex, aValue));
}
void
@ -199,7 +199,7 @@ AudioNodeStream::SetInt32Parameter(uint32_t aIndex, int32_t aValue)
uint32_t mIndex;
};
GraphImpl()->AppendMessage(new Message(this, aIndex, aValue));
GraphImpl()->AppendMessage(MakeUnique<Message>(this, aIndex, aValue));
}
void
@ -225,7 +225,7 @@ AudioNodeStream::SendTimelineEvent(uint32_t aIndex,
TrackRate mSampleRate;
uint32_t mIndex;
};
GraphImpl()->AppendMessage(new Message(this, aIndex, aEvent));
GraphImpl()->AppendMessage(MakeUnique<Message>(this, aIndex, aEvent));
}
void
@ -246,7 +246,7 @@ AudioNodeStream::SetThreeDPointParameter(uint32_t aIndex, const ThreeDPoint& aVa
uint32_t mIndex;
};
GraphImpl()->AppendMessage(new Message(this, aIndex, aValue));
GraphImpl()->AppendMessage(MakeUnique<Message>(this, aIndex, aValue));
}
void
@ -267,7 +267,7 @@ AudioNodeStream::SetBuffer(already_AddRefed<ThreadSharedFloatArrayBufferList>&&
RefPtr<ThreadSharedFloatArrayBufferList> mBuffer;
};
GraphImpl()->AppendMessage(new Message(this, aBuffer));
GraphImpl()->AppendMessage(MakeUnique<Message>(this, aBuffer));
}
void
@ -289,7 +289,7 @@ AudioNodeStream::SetRawArrayData(nsTArray<float>& aData)
nsTArray<float> mData;
};
GraphImpl()->AppendMessage(new Message(this, aData));
GraphImpl()->AppendMessage(MakeUnique<Message>(this, aData));
}
void
@ -320,9 +320,9 @@ AudioNodeStream::SetChannelMixingParameters(uint32_t aNumberOfChannels,
ChannelInterpretation mChannelInterpretation;
};
GraphImpl()->AppendMessage(new Message(this, aNumberOfChannels,
aChannelCountMode,
aChannelInterpretation));
GraphImpl()->AppendMessage(MakeUnique<Message>(this, aNumberOfChannels,
aChannelCountMode,
aChannelInterpretation));
}
void
@ -341,7 +341,7 @@ AudioNodeStream::SetPassThrough(bool aPassThrough)
bool mPassThrough;
};
GraphImpl()->AppendMessage(new Message(this, aPassThrough));
GraphImpl()->AppendMessage(MakeUnique<Message>(this, aPassThrough));
}
void
@ -399,7 +399,7 @@ void
AudioNodeStream::AdvanceAndResume(StreamTime aAdvance)
{
mMainThreadCurrentTime += aAdvance;
GraphImpl()->AppendMessage(new AdvanceAndResumeMessage(this, aAdvance));
GraphImpl()->AppendMessage(MakeUnique<AdvanceAndResumeMessage>(this, aAdvance));
}
void
@ -731,7 +731,7 @@ AudioNodeStream::ScheduleCheckForInactive()
return;
}
nsAutoPtr<CheckForInactiveMessage> message(new CheckForInactiveMessage(this));
auto message = MakeUnique<CheckForInactiveMessage>(this);
GraphImpl()->RunMessageAfterProcessing(Move(message));
}

View File

@ -884,7 +884,7 @@ UnsetTrackId(MediaStreamGraphImpl* graph) {
}
RefPtr<PipelineListener> listener_;
};
graph->AppendMessage(new Message(this));
graph->AppendMessage(MakeUnique<Message>(this));
#else
UnsetTrackIdImpl();
#endif
@ -1373,7 +1373,7 @@ static void AddTrackAndListener(MediaStream* source,
// atomically and have start time 0. When not queueing we have to add
// the track on the MediaStreamGraph thread so it can be added with the
// appropriate start time.
source->GraphImpl()->AppendMessage(new Message(source, track_id, track_rate, segment, listener, completed));
source->GraphImpl()->AppendMessage(MakeUnique<Message>(source, track_id, track_rate, segment, listener, completed));
MOZ_MTLOG(ML_INFO, "Dispatched track-add for track id " << track_id <<
" on stream " << source);
return;