[vlc-commits] auhal: do an early check for the stream format set

David Fuhrmann git at videolan.org
Mon Feb 24 15:28:21 CET 2014


vlc | branch: master | David Fuhrmann <david.fuhrmann at googlemail.com> | Sun Feb 23 23:55:14 2014 +0100| [897c162eb5fa4cc7b1878e280de32a3f2d3649b8] | committer: David Fuhrmann

auhal: do an early check for the stream format set

This prevents waiting for the timeout in some situations, especially
if the format was already set to the new value before.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=897c162eb5fa4cc7b1878e280de32a3f2d3649b8
---

 modules/audio_output/auhal.c |   18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/modules/audio_output/auhal.c b/modules/audio_output/auhal.c
index 3ab1aa0..2c3ceb8 100644
--- a/modules/audio_output/auhal.c
+++ b/modules/audio_output/auhal.c
@@ -1725,9 +1725,7 @@ static int AudioStreamSupportsDigital(audio_output_t *p_aout, AudioStreamID i_st
  */
 static int AudioStreamChangeFormat(audio_output_t *p_aout, AudioStreamID i_stream_id, AudioStreamBasicDescription change_format)
 {
-    OSStatus            err = noErr;
-    UInt32              i_param_size = 0;
-
+    OSStatus err = noErr;
     int retValue = true;
 
     AudioObjectPropertyAddress physicalFormatAddress = { kAudioStreamPropertyPhysicalFormat, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
@@ -1762,14 +1760,10 @@ static int AudioStreamChangeFormat(audio_output_t *p_aout, AudioStreamID i_strea
      * it is also not atomic in its behaviour.
      * Therefore we check 5 times before we really give up.
      * FIXME: failing isn't actually implemented yet. */
+    AudioStreamBasicDescription actual_format;
+    UInt32 i_param_size = sizeof(AudioStreamBasicDescription);
     for (int i = 0; i < 5; i++) {
-        AudioStreamBasicDescription actual_format;
-        mtime_t timeout = mdate() + 500000;
-
-        if (vlc_cond_timedwait(&w.cond, &w.lock, timeout))
-            msg_Dbg(p_aout, "reached timeout");
-
-        i_param_size = sizeof(AudioStreamBasicDescription);
+        /* Callback is not always invoked. So first check if format is already set. */
         err = AudioObjectGetPropertyData(i_stream_id, &physicalFormatAddress, 0, NULL, &i_param_size, &actual_format);
 
         msg_Dbg(p_aout, STREAM_FORMAT_MSG("actual format in use: ", actual_format));
@@ -1779,7 +1773,11 @@ static int AudioStreamChangeFormat(audio_output_t *p_aout, AudioStreamID i_strea
             /* The right format is now active */
             break;
         }
+
         /* We need to check again */
+        mtime_t timeout = mdate() + 500000;
+        if (vlc_cond_timedwait(&w.cond, &w.lock, timeout))
+            msg_Dbg(p_aout, "reached timeout");
     }
 
 out:



More information about the vlc-commits mailing list