diff --git a/content/media/encoder/TrackEncoder.cpp b/content/media/encoder/TrackEncoder.cpp index 4533616f172e..1284b0541dc6 100644 --- a/content/media/encoder/TrackEncoder.cpp +++ b/content/media/encoder/TrackEncoder.cpp @@ -67,16 +67,24 @@ AudioTrackEncoder::NotifyRemoved(MediaStreamGraph* aGraph) { // In case that MediaEncoder does not receive a TRACK_EVENT_ENDED event. LOG("[AudioTrackEncoder]: NotifyRemoved."); + NotifyEndOfStream(); +} +void +AudioTrackEncoder::NotifyEndOfStream() +{ // If source audio chunks are completely silent till the end of encoding, // initialize the encoder with default channel counts and sampling rate, and // append this many null data to the segment of track encoder. - if (!mInitialized && mSilentDuration > 0) { + if (!mCanceled && !mInitialized && mSilentDuration > 0) { Init(DEFAULT_CHANNELS, DEFAULT_SAMPLING_RATE); mRawSegment->AppendNullData(mSilentDuration); mSilentDuration = 0; } - NotifyEndOfStream(); + + ReentrantMonitorAutoEnter mon(mReentrantMonitor); + mEndOfStream = true; + mReentrantMonitor.NotifyAll(); } nsresult diff --git a/content/media/encoder/TrackEncoder.h b/content/media/encoder/TrackEncoder.h index c65898e38d4b..c3cabcd1dc8c 100644 --- a/content/media/encoder/TrackEncoder.h +++ b/content/media/encoder/TrackEncoder.h @@ -130,12 +130,7 @@ protected: * Notifies the audio encoder that we have reached the end of source stream, * and wakes up mReentrantMonitor if encoder is waiting for more track data. */ - void NotifyEndOfStream() - { - ReentrantMonitorAutoEnter mon(mReentrantMonitor); - mEndOfStream = true; - mReentrantMonitor.NotifyAll(); - } + void NotifyEndOfStream(); /** * Interleaves the track data and stores the result into aOutput. Might need