]> git.sesse.net Git - vlc/blobdiff - modules/codec/cc.c
Use var_Inherit* instead of var_CreateGet*.
[vlc] / modules / codec / cc.c
index 4db6b31a7f476d30102bb50bbe7713a0eb16ee2a..ee20e50d5e28faa6cd46b0a3d026b450f67e9ae2 100644 (file)
 
 #include <vlc_common.h>
 #include <vlc_plugin.h>
-#include <vlc_vout.h>
 #include <vlc_codec.h>
 #include <vlc_input.h>
 
-#include <vlc_osd.h>
 #include <vlc_filter.h>
 #include <vlc_image.h>
 #include <vlc_charset.h>
 #include <vlc_stream.h>
 #include <vlc_xml.h>
-#include <errno.h>
 #include <string.h>
 
 #include <assert.h>
 static int  Open ( vlc_object_t * );
 static void Close( vlc_object_t * );
 
-vlc_module_begin();
-    set_shortname( N_("CC 608/708"));
-    set_description( N_("Closed Captions decoder") );
-    set_capability( "decoder", 50 );
-    set_callbacks( Open, Close );
-vlc_module_end();
+vlc_module_begin ()
+    set_shortname( N_("CC 608/708"))
+    set_description( N_("Closed Captions decoder") )
+    set_capability( "decoder", 50 )
+    set_callbacks( Open, Close )
+vlc_module_end ()
 
 /*****************************************************************************
  * Local prototypes
@@ -199,19 +196,19 @@ static int Open( vlc_object_t *p_this )
     p_dec->pf_decode_sub = Decode;
 
     /* Allocate the memory needed to store the decoder's structure */
-    p_dec->p_sys = p_sys = malloc( sizeof( *p_sys ) );
+    p_dec->p_sys = p_sys = calloc( 1, sizeof( *p_sys ) );
     if( p_sys == NULL )
         return VLC_ENOMEM;
 
     /* init of p_sys */
-    memset( p_sys, 0, sizeof( *p_sys ) );
-    p_sys->i_block = 0;
-
     p_sys->i_field = i_field;
     p_sys->i_channel = i_channel;
 
     Eia608Init( &p_sys->eia608 );
 
+    p_dec->fmt_out.i_cat = SPU_ES;
+    p_dec->fmt_out.i_codec = VLC_CODEC_TEXT;
+
     return VLC_SUCCESS;
 }
 
@@ -295,11 +292,11 @@ static block_t *Pop( decoder_t *p_dec )
         return NULL;
 
     p_block = p_sys->pp_block[i_index = 0];
-    if( p_block->i_pts > 0 )
+    if( p_block->i_pts > VLC_TS_INVALID )
     {
         for( i = 1; i < p_sys->i_block-1; i++ )
         {
-            if( p_sys->pp_block[i]->i_pts > 0 && p_block->i_pts > 0 &&
+            if( p_sys->pp_block[i]->i_pts > VLC_TS_INVALID && p_block->i_pts > VLC_TS_INVALID &&
                 p_sys->pp_block[i]->i_pts < p_block->i_pts )
                 p_block = p_sys->pp_block[i_index = i];
         }
@@ -318,7 +315,7 @@ static subpicture_t *Subtitle( decoder_t *p_dec, char *psz_subtitle, char *psz_h
     video_format_t fmt;
 
     /* We cannot display a subpicture with no date */
-    if( i_pts == 0 )
+    if( i_pts <= VLC_TS_INVALID )
     {
         msg_Warn( p_dec, "subtitle without a date" );
         return NULL;
@@ -329,7 +326,7 @@ static subpicture_t *Subtitle( decoder_t *p_dec, char *psz_subtitle, char *psz_h
         EnsureUTF8( psz_html );
 
     /* Create the subpicture unit */
-    p_spu = decoder_NewSubpicture( p_dec );
+    p_spu = decoder_NewSubpicture( p_dec, NULL );
     if( !p_spu )
     {
         msg_Warn( p_dec, "can't get spu buffer" );
@@ -340,8 +337,7 @@ static subpicture_t *Subtitle( decoder_t *p_dec, char *psz_subtitle, char *psz_h
 
     /* Create a new subpicture region */
     memset( &fmt, 0, sizeof(video_format_t) );
-    fmt.i_chroma = VLC_FOURCC('T','E','X','T');
-    fmt.i_aspect = 0;
+    fmt.i_chroma = VLC_CODEC_TEXT;
     fmt.i_width = fmt.i_height = 0;
     fmt.i_x_offset = fmt.i_y_offset = 0;
     p_spu->p_region = subpicture_region_New( &fmt );
@@ -566,6 +562,9 @@ static void Eia608EraseToEndOfRow( eia608_t *h )
 
 static void Eia608RollUp( eia608_t *h )
 {
+    if( h->mode == EIA608_MODE_TEXT )
+        return;
+
     const int i_screen = Eia608GetWritingScreenIndex( h );
     eia608_screen *screen = &h->screen[i_screen];
 
@@ -604,16 +603,25 @@ static void Eia608RollUp( eia608_t *h )
     /* Reset current row */
     Eia608ClearScreenRow( h, i_screen, h->cursor.i_row );
 }
-static void Eia608ParseChannel( eia608_t *h, uint8_t d1 )
+static void Eia608ParseChannel( eia608_t *h, const uint8_t d[2] )
 {
-    if( d1 == 0x14 )
-        h->i_channel = 1;
-    else if( d1 == 0x1c )
-        h->i_channel = 2;
-    else if( ( d1 >= 0x01 && d1 <= 0x0f ) || d1 == 0x15 )
+    /* Check odd parity */
+    static const int p4[16] = {
+        0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0
+    };
+    if( p4[d[0] & 0xf] == p4[d[0] >> 4] ||
+        p4[d[1] & 0xf] == p4[ d[1] >> 4] )
+    {
+        h->i_channel = -1;
+        return;
+    }
+
+    /* */
+    const int d1 = d[0] & 0x7f;
+    if( d1 >= 0x10 && d1 <= 0x1f )
+        h->i_channel = 1 + ((d1 & 0x08) != 0);
+    else if( d1 < 0x10 )
         h->i_channel = 3;
-    else if( d1 == 0x1d )
-        h->i_channel = 4;
 }
 static bool Eia608ParseTextAttribute( eia608_t *h, uint8_t d2 )
 {
@@ -1069,14 +1077,14 @@ static void Eia608Init( eia608_t *h )
 }
 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 d1 = data[0] & 0x7f; /* Removed parity bit */
     const uint8_t d2 = data[1] & 0x7f;
     bool b_screen_changed = false;
 
     if( d1 == 0 && d2 == 0 )
-        return false;   /* Ignore padding */
+        return false;   /* Ignore padding (parity check are sometimes invalid on them) */
 
-    Eia608ParseChannel( h, d1 );
+    Eia608ParseChannel( h, data );
     if( h->i_channel != i_channel_selected )
         return false;
     //fprintf( stderr, "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC %x %x\n", data[0], data[1] );
@@ -1130,5 +1138,6 @@ static char *Eia608Text( eia608_t *h, bool b_html )
 
 static void Eia608Exit( eia608_t *h )
 {
+    VLC_UNUSED( h );
 }