* It includes functions allowing to open a new thread, send pictures to a
* thread, and destroy a previously oppened video output thread.
*****************************************************************************
- * Copyright (C) 2000-2001 VideoLAN
- * $Id: video_output.c,v 1.228 2003/06/28 21:18:58 fenrir Exp $
+ * Copyright (C) 2000-2004 VideoLAN
+ * $Id$
*
* Authors: Vincent Seguin <seguin@via.ecp.fr>
*
static void MaskToShift ( int *, int *, uint32_t );
static void InitWindowSize ( vout_thread_t *, int *, int * );
+void vout_IntfInit( vout_thread_t * );
+
/* Object variables callbacks */
static int FullscreenCallback( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * );
static int DeinterlaceCallback( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * );
+static int FilterCallback( vlc_object_t *, char const *,
+ vlc_value_t, vlc_value_t, void * );
+
+/**
+ * vout_AspectRatio
+ *
+ * Set the i_aspect_x and i_aspect_y from i_aspect.
+ */
+void vout_AspectRatio( unsigned int i_aspect,
+ /*out*/ unsigned int *i_aspect_x,
+ /*out*/ unsigned int *i_aspect_y )
+{
+ unsigned int i_pgcd = ReduceHeight( i_aspect );
+ *i_aspect_x = i_aspect / i_pgcd;
+ *i_aspect_y = VOUT_ASPECT_FACTOR / i_pgcd;
+}
/*****************************************************************************
* vout_Request: find a video output thread, create one, or destroy one.
/* Reattach video output to input before bailing out */
if( p_vout )
{
- vlc_object_t *p_input;
+ vlc_object_t *p_playlist;
- p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_PARENT );
+ p_playlist = vlc_object_find( p_this,
+ VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
- if( p_input )
+ if( p_playlist )
{
vlc_object_detach( p_vout );
- vlc_object_attach( p_vout, p_input );
+ vlc_object_attach( p_vout, p_playlist );
- vlc_object_release( p_input );
+ vlc_object_release( p_playlist );
}
else
{
+ msg_Dbg( p_this, "cannot find playlist, destroying vout" );
vlc_object_detach( p_vout );
- /* vlc_object_release( p_vout ); */
vout_Destroy( p_vout );
}
}
if( !p_vout )
{
- vlc_object_t *p_input;
+ vlc_object_t *p_playlist;
- p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_PARENT );
- if( p_input )
+ p_playlist = vlc_object_find( p_this,
+ VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
+ if( p_playlist )
{
- p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT,
- FIND_CHILD );
+ p_vout = vlc_object_find( p_playlist,
+ VLC_OBJECT_VOUT, FIND_CHILD );
/* only first children of p_input for unused vout */
- if( p_vout && p_vout->p_parent != p_input )
+ if( p_vout && p_vout->p_parent != p_playlist )
{
vlc_object_release( p_vout );
p_vout = NULL;
}
- vlc_object_release( p_input );
+ vlc_object_release( p_playlist );
}
}
}
return NULL;
}
- var_Create( p_vout, "intf-change", VLC_VAR_BOOL );
- val.b_bool = VLC_TRUE;
- var_Set( p_vout, "intf-change", val );
-
- p_vout->b_override_aspect = VLC_FALSE;
-
- /* If the parent is not a VOUT object, that means we are at the start of
- * the video output pipe */
- if( p_parent->i_object_type != VLC_OBJECT_VOUT )
- {
- char *psz_aspect = config_GetPsz( p_parent, "aspect-ratio" );
-
- /* Check whether the user tried to override aspect ratio */
- if( psz_aspect )
- {
- unsigned int i_new_aspect = i_aspect;
- char *psz_parser = strchr( psz_aspect, ':' );
-
- if( psz_parser )
- {
- *psz_parser++ = '\0';
- i_new_aspect = atoi( psz_aspect ) * VOUT_ASPECT_FACTOR
- / atoi( psz_parser );
- }
- else
- {
- i_new_aspect = i_width * VOUT_ASPECT_FACTOR
- * atof( psz_aspect )
- / i_height;
- }
-
- free( psz_aspect );
-
- if( i_new_aspect && i_new_aspect != i_aspect )
- {
- int i_pgcd = ReduceHeight( i_new_aspect );
-
- msg_Dbg( p_vout, "overriding source aspect ratio to %i:%i",
- i_new_aspect / i_pgcd, VOUT_ASPECT_FACTOR / i_pgcd );
-
- i_aspect = i_new_aspect;
-
- p_vout->b_override_aspect = VLC_TRUE;
- }
- }
-
- /* Look for the default filter configuration */
- p_vout->psz_filter_chain = config_GetPsz( p_parent, "filter" );
- }
- else
- {
- /* continue the parent's filter chain */
- char *psz_end;
-
- psz_end = strchr( ((vout_thread_t *)p_parent)->psz_filter_chain, ':' );
- if( psz_end && *(psz_end+1) )
- p_vout->psz_filter_chain = strdup( psz_end+1 );
- else p_vout->psz_filter_chain = NULL;
- }
-
- /* Choose the video output module */
- if( !p_vout->psz_filter_chain || !*p_vout->psz_filter_chain )
- {
- psz_plugin = config_GetPsz( p_parent, "vout" );
- }
- else
- {
- /* the filter chain is a string list of filters separated by double
- * colons */
- char *psz_end;
-
- psz_end = strchr( p_vout->psz_filter_chain, ':' );
- if( psz_end )
- psz_plugin = strndup( p_vout->psz_filter_chain,
- psz_end - p_vout->psz_filter_chain );
- else psz_plugin = strdup( p_vout->psz_filter_chain );
- }
-
/* Initialize pictures and subpictures - translation tables and functions
* will be initialized later in InitThread */
for( i_index = 0; i_index < 2 * VOUT_MAX_PICTURES; i_index++)
p_vout->b_interface = 0;
p_vout->b_scale = 1;
p_vout->b_fullscreen = 0;
+ p_vout->i_alignment = 0;
p_vout->render_time = 10;
p_vout->c_fps_samples = 0;
p_vout->b_filter_change = 0;
+ p_vout->pf_control = 0;
/* Mouse coordinates */
var_Create( p_vout, "mouse-x", VLC_VAR_INTEGER );
var_Create( p_vout, "mouse-button-down", VLC_VAR_INTEGER );
var_Create( p_vout, "mouse-moved", VLC_VAR_BOOL );
var_Create( p_vout, "mouse-clicked", VLC_VAR_INTEGER );
- var_Create( p_vout, "key-pressed", VLC_VAR_STRING );
- /* Initialize the dimensions of the video window */
- InitWindowSize( p_vout, &p_vout->i_window_width,
- &p_vout->i_window_height );
+ var_Create( p_vout, "intf-change", VLC_VAR_BOOL );
+ val.b_bool = VLC_TRUE;
+ var_Set( p_vout, "intf-change", val );
- /* Create thread and set locks */
+ /* Initialize locks */
vlc_mutex_init( p_vout, &p_vout->picture_lock );
vlc_mutex_init( p_vout, &p_vout->subpicture_lock );
vlc_mutex_init( p_vout, &p_vout->change_lock );
+ /* Attach the new object now so we can use var inheritance below */
vlc_object_attach( p_vout, p_parent );
+ /* Take care of some "interface/control" related initialisations */
+ vout_IntfInit( p_vout );
+
+ p_vout->b_override_aspect = VLC_FALSE;
+
+ /* If the parent is not a VOUT object, that means we are at the start of
+ * the video output pipe */
+ if( p_parent->i_object_type != VLC_OBJECT_VOUT )
+ {
+ var_Get( p_vout, "aspect-ratio", &val );
+
+ /* Check whether the user tried to override aspect ratio */
+ if( val.psz_string )
+ {
+ unsigned int i_new_aspect = i_aspect;
+ char *psz_parser = strchr( val.psz_string, ':' );
+
+ if( psz_parser )
+ {
+ *psz_parser++ = '\0';
+ i_new_aspect = atoi( val.psz_string ) * VOUT_ASPECT_FACTOR
+ / atoi( psz_parser );
+ }
+ else
+ {
+ i_new_aspect = i_width * VOUT_ASPECT_FACTOR
+ * atof( val.psz_string )
+ / i_height;
+ }
+
+ free( val.psz_string );
+
+ if( i_new_aspect && i_new_aspect != i_aspect )
+ {
+ unsigned int i_aspect_x, i_aspect_y;
+
+ vout_AspectRatio( i_new_aspect, &i_aspect_x, &i_aspect_y );
+
+ msg_Dbg( p_vout, "overriding source aspect ratio to %i:%i",
+ i_aspect_x, i_aspect_y );
+
+ p_vout->render.i_aspect = i_new_aspect;
+
+ p_vout->b_override_aspect = VLC_TRUE;
+ }
+ }
+
+ /* Look for the default filter configuration */
+ var_Create( p_vout, "filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
+ var_Get( p_vout, "filter", &val );
+ p_vout->psz_filter_chain = val.psz_string;
+ }
+ else
+ {
+ /* continue the parent's filter chain */
+ char *psz_end;
+
+ psz_end = strchr( ((vout_thread_t *)p_parent)->psz_filter_chain, ':' );
+ if( psz_end && *(psz_end+1) )
+ p_vout->psz_filter_chain = strdup( psz_end+1 );
+ else p_vout->psz_filter_chain = NULL;
+ }
+
+ /* Choose the video output module */
+ if( !p_vout->psz_filter_chain || !*p_vout->psz_filter_chain )
+ {
+ var_Create( p_vout, "vout", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
+ var_Get( p_vout, "vout", &val );
+ psz_plugin = val.psz_string;
+ }
+ else
+ {
+ /* the filter chain is a string list of filters separated by double
+ * colons */
+ char *psz_end;
+
+ psz_end = strchr( p_vout->psz_filter_chain, ':' );
+ if( psz_end )
+ psz_plugin = strndup( p_vout->psz_filter_chain,
+ psz_end - p_vout->psz_filter_chain );
+ else psz_plugin = strdup( p_vout->psz_filter_chain );
+ }
+
+ /* Initialize the dimensions of the video window */
+ InitWindowSize( p_vout, &p_vout->i_window_width,
+ &p_vout->i_window_height );
+
+ /* Create the vout thread */
p_vout->p_module = module_Need( p_vout,
- ( p_vout->psz_filter_chain &&
- *p_vout->psz_filter_chain ) ?
- "video filter" : "video output",
- psz_plugin );
+ ( p_vout->psz_filter_chain && *p_vout->psz_filter_chain ) ?
+ "video filter" : "video output", psz_plugin, 0 );
if( psz_plugin ) free( psz_plugin );
if( p_vout->p_module == NULL )
return NULL;
}
+ p_vout->p_text_renderer_module =
+ module_Need( p_vout, "text renderer", NULL, 0 );
+ if( p_vout->p_text_renderer_module == NULL )
+ {
+ msg_Warn( p_vout, "no suitable text renderer module" );
+ p_vout->pf_add_string = NULL;
+ }
+
/* Create a few object variables for interface interaction */
var_Create( p_vout, "fullscreen", VLC_VAR_BOOL );
text.psz_string = _("Fullscreen");
if( var_Get( p_vout, "deinterlace-mode", &val ) == VLC_SUCCESS )
{
var_Set( p_vout, "deinterlace", val );
+ if( val.psz_string ) free( val.psz_string );
}
var_AddCallback( p_vout, "deinterlace", DeinterlaceCallback, NULL );
+
+ var_Create( p_vout, "filter", VLC_VAR_STRING );
+ text.psz_string = _("Filters");
+ var_Change( p_vout, "filter", VLC_VAR_SETTEXT, &text, NULL );
+ var_Change( p_vout, "filter", VLC_VAR_INHERITVALUE, &val, NULL );
+ if( val.psz_string )
+ {
+ var_Set( p_vout, "filter", val );
+ free( val.psz_string );
+ }
+ var_AddCallback( p_vout, "filter", FilterCallback, NULL );
+
/* Calculate delay created by internal caching */
p_input_thread = (input_thread_t *)vlc_object_find( p_vout,
VLC_OBJECT_INPUT, FIND_ANYWHERE );
* update using one of the THREAD_* constants.
*****************************************************************************/
void vout_Destroy( vout_thread_t *p_vout )
-{
+{
vlc_object_t *p_playlist;
-
+
/* Request thread destruction */
p_vout->b_die = VLC_TRUE;
vlc_thread_join( p_vout );
var_Destroy( p_vout, "intf-change" );
- p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
+ p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
FIND_ANYWHERE );
+ if( p_vout->psz_filter_chain ) free( p_vout->psz_filter_chain );
+
/* Free structure */
vlc_object_destroy( p_vout );
/* If it was the last vout, tell the interface to show up */
if( p_playlist != NULL )
{
- vout_thread_t *p_another_vout = vlc_object_find( p_playlist,
+ vout_thread_t *p_another_vout = vlc_object_find( p_playlist,
VLC_OBJECT_VOUT, FIND_ANYWHERE );
if( p_another_vout == NULL )
{
*****************************************************************************/
static int InitThread( vout_thread_t *p_vout )
{
- int i, i_pgcd;
+ int i;
+ unsigned int i_aspect_x, i_aspect_y;
vlc_mutex_lock( &p_vout->change_lock );
if( i_new_aspect && i_new_aspect != p_vout->output.i_aspect )
{
- int i_pgcd = ReduceHeight( i_new_aspect );
+ vout_AspectRatio( i_new_aspect, &i_aspect_x, &i_aspect_y );
+
msg_Dbg( p_vout, "output ratio forced to %i:%i\n",
- i_new_aspect / i_pgcd, VOUT_ASPECT_FACTOR / i_pgcd );
+ i_aspect_x, i_aspect_y );
p_vout->output.i_aspect = i_new_aspect;
}
}
}
#endif
- i_pgcd = ReduceHeight( p_vout->render.i_aspect );
+ vout_AspectRatio( p_vout->render.i_aspect, &i_aspect_x, &i_aspect_y );
msg_Dbg( p_vout,
"picture in %ix%i, chroma 0x%.8x (%4.4s), aspect ratio %i:%i",
p_vout->render.i_width, p_vout->render.i_height,
p_vout->render.i_chroma, (char*)&p_vout->render.i_chroma,
- p_vout->render.i_aspect / i_pgcd, VOUT_ASPECT_FACTOR / i_pgcd );
+ i_aspect_x, i_aspect_y );
- i_pgcd = ReduceHeight( p_vout->output.i_aspect );
+ vout_AspectRatio( p_vout->output.i_aspect, &i_aspect_x, &i_aspect_y );
msg_Dbg( p_vout,
"picture out %ix%i, chroma 0x%.8x (%4.4s), aspect ratio %i:%i",
p_vout->output.i_width, p_vout->output.i_height,
p_vout->output.i_chroma, (char*)&p_vout->output.i_chroma,
- p_vout->output.i_aspect / i_pgcd, VOUT_ASPECT_FACTOR / i_pgcd );
+ i_aspect_x, i_aspect_y );
/* Calculate shifts from system-updated masks */
MaskToShift( &p_vout->output.i_lrshift, &p_vout->output.i_rrshift,
p_vout->b_direct = 0;
/* Choose the best module */
- p_vout->chroma.p_module = module_Need( p_vout, "chroma", NULL );
+ p_vout->chroma.p_module = module_Need( p_vout, "chroma", NULL, 0 );
if( p_vout->chroma.p_module == NULL )
{
}
if( display_date >
- current_date + p_vout->i_pts_delay + VOUT_BOGUS_DELAY )
+ current_date + p_vout->i_pts_delay + VOUT_BOGUS_DELAY )
{
/* Picture is waaay too early: it will be destroyed */
vlc_mutex_lock( &p_vout->picture_lock );
*/
if( display_date != 0 && p_directbuffer != NULL )
{
- /* Store render time using a sliding mean */
- p_vout->render_time += mdate() - current_date;
- p_vout->render_time >>= 1;
+ mtime_t current_render_time = mdate() - current_date;
+ /* if render time is very large we don't include it in the mean */
+ if( current_render_time < p_vout->render_time +
+ VOUT_DISPLAY_DELAY )
+ {
+ /* Store render time using a sliding mean weighting to
+ * current value in a 3 to 1 ratio*/
+ p_vout->render_time *= 3;
+ p_vout->render_time += current_render_time;
+ p_vout->render_time >>= 2;
+ }
}
/* Give back change lock */
/* Sleep a while or until a given date */
if( display_date != 0 )
{
- mwait( display_date - VOUT_MWAIT_TOLERANCE );
+ /* If there are filters in the chain, better give them the picture
+ * in advance */
+ if( !p_vout->psz_filter_chain || !*p_vout->psz_filter_chain )
+ {
+ mwait( display_date - VOUT_MWAIT_TOLERANCE );
+ }
}
else
{
}
/* Need to reinitialise the chroma plugin */
- if( p_vout->chroma.p_module->pf_deactivate )
- p_vout->chroma.p_module->pf_deactivate( VLC_OBJECT(p_vout) );
- p_vout->chroma.p_module->pf_activate( VLC_OBJECT(p_vout) );
+ if( p_vout->chroma.p_module )
+ {
+ if( p_vout->chroma.p_module->pf_deactivate )
+ p_vout->chroma.p_module->pf_deactivate( VLC_OBJECT(p_vout) );
+ p_vout->chroma.p_module->pf_activate( VLC_OBJECT(p_vout) );
+ }
+ }
+
+ if( p_vout->i_changes & VOUT_PICTURE_BUFFERS_CHANGE )
+ {
+ /* This happens when the picture buffers need to be recreated.
+ * This is useful on multimonitor displays for instance.
+ *
+ * Warning: This only works when the vout creates only 1 picture
+ * buffer!! */
+ p_vout->i_changes &= ~VOUT_PICTURE_BUFFERS_CHANGE;
+
+ if( !p_vout->b_direct )
+ {
+ module_Unneed( p_vout, p_vout->chroma.p_module );
+ }
+
+ vlc_mutex_lock( &p_vout->picture_lock );
+
+ p_vout->pf_end( p_vout );
+
+ I_OUTPUTPICTURES = I_RENDERPICTURES = 0;
+
+ p_vout->b_error = InitThread( p_vout );
+
+ vlc_mutex_unlock( &p_vout->picture_lock );
}
}
}
}
+ if( p_vout->p_text_renderer_module )
+ module_Unneed( p_vout, p_vout->p_text_renderer_module );
+
/* Destroy translation tables */
p_vout->pf_end( p_vout );
{
int i_dummy = VOUT_ASPECT_FACTOR;
int i_pgcd = 1;
-
+
if( !i_ratio )
{
return i_pgcd;
static void InitWindowSize( vout_thread_t *p_vout, int *pi_width,
int *pi_height )
{
+ vlc_value_t val;
int i_width, i_height;
uint64_t ll_zoom;
#define FP_FACTOR 1000 /* our fixed point factor */
- i_width = config_GetInt( p_vout, "width" );
- i_height = config_GetInt( p_vout, "height" );
- ll_zoom = (uint64_t)( FP_FACTOR * config_GetFloat( p_vout, "zoom" ) );
+ var_Get( p_vout, "align", &val );
+ p_vout->i_alignment = val.i_int;
+
+ var_Get( p_vout, "width", &val );
+ i_width = val.i_int;
+ var_Get( p_vout, "height", &val );
+ i_height = val.i_int;
+ var_Get( p_vout, "zoom", &val );
+ ll_zoom = (uint64_t)( FP_FACTOR * val.f_float );
if( i_width > 0 && i_height > 0)
{
for( i = 0 ; i < p_input->stream.i_es_number ; i++ )
{
- if( ( ES->i_cat == VIDEO_ES ) && ES->p_decoder_fifo != NULL )
+ if( ( ES->i_cat == VIDEO_ES ) && ES->p_dec != NULL )
{
input_UnselectES( p_input, ES );
input_SelectES( p_input, ES );
var_Set( p_vout, "intf-change", val );
return VLC_SUCCESS;
}
+
+static int FilterCallback( vlc_object_t *p_this, char const *psz_cmd,
+ vlc_value_t oldval, vlc_value_t newval, void *p_data )
+{
+ vout_thread_t *p_vout = (vout_thread_t *)p_this;
+ input_thread_t *p_input;
+ vlc_value_t val;
+ unsigned int i;
+
+ p_input = (input_thread_t *)vlc_object_find( p_this, VLC_OBJECT_INPUT,
+ FIND_PARENT );
+
+ if (!p_input)
+ {
+ msg_Err( p_vout, "Input not found" );
+ return( VLC_EGENERIC );
+ }
+ /* Restart the video stream */
+ vlc_mutex_lock( &p_input->stream.stream_lock );
+
+ p_vout->b_filter_change = VLC_TRUE;
+
+#define ES p_input->stream.pp_es[i]
+
+ for( i = 0 ; i < p_input->stream.i_es_number ; i++ )
+ {
+ if( ( ES->i_cat == VIDEO_ES ) && ES->p_dec != NULL )
+ {
+ input_UnselectES( p_input, ES );
+ input_SelectES( p_input, ES );
+ }
+#undef ES
+ }
+ vlc_mutex_unlock( &p_input->stream.stream_lock );
+
+ vlc_object_release( p_input );
+
+ val.b_bool = VLC_TRUE;
+ var_Set( p_vout, "intf-change", val );
+ return VLC_SUCCESS;
+}
+