]> git.sesse.net Git - vlc/blobdiff - modules/codec/ogt/cvd.c
* src/video_output/vout_subpictures.c : New OSD channels
[vlc] / modules / codec / ogt / cvd.c
index 7e3a29ec534d94dc221a98d2b6c2b421ccac18b6..ed6c5d633ccccc35f7f9ab894bbc8cb1a24215cb 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * cvd.c : CVD Subtitle decoder thread
  *****************************************************************************
- * Copyright (C) 2003 VideoLAN
- * $Id: cvd.c,v 1.7 2004/01/04 04:56:21 rocky Exp $
+ * Copyright (C) 2003, 2004 VideoLAN
+ * $Id$
  *
  * Authors: Rocky Bernstein
  *   based on code from:
 /*****************************************************************************
  * Module descriptor.
  *****************************************************************************/
-static int  DecoderOpen   ( vlc_object_t * );
+static int  VCDSubOpen   ( vlc_object_t * );
 static int  PacketizerOpen( vlc_object_t * );
 
 vlc_module_begin();
     set_description( _("CVD subtitle decoder") );
     set_capability( "decoder", 50 );
-    set_callbacks( DecoderOpen, VCDSubClose );
+    set_callbacks( VCDSubOpen, VCDSubClose );
 
     add_integer ( MODULE_STRING "-debug", 0, NULL,
-                  N_("set debug mask for additional debugging."),
-                  N_(DEBUG_LONGTEXT), VLC_TRUE );
+                  DEBUG_TEXT, DEBUG_LONGTEXT, VLC_TRUE );
+
+    add_integer ( MODULE_STRING "-horizontal-correct", 0, NULL,
+                  HORIZONTAL_CORRECT, HORIZONTAL_CORRECT_LONGTEXT, VLC_FALSE );
+
+    add_integer ( MODULE_STRING "-vertical-correct", 0, NULL,
+                  VERTICAL_CORRECT, VERTICAL_CORRECT_LONGTEXT, VLC_FALSE );
+
+    add_string( MODULE_STRING "-aspect-ratio", "", NULL,
+                SUB_ASPECT_RATIO_TEXT, SUB_ASPECT_RATIO_LONGTEXT,
+                VLC_TRUE );
+
+    add_integer( MODULE_STRING "-duration-scaling", 3, NULL,
+                 DURATION_SCALE_TEXT, DURATION_SCALE_LONGTEXT,
+                 VLC_TRUE );
 
     add_submodule();
     set_description( _("Chaoji VCD subtitle packetizer") );
@@ -67,13 +80,13 @@ static block_t *Packetize( decoder_t *, block_t ** );
 
 
 /*****************************************************************************
- * DecoderOpen
+ * VCDSubOpen
  *****************************************************************************
  * Tries to launch a decoder and return score so that the interface is able
  * to chose.
  *****************************************************************************/
 static int
-DecoderOpen( vlc_object_t *p_this )
+VCDSubOpen( vlc_object_t *p_this )
 {
     decoder_t     *p_dec = (decoder_t*)p_this;
     decoder_sys_t *p_sys;
@@ -115,7 +128,7 @@ static int PacketizerOpen( vlc_object_t *p_this )
 {
     decoder_t *p_dec = (decoder_t*)p_this;
 
-    if( DecoderOpen( p_this ) )
+    if( VCDSubOpen( p_this ) )
     {
         return VLC_EGENERIC;
     }
@@ -132,6 +145,7 @@ Decode ( decoder_t *p_dec, block_t **pp_block )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
     block_t       *p_spu = Reassemble( p_dec, pp_block );
+    vout_thread_t *p_last_vout = p_dec->p_sys->p_vout;
 
     dbg_print( (DECODE_DBG_CALL) , "");
 
@@ -143,6 +157,12 @@ Decode ( decoder_t *p_dec, block_t **pp_block )
 
         if( ( p_sys->p_vout = VCDSubFindVout( p_dec ) ) )
         {
+            if( p_last_vout != p_sys->p_vout )
+            {
+                p_sys->i_subpic_channel =
+                    vout_RegisterOSDChannel( p_sys->p_vout );
+            }
+
             /* Parse and decode */
             E_(ParsePacket)( p_dec );
 
@@ -182,11 +202,11 @@ Packetize( decoder_t *p_dec, block_t **pp_block )
 /*****************************************************************************
  Reassemble:
 
- The data for single screen subtitle may come in one of many
- non-contiguous packets of a stream. This routine is called when the
- next packet in the stream comes in. The job of this routine is to
- parse the header, if this is the beginning, and combine the packets
into one complete subtitle unit.
+ Data for single screen subtitle may come in several non-contiguous
+ packets of a stream. This routine is called when the next packet in
+ the stream comes in. The job of this routine is to parse the header,
+ if this is the beginning, and combine the packets into one complete
+ subtitle unit.
 
  If everything is complete, we will return a block. Otherwise return
  NULL.
@@ -216,23 +236,48 @@ Reassemble( decoder_t *p_dec, block_t **pp_block )
 
     p_buffer = p_block->p_buffer;
 
-    dbg_print( (DECODE_DBG_CALL|DECODE_DBG_PACKET), 
-              "header: 0x%02x 0x%02x 0x%02x 0x%02x, 0x%02x, 0x%02x, size: %i",
-              p_buffer[1], p_buffer[2], p_buffer[3], p_buffer[4],
-              p_buffer[5], p_buffer[6],
-              p_block->i_buffer);
+    dbg_print( (DECODE_DBG_CALL|DECODE_DBG_PACKET),
+               "header: 0x%02x 0x%02x 0x%02x 0x%02x, 0x%02x, 0x%02x, size: %i",
+               p_buffer[1], p_buffer[2], p_buffer[3], p_buffer[4],
+               p_buffer[5], p_buffer[6],
+               p_block->i_buffer);
+
+
+    /* Attach to our input thread and see if subtitle is selected. */
+    {
+        vlc_object_t * p_input;
+        vlc_value_t val;
+
+        p_input = vlc_object_find( p_dec, VLC_OBJECT_INPUT, FIND_PARENT );
+
+        if( !p_input ) return NULL;
+
+        if( var_Get( p_input, "spu-channel", &val ) )
+        {
+          vlc_object_release( p_input );
+          return NULL;
+        }
+
+        vlc_object_release( p_input );
+
+        /* Number could be 0bd, 1bd, 2bd, 3bd for 0..3. If so
+           reduce it to 0..3.
+         */
+        if ( (val.i_int & 0xff) == 0xbd ) val.i_int >>= 8;
+
+        if( val.i_int == -1 || val.i_int != p_buffer[0] )
+          return NULL;
+    }
 
-    if( config_GetInt( p_dec, "spu-channel" ) != p_buffer[0] )
-      return NULL;
 
-    /* There is little data on the format, but it does not seem to have a
-       good way to detect the first packet in the subtitle.  It seems,
-       however, that it has a valid pts while later packets for the same
-       image don't */
+    /* From the scant data on the format, there is only only way known
+       to detect the first packet in a subtitle.  The first packet
+       seems to have a valid PTS while later packets for the same
+       image don't. */
 
     if ( p_sys->state == SUBTITLE_BLOCK_EMPTY && p_block->i_pts == 0 ) {
-      msg_Warn( p_dec, 
-               "first packet expected but no PTS present -- skipped\n");
+      msg_Warn( p_dec,
+                "first packet expected but no PTS present -- skipped\n");
       return NULL;
     }
 
@@ -243,8 +288,8 @@ Reassemble( decoder_t *p_dec, block_t **pp_block )
     }
 
     /* FIXME - remove append_data and use chainappend */
-    VCDSubAppendData( p_dec, p_buffer + SPU_HEADER_LEN, 
-                     p_block->i_buffer - SPU_HEADER_LEN );
+    VCDSubAppendData( p_dec, p_buffer + SPU_HEADER_LEN,
+                      p_block->i_buffer - SPU_HEADER_LEN );
 
     block_ChainAppend( &p_sys->p_block, p_block );
 
@@ -258,6 +303,5 @@ Reassemble( decoder_t *p_dec, block_t **pp_block )
       p_sys->state = SUBTITLE_BLOCK_PARTIAL;
     }
 
-    
     return NULL;
 }