]> git.sesse.net Git - vlc/blob - modules/codec/zvbi.c
Remove most stray semi-colons in module descriptions
[vlc] / modules / codec / zvbi.c
1 /*****************************************************************************
2  * zvbi.c : VBI and Teletext PES demux and decoder using libzvbi
3  *****************************************************************************
4  * Copyright (C) 2007, M2X
5  * $Id$
6  *
7  * Authors: Derk-Jan Hartman <djhartman at m2x dot nl>
8  *          Jean-Paul Saman <jpsaman at m2x dot nl>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24 /*****************************************************************************
25  *
26  * information on teletext format can be found here :
27  * http://pdc.ro.nu/teletext.html
28  *
29  *****************************************************************************/
30
31 /* This module implements:
32  * ETSI EN 301 775: VBI data in PES
33  * ETSI EN 300 472: EBU Teletext data in PES
34  * ETSI EN 300 706: Enhanced Teletext (libzvbi)
35  * ETSI EN 300 231: Video Programme System [VPS] (libzvbi)
36  * ETSI EN 300 294: 625-line Wide Screen Signaling [WSS] (libzvbi)
37  * EIA-608 Revision A: Closed Captioning [CC] (libzvbi)
38  */
39
40 #ifdef HAVE_CONFIG_H
41 # include "config.h"
42 #endif
43
44 #include <vlc_common.h>
45 #include <vlc_plugin.h>
46 #include <assert.h>
47 #include <libzvbi.h>
48
49 #include <vlc_vout.h>
50 #include <vlc_codec.h>
51 #include <vlc_osd.h>
52
53 /*****************************************************************************
54  * Module descriptor.
55  *****************************************************************************/
56 static int  Open ( vlc_object_t * );
57 static void Close( vlc_object_t * );
58
59 #define PAGE_TEXT N_("Teletext page")
60 #define PAGE_LONGTEXT N_("Open the indicated Teletext page." \
61         "Default page is index 100")
62
63 #define OPAQUE_TEXT N_("Text is always opaque")
64 #define OPAQUE_LONGTEXT N_("Setting vbi-opaque to false " \
65         "makes the boxed text transparent." )
66
67 #define POS_TEXT N_("Teletext alignment")
68 #define POS_LONGTEXT N_( \
69   "You can enforce the teletext position on the video " \
70   "(0=center, 1=left, 2=right, 4=top, 8=bottom, you can " \
71   "also use combinations of these values, eg. 6 = top-right).")
72
73 #define TELX_TEXT N_("Teletext text subtitles")
74 #define TELX_LONGTEXT N_( "Output teletext subtitles as text " \
75   "instead of as RGBA" )
76
77 static const int pi_pos_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 };
78 static const char *const ppsz_pos_descriptions[] =
79 { N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"),
80   N_("Top-Left"), N_("Top-Right"), N_("Bottom-Left"), N_("Bottom-Right") };
81
82 vlc_module_begin ()
83     set_description( N_("VBI and Teletext decoder") )
84     set_shortname( N_("VBI & Teletext") )
85     set_capability( "decoder", 51 )
86     set_category( CAT_INPUT )
87     set_subcategory( SUBCAT_INPUT_SCODEC )
88     set_callbacks( Open, Close )
89
90     add_integer( "vbi-page", 100, NULL,
91                  PAGE_TEXT, PAGE_LONGTEXT, false );
92     add_bool( "vbi-opaque", true, NULL,
93                  OPAQUE_TEXT, OPAQUE_LONGTEXT, false );
94     add_integer( "vbi-position", 4, NULL, POS_TEXT, POS_LONGTEXT, false )
95         change_integer_list( pi_pos_values, ppsz_pos_descriptions, NULL );
96     add_bool( "vbi-text", false, NULL,
97               TELX_TEXT, TELX_LONGTEXT, false );
98 vlc_module_end ()
99
100 /****************************************************************************
101  * Local structures
102  ****************************************************************************/
103
104 // #define ZVBI_DEBUG
105
106 //Guessing table for missing "default region triplet"
107 static const int pi_default_triplet[] = {
108  0, 0,           // slo cze
109  8,              // pol
110  24,24,24,24,    //ssc scr slv rum
111  32,32,32,32,32, //est lit rus bul ukr
112  48,48,          //gre ell
113  64,             //ara
114  88,             //heb
115  16 };           //default
116 static const char *const ppsz_default_triplet[] = {
117  "slo", "cze",
118  "pol",
119  "ssc", "scr", "slv", "rum",
120  "est", "lit", "rus", "bul", "ukr",
121  "gre", "ell",
122  "ara",
123  "heb",
124  NULL
125 };
126
127 typedef enum {
128     ZVBI_KEY_RED    = 'r' << 16,
129     ZVBI_KEY_GREEN  = 'g' << 16,
130     ZVBI_KEY_YELLOW = 'y' << 16,
131     ZVBI_KEY_BLUE   = 'b' << 16,
132     ZVBI_KEY_INDEX  = 'i' << 16,
133 } ttxt_key_id;
134
135 typedef enum {
136     DATA_UNIT_EBU_TELETEXT_NON_SUBTITLE     = 0x02,
137     DATA_UNIT_EBU_TELETEXT_SUBTITLE         = 0x03,
138     DATA_UNIT_EBU_TELETEXT_INVERTED         = 0x0C,
139
140     DATA_UNIT_ZVBI_WSS_CPR1204              = 0xB4,
141     DATA_UNIT_ZVBI_CLOSED_CAPTION_525       = 0xB5,
142     DATA_UNIT_ZVBI_MONOCHROME_SAMPLES_525   = 0xB6,
143
144     DATA_UNIT_VPS                           = 0xC3,
145     DATA_UNIT_WSS                           = 0xC4,
146     DATA_UNIT_CLOSED_CAPTION                = 0xC5,
147     DATA_UNIT_MONOCHROME_SAMPLES            = 0xC6,
148
149     DATA_UNIT_STUFFING                      = 0xFF,
150 } data_unit_id;
151
152 struct decoder_sys_t
153 {
154     vbi_decoder *     p_vbi_dec;
155     vbi_dvb_demux *   p_dvb_demux;
156     unsigned int      i_last_page;
157     bool              b_update;
158     bool              b_text;   /* Subtitles as text */
159
160     vlc_mutex_t       lock; /* Lock to protect the following variables */
161     /* Positioning of Teletext images */
162     int               i_align;
163     /* */
164     unsigned int      i_wanted_page;
165     unsigned int      i_wanted_subpage;
166     /* */
167     bool              b_opaque;
168     struct {
169         int pgno, subno;
170     }                 nav_link[6];
171     int               i_key[3];
172 };
173
174 static subpicture_t *Decode( decoder_t *, block_t ** );
175
176 static subpicture_t *Subpicture( decoder_t *p_dec, video_format_t *p_fmt,
177                                  bool b_text,
178                                  int i_columns, int i_rows,
179                                  int i_align, mtime_t i_pts );
180
181 static void EventHandler( vbi_event *ev, void *user_data );
182 static int OpaquePage( picture_t *p_src, const vbi_page p_page,
183                        const video_format_t fmt, bool b_opaque );
184
185 /* Properties callbacks */
186 static int RequestPage( vlc_object_t *p_this, char const *psz_cmd,
187                         vlc_value_t oldval, vlc_value_t newval, void *p_data );
188 static int Opaque( vlc_object_t *p_this, char const *psz_cmd,
189                    vlc_value_t oldval, vlc_value_t newval, void *p_data );
190 static int Position( vlc_object_t *p_this, char const *psz_cmd,
191                      vlc_value_t oldval, vlc_value_t newval, void *p_data );
192 static int EventKey( vlc_object_t *p_this, char const *psz_cmd,
193                      vlc_value_t oldval, vlc_value_t newval, void *p_data );
194
195 /*****************************************************************************
196  * Open: probe the decoder and return score
197  *****************************************************************************
198  * Tries to launch a decoder and return score so that the interface is able
199  * to chose.
200  *****************************************************************************/
201 static int Open( vlc_object_t *p_this )
202 {
203     decoder_t     *p_dec = (decoder_t *) p_this;
204     decoder_sys_t *p_sys = NULL;
205
206     if( p_dec->fmt_in.i_codec != VLC_FOURCC('t','e','l','x') )
207         return VLC_EGENERIC;
208
209     p_dec->pf_decode_sub = Decode;
210     p_sys = p_dec->p_sys = malloc( sizeof(decoder_sys_t) );
211     if( p_sys == NULL )
212         return VLC_ENOMEM;
213     memset( p_sys, 0, sizeof(decoder_sys_t) );
214
215     p_sys->i_key[0] = p_sys->i_key[1] = p_sys->i_key[2] = '*' - '0';
216     p_sys->b_update = false;
217     p_sys->p_vbi_dec = vbi_decoder_new();
218     p_sys->p_dvb_demux = vbi_dvb_pes_demux_new( NULL, NULL );
219     vlc_mutex_init( &p_sys->lock );
220
221     if( (p_sys->p_vbi_dec == NULL) || (p_sys->p_dvb_demux == NULL) )
222     {
223         msg_Err( p_dec, "VBI decoder/demux could not be created." );
224         Close( p_this );
225         return VLC_ENOMEM;
226     }
227
228     /* Some broadcasters in countries with level 1 and level 1.5 still not send a G0 to do 
229      * matches against table 32 of ETSI 300 706. We try to do some best effort guessing
230      * This is not perfect, but might handle some cases where we know the vbi language 
231      * is known. It would be better if people started sending G0 */
232     for( int i = 0; ppsz_default_triplet[i] != NULL; i++ )
233     {
234         if( p_dec->fmt_in.psz_language && !strcasecmp( p_dec->fmt_in.psz_language, ppsz_default_triplet[i] ) )
235         {
236             vbi_teletext_set_default_region( p_sys->p_vbi_dec, pi_default_triplet[i]);
237             msg_Dbg( p_dec, "overwriting default zvbi region: %d", pi_default_triplet[i] );
238         }
239     }
240
241     vbi_event_handler_register( p_sys->p_vbi_dec, VBI_EVENT_TTX_PAGE | VBI_EVENT_NETWORK |
242 #ifdef ZVBI_DEBUG
243                                 VBI_EVENT_CAPTION | VBI_EVENT_TRIGGER |
244                                 VBI_EVENT_ASPECT | VBI_EVENT_PROG_INFO | VBI_EVENT_NETWORK_ID |
245 #endif
246                                 0 , EventHandler, p_dec );
247
248     /* Create the var on vlc_global. */
249     p_sys->i_wanted_page = var_CreateGetInteger( p_dec, "vbi-page" );
250     var_AddCallback( p_dec, "vbi-page",
251                      RequestPage, p_sys );
252
253     /* Check if the Teletext track has a known "initial page". */
254     if( p_sys->i_wanted_page == 100 && p_dec->fmt_in.subs.dvb.i_id != -1 )
255     {
256         int i_wanted_magazine = p_dec->fmt_in.subs.dvb.i_id >> 16;
257         if( i_wanted_magazine == 0 )
258             i_wanted_magazine = 8;
259         p_sys->i_wanted_page = vbi_bcd2dec(p_dec->fmt_in.subs.dvb.i_id & 0xff);
260         p_sys->i_wanted_page += 100*i_wanted_magazine;
261     }
262     p_sys->i_wanted_subpage = VBI_ANY_SUBNO;
263
264     p_sys->b_opaque = var_CreateGetBool( p_dec, "vbi-opaque" );
265     var_AddCallback( p_dec, "vbi-opaque", Opaque, p_sys );
266
267     p_sys->i_align = var_CreateGetInteger( p_dec, "vbi-position" );
268     var_AddCallback( p_dec, "vbi-position", Position, p_sys );
269
270     p_sys->b_text = var_CreateGetBool( p_dec, "vbi-text" );
271 //    var_AddCallback( p_dec, "vbi-text", Text, p_sys );
272
273     /* Listen for keys */
274     var_AddCallback( p_dec->p_libvlc, "key-pressed", EventKey, p_sys );
275
276     es_format_Init( &p_dec->fmt_out, SPU_ES, VLC_FOURCC( 's','p','u',' ' ) );
277     if( p_sys->b_text )
278         p_dec->fmt_out.video.i_chroma = VLC_FOURCC('T','E','X','T');
279     else
280         p_dec->fmt_out.video.i_chroma = VLC_FOURCC('R','G','B','A');
281     return VLC_SUCCESS;
282 }
283
284 /*****************************************************************************
285  * Close:
286  *****************************************************************************/
287 static void Close( vlc_object_t *p_this )
288 {
289     decoder_t     *p_dec = (decoder_t*) p_this;
290     decoder_sys_t *p_sys = p_dec->p_sys;
291
292     var_DelCallback( p_dec, "vbi-position", Position, p_sys );
293     var_DelCallback( p_dec, "vbi-opaque", Opaque, p_sys );
294     var_DelCallback( p_dec, "vbi-page", RequestPage, p_sys );
295     var_DelCallback( p_dec->p_libvlc, "key-pressed", EventKey, p_sys );
296
297     vlc_mutex_destroy( &p_sys->lock );
298
299     if( p_sys->p_vbi_dec )
300         vbi_decoder_delete( p_sys->p_vbi_dec );
301     if( p_sys->p_dvb_demux )
302         vbi_dvb_demux_delete( p_sys->p_dvb_demux );
303     free( p_sys );
304 }
305
306 #define MAX_SLICES 32
307
308 #ifdef WORDS_BIGENDIAN
309 # define ZVBI_PIXFMT_RGBA32 VBI_PIXFMT_RGBA32_BE
310 #else
311 # define ZVBI_PIXFMT_RGBA32 VBI_PIXFMT_RGBA32_LE
312 #endif
313
314
315 /*****************************************************************************
316  * Decode:
317  *****************************************************************************/
318 static subpicture_t *Decode( decoder_t *p_dec, block_t **pp_block )
319 {
320     decoder_sys_t   *p_sys = p_dec->p_sys;
321     block_t         *p_block;
322     subpicture_t    *p_spu = NULL;
323     video_format_t  fmt;
324     bool            b_cached = false;
325     vbi_page        p_page;
326     const uint8_t   *p_pos;
327     unsigned int    i_left;
328
329     if( (pp_block == NULL) || (*pp_block == NULL) )
330         return NULL;
331
332     p_block = *pp_block;
333     *pp_block = NULL;
334
335     p_pos = p_block->p_buffer;
336     i_left = p_block->i_buffer;
337
338     while( i_left > 0 )
339     {
340         vbi_sliced      p_sliced[MAX_SLICES];
341         unsigned int    i_lines = 0;
342         int64_t         i_pts;
343
344         i_lines = vbi_dvb_demux_cor( p_sys->p_dvb_demux, p_sliced,
345                                      MAX_SLICES, &i_pts, &p_pos, &i_left );
346
347         if( i_lines > 0 )
348             vbi_decode( p_sys->p_vbi_dec, p_sliced, i_lines, i_pts / 90000.0 );
349     }
350
351     /* */
352     vlc_mutex_lock( &p_sys->lock );
353     const int i_align = p_sys->i_align;
354     const unsigned int i_wanted_page = p_sys->i_wanted_page;
355     const unsigned int i_wanted_subpage = p_sys->i_wanted_subpage;
356     const bool b_opaque = p_sys->b_opaque;
357     vlc_mutex_unlock( &p_sys->lock );
358
359     /* Try to see if the page we want is in the cache yet */
360     b_cached = vbi_fetch_vt_page( p_sys->p_vbi_dec, &p_page,
361                                   vbi_dec2bcd( i_wanted_page ),
362                                   i_wanted_subpage, VBI_WST_LEVEL_3p5,
363                                   25, true );
364
365     if( i_wanted_page == p_sys->i_last_page && !p_sys->b_update )
366         goto error;
367
368     if( !b_cached )
369     {
370         if( p_sys->i_last_page != i_wanted_page )
371         {
372             /* We need to reset the subtitle */
373             p_spu = Subpicture( p_dec, &fmt, true,
374                                 p_page.columns, p_page.rows,
375                                 i_align, p_block->i_pts );
376             if( !p_spu )
377                 goto error;
378             p_spu->p_region->psz_text = strdup("");
379
380             p_sys->b_update = true;
381             p_sys->i_last_page = i_wanted_page;
382             goto exit;
383         }
384         goto error;
385     }
386
387     p_sys->b_update = false;
388     p_sys->i_last_page = i_wanted_page;
389 #ifdef ZVBI_DEBUG
390     msg_Dbg( p_dec, "we now have page: %d ready for display",
391              i_wanted_page );
392 #endif
393     /* If there is a page or sub to render, then we do that here */
394     /* Create the subpicture unit */
395     p_spu = Subpicture( p_dec, &fmt, p_sys->b_text,
396                         p_page.columns, p_page.rows,
397                         i_align, p_block->i_pts );
398     if( !p_spu )
399         goto error;
400
401     if( p_sys->b_text )
402     {
403         unsigned int i_textsize = 7000;
404         int i_total;
405         char p_text[i_textsize+1];
406
407         i_total = vbi_print_page_region( &p_page, p_text, i_textsize,
408                         "UTF-8", 0, 0, 0, 0, p_page.columns, p_page.rows );
409         p_text[i_total] = '\0';
410         /* Strip off the pagenumber */
411         if( i_total <= 40 )
412             goto error;
413         p_spu->p_region->psz_text = strdup( &p_text[8] );
414
415 #ifdef ZVBI_DEBUG
416         msg_Info( p_dec, "page %x-%x(%d)\n%s", p_page.pgno, p_page.subno, i_total, p_text );
417 #endif
418     }
419     else
420     {
421         picture_t *p_pic = p_spu->p_region->p_picture;
422
423         /* ZVBI is stupid enough to assume pitch == width */
424         p_pic->p->i_pitch = 4 * fmt.i_width;
425         vbi_draw_vt_page( &p_page, ZVBI_PIXFMT_RGBA32,
426                           p_spu->p_region->p_picture->p->p_pixels, 1, 1 );
427
428         vlc_mutex_lock( &p_sys->lock );
429         memcpy( p_sys->nav_link, &p_page.nav_link, sizeof( p_sys->nav_link )) ;
430         vlc_mutex_unlock( &p_sys->lock );
431
432         OpaquePage( p_pic, p_page, fmt, b_opaque );
433     }
434
435 exit:
436     vbi_unref_page( &p_page );
437     block_Release( p_block );
438     return p_spu;
439
440 error:
441     vbi_unref_page( &p_page );
442     if( p_spu != NULL )
443     {
444         decoder_DeleteSubpicture( p_dec, p_spu );
445         p_spu = NULL;
446     }
447
448     block_Release( p_block );
449     return NULL;
450 }
451
452 static subpicture_t *Subpicture( decoder_t *p_dec, video_format_t *p_fmt,
453                                  bool b_text,
454                                  int i_columns, int i_rows, int i_align,
455                                  mtime_t i_pts )
456 {
457     video_format_t fmt;
458     subpicture_t *p_spu;
459
460     /* If there is a page or sub to render, then we do that here */
461     /* Create the subpicture unit */
462     p_spu = decoder_NewSubpicture( p_dec );
463     if( !p_spu )
464     {
465         msg_Warn( p_dec, "can't get spu buffer" );
466         return NULL;
467     }
468
469     memset( &fmt, 0, sizeof(video_format_t) );
470     fmt.i_chroma = b_text ? VLC_FOURCC('T','E','X','T') :
471                                    VLC_FOURCC('R','G','B','A');
472     fmt.i_aspect = b_text ? 0 : VOUT_ASPECT_FACTOR;
473     if( b_text )
474     {
475         fmt.i_bits_per_pixel = 0;
476     }
477     else
478     {
479         fmt.i_sar_num = fmt.i_sar_den = 1;
480         fmt.i_width = fmt.i_visible_width = i_columns * 12;
481         fmt.i_height = fmt.i_visible_height = i_rows * 10;
482         fmt.i_bits_per_pixel = 32;
483     }
484     fmt.i_x_offset = fmt.i_y_offset = 0;
485
486     p_spu->p_region = subpicture_region_New( &fmt );
487     if( p_spu->p_region == NULL )
488     {
489         msg_Err( p_dec, "cannot allocate SPU region" );
490         decoder_DeleteSubpicture( p_dec, p_spu );
491         return NULL;
492     }
493
494     p_spu->p_region->i_x = 0;
495     p_spu->p_region->i_y = 0;
496     p_spu->p_region->i_align = i_align;
497
498     p_spu->i_start = i_pts;
499     p_spu->i_stop = 0;
500     p_spu->b_ephemer = true;
501     p_spu->b_absolute = false;
502
503     if( !b_text )
504     {
505         p_spu->i_original_picture_width = fmt.i_width;
506         p_spu->i_original_picture_height = fmt.i_height;
507     }
508
509     /* */
510     *p_fmt = fmt;
511     return p_spu;
512 }
513
514 static void EventHandler( vbi_event *ev, void *user_data )
515 {
516     decoder_t *p_dec        = (decoder_t *)user_data;
517     decoder_sys_t *p_sys    = p_dec->p_sys;
518
519     if( ev->type == VBI_EVENT_TTX_PAGE )
520     {
521 #ifdef ZVBI_DEBUG
522         msg_Info( p_dec, "Page %03x.%02x ",
523                     ev->ev.ttx_page.pgno,
524                     ev->ev.ttx_page.subno & 0xFF);
525 #endif
526         if( p_sys->i_last_page == vbi_bcd2dec( ev->ev.ttx_page.pgno ) )
527             p_sys->b_update = true;
528 #ifdef ZVBI_DEBUG
529         if( ev->ev.ttx_page.clock_update )
530             msg_Dbg( p_dec, "clock" );
531         if( ev->ev.ttx_page.header_update )
532             msg_Dbg( p_dec, "header" );
533 #endif
534     }
535     else if( ev->type == VBI_EVENT_CLOSE )
536         msg_Dbg( p_dec, "Close event" );
537     else if( ev->type == VBI_EVENT_CAPTION )
538         msg_Dbg( p_dec, "Caption line: %x", ev->ev.caption.pgno );
539     else if( ev->type == VBI_EVENT_NETWORK )
540     {
541         msg_Dbg( p_dec, "Network change");
542         vbi_network n = ev->ev.network;
543         msg_Dbg( p_dec, "Network id:%d name: %s, call: %s ", n.nuid, n.name, n.call );
544     }
545     else if( ev->type == VBI_EVENT_TRIGGER )
546         msg_Dbg( p_dec, "Trigger event" );
547     else if( ev->type == VBI_EVENT_ASPECT )
548         msg_Dbg( p_dec, "Aspect update" );
549     else if( ev->type == VBI_EVENT_PROG_INFO )
550         msg_Dbg( p_dec, "Program info received" );
551     else if( ev->type == VBI_EVENT_NETWORK_ID )
552         msg_Dbg( p_dec, "Network ID changed" );
553 }
554
555 static int OpaquePage( picture_t *p_src, const vbi_page p_page,
556                        const video_format_t fmt, bool b_opaque )
557 {
558     unsigned int    x, y;
559
560     assert( fmt.i_chroma == VLC_FOURCC('R','G','B','A' ) );
561
562     /* Kludge since zvbi doesn't provide an option to specify opacity. */
563     for( y = 0; y < fmt.i_height; y++ )
564     {
565         for( x = 0; x < fmt.i_width; x++ )
566         {
567             const vbi_opacity opacity = p_page.text[ y/10 * p_page.columns + x/12 ].opacity;
568             const int background = p_page.text[ y/10 * p_page.columns + x/12 ].background;
569             uint32_t *p_pixel = (uint32_t*)&p_src->p->p_pixels[y * p_src->p->i_pitch + 4*x];
570
571             switch( opacity )
572             {
573             /* Show video instead of this character */
574             case VBI_TRANSPARENT_SPACE:
575                 *p_pixel = 0;
576                 break;
577             /* Display foreground and background color */
578             /* To make the boxed text "closed captioning" transparent
579              * change true to false.
580              */
581             case VBI_OPAQUE:
582             /* alpha blend video into background color */
583             case VBI_SEMI_TRANSPARENT:
584                 if( b_opaque )
585                     break;
586             /* Full text transparency. only foreground color is show */
587             case VBI_TRANSPARENT_FULL:
588                 if( (*p_pixel) == (0xff000000 | p_page.color_map[background] ) )
589                     *p_pixel = 0;
590                 break;
591             }
592         }
593     }
594     /* end of kludge */
595     return VLC_SUCCESS;
596 }
597
598 /* Callbacks */
599 static int RequestPage( vlc_object_t *p_this, char const *psz_cmd,
600                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
601 {
602     decoder_sys_t *p_sys = p_data;
603     VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
604
605     vlc_mutex_lock( &p_sys->lock );
606     switch( newval.i_int )
607     {
608         case ZVBI_KEY_RED:
609             p_sys->i_wanted_page = vbi_bcd2dec( p_sys->nav_link[0].pgno );
610             p_sys->i_wanted_subpage = p_sys->nav_link[0].subno;
611             break;
612         case ZVBI_KEY_GREEN:
613             p_sys->i_wanted_page = vbi_bcd2dec( p_sys->nav_link[1].pgno );
614             p_sys->i_wanted_subpage = p_sys->nav_link[1].subno;
615             break;
616         case ZVBI_KEY_YELLOW:
617             p_sys->i_wanted_page = vbi_bcd2dec( p_sys->nav_link[2].pgno );
618             p_sys->i_wanted_subpage = p_sys->nav_link[2].subno;
619             break;
620         case ZVBI_KEY_BLUE:
621             p_sys->i_wanted_page = vbi_bcd2dec( p_sys->nav_link[3].pgno );
622             p_sys->i_wanted_subpage = p_sys->nav_link[3].subno;
623             break;
624         case ZVBI_KEY_INDEX:
625             p_sys->i_wanted_page = vbi_bcd2dec( p_sys->nav_link[5].pgno ); /* #4 is SKIPPED */
626             p_sys->i_wanted_subpage = p_sys->nav_link[5].subno;
627             break;
628     }
629     if( newval.i_int > 0 && newval.i_int < 999 )
630     {
631         p_sys->i_wanted_page = newval.i_int;
632         p_sys->i_wanted_subpage = VBI_ANY_SUBNO;
633     }
634     vlc_mutex_unlock( &p_sys->lock );
635
636     return VLC_SUCCESS;
637 }
638
639 static int Opaque( vlc_object_t *p_this, char const *psz_cmd,
640                    vlc_value_t oldval, vlc_value_t newval, void *p_data )
641 {
642     decoder_sys_t *p_sys = p_data;
643     VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
644
645     vlc_mutex_lock( &p_sys->lock );
646     p_sys->b_opaque = newval.b_bool;
647     p_sys->b_update = true;
648     vlc_mutex_unlock( &p_sys->lock );
649
650     return VLC_SUCCESS;
651 }
652
653 static int Position( vlc_object_t *p_this, char const *psz_cmd,
654                      vlc_value_t oldval, vlc_value_t newval, void *p_data )
655 {
656     decoder_sys_t *p_sys = p_data;
657     VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
658
659     vlc_mutex_lock( &p_sys->lock );
660     p_sys->i_align = newval.i_int;
661     vlc_mutex_unlock( &p_sys->lock );
662
663     return VLC_SUCCESS;
664 }
665
666 static int EventKey( vlc_object_t *p_this, char const *psz_cmd,
667                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
668 {
669     decoder_sys_t *p_sys = p_data;
670     VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
671
672     /* FIXME: Capture + and - key for subpage browsing */
673     if( newval.i_int == '-' || newval.i_int == '+' )
674     {
675         vlc_mutex_lock( &p_sys->lock );
676         if( p_sys->i_wanted_subpage == VBI_ANY_SUBNO && newval.i_int == '+' )
677             p_sys->i_wanted_subpage = vbi_dec2bcd(1);
678         else if ( newval.i_int == '+' )
679             p_sys->i_wanted_subpage = vbi_add_bcd( p_sys->i_wanted_subpage, 1);
680         else if( newval.i_int == '-')
681             p_sys->i_wanted_subpage = vbi_add_bcd( p_sys->i_wanted_subpage, 0xF9999999); /* BCD complement - 1 */
682
683         if ( !vbi_bcd_digits_greater( p_sys->i_wanted_subpage, 0x00 ) || vbi_bcd_digits_greater( p_sys->i_wanted_subpage, 0x99 ) )
684                 p_sys->i_wanted_subpage = VBI_ANY_SUBNO;
685         else
686             vout_OSDMessage( p_this, DEFAULT_CHAN, "%s: %d", _("Subpage"), vbi_bcd2dec( p_sys->i_wanted_subpage) );
687
688         p_sys->b_update = true;
689         vlc_mutex_unlock( &p_sys->lock );
690     }
691
692     /* Capture 0-9 for page selection */
693     if( newval.i_int < '0' || newval.i_int > '9' )
694         return VLC_SUCCESS;
695
696     vlc_mutex_lock( &p_sys->lock );
697     p_sys->i_key[0] = p_sys->i_key[1];
698     p_sys->i_key[1] = p_sys->i_key[2];
699     p_sys->i_key[2] = (int)(newval.i_int - '0');
700     vout_OSDMessage( p_this, DEFAULT_CHAN, "%s: %c%c%c", _("Page"), (char)(p_sys->i_key[0]+'0'), (char)(p_sys->i_key[1]+'0'), (char)(p_sys->i_key[2]+'0') );
701
702     if( p_sys->i_key[0] > 0 && p_sys->i_key[0] <= 8 &&
703         p_sys->i_key[1] >= 0 && p_sys->i_key[1] <= 9 &&
704         p_sys->i_key[2] >= 0 && p_sys->i_key[2] <= 9 )
705     {
706         p_sys->i_wanted_page = p_sys->i_key[0]*100 + p_sys->i_key[1]*10 + p_sys->i_key[2];
707         p_sys->i_wanted_subpage = VBI_ANY_SUBNO;
708         p_sys->i_key[0] = p_sys->i_key[1] = p_sys->i_key[2] = '*' - '0';
709     }
710     vlc_mutex_unlock( &p_sys->lock );
711
712     return VLC_SUCCESS;
713 }