diff options
author | wm4 <wm4@nowhere> | 2013-12-21 20:03:36 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-12-21 21:43:16 +0100 |
commit | 9242c34fa26aafb09a9973a5175c281233a13bdc (patch) | |
tree | c94bf638a38ce29c8c6e37c9c6167968e8d3cc34 /audio | |
parent | d8d42b44fc717c695af59c14213d54885088ea37 (diff) | |
download | mpv-9242c34fa26aafb09a9973a5175c281233a13bdc.tar.bz2 mpv-9242c34fa26aafb09a9973a5175c281233a13bdc.tar.xz |
m_option: add mp_log callback to OPT_STRING_VALIDATE options
And also convert a bunch of other code, especially ao_wasapi and
ao_portaudio.
Diffstat (limited to 'audio')
-rw-r--r-- | audio/out/ao_openal.c | 10 | ||||
-rw-r--r-- | audio/out/ao_portaudio.c | 49 | ||||
-rw-r--r-- | audio/out/ao_wasapi.c | 63 |
3 files changed, 62 insertions, 60 deletions
diff --git a/audio/out/ao_openal.c b/audio/out/ao_openal.c index d613b74208..3cb8ba5149 100644 --- a/audio/out/ao_openal.c +++ b/audio/out/ao_openal.c @@ -79,18 +79,18 @@ static int control(struct ao *ao, enum aocontrol cmd, void *arg) return CONTROL_UNKNOWN; } -static int validate_device_opt(const m_option_t *opt, struct bstr name, - struct bstr param) +static int validate_device_opt(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param) { if (bstr_equals0(param, "help")) { if (alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_TRUE) { - mp_msg(MSGT_AO, MSGL_FATAL, "Device listing not supported.\n"); + mp_fatal(log, "Device listing not supported.\n"); return M_OPT_EXIT; } const char *list = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER); - mp_msg(MSGT_AO, MSGL_INFO, "OpenAL devices:\n"); + mp_info(log, "OpenAL devices:\n"); while (list && *list) { - mp_msg(MSGT_AO, MSGL_INFO, " '%s'\n", list); + mp_info(log, " '%s'\n", list); list = list + strlen(list) + 1; } return M_OPT_EXIT - 1; diff --git a/audio/out/ao_portaudio.c b/audio/out/ao_portaudio.c index 8b4efe7944..8b7e3041cd 100644 --- a/audio/out/ao_portaudio.c +++ b/audio/out/ao_portaudio.c @@ -65,21 +65,21 @@ static const struct format_map format_maps[] = { {AF_FORMAT_UNKNOWN, 0} }; -static bool check_pa_ret(int ret) +static bool check_pa_ret(struct mp_log *log, int ret) { if (ret < 0) { - mp_msg(MSGT_AO, MSGL_ERR, "[ao/portaudio] %s\n", - Pa_GetErrorText(ret)); + mp_err(log, "%s\n", Pa_GetErrorText(ret)); if (ret == paUnanticipatedHostError) { const PaHostErrorInfo* hosterr = Pa_GetLastHostErrorInfo(); - mp_msg(MSGT_AO, MSGL_ERR, "[ao/portaudio] Host error: %s\n", - hosterr->errorText); + mp_err(log, "Host error: %s\n", hosterr->errorText); } return false; } return true; } +#define CHECK_PA_RET(ret) check_pa_ret(ao->log, (ret)) + static int seconds_to_bytes(struct ao *ao, double seconds) { return af_fmt_seconds_to_bytes(ao->format, seconds, ao->channels.num, @@ -93,23 +93,23 @@ static int to_int(const char *s, int return_on_error) return (s[0] && !endptr[0]) ? res : return_on_error; } -static int find_device(const char *name) +static int find_device(struct mp_log *log, const char *name) { int found = paNoDevice; if (!name) return found; int help = strcmp(name, "help") == 0; int count = Pa_GetDeviceCount(); - check_pa_ret(count); + check_pa_ret(log, count); int index = to_int(name, -1); if (help) - mp_msg(MSGT_AO, MSGL_INFO, "PortAudio devices:\n"); + mp_info(log, "PortAudio devices:\n"); for (int n = 0; n < count; n++) { const PaDeviceInfo* info = Pa_GetDeviceInfo(n); if (help) { if (info->maxOutputChannels < 1) continue; - mp_msg(MSGT_AO, MSGL_INFO, " %d '%s', %d channels, latency: %.2f " + mp_info(log, " %d '%s', %d channels, latency: %.2f " "ms, sample rate: %.0f\n", n, info->name, info->maxOutputChannels, info->defaultHighOutputLatency * 1000, @@ -121,21 +121,20 @@ static int find_device(const char *name) } } if (found == paNoDevice && !help) - mp_msg(MSGT_AO, MSGL_WARN, "[ao/portaudio] Device '%s' not found!\n", - name); + mp_warn(log, "Device '%s' not found!\n", name); return found; } -static int validate_device_opt(const m_option_t *opt, struct bstr name, - struct bstr param) +static int validate_device_opt(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param) { // Note: we do not check whether the device actually exist, because this // might break elaborate configs with several AOs trying several // devices. We do it merely for making "help" special. if (bstr_equals0(param, "help")) { - if (!check_pa_ret(Pa_Initialize())) + if (!check_pa_ret(log, Pa_Initialize())) return M_OPT_EXIT; - find_device("help"); + find_device(log, "help"); Pa_Terminate(); return M_OPT_EXIT - 1; } @@ -205,9 +204,9 @@ static void uninit(struct ao *ao, bool cut_audio) pthread_mutex_unlock(&priv->ring_mutex); - check_pa_ret(Pa_StopStream(priv->stream)); + CHECK_PA_RET(Pa_StopStream(priv->stream)); } - check_pa_ret(Pa_CloseStream(priv->stream)); + CHECK_PA_RET(Pa_CloseStream(priv->stream)); } pthread_mutex_destroy(&priv->ring_mutex); @@ -218,14 +217,14 @@ static int init(struct ao *ao) { struct priv *priv = ao->priv; - if (!check_pa_ret(Pa_Initialize())) + if (!CHECK_PA_RET(Pa_Initialize())) return -1; pthread_mutex_init(&priv->ring_mutex, NULL); int pa_device = Pa_GetDefaultOutputDevice(); if (priv->cfg_device && priv->cfg_device[0]) - pa_device = find_device(priv->cfg_device); + pa_device = find_device(ao->log, priv->cfg_device); if (pa_device == paNoDevice) goto error_exit; @@ -264,9 +263,9 @@ static int init(struct ao *ao) priv->framelen = ao->channels.num * (af_fmt2bits(ao->format) / 8); ao->bps = ao->samplerate * priv->framelen; - if (!check_pa_ret(Pa_IsFormatSupported(NULL, &sp, ao->samplerate))) + if (!CHECK_PA_RET(Pa_IsFormatSupported(NULL, &sp, ao->samplerate))) goto error_exit; - if (!check_pa_ret(Pa_OpenStream(&priv->stream, NULL, &sp, ao->samplerate, + if (!CHECK_PA_RET(Pa_OpenStream(&priv->stream, NULL, &sp, ao->samplerate, paFramesPerBufferUnspecified, paNoFlag, stream_callback, ao))) goto error_exit; @@ -293,7 +292,7 @@ static int play(struct ao *ao, void **data, int samples, int flags) pthread_mutex_unlock(&priv->ring_mutex); if (Pa_IsStreamStopped(priv->stream) == 1) - check_pa_ret(Pa_StartStream(priv->stream)); + CHECK_PA_RET(Pa_StartStream(priv->stream)); return write_len / ao->sstride; } @@ -333,7 +332,7 @@ static void reset(struct ao *ao) struct priv *priv = ao->priv; if (Pa_IsStreamStopped(priv->stream) != 1) - check_pa_ret(Pa_AbortStream(priv->stream)); + CHECK_PA_RET(Pa_AbortStream(priv->stream)); pthread_mutex_lock(&priv->ring_mutex); @@ -349,7 +348,7 @@ static void pause(struct ao *ao) { struct priv *priv = ao->priv; - check_pa_ret(Pa_AbortStream(priv->stream)); + CHECK_PA_RET(Pa_AbortStream(priv->stream)); double stream_time = Pa_GetStreamTime(priv->stream); @@ -368,7 +367,7 @@ static void resume(struct ao *ao) { struct priv *priv = ao->priv; - check_pa_ret(Pa_StartStream(priv->stream)); + CHECK_PA_RET(Pa_StartStream(priv->stream)); } #define OPT_BASE_STRUCT struct priv diff --git a/audio/out/ao_wasapi.c b/audio/out/ao_wasapi.c index 344790cee4..3d0d1ddf3d 100644 --- a/audio/out/ao_wasapi.c +++ b/audio/out/ao_wasapi.c @@ -697,7 +697,9 @@ end: return found; } -static HRESULT enumerate_with_state(char *header, int status, int with_id) { +static HRESULT enumerate_with_state(struct mp_log *log, char *header, + int status, int with_id) +{ HRESULT hr; IMMDeviceEnumerator *pEnumerator = NULL; IMMDeviceCollection *pDevices = NULL; @@ -724,7 +726,7 @@ static HRESULT enumerate_with_state(char *header, int status, int with_id) { int count; IMMDeviceCollection_GetCount(pDevices, &count); if (count > 0) { - mp_msg(MSGT_AO, MSGL_INFO, "ao-wasapi: %s\n", header); + mp_info(log, "%s\n", header); } for (int i = 0; i < count; i++) { @@ -739,11 +741,9 @@ static HRESULT enumerate_with_state(char *header, int status, int with_id) { mark = " (default)"; if (with_id) { - mp_msg(MSGT_AO, MSGL_INFO, "ao-wasapi: Device #%d: %s, ID: %s%s\n", - i, name, id, mark); + mp_info(log, "Device #%d: %s, ID: %s%s\n", i, name, id, mark); } else { - mp_msg(MSGT_AO, MSGL_INFO, "ao-wasapi: %s, ID: %s%s\n", - name, id, mark); + mp_info(log, "%s, ID: %s%s\n", name, id, mark); } free(name); @@ -763,24 +763,27 @@ exit_label: return hr; } -static int enumerate_devices(void) { +static int enumerate_devices(struct mp_log *log) +{ HRESULT hr; CoInitialize(NULL); - hr = enumerate_with_state("Active devices:", DEVICE_STATE_ACTIVE, 1); + hr = enumerate_with_state(log, "Active devices:", DEVICE_STATE_ACTIVE, 1); EXIT_ON_ERROR(hr); - hr = enumerate_with_state("Unplugged devices:", DEVICE_STATE_UNPLUGGED, 0); + hr = enumerate_with_state(log, "Unplugged devices:", DEVICE_STATE_UNPLUGGED, 0); EXIT_ON_ERROR(hr); CoUninitialize(); return 0; exit_label: - mp_msg(MSGT_AO, MSGL_ERR, "Error enumerating devices: HRESULT %08"PRIx32" \"%s\"\n", - (uint32_t)hr, explain_err(hr)); + mp_err(log, "Error enumerating devices: HRESULT %08"PRIx32" \"%s\"\n", + (uint32_t)hr, explain_err(hr)); CoUninitialize(); return 1; } -static HRESULT find_and_load_device(IMMDevice **ppDevice, char *search) { +static HRESULT find_and_load_device(struct ao *ao, IMMDevice **ppDevice, + char *search) +{ HRESULT hr; IMMDeviceEnumerator *pEnumerator = NULL; IMMDeviceCollection *pDevices = NULL; @@ -810,16 +813,16 @@ static HRESULT find_and_load_device(IMMDevice **ppDevice, char *search) { IMMDeviceCollection_GetCount(pDevices, &count); if (devno >= count) { - mp_msg(MSGT_AO, MSGL_ERR, "ao-wasapi: no device #%d!\n", devno); + MP_ERR(ao, "no device #%d!\n", devno); } else { - mp_msg(MSGT_AO, MSGL_V, "ao-wasapi: finding device #%d\n", devno); + MP_VERBOSE(ao, "finding device #%d\n", devno); hr = IMMDeviceCollection_Item(pDevices, devno, &pTempDevice); EXIT_ON_ERROR(hr); hr = IMMDevice_GetId(pTempDevice, &deviceID); EXIT_ON_ERROR(hr); - mp_msg(MSGT_AO, MSGL_V, "ao-wasapi: found device #%d\n", devno); + MP_VERBOSE(ao, "found device #%d\n", devno); } } else { hr = IMMDeviceEnumerator_EnumAudioEndpoints(pEnumerator, eRender, @@ -830,7 +833,7 @@ static HRESULT find_and_load_device(IMMDevice **ppDevice, char *search) { int count; IMMDeviceCollection_GetCount(pDevices, &count); - mp_msg(MSGT_AO, MSGL_V, "ao-wasapi: finding device %s\n", devid); + MP_VERBOSE(ao, "finding device %s\n", devid); IMMDevice *prevDevice = NULL; @@ -848,14 +851,14 @@ static HRESULT find_and_load_device(IMMDevice **ppDevice, char *search) { if (deviceID) { char *name; if (!search_err) { - mp_msg(MSGT_AO, MSGL_ERR, "ao-wasapi: multiple matching devices found!\n"); + MP_ERR(ao, "multiple matching devices found!\n"); name = get_device_name(prevDevice); - mp_msg(MSGT_AO, MSGL_ERR, "ao-wasapi: %s\n", name); + MP_ERR(ao, "%s\n", name); free(name); search_err = 1; } name = get_device_name(pTempDevice); - mp_msg(MSGT_AO, MSGL_ERR, "ao-wasapi: %s\n", name); + MP_ERR(ao, "%s\n", name); free(name); } hr = IMMDevice_GetId(pTempDevice, &deviceID); @@ -867,7 +870,7 @@ static HRESULT find_and_load_device(IMMDevice **ppDevice, char *search) { } if (deviceID == NULL) { - mp_msg(MSGT_AO, MSGL_ERR, "ao-wasapi: could not find device %s!\n", devid); + MP_ERR(ao, "could not find device %s!\n", devid); } } @@ -877,12 +880,12 @@ static HRESULT find_and_load_device(IMMDevice **ppDevice, char *search) { if (deviceID == NULL || search_err) { hr = E_NOTFOUND; } else { - mp_msg(MSGT_AO, MSGL_V, "ao-wasapi: loading device %S\n", deviceID); + MP_VERBOSE(ao, "loading device %S\n", deviceID); hr = IMMDeviceEnumerator_GetDevice(pEnumerator, deviceID, ppDevice); if (FAILED(hr)) { - mp_msg(MSGT_AO, MSGL_ERR, "ao-wasapi: could not load requested device!\n"); + MP_ERR(ao, "could not load requested device!\n"); } } @@ -893,14 +896,15 @@ exit_label: return hr; } -static int validate_device(const m_option_t *opt, struct bstr name, - struct bstr param) { +static int validate_device(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param) +{ if (bstr_equals0(param, "help")) { - enumerate_devices(); + enumerate_devices(log); return M_OPT_EXIT; } - mp_msg(MSGT_AO, MSGL_DBG2, "ao-wasapi: validating device=%s\n", param.start); + mp_dbg(log, "validating device=%s\n", param.start); char *end; int devno = (int) strtol(param.start, &end, 10); @@ -909,8 +913,7 @@ static int validate_device(const m_option_t *opt, struct bstr name, if ((end == (void*)param.start || *end) && devno < 0) ret = M_OPT_OUT_OF_RANGE; - mp_msg(MSGT_AO, MSGL_DBG2, "ao-wasapi: device=%s %svalid\n", - param.start, ret == 1 ? "" : "not "); + mp_dbg(log, "device=%s %svalid\n", param.start, ret == 1 ? "" : "not "); return ret; } @@ -935,7 +938,7 @@ static int thread_init(struct ao *ao) MP_VERBOSE(ao, "default device ID: %s\n", id); free(id); } else { - hr = find_and_load_device(&state->pDevice, state->opt_device); + hr = find_and_load_device(ao, &state->pDevice, state->opt_device); } EXIT_ON_ERROR(hr); @@ -1210,7 +1213,7 @@ static int init(struct ao *ao) fill_VistaBlob(state); if (state->opt_list) { - enumerate_devices(); + enumerate_devices(state->log); } if (state->opt_exclusive) { |