Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-2-2
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-2-2
Commits
4b8038be
Commit
4b8038be
authored
Dec 12, 2009
by
Laurent Aimar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplified projectm module by using vlc_thread_t.
parent
f53f829a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
112 additions
and
120 deletions
+112
-120
modules/visualization/projectm.cpp
modules/visualization/projectm.cpp
+112
-120
No files found.
modules/visualization/projectm.cpp
View file @
4b8038be
...
@@ -70,12 +70,12 @@ vlc_module_end ()
...
@@ -70,12 +70,12 @@ vlc_module_end ()
/*****************************************************************************
/*****************************************************************************
* Local prototypes
* Local prototypes
*****************************************************************************/
*****************************************************************************/
typedef
struc
t
struct
filter_sys_
t
{
{
VLC_COMMON_MEMBERS
/* */
/* */
vlc_sem_t
ready
;
vlc_thread_t
thread
;
vlc_sem_t
ready
;
bool
b_error
;
/* video output module and opengl provider */
/* video output module and opengl provider */
vout_thread_t
*
p_opengl
;
vout_thread_t
*
p_opengl
;
...
@@ -91,22 +91,16 @@ typedef struct
...
@@ -91,22 +91,16 @@ typedef struct
/* audio info */
/* audio info */
int
i_channels
;
int
i_channels
;
vlc_mutex_t
lock
;
float
*
p_buffer
;
float
*
p_buffer
;
int
i_buffer_size
;
int
i_buffer_size
;
int
i_nb_samples
;
int
i_nb_samples
;
vlc_mutex_t
lock
;
}
projectm_thread_t
;
struct
filter_sys_t
{
projectm_thread_t
*
p_thread
;
};
};
static
block_t
*
DoWork
(
filter_t
*
,
block_t
*
);
static
block_t
*
DoWork
(
filter_t
*
,
block_t
*
);
static
void
*
Thread
(
vlc_object_t
*
);
static
void
*
Thread
(
void
*
);
/**
/**
...
@@ -114,38 +108,40 @@ static void* Thread( vlc_object_t * );
...
@@ -114,38 +108,40 @@ static void* Thread( vlc_object_t * );
* p_thread: projectm thread object
* p_thread: projectm thread object
* @return VLC_SUCCESS or vlc error codes
* @return VLC_SUCCESS or vlc error codes
*/
*/
static
int
initOpenGL
(
projectm_thread_t
*
p_thread
)
static
int
initOpenGL
(
filter_t
*
p_filter
)
{
{
p_thread
->
p_opengl
=
(
vout_thread_t
*
)
vlc_object_create
(
p_thread
,
filter_sys_t
*
p_sys
=
p_filter
->
p_sys
;
sizeof
(
vout_thread_t
)
);
if
(
!
p_thread
->
p_opengl
)
p_sys
->
p_opengl
=
(
vout_thread_t
*
)
vlc_object_create
(
p_filter
,
sizeof
(
vout_thread_t
)
);
if
(
!
p_sys
->
p_opengl
)
return
VLC_ENOMEM
;
return
VLC_ENOMEM
;
vlc_object_attach
(
p_
thread
->
p_opengl
,
p_thread
);
vlc_object_attach
(
p_
sys
->
p_opengl
,
p_filter
);
/* Initialize the opengl object */
/* Initialize the opengl object */
video_format_Setup
(
&
p_
thread
->
p_opengl
->
fmt_in
,
VLC_CODEC_RGB32
,
video_format_Setup
(
&
p_
sys
->
p_opengl
->
fmt_in
,
VLC_CODEC_RGB32
,
p_
thread
->
i_width
,
p_thread
->
i_height
,
1
);
p_
sys
->
i_width
,
p_sys
->
i_height
,
1
);
p_
thread
->
p_opengl
->
i_window_width
=
p_thread
->
i_width
;
p_
sys
->
p_opengl
->
i_window_width
=
p_sys
->
i_width
;
p_
thread
->
p_opengl
->
i_window_height
=
p_thread
->
i_height
;
p_
sys
->
p_opengl
->
i_window_height
=
p_sys
->
i_height
;
p_
thread
->
p_opengl
->
render
.
i_width
=
p_thread
->
i_width
;
p_
sys
->
p_opengl
->
render
.
i_width
=
p_sys
->
i_width
;
p_
thread
->
p_opengl
->
render
.
i_height
=
p_thread
->
i_height
;
p_
sys
->
p_opengl
->
render
.
i_height
=
p_sys
->
i_height
;
p_
thread
->
p_opengl
->
render
.
i_aspect
=
VOUT_ASPECT_FACTOR
;
p_
sys
->
p_opengl
->
render
.
i_aspect
=
VOUT_ASPECT_FACTOR
;
p_
thread
->
p_opengl
->
b_fullscreen
=
false
;
p_
sys
->
p_opengl
->
b_fullscreen
=
false
;
p_
thread
->
p_opengl
->
b_autoscale
=
true
;
p_
sys
->
p_opengl
->
b_autoscale
=
true
;
p_
thread
->
p_opengl
->
i_alignment
=
0
;
p_
sys
->
p_opengl
->
i_alignment
=
0
;
p_
thread
->
p_opengl
->
fmt_in
.
i_sar_num
=
1
;
p_
sys
->
p_opengl
->
fmt_in
.
i_sar_num
=
1
;
p_
thread
->
p_opengl
->
fmt_in
.
i_sar_den
=
1
;
p_
sys
->
p_opengl
->
fmt_in
.
i_sar_den
=
1
;
p_
thread
->
p_opengl
->
fmt_render
=
p_thread
->
p_opengl
->
fmt_in
;
p_
sys
->
p_opengl
->
fmt_render
=
p_sys
->
p_opengl
->
fmt_in
;
/* Ask for the opengl provider */
/* Ask for the opengl provider */
p_
thread
->
p_module
=
module_need
(
p_thread
->
p_opengl
,
"opengl provider"
,
p_
sys
->
p_module
=
module_need
(
p_sys
->
p_opengl
,
"opengl provider"
,
NULL
,
false
);
NULL
,
false
);
if
(
!
p_
thread
->
p_module
)
if
(
!
p_
sys
->
p_module
)
{
{
msg_Err
(
p_
thread
,
"unable to initialize OpenGL"
);
msg_Err
(
p_
filter
,
"unable to initialize OpenGL"
);
vlc_object_detach
(
p_
thread
->
p_opengl
);
vlc_object_detach
(
p_
sys
->
p_opengl
);
vlc_object_release
(
p_
thread
->
p_opengl
);
vlc_object_release
(
p_
sys
->
p_opengl
);
return
VLC_EGENERIC
;
return
VLC_EGENERIC
;
}
}
...
@@ -160,9 +156,8 @@ static int initOpenGL( projectm_thread_t *p_thread )
...
@@ -160,9 +156,8 @@ static int initOpenGL( projectm_thread_t *p_thread )
*/
*/
static
int
Open
(
vlc_object_t
*
p_this
)
static
int
Open
(
vlc_object_t
*
p_this
)
{
{
filter_t
*
p_filter
=
(
filter_t
*
)
p_this
;
filter_t
*
p_filter
=
(
filter_t
*
)
p_this
;
filter_sys_t
*
p_sys
;
filter_sys_t
*
p_sys
;
projectm_thread_t
*
p_thread
;
/* Test the audio format */
/* Test the audio format */
if
(
p_filter
->
fmt_in
.
audio
.
i_format
!=
VLC_CODEC_FL32
||
if
(
p_filter
->
fmt_in
.
audio
.
i_format
!=
VLC_CODEC_FL32
||
...
@@ -184,37 +179,32 @@ static int Open( vlc_object_t * p_this )
...
@@ -184,37 +179,32 @@ static int Open( vlc_object_t * p_this )
return
VLC_ENOMEM
;
return
VLC_ENOMEM
;
/* Create the object for the thread */
/* Create the object for the thread */
p_sys
->
p_thread
=
p_thread
=
(
projectm_thread_t
*
)
vlc_sem_init
(
&
p_sys
->
ready
,
0
);
vlc_object_create
(
p_filter
,
sizeof
(
projectm_thread_t
)
);
p_sys
->
b_error
=
false
;
vlc_object_attach
(
p_sys
->
p_thread
,
p_filter
);
p_sys
->
i_width
=
var_CreateGetInteger
(
p_filter
,
"projectm-width"
);
vlc_sem_init
(
&
p_thread
->
ready
,
0
);
p_sys
->
i_height
=
var_CreateGetInteger
(
p_filter
,
"projectm-height"
);
p_thread
->
b_error
=
false
;
p_sys
->
i_channels
=
aout_FormatNbChannels
(
&
p_filter
->
fmt_in
.
audio
);
p_thread
->
i_width
=
var_CreateGetInteger
(
p_filter
,
"projectm-width"
);
p_sys
->
psz_config
=
var_CreateGetString
(
p_filter
,
"projectm-config"
);
p_thread
->
i_height
=
var_CreateGetInteger
(
p_filter
,
"projectm-height"
);
vlc_mutex_init
(
&
p_sys
->
lock
);
p_sys
->
p_buffer
=
NULL
;
p_thread
->
i_channels
=
aout_FormatNbChannels
(
&
p_filter
->
fmt_in
.
audio
);
p_sys
->
i_buffer_size
=
0
;
p_thread
->
psz_config
=
var_CreateGetString
(
p_filter
,
"projectm-config"
);
p_sys
->
i_nb_samples
=
0
;
vlc_mutex_init
(
&
p_thread
->
lock
);
p_thread
->
p_buffer
=
NULL
;
p_thread
->
i_buffer_size
=
0
;
p_thread
->
i_nb_samples
=
0
;
/* Create the thread */
/* Create the thread */
if
(
vlc_thread_create
(
p_thread
,
"projectm update thread"
,
Thread
,
if
(
vlc_clone
(
&
p_sys
->
thread
,
Thread
,
p_filter
,
VLC_THREAD_PRIORITY_LOW
)
)
VLC_THREAD_PRIORITY_LOW
)
)
goto
error
;
goto
error
;
vlc_sem_wait
(
&
p_thread
->
ready
);
vlc_sem_wait
(
&
p_sys
->
ready
);
if
(
p_thread
->
b_error
)
if
(
p_sys
->
b_error
)
{
vlc_join
(
p_sys
->
thread
,
NULL
);
goto
error
;
goto
error
;
}
return
VLC_SUCCESS
;
return
VLC_SUCCESS
;
error:
error:
vlc_thread_join
(
p_thread
);
vlc_sem_destroy
(
&
p_sys
->
ready
);
vlc_sem_destroy
(
&
p_thread
->
ready
);
vlc_object_detach
(
p_thread
);
vlc_object_release
(
p_thread
);
free
(
p_sys
);
free
(
p_sys
);
return
VLC_EGENERIC
;
return
VLC_EGENERIC
;
}
}
...
@@ -228,21 +218,16 @@ static void Close( vlc_object_t *p_this )
...
@@ -228,21 +218,16 @@ static void Close( vlc_object_t *p_this )
{
{
filter_t
*
p_filter
=
(
filter_t
*
)
p_this
;
filter_t
*
p_filter
=
(
filter_t
*
)
p_this
;
filter_sys_t
*
p_sys
=
p_filter
->
p_sys
;
filter_sys_t
*
p_sys
=
p_filter
->
p_sys
;
projectm_thread_t
*
p_thread
=
p_sys
->
p_thread
;
/* Stop the thread */
/* Stop the thread */
vlc_
object_kill
(
p_
thread
);
vlc_
cancel
(
p_sys
->
thread
);
vlc_
thread_join
(
p_thread
);
vlc_
join
(
p_sys
->
thread
,
NULL
);
/* Free the ressources */
/* Free the ressources */
vlc_sem_destroy
(
&
p_thread
->
ready
);
vlc_sem_destroy
(
&
p_sys
->
ready
);
vlc_mutex_destroy
(
&
p_thread
->
lock
);
vlc_mutex_destroy
(
&
p_sys
->
lock
);
free
(
p_thread
->
p_buffer
);
free
(
p_sys
->
p_buffer
);
free
(
p_thread
->
psz_config
);
free
(
p_sys
->
psz_config
);
vlc_object_detach
(
p_thread
);
vlc_object_release
(
p_thread
);
free
(
p_sys
);
free
(
p_sys
);
}
}
...
@@ -256,88 +241,95 @@ static void Close( vlc_object_t *p_this )
...
@@ -256,88 +241,95 @@ static void Close( vlc_object_t *p_this )
*/
*/
static
block_t
*
DoWork
(
filter_t
*
p_filter
,
block_t
*
p_in_buf
)
static
block_t
*
DoWork
(
filter_t
*
p_filter
,
block_t
*
p_in_buf
)
{
{
projectm_thread_t
*
p_thread
=
p_filter
->
p_sys
->
p_thread
;
filter_sys_t
*
p_sys
=
p_filter
->
p_sys
;
vlc_mutex_lock
(
&
p_
thread
->
lock
);
vlc_mutex_lock
(
&
p_
sys
->
lock
);
if
(
p_
thread
->
i_buffer_size
>
0
)
if
(
p_
sys
->
i_buffer_size
>
0
)
{
{
p_
thread
->
p_buffer
[
0
]
=
0
;
p_
sys
->
p_buffer
[
0
]
=
0
;
p_
thread
->
i_nb_samples
=
__MIN
(
p_thread
->
i_buffer_size
,
p_
sys
->
i_nb_samples
=
__MIN
(
p_sys
->
i_buffer_size
,
p_in_buf
->
i_nb_samples
);
p_in_buf
->
i_nb_samples
);
for
(
int
i
=
0
;
i
<
p_
thread
->
i_nb_samples
;
i
++
)
for
(
int
i
=
0
;
i
<
p_
sys
->
i_nb_samples
;
i
++
)
p_
thread
->
p_buffer
[
i
]
=
p_in_buf
->
p_buffer
[
i
];
p_
sys
->
p_buffer
[
i
]
=
p_in_buf
->
p_buffer
[
i
];
}
}
vlc_mutex_unlock
(
&
p_sys
->
lock
);
vlc_mutex_unlock
(
&
p_thread
->
lock
);
return
p_in_buf
;
return
p_in_buf
;
}
}
/**
* Clean up function when Thread() is cancelled.
*/
static
void
ThreadCleanup
(
void
*
p_data
)
{
filter_t
*
p_filter
=
(
filter_t
*
)
p_data
;
filter_sys_t
*
p_sys
=
p_filter
->
p_sys
;
/* Cleanup */
delete
p_sys
->
p_projectm
;
/* Free the openGL provider */
module_unneed
(
p_sys
->
p_opengl
,
p_sys
->
p_module
);
vlc_object_detach
(
p_sys
->
p_opengl
);
vlc_object_release
(
p_sys
->
p_opengl
);
}
/**
/**
* ProjectM update thread which do the rendering
* ProjectM update thread which do the rendering
* @param p_this: the p_thread object
* @param p_this: the p_thread object
*/
*/
static
void
*
Thread
(
vlc_object_t
*
p_this
)
static
void
*
Thread
(
void
*
p_data
)
{
{
/* we don't want to be interupted in this thread */
filter_t
*
p_filter
=
(
filter_t
*
)
p_data
;
filter_sys_t
*
p_sys
=
p_filter
->
p_sys
;
int
cancel
=
vlc_savecancel
();
int
cancel
=
vlc_savecancel
();
projectm_thread_t
*
p_thread
=
(
projectm_thread_t
*
)
p_this
;
/* Create the openGL provider */
/* Create the openGL provider */
if
(
initOpenGL
(
p_
thread
)
)
if
(
initOpenGL
(
p_
filter
)
)
{
{
p_
thread
->
b_error
=
true
;
p_
sys
->
b_error
=
true
;
vlc_sem_post
(
&
p_
thread
->
ready
);
vlc_sem_post
(
&
p_
sys
->
ready
);
return
NULL
;
return
NULL
;
}
}
vlc_cleanup_push
(
ThreadCleanup
,
p_filter
);
/* Initialize the opengl provider for this thread */
/* Initialize the opengl provider for this thread */
p_
thread
->
p_opengl
->
pf_init
(
p_thread
->
p_opengl
);
p_
sys
->
p_opengl
->
pf_init
(
p_sys
->
p_opengl
);
/* Create the projectM object */
/* Create the projectM object */
p_
thread
->
p_projectm
=
new
projectM
(
p_thread
->
psz_config
);
p_
sys
->
p_projectm
=
new
projectM
(
p_sys
->
psz_config
);
p_
thread
->
i_buffer_size
=
p_thread
->
p_projectm
->
pcm
()
->
maxsamples
;
p_
sys
->
i_buffer_size
=
p_sys
->
p_projectm
->
pcm
()
->
maxsamples
;
p_
thread
->
p_buffer
=
(
float
*
)
malloc
(
p_thread
->
i_buffer_size
*
p_
sys
->
p_buffer
=
(
float
*
)
calloc
(
p_sys
->
i_buffer_size
,
sizeof
(
float
)
);
sizeof
(
float
)
);
vlc_sem_post
(
&
p_
thread
->
ready
);
vlc_sem_post
(
&
p_
sys
->
ready
);
/* TODO: Give to projectm the name of the input
/* TODO: Give to projectm the name of the input
p_
thread
->p_projectm->projectM_setTitle( "" ); */
p_
sys
->p_projectm->projectM_setTitle( "" ); */
/* Reset the dislay to get the right size */
/* Reset the dislay to get the right size */
p_
thread
->
p_projectm
->
projectM_resetGL
(
p_thread
->
i_width
,
p_
sys
->
p_projectm
->
projectM_resetGL
(
p_sys
->
i_width
,
p_thread
->
i_height
);
p_sys
->
i_height
);
while
(
vlc_object_alive
(
p_thread
)
)
for
(
;;
)
{
{
/* Manage the events */
/* Manage the events */
p_
thread
->
p_opengl
->
pf_manage
(
p_thread
->
p_opengl
);
p_
sys
->
p_opengl
->
pf_manage
(
p_sys
->
p_opengl
);
/* Render the image and swap the buffers */
/* Render the image and swap the buffers */
vlc_mutex_lock
(
&
p_
thread
->
lock
);
vlc_mutex_lock
(
&
p_
sys
->
lock
);
if
(
p_
thread
->
i_nb_samples
>
0
)
if
(
p_
sys
->
i_nb_samples
>
0
)
p_
thread
->
p_projectm
->
pcm
()
->
addPCMfloat
(
p_thread
->
p_buffer
,
p_
sys
->
p_projectm
->
pcm
()
->
addPCMfloat
(
p_sys
->
p_buffer
,
p_thread
->
i_nb_samples
);
p_sys
->
i_nb_samples
);
p_
thread
->
p_projectm
->
renderFrame
();
p_
sys
->
p_projectm
->
renderFrame
();
p_
thread
->
p_opengl
->
pf_swap
(
p_thread
->
p_opengl
);
p_
sys
->
p_opengl
->
pf_swap
(
p_sys
->
p_opengl
);
vlc_mutex_unlock
(
&
p_
thread
->
lock
);
vlc_mutex_unlock
(
&
p_
sys
->
lock
);
/* TODO: use a fps limiter */
/* TODO: use a fps limiter */
vlc_restorecancel
(
cancel
);
msleep
(
10000
);
msleep
(
10000
);
cancel
=
vlc_savecancel
();
}
}
vlc_cleanup_pop
();
/* Cleanup */
delete
p_thread
->
p_projectm
;
/* Free the openGL provider */
module_unneed
(
p_thread
->
p_opengl
,
p_thread
->
p_module
);
vlc_object_detach
(
p_thread
->
p_opengl
);
vlc_object_release
(
p_thread
->
p_opengl
);
vlc_restorecancel
(
cancel
);
return
NULL
;
}
}
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