winmm_output_plugin: fail if wrong device specified instead of using fallback.
Silently choosing default is misleading and can cause hours of investigation. It's better to fail immediately telling user what is wrong with config.
This commit is contained in:
parent
b88b2b3d79
commit
33232face9
1
NEWS
1
NEWS
@ -20,6 +20,7 @@ ver 0.17 (2011/??/??)
|
|||||||
- raop: new output plugin
|
- raop: new output plugin
|
||||||
- shout: add possibility to set url
|
- shout: add possibility to set url
|
||||||
- roar: new output plugin for RoarAudio
|
- roar: new output plugin for RoarAudio
|
||||||
|
- winmm: fail if wrong device specified instead of using default device
|
||||||
* playlist:
|
* playlist:
|
||||||
- allow references to songs outside the music directory
|
- allow references to songs outside the music directory
|
||||||
* state_file: add option "restore_paused"
|
* state_file: add option "restore_paused"
|
||||||
|
@ -74,33 +74,45 @@ winmm_output_test_default_device(void)
|
|||||||
return waveOutGetNumDevs() > 0;
|
return waveOutGetNumDevs() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static UINT
|
static bool
|
||||||
get_device_id(const char *device_name)
|
get_device_id(const char *device_name, UINT *device_id, GError **error_r)
|
||||||
{
|
{
|
||||||
/* if device is not specified use wave mapper */
|
/* if device is not specified use wave mapper */
|
||||||
if (device_name == NULL)
|
if (device_name == NULL) {
|
||||||
return WAVE_MAPPER;
|
*device_id = WAVE_MAPPER;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
UINT numdevs = waveOutGetNumDevs();
|
||||||
|
|
||||||
/* check for device id */
|
/* check for device id */
|
||||||
char *endptr;
|
char *endptr;
|
||||||
UINT id = strtoul(device_name, &endptr, 0);
|
UINT id = strtoul(device_name, &endptr, 0);
|
||||||
if (endptr > device_name && *endptr == 0)
|
if (endptr > device_name && *endptr == 0) {
|
||||||
return id;
|
if (id >= numdevs)
|
||||||
|
goto fail;
|
||||||
|
*device_id = id;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/* check for device name */
|
/* check for device name */
|
||||||
for (UINT i = 0; i < waveOutGetNumDevs(); i++) {
|
for (UINT i = 0; i < numdevs; i++) {
|
||||||
WAVEOUTCAPS caps;
|
WAVEOUTCAPS caps;
|
||||||
MMRESULT result = waveOutGetDevCaps(i, &caps, sizeof(caps));
|
MMRESULT result = waveOutGetDevCaps(i, &caps, sizeof(caps));
|
||||||
if (result != MMSYSERR_NOERROR)
|
if (result != MMSYSERR_NOERROR)
|
||||||
continue;
|
continue;
|
||||||
/* szPname is only 32 chars long, so it is often truncated.
|
/* szPname is only 32 chars long, so it is often truncated.
|
||||||
Use partial match to work around this. */
|
Use partial match to work around this. */
|
||||||
if (strstr(device_name, caps.szPname) == device_name)
|
if (strstr(device_name, caps.szPname) == device_name) {
|
||||||
return i;
|
*device_id = i;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fallback to wave mapper */
|
fail:
|
||||||
return WAVE_MAPPER;
|
g_set_error(error_r, winmm_output_quark(), 0,
|
||||||
|
"device \"%s\" is not found", device_name);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct audio_output *
|
static struct audio_output *
|
||||||
@ -113,7 +125,12 @@ winmm_output_init(const struct config_param *param, GError **error_r)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *device = config_get_block_string(param, "device", NULL);
|
const char *device = config_get_block_string(param, "device", NULL);
|
||||||
wo->device_id = get_device_id(device);
|
if (!get_device_id(device, &wo->device_id, error_r)) {
|
||||||
|
ao_base_finish(&wo->base);
|
||||||
|
g_free(wo);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return &wo->base;
|
return &wo->base;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user