X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fcodec%2Fspudec%2Fparse.c;h=f2c404faaccd0dc3ccca024f9ddf6b4f8b0dc691;hb=f0c76d5063ea5929f8b514e3bc5b0681cdf8d35e;hp=fe7381a9b45de7c0ffc55b78f2cdd065e0099816;hpb=6fa56f0c47ba7d64a99c70e809ed67374da47a14;p=vlc diff --git a/modules/codec/spudec/parse.c b/modules/codec/spudec/parse.c index fe7381a9b4..f2c404faac 100644 --- a/modules/codec/spudec/parse.c +++ b/modules/codec/spudec/parse.c @@ -26,18 +26,34 @@ /***************************************************************************** * Preamble *****************************************************************************/ -#include -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#include #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. @@ -61,11 +77,12 @@ static inline unsigned int AddNibble( unsigned int i_code, * This function parses the SPU packet and, if valid, sends it to the * video output. *****************************************************************************/ -subpicture_t * E_(ParsePacket)( decoder_t *p_dec ) +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 ); @@ -77,8 +94,8 @@ subpicture_t * E_(ParsePacket)( decoder_t *p_dec ) * this stupid interlacing stuff once. */ p_spu_data = malloc( sizeof(subpicture_data_t) + 4 * p_sys->i_rle_size ); p_spu_data->p_data = (uint8_t *)p_spu_data + sizeof(subpicture_data_t); - p_spu_data->b_palette = VLC_FALSE; - p_spu_data->b_auto_crop = VLC_FALSE; + p_spu_data->b_palette = false; + p_spu_data->b_auto_crop = false; p_spu_data->i_y_top_offset = 0; p_spu_data->i_y_bottom_offset = 0; @@ -95,8 +112,10 @@ subpicture_t * E_(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 ); @@ -104,18 +123,20 @@ subpicture_t * E_(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 ); return NULL; } +#ifdef DEBUG_SPUDEC msg_Dbg( p_dec, "total size: 0x%x, RLE offsets: 0x%x 0x%x", p_sys->i_spu_size, 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; @@ -129,7 +150,7 @@ subpicture_t * E_(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; @@ -143,11 +164,12 @@ static int ParseControlSeq( decoder_t *p_dec, subpicture_t *p_spu, uint8_t i_command = SPU_CMD_END; mtime_t date = 0; - unsigned int i, pi_alpha[4]; + if( !p_spu || !p_spu_data ) + return VLC_EGENERIC; /* Initialize the structure */ p_spu->i_start = p_spu->i_stop = 0; - p_spu->b_ephemer = VLC_FALSE; + p_spu->b_ephemer = false; for( i_index = 4 + p_sys->i_rle_size; i_index < p_sys->i_spu_size ; ) { @@ -163,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; @@ -187,7 +208,7 @@ static int ParseControlSeq( decoder_t *p_dec, subpicture_t *p_spu, { case SPU_CMD_FORCE_DISPLAY: /* 00 (force displaying) */ p_spu->i_start = p_spu_data->i_pts + date; - p_spu->b_ephemer = VLC_TRUE; + p_spu->b_ephemer = true; i_index += 1; break; @@ -203,7 +224,6 @@ static int ParseControlSeq( decoder_t *p_dec, subpicture_t *p_spu, break; case SPU_CMD_SET_PALETTE: - /* 03xxxx (palette) */ if( i_index + 3 > p_sys->i_spu_size ) { @@ -214,8 +234,9 @@ static int ParseControlSeq( decoder_t *p_dec, subpicture_t *p_spu, if( p_dec->fmt_in.subs.spu.palette[0] == 0xBeeF ) { unsigned int idx[4]; + int i; - p_spu_data->b_palette = VLC_TRUE; + p_spu_data->b_palette = true; idx[0] = (p_sys->buffer[i_index+1]>>4)&0x0f; idx[1] = (p_sys->buffer[i_index+1])&0x0f; @@ -258,19 +279,19 @@ 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 ) - p_spu_data->b_auto_crop = VLC_TRUE; + if( p_spu_properties->i_height > 250 ) + p_spu_data->b_auto_crop = true; i_index += 7; break; @@ -318,7 +339,7 @@ static int ParseControlSeq( decoder_t *p_dec, subpicture_t *p_spu, } /* We need to check for quit commands here */ - if( p_dec->b_die ) + if( !vlc_object_alive (p_dec) ) { return VLC_EGENERIC; } @@ -347,13 +368,14 @@ static int ParseControlSeq( decoder_t *p_dec, subpicture_t *p_spu, if( !p_spu->i_start ) { msg_Err( p_dec, "no `start display' command" ); + return VLC_EGENERIC; } if( p_spu->i_stop <= p_spu->i_start && !p_spu->b_ephemer ) { /* This subtitle will live for 5 seconds or until the next subtitle */ p_spu->i_stop = p_spu->i_start + (mtime_t)500 * 11000; - p_spu->b_ephemer = VLC_TRUE; + p_spu->b_ephemer = true; } /* Get rid of padding bytes */ @@ -377,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; @@ -397,7 +420,7 @@ static int ParseRLE( decoder_t *p_dec, subpicture_t * p_spu, unsigned int *pi_offset; /* Cropping */ - vlc_bool_t b_empty_top = VLC_TRUE; + bool b_empty_top = true; unsigned int i_skipped_top = 0, i_skipped_bottom = 0; unsigned int i_transparent_code = 0; @@ -477,7 +500,7 @@ static int ParseRLE( decoder_t *p_dec, subpicture_t * p_spu, } else { - p_spu_data->b_auto_crop = VLC_FALSE; + p_spu_data->b_auto_crop = false; } } @@ -502,7 +525,7 @@ static int ParseRLE( decoder_t *p_dec, subpicture_t * p_spu, *p_dest++ = i_code; /* Valid code means no blank line */ - b_empty_top = VLC_FALSE; + b_empty_top = false; i_skipped_bottom = 0; } } @@ -546,19 +569,24 @@ static int ParseRLE( decoder_t *p_dec, subpicture_t * p_spu, return VLC_EGENERIC; } +#ifdef DEBUG_SPUDEC msg_Dbg( p_dec, "valid subtitle, size: %ix%i, position: %i,%i", p_spu->i_width, p_spu->i_height, p_spu->i_x, p_spu->i_y ); +#endif /* Crop if necessary */ if( i_skipped_top || i_skipped_bottom ) { +#ifdef DEBUG_SPUDEC int i_y = p_spu->i_y + i_skipped_top; int i_height = p_spu->i_height - (i_skipped_top + i_skipped_bottom); - +#endif p_spu_data->i_y_top_offset = i_skipped_top; p_spu_data->i_y_bottom_offset = i_skipped_bottom; +#ifdef DEBUG_SPUDEC msg_Dbg( p_dec, "cropped to: %ix%i, position: %i,%i", p_spu->i_width, i_height, p_spu->i_x, i_y ); +#endif } /* Handle color if no palette was found */ @@ -613,42 +641,34 @@ static int ParseRLE( decoder_t *p_dec, subpicture_t * p_spu, p_spu_data->pi_yuv[i_shade][2] = 0x80; } +#ifdef DEBUG_SPUDEC msg_Dbg( p_dec, "using custom palette (border %i, inner %i, shade %i)", i_border, i_inner, i_shade ); +#endif } return VLC_SUCCESS; } 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; uint16_t *p_source = (uint16_t *)p_spu_data->p_data; video_format_t fmt; + video_palette_t palette; /* Create a new subpicture region */ 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 ); - if( !p_spu->p_region ) - { - msg_Err( p_dec, "cannot allocate SPU region" ); - 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; - - /* Build palette */ + fmt.p_palette = &palette; fmt.p_palette->i_entries = 4; for( i_x = 0; i_x < fmt.p_palette->i_entries; i_x++ ) { @@ -660,6 +680,18 @@ static void Render( decoder_t *p_dec, subpicture_t *p_spu, p_spu_data->pi_alpha[i_x] << 4; } + p_spu->p_region = subpicture_region_New( &fmt ); + if( !p_spu->p_region ) + { + msg_Err( p_dec, "cannot allocate SPU region" ); + return; + } + + 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; + /* Draw until we reach the bottom of the subtitle */ for( i_y = 0; i_y < (int)fmt.i_height * i_pitch; i_y += i_pitch ) {