diff options
Diffstat (limited to 'src/spu_dec')
-rw-r--r-- | src/spu_dec/cmml_decoder.c | 97 | ||||
-rw-r--r-- | src/spu_dec/spu_decoder.c | 17 | ||||
-rw-r--r-- | src/spu_dec/sputext_decoder.c | 77 |
3 files changed, 83 insertions, 108 deletions
diff --git a/src/spu_dec/cmml_decoder.c b/src/spu_dec/cmml_decoder.c index 4dea5645f..da59ed8ae 100644 --- a/src/spu_dec/cmml_decoder.c +++ b/src/spu_dec/cmml_decoder.c @@ -94,8 +94,7 @@ static void update_font_size (spucmml_decoder_t *this) { { 16, 20, 24, 32 }, /* SUBTITLE_SIZE_LARGE */ }; - const int *vec = sizes[this->subtitle_size]; - int y; + const int *const vec = sizes[this->subtitle_size]; if( this->cached_width >= 512 ) this->font_size = vec[3]; @@ -108,7 +107,7 @@ static void update_font_size (spucmml_decoder_t *this) { this->line_height = this->font_size + 10; - y = this->cached_height - (SUB_MAX_TEXT * this->line_height) - 5; + int y = this->cached_height - (SUB_MAX_TEXT * this->line_height) - 5; if(((y - this->vertical_offset) >= 0) && ((y - this->vertical_offset) <= this->cached_height)) y -= this->vertical_offset; @@ -137,83 +136,80 @@ static void update_font_size (spucmml_decoder_t *this) { } static int get_width(spucmml_decoder_t *this, char* text) { - size_t i=0; - int width=0,w,dummy; - char letter[2]={0, 0}; + int width=0; + + while (1) + switch (*text) { + case '\0': + llprintf(LOG_WIDTH, "get_width returning width of %d\n", width); + return width; - while (i<=strlen(text)) { - switch (text[i]) { case '<': - if (!strncmp("<b>", text+i, 3)) { + if (!strncmp("<b>", text, 3)) { /*Do somethink to enable BOLD typeface*/ - i=i+3; + text += 3; break; - } else if (!strncmp("</b>", text+i, 3)) { + } else if (!strncmp("</b>", text, 3)) { /*Do somethink to disable BOLD typeface*/ - i=i+4; + text += 4; break; - } else if (!strncmp("<i>", text+i, 3)) { + } else if (!strncmp("<i>", text, 3)) { /*Do somethink to enable italics typeface*/ - i=i+3; + text += 3; break; - } else if (!strncmp("</i>", text+i, 3)) { + } else if (!strncmp("</i>", text, 3)) { /*Do somethink to disable italics typeface*/ - i=i+4; + text += 4; break; - } else if (!strncmp("<font>", text+i, 3)) { + } else if (!strncmp("<font>", text, 3)) { /*Do somethink to disable typing fixme - no teststreams*/ - i=i+6; + text += 6; break; - } else if (!strncmp("</font>", text+i, 3)) { + } else if (!strncmp("</font>", text, 3)) { /*Do somethink to enable typing fixme - no teststreams*/ - i=i+7; + text += 7; break; } default: - letter[0]=text[i]; - this->stream->osd_renderer->get_text_size(this->osd, letter, &w, &dummy); - width=width+w; - i++; + { + int w, dummy; + const char letter[2] = { *text, '\0' }; + this->stream->osd_renderer->get_text_size(this->osd, letter, &w, &dummy); + width += w; + text++; + } } - } - - llprintf(LOG_WIDTH, "get_width returning width of %d\n", width); - - return width; } static void render_line(spucmml_decoder_t *this, int x, int y, char* text) { - size_t i=0; - int w,dummy; - char letter[2]={0,0}; + while (*text != '\0') { + int w, dummy; + const char letter[2] = { *text, '\0' }; - while (i<=strlen(text)) { - letter[0]=text[i]; this->stream->osd_renderer->render_text(this->osd, x, y, letter, OSD_TEXT1); this->stream->osd_renderer->get_text_size(this->osd, letter, &w, &dummy); - x=x+w; - i++; + x += w; + text++; } } static void draw_subtitle(spucmml_decoder_t *this, int64_t sub_start) { - int line, y; - int font_size; - this->stream->osd_renderer->filled_rect (this->osd, 0, 0, this->cached_width-1, this->line_height * SUB_MAX_TEXT - 1, 0); - y = (SUB_MAX_TEXT - this->lines) * this->line_height; - font_size = this->font_size; + const int y = (SUB_MAX_TEXT - this->lines) * this->line_height; + int font_size = this->font_size; this->stream->osd_renderer->set_encoding(this->osd, this->class->src_encoding); + int line; + for (line=0; line<this->lines; line++) { - int w,x; + int x; while(1) { - w=get_width( this, this->text[line]); + const int w = get_width( this, this->text[line]); x = (this->cached_width - w) / 2; if( w > this->cached_width && font_size > 16 ) { @@ -242,14 +238,13 @@ static void draw_subtitle(spucmml_decoder_t *this, int64_t sub_start) { static void spudec_decode_data (spu_decoder_t *this_gen, buf_element_t *buf) { spucmml_decoder_t *this = (spucmml_decoder_t *) this_gen; - char *str; xml_node_t *packet_xml_root; char * anchor_text = NULL; lprintf("CMML packet seen\n"); - str = (char *) buf->content; + char *str = (char *) buf->content; /* parse the CMML */ @@ -440,11 +435,8 @@ static void update_osd_font(void *this_gen, xine_cfg_entry_t *entry) } static spu_decoder_t *spucmml_class_open_plugin (spu_decoder_class_t *class_gen, xine_stream_t *stream) { - spucmml_class_t *class = (spucmml_class_t *)class_gen; - spucmml_decoder_t *this ; - - this = (spucmml_decoder_t *) calloc(1, sizeof(spucmml_decoder_t)); + spucmml_decoder_t *this = (spucmml_decoder_t *) calloc(1, sizeof(spucmml_decoder_t)); this->spu_decoder.decode_data = spudec_decode_data; this->spu_decoder.reset = spudec_reset; @@ -454,7 +446,7 @@ static spu_decoder_t *spucmml_class_open_plugin (spu_decoder_class_t *class_gen, this->spu_decoder.set_button = NULL; this->spu_decoder.dispose = spudec_dispose; - this->class = class; + this->class = class_gen; this->stream = stream; this->event_queue = xine_event_new_queue (this->stream); @@ -493,10 +485,7 @@ static void update_src_encoding(void *this_gen, xine_cfg_entry_t *entry) } static void *init_spu_decoder_plugin (xine_t *xine, void *data) { - - spucmml_class_t *this ; - - this = (spucmml_class_t *) calloc(1, sizeof(spucmml_class_t)); + spucmml_class_t *this = (spucmml_class_t *) calloc(1, sizeof(spucmml_class_t)); this->class.open_plugin = spucmml_class_open_plugin; this->class.identifier = "spucmml"; diff --git a/src/spu_dec/spu_decoder.c b/src/spu_dec/spu_decoder.c index a2c0a8827..b77c5b493 100644 --- a/src/spu_dec/spu_decoder.c +++ b/src/spu_dec/spu_decoder.c @@ -69,11 +69,9 @@ static const clut_t default_clut[] = { }; static void spudec_decode_data (spu_decoder_t *this_gen, buf_element_t *buf) { - uint32_t stream_id; - spudec_seq_t *cur_seq; spudec_decoder_t *this = (spudec_decoder_t *) this_gen; - stream_id = buf->type & 0x1f ; - cur_seq = &this->spudec_stream_state[stream_id].ra_seq; + const uint8_t stream_id = buf->type & 0x1f ; + spudec_seq_t *cur_seq = &this->spudec_stream_state[stream_id].ra_seq; #ifdef LOG_DEBUG printf("libspudec:got buffer type = %x\n", buf->type); @@ -178,7 +176,6 @@ static void spudec_discontinuity (spu_decoder_t *this_gen) { static void spudec_dispose (spu_decoder_t *this_gen) { spudec_decoder_t *this = (spudec_decoder_t *) this_gen; - int i; video_overlay_manager_t *ovl_manager = this->stream->video_out->get_overlay_manager (this->stream->video_out); if( this->menu_handle >= 0 ) @@ -186,6 +183,7 @@ static void spudec_dispose (spu_decoder_t *this_gen) { this->menu_handle); this->menu_handle = -1; + int i; for (i=0; i < MAX_STREAMS; i++) { if( this->spudec_stream_state[i].overlay_handle >= 0 ) ovl_manager->free_handle(ovl_manager, @@ -226,11 +224,9 @@ static void spudec_set_button (spu_decoder_t *this_gen, int32_t button, int32_t * when video_overlay does menus */ video_overlay_manager_t *ovl_manager; - video_overlay_event_t *overlay_event = NULL; - vo_overlay_t *overlay = NULL; - overlay_event = calloc(1, sizeof(video_overlay_event_t)); + video_overlay_event_t *overlay_event = calloc(1, sizeof(video_overlay_event_t)); + vo_overlay_t *overlay = calloc(1, sizeof(vo_overlay_t)); - overlay = calloc(1, sizeof(vo_overlay_t)); /* FIXME: Watch out for threads. We should really put a lock on this * because events is a different thread than decode_data */ @@ -314,7 +310,6 @@ static void spudec_set_button (spu_decoder_t *this_gen, int32_t button, int32_t static spu_decoder_t *open_plugin (spu_decoder_class_t *class_gen, xine_stream_t *stream) { spudec_decoder_t *this ; - int i; this = (spudec_decoder_t *) calloc(1, sizeof (spudec_decoder_t)); @@ -338,6 +333,8 @@ static spu_decoder_t *open_plugin (spu_decoder_class_t *class_gen, xine_stream_t this->ovl_caps = stream->video_out->get_capabilities(stream->video_out); this->output_open = 0; this->last_event_vpts = 0; + + int i; for (i=0; i < MAX_STREAMS; i++) { this->spudec_stream_state[i].ra_seq.complete = 1; this->spudec_stream_state[i].overlay_handle = -1; diff --git a/src/spu_dec/sputext_decoder.c b/src/spu_dec/sputext_decoder.c index 615910275..e86ee76e3 100644 --- a/src/spu_dec/sputext_decoder.c +++ b/src/spu_dec/sputext_decoder.c @@ -185,7 +185,7 @@ static inline char *get_font (sputext_class_t *class) } static void update_font_size (sputext_decoder_t *this, int force_update) { - static int sizes[SUBTITLE_SIZE_NUM] = { 16, 20, 24, 32, 48, 64 }; + static const int sizes[SUBTITLE_SIZE_NUM] = { 16, 20, 24, 32, 48, 64 }; if ((this->subtitle_size != this->class->subtitle_size) || (this->vertical_offset != this->class->vertical_offset) || @@ -214,11 +214,9 @@ static void update_font_size (sputext_decoder_t *this, int force_update) { } static void update_output_size (sputext_decoder_t *this) { - int unscaled; - - unscaled = this->class->use_unscaled && - (this->stream->video_out->get_capabilities(this->stream->video_out) & - VO_CAP_UNSCALED_OVERLAY); + const int unscaled = this->class->use_unscaled && + (this->stream->video_out->get_capabilities(this->stream->video_out) & + VO_CAP_UNSCALED_OVERLAY); if( unscaled != this->unscaled ) { this->unscaled = unscaled; @@ -330,13 +328,8 @@ static int parse_utf8_size(const void *buf) static int ogm_render_line_internal(sputext_decoder_t *this, int x, int y, const char *text, int render) { - int i = 0, w, value; - char* end; - char letter[5]={0, 0, 0, 0, 0}; - const char *encoding = this->buf_encoding ? this->buf_encoding - : this->class->src_encoding; - int shift, isutf8 = !strcmp(encoding, "utf-8"); - size_t length = strlen (text); + const size_t length = strlen (text); + size_t i = 0; while (i <= length) { @@ -380,6 +373,7 @@ static int ogm_render_line_internal(sputext_decoder_t *this, int x, int y, const if (text[i] == '{') { if (!strncmp("{\\", text+i, 2)) { + int value; if (sscanf(text+i, "{\\b%d}", &value) == 1) { if (render) { @@ -396,7 +390,7 @@ static int ogm_render_line_internal(sputext_decoder_t *this, int x, int y, const this->current_osd_text = OSD_TEXT1; } } - end = strstr(text+i+2, "}"); + char *const end = strstr(text+i+2, "}"); if (end) { i=end-text+1; continue; @@ -404,15 +398,20 @@ static int ogm_render_line_internal(sputext_decoder_t *this, int x, int y, const } } - shift = isutf8 ? parse_utf8_size (&text[i]) : 1; + char letter[5]; + const char *const encoding = this->buf_encoding ? : this->class->src_encoding; + const int isutf8 = !strcmp(encoding, "utf-8"); + const size_t shift = isutf8 ? parse_utf8_size (&text[i]) : 1; memcpy(letter,&text[i],shift); letter[shift]=0; if (render) this->renderer->render_text(this->osd, x, y, letter, this->current_osd_text); - this->renderer->get_text_size(this->osd, letter, &w, &value); - x=x+w; - i+=shift; + + int w, dummy; + this->renderer->get_text_size(this->osd, letter, &w, &dummy); + x += w; + i += shift; } return x; @@ -548,15 +547,9 @@ static int is_cjk_encoding(const char *enc) { static void draw_subtitle(sputext_decoder_t *this, int64_t sub_start, int64_t sub_end ) { - int line, y; - int font_size; - char *font; - const char *encoding = (this->buf_encoding)?this->buf_encoding: - this->class->src_encoding; + int y; int sub_x, sub_y, max_width; int alignment; - int rebuild_all; - _x_assert(this->renderer != NULL); if ( ! this->renderer ) @@ -566,21 +559,20 @@ static void draw_subtitle(sputext_decoder_t *this, int64_t sub_start, int64_t su update_font_size(this, 0); - font = get_font (this->class); + const char *const font = get_font (this->class); if( strcmp(this->font, font) ) { strncpy(this->font, font, FILENAME_MAX); this->font[FILENAME_MAX - 1] = '\0'; this->renderer->set_font (this->osd, font, this->font_size); } - font_size = this->font_size; - if (this->buf_encoding) - this->renderer->set_encoding(this->osd, this->buf_encoding); - else - this->renderer->set_encoding(this->osd, this->class->src_encoding); + int font_size = this->font_size; + const char *const encoding = this->buf_encoding ? : this->class->src_encoding; + this->renderer->set_encoding(this->osd, encoding); - rebuild_all = 0; + int rebuild_all = 0; + int line; for (line = 0; line < this->lines; line++) { int line_width = ogm_get_width(this, this->text[line]); @@ -638,30 +630,27 @@ static void draw_subtitle(sputext_decoder_t *this, int64_t sub_start, int64_t su /* regenerate all the lines to find something that better fits */ if (rebuild_all) { - int line, line_width; - char *stream, *current_cut, *best_cut; - char buf[SUB_BUFSIZE * SUB_MAX_TEXT]; + char buf[SUB_BUFSIZE * SUB_MAX_TEXT] = { 0, }; - buf[0] = 0; + int line; for(line = 0; line < this->lines; line++) { - size_t len = strlen(buf); - if (len) { + const size_t len = strlen(buf); + if (len) buf[len] = ' '; - len++; - } - strncpy(buf + len, this->text[line], SUB_BUFSIZE); - *(buf + len + SUB_BUFSIZE) = 0; + + strncat(buf, this->text[line], SUB_BUFSIZE-len-1); } - stream = buf; + char *stream = buf; this->lines = 0; + char *current_cut, *best_cut; do { if (this->lines + 1 < SUB_MAX_TEXT) { /* find the longest sequence witch fit */ - line_width = 0; + int line_width = 0; current_cut = stream; best_cut = NULL; while (line_width < max_width) { |