diff options
Diffstat (limited to 'audio/out')
-rw-r--r-- | audio/out/ao.c | 34 | ||||
-rw-r--r-- | audio/out/ao_alsa.c | 21 | ||||
-rw-r--r-- | audio/out/ao_coreaudio.c | 2 | ||||
-rw-r--r-- | audio/out/ao_coreaudio_utils.c | 2 | ||||
-rw-r--r-- | audio/out/ao_lavc.c | 5 | ||||
-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 | 164 |
8 files changed, 122 insertions, 165 deletions
diff --git a/audio/out/ao.c b/audio/out/ao.c index ddd177400d..4530b1c3b7 100644 --- a/audio/out/ao.c +++ b/audio/out/ao.c @@ -130,7 +130,7 @@ static struct ao *ao_create(bool probing, struct mpv_global *global, struct mp_log *log = mp_log_new(NULL, global->log, "ao"); struct m_obj_desc desc; if (!m_obj_list_find(&desc, &ao_obj_list, bstr0(name))) { - mp_msg_log(log, MSGL_ERR, "Audio output %s not found!\n", name); + mp_msg(log, MSGL_ERR, "Audio output %s not found!\n", name); talloc_free(log); return NULL; }; @@ -149,7 +149,7 @@ static struct ao *ao_create(bool probing, struct mpv_global *global, }; if (ao->driver->encode != !!ao->encode_lavc_ctx) goto error; - struct m_config *config = m_config_from_obj_desc(ao, &desc); + struct m_config *config = m_config_from_obj_desc(ao, ao->log, &desc); if (m_config_apply_defaults(config, name, global->opts->ao_defs) < 0) goto error; if (m_config_set_obj_params(config, args) < 0) @@ -176,33 +176,37 @@ struct ao *ao_init_best(struct mpv_global *global, struct encode_lavc_context *encode_lavc_ctx, int samplerate, int format, struct mp_chmap channels) { + struct mp_log *log = mp_log_new(NULL, global->log, "ao"); + struct ao *ao = NULL; struct m_obj_settings *ao_list = global->opts->audio_driver_list; if (ao_list && ao_list[0].name) { for (int n = 0; ao_list[n].name; n++) { if (strlen(ao_list[n].name) == 0) goto autoprobe; - mp_msg(MSGT_AO, MSGL_V, "Trying preferred audio driver '%s'\n", - ao_list[n].name); - struct ao *ao = ao_create(false, global, input_ctx, encode_lavc_ctx, - samplerate, format, channels, - ao_list[n].name, ao_list[n].attribs); + mp_verbose(log, "Trying preferred audio driver '%s'\n", + ao_list[n].name); + ao = ao_create(false, global, input_ctx, encode_lavc_ctx, + samplerate, format, channels, + ao_list[n].name, ao_list[n].attribs); if (ao) - return ao; - mp_msg(MSGT_AO, MSGL_WARN, "Failed to initialize audio driver '%s'\n", + goto done; + mp_warn(log, "Failed to initialize audio driver '%s'\n", ao_list[n].name); } - return NULL; + goto done; } autoprobe: // now try the rest... for (int i = 0; audio_out_drivers[i]; i++) { - struct ao *ao = ao_create(true, global, input_ctx, encode_lavc_ctx, - samplerate, format, channels, - (char *)audio_out_drivers[i]->name, NULL); + ao = ao_create(true, global, input_ctx, encode_lavc_ctx, + samplerate, format, channels, + (char *)audio_out_drivers[i]->name, NULL); if (ao) - return ao; + goto done; } - return NULL; +done: + talloc_free(log); + return ao; } void ao_uninit(struct ao *ao, bool cut_audio) diff --git a/audio/out/ao_alsa.c b/audio/out/ao_alsa.c index a65b9b05ec..f4884f077c 100644 --- a/audio/out/ao_alsa.c +++ b/audio/out/ao_alsa.c @@ -80,25 +80,6 @@ struct priv { static float get_delay(struct ao *ao); static void uninit(struct ao *ao, bool immed); -static void alsa_error_handler(const char *file, int line, const char *function, - int err, const char *format, ...) -{ - char tmp[0xc00]; - va_list va; - - va_start(va, format); - vsnprintf(tmp, sizeof tmp, format, va); - va_end(va); - - if (err) { - mp_msg(MSGT_AO, MSGL_ERR, "alsa-lib: %s:%i:(%s) %s: %s\n", - file, line, function, tmp, snd_strerror(err)); - } else { - mp_msg(MSGT_AO, MSGL_ERR, "alsa-lib: %s:%i:(%s) %s\n", - file, line, function, tmp); - } -} - /* to set/get/query special features/parameters */ static int control(struct ao *ao, enum aocontrol cmd, void *arg) { @@ -401,7 +382,6 @@ static int init(struct ao *ao) p->can_pause = 1; MP_VERBOSE(ao, "using ALSA version: %s\n", snd_asoundlib_version()); - snd_lib_error_set_handler(alsa_error_handler); int open_mode = p->cfg_block ? 0 : SND_PCM_NONBLOCK; //modes = 0, SND_PCM_NONBLOCK, SND_PCM_ASYNC @@ -573,7 +553,6 @@ static void uninit(struct ao *ao, bool immed) alsa_error: p->alsa = NULL; - snd_lib_error_set_handler(NULL); } static void audio_pause(struct ao *ao) diff --git a/audio/out/ao_coreaudio.c b/audio/out/ao_coreaudio.c index 4a4091daf9..ba95fa728d 100644 --- a/audio/out/ao_coreaudio.c +++ b/audio/out/ao_coreaudio.c @@ -271,7 +271,7 @@ static int init(struct ao *ao) selected_device = p->opt_device_id; } - if (mp_msg_test_log(ao->log, MSGL_V)) { + if (mp_msg_test(ao->log, MSGL_V)) { char *name; err = CA_GET_STR(selected_device, kAudioObjectPropertyName, &name); CHECK_CA_ERROR("could not get selected audio device name"); diff --git a/audio/out/ao_coreaudio_utils.c b/audio/out/ao_coreaudio_utils.c index 9fa54c726c..97125c7f21 100644 --- a/audio/out/ao_coreaudio_utils.c +++ b/audio/out/ao_coreaudio_utils.c @@ -57,7 +57,7 @@ bool check_ca_st(struct ao *ao, int level, OSStatus code, const char *message) if (code == noErr) return true; char *error_string = fourcc_repr(NULL, code); - mp_msg_log(ao->log, level, "%s (%s)\n", message, error_string); + mp_msg(ao->log, level, "%s (%s)\n", message, error_string); talloc_free(error_string); return false; diff --git a/audio/out/ao_lavc.c b/audio/out/ao_lavc.c index 3e4ba01105..359fbae0fa 100644 --- a/audio/out/ao_lavc.c +++ b/audio/out/ao_lavc.c @@ -69,6 +69,11 @@ static void select_format(struct ao *ao, AVCodec *codec) ++sampleformat) { int fmt = af_from_avformat(*sampleformat); + if (!fmt) { + MP_WARN(ao, "unsupported lavc format %s", + av_get_sample_fmt_name(*sampleformat)); + continue; + } int score = af_format_conversion_score(fmt, ao->format); if (score > best_score) { best_score = score; 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 3804aa0cb9..3d0d1ddf3d 100644 --- a/audio/out/ao_wasapi.c +++ b/audio/out/ao_wasapi.c @@ -72,6 +72,7 @@ union WAVEFMT { }; typedef struct wasapi_state { + struct mp_log *log; HANDLE threadLoop; /* Init phase */ @@ -100,9 +101,6 @@ typedef struct wasapi_state { DWORD vol_hw_support, status; float audio_volume; - /* Prints, for in case line buffers are disabled */ - CRITICAL_SECTION print_lock; - /* Buffers */ struct mp_ring *ringbuff; size_t buffer_block_size; /* Size of each block in bytes */ @@ -296,8 +294,8 @@ static int set_ao_format(struct wasapi_state *state, wformat.Format.wBitsPerSample, wformat.SubFormat.Data1 == 3); if (wformat.SubFormat.Data1 != 1 && wformat.SubFormat.Data1 != 3) { - mp_msg(MSGT_AO, MSGL_ERR, "ao-wasapi: unknown SubFormat %"PRIu32"\n", - (uint32_t)wformat.SubFormat.Data1); + MP_ERR(ao, "unknown SubFormat %"PRIu32"\n", + (uint32_t)wformat.SubFormat.Data1); return 0; } @@ -323,10 +321,8 @@ static int try_format(struct wasapi_state *state, int af_format = format_set_bits(ao->format, bits, bits == 32); - EnterCriticalSection(&state->print_lock); - mp_msg(MSGT_AO, MSGL_V, "ao-wasapi: trying %dch %s @ %dhz\n", - channels.num, af_fmt_to_str(af_format), samplerate); - LeaveCriticalSection(&state->print_lock); + MP_VERBOSE(ao, "trying %dch %s @ %dhz\n", + channels.num, af_fmt_to_str(af_format), samplerate); union WAVEFMT u; u.extensible = &wformat; @@ -349,20 +345,16 @@ static int try_format(struct wasapi_state *state, if (hr == S_FALSE) { if (set_ao_format(state, ao, wformat)) { - EnterCriticalSection(&state->print_lock); - mp_msg(MSGT_AO, MSGL_V, "ao-wasapi: accepted as %dch %s @ %dhz\n", - ao->channels.num, af_fmt_to_str(ao->format), ao->samplerate); - LeaveCriticalSection(&state->print_lock); + MP_VERBOSE(ao, "accepted as %dch %s @ %dhz\n", + ao->channels.num, af_fmt_to_str(ao->format), ao->samplerate); return 1; } } if (hr == S_OK || (!state->opt_exclusive && hr == AUDCLNT_E_UNSUPPORTED_FORMAT)) { // AUDCLNT_E_UNSUPPORTED_FORMAT here means "works in shared, doesn't in exclusive" if (set_ao_format(state, ao, wformat)) { - EnterCriticalSection(&state->print_lock); - mp_msg(MSGT_AO, MSGL_V, "ao-wasapi: %dch %s @ %dhz accepted\n", - ao->channels.num, af_fmt_to_str(af_format), samplerate); - LeaveCriticalSection(&state->print_lock); + MP_VERBOSE(ao, "%dch %s @ %dhz accepted\n", + ao->channels.num, af_fmt_to_str(af_format), samplerate); return 1; } } @@ -416,10 +408,8 @@ static int try_passthrough(struct wasapi_state *state, union WAVEFMT u; u.extensible = &wformat; - EnterCriticalSection(&state->print_lock); - mp_msg(MSGT_AO, MSGL_V, "ao-wasapi: trying passthrough for %s...\n", - af_fmt_to_str((ao->format&~AF_FORMAT_END_MASK) | AF_FORMAT_LE)); - LeaveCriticalSection(&state->print_lock); + MP_VERBOSE(ao, "trying passthrough for %s...\n", + af_fmt_to_str((ao->format&~AF_FORMAT_END_MASK) | AF_FORMAT_LE)); HRESULT hr = IAudioClient_IsFormatSupported(state->pAudioClient, state->share_mode, @@ -440,12 +430,10 @@ static int find_formats(struct ao *const ao) if (try_passthrough(state, ao)) return 0; - EnterCriticalSection(&state->print_lock); - mp_msg(MSGT_AO, MSGL_ERR, "ao-wasapi: couldn't use passthrough!"); + MP_ERR(ao, "couldn't use passthrough!"); if (!state->opt_exclusive) - mp_msg(MSGT_AO, MSGL_ERR, " (try exclusive mode)"); - mp_msg(MSGT_AO, MSGL_ERR, "\n"); - LeaveCriticalSection(&state->print_lock); + MP_ERR(ao, " (try exclusive mode)"); + MP_ERR(ao, "\n"); return -1; } @@ -464,9 +452,7 @@ static int find_formats(struct ao *const ao) return 0; } - EnterCriticalSection(&state->print_lock); - mp_msg(MSGT_AO, MSGL_WARN, "ao-wasapi: couldn't use default mix format!\n"); - LeaveCriticalSection(&state->print_lock); + MP_WARN(ao, "couldn't use default mix format!\n"); } /* Exclusive mode, we have to guess. */ @@ -537,9 +523,7 @@ static int find_formats(struct ao *const ao) bits = start_bits; mp_chmap_from_channels(&ao->channels, 2); } else { - EnterCriticalSection(&state->print_lock); - mp_msg(MSGT_AO, MSGL_ERR, "ao-wasapi: couldn't find acceptable audio format!\n"); - LeaveCriticalSection(&state->print_lock); + MP_ERR(ao, "couldn't find acceptable audio format!\n"); return -1; } } @@ -566,12 +550,8 @@ reinit: NULL); /* something about buffer sizes on Win7, fixme might loop forever */ if (hr == AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED) { - EnterCriticalSection(&state->print_lock); - mp_msg( - MSGT_AO, MSGL_V, - "ao-wasapi: IAudioClient::Initialize negotiation failed with %s, used %lld * 100ns\n", - explain_err(hr), state->defaultRequestedDuration); - LeaveCriticalSection(&state->print_lock); + MP_VERBOSE(state, "IAudioClient::Initialize negotiation failed with %s, used %lld * 100ns\n", + explain_err(hr), state->defaultRequestedDuration); if (offset > 10.0) goto exit_label; /* is 10 enough to break out of the loop?*/ IAudioClient_GetBufferSize(state->pAudioClient, &state->bufferFrameCount); @@ -603,18 +583,12 @@ reinit: state->bufferFrameCount; state->hTask = state->VistaBlob.pAvSetMmThreadCharacteristicsW(L"Pro Audio", &state->taskIndex); - EnterCriticalSection(&state->print_lock); - mp_msg(MSGT_AO, MSGL_V, - "ao-wasapi: fix_format OK, using %lld byte buffer block size!\n", - (long long) state->buffer_block_size); - LeaveCriticalSection(&state->print_lock); + MP_VERBOSE(state, "fix_format OK, using %lld byte buffer block size!\n", + (long long) state->buffer_block_size); return 0; exit_label: - EnterCriticalSection(&state->print_lock); - mp_msg(MSGT_AO, MSGL_ERR, - "ao-wasapi: fix_format fails with %s, failed to determine buffer block size!\n", + MP_ERR(state, "fix_format fails with %s, failed to determine buffer block size!\n", explain_err(hr)); - LeaveCriticalSection(&state->print_lock); SetEvent(state->fatal_error); return 1; } @@ -723,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; @@ -750,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++) { @@ -765,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); @@ -789,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; @@ -836,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, @@ -856,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; @@ -874,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); @@ -893,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); } } @@ -903,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"); } } @@ -919,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); @@ -935,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; } @@ -958,15 +935,15 @@ static int thread_init(struct ao *ao) SAFE_RELEASE(pEnumerator, IMMDeviceEnumerator_Release(pEnumerator)); char *id = get_device_id(state->pDevice); - mp_msg(MSGT_AO, MSGL_V, "ao-wasapi: default device ID: %s\n", id); + 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); char *name = get_device_name(state->pDevice); - mp_msg(MSGT_AO, MSGL_V, "ao-wasapi: device loaded: %s\n", name); + MP_VERBOSE(ao, "device loaded: %s\n", name); free(name); hr = IMMDeviceActivator_Activate(state->pDevice, &IID_IAudioClient, @@ -984,9 +961,7 @@ static int thread_init(struct ao *ao) if (state->init_ret) goto exit_label; if (!fix_format(state)) { /* now that we're sure what format to use */ - EnterCriticalSection(&state->print_lock); - mp_msg(MSGT_AO, MSGL_V, "ao-wasapi: thread_init OK!\n"); - LeaveCriticalSection(&state->print_lock); + MP_VERBOSE(ao, "thread_init OK!\n"); SetEvent(state->init_done); return state->init_ret; } @@ -1046,9 +1021,7 @@ static void thread_feed(wasapi_state *state,int force_feed) EXIT_ON_ERROR(hr); return; exit_label: - EnterCriticalSection(&state->print_lock); - mp_msg(MSGT_AO, MSGL_ERR, "ao-wasapi: thread_feed fails with %"PRIx32"!\n", (uint32_t)hr); - LeaveCriticalSection(&state->print_lock); + MP_ERR(state, "thread_feed fails with %"PRIx32"!\n", (uint32_t)hr); return; } @@ -1124,9 +1097,7 @@ static DWORD __stdcall ThreadLoop(void *lpParameter) HANDLE playcontrol[] = {state->hUninit, state->hPause, state->hReset, state->hGetvol, state->hSetvol, state->hPlay, state->hFeed, NULL}; - EnterCriticalSection(&state->print_lock); - mp_msg(MSGT_AO, MSGL_V, "ao-wasapi: Entering dispatch loop!\n"); - LeaveCriticalSection(&state->print_lock); + MP_VERBOSE(ao, "Entering dispatch loop!\n"); while (1) { /* watch events, poll at least every 2 seconds */ waitstatus = WaitForMultipleObjects(7, playcontrol, FALSE, 2000); switch (waitstatus) { @@ -1216,7 +1187,7 @@ static int setup_buffers(struct wasapi_state *state) static void uninit(struct ao *ao, bool block) { - mp_msg(MSGT_AO, MSGL_V, "ao-wasapi: uninit!\n"); + MP_VERBOSE(ao, "uninit!\n"); struct wasapi_state *state = (struct wasapi_state *)ao->priv; state->immed = !block; SetEvent(state->hUninit); @@ -1226,23 +1197,23 @@ static void uninit(struct ao *ao, bool block) if (state->VistaBlob.hAvrt) FreeLibrary(state->VistaBlob.hAvrt); closehandles(ao); - DeleteCriticalSection(&state->print_lock); - mp_msg(MSGT_AO, MSGL_V, "ao-wasapi: uninit END!\n"); + MP_VERBOSE(ao, "uninit END!\n"); } static int init(struct ao *ao) { - mp_msg(MSGT_AO, MSGL_V, "ao-wasapi: init!\n"); + MP_VERBOSE(ao, "init!\n"); ao->format = af_fmt_from_planar(ao->format); struct mp_chmap_sel sel = {0}; mp_chmap_sel_add_waveext(&sel); if (!ao_chmap_sel_adjust(ao, &sel, &ao->channels)) return -1; struct wasapi_state *state = (struct wasapi_state *)ao->priv; + state->log = ao->log; fill_VistaBlob(state); if (state->opt_list) { - enumerate_devices(); + enumerate_devices(state->log); } if (state->opt_exclusive) { @@ -1261,7 +1232,6 @@ static int init(struct ao *ao) state->hUninit = CreateEventW(NULL, FALSE, FALSE, NULL); state->fatal_error = CreateEventW(NULL, TRUE, FALSE, NULL); state->hFeed = CreateEvent(NULL, FALSE, FALSE, NULL); /* for wasapi event mode */ - InitializeCriticalSection(&state->print_lock); if (!state->init_done || !state->fatal_error || !state->hPlay || !state->hPause || !state->hFeed || !state->hReset || !state->hGetvol || !state->hSetvol || !state->hDoneVol) @@ -1274,18 +1244,18 @@ static int init(struct ao *ao) state->threadLoop = (HANDLE)CreateThread(NULL, 0, &ThreadLoop, ao, 0, NULL); if (!state->threadLoop) { /* failed to init thread */ - mp_msg(MSGT_AO, MSGL_ERR, "ao-wasapi: fail to create thread!\n"); + MP_ERR(ao, "fail to create thread!\n"); return -1; } WaitForSingleObject(state->init_done, INFINITE); /* wait on init complete */ if (state->init_ret) { if (!ao->probing) { - mp_msg(MSGT_AO, MSGL_ERR, "ao-wasapi: thread_init failed!\n"); + MP_ERR(ao, "thread_init failed!\n"); } } else { - mp_msg(MSGT_AO, MSGL_V, "ao-wasapi: Init Done!\n"); + MP_VERBOSE(ao, "Init Done!\n"); if (setup_buffers(state)) - mp_msg(MSGT_AO, MSGL_ERR, "ao-wasapi: buffer setup failed!\n"); + MP_ERR(ao, "buffer setup failed!\n"); } return state->init_ret; } |