Bug 1294634 - Use a switch statement to convert State to string.
MozReview-Commit-ID: 513zK0G0Pvi
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1033,36 +1033,49 @@ void MediaDecoderStateMachine::UpdatePla
bool fragmentEnded = mFragmentEndTime >= 0 && GetMediaTime() >= mFragmentEndTime;
mMetadataManager.DispatchMetadataIfNeeded(TimeUnit::FromMicroseconds(aTime));
if (fragmentEnded) {
StopPlayback();
}
}
-static const char* const gMachineStateStr[] = {
- "DECODING_METADATA",
- "WAIT_FOR_CDM",
- "DORMANT",
- "DECODING",
- "SEEKING",
- "BUFFERING",
- "COMPLETED",
- "SHUTDOWN",
- "ERROR"
-};
+/* static */ const char*
+MediaDecoderStateMachine::ToStateStr(State aState)
+{
+ switch (aState) {
+ case DECODER_STATE_DECODING_METADATA: return "DECODING_METADATA";
+ case DECODER_STATE_WAIT_FOR_CDM: return "WAIT_FOR_CDM";
+ case DECODER_STATE_DORMANT: return "DORMANT";
+ case DECODER_STATE_DECODING: return "DECODING";
+ case DECODER_STATE_SEEKING: return "SEEKING";
+ case DECODER_STATE_BUFFERING: return "BUFFERING";
+ case DECODER_STATE_COMPLETED: return "COMPLETED";
+ case DECODER_STATE_SHUTDOWN: return "SHUTDOWN";
+ case DECODER_STATE_ERROR: return "ERROR";
+ default: MOZ_ASSERT_UNREACHABLE("Invalid state.");
+ }
+ return "UNKNOWN";
+}
+
+const char*
+MediaDecoderStateMachine::ToStateStr()
+{
+ MOZ_ASSERT(OnTaskQueue());
+ return ToStateStr(mState);
+}
void MediaDecoderStateMachine::SetState(State aState)
{
MOZ_ASSERT(OnTaskQueue());
if (mState == aState) {
return;
}
DECODER_LOG("Change machine state from %s to %s",
- gMachineStateStr[mState], gMachineStateStr[aState]);
+ ToStateStr(), ToStateStr(aState));
mState = aState;
mIsShutdown = mState == DECODER_STATE_ERROR || mState == DECODER_STATE_SHUTDOWN;
// Clear state-scoped state.
mSentPlaybackEndedEvent = false;
}
@@ -2771,17 +2784,17 @@ MediaDecoderStateMachine::DumpDebugInfo(
// this function before shutdown begins.
nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction([this] () {
DUMP_LOG(
"GetMediaTime=%lld GetClock=%lld "
"mState=%s mPlayState=%d mDecodingFirstFrame=%d IsPlaying=%d "
"mAudioStatus=%s mVideoStatus=%s mDecodedAudioEndTime=%lld mDecodedVideoEndTime=%lld "
"mIsAudioPrerolling=%d mIsVideoPrerolling=%d",
GetMediaTime(), mMediaSink->IsStarted() ? GetClock() : -1,
- gMachineStateStr[mState], mPlayState.Ref(), mDecodingFirstFrame, IsPlaying(),
+ ToStateStr(), mPlayState.Ref(), mDecodingFirstFrame, IsPlaying(),
AudioRequestStatus(), VideoRequestStatus(), mDecodedAudioEndTime, mDecodedVideoEndTime,
mIsAudioPrerolling, mIsVideoPrerolling);
});
OwnerThread()->DispatchStateChange(r.forget());
}
void MediaDecoderStateMachine::AddOutputStream(ProcessedMediaStream* aStream,
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -248,16 +248,19 @@ public:
// Immutable after construction - may be called on any thread.
bool IsRealTime() const { return mRealTime; }
size_t SizeOfVideoQueue() const;
size_t SizeOfAudioQueue() const;
private:
+ static const char* ToStateStr(State aState);
+ const char* ToStateStr();
+
// Functions used by assertions to ensure we're calling things
// on the appropriate threads.
bool OnTaskQueue() const;
// Initialization that needs to happen on the task queue. This is the first
// task that gets run on the task queue, and is dispatched from the MDSM
// constructor immediately after the task queue is created.
void InitializationTask(MediaDecoder* aDecoder);