Bug 1163497. Part 2 - Remove MediaDecoder::DestroyDecodedStream(). r=roc.

This commit is contained in:
JW Wang 2015-05-10 12:26:03 +08:00
parent 81a8e06a08
commit c079ecbf7c
3 changed files with 31 additions and 41 deletions

View File

@ -195,6 +195,33 @@ DecodedStream::DestroyData()
{
MOZ_ASSERT(NS_IsMainThread());
GetReentrantMonitor().AssertCurrentThreadIn();
// Avoid the redundant blocking to output stream.
if (!mData) {
return;
}
// All streams are having their SourceMediaStream disconnected, so they
// need to be explicitly blocked again.
auto& outputStreams = OutputStreams();
for (int32_t i = outputStreams.Length() - 1; i >= 0; --i) {
OutputStreamData& os = outputStreams[i];
// Explicitly remove all existing ports.
// This is not strictly necessary but it's good form.
MOZ_ASSERT(os.mPort, "Double-delete of the ports!");
os.mPort->Destroy();
os.mPort = nullptr;
// During cycle collection, nsDOMMediaStream can be destroyed and send
// its Destroy message before this decoder is destroyed. So we have to
// be careful not to send any messages after the Destroy().
if (os.mStream->IsDestroyed()) {
// Probably the DOM MediaStream was GCed. Clean up.
outputStreams.RemoveElementAt(i);
} else {
os.mStream->ChangeExplicitBlockerCount(1);
}
}
mData = nullptr;
}
@ -223,6 +250,8 @@ DecodedStream::GetReentrantMonitor()
void
DecodedStream::Connect(OutputStreamData* aStream)
{
MOZ_ASSERT(NS_IsMainThread());
GetReentrantMonitor().AssertCurrentThreadIn();
NS_ASSERTION(!aStream->mPort, "Already connected?");
// The output stream must stay in sync with the decoded stream, so if

View File

@ -303,40 +303,6 @@ void MediaDecoder::UpdateDecodedStream()
}
}
void MediaDecoder::DestroyDecodedStream()
{
MOZ_ASSERT(NS_IsMainThread());
GetReentrantMonitor().AssertCurrentThreadIn();
// Avoid the redundant blocking to output stream.
if (!GetDecodedStream()) {
return;
}
// All streams are having their SourceMediaStream disconnected, so they
// need to be explicitly blocked again.
auto& outputStreams = OutputStreams();
for (int32_t i = outputStreams.Length() - 1; i >= 0; --i) {
OutputStreamData& os = outputStreams[i];
// Explicitly remove all existing ports.
// This is not strictly necessary but it's good form.
MOZ_ASSERT(os.mPort, "Double-delete of the ports!");
os.mPort->Destroy();
os.mPort = nullptr;
// During cycle collection, nsDOMMediaStream can be destroyed and send
// its Destroy message before this decoder is destroyed. So we have to
// be careful not to send any messages after the Destroy().
if (os.mStream->IsDestroyed()) {
// Probably the DOM MediaStream was GCed. Clean up.
outputStreams.RemoveElementAt(i);
} else {
os.mStream->ChangeExplicitBlockerCount(1);
}
}
mDecodedStream.DestroyData();
}
void MediaDecoder::UpdateStreamBlockingForStateMachinePlaying()
{
GetReentrantMonitor().AssertCurrentThreadIn();
@ -369,8 +335,8 @@ void MediaDecoder::RecreateDecodedStream(int64_t aStartTimeUSecs,
if (!aGraph) {
aGraph = GetDecodedStream()->mStream->Graph();
}
DestroyDecodedStream();
mDecodedStream.DestroyData();
mDecodedStream.RecreateData(aStartTimeUSecs, aGraph->CreateSourceStream(nullptr));
// Note that the delay between removing ports in DestroyDecodedStream
@ -562,7 +528,7 @@ MediaDecoder::~MediaDecoder()
// Don't destroy the decoded stream until destructor in order to keep the
// invariant that the decoded stream is always available in capture mode.
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
DestroyDecodedStream();
mDecodedStream.DestroyData();
}
MediaMemoryTracker::RemoveMediaDecoder(this);
UnpinForSeek();

View File

@ -397,11 +397,6 @@ public:
void UpdateDecodedStream();
/**
* Disconnects mDecodedStream->mStream from all outputs and clears
* mDecodedStream.
*/
void DestroyDecodedStream();
/**
* Recreates mDecodedStream. Call this to create mDecodedStream at first,
* and when seeking, to ensure a new stream is set up with fresh buffers.