1
0
mirror of https://github.com/mpv-player/mpv synced 2025-04-11 04:01:31 +00:00

ao_dsound: uncrustify

This commit is contained in:
wm4 2013-06-04 00:51:07 +02:00
parent 92ae48db0f
commit cee56e8623

View File

@ -62,7 +62,9 @@ LIBAO_EXTERN(dsound)
#define WAVE_FORMAT_DOLBY_AC3_SPDIF 0x0092
#define WAVE_FORMAT_EXTENSIBLE 0xFFFE
static const GUID KSDATAFORMAT_SUBTYPE_PCM = {0x1,0x0000,0x0010, {0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71}};
static const GUID KSDATAFORMAT_SUBTYPE_PCM = {
0x1, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
};
#if 0
#define DSSPEAKER_HEADPHONE 0x00000001
@ -131,8 +133,8 @@ static char * dserr2str(int err)
case DSERR_UNINITIALIZED: return "DSERR_UNINITIALIZED";
case DSERR_NOINTERFACE: return "DSERR_NOINTERFACE";
case DSERR_ACCESSDENIED: return "DSERR_ACCESSDENIED";
default: return "unknown";
}
return "unknown";
}
/**
@ -172,16 +174,16 @@ static void print_help(void)
\brief enumerate direct sound devices
\return TRUE to continue with the enumeration
*/
static BOOL CALLBACK DirectSoundEnum(LPGUID guid,LPCSTR desc,LPCSTR module,LPVOID context)
static BOOL CALLBACK DirectSoundEnum(LPGUID guid, LPCSTR desc, LPCSTR module,
LPVOID context)
{
int *device_index = context;
mp_msg(MSGT_AO, MSGL_V, "%i %s ", *device_index, desc);
if (device_num == *device_index) {
mp_msg(MSGT_AO, MSGL_V, "<--");
if(guid){
if (guid)
memcpy(&device, guid, sizeof(GUID));
}
}
mp_msg(MSGT_AO, MSGL_V, "\n");
(*device_index)++;
return TRUE;
@ -214,8 +216,10 @@ static int InitDirectSound(void)
mp_msg(MSGT_AO, MSGL_ERR, "ao_dsound: cannot load DSOUND.DLL\n");
return 0;
}
OurDirectSoundCreate = (void*)GetProcAddress(hdsound_dll, "DirectSoundCreate");
OurDirectSoundEnumerate = (void*)GetProcAddress(hdsound_dll, "DirectSoundEnumerateA");
OurDirectSoundCreate = (void *)GetProcAddress(hdsound_dll,
"DirectSoundCreate");
OurDirectSoundEnumerate = (void *)GetProcAddress(hdsound_dll,
"DirectSoundEnumerateA");
if (OurDirectSoundCreate == NULL || OurDirectSoundEnumerate == NULL) {
mp_msg(MSGT_AO, MSGL_ERR, "ao_dsound: GetProcAddress FAILED\n");
@ -228,8 +232,11 @@ static int InitDirectSound(void)
OurDirectSoundEnumerate(DirectSoundEnum, &device_index);
// Create the direct sound object
if FAILED(OurDirectSoundCreate((device_num)?&device:NULL, &hds, NULL )) {
mp_msg(MSGT_AO, MSGL_ERR, "ao_dsound: cannot create a DirectSound device\n");
if (FAILED(OurDirectSoundCreate((device_num) ? &device : NULL, &hds,
NULL)))
{
mp_msg(MSGT_AO, MSGL_ERR,
"ao_dsound: cannot create a DirectSound device\n");
FreeLibrary(hdsound_dll);
return 0;
}
@ -244,8 +251,11 @@ static int InitDirectSound(void)
* sound without any video, and so what window handle should we use ???
* The hack for now is to use the Desktop window handle - it seems to be
* working */
if (IDirectSound_SetCooperativeLevel(hds, GetDesktopWindow(), DSSCL_EXCLUSIVE)) {
mp_msg(MSGT_AO, MSGL_ERR, "ao_dsound: cannot set direct sound cooperative level\n");
if (IDirectSound_SetCooperativeLevel(hds, GetDesktopWindow(),
DSSCL_EXCLUSIVE))
{
mp_msg(MSGT_AO, MSGL_ERR,
"ao_dsound: cannot set direct sound cooperative level\n");
IDirectSound_Release(hds);
FreeLibrary(hdsound_dll);
return 0;
@ -255,7 +265,9 @@ static int InitDirectSound(void)
memset(&dscaps, 0, sizeof(DSCAPS));
dscaps.dwSize = sizeof(DSCAPS);
if (DS_OK == IDirectSound_GetCaps(hds, &dscaps)) {
if (dscaps.dwFlags & DSCAPS_EMULDRIVER) mp_msg(MSGT_AO, MSGL_V, "ao_dsound: DirectSound is emulated, waveOut may give better performance\n");
if (dscaps.dwFlags & DSCAPS_EMULDRIVER)
mp_msg(MSGT_AO, MSGL_V,
"ao_dsound: DirectSound is emulated, waveOut may give better performance\n");
} else {
mp_msg(MSGT_AO, MSGL_V, "ao_dsound: cannot get device capabilities\n");
}
@ -295,17 +307,17 @@ static int write_buffer(unsigned char *data, int len)
underrun_check = 0;
// Lock the buffer
res = IDirectSoundBuffer_Lock(hdsbuf,write_offset, len, &lpvPtr1, &dwBytes1, &lpvPtr2, &dwBytes2, 0);
res = IDirectSoundBuffer_Lock(hdsbuf, write_offset, len, &lpvPtr1, &dwBytes1,
&lpvPtr2, &dwBytes2, 0);
// If the buffer was lost, restore and retry lock.
if (DSERR_BUFFERLOST == res)
{
if (DSERR_BUFFERLOST == res) {
IDirectSoundBuffer_Restore(hdsbuf);
res = IDirectSoundBuffer_Lock(hdsbuf,write_offset, len, &lpvPtr1, &dwBytes1, &lpvPtr2, &dwBytes2, 0);
res = IDirectSoundBuffer_Lock(hdsbuf, write_offset, len, &lpvPtr1,
&dwBytes1, &lpvPtr2, &dwBytes2, 0);
}
if (SUCCEEDED(res))
{
if (SUCCEEDED(res)) {
if (!AF_FORMAT_IS_AC3(ao_data.format)) {
memcpy(lpvPtr1, data, dwBytes1);
if (lpvPtr2 != NULL)
@ -317,21 +329,22 @@ static int write_buffer(unsigned char *data, int len)
} else {
// Write to pointers without reordering.
memcpy(lpvPtr1, data, dwBytes1);
if (NULL != lpvPtr2 )memcpy(lpvPtr2,data+dwBytes1,dwBytes2);
if (NULL != lpvPtr2)
memcpy(lpvPtr2, data + dwBytes1, dwBytes2);
write_offset += dwBytes1 + dwBytes2;
if(write_offset>=buffer_size)write_offset=dwBytes2;
if (write_offset >= buffer_size)
write_offset = dwBytes2;
}
// Release the data back to DirectSound.
res = IDirectSoundBuffer_Unlock(hdsbuf,lpvPtr1,dwBytes1,lpvPtr2,dwBytes2);
if (SUCCEEDED(res))
{
res = IDirectSoundBuffer_Unlock(hdsbuf, lpvPtr1, dwBytes1, lpvPtr2,
dwBytes2);
if (SUCCEEDED(res)) {
// Success.
DWORD status;
IDirectSoundBuffer_GetStatus(hdsbuf, &status);
if (!(status & DSBSTATUS_PLAYING)){
if (!(status & DSBSTATUS_PLAYING))
res = IDirectSoundBuffer_Play(hdsbuf, 0, 0, DSBPLAY_LOOPING);
}
return dwBytes1 + dwBytes2;
}
}
@ -380,7 +393,8 @@ static int control(int cmd, void *arg)
static int init(int rate, const struct mp_chmap *channels, int format, int flags)
{
int res;
if (!InitDirectSound()) return 0;
if (!InitDirectSound())
return 0;
global_ao->no_persistent_volume = true;
audio_volume = 100;
@ -390,10 +404,12 @@ static int init(int rate, const struct mp_chmap *channels, int format, int flags
DSBUFFERDESC dsbpridesc;
DSBUFFERDESC dsbdesc;
if (AF_FORMAT_IS_AC3(format)) {
if (AF_FORMAT_IS_AC3(format))
format = AF_FORMAT_AC3_NE;
} else {
struct mp_chmap_sel sel = {0};
else {
struct mp_chmap_sel sel = {
0
};
mp_chmap_sel_add_waveext(&sel);
if (!ao_chmap_sel_adjust(&ao_data, &sel, &ao_data.channels))
return 0;
@ -405,20 +421,27 @@ static int init(int rate, const struct mp_chmap *channels, int format, int flags
case AF_FORMAT_U8:
break;
default:
mp_msg(MSGT_AO, MSGL_V,"ao_dsound: format %s not supported defaulting to Signed 16-bit Little-Endian\n",af_fmt2str_short(format));
mp_msg(MSGT_AO, MSGL_V,
"ao_dsound: format %s not supported defaulting to Signed 16-bit Little-Endian\n",
af_fmt2str_short(format));
format = AF_FORMAT_S16_LE;
}
//fill global ao_data
ao_data.samplerate = rate;
ao_data.format = format;
ao_data.bps = ao_data.channels.num * rate * (af_fmt2bits(format) >> 3);
if(ao_data.buffersize==-1) ao_data.buffersize = ao_data.bps; // space for 1 sec
mp_msg(MSGT_AO, MSGL_V,"ao_dsound: Samplerate:%iHz Channels:%i Format:%s\n", rate, ao_data.channels.num, af_fmt2str_short(format));
mp_msg(MSGT_AO, MSGL_V,"ao_dsound: Buffersize:%d bytes (%d msec)\n", ao_data.buffersize, ao_data.buffersize / ao_data.bps * 1000);
if (ao_data.buffersize == -1)
ao_data.buffersize = ao_data.bps; // space for 1 sec
mp_msg(MSGT_AO, MSGL_V,
"ao_dsound: Samplerate:%iHz Channels:%i Format:%s\n", rate,
ao_data.channels.num, af_fmt2str_short(format));
mp_msg(MSGT_AO, MSGL_V, "ao_dsound: Buffersize:%d bytes (%d msec)\n",
ao_data.buffersize, ao_data.buffersize / ao_data.bps * 1000);
//fill waveformatex
ZeroMemory(&wformat, sizeof(WAVEFORMATEXTENSIBLE));
wformat.Format.cbSize = (ao_data.channels.num > 2) ? sizeof(WAVEFORMATEXTENSIBLE)-sizeof(WAVEFORMATEX) : 0;
wformat.Format.cbSize = (ao_data.channels.num > 2)
? sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX) : 0;
wformat.Format.nChannels = ao_data.channels.num;
wformat.Format.nSamplesPerSec = rate;
if (AF_FORMAT_IS_AC3(format)) {
@ -426,9 +449,11 @@ static int init(int rate, const struct mp_chmap *channels, int format, int flags
wformat.Format.wBitsPerSample = 16;
wformat.Format.nBlockAlign = 4;
} else {
wformat.Format.wFormatTag = (ao_data.channels.num > 2) ? WAVE_FORMAT_EXTENSIBLE : WAVE_FORMAT_PCM;
wformat.Format.wFormatTag = (ao_data.channels.num > 2)
? WAVE_FORMAT_EXTENSIBLE : WAVE_FORMAT_PCM;
wformat.Format.wBitsPerSample = af_fmt2bits(format);
wformat.Format.nBlockAlign = wformat.Format.nChannels * (wformat.Format.wBitsPerSample >> 3);
wformat.Format.nBlockAlign = wformat.Format.nChannels *
(wformat.Format.wBitsPerSample >> 3);
}
// fill in primary sound buffer descriptor
@ -438,7 +463,6 @@ static int init(int rate, const struct mp_chmap *channels, int format, int flags
dsbpridesc.dwBufferBytes = 0;
dsbpridesc.lpwfxFormat = NULL;
// fill in the secondary sound buffer (=stream buffer) descriptor
memset(&dsbdesc, 0, sizeof(DSBUFFERDESC));
dsbdesc.dwSize = sizeof(DSBUFFERDESC);
@ -453,7 +477,8 @@ static int init(int rate, const struct mp_chmap *channels, int format, int flags
// Needed for 5.1 on emu101k - shit soundblaster
dsbdesc.dwFlags |= DSBCAPS_LOCHARDWARE;
}
wformat.Format.nAvgBytesPerSec = wformat.Format.nSamplesPerSec * wformat.Format.nBlockAlign;
wformat.Format.nAvgBytesPerSec = wformat.Format.nSamplesPerSec *
wformat.Format.nBlockAlign;
dsbdesc.dwBufferBytes = ao_data.buffersize;
dsbdesc.lpwfxFormat = (WAVEFORMATEX *)&wformat;
@ -467,11 +492,17 @@ static int init(int rate, const struct mp_chmap *channels, int format, int flags
res = IDirectSound_CreateSoundBuffer(hds, &dsbpridesc, &hdspribuf, NULL);
if (res != DS_OK) {
UninitDirectSound();
mp_msg(MSGT_AO, MSGL_ERR,"ao_dsound: cannot create primary buffer (%s)\n", dserr2str(res));
mp_msg(MSGT_AO, MSGL_ERR,
"ao_dsound: cannot create primary buffer (%s)\n",
dserr2str(res));
return 0;
}
res = IDirectSoundBuffer_SetFormat(hdspribuf, (WAVEFORMATEX *)&wformat);
if ( res != DS_OK ) mp_msg(MSGT_AO, MSGL_WARN,"ao_dsound: cannot set primary buffer format (%s), using standard setting (bad quality)", dserr2str(res));
if (res != DS_OK) {
mp_msg(MSGT_AO, MSGL_WARN,
"ao_dsound: cannot set primary buffer format (%s), using "
"standard setting (bad quality)", dserr2str(res));
}
mp_msg(MSGT_AO, MSGL_V, "ao_dsound: primary buffer created\n");
@ -486,7 +517,9 @@ static int init(int rate, const struct mp_chmap *channels, int format, int flags
}
if (res != DS_OK) {
UninitDirectSound();
mp_msg(MSGT_AO, MSGL_ERR, "ao_dsound: cannot create secondary (stream)buffer (%s)\n", dserr2str(res));
mp_msg(MSGT_AO, MSGL_ERR,
"ao_dsound: cannot create secondary (stream)buffer (%s)\n",
dserr2str(res));
return 0;
}
}
@ -550,7 +583,8 @@ static int check_free_buffer_size(void)
// play_cursor is the actual postion of the play cursor
// write_cursor is the position after which it is assumed to be save to write data
// write_offset is the postion where we actually write the data to
if(space > buffer_size)space -= buffer_size; // write_offset < play_offset
if (space > buffer_size)
space -= buffer_size; // write_offset < play_offset
// Check for buffer underruns. An underrun happens if DirectSound
// started to play old data beyond the current write_offset. Detect this
// by checking whether the free space shrinks, even though no data was
@ -573,7 +607,8 @@ static int check_free_buffer_size(void)
static int get_space(void)
{
int space = check_free_buffer_size();
if(space < min_free_space)return 0;
if (space < min_free_space)
return 0;
return space - min_free_space;
}
@ -587,7 +622,8 @@ static int get_space(void)
static int play(void *data, int len, int flags)
{
int space = check_free_buffer_size();
if(space < len) len = space;
if (space < len)
len = space;
if (!(flags & AOPLAY_FINAL_CHUNK))
len = (len / ao_data.outburst) * ao_data.outburst;