Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
195787d4
Commit
195787d4
authored
Oct 21, 2010
by
Jean-Paul Saman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
audio_output/amem.c: Abstract vlc_sem_* calls into amem_sem_* calls
Abstract vlc_sem_* calls into amem_sem_* calls.
parent
e73d940f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
97 additions
and
44 deletions
+97
-44
include/vlc_threads.h
include/vlc_threads.h
+1
-0
modules/audio_output/amem.c
modules/audio_output/amem.c
+96
-44
No files found.
include/vlc_threads.h
View file @
195787d4
...
...
@@ -123,6 +123,7 @@ typedef sem_t vlc_sem_t;
#elif defined( WIN32 )
#if !defined( UNDER_CE )
typedef
HANDLE
vlc_thread_t
;
typedef
HANDLE
vlc_sem_t
;
#else
typedef
struct
{
...
...
modules/audio_output/amem.c
View file @
195787d4
...
...
@@ -93,10 +93,10 @@ static const int format_int[] = { VLC_CODEC_U8,
/* Shared memory header structure */
typedef
struct
{
vlc_sem_t
sem
;
/* handle to semaphore */
#if defined(_WIN32_WINNT) || defined(WIN32)
WAVEFORMATEX
wave
;
WAVEFORMATEX
wave
;
#else
vlc_sem_t
sem
;
vlc_fourcc_t
i_format
;
unsigned
int
i_rate
;
unsigned
int
i_bytes_per_frame
;
...
...
@@ -116,7 +116,6 @@ typedef struct
/* Private structure */
struct
aout_sys_t
{
char
*
psz_name
;
int
i_delay
;
#if defined(_WIN32_WINNT) || defined(WIN32)
...
...
@@ -126,6 +125,9 @@ struct aout_sys_t
#endif
amem_shared_t
*
header
;
char
*
psz_name
;
bool
b_own_semaphore
;
};
static
int
Open
(
vlc_object_t
*
);
...
...
@@ -138,6 +140,82 @@ static void ExitSharedMem(aout_instance_t *);
/*
* Shared Memory helpers
*/
static
void
amem_sem_init
(
vlc_sem_t
*
sem
,
unsigned
value
)
{
#if defined(_WIN32_WINNT) || defined(WIN32)
sem
=
CreateSemaphore
(
NULL
/*LPSECURITY_ATTRIBUTES*/
,
1
,
1
,
NULL
);
if
(
sem
==
NULL
)
abort
();
#else
if
(
unlikely
(
sem_init
(
sem
,
1
/* share between process*/
,
value
))
==
-
1
)
abort
();
#endif
}
static
int
amem_sem_trywait
(
vlc_sem_t
*
sem
)
{
int
again
=
0
;
do
{
#if defined(_WIN32_WINNT) || defined(WIN32)
DWORD
wait
=
WaitForSingleObject
(
sem
,
0L
);
switch
(
wait
)
{
case
WAIT_OBJECT_0
:
return
VLC_SUCCESS
;
case
WAIT_TIMEOUT
:
again
++
;
break
;
default:
return
VLC_EGENERIC
;
}
#else
if
(
sem_trywait
(
sem
)
==
0
)
break
;
if
(
errno
==
EAGAIN
)
again
++
;
#endif
if
(
again
==
3
)
return
VLC_EGENERIC
;
}
while
(
again
<
3
);
return
VLC_SUCCESS
;
}
static
void
amem_sem_wait
(
vlc_sem_t
*
sem
)
{
#if defined(_WIN32_WINNT) || defined(WIN32)
DWORD
wait
=
WaitForSingleObject
(
sem
,
0L
);
assert
(
wait
==
WAIT_OBJECT_0
);
#else
vlc_sem_wait
(
sem
);
#endif
}
static
void
amem_sem_post
(
vlc_sem_t
*
sem
)
{
#if defined(_WIN32_WINNT) || defined(WIN32)
BOOL
ret
=
ReleaseSemaphore
(
sem
,
1
,
NULL
);
#else
int
ret
=
vlc_sem_post
(
sem
);
#endif
assert
(
ret
>=
0
);
}
static
void
amem_sem_destroy
(
vlc_sem_t
*
sem
)
{
#if defined(_WIN32_WINNT) || defined(WIN32)
BOOL
ret
=
CloseHandle
(
sem
);
assert
(
ret
>=
0
);
#else
vlc_sem_destroy
(
sem
);
#endif
}
#if defined(_WIN32_WINNT) || defined(WIN32)
/* FIXME: not tested yet */
static
int
amem_shmem_create
(
aout_instance_t
*
aout
,
ssize_t
len
)
...
...
@@ -176,6 +254,8 @@ static int amem_shmem_create(aout_instance_t *aout, ssize_t len)
}
sys
->
header
->
samples
=
sys
->
header
+
sizeof
(
amem_shared_t
);
amem_sem_init
(
&
sys
->
header
->
sem
,
1
);
sys
->
b_own_semaphore
=
true
;
return
VLC_SUCCESS
;
}
...
...
@@ -214,8 +294,6 @@ static int amem_shmem_open(aout_instance_t *aout, ssize_t len)
sys
->
header
->
samples
=
sys
->
header
+
sizeof
(
amem_shared_t
);
/* FIXME: initialize semaphore */
return
VLC_SUCCESS
;
}
...
...
@@ -223,7 +301,8 @@ static void amem_shmem_close(aout_instance_t *aout)
{
aout_sys_t
*
sys
=
(
aout_sys_t
*
)
aout
->
output
.
p_sys
;
/* FIXME: release semaphore */
if
(
sys
->
b_own_semaphore
)
amem_sem_destroy
(
&
sys
->
header
->
sem
);
UnmapViewOfFile
(
sys
->
header
);
CloseHandle
(
sys
->
handle
);
...
...
@@ -233,7 +312,7 @@ static void amem_shmem_header(aout_instance_t *aout)
{
aout_sys_t
*
sys
=
(
aout_sys_t
*
)
aout
->
output
.
p_sys
;
vlc
_sem_wait
(
&
sys
->
header
->
sem
);
amem
_sem_wait
(
&
sys
->
header
->
sem
);
/* Fill header struct */
uint16_t
tag
=
0
;
...
...
@@ -255,31 +334,24 @@ static void amem_shmem_header(aout_instance_t *aout)
memset
(
sys
->
header
->
samples
,
0
,
(
aout
->
output
.
i_nb_samples
*
aout
->
output
.
output
.
i_bitspersample
));
if
(
vlc_sem_post
(
&
sys
->
header
->
sem
)
<
0
)
msg_Err
(
aout
,
"failed unlocking semaphore (%m)"
);
amem_sem_post
(
&
sys
->
header
->
sem
);
}
static
void
amem_shmem_write
(
aout_instance_t
*
aout
,
aout_buffer_t
*
data
)
{
aout_sys_t
*
sys
=
(
aout_sys_t
*
)
aout
->
output
.
p_sys
;
/* FIXME: lock Semaphore */
amem_sem_wait
(
&
header
->
sem
);
/* FIXME: Do not assume we can fill entire buffer */
CopyMemory
((
PVOID
)
sys
->
header
->
samples
,
data
->
p_buffer
,
data
->
i_buffer
);
sys
->
header
->
i_nb_samples
=
p_buffer
->
i_buffer
/
(
sys
->
header
->
i_bitspersample
/
8
);
/* FIXME: unlock Semaphore */
amem_sem_post
(
&
header
->
sem
);
}
#else
static
void
amem_sem_init
(
vlc_sem_t
*
sem
,
unsigned
value
)
{
if
(
unlikely
(
sem_init
(
sem
,
1
/* share between process*/
,
value
))
==
-
1
)
abort
();
}
static
int
amem_shmem_create
(
aout_instance_t
*
aout
,
ssize_t
len
)
{
aout_sys_t
*
sys
=
(
aout_sys_t
*
)
aout
->
output
.
p_sys
;
...
...
@@ -310,7 +382,7 @@ static int amem_shmem_create(aout_instance_t *aout, ssize_t len)
/* initialize unamed semaphore */
amem_sem_init
(
&
sys
->
header
->
sem
,
1
);
sys
->
b_own_semaphore
=
true
;
msg_Dbg
(
aout
,
"shared memory created"
);
return
VLC_SUCCESS
;
}
...
...
@@ -351,7 +423,8 @@ static void amem_shmem_close(aout_instance_t *aout)
{
aout_sys_t
*
sys
=
(
aout_sys_t
*
)
aout
->
output
.
p_sys
;
vlc_sem_destroy
(
&
sys
->
header
->
sem
);
if
(
sys
->
b_own_semaphore
)
amem_sem_destroy
(
&
sys
->
header
->
sem
);
/* Determine shared memory size */
if
(
sys
->
header
!=
MAP_FAILED
)
...
...
@@ -375,7 +448,7 @@ static void amem_shmem_header(aout_instance_t *aout)
msg_Dbg
(
aout
,
"syncing shared header"
);
vlc
_sem_wait
(
&
header
->
sem
);
amem
_sem_wait
(
&
header
->
sem
);
/* Fill header struct */
header
->
i_format
=
aout
->
output
.
output
.
i_format
;
...
...
@@ -394,34 +467,14 @@ static void amem_shmem_header(aout_instance_t *aout)
memset
(
header
->
samples
,
0
,
(
aout
->
output
.
i_nb_samples
*
aout
->
output
.
output
.
i_bitspersample
));
if
(
vlc_sem_post
(
&
header
->
sem
)
<
0
)
msg_Err
(
aout
,
"failed unlocking semaphore (%m)"
);
amem_sem_post
(
&
header
->
sem
);
}
static
int
amem_shmem_write
(
aout_instance_t
*
aout
,
aout_buffer_t
*
p_buffer
)
{
aout_sys_t
*
sys
=
(
aout_sys_t
*
)
aout
->
output
.
p_sys
;
#if 0
int again = 0;
do
{
if (sem_trywait(&sys->header->sem) == 0)
break;
if (errno == EAGAIN)
again++;
if (again == 3)
{
msg_Err(aout, "Failed locking semaphore for writing");
return VLC_EGENERIC;
}
} while (again < 3);
#endif
vlc_sem_wait
(
&
sys
->
header
->
sem
);
amem_sem_wait
(
&
sys
->
header
->
sem
);
/* FIXME: do not assume we can fill the entire buffer */
assert
(
p_buffer
->
i_nb_samples
<=
sys
->
header
->
i_max_samples
);
...
...
@@ -430,8 +483,7 @@ static int amem_shmem_write(aout_instance_t *aout, aout_buffer_t *p_buffer)
sys
->
header
->
i_nb_samples
=
p_buffer
->
i_nb_samples
;
sys
->
header
->
i_write_samples
+=
p_buffer
->
i_nb_samples
;
if
(
vlc_sem_post
(
&
sys
->
header
->
sem
)
<
0
)
msg_Err
(
aout
,
"failed unlocking semaphore (%m)"
);
amem_sem_post
(
&
sys
->
header
->
sem
);
return
VLC_SUCCESS
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment