1 /*****************************************************************************
2 * vout_subpictures.c : subpicture management functions
3 *****************************************************************************
4 * Copyright (C) 2000-2007 the VideoLAN team
7 * Authors: Vincent Seguin <seguin@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
9 * Gildas Bazin <gbazin@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
33 #include <vlc_common.h>
35 #include <vlc_block.h>
36 #include <vlc_filter.h>
38 #include "../libvlc.h"
42 /*****************************************************************************
44 *****************************************************************************/
45 static void UpdateSPU ( spu_t *, vlc_object_t * );
46 static int CropCallback( vlc_object_t *, char const *,
47 vlc_value_t, vlc_value_t, void * );
49 static int spu_vaControlDefault( spu_t *, int, va_list );
51 static subpicture_t *sub_new_buffer( filter_t * );
52 static void sub_del_buffer( filter_t *, subpicture_t * );
53 static subpicture_t *spu_new_buffer( filter_t * );
54 static void spu_del_buffer( filter_t *, subpicture_t * );
55 static picture_t *spu_new_video_buffer( filter_t * );
56 static void spu_del_video_buffer( filter_t *, picture_t * );
58 static int spu_ParseChain( spu_t * );
59 static int SubFilterCallback( vlc_object_t *, char const *,
60 vlc_value_t, vlc_value_t, void * );
62 static int sub_filter_allocation_init( filter_t *, void * );
63 static void sub_filter_allocation_clear( filter_t * );
64 struct filter_owner_sys_t
76 static void FilterRelease( filter_t *p_filter )
78 if( p_filter->p_module )
79 module_Unneed( p_filter, p_filter->p_module );
81 vlc_object_detach( p_filter );
82 vlc_object_release( p_filter );
86 * Creates the subpicture unit
88 * \param p_this the parent object which creates the subpicture unit
90 spu_t *__spu_Create( vlc_object_t *p_this )
93 spu_t *p_spu = vlc_custom_create( p_this, sizeof( spu_t ),
94 VLC_OBJECT_GENERIC, "subpicture" );
96 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++)
98 p_spu->p_subpicture[i_index].i_status = FREE_SUBPICTURE;
101 p_spu->p_blend = NULL;
102 p_spu->p_text = NULL;
103 p_spu->p_scale = NULL;
104 p_spu->p_scale_yuvp = NULL;
105 p_spu->pf_control = spu_vaControlDefault;
107 /* Register the default subpicture channel */
108 p_spu->i_channel = 2;
110 vlc_mutex_init( &p_spu->subpicture_lock );
112 vlc_object_attach( p_spu, p_this );
114 p_spu->p_chain = filter_chain_New( p_spu, "sub filter", false,
115 sub_filter_allocation_init,
116 sub_filter_allocation_clear,
122 * Initialise the subpicture unit
124 * \param p_spu the subpicture unit object
126 int spu_Init( spu_t *p_spu )
130 /* If the user requested a sub margin, we force the position. */
131 var_Create( p_spu, "sub-margin", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
132 var_Get( p_spu, "sub-margin", &val );
133 p_spu->i_margin = val.i_int;
135 var_Create( p_spu, "sub-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
136 var_AddCallback( p_spu, "sub-filter", SubFilterCallback, p_spu );
138 spu_ParseChain( p_spu );
143 int spu_ParseChain( spu_t *p_spu )
145 char *psz_parser = var_GetString( p_spu, "sub-filter" );
146 if( filter_chain_AppendFromString( p_spu->p_chain, psz_parser ) < 0 )
157 * Destroy the subpicture unit
159 * \param p_this the parent object which destroys the subpicture unit
161 void spu_Destroy( spu_t *p_spu )
165 /* Destroy all remaining subpictures */
166 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
168 if( p_spu->p_subpicture[i_index].i_status != FREE_SUBPICTURE )
170 spu_DestroySubpicture( p_spu, &p_spu->p_subpicture[i_index] );
175 FilterRelease( p_spu->p_blend );
178 FilterRelease( p_spu->p_text );
180 if( p_spu->p_scale_yuvp )
181 FilterRelease( p_spu->p_scale_yuvp );
184 FilterRelease( p_spu->p_scale );
186 filter_chain_Delete( p_spu->p_chain );
188 vlc_mutex_destroy( &p_spu->subpicture_lock );
189 vlc_object_release( p_spu );
193 * Attach/Detach the SPU from any input
195 * \param p_this the object in which to destroy the subpicture unit
196 * \param b_attach to select attach or detach
198 void spu_Attach( spu_t *p_spu, vlc_object_t *p_this, bool b_attach )
200 vlc_object_t *p_input;
202 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_PARENT );
203 if( !p_input ) return;
207 UpdateSPU( p_spu, VLC_OBJECT(p_input) );
208 var_AddCallback( p_input, "highlight", CropCallback, p_spu );
209 vlc_object_release( p_input );
213 /* Delete callback */
214 var_DelCallback( p_input, "highlight", CropCallback, p_spu );
215 vlc_object_release( p_input );
220 * Create a subpicture region
222 * \param p_this vlc_object_t
223 * \param p_fmt the format that this subpicture region should have
225 static void RegionPictureRelease( picture_t *p_pic )
227 free( p_pic->p_data_orig );
228 /* We use pf_release nullity to know if the picture has already been released. */
229 p_pic->pf_release = NULL;
231 subpicture_region_t *__spu_CreateRegion( vlc_object_t *p_this,
232 video_format_t *p_fmt )
234 subpicture_region_t *p_region = malloc( sizeof(subpicture_region_t) );
235 if( !p_region ) return NULL;
237 memset( p_region, 0, sizeof(subpicture_region_t) );
238 p_region->i_alpha = 0xff;
239 p_region->p_next = NULL;
240 p_region->p_cache = NULL;
241 p_region->fmt = *p_fmt;
242 p_region->psz_text = NULL;
243 p_region->p_style = NULL;
245 if( p_fmt->i_chroma == VLC_FOURCC('Y','U','V','P') )
246 p_fmt->p_palette = p_region->fmt.p_palette =
247 malloc( sizeof(video_palette_t) );
248 else p_fmt->p_palette = p_region->fmt.p_palette = NULL;
250 p_region->picture.p_data_orig = NULL;
252 if( p_fmt->i_chroma == VLC_FOURCC('T','E','X','T') ) return p_region;
254 vout_AllocatePicture( p_this, &p_region->picture, p_fmt->i_chroma,
255 p_fmt->i_width, p_fmt->i_height, p_fmt->i_aspect );
257 if( !p_region->picture.i_planes )
260 free( p_fmt->p_palette );
264 p_region->picture.pf_release = RegionPictureRelease;
270 * Make a subpicture region from an existing picture_t
272 * \param p_this vlc_object_t
273 * \param p_fmt the format that this subpicture region should have
274 * \param p_pic a pointer to the picture creating the region (not freed)
276 subpicture_region_t *__spu_MakeRegion( vlc_object_t *p_this,
277 video_format_t *p_fmt,
280 subpicture_region_t *p_region = malloc( sizeof(subpicture_region_t) );
282 if( !p_region ) return NULL;
283 memset( p_region, 0, sizeof(subpicture_region_t) );
284 p_region->i_alpha = 0xff;
285 p_region->p_next = 0;
286 p_region->p_cache = 0;
287 p_region->fmt = *p_fmt;
288 p_region->psz_text = 0;
289 p_region->p_style = NULL;
291 if( p_fmt->i_chroma == VLC_FOURCC('Y','U','V','P') )
292 p_fmt->p_palette = p_region->fmt.p_palette =
293 malloc( sizeof(video_palette_t) );
294 else p_fmt->p_palette = p_region->fmt.p_palette = NULL;
296 memcpy( &p_region->picture, p_pic, sizeof(picture_t) );
297 p_region->picture.pf_release = RegionPictureRelease;
303 * Destroy a subpicture region
305 * \param p_this vlc_object_t
306 * \param p_region the subpicture region to destroy
308 void __spu_DestroyRegion( vlc_object_t *p_this, subpicture_region_t *p_region )
310 if( !p_region ) return;
311 if( p_region->picture.pf_release )
312 p_region->picture.pf_release( &p_region->picture );
313 free( p_region->fmt.p_palette );
314 if( p_region->p_cache ) __spu_DestroyRegion( p_this, p_region->p_cache );
316 free( p_region->psz_text );
317 free( p_region->psz_html );
318 //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
323 * Display a subpicture
325 * Remove the reservation flag of a subpicture, which will cause it to be
327 * \param p_spu the subpicture unit object
328 * \param p_subpic the subpicture to display
330 void spu_DisplaySubpicture( spu_t *p_spu, subpicture_t *p_subpic )
332 /* Check if status is valid */
333 if( p_subpic->i_status != RESERVED_SUBPICTURE )
335 msg_Err( p_spu, "subpicture %p has invalid status #%d",
336 p_subpic, p_subpic->i_status );
339 /* Remove reservation flag */
340 p_subpic->i_status = READY_SUBPICTURE;
342 if( p_subpic->i_channel == DEFAULT_CHAN )
344 p_subpic->i_channel = 0xFFFF;
345 spu_Control( p_spu, SPU_CHANNEL_CLEAR, DEFAULT_CHAN );
346 p_subpic->i_channel = DEFAULT_CHAN;
351 * Allocate a subpicture in the spu heap.
353 * This function create a reserved subpicture in the spu heap.
354 * A null pointer is returned if the function fails. This method provides an
355 * already allocated zone of memory in the spu data fields. It needs locking
356 * since several pictures can be created by several producers threads.
357 * \param p_spu the subpicture unit in which to create the subpicture
358 * \return NULL on error, a reserved subpicture otherwise
360 subpicture_t *spu_CreateSubpicture( spu_t *p_spu )
362 int i_subpic; /* subpicture index */
363 subpicture_t * p_subpic = NULL; /* first free subpicture */
366 vlc_mutex_lock( &p_spu->subpicture_lock );
369 * Look for an empty place
372 for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
374 if( p_spu->p_subpicture[i_subpic].i_status == FREE_SUBPICTURE )
376 /* Subpicture is empty and ready for allocation */
377 p_subpic = &p_spu->p_subpicture[i_subpic];
378 p_spu->p_subpicture[i_subpic].i_status = RESERVED_SUBPICTURE;
383 /* If no free subpicture could be found */
384 if( p_subpic == NULL )
386 msg_Err( p_spu, "subpicture heap is full" );
387 vlc_mutex_unlock( &p_spu->subpicture_lock );
391 /* Copy subpicture information, set some default values */
392 memset( p_subpic, 0, sizeof(subpicture_t) );
393 p_subpic->i_status = RESERVED_SUBPICTURE;
394 p_subpic->b_absolute = true;
395 p_subpic->b_pausable = false;
396 p_subpic->b_fade = false;
397 p_subpic->b_subtitle = false;
398 p_subpic->i_alpha = 0xFF;
399 p_subpic->p_region = NULL;
400 p_subpic->pf_render = NULL;
401 p_subpic->pf_destroy = NULL;
402 p_subpic->p_sys = NULL;
403 vlc_mutex_unlock( &p_spu->subpicture_lock );
405 p_subpic->pf_create_region = __spu_CreateRegion;
406 p_subpic->pf_make_region = __spu_MakeRegion;
407 p_subpic->pf_destroy_region = __spu_DestroyRegion;
413 * Remove a subpicture from the heap
415 * This function frees a previously reserved subpicture.
416 * It is meant to be used when the construction of a picture aborted.
417 * This function does not need locking since reserved subpictures are ignored
420 void spu_DestroySubpicture( spu_t *p_spu, subpicture_t *p_subpic )
423 vlc_mutex_lock( &p_spu->subpicture_lock );
425 /* There can be race conditions so we need to check the status */
426 if( p_subpic->i_status == FREE_SUBPICTURE )
428 vlc_mutex_unlock( &p_spu->subpicture_lock );
432 /* Check if status is valid */
433 if( ( p_subpic->i_status != RESERVED_SUBPICTURE )
434 && ( p_subpic->i_status != READY_SUBPICTURE ) )
436 msg_Err( p_spu, "subpicture %p has invalid status %d",
437 p_subpic, p_subpic->i_status );
440 while( p_subpic->p_region )
442 subpicture_region_t *p_region = p_subpic->p_region;
443 p_subpic->p_region = p_region->p_next;
444 spu_DestroyRegion( p_spu, p_region );
447 if( p_subpic->pf_destroy )
449 p_subpic->pf_destroy( p_subpic );
452 p_subpic->i_status = FREE_SUBPICTURE;
454 vlc_mutex_unlock( &p_spu->subpicture_lock );
457 /*****************************************************************************
458 * spu_RenderSubpictures: render a subpicture list
459 *****************************************************************************
460 * This function renders all sub picture units in the list.
461 *****************************************************************************/
462 static void SpuRenderCreateBlend( spu_t *p_spu, vlc_fourcc_t i_chroma, int i_aspect )
466 assert( !p_spu->p_blend );
469 p_blend = vlc_custom_create( p_spu, sizeof(filter_t),
470 VLC_OBJECT_GENERIC, "blend" );
474 es_format_Init( &p_blend->fmt_in, VIDEO_ES, 0 );
476 es_format_Init( &p_blend->fmt_out, VIDEO_ES, 0 );
477 p_blend->fmt_out.video.i_x_offset = 0;
478 p_blend->fmt_out.video.i_y_offset = 0;
479 p_blend->fmt_out.video.i_chroma = i_chroma;
480 p_blend->fmt_out.video.i_aspect = i_aspect;
482 /* The blend module will be loaded when needed with the real
484 p_blend->p_module = NULL;
487 vlc_object_attach( p_blend, p_spu );
489 static void SpuRenderUpdateBlend( spu_t *p_spu, int i_out_width, int i_out_height, const video_format_t *p_in_fmt )
491 filter_t *p_blend = p_spu->p_blend;
496 if( p_blend->p_module && p_blend->fmt_in.video.i_chroma != p_in_fmt->i_chroma )
498 /* The chroma is not the same, we need to reload the blend module
499 * XXX to match the old behaviour just test !p_blend->fmt_in.video.i_chroma */
500 module_Unneed( p_blend, p_blend->p_module );
501 p_blend->p_module = NULL;
505 p_blend->fmt_in.video = *p_in_fmt;
508 p_blend->fmt_out.video.i_width =
509 p_blend->fmt_out.video.i_visible_width = i_out_width;
510 p_blend->fmt_out.video.i_height =
511 p_blend->fmt_out.video.i_visible_height = i_out_height;
514 if( !p_blend->p_module )
515 p_blend->p_module = module_Need( p_blend, "video blending", 0, 0 );
517 static void SpuRenderCreateAndLoadText( spu_t *p_spu, int i_width, int i_height )
521 assert( !p_spu->p_text );
524 p_text = vlc_custom_create( p_spu, sizeof(filter_t),
525 VLC_OBJECT_GENERIC, "spu text" );
529 es_format_Init( &p_text->fmt_in, VIDEO_ES, 0 );
531 es_format_Init( &p_text->fmt_out, VIDEO_ES, 0 );
532 p_text->fmt_out.video.i_width =
533 p_text->fmt_out.video.i_visible_width = i_width;
534 p_text->fmt_out.video.i_height =
535 p_text->fmt_out.video.i_visible_height = i_height;
537 p_text->pf_sub_buffer_new = spu_new_buffer;
538 p_text->pf_sub_buffer_del = spu_del_buffer;
540 vlc_object_attach( p_text, p_spu );
542 /* FIXME TOCHECK shouldn't module_Need( , , psz_modulename, false ) do the
543 * same than these 2 calls ? */
544 char *psz_modulename = var_CreateGetString( p_spu, "text-renderer" );
545 if( psz_modulename && *psz_modulename )
547 p_text->p_module = module_Need( p_text, "text renderer",
548 psz_modulename, true );
550 free( psz_modulename );
552 if( !p_text->p_module )
553 p_text->p_module = module_Need( p_text, "text renderer", NULL, false );
556 static filter_t *CreateAndLoadScale( vlc_object_t *p_obj, vlc_fourcc_t i_chroma )
560 p_scale = vlc_custom_create( p_obj, sizeof(filter_t),
561 VLC_OBJECT_GENERIC, "scale" );
565 es_format_Init( &p_scale->fmt_in, VIDEO_ES, 0 );
566 p_scale->fmt_in.video.i_chroma = i_chroma;
567 p_scale->fmt_in.video.i_width =
568 p_scale->fmt_in.video.i_height = 32;
570 es_format_Init( &p_scale->fmt_out, VIDEO_ES, 0 );
571 p_scale->fmt_out.video.i_chroma = i_chroma;
572 p_scale->fmt_out.video.i_width =
573 p_scale->fmt_out.video.i_height = 16;
575 p_scale->pf_vout_buffer_new = spu_new_video_buffer;
576 p_scale->pf_vout_buffer_del = spu_del_video_buffer;
578 vlc_object_attach( p_scale, p_obj );
579 p_scale->p_module = module_Need( p_scale, "video filter2", 0, 0 );
584 static void SpuRenderCreateAndLoadScale( spu_t *p_spu )
586 /* FIXME: We'll also be using it for YUVA and RGBA blending ... */
588 assert( !p_spu->p_scale );
589 assert( !p_spu->p_scale_yuvp );
590 p_spu->p_scale = CreateAndLoadScale( VLC_OBJECT(p_spu), VLC_FOURCC('Y','U','V','A') );
591 p_spu->p_scale_yuvp = p_spu->p_scale_yuvp = CreateAndLoadScale( VLC_OBJECT(p_spu), VLC_FOURCC('Y','U','V','P') );
594 static void SpuRenderText( spu_t *p_spu, bool *pb_rerender_text,
595 subpicture_t *p_subpic, subpicture_region_t *p_region, int i_min_scale_ratio )
597 assert( p_region->fmt.i_chroma == VLC_FOURCC('T','E','X','T') );
599 if( !p_spu->p_text || !p_spu->p_text->p_module )
602 /* Setup 3 variables which can be used to render
603 * time-dependent text (and effects). The first indicates
604 * the total amount of time the text will be on screen,
605 * the second the amount of time it has already been on
606 * screen (can be a negative value as text is layed out
607 * before it is rendered) and the third is a feedback
608 * variable from the renderer - if the renderer sets it
609 * then this particular text is time-dependent, eg. the
610 * visual progress bar inside the text in karaoke and the
611 * text needs to be rendered multiple times in order for
612 * the effect to work - we therefore need to return the
613 * region to its original state at the end of the loop,
614 * instead of leaving it in YUVA or YUVP.
615 * Any renderer which is unaware of how to render
616 * time-dependent text can happily ignore the variables
617 * and render the text the same as usual - it should at
618 * least show up on screen, but the effect won't change
619 * the text over time.
622 /* FIXME why these variables are recreated every time and not
623 * when text renderer module was created ? */
624 var_Create( p_spu->p_text, "spu-duration", VLC_VAR_TIME );
625 var_Create( p_spu->p_text, "spu-elapsed", VLC_VAR_TIME );
626 var_Create( p_spu->p_text, "text-rerender", VLC_VAR_BOOL );
627 var_Create( p_spu->p_text, "scale", VLC_VAR_INTEGER );
629 var_SetTime( p_spu->p_text, "spu-duration", p_subpic->i_stop - p_subpic->i_start );
630 var_SetTime( p_spu->p_text, "spu-elapsed", mdate() - p_subpic->i_start );
631 var_SetBool( p_spu->p_text, "text-rerender", false );
632 var_SetInteger( p_spu->p_text, "scale", i_min_scale_ratio );
634 if( p_spu->p_text->pf_render_html && p_region->psz_html )
636 p_spu->p_text->pf_render_html( p_spu->p_text,
637 p_region, p_region );
639 else if( p_spu->p_text->pf_render_text )
641 p_spu->p_text->pf_render_text( p_spu->p_text,
642 p_region, p_region );
644 *pb_rerender_text = var_GetBool( p_spu->p_text, "text-rerender" );
646 var_Destroy( p_spu->p_text, "spu-duration" );
647 var_Destroy( p_spu->p_text, "spu-elapsed" );
648 var_Destroy( p_spu->p_text, "text-rerender" );
649 var_Destroy( p_spu->p_text, "scale" );
652 p_region->i_align |= SUBPICTURE_RENDERED;
655 static void SpuRenderRegion( spu_t *p_spu,
656 picture_t *p_pic_dst,
657 subpicture_t *p_subpic, subpicture_region_t *p_region,
658 const int i_scale_width_orig, const int i_scale_height_orig,
659 const int pi_subpic_x[SCALE_SIZE],
660 const int pi_scale_width[SCALE_SIZE],
661 const int pi_scale_height[SCALE_SIZE],
662 const video_format_t *p_fmt )
664 video_format_t fmt_original;
665 bool b_rerender_text;
666 bool b_restore_format = false;
675 vlc_assert_locked( &p_spu->subpicture_lock );
677 fmt_original = p_region->fmt;
678 b_rerender_text = false;
679 if( p_region->fmt.i_chroma == VLC_FOURCC('T','E','X','T') )
681 SpuRenderText( p_spu, &b_rerender_text, p_subpic, p_region, __MIN(i_scale_width_orig, i_scale_height_orig) );
682 b_restore_format = b_rerender_text;
684 /* Check if the rendering has failed ... */
685 if( p_region->fmt.i_chroma == VLC_FOURCC('T','E','X','T') )
689 if( p_region->i_align & SUBPICTURE_RENDERED )
691 /* We are using a region which come from rendered text */
692 i_scale_idx = SCALE_TEXT;
693 i_inv_scale_x = i_scale_width_orig;
694 i_inv_scale_y = i_scale_height_orig;
698 i_scale_idx = SCALE_DEFAULT;
699 i_inv_scale_x = 1000;
700 i_inv_scale_y = 1000;
703 i_x_offset = (p_region->i_x + pi_subpic_x[ i_scale_idx ]) * i_inv_scale_x / 1000;
704 i_y_offset = (p_region->i_y + p_subpic->i_y) * i_inv_scale_y / 1000;
706 /* Force palette if requested
707 * FIXME b_force_palette and b_force_crop are applied to all subpictures using palette
708 * instead of only the right one (being the dvd spu).
710 const bool b_using_palette = p_region->fmt.i_chroma == VLC_FOURCC('Y','U','V','P');
711 const bool b_force_palette = b_using_palette && p_spu->b_force_palette;
712 const bool b_force_crop = b_force_palette && p_spu->b_force_crop;
714 if( b_force_palette )
716 /* It looks so wrong I won't comment
717 * p_palette->palette is [256][4] with a int i_entries
718 * p_spu->palette is [4][4]
720 p_region->fmt.p_palette->i_entries = 4;
721 memcpy( p_region->fmt.p_palette->palette, p_spu->palette, 4*sizeof(uint32_t) );
724 if( b_using_palette )
725 p_scale = p_spu->p_scale_yuvp;
727 p_scale = p_spu->p_scale;
730 ( ( pi_scale_width[i_scale_idx] > 0 && pi_scale_width[i_scale_idx] != 1000 ) ||
731 ( pi_scale_height[i_scale_idx] > 0 && pi_scale_height[i_scale_idx] != 1000 ) ||
732 ( b_force_palette ) ) )
734 const unsigned i_dst_width = p_region->fmt.i_width * pi_scale_width[i_scale_idx] / 1000;
735 const unsigned i_dst_height = p_region->fmt.i_height * pi_scale_height[i_scale_idx] / 1000;
737 /* Destroy if cache is unusable */
738 if( p_region->p_cache )
740 if( p_region->p_cache->fmt.i_width != i_dst_width ||
741 p_region->p_cache->fmt.i_height != i_dst_height ||
744 p_subpic->pf_destroy_region( VLC_OBJECT(p_spu),
746 p_region->p_cache = NULL;
750 /* Scale if needed into cache */
751 if( !p_region->p_cache )
755 p_scale->fmt_in.video = p_region->fmt;
756 p_scale->fmt_out.video = p_region->fmt;
759 p_subpic->pf_create_region( VLC_OBJECT(p_spu),
760 &p_scale->fmt_out.video );
761 p_region->p_cache->p_next = p_region->p_next;
763 if( p_scale->fmt_out.video.p_palette )
764 *p_scale->fmt_out.video.p_palette =
765 *p_region->fmt.p_palette;
767 vout_CopyPicture( p_spu, &p_region->p_cache->picture,
768 &p_region->picture );
770 p_scale->fmt_out.video.i_width = i_dst_width;
771 p_scale->fmt_out.video.i_height = i_dst_height;
773 p_scale->fmt_out.video.i_visible_width =
774 p_region->fmt.i_visible_width * pi_scale_width[ i_scale_idx ] / 1000;
775 p_scale->fmt_out.video.i_visible_height =
776 p_region->fmt.i_visible_height * pi_scale_height[ i_scale_idx ] / 1000;
778 p_region->p_cache->fmt = p_scale->fmt_out.video;
779 p_region->p_cache->i_x = p_region->i_x * pi_scale_width[ i_scale_idx ] / 1000;
780 p_region->p_cache->i_y = p_region->i_y * pi_scale_height[ i_scale_idx ] / 1000;
781 p_region->p_cache->i_align = p_region->i_align;
782 p_region->p_cache->i_alpha = p_region->i_alpha;
785 if( p_scale->p_module )
786 p_pic = p_scale->pf_video_filter( p_scale, &p_region->p_cache->picture );
788 msg_Err( p_spu, "scaling failed (module not loaded)" );
792 p_region->p_cache->picture = *p_pic;
797 p_subpic->pf_destroy_region( VLC_OBJECT(p_spu),
799 p_region->p_cache = NULL;
803 /* And use the scaled picture */
804 if( p_region->p_cache )
806 p_region = p_region->p_cache;
807 fmt_original = p_region->fmt;
811 if( p_region->i_align & SUBPICTURE_ALIGN_BOTTOM )
813 i_y_offset = p_fmt->i_height - p_region->fmt.i_height -
814 (p_subpic->i_y + p_region->i_y) * i_inv_scale_y / 1000;
816 else if ( !(p_region->i_align & SUBPICTURE_ALIGN_TOP) )
818 i_y_offset = p_fmt->i_height / 2 - p_region->fmt.i_height / 2;
821 if( p_region->i_align & SUBPICTURE_ALIGN_RIGHT )
823 i_x_offset = p_fmt->i_width - p_region->fmt.i_width -
824 (pi_subpic_x[ i_scale_idx ] + p_region->i_x)
825 * i_inv_scale_x / 1000;
827 else if ( !(p_region->i_align & SUBPICTURE_ALIGN_LEFT) )
829 i_x_offset = p_fmt->i_width / 2 - p_region->fmt.i_width / 2;
832 if( p_subpic->b_absolute )
834 i_x_offset = (p_region->i_x +
835 pi_subpic_x[ i_scale_idx ] *
836 pi_scale_width[ i_scale_idx ] / 1000)
837 * i_inv_scale_x / 1000;
838 i_y_offset = (p_region->i_y +
839 p_subpic->i_y * pi_scale_height[ i_scale_idx ] / 1000)
840 * i_inv_scale_y / 1000;
844 i_x_offset = __MAX( i_x_offset, 0 );
845 i_y_offset = __MAX( i_y_offset, 0 );
847 if( p_spu->i_margin != 0 && !b_force_crop )
850 int i_low = (i_y_offset - p_spu->i_margin) * i_inv_scale_y / 1000;
851 int i_high = i_low + p_region->fmt.i_height;
853 /* crop extra margin to keep within bounds */
856 if( i_high > (int)p_fmt->i_height )
857 i_diff = i_high - p_fmt->i_height;
858 i_y_offset -= ( p_spu->i_margin * i_inv_scale_y / 1000 + i_diff );
861 /* Force cropping if requested */
864 video_format_t *p_fmt = &p_region->fmt;
865 int i_crop_x = p_spu->i_crop_x * pi_scale_width[ i_scale_idx ] / 1000
866 * i_inv_scale_x / 1000;
867 int i_crop_y = p_spu->i_crop_y * pi_scale_height[ i_scale_idx ] / 1000
868 * i_inv_scale_y / 1000;
869 int i_crop_width = p_spu->i_crop_width * pi_scale_width[ i_scale_idx ] / 1000
870 * i_inv_scale_x / 1000;
871 int i_crop_height = p_spu->i_crop_height * pi_scale_height[ i_scale_idx ] / 1000
872 * i_inv_scale_y / 1000;
874 /* Find the intersection */
875 if( i_crop_x + i_crop_width <= i_x_offset ||
876 i_x_offset + (int)p_fmt->i_visible_width < i_crop_x ||
877 i_crop_y + i_crop_height <= i_y_offset ||
878 i_y_offset + (int)p_fmt->i_visible_height < i_crop_y )
880 /* No intersection */
881 p_fmt->i_visible_width = p_fmt->i_visible_height = 0;
885 int i_x, i_y, i_x_end, i_y_end;
886 i_x = __MAX( i_crop_x, i_x_offset );
887 i_y = __MAX( i_crop_y, i_y_offset );
888 i_x_end = __MIN( i_crop_x + i_crop_width,
889 i_x_offset + (int)p_fmt->i_visible_width );
890 i_y_end = __MIN( i_crop_y + i_crop_height,
891 i_y_offset + (int)p_fmt->i_visible_height );
893 p_fmt->i_x_offset = i_x - i_x_offset;
894 p_fmt->i_y_offset = i_y - i_y_offset;
895 p_fmt->i_visible_width = i_x_end - i_x;
896 p_fmt->i_visible_height = i_y_end - i_y;
901 b_restore_format = true;
904 i_x_offset = __MAX( i_x_offset, 0 );
905 i_y_offset = __MAX( i_y_offset, 0 );
907 /* Compute alpha blend value */
909 if( p_subpic->b_fade )
911 mtime_t i_fade_start = ( p_subpic->i_stop +
912 p_subpic->i_start ) / 2;
913 mtime_t i_now = mdate();
914 if( i_now >= i_fade_start && p_subpic->i_stop > i_fade_start )
916 i_fade_alpha = 255 * ( p_subpic->i_stop - i_now ) /
917 ( p_subpic->i_stop - i_fade_start );
921 /* Update the blender */
922 SpuRenderUpdateBlend( p_spu, p_fmt->i_width, p_fmt->i_height, &p_region->fmt );
924 if( p_spu->p_blend->p_module )
926 p_spu->p_blend->pf_video_blend( p_spu->p_blend, p_pic_dst,
927 &p_region->picture, i_x_offset, i_y_offset,
928 i_fade_alpha * p_subpic->i_alpha * p_region->i_alpha / 65025 );
932 msg_Err( p_spu, "blending %4.4s to %4.4s failed",
933 (char *)&p_spu->p_blend->fmt_out.video.i_chroma,
934 (char *)&p_spu->p_blend->fmt_out.video.i_chroma );
938 if( b_rerender_text )
940 /* Some forms of subtitles need to be re-rendered more than
941 * once, eg. karaoke. We therefore restore the region to its
942 * pre-rendered state, so the next time through everything is
945 p_region->picture.pf_release( &p_region->picture );
946 memset( &p_region->picture, 0, sizeof( picture_t ) );
947 p_region->i_align &= ~SUBPICTURE_RENDERED;
949 if( b_restore_format )
950 p_region->fmt = fmt_original;
953 void spu_RenderSubpictures( spu_t *p_spu, video_format_t *p_fmt,
954 picture_t *p_pic_dst,
955 subpicture_t *p_subpic,
956 int i_scale_width_orig, int i_scale_height_orig )
958 int i_source_video_width;
959 int i_source_video_height;
960 subpicture_t *p_subpic_v;
963 vlc_mutex_lock( &p_spu->subpicture_lock );
965 for( p_subpic_v = p_subpic;
966 p_subpic_v != NULL && p_subpic_v->i_status != FREE_SUBPICTURE;
967 p_subpic_v = p_subpic_v->p_next )
969 if( p_subpic_v->pf_pre_render )
970 p_subpic_v->pf_pre_render( p_fmt, p_spu, p_subpic_v );
973 if( i_scale_width_orig <= 0 )
974 i_scale_width_orig = 1000;
975 if( i_scale_height_orig <= 0 )
976 i_scale_height_orig = 1000;
978 i_source_video_width = p_fmt->i_width * 1000 / i_scale_width_orig;
979 i_source_video_height = p_fmt->i_height * 1000 / i_scale_height_orig;
981 /* Check i_status again to make sure spudec hasn't destroyed the subpic */
982 for( ; ( p_subpic != NULL ) && ( p_subpic->i_status != FREE_SUBPICTURE ); p_subpic = p_subpic->p_next )
984 subpicture_region_t *p_region;
985 int pi_scale_width[ SCALE_SIZE ];
986 int pi_scale_height[ SCALE_SIZE ];
987 int pi_subpic_x[ SCALE_SIZE ];
990 /* If the source video and subtitles stream agree on the size of
991 * the video then disregard all further references to the subtitle
994 if( ( i_source_video_height == p_subpic->i_original_picture_height ) &&
995 ( i_source_video_width == p_subpic->i_original_picture_width ) )
997 /* FIXME this looks wrong */
998 p_subpic->i_original_picture_height = 0;
999 p_subpic->i_original_picture_width = 0;
1002 for( k = 0; k < SCALE_SIZE ; k++ )
1003 pi_subpic_x[ k ] = p_subpic->i_x;
1005 if( p_subpic->pf_update_regions )
1007 /* TODO do not reverse the scaling that was done before calling
1008 * spu_RenderSubpictures, just pass it along (or do it inside
1009 * spu_RenderSubpictures) */
1010 video_format_t fmt_org = *p_fmt;
1012 fmt_org.i_visible_width = i_source_video_width;
1014 fmt_org.i_visible_height = i_source_video_height;
1016 p_subpic->pf_update_regions( &fmt_org, p_spu, p_subpic, mdate() );
1020 p_region = p_subpic->p_region;
1024 /* Create the blending module */
1025 if( !p_spu->p_blend )
1026 SpuRenderCreateBlend( p_spu, p_fmt->i_chroma, p_fmt->i_aspect );
1028 /* Load the text rendering module; it is possible there is a
1029 * text region somewhere in the subpicture other than the first
1030 * element in the region list, so just load it anyway as we'll
1031 * probably want it sooner or later. */
1032 if( !p_spu->p_text )
1033 SpuRenderCreateAndLoadText( p_spu, p_fmt->i_width, p_fmt->i_height );
1037 subpicture_region_t *p_text_region = p_subpic->p_region;
1039 /* Only overwrite the size fields if the region is still in
1040 * pre-rendered TEXT format. We have to traverse the subregion
1041 * list because if more than one subregion is present, the text
1042 * region isn't guarentteed to be the first in the list, and
1043 * only text regions use this flag. All of this effort assists
1044 * with the rescaling of text that has been rendered at native
1045 * resolution, rather than video resolution.
1047 while( p_text_region &&
1048 p_text_region->fmt.i_chroma != VLC_FOURCC('T','E','X','T') )
1050 p_text_region = p_text_region->p_next;
1053 if( p_text_region &&
1054 ( ( p_text_region->i_align & SUBPICTURE_RENDERED ) == 0 ) )
1056 if( p_subpic->i_original_picture_height > 0 &&
1057 p_subpic->i_original_picture_width > 0 )
1059 p_spu->p_text->fmt_out.video.i_width =
1060 p_spu->p_text->fmt_out.video.i_visible_width =
1061 p_subpic->i_original_picture_width;
1062 p_spu->p_text->fmt_out.video.i_height =
1063 p_spu->p_text->fmt_out.video.i_visible_height =
1064 p_subpic->i_original_picture_height;
1068 p_spu->p_text->fmt_out.video.i_width =
1069 p_spu->p_text->fmt_out.video.i_visible_width =
1071 p_spu->p_text->fmt_out.video.i_height =
1072 p_spu->p_text->fmt_out.video.i_visible_height =
1078 * scale[] allows to pass from rendered size (by text module) to video output size */
1079 pi_scale_width[SCALE_TEXT] = p_fmt->i_width * 1000 /
1080 p_spu->p_text->fmt_out.video.i_width;
1081 pi_scale_height[SCALE_TEXT]= p_fmt->i_height * 1000 /
1082 p_spu->p_text->fmt_out.video.i_height;
1086 /* Just set a value to avoid using invalid memory while looping over the array */
1087 pi_scale_width[SCALE_TEXT] =
1088 pi_scale_height[SCALE_TEXT]= 1000;
1092 * scale[] allows to pass from native (either video or original) size to output size */
1094 if( p_subpic->i_original_picture_height > 0 &&
1095 p_subpic->i_original_picture_width > 0 )
1097 pi_scale_width[SCALE_DEFAULT] = p_fmt->i_width * 1000 / p_subpic->i_original_picture_width;
1098 pi_scale_height[SCALE_DEFAULT] = p_fmt->i_height * 1000 / p_subpic->i_original_picture_height;
1102 pi_scale_width[ SCALE_DEFAULT ] = i_scale_width_orig;
1103 pi_scale_height[ SCALE_DEFAULT ] = i_scale_height_orig;
1106 for( k = 0; k < SCALE_SIZE ; k++ )
1108 /* Case of both width and height being specified has been dealt
1109 * with above by instead rendering to an output pane of the
1110 * explicit dimensions specified - we don't need to scale it.
1112 if( p_subpic->i_original_picture_height > 0 &&
1113 p_subpic->i_original_picture_width <= 0 )
1115 pi_scale_height[ k ] = pi_scale_height[ k ] * i_source_video_height /
1116 p_subpic->i_original_picture_height;
1117 pi_scale_width[ k ] = pi_scale_width[ k ] * i_source_video_height /
1118 p_subpic->i_original_picture_height;
1122 /* Set default subpicture aspect ratio */
1123 if( !p_region->fmt.i_sar_num || !p_region->fmt.i_sar_den )
1125 if( p_region->fmt.i_aspect != 0 )
1127 p_region->fmt.i_sar_den = p_region->fmt.i_aspect;
1128 p_region->fmt.i_sar_num = VOUT_ASPECT_FACTOR;
1132 p_region->fmt.i_sar_den = p_fmt->i_sar_den;
1133 p_region->fmt.i_sar_num = p_fmt->i_sar_num;
1137 /* Take care of the aspect ratio */
1138 if( ( p_region->fmt.i_sar_num * p_fmt->i_sar_den ) !=
1139 ( p_region->fmt.i_sar_den * p_fmt->i_sar_num ) )
1141 for( k = 0; k < SCALE_SIZE; k++ )
1143 pi_scale_width[k] = pi_scale_width[ k ] *
1144 (int64_t)p_region->fmt.i_sar_num * p_fmt->i_sar_den /
1145 p_region->fmt.i_sar_den / p_fmt->i_sar_num;
1147 pi_subpic_x[k] = p_subpic->i_x * pi_scale_width[ k ] / 1000;
1151 /* Load the scaling module when needed */
1152 if( !p_spu->p_scale )
1154 bool b_scale_used = false;
1156 for( k = 0; k < SCALE_SIZE; k++ )
1158 const int i_scale_w = pi_scale_width[k];
1159 const int i_scale_h = pi_scale_height[k];
1160 if( ( i_scale_w > 0 && i_scale_w != 1000 ) || ( i_scale_h > 0 && i_scale_h != 1000 ) )
1161 b_scale_used = true;
1165 SpuRenderCreateAndLoadScale( p_spu );
1168 for( ; p_region != NULL; p_region = p_region->p_next )
1169 SpuRenderRegion( p_spu, p_pic_dst,
1170 p_subpic, p_region, i_scale_width_orig, i_scale_height_orig,
1171 pi_subpic_x, pi_scale_width, pi_scale_height,
1175 vlc_mutex_unlock( &p_spu->subpicture_lock );
1178 /*****************************************************************************
1179 * spu_SortSubpictures: find the subpictures to display
1180 *****************************************************************************
1181 * This function parses all subpictures and decides which ones need to be
1182 * displayed. This operation does not need lock, since only READY_SUBPICTURE
1183 * are handled. If no picture has been selected, display_date will depend on
1185 * We also check for ephemer DVD subpictures (subpictures that have
1186 * to be removed if a newer one is available), which makes it a lot
1187 * more difficult to guess if a subpicture has to be rendered or not.
1188 *****************************************************************************/
1189 subpicture_t *spu_SortSubpictures( spu_t *p_spu, mtime_t display_date,
1192 int i_index, i_channel;
1193 subpicture_t *p_subpic = NULL;
1194 subpicture_t *p_ephemer;
1195 mtime_t ephemer_date;
1197 /* Run subpicture filters */
1198 filter_chain_SubFilter( p_spu->p_chain, display_date );
1200 /* We get an easily parsable chained list of subpictures which
1201 * ends with NULL since p_subpic was initialized to NULL. */
1202 for( i_channel = 0; i_channel < p_spu->i_channel; i_channel++ )
1207 for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
1209 if( p_spu->p_subpicture[i_index].i_channel != i_channel ||
1210 p_spu->p_subpicture[i_index].i_status != READY_SUBPICTURE )
1215 display_date < p_spu->p_subpicture[i_index].i_start )
1217 /* Too early, come back next monday */
1221 if( p_spu->p_subpicture[i_index].i_start > ephemer_date )
1222 ephemer_date = p_spu->p_subpicture[i_index].i_start;
1224 if( display_date > p_spu->p_subpicture[i_index].i_stop &&
1225 ( !p_spu->p_subpicture[i_index].b_ephemer ||
1226 p_spu->p_subpicture[i_index].i_stop >
1227 p_spu->p_subpicture[i_index].i_start ) &&
1228 !( p_spu->p_subpicture[i_index].b_pausable &&
1231 /* Too late, destroy the subpic */
1232 spu_DestroySubpicture( p_spu, &p_spu->p_subpicture[i_index] );
1236 /* If this is an ephemer subpic, add it to our list */
1237 if( p_spu->p_subpicture[i_index].b_ephemer )
1239 p_spu->p_subpicture[i_index].p_next = p_ephemer;
1240 p_ephemer = &p_spu->p_subpicture[i_index];
1245 p_spu->p_subpicture[i_index].p_next = p_subpic;
1246 p_subpic = &p_spu->p_subpicture[i_index];
1249 /* If we found ephemer subpictures, check if they have to be
1250 * displayed or destroyed */
1251 while( p_ephemer != NULL )
1253 subpicture_t *p_tmp = p_ephemer;
1254 p_ephemer = p_ephemer->p_next;
1256 if( p_tmp->i_start < ephemer_date )
1258 /* Ephemer subpicture has lived too long */
1259 spu_DestroySubpicture( p_spu, p_tmp );
1263 /* Ephemer subpicture can still live a bit */
1264 p_tmp->p_next = p_subpic;
1273 /*****************************************************************************
1274 * SpuClearChannel: clear an spu channel
1275 *****************************************************************************
1276 * This function destroys the subpictures which belong to the spu channel
1277 * corresponding to i_channel_id.
1278 *****************************************************************************/
1279 static void SpuClearChannel( spu_t *p_spu, int i_channel, bool b_locked )
1281 int i_subpic; /* subpicture index */
1282 subpicture_t *p_subpic = NULL; /* first free subpicture */
1285 vlc_mutex_lock( &p_spu->subpicture_lock );
1287 for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
1289 p_subpic = &p_spu->p_subpicture[i_subpic];
1290 if( p_subpic->i_status == FREE_SUBPICTURE
1291 || ( p_subpic->i_status != RESERVED_SUBPICTURE
1292 && p_subpic->i_status != READY_SUBPICTURE ) )
1297 if( p_subpic->i_channel == i_channel )
1299 while( p_subpic->p_region )
1301 subpicture_region_t *p_region = p_subpic->p_region;
1302 p_subpic->p_region = p_region->p_next;
1303 spu_DestroyRegion( p_spu, p_region );
1306 if( p_subpic->pf_destroy ) p_subpic->pf_destroy( p_subpic );
1307 p_subpic->i_status = FREE_SUBPICTURE;
1312 vlc_mutex_unlock( &p_spu->subpicture_lock );
1315 /*****************************************************************************
1316 * spu_ControlDefault: default methods for the subpicture unit control.
1317 *****************************************************************************/
1318 static int spu_vaControlDefault( spu_t *p_spu, int i_query, va_list args )
1324 case SPU_CHANNEL_REGISTER:
1325 pi = (int *)va_arg( args, int * );
1326 vlc_mutex_lock( &p_spu->subpicture_lock );
1328 *pi = p_spu->i_channel++;
1329 vlc_mutex_unlock( &p_spu->subpicture_lock );
1332 case SPU_CHANNEL_CLEAR:
1333 i = (int)va_arg( args, int );
1334 SpuClearChannel( p_spu, i, false );
1338 msg_Dbg( p_spu, "control query not supported" );
1339 return VLC_EGENERIC;
1345 /*****************************************************************************
1346 * Object variables callbacks
1347 *****************************************************************************/
1349 /*****************************************************************************
1350 * UpdateSPU: update subpicture settings
1351 *****************************************************************************
1352 * This function is called from CropCallback and at initialization time, to
1353 * retrieve crop information from the input.
1354 *****************************************************************************/
1355 static void UpdateSPU( spu_t *p_spu, vlc_object_t *p_object )
1359 vlc_mutex_lock( &p_spu->subpicture_lock );
1361 p_spu->b_force_palette = false;
1362 p_spu->b_force_crop = false;
1364 if( var_Get( p_object, "highlight", &val ) || !val.b_bool )
1366 vlc_mutex_unlock( &p_spu->subpicture_lock );
1370 p_spu->b_force_crop = true;
1371 var_Get( p_object, "x-start", &val );
1372 p_spu->i_crop_x = val.i_int;
1373 var_Get( p_object, "y-start", &val );
1374 p_spu->i_crop_y = val.i_int;
1375 var_Get( p_object, "x-end", &val );
1376 p_spu->i_crop_width = val.i_int - p_spu->i_crop_x;
1377 var_Get( p_object, "y-end", &val );
1378 p_spu->i_crop_height = val.i_int - p_spu->i_crop_y;
1380 if( var_Get( p_object, "menu-palette", &val ) == VLC_SUCCESS )
1382 memcpy( p_spu->palette, val.p_address, 16 );
1383 p_spu->b_force_palette = true;
1385 vlc_mutex_unlock( &p_spu->subpicture_lock );
1387 msg_Dbg( p_object, "crop: %i,%i,%i,%i, palette forced: %i",
1388 p_spu->i_crop_x, p_spu->i_crop_y,
1389 p_spu->i_crop_width, p_spu->i_crop_height,
1390 p_spu->b_force_palette );
1393 /*****************************************************************************
1394 * CropCallback: called when the highlight properties are changed
1395 *****************************************************************************
1396 * This callback is called from the input thread when we need cropping
1397 *****************************************************************************/
1398 static int CropCallback( vlc_object_t *p_object, char const *psz_var,
1399 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1401 (void)psz_var; (void)oldval; (void)newval;
1402 UpdateSPU( (spu_t *)p_data, p_object );
1406 /*****************************************************************************
1407 * Buffers allocation callbacks for the filters
1408 *****************************************************************************/
1409 static subpicture_t *sub_new_buffer( filter_t *p_filter )
1411 filter_owner_sys_t *p_sys = p_filter->p_owner;
1412 subpicture_t *p_subpicture = spu_CreateSubpicture( p_sys->p_spu );
1413 if( p_subpicture ) p_subpicture->i_channel = p_sys->i_channel;
1414 return p_subpicture;
1417 static void sub_del_buffer( filter_t *p_filter, subpicture_t *p_subpic )
1419 filter_owner_sys_t *p_sys = p_filter->p_owner;
1420 spu_DestroySubpicture( p_sys->p_spu, p_subpic );
1423 static subpicture_t *spu_new_buffer( filter_t *p_filter )
1426 subpicture_t *p_subpic = (subpicture_t *)malloc(sizeof(subpicture_t));
1427 if( !p_subpic ) return NULL;
1428 memset( p_subpic, 0, sizeof(subpicture_t) );
1429 p_subpic->b_absolute = true;
1431 p_subpic->pf_create_region = __spu_CreateRegion;
1432 p_subpic->pf_make_region = __spu_MakeRegion;
1433 p_subpic->pf_destroy_region = __spu_DestroyRegion;
1438 static void spu_del_buffer( filter_t *p_filter, subpicture_t *p_subpic )
1440 while( p_subpic->p_region )
1442 subpicture_region_t *p_region = p_subpic->p_region;
1443 p_subpic->p_region = p_region->p_next;
1444 p_subpic->pf_destroy_region( VLC_OBJECT(p_filter), p_region );
1450 static picture_t *spu_new_video_buffer( filter_t *p_filter )
1452 picture_t *p_picture = malloc( sizeof(picture_t) );
1453 if( !p_picture ) return NULL;
1454 if( vout_AllocatePicture( p_filter, p_picture,
1455 p_filter->fmt_out.video.i_chroma,
1456 p_filter->fmt_out.video.i_width,
1457 p_filter->fmt_out.video.i_height,
1458 p_filter->fmt_out.video.i_aspect )
1465 p_picture->pf_release = RegionPictureRelease;
1470 static void spu_del_video_buffer( filter_t *p_filter, picture_t *p_pic )
1475 free( p_pic->p_data_orig );
1480 static int SubFilterCallback( vlc_object_t *p_object, char const *psz_var,
1481 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1483 VLC_UNUSED(p_object); VLC_UNUSED(oldval);
1484 VLC_UNUSED(newval); VLC_UNUSED(psz_var);
1486 spu_t *p_spu = (spu_t *)p_data;
1487 vlc_mutex_lock( &p_spu->subpicture_lock );
1488 filter_chain_Reset( p_spu->p_chain, NULL, NULL );
1489 spu_ParseChain( p_spu );
1490 vlc_mutex_unlock( &p_spu->subpicture_lock );
1494 static int sub_filter_allocation_init( filter_t *p_filter, void *p_data )
1496 spu_t *p_spu = (spu_t *)p_data;
1498 p_filter->pf_sub_buffer_new = sub_new_buffer;
1499 p_filter->pf_sub_buffer_del = sub_del_buffer;
1501 filter_owner_sys_t *p_sys = malloc( sizeof(filter_owner_sys_t) );
1502 if( !p_sys ) return VLC_EGENERIC;
1504 p_filter->p_owner = p_sys;
1505 spu_Control( p_spu, SPU_CHANNEL_REGISTER, &p_sys->i_channel );
1506 p_sys->p_spu = p_spu;
1511 static void sub_filter_allocation_clear( filter_t *p_filter )
1513 filter_owner_sys_t *p_sys = p_filter->p_owner;
1514 SpuClearChannel( p_sys->p_spu, p_sys->i_channel, true );
1515 free( p_filter->p_owner );