mirror of
https://github.com/mpv-player/mpv
synced 2024-12-26 00:42:57 +00:00
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.
This commit is contained in:
parent
60c06fec1e
commit
7cc3c3aeec
@ -72,6 +72,7 @@ union WAVEFMT {
|
|||||||
};
|
};
|
||||||
|
|
||||||
typedef struct wasapi_state {
|
typedef struct wasapi_state {
|
||||||
|
struct mp_log *log;
|
||||||
HANDLE threadLoop;
|
HANDLE threadLoop;
|
||||||
|
|
||||||
/* Init phase */
|
/* Init phase */
|
||||||
@ -100,9 +101,6 @@ typedef struct wasapi_state {
|
|||||||
DWORD vol_hw_support, status;
|
DWORD vol_hw_support, status;
|
||||||
float audio_volume;
|
float audio_volume;
|
||||||
|
|
||||||
/* Prints, for in case line buffers are disabled */
|
|
||||||
CRITICAL_SECTION print_lock;
|
|
||||||
|
|
||||||
/* Buffers */
|
/* Buffers */
|
||||||
struct mp_ring *ringbuff;
|
struct mp_ring *ringbuff;
|
||||||
size_t buffer_block_size; /* Size of each block in bytes */
|
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);
|
wformat.Format.wBitsPerSample, wformat.SubFormat.Data1 == 3);
|
||||||
|
|
||||||
if (wformat.SubFormat.Data1 != 1 && 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",
|
MP_ERR(ao, "unknown SubFormat %"PRIu32"\n",
|
||||||
(uint32_t)wformat.SubFormat.Data1);
|
(uint32_t)wformat.SubFormat.Data1);
|
||||||
return 0;
|
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);
|
int af_format = format_set_bits(ao->format, bits, bits == 32);
|
||||||
|
|
||||||
EnterCriticalSection(&state->print_lock);
|
MP_VERBOSE(ao, "trying %dch %s @ %dhz\n",
|
||||||
mp_msg(MSGT_AO, MSGL_V, "ao-wasapi: trying %dch %s @ %dhz\n",
|
channels.num, af_fmt_to_str(af_format), samplerate);
|
||||||
channels.num, af_fmt_to_str(af_format), samplerate);
|
|
||||||
LeaveCriticalSection(&state->print_lock);
|
|
||||||
|
|
||||||
union WAVEFMT u;
|
union WAVEFMT u;
|
||||||
u.extensible = &wformat;
|
u.extensible = &wformat;
|
||||||
@ -349,20 +345,16 @@ static int try_format(struct wasapi_state *state,
|
|||||||
|
|
||||||
if (hr == S_FALSE) {
|
if (hr == S_FALSE) {
|
||||||
if (set_ao_format(state, ao, wformat)) {
|
if (set_ao_format(state, ao, wformat)) {
|
||||||
EnterCriticalSection(&state->print_lock);
|
MP_VERBOSE(ao, "accepted as %dch %s @ %dhz\n",
|
||||||
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);
|
||||||
ao->channels.num, af_fmt_to_str(ao->format), ao->samplerate);
|
|
||||||
LeaveCriticalSection(&state->print_lock);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} if (hr == S_OK || (!state->opt_exclusive && hr == AUDCLNT_E_UNSUPPORTED_FORMAT)) {
|
} 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"
|
// AUDCLNT_E_UNSUPPORTED_FORMAT here means "works in shared, doesn't in exclusive"
|
||||||
if (set_ao_format(state, ao, wformat)) {
|
if (set_ao_format(state, ao, wformat)) {
|
||||||
EnterCriticalSection(&state->print_lock);
|
MP_VERBOSE(ao, "%dch %s @ %dhz accepted\n",
|
||||||
mp_msg(MSGT_AO, MSGL_V, "ao-wasapi: %dch %s @ %dhz accepted\n",
|
ao->channels.num, af_fmt_to_str(af_format), samplerate);
|
||||||
ao->channels.num, af_fmt_to_str(af_format), samplerate);
|
|
||||||
LeaveCriticalSection(&state->print_lock);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -416,10 +408,8 @@ static int try_passthrough(struct wasapi_state *state,
|
|||||||
union WAVEFMT u;
|
union WAVEFMT u;
|
||||||
u.extensible = &wformat;
|
u.extensible = &wformat;
|
||||||
|
|
||||||
EnterCriticalSection(&state->print_lock);
|
MP_VERBOSE(ao, "trying passthrough for %s...\n",
|
||||||
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));
|
||||||
af_fmt_to_str((ao->format&~AF_FORMAT_END_MASK) | AF_FORMAT_LE));
|
|
||||||
LeaveCriticalSection(&state->print_lock);
|
|
||||||
|
|
||||||
HRESULT hr = IAudioClient_IsFormatSupported(state->pAudioClient,
|
HRESULT hr = IAudioClient_IsFormatSupported(state->pAudioClient,
|
||||||
state->share_mode,
|
state->share_mode,
|
||||||
@ -440,12 +430,10 @@ static int find_formats(struct ao *const ao)
|
|||||||
if (try_passthrough(state, ao))
|
if (try_passthrough(state, ao))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
EnterCriticalSection(&state->print_lock);
|
MP_ERR(ao, "couldn't use passthrough!");
|
||||||
mp_msg(MSGT_AO, MSGL_ERR, "ao-wasapi: couldn't use passthrough!");
|
|
||||||
if (!state->opt_exclusive)
|
if (!state->opt_exclusive)
|
||||||
mp_msg(MSGT_AO, MSGL_ERR, " (try exclusive mode)");
|
MP_ERR(ao, " (try exclusive mode)");
|
||||||
mp_msg(MSGT_AO, MSGL_ERR, "\n");
|
MP_ERR(ao, "\n");
|
||||||
LeaveCriticalSection(&state->print_lock);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -464,9 +452,7 @@ static int find_formats(struct ao *const ao)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
EnterCriticalSection(&state->print_lock);
|
MP_WARN(ao, "couldn't use default mix format!\n");
|
||||||
mp_msg(MSGT_AO, MSGL_WARN, "ao-wasapi: couldn't use default mix format!\n");
|
|
||||||
LeaveCriticalSection(&state->print_lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Exclusive mode, we have to guess. */
|
/* Exclusive mode, we have to guess. */
|
||||||
@ -537,9 +523,7 @@ static int find_formats(struct ao *const ao)
|
|||||||
bits = start_bits;
|
bits = start_bits;
|
||||||
mp_chmap_from_channels(&ao->channels, 2);
|
mp_chmap_from_channels(&ao->channels, 2);
|
||||||
} else {
|
} else {
|
||||||
EnterCriticalSection(&state->print_lock);
|
MP_ERR(ao, "couldn't find acceptable audio format!\n");
|
||||||
mp_msg(MSGT_AO, MSGL_ERR, "ao-wasapi: couldn't find acceptable audio format!\n");
|
|
||||||
LeaveCriticalSection(&state->print_lock);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -566,12 +550,8 @@ reinit:
|
|||||||
NULL);
|
NULL);
|
||||||
/* something about buffer sizes on Win7, fixme might loop forever */
|
/* something about buffer sizes on Win7, fixme might loop forever */
|
||||||
if (hr == AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED) {
|
if (hr == AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED) {
|
||||||
EnterCriticalSection(&state->print_lock);
|
MP_VERBOSE(state, "IAudioClient::Initialize negotiation failed with %s, used %lld * 100ns\n",
|
||||||
mp_msg(
|
explain_err(hr), state->defaultRequestedDuration);
|
||||||
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);
|
|
||||||
if (offset > 10.0)
|
if (offset > 10.0)
|
||||||
goto exit_label; /* is 10 enough to break out of the loop?*/
|
goto exit_label; /* is 10 enough to break out of the loop?*/
|
||||||
IAudioClient_GetBufferSize(state->pAudioClient, &state->bufferFrameCount);
|
IAudioClient_GetBufferSize(state->pAudioClient, &state->bufferFrameCount);
|
||||||
@ -603,18 +583,12 @@ reinit:
|
|||||||
state->bufferFrameCount;
|
state->bufferFrameCount;
|
||||||
state->hTask =
|
state->hTask =
|
||||||
state->VistaBlob.pAvSetMmThreadCharacteristicsW(L"Pro Audio", &state->taskIndex);
|
state->VistaBlob.pAvSetMmThreadCharacteristicsW(L"Pro Audio", &state->taskIndex);
|
||||||
EnterCriticalSection(&state->print_lock);
|
MP_VERBOSE(state, "fix_format OK, using %lld byte buffer block size!\n",
|
||||||
mp_msg(MSGT_AO, MSGL_V,
|
(long long) state->buffer_block_size);
|
||||||
"ao-wasapi: fix_format OK, using %lld byte buffer block size!\n",
|
|
||||||
(long long) state->buffer_block_size);
|
|
||||||
LeaveCriticalSection(&state->print_lock);
|
|
||||||
return 0;
|
return 0;
|
||||||
exit_label:
|
exit_label:
|
||||||
EnterCriticalSection(&state->print_lock);
|
MP_ERR(state, "fix_format fails with %s, failed to determine buffer block size!\n",
|
||||||
mp_msg(MSGT_AO, MSGL_ERR,
|
|
||||||
"ao-wasapi: fix_format fails with %s, failed to determine buffer block size!\n",
|
|
||||||
explain_err(hr));
|
explain_err(hr));
|
||||||
LeaveCriticalSection(&state->print_lock);
|
|
||||||
SetEvent(state->fatal_error);
|
SetEvent(state->fatal_error);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -958,7 +932,7 @@ static int thread_init(struct ao *ao)
|
|||||||
SAFE_RELEASE(pEnumerator, IMMDeviceEnumerator_Release(pEnumerator));
|
SAFE_RELEASE(pEnumerator, IMMDeviceEnumerator_Release(pEnumerator));
|
||||||
|
|
||||||
char *id = get_device_id(state->pDevice);
|
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);
|
free(id);
|
||||||
} else {
|
} else {
|
||||||
hr = find_and_load_device(&state->pDevice, state->opt_device);
|
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);
|
EXIT_ON_ERROR(hr);
|
||||||
|
|
||||||
char *name = get_device_name(state->pDevice);
|
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);
|
free(name);
|
||||||
|
|
||||||
hr = IMMDeviceActivator_Activate(state->pDevice, &IID_IAudioClient,
|
hr = IMMDeviceActivator_Activate(state->pDevice, &IID_IAudioClient,
|
||||||
@ -984,9 +958,7 @@ static int thread_init(struct ao *ao)
|
|||||||
if (state->init_ret)
|
if (state->init_ret)
|
||||||
goto exit_label;
|
goto exit_label;
|
||||||
if (!fix_format(state)) { /* now that we're sure what format to use */
|
if (!fix_format(state)) { /* now that we're sure what format to use */
|
||||||
EnterCriticalSection(&state->print_lock);
|
MP_VERBOSE(ao, "thread_init OK!\n");
|
||||||
mp_msg(MSGT_AO, MSGL_V, "ao-wasapi: thread_init OK!\n");
|
|
||||||
LeaveCriticalSection(&state->print_lock);
|
|
||||||
SetEvent(state->init_done);
|
SetEvent(state->init_done);
|
||||||
return state->init_ret;
|
return state->init_ret;
|
||||||
}
|
}
|
||||||
@ -1046,9 +1018,7 @@ static void thread_feed(wasapi_state *state,int force_feed)
|
|||||||
EXIT_ON_ERROR(hr);
|
EXIT_ON_ERROR(hr);
|
||||||
return;
|
return;
|
||||||
exit_label:
|
exit_label:
|
||||||
EnterCriticalSection(&state->print_lock);
|
MP_ERR(state, "thread_feed fails with %"PRIx32"!\n", (uint32_t)hr);
|
||||||
mp_msg(MSGT_AO, MSGL_ERR, "ao-wasapi: thread_feed fails with %"PRIx32"!\n", (uint32_t)hr);
|
|
||||||
LeaveCriticalSection(&state->print_lock);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1124,9 +1094,7 @@ static DWORD __stdcall ThreadLoop(void *lpParameter)
|
|||||||
HANDLE playcontrol[] =
|
HANDLE playcontrol[] =
|
||||||
{state->hUninit, state->hPause, state->hReset, state->hGetvol,
|
{state->hUninit, state->hPause, state->hReset, state->hGetvol,
|
||||||
state->hSetvol, state->hPlay, state->hFeed, NULL};
|
state->hSetvol, state->hPlay, state->hFeed, NULL};
|
||||||
EnterCriticalSection(&state->print_lock);
|
MP_VERBOSE(ao, "Entering dispatch loop!\n");
|
||||||
mp_msg(MSGT_AO, MSGL_V, "ao-wasapi: Entering dispatch loop!\n");
|
|
||||||
LeaveCriticalSection(&state->print_lock);
|
|
||||||
while (1) { /* watch events, poll at least every 2 seconds */
|
while (1) { /* watch events, poll at least every 2 seconds */
|
||||||
waitstatus = WaitForMultipleObjects(7, playcontrol, FALSE, 2000);
|
waitstatus = WaitForMultipleObjects(7, playcontrol, FALSE, 2000);
|
||||||
switch (waitstatus) {
|
switch (waitstatus) {
|
||||||
@ -1216,7 +1184,7 @@ static int setup_buffers(struct wasapi_state *state)
|
|||||||
|
|
||||||
static void uninit(struct ao *ao, bool block)
|
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;
|
struct wasapi_state *state = (struct wasapi_state *)ao->priv;
|
||||||
state->immed = !block;
|
state->immed = !block;
|
||||||
SetEvent(state->hUninit);
|
SetEvent(state->hUninit);
|
||||||
@ -1226,19 +1194,19 @@ static void uninit(struct ao *ao, bool block)
|
|||||||
if (state->VistaBlob.hAvrt)
|
if (state->VistaBlob.hAvrt)
|
||||||
FreeLibrary(state->VistaBlob.hAvrt);
|
FreeLibrary(state->VistaBlob.hAvrt);
|
||||||
closehandles(ao);
|
closehandles(ao);
|
||||||
DeleteCriticalSection(&state->print_lock);
|
MP_VERBOSE(ao, "uninit END!\n");
|
||||||
mp_msg(MSGT_AO, MSGL_V, "ao-wasapi: uninit END!\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int init(struct ao *ao)
|
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);
|
ao->format = af_fmt_from_planar(ao->format);
|
||||||
struct mp_chmap_sel sel = {0};
|
struct mp_chmap_sel sel = {0};
|
||||||
mp_chmap_sel_add_waveext(&sel);
|
mp_chmap_sel_add_waveext(&sel);
|
||||||
if (!ao_chmap_sel_adjust(ao, &sel, &ao->channels))
|
if (!ao_chmap_sel_adjust(ao, &sel, &ao->channels))
|
||||||
return -1;
|
return -1;
|
||||||
struct wasapi_state *state = (struct wasapi_state *)ao->priv;
|
struct wasapi_state *state = (struct wasapi_state *)ao->priv;
|
||||||
|
state->log = ao->log;
|
||||||
fill_VistaBlob(state);
|
fill_VistaBlob(state);
|
||||||
|
|
||||||
if (state->opt_list) {
|
if (state->opt_list) {
|
||||||
@ -1261,7 +1229,6 @@ static int init(struct ao *ao)
|
|||||||
state->hUninit = CreateEventW(NULL, FALSE, FALSE, NULL);
|
state->hUninit = CreateEventW(NULL, FALSE, FALSE, NULL);
|
||||||
state->fatal_error = CreateEventW(NULL, TRUE, FALSE, NULL);
|
state->fatal_error = CreateEventW(NULL, TRUE, FALSE, NULL);
|
||||||
state->hFeed = CreateEvent(NULL, FALSE, FALSE, NULL); /* for wasapi event mode */
|
state->hFeed = CreateEvent(NULL, FALSE, FALSE, NULL); /* for wasapi event mode */
|
||||||
InitializeCriticalSection(&state->print_lock);
|
|
||||||
if (!state->init_done || !state->fatal_error || !state->hPlay ||
|
if (!state->init_done || !state->fatal_error || !state->hPlay ||
|
||||||
!state->hPause || !state->hFeed || !state->hReset || !state->hGetvol ||
|
!state->hPause || !state->hFeed || !state->hReset || !state->hGetvol ||
|
||||||
!state->hSetvol || !state->hDoneVol)
|
!state->hSetvol || !state->hDoneVol)
|
||||||
@ -1274,18 +1241,18 @@ static int init(struct ao *ao)
|
|||||||
state->threadLoop = (HANDLE)CreateThread(NULL, 0, &ThreadLoop, ao, 0, NULL);
|
state->threadLoop = (HANDLE)CreateThread(NULL, 0, &ThreadLoop, ao, 0, NULL);
|
||||||
if (!state->threadLoop) {
|
if (!state->threadLoop) {
|
||||||
/* failed to init thread */
|
/* 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;
|
return -1;
|
||||||
}
|
}
|
||||||
WaitForSingleObject(state->init_done, INFINITE); /* wait on init complete */
|
WaitForSingleObject(state->init_done, INFINITE); /* wait on init complete */
|
||||||
if (state->init_ret) {
|
if (state->init_ret) {
|
||||||
if (!ao->probing) {
|
if (!ao->probing) {
|
||||||
mp_msg(MSGT_AO, MSGL_ERR, "ao-wasapi: thread_init failed!\n");
|
MP_ERR(ao, "thread_init failed!\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mp_msg(MSGT_AO, MSGL_V, "ao-wasapi: Init Done!\n");
|
MP_VERBOSE(ao, "Init Done!\n");
|
||||||
if (setup_buffers(state))
|
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;
|
return state->init_ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user