]> git.sesse.net Git - vlc/blobdiff - modules/codec/ogt/cvd_parse.c
* ALL: separation of the SPU engine from the VOUT.
[vlc] / modules / codec / ogt / cvd_parse.c
index 48416f060f51e696726a7a1268dc451ab6387bb6..289619729dafefdd653f202cf1828c9fcd67e8b1 100644 (file)
@@ -2,7 +2,7 @@
  * parse.c: Philips OGT (SVCD subtitle) packet parser
  *****************************************************************************
  * Copyright (C) 2003, 2004 VideoLAN
- * $Id: cvd_parse.c,v 1.9 2004/01/10 13:59:25 rocky Exp $
+ * $Id$
  *
  * Authors: Rocky Bernstein 
  *   based on code from: 
@@ -95,11 +95,11 @@ void E_(ParseHeader)( decoder_t *p_dec, uint8_t *p_buffer, block_t *p_block )
   p_sys->metadata_offset = GETINT16(p);
   p_sys->metadata_length = p_sys->i_spu_size - p_sys->metadata_offset;
 
-  p_sys->comp_image_offset = 4;
-  p_sys->comp_image_length = p_sys->metadata_offset - p_sys->comp_image_offset;
+  p_sys->i_image_offset = 4;
+  p_sys->i_image_length = p_sys->metadata_offset - p_sys->i_image_offset;
   
   dbg_print(DECODE_DBG_PACKET, "total size: %d  image size: %d\n",
-           p_sys->i_spu_size, p_sys->comp_image_length);
+           p_sys->i_spu_size, p_sys->i_image_length);
 
 }
 
@@ -136,12 +136,20 @@ void E_(ParseMetaInfo)( decoder_t *p_dec  )
     switch ( p[0] ) {
       
     case 0x04: /* subtitle duration in 1/90000ths of a second */
+      {
+       mtime_t i_duration = (p[1]<<16) + (p[2]<<8) + p[3];
+       mtime_t i_duration_scale = config_GetInt( p_dec, MODULE_STRING 
+                                    "-duration-scaling" );
+               
+       dbg_print( DECODE_DBG_PACKET, 
+                  "subtitle display duration %lu secs  (scaled %lu secs)", 
+                  (long unsigned int) (i_duration / 90000), 
+                  (long unsigned int) (i_duration * i_duration_scale / 90000)
+                  );
+       p_sys->i_duration = i_duration * i_duration_scale ;
+       break;
+      }
       
-      p_sys->i_duration = (p[1]<<16) + (p[2]<<8) + p[3];
-      
-      dbg_print( DECODE_DBG_PACKET, 
-                "subtitle display duration %u", p_sys->i_duration);
-      break;
       
     case 0x0c: /* unknown */
       dbg_print( DECODE_DBG_PACKET, 
@@ -241,18 +249,18 @@ void E_(ParseMetaInfo)( decoder_t *p_dec  )
       
     case 0x47:
       /* offset to start of even rows of interlaced image, we correct
-        to make it relative to comp_image_offset (usually 4) */
+        to make it relative to i_image_offset (usually 4) */
       p_sys->first_field_offset =
-       (p[2] << 8) + p[3] - p_sys->comp_image_offset;
+       (p[2] << 8) + p[3] - p_sys->i_image_offset;
       dbg_print( DECODE_DBG_PACKET, 
                 "first_field_offset %d", p_sys->first_field_offset);
       break;
       
     case 0x4f:
       /* offset to start of odd rows of interlaced image, we correct
-        to make it relative to comp_image_offset (usually 4) */
+        to make it relative to i_image_offset (usually 4) */
       p_sys->second_field_offset =
-       (p[2] << 8) + p[3] - p_sys->comp_image_offset;
+       (p[2] << 8) + p[3] - p_sys->i_image_offset;
       dbg_print( DECODE_DBG_PACKET, 
                 "second_field_offset %d", p_sys->second_field_offset);
       break;
@@ -284,11 +292,10 @@ E_(ParsePacket)( decoder_t *p_dec)
     dbg_print( (DECODE_DBG_CALL|DECODE_DBG_EXT) , "");
 
     /* Allocate the subpicture internal data. */
-    p_spu = vout_CreateSubPicture( p_sys->p_vout, MEMORY_SUBPICTURE );
-    if( p_spu == NULL )
-    {
-        return;
-    }
+    p_spu = spu_CreateSubpicture( p_sys->p_vout->p_spu );
+    if( p_spu == NULL ) return;
+
+    p_spu->i_channel = p_sys->i_subpic_channel;
 
     /* In ParseImage we expand the run-length encoded color 0's; also
        we expand pixels and remove the color palette. This should
@@ -300,16 +307,26 @@ E_(ParsePacket)( decoder_t *p_dec)
     /* Fill the p_spu structure */
     vlc_mutex_init( p_dec, &p_spu->p_sys->lock );
 
-    p_spu->pf_render  = VCDSubRender;
+    p_spu->pf_render  = VCDSubBlend;
     p_spu->pf_destroy = VCDSubDestroySPU;
     p_spu->p_sys->p_data = (uint8_t*)p_spu->p_sys + sizeof( subpicture_sys_t );
 
     p_spu->p_sys->i_x_end        = p_sys->i_x_start + p_sys->i_width - 1;
     p_spu->p_sys->i_y_end        = p_sys->i_y_start + p_sys->i_height - 1;
 
+    p_spu->i_x        = p_sys->i_x_start 
+      + config_GetInt( p_dec, MODULE_STRING "-horizontal-correct" );
+
+    p_spu->p_sys->p_palette[0] = p_sys->p_palette[0];
+    p_spu->p_sys->p_palette[1] = p_sys->p_palette[1];
+    p_spu->p_sys->p_palette[2] = p_sys->p_palette[2];
+    p_spu->p_sys->p_palette[3] = p_sys->p_palette[3];
+
     /* FIXME: use aspect ratio for x? */
-    p_spu->i_x        = p_sys->i_x_start * 3 / 4; 
-    p_spu->i_y        = p_sys->i_y_start;
+    p_spu->i_x        = (p_spu->i_x * 3) / 4; 
+    p_spu->i_y        = p_sys->i_y_start 
+      + config_GetInt( p_dec, MODULE_STRING "-vertical-correct" );
+
     p_spu->i_width    = p_sys->i_width;
     p_spu->i_height   = p_sys->i_height;
 
@@ -330,12 +347,12 @@ E_(ParsePacket)( decoder_t *p_dec)
     if( ParseImage( p_dec, p_spu ) )
     {
         /* There was a parse error, delete the subpicture */
-        vout_DestroySubPicture( p_sys->p_vout, p_spu );
+        spu_DestroySubpicture( p_sys->p_vout->p_spu, p_spu );
         return;
     }
 
     /* SPU is finished - we can ask the video output to display it */
-    vout_DisplaySubPicture( p_sys->p_vout, p_spu );
+    spu_DisplaySubpicture( p_sys->p_vout->p_spu, p_spu );
 
 }
 
@@ -413,8 +430,8 @@ ParseImage( decoder_t *p_dec, subpicture_t * p_spu )
     uint8_t i_pending = 0;     /* number of pixels to fill with 
                                  color zero 0..3 */
     ogt_color_t i_color=0;     /* current pixel color: 0..3 */
-    uint8_t *p = p_sys->subtitle_data  + p_sys->comp_image_offset;
-    uint8_t *maxp = p + p_sys->comp_image_length;
+    uint8_t *p = p_sys->subtitle_data  + p_sys->i_image_offset;
+    uint8_t *maxp = p + p_sys->i_image_length;
 
     dbg_print( (DECODE_DBG_CALL) , "width x height: %dx%d",
               i_width, i_height);
@@ -522,29 +539,8 @@ ParseImage( decoder_t *p_dec, subpicture_t * p_spu )
     }
 #endif /*HAVE_LIBPNG*/
 
-    VCDInlinePalette( p_dest, p_sys, i_height, i_width );
-
-    /* The video is automatically scaled. However subtitle bitmaps
-       assume a 1:1 aspect ratio. So we need to scale to compensate for
-       or undo the effects of video output scaling. 
-
-       Perhaps this should go in the Render routine? The advantage would
-       be that it will deal with a dynamically changing aspect ratio.
-       The downside is having to scale many times for each render call.
-    */
-    
-    {
-      vout_thread_t *p_vout = vlc_object_find( p_spu->p_sys->p_input,
-                                              VLC_OBJECT_VOUT, 
-                                              FIND_CHILD );
-      unsigned int i_aspect_x, i_aspect_y;
-      if (p_vout) {
-       vout_AspectRatio( p_vout->render.i_aspect, &i_aspect_x, &i_aspect_y );
-       VCDSubScaleX( p_dec, p_spu, i_aspect_y, i_aspect_x );
-      }
-    }
+    VCDSubHandleScaling( p_spu, p_dec );
 
-    /* To be finished...*/
     return VLC_SUCCESS;
 
 }