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 *****************************************************************************/
35 #include <vlc_block.h>
36 #include <vlc_filter.h>
39 /*****************************************************************************
41 *****************************************************************************/
42 static void UpdateSPU ( spu_t *, vlc_object_t * );
43 static int CropCallback( vlc_object_t *, char const *,
44 vlc_value_t, vlc_value_t, void * );
46 static int spu_vaControlDefault( spu_t *, int, va_list );
48 static subpicture_t *sub_new_buffer( filter_t * );
49 static void sub_del_buffer( filter_t *, subpicture_t * );
50 static subpicture_t *spu_new_buffer( filter_t * );
51 static void spu_del_buffer( filter_t *, subpicture_t * );
52 static picture_t *spu_new_video_buffer( filter_t * );
53 static void spu_del_video_buffer( filter_t *, picture_t * );
55 static int spu_ParseChain( spu_t * );
56 static void spu_DeleteChain( spu_t * );
57 static int SubFilterCallback( vlc_object_t *, char const *,
58 vlc_value_t, vlc_value_t, void * );
60 struct filter_owner_sys_t
72 * Creates the subpicture unit
74 * \param p_this the parent object which creates the subpicture unit
76 spu_t *__spu_Create( vlc_object_t *p_this )
79 spu_t *p_spu = vlc_object_create( p_this, VLC_OBJECT_SPU );
81 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++)
83 p_spu->p_subpicture[i_index].i_status = FREE_SUBPICTURE;
86 p_spu->p_blend = NULL;
88 p_spu->p_scale = NULL;
90 p_spu->pf_control = spu_vaControlDefault;
92 /* Register the default subpicture channel */
95 vlc_mutex_init( p_this, &p_spu->subpicture_lock );
97 vlc_object_attach( p_spu, p_this );
103 * Initialise the subpicture unit
105 * \param p_spu the subpicture unit object
107 int spu_Init( spu_t *p_spu )
111 /* If the user requested a sub margin, we force the position. */
112 var_Create( p_spu, "sub-margin", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
113 var_Get( p_spu, "sub-margin", &val );
114 p_spu->i_margin = val.i_int;
116 var_Create( p_spu, "sub-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
117 var_AddCallback( p_spu, "sub-filter", SubFilterCallback, p_spu );
119 spu_ParseChain( p_spu );
124 int spu_ParseChain( spu_t *p_spu )
128 var_Get( p_spu, "sub-filter", &val );
129 psz_parser = val.psz_string;
131 while( psz_parser && *psz_parser )
133 config_chain_t *p_cfg;
136 psz_parser = config_ChainCreate( &psz_name, &p_cfg, psz_parser );
138 msg_Dbg( p_spu, "adding sub-filter: %s", psz_name );
140 p_spu->pp_filter[p_spu->i_filter] =
141 vlc_object_create( p_spu, VLC_OBJECT_FILTER );
142 vlc_object_attach( p_spu->pp_filter[p_spu->i_filter], p_spu );
143 p_spu->pp_filter[p_spu->i_filter]->pf_sub_buffer_new = sub_new_buffer;
144 p_spu->pp_filter[p_spu->i_filter]->pf_sub_buffer_del = sub_del_buffer;
145 p_spu->pp_filter[p_spu->i_filter]->p_cfg = p_cfg;
146 p_spu->pp_filter[p_spu->i_filter]->p_module =
147 module_Need( p_spu->pp_filter[p_spu->i_filter],
148 "sub filter", psz_name, VLC_TRUE );
149 if( p_spu->pp_filter[p_spu->i_filter]->p_module )
151 filter_owner_sys_t *p_sys = malloc( sizeof(filter_owner_sys_t) );
154 p_spu->pp_filter[p_spu->i_filter]->p_owner = p_sys;
155 spu_Control( p_spu, SPU_CHANNEL_REGISTER, &p_sys->i_channel );
156 p_sys->p_spu = p_spu;
162 msg_Dbg( p_spu, "no sub filter found" );
163 config_ChainDestroy( p_spu->pp_filter[p_spu->i_filter]->p_cfg );
164 vlc_object_detach( p_spu->pp_filter[p_spu->i_filter] );
165 vlc_object_destroy( p_spu->pp_filter[p_spu->i_filter] );
168 if( p_spu->i_filter >= 10 )
170 msg_Dbg( p_spu, "can't add anymore filters" );
175 if( val.psz_string ) free( val.psz_string );
181 * Destroy the subpicture unit
183 * \param p_this the parent object which destroys the subpicture unit
185 void spu_Destroy( spu_t *p_spu )
189 vlc_object_detach( p_spu );
191 /* Destroy all remaining subpictures */
192 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
194 if( p_spu->p_subpicture[i_index].i_status != FREE_SUBPICTURE )
196 spu_DestroySubpicture( p_spu, &p_spu->p_subpicture[i_index] );
202 if( p_spu->p_blend->p_module )
203 module_Unneed( p_spu->p_blend, p_spu->p_blend->p_module );
205 vlc_object_detach( p_spu->p_blend );
206 vlc_object_destroy( p_spu->p_blend );
211 if( p_spu->p_text->p_module )
212 module_Unneed( p_spu->p_text, p_spu->p_text->p_module );
214 vlc_object_detach( p_spu->p_text );
215 vlc_object_destroy( p_spu->p_text );
220 if( p_spu->p_scale->p_module )
221 module_Unneed( p_spu->p_scale, p_spu->p_scale->p_module );
223 vlc_object_detach( p_spu->p_scale );
224 vlc_object_destroy( p_spu->p_scale );
227 spu_DeleteChain( p_spu );
229 vlc_mutex_destroy( &p_spu->subpicture_lock );
230 vlc_object_destroy( p_spu );
233 static void spu_DeleteChain( spu_t *p_spu )
235 if( p_spu->i_filter )
236 while( p_spu->i_filter )
239 module_Unneed( p_spu->pp_filter[p_spu->i_filter],
240 p_spu->pp_filter[p_spu->i_filter]->p_module );
241 free( p_spu->pp_filter[p_spu->i_filter]->p_owner );
242 config_ChainDestroy( p_spu->pp_filter[p_spu->i_filter]->p_cfg );
243 vlc_object_detach( p_spu->pp_filter[p_spu->i_filter] );
244 vlc_object_destroy( p_spu->pp_filter[p_spu->i_filter] );
249 * Attach/Detach the SPU from any input
251 * \param p_this the object in which to destroy the subpicture unit
252 * \param b_attach to select attach or detach
254 void spu_Attach( spu_t *p_spu, vlc_object_t *p_this, vlc_bool_t b_attach )
256 vlc_object_t *p_input;
258 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_PARENT );
259 if( !p_input ) return;
263 UpdateSPU( p_spu, VLC_OBJECT(p_input) );
264 var_AddCallback( p_input, "highlight", CropCallback, p_spu );
265 vlc_object_release( p_input );
269 /* Delete callback */
270 var_DelCallback( p_input, "highlight", CropCallback, p_spu );
271 vlc_object_release( p_input );
276 * Create a subpicture region
278 * \param p_this vlc_object_t
279 * \param p_fmt the format that this subpicture region should have
281 static void RegionPictureRelease( picture_t *p_pic )
283 if( p_pic->p_data_orig ) free( p_pic->p_data_orig );
285 subpicture_region_t *__spu_CreateRegion( vlc_object_t *p_this,
286 video_format_t *p_fmt )
288 subpicture_region_t *p_region = malloc( sizeof(subpicture_region_t) );
289 if( !p_region ) return NULL;
291 memset( p_region, 0, sizeof(subpicture_region_t) );
292 p_region->p_next = NULL;
293 p_region->p_cache = NULL;
294 p_region->fmt = *p_fmt;
295 p_region->psz_text = NULL;
296 p_region->p_style = NULL;
298 if( p_fmt->i_chroma == VLC_FOURCC('Y','U','V','P') )
299 p_fmt->p_palette = p_region->fmt.p_palette =
300 malloc( sizeof(video_palette_t) );
301 else p_fmt->p_palette = p_region->fmt.p_palette = NULL;
303 p_region->picture.p_data_orig = NULL;
305 if( p_fmt->i_chroma == VLC_FOURCC('T','E','X','T') ) return p_region;
307 vout_AllocatePicture( p_this, &p_region->picture, p_fmt->i_chroma,
308 p_fmt->i_width, p_fmt->i_height, p_fmt->i_aspect );
310 if( !p_region->picture.i_planes )
313 if( p_fmt->p_palette ) free( p_fmt->p_palette );
317 p_region->picture.pf_release = RegionPictureRelease;
323 * Make a subpicture region from an existing picture_t
325 * \param p_this vlc_object_t
326 * \param p_fmt the format that this subpicture region should have
327 * \param p_pic a pointer to the picture creating the region (not freed)
329 subpicture_region_t *__spu_MakeRegion( vlc_object_t *p_this,
330 video_format_t *p_fmt,
333 subpicture_region_t *p_region = malloc( sizeof(subpicture_region_t) );
335 if( !p_region ) return NULL;
336 memset( p_region, 0, sizeof(subpicture_region_t) );
337 p_region->p_next = 0;
338 p_region->p_cache = 0;
339 p_region->fmt = *p_fmt;
340 p_region->psz_text = 0;
341 p_region->p_style = NULL;
343 if( p_fmt->i_chroma == VLC_FOURCC('Y','U','V','P') )
344 p_fmt->p_palette = p_region->fmt.p_palette =
345 malloc( sizeof(video_palette_t) );
346 else p_fmt->p_palette = p_region->fmt.p_palette = NULL;
348 memcpy( &p_region->picture, p_pic, sizeof(picture_t) );
349 p_region->picture.pf_release = RegionPictureRelease;
355 * Destroy a subpicture region
357 * \param p_this vlc_object_t
358 * \param p_region the subpicture region to destroy
360 void __spu_DestroyRegion( vlc_object_t *p_this, subpicture_region_t *p_region )
362 if( !p_region ) return;
363 if( p_region->picture.pf_release )
364 p_region->picture.pf_release( &p_region->picture );
365 if( p_region->fmt.p_palette ) free( p_region->fmt.p_palette );
366 if( p_region->p_cache ) __spu_DestroyRegion( p_this, p_region->p_cache );
368 if( p_region->psz_text )
369 free( p_region->psz_text );
370 if( p_region->psz_html )
371 free( p_region->psz_html );
372 //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
377 * Display a subpicture
379 * Remove the reservation flag of a subpicture, which will cause it to be
381 * \param p_spu the subpicture unit object
382 * \param p_subpic the subpicture to display
384 void spu_DisplaySubpicture( spu_t *p_spu, subpicture_t *p_subpic )
386 /* Check if status is valid */
387 if( p_subpic->i_status != RESERVED_SUBPICTURE )
389 msg_Err( p_spu, "subpicture %p has invalid status #%d",
390 p_subpic, p_subpic->i_status );
393 /* Remove reservation flag */
394 p_subpic->i_status = READY_SUBPICTURE;
396 if( p_subpic->i_channel == DEFAULT_CHAN )
398 p_subpic->i_channel = 0xFFFF;
399 spu_Control( p_spu, SPU_CHANNEL_CLEAR, DEFAULT_CHAN );
400 p_subpic->i_channel = DEFAULT_CHAN;
405 * Allocate a subpicture in the spu heap.
407 * This function create a reserved subpicture in the spu heap.
408 * A null pointer is returned if the function fails. This method provides an
409 * already allocated zone of memory in the spu data fields. It needs locking
410 * since several pictures can be created by several producers threads.
411 * \param p_spu the subpicture unit in which to create the subpicture
412 * \return NULL on error, a reserved subpicture otherwise
414 subpicture_t *spu_CreateSubpicture( spu_t *p_spu )
416 int i_subpic; /* subpicture index */
417 subpicture_t * p_subpic = NULL; /* first free subpicture */
420 vlc_mutex_lock( &p_spu->subpicture_lock );
423 * Look for an empty place
426 for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
428 if( p_spu->p_subpicture[i_subpic].i_status == FREE_SUBPICTURE )
430 /* Subpicture is empty and ready for allocation */
431 p_subpic = &p_spu->p_subpicture[i_subpic];
432 p_spu->p_subpicture[i_subpic].i_status = RESERVED_SUBPICTURE;
437 /* If no free subpicture could be found */
438 if( p_subpic == NULL )
440 msg_Err( p_spu, "subpicture heap is full" );
441 vlc_mutex_unlock( &p_spu->subpicture_lock );
445 /* Copy subpicture information, set some default values */
446 memset( p_subpic, 0, sizeof(subpicture_t) );
447 p_subpic->i_status = RESERVED_SUBPICTURE;
448 p_subpic->b_absolute = VLC_TRUE;
449 p_subpic->b_pausable = VLC_FALSE;
450 p_subpic->b_fade = VLC_FALSE;
451 p_subpic->i_alpha = 0xFF;
452 p_subpic->p_region = NULL;
453 p_subpic->pf_render = NULL;
454 p_subpic->pf_destroy = NULL;
455 p_subpic->p_sys = NULL;
456 vlc_mutex_unlock( &p_spu->subpicture_lock );
458 p_subpic->pf_create_region = __spu_CreateRegion;
459 p_subpic->pf_make_region = __spu_MakeRegion;
460 p_subpic->pf_destroy_region = __spu_DestroyRegion;
466 * Remove a subpicture from the heap
468 * This function frees a previously reserved subpicture.
469 * It is meant to be used when the construction of a picture aborted.
470 * This function does not need locking since reserved subpictures are ignored
473 void spu_DestroySubpicture( spu_t *p_spu, subpicture_t *p_subpic )
476 vlc_mutex_lock( &p_spu->subpicture_lock );
478 /* There can be race conditions so we need to check the status */
479 if( p_subpic->i_status == FREE_SUBPICTURE )
481 vlc_mutex_unlock( &p_spu->subpicture_lock );
485 /* Check if status is valid */
486 if( ( p_subpic->i_status != RESERVED_SUBPICTURE )
487 && ( p_subpic->i_status != READY_SUBPICTURE ) )
489 msg_Err( p_spu, "subpicture %p has invalid status %d",
490 p_subpic, p_subpic->i_status );
493 while( p_subpic->p_region )
495 subpicture_region_t *p_region = p_subpic->p_region;
496 p_subpic->p_region = p_region->p_next;
497 spu_DestroyRegion( p_spu, p_region );
500 if( p_subpic->pf_destroy )
502 p_subpic->pf_destroy( p_subpic );
505 p_subpic->i_status = FREE_SUBPICTURE;
507 vlc_mutex_unlock( &p_spu->subpicture_lock );
510 /*****************************************************************************
511 * spu_RenderSubpictures: render a subpicture list
512 *****************************************************************************
513 * This function renders all sub picture units in the list.
514 *****************************************************************************/
515 void spu_RenderSubpictures( spu_t *p_spu, video_format_t *p_fmt,
516 picture_t *p_pic_dst, picture_t *p_pic_src,
517 subpicture_t *p_subpic,
518 int i_scale_width_orig, int i_scale_height_orig )
520 int i_source_video_width;
521 int i_source_video_height;
524 vlc_mutex_lock( &p_spu->subpicture_lock );
526 if( i_scale_width_orig <= 0 )
527 i_scale_width_orig = 1;
528 if( i_scale_height_orig <= 0 )
529 i_scale_height_orig = 1;
531 i_source_video_width = p_fmt->i_width * 1000 / i_scale_width_orig;
532 i_source_video_height = p_fmt->i_height * 1000 / i_scale_height_orig;
534 /* Check i_status again to make sure spudec hasn't destroyed the subpic */
535 while( ( p_subpic != NULL ) && ( p_subpic->i_status != FREE_SUBPICTURE ) )
537 subpicture_region_t *p_region = p_subpic->p_region;
538 int pi_scale_width[ SCALE_SIZE ];
539 int pi_scale_height[ SCALE_SIZE ];
540 int pi_subpic_x[ SCALE_SIZE ];
543 /* If the source video and subtitles stream agree on the size of
544 * the video then disregard all further references to the subtitle
547 if( ( i_source_video_height == p_subpic->i_original_picture_height ) &&
548 ( i_source_video_width == p_subpic->i_original_picture_width ) )
550 p_subpic->i_original_picture_height = 0;
551 p_subpic->i_original_picture_width = 0;
554 for( k = 0; k < SCALE_SIZE ; k++ )
555 pi_subpic_x[ k ] = p_subpic->i_x;
557 /* Load the blending module */
558 if( !p_spu->p_blend && p_region )
560 p_spu->p_blend = vlc_object_create( p_spu, VLC_OBJECT_FILTER );
561 vlc_object_attach( p_spu->p_blend, p_spu );
562 p_spu->p_blend->fmt_out.video.i_x_offset =
563 p_spu->p_blend->fmt_out.video.i_y_offset = 0;
564 p_spu->p_blend->fmt_out.video.i_aspect = p_fmt->i_aspect;
565 p_spu->p_blend->fmt_out.video.i_chroma = p_fmt->i_chroma;
567 /* The blend module will be loaded when needed with the real
569 memset( &p_spu->p_blend->fmt_in, 0, sizeof(p_spu->p_blend->fmt_in) );
570 p_spu->p_blend->p_module = NULL;
573 /* Load the text rendering module; it is possible there is a
574 * text region somewhere in the subpicture other than the first
575 * element in the region list, so just load it anyway as we'll
576 * probably want it sooner or later. */
577 if( !p_spu->p_text && p_region )
579 char *psz_modulename = NULL;
581 p_spu->p_text = vlc_object_create( p_spu, VLC_OBJECT_FILTER );
582 vlc_object_attach( p_spu->p_text, p_spu );
584 p_spu->p_text->fmt_out.video.i_width =
585 p_spu->p_text->fmt_out.video.i_visible_width =
587 p_spu->p_text->fmt_out.video.i_height =
588 p_spu->p_text->fmt_out.video.i_visible_height =
591 p_spu->p_text->pf_sub_buffer_new = spu_new_buffer;
592 p_spu->p_text->pf_sub_buffer_del = spu_del_buffer;
594 psz_modulename = var_CreateGetString( p_spu, "text-renderer" );
595 if( psz_modulename && *psz_modulename )
597 p_spu->p_text->p_module =
598 module_Need( p_spu->p_text, "text renderer",
599 psz_modulename, VLC_TRUE );
601 if( !p_spu->p_text->p_module )
603 p_spu->p_text->p_module =
604 module_Need( p_spu->p_text, "text renderer", 0, 0 );
606 if( psz_modulename ) free( psz_modulename );
611 subpicture_region_t *p_text_region = p_subpic->p_region;
613 /* Only overwrite the size fields if the region is still in
614 * pre-rendered TEXT format. We have to traverse the subregion
615 * list because if more than one subregion is present, the text
616 * region isn't guarentteed to be the first in the list, and
617 * only text regions use this flag. All of this effort assists
618 * with the rescaling of text that has been rendered at native
619 * resolution, rather than video resolution.
621 while( p_text_region &&
622 ( p_text_region->fmt.i_chroma != VLC_FOURCC('T','E','X','T') ) )
624 p_text_region = p_text_region->p_next;
628 ( ( p_text_region->i_align & SUBPICTURE_RENDERED ) == 0 ) )
630 if( (p_subpic->i_original_picture_height > 0) &&
631 (p_subpic->i_original_picture_width > 0) )
633 p_spu->p_text->fmt_out.video.i_width =
634 p_spu->p_text->fmt_out.video.i_visible_width =
635 p_subpic->i_original_picture_width;
636 p_spu->p_text->fmt_out.video.i_height =
637 p_spu->p_text->fmt_out.video.i_visible_height =
638 p_subpic->i_original_picture_height;
642 p_spu->p_text->fmt_out.video.i_width =
643 p_spu->p_text->fmt_out.video.i_visible_width =
645 p_spu->p_text->fmt_out.video.i_height =
646 p_spu->p_text->fmt_out.video.i_visible_height =
652 pi_scale_width[ SCALE_DEFAULT ] = i_scale_width_orig;
653 pi_scale_height[ SCALE_DEFAULT ] = i_scale_height_orig;
657 pi_scale_width[ SCALE_TEXT ] = ( p_fmt->i_width * 1000 ) /
658 p_spu->p_text->fmt_out.video.i_width;
659 pi_scale_height[ SCALE_TEXT ] = ( p_fmt->i_height * 1000 ) /
660 p_spu->p_text->fmt_out.video.i_height;
662 /* If we have an explicit size plane to render to, then turn off
663 * the fontsize rescaling.
665 if( (p_subpic->i_original_picture_height > 0) &&
666 (p_subpic->i_original_picture_width > 0) )
668 i_scale_width_orig = 1000;
669 i_scale_height_orig = 1000;
672 for( k = 0; k < SCALE_SIZE ; k++ )
674 /* Case of both width and height being specified has been dealt
675 * with above by instead rendering to an output pane of the
676 * explicit dimensions specified - we don't need to scale it.
678 if( (p_subpic->i_original_picture_height > 0) &&
679 (p_subpic->i_original_picture_width <= 0) )
681 pi_scale_height[ k ] = pi_scale_height[ k ] * i_source_video_height /
682 p_subpic->i_original_picture_height;
683 pi_scale_width[ k ] = pi_scale_width[ k ] * i_source_video_height /
684 p_subpic->i_original_picture_height;
688 /* Set default subpicture aspect ratio */
689 if( p_region && p_region->fmt.i_aspect &&
690 ( !p_region->fmt.i_sar_num || !p_region->fmt.i_sar_den ) )
692 p_region->fmt.i_sar_den = p_region->fmt.i_aspect;
693 p_region->fmt.i_sar_num = VOUT_ASPECT_FACTOR;
696 ( !p_region->fmt.i_sar_num || !p_region->fmt.i_sar_den ) )
698 p_region->fmt.i_sar_den = p_fmt->i_sar_den;
699 p_region->fmt.i_sar_num = p_fmt->i_sar_num;
702 /* Take care of the aspect ratio */
704 ( ( p_region->fmt.i_sar_num * p_fmt->i_sar_den ) !=
705 ( p_region->fmt.i_sar_den * p_fmt->i_sar_num ) ) )
707 for( k = 0; k < SCALE_SIZE ; k++ )
709 pi_scale_width[ k ] = pi_scale_width[ k ] *
710 (int64_t)p_region->fmt.i_sar_num * p_fmt->i_sar_den /
711 p_region->fmt.i_sar_den / p_fmt->i_sar_num;
712 pi_subpic_x[ k ] = p_subpic->i_x * pi_scale_width[ k ] / 1000;
716 /* Load the scaling module */
717 if( !p_spu->p_scale &&
718 ((((pi_scale_width[ SCALE_TEXT ] > 0) || (pi_scale_height[ SCALE_TEXT ] > 0)) &&
719 ((pi_scale_width[ SCALE_TEXT ] != 1000) || (pi_scale_height[ SCALE_TEXT ] != 1000))) ||
720 (((pi_scale_width[ SCALE_DEFAULT ] > 0) || (pi_scale_height[ SCALE_DEFAULT ] > 0)) &&
721 ((pi_scale_width[ SCALE_DEFAULT ] != 1000) || (pi_scale_height[ SCALE_DEFAULT ] != 1000)))) )
723 p_spu->p_scale = vlc_object_create( p_spu, VLC_OBJECT_FILTER );
724 vlc_object_attach( p_spu->p_scale, p_spu );
725 p_spu->p_scale->fmt_out.video.i_chroma =
726 p_spu->p_scale->fmt_in.video.i_chroma =
727 VLC_FOURCC('Y','U','V','P');
728 /* FIXME: We'll also be using it for YUVA and RGBA blending ... */
730 p_spu->p_scale->fmt_in.video.i_width =
731 p_spu->p_scale->fmt_in.video.i_height = 32;
732 p_spu->p_scale->fmt_out.video.i_width =
733 p_spu->p_scale->fmt_out.video.i_height = 16;
735 p_spu->p_scale->pf_vout_buffer_new = spu_new_video_buffer;
736 p_spu->p_scale->pf_vout_buffer_del = spu_del_video_buffer;
737 p_spu->p_scale->p_module =
738 module_Need( p_spu->p_scale, "video filter2", 0, 0 );
743 video_format_t orig_fmt = p_region->fmt;
744 vlc_bool_t b_rerender_text = VLC_FALSE;
745 int i_fade_alpha = 255;
748 int i_scale_idx = SCALE_DEFAULT;
749 int i_inv_scale_x = 1000;
750 int i_inv_scale_y = 1000;
752 if( p_region->fmt.i_chroma == VLC_FOURCC('T','E','X','T') )
754 if( p_spu->p_text && p_spu->p_text->p_module )
758 /* Setup 3 variables which can be used to render
759 * time-dependent text (and effects). The first indicates
760 * the total amount of time the text will be on screen,
761 * the second the amount of time it has already been on
762 * screen (can be a negative value as text is layed out
763 * before it is rendered) and the third is a feedback
764 * variable from the renderer - if the renderer sets it
765 * then this particular text is time-dependent, eg. the
766 * visual progress bar inside the text in karaoke and the
767 * text needs to be rendered multiple times in order for
768 * the effect to work - we therefore need to return the
769 * region to its original state at the end of the loop,
770 * instead of leaving it in YUVA or YUVP.
771 * Any renderer which is unaware of how to render
772 * time-dependent text can happily ignore the variables
773 * and render the text the same as usual - it should at
774 * least show up on screen, but the effect won't change
775 * the text over time.
778 var_Create( p_spu->p_text, "spu-duration", VLC_VAR_TIME );
779 val.i_time = p_subpic->i_stop - p_subpic->i_start;
780 var_Set( p_spu->p_text, "spu-duration", val );
782 var_Create( p_spu->p_text, "spu-elapsed", VLC_VAR_TIME );
783 val.i_time = mdate() - p_subpic->i_start;
784 var_Set( p_spu->p_text, "spu-elapsed", val );
786 var_Create( p_spu->p_text, "text-rerender", VLC_VAR_BOOL );
787 var_SetBool( p_spu->p_text, "text-rerender", VLC_FALSE );
789 var_Create( p_spu->p_text, "scale", VLC_VAR_INTEGER );
790 var_SetInteger( p_spu->p_text, "scale",
791 __MIN(i_scale_width_orig, i_scale_height_orig) );
793 if( p_spu->p_text->pf_render_html && p_region->psz_html )
795 p_spu->p_text->pf_render_html( p_spu->p_text,
796 p_region, p_region );
798 else if( p_spu->p_text->pf_render_text )
800 p_spu->p_text->pf_render_text( p_spu->p_text,
801 p_region, p_region );
803 b_rerender_text = var_GetBool( p_spu->p_text, "text-rerender" );
805 var_Destroy( p_spu->p_text, "spu-duration" );
806 var_Destroy( p_spu->p_text, "spu-elapsed" );
807 var_Destroy( p_spu->p_text, "text-rerender" );
808 var_Destroy( p_spu->p_text, "scale" );
810 p_region->i_align |= SUBPICTURE_RENDERED;
813 if( p_region->i_align & SUBPICTURE_RENDERED )
815 i_scale_idx = SCALE_TEXT;
816 i_inv_scale_x = i_scale_width_orig;
817 i_inv_scale_y = i_scale_height_orig;
820 i_x_offset = (p_region->i_x + pi_subpic_x[ i_scale_idx ]) * i_inv_scale_x / 1000;
821 i_y_offset = (p_region->i_y + p_subpic->i_y) * i_inv_scale_y / 1000;
823 /* Force palette if requested */
824 if( p_spu->b_force_palette &&
825 ( VLC_FOURCC('Y','U','V','P') == p_region->fmt.i_chroma ) )
827 memcpy( p_region->fmt.p_palette->palette,
828 p_spu->palette, 16 );
831 /* Scale SPU if necessary */
832 if( p_region->p_cache &&
833 ( p_region->fmt.i_chroma != VLC_FOURCC('T','E','X','T') ) )
835 if( pi_scale_width[ i_scale_idx ] * p_region->fmt.i_width / 1000 !=
836 p_region->p_cache->fmt.i_width ||
837 pi_scale_height[ i_scale_idx ] * p_region->fmt.i_height / 1000 !=
838 p_region->p_cache->fmt.i_height )
840 p_subpic->pf_destroy_region( VLC_OBJECT(p_spu),
842 p_region->p_cache = 0;
846 if( ( ( pi_scale_width[ i_scale_idx ] != 1000 ) ||
847 ( pi_scale_height[ i_scale_idx ] != 1000 ) ) &&
848 ( ( pi_scale_width[ i_scale_idx ] > 0 ) ||
849 ( pi_scale_height[ i_scale_idx ] > 0 ) ) &&
850 p_spu->p_scale && !p_region->p_cache &&
851 ( p_region->fmt.i_chroma != VLC_FOURCC('T','E','X','T') ) )
855 p_spu->p_scale->fmt_in.video = p_region->fmt;
856 p_spu->p_scale->fmt_out.video = p_region->fmt;
859 p_subpic->pf_create_region( VLC_OBJECT(p_spu),
860 &p_spu->p_scale->fmt_out.video );
861 if( p_spu->p_scale->fmt_out.video.p_palette )
862 *p_spu->p_scale->fmt_out.video.p_palette =
863 *p_region->fmt.p_palette;
864 p_region->p_cache->p_next = p_region->p_next;
866 vout_CopyPicture( p_spu, &p_region->p_cache->picture,
867 &p_region->picture );
869 p_spu->p_scale->fmt_out.video.i_width =
870 p_region->fmt.i_width * pi_scale_width[ i_scale_idx ] / 1000;
871 p_spu->p_scale->fmt_out.video.i_visible_width =
872 p_region->fmt.i_visible_width * pi_scale_width[ i_scale_idx ] / 1000;
873 p_spu->p_scale->fmt_out.video.i_height =
874 p_region->fmt.i_height * pi_scale_height[ i_scale_idx ] / 1000;
875 p_spu->p_scale->fmt_out.video.i_visible_height =
876 p_region->fmt.i_visible_height * pi_scale_height[ i_scale_idx ] / 1000;
877 p_region->p_cache->fmt = p_spu->p_scale->fmt_out.video;
878 p_region->p_cache->i_x = p_region->i_x * pi_scale_width[ i_scale_idx ] / 1000;
879 p_region->p_cache->i_y = p_region->i_y * pi_scale_height[ i_scale_idx ] / 1000;
880 p_region->p_cache->i_align = p_region->i_align;
882 p_pic = p_spu->p_scale->pf_video_filter(
883 p_spu->p_scale, &p_region->p_cache->picture );
886 picture_t p_pic_tmp = p_region->p_cache->picture;
887 p_region->p_cache->picture = *p_pic;
893 if( ( ( pi_scale_width[ i_scale_idx ] != 1000 ) ||
894 ( pi_scale_height[ i_scale_idx ] != 1000 ) ) &&
895 ( ( pi_scale_width[ i_scale_idx ] > 0 ) ||
896 ( pi_scale_height[ i_scale_idx ] > 0 ) ) &&
897 p_spu->p_scale && p_region->p_cache &&
898 ( p_region->fmt.i_chroma != VLC_FOURCC('T','E','X','T') ) )
900 p_region = p_region->p_cache;
903 if( p_region->i_align & SUBPICTURE_ALIGN_BOTTOM )
905 i_y_offset = p_fmt->i_height - p_region->fmt.i_height -
906 (p_subpic->i_y + p_region->i_y) * i_inv_scale_y / 1000;
908 else if ( !(p_region->i_align & SUBPICTURE_ALIGN_TOP) )
910 i_y_offset = p_fmt->i_height / 2 - p_region->fmt.i_height / 2;
913 if( p_region->i_align & SUBPICTURE_ALIGN_RIGHT )
915 i_x_offset = p_fmt->i_width - p_region->fmt.i_width -
916 (pi_subpic_x[ i_scale_idx ] + p_region->i_x)
917 * i_inv_scale_x / 1000;
919 else if ( !(p_region->i_align & SUBPICTURE_ALIGN_LEFT) )
921 i_x_offset = p_fmt->i_width / 2 - p_region->fmt.i_width / 2;
924 if( p_subpic->b_absolute )
926 i_x_offset = (p_region->i_x +
927 pi_subpic_x[ i_scale_idx ] *
928 pi_scale_width[ i_scale_idx ] / 1000)
929 * i_inv_scale_x / 1000;
930 i_y_offset = (p_region->i_y +
931 p_subpic->i_y * pi_scale_height[ i_scale_idx ] / 1000)
932 * i_inv_scale_y / 1000;
936 i_x_offset = __MAX( i_x_offset, 0 );
937 i_y_offset = __MAX( i_y_offset, 0 );
939 if( ( p_spu->i_margin != 0 ) &&
940 ( p_spu->b_force_crop == VLC_FALSE ) )
943 int i_low = (i_y_offset - p_spu->i_margin) * i_inv_scale_y / 1000;
944 int i_high = i_low + p_region->fmt.i_height;
946 /* crop extra margin to keep within bounds */
949 if( i_high > (int)p_fmt->i_height )
950 i_diff = i_high - p_fmt->i_height;
951 i_y_offset -= ( p_spu->i_margin * i_inv_scale_y / 1000 + i_diff );
954 if( p_subpic->b_fade )
956 mtime_t i_fade_start = ( p_subpic->i_stop +
957 p_subpic->i_start ) / 2;
958 mtime_t i_now = mdate();
959 if( i_now >= i_fade_start && p_subpic->i_stop > i_fade_start )
961 i_fade_alpha = 255 * ( p_subpic->i_stop - i_now ) /
962 ( p_subpic->i_stop - i_fade_start );
966 if( p_region->fmt.i_chroma != VLC_FOURCC('T','E','X','T') )
968 if( p_spu->p_blend->fmt_in.video.i_chroma != p_region->fmt.i_chroma )
970 /* The chroma is not the same, we need to reload the blend module
971 * XXX to match the old behaviour just test !p_spu->p_blend->fmt_in.video.i_chroma */
972 if( p_spu->p_blend->p_module )
973 module_Unneed( p_spu->p_blend, p_spu->p_blend->p_module );
975 p_spu->p_blend->fmt_in.video = p_region->fmt;
976 p_spu->p_blend->p_module = module_Need( p_spu->p_blend, "video blending", 0, 0 );
980 p_spu->p_blend->fmt_in.video = p_region->fmt;
983 /* Force cropping if requested */
984 if( p_spu->b_force_crop )
986 video_format_t *p_fmt = &p_spu->p_blend->fmt_in.video;
987 int i_crop_x = p_spu->i_crop_x * pi_scale_width[ i_scale_idx ] / 1000
988 * i_inv_scale_x / 1000;
989 int i_crop_y = p_spu->i_crop_y * pi_scale_height[ i_scale_idx ] / 1000
990 * i_inv_scale_y / 1000;
991 int i_crop_width = p_spu->i_crop_width * pi_scale_width[ i_scale_idx ] / 1000
992 * i_inv_scale_x / 1000;
993 int i_crop_height = p_spu->i_crop_height * pi_scale_height[ i_scale_idx ] / 1000
994 * i_inv_scale_y / 1000;
996 /* Find the intersection */
997 if( i_crop_x + i_crop_width <= i_x_offset ||
998 i_x_offset + (int)p_fmt->i_visible_width < i_crop_x ||
999 i_crop_y + i_crop_height <= i_y_offset ||
1000 i_y_offset + (int)p_fmt->i_visible_height < i_crop_y )
1002 /* No intersection */
1003 p_fmt->i_visible_width = p_fmt->i_visible_height = 0;
1007 int i_x, i_y, i_x_end, i_y_end;
1008 i_x = __MAX( i_crop_x, i_x_offset );
1009 i_y = __MAX( i_crop_y, i_y_offset );
1010 i_x_end = __MIN( i_crop_x + i_crop_width,
1011 i_x_offset + (int)p_fmt->i_visible_width );
1012 i_y_end = __MIN( i_crop_y + i_crop_height,
1013 i_y_offset + (int)p_fmt->i_visible_height );
1015 p_fmt->i_x_offset = i_x - i_x_offset;
1016 p_fmt->i_y_offset = i_y - i_y_offset;
1017 p_fmt->i_visible_width = i_x_end - i_x;
1018 p_fmt->i_visible_height = i_y_end - i_y;
1025 i_x_offset = __MAX( i_x_offset, 0 );
1026 i_y_offset = __MAX( i_y_offset, 0 );
1028 /* Update the output picture size */
1029 p_spu->p_blend->fmt_out.video.i_width =
1030 p_spu->p_blend->fmt_out.video.i_visible_width =
1032 p_spu->p_blend->fmt_out.video.i_height =
1033 p_spu->p_blend->fmt_out.video.i_visible_height =
1036 if( p_spu->p_blend->p_module )
1038 p_spu->p_blend->pf_video_blend( p_spu->p_blend, p_pic_dst,
1039 p_pic_src, &p_region->picture, i_x_offset, i_y_offset,
1040 i_fade_alpha * p_subpic->i_alpha / 255 );
1044 msg_Err( p_spu, "blending %4.4s to %4.4s failed",
1045 (char *)&p_spu->p_blend->fmt_out.video.i_chroma,
1046 (char *)&p_spu->p_blend->fmt_out.video.i_chroma );
1050 if( b_rerender_text )
1052 /* Some forms of subtitles need to be re-rendered more than
1053 * once, eg. karaoke. We therefore restore the region to its
1054 * pre-rendered state, so the next time through everything is
1057 p_region->picture.pf_release( &p_region->picture );
1058 memset( &p_region->picture, 0, sizeof( picture_t ) );
1059 p_region->fmt = orig_fmt;
1060 p_region->i_align &= ~SUBPICTURE_RENDERED;
1062 p_region = p_region->p_next;
1065 p_subpic = p_subpic->p_next;
1068 vlc_mutex_unlock( &p_spu->subpicture_lock );
1071 /*****************************************************************************
1072 * spu_SortSubpictures: find the subpictures to display
1073 *****************************************************************************
1074 * This function parses all subpictures and decides which ones need to be
1075 * displayed. This operation does not need lock, since only READY_SUBPICTURE
1076 * are handled. If no picture has been selected, display_date will depend on
1078 * We also check for ephemer DVD subpictures (subpictures that have
1079 * to be removed if a newer one is available), which makes it a lot
1080 * more difficult to guess if a subpicture has to be rendered or not.
1081 *****************************************************************************/
1082 subpicture_t *spu_SortSubpictures( spu_t *p_spu, mtime_t display_date,
1083 vlc_bool_t b_paused )
1085 int i_index, i_channel;
1086 subpicture_t *p_subpic = NULL;
1087 subpicture_t *p_ephemer;
1088 mtime_t ephemer_date;
1090 /* Run subpicture filters */
1091 for( i_index = 0; i_index < p_spu->i_filter; i_index++ )
1093 subpicture_t *p_subpic_filter;
1094 p_subpic_filter = p_spu->pp_filter[i_index]->
1095 pf_sub_filter( p_spu->pp_filter[i_index], display_date );
1096 if( p_subpic_filter )
1098 spu_DisplaySubpicture( p_spu, p_subpic_filter );
1102 /* We get an easily parsable chained list of subpictures which
1103 * ends with NULL since p_subpic was initialized to NULL. */
1104 for( i_channel = 0; i_channel < p_spu->i_channel; i_channel++ )
1109 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
1111 if( p_spu->p_subpicture[i_index].i_channel != i_channel ||
1112 p_spu->p_subpicture[i_index].i_status != READY_SUBPICTURE )
1117 display_date < p_spu->p_subpicture[i_index].i_start )
1119 /* Too early, come back next monday */
1123 if( p_spu->p_subpicture[i_index].i_start > ephemer_date )
1124 ephemer_date = p_spu->p_subpicture[i_index].i_start;
1126 if( display_date > p_spu->p_subpicture[i_index].i_stop &&
1127 ( !p_spu->p_subpicture[i_index].b_ephemer ||
1128 p_spu->p_subpicture[i_index].i_stop >
1129 p_spu->p_subpicture[i_index].i_start ) &&
1130 !( p_spu->p_subpicture[i_index].b_pausable &&
1133 /* Too late, destroy the subpic */
1134 spu_DestroySubpicture( p_spu, &p_spu->p_subpicture[i_index] );
1138 /* If this is an ephemer subpic, add it to our list */
1139 if( p_spu->p_subpicture[i_index].b_ephemer )
1141 p_spu->p_subpicture[i_index].p_next = p_ephemer;
1142 p_ephemer = &p_spu->p_subpicture[i_index];
1147 p_spu->p_subpicture[i_index].p_next = p_subpic;
1148 p_subpic = &p_spu->p_subpicture[i_index];
1151 /* If we found ephemer subpictures, check if they have to be
1152 * displayed or destroyed */
1153 while( p_ephemer != NULL )
1155 subpicture_t *p_tmp = p_ephemer;
1156 p_ephemer = p_ephemer->p_next;
1158 if( p_tmp->i_start < ephemer_date )
1160 /* Ephemer subpicture has lived too long */
1161 spu_DestroySubpicture( p_spu, p_tmp );
1165 /* Ephemer subpicture can still live a bit */
1166 p_tmp->p_next = p_subpic;
1175 /*****************************************************************************
1176 * SpuClearChannel: clear an spu channel
1177 *****************************************************************************
1178 * This function destroys the subpictures which belong to the spu channel
1179 * corresponding to i_channel_id.
1180 *****************************************************************************/
1181 static void SpuClearChannel( spu_t *p_spu, int i_channel )
1183 int i_subpic; /* subpicture index */
1184 subpicture_t *p_subpic = NULL; /* first free subpicture */
1186 vlc_mutex_lock( &p_spu->subpicture_lock );
1188 for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
1190 p_subpic = &p_spu->p_subpicture[i_subpic];
1191 if( p_subpic->i_status == FREE_SUBPICTURE
1192 || ( p_subpic->i_status != RESERVED_SUBPICTURE
1193 && p_subpic->i_status != READY_SUBPICTURE ) )
1198 if( p_subpic->i_channel == i_channel )
1200 while( p_subpic->p_region )
1202 subpicture_region_t *p_region = p_subpic->p_region;
1203 p_subpic->p_region = p_region->p_next;
1204 spu_DestroyRegion( p_spu, p_region );
1207 if( p_subpic->pf_destroy ) p_subpic->pf_destroy( p_subpic );
1208 p_subpic->i_status = FREE_SUBPICTURE;
1212 vlc_mutex_unlock( &p_spu->subpicture_lock );
1215 /*****************************************************************************
1216 * spu_ControlDefault: default methods for the subpicture unit control.
1217 *****************************************************************************/
1218 static int spu_vaControlDefault( spu_t *p_spu, int i_query, va_list args )
1224 case SPU_CHANNEL_REGISTER:
1225 pi = (int *)va_arg( args, int * );
1226 if( pi ) *pi = p_spu->i_channel++;
1229 case SPU_CHANNEL_CLEAR:
1230 i = (int)va_arg( args, int );
1231 SpuClearChannel( p_spu, i );
1235 msg_Dbg( p_spu, "control query not supported" );
1236 return VLC_EGENERIC;
1242 /*****************************************************************************
1243 * Object variables callbacks
1244 *****************************************************************************/
1246 /*****************************************************************************
1247 * UpdateSPU: update subpicture settings
1248 *****************************************************************************
1249 * This function is called from CropCallback and at initialization time, to
1250 * retrieve crop information from the input.
1251 *****************************************************************************/
1252 static void UpdateSPU( spu_t *p_spu, vlc_object_t *p_object )
1256 p_spu->b_force_palette = VLC_FALSE;
1257 p_spu->b_force_crop = VLC_FALSE;
1259 if( var_Get( p_object, "highlight", &val ) || !val.b_bool ) return;
1261 p_spu->b_force_crop = VLC_TRUE;
1262 var_Get( p_object, "x-start", &val );
1263 p_spu->i_crop_x = val.i_int;
1264 var_Get( p_object, "y-start", &val );
1265 p_spu->i_crop_y = val.i_int;
1266 var_Get( p_object, "x-end", &val );
1267 p_spu->i_crop_width = val.i_int - p_spu->i_crop_x;
1268 var_Get( p_object, "y-end", &val );
1269 p_spu->i_crop_height = val.i_int - p_spu->i_crop_y;
1271 if( var_Get( p_object, "menu-palette", &val ) == VLC_SUCCESS )
1273 memcpy( p_spu->palette, val.p_address, 16 );
1274 p_spu->b_force_palette = VLC_TRUE;
1277 msg_Dbg( p_object, "crop: %i,%i,%i,%i, palette forced: %i",
1278 p_spu->i_crop_x, p_spu->i_crop_y,
1279 p_spu->i_crop_width, p_spu->i_crop_height,
1280 p_spu->b_force_palette );
1283 /*****************************************************************************
1284 * CropCallback: called when the highlight properties are changed
1285 *****************************************************************************
1286 * This callback is called from the input thread when we need cropping
1287 *****************************************************************************/
1288 static int CropCallback( vlc_object_t *p_object, char const *psz_var,
1289 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1291 (void)psz_var; (void)oldval; (void)newval;
1292 UpdateSPU( (spu_t *)p_data, p_object );
1296 /*****************************************************************************
1297 * Buffers allocation callbacks for the filters
1298 *****************************************************************************/
1299 static subpicture_t *sub_new_buffer( filter_t *p_filter )
1301 filter_owner_sys_t *p_sys = p_filter->p_owner;
1302 subpicture_t *p_subpicture = spu_CreateSubpicture( p_sys->p_spu );
1303 if( p_subpicture ) p_subpicture->i_channel = p_sys->i_channel;
1304 return p_subpicture;
1307 static void sub_del_buffer( filter_t *p_filter, subpicture_t *p_subpic )
1309 filter_owner_sys_t *p_sys = p_filter->p_owner;
1310 spu_DestroySubpicture( p_sys->p_spu, p_subpic );
1313 static subpicture_t *spu_new_buffer( filter_t *p_filter )
1316 subpicture_t *p_subpic = (subpicture_t *)malloc(sizeof(subpicture_t));
1317 if( !p_subpic ) return NULL;
1318 memset( p_subpic, 0, sizeof(subpicture_t) );
1319 p_subpic->b_absolute = VLC_TRUE;
1321 p_subpic->pf_create_region = __spu_CreateRegion;
1322 p_subpic->pf_make_region = __spu_MakeRegion;
1323 p_subpic->pf_destroy_region = __spu_DestroyRegion;
1328 static void spu_del_buffer( filter_t *p_filter, subpicture_t *p_subpic )
1330 while( p_subpic->p_region )
1332 subpicture_region_t *p_region = p_subpic->p_region;
1333 p_subpic->p_region = p_region->p_next;
1334 p_subpic->pf_destroy_region( VLC_OBJECT(p_filter), p_region );
1340 static picture_t *spu_new_video_buffer( filter_t *p_filter )
1342 picture_t *p_picture = malloc( sizeof(picture_t) );
1343 if( !p_picture ) return NULL;
1344 if( vout_AllocatePicture( p_filter, p_picture,
1345 p_filter->fmt_out.video.i_chroma,
1346 p_filter->fmt_out.video.i_width,
1347 p_filter->fmt_out.video.i_height,
1348 p_filter->fmt_out.video.i_aspect )
1355 p_picture->pf_release = RegionPictureRelease;
1360 static void spu_del_video_buffer( filter_t *p_filter, picture_t *p_pic )
1365 if( p_pic->p_data_orig ) free( p_pic->p_data_orig );
1370 static int SubFilterCallback( vlc_object_t *p_object, char const *psz_var,
1371 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1373 (void)p_object; (void)oldval; (void)newval;
1375 spu_t *p_spu = (spu_t *)p_data;
1376 vlc_mutex_lock( &p_spu->subpicture_lock );
1377 spu_DeleteChain( p_spu );
1378 spu_ParseChain( p_spu );
1379 vlc_mutex_unlock( &p_spu->subpicture_lock );