Commit 3bc30b81 authored by Laurent Aimar's avatar Laurent Aimar

* all: clean up.

        use vout_Request to release the vout (so vout isn't closed when
        changing playlist item).
parent 07d406a6
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* effects.c : Effects for the visualization system * effects.c : Effects for the visualization system
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: effects.c,v 1.6 2003/09/08 22:00:47 zorglub Exp $ * $Id: effects.c,v 1.7 2003/09/20 00:37:53 fenrir Exp $
* *
* Authors: Clment Stenac <zorglub@via.ecp.fr> * Authors: Clment Stenac <zorglub@via.ecp.fr>
* *
...@@ -24,6 +24,12 @@ ...@@ -24,6 +24,12 @@
/***************************************************************************** /*****************************************************************************
* Preamble * Preamble
*****************************************************************************/ *****************************************************************************/
#include <stdlib.h> /* malloc(), free() */
#include <vlc/vlc.h>
#include <vlc/vout.h>
#include "audio_output.h"
#include "aout_internal.h"
#include "visual.h" #include "visual.h"
#include <math.h> #include <math.h>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* visual.c : Visualisation system * visual.c : Visualisation system
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: visual.c,v 1.8 2003/09/19 21:53:32 hartman Exp $ * $Id: visual.c,v 1.9 2003/09/20 00:37:53 fenrir Exp $
* *
* Authors: Clment Stenac <zorglub@via.ecp.fr> * Authors: Clment Stenac <zorglub@via.ecp.fr>
* *
...@@ -24,18 +24,13 @@ ...@@ -24,18 +24,13 @@
/***************************************************************************** /*****************************************************************************
* Preamble * Preamble
*****************************************************************************/ *****************************************************************************/
#include "visual.h" #include <stdlib.h> /* malloc(), free() */
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <vlc/vout.h>
#include "audio_output.h"
#include "aout_internal.h"
/***************************************************************************** #include "visual.h"
* Local prototypes
*****************************************************************************/
static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * );
static void DoWork ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
aout_buffer_t * );
/***************************************************************************** /*****************************************************************************
* Module descriptor * Module descriptor
...@@ -73,6 +68,9 @@ static void DoWork ( aout_instance_t *, aout_filter_t *, aout_buffer_t *, ...@@ -73,6 +68,9 @@ static void DoWork ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
#define STARS_LONGTEXT N_( \ #define STARS_LONGTEXT N_( \
"Defines the number of stars to draw with random effect" ) "Defines the number of stars to draw with random effect" )
static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * );
vlc_module_begin(); vlc_module_begin();
add_category_hint( N_("visualizer") , NULL , VLC_FALSE); add_category_hint( N_("visualizer") , NULL , VLC_FALSE);
set_description( _("visualizer filter") ); set_description( _("visualizer filter") );
...@@ -97,159 +95,155 @@ vlc_module_begin(); ...@@ -97,159 +95,155 @@ vlc_module_begin();
add_shortcut( "visualizer"); add_shortcut( "visualizer");
vlc_module_end(); vlc_module_end();
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static void DoWork( aout_instance_t *, aout_filter_t *,
aout_buffer_t *, aout_buffer_t * );
static struct
{
char *psz_name;
int (*pf_run)( visual_effect_t *, aout_instance_t *,
aout_buffer_t *, picture_t *);
} pf_effect_run[]=
{
{ "scope", scope_Run },
{ "spectrum", spectrum_Run },
{ "random", random_Run},
{ "dummy", dummy_Run},
{ NULL, dummy_Run}
};
/***************************************************************************** /*****************************************************************************
* Open: open the visualizer * Open: open the visualizer
*****************************************************************************/ *****************************************************************************/
static int Open( vlc_object_t *p_this ) static int Open( vlc_object_t *p_this )
{ {
aout_filter_t *p_filter = (aout_filter_t *)p_this; aout_filter_t *p_filter = (aout_filter_t *)p_this;
aout_filter_sys_t *p_sys;
char *psz_effects; char *psz_effects, *psz_parser;
char *psz_eof; /* Used to parse effect list */
char *psz_eoa, *psz_boa; /* Used to parse arg lists */
vlc_bool_t b_end = VLC_FALSE; if( ( p_filter->input.i_format != VLC_FOURCC('f','l','3','2') &&
p_filter->input.i_format != VLC_FOURCC('f','i','3','2') ) )
visual_effect_t *p_current_effect = NULL;
if( (p_filter->input.i_format != VLC_FOURCC('f','l','3','2')
&& p_filter->input.i_format != VLC_FOURCC('f','i','3','2')) )
{ {
return -1; return VLC_EGENERIC;
} }
p_filter->p_sys = malloc(sizeof(struct aout_filter_sys_t)); p_sys = p_filter->p_sys = malloc( sizeof( aout_filter_sys_t ) );
if ( p_filter->p_sys == NULL ) if( p_sys == NULL )
{ {
msg_Err( p_filter, "out of memory" ); msg_Err( p_filter, "out of memory" );
return -1; return VLC_EGENERIC;
} }
p_filter->p_sys->i_height = config_GetInt( p_filter , "effect-height"); p_sys->i_height = config_GetInt( p_filter , "effect-height");
p_filter->p_sys->i_width = config_GetInt( p_filter , "effect-width"); p_sys->i_width = config_GetInt( p_filter , "effect-width");
if ( p_filter->p_sys->i_height < 20 )
p_filter->p_sys->i_height = 20;
if ( p_filter->p_sys->i_width < 20 )
p_filter->p_sys->i_width = 20;
if( (p_filter->p_sys->i_height % 2 ) != 0 ) if( p_sys->i_height < 20 ) p_sys->i_height = 20;
p_filter->p_sys->i_height --; if( p_sys->i_width < 20 ) p_sys->i_width = 20;
if( (p_sys->i_height % 2 ) != 0 ) p_sys->i_height--;
if( (p_sys->i_width % 2 ) != 0 ) p_sys->i_width--;
if( (p_filter->p_sys->i_width % 2 ) != 0 ) p_sys->i_effect = 0;
p_filter->p_sys->i_width --; p_sys->effect = NULL;
/* Parse the effect list */ /* Parse the effect list */
psz_effects = config_GetPsz( p_filter, "effect-list" ); psz_parser = psz_effects = config_GetPsz( p_filter, "effect-list" );
msg_Dbg( p_filter , "Building list of effects" ); msg_Dbg( p_filter , "Building list of effects" );
p_filter->p_sys->p_first_effect = while( psz_parser && *psz_parser != '\0' )
(visual_effect_t *)malloc( sizeof( visual_effect_t ) );
if( !p_filter->p_sys->p_first_effect )
{ {
msg_Err( p_filter, "Out of memory" ); visual_effect_t *p_effect;
return -1; int i;
}
p_effect = malloc( sizeof( visual_effect_t ) );
p_effect->i_width = p_sys->i_width;
p_effect->i_height= p_sys->i_height;
p_effect->i_nb_chans = aout_FormatNbChannels( &p_filter->input);
p_effect->psz_args = NULL;
p_effect->p_data = NULL;
p_current_effect = p_filter->p_sys->p_first_effect; p_effect->pf_run = NULL;
p_current_effect->p_next = NULL; p_effect->psz_name = NULL;
while(1)
for( i = 0; pf_effect_run[i].psz_name != NULL; i++ )
{ {
psz_eof = strchr( psz_effects , ',' ); if( !strncasecmp( psz_parser,
if( !psz_eof ) pf_effect_run[i].psz_name,
strlen( pf_effect_run[i].psz_name ) ) )
{ {
b_end = VLC_TRUE; p_effect->pf_run = pf_effect_run[i].pf_run;
psz_eof = strchr( psz_effects,'\0'); p_effect->psz_name = strdup( pf_effect_run[i].psz_name );
break;
} }
if( psz_eof )
{
*psz_eof = '\0';
} }
p_current_effect->p_next = if( p_effect->psz_name )
(visual_effect_t *)malloc( sizeof( visual_effect_t ) );
if( !p_current_effect )
{ {
msg_Err( p_filter, "Out of memory" ); psz_parser += strlen( p_effect->psz_name );
}
p_current_effect = p_current_effect -> p_next; if( *psz_parser == '{' )
p_current_effect->psz_func = strdup("dummy");
p_current_effect->p_next = NULL;
p_current_effect->i_width = p_filter->p_sys->i_width;
p_current_effect->i_height = p_filter->p_sys->i_height;
p_current_effect->p_data = NULL;
#if 0
if(! strncasecmp(psz_effects,"dummy",5))
p_current_effect->pf_run = dummy_Run;
else if(! strncasecmp(psz_effects,"scope",5) )
p_current_effect->pf_run = scope_Run;
else if(! strncasecmp(psz_effects,"spectrum",8) )
p_current_effect->pf_run = spectrum_Run;
else if(! strncasecmp(psz_effects,"random",6) )
p_current_effect->pf_run = random_Run;
else if(! strncasecmp(psz_effects,"blur",4) )
p_current_effect->pf_run = blur_Run;
#endif
if(! ( strncasecmp(psz_effects,"dummy",5) &&
strncasecmp(psz_effects,"scope",5) &&
strncasecmp(psz_effects,"spectrum",8) &&
strncasecmp(psz_effects,"random",6) ) )
p_current_effect->psz_func = strdup( psz_effects ) ;
p_current_effect->psz_args = NULL;
p_current_effect->i_nb_chans =
aout_FormatNbChannels( &p_filter->input);
psz_boa = strchr( psz_effects, '{' );
if( psz_boa )
{ {
psz_eoa = strchr( psz_effects, '}'); char *psz_eoa;
if( ! psz_eoa )
psz_parser++;
if( ( psz_eoa = strchr( psz_parser, '}') ) == NULL )
{ {
msg_Err( p_filter, "Unable to parse effect list. Aborting"); msg_Err( p_filter, "Unable to parse effect list. Aborting");
return -1; break;
}
p_effect->psz_args = strndup( psz_parser, psz_eoa - psz_parser);
} }
*psz_eoa = '\0';
p_current_effect->psz_args = strdup(++psz_boa);
psz_effects = psz_eoa;
} }
psz_effects = psz_eof; else
psz_effects ++; {
msg_Err( p_filter, "unknown visual effect" );
}
if( b_end == VLC_TRUE ) TAB_APPEND( p_sys->i_effect, p_sys->effect, p_effect );
if( strchr( psz_parser, ',' ) )
{
psz_parser = strchr( psz_parser, ',' ) + 1;
}
else if( strchr( psz_parser, ':' ) )
{
psz_parser = strchr( psz_parser, ':' ) + 1;
}
else
{
break; break;
} }
}
if( psz_effects )
{
free( psz_effects );
}
p_filter->pf_do_work = DoWork;
p_filter->b_in_place= 1;
/* Open the video output */ /* Open the video output */
p_filter->p_sys->p_vout = p_sys->p_vout =
vout_Request( p_filter, NULL, vout_Request( p_filter, NULL,
p_filter->p_sys->i_width, p_sys->i_width, p_sys->i_height,
p_filter->p_sys->i_height,
VLC_FOURCC('I','4','2','0'),
VOUT_ASPECT_FACTOR * p_filter->p_sys->i_width/
p_filter->p_sys->i_height );
/* vout_Create( p_filter,
p_filter->p_sys->i_width,
p_filter->p_sys->i_height,
VLC_FOURCC('I','4','2','0'), VLC_FOURCC('I','4','2','0'),
VOUT_ASPECT_FACTOR * p_filter->p_sys->i_width/ VOUT_ASPECT_FACTOR * p_sys->i_width/p_sys->i_height );
p_filter->p_sys->i_height );*/
if( p_filter->p_sys->p_vout == NULL ) if( p_sys->p_vout == NULL )
{ {
msg_Err( p_filter, "no suitable vout module" ); msg_Err( p_filter, "no suitable vout module" );
if(p_filter->p_sys) free( p_sys );
free( p_filter->p_sys ); return VLC_EGENERIC;
return -1;
} }
msg_Dbg(p_filter,"Visualizer initialized"); p_filter->pf_do_work = DoWork;
return 0 ; p_filter->b_in_place= 1;
msg_Dbg( p_filter,"Visualizer initialized");
return VLC_SUCCESS;
} }
/***************************************************************************** /*****************************************************************************
...@@ -260,68 +254,47 @@ static int Open( vlc_object_t *p_this ) ...@@ -260,68 +254,47 @@ static int Open( vlc_object_t *p_this )
static void DoWork( aout_instance_t *p_aout, aout_filter_t *p_filter, static void DoWork( aout_instance_t *p_aout, aout_filter_t *p_filter,
aout_buffer_t *p_in_buf, aout_buffer_t *p_out_buf ) aout_buffer_t *p_in_buf, aout_buffer_t *p_out_buf )
{ {
aout_filter_sys_t *p_sys = p_filter->p_sys;
picture_t *p_outpic; picture_t *p_outpic;
int i;
visual_effect_t *p_current_effect;
int i_input_nb = aout_FormatNbChannels( &p_filter->input );
int i_output_nb = aout_FormatNbChannels( &p_filter->output );
s32 * p_dest = (s32 *)p_out_buf->p_buffer;
s32 * p_src = (s32 *)p_in_buf->p_buffer;
int i_index;
p_out_buf->i_nb_samples = p_in_buf->i_nb_samples; p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes * i_output_nb / i_input_nb; p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes *
aout_FormatNbChannels( &p_filter->output ) /
aout_FormatNbChannels( &p_filter->input );
/* First, get a new picture */ /* First, get a new picture */
while( ( p_outpic = vout_CreatePicture( p_filter->p_sys->p_vout, while( ( p_outpic = vout_CreatePicture( p_sys->p_vout, 0, 0, 3 ) ) == NULL)
VLC_FALSE, VLC_FALSE, 3 ) ) == NULL ) {
if( p_aout->b_die )
{ {
if(p_aout->b_die )
return; return;
}
msleep( VOUT_OUTMEM_SLEEP ); msleep( VOUT_OUTMEM_SLEEP );
} }
/* Blank the picture */ /* Blank the picture */
for( i_index = 0 ; i_index < p_outpic->i_planes ; i_index++ ) for( i = 0 ; i < p_outpic->i_planes ; i++ )
{ {
memset( p_outpic->p[i_index].p_pixels, i_index ? 0x80 : 0x00, memset( p_outpic->p[i].p_pixels, i > 0 ? 0x80 : 0x00,
p_outpic->p[i_index].i_lines * p_outpic->p[i_index].i_pitch ); p_outpic->p[i].i_lines * p_outpic->p[i].i_pitch );
} }
/* We can now call our visualization effects */ /* We can now call our visualization effects */
p_current_effect = p_filter->p_sys->p_first_effect; for( i = 0; i < p_sys->i_effect; i++ )
while( p_current_effect && p_current_effect->psz_func )
{ {
#define p_effect p_sys->effect[i]
if( !strcasecmp( p_current_effect->psz_func, "dummy" ) ) if( p_effect->pf_run )
{
dummy_Run(p_current_effect, p_aout, p_out_buf , p_outpic );
}
else if( !strcasecmp( p_current_effect->psz_func, "scope" ) )
{
scope_Run(p_current_effect, p_aout, p_out_buf , p_outpic );
}
else if( !strcasecmp( p_current_effect->psz_func, "random" ) )
{ {
random_Run(p_current_effect, p_aout, p_out_buf , p_outpic ); p_effect->pf_run( p_effect, p_aout, p_out_buf, p_outpic );
} }
else if( !strcasecmp( p_current_effect->psz_func, "spectrum" ) ) #undef p_effect
{
spectrum_Run(p_current_effect, p_aout, p_out_buf , p_outpic );
}
p_current_effect = p_current_effect->p_next;
} }
vout_DatePicture ( p_filter->p_sys->p_vout,p_outpic, vout_DatePicture( p_sys->p_vout, p_outpic,
( p_in_buf->start_date + p_in_buf->end_date) /2 ); ( p_in_buf->start_date + p_in_buf->end_date ) / 2 );
vout_DisplayPicture ( p_filter->p_sys->p_vout, p_outpic );
vout_DisplayPicture( p_sys->p_vout, p_outpic );
} }
/***************************************************************************** /*****************************************************************************
...@@ -330,24 +303,35 @@ static void DoWork( aout_instance_t *p_aout, aout_filter_t *p_filter, ...@@ -330,24 +303,35 @@ static void DoWork( aout_instance_t *p_aout, aout_filter_t *p_filter,
static void Close( vlc_object_t *p_this ) static void Close( vlc_object_t *p_this )
{ {
aout_filter_t * p_filter = (aout_filter_t *)p_this; aout_filter_t * p_filter = (aout_filter_t *)p_this;
aout_filter_sys_t *p_sys = p_filter->p_sys;
visual_effect_t *p_old; int i;
visual_effect_t *p_cur = p_filter->p_sys->p_first_effect;
if( p_filter->p_sys->p_vout ) if( p_filter->p_sys->p_vout )
{ {
vlc_object_detach( p_filter->p_sys->p_vout) ; vout_Request( p_filter, p_filter->p_sys->p_vout, 0, 0, 0, 0 );
vout_Destroy( p_filter->p_sys->p_vout );
} }
/* Free the list */ /* Free the list */
while( p_cur ) for( i = 0; i < p_sys->i_effect; i++ )
{
#define p_effect p_sys->effect[i]
if( p_effect->psz_name )
{ {
p_old = p_cur; free( p_effect->psz_name );
p_cur = p_cur->p_next; }
if( p_old ) free( p_old ); if( p_effect->psz_args )
{
free( p_effect->psz_args );
}
free( p_effect );
#undef p_effect
} }
if( p_filter->p_sys != NULL ) if( p_sys->effect )
free( p_filter->p_sys); {
free( p_sys->effect );
}
free( p_filter->p_sys );
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* visual.h : Header for the visualisation system * visual.h : Header for the visualisation system
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: visual.h,v 1.4 2003/09/10 10:21:09 zorglub Exp $ * $Id: visual.h,v 1.5 2003/09/20 00:37:53 fenrir Exp $
* *
* Authors: Clment Stenac <zorglub@via.ecp.fr> * Authors: Clment Stenac <zorglub@via.ecp.fr>
* *
...@@ -21,34 +21,13 @@ ...@@ -21,34 +21,13 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/ *****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include <stdlib.h> /* malloc(), free() */
#include <string.h> /* strdup() */
#include <errno.h>
#include <vlc/vlc.h>
#include <vlc/vout.h>
#include "audio_output.h"
#include "aout_internal.h"
/*****************************************************************************
* aout_filter_sys_t: visualizer audio filter method descriptor
*****************************************************************************
* This structure is part of the audio filter descriptor.
* It describes some visualizer specific variables.
*****************************************************************************/
typedef struct visual_effect_t typedef struct visual_effect_t
{ {
int (*pf_run) char * psz_name; /* Filter name*/
(struct visual_effect_t * , aout_instance_t *,
int (*pf_run)( struct visual_effect_t * , aout_instance_t *,
aout_buffer_t *, picture_t *); aout_buffer_t *, picture_t *);
void * p_data; /* The effect stores whatever it wants here */ void * p_data; /* The effect stores whatever it wants here */
char * psz_func;
struct visual_effect_t * p_next;
int i_width; int i_width;
int i_height; int i_height;
char * psz_args; char * psz_args;
...@@ -56,13 +35,22 @@ typedef struct visual_effect_t ...@@ -56,13 +35,22 @@ typedef struct visual_effect_t
} visual_effect_t ; } visual_effect_t ;
struct aout_filter_sys_t /*****************************************************************************
* aout_filter_sys_t: visualizer audio filter method descriptor
*****************************************************************************
* This structure is part of the audio filter descriptor.
* It describes some visualizer specific variables.
*****************************************************************************/
typedef struct aout_filter_sys_t
{ {
vout_thread_t *p_vout; vout_thread_t *p_vout;
visual_effect_t *p_first_effect;
int i_width; int i_width;
int i_height; int i_height;
};
int i_effect;
visual_effect_t **effect;
} aout_filter_sys_t;
/* Prototypes */ /* Prototypes */
int scope_Run int scope_Run
......
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