@@ -121,14 +121,16 @@ SpeechRecognition::GetParentObject() const
121121void
122122SpeechRecognition::ProcessEvent (SpeechEvent* aEvent)
123123{
124- SR_LOG (" Processing event %d" , aEvent->mType );
124+ SR_LOG (" Processing %s, current state is %s" ,
125+ GetName (aEvent),
126+ GetName (mCurrentState ));
125127
126128 MOZ_ASSERT (!mProcessingEvent , " Event dispatch should be sequential!" );
127129 mProcessingEvent = true ;
128130
129- SR_LOG (" Current state: %d" , mCurrentState );
130131 mCurrentState = TransitionAndGetNextState (aEvent);
131- SR_LOG (" Transitioned to state: %d" , mCurrentState );
132+ SR_LOG (" Transitioned to state: %s" , GetName (mCurrentState ));
133+
132134 mProcessingEvent = false ;
133135}
134136
@@ -151,6 +153,8 @@ SpeechRecognition::TransitionAndGetNextState(SpeechEvent* aEvent)
151153 case EVENT_AUDIO_ERROR :
152154 case EVENT_RECOGNITIONSERVICE_ERROR :
153155 return AbortError (aEvent);
156+ case EVENT_COUNT :
157+ MOZ_NOT_REACHED (" Invalid event EVENT_COUNT" );
154158 }
155159 case STATE_STARTING :
156160 switch (aEvent->mType ) {
@@ -167,8 +171,10 @@ SpeechRecognition::TransitionAndGetNextState(SpeechEvent* aEvent)
167171 case EVENT_RECOGNITIONSERVICE_FINAL_RESULT :
168172 return DoNothing (aEvent);
169173 case EVENT_START :
170- SR_LOG (" STATE_STARTING: Unhandled event %d " , aEvent-> mType );
174+ SR_LOG (" STATE_STARTING: Unhandled event %s " , GetName ( aEvent) );
171175 MOZ_NOT_REACHED (" " );
176+ case EVENT_COUNT :
177+ MOZ_NOT_REACHED (" Invalid event EVENT_COUNT" );
172178 }
173179 case STATE_ESTIMATING :
174180 switch (aEvent->mType ) {
@@ -187,6 +193,8 @@ SpeechRecognition::TransitionAndGetNextState(SpeechEvent* aEvent)
187193 case EVENT_START :
188194 SR_LOG (" STATE_ESTIMATING: Unhandled event %d" , aEvent->mType );
189195 MOZ_NOT_REACHED (" " );
196+ case EVENT_COUNT :
197+ MOZ_NOT_REACHED (" Invalid event EVENT_COUNT" );
190198 }
191199 case STATE_WAITING_FOR_SPEECH :
192200 switch (aEvent->mType ) {
@@ -203,8 +211,10 @@ SpeechRecognition::TransitionAndGetNextState(SpeechEvent* aEvent)
203211 case EVENT_RECOGNITIONSERVICE_ERROR :
204212 return DoNothing (aEvent);
205213 case EVENT_START :
206- SR_LOG (" STATE_STARTING: Unhandled event %d " , aEvent-> mType );
214+ SR_LOG (" STATE_STARTING: Unhandled event %s " , GetName ( aEvent) );
207215 MOZ_NOT_REACHED (" " );
216+ case EVENT_COUNT :
217+ MOZ_NOT_REACHED (" Invalid event EVENT_COUNT" );
208218 }
209219 case STATE_RECOGNIZING :
210220 switch (aEvent->mType ) {
@@ -221,8 +231,10 @@ SpeechRecognition::TransitionAndGetNextState(SpeechEvent* aEvent)
221231 case EVENT_RECOGNITIONSERVICE_INTERMEDIATE_RESULT :
222232 return DoNothing (aEvent);
223233 case EVENT_START :
224- SR_LOG (" STATE_RECOGNIZING: Unhandled aEvent %d " , aEvent-> mType );
234+ SR_LOG (" STATE_RECOGNIZING: Unhandled aEvent %s " , GetName ( aEvent) );
225235 MOZ_NOT_REACHED (" " );
236+ case EVENT_COUNT :
237+ MOZ_NOT_REACHED (" Invalid event EVENT_COUNT" );
226238 }
227239 case STATE_WAITING_FOR_RESULT :
228240 switch (aEvent->mType ) {
@@ -239,11 +251,15 @@ SpeechRecognition::TransitionAndGetNextState(SpeechEvent* aEvent)
239251 return AbortSilently (aEvent);
240252 case EVENT_START :
241253 case EVENT_RECOGNITIONSERVICE_INTERMEDIATE_RESULT :
242- SR_LOG (" STATE_WAITING_FOR_RESULT: Unhandled aEvent %d " , aEvent-> mType );
254+ SR_LOG (" STATE_WAITING_FOR_RESULT: Unhandled aEvent %s " , GetName ( aEvent) );
243255 MOZ_NOT_REACHED (" " );
256+ case EVENT_COUNT :
257+ MOZ_NOT_REACHED (" Invalid event EVENT_COUNT" );
244258 }
259+ case STATE_COUNT :
260+ MOZ_NOT_REACHED (" Invalid state STATE_COUNT" );
245261 }
246- SR_LOG (" Unhandled state %d " , mCurrentState );
262+ SR_LOG (" Unhandled state %s " , GetName ( mCurrentState ) );
247263 MOZ_NOT_REACHED (" " );
248264 return mCurrentState ;
249265}
@@ -805,6 +821,42 @@ SpeechRecognition::FeedAudioData(already_AddRefed<SharedBuffer> aSamples,
805821 return ;
806822}
807823
824+ const char *
825+ SpeechRecognition::GetName (FSMState aId)
826+ {
827+ static const char * names[] = {
828+ " STATE_IDLE" ,
829+ " STATE_STARTING" ,
830+ " STATE_ESTIMATING" ,
831+ " STATE_WAITING_FOR_SPEECH" ,
832+ " STATE_RECOGNIZING" ,
833+ " STATE_WAITING_FOR_RESULT"
834+ };
835+
836+ MOZ_ASSERT (aId < STATE_COUNT );
837+ MOZ_ASSERT (ArrayLength (names) == STATE_COUNT );
838+ return names[aId];
839+ }
840+
841+ const char *
842+ SpeechRecognition::GetName (SpeechEvent* aEvent)
843+ {
844+ static const char * names[] = {
845+ " EVENT_START" ,
846+ " EVENT_STOP" ,
847+ " EVENT_ABORT" ,
848+ " EVENT_AUDIO_DATA" ,
849+ " EVENT_AUDIO_ERROR" ,
850+ " EVENT_RECOGNITIONSERVICE_INTERMEDIATE_RESULT" ,
851+ " EVENT_RECOGNITIONSERVICE_FINAL_RESULT" ,
852+ " EVENT_RECOGNITIONSERVICE_ERROR"
853+ };
854+
855+ MOZ_ASSERT (aEvent->mType < EVENT_COUNT );
856+ MOZ_ASSERT (ArrayLength (names) == EVENT_COUNT );
857+ return names[aEvent->mType ];
858+ }
859+
808860NS_IMPL_ISUPPORTS1 (SpeechRecognition::GetUserMediaStreamOptions, nsIMediaStreamOptions)
809861
810862NS_IMETHODIMP
0 commit comments