mirror of https://github.com/mpv-player/mpv
ao_wasapi: move out some utility functions
Note that hresult_to_str() (coming from wasapi_explain_err()) is mostly wasapi-specific, but since HRESULT error codes are unique, it can be extended for any other use.
This commit is contained in:
parent
994459e4ce
commit
31a4547187
|
@ -30,6 +30,7 @@
|
|||
|
||||
#include "common/msg.h"
|
||||
#include "osdep/atomics.h"
|
||||
#include "osdep/windows_utils.h"
|
||||
#include "internal.h"
|
||||
#include "ao.h"
|
||||
|
||||
|
@ -114,13 +115,8 @@ typedef struct wasapi_state {
|
|||
change_notify change;
|
||||
} wasapi_state;
|
||||
|
||||
char *mp_GUID_to_str_buf(char *buf, size_t buf_size, const GUID *guid);
|
||||
char *mp_PKEY_to_str_buf(char *buf, size_t buf_size, const PROPERTYKEY *pkey);
|
||||
char *mp_HRESULT_to_str_buf(char *buf, size_t buf_size, HRESULT hr);
|
||||
#define mp_GUID_to_str(guid) mp_GUID_to_str_buf((char[40]){0}, 40, (guid))
|
||||
#define mp_PKEY_to_str(pkey) mp_PKEY_to_str_buf((char[42]){0}, 42, (pkey))
|
||||
#define mp_HRESULT_to_str(hr) mp_HRESULT_to_str_buf((char[60]){0}, 60, (hr))
|
||||
#define mp_LastError_to_str() mp_HRESULT_to_str(HRESULT_FROM_WIN32(GetLastError()))
|
||||
|
||||
void wasapi_list_devs(struct ao *ao, struct ao_device_list *list);
|
||||
LPWSTR find_deviceID(struct ao *ao);
|
||||
|
|
|
@ -104,18 +104,6 @@ static int special_subtype_to_format(const GUID *subtype) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
char *mp_GUID_to_str_buf(char *buf, size_t buf_size, const GUID *guid)
|
||||
{
|
||||
snprintf(buf, buf_size,
|
||||
"{%8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x}",
|
||||
(unsigned) guid->Data1, guid->Data2, guid->Data3,
|
||||
guid->Data4[0], guid->Data4[1],
|
||||
guid->Data4[2], guid->Data4[3],
|
||||
guid->Data4[4], guid->Data4[5],
|
||||
guid->Data4[6], guid->Data4[7]);
|
||||
return buf;
|
||||
}
|
||||
|
||||
char *mp_PKEY_to_str_buf(char *buf, size_t buf_size, const PROPERTYKEY *pkey)
|
||||
{
|
||||
buf = mp_GUID_to_str_buf(buf, buf_size, &pkey->fmtid);
|
||||
|
@ -125,65 +113,6 @@ char *mp_PKEY_to_str_buf(char *buf, size_t buf_size, const PROPERTYKEY *pkey)
|
|||
return buf;
|
||||
}
|
||||
|
||||
static char *wasapi_explain_err(const HRESULT hr)
|
||||
{
|
||||
#define E(x) case x : return # x ;
|
||||
switch (hr) {
|
||||
E(S_OK)
|
||||
E(S_FALSE)
|
||||
E(E_FAIL)
|
||||
E(E_OUTOFMEMORY)
|
||||
E(E_POINTER)
|
||||
E(E_HANDLE)
|
||||
E(E_NOTIMPL)
|
||||
E(E_INVALIDARG)
|
||||
E(E_PROP_ID_UNSUPPORTED)
|
||||
E(E_NOINTERFACE)
|
||||
E(REGDB_E_IIDNOTREG)
|
||||
E(CO_E_NOTINITIALIZED)
|
||||
E(AUDCLNT_E_NOT_INITIALIZED)
|
||||
E(AUDCLNT_E_ALREADY_INITIALIZED)
|
||||
E(AUDCLNT_E_WRONG_ENDPOINT_TYPE)
|
||||
E(AUDCLNT_E_DEVICE_INVALIDATED)
|
||||
E(AUDCLNT_E_NOT_STOPPED)
|
||||
E(AUDCLNT_E_BUFFER_TOO_LARGE)
|
||||
E(AUDCLNT_E_OUT_OF_ORDER)
|
||||
E(AUDCLNT_E_UNSUPPORTED_FORMAT)
|
||||
E(AUDCLNT_E_INVALID_SIZE)
|
||||
E(AUDCLNT_E_DEVICE_IN_USE)
|
||||
E(AUDCLNT_E_BUFFER_OPERATION_PENDING)
|
||||
E(AUDCLNT_E_THREAD_NOT_REGISTERED)
|
||||
E(AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED)
|
||||
E(AUDCLNT_E_ENDPOINT_CREATE_FAILED)
|
||||
E(AUDCLNT_E_SERVICE_NOT_RUNNING)
|
||||
E(AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED)
|
||||
E(AUDCLNT_E_EXCLUSIVE_MODE_ONLY)
|
||||
E(AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL)
|
||||
E(AUDCLNT_E_EVENTHANDLE_NOT_SET)
|
||||
E(AUDCLNT_E_INCORRECT_BUFFER_SIZE)
|
||||
E(AUDCLNT_E_BUFFER_SIZE_ERROR)
|
||||
E(AUDCLNT_E_CPUUSAGE_EXCEEDED)
|
||||
E(AUDCLNT_E_BUFFER_ERROR)
|
||||
E(AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED)
|
||||
E(AUDCLNT_E_INVALID_DEVICE_PERIOD)
|
||||
E(AUDCLNT_E_INVALID_STREAM_FLAG)
|
||||
E(AUDCLNT_E_ENDPOINT_OFFLOAD_NOT_CAPABLE)
|
||||
E(AUDCLNT_E_RESOURCES_INVALIDATED)
|
||||
E(AUDCLNT_S_BUFFER_EMPTY)
|
||||
E(AUDCLNT_S_THREAD_ALREADY_REGISTERED)
|
||||
E(AUDCLNT_S_POSITION_STALLED)
|
||||
default:
|
||||
return "<Unknown>";
|
||||
}
|
||||
#undef E
|
||||
}
|
||||
|
||||
char *mp_HRESULT_to_str_buf(char *buf, size_t buf_size, HRESULT hr)
|
||||
{
|
||||
snprintf(buf, buf_size, "%s (0x%"PRIx32")",
|
||||
wasapi_explain_err(hr), (uint32_t) hr);
|
||||
return buf;
|
||||
}
|
||||
static void update_waveformat_datarate(WAVEFORMATEXTENSIBLE *wformat)
|
||||
{
|
||||
WAVEFORMATEX *wf = &wformat->Format;
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* This file is part of mpv.
|
||||
*
|
||||
* mpv is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* mpv is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <windows.h>
|
||||
#include <errors.h>
|
||||
#include <audioclient.h>
|
||||
|
||||
#include "windows_utils.h"
|
||||
|
||||
char *mp_GUID_to_str_buf(char *buf, size_t buf_size, const GUID *guid)
|
||||
{
|
||||
snprintf(buf, buf_size,
|
||||
"{%8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x}",
|
||||
(unsigned) guid->Data1, guid->Data2, guid->Data3,
|
||||
guid->Data4[0], guid->Data4[1],
|
||||
guid->Data4[2], guid->Data4[3],
|
||||
guid->Data4[4], guid->Data4[5],
|
||||
guid->Data4[6], guid->Data4[7]);
|
||||
return buf;
|
||||
}
|
||||
|
||||
static char *hresult_to_str(const HRESULT hr)
|
||||
{
|
||||
#define E(x) case x : return # x ;
|
||||
switch (hr) {
|
||||
E(S_OK)
|
||||
E(S_FALSE)
|
||||
E(E_FAIL)
|
||||
E(E_OUTOFMEMORY)
|
||||
E(E_POINTER)
|
||||
E(E_HANDLE)
|
||||
E(E_NOTIMPL)
|
||||
E(E_INVALIDARG)
|
||||
E(E_PROP_ID_UNSUPPORTED)
|
||||
E(E_NOINTERFACE)
|
||||
E(REGDB_E_IIDNOTREG)
|
||||
E(CO_E_NOTINITIALIZED)
|
||||
E(AUDCLNT_E_NOT_INITIALIZED)
|
||||
E(AUDCLNT_E_ALREADY_INITIALIZED)
|
||||
E(AUDCLNT_E_WRONG_ENDPOINT_TYPE)
|
||||
E(AUDCLNT_E_DEVICE_INVALIDATED)
|
||||
E(AUDCLNT_E_NOT_STOPPED)
|
||||
E(AUDCLNT_E_BUFFER_TOO_LARGE)
|
||||
E(AUDCLNT_E_OUT_OF_ORDER)
|
||||
E(AUDCLNT_E_UNSUPPORTED_FORMAT)
|
||||
E(AUDCLNT_E_INVALID_SIZE)
|
||||
E(AUDCLNT_E_DEVICE_IN_USE)
|
||||
E(AUDCLNT_E_BUFFER_OPERATION_PENDING)
|
||||
E(AUDCLNT_E_THREAD_NOT_REGISTERED)
|
||||
E(AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED)
|
||||
E(AUDCLNT_E_ENDPOINT_CREATE_FAILED)
|
||||
E(AUDCLNT_E_SERVICE_NOT_RUNNING)
|
||||
E(AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED)
|
||||
E(AUDCLNT_E_EXCLUSIVE_MODE_ONLY)
|
||||
E(AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL)
|
||||
E(AUDCLNT_E_EVENTHANDLE_NOT_SET)
|
||||
E(AUDCLNT_E_INCORRECT_BUFFER_SIZE)
|
||||
E(AUDCLNT_E_BUFFER_SIZE_ERROR)
|
||||
E(AUDCLNT_E_CPUUSAGE_EXCEEDED)
|
||||
E(AUDCLNT_E_BUFFER_ERROR)
|
||||
E(AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED)
|
||||
E(AUDCLNT_E_INVALID_DEVICE_PERIOD)
|
||||
E(AUDCLNT_E_INVALID_STREAM_FLAG)
|
||||
E(AUDCLNT_E_ENDPOINT_OFFLOAD_NOT_CAPABLE)
|
||||
E(AUDCLNT_E_RESOURCES_INVALIDATED)
|
||||
E(AUDCLNT_S_BUFFER_EMPTY)
|
||||
E(AUDCLNT_S_THREAD_ALREADY_REGISTERED)
|
||||
E(AUDCLNT_S_POSITION_STALLED)
|
||||
default:
|
||||
return "<Unknown>";
|
||||
}
|
||||
#undef E
|
||||
}
|
||||
|
||||
char *mp_HRESULT_to_str_buf(char *buf, size_t buf_size, HRESULT hr)
|
||||
{
|
||||
snprintf(buf, buf_size, "%s (0x%"PRIx32")",
|
||||
hresult_to_str(hr), (uint32_t) hr);
|
||||
return buf;
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* This file is part of mpv.
|
||||
*
|
||||
* mpv is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* mpv is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MP_WINDOWS_UTILS_H_
|
||||
#define MP_WINDOWS_UTILS_H_
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
char *mp_GUID_to_str_buf(char *buf, size_t buf_size, const GUID *guid);
|
||||
#define mp_GUID_to_str(guid) mp_GUID_to_str_buf((char[40]){0}, 40, (guid))
|
||||
char *mp_HRESULT_to_str_buf(char *buf, size_t buf_size, HRESULT hr);
|
||||
#define mp_HRESULT_to_str(hr) mp_HRESULT_to_str_buf((char[60]){0}, 60, (hr))
|
||||
#define mp_LastError_to_str() mp_HRESULT_to_str(HRESULT_FROM_WIN32(GetLastError()))
|
||||
|
||||
#endif
|
|
@ -392,6 +392,7 @@ def build(ctx):
|
|||
( "osdep/glob-win.c", "glob-win32-replacement" ),
|
||||
( "osdep/w32_keyboard.c", "os-win32" ),
|
||||
( "osdep/w32_keyboard.c", "os-cygwin" ),
|
||||
( "osdep/windows_utils.c", "win32" ),
|
||||
( "osdep/mpv.rc", "win32-executable" ),
|
||||
( "osdep/win32/pthread.c", "win32-internal-pthreads"),
|
||||
|
||||
|
|
Loading…
Reference in New Issue