-/*****************************************************************************
- * overlay_t: Overlay descriptor
- *****************************************************************************/
-
-struct overlay_t
-{
- int i_x, i_y;
- int i_alpha;
- vlc_bool_t b_active;
-
- video_format_t format;
- union {
- picture_t *p_pic;
- char *p_text;
- } data;
-};
-typedef struct overlay_t overlay_t;
-
-static overlay_t *OverlayCreate( void )
-{
- overlay_t *p_ovl = malloc( sizeof( overlay_t ) );
- if( p_ovl == NULL )
- return NULL;
- memset( p_ovl, 0, sizeof( overlay_t ) );
-
- p_ovl->i_x = p_ovl->i_y = 0;
- p_ovl->i_alpha = 0xFF;
- p_ovl->b_active = VLC_FALSE;
- vout_InitFormat( &p_ovl->format, VLC_FOURCC( '\0','\0','\0','\0') , 0, 0,
- VOUT_ASPECT_FACTOR );
- p_ovl->data.p_text = NULL;
-
- return p_ovl;
-}
-
-static int OverlayDestroy( overlay_t *p_ovl )
-{
- if( p_ovl->data.p_text != NULL )
- free( p_ovl->data.p_text );
-
- return VLC_SUCCESS;
-}
-
-/*****************************************************************************
- * list_t: Command queue
- *****************************************************************************/
-
-struct list_t
-{
- overlay_t **pp_head, **pp_tail;
-};
-typedef struct list_t list_t;
-
-static int ListInit( list_t *p_list )
-{
- p_list->pp_head = malloc( 16 * sizeof( overlay_t * ) );
- if( p_list->pp_head == NULL )
- return VLC_ENOMEM;
-
- p_list->pp_tail = p_list->pp_head + 16;
- memset( p_list->pp_head, 0, 16 * sizeof( overlay_t * ) );
-
- return VLC_SUCCESS;
-}
-
-static int ListDestroy( list_t *p_list )
-{
- for( overlay_t **pp_cur = p_list->pp_head;
- pp_cur < p_list->pp_tail;
- ++pp_cur )
- {
- if( *pp_cur != NULL )
- {
- OverlayDestroy( *pp_cur );
- free( *pp_cur );
- }
- }
- free( p_list->pp_head );
-
- return VLC_SUCCESS;
-}
-
-static ssize_t ListAdd( list_t *p_list, overlay_t *p_new )
-{
- /* Find an available slot */
- for( overlay_t **pp_cur = p_list->pp_head;
- pp_cur < p_list->pp_tail;
- ++pp_cur )
- {
- if( *pp_cur == NULL )
- {
- *pp_cur = p_new;
- return pp_cur - p_list->pp_head;
- }
- }
-
- /* Have to expand */
- size_t i_size = p_list->pp_tail - p_list->pp_head;
- size_t i_newsize = i_size * 2;
- p_list->pp_head = realloc( p_list->pp_head,
- i_newsize * sizeof( overlay_t * ) );
- if( p_list->pp_head == NULL )
- return VLC_ENOMEM;
-
- p_list->pp_tail = p_list->pp_head + i_newsize;
- memset( p_list->pp_head + i_size, 0, i_size * sizeof( overlay_t * ) );
- p_list->pp_head[i_size] = p_new;
- return i_size;
-}
-
-static int ListRemove( list_t *p_list, size_t i_idx )
-{
- int ret;
-
- if( ( i_idx >= (size_t)( p_list->pp_tail - p_list->pp_head ) ) ||
- ( p_list->pp_head[i_idx] == NULL ) )
- {
- return VLC_EGENERIC;
- }
-
- ret = OverlayDestroy( p_list->pp_head[i_idx] );
- free( p_list->pp_head[i_idx] );
- p_list->pp_head[i_idx] = NULL;
-
- return ret;
-}
-
-static overlay_t *ListGet( list_t *p_list, size_t i_idx )
-{
- if( ( i_idx >= (size_t)( p_list->pp_tail - p_list->pp_head ) ) ||
- ( p_list->pp_head[i_idx] == NULL ) )
- {
- return NULL;
- }
- return p_list->pp_head[i_idx];
-}
-
-static overlay_t *ListWalk( list_t *p_list )
-{
- static overlay_t **pp_cur = NULL;
-
- if( pp_cur == NULL )
- pp_cur = p_list->pp_head;
- else
- pp_cur = pp_cur + 1;
-
- for( ; pp_cur < p_list->pp_tail; ++pp_cur )
- {
- if( ( *pp_cur != NULL ) &&
- ( (*pp_cur)->b_active == VLC_TRUE )&&
- ( (*pp_cur)->format.i_chroma != VLC_FOURCC( '\0','\0','\0','\0') ) )
- {
- return *pp_cur;
- }
- }
- pp_cur = NULL;
- return NULL;
-}
-
-/*****************************************************************************
- * filter_sys_t: adjust filter method descriptor
- *****************************************************************************/
-struct filter_sys_t
-{
- buffer_t input, output;
-
- int i_inputfd, i_outputfd;
-
- char *psz_inputfile, *psz_outputfile;
-
- vlc_bool_t b_updated, b_atomic;
- queue_t atomic, pending, processed;
- list_t overlays;
-};
-
-/*****************************************************************************
- * Command functions
- *****************************************************************************/
-
-#define SKIP \
- { \
- const char *psz_temp = psz_command; \
- while( isspace( *psz_temp ) ) { \
- ++psz_temp; \
- } \
- if( psz_temp == psz_command ) { \
- return VLC_EGENERIC; \
- } \
- psz_command = psz_temp; \
- }
-#define INT( name ) \
- SKIP \
- { \
- char *psz_temp; \
- p_myparams->name = strtol( psz_command, &psz_temp, 10 ); \
- if( psz_temp == psz_command ) \
- { \
- return VLC_EGENERIC; \
- } \
- psz_command = psz_temp; \
- }
-#define CHARS( name, count ) \
- SKIP \
- { \
- if( psz_end - psz_command < count ) \
- { \
- return VLC_EGENERIC; \
- } \
- memcpy( p_myparams->name, psz_command, count ); \
- psz_command += count; \
- }
-#define COMMAND( name, param, ret, atomic, code ) \
-static int Command##name##Parse( const char *psz_command, \
- const char *psz_end, \
- commandparams_t *p_params ) \
-{ \
- struct commandparams##name##_t *p_myparams = &p_params->name; \
- param \
- return VLC_SUCCESS; \
-}
-#include "dynamicoverlay_commands.h"
-#undef COMMAND
-#undef SKIP
-#undef INT
-#undef CHARS
-
-#define COMMAND( name, param, ret, atomic, code ) \
-static int Command##name##Exec( filter_t *p_filter, \
- const commandparams_t *p_gparams, \
- commandresults_t *p_gresults, \
- filter_sys_t *p_sys ) \
-{ \
- const struct commandparams##name##_t *p_params = &p_gparams->name; \
- struct commandresults##name##_t *p_results = &p_gresults->name; \
- code \
-}
-#include "dynamicoverlay_commands.h"
-#undef COMMAND
-
-#define INT( name ) \
- { \
- int ret = BufferPrintf( p_output, " %d", p_myresults->name ); \
- if( ret != VLC_SUCCESS ) { \
- return ret; \
- } \
- }
-#define CHARS( name, count ) \
- { \
- int ret = BufferAdd( p_output, p_myresults->name, count ); \
- if( ret != VLC_SUCCESS ) { \
- return ret; \
- } \
- }
-#define COMMAND( name, param, ret, atomic, code ) \
-static int Command##name##Unparse( const commandresults_t *p_results, \
- buffer_t *p_output ) \
-{ \
- const struct commandresults##name##_t *p_myresults = &p_results->name; \
- ret \
- return VLC_SUCCESS; \
-}
-#include "dynamicoverlay_commands.h"
-#undef COMMAND
-#undef INT
-#undef CHARS
-
-static commanddesc_t p_commands[] =
-{
-#define COMMAND( name, param, ret, atomic, code ) \
-{ #name, atomic, Command##name##Parse, Command##name##Exec, Command##name##Unparse },
-#include "dynamicoverlay_commands.h"
-#undef COMMAND
-};
-
-#define NUMCOMMANDS (sizeof(p_commands)/sizeof(commanddesc_t))
-