]> git.sesse.net Git - vlc/blobdiff - modules/codec/cc.c
Preferences: don't show empty boxes ('zoom' box bug)
[vlc] / modules / codec / cc.c
index 2ca92d70cd56f7fcd66ab289ccc8c9df4d71fa0a..5b09488a5aec16a8a211f42e67ac38868b371709 100644 (file)
@@ -2,7 +2,7 @@
  * cc608.c : CC 608/708 subtitles decoder
  *****************************************************************************
  * Copyright (C) 2007 Laurent Aimar
- * $Id: subsdec.c 22151 2007-09-18 16:20:49Z courmisch $
+ * $Id$
  *
  * Authors: Laurent Aimar < fenrir # via.ecp.fr>
  *
  *  708 decoding
  */
 
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_vout.h>
 #include <vlc_codec.h>
 #include <vlc_input.h>
@@ -47,6 +52,8 @@
 #include <errno.h>
 #include <string.h>
 
+#include <assert.h>
+
 /*****************************************************************************
  * Module descriptor.
  *****************************************************************************/
@@ -54,8 +61,8 @@ static int  Open ( vlc_object_t * );
 static void Close( vlc_object_t * );
 
 vlc_module_begin();
-    set_shortname( _("CC 608/708"));
-    set_description( _("Closed Captions decoder") );
+    set_shortname( N_("CC 608/708"));
+    set_description( N_("Closed Captions decoder") );
     set_capability( "decoder", 50 );
     set_callbacks( Open, Close );
 vlc_module_end();
@@ -135,8 +142,8 @@ typedef struct
 } eia608_t;
 
 static void         Eia608Init( eia608_t * );
-static vlc_bool_t   Eia608Parse( eia608_t *h, int i_channel_selected, const uint8_t data[2] );
-static char        *Eia608Text( eia608_t *h, vlc_bool_t b_html );
+static bool   Eia608Parse( eia608_t *h, int i_channel_selected, const uint8_t data[2] );
+static char        *Eia608Text( eia608_t *h, bool b_html );
 static void         Eia608Exit( eia608_t * );
 
 /* It will be enough up to 63 B frames, which is far too high for
@@ -148,7 +155,6 @@ struct decoder_sys_t
 
     int     i_block;
     block_t *pp_block[CC_MAX_REORDER_SIZE];
-    block_t *p_current;
 
     int i_field;
     int i_channel;
@@ -195,15 +201,11 @@ static int Open( vlc_object_t *p_this )
     /* Allocate the memory needed to store the decoder's structure */
     p_dec->p_sys = p_sys = malloc( sizeof( *p_sys ) );
     if( p_sys == NULL )
-    {
-        msg_Err( p_dec, "out of memory" );
         return VLC_ENOMEM;
-    }
 
     /* init of p_sys */
     memset( p_sys, 0, sizeof( *p_sys ) );
     p_sys->i_block = 0;
-    p_sys->p_current = NULL;
 
     p_sys->i_field = i_field;
     p_sys->i_channel = i_channel;
@@ -224,8 +226,6 @@ static subpicture_t *Convert( decoder_t *, block_t * );
 
 static subpicture_t *Decode( decoder_t *p_dec, block_t **pp_block )
 {
-    decoder_sys_t *p_sys = p_dec->p_sys;
-
     if( pp_block && *pp_block )
     {
         Push( p_dec, *pp_block );
@@ -234,11 +234,7 @@ static subpicture_t *Decode( decoder_t *p_dec, block_t **pp_block )
 
     for( ;; )
     {
-        block_t *p_block;
-
-        p_block = p_sys->p_current;
-        if( !p_block )
-            p_block = Pop( p_dec );
+        block_t *p_block = Pop( p_dec );
         if( !p_block )
             break;
 
@@ -338,12 +334,11 @@ static subpicture_t *Subtitle( decoder_t *p_dec, char *psz_subtitle, char *psz_h
     {
         msg_Warn( p_dec, "can't get spu buffer" );
         free( psz_subtitle );
-        if( psz_html )
-            free( psz_html );
+        free( psz_html );
         return NULL;
     }
 
-    p_spu->b_pausable = VLC_TRUE;
+    p_spu->b_pausable = true;
 
     /* Create a new subpicture region */
     memset( &fmt, 0, sizeof(video_format_t) );
@@ -356,8 +351,7 @@ static subpicture_t *Subtitle( decoder_t *p_dec, char *psz_subtitle, char *psz_h
     {
         msg_Err( p_dec, "cannot allocate SPU region" );
         free( psz_subtitle );
-        if( psz_html )
-            free( psz_html );
+        free( psz_html );
         p_dec->pf_spu_buffer_del( p_dec, p_spu );
         return NULL;
     }
@@ -373,8 +367,8 @@ static subpicture_t *Subtitle( decoder_t *p_dec, char *psz_subtitle, char *psz_h
 
     p_spu->i_start = i_pts;
     p_spu->i_stop = i_pts + 10000000;   /* 10s max */
-    p_spu->b_ephemer = VLC_TRUE;
-    p_spu->b_absolute = VLC_FALSE;
+    p_spu->b_ephemer = true;
+    p_spu->b_absolute = false;
 
     return p_spu;
 }
@@ -383,29 +377,25 @@ static subpicture_t *Convert( decoder_t *p_dec, block_t *p_block )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
     const int64_t i_pts = p_block->i_pts;
-    vlc_bool_t b_changed = VLC_FALSE;
-
-    p_sys->p_current = p_block;
+    bool b_changed = false;
 
     /* TODO do the real decoding here */
-    while( p_block && p_block->i_buffer >= 3 )
+    while( p_block->i_buffer >= 3 )
     {
         if( p_block->p_buffer[0] == p_sys->i_field )
             b_changed |= Eia608Parse( &p_sys->eia608, p_sys->i_channel, &p_block->p_buffer[1] );
 
         p_block->i_buffer -= 3;
         p_block->p_buffer += 3;
-        if( p_block->i_buffer <= 0 )
-        {
-            block_Release( p_block );
-            p_sys->p_current = p_block = NULL;
-        }
     }
+    if( p_block )
+        block_Release( p_block );
+
     static int64_t i_last = 0;
     if( b_changed )//&& i_pts - i_last > 100*1000 )
     {
-        char *psz_subtitle = Eia608Text( &p_sys->eia608, VLC_FALSE );
-        char *psz_html     = NULL;//Eia608Text( &p_sys->eia608, VLC_TRUE );
+        char *psz_subtitle = Eia608Text( &p_sys->eia608, false );
+        char *psz_html     = NULL;//Eia608Text( &p_sys->eia608, true );
         i_last = i_pts;
         return Subtitle( p_dec, psz_subtitle, psz_html, i_pts );
     }
@@ -473,18 +463,18 @@ static void Eia608ClearScreenRowX( eia608_t *h, int i_screen, int i_row, int x )
 
     if( x == 0 )
     {
-        screen->row_used[i_row] = VLC_FALSE;
+        screen->row_used[i_row] = false;
     }
     else
     {
-        screen->row_used[i_row] = VLC_FALSE;
+        screen->row_used[i_row] = false;
         for( i = 0; i < x; i++ )
         {
             if( screen->characters[i_row][i] != ' ' ||
                 screen->colors[i_row][i] != EIA608_COLOR_DEFAULT ||
                 screen->fonts[i_row][i] != EIA608_FONT_REGULAR )
             {
-                screen->row_used[i_row] = VLC_TRUE;
+                screen->row_used[i_row] = true;
                 break;
             }
         }
@@ -529,7 +519,7 @@ static int Eia608GetWritingScreenIndex( eia608_t *h )
     }
 }
 
-static void Eia608EraseScreen( eia608_t *h, vlc_bool_t b_displayed )
+static void Eia608EraseScreen( eia608_t *h, bool b_displayed )
 {
     Eia608ClearScreen( h, b_displayed ? h->i_screen : (1-h->i_screen) );
 }
@@ -548,7 +538,7 @@ static void Eia608Write( eia608_t *h, const uint8_t c )
     screen->characters[i_row][i_column] = c;
     screen->colors[i_row][i_column] = h->color;
     screen->fonts[i_row][i_column] = h->font;
-    screen->row_used[i_row] = VLC_TRUE;
+    screen->row_used[i_row] = true;
     Eia608Cursor( h, 1 );
 }
 static void Eia608Erase( eia608_t *h )
@@ -627,7 +617,7 @@ static void Eia608ParseChannel( eia608_t *h, uint8_t d1 )
     else if( d1 == 0x1d )
         h->i_channel = 4;
 }
-static vlc_bool_t Eia608ParseTextAttribute( eia608_t *h, uint8_t d2 )
+static bool Eia608ParseTextAttribute( eia608_t *h, uint8_t d2 )
 {
     const int i_index = d2 - 0x20;
     assert( d2 >= 0x20 && d2 <= 0x2f );
@@ -636,21 +626,21 @@ static vlc_bool_t Eia608ParseTextAttribute( eia608_t *h, uint8_t d2 )
     h->font  = pac2_attribs[i_index].i_font;
     Eia608Cursor( h, 1 );
 
-    return VLC_FALSE;
+    return false;
 }
-static vlc_bool_t Eia608ParseSingle( eia608_t *h, const uint8_t dx )
+static bool Eia608ParseSingle( eia608_t *h, const uint8_t dx )
 {
     assert( dx >= 0x20 );
     Eia608Write( h, dx );
-    return VLC_TRUE;
+    return true;
 }
-static vlc_bool_t Eia608ParseDouble( eia608_t *h, uint8_t d2 )
+static bool Eia608ParseDouble( eia608_t *h, uint8_t d2 )
 {
     assert( d2 >= 0x30 && d2 <= 0x3f );
     Eia608Write( h, d2 + 0x50 ); /* We use charaters 0x80...0x8f */
-    return VLC_TRUE;
+    return true;
 }
-static vlc_bool_t Eia608ParseExtended( eia608_t *h, uint8_t d1, uint8_t d2 )
+static bool Eia608ParseExtended( eia608_t *h, uint8_t d1, uint8_t d2 )
 {
     assert( d2 >= 0x20 && d2 <= 0x3f );
     assert( d1 == 0x12 || d1 == 0x13 );
@@ -663,11 +653,11 @@ static vlc_bool_t Eia608ParseExtended( eia608_t *h, uint8_t d1, uint8_t d2 )
      * advanced one */
     Eia608Cursor( h, -1 );
     Eia608Write( h, d2 );
-    return VLC_TRUE;
+    return true;
 }
-static vlc_bool_t Eia608ParseCommand0x14( eia608_t *h, uint8_t d2 )
+static bool Eia608ParseCommand0x14( eia608_t *h, uint8_t d2 )
 {
-    vlc_bool_t b_changed = VLC_FALSE;
+    bool b_changed = false;
 
     switch( d2 )
     {
@@ -676,7 +666,7 @@ static vlc_bool_t Eia608ParseCommand0x14( eia608_t *h, uint8_t d2 )
         break;
     case 0x21:  /* Backspace */
         Eia608Erase( h );
-        b_changed = VLC_TRUE;
+        b_changed = true;
         break;
     case 0x22:  /* Reserved */
     case 0x23:
@@ -689,9 +679,9 @@ static vlc_bool_t Eia608ParseCommand0x14( eia608_t *h, uint8_t d2 )
     case 0x27:  /* Rollup 4 */
         if( h->mode == EIA608_MODE_POPUP || h->mode == EIA608_MODE_PAINTON )
         {
-            Eia608EraseScreen( h, VLC_TRUE );
-            Eia608EraseScreen( h, VLC_FALSE );
-            b_changed = VLC_TRUE;
+            Eia608EraseScreen( h, true );
+            Eia608EraseScreen( h, false );
+            b_changed = true;
         }
 
         if( d2 == 0x25 )
@@ -719,15 +709,15 @@ static vlc_bool_t Eia608ParseCommand0x14( eia608_t *h, uint8_t d2 )
         break;
 
     case 0x2c: /* Erase displayed memory */
-        Eia608EraseScreen( h, VLC_TRUE );
-        b_changed = VLC_TRUE;
+        Eia608EraseScreen( h, true );
+        b_changed = true;
         break;
     case 0x2d: /* Carriage return */
         Eia608RollUp(h);
-        b_changed = VLC_TRUE;
+        b_changed = true;
         break;
     case 0x2e: /* Erase non displayed memory */
-        Eia608EraseScreen( h, VLC_FALSE );
+        Eia608EraseScreen( h, false );
         break;
     case 0x2f: /* End of caption (flip screen if not paint on) */
         if( h->mode != EIA608_MODE_PAINTON )
@@ -737,12 +727,12 @@ static vlc_bool_t Eia608ParseCommand0x14( eia608_t *h, uint8_t d2 )
         h->cursor.i_row = 0;
         h->color = EIA608_COLOR_DEFAULT;
         h->font = EIA608_FONT_REGULAR;
-        b_changed = VLC_TRUE;
+        b_changed = true;
         break;
     }
     return b_changed;
 }
-static vlc_bool_t Eia608ParseCommand0x17( eia608_t *h, uint8_t d2 )
+static bool Eia608ParseCommand0x17( eia608_t *h, uint8_t d2 )
 {
     switch( d2 )
     {
@@ -756,9 +746,9 @@ static vlc_bool_t Eia608ParseCommand0x17( eia608_t *h, uint8_t d2 )
         Eia608Cursor( h, 3 );
         break;
     }
-    return VLC_FALSE;
+    return false;
 }
-static vlc_bool_t Eia608ParsePac( eia608_t *h, uint8_t d1, uint8_t d2 )
+static bool Eia608ParsePac( eia608_t *h, uint8_t d1, uint8_t d2 )
 {
     static const int pi_row[] = {
         11, -1, 1, 2, 3, 4, 12, 13, 14, 15, 5, 6, 7, 8, 9, 10
@@ -768,7 +758,7 @@ static vlc_bool_t Eia608ParsePac( eia608_t *h, uint8_t d1, uint8_t d2 )
     assert( d2 >= 0x40 && d2 <= 0x7f );
 
     if( pi_row[i_row_index] <= 0 )
-        return VLC_FALSE;
+        return false;
 
     /* Row */
     if( h->mode != EIA608_MODE_TEXT )
@@ -780,12 +770,12 @@ static vlc_bool_t Eia608ParsePac( eia608_t *h, uint8_t d1, uint8_t d2 )
     else if( d2 >= 0x40 )
         d2 -= 0x40;
     h->cursor.i_column = pac2_attribs[d2].i_column;
-    return VLC_FALSE;
+    return false;
 }
 
-static vlc_bool_t Eia608ParseData( eia608_t *h, uint8_t d1, uint8_t d2 )
+static bool Eia608ParseData( eia608_t *h, uint8_t d1, uint8_t d2 )
 {
-    vlc_bool_t b_changed = VLC_FALSE;
+    bool b_changed = false;
 
     if( d1 >= 0x18 && d1 <= 0x1f )
         d1 -= 8;
@@ -961,7 +951,7 @@ static void Eia608Strlcat( char *d, const char *s, int i_max )
         d[i_max-1] = '\0';
 }
 
-static void Eia608TextLine( struct eia608_screen *screen, char *psz_text, int i_text_max, int i_row, vlc_bool_t b_html )
+static void Eia608TextLine( struct eia608_screen *screen, char *psz_text, int i_text_max, int i_row, bool b_html )
 {
     const uint8_t *p_char = screen->characters[i_row];
     const eia608_color_t *p_color = screen->colors[i_row];
@@ -970,8 +960,8 @@ static void Eia608TextLine( struct eia608_screen *screen, char *psz_text, int i_
     int i_end;
     int x;
     eia608_color_t last_color = EIA608_COLOR_DEFAULT;
-    vlc_bool_t     b_last_italics = VLC_FALSE;
-    vlc_bool_t     b_last_underline = VLC_FALSE;
+    bool     b_last_italics = false;
+    bool     b_last_underline = false;
 
     /* Search the start */
     i_start = 0;
@@ -988,14 +978,14 @@ static void Eia608TextLine( struct eia608_screen *screen, char *psz_text, int i_
     for( x = i_start; x <= i_end; x++ )
     {
         eia608_color_t color = p_color[x];
-        vlc_bool_t b_italics = p_font[x] & EIA608_FONT_ITALICS;
-        vlc_bool_t b_underline = p_font[x] & EIA608_FONT_UNDERLINE;
+        bool b_italics = p_font[x] & EIA608_FONT_ITALICS;
+        bool b_underline = p_font[x] & EIA608_FONT_UNDERLINE;
         char utf8[4];
 
         /* */
         if( b_html )
         {
-            vlc_bool_t b_close_color, b_close_italics, b_close_underline;
+            bool b_close_color, b_close_italics, b_close_underline;
 
             /* We create the tags font / i / u in that orders */
             b_close_color = color != last_color && last_color != EIA608_COLOR_DEFAULT;
@@ -1079,18 +1069,19 @@ static void Eia608Init( eia608_t *h )
     h->font = EIA608_FONT_REGULAR;
     h->i_row_rollup = EIA608_SCREEN_ROWS-1;
 }
-static vlc_bool_t Eia608Parse( eia608_t *h, int i_channel_selected, const uint8_t data[2] )
+static bool Eia608Parse( eia608_t *h, int i_channel_selected, const uint8_t data[2] )
 {
     const uint8_t d1 = data[0] & 0x7f; /* Removed parity bit TODO we might want to check them */
     const uint8_t d2 = data[1] & 0x7f;
-    vlc_bool_t b_screen_changed = VLC_FALSE;
+    bool b_screen_changed = false;
 
     if( d1 == 0 && d2 == 0 )
-        return VLC_FALSE;   /* Ignore padding */
+        return false;   /* Ignore padding */
 
     Eia608ParseChannel( h, d1 );
     if( h->i_channel != i_channel_selected )
-        return VLC_FALSE;
+        return false;
+    //fprintf( stderr, "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC %x %x\n", data[0], data[1] );
 
     if( d1 >= 0x10 )
     {
@@ -1108,16 +1099,18 @@ static vlc_bool_t Eia608Parse( eia608_t *h, int i_channel_selected, const uint8_
     return b_screen_changed;
 }
 
-static char *Eia608Text( eia608_t *h, vlc_bool_t b_html )
+static char *Eia608Text( eia608_t *h, bool b_html )
 {
     const int i_size = EIA608_SCREEN_ROWS * 3 * EIA608_SCREEN_COLUMNS+1;
     struct eia608_screen *screen = &h->screen[h->i_screen];
-    vlc_bool_t b_first = VLC_TRUE;
+    bool b_first = true;
     char *psz;
     int i;
 
     /* We allocate a buffer big enough for normal case */
     psz = malloc( i_size );
+    if( !psz )
+        return NULL;
     *psz = '\0';
     if( b_html )
         Eia608Strlcat( psz, "<text>", i_size );
@@ -1128,7 +1121,7 @@ static char *Eia608Text( eia608_t *h, vlc_bool_t b_html )
 
         if( !b_first )
             Eia608Strlcat( psz, b_html ? "<br />" : "\n", i_size );
-        b_first = VLC_FALSE;
+        b_first = false;
 
         Eia608TextLine( screen, psz, i_size, i, b_html );
     }