1 /*****************************************************************************
2 * vout_subpictures.c : subpicture management functions
3 *****************************************************************************
4 * Copyright (C) 2000-2007 the VideoLAN team
7 * Authors: Vincent Seguin <seguin@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
9 * Gildas Bazin <gbazin@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
33 #include <vlc_common.h>
35 #include <vlc_block.h>
36 #include <vlc_filter.h>
38 #include "../libvlc.h"
42 /*****************************************************************************
44 *****************************************************************************/
45 static void UpdateSPU ( spu_t *, vlc_object_t * );
46 static int CropCallback( vlc_object_t *, char const *,
47 vlc_value_t, vlc_value_t, void * );
49 static int spu_vaControlDefault( spu_t *, int, va_list );
51 static subpicture_t *sub_new_buffer( filter_t * );
52 static void sub_del_buffer( filter_t *, subpicture_t * );
53 static subpicture_t *spu_new_buffer( filter_t * );
54 static void spu_del_buffer( filter_t *, subpicture_t * );
55 static picture_t *spu_new_video_buffer( filter_t * );
56 static void spu_del_video_buffer( filter_t *, picture_t * );
58 static int spu_ParseChain( spu_t * );
59 static int SubFilterCallback( vlc_object_t *, char const *,
60 vlc_value_t, vlc_value_t, void * );
62 static int sub_filter_allocation_init( filter_t *, void * );
63 static void sub_filter_allocation_clear( filter_t * );
64 struct filter_owner_sys_t
76 #define SCALE_UNIT (1000)
78 static void FilterRelease( filter_t *p_filter )
80 if( p_filter->p_module )
81 module_Unneed( p_filter, p_filter->p_module );
83 vlc_object_detach( p_filter );
84 vlc_object_release( p_filter );
88 * Creates the subpicture unit
90 * \param p_this the parent object which creates the subpicture unit
92 spu_t *__spu_Create( vlc_object_t *p_this )
95 spu_t *p_spu = vlc_custom_create( p_this, sizeof( spu_t ),
96 VLC_OBJECT_GENERIC, "subpicture" );
98 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++)
100 p_spu->p_subpicture[i_index].i_status = FREE_SUBPICTURE;
103 p_spu->p_blend = NULL;
104 p_spu->p_text = NULL;
105 p_spu->p_scale = NULL;
106 p_spu->p_scale_yuvp = NULL;
107 p_spu->pf_control = spu_vaControlDefault;
109 /* Register the default subpicture channel */
110 p_spu->i_channel = 2;
112 vlc_mutex_init( &p_spu->subpicture_lock );
114 vlc_object_attach( p_spu, p_this );
116 p_spu->p_chain = filter_chain_New( p_spu, "sub filter", false,
117 sub_filter_allocation_init,
118 sub_filter_allocation_clear,
124 * Initialise the subpicture unit
126 * \param p_spu the subpicture unit object
128 int spu_Init( spu_t *p_spu )
132 /* If the user requested a sub margin, we force the position. */
133 var_Create( p_spu, "sub-margin", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
134 var_Get( p_spu, "sub-margin", &val );
135 p_spu->i_margin = val.i_int;
137 var_Create( p_spu, "sub-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
138 var_AddCallback( p_spu, "sub-filter", SubFilterCallback, p_spu );
140 spu_ParseChain( p_spu );
145 int spu_ParseChain( spu_t *p_spu )
147 char *psz_parser = var_GetString( p_spu, "sub-filter" );
148 if( filter_chain_AppendFromString( p_spu->p_chain, psz_parser ) < 0 )
159 * Destroy the subpicture unit
161 * \param p_this the parent object which destroys the subpicture unit
163 void spu_Destroy( spu_t *p_spu )
167 /* Destroy all remaining subpictures */
168 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
170 if( p_spu->p_subpicture[i_index].i_status != FREE_SUBPICTURE )
172 spu_DestroySubpicture( p_spu, &p_spu->p_subpicture[i_index] );
177 FilterRelease( p_spu->p_blend );
180 FilterRelease( p_spu->p_text );
182 if( p_spu->p_scale_yuvp )
183 FilterRelease( p_spu->p_scale_yuvp );
186 FilterRelease( p_spu->p_scale );
188 filter_chain_Delete( p_spu->p_chain );
190 vlc_mutex_destroy( &p_spu->subpicture_lock );
191 vlc_object_release( p_spu );
195 * Attach/Detach the SPU from any input
197 * \param p_this the object in which to destroy the subpicture unit
198 * \param b_attach to select attach or detach
200 void spu_Attach( spu_t *p_spu, vlc_object_t *p_this, bool b_attach )
202 vlc_object_t *p_input;
204 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_PARENT );
205 if( !p_input ) return;
209 UpdateSPU( p_spu, VLC_OBJECT(p_input) );
210 var_AddCallback( p_input, "highlight", CropCallback, p_spu );
211 vlc_object_release( p_input );
215 /* Delete callback */
216 var_DelCallback( p_input, "highlight", CropCallback, p_spu );
217 vlc_object_release( p_input );
222 * Create a subpicture region
224 * \param p_this vlc_object_t
225 * \param p_fmt the format that this subpicture region should have
227 static void RegionPictureRelease( picture_t *p_pic )
229 free( p_pic->p_data_orig );
230 /* We use pf_release nullity to know if the picture has already been released. */
231 p_pic->pf_release = NULL;
233 subpicture_region_t *__spu_CreateRegion( vlc_object_t *p_this,
234 video_format_t *p_fmt )
236 subpicture_region_t *p_region = malloc( sizeof(subpicture_region_t) );
237 if( !p_region ) return NULL;
239 memset( p_region, 0, sizeof(subpicture_region_t) );
240 p_region->i_alpha = 0xff;
241 p_region->p_next = NULL;
242 p_region->p_cache = NULL;
243 p_region->fmt = *p_fmt;
244 p_region->psz_text = NULL;
245 p_region->p_style = NULL;
247 if( p_fmt->i_chroma == VLC_FOURCC('Y','U','V','P') )
248 p_fmt->p_palette = p_region->fmt.p_palette =
249 malloc( sizeof(video_palette_t) );
250 else p_fmt->p_palette = p_region->fmt.p_palette = NULL;
252 p_region->picture.p_data_orig = NULL;
254 if( p_fmt->i_chroma == VLC_FOURCC('T','E','X','T') ) return p_region;
256 vout_AllocatePicture( p_this, &p_region->picture, p_fmt->i_chroma,
257 p_fmt->i_width, p_fmt->i_height, p_fmt->i_aspect );
259 if( !p_region->picture.i_planes )
262 free( p_fmt->p_palette );
266 p_region->picture.pf_release = RegionPictureRelease;
272 * Make a subpicture region from an existing picture_t
274 * \param p_this vlc_object_t
275 * \param p_fmt the format that this subpicture region should have
276 * \param p_pic a pointer to the picture creating the region (not freed)
278 subpicture_region_t *__spu_MakeRegion( vlc_object_t *p_this,
279 video_format_t *p_fmt,
282 subpicture_region_t *p_region = malloc( sizeof(subpicture_region_t) );
284 if( !p_region ) return NULL;
285 memset( p_region, 0, sizeof(subpicture_region_t) );
286 p_region->i_alpha = 0xff;
287 p_region->p_next = 0;
288 p_region->p_cache = 0;
289 p_region->fmt = *p_fmt;
290 p_region->psz_text = 0;
291 p_region->p_style = NULL;
293 if( p_fmt->i_chroma == VLC_FOURCC('Y','U','V','P') )
294 p_fmt->p_palette = p_region->fmt.p_palette =
295 malloc( sizeof(video_palette_t) );
296 else p_fmt->p_palette = p_region->fmt.p_palette = NULL;
298 memcpy( &p_region->picture, p_pic, sizeof(picture_t) );
299 p_region->picture.pf_release = RegionPictureRelease;
305 * Destroy a subpicture region
307 * \param p_this vlc_object_t
308 * \param p_region the subpicture region to destroy
310 void __spu_DestroyRegion( vlc_object_t *p_this, subpicture_region_t *p_region )
312 if( !p_region ) return;
313 if( p_region->picture.pf_release )
314 p_region->picture.pf_release( &p_region->picture );
315 free( p_region->fmt.p_palette );
316 if( p_region->p_cache ) __spu_DestroyRegion( p_this, p_region->p_cache );
318 free( p_region->psz_text );
319 free( p_region->psz_html );
320 //free( p_region->p_style ); FIXME --fenrir plugin does not allocate the memory for it. I think it might lead to segfault, video renderer can live longer than the decoder
325 * Display a subpicture
327 * Remove the reservation flag of a subpicture, which will cause it to be
329 * \param p_spu the subpicture unit object
330 * \param p_subpic the subpicture to display
332 void spu_DisplaySubpicture( spu_t *p_spu, subpicture_t *p_subpic )
334 /* Check if status is valid */
335 if( p_subpic->i_status != RESERVED_SUBPICTURE )
337 msg_Err( p_spu, "subpicture %p has invalid status #%d",
338 p_subpic, p_subpic->i_status );
341 /* Remove reservation flag */
342 p_subpic->i_status = READY_SUBPICTURE;
344 if( p_subpic->i_channel == DEFAULT_CHAN )
346 p_subpic->i_channel = 0xFFFF;
347 spu_Control( p_spu, SPU_CHANNEL_CLEAR, DEFAULT_CHAN );
348 p_subpic->i_channel = DEFAULT_CHAN;
353 * Allocate a subpicture in the spu heap.
355 * This function create a reserved subpicture in the spu heap.
356 * A null pointer is returned if the function fails. This method provides an
357 * already allocated zone of memory in the spu data fields. It needs locking
358 * since several pictures can be created by several producers threads.
359 * \param p_spu the subpicture unit in which to create the subpicture
360 * \return NULL on error, a reserved subpicture otherwise
362 subpicture_t *spu_CreateSubpicture( spu_t *p_spu )
364 int i_subpic; /* subpicture index */
365 subpicture_t * p_subpic = NULL; /* first free subpicture */
368 vlc_mutex_lock( &p_spu->subpicture_lock );
371 * Look for an empty place
374 for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
376 if( p_spu->p_subpicture[i_subpic].i_status == FREE_SUBPICTURE )
378 /* Subpicture is empty and ready for allocation */
379 p_subpic = &p_spu->p_subpicture[i_subpic];
380 p_spu->p_subpicture[i_subpic].i_status = RESERVED_SUBPICTURE;
385 /* If no free subpicture could be found */
386 if( p_subpic == NULL )
388 msg_Err( p_spu, "subpicture heap is full" );
389 vlc_mutex_unlock( &p_spu->subpicture_lock );
393 /* Copy subpicture information, set some default values */
394 memset( p_subpic, 0, sizeof(subpicture_t) );
395 p_subpic->i_status = RESERVED_SUBPICTURE;
396 p_subpic->b_absolute = true;
397 p_subpic->b_fade = false;
398 p_subpic->b_subtitle = false;
399 p_subpic->i_alpha = 0xFF;
400 p_subpic->p_region = NULL;
401 p_subpic->pf_render = NULL;
402 p_subpic->pf_destroy = NULL;
403 p_subpic->p_sys = NULL;
404 vlc_mutex_unlock( &p_spu->subpicture_lock );
406 p_subpic->pf_create_region = __spu_CreateRegion;
407 p_subpic->pf_make_region = __spu_MakeRegion;
408 p_subpic->pf_destroy_region = __spu_DestroyRegion;
414 * Remove a subpicture from the heap
416 * This function frees a previously reserved subpicture.
417 * It is meant to be used when the construction of a picture aborted.
418 * This function does not need locking since reserved subpictures are ignored
421 void spu_DestroySubpicture( spu_t *p_spu, subpicture_t *p_subpic )
424 vlc_mutex_lock( &p_spu->subpicture_lock );
426 /* There can be race conditions so we need to check the status */
427 if( p_subpic->i_status == FREE_SUBPICTURE )
429 vlc_mutex_unlock( &p_spu->subpicture_lock );
433 /* Check if status is valid */
434 if( ( p_subpic->i_status != RESERVED_SUBPICTURE )
435 && ( p_subpic->i_status != READY_SUBPICTURE ) )
437 msg_Err( p_spu, "subpicture %p has invalid status %d",
438 p_subpic, p_subpic->i_status );
441 while( p_subpic->p_region )
443 subpicture_region_t *p_region = p_subpic->p_region;
444 p_subpic->p_region = p_region->p_next;
445 spu_DestroyRegion( p_spu, p_region );
448 if( p_subpic->pf_destroy )
450 p_subpic->pf_destroy( p_subpic );
453 p_subpic->i_status = FREE_SUBPICTURE;
455 vlc_mutex_unlock( &p_spu->subpicture_lock );
458 /*****************************************************************************
459 * spu_RenderSubpictures: render a subpicture list
460 *****************************************************************************
461 * This function renders all sub picture units in the list.
462 *****************************************************************************/
463 static void SpuRenderCreateBlend( spu_t *p_spu, vlc_fourcc_t i_chroma, int i_aspect )
467 assert( !p_spu->p_blend );
470 p_blend = vlc_custom_create( p_spu, sizeof(filter_t),
471 VLC_OBJECT_GENERIC, "blend" );
475 es_format_Init( &p_blend->fmt_in, VIDEO_ES, 0 );
477 es_format_Init( &p_blend->fmt_out, VIDEO_ES, 0 );
478 p_blend->fmt_out.video.i_x_offset = 0;
479 p_blend->fmt_out.video.i_y_offset = 0;
480 p_blend->fmt_out.video.i_chroma = i_chroma;
481 p_blend->fmt_out.video.i_aspect = i_aspect;
483 /* The blend module will be loaded when needed with the real
485 p_blend->p_module = NULL;
488 vlc_object_attach( p_blend, p_spu );
490 static void SpuRenderUpdateBlend( spu_t *p_spu, int i_out_width, int i_out_height, const video_format_t *p_in_fmt )
492 filter_t *p_blend = p_spu->p_blend;
497 if( p_blend->p_module && p_blend->fmt_in.video.i_chroma != p_in_fmt->i_chroma )
499 /* The chroma is not the same, we need to reload the blend module
500 * XXX to match the old behaviour just test !p_blend->fmt_in.video.i_chroma */
501 module_Unneed( p_blend, p_blend->p_module );
502 p_blend->p_module = NULL;
506 p_blend->fmt_in.video = *p_in_fmt;
509 p_blend->fmt_out.video.i_width =
510 p_blend->fmt_out.video.i_visible_width = i_out_width;
511 p_blend->fmt_out.video.i_height =
512 p_blend->fmt_out.video.i_visible_height = i_out_height;
515 if( !p_blend->p_module )
516 p_blend->p_module = module_Need( p_blend, "video blending", 0, 0 );
518 static void SpuRenderCreateAndLoadText( spu_t *p_spu, int i_width, int i_height )
522 assert( !p_spu->p_text );
525 p_text = vlc_custom_create( p_spu, sizeof(filter_t),
526 VLC_OBJECT_GENERIC, "spu text" );
530 es_format_Init( &p_text->fmt_in, VIDEO_ES, 0 );
532 es_format_Init( &p_text->fmt_out, VIDEO_ES, 0 );
533 p_text->fmt_out.video.i_width =
534 p_text->fmt_out.video.i_visible_width = i_width;
535 p_text->fmt_out.video.i_height =
536 p_text->fmt_out.video.i_visible_height = i_height;
538 p_text->pf_sub_buffer_new = spu_new_buffer;
539 p_text->pf_sub_buffer_del = spu_del_buffer;
541 vlc_object_attach( p_text, p_spu );
543 /* FIXME TOCHECK shouldn't module_Need( , , psz_modulename, false ) do the
544 * same than these 2 calls ? */
545 char *psz_modulename = var_CreateGetString( p_spu, "text-renderer" );
546 if( psz_modulename && *psz_modulename )
548 p_text->p_module = module_Need( p_text, "text renderer",
549 psz_modulename, true );
551 free( psz_modulename );
553 if( !p_text->p_module )
554 p_text->p_module = module_Need( p_text, "text renderer", NULL, false );
557 static filter_t *CreateAndLoadScale( vlc_object_t *p_obj, vlc_fourcc_t i_chroma )
561 p_scale = vlc_custom_create( p_obj, sizeof(filter_t),
562 VLC_OBJECT_GENERIC, "scale" );
566 es_format_Init( &p_scale->fmt_in, VIDEO_ES, 0 );
567 p_scale->fmt_in.video.i_chroma = i_chroma;
568 p_scale->fmt_in.video.i_width =
569 p_scale->fmt_in.video.i_height = 32;
571 es_format_Init( &p_scale->fmt_out, VIDEO_ES, 0 );
572 p_scale->fmt_out.video.i_chroma = i_chroma;
573 p_scale->fmt_out.video.i_width =
574 p_scale->fmt_out.video.i_height = 16;
576 p_scale->pf_vout_buffer_new = spu_new_video_buffer;
577 p_scale->pf_vout_buffer_del = spu_del_video_buffer;
579 vlc_object_attach( p_scale, p_obj );
580 p_scale->p_module = module_Need( p_scale, "video filter2", 0, 0 );
585 static void SpuRenderCreateAndLoadScale( spu_t *p_spu )
587 /* FIXME: We'll also be using it for YUVA and RGBA blending ... */
589 assert( !p_spu->p_scale );
590 assert( !p_spu->p_scale_yuvp );
591 p_spu->p_scale = CreateAndLoadScale( VLC_OBJECT(p_spu), VLC_FOURCC('Y','U','V','A') );
592 p_spu->p_scale_yuvp = p_spu->p_scale_yuvp = CreateAndLoadScale( VLC_OBJECT(p_spu), VLC_FOURCC('Y','U','V','P') );
595 static void SpuRenderText( spu_t *p_spu, bool *pb_rerender_text,
596 subpicture_t *p_subpic, subpicture_region_t *p_region, int i_min_scale_ratio )
598 assert( p_region->fmt.i_chroma == VLC_FOURCC('T','E','X','T') );
600 if( !p_spu->p_text || !p_spu->p_text->p_module )
603 /* Setup 3 variables which can be used to render
604 * time-dependent text (and effects). The first indicates
605 * the total amount of time the text will be on screen,
606 * the second the amount of time it has already been on
607 * screen (can be a negative value as text is layed out
608 * before it is rendered) and the third is a feedback
609 * variable from the renderer - if the renderer sets it
610 * then this particular text is time-dependent, eg. the
611 * visual progress bar inside the text in karaoke and the
612 * text needs to be rendered multiple times in order for
613 * the effect to work - we therefore need to return the
614 * region to its original state at the end of the loop,
615 * instead of leaving it in YUVA or YUVP.
616 * Any renderer which is unaware of how to render
617 * time-dependent text can happily ignore the variables
618 * and render the text the same as usual - it should at
619 * least show up on screen, but the effect won't change
620 * the text over time.
623 /* FIXME why these variables are recreated every time and not
624 * when text renderer module was created ? */
625 var_Create( p_spu->p_text, "spu-duration", VLC_VAR_TIME );
626 var_Create( p_spu->p_text, "spu-elapsed", VLC_VAR_TIME );
627 var_Create( p_spu->p_text, "text-rerender", VLC_VAR_BOOL );
628 var_Create( p_spu->p_text, "scale", VLC_VAR_INTEGER );
630 var_SetTime( p_spu->p_text, "spu-duration", p_subpic->i_stop - p_subpic->i_start );
631 var_SetTime( p_spu->p_text, "spu-elapsed", mdate() - p_subpic->i_start );
632 var_SetBool( p_spu->p_text, "text-rerender", false );
633 var_SetInteger( p_spu->p_text, "scale", i_min_scale_ratio );
635 if( p_spu->p_text->pf_render_html && p_region->psz_html )
637 p_spu->p_text->pf_render_html( p_spu->p_text,
638 p_region, p_region );
640 else if( p_spu->p_text->pf_render_text )
642 p_spu->p_text->pf_render_text( p_spu->p_text,
643 p_region, p_region );
645 *pb_rerender_text = var_GetBool( p_spu->p_text, "text-rerender" );
647 var_Destroy( p_spu->p_text, "spu-duration" );
648 var_Destroy( p_spu->p_text, "spu-elapsed" );
649 var_Destroy( p_spu->p_text, "text-rerender" );
650 var_Destroy( p_spu->p_text, "scale" );
653 p_region->i_align |= SUBPICTURE_RENDERED;
659 static void SpuRegionPlace( int *pi_x, int *pi_y,
660 const video_format_t *p_fmt,
661 const subpicture_t *p_subpic,
662 const subpicture_region_t *p_region,
663 int i_inv_scale_x, int i_inv_scale_y )
665 int i_delta_x = p_region->i_x * i_inv_scale_x / SCALE_UNIT;
666 int i_delta_y = p_region->i_y * i_inv_scale_y / SCALE_UNIT;
669 if( p_region->i_align & SUBPICTURE_ALIGN_TOP )
673 else if( p_region->i_align & SUBPICTURE_ALIGN_BOTTOM )
675 i_y = p_fmt->i_height - p_region->fmt.i_height - i_delta_y;
679 i_y = p_fmt->i_height / 2 - p_region->fmt.i_height / 2;
682 if( p_region->i_align & SUBPICTURE_ALIGN_LEFT )
686 else if( p_region->i_align & SUBPICTURE_ALIGN_RIGHT )
688 i_x = p_fmt->i_width - p_region->fmt.i_width - i_delta_x;
692 i_x = p_fmt->i_width / 2 - p_region->fmt.i_width / 2;
695 if( p_subpic->b_absolute )
701 *pi_x = __MAX( i_x, 0 );
702 *pi_y = __MAX( i_y, 0 );
705 static void SpuRenderRegion( spu_t *p_spu,
706 picture_t *p_pic_dst,
707 subpicture_t *p_subpic, subpicture_region_t *p_region,
708 const int i_scale_width_orig, const int i_scale_height_orig,
709 const int pi_scale_width[SCALE_SIZE],
710 const int pi_scale_height[SCALE_SIZE],
711 const video_format_t *p_fmt )
713 video_format_t fmt_original;
714 bool b_rerender_text;
715 bool b_restore_format = false;
724 vlc_assert_locked( &p_spu->subpicture_lock );
726 fmt_original = p_region->fmt;
727 b_rerender_text = false;
728 if( p_region->fmt.i_chroma == VLC_FOURCC('T','E','X','T') )
730 SpuRenderText( p_spu, &b_rerender_text, p_subpic, p_region, __MIN(i_scale_width_orig, i_scale_height_orig) );
731 b_restore_format = b_rerender_text;
733 /* Check if the rendering has failed ... */
734 if( p_region->fmt.i_chroma == VLC_FOURCC('T','E','X','T') )
738 if( p_region->i_align & SUBPICTURE_RENDERED )
740 /* We are using a region which come from rendered text */
741 i_scale_idx = SCALE_TEXT;
742 i_inv_scale_x = i_scale_width_orig;
743 i_inv_scale_y = i_scale_height_orig;
747 i_scale_idx = SCALE_DEFAULT;
748 i_inv_scale_x = SCALE_UNIT;
749 i_inv_scale_y = SCALE_UNIT;
752 /* Force palette if requested
753 * FIXME b_force_palette and b_force_crop are applied to all subpictures using palette
754 * instead of only the right one (being the dvd spu).
756 const bool b_using_palette = p_region->fmt.i_chroma == VLC_FOURCC('Y','U','V','P');
757 const bool b_force_palette = b_using_palette && p_spu->b_force_palette;
758 const bool b_force_crop = b_force_palette && p_spu->b_force_crop;
760 if( b_force_palette )
762 /* It looks so wrong I won't comment
763 * p_palette->palette is [256][4] with a int i_entries
764 * p_spu->palette is [4][4]
766 p_region->fmt.p_palette->i_entries = 4;
767 memcpy( p_region->fmt.p_palette->palette, p_spu->palette, 4*sizeof(uint32_t) );
770 if( b_using_palette )
771 p_scale = p_spu->p_scale_yuvp;
773 p_scale = p_spu->p_scale;
776 ( ( pi_scale_width[i_scale_idx] > 0 && pi_scale_width[i_scale_idx] != SCALE_UNIT ) ||
777 ( pi_scale_height[i_scale_idx] > 0 && pi_scale_height[i_scale_idx] != SCALE_UNIT ) ||
778 ( b_force_palette ) ) )
780 const unsigned i_dst_width = p_region->fmt.i_width * pi_scale_width[i_scale_idx] / SCALE_UNIT;
781 const unsigned i_dst_height = p_region->fmt.i_height * pi_scale_height[i_scale_idx] / SCALE_UNIT;
783 /* Destroy if cache is unusable */
784 if( p_region->p_cache )
786 if( p_region->p_cache->fmt.i_width != i_dst_width ||
787 p_region->p_cache->fmt.i_height != i_dst_height ||
790 p_subpic->pf_destroy_region( VLC_OBJECT(p_spu),
792 p_region->p_cache = NULL;
796 /* Scale if needed into cache */
797 if( !p_region->p_cache )
801 p_scale->fmt_in.video = p_region->fmt;
802 p_scale->fmt_out.video = p_region->fmt;
805 p_subpic->pf_create_region( VLC_OBJECT(p_spu),
806 &p_scale->fmt_out.video );
807 p_region->p_cache->p_next = p_region->p_next;
809 if( p_scale->fmt_out.video.p_palette )
810 *p_scale->fmt_out.video.p_palette =
811 *p_region->fmt.p_palette;
813 vout_CopyPicture( p_spu, &p_region->p_cache->picture,
814 &p_region->picture );
816 p_scale->fmt_out.video.i_width = i_dst_width;
817 p_scale->fmt_out.video.i_height = i_dst_height;
819 p_scale->fmt_out.video.i_visible_width =
820 p_region->fmt.i_visible_width * pi_scale_width[ i_scale_idx ] / SCALE_UNIT;
821 p_scale->fmt_out.video.i_visible_height =
822 p_region->fmt.i_visible_height * pi_scale_height[ i_scale_idx ] / SCALE_UNIT;
824 p_region->p_cache->fmt = p_scale->fmt_out.video;
825 p_region->p_cache->i_x = p_region->i_x * pi_scale_width[ i_scale_idx ] / SCALE_UNIT;
826 p_region->p_cache->i_y = p_region->i_y * pi_scale_height[ i_scale_idx ] / SCALE_UNIT;
827 p_region->p_cache->i_align = p_region->i_align;
828 p_region->p_cache->i_alpha = p_region->i_alpha;
831 if( p_scale->p_module )
832 p_pic = p_scale->pf_video_filter( p_scale, &p_region->p_cache->picture );
834 msg_Err( p_spu, "scaling failed (module not loaded)" );
838 p_region->p_cache->picture = *p_pic;
843 p_subpic->pf_destroy_region( VLC_OBJECT(p_spu),
845 p_region->p_cache = NULL;
849 /* And use the scaled picture */
850 if( p_region->p_cache )
852 p_region = p_region->p_cache;
853 fmt_original = p_region->fmt;
858 SpuRegionPlace( &i_x_offset, &i_y_offset,
859 p_fmt, p_subpic, p_region,
860 i_inv_scale_x, i_inv_scale_y );
862 if( p_spu->i_margin != 0 && !b_force_crop )
865 int i_low = (i_y_offset - p_spu->i_margin) * i_inv_scale_y / SCALE_UNIT;
866 int i_high = i_low + p_region->fmt.i_height;
868 /* crop extra margin to keep within bounds */
871 if( i_high > (int)p_fmt->i_height )
872 i_diff = i_high - p_fmt->i_height;
873 i_y_offset -= ( p_spu->i_margin * i_inv_scale_y / SCALE_UNIT + i_diff );
876 /* Force cropping if requested */
879 video_format_t *p_fmt = &p_region->fmt;
880 int i_crop_x = p_spu->i_crop_x * pi_scale_width[ i_scale_idx ] / SCALE_UNIT
881 * i_inv_scale_x / SCALE_UNIT;
882 int i_crop_y = p_spu->i_crop_y * pi_scale_height[ i_scale_idx ] / SCALE_UNIT
883 * i_inv_scale_y / SCALE_UNIT;
884 int i_crop_width = p_spu->i_crop_width * pi_scale_width[ i_scale_idx ] / SCALE_UNIT
885 * i_inv_scale_x / SCALE_UNIT;
886 int i_crop_height = p_spu->i_crop_height * pi_scale_height[ i_scale_idx ] / SCALE_UNIT
887 * i_inv_scale_y / SCALE_UNIT;
889 /* Find the intersection */
890 if( i_crop_x + i_crop_width <= i_x_offset ||
891 i_x_offset + (int)p_fmt->i_visible_width < i_crop_x ||
892 i_crop_y + i_crop_height <= i_y_offset ||
893 i_y_offset + (int)p_fmt->i_visible_height < i_crop_y )
895 /* No intersection */
896 p_fmt->i_visible_width = p_fmt->i_visible_height = 0;
900 int i_x, i_y, i_x_end, i_y_end;
901 i_x = __MAX( i_crop_x, i_x_offset );
902 i_y = __MAX( i_crop_y, i_y_offset );
903 i_x_end = __MIN( i_crop_x + i_crop_width,
904 i_x_offset + (int)p_fmt->i_visible_width );
905 i_y_end = __MIN( i_crop_y + i_crop_height,
906 i_y_offset + (int)p_fmt->i_visible_height );
908 p_fmt->i_x_offset = i_x - i_x_offset;
909 p_fmt->i_y_offset = i_y - i_y_offset;
910 p_fmt->i_visible_width = i_x_end - i_x;
911 p_fmt->i_visible_height = i_y_end - i_y;
916 b_restore_format = true;
919 i_x_offset = __MAX( i_x_offset, 0 );
920 i_y_offset = __MAX( i_y_offset, 0 );
922 /* Compute alpha blend value */
924 if( p_subpic->b_fade )
926 mtime_t i_fade_start = ( p_subpic->i_stop +
927 p_subpic->i_start ) / 2;
928 mtime_t i_now = mdate();
929 if( i_now >= i_fade_start && p_subpic->i_stop > i_fade_start )
931 i_fade_alpha = 255 * ( p_subpic->i_stop - i_now ) /
932 ( p_subpic->i_stop - i_fade_start );
936 /* Update the blender */
937 SpuRenderUpdateBlend( p_spu, p_fmt->i_width, p_fmt->i_height, &p_region->fmt );
939 if( p_spu->p_blend->p_module )
941 p_spu->p_blend->pf_video_blend( p_spu->p_blend, p_pic_dst,
942 &p_region->picture, i_x_offset, i_y_offset,
943 i_fade_alpha * p_subpic->i_alpha * p_region->i_alpha / 65025 );
947 msg_Err( p_spu, "blending %4.4s to %4.4s failed",
948 (char *)&p_spu->p_blend->fmt_out.video.i_chroma,
949 (char *)&p_spu->p_blend->fmt_out.video.i_chroma );
953 if( b_rerender_text )
955 /* Some forms of subtitles need to be re-rendered more than
956 * once, eg. karaoke. We therefore restore the region to its
957 * pre-rendered state, so the next time through everything is
960 p_region->picture.pf_release( &p_region->picture );
961 memset( &p_region->picture, 0, sizeof( picture_t ) );
962 p_region->i_align &= ~SUBPICTURE_RENDERED;
964 if( b_restore_format )
965 p_region->fmt = fmt_original;
968 void spu_RenderSubpictures( spu_t *p_spu, video_format_t *p_fmt,
969 picture_t *p_pic_dst,
970 subpicture_t *p_subpic_list,
971 int i_scale_width_orig, int i_scale_height_orig )
973 const mtime_t i_current_date = mdate();
974 int i_source_video_width;
975 int i_source_video_height;
976 subpicture_t *p_subpic;
979 vlc_mutex_lock( &p_spu->subpicture_lock );
981 if( i_scale_width_orig <= 0 )
982 i_scale_width_orig = SCALE_UNIT;
983 if( i_scale_height_orig <= 0 )
984 i_scale_height_orig = SCALE_UNIT;
986 i_source_video_width = p_fmt->i_width * SCALE_UNIT / i_scale_width_orig;
987 i_source_video_height = p_fmt->i_height * SCALE_UNIT / i_scale_height_orig;
989 /* Check i_status again to make sure spudec hasn't destroyed the subpic */
990 for( p_subpic = p_subpic_list;
991 p_subpic != NULL && p_subpic->i_status != FREE_SUBPICTURE;
992 p_subpic = p_subpic->p_next )
994 /* If the source video and subtitles stream agree on the size of
995 * the video then disregard all further references to the subtitle
998 if( ( i_source_video_height == p_subpic->i_original_picture_height ) &&
999 ( i_source_video_width == p_subpic->i_original_picture_width ) )
1001 /* FIXME this looks wrong */
1002 p_subpic->i_original_picture_height = 0;
1003 p_subpic->i_original_picture_width = 0;
1007 if( p_subpic->pf_pre_render )
1008 p_subpic->pf_pre_render( p_fmt, p_spu, p_subpic );
1010 if( p_subpic->pf_update_regions )
1012 /* TODO do not reverse the scaling that was done before calling
1013 * spu_RenderSubpictures, just pass it along (or do it inside
1014 * spu_RenderSubpictures) */
1015 video_format_t fmt_org = *p_fmt;
1017 fmt_org.i_visible_width = i_source_video_width;
1019 fmt_org.i_visible_height = i_source_video_height;
1021 p_subpic->pf_update_regions( &fmt_org, p_spu, p_subpic, i_current_date );
1025 /* Create the blending module */
1026 if( !p_spu->p_blend )
1027 SpuRenderCreateBlend( p_spu, p_fmt->i_chroma, p_fmt->i_aspect );
1029 /* Load the scaling module */
1030 if( !p_spu->p_scale && !p_spu->p_scale_yuvp )
1031 SpuRenderCreateAndLoadScale( p_spu );
1033 /* Load the text rendering module; it is possible there is a
1034 * text region somewhere in the subpicture other than the first
1035 * element in the region list, so just load it anyway as we'll
1036 * probably want it sooner or later. */
1037 if( !p_spu->p_text )
1038 SpuRenderCreateAndLoadText( p_spu, p_fmt->i_width, p_fmt->i_height );
1040 /* Process all subpictures and regions */
1041 for( p_subpic = p_subpic_list;
1042 p_subpic != NULL && p_subpic->i_status != FREE_SUBPICTURE;
1043 p_subpic = p_subpic->p_next )
1045 subpicture_region_t *p_region;
1046 int pi_scale_width[ SCALE_SIZE ];
1047 int pi_scale_height[ SCALE_SIZE ];
1050 if( !p_subpic->p_region )
1056 subpicture_region_t *p_text_region = p_subpic->p_region;
1058 /* Only overwrite the size fields if the region is still in
1059 * pre-rendered TEXT format. We have to traverse the subregion
1060 * list because if more than one subregion is present, the text
1061 * region isn't guarentteed to be the first in the list, and
1062 * only text regions use this flag. All of this effort assists
1063 * with the rescaling of text that has been rendered at native
1064 * resolution, rather than video resolution.
1066 while( p_text_region &&
1067 p_text_region->fmt.i_chroma != VLC_FOURCC('T','E','X','T') )
1069 p_text_region = p_text_region->p_next;
1072 if( p_text_region &&
1073 ( ( p_text_region->i_align & SUBPICTURE_RENDERED ) == 0 ) )
1075 if( p_subpic->i_original_picture_height > 0 &&
1076 p_subpic->i_original_picture_width > 0 )
1078 p_spu->p_text->fmt_out.video.i_width =
1079 p_spu->p_text->fmt_out.video.i_visible_width =
1080 p_subpic->i_original_picture_width;
1081 p_spu->p_text->fmt_out.video.i_height =
1082 p_spu->p_text->fmt_out.video.i_visible_height =
1083 p_subpic->i_original_picture_height;
1087 p_spu->p_text->fmt_out.video.i_width =
1088 p_spu->p_text->fmt_out.video.i_visible_width =
1090 p_spu->p_text->fmt_out.video.i_height =
1091 p_spu->p_text->fmt_out.video.i_visible_height =
1097 * scale[] allows to pass from rendered size (by text module) to video output size */
1098 pi_scale_width[SCALE_TEXT] = p_fmt->i_width * SCALE_UNIT /
1099 p_spu->p_text->fmt_out.video.i_width;
1100 pi_scale_height[SCALE_TEXT]= p_fmt->i_height * SCALE_UNIT /
1101 p_spu->p_text->fmt_out.video.i_height;
1105 /* Just set a value to avoid using invalid memory while looping over the array */
1106 pi_scale_width[SCALE_TEXT] =
1107 pi_scale_height[SCALE_TEXT]= SCALE_UNIT;
1111 * scale[] allows to pass from native (either video or original) size to output size */
1112 if( p_subpic->i_original_picture_height > 0 &&
1113 p_subpic->i_original_picture_width > 0 )
1115 pi_scale_width[SCALE_DEFAULT] = p_fmt->i_width * SCALE_UNIT / p_subpic->i_original_picture_width;
1116 pi_scale_height[SCALE_DEFAULT] = p_fmt->i_height * SCALE_UNIT / p_subpic->i_original_picture_height;
1120 pi_scale_width[ SCALE_DEFAULT ] = i_scale_width_orig;
1121 pi_scale_height[ SCALE_DEFAULT ] = i_scale_height_orig;
1124 for( k = 0; k < SCALE_SIZE ; k++ )
1126 /* Case of both width and height being specified has been dealt
1127 * with above by instead rendering to an output pane of the
1128 * explicit dimensions specified - we don't need to scale it.
1130 if( p_subpic->i_original_picture_height > 0 &&
1131 p_subpic->i_original_picture_width <= 0 )
1133 pi_scale_height[ k ] = pi_scale_height[ k ] * i_source_video_height /
1134 p_subpic->i_original_picture_height;
1135 pi_scale_width[ k ] = pi_scale_width[ k ] * i_source_video_height /
1136 p_subpic->i_original_picture_height;
1140 /* Set default subpicture aspect ratio
1141 * FIXME if we only handle 1 aspect ratio per picture, why is it set per
1143 p_region = p_subpic->p_region;
1144 if( !p_region->fmt.i_sar_num || !p_region->fmt.i_sar_den )
1146 if( p_region->fmt.i_aspect != 0 )
1148 p_region->fmt.i_sar_den = p_region->fmt.i_aspect;
1149 p_region->fmt.i_sar_num = VOUT_ASPECT_FACTOR;
1153 p_region->fmt.i_sar_den = p_fmt->i_sar_den;
1154 p_region->fmt.i_sar_num = p_fmt->i_sar_num;
1158 /* Take care of the aspect ratio */
1159 if( ( p_region->fmt.i_sar_num * p_fmt->i_sar_den ) !=
1160 ( p_region->fmt.i_sar_den * p_fmt->i_sar_num ) )
1162 /* FIXME FIXME what about region->i_x/i_y ? */
1163 for( k = 0; k < SCALE_SIZE; k++ )
1165 pi_scale_width[k] = pi_scale_width[k] *
1166 (int64_t)p_region->fmt.i_sar_num * p_fmt->i_sar_den /
1167 p_region->fmt.i_sar_den / p_fmt->i_sar_num;
1171 /* Render all regions */
1172 for( ; p_region != NULL; p_region = p_region->p_next )
1173 SpuRenderRegion( p_spu, p_pic_dst,
1174 p_subpic, p_region, i_scale_width_orig, i_scale_height_orig,
1175 pi_scale_width, pi_scale_height,
1179 vlc_mutex_unlock( &p_spu->subpicture_lock );
1182 /*****************************************************************************
1183 * spu_SortSubpictures: find the subpictures to display
1184 *****************************************************************************
1185 * This function parses all subpictures and decides which ones need to be
1186 * displayed. This operation does not need lock, since only READY_SUBPICTURE
1187 * are handled. If no picture has been selected, display_date will depend on
1189 * We also check for ephemer DVD subpictures (subpictures that have
1190 * to be removed if a newer one is available), which makes it a lot
1191 * more difficult to guess if a subpicture has to be rendered or not.
1192 *****************************************************************************/
1193 subpicture_t *spu_SortSubpictures( spu_t *p_spu, mtime_t display_date,
1194 bool b_paused, bool b_subtitle_only )
1197 subpicture_t *p_subpic = NULL;
1199 /* Run subpicture filters */
1200 filter_chain_SubFilter( p_spu->p_chain, display_date );
1202 /* We get an easily parsable chained list of subpictures which
1203 * ends with NULL since p_subpic was initialized to NULL. */
1204 for( i_channel = 0; i_channel < p_spu->i_channel; i_channel++ )
1206 subpicture_t *p_ephemer = NULL;
1207 mtime_t ephemer_date = 0;
1210 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
1212 subpicture_t *p_current = &p_spu->p_subpicture[i_index];
1214 if( p_current->i_channel != i_channel ||
1215 p_current->i_status != READY_SUBPICTURE ||
1216 ( b_subtitle_only && !p_current->b_subtitle ) )
1221 display_date < p_current->i_start )
1223 /* Too early, come back next monday */
1227 if( p_current->i_start > ephemer_date )
1228 ephemer_date = p_current->i_start;
1230 if( display_date > p_current->i_stop &&
1231 ( !p_current->b_ephemer || p_current->i_stop > p_current->i_start ) &&
1232 !( p_current->b_subtitle && b_paused ) ) /* XXX Assume that subtitle are pausable */
1234 /* Too late, destroy the subpic */
1235 spu_DestroySubpicture( p_spu, &p_spu->p_subpicture[i_index] );
1239 /* If this is an ephemer subpic, add it to our list */
1240 if( p_current->b_ephemer )
1242 p_current->p_next = p_ephemer;
1243 p_ephemer = p_current;
1248 p_current->p_next = p_subpic;
1249 p_subpic = p_current;
1252 /* If we found ephemer subpictures, check if they have to be
1253 * displayed or destroyed */
1254 while( p_ephemer != NULL )
1256 subpicture_t *p_tmp = p_ephemer;
1257 p_ephemer = p_ephemer->p_next;
1259 if( p_tmp->i_start < ephemer_date )
1261 /* Ephemer subpicture has lived too long */
1262 spu_DestroySubpicture( p_spu, p_tmp );
1266 /* Ephemer subpicture can still live a bit */
1267 p_tmp->p_next = p_subpic;
1276 /*****************************************************************************
1277 * SpuClearChannel: clear an spu channel
1278 *****************************************************************************
1279 * This function destroys the subpictures which belong to the spu channel
1280 * corresponding to i_channel_id.
1281 *****************************************************************************/
1282 static void SpuClearChannel( spu_t *p_spu, int i_channel, bool b_locked )
1284 int i_subpic; /* subpicture index */
1285 subpicture_t *p_subpic = NULL; /* first free subpicture */
1288 vlc_mutex_lock( &p_spu->subpicture_lock );
1290 for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
1292 p_subpic = &p_spu->p_subpicture[i_subpic];
1293 if( p_subpic->i_status == FREE_SUBPICTURE
1294 || ( p_subpic->i_status != RESERVED_SUBPICTURE
1295 && p_subpic->i_status != READY_SUBPICTURE ) )
1300 if( p_subpic->i_channel == i_channel )
1302 while( p_subpic->p_region )
1304 subpicture_region_t *p_region = p_subpic->p_region;
1305 p_subpic->p_region = p_region->p_next;
1306 spu_DestroyRegion( p_spu, p_region );
1309 if( p_subpic->pf_destroy ) p_subpic->pf_destroy( p_subpic );
1310 p_subpic->i_status = FREE_SUBPICTURE;
1315 vlc_mutex_unlock( &p_spu->subpicture_lock );
1318 /*****************************************************************************
1319 * spu_ControlDefault: default methods for the subpicture unit control.
1320 *****************************************************************************/
1321 static int spu_vaControlDefault( spu_t *p_spu, int i_query, va_list args )
1327 case SPU_CHANNEL_REGISTER:
1328 pi = (int *)va_arg( args, int * );
1329 vlc_mutex_lock( &p_spu->subpicture_lock );
1331 *pi = p_spu->i_channel++;
1332 vlc_mutex_unlock( &p_spu->subpicture_lock );
1335 case SPU_CHANNEL_CLEAR:
1336 i = (int)va_arg( args, int );
1337 SpuClearChannel( p_spu, i, false );
1341 msg_Dbg( p_spu, "control query not supported" );
1342 return VLC_EGENERIC;
1348 /*****************************************************************************
1349 * Object variables callbacks
1350 *****************************************************************************/
1352 /*****************************************************************************
1353 * UpdateSPU: update subpicture settings
1354 *****************************************************************************
1355 * This function is called from CropCallback and at initialization time, to
1356 * retrieve crop information from the input.
1357 *****************************************************************************/
1358 static void UpdateSPU( spu_t *p_spu, vlc_object_t *p_object )
1362 vlc_mutex_lock( &p_spu->subpicture_lock );
1364 p_spu->b_force_palette = false;
1365 p_spu->b_force_crop = false;
1367 if( var_Get( p_object, "highlight", &val ) || !val.b_bool )
1369 vlc_mutex_unlock( &p_spu->subpicture_lock );
1373 p_spu->b_force_crop = true;
1374 var_Get( p_object, "x-start", &val );
1375 p_spu->i_crop_x = val.i_int;
1376 var_Get( p_object, "y-start", &val );
1377 p_spu->i_crop_y = val.i_int;
1378 var_Get( p_object, "x-end", &val );
1379 p_spu->i_crop_width = val.i_int - p_spu->i_crop_x;
1380 var_Get( p_object, "y-end", &val );
1381 p_spu->i_crop_height = val.i_int - p_spu->i_crop_y;
1383 if( var_Get( p_object, "menu-palette", &val ) == VLC_SUCCESS )
1385 memcpy( p_spu->palette, val.p_address, 16 );
1386 p_spu->b_force_palette = true;
1388 vlc_mutex_unlock( &p_spu->subpicture_lock );
1390 msg_Dbg( p_object, "crop: %i,%i,%i,%i, palette forced: %i",
1391 p_spu->i_crop_x, p_spu->i_crop_y,
1392 p_spu->i_crop_width, p_spu->i_crop_height,
1393 p_spu->b_force_palette );
1396 /*****************************************************************************
1397 * CropCallback: called when the highlight properties are changed
1398 *****************************************************************************
1399 * This callback is called from the input thread when we need cropping
1400 *****************************************************************************/
1401 static int CropCallback( vlc_object_t *p_object, char const *psz_var,
1402 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1404 (void)psz_var; (void)oldval; (void)newval;
1405 UpdateSPU( (spu_t *)p_data, p_object );
1409 /*****************************************************************************
1410 * Buffers allocation callbacks for the filters
1411 *****************************************************************************/
1412 static subpicture_t *sub_new_buffer( filter_t *p_filter )
1414 filter_owner_sys_t *p_sys = p_filter->p_owner;
1415 subpicture_t *p_subpicture = spu_CreateSubpicture( p_sys->p_spu );
1416 if( p_subpicture ) p_subpicture->i_channel = p_sys->i_channel;
1417 return p_subpicture;
1420 static void sub_del_buffer( filter_t *p_filter, subpicture_t *p_subpic )
1422 filter_owner_sys_t *p_sys = p_filter->p_owner;
1423 spu_DestroySubpicture( p_sys->p_spu, p_subpic );
1426 static subpicture_t *spu_new_buffer( filter_t *p_filter )
1429 subpicture_t *p_subpic = (subpicture_t *)malloc(sizeof(subpicture_t));
1430 if( !p_subpic ) return NULL;
1431 memset( p_subpic, 0, sizeof(subpicture_t) );
1432 p_subpic->b_absolute = true;
1434 p_subpic->pf_create_region = __spu_CreateRegion;
1435 p_subpic->pf_make_region = __spu_MakeRegion;
1436 p_subpic->pf_destroy_region = __spu_DestroyRegion;
1441 static void spu_del_buffer( filter_t *p_filter, subpicture_t *p_subpic )
1443 while( p_subpic->p_region )
1445 subpicture_region_t *p_region = p_subpic->p_region;
1446 p_subpic->p_region = p_region->p_next;
1447 p_subpic->pf_destroy_region( VLC_OBJECT(p_filter), p_region );
1453 static picture_t *spu_new_video_buffer( filter_t *p_filter )
1455 picture_t *p_picture = malloc( sizeof(picture_t) );
1456 if( !p_picture ) return NULL;
1457 if( vout_AllocatePicture( p_filter, p_picture,
1458 p_filter->fmt_out.video.i_chroma,
1459 p_filter->fmt_out.video.i_width,
1460 p_filter->fmt_out.video.i_height,
1461 p_filter->fmt_out.video.i_aspect )
1468 p_picture->pf_release = RegionPictureRelease;
1473 static void spu_del_video_buffer( filter_t *p_filter, picture_t *p_pic )
1478 free( p_pic->p_data_orig );
1483 static int SubFilterCallback( vlc_object_t *p_object, char const *psz_var,
1484 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1486 VLC_UNUSED(p_object); VLC_UNUSED(oldval);
1487 VLC_UNUSED(newval); VLC_UNUSED(psz_var);
1489 spu_t *p_spu = (spu_t *)p_data;
1490 vlc_mutex_lock( &p_spu->subpicture_lock );
1491 filter_chain_Reset( p_spu->p_chain, NULL, NULL );
1492 spu_ParseChain( p_spu );
1493 vlc_mutex_unlock( &p_spu->subpicture_lock );
1497 static int sub_filter_allocation_init( filter_t *p_filter, void *p_data )
1499 spu_t *p_spu = (spu_t *)p_data;
1501 p_filter->pf_sub_buffer_new = sub_new_buffer;
1502 p_filter->pf_sub_buffer_del = sub_del_buffer;
1504 filter_owner_sys_t *p_sys = malloc( sizeof(filter_owner_sys_t) );
1505 if( !p_sys ) return VLC_EGENERIC;
1507 p_filter->p_owner = p_sys;
1508 spu_Control( p_spu, SPU_CHANNEL_REGISTER, &p_sys->i_channel );
1509 p_sys->p_spu = p_spu;
1514 static void sub_filter_allocation_clear( filter_t *p_filter )
1516 filter_owner_sys_t *p_sys = p_filter->p_owner;
1517 SpuClearChannel( p_sys->p_spu, p_sys->i_channel, true );
1518 free( p_filter->p_owner );