Bug 1300446 - Check return value from GetCubebContext - r=kinetik
authorGerald Squelart <gsquelart@mozilla.com>
Tue, 30 Aug 2016 17:20:10 -0700
changeset 312662 03056868056e209bb08eece43061972c66ef4742
parent 312661 f0a2a1052c7fcfef5bdbb192c84f081e90814694
child 312663 6681da2c76630a86094847d7fcbe702dec99ebf0
push id30652
push userphilringnalda@gmail.com
push dateMon, 05 Sep 2016 20:05:11 +0000
treeherdermozilla-central@91a0bc34de8a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs1300446
milestone51.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 1300446 - Check return value from GetCubebContext - r=kinetik MozReview-Commit-ID: Y9b5Aq2RZE
dom/media/CubebUtils.cpp
dom/media/GraphDriver.cpp
dom/media/webrtc/MediaEngineWebRTC.cpp
--- a/dom/media/CubebUtils.cpp
+++ b/dom/media/CubebUtils.cpp
@@ -308,18 +308,21 @@ cubeb_stream_type ConvertChannelToCubebT
       NS_ERROR("The value of AudioChannel is invalid");
       return CUBEB_STREAM_TYPE_MAX;
   }
 }
 #endif
 
 void GetCurrentBackend(nsAString& aBackend)
 {
-  const char* backend = cubeb_get_backend_id(GetCubebContext());
-  if (!backend) {
-    aBackend.AssignLiteral("unknown");
-    return;
+  cubeb* cubebContext = GetCubebContext();
+  if (cubebContext) {
+    const char* backend = cubeb_get_backend_id(cubebContext);
+    if (backend) {
+      aBackend.AssignASCII(backend);
+      return;
+    }
   }
-  aBackend.AssignASCII(backend);
+  aBackend.AssignLiteral("unknown");
 }
 
 } // namespace CubebUtils
 } // namespace mozilla
--- a/dom/media/GraphDriver.cpp
+++ b/dom/media/GraphDriver.cpp
@@ -583,16 +583,22 @@ AudioCallbackDriver::AudioCallbackDriver
 AudioCallbackDriver::~AudioCallbackDriver()
 {
   MOZ_ASSERT(mPromisesForOperation.IsEmpty());
 }
 
 void
 AudioCallbackDriver::Init()
 {
+  cubeb* cubebContext = CubebUtils::GetCubebContext();
+  if (!cubebContext) {
+    NS_WARNING("Could not get cubeb context.");
+    return;
+  }
+
   cubeb_stream_params output;
   cubeb_stream_params input;
   uint32_t latency_frames;
   bool firstStream = CubebUtils::GetFirstStream();
 
   MOZ_ASSERT(!NS_IsMainThread(),
       "This is blocking and should never run on the main thread.");
 
@@ -614,17 +620,17 @@ AudioCallbackDriver::Init()
 
   output.channels = mGraphImpl->AudioChannelCount();
   if (AUDIO_OUTPUT_FORMAT == AUDIO_FORMAT_S16) {
     output.format = CUBEB_SAMPLE_S16NE;
   } else {
     output.format = CUBEB_SAMPLE_FLOAT32NE;
   }
 
-  if (cubeb_get_min_latency(CubebUtils::GetCubebContext(), output, &latency_frames) != CUBEB_OK) {
+  if (cubeb_get_min_latency(cubebContext, output, &latency_frames) != CUBEB_OK) {
     NS_WARNING("Could not get minimal latency from cubeb.");
     return;
   }
 
   input = output;
   input.channels = mInputChannels; // change to support optional stereo capture
 
   cubeb_stream* stream = nullptr;
@@ -645,17 +651,17 @@ AudioCallbackDriver::Init()
          // XXX we should figure out how we would use a deviceID for output without webrtc.
          // Currently we don't set this though, so it's ok
          || AudioInputCubeb::GetDeviceID(mGraphImpl->mOutputDeviceID, output_id)
 #endif
          ) &&
         // XXX Only pass input input if we have an input listener.  Always
         // set up output because it's easier, and it will just get silence.
         // XXX Add support for adding/removing an input listener later.
-        cubeb_stream_init(CubebUtils::GetCubebContext(), &stream,
+        cubeb_stream_init(cubebContext, &stream,
                           "AudioCallbackDriver",
                           input_id,
                           mGraphImpl->mInputWanted ? &input : nullptr,
                           output_id,
                           mGraphImpl->mOutputWanted ? &output : nullptr, latency_frames,
                           DataCallback_s, StateCallback_s, this) == CUBEB_OK) {
       mAudioStream.own(stream);
       DebugOnly<int> rv = cubeb_stream_set_volume(mAudioStream, CubebUtils::GetVolumeScale());
--- a/dom/media/webrtc/MediaEngineWebRTC.cpp
+++ b/dom/media/webrtc/MediaEngineWebRTC.cpp
@@ -49,19 +49,24 @@ cubeb_device_collection* AudioInputCubeb
 bool AudioInputCubeb::mAnyInUse = false;
 StaticMutex AudioInputCubeb::sMutex;
 
 // AudioDeviceID is an annoying opaque value that's really a string
 // pointer, and is freed when the cubeb_device_collection is destroyed
 
 void AudioInputCubeb::UpdateDeviceList()
 {
+  cubeb* cubebContext = CubebUtils::GetCubebContext();
+  if (!cubebContext) {
+    return;
+  }
+
   cubeb_device_collection *devices = nullptr;
 
-  if (CUBEB_OK != cubeb_enumerate_devices(CubebUtils::GetCubebContext(),
+  if (CUBEB_OK != cubeb_enumerate_devices(cubebContext,
                                           CUBEB_DEVICE_TYPE_INPUT,
                                           &devices)) {
     return;
   }
 
   for (auto& device_index : (*mDeviceIndexes)) {
     device_index = -1; // unmapped
   }