summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-12-21 18:34:42 +0100
committerwm4 <wm4@nowhere>2013-12-21 20:50:12 +0100
commit7cc3c3aeec702898a1722cbd8ce1dd8b4658c4be (patch)
treee66218e1f22eda46b34d2dd6cec52fb3f469cea5
parent60c06fec1e45e1ddb285fe54f1106e1fc8838edd (diff)
downloadmpv-7cc3c3aeec702898a1722cbd8ce1dd8b4658c4be.tar.bz2
mpv-7cc3c3aeec702898a1722cbd8ce1dd8b4658c4be.tar.xz
ao_wasapi: mp_msg conversions
Remove the nonsensical print_lock too. Things that are called from the option validator are not converted yet, because the option parser doesn't provide a log context yet.
-rw-r--r--audio/out/ao_wasapi.c101
1 files changed, 34 insertions, 67 deletions
diff --git a/audio/out/ao_wasapi.c b/audio/out/ao_wasapi.c
index 3804aa0cb9..344790cee4 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;
}
@@ -958,7 +932,7 @@ 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);
@@ -966,7 +940,7 @@ static int thread_init(struct ao *ao)
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 +958,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 +1018,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 +1094,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 +1184,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,19 +1194,19 @@ 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) {
@@ -1261,7 +1229,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 +1241,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;
}