]> git.sesse.net Git - vlc/blobdiff - modules/codec/spudec/parse.c
Changed subpicture_region_t->picture into a picture_t *
[vlc] / modules / codec / spudec / parse.c
index aeb7c91a4f8862539a45936f6ae356a9767b534c..4e118e02b180af03793a7989899e57e3446f2d82 100644 (file)
 #include <vlc_common.h>
 #include <vlc_vout.h>
 #include <vlc_codec.h>
+#include <vlc_input.h>
 
 #include "spudec.h"
 
 /*****************************************************************************
  * Local prototypes.
  *****************************************************************************/
-static int  ParseControlSeq( decoder_t *, subpicture_t *, subpicture_data_t *);
-static int  ParseRLE       ( decoder_t *, subpicture_t *, subpicture_data_t *);
-static void Render         ( decoder_t *, subpicture_t *, subpicture_data_t *);
+typedef struct
+{
+    int i_width;
+    int i_height;
+    int i_x;
+    int i_y;
+} spu_properties_t;
+
+static int  ParseControlSeq( decoder_t *, subpicture_t *, subpicture_data_t *,
+                             spu_properties_t * );
+static int  ParseRLE       ( decoder_t *, subpicture_data_t *,
+                             const spu_properties_t * );
+static void Render         ( decoder_t *, subpicture_t *, subpicture_data_t *,
+                             const spu_properties_t * );
 
 /*****************************************************************************
  * AddNibble: read a nibble from a source packet and add it to our integer.
@@ -70,13 +82,12 @@ subpicture_t * ParsePacket( decoder_t *p_dec )
     decoder_sys_t *p_sys = p_dec->p_sys;
     subpicture_data_t *p_spu_data;
     subpicture_t *p_spu;
+    spu_properties_t spu_properties;
 
     /* Allocate the subpicture internal data. */
     p_spu = p_dec->pf_spu_buffer_new( p_dec );
     if( !p_spu ) return NULL;
 
-    p_spu->b_pausable = true;
-
     /* Rationale for the "p_spudec->i_rle_size * 4": we are going to
      * expand the RLE stuff so that we won't need to read nibbles later
      * on. This will speed things up a lot. Plus, we'll only need to do
@@ -101,8 +112,10 @@ subpicture_t * ParsePacket( decoder_t *p_dec )
     p_spu->i_original_picture_height =
         p_dec->fmt_in.subs.spu.i_original_frame_height;
 
+    memset( &spu_properties, 0, sizeof(spu_properties) );
+
     /* Getting the control part */
-    if( ParseControlSeq( p_dec, p_spu, p_spu_data ) )
+    if( ParseControlSeq( p_dec, p_spu, p_spu_data, &spu_properties ) )
     {
         /* There was a parse error, delete the subpicture */
         p_dec->pf_spu_buffer_del( p_dec, p_spu );
@@ -110,7 +123,7 @@ subpicture_t * ParsePacket( decoder_t *p_dec )
     }
 
     /* We try to display it */
-    if( ParseRLE( p_dec, p_spu, p_spu_data ) )
+    if( ParseRLE( p_dec, p_spu_data, &spu_properties ) )
     {
         /* There was a parse error, delete the subpicture */
         p_dec->pf_spu_buffer_del( p_dec, p_spu );
@@ -123,7 +136,7 @@ subpicture_t * ParsePacket( decoder_t *p_dec )
              p_spu_data->pi_offset[0], p_spu_data->pi_offset[1] );
 #endif
 
-    Render( p_dec, p_spu, p_spu_data );
+    Render( p_dec, p_spu, p_spu_data, &spu_properties );
     free( p_spu_data );
 
     return p_spu;
@@ -137,7 +150,7 @@ subpicture_t * ParsePacket( decoder_t *p_dec )
  * subtitles format, see http://sam.zoy.org/doc/dvd/subtitles/index.html
  *****************************************************************************/
 static int ParseControlSeq( decoder_t *p_dec, subpicture_t *p_spu,
-                            subpicture_data_t *p_spu_data )
+                            subpicture_data_t *p_spu_data, spu_properties_t *p_spu_properties )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
 
@@ -172,9 +185,8 @@ static int ParseControlSeq( decoder_t *p_dec, subpicture_t *p_spu,
 
             /* Get the control sequence date */
             date = (mtime_t)GetWBE( &p_sys->buffer[i_index] ) * 11000;
-            /* FIXME How to access i_rate
-                    * p_spudec->bit_stream.p_pes->i_rate / DEFAULT_RATE;
-            */
+            if( p_sys->i_rate )
+                date = date * p_sys->i_rate / INPUT_RATE_DEFAULT;
 
             /* Next offset */
             i_cur_seq = i_index;
@@ -267,18 +279,18 @@ static int ParseControlSeq( decoder_t *p_dec, subpicture_t *p_spu,
                 return VLC_EGENERIC;
             }
 
-            p_spu->i_x = (p_sys->buffer[i_index+1]<<4)|
+            p_spu_properties->i_x = (p_sys->buffer[i_index+1]<<4)|
                          ((p_sys->buffer[i_index+2]>>4)&0x0f);
-            p_spu->i_width = (((p_sys->buffer[i_index+2]&0x0f)<<8)|
-                              p_sys->buffer[i_index+3]) - p_spu->i_x + 1;
+            p_spu_properties->i_width = (((p_sys->buffer[i_index+2]&0x0f)<<8)|
+                              p_sys->buffer[i_index+3]) - p_spu_properties->i_x + 1;
 
-            p_spu->i_y = (p_sys->buffer[i_index+4]<<4)|
+            p_spu_properties->i_y = (p_sys->buffer[i_index+4]<<4)|
                          ((p_sys->buffer[i_index+5]>>4)&0x0f);
-            p_spu->i_height = (((p_sys->buffer[i_index+5]&0x0f)<<8)|
-                              p_sys->buffer[i_index+6]) - p_spu->i_y + 1;
+            p_spu_properties->i_height = (((p_sys->buffer[i_index+5]&0x0f)<<8)|
+                              p_sys->buffer[i_index+6]) - p_spu_properties->i_y + 1;
 
             /* Auto crop fullscreen subtitles */
-            if( p_spu->i_height > 250 )
+            if( p_spu_properties->i_height > 250 )
                 p_spu_data->b_auto_crop = true;
 
             i_index += 7;
@@ -387,16 +399,17 @@ static int ParseControlSeq( decoder_t *p_dec, subpicture_t *p_spu,
  * convenient structure for later decoding. For more information on the
  * subtitles format, see http://sam.zoy.org/doc/dvd/subtitles/index.html
  *****************************************************************************/
-static int ParseRLE( decoder_t *p_dec, subpicture_t * p_spu,
-                     subpicture_data_t *p_spu_data )
+static int ParseRLE( decoder_t *p_dec,
+                     subpicture_data_t *p_spu_data,
+                     const spu_properties_t *p_spu_properties )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
     uint8_t       *p_src = &p_sys->buffer[4];
 
     unsigned int i_code;
 
-    unsigned int i_width = p_spu->i_width;
-    unsigned int i_height = p_spu->i_height;
+    unsigned int i_width = p_spu_properties->i_width;
+    unsigned int i_height = p_spu_properties->i_height;
     unsigned int i_x, i_y;
 
     uint16_t *p_dest = (uint16_t *)p_spu_data->p_data;
@@ -638,7 +651,8 @@ static int ParseRLE( decoder_t *p_dec, subpicture_t * p_spu,
 }
 
 static void Render( decoder_t *p_dec, subpicture_t *p_spu,
-                    subpicture_data_t *p_spu_data )
+                    subpicture_data_t *p_spu_data,
+                    const spu_properties_t *p_spu_properties )
 {
     uint8_t *p_p;
     int i_x, i_y, i_len, i_color, i_pitch;
@@ -649,8 +663,8 @@ static void Render( decoder_t *p_dec, subpicture_t *p_spu,
     memset( &fmt, 0, sizeof(video_format_t) );
     fmt.i_chroma = VLC_FOURCC('Y','U','V','P');
     fmt.i_aspect = 0; /* 0 means use aspect ratio of background video */
-    fmt.i_width = fmt.i_visible_width = p_spu->i_width;
-    fmt.i_height = fmt.i_visible_height = p_spu->i_height -
+    fmt.i_width = fmt.i_visible_width = p_spu_properties->i_width;
+    fmt.i_height = fmt.i_visible_height = p_spu_properties->i_height -
         p_spu_data->i_y_top_offset - p_spu_data->i_y_bottom_offset;
     fmt.i_x_offset = fmt.i_y_offset = 0;
     p_spu->p_region = p_spu->pf_create_region( VLC_OBJECT(p_dec), &fmt );
@@ -660,10 +674,10 @@ static void Render( decoder_t *p_dec, subpicture_t *p_spu,
         return;
     }
 
-    p_spu->p_region->i_x = 0;
-    p_spu->p_region->i_y = p_spu_data->i_y_top_offset;
-    p_p = p_spu->p_region->picture.p->p_pixels;
-    i_pitch = p_spu->p_region->picture.p->i_pitch;
+    p_spu->p_region->i_x = p_spu_properties->i_x;
+    p_spu->p_region->i_y = p_spu_properties->i_y + p_spu_data->i_y_top_offset;
+    p_p = p_spu->p_region->p_picture->p->p_pixels;
+    i_pitch = p_spu->p_region->p_picture->p->i_pitch;
 
     /* Build palette */
     fmt.p_palette->i_entries = 4;