Commit 4684a91e authored by Gildas Bazin's avatar Gildas Bazin

* include/variables.h, src/misc/variables.c: you can now use var_Create() directly to create an object variable with an inherited value.
   eg. var_Create( p_vout, "zoom", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
   Beware, the object in which you create the var must be attached to a parent for this to work (otherwise we can't navigate the parents hierarchy to find the value to inherit).

* src/input/input.c, src/input/input_programs.c, src/video_output/video_output.c: converted more config_GetFoo() into var_Create()/var_Get();
parent 5b165b73
......@@ -2,7 +2,7 @@
* variables.h: variables handling
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: variables.h,v 1.14 2003/05/24 23:40:11 gbazin Exp $
* $Id: variables.h,v 1.15 2003/07/23 22:01:25 gbazin Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
......@@ -96,6 +96,9 @@ struct variable_t
#define VLC_VAR_ISCOMMAND 0x2000
#define VLC_VAR_ISCONFIG 0x2000
/* Creation flag */
#define VLC_VAR_DOINHERIT 0x8000
/*****************************************************************************
* Variable actions
*****************************************************************************/
......
......@@ -4,7 +4,7 @@
* decoders.
*****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
* $Id: input.c,v 1.234 2003/07/23 01:13:48 gbazin Exp $
* $Id: input.c,v 1.235 2003/07/23 22:01:25 gbazin Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
......@@ -86,22 +86,15 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
ParseOption( p_input, p_item->ppsz_options[i] );
}
/* Create a few object variables we'll need later */
if( !var_Type( p_input, "sout" ) )
{
var_Create( p_input, "sout", VLC_VAR_STRING );
var_Change( p_input, "sout", VLC_VAR_INHERITVALUE, NULL, NULL );
}
if( !var_Type( p_input, "sout-audio" ) )
{
var_Create( p_input, "sout-audio", VLC_VAR_BOOL );
var_Change( p_input, "sout-audio", VLC_VAR_INHERITVALUE, NULL, NULL );
}
if( !var_Type( p_input, "sout-video" ) )
{
var_Create( p_input, "sout-video", VLC_VAR_BOOL );
var_Change( p_input, "sout-video", VLC_VAR_INHERITVALUE, NULL, NULL );
}
/* Create a few object variables we'll need later on */
var_Create( p_input, "video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
var_Create( p_input, "audio", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
var_Create( p_input, "audio-channel", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
var_Create( p_input, "spu-channel", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
var_Create( p_input, "sout", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
var_Create( p_input, "sout-audio", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
var_Create( p_input, "sout-video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
/* Initialize thread properties */
p_input->b_eof = 0;
......@@ -547,7 +540,7 @@ static int InitThread( input_thread_t * p_input )
/* Initialize optional stream output. */
var_Get( p_input, "sout", &val );
if ( val.psz_string != NULL )
if( val.psz_string != NULL )
{
if ( *val.psz_string && (p_input->stream.p_sout =
sout_NewInstance( p_input, val.psz_string )) == NULL )
......
......@@ -2,7 +2,7 @@
* input_programs.c: es_descriptor_t, pgrm_descriptor_t management
*****************************************************************************
* Copyright (C) 1999-2002 VideoLAN
* $Id: input_programs.c,v 1.114 2003/05/18 23:16:57 fenrir Exp $
* $Id: input_programs.c,v 1.115 2003/07/23 22:01:25 gbazin Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
......@@ -427,11 +427,14 @@ int input_SetProgram( input_thread_t * p_input, pgrm_descriptor_t * p_new_prg )
#undef p_es
}
}
/* Get the number of the required audio stream */
if( config_GetInt( p_input, "audio" ) )
var_Get( p_input, "audio", &val );
if( val.b_bool )
{
/* Default is the first one */
i_required_audio_es = config_GetInt( p_input, "audio-channel" );
var_Get( p_input, "audio-channel", &val );
i_required_audio_es = val.i_int;
if( i_required_audio_es < 0 )
{
i_required_audio_es = 1;
......@@ -443,10 +446,12 @@ int input_SetProgram( input_thread_t * p_input, pgrm_descriptor_t * p_new_prg )
}
/* Same thing for subtitles */
if( config_GetInt( p_input, "video" ) )
var_Get( p_input, "video", &val );
if( val.b_bool )
{
/* for spu, default is none */
i_required_spu_es = config_GetInt( p_input, "spu-channel" );
var_Get( p_input, "spu-channel", &val );
i_required_spu_es = val.i_int;
if( i_required_spu_es < 0 )
{
i_required_spu_es = 0;
......@@ -821,19 +826,26 @@ int input_SelectES( input_thread_t * p_input, es_descriptor_t * p_es )
return -1;
}
if( ((p_es->i_cat == VIDEO_ES) || (p_es->i_cat == SPU_ES))
&& !config_GetInt( p_input, "video" ) )
if( p_es->i_cat == VIDEO_ES || p_es->i_cat == SPU_ES )
{
msg_Dbg( p_input,
"video is disabled, not selecting ES 0x%x", p_es->i_id );
return -1;
var_Get( p_input, "video", &val );
if( !val.b_bool )
{
msg_Dbg( p_input, "video is disabled, not selecting ES 0x%x",
p_es->i_id );
return -1;
}
}
if( (p_es->i_cat == AUDIO_ES) && !config_GetInt( p_input, "audio" ) )
if( p_es->i_cat == AUDIO_ES )
{
msg_Dbg( p_input,
"audio is disabled, not selecting ES 0x%x", p_es->i_id );
return -1;
var_Get( p_input, "audio", &val );
if( !val.b_bool )
{
msg_Dbg( p_input, "audio is disabled, not selecting ES 0x%x",
p_es->i_id );
return -1;
}
}
msg_Dbg( p_input, "selecting ES 0x%x", p_es->i_id );
......
......@@ -2,7 +2,7 @@
* variables.c: routines for object variables handling
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: variables.c,v 1.27 2003/07/22 15:59:06 gbazin Exp $
* $Id: variables.c,v 1.28 2003/07/23 22:01:25 gbazin Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
......@@ -159,7 +159,7 @@ int __var_Create( vlc_object_t *p_this, const char *psz_name, int i_type )
if( i_new >= 0 )
{
/* If the types differ, variable creation failed. */
if( i_type != p_this->p_vars[i_new].i_type )
if( (i_type & ~VLC_VAR_DOINHERIT) != p_this->p_vars[i_new].i_type )
{
vlc_mutex_unlock( &p_this->var_lock );
return VLC_EBADVAR;
......@@ -190,7 +190,7 @@ int __var_Create( vlc_object_t *p_this, const char *psz_name, int i_type )
p_var->psz_name = strdup( psz_name );
p_var->psz_text = NULL;
p_var->i_type = i_type;
p_var->i_type = i_type & ~VLC_VAR_DOINHERIT;
memset( &p_var->val, 0, sizeof(vlc_value_t) );
p_var->pf_dup = DupDummy;
......@@ -261,6 +261,22 @@ int __var_Create( vlc_object_t *p_this, const char *psz_name, int i_type )
/* Duplicate the default data we stored. */
p_var->pf_dup( &p_var->val );
if( i_type & VLC_VAR_DOINHERIT )
{
vlc_value_t val;
if( InheritValue( p_this, psz_name, &val, p_var->i_type )
== VLC_SUCCESS );
{
/* Free data if needed */
p_var->pf_free( &p_var->val );
/* Check boundaries and list */
CheckValue( p_var, &val );
/* Set the variable */
p_var->val = val;
}
}
vlc_mutex_unlock( &p_this->var_lock );
return VLC_SUCCESS;
......@@ -1142,7 +1158,6 @@ static int InheritValue( vlc_object_t *p_this, const char *psz_name,
p_var->pf_dup( p_val );
vlc_mutex_unlock( &p_this->p_parent->var_lock );
return VLC_SUCCESS;
}
......
......@@ -5,7 +5,7 @@
* thread, and destroy a previously oppened video output thread.
*****************************************************************************
* Copyright (C) 2000-2001 VideoLAN
* $Id: video_output.c,v 1.229 2003/07/14 21:32:59 sigmunau Exp $
* $Id: video_output.c,v 1.230 2003/07/23 22:01:25 gbazin Exp $
*
* Authors: Vincent Seguin <seguin@via.ecp.fr>
*
......@@ -216,38 +216,116 @@ vout_thread_t * __vout_Create( vlc_object_t *p_parent,
return NULL;
}
/* 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->p_picture[i_index].pf_lock = NULL;
p_vout->p_picture[i_index].pf_unlock = NULL;
p_vout->p_picture[i_index].i_status = FREE_PICTURE;
p_vout->p_picture[i_index].i_type = EMPTY_PICTURE;
}
for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++)
{
p_vout->p_subpicture[i_index].i_status = FREE_SUBPICTURE;
p_vout->p_subpicture[i_index].i_type = EMPTY_SUBPICTURE;
}
/* No images in the heap */
p_vout->i_heap_size = 0;
/* Initialize the rendering heap */
I_RENDERPICTURES = 0;
p_vout->render.i_width = i_width;
p_vout->render.i_height = i_height;
p_vout->render.i_chroma = i_chroma;
p_vout->render.i_aspect = i_aspect;
p_vout->render.i_rmask = 0;
p_vout->render.i_gmask = 0;
p_vout->render.i_bmask = 0;
p_vout->render.i_last_used_pic = -1;
p_vout->render.b_allow_modify_pics = 1;
/* Zero the output heap */
I_OUTPUTPICTURES = 0;
p_vout->output.i_width = 0;
p_vout->output.i_height = 0;
p_vout->output.i_chroma = 0;
p_vout->output.i_aspect = 0;
p_vout->output.i_rmask = 0;
p_vout->output.i_gmask = 0;
p_vout->output.i_bmask = 0;
/* Initialize misc stuff */
p_vout->i_changes = 0;
p_vout->f_gamma = 0;
p_vout->b_grayscale = 0;
p_vout->b_info = 0;
p_vout->b_interface = 0;
p_vout->b_scale = 1;
p_vout->b_fullscreen = 0;
p_vout->render_time = 10;
p_vout->c_fps_samples = 0;
p_vout->b_filter_change = 0;
/* Mouse coordinates */
var_Create( p_vout, "mouse-x", VLC_VAR_INTEGER );
var_Create( p_vout, "mouse-y", 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 );
var_Create( p_vout, "intf-change", VLC_VAR_BOOL );
val.b_bool = VLC_TRUE;
var_Set( p_vout, "intf-change", val );
/* 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 );
/* Create a few object variables we'll need later on */
var_Create( p_vout, "aspect-ratio", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
var_Create( p_vout, "width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Create( p_vout, "height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Create( p_vout, "zoom", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
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" );
var_Get( p_vout, "aspect-ratio", &val );
/* Check whether the user tried to override aspect ratio */
if( psz_aspect )
if( val.psz_string )
{
unsigned int i_new_aspect = i_aspect;
char *psz_parser = strchr( psz_aspect, ':' );
char *psz_parser = strchr( val.psz_string, ':' );
if( psz_parser )
{
*psz_parser++ = '\0';
i_new_aspect = atoi( psz_aspect ) * VOUT_ASPECT_FACTOR
/ atoi( psz_parser );
i_new_aspect = atoi( val.psz_string ) * VOUT_ASPECT_FACTOR
/ atoi( psz_parser );
}
else
{
i_new_aspect = i_width * VOUT_ASPECT_FACTOR
* atof( psz_aspect )
* atof( val.psz_string )
/ i_height;
}
free( psz_aspect );
free( val.psz_string );
if( i_new_aspect && i_new_aspect != i_aspect )
{
......@@ -256,14 +334,16 @@ vout_thread_t * __vout_Create( vlc_object_t *p_parent,
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->render.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" );
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
{
......@@ -279,7 +359,9 @@ vout_thread_t * __vout_Create( vlc_object_t *p_parent,
/* Choose the video output module */
if( !p_vout->psz_filter_chain || !*p_vout->psz_filter_chain )
{
psz_plugin = config_GetPsz( p_parent, "vout" );
var_Create( p_vout, "vout", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
var_Get( p_vout, "vout", &val );
psz_plugin = val.psz_string;
}
else
{
......@@ -294,81 +376,11 @@ vout_thread_t * __vout_Create( vlc_object_t *p_parent,
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->p_picture[i_index].pf_lock = NULL;
p_vout->p_picture[i_index].pf_unlock = NULL;
p_vout->p_picture[i_index].i_status = FREE_PICTURE;
p_vout->p_picture[i_index].i_type = EMPTY_PICTURE;
}
for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++)
{
p_vout->p_subpicture[i_index].i_status = FREE_SUBPICTURE;
p_vout->p_subpicture[i_index].i_type = EMPTY_SUBPICTURE;
}
/* No images in the heap */
p_vout->i_heap_size = 0;
/* Initialize the rendering heap */
I_RENDERPICTURES = 0;
p_vout->render.i_width = i_width;
p_vout->render.i_height = i_height;
p_vout->render.i_chroma = i_chroma;
p_vout->render.i_aspect = i_aspect;
p_vout->render.i_rmask = 0;
p_vout->render.i_gmask = 0;
p_vout->render.i_bmask = 0;
p_vout->render.i_last_used_pic = -1;
p_vout->render.b_allow_modify_pics = 1;
/* Zero the output heap */
I_OUTPUTPICTURES = 0;
p_vout->output.i_width = 0;
p_vout->output.i_height = 0;
p_vout->output.i_chroma = 0;
p_vout->output.i_aspect = 0;
p_vout->output.i_rmask = 0;
p_vout->output.i_gmask = 0;
p_vout->output.i_bmask = 0;
/* Initialize misc stuff */
p_vout->i_changes = 0;
p_vout->f_gamma = 0;
p_vout->b_grayscale = 0;
p_vout->b_info = 0;
p_vout->b_interface = 0;
p_vout->b_scale = 1;
p_vout->b_fullscreen = 0;
p_vout->render_time = 10;
p_vout->c_fps_samples = 0;
p_vout->b_filter_change = 0;
/* Mouse coordinates */
var_Create( p_vout, "mouse-x", VLC_VAR_INTEGER );
var_Create( p_vout, "mouse-y", 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 );
/* Create thread and set 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 );
vlc_object_attach( p_vout, p_parent );
/* Create the vout thread */
p_vout->p_module = module_Need( p_vout,
( p_vout->psz_filter_chain &&
*p_vout->psz_filter_chain ) ?
......@@ -1157,14 +1169,18 @@ static void MaskToShift( int *pi_left, int *pi_right, uint32_t i_mask )
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, "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)
{
......
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