]> git.sesse.net Git - vlc/blob - src/video_output/vout_subpictures.c
* ALL: Major rework of the subpictures architecture.
[vlc] / src / video_output / vout_subpictures.c
1 /*****************************************************************************
2  * vout_subpictures.c : subpicture management functions
3  *****************************************************************************
4  * Copyright (C) 2000-2004 VideoLAN
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., 59 Temple Place - Suite 330, Boston, MA  02111, 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
35 #include "vlc_video.h"
36 #include "video_output.h"
37 #include "vlc_filter.h"
38 #include "osd.h"
39
40 static void UpdateSPU        ( vout_thread_t *, vlc_object_t * );
41 static int  CropCallback     ( vlc_object_t *, char const *,
42                                vlc_value_t, vlc_value_t, void * );
43
44 static subpicture_t *spu_new_buffer( filter_t * );
45 static void spu_del_buffer( filter_t *, subpicture_t * );
46
47 /**
48  * Initialise the subpicture decoder unit
49  *
50  * \param p_vout the vout in which to create the subpicture unit
51  */
52 void vout_InitSPU( vout_thread_t *p_vout )
53 {
54     vlc_object_t *p_input;
55     int i_index;
56
57     for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++)
58     {
59         p_vout->p_subpicture[i_index].i_status = FREE_SUBPICTURE;
60         p_vout->p_subpicture[i_index].i_type   = EMPTY_SUBPICTURE;
61     }
62
63     /* Load the text rendering module */
64     p_vout->p_text = vlc_object_create( p_vout, sizeof(filter_t) );
65     p_vout->p_text->pf_spu_buffer_new = spu_new_buffer;
66     p_vout->p_text->pf_spu_buffer_del = spu_del_buffer;
67     p_vout->p_text->p_owner = (filter_owner_sys_t *)p_vout;
68     vlc_object_attach( p_vout->p_text, p_vout );
69     p_vout->p_text->p_module =
70         module_Need( p_vout->p_text, "text renderer", 0, 0 );
71     if( p_vout->p_text->p_module == NULL )
72     {
73         msg_Warn( p_vout, "no suitable text renderer module" );
74         vlc_object_detach( p_vout->p_text );
75         vlc_object_destroy( p_vout->p_text );
76         p_vout->p_text = NULL;
77     }
78
79     p_vout->p_blend = NULL;
80
81     p_vout->i_crop_x = p_vout->i_crop_y =
82         p_vout->i_crop_width = p_vout->i_crop_height = 0;
83     p_vout->b_force_alpha = VLC_FALSE;
84     p_vout->b_force_crop = VLC_FALSE;
85
86     /* Create callback */
87     p_input = vlc_object_find( p_vout, VLC_OBJECT_INPUT, FIND_PARENT );
88     if( p_input )
89     {
90         UpdateSPU( p_vout, VLC_OBJECT(p_input) );
91         var_AddCallback( p_input, "highlight", CropCallback, p_vout );
92         vlc_object_release( p_input );
93     }
94 }
95
96 /**
97  * Destroy the subpicture decoder unit
98  *
99  * \param p_vout the vout in which to destroy the subpicture unit
100  */
101 void vout_DestroySPU( vout_thread_t *p_vout )
102 {
103     vlc_object_t *p_input;
104     int i_index;
105
106     /* Destroy all remaining subpictures */
107     for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
108     {
109         if( p_vout->p_subpicture[i_index].i_status != FREE_SUBPICTURE )
110         {
111             vout_DestroySubPicture( p_vout,
112                                     &p_vout->p_subpicture[i_index] );
113         }
114     }
115
116     if( p_vout->p_text )
117     {
118         if( p_vout->p_text->p_module )
119             module_Unneed( p_vout->p_text, p_vout->p_text->p_module );
120
121         vlc_object_detach( p_vout->p_text );
122         vlc_object_destroy( p_vout->p_text );
123     }
124
125     if( p_vout->p_blend )
126     {
127         if( p_vout->p_blend->p_module )
128             module_Unneed( p_vout->p_blend, p_vout->p_blend->p_module );
129
130         vlc_object_detach( p_vout->p_blend );
131         vlc_object_destroy( p_vout->p_blend );
132     }
133
134     /* Delete callback */
135     p_input = vlc_object_find( p_vout, VLC_OBJECT_INPUT, FIND_PARENT );
136     if( p_input )
137     {
138         var_DelCallback( p_input, "highlight", CropCallback, p_vout );
139         vlc_object_release( p_input );
140     }
141 }
142
143 /**
144  * Create a subpicture region
145  *
146  * \param p_this vlc_object_t
147  * \param p_fmt the format that this subpicture region should have
148  */
149 subpicture_region_t *__spu_CreateRegion( vlc_object_t *p_this,
150                                          video_format_t *p_fmt )
151 {
152     subpicture_region_t *p_region = malloc( sizeof(subpicture_region_t) );
153     memset( p_region, 0, sizeof(subpicture_region_t) );
154     p_region->p_next = 0;
155     p_region->fmt = *p_fmt;
156
157     vout_AllocatePicture( p_this, &p_region->picture, p_fmt->i_chroma,
158                           p_fmt->i_width, p_fmt->i_height, p_fmt->i_aspect );
159
160     if( !p_region->picture.i_planes )
161     {
162         free( p_region );
163         return NULL;
164     }
165
166     if( p_fmt->i_chroma == VLC_FOURCC('Y','U','V','P') )
167         p_fmt->p_palette = p_region->fmt.p_palette =
168             malloc( sizeof(video_palette_t) );
169     else p_fmt->p_palette = p_region->fmt.p_palette = NULL;
170
171     return p_region;
172 }
173
174 /**
175  * Destroy a subpicture region
176  *
177  * \param p_this vlc_object_t
178  * \param p_region the subpicture region to destroy
179  */
180 void __spu_DestroyRegion( vlc_object_t *p_this, subpicture_region_t *p_region )
181 {
182     if( !p_region ) return;
183     if( p_region->picture.p_data_orig ) free( p_region->picture.p_data_orig );
184     if( p_region->fmt.p_palette ) free( p_region->fmt.p_palette );
185     free( p_region );
186 }
187
188 /**
189  * Display a subpicture unit
190  *
191  * Remove the reservation flag of a subpicture, which will cause it to be
192  * ready for display.
193  * \param p_vout the video output this subpicture should be displayed on
194  * \param p_subpic the subpicture to display
195  */
196 void vout_DisplaySubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
197 {
198     int         i_margin;
199
200     /* Check if status is valid */
201     if( p_subpic->i_status != RESERVED_SUBPICTURE )
202     {
203         msg_Err( p_vout, "subpicture %p has invalid status #%d",
204                          p_subpic, p_subpic->i_status );
205     }
206
207     /* If the user requested an SPU margin, we force the position after
208      * having checked that it was a valid value. */
209     i_margin = config_GetInt( p_vout, "spumargin" );
210
211     if( i_margin >= 0 )
212     {
213         if( p_subpic->i_height + (unsigned int)i_margin
214                                                  <= p_vout->output.i_height )
215         {
216             p_subpic->i_y = p_vout->output.i_height
217                              - i_margin - p_subpic->i_height;
218         }
219     }
220
221     /* Remove reservation flag */
222     p_subpic->i_status = READY_SUBPICTURE;
223 }
224
225 /**
226  * Allocate a subpicture in the video output heap.
227  *
228  * This function create a reserved subpicture in the video output heap.
229  * A null pointer is returned if the function fails. This method provides an
230  * already allocated zone of memory in the spu data fields. It needs locking
231  * since several pictures can be created by several producers threads.
232  * \param p_vout the vout in which to create the subpicture
233  * \param i_channel the channel this subpicture should belong to
234  * \param i_type the type of the subpicture
235  * \return NULL on error, a reserved subpicture otherwise
236  */
237 subpicture_t *vout_CreateSubPicture( vout_thread_t *p_vout, int i_channel,
238                                      int i_type )
239 {
240     int                 i_subpic;                        /* subpicture index */
241     subpicture_t *      p_subpic = NULL;            /* first free subpicture */
242
243     /* Clear the default channel before writing into it */
244     if( i_channel == DEFAULT_CHAN )
245     {
246         vout_ClearOSDChannel( p_vout, DEFAULT_CHAN );
247     }
248
249     /* Get lock */
250     vlc_mutex_lock( &p_vout->subpicture_lock );
251
252     /*
253      * Look for an empty place
254      */
255     p_subpic = NULL;
256     for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
257     {
258         if( p_vout->p_subpicture[i_subpic].i_status == FREE_SUBPICTURE )
259         {
260             /* Subpicture is empty and ready for allocation */
261             p_subpic = &p_vout->p_subpicture[i_subpic];
262             p_vout->p_subpicture[i_subpic].i_status = RESERVED_SUBPICTURE;
263             break;
264         }
265     }
266
267     /* If no free subpicture could be found */
268     if( p_subpic == NULL )
269     {
270         msg_Err( p_vout, "subpicture heap is full" );
271         vlc_mutex_unlock( &p_vout->subpicture_lock );
272         return NULL;
273     }
274
275     /* Copy subpicture information, set some default values */
276     p_subpic->i_channel = i_channel;
277     p_subpic->i_type    = i_type;
278     p_subpic->i_status  = RESERVED_SUBPICTURE;
279
280     p_subpic->i_start   = 0;
281     p_subpic->i_stop    = 0;
282     p_subpic->b_ephemer = VLC_FALSE;
283
284     p_subpic->i_x       = 0;
285     p_subpic->i_y       = 0;
286     p_subpic->i_width   = 0;
287     p_subpic->i_height  = 0;
288     p_subpic->b_absolute= VLC_TRUE;
289     p_subpic->i_flags   = 0;
290     p_subpic->pf_render = 0;
291     p_subpic->pf_destroy= 0;
292     p_subpic->p_sys     = 0;
293
294     /* Remain last subpicture displayed in DEFAULT_CHAN */
295     if( i_channel == DEFAULT_CHAN )
296     {
297         p_vout->p_default_channel = p_subpic;
298     }
299
300     vlc_mutex_unlock( &p_vout->subpicture_lock );
301
302     p_subpic->pf_create_region = __spu_CreateRegion;
303     p_subpic->pf_destroy_region = __spu_DestroyRegion;
304
305     return p_subpic;
306 }
307
308 /**
309  * Remove a subpicture from the heap
310  *
311  * This function frees a previously reserved subpicture.
312  * It is meant to be used when the construction of a picture aborted.
313  * This function does not need locking since reserved subpictures are ignored
314  * by the output thread.
315  */
316 void vout_DestroySubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
317 {
318     /* Get lock */
319     vlc_mutex_lock( &p_vout->subpicture_lock );
320
321     /* There can be race conditions so we need to check the status */
322     if( p_subpic->i_status == FREE_SUBPICTURE )
323     {
324         vlc_mutex_unlock( &p_vout->subpicture_lock );
325         return;
326     }
327
328     /* Check if status is valid */
329     if( ( p_subpic->i_status != RESERVED_SUBPICTURE )
330            && ( p_subpic->i_status != READY_SUBPICTURE ) )
331     {
332         msg_Err( p_vout, "subpicture %p has invalid status %d",
333                          p_subpic, p_subpic->i_status );
334     }
335
336     while( p_subpic->p_region )
337     {
338         subpicture_region_t *p_region = p_subpic->p_region;
339         p_subpic->p_region = p_region->p_next;
340         spu_DestroyRegion( p_vout, p_region );
341     }
342
343     if( p_subpic->pf_destroy )
344     {
345         p_subpic->pf_destroy( p_subpic );
346     }
347
348     p_subpic->i_status = FREE_SUBPICTURE;
349
350     vlc_mutex_unlock( &p_vout->subpicture_lock );
351 }
352
353 /*****************************************************************************
354  * vout_RenderSubPictures: render a subpicture list
355  *****************************************************************************
356  * This function renders all sub picture units in the list.
357  *****************************************************************************/
358 void vout_RenderSubPictures( vout_thread_t *p_vout, picture_t *p_pic,
359                              subpicture_t *p_subpic )
360 {
361     /* Load the blending module */
362     if( !p_vout->p_blend && p_subpic && p_subpic->p_region )
363     {
364         p_vout->p_blend = vlc_object_create( p_vout, sizeof(filter_t) );
365         vlc_object_attach( p_vout->p_blend, p_vout );
366         p_vout->p_blend->fmt_out.video.i_width =
367             p_vout->p_blend->fmt_out.video.i_visible_width =
368                 p_vout->render.i_width;
369         p_vout->p_blend->fmt_out.video.i_height =
370             p_vout->p_blend->fmt_out.video.i_visible_height =
371                 p_vout->render.i_height;
372         p_vout->p_blend->fmt_out.video.i_x_offset =
373             p_vout->p_blend->fmt_out.video.i_y_offset = 0;
374         p_vout->p_blend->fmt_out.video.i_aspect =
375             p_vout->render.i_aspect;
376         p_vout->p_blend->fmt_out.video.i_chroma =
377             p_vout->output.i_chroma;
378
379         p_vout->p_blend->fmt_in.video = p_subpic->p_region->fmt;
380
381         p_vout->p_blend->p_module =
382             module_Need( p_vout->p_blend, "video blending", 0, 0 );
383     }
384
385     /* Get lock */
386     vlc_mutex_lock( &p_vout->subpicture_lock );
387
388     /* Check i_status again to make sure spudec hasn't destroyed the subpic */
389     while( p_subpic != NULL && p_subpic->i_status != FREE_SUBPICTURE )
390     {
391         subpicture_region_t *p_region = p_subpic->p_region;
392
393         if( p_subpic->pf_render )
394         {
395             p_subpic->pf_render( p_vout, p_pic, p_subpic );
396         }
397         else while( p_region && p_vout->p_blend &&
398                     p_vout->p_blend->pf_video_blend )
399         {
400             int i_x_offset = p_region->i_x + p_subpic->i_x;
401             int i_y_offset = p_region->i_y + p_subpic->i_y;
402
403             if( p_subpic->i_flags & OSD_ALIGN_BOTTOM )
404             {
405                 i_y_offset += p_vout->output.i_height - p_region->fmt.i_height;
406             }
407             else if ( !(p_subpic->i_flags & OSD_ALIGN_TOP) )
408             {
409                 i_y_offset += p_vout->output.i_height / 2 -
410                     p_region->fmt.i_height / 2;
411             }
412
413             if( p_subpic->i_flags & OSD_ALIGN_RIGHT )
414             {
415                 i_x_offset += p_vout->output.i_width - p_region->fmt.i_width;
416             }
417             else if ( !(p_subpic->i_flags & OSD_ALIGN_LEFT) )
418             {
419                 i_x_offset += p_vout->output.i_width / 2 -
420                     p_region->fmt.i_width / 2;
421             }
422
423             if( p_subpic->b_absolute )
424             {
425                 i_x_offset = p_region->i_x + p_subpic->i_x;
426                 i_y_offset = p_region->i_y + p_subpic->i_y;
427             }
428
429             p_vout->p_blend->fmt_in.video = p_region->fmt;
430
431             /* Force cropping if requested */
432             if( p_vout->b_force_crop )
433             {
434                 p_vout->p_blend->fmt_in.video.i_x_offset = p_vout->i_crop_x;
435                 p_vout->p_blend->fmt_in.video.i_y_offset = p_vout->i_crop_y;
436                 p_vout->p_blend->fmt_in.video.i_visible_width =
437                     p_vout->i_crop_width;
438                 p_vout->p_blend->fmt_in.video.i_visible_height =
439                     p_vout->i_crop_height;
440                 i_x_offset += p_vout->i_crop_x;
441                 i_y_offset += p_vout->i_crop_y;
442             }
443
444             /* Force palette if requested */
445             if( p_vout->b_force_alpha && VLC_FOURCC('Y','U','V','P') ==
446                 p_vout->p_blend->fmt_in.video.i_chroma )
447             {
448                 p_vout->p_blend->fmt_in.video.p_palette->palette[0][3] =
449                     p_vout->pi_alpha[0];
450                 p_vout->p_blend->fmt_in.video.p_palette->palette[1][3] =
451                     p_vout->pi_alpha[1];
452                 p_vout->p_blend->fmt_in.video.p_palette->palette[2][3] =
453                     p_vout->pi_alpha[2];
454                 p_vout->p_blend->fmt_in.video.p_palette->palette[3][3] =
455                     p_vout->pi_alpha[3];
456             }
457
458             p_vout->p_blend->pf_video_blend( p_vout->p_blend,
459                 p_pic, p_pic, &p_region->picture, i_x_offset, i_y_offset );
460
461             p_region = p_region->p_next;
462         }
463
464         p_subpic = p_subpic->p_next;
465     }
466
467     vlc_mutex_unlock( &p_vout->subpicture_lock );
468 }
469
470 /*****************************************************************************
471  * vout_SortSubPictures: find the subpictures to display
472  *****************************************************************************
473  * This function parses all subpictures and decides which ones need to be
474  * displayed. This operation does not need lock, since only READY_SUBPICTURE
475  * are handled. If no picture has been selected, display_date will depend on
476  * the subpicture.
477  * We also check for ephemer DVD subpictures (subpictures that have
478  * to be removed if a newer one is available), which makes it a lot
479  * more difficult to guess if a subpicture has to be rendered or not.
480  *****************************************************************************/
481 subpicture_t *vout_SortSubPictures( vout_thread_t *p_vout,
482                                     mtime_t display_date )
483 {
484     int i_index;
485     subpicture_t *p_subpic     = NULL;
486     subpicture_t *p_ephemer    = NULL;
487     mtime_t       ephemer_date = 0;
488
489     /* We get an easily parsable chained list of subpictures which
490      * ends with NULL since p_subpic was initialized to NULL. */
491     for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
492     {
493         if( p_vout->p_subpicture[i_index].i_status == READY_SUBPICTURE )
494         {
495             /* If it is a DVD subpicture, check its date */
496             if( p_vout->p_subpicture[i_index].i_type == MEMORY_SUBPICTURE )
497             {
498                 if( !p_vout->p_subpicture[i_index].b_ephemer
499                      && display_date > p_vout->p_subpicture[i_index].i_stop )
500                 {
501                     /* Too late, destroy the subpic */
502                     vout_DestroySubPicture( p_vout,
503                                     &p_vout->p_subpicture[i_index] );
504                     continue;
505                 }
506
507                 if( display_date
508                      && display_date < p_vout->p_subpicture[i_index].i_start )
509                 {
510                     /* Too early, come back next monday */
511                     continue;
512                 }
513
514                 /* If this is an ephemer subpic, see if it's the
515                  * youngest we have */
516                 if( p_vout->p_subpicture[i_index].b_ephemer )
517                 {
518                     if( p_ephemer == NULL )
519                     {
520                         p_ephemer = &p_vout->p_subpicture[i_index];
521                         continue;
522                     }
523
524                     if( p_vout->p_subpicture[i_index].i_start
525                                                      < p_ephemer->i_start )
526                     {
527                         /* Link the previous ephemer subpicture and
528                          * replace it with the current one */
529                         p_ephemer->p_next = p_subpic;
530                         p_subpic = p_ephemer;
531                         p_ephemer = &p_vout->p_subpicture[i_index];
532
533                         /* If it's the 2nd youngest subpicture,
534                          * register its date */
535                         if( !ephemer_date
536                               || ephemer_date > p_subpic->i_start )
537                         {
538                             ephemer_date = p_subpic->i_start;
539                         }
540
541                         continue;
542                     }
543                 }
544
545                 p_vout->p_subpicture[i_index].p_next = p_subpic;
546                 p_subpic = &p_vout->p_subpicture[i_index];
547
548                 /* If it's the 2nd youngest subpicture, register its date */
549                 if( !ephemer_date || ephemer_date > p_subpic->i_start )
550                 {
551                     ephemer_date = p_subpic->i_start;
552                 }
553             }
554             /* If it's not a DVD subpicture, just register it */
555             else
556             {
557                 p_vout->p_subpicture[i_index].p_next = p_subpic;
558                 p_subpic = &p_vout->p_subpicture[i_index];
559             }
560         }
561     }
562
563     /* If we found an ephemer subpicture, check if it has to be
564      * displayed */
565     if( p_ephemer != NULL )
566     {
567         if( p_ephemer->i_start < ephemer_date )
568         {
569             /* Ephemer subpicture has lived too long */
570             vout_DestroySubPicture( p_vout, p_ephemer );
571         }
572         else
573         {
574             /* Ephemer subpicture can still live a bit */
575             p_ephemer->p_next = p_subpic;
576             return p_ephemer;
577         }
578     }
579
580     return p_subpic;
581 }
582
583 /*****************************************************************************
584  * vout_RegisterOSDChannel: register an OSD channel
585  *****************************************************************************
586  * This function affects an ID to an OSD channel
587  *****************************************************************************/
588 int vout_RegisterOSDChannel( vout_thread_t *p_vout )
589 {
590     msg_Dbg( p_vout, "Registering OSD channel, ID: %i",
591              p_vout->i_channel_count + 1 );
592     return ++p_vout->i_channel_count;
593 }
594
595 /*****************************************************************************
596  * vout_ClearOSDChannel: clear an OSD channel
597  *****************************************************************************
598  * This function destroys the subpictures which belong to the OSD channel
599  * corresponding to i_channel_id.
600  *****************************************************************************/
601 void vout_ClearOSDChannel( vout_thread_t *p_vout, int i_channel )
602 {
603     int                 i_subpic;                        /* subpicture index */
604     subpicture_t *      p_subpic = NULL;            /* first free subpicture */
605
606     if( i_channel == DEFAULT_CHAN )
607     {
608         if( p_vout->p_default_channel != NULL )
609         {
610             vout_DestroySubPicture( p_vout, p_vout->p_default_channel );
611         }
612         p_vout->p_default_channel = NULL;
613         return;
614     }
615
616     vlc_mutex_lock( &p_vout->subpicture_lock );
617
618     for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
619     {
620         p_subpic = &p_vout->p_subpicture[i_subpic];
621         if( p_subpic->i_status == FREE_SUBPICTURE
622             || ( p_subpic->i_status != RESERVED_SUBPICTURE
623                  && p_subpic->i_status != READY_SUBPICTURE ) )
624         {
625             continue;
626         }
627
628         if( p_subpic->i_channel == i_channel )
629         {
630             while( p_subpic->p_region )
631             {
632                 subpicture_region_t *p_region = p_subpic->p_region;
633                 p_subpic->p_region = p_region->p_next;
634                 spu_DestroyRegion( p_vout, p_region );
635             }
636
637             if( p_subpic->pf_destroy )
638             {
639                 p_subpic->pf_destroy( p_subpic );
640             }
641             p_subpic->i_status = FREE_SUBPICTURE;
642         }
643     }
644
645     vlc_mutex_unlock( &p_vout->subpicture_lock );
646 }
647
648 /*****************************************************************************
649  * UpdateSPU: update subpicture settings
650  *****************************************************************************
651  * This function is called from CropCallback and at initialization time, to
652  * retrieve crop information from the input.
653  *****************************************************************************/
654 static void UpdateSPU( vout_thread_t *p_vout, vlc_object_t *p_object )
655 {
656     vlc_value_t val;
657
658     p_vout->b_force_alpha = VLC_FALSE;
659     p_vout->b_force_crop = VLC_FALSE;
660
661     if( var_Get( p_object, "highlight", &val ) || !val.b_bool ) return;
662
663     p_vout->b_force_crop = VLC_TRUE;
664     var_Get( p_object, "x-start", &val );
665     p_vout->i_crop_x = val.i_int;
666     var_Get( p_object, "y-start", &val );
667     p_vout->i_crop_y = val.i_int;
668     var_Get( p_object, "x-end", &val );
669     p_vout->i_crop_width = val.i_int - p_vout->i_crop_x;
670     var_Get( p_object, "y-end", &val );
671     p_vout->i_crop_height = val.i_int - p_vout->i_crop_y;
672
673 #if 0
674     if( var_Get( p_object, "color", &val ) == VLC_SUCCESS )
675     {
676         int i;
677         for( i = 0; i < 4; i++ )
678         {
679             p_vout->pi_color[i] = ((uint8_t *)val.p_address)[i];
680         }
681     }
682 #endif
683
684     if( var_Get( p_object, "contrast", &val ) == VLC_SUCCESS )
685     {
686         int i;
687         for( i = 0; i < 4; i++ )
688         {
689             p_vout->pi_alpha[i] = ((uint8_t *)val.p_address)[i];
690             p_vout->pi_alpha[i] = p_vout->pi_alpha[i] == 0xf ?
691                 0xff : p_vout->pi_alpha[i] << 4;
692         }
693         p_vout->b_force_alpha = VLC_TRUE;
694     }
695
696     msg_Dbg( p_vout, "crop: %i,%i,%i,%i, alpha: %i",
697              p_vout->i_crop_x, p_vout->i_crop_y,
698              p_vout->i_crop_width, p_vout->i_crop_height,
699              p_vout->b_force_alpha );
700 }
701
702 /*****************************************************************************
703  * CropCallback: called when the highlight properties are changed
704  *****************************************************************************
705  * This callback is called from the input thread when we need cropping
706  *****************************************************************************/
707 static int CropCallback( vlc_object_t *p_object, char const *psz_var,
708                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
709 {
710     UpdateSPU( (vout_thread_t *)p_data, p_object );
711     return VLC_SUCCESS;
712 }
713
714 /*****************************************************************************
715  * Buffers allocation callbacks for the filters
716  *****************************************************************************/
717 static subpicture_t *spu_new_buffer( filter_t *p_filter )
718 {
719     vout_thread_t *p_vout = (vout_thread_t *)p_filter->p_owner;
720     subpicture_t *p_spu;
721
722     p_spu = vout_CreateSubPicture( p_vout, !DEFAULT_CHAN, MEMORY_SUBPICTURE );
723     return p_spu;
724 }
725
726 static void spu_del_buffer( filter_t *p_filter, subpicture_t *p_spu )
727 {
728     vout_thread_t *p_vout = (vout_thread_t *)p_filter->p_owner;
729     vout_DestroySubPicture( p_vout, p_spu );
730 }