Bug 1458020 - 5. Return default sample rate / frames per buffer; r?esawin draft
authorJim Chen <nchen@mozilla.com>
Thu, 17 May 2018 19:41:14 -0400
changeset 796620 e7095dd931b6d9559c3230d44536b029e75b7520
parent 796619 b1e93eb179a9bcf156021be26241c7afc3138c18
child 796621 5c49abab40f80e7c323cfda06f817d604165abde
push id110315
push userbmo:nchen@mozilla.com
push dateThu, 17 May 2018 23:41:44 +0000
reviewersesawin
bugs1458020
milestone62.0a1
Bug 1458020 - 5. Return default sample rate / frames per buffer; r?esawin We apparently fail to get these properties when running in an emulator, so we should just return default values. MozReview-Commit-ID: IZVYIG9INaq
dom/media/CubebUtils.cpp
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
--- a/dom/media/CubebUtils.cpp
+++ b/dom/media/CubebUtils.cpp
@@ -299,23 +299,23 @@ cubeb* GetCubebContext()
 }
 
 bool InitPreferredSampleRate()
 {
   StaticMutexAutoLock lock(sMutex);
   if (sPreferredSampleRate != 0) {
     return true;
   }
+#ifdef MOZ_WIDGET_ANDROID
+  sPreferredSampleRate = AndroidGetAudioOutputSampleRate();
+#else
   cubeb* context = GetCubebContextUnlocked();
   if (!context) {
     return false;
   }
-#ifdef MOZ_WIDGET_ANDROID
-  sPreferredSampleRate = AndroidGetAudioOutputSampleRate();
-#else
   if (cubeb_get_preferred_sample_rate(context,
                                       &sPreferredSampleRate) != CUBEB_OK) {
 
     return false;
   }
 #endif
   MOZ_ASSERT(sPreferredSampleRate);
   return true;
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
@@ -1846,44 +1846,48 @@ public class GeckoAppShell
             final Display disp = wm.getDefaultDisplay();
             sScreenSize = new Rect(0, 0, disp.getWidth(), disp.getHeight());
         }
         return sScreenSize;
     }
 
     @WrapForJNI(calledFrom = "any")
     public static int getAudioOutputFramesPerBuffer() {
+        final int DEFAULT = 512;
+
         if (SysInfo.getVersion() < 17) {
-            return 0;
+            return DEFAULT;
         }
         final AudioManager am = (AudioManager)getApplicationContext()
                                 .getSystemService(Context.AUDIO_SERVICE);
         if (am == null) {
-            return 0;
+            return DEFAULT;
         }
         final String prop = am.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER);
         if (prop == null) {
-            return 0;
+            return DEFAULT;
         }
         return Integer.parseInt(prop);
     }
 
     @WrapForJNI(calledFrom = "any")
     public static int getAudioOutputSampleRate() {
+        final int DEFAULT = 44100;
+
         if (SysInfo.getVersion() < 17) {
-            return 0;
+            return DEFAULT;
         }
         final AudioManager am = (AudioManager)getApplicationContext()
                                 .getSystemService(Context.AUDIO_SERVICE);
         if (am == null) {
-            return 0;
+            return DEFAULT;
         }
         final String prop = am.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
         if (prop == null) {
-            return 0;
+            return DEFAULT;
         }
         return Integer.parseInt(prop);
     }
 
     @WrapForJNI
     public static String getDefaultLocale() {
         final Locale locale = Locale.getDefault();
         if (Build.VERSION.SDK_INT >= 21) {