Commit 66fa9a78 authored by Jean-Paul Saman's avatar Jean-Paul Saman

audio_output/amem.c: windows build fixes

Various windows build fixes:
- define NAME_MAX 255
- use audio_format_t structure from aout_instance_t
- memcpy string into szName[NAME_MAX]
- amem_sem_init(): use value variable in function CreateSemaphore()
- GetLastError() provides DWORD, so use %ld in msg_Err()
- amem_sem_wait(): use INFINITE iso 0L
- remove '#include "windows_audio_common.h"'
parent 5afe1fdc
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
# include <conio.h> # include <conio.h>
# include <tchar.h> # include <tchar.h>
//# include "windows_audio_common.h" # define NAME_MAX 255
#else #else
# include <limits.h> # include <limits.h>
# include <errno.h> # include <errno.h>
...@@ -152,7 +152,7 @@ static void ExitSharedMem(aout_instance_t *); ...@@ -152,7 +152,7 @@ static void ExitSharedMem(aout_instance_t *);
static void amem_sem_init(vlc_sem_t *sem, unsigned value) static void amem_sem_init(vlc_sem_t *sem, unsigned value)
{ {
#if defined(_WIN32_WINNT) || defined(WIN32) #if defined(_WIN32_WINNT) || defined(WIN32)
sem = (vlc_sem_t *) CreateSemaphore(NULL /*LPSECURITY_ATTRIBUTES*/, 1, 1, NULL); sem = (vlc_sem_t *) CreateSemaphore(NULL /*LPSECURITY_ATTRIBUTES*/, 1, value, NULL);
if (sem == NULL) if (sem == NULL)
abort(); abort();
#else #else
...@@ -197,7 +197,7 @@ static int amem_sem_trywait(vlc_sem_t *sem) ...@@ -197,7 +197,7 @@ static int amem_sem_trywait(vlc_sem_t *sem)
static void amem_sem_wait(vlc_sem_t *sem) static void amem_sem_wait(vlc_sem_t *sem)
{ {
#if defined(_WIN32_WINNT) || defined(WIN32) #if defined(_WIN32_WINNT) || defined(WIN32)
DWORD wait = WaitForSingleObject((HANDLE) *sem, 0L); DWORD wait = WaitForSingleObject((HANDLE) *sem, INFINTE);
assert(wait == WAIT_OBJECT_0); assert(wait == WAIT_OBJECT_0);
#else #else
vlc_sem_wait(sem); vlc_sem_wait(sem);
...@@ -240,7 +240,15 @@ static int amem_shmem_open(aout_instance_t *aout, unsigned int i_buffers, ssize_ ...@@ -240,7 +240,15 @@ static int amem_shmem_open(aout_instance_t *aout, unsigned int i_buffers, ssize_
aout_sys_t *sys = (aout_sys_t *)aout->output.p_sys; aout_sys_t *sys = (aout_sys_t *)aout->output.p_sys;
#if defined(_WIN32_WINNT) || defined(WIN32) #if defined(_WIN32_WINNT) || defined(WIN32)
TCHAR szName[]=TEXT(sys->psz_name); TCHAR szName[NAME_MAX];
size_t nameLen = strlen(sys->psz_name);
if (nameLen > NAME_MAX)
nameLen = NAME_MAX - 1;
if (nameLen == 0)
return VLC_EGENERIC;
memcpy(&szName, TEXT(sys->psz_name), nameLen);
szName[NAME_MAX - 1] = '\0';
if (b_create) if (b_create)
{ {
...@@ -259,7 +267,7 @@ static int amem_shmem_open(aout_instance_t *aout, unsigned int i_buffers, ssize_ ...@@ -259,7 +267,7 @@ static int amem_shmem_open(aout_instance_t *aout, unsigned int i_buffers, ssize_
if (sys->handle == NULL) if (sys->handle == NULL)
{ {
msg_Err(aout, "could not %s file mapping object (%d).", msg_Err(aout, "could not %s file mapping object (%ld).",
b_create ? "create": "open", GetLastError()); b_create ? "create": "open", GetLastError());
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -268,7 +276,7 @@ static int amem_shmem_open(aout_instance_t *aout, unsigned int i_buffers, ssize_ ...@@ -268,7 +276,7 @@ static int amem_shmem_open(aout_instance_t *aout, unsigned int i_buffers, ssize_
FILE_MAP_ALL_ACCESS, 0, 0, len); FILE_MAP_ALL_ACCESS, 0, 0, len);
if (sys->header == NULL) if (sys->header == NULL)
{ {
msg_Err(aout, "could not map view of file (%d).", GetLastError()); msg_Err(aout, "could not map view of file (%ld).", GetLastError());
CloseHandle(sys->handle); CloseHandle(sys->handle);
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -299,8 +307,11 @@ static int amem_shmem_open(aout_instance_t *aout, unsigned int i_buffers, ssize_ ...@@ -299,8 +307,11 @@ static int amem_shmem_open(aout_instance_t *aout, unsigned int i_buffers, ssize_
msg_Err(aout, "could not mmap shared memory object (%m)"); msg_Err(aout, "could not mmap shared memory object (%m)");
return VLC_EGENERIC; return VLC_EGENERIC;
} }
#endif #endif
size_t buflen = (aout->output.i_nb_samples * aout->output.output.i_bitspersample);
/* setup pointers in shared structures */ /* setup pointers in shared structures */
sys->header->i_buffers = i_buffers; sys->header->i_buffers = i_buffers;
for (unsigned int i = 0; i < sys->header->i_buffers; i++) for (unsigned int i = 0; i < sys->header->i_buffers; i++)
...@@ -310,7 +321,7 @@ static int amem_shmem_open(aout_instance_t *aout, unsigned int i_buffers, ssize_ ...@@ -310,7 +321,7 @@ static int amem_shmem_open(aout_instance_t *aout, unsigned int i_buffers, ssize_
{ {
buffer->i_nb_samples = 0; buffer->i_nb_samples = 0;
if (b_create) if (b_create)
memset(buffer->samples, 0, (sys->header->i_max_samples * sys->header->i_bitspersample)); memset(buffer->samples, 0, buflen);
} }
} }
...@@ -368,8 +379,8 @@ static void amem_shmem_header(aout_instance_t *aout) ...@@ -368,8 +379,8 @@ static void amem_shmem_header(aout_instance_t *aout)
fourcc_to_wf_tag(aout->output.output.i_format, &tag); fourcc_to_wf_tag(aout->output.output.i_format, &tag);
header->wave.wFormatTag = tag; header->wave.wFormatTag = tag;
header->wave.nChannels = aout->output.output.i_channels; header->wave.nChannels = aout->output.output.i_channels;
header->wave.nSamplesPerSec = header->i_rate * header->i_max_samples; header->wave.nSamplesPerSec = aout->output.output.i_rate * aout->output.i_nb_samples;
header->wave.wBitsPerSample = header->i_bitspersample; header->wave.wBitsPerSample = aout->output.output.i_bitspersample;
header->wave.nBlockAlign = header->wave.wBitsPerSample / 8 * header->wave.nChannels; header->wave.nBlockAlign = header->wave.wBitsPerSample / 8 * header->wave.nChannels;
header->wave.nAvgBytesPerSec = header->wave.nSamplesPerSec * header->wave.nBlockAlign; header->wave.nAvgBytesPerSec = header->wave.nSamplesPerSec * header->wave.nBlockAlign;
header->wave.cbSize = 0; /* No additional format metadata */ header->wave.cbSize = 0; /* No additional format metadata */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment