[pulseaudio-commits] src/modules

Tanu Kaskinen tanuk at kemper.freedesktop.org
Wed May 29 04:09:20 PDT 2013


 src/modules/macosx/module-coreaudio-device.c |   33 ++++++++++++++++++---------
 1 file changed, 23 insertions(+), 10 deletions(-)

New commits:
commit a0032eb7f9c8ef15b0f6cd97e5572d10fec86de7
Author: Vadim Troshchinskiy <vtroshchinskiy at qindel.es>
Date:   Wed May 29 13:58:36 2013 +0300

    osx: Fix latency querying
    
    get_latency_us() used an uninitialized variable, and an incorrect
    scope for some of the AudioObjectGetPropertyData() calls. As a result,
    audio would randomly not work at all.
    
    BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=65122

diff --git a/src/modules/macosx/module-coreaudio-device.c b/src/modules/macosx/module-coreaudio-device.c
index ea88ebd..b1a5176 100644
--- a/src/modules/macosx/module-coreaudio-device.c
+++ b/src/modules/macosx/module-coreaudio-device.c
@@ -183,7 +183,7 @@ static pa_usec_t get_latency_us(pa_object *o) {
     struct userdata *u;
     pa_sample_spec *ss;
     bool is_source;
-    UInt32 v, total = 0;
+    UInt32 v = 0, total = 0;
     UInt32 err, size = sizeof(v);
     AudioObjectPropertyAddress property_address;
     AudioObjectID stream_id;
@@ -205,26 +205,35 @@ static pa_usec_t get_latency_us(pa_object *o) {
 
     pa_assert(u);
 
-    property_address.mScope = kAudioObjectPropertyScopeGlobal;
+    property_address.mScope = is_source ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
     property_address.mElement = kAudioObjectPropertyElementMaster;
 
     /* get the device latency */
     property_address.mSelector = kAudioDevicePropertyLatency;
-    size = sizeof(total);
-    AudioObjectGetPropertyData(u->object_id, &property_address, 0, NULL, &size, &total);
-    total += v;
+    size = sizeof(v);
+    err = AudioObjectGetPropertyData(u->object_id, &property_address, 0, NULL, &size, &v);
+    if (!err)
+        total += v;
+    else
+        pa_log_warn("Failed to get device latency: %i", err);
 
     /* the IOProc buffer size */
     property_address.mSelector = kAudioDevicePropertyBufferFrameSize;
     size = sizeof(v);
-    AudioObjectGetPropertyData(u->object_id, &property_address, 0, NULL, &size, &v);
-    total += v;
+    err = AudioObjectGetPropertyData(u->object_id, &property_address, 0, NULL, &size, &v);
+    if (!err)
+        total += v;
+    else
+        pa_log_warn("Failed to get buffer frame size: %i", err);
 
     /* IOProc safety offset - this value is the same for both directions, hence we divide it by 2 */
     property_address.mSelector = kAudioDevicePropertySafetyOffset;
     size = sizeof(v);
-    AudioObjectGetPropertyData(u->object_id, &property_address, 0, NULL, &size, &v);
-    total += v / 2;
+    err = AudioObjectGetPropertyData(u->object_id, &property_address, 0, NULL, &size, &v);
+    if (!err)
+        total += v / 2;
+    else
+        pa_log_warn("Failed to get safety offset: %i", err);
 
     /* get the stream latency.
      * FIXME: this assumes the stream latency is the same for all streams */
@@ -233,11 +242,15 @@ static pa_usec_t get_latency_us(pa_object *o) {
     err = AudioObjectGetPropertyData(u->object_id, &property_address, 0, NULL, &size, &stream_id);
     if (!err) {
         property_address.mSelector = kAudioStreamPropertyLatency;
+        property_address.mScope = kAudioObjectPropertyScopeGlobal;
         size = sizeof(v);
         err = AudioObjectGetPropertyData(stream_id, &property_address, 0, NULL, &size, &v);
         if (!err)
             total += v;
-    }
+        else
+            pa_log_warn("Failed to get stream latency: %i", err);
+    } else
+        pa_log_warn("Failed to get streams: %i", err);
 
     return pa_bytes_to_usec(total * pa_frame_size(ss), ss);
 }



More information about the pulseaudio-commits mailing list