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
77 * Creates the subpicture unit
79 * \param p_this the parent object which creates the subpicture unit
81 spu_t *__spu_Create( vlc_object_t *p_this )
84 spu_t *p_spu = vlc_custom_create( p_this, sizeof( spu_t ),
85 VLC_OBJECT_GENERIC, "subpicture" );
87 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++)
89 p_spu->p_subpicture[i_index].i_status = FREE_SUBPICTURE;
92 p_spu->p_blend = NULL;
94 p_spu->p_scale = NULL;
95 p_spu->pf_control = spu_vaControlDefault;
97 /* Register the default subpicture channel */
100 vlc_mutex_init( &p_spu->subpicture_lock );
102 vlc_object_attach( p_spu, p_this );
104 p_spu->p_chain = filter_chain_New( p_spu, "sub filter", false,
105 sub_filter_allocation_init,
106 sub_filter_allocation_clear,
112 * Initialise the subpicture unit
114 * \param p_spu the subpicture unit object
116 int spu_Init( spu_t *p_spu )
120 /* If the user requested a sub margin, we force the position. */
121 var_Create( p_spu, "sub-margin", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
122 var_Get( p_spu, "sub-margin", &val );
123 p_spu->i_margin = val.i_int;
125 var_Create( p_spu, "sub-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
126 var_AddCallback( p_spu, "sub-filter", SubFilterCallback, p_spu );
128 spu_ParseChain( p_spu );
133 int spu_ParseChain( spu_t *p_spu )
135 char *psz_parser = var_GetString( p_spu, "sub-filter" );
136 if( filter_chain_AppendFromString( p_spu->p_chain, psz_parser ) < 0 )
147 * Destroy the subpicture unit
149 * \param p_this the parent object which destroys the subpicture unit
151 void spu_Destroy( spu_t *p_spu )
155 /* Destroy all remaining subpictures */
156 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
158 if( p_spu->p_subpicture[i_index].i_status != FREE_SUBPICTURE )
160 spu_DestroySubpicture( p_spu, &p_spu->p_subpicture[i_index] );
166 if( p_spu->p_blend->p_module )
167 module_Unneed( p_spu->p_blend, p_spu->p_blend->p_module );
169 vlc_object_detach( p_spu->p_blend );
170 vlc_object_release( p_spu->p_blend );
175 if( p_spu->p_text->p_module )
176 module_Unneed( p_spu->p_text, p_spu->p_text->p_module );
178 vlc_object_detach( p_spu->p_text );
179 vlc_object_release( p_spu->p_text );
184 if( p_spu->p_scale->p_module )
185 module_Unneed( p_spu->p_scale, p_spu->p_scale->p_module );
187 vlc_object_detach( p_spu->p_scale );
188 vlc_object_release( p_spu->p_scale );
191 filter_chain_Delete( p_spu->p_chain );
193 vlc_mutex_destroy( &p_spu->subpicture_lock );
194 vlc_object_release( p_spu );
198 * Attach/Detach the SPU from any input
200 * \param p_this the object in which to destroy the subpicture unit
201 * \param b_attach to select attach or detach
203 void spu_Attach( spu_t *p_spu, vlc_object_t *p_this, bool b_attach )
205 vlc_object_t *p_input;
207 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_PARENT );
208 if( !p_input ) return;
212 UpdateSPU( p_spu, VLC_OBJECT(p_input) );
213 var_AddCallback( p_input, "highlight", CropCallback, p_spu );
214 vlc_object_release( p_input );
218 /* Delete callback */
219 var_DelCallback( p_input, "highlight", CropCallback, p_spu );
220 vlc_object_release( p_input );
225 * Create a subpicture region
227 * \param p_this vlc_object_t
228 * \param p_fmt the format that this subpicture region should have
230 static void RegionPictureRelease( picture_t *p_pic )
232 free( p_pic->p_data_orig );
234 subpicture_region_t *__spu_CreateRegion( vlc_object_t *p_this,
235 video_format_t *p_fmt )
237 subpicture_region_t *p_region = malloc( sizeof(subpicture_region_t) );
238 if( !p_region ) return NULL;
240 memset( p_region, 0, sizeof(subpicture_region_t) );
241 p_region->i_alpha = 0xff;
242 p_region->p_next = NULL;
243 p_region->p_cache = NULL;
244 p_region->fmt = *p_fmt;
245 p_region->psz_text = NULL;
246 p_region->p_style = NULL;
248 if( p_fmt->i_chroma == VLC_FOURCC('Y','U','V','P') )
249 p_fmt->p_palette = p_region->fmt.p_palette =
250 malloc( sizeof(video_palette_t) );
251 else p_fmt->p_palette = p_region->fmt.p_palette = NULL;
253 p_region->picture.p_data_orig = NULL;
255 if( p_fmt->i_chroma == VLC_FOURCC('T','E','X','T') ) return p_region;
257 vout_AllocatePicture( p_this, &p_region->picture, p_fmt->i_chroma,
258 p_fmt->i_width, p_fmt->i_height, p_fmt->i_aspect );
260 if( !p_region->picture.i_planes )
263 free( p_fmt->p_palette );
267 p_region->picture.pf_release = RegionPictureRelease;
273 * Make a subpicture region from an existing picture_t
275 * \param p_this vlc_object_t
276 * \param p_fmt the format that this subpicture region should have
277 * \param p_pic a pointer to the picture creating the region (not freed)
279 subpicture_region_t *__spu_MakeRegion( vlc_object_t *p_this,
280 video_format_t *p_fmt,
283 subpicture_region_t *p_region = malloc( sizeof(subpicture_region_t) );
285 if( !p_region ) return NULL;
286 memset( p_region, 0, sizeof(subpicture_region_t) );
287 p_region->i_alpha = 0xff;
288 p_region->p_next = 0;
289 p_region->p_cache = 0;
290 p_region->fmt = *p_fmt;
291 p_region->psz_text = 0;
292 p_region->p_style = NULL;
294 if( p_fmt->i_chroma == VLC_FOURCC('Y','U','V','P') )
295 p_fmt->p_palette = p_region->fmt.p_palette =
296 malloc( sizeof(video_palette_t) );
297 else p_fmt->p_palette = p_region->fmt.p_palette = NULL;
299 memcpy( &p_region->picture, p_pic, sizeof(picture_t) );
300 p_region->picture.pf_release = RegionPictureRelease;
306 * Destroy a subpicture region
308 * \param p_this vlc_object_t
309 * \param p_region the subpicture region to destroy
311 void __spu_DestroyRegion( vlc_object_t *p_this, subpicture_region_t *p_region )
313 if( !p_region ) return;
314 if( p_region->picture.pf_release )
315 p_region->picture.pf_release( &p_region->picture );
316 free( p_region->fmt.p_palette );
317 if( p_region->p_cache ) __spu_DestroyRegion( p_this, p_region->p_cache );
319 free( p_region->psz_text );
320 free( p_region->psz_html );
321 //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
326 * Display a subpicture
328 * Remove the reservation flag of a subpicture, which will cause it to be
330 * \param p_spu the subpicture unit object
331 * \param p_subpic the subpicture to display
333 void spu_DisplaySubpicture( spu_t *p_spu, subpicture_t *p_subpic )
335 /* Check if status is valid */
336 if( p_subpic->i_status != RESERVED_SUBPICTURE )
338 msg_Err( p_spu, "subpicture %p has invalid status #%d",
339 p_subpic, p_subpic->i_status );
342 /* Remove reservation flag */
343 p_subpic->i_status = READY_SUBPICTURE;
345 if( p_subpic->i_channel == DEFAULT_CHAN )
347 p_subpic->i_channel = 0xFFFF;
348 spu_Control( p_spu, SPU_CHANNEL_CLEAR, DEFAULT_CHAN );
349 p_subpic->i_channel = DEFAULT_CHAN;
354 * Allocate a subpicture in the spu heap.
356 * This function create a reserved subpicture in the spu heap.
357 * A null pointer is returned if the function fails. This method provides an
358 * already allocated zone of memory in the spu data fields. It needs locking
359 * since several pictures can be created by several producers threads.
360 * \param p_spu the subpicture unit in which to create the subpicture
361 * \return NULL on error, a reserved subpicture otherwise
363 subpicture_t *spu_CreateSubpicture( spu_t *p_spu )
365 int i_subpic; /* subpicture index */
366 subpicture_t * p_subpic = NULL; /* first free subpicture */
369 vlc_mutex_lock( &p_spu->subpicture_lock );
372 * Look for an empty place
375 for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
377 if( p_spu->p_subpicture[i_subpic].i_status == FREE_SUBPICTURE )
379 /* Subpicture is empty and ready for allocation */
380 p_subpic = &p_spu->p_subpicture[i_subpic];
381 p_spu->p_subpicture[i_subpic].i_status = RESERVED_SUBPICTURE;
386 /* If no free subpicture could be found */
387 if( p_subpic == NULL )
389 msg_Err( p_spu, "subpicture heap is full" );
390 vlc_mutex_unlock( &p_spu->subpicture_lock );
394 /* Copy subpicture information, set some default values */
395 memset( p_subpic, 0, sizeof(subpicture_t) );
396 p_subpic->i_status = RESERVED_SUBPICTURE;
397 p_subpic->b_absolute = true;
398 p_subpic->b_pausable = false;
399 p_subpic->b_fade = false;
400 p_subpic->i_alpha = 0xFF;
401 p_subpic->p_region = NULL;
402 p_subpic->pf_render = NULL;
403 p_subpic->pf_destroy = NULL;
404 p_subpic->p_sys = NULL;
405 vlc_mutex_unlock( &p_spu->subpicture_lock );
407 p_subpic->pf_create_region = __spu_CreateRegion;
408 p_subpic->pf_make_region = __spu_MakeRegion;
409 p_subpic->pf_destroy_region = __spu_DestroyRegion;
415 * Remove a subpicture from the heap
417 * This function frees a previously reserved subpicture.
418 * It is meant to be used when the construction of a picture aborted.
419 * This function does not need locking since reserved subpictures are ignored
422 void spu_DestroySubpicture( spu_t *p_spu, subpicture_t *p_subpic )
425 vlc_mutex_lock( &p_spu->subpicture_lock );
427 /* There can be race conditions so we need to check the status */
428 if( p_subpic->i_status == FREE_SUBPICTURE )
430 vlc_mutex_unlock( &p_spu->subpicture_lock );
434 /* Check if status is valid */
435 if( ( p_subpic->i_status != RESERVED_SUBPICTURE )
436 && ( p_subpic->i_status != READY_SUBPICTURE ) )
438 msg_Err( p_spu, "subpicture %p has invalid status %d",
439 p_subpic, p_subpic->i_status );
442 while( p_subpic->p_region )
444 subpicture_region_t *p_region = p_subpic->p_region;
445 p_subpic->p_region = p_region->p_next;
446 spu_DestroyRegion( p_spu, p_region );
449 if( p_subpic->pf_destroy )
451 p_subpic->pf_destroy( p_subpic );
454 p_subpic->i_status = FREE_SUBPICTURE;
456 vlc_mutex_unlock( &p_spu->subpicture_lock );
459 /*****************************************************************************
460 * spu_RenderSubpictures: render a subpicture list
461 *****************************************************************************
462 * This function renders all sub picture units in the list.
463 *****************************************************************************/
464 static void SpuRenderCreateBlend( spu_t *p_spu, vlc_fourcc_t i_chroma, int i_aspect )
468 assert( !p_spu->p_blend );
471 p_blend = vlc_custom_create( p_spu, sizeof(filter_t),
472 VLC_OBJECT_GENERIC, "blend" );
476 es_format_Init( &p_blend->fmt_in, VIDEO_ES, 0 );
478 es_format_Init( &p_blend->fmt_out, VIDEO_ES, 0 );
479 p_blend->fmt_out.video.i_x_offset = 0;
480 p_blend->fmt_out.video.i_y_offset = 0;
481 p_blend->fmt_out.video.i_chroma = i_chroma;
482 p_blend->fmt_out.video.i_aspect = i_aspect;
484 /* The blend module will be loaded when needed with the real
486 p_blend->p_module = NULL;
489 vlc_object_attach( p_blend, p_spu );
491 static void SpuRenderUpdateBlend( spu_t *p_spu, const video_format_t *p_vfmt )
493 filter_t *p_blend = p_spu->p_blend;
498 if( p_blend->p_module && p_blend->fmt_in.video.i_chroma != p_vfmt->i_chroma )
500 /* The chroma is not the same, we need to reload the blend module
501 * XXX to match the old behaviour just test !p_blend->fmt_in.video.i_chroma */
502 module_Unneed( p_blend, p_blend->p_module );
503 p_blend->p_module = NULL;
507 p_blend->fmt_in.video = *p_vfmt;
510 if( !p_blend->p_module )
511 p_blend->p_module = module_Need( p_blend, "video blending", 0, 0 );
513 static void SpuRenderCreateAndLoadText( spu_t *p_spu, int i_width, int i_height )
517 assert( !p_spu->p_text );
520 p_text = vlc_custom_create( p_spu, sizeof(filter_t),
521 VLC_OBJECT_GENERIC, "spu text" );
525 es_format_Init( &p_text->fmt_in, VIDEO_ES, 0 );
527 es_format_Init( &p_text->fmt_out, VIDEO_ES, 0 );
528 p_text->fmt_out.video.i_width =
529 p_text->fmt_out.video.i_visible_width = i_width;
530 p_text->fmt_out.video.i_height =
531 p_text->fmt_out.video.i_visible_height = i_height;
533 p_text->pf_sub_buffer_new = spu_new_buffer;
534 p_text->pf_sub_buffer_del = spu_del_buffer;
536 vlc_object_attach( p_text, p_spu );
538 /* FIXME TOCHECK shouldn't module_Need( , , psz_modulename, false ) do the
539 * same than these 2 calls ? */
540 char *psz_modulename = var_CreateGetString( p_spu, "text-renderer" );
541 if( psz_modulename && *psz_modulename )
543 p_text->p_module = module_Need( p_text, "text renderer",
544 psz_modulename, true );
546 free( psz_modulename );
548 if( !p_text->p_module )
549 p_text->p_module = module_Need( p_text, "text renderer", NULL, false );
552 static void SpuRenderCreateAndLoadScale( spu_t *p_spu )
554 /* FIXME: We'll also be using it for YUVA and RGBA blending ... */
555 const vlc_fourcc_t i_dummy_chroma = VLC_FOURCC('Y','U','V','P');
559 assert( !p_spu->p_scale );
562 p_scale = vlc_custom_create( p_spu, sizeof(filter_t),
563 VLC_OBJECT_GENERIC, "scale" );
567 es_format_Init( &p_scale->fmt_in, VIDEO_ES, 0 );
568 p_scale->fmt_in.video.i_chroma = i_dummy_chroma;
569 p_scale->fmt_in.video.i_width =
570 p_scale->fmt_in.video.i_height = 32;
572 es_format_Init( &p_scale->fmt_out, VIDEO_ES, 0 );
573 p_scale->fmt_out.video.i_chroma = i_dummy_chroma;
574 p_scale->fmt_out.video.i_width =
575 p_scale->fmt_out.video.i_height = 16;
577 p_scale->pf_vout_buffer_new = spu_new_video_buffer;
578 p_scale->pf_vout_buffer_del = spu_del_video_buffer;
580 vlc_object_attach( p_scale, p_spu );
581 p_scale->p_module = module_Need( p_spu->p_scale, "video filter2", 0, 0 );
584 //__MIN(i_scale_width_orig, i_scale_height_orig) );
585 static void SpuRenderText( spu_t *p_spu, bool *pb_rerender_text,
586 subpicture_t *p_subpic, subpicture_region_t *p_region, int i_min_scale_ratio )
588 assert( p_region->fmt.i_chroma == VLC_FOURCC('T','E','X','T') );
590 if( !p_spu->p_text || !p_spu->p_text->p_module )
593 /* Setup 3 variables which can be used to render
594 * time-dependent text (and effects). The first indicates
595 * the total amount of time the text will be on screen,
596 * the second the amount of time it has already been on
597 * screen (can be a negative value as text is layed out
598 * before it is rendered) and the third is a feedback
599 * variable from the renderer - if the renderer sets it
600 * then this particular text is time-dependent, eg. the
601 * visual progress bar inside the text in karaoke and the
602 * text needs to be rendered multiple times in order for
603 * the effect to work - we therefore need to return the
604 * region to its original state at the end of the loop,
605 * instead of leaving it in YUVA or YUVP.
606 * Any renderer which is unaware of how to render
607 * time-dependent text can happily ignore the variables
608 * and render the text the same as usual - it should at
609 * least show up on screen, but the effect won't change
610 * the text over time.
613 /* FIXME why these variables are recreated every time and not
614 * when text renderer module was created ? */
615 var_Create( p_spu->p_text, "spu-duration", VLC_VAR_TIME );
616 var_Create( p_spu->p_text, "spu-elapsed", VLC_VAR_TIME );
617 var_Create( p_spu->p_text, "text-rerender", VLC_VAR_BOOL );
618 var_Create( p_spu->p_text, "scale", VLC_VAR_INTEGER );
620 var_SetTime( p_spu->p_text, "spu-duration", p_subpic->i_stop - p_subpic->i_start );
621 var_SetTime( p_spu->p_text, "spu-elapsed", mdate() - p_subpic->i_start );
622 var_SetBool( p_spu->p_text, "text-rerender", false );
623 var_SetInteger( p_spu->p_text, "scale", i_min_scale_ratio );
625 if( p_spu->p_text->pf_render_html && p_region->psz_html )
627 p_spu->p_text->pf_render_html( p_spu->p_text,
628 p_region, p_region );
630 else if( p_spu->p_text->pf_render_text )
632 p_spu->p_text->pf_render_text( p_spu->p_text,
633 p_region, p_region );
635 *pb_rerender_text = var_GetBool( p_spu->p_text, "text-rerender" );
637 var_Destroy( p_spu->p_text, "spu-duration" );
638 var_Destroy( p_spu->p_text, "spu-elapsed" );
639 var_Destroy( p_spu->p_text, "text-rerender" );
640 var_Destroy( p_spu->p_text, "scale" );
643 p_region->i_align |= SUBPICTURE_RENDERED;
646 static void SpuRenderRegion( spu_t *p_spu,
647 picture_t *p_pic_dst, picture_t *p_pic_src,
648 subpicture_t *p_subpic, subpicture_region_t *p_region,
649 const int i_scale_width_orig, const int i_scale_height_orig,
650 const int pi_subpic_x[SCALE_SIZE],
651 const int pi_scale_width[SCALE_SIZE],
652 const int pi_scale_height[SCALE_SIZE],
653 const video_format_t *p_fmt )
655 video_format_t orig_fmt;
656 bool b_rerender_text;
664 orig_fmt = p_region->fmt;
665 b_rerender_text = false;
666 if( p_region->fmt.i_chroma == VLC_FOURCC('T','E','X','T') )
667 SpuRenderText( p_spu, &b_rerender_text, p_subpic, p_region, __MIN(i_scale_width_orig, i_scale_height_orig) );
669 /* From now on, we can only process non text data */
670 if( p_region->fmt.i_chroma == VLC_FOURCC('T','E','X','T') )
673 if( p_region->i_align & SUBPICTURE_RENDERED )
675 /* We are using a region which come from rendered text */
676 i_scale_idx = SCALE_TEXT;
677 i_inv_scale_x = i_scale_width_orig;
678 i_inv_scale_y = i_scale_height_orig;
682 i_scale_idx = SCALE_DEFAULT;
683 i_inv_scale_x = 1000;
684 i_inv_scale_y = 1000;
687 i_x_offset = (p_region->i_x + pi_subpic_x[ i_scale_idx ]) * i_inv_scale_x / 1000;
688 i_y_offset = (p_region->i_y + p_subpic->i_y) * i_inv_scale_y / 1000;
690 /* Force palette if requested */
691 if( p_spu->b_force_palette &&
692 p_region->fmt.i_chroma == VLC_FOURCC('Y','U','V','P') )
694 /* It looks so wrong I won't comment
695 * p_palette->palette is [256][4] with a int i_entries
696 * p_spu->palette is [4][4]
698 memcpy( p_region->fmt.p_palette->palette, p_spu->palette, 16 );
701 /* Scale SPU if necessary */
702 if( p_region->p_cache )
704 if( pi_scale_width[ i_scale_idx ] * p_region->fmt.i_width / 1000 !=
705 p_region->p_cache->fmt.i_width ||
706 pi_scale_height[ i_scale_idx ] * p_region->fmt.i_height / 1000 !=
707 p_region->p_cache->fmt.i_height )
709 p_subpic->pf_destroy_region( VLC_OBJECT(p_spu),
711 p_region->p_cache = NULL;
715 if( p_spu->p_scale &&
716 ( ( pi_scale_width[i_scale_idx] > 0 && pi_scale_width[i_scale_idx] != 1000 ) ||
717 ( pi_scale_height[i_scale_idx] > 0 && pi_scale_height[i_scale_idx] != 1000 ) ) )
719 if( !p_region->p_cache )
723 p_spu->p_scale->fmt_in.video = p_region->fmt;
724 p_spu->p_scale->fmt_out.video = p_region->fmt;
727 p_subpic->pf_create_region( VLC_OBJECT(p_spu),
728 &p_spu->p_scale->fmt_out.video );
729 if( p_spu->p_scale->fmt_out.video.p_palette )
730 *p_spu->p_scale->fmt_out.video.p_palette =
731 *p_region->fmt.p_palette;
732 p_region->p_cache->p_next = p_region->p_next;
734 vout_CopyPicture( p_spu, &p_region->p_cache->picture,
735 &p_region->picture );
737 p_spu->p_scale->fmt_out.video.i_width =
738 p_region->fmt.i_width * pi_scale_width[ i_scale_idx ] / 1000;
739 p_spu->p_scale->fmt_out.video.i_visible_width =
740 p_region->fmt.i_visible_width * pi_scale_width[ i_scale_idx ] / 1000;
741 p_spu->p_scale->fmt_out.video.i_height =
742 p_region->fmt.i_height * pi_scale_height[ i_scale_idx ] / 1000;
743 p_spu->p_scale->fmt_out.video.i_visible_height =
744 p_region->fmt.i_visible_height * pi_scale_height[ i_scale_idx ] / 1000;
745 p_region->p_cache->fmt = p_spu->p_scale->fmt_out.video;
746 p_region->p_cache->i_x = p_region->i_x * pi_scale_width[ i_scale_idx ] / 1000;
747 p_region->p_cache->i_y = p_region->i_y * pi_scale_height[ i_scale_idx ] / 1000;
748 p_region->p_cache->i_align = p_region->i_align;
749 p_region->p_cache->i_alpha = p_region->i_alpha;
751 p_pic = p_spu->p_scale->pf_video_filter(
752 p_spu->p_scale, &p_region->p_cache->picture );
755 picture_t p_pic_tmp = p_region->p_cache->picture;
756 p_region->p_cache->picture = *p_pic;
762 if( p_region->p_cache )
763 p_region = p_region->p_cache;
766 if( p_region->i_align & SUBPICTURE_ALIGN_BOTTOM )
768 i_y_offset = p_fmt->i_height - p_region->fmt.i_height -
769 (p_subpic->i_y + p_region->i_y) * i_inv_scale_y / 1000;
771 else if ( !(p_region->i_align & SUBPICTURE_ALIGN_TOP) )
773 i_y_offset = p_fmt->i_height / 2 - p_region->fmt.i_height / 2;
776 if( p_region->i_align & SUBPICTURE_ALIGN_RIGHT )
778 i_x_offset = p_fmt->i_width - p_region->fmt.i_width -
779 (pi_subpic_x[ i_scale_idx ] + p_region->i_x)
780 * i_inv_scale_x / 1000;
782 else if ( !(p_region->i_align & SUBPICTURE_ALIGN_LEFT) )
784 i_x_offset = p_fmt->i_width / 2 - p_region->fmt.i_width / 2;
787 if( p_subpic->b_absolute )
789 i_x_offset = (p_region->i_x +
790 pi_subpic_x[ i_scale_idx ] *
791 pi_scale_width[ i_scale_idx ] / 1000)
792 * i_inv_scale_x / 1000;
793 i_y_offset = (p_region->i_y +
794 p_subpic->i_y * pi_scale_height[ i_scale_idx ] / 1000)
795 * i_inv_scale_y / 1000;
799 i_x_offset = __MAX( i_x_offset, 0 );
800 i_y_offset = __MAX( i_y_offset, 0 );
802 if( p_spu->i_margin != 0 && !p_spu->b_force_crop )
805 int i_low = (i_y_offset - p_spu->i_margin) * i_inv_scale_y / 1000;
806 int i_high = i_low + p_region->fmt.i_height;
808 /* crop extra margin to keep within bounds */
811 if( i_high > (int)p_fmt->i_height )
812 i_diff = i_high - p_fmt->i_height;
813 i_y_offset -= ( p_spu->i_margin * i_inv_scale_y / 1000 + i_diff );
817 if( p_subpic->b_fade )
819 mtime_t i_fade_start = ( p_subpic->i_stop +
820 p_subpic->i_start ) / 2;
821 mtime_t i_now = mdate();
822 if( i_now >= i_fade_start && p_subpic->i_stop > i_fade_start )
824 i_fade_alpha = 255 * ( p_subpic->i_stop - i_now ) /
825 ( p_subpic->i_stop - i_fade_start );
830 SpuRenderUpdateBlend( p_spu, &p_region->fmt );
832 /* Force cropping if requested */
833 if( p_spu->b_force_crop )
835 video_format_t *p_fmt = &p_spu->p_blend->fmt_in.video;
836 int i_crop_x = p_spu->i_crop_x * pi_scale_width[ i_scale_idx ] / 1000
837 * i_inv_scale_x / 1000;
838 int i_crop_y = p_spu->i_crop_y * pi_scale_height[ i_scale_idx ] / 1000
839 * i_inv_scale_y / 1000;
840 int i_crop_width = p_spu->i_crop_width * pi_scale_width[ i_scale_idx ] / 1000
841 * i_inv_scale_x / 1000;
842 int i_crop_height = p_spu->i_crop_height * pi_scale_height[ i_scale_idx ] / 1000
843 * i_inv_scale_y / 1000;
845 /* Find the intersection */
846 if( i_crop_x + i_crop_width <= i_x_offset ||
847 i_x_offset + (int)p_fmt->i_visible_width < i_crop_x ||
848 i_crop_y + i_crop_height <= i_y_offset ||
849 i_y_offset + (int)p_fmt->i_visible_height < i_crop_y )
851 /* No intersection */
852 p_fmt->i_visible_width = p_fmt->i_visible_height = 0;
856 int i_x, i_y, i_x_end, i_y_end;
857 i_x = __MAX( i_crop_x, i_x_offset );
858 i_y = __MAX( i_crop_y, i_y_offset );
859 i_x_end = __MIN( i_crop_x + i_crop_width,
860 i_x_offset + (int)p_fmt->i_visible_width );
861 i_y_end = __MIN( i_crop_y + i_crop_height,
862 i_y_offset + (int)p_fmt->i_visible_height );
864 p_fmt->i_x_offset = i_x - i_x_offset;
865 p_fmt->i_y_offset = i_y - i_y_offset;
866 p_fmt->i_visible_width = i_x_end - i_x;
867 p_fmt->i_visible_height = i_y_end - i_y;
874 i_x_offset = __MAX( i_x_offset, 0 );
875 i_y_offset = __MAX( i_y_offset, 0 );
877 /* Update the output picture size */
878 p_spu->p_blend->fmt_out.video.i_width =
879 p_spu->p_blend->fmt_out.video.i_visible_width = p_fmt->i_width;
880 p_spu->p_blend->fmt_out.video.i_height =
881 p_spu->p_blend->fmt_out.video.i_visible_height = p_fmt->i_height;
883 if( p_spu->p_blend->p_module )
885 p_spu->p_blend->pf_video_blend( p_spu->p_blend, p_pic_dst,
886 p_pic_src, &p_region->picture, i_x_offset, i_y_offset,
887 i_fade_alpha * p_subpic->i_alpha * p_region->i_alpha / 65025 );
891 msg_Err( p_spu, "blending %4.4s to %4.4s failed",
892 (char *)&p_spu->p_blend->fmt_out.video.i_chroma,
893 (char *)&p_spu->p_blend->fmt_out.video.i_chroma );
897 if( b_rerender_text )
899 /* Some forms of subtitles need to be re-rendered more than
900 * once, eg. karaoke. We therefore restore the region to its
901 * pre-rendered state, so the next time through everything is
904 p_region->picture.pf_release( &p_region->picture );
905 memset( &p_region->picture, 0, sizeof( picture_t ) );
906 p_region->fmt = orig_fmt;
907 p_region->i_align &= ~SUBPICTURE_RENDERED;
911 void spu_RenderSubpictures( spu_t *p_spu, video_format_t *p_fmt,
912 picture_t *p_pic_dst, picture_t *p_pic_src,
913 subpicture_t *p_subpic,
914 int i_scale_width_orig, int i_scale_height_orig )
916 int i_source_video_width;
917 int i_source_video_height;
918 subpicture_t *p_subpic_v;
921 vlc_mutex_lock( &p_spu->subpicture_lock );
923 for( p_subpic_v = p_subpic;
924 p_subpic_v != NULL && p_subpic_v->i_status != FREE_SUBPICTURE;
925 p_subpic_v = p_subpic_v->p_next )
927 if( p_subpic_v->pf_pre_render )
929 p_subpic_v->pf_pre_render( p_fmt, p_spu, p_subpic_v, mdate() );
933 if( i_scale_width_orig <= 0 )
934 i_scale_width_orig = 1000;
935 if( i_scale_height_orig <= 0 )
936 i_scale_height_orig = 1000;
938 i_source_video_width = p_fmt->i_width * 1000 / i_scale_width_orig;
939 i_source_video_height = p_fmt->i_height * 1000 / i_scale_height_orig;
941 /* Check i_status again to make sure spudec hasn't destroyed the subpic */
942 for( ; ( p_subpic != NULL ) && ( p_subpic->i_status != FREE_SUBPICTURE ); p_subpic = p_subpic->p_next )
944 subpicture_region_t *p_region;
945 int pi_scale_width[ SCALE_SIZE ];
946 int pi_scale_height[ SCALE_SIZE ];
947 int pi_subpic_x[ SCALE_SIZE ];
950 /* If the source video and subtitles stream agree on the size of
951 * the video then disregard all further references to the subtitle
954 if( ( i_source_video_height == p_subpic->i_original_picture_height ) &&
955 ( i_source_video_width == p_subpic->i_original_picture_width ) )
957 p_subpic->i_original_picture_height = 0;
958 p_subpic->i_original_picture_width = 0;
961 for( k = 0; k < SCALE_SIZE ; k++ )
962 pi_subpic_x[ k ] = p_subpic->i_x;
964 if( p_subpic->pf_update_regions )
966 /* FIXME that part look like crap too if there is more than 1 region */
968 if( p_subpic->p_region )
969 spu_DestroyRegion( p_spu, p_subpic->p_region );
971 /* TODO do not reverse the scaling that was done before calling
972 * spu_RenderSubpictures, just pass it along (or do it inside
973 * spu_RenderSubpictures) */
974 video_format_t fmt_org = *p_fmt;
976 fmt_org.i_visible_width = i_source_video_width;
978 fmt_org.i_visible_height = i_source_video_height;
980 p_subpic->p_region = p_subpic->pf_update_regions( &fmt_org, p_spu, p_subpic, mdate() );
984 p_region = p_subpic->p_region;
988 /* Create the blending module */
989 if( !p_spu->p_blend )
990 SpuRenderCreateBlend( p_spu, p_fmt->i_chroma, p_fmt->i_aspect );
992 /* Load the text rendering module; it is possible there is a
993 * text region somewhere in the subpicture other than the first
994 * element in the region list, so just load it anyway as we'll
995 * probably want it sooner or later. */
997 SpuRenderCreateAndLoadText( p_spu, p_fmt->i_width, p_fmt->i_height );
1001 subpicture_region_t *p_text_region = p_subpic->p_region;
1003 /* Only overwrite the size fields if the region is still in
1004 * pre-rendered TEXT format. We have to traverse the subregion
1005 * list because if more than one subregion is present, the text
1006 * region isn't guarentteed to be the first in the list, and
1007 * only text regions use this flag. All of this effort assists
1008 * with the rescaling of text that has been rendered at native
1009 * resolution, rather than video resolution.
1011 while( p_text_region &&
1012 p_text_region->fmt.i_chroma != VLC_FOURCC('T','E','X','T') )
1014 p_text_region = p_text_region->p_next;
1017 if( p_text_region &&
1018 ( ( p_text_region->i_align & SUBPICTURE_RENDERED ) == 0 ) )
1020 if( (p_subpic->i_original_picture_height > 0) &&
1021 (p_subpic->i_original_picture_width > 0) )
1023 p_spu->p_text->fmt_out.video.i_width =
1024 p_spu->p_text->fmt_out.video.i_visible_width =
1025 p_subpic->i_original_picture_width;
1026 p_spu->p_text->fmt_out.video.i_height =
1027 p_spu->p_text->fmt_out.video.i_visible_height =
1028 p_subpic->i_original_picture_height;
1032 p_spu->p_text->fmt_out.video.i_width =
1033 p_spu->p_text->fmt_out.video.i_visible_width =
1035 p_spu->p_text->fmt_out.video.i_height =
1036 p_spu->p_text->fmt_out.video.i_visible_height =
1042 pi_scale_width[SCALE_TEXT] = p_fmt->i_width * 1000 /
1043 p_spu->p_text->fmt_out.video.i_width;
1044 pi_scale_height[SCALE_TEXT]= p_fmt->i_height * 1000 /
1045 p_spu->p_text->fmt_out.video.i_height;
1048 pi_scale_width[ SCALE_DEFAULT ] = i_scale_width_orig;
1049 pi_scale_height[ SCALE_DEFAULT ] = i_scale_height_orig;
1051 /* If we have an explicit size plane to render to, then turn off
1052 * the fontsize rescaling.
1054 if( (p_subpic->i_original_picture_height > 0) &&
1055 (p_subpic->i_original_picture_width > 0) )
1058 /* FIXME That seems so wrong */
1059 i_scale_width_orig = 1000;
1060 i_scale_height_orig = 1000;
1062 /* It is probably that :*/
1063 pi_scale_width[ SCALE_DEFAULT ] = i_scale_width_orig * i_source_video_width / p_subpic->i_original_picture_width;
1064 pi_scale_height[ SCALE_DEFAULT ] = i_scale_height_orig * i_source_video_height / p_subpic->i_original_picture_height;
1068 for( k = 0; k < SCALE_SIZE ; k++ )
1070 /* Case of both width and height being specified has been dealt
1071 * with above by instead rendering to an output pane of the
1072 * explicit dimensions specified - we don't need to scale it.
1074 if( (p_subpic->i_original_picture_height > 0) &&
1075 (p_subpic->i_original_picture_width <= 0) )
1077 pi_scale_height[ k ] = pi_scale_height[ k ] * i_source_video_height /
1078 p_subpic->i_original_picture_height;
1079 pi_scale_width[ k ] = pi_scale_width[ k ] * i_source_video_height /
1080 p_subpic->i_original_picture_height;
1084 /* Set default subpicture aspect ratio */
1085 if( p_region->fmt.i_aspect && ( !p_region->fmt.i_sar_num || !p_region->fmt.i_sar_den ) )
1087 p_region->fmt.i_sar_den = p_region->fmt.i_aspect;
1088 p_region->fmt.i_sar_num = VOUT_ASPECT_FACTOR;
1090 if( !p_region->fmt.i_sar_num || !p_region->fmt.i_sar_den )
1092 p_region->fmt.i_sar_den = p_fmt->i_sar_den;
1093 p_region->fmt.i_sar_num = p_fmt->i_sar_num;
1096 /* Take care of the aspect ratio */
1097 if( ( p_region->fmt.i_sar_num * p_fmt->i_sar_den ) !=
1098 ( p_region->fmt.i_sar_den * p_fmt->i_sar_num ) )
1100 for( k = 0; k < SCALE_SIZE ; k++ )
1102 pi_scale_width[ k ] = pi_scale_width[ k ] *
1103 (int64_t)p_region->fmt.i_sar_num * p_fmt->i_sar_den /
1104 p_region->fmt.i_sar_den / p_fmt->i_sar_num;
1105 pi_subpic_x[ k ] = p_subpic->i_x * pi_scale_width[ k ] / 1000;
1109 /* Load the scaling module when needed */
1110 if( !p_spu->p_scale )
1112 bool b_scale_used = false;
1114 for( k = 0; k < SCALE_SIZE ; k++ )
1116 const int i_scale_w = pi_scale_width[k];
1117 const int i_scale_h = pi_scale_height[k];
1118 if( ( i_scale_w > 0 && i_scale_w != 1000 ) || ( i_scale_h > 0 && i_scale_h != 1000 ) )
1119 b_scale_used = true;
1123 SpuRenderCreateAndLoadScale( p_spu );
1126 for( ; p_region != NULL; p_region = p_region->p_next )
1127 SpuRenderRegion( p_spu, p_pic_dst, p_pic_src,
1128 p_subpic, p_region, i_scale_width_orig, i_scale_height_orig,
1129 pi_subpic_x, pi_scale_width, pi_scale_height,
1133 vlc_mutex_unlock( &p_spu->subpicture_lock );
1136 /*****************************************************************************
1137 * spu_SortSubpictures: find the subpictures to display
1138 *****************************************************************************
1139 * This function parses all subpictures and decides which ones need to be
1140 * displayed. This operation does not need lock, since only READY_SUBPICTURE
1141 * are handled. If no picture has been selected, display_date will depend on
1143 * We also check for ephemer DVD subpictures (subpictures that have
1144 * to be removed if a newer one is available), which makes it a lot
1145 * more difficult to guess if a subpicture has to be rendered or not.
1146 *****************************************************************************/
1147 subpicture_t *spu_SortSubpictures( spu_t *p_spu, mtime_t display_date,
1150 int i_index, i_channel;
1151 subpicture_t *p_subpic = NULL;
1152 subpicture_t *p_ephemer;
1153 mtime_t ephemer_date;
1155 /* Run subpicture filters */
1156 filter_chain_SubFilter( p_spu->p_chain, display_date );
1158 /* We get an easily parsable chained list of subpictures which
1159 * ends with NULL since p_subpic was initialized to NULL. */
1160 for( i_channel = 0; i_channel < p_spu->i_channel; i_channel++ )
1165 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
1167 if( p_spu->p_subpicture[i_index].i_channel != i_channel ||
1168 p_spu->p_subpicture[i_index].i_status != READY_SUBPICTURE )
1173 display_date < p_spu->p_subpicture[i_index].i_start )
1175 /* Too early, come back next monday */
1179 if( p_spu->p_subpicture[i_index].i_start > ephemer_date )
1180 ephemer_date = p_spu->p_subpicture[i_index].i_start;
1182 if( display_date > p_spu->p_subpicture[i_index].i_stop &&
1183 ( !p_spu->p_subpicture[i_index].b_ephemer ||
1184 p_spu->p_subpicture[i_index].i_stop >
1185 p_spu->p_subpicture[i_index].i_start ) &&
1186 !( p_spu->p_subpicture[i_index].b_pausable &&
1189 /* Too late, destroy the subpic */
1190 spu_DestroySubpicture( p_spu, &p_spu->p_subpicture[i_index] );
1194 /* If this is an ephemer subpic, add it to our list */
1195 if( p_spu->p_subpicture[i_index].b_ephemer )
1197 p_spu->p_subpicture[i_index].p_next = p_ephemer;
1198 p_ephemer = &p_spu->p_subpicture[i_index];
1203 p_spu->p_subpicture[i_index].p_next = p_subpic;
1204 p_subpic = &p_spu->p_subpicture[i_index];
1207 /* If we found ephemer subpictures, check if they have to be
1208 * displayed or destroyed */
1209 while( p_ephemer != NULL )
1211 subpicture_t *p_tmp = p_ephemer;
1212 p_ephemer = p_ephemer->p_next;
1214 if( p_tmp->i_start < ephemer_date )
1216 /* Ephemer subpicture has lived too long */
1217 spu_DestroySubpicture( p_spu, p_tmp );
1221 /* Ephemer subpicture can still live a bit */
1222 p_tmp->p_next = p_subpic;
1231 /*****************************************************************************
1232 * SpuClearChannel: clear an spu channel
1233 *****************************************************************************
1234 * This function destroys the subpictures which belong to the spu channel
1235 * corresponding to i_channel_id.
1236 *****************************************************************************/
1237 static void SpuClearChannel( spu_t *p_spu, int i_channel, bool b_locked )
1239 int i_subpic; /* subpicture index */
1240 subpicture_t *p_subpic = NULL; /* first free subpicture */
1243 vlc_mutex_lock( &p_spu->subpicture_lock );
1245 for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
1247 p_subpic = &p_spu->p_subpicture[i_subpic];
1248 if( p_subpic->i_status == FREE_SUBPICTURE
1249 || ( p_subpic->i_status != RESERVED_SUBPICTURE
1250 && p_subpic->i_status != READY_SUBPICTURE ) )
1255 if( p_subpic->i_channel == i_channel )
1257 while( p_subpic->p_region )
1259 subpicture_region_t *p_region = p_subpic->p_region;
1260 p_subpic->p_region = p_region->p_next;
1261 spu_DestroyRegion( p_spu, p_region );
1264 if( p_subpic->pf_destroy ) p_subpic->pf_destroy( p_subpic );
1265 p_subpic->i_status = FREE_SUBPICTURE;
1270 vlc_mutex_unlock( &p_spu->subpicture_lock );
1273 /*****************************************************************************
1274 * spu_ControlDefault: default methods for the subpicture unit control.
1275 *****************************************************************************/
1276 static int spu_vaControlDefault( spu_t *p_spu, int i_query, va_list args )
1282 case SPU_CHANNEL_REGISTER:
1283 pi = (int *)va_arg( args, int * );
1284 if( pi ) *pi = p_spu->i_channel++;
1287 case SPU_CHANNEL_CLEAR:
1288 i = (int)va_arg( args, int );
1289 SpuClearChannel( p_spu, i, false );
1293 msg_Dbg( p_spu, "control query not supported" );
1294 return VLC_EGENERIC;
1300 /*****************************************************************************
1301 * Object variables callbacks
1302 *****************************************************************************/
1304 /*****************************************************************************
1305 * UpdateSPU: update subpicture settings
1306 *****************************************************************************
1307 * This function is called from CropCallback and at initialization time, to
1308 * retrieve crop information from the input.
1309 *****************************************************************************/
1310 static void UpdateSPU( spu_t *p_spu, vlc_object_t *p_object )
1314 p_spu->b_force_palette = false;
1315 p_spu->b_force_crop = false;
1317 if( var_Get( p_object, "highlight", &val ) || !val.b_bool ) return;
1319 p_spu->b_force_crop = true;
1320 var_Get( p_object, "x-start", &val );
1321 p_spu->i_crop_x = val.i_int;
1322 var_Get( p_object, "y-start", &val );
1323 p_spu->i_crop_y = val.i_int;
1324 var_Get( p_object, "x-end", &val );
1325 p_spu->i_crop_width = val.i_int - p_spu->i_crop_x;
1326 var_Get( p_object, "y-end", &val );
1327 p_spu->i_crop_height = val.i_int - p_spu->i_crop_y;
1329 if( var_Get( p_object, "menu-palette", &val ) == VLC_SUCCESS )
1331 memcpy( p_spu->palette, val.p_address, 16 );
1332 p_spu->b_force_palette = true;
1335 msg_Dbg( p_object, "crop: %i,%i,%i,%i, palette forced: %i",
1336 p_spu->i_crop_x, p_spu->i_crop_y,
1337 p_spu->i_crop_width, p_spu->i_crop_height,
1338 p_spu->b_force_palette );
1341 /*****************************************************************************
1342 * CropCallback: called when the highlight properties are changed
1343 *****************************************************************************
1344 * This callback is called from the input thread when we need cropping
1345 *****************************************************************************/
1346 static int CropCallback( vlc_object_t *p_object, char const *psz_var,
1347 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1349 (void)psz_var; (void)oldval; (void)newval;
1350 UpdateSPU( (spu_t *)p_data, p_object );
1354 /*****************************************************************************
1355 * Buffers allocation callbacks for the filters
1356 *****************************************************************************/
1357 static subpicture_t *sub_new_buffer( filter_t *p_filter )
1359 filter_owner_sys_t *p_sys = p_filter->p_owner;
1360 subpicture_t *p_subpicture = spu_CreateSubpicture( p_sys->p_spu );
1361 if( p_subpicture ) p_subpicture->i_channel = p_sys->i_channel;
1362 return p_subpicture;
1365 static void sub_del_buffer( filter_t *p_filter, subpicture_t *p_subpic )
1367 filter_owner_sys_t *p_sys = p_filter->p_owner;
1368 spu_DestroySubpicture( p_sys->p_spu, p_subpic );
1371 static subpicture_t *spu_new_buffer( filter_t *p_filter )
1374 subpicture_t *p_subpic = (subpicture_t *)malloc(sizeof(subpicture_t));
1375 if( !p_subpic ) return NULL;
1376 memset( p_subpic, 0, sizeof(subpicture_t) );
1377 p_subpic->b_absolute = true;
1379 p_subpic->pf_create_region = __spu_CreateRegion;
1380 p_subpic->pf_make_region = __spu_MakeRegion;
1381 p_subpic->pf_destroy_region = __spu_DestroyRegion;
1386 static void spu_del_buffer( filter_t *p_filter, subpicture_t *p_subpic )
1388 while( p_subpic->p_region )
1390 subpicture_region_t *p_region = p_subpic->p_region;
1391 p_subpic->p_region = p_region->p_next;
1392 p_subpic->pf_destroy_region( VLC_OBJECT(p_filter), p_region );
1398 static picture_t *spu_new_video_buffer( filter_t *p_filter )
1400 picture_t *p_picture = malloc( sizeof(picture_t) );
1401 if( !p_picture ) return NULL;
1402 if( vout_AllocatePicture( p_filter, p_picture,
1403 p_filter->fmt_out.video.i_chroma,
1404 p_filter->fmt_out.video.i_width,
1405 p_filter->fmt_out.video.i_height,
1406 p_filter->fmt_out.video.i_aspect )
1413 p_picture->pf_release = RegionPictureRelease;
1418 static void spu_del_video_buffer( filter_t *p_filter, picture_t *p_pic )
1423 free( p_pic->p_data_orig );
1428 static int SubFilterCallback( vlc_object_t *p_object, char const *psz_var,
1429 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1431 VLC_UNUSED(p_object); VLC_UNUSED(oldval);
1432 VLC_UNUSED(newval); VLC_UNUSED(psz_var);
1434 spu_t *p_spu = (spu_t *)p_data;
1435 vlc_mutex_lock( &p_spu->subpicture_lock );
1436 filter_chain_Reset( p_spu->p_chain, NULL, NULL );
1437 spu_ParseChain( p_spu );
1438 vlc_mutex_unlock( &p_spu->subpicture_lock );
1442 static int sub_filter_allocation_init( filter_t *p_filter, void *p_data )
1444 spu_t *p_spu = (spu_t *)p_data;
1446 p_filter->pf_sub_buffer_new = sub_new_buffer;
1447 p_filter->pf_sub_buffer_del = sub_del_buffer;
1449 filter_owner_sys_t *p_sys = malloc( sizeof(filter_owner_sys_t) );
1450 if( !p_sys ) return VLC_EGENERIC;
1452 p_filter->p_owner = p_sys;
1453 spu_Control( p_spu, SPU_CHANNEL_REGISTER, &p_sys->i_channel );
1454 p_sys->p_spu = p_spu;
1459 static void sub_filter_allocation_clear( filter_t *p_filter )
1461 filter_owner_sys_t *p_sys = p_filter->p_owner;
1462 SpuClearChannel( p_sys->p_spu, p_sys->i_channel, true );
1463 free( p_filter->p_owner );