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 */
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;
}
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);
}
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);
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
*/
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);