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 *****************************************************************************/
31 #include <vlc_block.h>
32 #include <vlc_filter.h>
35 /*****************************************************************************
37 *****************************************************************************/
38 static void UpdateSPU ( spu_t *, vlc_object_t * );
39 static int CropCallback( vlc_object_t *, char const *,
40 vlc_value_t, vlc_value_t, void * );
42 static int spu_vaControlDefault( spu_t *, int, va_list );
44 static subpicture_t *sub_new_buffer( filter_t * );
45 static void sub_del_buffer( filter_t *, subpicture_t * );
46 static subpicture_t *spu_new_buffer( filter_t * );
47 static void spu_del_buffer( filter_t *, subpicture_t * );
48 static picture_t *spu_new_video_buffer( filter_t * );
49 static void spu_del_video_buffer( filter_t *, picture_t * );
51 static int spu_ParseChain( spu_t * );
52 static void spu_DeleteChain( spu_t * );
53 static int SubFilterCallback( vlc_object_t *, char const *,
54 vlc_value_t, vlc_value_t, void * );
56 struct filter_owner_sys_t
68 * Creates the subpicture unit
70 * \param p_this the parent object which creates the subpicture unit
72 spu_t *__spu_Create( vlc_object_t *p_this )
75 spu_t *p_spu = vlc_object_create( p_this, VLC_OBJECT_SPU );
77 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++)
79 p_spu->p_subpicture[i_index].i_status = FREE_SUBPICTURE;
82 p_spu->p_blend = NULL;
84 p_spu->p_scale = NULL;
86 p_spu->pf_control = spu_vaControlDefault;
88 /* Register the default subpicture channel */
91 vlc_mutex_init( p_this, &p_spu->subpicture_lock );
93 vlc_object_attach( p_spu, p_this );
99 * Initialise the subpicture unit
101 * \param p_spu the subpicture unit object
103 int spu_Init( spu_t *p_spu )
107 /* If the user requested a sub margin, we force the position. */
108 var_Create( p_spu, "sub-margin", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
109 var_Get( p_spu, "sub-margin", &val );
110 p_spu->i_margin = val.i_int;
112 var_Create( p_spu, "sub-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
113 var_AddCallback( p_spu, "sub-filter", SubFilterCallback, p_spu );
115 spu_ParseChain( p_spu );
120 int spu_ParseChain( spu_t *p_spu )
124 var_Get( p_spu, "sub-filter", &val );
125 psz_parser = val.psz_string;
127 while( psz_parser && *psz_parser )
129 config_chain_t *p_cfg;
132 psz_parser = config_ChainCreate( &psz_name, &p_cfg, psz_parser );
134 msg_Dbg( p_spu, "adding sub-filter: %s", psz_name );
136 p_spu->pp_filter[p_spu->i_filter] =
137 vlc_object_create( p_spu, VLC_OBJECT_FILTER );
138 vlc_object_attach( p_spu->pp_filter[p_spu->i_filter], p_spu );
139 p_spu->pp_filter[p_spu->i_filter]->pf_sub_buffer_new = sub_new_buffer;
140 p_spu->pp_filter[p_spu->i_filter]->pf_sub_buffer_del = sub_del_buffer;
141 p_spu->pp_filter[p_spu->i_filter]->p_cfg = p_cfg;
142 p_spu->pp_filter[p_spu->i_filter]->p_module =
143 module_Need( p_spu->pp_filter[p_spu->i_filter],
144 "sub filter", psz_name, VLC_TRUE );
145 if( p_spu->pp_filter[p_spu->i_filter]->p_module )
147 filter_owner_sys_t *p_sys = malloc( sizeof(filter_owner_sys_t) );
150 p_spu->pp_filter[p_spu->i_filter]->p_owner = p_sys;
151 spu_Control( p_spu, SPU_CHANNEL_REGISTER, &p_sys->i_channel );
152 p_sys->p_spu = p_spu;
158 msg_Dbg( p_spu, "no sub filter found" );
159 config_ChainDestroy( p_spu->pp_filter[p_spu->i_filter]->p_cfg );
160 vlc_object_detach( p_spu->pp_filter[p_spu->i_filter] );
161 vlc_object_destroy( p_spu->pp_filter[p_spu->i_filter] );
164 if( p_spu->i_filter >= 10 )
166 msg_Dbg( p_spu, "can't add anymore filters" );
171 if( val.psz_string ) free( val.psz_string );
177 * Destroy the subpicture unit
179 * \param p_this the parent object which destroys the subpicture unit
181 void spu_Destroy( spu_t *p_spu )
185 vlc_object_detach( p_spu );
187 /* Destroy all remaining subpictures */
188 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
190 if( p_spu->p_subpicture[i_index].i_status != FREE_SUBPICTURE )
192 spu_DestroySubpicture( p_spu, &p_spu->p_subpicture[i_index] );
198 if( p_spu->p_blend->p_module )
199 module_Unneed( p_spu->p_blend, p_spu->p_blend->p_module );
201 vlc_object_detach( p_spu->p_blend );
202 vlc_object_destroy( p_spu->p_blend );
207 if( p_spu->p_text->p_module )
208 module_Unneed( p_spu->p_text, p_spu->p_text->p_module );
210 vlc_object_detach( p_spu->p_text );
211 vlc_object_destroy( p_spu->p_text );
216 if( p_spu->p_scale->p_module )
217 module_Unneed( p_spu->p_scale, p_spu->p_scale->p_module );
219 vlc_object_detach( p_spu->p_scale );
220 vlc_object_destroy( p_spu->p_scale );
223 spu_DeleteChain( p_spu );
225 vlc_mutex_destroy( &p_spu->subpicture_lock );
226 vlc_object_destroy( p_spu );
229 static void spu_DeleteChain( spu_t *p_spu )
231 if( p_spu->i_filter )
232 while( p_spu->i_filter )
235 module_Unneed( p_spu->pp_filter[p_spu->i_filter],
236 p_spu->pp_filter[p_spu->i_filter]->p_module );
237 free( p_spu->pp_filter[p_spu->i_filter]->p_owner );
238 config_ChainDestroy( p_spu->pp_filter[p_spu->i_filter]->p_cfg );
239 vlc_object_detach( p_spu->pp_filter[p_spu->i_filter] );
240 vlc_object_destroy( p_spu->pp_filter[p_spu->i_filter] );
245 * Attach/Detach the SPU from any input
247 * \param p_this the object in which to destroy the subpicture unit
248 * \param b_attach to select attach or detach
250 void spu_Attach( spu_t *p_spu, vlc_object_t *p_this, vlc_bool_t b_attach )
252 vlc_object_t *p_input;
254 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_PARENT );
255 if( !p_input ) return;
259 UpdateSPU( p_spu, VLC_OBJECT(p_input) );
260 var_AddCallback( p_input, "highlight", CropCallback, p_spu );
261 vlc_object_release( p_input );
265 /* Delete callback */
266 var_DelCallback( p_input, "highlight", CropCallback, p_spu );
267 vlc_object_release( p_input );
272 * Create a subpicture region
274 * \param p_this vlc_object_t
275 * \param p_fmt the format that this subpicture region should have
277 static void RegionPictureRelease( picture_t *p_pic )
279 if( p_pic->p_data_orig ) free( p_pic->p_data_orig );
281 subpicture_region_t *__spu_CreateRegion( vlc_object_t *p_this,
282 video_format_t *p_fmt )
284 subpicture_region_t *p_region = malloc( sizeof(subpicture_region_t) );
285 if( !p_region ) return NULL;
287 memset( p_region, 0, sizeof(subpicture_region_t) );
288 p_region->p_next = NULL;
289 p_region->p_cache = NULL;
290 p_region->fmt = *p_fmt;
291 p_region->psz_text = NULL;
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 p_region->picture.p_data_orig = NULL;
301 if( p_fmt->i_chroma == VLC_FOURCC('T','E','X','T') ) return p_region;
303 vout_AllocatePicture( p_this, &p_region->picture, p_fmt->i_chroma,
304 p_fmt->i_width, p_fmt->i_height, p_fmt->i_aspect );
306 if( !p_region->picture.i_planes )
309 if( p_fmt->p_palette ) free( p_fmt->p_palette );
313 p_region->picture.pf_release = RegionPictureRelease;
319 * Make a subpicture region from an existing picture_t
321 * \param p_this vlc_object_t
322 * \param p_fmt the format that this subpicture region should have
323 * \param p_pic a pointer to the picture creating the region (not freed)
325 subpicture_region_t *__spu_MakeRegion( vlc_object_t *p_this,
326 video_format_t *p_fmt,
329 subpicture_region_t *p_region = malloc( sizeof(subpicture_region_t) );
331 if( !p_region ) return NULL;
332 memset( p_region, 0, sizeof(subpicture_region_t) );
333 p_region->p_next = 0;
334 p_region->p_cache = 0;
335 p_region->fmt = *p_fmt;
336 p_region->psz_text = 0;
337 p_region->p_style = NULL;
339 if( p_fmt->i_chroma == VLC_FOURCC('Y','U','V','P') )
340 p_fmt->p_palette = p_region->fmt.p_palette =
341 malloc( sizeof(video_palette_t) );
342 else p_fmt->p_palette = p_region->fmt.p_palette = NULL;
344 memcpy( &p_region->picture, p_pic, sizeof(picture_t) );
345 p_region->picture.pf_release = RegionPictureRelease;
351 * Destroy a subpicture region
353 * \param p_this vlc_object_t
354 * \param p_region the subpicture region to destroy
356 void __spu_DestroyRegion( vlc_object_t *p_this, subpicture_region_t *p_region )
358 if( !p_region ) return;
359 if( p_region->picture.pf_release )
360 p_region->picture.pf_release( &p_region->picture );
361 if( p_region->fmt.p_palette ) free( p_region->fmt.p_palette );
362 if( p_region->p_cache ) __spu_DestroyRegion( p_this, p_region->p_cache );
364 if( p_region->psz_text )
365 free( p_region->psz_text );
366 if( p_region->psz_html )
367 free( p_region->psz_html );
368 //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
373 * Display a subpicture
375 * Remove the reservation flag of a subpicture, which will cause it to be
377 * \param p_spu the subpicture unit object
378 * \param p_subpic the subpicture to display
380 void spu_DisplaySubpicture( spu_t *p_spu, subpicture_t *p_subpic )
382 /* Check if status is valid */
383 if( p_subpic->i_status != RESERVED_SUBPICTURE )
385 msg_Err( p_spu, "subpicture %p has invalid status #%d",
386 p_subpic, p_subpic->i_status );
389 /* Remove reservation flag */
390 p_subpic->i_status = READY_SUBPICTURE;
392 if( p_subpic->i_channel == DEFAULT_CHAN )
394 p_subpic->i_channel = 0xFFFF;
395 spu_Control( p_spu, SPU_CHANNEL_CLEAR, DEFAULT_CHAN );
396 p_subpic->i_channel = DEFAULT_CHAN;
401 * Allocate a subpicture in the spu heap.
403 * This function create a reserved subpicture in the spu heap.
404 * A null pointer is returned if the function fails. This method provides an
405 * already allocated zone of memory in the spu data fields. It needs locking
406 * since several pictures can be created by several producers threads.
407 * \param p_spu the subpicture unit in which to create the subpicture
408 * \return NULL on error, a reserved subpicture otherwise
410 subpicture_t *spu_CreateSubpicture( spu_t *p_spu )
412 int i_subpic; /* subpicture index */
413 subpicture_t * p_subpic = NULL; /* first free subpicture */
416 vlc_mutex_lock( &p_spu->subpicture_lock );
419 * Look for an empty place
422 for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
424 if( p_spu->p_subpicture[i_subpic].i_status == FREE_SUBPICTURE )
426 /* Subpicture is empty and ready for allocation */
427 p_subpic = &p_spu->p_subpicture[i_subpic];
428 p_spu->p_subpicture[i_subpic].i_status = RESERVED_SUBPICTURE;
433 /* If no free subpicture could be found */
434 if( p_subpic == NULL )
436 msg_Err( p_spu, "subpicture heap is full" );
437 vlc_mutex_unlock( &p_spu->subpicture_lock );
441 /* Copy subpicture information, set some default values */
442 memset( p_subpic, 0, sizeof(subpicture_t) );
443 p_subpic->i_status = RESERVED_SUBPICTURE;
444 p_subpic->b_absolute = VLC_TRUE;
445 p_subpic->b_pausable = VLC_FALSE;
446 p_subpic->b_fade = VLC_FALSE;
447 p_subpic->i_alpha = 0xFF;
448 p_subpic->p_region = NULL;
449 p_subpic->pf_render = NULL;
450 p_subpic->pf_destroy = NULL;
451 p_subpic->p_sys = NULL;
452 vlc_mutex_unlock( &p_spu->subpicture_lock );
454 p_subpic->pf_create_region = __spu_CreateRegion;
455 p_subpic->pf_make_region = __spu_MakeRegion;
456 p_subpic->pf_destroy_region = __spu_DestroyRegion;
462 * Remove a subpicture from the heap
464 * This function frees a previously reserved subpicture.
465 * It is meant to be used when the construction of a picture aborted.
466 * This function does not need locking since reserved subpictures are ignored
469 void spu_DestroySubpicture( spu_t *p_spu, subpicture_t *p_subpic )
472 vlc_mutex_lock( &p_spu->subpicture_lock );
474 /* There can be race conditions so we need to check the status */
475 if( p_subpic->i_status == FREE_SUBPICTURE )
477 vlc_mutex_unlock( &p_spu->subpicture_lock );
481 /* Check if status is valid */
482 if( ( p_subpic->i_status != RESERVED_SUBPICTURE )
483 && ( p_subpic->i_status != READY_SUBPICTURE ) )
485 msg_Err( p_spu, "subpicture %p has invalid status %d",
486 p_subpic, p_subpic->i_status );
489 while( p_subpic->p_region )
491 subpicture_region_t *p_region = p_subpic->p_region;
492 p_subpic->p_region = p_region->p_next;
493 spu_DestroyRegion( p_spu, p_region );
496 if( p_subpic->pf_destroy )
498 p_subpic->pf_destroy( p_subpic );
501 p_subpic->i_status = FREE_SUBPICTURE;
503 vlc_mutex_unlock( &p_spu->subpicture_lock );
506 /*****************************************************************************
507 * spu_RenderSubpictures: render a subpicture list
508 *****************************************************************************
509 * This function renders all sub picture units in the list.
510 *****************************************************************************/
511 void spu_RenderSubpictures( spu_t *p_spu, video_format_t *p_fmt,
512 picture_t *p_pic_dst, picture_t *p_pic_src,
513 subpicture_t *p_subpic,
514 int i_scale_width_orig, int i_scale_height_orig )
516 int i_source_video_width;
517 int i_source_video_height;
520 vlc_mutex_lock( &p_spu->subpicture_lock );
522 if( i_scale_width_orig <= 0 )
523 i_scale_width_orig = 1;
524 if( i_scale_height_orig <= 0 )
525 i_scale_height_orig = 1;
527 i_source_video_width = p_fmt->i_width * 1000 / i_scale_width_orig;
528 i_source_video_height = p_fmt->i_height * 1000 / i_scale_height_orig;
530 /* Check i_status again to make sure spudec hasn't destroyed the subpic */
531 while( ( p_subpic != NULL ) && ( p_subpic->i_status != FREE_SUBPICTURE ) )
533 subpicture_region_t *p_region = p_subpic->p_region;
534 int pi_scale_width[ SCALE_SIZE ];
535 int pi_scale_height[ SCALE_SIZE ];
536 int pi_subpic_x[ SCALE_SIZE ];
539 /* If the source video and subtitles stream agree on the size of
540 * the video then disregard all further references to the subtitle
543 if( ( i_source_video_height == p_subpic->i_original_picture_height ) &&
544 ( i_source_video_width == p_subpic->i_original_picture_width ) )
546 p_subpic->i_original_picture_height = 0;
547 p_subpic->i_original_picture_width = 0;
550 for( k = 0; k < SCALE_SIZE ; k++ )
551 pi_subpic_x[ k ] = p_subpic->i_x;
553 /* Load the blending module */
554 if( !p_spu->p_blend && p_region )
556 p_spu->p_blend = vlc_object_create( p_spu, VLC_OBJECT_FILTER );
557 vlc_object_attach( p_spu->p_blend, p_spu );
558 p_spu->p_blend->fmt_out.video.i_x_offset =
559 p_spu->p_blend->fmt_out.video.i_y_offset = 0;
560 p_spu->p_blend->fmt_out.video.i_aspect = p_fmt->i_aspect;
561 p_spu->p_blend->fmt_out.video.i_chroma = p_fmt->i_chroma;
563 /* The blend module will be loaded when needed with the real input format */
564 memset( &p_spu->p_blend->fmt_in, 0, sizeof(p_spu->p_blend->fmt_in) );
565 p_spu->p_blend->p_module = NULL;
568 /* Load the text rendering module; it is possible there is a
569 * text region somewhere in the subpicture other than the first
570 * element in the region list, so just load it anyway as we'll
571 * probably want it sooner or later. */
572 if( !p_spu->p_text && p_region )
574 char *psz_modulename = NULL;
576 p_spu->p_text = vlc_object_create( p_spu, VLC_OBJECT_FILTER );
577 vlc_object_attach( p_spu->p_text, p_spu );
579 p_spu->p_text->fmt_out.video.i_width =
580 p_spu->p_text->fmt_out.video.i_visible_width =
582 p_spu->p_text->fmt_out.video.i_height =
583 p_spu->p_text->fmt_out.video.i_visible_height =
586 p_spu->p_text->pf_sub_buffer_new = spu_new_buffer;
587 p_spu->p_text->pf_sub_buffer_del = spu_del_buffer;
589 psz_modulename = var_CreateGetString( p_spu, "text-renderer" );
590 if( psz_modulename && *psz_modulename )
592 p_spu->p_text->p_module =
593 module_Need( p_spu->p_text, "text renderer",
594 psz_modulename, VLC_TRUE );
596 if( !p_spu->p_text->p_module )
598 p_spu->p_text->p_module =
599 module_Need( p_spu->p_text, "text renderer", 0, 0 );
601 if( psz_modulename ) free( psz_modulename );
606 subpicture_region_t *p_text_region = p_subpic->p_region;
608 /* Only overwrite the size fields if the region is still in pre-rendered
609 * TEXT format. We have to traverse the subregion list because if more
610 * than one subregion is present, the text region isn't guarentteed to
611 * be the first in the list, and only text regions use this flag.
612 * All of this effort assists with the rescaling of text that has been
613 * rendered at native resolution, rather than video resolution.
615 while( p_text_region &&
616 ( p_text_region->fmt.i_chroma != VLC_FOURCC('T','E','X','T') ) )
618 p_text_region = p_text_region->p_next;
622 ( ( p_text_region->i_align & SUBPICTURE_RENDERED ) == 0 ) )
624 if( (p_subpic->i_original_picture_height > 0) &&
625 (p_subpic->i_original_picture_width > 0) )
627 p_spu->p_text->fmt_out.video.i_width =
628 p_spu->p_text->fmt_out.video.i_visible_width =
629 p_subpic->i_original_picture_width;
630 p_spu->p_text->fmt_out.video.i_height =
631 p_spu->p_text->fmt_out.video.i_visible_height =
632 p_subpic->i_original_picture_height;
636 p_spu->p_text->fmt_out.video.i_width =
637 p_spu->p_text->fmt_out.video.i_visible_width =
639 p_spu->p_text->fmt_out.video.i_height =
640 p_spu->p_text->fmt_out.video.i_visible_height =
646 pi_scale_width[ SCALE_DEFAULT ] = i_scale_width_orig;
647 pi_scale_height[ SCALE_DEFAULT ] = i_scale_height_orig;
651 pi_scale_width[ SCALE_TEXT ] = ( p_fmt->i_width * 1000 ) /
652 p_spu->p_text->fmt_out.video.i_width;
653 pi_scale_height[ SCALE_TEXT ] = ( p_fmt->i_height * 1000 ) /
654 p_spu->p_text->fmt_out.video.i_height;
656 /* If we have an explicit size plane to render to, then turn off
657 * the fontsize rescaling.
659 if( (p_subpic->i_original_picture_height > 0) &&
660 (p_subpic->i_original_picture_width > 0) )
662 i_scale_width_orig = 1000;
663 i_scale_height_orig = 1000;
666 for( k = 0; k < SCALE_SIZE ; k++ )
668 /* Case of both width and height being specified has been dealt with
669 * above by instead rendering to an output pane of the explicit
670 * dimensions specified - we don't need to scale it.
672 if( (p_subpic->i_original_picture_height > 0) &&
673 (p_subpic->i_original_picture_width <= 0) )
675 pi_scale_height[ k ] = pi_scale_height[ k ] * i_source_video_height /
676 p_subpic->i_original_picture_height;
677 pi_scale_width[ k ] = pi_scale_width[ k ] * i_source_video_height /
678 p_subpic->i_original_picture_height;
682 /* Set default subpicture aspect ratio */
683 if( p_region && p_region->fmt.i_aspect &&
684 ( !p_region->fmt.i_sar_num || !p_region->fmt.i_sar_den ) )
686 p_region->fmt.i_sar_den = p_region->fmt.i_aspect;
687 p_region->fmt.i_sar_num = VOUT_ASPECT_FACTOR;
690 ( !p_region->fmt.i_sar_num || !p_region->fmt.i_sar_den ) )
692 p_region->fmt.i_sar_den = p_fmt->i_sar_den;
693 p_region->fmt.i_sar_num = p_fmt->i_sar_num;
696 /* Take care of the aspect ratio */
698 ( ( p_region->fmt.i_sar_num * p_fmt->i_sar_den ) !=
699 ( p_region->fmt.i_sar_den * p_fmt->i_sar_num ) ) )
701 for( k = 0; k < SCALE_SIZE ; k++ )
703 pi_scale_width[ k ] = pi_scale_width[ k ] *
704 (int64_t)p_region->fmt.i_sar_num * p_fmt->i_sar_den /
705 p_region->fmt.i_sar_den / p_fmt->i_sar_num;
706 pi_subpic_x[ k ] = p_subpic->i_x * pi_scale_width[ k ] / 1000;
710 /* Load the scaling module */
711 if( !p_spu->p_scale &&
712 ((((pi_scale_width[ SCALE_TEXT ] > 0) || (pi_scale_height[ SCALE_TEXT ] > 0)) &&
713 ((pi_scale_width[ SCALE_TEXT ] != 1000) || (pi_scale_height[ SCALE_TEXT ] != 1000))) ||
714 (((pi_scale_width[ SCALE_DEFAULT ] > 0) || (pi_scale_height[ SCALE_DEFAULT ] > 0)) &&
715 ((pi_scale_width[ SCALE_DEFAULT ] != 1000) || (pi_scale_height[ SCALE_DEFAULT ] != 1000)))) )
717 p_spu->p_scale = vlc_object_create( p_spu, VLC_OBJECT_FILTER );
718 vlc_object_attach( p_spu->p_scale, p_spu );
719 p_spu->p_scale->fmt_out.video.i_chroma =
720 p_spu->p_scale->fmt_in.video.i_chroma =
721 VLC_FOURCC('Y','U','V','P');
722 /* FIXME: We'll also be using it for YUVA and RGBA blending ... */
724 p_spu->p_scale->fmt_in.video.i_width =
725 p_spu->p_scale->fmt_in.video.i_height = 32;
726 p_spu->p_scale->fmt_out.video.i_width =
727 p_spu->p_scale->fmt_out.video.i_height = 16;
729 p_spu->p_scale->pf_vout_buffer_new = spu_new_video_buffer;
730 p_spu->p_scale->pf_vout_buffer_del = spu_del_video_buffer;
731 p_spu->p_scale->p_module =
732 module_Need( p_spu->p_scale, "video filter2", 0, 0 );
737 video_format_t orig_fmt = p_region->fmt;
738 vlc_bool_t b_rerender_text = VLC_FALSE;
739 int i_fade_alpha = 255;
742 int i_scale_idx = SCALE_DEFAULT;
743 int i_inv_scale_x = 1000;
744 int i_inv_scale_y = 1000;
746 if( p_region->fmt.i_chroma == VLC_FOURCC('T','E','X','T') )
748 if( p_spu->p_text && p_spu->p_text->p_module )
752 /* Setup 3 variables which can be used to render
753 * time-dependent text (and effects). The first indicates
754 * the total amount of time the text will be on screen,
755 * the second the amount of time it has already been on
756 * screen (can be a negative value as text is layed out
757 * before it is rendered) and the third is a feedback
758 * variable from the renderer - if the renderer sets it
759 * then this particular text is time-dependent, eg. the
760 * visual progress bar inside the text in karaoke and the
761 * text needs to be rendered multiple times in order for
762 * the effect to work - we therefore need to return the
763 * region to its original state at the end of the loop,
764 * instead of leaving it in YUVA or YUVP.
765 * Any renderer which is unaware of how to render
766 * time-dependent text can happily ignore the variables
767 * and render the text the same as usual - it should at
768 * least show up on screen, but the effect won't change
769 * the text over time.
772 var_Create( p_spu->p_text, "spu-duration", VLC_VAR_TIME );
773 val.i_time = p_subpic->i_stop - p_subpic->i_start;
774 var_Set( p_spu->p_text, "spu-duration", val );
776 var_Create( p_spu->p_text, "spu-elapsed", VLC_VAR_TIME );
777 val.i_time = mdate() - p_subpic->i_start;
778 var_Set( p_spu->p_text, "spu-elapsed", val );
780 var_Create( p_spu->p_text, "text-rerender", VLC_VAR_BOOL );
781 var_SetBool( p_spu->p_text, "text-rerender", VLC_FALSE );
783 var_Create( p_spu->p_text, "scale", VLC_VAR_INTEGER );
784 var_SetInteger( p_spu->p_text, "scale",
785 __MIN(i_scale_width_orig, i_scale_height_orig) );
787 if( p_spu->p_text->pf_render_html && p_region->psz_html )
789 p_spu->p_text->pf_render_html( p_spu->p_text,
790 p_region, p_region );
792 else if( p_spu->p_text->pf_render_text )
794 p_spu->p_text->pf_render_text( p_spu->p_text,
795 p_region, p_region );
797 b_rerender_text = var_GetBool( p_spu->p_text, "text-rerender" );
799 var_Destroy( p_spu->p_text, "spu-duration" );
800 var_Destroy( p_spu->p_text, "spu-elapsed" );
801 var_Destroy( p_spu->p_text, "text-rerender" );
802 var_Destroy( p_spu->p_text, "scale" );
804 p_region->i_align |= SUBPICTURE_RENDERED;
807 if( p_region->i_align & SUBPICTURE_RENDERED )
809 i_scale_idx = SCALE_TEXT;
810 i_inv_scale_x = i_scale_width_orig;
811 i_inv_scale_y = i_scale_height_orig;
814 i_x_offset = (p_region->i_x + pi_subpic_x[ i_scale_idx ]) * i_inv_scale_x / 1000;
815 i_y_offset = (p_region->i_y + p_subpic->i_y) * i_inv_scale_y / 1000;
817 /* Force palette if requested */
818 if( p_spu->b_force_palette &&
819 ( VLC_FOURCC('Y','U','V','P') == p_region->fmt.i_chroma ) )
821 memcpy( p_region->fmt.p_palette->palette,
822 p_spu->palette, 16 );
825 /* Scale SPU if necessary */
826 if( p_region->p_cache &&
827 ( p_region->fmt.i_chroma != VLC_FOURCC('T','E','X','T') ) )
829 if( pi_scale_width[ i_scale_idx ] * p_region->fmt.i_width / 1000 !=
830 p_region->p_cache->fmt.i_width ||
831 pi_scale_height[ i_scale_idx ] * p_region->fmt.i_height / 1000 !=
832 p_region->p_cache->fmt.i_height )
834 p_subpic->pf_destroy_region( VLC_OBJECT(p_spu),
836 p_region->p_cache = 0;
840 if( ( ( pi_scale_width[ i_scale_idx ] != 1000 ) ||
841 ( pi_scale_height[ i_scale_idx ] != 1000 ) ) &&
842 ( ( pi_scale_width[ i_scale_idx ] > 0 ) ||
843 ( pi_scale_height[ i_scale_idx ] > 0 ) ) &&
844 p_spu->p_scale && !p_region->p_cache &&
845 ( p_region->fmt.i_chroma != VLC_FOURCC('T','E','X','T') ) )
849 p_spu->p_scale->fmt_in.video = p_region->fmt;
850 p_spu->p_scale->fmt_out.video = p_region->fmt;
853 p_subpic->pf_create_region( VLC_OBJECT(p_spu),
854 &p_spu->p_scale->fmt_out.video );
855 if( p_spu->p_scale->fmt_out.video.p_palette )
856 *p_spu->p_scale->fmt_out.video.p_palette =
857 *p_region->fmt.p_palette;
858 p_region->p_cache->p_next = p_region->p_next;
860 vout_CopyPicture( p_spu, &p_region->p_cache->picture,
861 &p_region->picture );
863 p_spu->p_scale->fmt_out.video.i_width =
864 p_region->fmt.i_width * pi_scale_width[ i_scale_idx ] / 1000;
865 p_spu->p_scale->fmt_out.video.i_visible_width =
866 p_region->fmt.i_visible_width * pi_scale_width[ i_scale_idx ] / 1000;
867 p_spu->p_scale->fmt_out.video.i_height =
868 p_region->fmt.i_height * pi_scale_height[ i_scale_idx ] / 1000;
869 p_spu->p_scale->fmt_out.video.i_visible_height =
870 p_region->fmt.i_visible_height * pi_scale_height[ i_scale_idx ] / 1000;
871 p_region->p_cache->fmt = p_spu->p_scale->fmt_out.video;
872 p_region->p_cache->i_x = p_region->i_x * pi_scale_width[ i_scale_idx ] / 1000;
873 p_region->p_cache->i_y = p_region->i_y * pi_scale_height[ i_scale_idx ] / 1000;
874 p_region->p_cache->i_align = p_region->i_align;
876 p_pic = p_spu->p_scale->pf_video_filter(
877 p_spu->p_scale, &p_region->p_cache->picture );
880 picture_t p_pic_tmp = p_region->p_cache->picture;
881 p_region->p_cache->picture = *p_pic;
887 if( ( ( pi_scale_width[ i_scale_idx ] != 1000 ) ||
888 ( pi_scale_height[ i_scale_idx ] != 1000 ) ) &&
889 ( ( pi_scale_width[ i_scale_idx ] > 0 ) ||
890 ( pi_scale_height[ i_scale_idx ] > 0 ) ) &&
891 p_spu->p_scale && p_region->p_cache &&
892 ( p_region->fmt.i_chroma != VLC_FOURCC('T','E','X','T') ) )
894 p_region = p_region->p_cache;
897 if( p_region->i_align & SUBPICTURE_ALIGN_BOTTOM )
899 i_y_offset = p_fmt->i_height - p_region->fmt.i_height -
900 (p_subpic->i_y + p_region->i_y) * i_inv_scale_y / 1000;
902 else if ( !(p_region->i_align & SUBPICTURE_ALIGN_TOP) )
904 i_y_offset = p_fmt->i_height / 2 - p_region->fmt.i_height / 2;
907 if( p_region->i_align & SUBPICTURE_ALIGN_RIGHT )
909 i_x_offset = p_fmt->i_width - p_region->fmt.i_width -
910 (pi_subpic_x[ i_scale_idx ] + p_region->i_x)
911 * i_inv_scale_x / 1000;
913 else if ( !(p_region->i_align & SUBPICTURE_ALIGN_LEFT) )
915 i_x_offset = p_fmt->i_width / 2 - p_region->fmt.i_width / 2;
918 if( p_subpic->b_absolute )
920 i_x_offset = (p_region->i_x +
921 pi_subpic_x[ i_scale_idx ] *
922 pi_scale_width[ i_scale_idx ] / 1000)
923 * i_inv_scale_x / 1000;
924 i_y_offset = (p_region->i_y +
925 p_subpic->i_y * pi_scale_height[ i_scale_idx ] / 1000)
926 * i_inv_scale_y / 1000;
930 i_x_offset = __MAX( i_x_offset, 0 );
931 i_y_offset = __MAX( i_y_offset, 0 );
933 if( ( p_spu->i_margin != 0 ) &&
934 ( p_spu->b_force_crop == VLC_FALSE ) )
937 int i_low = (i_y_offset - p_spu->i_margin) * i_inv_scale_y / 1000;
938 int i_high = i_low + p_region->fmt.i_height;
940 /* crop extra margin to keep within bounds */
943 if( i_high > (int)p_fmt->i_height )
944 i_diff = i_high - p_fmt->i_height;
945 i_y_offset -= ( p_spu->i_margin * i_inv_scale_y / 1000 + i_diff );
948 if( p_subpic->b_fade )
950 mtime_t i_fade_start = ( p_subpic->i_stop +
951 p_subpic->i_start ) / 2;
952 mtime_t i_now = mdate();
953 if( i_now >= i_fade_start && p_subpic->i_stop > i_fade_start )
955 i_fade_alpha = 255 * ( p_subpic->i_stop - i_now ) /
956 ( p_subpic->i_stop - i_fade_start );
960 if( p_region->fmt.i_chroma != VLC_FOURCC('T','E','X','T') )
962 if( p_spu->p_blend->fmt_in.video.i_chroma != p_region->fmt.i_chroma )
964 /* The chroma is not the same, we need to reload the blend module
965 * XXX to match the old behaviour just test !p_spu->p_blend->fmt_in.video.i_chroma */
966 if( p_spu->p_blend->p_module )
967 module_Unneed( p_spu->p_blend, p_spu->p_blend->p_module );
969 p_spu->p_blend->fmt_in.video = p_region->fmt;
970 p_spu->p_blend->p_module = module_Need( p_spu->p_blend, "video blending", 0, 0 );
974 p_spu->p_blend->fmt_in.video = p_region->fmt;
977 /* Force cropping if requested */
978 if( p_spu->b_force_crop )
980 video_format_t *p_fmt = &p_spu->p_blend->fmt_in.video;
981 int i_crop_x = p_spu->i_crop_x * pi_scale_width[ i_scale_idx ] / 1000
982 * i_inv_scale_x / 1000;
983 int i_crop_y = p_spu->i_crop_y * pi_scale_height[ i_scale_idx ] / 1000
984 * i_inv_scale_y / 1000;
985 int i_crop_width = p_spu->i_crop_width * pi_scale_width[ i_scale_idx ] / 1000
986 * i_inv_scale_x / 1000;
987 int i_crop_height = p_spu->i_crop_height * pi_scale_height[ i_scale_idx ] / 1000
988 * i_inv_scale_y / 1000;
990 /* Find the intersection */
991 if( i_crop_x + i_crop_width <= i_x_offset ||
992 i_x_offset + (int)p_fmt->i_visible_width < i_crop_x ||
993 i_crop_y + i_crop_height <= i_y_offset ||
994 i_y_offset + (int)p_fmt->i_visible_height < i_crop_y )
996 /* No intersection */
997 p_fmt->i_visible_width = p_fmt->i_visible_height = 0;
1001 int i_x, i_y, i_x_end, i_y_end;
1002 i_x = __MAX( i_crop_x, i_x_offset );
1003 i_y = __MAX( i_crop_y, i_y_offset );
1004 i_x_end = __MIN( i_crop_x + i_crop_width,
1005 i_x_offset + (int)p_fmt->i_visible_width );
1006 i_y_end = __MIN( i_crop_y + i_crop_height,
1007 i_y_offset + (int)p_fmt->i_visible_height );
1009 p_fmt->i_x_offset = i_x - i_x_offset;
1010 p_fmt->i_y_offset = i_y - i_y_offset;
1011 p_fmt->i_visible_width = i_x_end - i_x;
1012 p_fmt->i_visible_height = i_y_end - i_y;
1019 i_x_offset = __MAX( i_x_offset, 0 );
1020 i_y_offset = __MAX( i_y_offset, 0 );
1022 /* Update the output picture size */
1023 p_spu->p_blend->fmt_out.video.i_width =
1024 p_spu->p_blend->fmt_out.video.i_visible_width =
1026 p_spu->p_blend->fmt_out.video.i_height =
1027 p_spu->p_blend->fmt_out.video.i_visible_height =
1030 if( p_spu->p_blend->p_module )
1032 p_spu->p_blend->pf_video_blend( p_spu->p_blend, p_pic_dst,
1033 p_pic_src, &p_region->picture, i_x_offset, i_y_offset,
1034 i_fade_alpha * p_subpic->i_alpha / 255 );
1038 msg_Err( p_spu, "blending %4.4s to %4.4s failed",
1039 (char *)&p_spu->p_blend->fmt_out.video.i_chroma,
1040 (char *)&p_spu->p_blend->fmt_out.video.i_chroma );
1044 if( b_rerender_text )
1046 /* Some forms of subtitles need to be re-rendered more than
1047 * once, eg. karaoke. We therefore restore the region to its
1048 * pre-rendered state, so the next time through everything is
1051 p_region->picture.pf_release( &p_region->picture );
1052 memset( &p_region->picture, 0, sizeof( picture_t ) );
1053 p_region->fmt = orig_fmt;
1054 p_region->i_align &= ~SUBPICTURE_RENDERED;
1056 p_region = p_region->p_next;
1059 p_subpic = p_subpic->p_next;
1062 vlc_mutex_unlock( &p_spu->subpicture_lock );
1065 /*****************************************************************************
1066 * spu_SortSubpictures: find the subpictures to display
1067 *****************************************************************************
1068 * This function parses all subpictures and decides which ones need to be
1069 * displayed. This operation does not need lock, since only READY_SUBPICTURE
1070 * are handled. If no picture has been selected, display_date will depend on
1072 * We also check for ephemer DVD subpictures (subpictures that have
1073 * to be removed if a newer one is available), which makes it a lot
1074 * more difficult to guess if a subpicture has to be rendered or not.
1075 *****************************************************************************/
1076 subpicture_t *spu_SortSubpictures( spu_t *p_spu, mtime_t display_date,
1077 vlc_bool_t b_paused )
1079 int i_index, i_channel;
1080 subpicture_t *p_subpic = NULL;
1081 subpicture_t *p_ephemer;
1082 mtime_t ephemer_date;
1084 /* Run subpicture filters */
1085 for( i_index = 0; i_index < p_spu->i_filter; i_index++ )
1087 subpicture_t *p_subpic_filter;
1088 p_subpic_filter = p_spu->pp_filter[i_index]->
1089 pf_sub_filter( p_spu->pp_filter[i_index], display_date );
1090 if( p_subpic_filter )
1092 spu_DisplaySubpicture( p_spu, p_subpic_filter );
1096 /* We get an easily parsable chained list of subpictures which
1097 * ends with NULL since p_subpic was initialized to NULL. */
1098 for( i_channel = 0; i_channel < p_spu->i_channel; i_channel++ )
1103 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
1105 if( p_spu->p_subpicture[i_index].i_channel != i_channel ||
1106 p_spu->p_subpicture[i_index].i_status != READY_SUBPICTURE )
1111 display_date < p_spu->p_subpicture[i_index].i_start )
1113 /* Too early, come back next monday */
1117 if( p_spu->p_subpicture[i_index].i_start > ephemer_date )
1118 ephemer_date = p_spu->p_subpicture[i_index].i_start;
1120 if( display_date > p_spu->p_subpicture[i_index].i_stop &&
1121 ( !p_spu->p_subpicture[i_index].b_ephemer ||
1122 p_spu->p_subpicture[i_index].i_stop >
1123 p_spu->p_subpicture[i_index].i_start ) &&
1124 !( p_spu->p_subpicture[i_index].b_pausable &&
1127 /* Too late, destroy the subpic */
1128 spu_DestroySubpicture( p_spu, &p_spu->p_subpicture[i_index] );
1132 /* If this is an ephemer subpic, add it to our list */
1133 if( p_spu->p_subpicture[i_index].b_ephemer )
1135 p_spu->p_subpicture[i_index].p_next = p_ephemer;
1136 p_ephemer = &p_spu->p_subpicture[i_index];
1141 p_spu->p_subpicture[i_index].p_next = p_subpic;
1142 p_subpic = &p_spu->p_subpicture[i_index];
1145 /* If we found ephemer subpictures, check if they have to be
1146 * displayed or destroyed */
1147 while( p_ephemer != NULL )
1149 subpicture_t *p_tmp = p_ephemer;
1150 p_ephemer = p_ephemer->p_next;
1152 if( p_tmp->i_start < ephemer_date )
1154 /* Ephemer subpicture has lived too long */
1155 spu_DestroySubpicture( p_spu, p_tmp );
1159 /* Ephemer subpicture can still live a bit */
1160 p_tmp->p_next = p_subpic;
1169 /*****************************************************************************
1170 * SpuClearChannel: clear an spu channel
1171 *****************************************************************************
1172 * This function destroys the subpictures which belong to the spu channel
1173 * corresponding to i_channel_id.
1174 *****************************************************************************/
1175 static void SpuClearChannel( spu_t *p_spu, int i_channel )
1177 int i_subpic; /* subpicture index */
1178 subpicture_t *p_subpic = NULL; /* first free subpicture */
1180 vlc_mutex_lock( &p_spu->subpicture_lock );
1182 for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
1184 p_subpic = &p_spu->p_subpicture[i_subpic];
1185 if( p_subpic->i_status == FREE_SUBPICTURE
1186 || ( p_subpic->i_status != RESERVED_SUBPICTURE
1187 && p_subpic->i_status != READY_SUBPICTURE ) )
1192 if( p_subpic->i_channel == i_channel )
1194 while( p_subpic->p_region )
1196 subpicture_region_t *p_region = p_subpic->p_region;
1197 p_subpic->p_region = p_region->p_next;
1198 spu_DestroyRegion( p_spu, p_region );
1201 if( p_subpic->pf_destroy ) p_subpic->pf_destroy( p_subpic );
1202 p_subpic->i_status = FREE_SUBPICTURE;
1206 vlc_mutex_unlock( &p_spu->subpicture_lock );
1209 /*****************************************************************************
1210 * spu_ControlDefault: default methods for the subpicture unit control.
1211 *****************************************************************************/
1212 static int spu_vaControlDefault( spu_t *p_spu, int i_query, va_list args )
1218 case SPU_CHANNEL_REGISTER:
1219 pi = (int *)va_arg( args, int * );
1220 if( pi ) *pi = p_spu->i_channel++;
1223 case SPU_CHANNEL_CLEAR:
1224 i = (int)va_arg( args, int );
1225 SpuClearChannel( p_spu, i );
1229 msg_Dbg( p_spu, "control query not supported" );
1230 return VLC_EGENERIC;
1236 /*****************************************************************************
1237 * Object variables callbacks
1238 *****************************************************************************/
1240 /*****************************************************************************
1241 * UpdateSPU: update subpicture settings
1242 *****************************************************************************
1243 * This function is called from CropCallback and at initialization time, to
1244 * retrieve crop information from the input.
1245 *****************************************************************************/
1246 static void UpdateSPU( spu_t *p_spu, vlc_object_t *p_object )
1250 p_spu->b_force_palette = VLC_FALSE;
1251 p_spu->b_force_crop = VLC_FALSE;
1253 if( var_Get( p_object, "highlight", &val ) || !val.b_bool ) return;
1255 p_spu->b_force_crop = VLC_TRUE;
1256 var_Get( p_object, "x-start", &val );
1257 p_spu->i_crop_x = val.i_int;
1258 var_Get( p_object, "y-start", &val );
1259 p_spu->i_crop_y = val.i_int;
1260 var_Get( p_object, "x-end", &val );
1261 p_spu->i_crop_width = val.i_int - p_spu->i_crop_x;
1262 var_Get( p_object, "y-end", &val );
1263 p_spu->i_crop_height = val.i_int - p_spu->i_crop_y;
1265 if( var_Get( p_object, "menu-palette", &val ) == VLC_SUCCESS )
1267 memcpy( p_spu->palette, val.p_address, 16 );
1268 p_spu->b_force_palette = VLC_TRUE;
1271 msg_Dbg( p_object, "crop: %i,%i,%i,%i, palette forced: %i",
1272 p_spu->i_crop_x, p_spu->i_crop_y,
1273 p_spu->i_crop_width, p_spu->i_crop_height,
1274 p_spu->b_force_palette );
1277 /*****************************************************************************
1278 * CropCallback: called when the highlight properties are changed
1279 *****************************************************************************
1280 * This callback is called from the input thread when we need cropping
1281 *****************************************************************************/
1282 static int CropCallback( vlc_object_t *p_object, char const *psz_var,
1283 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1285 (void)psz_var; (void)oldval; (void)newval;
1286 UpdateSPU( (spu_t *)p_data, p_object );
1290 /*****************************************************************************
1291 * Buffers allocation callbacks for the filters
1292 *****************************************************************************/
1293 static subpicture_t *sub_new_buffer( filter_t *p_filter )
1295 filter_owner_sys_t *p_sys = p_filter->p_owner;
1296 subpicture_t *p_subpicture = spu_CreateSubpicture( p_sys->p_spu );
1297 if( p_subpicture ) p_subpicture->i_channel = p_sys->i_channel;
1298 return p_subpicture;
1301 static void sub_del_buffer( filter_t *p_filter, subpicture_t *p_subpic )
1303 filter_owner_sys_t *p_sys = p_filter->p_owner;
1304 spu_DestroySubpicture( p_sys->p_spu, p_subpic );
1307 static subpicture_t *spu_new_buffer( filter_t *p_filter )
1309 subpicture_t *p_subpic = (subpicture_t *)malloc(sizeof(subpicture_t));
1311 if( !p_subpic ) return NULL;
1312 memset( p_subpic, 0, sizeof(subpicture_t) );
1313 p_subpic->b_absolute = VLC_TRUE;
1315 p_subpic->pf_create_region = __spu_CreateRegion;
1316 p_subpic->pf_make_region = __spu_MakeRegion;
1317 p_subpic->pf_destroy_region = __spu_DestroyRegion;
1322 static void spu_del_buffer( filter_t *p_filter, subpicture_t *p_subpic )
1324 while( p_subpic->p_region )
1326 subpicture_region_t *p_region = p_subpic->p_region;
1327 p_subpic->p_region = p_region->p_next;
1328 p_subpic->pf_destroy_region( VLC_OBJECT(p_filter), p_region );
1334 static picture_t *spu_new_video_buffer( filter_t *p_filter )
1336 picture_t *p_picture = malloc( sizeof(picture_t) );
1337 if( !p_picture ) return NULL;
1338 if( vout_AllocatePicture( p_filter, p_picture,
1339 p_filter->fmt_out.video.i_chroma,
1340 p_filter->fmt_out.video.i_width,
1341 p_filter->fmt_out.video.i_height,
1342 p_filter->fmt_out.video.i_aspect )
1349 p_picture->pf_release = RegionPictureRelease;
1354 static void spu_del_video_buffer( filter_t *p_filter, picture_t *p_pic )
1357 if( p_pic && p_pic->p_data_orig ) free( p_pic->p_data_orig );
1358 if( p_pic ) free( p_pic );
1361 static int SubFilterCallback( vlc_object_t *p_object, char const *psz_var,
1362 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1364 (void)p_object; (void)oldval; (void)newval;
1366 if( !strcmp( psz_var, "sub-filter" ) )
1368 spu_t *p_spu = (spu_t *)p_data;
1369 vlc_mutex_lock( &p_spu->subpicture_lock );
1370 spu_DeleteChain( p_spu );
1371 spu_ParseChain( p_spu );
1372 vlc_mutex_unlock( &p_spu->subpicture_lock );