Commit 01bc9692 authored by Jean-Paul Saman's avatar Jean-Paul Saman

Rewrite old command definitions to no longer use those filthy macros. Added...

Rewrite old command definitions to no longer use those filthy macros. Added all text functionality so the test application runs successfully.
parent 5f65eb66
SOURCES_dynamicoverlay = dynamicoverlay.c dynamicoverlay_buffer.c dynamicoverlay_queue.c SOURCES_dynamicoverlay = dynamicoverlay_buffer.c dynamicoverlay_queue.c dynamicoverlay_list.c dynamicoverlay_commands.c dynamicoverlay.c
noinst_HEADERS = dynamicoverlay.h dynamicoverlay_commands.h noinst_HEADERS = dynamicoverlay.h
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
#ifndef DYNAMIC_OVERLAY_H #ifndef DYNAMIC_OVERLAY_H
#define DYNAMIC_OVERLAY_H 1 #define DYNAMIC_OVERLAY_H 1
#include <vlc/vlc.h>
#include <vlc_filter.h>
/***************************************************************************** /*****************************************************************************
* buffer_t: Command and response buffer * buffer_t: Command and response buffer
*****************************************************************************/ *****************************************************************************/
...@@ -42,60 +45,41 @@ int BufferDestroy( buffer_t *p_buffer ); ...@@ -42,60 +45,41 @@ int BufferDestroy( buffer_t *p_buffer );
int BufferAdd( buffer_t *p_buffer, const char *p_data, size_t i_len ); int BufferAdd( buffer_t *p_buffer, const char *p_data, size_t i_len );
int BufferPrintf( buffer_t *p_buffer, const char *p_fmt, ... ); int BufferPrintf( buffer_t *p_buffer, const char *p_fmt, ... );
int BufferDel( buffer_t *p_buffer, int i_len ); int BufferDel( buffer_t *p_buffer, int i_len );
char *BufferGetToken( buffer_t *p_buffer );
/***************************************************************************** /*****************************************************************************
* Command structures * Command structures
*****************************************************************************/ *****************************************************************************/
#define INT( name ) int name; /** struct commandparams_t - command params structure */
#define CHARS( name, count ) char name[count]; typedef struct commandparams_t
#define COMMAND( name, param, ret, atomic, code ) \
struct commandparams##name##_t \
{ \
param \
};
#include "dynamicoverlay_commands.h"
#undef COMMAND
#undef INT
#undef CHARS
union commandparams_t
{ {
#define COMMAND( name, param, ret, atomic, code ) struct commandparams##name##_t name; int32_t i_id; /*< overlay id */
#include "dynamicoverlay_commands.h" int32_t i_shmid; /*< shared memory identifier */
#undef COMMAND
}; vlc_fourcc_t fourcc;/*< chroma */
typedef union commandparams_t commandparams_t;
int32_t i_x; /*< x position of overlay */
#define INT( name ) int name; int32_t i_y; /*< y position of overlay */
#define CHARS( name, count ) char name[count]; int32_t i_width; /*< width of overlay */
#define COMMAND( name, param, ret, atomic, code ) \ int32_t i_height; /*< height of overlay */
struct commandresults##name##_t \
{ \ int32_t i_alpha; /*< alpha value of overlay */
ret \
}; struct text_style_t fontstyle; /*< text style */
#include "dynamicoverlay_commands.h"
#undef COMMAND vlc_bool_t b_visible; /*< visibility flag of overlay */
#undef INT } commandparams_t;
#undef CHARS
union commandresults_t {
#define COMMAND( name, param, ret, atomic, code ) struct commandresults##name##_t name;
#include "dynamicoverlay_commands.h"
#undef COMMAND
};
typedef union commandresults_t commandresults_t;
typedef struct commanddesc_t typedef struct commanddesc_t
{ {
const char *psz_command; const char *psz_command;
vlc_bool_t b_atomic; vlc_bool_t b_atomic;
int ( *pf_parser ) ( const char *psz_command, const char *psz_end, int ( *pf_parser ) ( char *psz_command, char *psz_end,
commandparams_t *p_params ); commandparams_t *p_params );
int ( *pf_execute ) ( filter_t *p_filter, const commandparams_t *p_params, int ( *pf_execute ) ( filter_t *p_filter, const commandparams_t *p_params,
commandresults_t *p_results, commandparams_t *p_results );
struct filter_sys_t *p_sys ); int ( *pf_unparse ) ( const commandparams_t *p_results,
int ( *pf_unparser ) ( const commandresults_t *p_results,
buffer_t *p_output ); buffer_t *p_output );
} commanddesc_t; } commanddesc_t;
...@@ -104,11 +88,13 @@ typedef struct command_t ...@@ -104,11 +88,13 @@ typedef struct command_t
struct commanddesc_t *p_command; struct commanddesc_t *p_command;
int i_status; int i_status;
commandparams_t params; commandparams_t params;
commandresults_t results; commandparams_t results;
struct command_t *p_next; struct command_t *p_next;
} command_t; } command_t;
void RegisterCommand( filter_t *p_filter );
void UnregisterCommand( filter_t *p_filter );
/***************************************************************************** /*****************************************************************************
* queue_t: Command queue * queue_t: Command queue
*****************************************************************************/ *****************************************************************************/
...@@ -125,4 +111,60 @@ int QueueEnqueue( queue_t *p_queue, command_t *p_cmd ); ...@@ -125,4 +111,60 @@ int QueueEnqueue( queue_t *p_queue, command_t *p_cmd );
command_t *QueueDequeue( queue_t *p_queue ); command_t *QueueDequeue( queue_t *p_queue );
int QueueTransfer( queue_t *p_sink, queue_t *p_source ); int QueueTransfer( queue_t *p_sink, queue_t *p_source );
/*****************************************************************************
* overlay_t: Overlay descriptor
*****************************************************************************/
typedef struct overlay_t
{
int i_x, i_y;
int i_alpha;
vlc_bool_t b_active;
video_format_t format;
struct text_style_t fontstyle;
union {
picture_t *p_pic;
char *p_text;
} data;
} overlay_t;
overlay_t *OverlayCreate( void );
int OverlayDestroy( overlay_t *p_ovl );
/*****************************************************************************
* list_t: Command queue
*****************************************************************************/
typedef struct list_t
{
overlay_t **pp_head, **pp_tail;
} list_t;
int ListInit( list_t *p_list );
int ListDestroy( list_t *p_list );
ssize_t ListAdd( list_t *p_list, overlay_t *p_new );
int ListRemove( list_t *p_list, size_t i_idx );
overlay_t *ListGet( list_t *p_list, size_t i_idx );
overlay_t *ListWalk( list_t *p_list );
/*****************************************************************************
* 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;
commanddesc_t **pp_commands; /* array of commands */
size_t i_commands;
vlc_bool_t b_updated, b_atomic;
queue_t atomic, pending, processed;
list_t overlays;
};
#endif #endif
/***************************************************************************** /*****************************************************************************
* dynamicoverlay_commands.def : dynamic overlay plugin commands * dynamicoverlay_buffer.h : dynamic overlay buffer
***************************************************************************** *****************************************************************************
* Copyright (C) 2008 the VideoLAN team * Copyright (C) 2008 the VideoLAN team
* $Id$ * $Id$
...@@ -27,6 +27,10 @@ ...@@ -27,6 +27,10 @@
#endif #endif
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <vlc_osd.h>
#include <vlc_filter.h>
#include <ctype.h>
#include "dynamicoverlay.h" #include "dynamicoverlay.h"
...@@ -55,6 +59,20 @@ int BufferDestroy( buffer_t *p_buffer ) ...@@ -55,6 +59,20 @@ int BufferDestroy( buffer_t *p_buffer )
return VLC_SUCCESS; return VLC_SUCCESS;
} }
char *BufferGetToken( buffer_t *p_buffer )
{
char *p_char = p_buffer->p_begin;
while( isspace( p_char[0] ) || p_char[0] == '\0' )
{
if( p_char <= (p_buffer->p_begin + p_buffer->i_length) )
p_char++;
else
return NULL;
}
return p_char;
}
int BufferAdd( buffer_t *p_buffer, const char *p_data, size_t i_len ) int BufferAdd( buffer_t *p_buffer, const char *p_data, size_t i_len )
{ {
if( ( p_buffer->i_size - p_buffer->i_length - if( ( p_buffer->i_size - p_buffer->i_length -
......
This diff is collapsed.
/*****************************************************************************
* dynamicoverlay_commands.def : dynamic overlay plugin commands
*****************************************************************************
* Copyright (C) 2008 the VideoLAN team
* $Id$
*
* Author: Søren Bøg <avacore@videolan.org>
* Jean-Paul Saman <jpsaman@videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include <sys/shm.h>
/* Commands must be sorted alphabetically.
I haven't found out how to implement quick sort in cpp */
COMMAND( DataSharedMem, INT( i_id ) INT( i_width ) INT( i_height )
CHARS( p_fourcc, 4 ) INT( i_shmid ), , VLC_TRUE, {
overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
if( p_ovl == NULL ) {
msg_Err( p_filter, "Invalid overlay: %d", p_params->i_id );
return VLC_EGENERIC;
}
struct shmid_ds shminfo;
if( shmctl( p_params->i_shmid, IPC_STAT, &shminfo ) == -1 ) {
msg_Err( p_filter, "Unable to access shared memory" );
return VLC_EGENERIC;
}
size_t i_size = shminfo.shm_segsz;
if( strncmp( p_params->p_fourcc, "TEXT", 4 ) == 0 ) {
if( p_params->i_height != 1 || p_params->i_width < 1 ) {
msg_Err( p_filter,
"Invalid width and/or height. when specifing text height "
"must be 1 and width the number of bytes in the string, "
"including the null terminator" );
return VLC_EGENERIC;
}
if( p_params->i_width > i_size ) {
msg_Err( p_filter,
"Insufficient data in shared memory. need %d, got %d",
p_params->i_width, i_size );
return VLC_EGENERIC;
}
p_ovl->data.p_text = malloc( p_params->i_width );
if( p_ovl->data.p_text == NULL )
{
msg_Err( p_filter, "Unable to allocate string storage" );
return VLC_ENOMEM;
}
vout_InitFormat( &p_ovl->format, VLC_FOURCC( 'T', 'E', 'X', 'T' ), 0, 0,
0 );
char *p_data = shmat( p_params->i_shmid, NULL, SHM_RDONLY );
if( p_data == NULL )
{
msg_Err( p_filter, "Unable to attach to shared memory" );
free( p_ovl->data.p_text );
p_ovl->data.p_text = NULL;
return VLC_ENOMEM;
}
memcpy( p_ovl->data.p_text, p_data, p_params->i_width );
shmdt( p_data );
} else {
p_ovl->data.p_pic = malloc( sizeof( picture_t ) );
if( p_ovl->data.p_pic == NULL )
{
msg_Err( p_filter, "Unable to allocate picture structure" );
return VLC_ENOMEM;
}
vout_InitFormat( &p_ovl->format, VLC_FOURCC( p_params->p_fourcc[0],
p_params->p_fourcc[1],
p_params->p_fourcc[2],
p_params->p_fourcc[3] ),
p_params->i_width, p_params->i_height,
VOUT_ASPECT_FACTOR );
if( vout_AllocatePicture( p_filter, p_ovl->data.p_pic,
p_ovl->format.i_chroma, p_params->i_width,
p_params->i_height, p_ovl->format.i_aspect ) )
{
msg_Err( p_filter, "Unable to allocate picture" );
free( p_ovl->data.p_pic );
p_ovl->data.p_pic = NULL;
return VLC_ENOMEM;
}
size_t i_neededsize = 0;
for( size_t i_plane = 0; i_plane < p_ovl->data.p_pic->i_planes;
++i_plane ) {
i_neededsize += p_ovl->data.p_pic->p[i_plane].i_visible_lines *
p_ovl->data.p_pic->p[i_plane].i_visible_pitch;
}
if( i_neededsize > i_size ) {
msg_Err( p_filter,
"Insufficient data in shared memory. need %d, got %d",
i_neededsize, i_size );
p_ovl->data.p_pic->pf_release( p_ovl->data.p_pic );
free( p_ovl->data.p_pic );
p_ovl->data.p_pic = NULL;
return VLC_EGENERIC;
}
char *p_data = shmat( p_params->i_shmid, NULL, SHM_RDONLY );
if( p_data == NULL )
{
msg_Err( p_filter, "Unable to attach to shared memory" );
p_ovl->data.p_pic->pf_release( p_ovl->data.p_pic );
free( p_ovl->data.p_pic );
p_ovl->data.p_pic = NULL;
return VLC_ENOMEM;
}
char *p_in = p_data;
for( size_t i_plane = 0; i_plane < p_ovl->data.p_pic->i_planes;
++i_plane ) {
char *p_out = p_ovl->data.p_pic->p[i_plane].p_pixels;
for( size_t i_line = 0;
i_line < p_ovl->data.p_pic->p[i_plane].i_visible_lines;
++i_line ) {
p_filter->p_libvlc->pf_memcpy( p_out, p_in,
p_ovl->data.p_pic->p[i_plane].i_visible_pitch );
p_out += p_ovl->data.p_pic->p[i_plane].i_pitch;
p_in += p_ovl->data.p_pic->p[i_plane].i_visible_pitch;
}
}
shmdt( p_data );
}
p_sys->b_updated = p_ovl->b_active;
return VLC_SUCCESS;
} )
COMMAND( DeleteImage, INT( i_id ), , VLC_TRUE, {
p_sys->b_updated = VLC_TRUE;
return ListRemove( &p_sys->overlays, p_params->i_id );
} )
COMMAND( EndAtomic, , , VLC_FALSE, {
QueueTransfer( &p_sys->pending, &p_sys->atomic );
p_sys->b_atomic = VLC_FALSE;
return VLC_SUCCESS;
} )
COMMAND( GenImage, , INT( i_newid ), VLC_FALSE, {
overlay_t *p_ovl = OverlayCreate();
if( p_ovl == NULL ) {
return VLC_ENOMEM;
}
ssize_t i_idx = ListAdd( &p_sys->overlays, p_ovl );
if( i_idx < 0 ) {
return i_idx;
}
p_results->i_newid = i_idx;
return VLC_SUCCESS;
} )
COMMAND( GetAlpha, INT( i_id ), INT( i_alpha ), VLC_FALSE, {
overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
if( p_ovl == NULL ) {
return VLC_EGENERIC;
}
p_results->i_alpha = p_ovl->i_alpha;
return VLC_SUCCESS;
} )
COMMAND( GetPosition, INT( i_id ), INT( i_x ) INT( i_y ), VLC_FALSE, {
overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
if( p_ovl == NULL ) {
return VLC_EGENERIC;
}
p_results->i_x = p_ovl->i_x;
p_results->i_y = p_ovl->i_y;
return VLC_SUCCESS;
} )
COMMAND( GetVisibility, INT( i_id ), INT( i_vis ), VLC_FALSE, {
overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
if( p_ovl == NULL ) {
return VLC_EGENERIC;
}
p_results->i_vis = ( p_ovl->b_active == VLC_TRUE ) ? 1 : 0;
return VLC_SUCCESS;
} )
COMMAND( SetAlpha, INT( i_id ) INT( i_alpha ), , VLC_TRUE, {
overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
if( p_ovl == NULL ) {
return VLC_EGENERIC;
}
p_ovl->i_alpha = p_params->i_alpha;
p_sys->b_updated = p_ovl->b_active;
return VLC_SUCCESS;
} )
COMMAND( SetPosition, INT( i_id ) INT( i_x ) INT( i_y ), , VLC_TRUE, {
overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
if( p_ovl == NULL ) {
return VLC_EGENERIC;
}
p_ovl->i_x = p_params->i_x;
p_ovl->i_y = p_params->i_y;
p_sys->b_updated = p_ovl->b_active;
return VLC_SUCCESS;
} )
COMMAND( SetVisibility, INT( i_id ) INT( i_vis ), , VLC_TRUE, {
overlay_t *p_ovl = ListGet( &p_sys->overlays, p_params->i_id );
if( p_ovl == NULL ) {
return VLC_EGENERIC;
}
p_ovl->b_active = ( p_params->i_vis == 0 ) ? VLC_FALSE : VLC_TRUE;
p_sys->b_updated = VLC_TRUE;
return VLC_SUCCESS;
} )
COMMAND( StartAtomic, , , VLC_FALSE, {
p_sys->b_atomic = VLC_TRUE;
return VLC_SUCCESS;
} )
/*****************************************************************************
* dynamicoverlay_list.h : dynamic overlay list
*****************************************************************************
* Copyright (C) 2008 the VideoLAN team
* $Id$
*
* Author: Søren Bøg <avacore@videolan.org>
* Jean-Paul Saman <jpsaman@videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <vlc/vlc.h>
#include <vlc_osd.h>
#include <fcntl.h>
#include "dynamicoverlay.h"
/*****************************************************************************
* list_t: Command queue
*****************************************************************************/
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;
}
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;
}
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;
}
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;
}
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];
}
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;
}
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#endif #endif
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <vlc_osd.h>
#include "dynamicoverlay.h" #include "dynamicoverlay.h"
......
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