]> git.sesse.net Git - vlc/blobdiff - modules/codec/zvbi.c
fix teletext framing code in DVB PES packets ignored
[vlc] / modules / codec / zvbi.c
index 209c64ffb5b88a4c4ea6d6ecb59c2235944158b3..17b8b5a0a0eb4e64ebec91368010763ab770b770 100644 (file)
@@ -331,17 +331,20 @@ static subpicture_t *Decode( decoder_t *p_dec, block_t **pp_block )
 
             if( ( i_id == 0x02 || i_id == 0x03 ) && i_size >= 44 && i_lines < MAX_SLICES )
             {
-                unsigned line_offset  = p_block->p_buffer[2] & 0x1f;
-                unsigned field_parity = p_block->p_buffer[2] & 0x20;
-
-                p_sliced[i_lines].id = VBI_SLICED_TELETEXT_B;
-                if( line_offset > 0 )
-                    p_sliced[i_lines].line = line_offset + (field_parity ? 0 : 313);
-                else
-                    p_sliced[i_lines].line = 0;
-                for( int i = 0; i < 42; i++ )
-                    p_sliced[i_lines].data[i] = vbi_rev8( p_block->p_buffer[4 + i] );
-                i_lines++;
+                if(p_block->p_buffer[3] == 0xE4 )    /* framing_code */
+                {
+                    unsigned line_offset  = p_block->p_buffer[2] & 0x1f;
+                    unsigned field_parity = p_block->p_buffer[2] & 0x20;
+
+                    p_sliced[i_lines].id = VBI_SLICED_TELETEXT_B;
+                    if( line_offset > 0 )
+                        p_sliced[i_lines].line = line_offset + (field_parity ? 0 : 313);
+                    else
+                        p_sliced[i_lines].line = 0;
+                    for( int i = 0; i < 42; i++ )
+                        p_sliced[i_lines].data[i] = vbi_rev8( p_block->p_buffer[4 + i] );
+                    i_lines++;
+                }
             }
 
             p_block->i_buffer -= 2 + i_size;
@@ -372,7 +375,7 @@ static subpicture_t *Decode( decoder_t *p_dec, block_t **pp_block )
 
     if( !b_cached )
     {
-        if( p_sys->i_last_page != i_wanted_page )
+        if( p_sys->b_text && p_sys->i_last_page != i_wanted_page )
         {
             /* We need to reset the subtitle */
             p_spu = Subpicture( p_dec, &fmt, true,
@@ -503,10 +506,7 @@ static subpicture_t *Subpicture( decoder_t *p_dec, video_format_t *p_fmt,
         return NULL;
     }
 
-    memset( &fmt, 0, sizeof(video_format_t) );
-    fmt.i_chroma = b_text ? VLC_CODEC_TEXT : VLC_CODEC_RGBA;
-    fmt.i_sar_num = 0;
-    fmt.i_sar_den = 1;
+    video_format_Init(&fmt, b_text ? VLC_CODEC_TEXT : VLC_CODEC_RGBA);
     if( b_text )
     {
         fmt.i_bits_per_pixel = 0;
@@ -516,6 +516,7 @@ static subpicture_t *Subpicture( decoder_t *p_dec, video_format_t *p_fmt,
         fmt.i_width = fmt.i_visible_width = i_columns * 12;
         fmt.i_height = fmt.i_visible_height = i_rows * 10;
         fmt.i_bits_per_pixel = 32;
+        fmt.i_sar_num = fmt.i_sar_den = 0; /* let the vout set the correct AR */
     }
     fmt.i_x_offset = fmt.i_y_offset = 0;
 
@@ -523,7 +524,7 @@ static subpicture_t *Subpicture( decoder_t *p_dec, video_format_t *p_fmt,
     if( p_spu->p_region == NULL )
     {
         msg_Err( p_dec, "cannot allocate SPU region" );
-        decoder_DeleteSubpicture( p_dec, p_spu );
+        subpicture_Delete( p_spu );
         return NULL;
     }
 
@@ -605,7 +606,7 @@ static int get_last_visible_row( vbi_char *p_text, int rows, int columns)
     {
         if (p_text[i].opacity != VBI_TRANSPARENT_SPACE)
         {
-            return ( i + columns - 1) / columns;
+            return i / columns;
         }
     }
 
@@ -661,32 +662,37 @@ static int RequestPage( vlc_object_t *p_this, char const *psz_cmd,
 {
     decoder_sys_t *p_sys = p_data;
     VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
+    int want_navlink = -1;
 
     vlc_mutex_lock( &p_sys->lock );
     switch( newval.i_int )
     {
         case ZVBI_KEY_RED:
-            p_sys->i_wanted_page = vbi_bcd2dec( p_sys->nav_link[0].pgno );
-            p_sys->i_wanted_subpage = p_sys->nav_link[0].subno;
+            want_navlink = 0;
             break;
         case ZVBI_KEY_GREEN:
-            p_sys->i_wanted_page = vbi_bcd2dec( p_sys->nav_link[1].pgno );
-            p_sys->i_wanted_subpage = p_sys->nav_link[1].subno;
+            want_navlink = 1;
             break;
         case ZVBI_KEY_YELLOW:
-            p_sys->i_wanted_page = vbi_bcd2dec( p_sys->nav_link[2].pgno );
-            p_sys->i_wanted_subpage = p_sys->nav_link[2].subno;
+            want_navlink = 2;
             break;
         case ZVBI_KEY_BLUE:
-            p_sys->i_wanted_page = vbi_bcd2dec( p_sys->nav_link[3].pgno );
-            p_sys->i_wanted_subpage = p_sys->nav_link[3].subno;
+            want_navlink = 3;
             break;
         case ZVBI_KEY_INDEX:
-            p_sys->i_wanted_page = vbi_bcd2dec( p_sys->nav_link[5].pgno ); /* #4 is SKIPPED */
-            p_sys->i_wanted_subpage = p_sys->nav_link[5].subno;
+            want_navlink = 5; /* #4 is SKIPPED */
             break;
     }
-    if( newval.i_int > 0 && newval.i_int < 999 )
+
+    if (want_navlink > -1)
+    {
+        int page = vbi_bcd2dec( p_sys->nav_link[want_navlink].pgno );
+        if (page > 0 && page < 999) {
+            p_sys->i_wanted_page = page;
+            p_sys->i_wanted_subpage = p_sys->nav_link[want_navlink].subno;
+        }
+    }
+    else if( newval.i_int > 0 && newval.i_int < 999 )
     {
         p_sys->i_wanted_page = newval.i_int;
         p_sys->i_wanted_subpage = VBI_ANY_SUBNO;