Commit 1e6a2a48 authored by Thomas Guillem's avatar Thomas Guillem

auhal: report the default device if the saved device is gone

(cherry picked from commit 15918ae5)
Signed-off-by: Thomas Guillem's avatarThomas Guillem <thomas@gllm.fr>
parent 22744394
...@@ -453,7 +453,7 @@ AudioDeviceHasOutput(audio_output_t *p_aout, AudioDeviceID i_dev_id) ...@@ -453,7 +453,7 @@ AudioDeviceHasOutput(audio_output_t *p_aout, AudioDeviceID i_dev_id)
} }
static void static void
RebuildDeviceList(audio_output_t * p_aout) RebuildDeviceList(audio_output_t * p_aout, UInt32 *p_id_exists)
{ {
struct aout_sys_t *p_sys = p_aout->sys; struct aout_sys_t *p_sys = p_aout->sys;
...@@ -479,6 +479,15 @@ RebuildDeviceList(audio_output_t * p_aout) ...@@ -479,6 +479,15 @@ RebuildDeviceList(audio_output_t * p_aout)
CFMutableArrayRef currentListOfDevices = CFMutableArrayRef currentListOfDevices =
CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks); CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
UInt32 i_id_exists;
if (p_id_exists)
{
i_id_exists = *p_id_exists;
*p_id_exists = 0;
}
else
i_id_exists = 0;
for (size_t i = 0; i < i_devices; i++) for (size_t i = 0; i < i_devices; i++)
{ {
CFStringRef device_name_ref; CFStringRef device_name_ref;
...@@ -516,6 +525,9 @@ RebuildDeviceList(audio_output_t * p_aout) ...@@ -516,6 +525,9 @@ RebuildDeviceList(audio_output_t * p_aout)
continue; continue;
} }
if (p_id_exists && i_id == i_id_exists)
*p_id_exists = i_id;
ReportDevice(p_aout, i_id, psz_name); ReportDevice(p_aout, i_id, psz_name);
CFNumberRef deviceNumber = CFNumberCreate(kCFAllocatorDefault, CFNumberRef deviceNumber = CFNumberCreate(kCFAllocatorDefault,
kCFNumberSInt32Type, &i_id); kCFNumberSInt32Type, &i_id);
...@@ -676,7 +688,7 @@ StreamsChangedListener(AudioObjectID inObjectID, UInt32 inNumberAddresses, ...@@ -676,7 +688,7 @@ StreamsChangedListener(AudioObjectID inObjectID, UInt32 inNumberAddresses,
return 0; return 0;
msg_Dbg(p_aout, "available physical formats for audio device changed"); msg_Dbg(p_aout, "available physical formats for audio device changed");
RebuildDeviceList(p_aout); RebuildDeviceList(p_aout, NULL);
vlc_mutex_lock(&p_sys->selected_device_lock); vlc_mutex_lock(&p_sys->selected_device_lock);
/* In this case audio has not yet started. Below code will not work and is /* In this case audio has not yet started. Below code will not work and is
...@@ -734,7 +746,7 @@ DevicesListener(AudioObjectID inObjectID, UInt32 inNumberAddresses, ...@@ -734,7 +746,7 @@ DevicesListener(AudioObjectID inObjectID, UInt32 inNumberAddresses,
aout_sys_t *p_sys = p_aout->sys; aout_sys_t *p_sys = p_aout->sys;
msg_Dbg(p_aout, "audio device configuration changed, resetting cache"); msg_Dbg(p_aout, "audio device configuration changed, resetting cache");
RebuildDeviceList(p_aout); RebuildDeviceList(p_aout, NULL);
vlc_mutex_lock(&p_sys->selected_device_lock); vlc_mutex_lock(&p_sys->selected_device_lock);
vlc_mutex_lock(&p_sys->device_list_lock); vlc_mutex_lock(&p_sys->device_list_lock);
...@@ -1671,7 +1683,24 @@ static int Open(vlc_object_t *obj) ...@@ -1671,7 +1683,24 @@ static int Open(vlc_object_t *obj)
kAudioHardwarePropertyDefaultOutputDevice, kAudioHardwarePropertyDefaultOutputDevice,
kAudioObjectPropertyScopeGlobal); kAudioObjectPropertyScopeGlobal);
RebuildDeviceList(p_aout); char *psz_audio_device = var_InheritString(p_aout, "auhal-audio-device");
if (psz_audio_device != NULL)
{
int dev_id_int = atoi(psz_audio_device);
UInt32 dev_id = dev_id_int < 0 ? 0 : dev_id_int;
RebuildDeviceList(p_aout, &dev_id);
p_sys->i_new_selected_dev = dev_id;
free(psz_audio_device);
}
else
{
RebuildDeviceList(p_aout, NULL);
p_sys->i_new_selected_dev = 0;
}
char deviceid[10];
sprintf(deviceid, "%i", p_sys->i_new_selected_dev);
aout_DeviceReport(p_aout, deviceid);
/* remember the volume */ /* remember the volume */
p_sys->f_volume = var_InheritInteger(p_aout, "auhal-volume") p_sys->f_volume = var_InheritInteger(p_aout, "auhal-volume")
...@@ -1680,10 +1709,6 @@ static int Open(vlc_object_t *obj) ...@@ -1680,10 +1709,6 @@ static int Open(vlc_object_t *obj)
p_sys->b_mute = var_InheritBool(p_aout, "mute"); p_sys->b_mute = var_InheritBool(p_aout, "mute");
aout_MuteReport(p_aout, p_sys->b_mute); aout_MuteReport(p_aout, p_sys->b_mute);
char *psz_audio_device = var_InheritString(p_aout, "auhal-audio-device");
SwitchAudioDevice(p_aout, psz_audio_device);
free(psz_audio_device);
ca_Open(p_aout); ca_Open(p_aout);
return VLC_SUCCESS; return VLC_SUCCESS;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment