1
0
mirror of https://github.com/mpv-player/mpv synced 2025-02-16 20:27:23 +00:00

ao_wasapi: Use the character set conversion functions from io.h

...rather than rolling out our own. The only possible advantage is that
the "custom" ones didn't use talloc.
This commit is contained in:
Diogo Franco (Kovensky) 2014-03-11 15:50:09 -03:00
parent c5012946ee
commit a0347e0651
2 changed files with 19 additions and 37 deletions

View File

@ -35,6 +35,7 @@
#include "audio/format.h"
#include "compat/atomics.h"
#include "osdep/timer.h"
#include "osdep/io.h"
#define EXIT_ON_ERROR(hres) \
do { if (FAILED(hres)) { goto exit_label; } } while(0)
@ -233,16 +234,6 @@ static int init(struct ao *ao)
return state->init_ret;
}
static wchar_t* utf8_to_wstring(char *string) {
if (string) {
int len = MultiByteToWideChar(CP_UTF8, 0, string, -1, NULL, 0);
wchar_t *ret = malloc(len * sizeof(wchar_t));
MultiByteToWideChar(CP_UTF8, 0, string, -1, ret, len);
return ret;
}
return NULL;
}
static int control(struct ao *ao, enum aocontrol cmd, void *arg)
{
struct wasapi_state *state = (struct wasapi_state *)ao->priv;
@ -297,7 +288,7 @@ static int control(struct ao *ao, enum aocontrol cmd, void *arg)
return CONTROL_OK;
case AOCONTROL_UPDATE_STREAM_TITLE: {
MP_VERBOSE(state, "Updating stream title to \"%s\"\n", (char*)arg);
wchar_t *title = utf8_to_wstring((char*)arg);
wchar_t *title = mp_from_utf8(NULL, (char*)arg);
wchar_t *tmp = NULL;
@ -311,7 +302,7 @@ static int control(struct ao *ao, enum aocontrol cmd, void *arg)
IAudioSessionControl_GetDisplayName(state->pSessionControlProxy, &tmp);
} while (lstrcmpW(title, tmp));
SAFE_RELEASE(tmp, CoTaskMemFree(tmp));
free(title);
talloc_free(title);
return CONTROL_OK;
}

View File

@ -29,6 +29,7 @@
#include "audio/out/ao_wasapi_utils.h"
#include "audio/format.h"
#include "osdep/io.h"
#define MIXER_DEFAULT_LABEL L"mpv - video player"
@ -565,16 +566,6 @@ exit_label:
return 1;
}
static char* wstring_to_utf8(wchar_t *wstring) {
if (wstring) {
int len = WideCharToMultiByte(CP_UTF8, 0, wstring, -1, NULL, 0, NULL, NULL);
char *ret = malloc(len);
WideCharToMultiByte(CP_UTF8, 0, wstring, -1, ret, len, NULL, NULL);
return ret;
}
return NULL;
}
static char* get_device_id(IMMDevice *pDevice) {
if (!pDevice) {
return NULL;
@ -586,11 +577,11 @@ static char* get_device_id(IMMDevice *pDevice) {
HRESULT hr = IMMDevice_GetId(pDevice, &devid);
EXIT_ON_ERROR(hr);
idstr = wstring_to_utf8(devid);
idstr = mp_to_utf8(NULL, devid);
if (strstr(idstr, "{0.0.0.00000000}.")) {
char *stripped = strdup(idstr + strlen("{0.0.0.00000000}."));
free(idstr);
char *stripped = talloc_strdup(NULL, idstr + strlen("{0.0.0.00000000}."));
talloc_free(idstr);
idstr = stripped;
}
@ -616,7 +607,7 @@ static char* get_device_name(IMMDevice *pDevice) {
hr = IPropertyStore_GetValue(pProps, &PKEY_Device_FriendlyName, &devname);
EXIT_ON_ERROR(hr);
namestr = wstring_to_utf8(devname.pwszVal);
namestr = mp_to_utf8(NULL, devname.pwszVal);
exit_label:
PropVariantClear(&devname);
@ -641,7 +632,7 @@ static char* get_device_desc(IMMDevice *pDevice) {
hr = IPropertyStore_GetValue(pProps, &PKEY_Device_DeviceDesc, &devdesc);
EXIT_ON_ERROR(hr);
desc = wstring_to_utf8(devdesc.pwszVal);
desc = mp_to_utf8(NULL, devdesc.pwszVal);
exit_label:
PropVariantClear(&devdesc);
@ -665,7 +656,7 @@ static int device_id_match(char *idstr, char *candidate) {
}
#undef FOUND
end:
free(idstr);
talloc_free(idstr);
return found;
}
@ -718,17 +709,17 @@ static HRESULT enumerate_with_state(struct mp_log *log, char *header,
mp_info(log, "%s, ID: %s%s\n", name, id, mark);
}
free(name);
free(id);
talloc_free(name);
talloc_free(id);
SAFE_RELEASE(pDevice, IMMDevice_Release(pDevice));
}
free(defid);
talloc_free(defid);
SAFE_RELEASE(pDevices, IMMDeviceCollection_Release(pDevices));
SAFE_RELEASE(pEnumerator, IMMDeviceEnumerator_Release(pEnumerator));
return hr;
exit_label:
free(defid);
talloc_free(defid);
SAFE_RELEASE(pDevice, IMMDevice_Release(pDevice));
SAFE_RELEASE(pDevices, IMMDeviceCollection_Release(pDevices));
SAFE_RELEASE(pEnumerator, IMMDeviceEnumerator_Release(pEnumerator));
@ -826,17 +817,17 @@ static HRESULT find_and_load_device(struct ao *ao, IMMDevice **ppDevice,
MP_ERR(ao, "multiple matching devices found!\n");
name = get_device_name(prevDevice);
MP_ERR(ao, "%s\n", name);
free(name);
talloc_free(name);
search_err = 1;
}
name = get_device_name(pTempDevice);
MP_ERR(ao, "%s\n", name);
free(name);
talloc_free(name);
}
hr = IMMDevice_GetId(pTempDevice, &deviceID);
prevDevice = pTempDevice;
}
free(desc);
talloc_free(desc);
SAFE_RELEASE(pTempDevice, IMMDevice_Release(pTempDevice));
}
@ -963,7 +954,7 @@ int wasapi_thread_init(struct ao *ao)
char *id = get_device_id(state->pDevice);
MP_VERBOSE(ao, "default device ID: %s\n", id);
free(id);
talloc_free(id);
} else {
hr = find_and_load_device(ao, &state->pDevice, state->opt_device);
}
@ -971,7 +962,7 @@ int wasapi_thread_init(struct ao *ao)
char *name = get_device_name(state->pDevice);
MP_VERBOSE(ao, "device loaded: %s\n", name);
free(name);
talloc_free(name);
hr = IMMDeviceActivator_Activate(state->pDevice, &IID_IAudioClient,
CLSCTX_ALL, NULL, (void **)&state->pAudioClient);