Bug 1225928 - Fix hang on linux when sending an empty string to speech synth. r=smaug
authorEitan Isaacson <eitan@monotonous.org>
Mon, 30 Nov 2015 18:59:01 -0800
changeset 308958 03c6bd7c9aecc4d1c697a1b731bd32580d1fb057
parent 308957 a9f0334501a97f1026aaa651ecbe760762abcef5
child 308959 86e73c5414d638ce77d4960a260cbeebff659568
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1225928
milestone45.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1225928 - Fix hang on linux when sending an empty string to speech synth. r=smaug
dom/media/webspeech/synth/speechd/SpeechDispatcherService.cpp
--- a/dom/media/webspeech/synth/speechd/SpeechDispatcherService.cpp
+++ b/dom/media/webspeech/synth/speechd/SpeechDispatcherService.cpp
@@ -488,24 +488,36 @@ SpeechDispatcherService::Speak(const nsA
 
   // The last three parameters don't matter for an indirect service
   nsresult rv = aTask->Setup(callback, 0, 0, 0);
 
   if (NS_FAILED(rv)) {
     return rv;
   }
 
-  int msg_id = spd_say(mSpeechdClient, SPD_MESSAGE, NS_ConvertUTF16toUTF8(aText).get());
+  if (aText.Length()) {
+    int msg_id = spd_say(
+      mSpeechdClient, SPD_MESSAGE, NS_ConvertUTF16toUTF8(aText).get());
+
+    if (msg_id < 0) {
+      return NS_ERROR_FAILURE;
+    }
 
-  if (msg_id < 0) {
-    return NS_ERROR_FAILURE;
+    mCallbacks.Put(msg_id, callback);
+  } else {
+    // Speech dispatcher does not work well with empty strings.
+    // In that case, don't send empty string to speechd,
+    // and just emulate a speechd start and end event.
+    NS_DispatchToMainThread(NS_NewRunnableMethodWithArgs<SPDNotificationType>(
+        callback, &SpeechDispatcherCallback::OnSpeechEvent, SPD_EVENT_BEGIN));
+
+    NS_DispatchToMainThread(NS_NewRunnableMethodWithArgs<SPDNotificationType>(
+        callback, &SpeechDispatcherCallback::OnSpeechEvent, SPD_EVENT_END));
   }
 
-  mCallbacks.Put(msg_id, callback);
-
   return NS_OK;
 }
 
 NS_IMETHODIMP
 SpeechDispatcherService::GetServiceType(SpeechServiceType* aServiceType)
 {
   *aServiceType = nsISpeechService::SERVICETYPE_INDIRECT_AUDIO;
   return NS_OK;