Bug 899935 - Produce zero-length output if calling Stop right after a Start call of MediaRecorder. r=roc

This commit is contained in:
Shelly Lin 2013-08-29 19:59:08 +08:00
parent 6f3bfc2065
commit fcd6eb5264
2 changed files with 14 additions and 5 deletions

View File

@ -89,10 +89,14 @@ public:
NS_IMETHODIMP Run()
{
MOZ_ASSERT(NS_IsMainThread());
mRecorder->mState = RecordingState::Inactive;
mRecorder->DispatchSimpleEvent(NS_LITERAL_STRING("stop"));
mRecorder->mReadThread->Shutdown();
mRecorder->mReadThread = nullptr;
// Setting mState to Inactive here is for the case where SourceStream
// ends itself, thus the recorder should stop itself too.
mRecorder->mState = RecordingState::Inactive;
mRecorder->DispatchSimpleEvent(NS_LITERAL_STRING("stop"));
return NS_OK;
}
@ -154,7 +158,7 @@ MediaRecorder::ExtractEncodedData()
NS_DispatchToMainThread(new PushBlobTask(this));
lastBlobTimeStamp = TimeStamp::Now();
}
} while (mState == RecordingState::Recording && !mEncoder->IsShutdown());
} while (!mEncoder->IsShutdown());
NS_DispatchToMainThread(new PushBlobTask(this));
}
@ -229,7 +233,12 @@ MediaRecorder::Stop(ErrorResult& aResult)
return;
}
mState = RecordingState::Inactive;
mTrackUnionStream->RemoveListener(mEncoder);
mStreamPort->Destroy();
mStreamPort = nullptr;
mTrackUnionStream->Destroy();
mTrackUnionStream = nullptr;
}
void

View File

@ -82,7 +82,7 @@ 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 (!mCanceled && !mInitialized && mSilentDuration > 0) {
if (!mCanceled && !mInitialized) {
Init(DEFAULT_CHANNELS, DEFAULT_SAMPLING_RATE);
mRawSegment->AppendNullData(mSilentDuration);
mSilentDuration = 0;