/*****************************************************************************
* mosaic.c : Mosaic video plugin for vlc
*****************************************************************************
- * Copyright (C) 2004-2005 VideoLAN
+ * Copyright (C) 2004-2005 the VideoLAN team
* $Id$
*
* Authors: Antoine Cellerier <dionoea@via.ecp.fr>
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
#include "vlc_filter.h"
#include "vlc_image.h"
-#include "../video_output/picture.h"
+#include "mosaic.h"
+
+#define BLANK_DELAY I64C(1000000)
/*****************************************************************************
* Local prototypes
struct filter_sys_t
{
vlc_mutex_t lock;
+ vlc_mutex_t *p_lock;
image_handler_t *p_image;
-#ifdef IMAGE_2PASSES
- image_handler_t *p_image2;
-#endif
picture_t *p_pic;
int i_position; /* mosaic positioning method */
int i_vborder, i_hborder; /* border width/height between miniatures */
int i_alpha; /* subfilter alpha blending */
+ vlc_bool_t b_bs; /* Bluescreen vars */
+ int i_bsu, i_bsv, i_bsut, i_bsvt;
+
char **ppsz_order; /* list of picture-id */
int i_order_length;
#define ALIGN_TEXT N_("Mosaic alignment")
#define POS_TEXT N_("Positioning method")
-#define POS_LONGTEXT N_("Positioning method. auto : automatically choose " \
- "the best number of rows and columns. fixed : use the user-defined " \
+#define POS_LONGTEXT N_("Positioning method. auto: automatically choose " \
+ "the best number of rows and columns. fixed: use the user-defined " \
"number of rows and columns.")
#define ROWS_TEXT N_("Number of rows")
#define COLS_TEXT N_("Number of columns")
#define DELAY_TEXT N_("Delay")
#define DELAY_LONGTEXT N_("Pictures coming from the picture video outputs " \
- "will be delayed accordingly (in milliseconds, >= 100 ms). For high " \
+ "will be delayed accordingly (in milliseconds). For high " \
"values you will need to raise file-caching and others.")
+#define BLUESCREEN_TEXT N_("Enable bluescreen (aka greenscreen or chroma key) video background replacing")
+#define BLUESCREENU_TEXT N_("Bluescreen chroma key U (0-255)")
+#define BLUESCREENV_TEXT N_("Bluescreen chroma key V (0-255)")
+#define BLUESCREENUTOL_TEXT N_("Bluescreen chroma key U tolerance")
+#define BLUESCREENVTOL_TEXT N_("Bluescreen chroma key V tolerance")
+
static int pi_pos_values[] = { 0, 1 };
static char * ppsz_pos_descriptions[] =
{ N_("auto"), N_("fixed") };
vlc_module_begin();
set_description( N_("Mosaic video sub filter") );
set_shortname( N_("Mosaic") );
+ set_category( CAT_VIDEO );
+ set_subcategory( SUBCAT_VIDEO_SUBPIC);
set_capability( "sub filter", 0 );
set_callbacks( CreateFilter, DestroyFilter );
add_bool( "mosaic-keep-picture", 0, NULL, KEEP_TEXT, KEEP_TEXT, VLC_FALSE );
add_string( "mosaic-order", "", NULL, ORDER_TEXT, ORDER_TEXT, VLC_FALSE );
- add_integer( "mosaic-delay", 100, NULL, DELAY_TEXT, DELAY_LONGTEXT,
+ add_integer( "mosaic-delay", 0, NULL, DELAY_TEXT, DELAY_LONGTEXT,
VLC_FALSE );
+
+ add_bool( "mosaic-bs", 0, NULL, BLUESCREEN_TEXT,
+ BLUESCREEN_TEXT, VLC_FALSE );
+ add_integer( "mosaic-bsu", 120, NULL, BLUESCREENU_TEXT,
+ BLUESCREENU_TEXT, VLC_FALSE );
+ add_integer( "mosaic-bsv", 90, NULL, BLUESCREENV_TEXT,
+ BLUESCREENV_TEXT, VLC_FALSE );
+ add_integer( "mosaic-bsut", 17, NULL, BLUESCREENUTOL_TEXT,
+ BLUESCREENUTOL_TEXT, VLC_FALSE );
+ add_integer( "mosaic-bsvt", 17, NULL, BLUESCREENVTOL_TEXT,
+ BLUESCREENVTOL_TEXT, VLC_FALSE );
+
+ var_Create( p_module->p_libvlc, "mosaic-lock", VLC_VAR_MUTEX );
vlc_module_end();
libvlc_t *p_libvlc = p_filter->p_libvlc;
char *psz_order;
int i_index;
+ vlc_value_t val;
+
+ /* The mosaic thread is more important than the decoder threads */
+ vlc_thread_set_priority( p_this, VLC_THREAD_PRIORITY_OUTPUT );
/* Allocate structure */
p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
vlc_mutex_init( p_filter, &p_sys->lock );
vlc_mutex_lock( &p_sys->lock );
+ var_Get( p_libvlc, "mosaic-lock", &val );
+ p_sys->p_lock = val.p_address;
+
#define GET_VAR( name, min, max ) \
p_sys->i_##name = __MIN( max, __MAX( min, \
var_CreateGetInteger( p_filter, "mosaic-" #name ) ) ); \
if ( !p_sys->b_keep )
{
p_sys->p_image = image_HandlerCreate( p_filter );
-#ifdef IMAGE_2PASSES
- p_sys->p_image2 = image_HandlerCreate( p_filter );
-#endif
}
p_sys->i_order_length = 0;
char *psz_end = NULL;
i_index = 0;
do
- {
+ {
psz_end = strchr( psz_order, ',' );
i_index++;
p_sys->ppsz_order = realloc( p_sys->ppsz_order,
p_sys->i_order_length = i_index;
}
- vlc_mutex_unlock( &p_sys->lock );
+ /* Bluescreen specific stuff */
+ GET_VAR( bsu, 0x00, 0xff );
+ GET_VAR( bsv, 0x00, 0xff );
+ GET_VAR( bsut, 0x00, 0xff );
+ GET_VAR( bsvt, 0x00, 0xff );
+ p_sys->b_bs = var_CreateGetBool( p_filter, "mosaic-bs" );
+ var_Destroy( p_filter, "mosaic-bs" );
+ var_Create( p_libvlc, "mosaic-bs", VLC_VAR_INTEGER );
+ var_SetBool( p_libvlc, "mosaic-bs", p_sys->b_bs );
+ var_AddCallback( p_libvlc, "mosaic-bs", MosaicCallback, p_sys );
+ if( p_sys->b_bs && p_sys->b_keep )
+ {
+ msg_Warn( p_filter, "mosaic-keep-picture needs to be disabled for"
+ " bluescreen to work" );
+ }
- vlc_thread_set_priority( p_filter, VLC_THREAD_PRIORITY_OUTPUT );
+ vlc_mutex_unlock( &p_sys->lock );
return VLC_SUCCESS;
}
if( !p_sys->b_keep )
{
image_HandlerDelete( p_sys->p_image );
-#ifdef IMAGE_2PASSES
- image_HandlerDelete( p_sys->p_image2 );
-#endif
}
if( p_sys->i_order_length )
var_Destroy( p_libvlc, "mosaic-cols" );
var_Destroy( p_libvlc, "mosaic-keep-aspect-ratio" );
+ var_Destroy( p_libvlc, "mosaic-bsu" );
+ var_Destroy( p_libvlc, "mosaic-bsv" );
+ var_Destroy( p_libvlc, "mosaic-bsut" );
+ var_Destroy( p_libvlc, "mosaic-bsvt" );
+ var_Destroy( p_libvlc, "mosaic-bs" );
+
if( p_sys->p_pic ) p_sys->p_pic->pf_release( p_sys->p_pic );
vlc_mutex_unlock( &p_sys->lock );
vlc_mutex_destroy( &p_sys->lock );
static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
{
filter_sys_t *p_sys = p_filter->p_sys;
- libvlc_t *p_libvlc = p_filter->p_libvlc;
+ bridge_t *p_bridge;
subpicture_t *p_spu;
subpicture_region_t *p_region;
subpicture_region_t *p_region_prev = NULL;
- picture_vout_t *p_picture_vout;
- vlc_value_t val, lockval;
-
- /* Wait for the specified date. This is to avoid running too fast and
- * take twice the same pictures. */
- mwait( date - p_sys->i_delay );
-
- if ( var_Get( p_libvlc, "picture-lock", &lockval ) )
- return NULL;
-
- vlc_mutex_lock( lockval.p_address );
-
- if( var_Get( p_libvlc, "p_picture_vout", &val ) )
- {
- vlc_mutex_unlock( lockval.p_address );
- return NULL;
- }
-
- p_picture_vout = val.p_address;
-
/* Allocate the subpicture internal data. */
p_spu = p_filter->pf_sub_buffer_new( p_filter );
if( !p_spu )
p_spu->b_absolute = VLC_FALSE;
vlc_mutex_lock( &p_sys->lock );
+ vlc_mutex_lock( p_sys->p_lock );
- if( p_sys->i_position == 0 ) /* use automatic positioning */
+ p_bridge = GetBridge( p_filter );
+ if ( p_bridge == NULL )
+ {
+ vlc_mutex_unlock( p_sys->p_lock );
+ vlc_mutex_unlock( &p_sys->lock );
+ return p_spu;
+ }
+
+ if ( p_sys->i_position == 0 ) /* use automatic positioning */
{
int i_numpics = p_sys->i_order_length; /* keep slots and all */
- for( i_index = 0;
- i_index < p_picture_vout->i_picture_num;
- i_index++ )
+ for ( i_index = 0; i_index < p_bridge->i_es_num; i_index++ )
{
- if( p_picture_vout->p_pic[i_index].i_status
- == PICTURE_VOUT_E_OCCUPIED )
+ bridged_es_t *p_es = p_bridge->pp_es[i_index];
+ if ( !p_es->b_empty )
{
i_numpics ++;
- if( p_sys->i_order_length
- && p_picture_vout->p_pic[i_index].psz_id != 0 )
+ if( p_sys->i_order_length && p_es->psz_id != 0 )
{
/* We also want to leave slots for images given in
* mosaic-order that are not available in p_vout_picture */
int i;
for( i = 0; i < p_sys->i_order_length ; i++ )
{
- if( !strcmp( p_sys->ppsz_order[i],
- p_picture_vout->p_pic[i_index].psz_id ) )
+ if( !strcmp( p_sys->ppsz_order[i], p_es->psz_id ) )
{
i_numpics--;
break;
i_real_index = 0;
- for( i_index = 0; i_index < p_picture_vout->i_picture_num; i_index++ )
+ for ( i_index = 0; i_index < p_bridge->i_es_num; i_index++ )
{
- picture_vout_e_t *p_pic = &p_picture_vout->p_pic[i_index];
+ bridged_es_t *p_es = p_bridge->pp_es[i_index];
video_format_t fmt_in = {0}, fmt_out = {0};
picture_t *p_converted;
-#ifdef IMAGE_2PASSES
- video_format_t fmt_middle = {0};
- picture_t *p_middle;
-#endif
- if( p_pic->i_status == PICTURE_VOUT_E_AVAILABLE
- || p_pic->p_picture == NULL )
- {
+ if ( p_es->b_empty )
continue;
+
+ while ( p_es->p_picture != NULL
+ && p_es->p_picture->date + p_sys->i_delay < date )
+ {
+ if ( p_es->p_picture->p_next != NULL )
+ {
+ picture_t *p_next = p_es->p_picture->p_next;
+ p_es->p_picture->pf_release( p_es->p_picture );
+ p_es->p_picture = p_next;
+ }
+ else if ( p_es->p_picture->date + p_sys->i_delay + BLANK_DELAY <
+ date )
+ {
+ /* Display blank */
+ p_es->p_picture->pf_release( p_es->p_picture );
+ p_es->p_picture = NULL;
+ p_es->pp_last = &p_es->p_picture;
+ break;
+ }
+ else
+ {
+ msg_Dbg( p_filter, "too late picture for %s (" I64Fd ")",
+ p_es->psz_id,
+ date - p_es->p_picture->date - p_sys->i_delay );
+ break;
+ }
}
- if( p_sys->i_order_length == 0 )
+ if ( p_es->p_picture == NULL )
+ continue;
+
+ if ( p_sys->i_order_length == 0 )
{
i_real_index++;
}
else
{
int i;
- for( i = 0; i <= p_sys->i_order_length; i++ )
+ for ( i = 0; i <= p_sys->i_order_length; i++ )
{
- if( i == p_sys->i_order_length ) break;
- if( strcmp( p_pic->psz_id, p_sys->ppsz_order[i] ) == 0 )
+ if ( i == p_sys->i_order_length ) break;
+ if ( strcmp( p_es->psz_id, p_sys->ppsz_order[i] ) == 0 )
{
i_real_index = i;
break;
}
}
- if( i == p_sys->i_order_length )
+ if ( i == p_sys->i_order_length )
i_real_index = ++i_greatest_real_index_used;
}
i_row = ( i_real_index / p_sys->i_cols ) % p_sys->i_rows;
i_col = i_real_index % p_sys->i_cols ;
- if( !p_sys->b_keep )
+ if ( !p_sys->b_keep )
{
/* Convert the images */
- fmt_in.i_chroma = p_pic->p_picture->format.i_chroma;
- fmt_in.i_height = p_pic->p_picture->format.i_height;
- fmt_in.i_width = p_pic->p_picture->format.i_width;
+ fmt_in.i_chroma = p_es->p_picture->format.i_chroma;
+ fmt_in.i_height = p_es->p_picture->format.i_height;
+ fmt_in.i_width = p_es->p_picture->format.i_width;
fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
fmt_out.i_width = fmt_in.i_width *
> (float)fmt_in.i_width / (float)fmt_in.i_height )
{
fmt_out.i_width = ( fmt_out.i_height * fmt_in.i_width )
- / fmt_in.i_height ;
+ / fmt_in.i_height;
}
else
{
fmt_out.i_height = ( fmt_out.i_width * fmt_in.i_height )
- / fmt_in.i_width ;
+ / fmt_in.i_width;
}
}
fmt_out.i_visible_width = fmt_out.i_width;
fmt_out.i_visible_height = fmt_out.i_height;
-#ifdef IMAGE_2PASSES
- fmt_middle.i_chroma = fmt_in.i_chroma;
- fmt_middle.i_visible_width = fmt_middle.i_width = fmt_out.i_width;
- fmt_middle.i_visible_height = fmt_middle.i_height = fmt_out.i_height;
-
- p_middle = image_Convert( p_sys->p_image2, p_pic->p_picture,
- &fmt_in, &fmt_middle );
- if( !p_middle )
- {
- msg_Warn( p_filter, "image resizing failed" );
- continue;
- }
-
- p_converted = image_Convert( p_sys->p_image, p_middle,
- &fmt_middle, &fmt_out );
- p_middle->pf_release( p_middle );
-
- if( !p_converted )
- {
- msg_Warn( p_filter, "image chroma conversion failed" );
- continue;
- }
-#else
- p_converted = image_Convert( p_sys->p_image, p_pic->p_picture,
+ p_converted = image_Convert( p_sys->p_image, p_es->p_picture,
&fmt_in, &fmt_out );
if( !p_converted )
{
"image resizing and chroma conversion failed" );
continue;
}
-#endif
+
+ /* Bluescreen stuff */
+ if( p_sys->b_bs )
+ {
+ int i,j;
+ int i_lines = p_converted->p[ A_PLANE ].i_lines;
+ int i_pitch = p_converted->p[ A_PLANE ].i_pitch;
+ uint8_t *p_a = p_converted->p[ A_PLANE ].p_pixels;
+ uint8_t *p_at = malloc( i_lines * i_pitch * sizeof( uint8_t ) );
+ uint8_t *p_u = p_converted->p[ U_PLANE ].p_pixels;
+ uint8_t *p_v = p_converted->p[ V_PLANE ].p_pixels;
+ uint8_t umin, umax, vmin, vmax;
+ umin = p_sys->i_bsu - p_sys->i_bsut >= 0x00 ?
+ p_sys->i_bsu - p_sys->i_bsut : 0x00;
+ umax = p_sys->i_bsu + p_sys->i_bsut <= 0xff ?
+ p_sys->i_bsu + p_sys->i_bsut : 0xff;
+ vmin = p_sys->i_bsv - p_sys->i_bsvt >= 0x00 ?
+ p_sys->i_bsv - p_sys->i_bsvt : 0x00;
+ vmax = p_sys->i_bsv + p_sys->i_bsvt <= 0xff ?
+ p_sys->i_bsv + p_sys->i_bsvt : 0xff;
+
+ for( i = 0; i < i_lines*i_pitch; i++ )
+ {
+ if( p_u[i] < umax
+ && p_u[i] > umin
+ && p_v[i] < vmax
+ && p_v[i] > vmin )
+ {
+ p_at[i] = 0x00;
+ }
+ else
+ {
+ p_at[i] = 0xff;
+ }
+ }
+ /* Gaussian convolution to make it look cleaner */
+ memset( p_a, 0, 2 * i_pitch );
+ for( i = 2; i < i_lines - 2; i++ )
+ {
+ p_a[i*i_pitch] = 0x00;
+ p_a[i*i_pitch+1] = 0x00;
+ for( j = 2; j < i_pitch - 2; j ++ )
+ {
+ p_a[i*i_pitch+j] = (uint8_t)((
+ /* 2 rows up */
+ ( p_at[(i-2)*i_pitch+j-2]<<1 )
+ + ( p_at[(i-2)*i_pitch+j-1]<<2 )
+ + ( p_at[(i-2)*i_pitch+j]<<2 )
+ + ( p_at[(i-2)*i_pitch+j+1]<<2 )
+ + ( p_at[(i-2)*i_pitch+j+2]<<1 )
+ /* 1 row up */
+ + ( p_at[(i-1)*i_pitch+j-1]<<3 )
+ + ( p_at[(i-1)*i_pitch+j-2]<<2 )
+ + ( p_at[(i-1)*i_pitch+j]*12 )
+ + ( p_at[(i-1)*i_pitch+j+1]<<3 )
+ + ( p_at[(i-1)*i_pitch+j+2]<<2 )
+ /* */
+ + ( p_at[i*i_pitch+j-2]<<2 )
+ + ( p_at[i*i_pitch+j-1]*12 )
+ + ( p_at[i*i_pitch+j]<<4 )
+ + ( p_at[i*i_pitch+j+1]*12 )
+ + ( p_at[i*i_pitch+j+2]<<2 )
+ /* 1 row down */
+ + ( p_at[(i+1)*i_pitch+j-2]<<2 )
+ + ( p_at[(i+1)*i_pitch+j-1]<<3 )
+ + ( p_at[(i+1)*i_pitch+j]*12 )
+ + ( p_at[(i+1)*i_pitch+j+1]<<3 )
+ + ( p_at[(i+1)*i_pitch+j+2]<<2 )
+ /* 2 rows down */
+ + ( p_at[(i+2)*i_pitch+j-2]<<1 )
+ + ( p_at[(i+2)*i_pitch+j-1]<<2 )
+ + ( p_at[(i+2)*i_pitch+j]<<2 )
+ + ( p_at[(i+2)*i_pitch+j+1]<<2 )
+ + ( p_at[(i+2)*i_pitch+j+2]<<1 )
+ )/152);
+ if( p_a[i*i_pitch+j] < 0xbf ) p_a[i*i_pitch+j] = 0x00;
+ }
+ }
+ free( p_at );
+ }
}
else
{
- p_converted = p_pic->p_picture;
+ p_converted = p_es->p_picture;
p_converted->i_refcount++;
fmt_in.i_width = fmt_out.i_width = p_converted->format.i_width;
fmt_in.i_height = fmt_out.i_height = p_converted->format.i_height;
msg_Err( p_filter, "cannot allocate SPU region" );
p_filter->pf_sub_buffer_del( p_filter, p_spu );
vlc_mutex_unlock( &p_sys->lock );
- vlc_mutex_unlock( lockval.p_address );
- return NULL;
+ vlc_mutex_unlock( p_sys->p_lock );
+ return p_spu;
}
/* HACK ALERT : let's fix the pointers to avoid picture duplication.
p_region_prev = p_region;
}
+ vlc_mutex_unlock( p_sys->p_lock );
vlc_mutex_unlock( &p_sys->lock );
- vlc_mutex_unlock( lockval.p_address );
return p_spu;
}