]> git.sesse.net Git - vlc/blob - src/video_output/vout_subpictures.c
Don't scale when original widht/height is zero.
[vlc] / src / video_output / vout_subpictures.c
1 /*****************************************************************************
2  * vout_subpictures.c : subpicture management functions
3  *****************************************************************************
4  * Copyright (C) 2000-2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Vincent Seguin <seguin@via.ecp.fr>
8  *          Samuel Hocevar <sam@zoy.org>
9  *          Gildas Bazin <gbazin@videolan.org>
10  *
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.
15  *
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.
20  *
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  *****************************************************************************/
25
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #include <stdlib.h>                                                /* free() */
30 #include <stdio.h>                                              /* sprintf() */
31 #include <string.h>                                            /* strerror() */
32
33 #include <vlc/vlc.h>
34 #include <vlc_vout.h>
35 #include <vlc_block.h>
36 #include <vlc_filter.h>
37 #include <vlc_osd.h>
38
39 /*****************************************************************************
40  * Local prototypes
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 * );
45
46 static int spu_vaControlDefault( spu_t *, int, va_list );
47
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 * );
54
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 * );
59
60 struct filter_owner_sys_t
61 {
62     spu_t *p_spu;
63     int i_channel;
64 };
65
66 /**
67  * Creates the subpicture unit
68  *
69  * \param p_this the parent object which creates the subpicture unit
70  */
71 spu_t *__spu_Create( vlc_object_t *p_this )
72 {
73     int i_index;
74     spu_t *p_spu = vlc_object_create( p_this, VLC_OBJECT_SPU );
75
76     for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++)
77     {
78         p_spu->p_subpicture[i_index].i_status = FREE_SUBPICTURE;
79     }
80
81     p_spu->p_blend = NULL;
82     p_spu->p_text = NULL;
83     p_spu->p_scale = NULL;
84     p_spu->i_filter = 0;
85     p_spu->pf_control = spu_vaControlDefault;
86
87     /* Register the default subpicture channel */
88     p_spu->i_channel = 2;
89
90     vlc_mutex_init( p_this, &p_spu->subpicture_lock );
91
92     vlc_object_attach( p_spu, p_this );
93
94     return p_spu;
95 }
96
97 /**
98  * Initialise the subpicture unit
99  *
100  * \param p_spu the subpicture unit object
101  */
102 int spu_Init( spu_t *p_spu )
103 {
104     vlc_value_t val;
105
106     /* If the user requested a sub margin, we force the position. */
107     var_Create( p_spu, "sub-margin", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
108     var_Get( p_spu, "sub-margin", &val );
109     p_spu->i_margin = val.i_int;
110
111     var_Create( p_spu, "sub-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
112     var_AddCallback( p_spu, "sub-filter", SubFilterCallback, p_spu );
113
114     spu_ParseChain( p_spu );
115
116     return VLC_EGENERIC;
117 }
118
119 int spu_ParseChain( spu_t *p_spu )
120 {
121     char *psz_parser;
122     vlc_value_t val;
123     var_Get( p_spu, "sub-filter", &val );
124     psz_parser = val.psz_string;
125
126     while( psz_parser && *psz_parser )
127     {
128         config_chain_t *p_cfg;
129         char *psz_name;
130
131         psz_parser = config_ChainCreate( &psz_name, &p_cfg, psz_parser );
132
133         msg_Dbg( p_spu, "adding sub-filter: %s", psz_name );
134
135         p_spu->pp_filter[p_spu->i_filter] =
136             vlc_object_create( p_spu, VLC_OBJECT_FILTER );
137         vlc_object_attach( p_spu->pp_filter[p_spu->i_filter], p_spu );
138         p_spu->pp_filter[p_spu->i_filter]->pf_sub_buffer_new = sub_new_buffer;
139         p_spu->pp_filter[p_spu->i_filter]->pf_sub_buffer_del = sub_del_buffer;
140         p_spu->pp_filter[p_spu->i_filter]->p_cfg = p_cfg;
141         p_spu->pp_filter[p_spu->i_filter]->p_module =
142             module_Need( p_spu->pp_filter[p_spu->i_filter],
143                          "sub filter", psz_name, VLC_TRUE );
144         if( p_spu->pp_filter[p_spu->i_filter]->p_module )
145         {
146             filter_owner_sys_t *p_sys = malloc( sizeof(filter_owner_sys_t) );
147             p_spu->pp_filter[p_spu->i_filter]->p_owner = p_sys;
148             spu_Control( p_spu, SPU_CHANNEL_REGISTER, &p_sys->i_channel );
149             p_sys->p_spu = p_spu;
150             p_spu->i_filter++;
151         }
152         else
153         {
154             msg_Dbg( p_spu, "no sub filter found" );
155             config_ChainDestroy( p_spu->pp_filter[p_spu->i_filter]->p_cfg );
156             vlc_object_detach( p_spu->pp_filter[p_spu->i_filter] );
157             vlc_object_destroy( p_spu->pp_filter[p_spu->i_filter] );
158         }
159
160         if( p_spu->i_filter >= 10 )
161         {
162             msg_Dbg( p_spu, "can't add anymore filters" );
163         }
164
165         free( psz_name );
166     }
167     if( val.psz_string ) free( val.psz_string );
168
169     return VLC_EGENERIC;
170 }
171
172 /**
173  * Destroy the subpicture unit
174  *
175  * \param p_this the parent object which destroys the subpicture unit
176  */
177 void spu_Destroy( spu_t *p_spu )
178 {
179     int i_index;
180
181     vlc_object_detach( p_spu );
182
183     /* Destroy all remaining subpictures */
184     for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
185     {
186         if( p_spu->p_subpicture[i_index].i_status != FREE_SUBPICTURE )
187         {
188             spu_DestroySubpicture( p_spu, &p_spu->p_subpicture[i_index] );
189         }
190     }
191
192     if( p_spu->p_blend )
193     {
194         if( p_spu->p_blend->p_module )
195             module_Unneed( p_spu->p_blend, p_spu->p_blend->p_module );
196
197         vlc_object_detach( p_spu->p_blend );
198         vlc_object_destroy( p_spu->p_blend );
199     }
200
201     if( p_spu->p_text )
202     {
203         if( p_spu->p_text->p_module )
204             module_Unneed( p_spu->p_text, p_spu->p_text->p_module );
205
206         vlc_object_detach( p_spu->p_text );
207         vlc_object_destroy( p_spu->p_text );
208     }
209
210     if( p_spu->p_scale )
211     {
212         if( p_spu->p_scale->p_module )
213             module_Unneed( p_spu->p_scale, p_spu->p_scale->p_module );
214
215         vlc_object_detach( p_spu->p_scale );
216         vlc_object_destroy( p_spu->p_scale );
217     }
218
219     spu_DeleteChain( p_spu );
220
221     vlc_mutex_destroy( &p_spu->subpicture_lock );
222     vlc_object_destroy( p_spu );
223 }
224
225 static void spu_DeleteChain( spu_t *p_spu )
226 {
227     if( p_spu->i_filter )
228     while( p_spu->i_filter-- )
229     {
230         module_Unneed( p_spu->pp_filter[p_spu->i_filter],
231                        p_spu->pp_filter[p_spu->i_filter]->p_module );
232         free( p_spu->pp_filter[p_spu->i_filter]->p_owner );
233         config_ChainDestroy( p_spu->pp_filter[p_spu->i_filter]->p_cfg );
234         vlc_object_detach( p_spu->pp_filter[p_spu->i_filter] );
235         vlc_object_destroy( p_spu->pp_filter[p_spu->i_filter] );
236     }
237 }
238
239 /**
240  * Attach/Detach the SPU from any input
241  *
242  * \param p_this the object in which to destroy the subpicture unit
243  * \param b_attach to select attach or detach
244  */
245 void spu_Attach( spu_t *p_spu, vlc_object_t *p_this, vlc_bool_t b_attach )
246 {
247     vlc_object_t *p_input;
248
249     p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_PARENT );
250     if( !p_input ) return;
251
252     if( b_attach )
253     {
254         UpdateSPU( p_spu, VLC_OBJECT(p_input) );
255         var_AddCallback( p_input, "highlight", CropCallback, p_spu );
256         vlc_object_release( p_input );
257     }
258     else
259     {
260         /* Delete callback */
261         var_DelCallback( p_input, "highlight", CropCallback, p_spu );
262         vlc_object_release( p_input );
263     }
264 }
265
266 /**
267  * Create a subpicture region
268  *
269  * \param p_this vlc_object_t
270  * \param p_fmt the format that this subpicture region should have
271  */
272 static void RegionPictureRelease( picture_t *p_pic )
273 {
274     if( p_pic->p_data_orig ) free( p_pic->p_data_orig );
275 }
276 subpicture_region_t *__spu_CreateRegion( vlc_object_t *p_this,
277                                          video_format_t *p_fmt )
278 {
279     subpicture_region_t *p_region = malloc( sizeof(subpicture_region_t) );
280     if( !p_region ) return NULL;
281
282     memset( p_region, 0, sizeof(subpicture_region_t) );
283     p_region->p_next = 0;
284     p_region->p_cache = 0;
285     p_region->fmt = *p_fmt;
286     p_region->psz_text = 0;
287     p_region->p_style = NULL;
288
289     if( p_fmt->i_chroma == VLC_FOURCC('Y','U','V','P') )
290         p_fmt->p_palette = p_region->fmt.p_palette =
291             malloc( sizeof(video_palette_t) );
292     else p_fmt->p_palette = p_region->fmt.p_palette = NULL;
293
294     p_region->picture.p_data_orig = NULL;
295
296     if( p_fmt->i_chroma == VLC_FOURCC('T','E','X','T') ) return p_region;
297
298     vout_AllocatePicture( p_this, &p_region->picture, p_fmt->i_chroma,
299                           p_fmt->i_width, p_fmt->i_height, p_fmt->i_aspect );
300
301     if( !p_region->picture.i_planes )
302     {
303         free( p_region );
304         if( p_fmt->p_palette ) free( p_fmt->p_palette );
305         return NULL;
306     }
307
308     p_region->picture.pf_release = RegionPictureRelease;
309
310     return p_region;
311 }
312
313 /**
314  * Make a subpicture region from an existing picture_t
315  *
316  * \param p_this vlc_object_t
317  * \param p_fmt the format that this subpicture region should have
318  * \param p_pic a pointer to the picture creating the region (not freed)
319  */
320 subpicture_region_t *__spu_MakeRegion( vlc_object_t *p_this,
321                                        video_format_t *p_fmt,
322                                        picture_t *p_pic )
323 {
324     subpicture_region_t *p_region = malloc( sizeof(subpicture_region_t) );
325     (void)p_this;
326     memset( p_region, 0, sizeof(subpicture_region_t) );
327     p_region->p_next = 0;
328     p_region->p_cache = 0;
329     p_region->fmt = *p_fmt;
330     p_region->psz_text = 0;
331     p_region->p_style = NULL;
332
333     if( p_fmt->i_chroma == VLC_FOURCC('Y','U','V','P') )
334         p_fmt->p_palette = p_region->fmt.p_palette =
335             malloc( sizeof(video_palette_t) );
336     else p_fmt->p_palette = p_region->fmt.p_palette = NULL;
337
338     memcpy( &p_region->picture, p_pic, sizeof(picture_t) );
339     p_region->picture.pf_release = RegionPictureRelease;
340
341     return p_region;
342 }
343
344 /**
345  * Destroy a subpicture region
346  *
347  * \param p_this vlc_object_t
348  * \param p_region the subpicture region to destroy
349  */
350 void __spu_DestroyRegion( vlc_object_t *p_this, subpicture_region_t *p_region )
351 {
352     if( !p_region ) return;
353     if( p_region->picture.pf_release )
354         p_region->picture.pf_release( &p_region->picture );
355     if( p_region->fmt.p_palette ) free( p_region->fmt.p_palette );
356     if( p_region->p_cache ) __spu_DestroyRegion( p_this, p_region->p_cache );
357
358     if( p_region->psz_text )
359         free( p_region->psz_text );
360     if( p_region->psz_html )
361         free( p_region->psz_html );
362     //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
363     free( p_region );
364 }
365
366 /**
367  * Display a subpicture
368  *
369  * Remove the reservation flag of a subpicture, which will cause it to be
370  * ready for display.
371  * \param p_spu the subpicture unit object
372  * \param p_subpic the subpicture to display
373  */
374 void spu_DisplaySubpicture( spu_t *p_spu, subpicture_t *p_subpic )
375 {
376     /* Check if status is valid */
377     if( p_subpic->i_status != RESERVED_SUBPICTURE )
378     {
379         msg_Err( p_spu, "subpicture %p has invalid status #%d",
380                  p_subpic, p_subpic->i_status );
381     }
382
383     /* Remove reservation flag */
384     p_subpic->i_status = READY_SUBPICTURE;
385
386     if( p_subpic->i_channel == DEFAULT_CHAN )
387     {
388         p_subpic->i_channel = 0xFFFF;
389         spu_Control( p_spu, SPU_CHANNEL_CLEAR, DEFAULT_CHAN );
390         p_subpic->i_channel = DEFAULT_CHAN;
391     }
392 }
393
394 /**
395  * Allocate a subpicture in the spu heap.
396  *
397  * This function create a reserved subpicture in the spu heap.
398  * A null pointer is returned if the function fails. This method provides an
399  * already allocated zone of memory in the spu data fields. It needs locking
400  * since several pictures can be created by several producers threads.
401  * \param p_spu the subpicture unit in which to create the subpicture
402  * \return NULL on error, a reserved subpicture otherwise
403  */
404 subpicture_t *spu_CreateSubpicture( spu_t *p_spu )
405 {
406     int                 i_subpic;                        /* subpicture index */
407     subpicture_t *      p_subpic = NULL;            /* first free subpicture */
408
409     /* Get lock */
410     vlc_mutex_lock( &p_spu->subpicture_lock );
411
412     /*
413      * Look for an empty place
414      */
415     p_subpic = NULL;
416     for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
417     {
418         if( p_spu->p_subpicture[i_subpic].i_status == FREE_SUBPICTURE )
419         {
420             /* Subpicture is empty and ready for allocation */
421             p_subpic = &p_spu->p_subpicture[i_subpic];
422             p_spu->p_subpicture[i_subpic].i_status = RESERVED_SUBPICTURE;
423             break;
424         }
425     }
426
427     /* If no free subpicture could be found */
428     if( p_subpic == NULL )
429     {
430         msg_Err( p_spu, "subpicture heap is full" );
431         vlc_mutex_unlock( &p_spu->subpicture_lock );
432         return NULL;
433     }
434
435     /* Copy subpicture information, set some default values */
436     memset( p_subpic, 0, sizeof(subpicture_t) );
437     p_subpic->i_status   = RESERVED_SUBPICTURE;
438     p_subpic->b_absolute = VLC_TRUE;
439     p_subpic->b_pausable = VLC_FALSE;
440     p_subpic->b_fade     = VLC_FALSE;
441     p_subpic->i_alpha    = 0xFF;
442     p_subpic->p_region   = 0;
443     p_subpic->pf_render  = 0;
444     p_subpic->pf_destroy = 0;
445     p_subpic->p_sys      = 0;
446     vlc_mutex_unlock( &p_spu->subpicture_lock );
447
448     p_subpic->pf_create_region = __spu_CreateRegion;
449     p_subpic->pf_make_region = __spu_MakeRegion;
450     p_subpic->pf_destroy_region = __spu_DestroyRegion;
451
452     return p_subpic;
453 }
454
455 /**
456  * Remove a subpicture from the heap
457  *
458  * This function frees a previously reserved subpicture.
459  * It is meant to be used when the construction of a picture aborted.
460  * This function does not need locking since reserved subpictures are ignored
461  * by the spu.
462  */
463 void spu_DestroySubpicture( spu_t *p_spu, subpicture_t *p_subpic )
464 {
465     /* Get lock */
466     vlc_mutex_lock( &p_spu->subpicture_lock );
467
468     /* There can be race conditions so we need to check the status */
469     if( p_subpic->i_status == FREE_SUBPICTURE )
470     {
471         vlc_mutex_unlock( &p_spu->subpicture_lock );
472         return;
473     }
474
475     /* Check if status is valid */
476     if( ( p_subpic->i_status != RESERVED_SUBPICTURE )
477            && ( p_subpic->i_status != READY_SUBPICTURE ) )
478     {
479         msg_Err( p_spu, "subpicture %p has invalid status %d",
480                          p_subpic, p_subpic->i_status );
481     }
482
483     while( p_subpic->p_region )
484     {
485         subpicture_region_t *p_region = p_subpic->p_region;
486         p_subpic->p_region = p_region->p_next;
487         spu_DestroyRegion( p_spu, p_region );
488     }
489
490     if( p_subpic->pf_destroy )
491     {
492         p_subpic->pf_destroy( p_subpic );
493     }
494
495     p_subpic->i_status = FREE_SUBPICTURE;
496
497     vlc_mutex_unlock( &p_spu->subpicture_lock );
498 }
499
500 /*****************************************************************************
501  * spu_RenderSubpictures: render a subpicture list
502  *****************************************************************************
503  * This function renders all sub picture units in the list.
504  *****************************************************************************/
505 void spu_RenderSubpictures( spu_t *p_spu, video_format_t *p_fmt,
506                             picture_t *p_pic_dst, picture_t *p_pic_src,
507                             subpicture_t *p_subpic,
508                             int i_scale_width_orig, int i_scale_height_orig )
509 {
510     /* Get lock */
511     vlc_mutex_lock( &p_spu->subpicture_lock );
512
513     /* Check i_status again to make sure spudec hasn't destroyed the subpic */
514     while( p_subpic != NULL && p_subpic->i_status != FREE_SUBPICTURE )
515     {
516         subpicture_region_t *p_region = p_subpic->p_region;
517         int i_scale_width, i_scale_height;
518         int i_subpic_x = p_subpic->i_x;
519
520         /* Load the blending module */
521         if( !p_spu->p_blend && p_region )
522         {
523             p_spu->p_blend = vlc_object_create( p_spu, VLC_OBJECT_FILTER );
524             vlc_object_attach( p_spu->p_blend, p_spu );
525             p_spu->p_blend->fmt_out.video.i_x_offset =
526                 p_spu->p_blend->fmt_out.video.i_y_offset = 0;
527             p_spu->p_blend->fmt_out.video.i_aspect = p_fmt->i_aspect;
528             p_spu->p_blend->fmt_out.video.i_chroma = p_fmt->i_chroma;
529             p_spu->p_blend->fmt_in.video.i_chroma = VLC_FOURCC('Y','U','V','P');
530             /* XXX: We'll also be using it for YUVA and RGBA blending ... */
531
532             p_spu->p_blend->p_module =
533                 module_Need( p_spu->p_blend, "video blending", 0, 0 );
534         }
535
536         /* Load the text rendering module */
537         if( !p_spu->p_text && p_region && p_region->fmt.i_chroma == VLC_FOURCC('T','E','X','T') )
538         {
539             char *psz_modulename = NULL;
540
541             p_spu->p_text = vlc_object_create( p_spu, VLC_OBJECT_FILTER );
542             vlc_object_attach( p_spu->p_text, p_spu );
543
544             p_spu->p_text->fmt_out.video.i_width =
545                 p_spu->p_text->fmt_out.video.i_visible_width =
546                 p_fmt->i_width;
547             p_spu->p_text->fmt_out.video.i_height =
548                 p_spu->p_text->fmt_out.video.i_visible_height =
549                 p_fmt->i_height;
550
551             p_spu->p_text->pf_sub_buffer_new = spu_new_buffer;
552             p_spu->p_text->pf_sub_buffer_del = spu_del_buffer;
553
554             psz_modulename = var_CreateGetString( p_spu, "text-renderer" );
555             if( psz_modulename && *psz_modulename )
556             {
557                 p_spu->p_text->p_module =
558                     module_Need( p_spu->p_text, "text renderer",
559                                  psz_modulename, VLC_TRUE );
560             }
561             if( !p_spu->p_text->p_module )
562             {
563                 p_spu->p_text->p_module =
564                     module_Need( p_spu->p_text, "text renderer", 0, 0 );
565             }
566             if( psz_modulename ) free( psz_modulename );
567         }
568         if( p_spu->p_text )
569         {
570             if( (p_subpic->i_original_picture_height > 0) &&
571                 (p_subpic->i_original_picture_width  > 0) )
572             {
573                 p_spu->p_text->fmt_out.video.i_width =
574                     p_spu->p_text->fmt_out.video.i_visible_width =
575                     p_subpic->i_original_picture_width;
576                 p_spu->p_text->fmt_out.video.i_height =
577                     p_spu->p_text->fmt_out.video.i_visible_height =
578                     p_subpic->i_original_picture_height;
579             }
580             else
581             {
582                 p_spu->p_text->fmt_out.video.i_width =
583                     p_spu->p_text->fmt_out.video.i_visible_width =
584                     p_fmt->i_width;
585                 p_spu->p_text->fmt_out.video.i_height =
586                     p_spu->p_text->fmt_out.video.i_visible_height =
587                     p_fmt->i_height;
588             }
589         }
590
591         i_scale_width = i_scale_width_orig;
592         i_scale_height = i_scale_height_orig;
593
594         if( (p_subpic->i_original_picture_height > 0) &&
595             (p_subpic->i_original_picture_width  > 0) )
596         {
597             i_scale_width = i_scale_width * p_fmt->i_width /
598                              p_subpic->i_original_picture_width;
599             i_scale_height = i_scale_height * p_fmt->i_height /
600                              p_subpic->i_original_picture_height;
601         }
602         else if( p_subpic->i_original_picture_height > 0 )
603         {
604             i_scale_height = i_scale_height * p_fmt->i_height /
605                              p_subpic->i_original_picture_height;
606             i_scale_width = i_scale_height * i_scale_height / p_fmt->i_height;
607         }
608
609         /* Set default subpicture aspect ratio */
610         if( p_region && p_region->fmt.i_aspect &&
611             (!p_region->fmt.i_sar_num || !p_region->fmt.i_sar_den) )
612         {
613             p_region->fmt.i_sar_den = p_region->fmt.i_aspect;
614             p_region->fmt.i_sar_num = VOUT_ASPECT_FACTOR;
615         }
616         if( p_region &&
617             (!p_region->fmt.i_sar_num || !p_region->fmt.i_sar_den) )
618         {
619             p_region->fmt.i_sar_den = p_fmt->i_sar_den;
620             p_region->fmt.i_sar_num = p_fmt->i_sar_num;
621         }
622
623         /* Take care of the aspect ratio */
624         if( p_region && p_region->fmt.i_sar_num * p_fmt->i_sar_den !=
625             p_region->fmt.i_sar_den * p_fmt->i_sar_num )
626         {
627             i_scale_width = i_scale_width *
628                 (int64_t)p_region->fmt.i_sar_num * p_fmt->i_sar_den /
629                 p_region->fmt.i_sar_den / p_fmt->i_sar_num;
630             i_subpic_x = p_subpic->i_x * i_scale_width / 1000;
631         }
632
633         /* Load the scaling module */
634         if( !p_spu->p_scale &&
635             ((i_scale_width > 0) || (i_scale_height > 0)) &&
636             ((i_scale_width != 1000) || (i_scale_height != 1000)) )
637         {
638             p_spu->p_scale = vlc_object_create( p_spu, VLC_OBJECT_FILTER );
639             vlc_object_attach( p_spu->p_scale, p_spu );
640             p_spu->p_scale->fmt_out.video.i_chroma =
641                 p_spu->p_scale->fmt_in.video.i_chroma =
642                     VLC_FOURCC('Y','U','V','P');
643             /* XXX: We'll also be using it for YUVA and RGBA blending ... */
644             p_spu->p_scale->fmt_in.video.i_width =
645                 p_spu->p_scale->fmt_in.video.i_height = 32;
646             p_spu->p_scale->fmt_out.video.i_width =
647                 p_spu->p_scale->fmt_out.video.i_height = 16;
648
649             p_spu->p_scale->pf_vout_buffer_new = spu_new_video_buffer;
650             p_spu->p_scale->pf_vout_buffer_del = spu_del_video_buffer;
651             p_spu->p_scale->p_module =
652                 module_Need( p_spu->p_scale, "video filter2", 0, 0 );
653         }
654
655         while( p_region && p_spu->p_blend && p_spu->p_blend->pf_video_blend )
656         {
657             video_format_t orig_fmt = p_region->fmt;
658             vlc_bool_t b_rerender_text = VLC_FALSE;
659             int i_fade_alpha = 255;
660             int i_x_offset = p_region->i_x + i_subpic_x;
661             int i_y_offset = p_region->i_y + p_subpic->i_y;
662
663             if( p_region->fmt.i_chroma == VLC_FOURCC('T','E','X','T') )
664             {
665                 if( p_spu->p_text && p_spu->p_text->p_module )
666                 {
667                     vlc_value_t  val;
668
669                     /* Setup 3 variables which can be used to render time-dependent
670                      * text (and effects). The first indicates the total amount of
671                      * time the text will be on screen, the second the amount of time
672                      * it has already been on screen (can be a negative value as text
673                      * is layed out before it is rendered) and the third is a feedback
674                      * variable from the renderer - if the renderer sets it then this
675                      * particular text is time-dependent, eg. the visual progress bar
676                      * inside the text in karaoke and the text needs to be rendered
677                      * multiple times in order for the effect to work - we therefore
678                      * need to return the region to its original state at the end of
679                      * the loop, instead of leaving it in YUVA or YUVP
680                      * Any renderer which is unaware of how to render time-dependent
681                      * text can happily ignore the variables and render the text the
682                      * same as usual - it should at least show up on screen, but the
683                      * effect won't change the text over time.
684                      */
685
686                     var_Create( p_spu->p_text, "spu-duration", VLC_VAR_TIME );
687                     val.i_time = p_subpic->i_stop - p_subpic->i_start;
688                     var_Set( p_spu->p_text, "spu-duration", val );
689
690                     var_Create( p_spu->p_text, "spu-elapsed", VLC_VAR_TIME );
691                     val.i_time = mdate() - p_subpic->i_start;
692                     var_Set( p_spu->p_text, "spu-elapsed", val );
693
694                     var_Create( p_spu->p_text, "text-rerender", VLC_VAR_BOOL );
695                     var_SetBool( p_spu->p_text, "text-rerender", VLC_FALSE );
696
697                     if( p_spu->p_text->pf_render_html && p_region->psz_html )
698                     {
699                         p_spu->p_text->pf_render_html( p_spu->p_text,
700                                                        p_region, p_region );
701                     }
702                     else if( p_spu->p_text->pf_render_text )
703                     {
704                         p_spu->p_text->pf_render_text( p_spu->p_text,
705                                                        p_region, p_region );
706                     }
707                     b_rerender_text = var_GetBool( p_spu->p_text, "text-rerender" );
708
709                     var_Destroy( p_spu->p_text, "spu-duration" );
710                     var_Destroy( p_spu->p_text, "spu-elapsed" );
711                     var_Destroy( p_spu->p_text, "text-rerender" );
712
713                 }
714             }
715
716             /* Force palette if requested */
717             if( p_spu->b_force_palette &&
718                 (VLC_FOURCC('Y','U','V','P') == p_region->fmt.i_chroma) )
719             {
720                 memcpy( p_region->fmt.p_palette->palette,
721                         p_spu->palette, 16 );
722             }
723
724             /* Scale SPU if necessary */
725             if( p_region->p_cache )
726             {
727                 if( i_scale_width * p_region->fmt.i_width / 1000 !=
728                     p_region->p_cache->fmt.i_width ||
729                     i_scale_height * p_region->fmt.i_height / 1000 !=
730                     p_region->p_cache->fmt.i_height )
731                 {
732                     p_subpic->pf_destroy_region( VLC_OBJECT(p_spu),
733                                                  p_region->p_cache );
734                     p_region->p_cache = 0;
735                 }
736             }
737
738             if( ((i_scale_width != 1000) || (i_scale_height != 1000)) &&
739                 ((i_scale_width > 0) || (i_scale_height > 0)) &&
740                 p_spu->p_scale && !p_region->p_cache )
741             {
742                 picture_t *p_pic;
743
744                 p_spu->p_scale->fmt_in.video = p_region->fmt;
745                 p_spu->p_scale->fmt_out.video = p_region->fmt;
746
747                 p_region->p_cache =
748                     p_subpic->pf_create_region( VLC_OBJECT(p_spu),
749                         &p_spu->p_scale->fmt_out.video );
750                 if( p_spu->p_scale->fmt_out.video.p_palette )
751                     *p_spu->p_scale->fmt_out.video.p_palette =
752                         *p_region->fmt.p_palette;
753                 p_region->p_cache->p_next = p_region->p_next;
754
755                 vout_CopyPicture( p_spu, &p_region->p_cache->picture,
756                                   &p_region->picture );
757
758                 p_spu->p_scale->fmt_out.video.i_width =
759                     p_region->fmt.i_width * i_scale_width / 1000;
760                 p_spu->p_scale->fmt_out.video.i_visible_width =
761                     p_region->fmt.i_visible_width * i_scale_width / 1000;
762                 p_spu->p_scale->fmt_out.video.i_height =
763                     p_region->fmt.i_height * i_scale_height / 1000;
764                 p_spu->p_scale->fmt_out.video.i_visible_height =
765                     p_region->fmt.i_visible_height * i_scale_height / 1000;
766                 p_region->p_cache->fmt = p_spu->p_scale->fmt_out.video;
767                 p_region->p_cache->i_x = p_region->i_x * i_scale_width / 1000;
768                 p_region->p_cache->i_y = p_region->i_y * i_scale_height / 1000;
769                 p_region->p_cache->i_align = p_region->i_align;
770
771                 p_pic = p_spu->p_scale->pf_video_filter(
772                                  p_spu->p_scale, &p_region->p_cache->picture );
773                 if( p_pic )
774                 {
775                     picture_t p_pic_tmp = p_region->p_cache->picture;
776                     p_region->p_cache->picture = *p_pic;
777                     *p_pic = p_pic_tmp;
778                     free( p_pic );
779                 }
780             }
781             if( ((i_scale_width != 1000) || (i_scale_height != 1000)) &&
782                 ((i_scale_width > 0) || (i_scale_height > 0)) &&
783                 p_spu->p_scale && p_region->p_cache )
784             {
785                 p_region = p_region->p_cache;
786             }
787
788             if( p_region->i_align & SUBPICTURE_ALIGN_BOTTOM )
789             {
790                 i_y_offset = p_fmt->i_height - p_region->fmt.i_height -
791                     p_subpic->i_y - p_region->i_y;
792             }
793             else if ( !(p_region->i_align & SUBPICTURE_ALIGN_TOP) )
794             {
795                 i_y_offset = p_fmt->i_height / 2 - p_region->fmt.i_height / 2;
796             }
797
798             if( p_region->i_align & SUBPICTURE_ALIGN_RIGHT )
799             {
800                 i_x_offset = p_fmt->i_width - p_region->fmt.i_width -
801                     i_subpic_x - p_region->i_x;
802             }
803             else if ( !(p_region->i_align & SUBPICTURE_ALIGN_LEFT) )
804             {
805                 i_x_offset = p_fmt->i_width / 2 - p_region->fmt.i_width / 2;
806             }
807
808             if( p_subpic->b_absolute )
809             {
810                 i_x_offset = p_region->i_x +
811                     i_subpic_x * i_scale_width / 1000;
812                 i_y_offset = p_region->i_y +
813                     p_subpic->i_y * i_scale_height / 1000;
814
815             }
816
817             i_x_offset = __MAX( i_x_offset, 0 );
818             i_y_offset = __MAX( i_y_offset, 0 );
819
820             if( p_spu->i_margin != 0 && p_spu->b_force_crop == VLC_FALSE )
821             {
822                 int i_diff = 0;
823                 int i_low = i_y_offset - p_spu->i_margin;
824                 int i_high = i_y_offset + p_region->fmt.i_height - p_spu->i_margin;
825
826                 /* crop extra margin to keep within bounds */
827                 if( i_low < 0 ) i_diff = i_low;
828                 if( i_high > (int)p_fmt->i_height ) i_diff = i_high - p_fmt->i_height;
829                 i_y_offset -= ( p_spu->i_margin + i_diff );
830             }
831
832             p_spu->p_blend->fmt_in.video = p_region->fmt;
833
834             /* Force cropping if requested */
835             if( p_spu->b_force_crop )
836             {
837                 video_format_t *p_fmt = &p_spu->p_blend->fmt_in.video;
838                 int i_crop_x = p_spu->i_crop_x * i_scale_width / 1000;
839                 int i_crop_y = p_spu->i_crop_y * i_scale_height / 1000;
840                 int i_crop_width = p_spu->i_crop_width * i_scale_width / 1000;
841                 int i_crop_height = p_spu->i_crop_height * i_scale_height/1000;
842
843                 /* Find the intersection */
844                 if( i_crop_x + i_crop_width <= i_x_offset ||
845                     i_x_offset + (int)p_fmt->i_visible_width < i_crop_x ||
846                     i_crop_y + i_crop_height <= i_y_offset ||
847                     i_y_offset + (int)p_fmt->i_visible_height < i_crop_y )
848                 {
849                     /* No intersection */
850                     p_fmt->i_visible_width = p_fmt->i_visible_height = 0;
851                 }
852                 else
853                 {
854                     int i_x, i_y, i_x_end, i_y_end;
855                     i_x = __MAX( i_crop_x, i_x_offset );
856                     i_y = __MAX( i_crop_y, i_y_offset );
857                     i_x_end = __MIN( i_crop_x + i_crop_width,
858                                    i_x_offset + (int)p_fmt->i_visible_width );
859                     i_y_end = __MIN( i_crop_y + i_crop_height,
860                                    i_y_offset + (int)p_fmt->i_visible_height );
861
862                     p_fmt->i_x_offset = i_x - i_x_offset;
863                     p_fmt->i_y_offset = i_y - i_y_offset;
864                     p_fmt->i_visible_width = i_x_end - i_x;
865                     p_fmt->i_visible_height = i_y_end - i_y;
866
867                     i_x_offset = i_x;
868                     i_y_offset = i_y;
869                 }
870             }
871
872             /* Update the output picture size */
873             p_spu->p_blend->fmt_out.video.i_width =
874                 p_spu->p_blend->fmt_out.video.i_visible_width =
875                     p_fmt->i_width;
876             p_spu->p_blend->fmt_out.video.i_height =
877                 p_spu->p_blend->fmt_out.video.i_visible_height =
878                     p_fmt->i_height;
879
880             if( p_subpic->b_fade )
881             {
882                 mtime_t i_fade_start = ( p_subpic->i_stop +
883                                          p_subpic->i_start ) / 2;
884                 mtime_t i_now = mdate();
885                 if( i_now >= i_fade_start && p_subpic->i_stop > i_fade_start )
886                 {
887                     i_fade_alpha = 255 * ( p_subpic->i_stop - i_now ) /
888                                    ( p_subpic->i_stop - i_fade_start );
889                 }
890             }
891
892             i_x_offset = __MAX( i_x_offset, 0 );
893             i_y_offset = __MAX( i_y_offset, 0 );
894
895             p_spu->p_blend->pf_video_blend( p_spu->p_blend, p_pic_dst,
896                 p_pic_src, &p_region->picture, i_x_offset, i_y_offset,
897                 i_fade_alpha * p_subpic->i_alpha / 255 );
898
899             if( b_rerender_text )
900             {
901                 /* Some forms of subtitles need to be re-rendered more than once,
902                  * eg. karaoke. We therefore restore the region to its pre-rendered
903                  * state, so the next time through everything is calculated again.
904                  */
905                 p_region->picture.pf_release( &p_region->picture );
906                 memset( &p_region->picture, 0, sizeof( picture_t ) );
907                 p_region->fmt = orig_fmt;
908             }
909             p_region = p_region->p_next;
910         }
911
912         p_subpic = p_subpic->p_next;
913     }
914
915     vlc_mutex_unlock( &p_spu->subpicture_lock );
916 }
917
918 /*****************************************************************************
919  * spu_SortSubpictures: find the subpictures to display
920  *****************************************************************************
921  * This function parses all subpictures and decides which ones need to be
922  * displayed. This operation does not need lock, since only READY_SUBPICTURE
923  * are handled. If no picture has been selected, display_date will depend on
924  * the subpicture.
925  * We also check for ephemer DVD subpictures (subpictures that have
926  * to be removed if a newer one is available), which makes it a lot
927  * more difficult to guess if a subpicture has to be rendered or not.
928  *****************************************************************************/
929 subpicture_t *spu_SortSubpictures( spu_t *p_spu, mtime_t display_date,
930                                    vlc_bool_t b_paused )
931 {
932     int i_index, i_channel;
933     subpicture_t *p_subpic = NULL;
934     subpicture_t *p_ephemer;
935     mtime_t      ephemer_date;
936
937     /* Run subpicture filters */
938     for( i_index = 0; i_index < p_spu->i_filter; i_index++ )
939     {
940         subpicture_t *p_subpic_filter;
941         p_subpic_filter = p_spu->pp_filter[i_index]->
942             pf_sub_filter( p_spu->pp_filter[i_index], display_date );
943         if( p_subpic_filter )
944         {
945             spu_DisplaySubpicture( p_spu, p_subpic_filter );
946         }
947     }
948
949     /* We get an easily parsable chained list of subpictures which
950      * ends with NULL since p_subpic was initialized to NULL. */
951     for( i_channel = 0; i_channel < p_spu->i_channel; i_channel++ )
952     {
953         p_ephemer = 0;
954         ephemer_date = 0;
955
956         for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
957         {
958             if( p_spu->p_subpicture[i_index].i_channel != i_channel ||
959                 p_spu->p_subpicture[i_index].i_status != READY_SUBPICTURE )
960             {
961                 continue;
962             }
963             if( display_date &&
964                 display_date < p_spu->p_subpicture[i_index].i_start )
965             {
966                 /* Too early, come back next monday */
967                 continue;
968             }
969
970             if( p_spu->p_subpicture[i_index].i_start > ephemer_date )
971                 ephemer_date = p_spu->p_subpicture[i_index].i_start;
972
973             if( display_date > p_spu->p_subpicture[i_index].i_stop &&
974                 ( !p_spu->p_subpicture[i_index].b_ephemer ||
975                   p_spu->p_subpicture[i_index].i_stop >
976                   p_spu->p_subpicture[i_index].i_start ) &&
977                 !( p_spu->p_subpicture[i_index].b_pausable &&
978                    b_paused ) )
979             {
980                 /* Too late, destroy the subpic */
981                 spu_DestroySubpicture( p_spu, &p_spu->p_subpicture[i_index] );
982                 continue;
983             }
984
985             /* If this is an ephemer subpic, add it to our list */
986             if( p_spu->p_subpicture[i_index].b_ephemer )
987             {
988                 p_spu->p_subpicture[i_index].p_next = p_ephemer;
989                 p_ephemer = &p_spu->p_subpicture[i_index];
990
991                 continue;
992             }
993
994             p_spu->p_subpicture[i_index].p_next = p_subpic;
995             p_subpic = &p_spu->p_subpicture[i_index];
996         }
997
998         /* If we found ephemer subpictures, check if they have to be
999          * displayed or destroyed */
1000         while( p_ephemer != NULL )
1001         {
1002             subpicture_t *p_tmp = p_ephemer;
1003             p_ephemer = p_ephemer->p_next;
1004
1005             if( p_tmp->i_start < ephemer_date )
1006             {
1007                 /* Ephemer subpicture has lived too long */
1008                 spu_DestroySubpicture( p_spu, p_tmp );
1009             }
1010             else
1011             {
1012                 /* Ephemer subpicture can still live a bit */
1013                 p_tmp->p_next = p_subpic;
1014                 p_subpic = p_tmp;
1015             }
1016         }
1017     }
1018
1019     return p_subpic;
1020 }
1021
1022 /*****************************************************************************
1023  * SpuClearChannel: clear an spu channel
1024  *****************************************************************************
1025  * This function destroys the subpictures which belong to the spu channel
1026  * corresponding to i_channel_id.
1027  *****************************************************************************/
1028 static void SpuClearChannel( spu_t *p_spu, int i_channel )
1029 {
1030     int          i_subpic;                               /* subpicture index */
1031     subpicture_t *p_subpic = NULL;                  /* first free subpicture */
1032
1033     vlc_mutex_lock( &p_spu->subpicture_lock );
1034
1035     for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
1036     {
1037         p_subpic = &p_spu->p_subpicture[i_subpic];
1038         if( p_subpic->i_status == FREE_SUBPICTURE
1039             || ( p_subpic->i_status != RESERVED_SUBPICTURE
1040                  && p_subpic->i_status != READY_SUBPICTURE ) )
1041         {
1042             continue;
1043         }
1044
1045         if( p_subpic->i_channel == i_channel )
1046         {
1047             while( p_subpic->p_region )
1048             {
1049                 subpicture_region_t *p_region = p_subpic->p_region;
1050                 p_subpic->p_region = p_region->p_next;
1051                 spu_DestroyRegion( p_spu, p_region );
1052             }
1053
1054             if( p_subpic->pf_destroy ) p_subpic->pf_destroy( p_subpic );
1055             p_subpic->i_status = FREE_SUBPICTURE;
1056         }
1057     }
1058
1059     vlc_mutex_unlock( &p_spu->subpicture_lock );
1060 }
1061
1062 /*****************************************************************************
1063  * spu_ControlDefault: default methods for the subpicture unit control.
1064  *****************************************************************************/
1065 static int spu_vaControlDefault( spu_t *p_spu, int i_query, va_list args )
1066 {
1067     int *pi, i;
1068
1069     switch( i_query )
1070     {
1071     case SPU_CHANNEL_REGISTER:
1072         pi = (int *)va_arg( args, int * );
1073         if( pi ) *pi = p_spu->i_channel++;
1074         break;
1075
1076     case SPU_CHANNEL_CLEAR:
1077         i = (int)va_arg( args, int );
1078         SpuClearChannel( p_spu, i );
1079         break;
1080
1081     default:
1082         msg_Dbg( p_spu, "control query not supported" );
1083         return VLC_EGENERIC;
1084     }
1085
1086     return VLC_SUCCESS;
1087 }
1088
1089 /*****************************************************************************
1090  * Object variables callbacks
1091  *****************************************************************************/
1092
1093 /*****************************************************************************
1094  * UpdateSPU: update subpicture settings
1095  *****************************************************************************
1096  * This function is called from CropCallback and at initialization time, to
1097  * retrieve crop information from the input.
1098  *****************************************************************************/
1099 static void UpdateSPU( spu_t *p_spu, vlc_object_t *p_object )
1100 {
1101     vlc_value_t val;
1102
1103     p_spu->b_force_palette = VLC_FALSE;
1104     p_spu->b_force_crop = VLC_FALSE;
1105
1106     if( var_Get( p_object, "highlight", &val ) || !val.b_bool ) return;
1107
1108     p_spu->b_force_crop = VLC_TRUE;
1109     var_Get( p_object, "x-start", &val );
1110     p_spu->i_crop_x = val.i_int;
1111     var_Get( p_object, "y-start", &val );
1112     p_spu->i_crop_y = val.i_int;
1113     var_Get( p_object, "x-end", &val );
1114     p_spu->i_crop_width = val.i_int - p_spu->i_crop_x;
1115     var_Get( p_object, "y-end", &val );
1116     p_spu->i_crop_height = val.i_int - p_spu->i_crop_y;
1117
1118     if( var_Get( p_object, "menu-palette", &val ) == VLC_SUCCESS )
1119     {
1120         memcpy( p_spu->palette, val.p_address, 16 );
1121         p_spu->b_force_palette = VLC_TRUE;
1122     }
1123
1124     msg_Dbg( p_object, "crop: %i,%i,%i,%i, palette forced: %i",
1125              p_spu->i_crop_x, p_spu->i_crop_y,
1126              p_spu->i_crop_width, p_spu->i_crop_height,
1127              p_spu->b_force_palette );
1128 }
1129
1130 /*****************************************************************************
1131  * CropCallback: called when the highlight properties are changed
1132  *****************************************************************************
1133  * This callback is called from the input thread when we need cropping
1134  *****************************************************************************/
1135 static int CropCallback( vlc_object_t *p_object, char const *psz_var,
1136                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
1137 {
1138     (void)psz_var; (void)oldval; (void)newval;
1139     UpdateSPU( (spu_t *)p_data, p_object );
1140     return VLC_SUCCESS;
1141 }
1142
1143 /*****************************************************************************
1144  * Buffers allocation callbacks for the filters
1145  *****************************************************************************/
1146 static subpicture_t *sub_new_buffer( filter_t *p_filter )
1147 {
1148     filter_owner_sys_t *p_sys = p_filter->p_owner;
1149     subpicture_t *p_subpicture = spu_CreateSubpicture( p_sys->p_spu );
1150     if( p_subpicture ) p_subpicture->i_channel = p_sys->i_channel;
1151     return p_subpicture;
1152 }
1153
1154 static void sub_del_buffer( filter_t *p_filter, subpicture_t *p_subpic )
1155 {
1156     filter_owner_sys_t *p_sys = p_filter->p_owner;
1157     spu_DestroySubpicture( p_sys->p_spu, p_subpic );
1158 }
1159
1160 static subpicture_t *spu_new_buffer( filter_t *p_filter )
1161 {
1162     subpicture_t *p_subpic = (subpicture_t *)malloc(sizeof(subpicture_t));
1163     (void)p_filter;
1164     memset( p_subpic, 0, sizeof(subpicture_t) );
1165     p_subpic->b_absolute = VLC_TRUE;
1166
1167     p_subpic->pf_create_region = __spu_CreateRegion;
1168     p_subpic->pf_make_region = __spu_MakeRegion;
1169     p_subpic->pf_destroy_region = __spu_DestroyRegion;
1170
1171     return p_subpic;
1172 }
1173
1174 static void spu_del_buffer( filter_t *p_filter, subpicture_t *p_subpic )
1175 {
1176     while( p_subpic->p_region )
1177     {
1178         subpicture_region_t *p_region = p_subpic->p_region;
1179         p_subpic->p_region = p_region->p_next;
1180         p_subpic->pf_destroy_region( VLC_OBJECT(p_filter), p_region );
1181     }
1182
1183     free( p_subpic );
1184 }
1185
1186 static picture_t *spu_new_video_buffer( filter_t *p_filter )
1187 {
1188     picture_t *p_picture = malloc( sizeof(picture_t) );
1189
1190     if( vout_AllocatePicture( p_filter, p_picture,
1191                               p_filter->fmt_out.video.i_chroma,
1192                               p_filter->fmt_out.video.i_width,
1193                               p_filter->fmt_out.video.i_height,
1194                               p_filter->fmt_out.video.i_aspect )
1195         != VLC_SUCCESS )
1196     {
1197         free( p_picture );
1198         return NULL;
1199     }
1200
1201     p_picture->pf_release = RegionPictureRelease;
1202
1203     return p_picture;
1204 }
1205
1206 static void spu_del_video_buffer( filter_t *p_filter, picture_t *p_pic )
1207 {
1208     (void)p_filter;
1209     if( p_pic && p_pic->p_data_orig ) free( p_pic->p_data_orig );
1210     if( p_pic ) free( p_pic );
1211 }
1212
1213 static int SubFilterCallback( vlc_object_t *p_object, char const *psz_var,
1214                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
1215 {
1216     (void)p_object; (void)oldval; (void)newval;
1217
1218     if( !strcmp( psz_var, "sub-filter" ) )
1219     {
1220         spu_t *p_spu = (spu_t *)p_data;
1221         vlc_mutex_lock( &p_spu->subpicture_lock );
1222         spu_DeleteChain( p_spu );
1223         spu_ParseChain( p_spu );
1224         vlc_mutex_unlock( &p_spu->subpicture_lock );
1225     }
1226     return VLC_SUCCESS;
1227 }