Commit 79883ab7 authored by Rocky Bernstein's avatar Rocky Bernstein

Marginally better

parent aee5d77c
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ogt.c : Overlay Graphics Text (SVCD subtitles) decoder thread * ogt.c : Overlay Graphics Text (SVCD subtitles) decoder thread
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * Copyright (C) 2003 VideoLAN
* $Id: ogt.c,v 1.1 2003/12/07 22:14:26 rocky Exp $ * $Id: ogt.c,v 1.2 2003/12/08 06:01:11 rocky Exp $
* *
* Authors: Rocky Bernstein * Authors: Rocky Bernstein
* based on code from: * based on code from:
...@@ -50,7 +50,7 @@ static int PacketizerOpen( vlc_object_t * ); ...@@ -50,7 +50,7 @@ static int PacketizerOpen( vlc_object_t * );
static void Close ( vlc_object_t * ); static void Close ( vlc_object_t * );
vlc_module_begin(); vlc_module_begin();
set_description( _("SVCD subtitle decoder") ); set_description( _("Philips OGT (SVCD subtitle) decoder") );
set_capability( "decoder", 50 ); set_capability( "decoder", 50 );
set_callbacks( DecoderOpen, Close ); set_callbacks( DecoderOpen, Close );
...@@ -59,7 +59,7 @@ vlc_module_begin(); ...@@ -59,7 +59,7 @@ vlc_module_begin();
N_(DEBUG_LONGTEXT), VLC_TRUE ); N_(DEBUG_LONGTEXT), VLC_TRUE );
add_submodule(); add_submodule();
set_description( _("SVCD subtitle packetizer") ); set_description( _("Phlips OGT (SVCD subtitle) packetizer") );
set_capability( "packetizer", 50 ); set_capability( "packetizer", 50 );
set_callbacks( PacketizerOpen, Close ); set_callbacks( PacketizerOpen, Close );
vlc_module_end(); vlc_module_end();
...@@ -238,47 +238,36 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block ) ...@@ -238,47 +238,36 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
return NULL; return NULL;
} }
#define SPU_HEADER_LEN 5 /*
/*****************************************************************************
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.
If everything is complete, we will return a block. Otherwise return
NULL.
The following information is mostly extracted from the SubMux package of The following information is mostly extracted from the SubMux package of
unknown author with additional experimentation. unknown author with additional experimentation.
The format is roughly as follows (everything is big-endian): The format is roughly as follows (everything is big-endian):
byte subtitle channel 0-3 size description
byte subtitle packet number in this subtitle image 0-N, -------------------------------------------
last is XOR'ed 0x80 byte subtitle channel (0..7) in bits 0-3
u_int16 subtitle image number byte subtitle packet number of this subtitle image 0-N,
u_int16 length in bytes of the rest if the subtitle packet is complete, the top bit of the byte is 1.
byte option flags, unknown meaning except bit 3 (0x08) indicates u_int16 subtitle image number
presence of the duration field u_int16 length in bytes of the rest
byte unknown meaning byte option flags, unknown meaning except bit 3 (0x08) indicates
u_int32 duration in 1/90000ths of a second (optional), start time presence of the duration field
is as indicated by the PTS in the PES header byte unknown
u_int32 xpos u_int32 duration in 1/90000ths of a second (optional), start time
u_int32 ypos is as indicated by the PTS in the PES header
u_int32 width (must be even) u_int32 xpos
u_int32 height (must be even) u_int32 ypos
byte[16] palette, 4 palette entries, each contains values for u_int32 width (must be even)
Y, U, V and transparency, 0 standing for transparent u_int32 height (must be even)
byte command, byte[16] palette, 4 palette entries, each contains values for
cmd>>6==1 indicates shift Y, U, V and transparency, 0 standing for transparent
(cmd>>4)&3 is direction from, (0=top,1=left,2=right,3=bottom) byte command,
u_int32 shift duration in 1/90000ths of a second cmd>>6==1 indicates shift
u_int16 offset of odd field (subtitle image is presented interlaced) (cmd>>4)&3 is direction from, (0=top,1=left,2=right,3=bottom)
byte[] image u_int32 shift duration in 1/90000ths of a second
u_int16 offset of odd field (subtitle image is presented interlaced)
byte[] bit image
The image is encoded using two bits per pixel that select a palette The image is encoded using two bits per pixel that select a palette
entry except that value 00 starts a limited rle. When 00 is seen, entry except that value 00 starts a limited rle. When 00 is seen,
...@@ -288,7 +277,96 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block ) ...@@ -288,7 +277,96 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
first field is padded to an even byte lenght and the complete subtitle first field is padded to an even byte lenght and the complete subtitle
is padded to a 4-byte multiple that always include one zero byte at is padded to a 4-byte multiple that always include one zero byte at
the end. the end.
*/
/* FIXME: do we really need p_buffer and p?
Can't all of thes _offset's and _lengths's get removed?
*/
static void
ParseHeader( decoder_t *p_dec, uint8_t *p_buffer, block_t *p_block )
{
decoder_sys_t *p_sys = p_dec->p_sys;
u_int8_t *p = p_buffer;
int i;
p_sys->i_pts = p_block->i_pts;
p_sys->i_spu_size = GETINT16(p);
p_sys->i_options = *p++;
p_sys->i_options2 = *p++;
if ( p_sys->i_options & 0x08 ) {
p_sys->i_duration = GETINT32(p);
} else {
/* 0 means display until next subtitle comes in. */
p_sys->i_duration = 0;
}
p_sys->i_x_start= GETINT16(p);
p_sys->i_y_start= GETINT16(p);
p_sys->i_width = GETINT16(p);
p_sys->i_height = GETINT16(p);
for (i=0; i<4; i++) {
p_sys->pi_palette[i].y = *p++;
p_sys->pi_palette[i].u = *p++;
p_sys->pi_palette[i].v = *p++;
/* We have just 4-bit resolution for alpha, but the value for SVCD
* has 8 bits so we scale down the values to the acceptable range */
p_sys->pi_palette[i].t = (*p++) >> 4;
}
p_sys->i_cmd = *p++;
/* We do not really know this, FIXME */
if ( p_sys->i_cmd ) {
p_sys->i_cmd_arg = GETINT32(p);
}
/* Image starts just after skipping next short */
p_sys->comp_image_offset = p + 2 - p_buffer;
/* There begins the first field, so no correction needed */
p_sys->first_field_offset = 0;
/* Actually, this is measured against a different origin, so we have to
adjust it */
p_sys->second_field_offset = GETINT16(p);
p_sys->comp_image_offset = p - p_buffer;
p_sys->comp_image_length =
p_sys->subtitle_data_length - p_sys->comp_image_offset;
p_sys->metadata_length = p_sys->comp_image_offset;
/*spuogt_init_subtitle_data(p_sys);*/
p_sys->subtitle_data_pos = 0;
dbg_print( (DECODE_DBG_PACKET),
"x-start: %d, y-start: %d, width: %d, height %d, "
"spu size: %d, duration: %u",
p_sys->i_x_start, p_sys->i_y_start,
p_sys->i_width, p_sys->i_height,
p_sys->i_spu_size, p_sys->i_duration );
}
#define SPU_HEADER_LEN 5
/*****************************************************************************
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.
If everything is complete, we will return a block. Otherwise return
NULL.
The format of the beginning of the subtitle packet that is used here.
size description
-------------------------------------------
byte subtitle channel (0..7) in bits 0-3
byte subtitle packet number of this subtitle image 0-N,
if the subtitle packet is complete, the top bit of the byte is 1.
u_int16 subtitle image number
*****************************************************************************/ *****************************************************************************/
static block_t * static block_t *
...@@ -356,64 +434,9 @@ Reassemble( decoder_t *p_dec, block_t **pp_block ) ...@@ -356,64 +434,9 @@ Reassemble( decoder_t *p_dec, block_t **pp_block )
if ( p_sys->i_packet == 0 ) { if ( p_sys->i_packet == 0 ) {
/* First packet in the subtitle block */ /* First packet in the subtitle block */
/* FIXME: Put all of this into a subroutine. */ ParseHeader( p_dec, p_buffer, p_block );
u_int8_t *p = p_buffer;
p = p_buffer;
int i;
p_sys->i_pts = p_block->i_pts;
p_sys->i_spu_size = GETINT16(p);
p_sys->i_options = *p++;
p_sys->i_options2 = *p++;
if ( p_sys->i_options & 0x08 ) {
p_sys->duration = GETINT32(p);
} else {
p_sys->duration = 0;
}
p_sys->i_x_start= GETINT16(p);
p_sys->i_y_start= GETINT16(p);
p_sys->i_width = GETINT16(p);
p_sys->i_height = GETINT16(p);
for (i=0; i<4; i++) {
p_sys->pi_palette[i].y = *p++;
p_sys->pi_palette[i].u = *p++;
p_sys->pi_palette[i].v = *p++;
/* We have just 4-bit resolution for alpha, but the value for SVCD
* has 8 bits so we scale down the values to the acceptable range */
p_sys->pi_palette[i].t = (*p++) >> 4;
}
p_sys->i_cmd = *p++;
/* We do not really know this, FIXME */
if ( p_sys->i_cmd ) {
p_sys->i_cmd_arg = GETINT32(p);
}
/* Image starts just after skipping next short */
p_sys->comp_image_offset = p + 2 - p_buffer;
/* There begins the first field, so no correction needed */
p_sys->first_field_offset = 0;
/* Actually, this is measured against a different origin, so we have to
adjust it */
p_sys->second_field_offset = GETINT16(p);
p_sys->comp_image_offset = p - p_buffer;
p_sys->comp_image_length =
p_sys->subtitle_data_length - p_sys->comp_image_offset;
p_sys->metadata_length = p_sys->comp_image_offset;
/*spuogt_init_subtitle_data(p_sys);*/
p_sys->subtitle_data_pos = 0;
dbg_print( (DECODE_DBG_PACKET),
"x-start: %d, y-start: %d, width: %d, height %d, "
"spu size: %d",
p_sys->i_x_start, p_sys->i_y_start,
p_sys->i_width, p_sys->i_height,
p_sys->i_spu_size );
} }
block_ChainAppend( &p_sys->p_block, p_block ); block_ChainAppend( &p_sys->p_block, p_block );
p_sys->i_spu += p_block->i_buffer - SPU_HEADER_LEN; p_sys->i_spu += p_block->i_buffer - SPU_HEADER_LEN;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ogt.h : Overlay Graphics Text (SVCD subtitles) decoder thread interface * ogt.h : Overlay Graphics Text (SVCD subtitles) decoder thread interface
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * Copyright (C) 2003 VideoLAN
* $Id: ogt.h,v 1.1 2003/12/07 22:14:26 rocky Exp $ * $Id: ogt.h,v 1.2 2003/12/08 06:01:11 rocky Exp $
* *
* Authors: Rocky Bernstein * Authors: Rocky Bernstein
* based on code from: * based on code from:
...@@ -62,9 +62,6 @@ typedef struct ogt_yuvt_val_s { ...@@ -62,9 +62,6 @@ typedef struct ogt_yuvt_val_s {
struct decoder_sys_t struct decoder_sys_t
{ {
#ifndef FIXED
int i_rle_size; /*REMOVE WHEN WE'VE GONE OVER ALL CODE*/
#endif
int i_debug; /* debugging mask */ int i_debug; /* debugging mask */
int b_packetizer; int b_packetizer;
...@@ -98,15 +95,14 @@ struct decoder_sys_t ...@@ -98,15 +95,14 @@ struct decoder_sys_t
int subtitle_data_length; /* goal for subtitle_data_pos while gathering, int subtitle_data_length; /* goal for subtitle_data_pos while gathering,
length of used subtitle_data later */ length of used subtitle_data later */
u_int32_t duration; /* how long to display the image, 0 stands u_int32_t i_duration; /* how long to display the image, 0 stands
for "until next sub" */ for "until next subtitle" */
u_int16_t i_x_start, i_y_start; /* position of top leftmost pixel of u_int16_t i_x_start, i_y_start; /* position of top leftmost pixel of
image when displayed */ image when displayed */
u_int16_t i_width, i_height; /* dimensions in pixels of image */ u_int16_t i_width, i_height; /* dimensions in pixels of image */
ogt_yuvt_val_t pi_palette[4]; ogt_yuvt_val_t pi_palette[4];
ogt_yuvt_val_t pi_palette_highlight[4];
u_int8_t i_options; u_int8_t i_options;
u_int8_t i_options2; u_int8_t i_options2;
...@@ -123,8 +119,12 @@ struct subpicture_sys_t ...@@ -123,8 +119,12 @@ struct subpicture_sys_t
/* Color information */ /* Color information */
vlc_bool_t b_palette; vlc_bool_t b_palette;
ogt_yuvt_val_t pi_palette[4];
#ifndef FIXED
uint8_t pi_alpha[4]; uint8_t pi_alpha[4];
uint8_t pi_yuv[4][3]; uint8_t pi_yuv[4][3];
#endif
/* Link to our input */ /* Link to our input */
vlc_object_t * p_input; vlc_object_t * p_input;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment