From: Diego 'F. P. <fla...@gm...> - 2008-07-04 14:37:38
|
# HG changeset patch # User Diego 'Flameeyes' Pettenò <fla...@gm...> # Date 1215181495 -7200 # Node ID 3022ff11598508d7e994ba3f02eba36837205458 # Parent 11104ddcae4c6e9bb1167e80151130732668ff7e Simplify code and update code style. With this change a lot of variables now result unused, as before they were only assigned after declaration. diff -r 3022ff11598508d7e994ba3f02eba36837205458 -r 11104ddcae4c6e9bb1167e80151130732668ff7e src/libspudvb/xine_spudvb_decoder.c --- a/src/libspudvb/xine_spudvb_decoder.c Fri Jul 04 16:24:55 2008 +0200 +++ b/src/libspudvb/xine_spudvb_decoder.c Fri Jul 04 16:24:03 2008 +0200 @@ -28,6 +28,7 @@ #include "pthread.h" #include <errno.h> #include "xine_internal.h" +#include "bswap.h" #include "osd.h" #define MAX_REGIONS 7 @@ -144,28 +145,24 @@ static void update_region (dvb_spu_decod /* reject invalid sizes and set some limits ! */ if ( region_width<=0 || region_height<=0 || region_width>720 || region_height>576 ) { - if ( reg->img ) { - free( reg->img ); - reg->img = NULL; - } + free( reg->img ); + reg->img = NULL; #ifdef LOG printf("SPUDVB: rejected region %d = %dx%d\n", region_id, region_width, region_height ); #endif return; } - if ( reg->width*reg->height<region_width*region_height ) { + if ( (reg->width*reg->height) < (region_width*region_height) ) { #ifdef LOG printf("SPUDVB: update size of region %d = %dx%d\n", region_id, region_width, region_height); #endif - if ( reg->img ) { - free( reg->img ); - reg->img = NULL; - } + free( reg->img ); + reg->img = NULL; } if ( !reg->img ) { - if ( !(reg->img=xine_xmalloc(region_width*region_height)) ) { + if ( !(reg->img=malloc(region_width*region_height)) ) { lprintf( "can't allocate mem for region %d\n", region_id ); return; } @@ -188,10 +185,9 @@ static void update_region (dvb_spu_decod static void do_plot (dvb_spu_decoder_t * this, int r, int x, int y, unsigned char pixel) { - int i; - dvbsub_func_t *dvbsub = this->dvbsub; - - i = (y * dvbsub->regions[r].width) + x; + dvbsub_func_t *const dvbsub = this->dvbsub; + + const int i = (y * dvbsub->regions[r].width) + x; /* do some clipping */ if ( i<(dvbsub->regions[r].width*dvbsub->regions[r].height) ) { dvbsub->regions[r].img[i] = pixel; @@ -204,7 +200,7 @@ static void plot (dvb_spu_decoder_t * th dvbsub_func_t *dvbsub = this->dvbsub; - int x2 = dvbsub->x + run_length; + const int x2 = dvbsub->x + run_length; while (dvbsub->x < x2) { do_plot (this, r, dvbsub->x, dvbsub->y, pixel); @@ -212,97 +208,90 @@ static void plot (dvb_spu_decoder_t * th } } -static unsigned char next_nibble (dvb_spu_decoder_t * this) -{ - unsigned char x; - dvbsub_func_t *dvbsub = this->dvbsub; - - if (dvbsub->nibble_flag == 0) { - x = (dvbsub->buf[dvbsub->i] & 0xf0) >> 4; - dvbsub->nibble_flag = 1; - } - else { - x = (dvbsub->buf[dvbsub->i++] & 0x0f); - dvbsub->nibble_flag = 0; - } - return (x); +static uint8_t next_nibble (dvb_spu_decoder_t * this) +{ + dvbsub_func_t *dvbsub = this->dvbsub; + + dvbsub->nibble_flag = !dvbsub->nibble_flag; + + if (dvbsub->nibble_flag) /* Inverted! */ + return (dvbsub->buf[dvbsub->i] & 0xf0) >> 4; + else + return (dvbsub->buf[dvbsub->i++] & 0x0f); } static void decode_4bit_pixel_code_string (dvb_spu_decoder_t * this, int r, int object_id, int ofs, int n) { - int next_bits, switch_1, switch_2, switch_3, run_length, pixel_code; - - dvbsub_func_t *dvbsub = this->dvbsub; - - int bits; - unsigned int data; - int j; + dvbsub_func_t *const dvbsub = this->dvbsub; if (dvbsub->in_scanline == 0) { dvbsub->in_scanline = 1; } dvbsub->nibble_flag = 0; - j = dvbsub->i + n; + const int j = dvbsub->i + n; while (dvbsub->i < j) { - bits = 0; - pixel_code = 0; - next_bits = next_nibble (this); + int bits = 0; + const uint8_t next_bits = next_nibble (this); if (next_bits != 0) { - pixel_code = next_bits; + const uint8_t pixel_code = next_bits; plot (this, r, 1, pixel_code); [... 597 lines omitted ...] - break; - } - } - this->dvbsub->i = new_i; - } - - return; + this->dvbsub->page.page_id = (this->dvbsub->buf[this->dvbsub->i] << 8) | this->dvbsub->buf[this->dvbsub->i + 1]; + const uint16_t segment_length = _X_BE_16(&this->dvbsub->buf[this->dvbsub->i + 2]); + const int new_i = this->dvbsub->i + segment_length + 4; + + /* only process complete segments */ + if(new_i > (this->pes_pkt_wrptr - this->pes_pkt)) + break; + + /* verify we've the right segment */ + if(this->dvbsub->page.page_id==this->spu_descriptor->comp_page_id){ + /* SEGMENT_DATA_FIELD */ + switch (segment_type) { + case 0x10: + process_page_composition_segment (this); + break; + case 0x11: + process_region_composition_segment (this); + break; + case 0x12: + process_CLUT_definition_segment(this); + break; + case 0x13: + process_object_data_segment (this); + break; + case 0x80: /* Page is now completely rendered */ + draw_subtitles( this ); + break; + default: + return; + break; + } + } + this->dvbsub->i = new_i; + } } static void spudec_reset (spu_decoder_t * this_gen) @@ -872,42 +837,30 @@ static void spudec_dispose (spu_decoder_ static void spudec_dispose (spu_decoder_t * this_gen) { dvb_spu_decoder_t *this = (dvb_spu_decoder_t *) this_gen; - int i; pthread_cancel(this->dvbsub_timer_thread); pthread_join(this->dvbsub_timer_thread, NULL); pthread_mutex_destroy(&this->dvbsub_osd_mutex); pthread_cond_destroy(&this->dvbsub_restart_timeout); - if(this->spu_descriptor){ - free(this->spu_descriptor); - this->spu_descriptor=NULL; - } - + free(this->spu_descriptor); + this->spu_descriptor=NULL; + + int i; for ( i=0; i<MAX_REGIONS; i++ ) { - if ( this->dvbsub->regions[i].img ) - free( this->dvbsub->regions[i].img ); + free( this->dvbsub->regions[i].img ); if ( this->dvbsub->regions[i].osd ) this->stream->osd_renderer->free_object( this->dvbsub->regions[i].osd ); } - if (this->pes_pkt) - free (this->pes_pkt); - - if (this->dvbsub) - free (this->dvbsub); - + free (this->pes_pkt); + free (this->dvbsub); free (this); } static spu_decoder_t *dvb_spu_class_open_plugin (spu_decoder_class_t * class_gen, xine_stream_t * stream) { - - int i; - dvb_spu_decoder_t *this; - dvb_spu_class_t *class = (dvb_spu_class_t *) class_gen; - - this = calloc(1, sizeof (dvb_spu_decoder_t)); + dvb_spu_decoder_t *this = calloc(1, sizeof (dvb_spu_decoder_t)); this->spu_decoder.decode_data = spudec_decode_data; this->spu_decoder.reset = spudec_reset; @@ -916,20 +869,13 @@ static spu_decoder_t *dvb_spu_class_open this->spu_decoder.get_interact_info = NULL; this->spu_decoder.set_button = NULL; - this->class = class; + this->class = class_gen; this->stream = stream; this->pes_pkt = calloc(65, 1024); this->spu_descriptor = calloc(1, sizeof(spu_dvb_descriptor_t)); this->dvbsub = calloc(1, sizeof (dvbsub_func_t)); - - for (i = 0; i < MAX_REGIONS; i++) { - this->dvbsub->page.regions[i].is_visible = 0; - this->dvbsub->regions[i].img = NULL; - this->dvbsub->regions[i].osd = NULL; - this->dvbsub->regions[i].CLUT_id = 0; - } pthread_mutex_init(&this->dvbsub_osd_mutex, NULL); pthread_cond_init(&this->dvbsub_restart_timeout, NULL); @@ -957,9 +903,7 @@ static char *dvb_spu_class_get_descripti static void *init_spu_decoder_plugin (xine_t * xine, void *data) { - - dvb_spu_class_t *this; - this = calloc(1, sizeof (dvb_spu_class_t)); + dvb_spu_class_t *this = calloc(1, sizeof (dvb_spu_class_t)); this->class.open_plugin = dvb_spu_class_open_plugin; this->class.get_identifier = dvb_spu_class_get_identifier; |