]> git.sesse.net Git - vlc/blobdiff - modules/audio_output/auhal.c
auhal: remove unneeded global variable
[vlc] / modules / audio_output / auhal.c
index cb5c07b15ccb8498953f9cd5d32c278147e2d198..182d9f7f74f8ca065f6bd5b759ade8b5df92090c 100644 (file)
@@ -98,7 +98,6 @@ struct aout_sys_t
     pid_t                       i_hog_pid;          /* The keep the pid of our hog status */
     AudioStreamID               i_stream_id;        /* The StreamID that has a cac3 streamformat */
     int                         i_stream_index;     /* The index of i_stream_id in an AudioBufferList */
-    AudioStreamBasicDescription stream_format;      /* The format we changed the stream to */
     AudioStreamBasicDescription sfmt_revert;        /* The original format of the stream */
     bool                        b_revert;           /* Whether we need to revert the stream format */
     bool                        b_changed_mixing;   /* Whether we need to set the mixing mode back */
@@ -716,6 +715,7 @@ static int StartSPDIF(audio_output_t * p_aout, audio_sample_format_t *fmt)
     Boolean                 b_writeable = false;
     AudioStreamID           *p_streams = NULL;
     unsigned                i_streams = 0;
+    AudioStreamBasicDescription desired_stream_format;
 
     /* Start doing the SPDIF setup proces */
     p_sys->b_digital = true;
@@ -856,11 +856,11 @@ static int StartSPDIF(audio_output_t * p_aout, audio_sample_format_t *fmt)
             }
 
             if (i_requested_rate_format >= 0) /* We prefer to output at the samplerate of the original audio */
-                p_sys->stream_format = p_format_list[i_requested_rate_format].mFormat;
+                desired_stream_format = p_format_list[i_requested_rate_format].mFormat;
             else if (i_current_rate_format >= 0) /* If not possible, we will try to use the current samplerate of the device */
-                p_sys->stream_format = p_format_list[i_current_rate_format].mFormat;
+                desired_stream_format = p_format_list[i_current_rate_format].mFormat;
             else
-                p_sys->stream_format = p_format_list[i_backup_rate_format].mFormat; /* And if we have to, any digital format will be just fine (highest rate possible) */
+                desired_stream_format = p_format_list[i_backup_rate_format].mFormat; /* And if we have to, any digital format will be just fine (highest rate possible) */
         }
         free(p_format_list);
     }
@@ -868,19 +868,19 @@ static int StartSPDIF(audio_output_t * p_aout, audio_sample_format_t *fmt)
 
     msg_Dbg(p_aout, STREAM_FORMAT_MSG("original stream format: ", p_sys->sfmt_revert));
 
-    if (!AudioStreamChangeFormat(p_aout, p_sys->i_stream_id, p_sys->stream_format)) {
+    if (!AudioStreamChangeFormat(p_aout, p_sys->i_stream_id, desired_stream_format)) {
         msg_Err(p_aout, "failed to change stream format for SPDIF output");
         return false;
     }
 
     /* Set the format flags */
-    if (p_sys->stream_format.mFormatFlags & kAudioFormatFlagIsBigEndian)
+    if (desired_stream_format.mFormatFlags & kAudioFormatFlagIsBigEndian)
         fmt->i_format = VLC_CODEC_SPDIFB;
     else
         fmt->i_format = VLC_CODEC_SPDIFL;
     fmt->i_bytes_per_frame = AOUT_SPDIF_SIZE;
     fmt->i_frame_length = A52_FRAME_NB;
-    fmt->i_rate = (unsigned int)p_sys->stream_format.mSampleRate;
+    fmt->i_rate = (unsigned int)desired_stream_format.mSampleRate;
     p_sys->i_rate = fmt->i_rate;
     aout_FormatPrepare(fmt);
 
@@ -1490,6 +1490,10 @@ static OSStatus StreamsChangedListener(AudioObjectID inObjectID,  UInt32 inNumbe
     msg_Dbg(p_aout, "available physical formats for audio device changed");
     RebuildDeviceList(p_aout);
 
+    /* In this case audio has not yet started. Below code will not work and is not needed here. */
+    if (p_sys->i_selected_dev == 0)
+        return 0;
+
     /*
      * check if changed stream id belongs to current device
      */
@@ -1497,18 +1501,22 @@ static OSStatus StreamsChangedListener(AudioObjectID inObjectID,  UInt32 inNumbe
     AudioObjectPropertyAddress streamsAddress = { kAudioDevicePropertyStreams, kAudioDevicePropertyScopeOutput, kAudioObjectPropertyElementMaster };
     err = AudioObjectGetPropertyDataSize(p_sys->i_selected_dev, &streamsAddress, 0, NULL, &i_param_size);
     if (err != noErr) {
-        msg_Err(p_aout, "could not get number of streams [%4.4s]", (char *)&err);
+        msg_Err(p_aout, "could not get number of streams for device %i [%4.4s]", p_sys->i_selected_dev, (char *)&err);
+        vlc_mutex_unlock(&p_sys->var_lock);
         return VLC_EGENERIC;
     }
 
     i_streams = i_param_size / sizeof(AudioStreamID);
     p_streams = (AudioStreamID *)malloc(i_param_size);
-    if (p_streams == NULL)
+    if (p_streams == NULL) {
+        vlc_mutex_unlock(&p_sys->var_lock);
         return VLC_ENOMEM;
+    }
 
     err = AudioObjectGetPropertyData(p_sys->i_selected_dev, &streamsAddress, 0, NULL, &i_param_size, p_streams);
     if (err != noErr) {
         msg_Err(p_aout, "could not get list of streams [%4.4s]", (char *)&err);
+        vlc_mutex_unlock(&p_sys->var_lock);
         return VLC_EGENERIC;
     }
     vlc_mutex_unlock(&p_sys->var_lock);