Commit 1f7592ff authored by Jean-Paul Saman's avatar Jean-Paul Saman

Refactor osdmenu parsing logic.

parent 7d39628d
......@@ -88,6 +88,7 @@ static inline int spu_vaControl( spu_t *p_spu, int i_query, va_list args )
else
return VLC_EGENERIC;
}
static inline int spu_Control( spu_t *p_spu, int i_query, ... )
{
va_list args;
......@@ -270,8 +271,6 @@ struct text_style_t
static const text_style_t default_text_style = { NULL, 22, 0xffffff, 0xff, STYLE_OUTLINE,
0x000000, 0xff, 0x000000, 0xff, 0xffffff, 0x80, 0xffffff, 0xff, 1, 0, -1 };
/**
* OSD menu button states
*
......@@ -286,6 +285,8 @@ static const text_style_t default_text_style = { NULL, 22, 0xffffff, 0xff, STYLE
#define OSD_BUTTON_SELECT 1
#define OSD_BUTTON_PRESSED 2
static const char *ppsz_button_states[] = { "unselect", "select", "pressed" };
/**
* OSD State object
*
......
/*****************************************************************************
* parser.c : OSD import module
* parser.c : OSD import module
*****************************************************************************
* Copyright (C) 2007 M2X
* $Id: $
......@@ -41,12 +41,12 @@
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static const char *ppsz_button_states[] = { "unselect", "select", "pressed" };
/*****************************************************************************
* Create a new Menu structure
*****************************************************************************/
osd_menu_t *osd_MenuNew( osd_menu_t *p_menu, const char *psz_path, int i_x, int i_y )
osd_menu_t *osd_MenuNew( osd_menu_t *p_menu, const char *psz_path,
int i_x, int i_y )
{
if( !p_menu ) return NULL;
......@@ -62,6 +62,7 @@ osd_menu_t *osd_MenuNew( osd_menu_t *p_menu, const char *psz_path, int i_x, int
p_menu->psz_path = strdup( psz_path );
else
p_menu->psz_path = NULL;
p_menu->i_x = i_x;
p_menu->i_y = i_y;
p_menu->i_style = OSD_MENU_STYLE_SIMPLE;
......@@ -72,15 +73,17 @@ osd_menu_t *osd_MenuNew( osd_menu_t *p_menu, const char *psz_path, int i_x, int
/*****************************************************************************
* Free the menu
*****************************************************************************/
void osd_MenuFree( vlc_object_t *p_this, osd_menu_t *p_menu )
void osd_MenuFree( osd_menu_t *p_menu )
{
msg_Dbg( p_this, "freeing menu" );
osd_ButtonFree( p_this, p_menu->p_button );
msg_Dbg( p_menu, "freeing menu" );
osd_ButtonFree( p_menu, p_menu->p_button );
if( p_menu->psz_path ) free( p_menu->psz_path );
if( p_menu->p_state ) free( p_menu->p_state );
p_menu->p_button = NULL;
p_menu->p_last_button = NULL;
if( p_menu->psz_path ) free( p_menu->psz_path );
p_menu->psz_path = NULL;
if( p_menu->p_state ) free( p_menu->p_state );
p_menu->p_state = NULL;
}
......@@ -107,7 +110,7 @@ osd_button_t *osd_ButtonNew( const char *psz_action, int i_x, int i_y )
/*****************************************************************************
* Free a button
*****************************************************************************/
void osd_ButtonFree( vlc_object_t *p_this, osd_button_t *p_button )
void osd_ButtonFree( osd_menu_t *p_menu, osd_button_t *p_button )
{
osd_button_t *p_current = p_button;
osd_button_t *p_next = NULL;
......@@ -122,7 +125,8 @@ void osd_ButtonFree( vlc_object_t *p_this, osd_button_t *p_button )
/* Then free end first and walk to the start. */
while( p_current->p_prev )
{
msg_Dbg( p_this, "+ freeing button %s [%p]", p_current->psz_action, p_current );
msg_Dbg( p_menu, "+ freeing button %s [%p]",
p_current->psz_action, p_current );
p_prev = p_current->p_prev;
p_current = p_prev;
if( p_current->p_next )
......@@ -138,16 +142,13 @@ void osd_ButtonFree( vlc_object_t *p_this, osd_button_t *p_button )
if( p_current->p_feedback )
free( p_current->p_feedback );
p_current->p_next->psz_action_down = NULL;
p_current->p_next->psz_action = NULL;
p_current->p_next->psz_name = NULL;
p_current->p_feedback = NULL;
/* Free all states first */
if( p_current->p_next->p_states )
osd_StatesFree( p_this, p_current->p_next->p_states );
p_current->p_next->p_states = NULL;
if( p_current->p_next) free( p_current->p_next );
osd_StatesFree( p_menu, p_current->p_next->p_states );
free( p_current->p_next );
p_current->p_next = NULL;
}
......@@ -164,23 +165,20 @@ void osd_ButtonFree( vlc_object_t *p_this, osd_button_t *p_button )
if( p_current->p_feedback )
free( p_current->p_feedback );
p_current->p_up->psz_action_down = NULL;
p_current->p_up->psz_action = NULL;
p_current->p_up->psz_name = NULL;
p_current->p_feedback = NULL;
/* Free all states first */
if( p_current->p_up->p_states )
osd_StatesFree( p_this, p_current->p_up->p_states );
p_current->p_up->p_states = NULL;
if( p_current->p_up ) free( p_current->p_up );
osd_StatesFree( p_menu, p_current->p_up->p_states );
free( p_current->p_up );
p_current->p_up = NULL;
}
}
/* Free the last one. */
if( p_button )
{
msg_Dbg( p_this, "+ freeing button %s [%p]", p_button->psz_action, p_button );
msg_Dbg( p_menu, "+ freeing button %s [%p]",
p_button->psz_action, p_button );
if( p_button->psz_name ) free( p_button->psz_name );
if( p_button->psz_action ) free( p_button->psz_action );
if( p_button->psz_action_down ) free( p_button->psz_action_down );
......@@ -188,15 +186,11 @@ void osd_ButtonFree( vlc_object_t *p_this, osd_button_t *p_button )
free( p_current->p_feedback->p_data_orig );
if( p_current->p_feedback )
free( p_current->p_feedback );
p_button->psz_name = NULL;
p_button->psz_action = NULL;
p_button->psz_action_down = NULL;
p_current->p_feedback = NULL;
if( p_button->p_states )
osd_StatesFree( p_this, p_button->p_states );
p_button->p_states = NULL;
osd_StatesFree( p_menu, p_button->p_states );
free( p_button );
p_button = NULL;
}
......@@ -205,9 +199,9 @@ void osd_ButtonFree( vlc_object_t *p_this, osd_button_t *p_button )
/*****************************************************************************
* Create a new state image
*****************************************************************************/
osd_state_t *osd_StateNew( vlc_object_t *p_this, const char *psz_file, const char *psz_state )
osd_state_t *osd_StateNew( osd_menu_t *p_menu, const char *psz_file,
const char *psz_state )
{
osd_menu_t *p_this;
osd_state_t *p_state = NULL;
video_format_t fmt_in, fmt_out;
......@@ -216,14 +210,13 @@ osd_state_t *osd_StateNew( vlc_object_t *p_this, const char *psz_file, const cha
return NULL;
memset( p_state, 0, sizeof(osd_state_t) );
memset( &fmt_in, 0, sizeof(video_format_t) );
memset( &fmt_out, 0, sizeof(video_format_t) );
fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
if( p_osd->p_image )
if( p_menu->p_image )
{
p_state->p_pic = image_ReadUrl( p_osd->p_image, p_osd->psz_file,
p_state->p_pic = image_ReadUrl( p_menu->p_image, p_menu->psz_file,
&fmt_in, &fmt_out );
}
......@@ -246,7 +239,7 @@ osd_state_t *osd_StateNew( vlc_object_t *p_this, const char *psz_file, const cha
/*****************************************************************************
* Free state images
*****************************************************************************/
void osd_StatesFree( vlc_object_t *p_this, osd_state_t *p_states )
void osd_StatesFree( osd_menu_t *p_menu, osd_state_t *p_states )
{
osd_state_t *p_state = p_states;
osd_state_t *p_next = NULL;
......@@ -260,17 +253,20 @@ void osd_StatesFree( vlc_object_t *p_this, osd_state_t *p_states )
/* Then free end first and walk to the start. */
while( p_state->p_prev )
{
msg_Dbg( p_this, " |- freeing state %s [%p]", p_state->psz_state, p_state );
msg_Dbg( p_menu, " |- freeing state %s [%p]",
p_state->psz_state, p_state );
p_prev = p_state->p_prev;
p_state = p_prev;
if( p_state->p_next )
{
if( p_state->p_next->p_pic && p_state->p_next->p_pic->p_data_orig )
free( p_state->p_next->p_pic->p_data_orig );
if( p_state->p_next->p_pic ) free( p_state->p_next->p_pic );
p_state->p_next->p_pic = NULL;
if( p_state->p_next->psz_state ) free( p_state->p_next->psz_state );
p_state->p_next->psz_state = NULL;
if( p_state->p_next->p_pic )
{
if( p_state->p_next->p_pic->p_data_orig )
free( p_state->p_next->p_pic->p_data_orig );
free( p_state->p_next->p_pic );
}
if( p_state->p_next->psz_state )
free( p_state->p_next->psz_state );
free( p_state->p_next );
p_state->p_next = NULL;
}
......@@ -278,13 +274,15 @@ void osd_StatesFree( vlc_object_t *p_this, osd_state_t *p_states )
/* Free the last one. */
if( p_states )
{
msg_Dbg( p_this, " |- freeing state %s [%p]", p_state->psz_state, p_states );
if( p_states->p_pic && p_states->p_pic->p_data_orig )
free( p_states->p_pic->p_data_orig );
if( p_states->p_pic ) free( p_states->p_pic );
p_states->p_pic = NULL;
msg_Dbg( p_menu, " |- freeing state %s [%p]",
p_state->psz_state, p_states );
if( p_states->p_pic )
{
if( p_states->p_pic->p_data_orig )
free( p_states->p_pic->p_data_orig );
free( p_states->p_pic );
}
if( p_state->psz_state ) free( p_state->psz_state );
p_state->psz_state = NULL;
free( p_states );
p_states = NULL;
}
......
......@@ -29,11 +29,11 @@
*/
osd_menu_t *osd_MenuNew( osd_menu_t *, const char *, int, int );
osd_button_t *osd_ButtonNew( const char *, int, int );
osd_state_t *osd_StateNew( vlc_object_t *, const char *, const char * );
osd_state_t *osd_StateNew( osd_menu_t *, const char *, const char * );
void osd_MenuFree ( vlc_object_t *, osd_menu_t * );
void osd_ButtonFree( vlc_object_t *, osd_button_t * );
void osd_StatesFree( vlc_object_t *, osd_state_t * );
void osd_MenuFree ( osd_menu_t * );
void osd_ButtonFree( osd_menu_t *, osd_button_t * );
void osd_StatesFree( osd_menu_t *, osd_state_t * );
#endif
......@@ -38,8 +38,8 @@
/***************************************************************************
* Prototypes
***************************************************************************/
int E_(osd_parser_simpleOpen) ( vlc_object_t *p_this );
int E_(osd_parser_xmlOpen) ( vlc_object_t *p_this );
int osd_parser_simpleOpen ( vlc_object_t *p_this );
int osd_parser_xmlOpen ( vlc_object_t *p_this );
static void osd_parser_Close( vlc_object_t *p_this );
......@@ -48,20 +48,20 @@ static void osd_parser_Close( vlc_object_t *p_this );
*****************************************************************************/
vlc_module_begin();
set_category( CAT_MISC );
set_category( CAT_OSD );
set_subcategory( SUBCAT_OSD_IMPORT );
add_submodule();
set_description( _("OSD configuration importer") );
add_shortcut( "import-osd" );
set_capability( "osd parser" , 0);
set_callbacks( E_(osd_parser_simpleOpen), osd_parser_Close );
set_callbacks( osd_parser_simpleOpen, osd_parser_Close );
add_submodule();
set_description( _("XML OSD configuration importer") );
add_shortcut( "import-osd-xml" );
set_capability( "osd parser" , 0);
set_callbacks( E_(osd_parser_xmlOpen), osd_parser_Close );
set_callbacks( osd_parser_xmlOpen, osd_parser_Close );
vlc_module_end();
......@@ -73,5 +73,5 @@ void osd_parser_Close ( vlc_object_t *p_this )
{
osd_menu_t *p_menu = (osd_menu_t *) p_this;
if( p_menu )
osd_MenuFree( p_this, &p_menu );
osd_MenuFree( p_menu );
}
......@@ -34,12 +34,16 @@
#include <vlc_osd.h>
#include <vlc_charset.h>
#include "osd_menu.h"
int osd_parser_simpleOpen( vlc_object_t *p_this );
/*****************************************************************************
* osd_ConfigLoader: Load and parse osd text configurationfile
* Simple parser open function
*****************************************************************************/
int E_(osd_parser_simpleOpen) ( vlc_object_t *p_this )
int osd_parser_simpleOpen( vlc_object_t *p_this )
{
osd_menu_t *p_menu = (osd_menu_t *) p_this->p_menu;
osd_menu_t *p_menu = (osd_menu_t *) p_this;
osd_button_t *p_current = NULL; /* button currently processed */
osd_button_t *p_prev = NULL; /* previous processed button */
......@@ -47,11 +51,14 @@ int E_(osd_parser_simpleOpen) ( vlc_object_t *p_this )
FILE *fd = NULL;
int result = 0;
if( !p_menu ) return VLC_ENOOBJ;
msg_Dbg( p_this, "opening osdmenu definition file %s", p_menu->psz_file );
fd = utf8_fopen( p_menu->psz_file, "r" );
if( !fd )
{
msg_Err( p_this, "failed to open osdmenu definition file %s", p_menu->psz_file );
msg_Err( p_this, "failed to open osdmenu definition file %s",
p_menu->psz_file );
return VLC_EGENERIC;
}
......@@ -96,9 +103,9 @@ int E_(osd_parser_simpleOpen) ( vlc_object_t *p_this )
msg_Dbg( p_this, "osdmenu dir %s", &path[0] );
if( i_len == 0 )
*p_menu = osd_MenuNew( *p_menu, NULL, 0, 0 );
p_menu = osd_MenuNew( p_menu, NULL, 0, 0 );
else
*p_menu = osd_MenuNew( *p_menu, &path[0], 0, 0 );
p_menu = osd_MenuNew( p_menu, &path[0], 0, 0 );
/* Peek for 'style' argument */
pos = ftell( fd );
......@@ -114,11 +121,11 @@ int E_(osd_parser_simpleOpen) ( vlc_object_t *p_this )
{
if( strncmp( &action[0], "default", 7) == 0 )
{
(*p_menu)->i_style = OSD_MENU_STYLE_SIMPLE;
p_menu->i_style = OSD_MENU_STYLE_SIMPLE;
}
else if( strncmp( &action[0], "concat", 6) == 0 )
{
(*p_menu)->i_style = OSD_MENU_STYLE_CONCAT;
p_menu->i_style = OSD_MENU_STYLE_CONCAT;
}
}
else
......@@ -129,7 +136,7 @@ int E_(osd_parser_simpleOpen) ( vlc_object_t *p_this )
}
}
if( !*p_menu )
if( !p_menu )
goto error;
/* read successive lines */
......@@ -161,7 +168,7 @@ int E_(osd_parser_simpleOpen) ( vlc_object_t *p_this )
if( p_prev )
p_prev->p_next = p_current;
else
(*p_menu)->p_button = p_current;
p_menu->p_button = p_current;
p_current->p_prev = p_prev;
/* parse all states */
......@@ -197,7 +204,7 @@ int E_(osd_parser_simpleOpen) ( vlc_object_t *p_this )
{
if( strncmp( &type[0], "volume", 6 ) == 0 )
{
(*p_menu)->p_state->p_volume = p_up;
p_menu->p_state->p_volume = p_up;
msg_Dbg( p_this, " + type=%s", &type[0] );
}
}
......@@ -223,7 +230,7 @@ int E_(osd_parser_simpleOpen) ( vlc_object_t *p_this )
goto error;
msg_Dbg( p_this, " + (menu up) hotkey down %s, file=%s%s",
&action[0], (*p_menu)->psz_path, &file[0] );
&action[0], p_menu->psz_path, &file[0] );
if( p_up->psz_action_down ) free( p_up->psz_action_down );
p_up->psz_action_down = strdup( &action[0] );
......@@ -245,19 +252,19 @@ int E_(osd_parser_simpleOpen) ( vlc_object_t *p_this )
p_range_prev = p_range_current;
if( (*p_menu)->psz_path )
if( p_menu->psz_path )
{
size_t i_path_size = strlen( (*p_menu)->psz_path );
size_t i_path_size = strlen( p_menu->psz_path );
size_t i_file_size = strlen( &file[0] );
strncpy( &path[0], (*p_menu)->psz_path, i_path_size );
strncpy( &path[0], p_menu->psz_path, i_path_size );
strncpy( &path[i_path_size], &file[0], 512 - (i_path_size + i_file_size) );
path[ i_path_size + i_file_size ] = '\0';
p_range_current = osd_StateNew( p_this, &path[0], "pressed" );
p_range_current = osd_StateNew( p_menu, &path[0], "pressed" );
}
else /* absolute paths are used. */
p_range_current = osd_StateNew( p_this, &file[0], "pressed" );
p_range_current = osd_StateNew( p_menu, &file[0], "pressed" );
if( !p_range_current || !p_range_current->p_pic )
goto error;
......@@ -272,8 +279,8 @@ int E_(osd_parser_simpleOpen) ( vlc_object_t *p_this )
p_range_current->p_prev = p_range_prev;
msg_Dbg( p_this, " |- range=%d, file=%s%s",
p_up->i_ranges,
(*p_menu)->psz_path, &file[0] );
p_up->i_ranges,
p_menu->psz_path, &file[0] );
}
if( i_index > 0 )
{
......@@ -319,8 +326,10 @@ int E_(osd_parser_simpleOpen) ( vlc_object_t *p_this )
if( result == 0 )
goto error;
msg_Dbg( p_this, " + hotkey down %s, file=%s%s", &action[0], (*p_menu)->psz_path, &file[0] );
if( p_current->psz_action_down ) free( p_current->psz_action_down );
msg_Dbg( p_this, " + hotkey down %s, file=%s%s",
&action[0], p_menu->psz_path, &file[0] );
if( p_current->psz_action_down )
free( p_current->psz_action_down );
p_current->psz_action_down = strdup( &action[0] );
/* Parse range contstruction :
......@@ -340,19 +349,19 @@ int E_(osd_parser_simpleOpen) ( vlc_object_t *p_this )
p_range_prev = p_range_current;
if( (*p_menu)->psz_path )
if( p_menu->psz_path )
{
size_t i_path_size = strlen( (*p_menu)->psz_path );
size_t i_path_size = strlen( p_menu->psz_path );
size_t i_file_size = strlen( &file[0] );
strncpy( &path[0], (*p_menu)->psz_path, i_path_size );
strncpy( &path[0], p_menu->psz_path, i_path_size );
strncpy( &path[i_path_size], &file[0], 512 - (i_path_size + i_file_size) );
path[ i_path_size + i_file_size ] = '\0';
p_range_current = osd_StateNew( p_this, &path[0], "pressed" );
p_range_current = osd_StateNew( p_menu, &path[0], "pressed" );
}
else /* absolute paths are used. */
p_range_current = osd_StateNew( p_this, &file[0], "pressed" );
p_range_current = osd_StateNew( p_menu, &file[0], "pressed" );
if( !p_range_current || !p_range_current->p_pic )
goto error;
......@@ -367,8 +376,8 @@ int E_(osd_parser_simpleOpen) ( vlc_object_t *p_this )
p_range_current->p_prev = p_range_prev;
msg_Dbg( p_this, " |- range=%d, file=%s%s",
p_current->i_ranges,
(*p_menu)->psz_path, &file[0] );
p_current->i_ranges,
p_menu->psz_path, &file[0] );
}
if( i_index > 0 )
{
......@@ -407,19 +416,19 @@ int E_(osd_parser_simpleOpen) ( vlc_object_t *p_this )
goto error;
}
if( (*p_menu)->psz_path )
if( p_menu->psz_path )
{
size_t i_path_size = strlen( (*p_menu)->psz_path );
size_t i_path_size = strlen( p_menu->psz_path );
size_t i_file_size = strlen( &file[0] );
strncpy( &path[0], (*p_menu)->psz_path, i_path_size );
strncpy( &path[0], p_menu->psz_path, i_path_size );
strncpy( &path[i_path_size], &file[0], 512 - (i_path_size + i_file_size) );
path[ i_path_size + i_file_size ] = '\0';
p_state_current = osd_StateNew( p_this, &path[0], &state[0] );
p_state_current = osd_StateNew( p_menu, &path[0], &state[0] );
}
else /* absolute paths are used. */
p_state_current = osd_StateNew( p_this, &file[0], &state[0] );
p_state_current = osd_StateNew( p_menu, &file[0], &state[0] );
if( !p_state_current || !p_state_current->p_pic )
goto error;
......@@ -430,7 +439,8 @@ int E_(osd_parser_simpleOpen) ( vlc_object_t *p_this )
p_current->p_states = p_state_current;
p_state_current->p_prev = p_state_prev;
msg_Dbg( p_this, " |- state=%s, file=%s%s", &state[0], (*p_menu)->psz_path, &file[0] );
msg_Dbg( p_this, " |- state=%s, file=%s%s", &state[0],
p_menu->psz_path, &file[0] );
}
p_current->p_current_state = p_current->p_states;
}
......@@ -438,21 +448,21 @@ int E_(osd_parser_simpleOpen) ( vlc_object_t *p_this )
/* Find the last button and store its pointer.
* The OSD menu behaves like a roundrobin list.
*/
p_current = (*p_menu)->p_button;
p_current = p_menu->p_button;
while( p_current && p_current->p_next )
{
osd_button_t *p_temp = NULL;
p_temp = p_current->p_next;
p_current = p_temp;
}
(*p_menu)->p_last_button = p_current;
p_menu->p_last_button = p_current;
fclose( fd );
return VLC_SUCCESS;
#undef MAX_FILE_PATH
error:
msg_Err( p_this, "parsing file failed (returned %d)", result );
osd_MenuFree( p_this, *p_menu );
msg_Err( p_menu, "parsing file failed (returned %d)", result );
osd_MenuFree( p_menu );
fclose( fd );
return VLC_EGENERIC;
}
......@@ -34,38 +34,17 @@
#include <vlc_osd.h>
#include <vlc_charset.h>
/***************************************************************************
* Prototypes
***************************************************************************/
#include "osd_menu.h"
static int E_(osd_parser_xmlOpen) ( vlc_object_t *p_this );
static void E_(osd_parser_xmlClose)( vlc_object_t *p_this );
/*****************************************************************************
* Module descriptor
*****************************************************************************/
vlc_module_begin();
set_category( CAT_MISC );
set_subcategory( SUBCAT_OSD_IMPORT );
set_description( _("XML OSD configuration importer") );
add_shortcut( "import-osd-xml" );
set_capability( "osd parser" , 0);
set_callbacks( osd_parser_xmlOpen, osd_parser_xmlClose );
vlc_module_end();
int osd_parser_xmlOpen ( vlc_object_t *p_this );
/****************************************************************************
* Local structures
****************************************************************************/
int E_(osd_parser_xmlOpen) ( vlc_object_t *p_this )
int osd_parser_xmlOpen( vlc_object_t *p_this )
{
return VLC_SUCCESS;
}
void E_(osd_parser_xmlClose) ( vlc_object_t *p_this )
{
}
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