[prev in list] [next in list] [prev in thread] [next in thread]
List: xine-cvslog
Subject: [xine-cvs] HG: xine-lib: Simplify code and update code style.
From: "=?UTF-8?Q?Diego=20'Flameeyes'=20Petten=C3=B2?=" <flameeyes () gmail ! com>
Date: 2008-07-04 14:37:46
Message-ID: 46f532cae19d304279f9.1215181597 () hg ! debian ! org
[Download RAW message or body]
# HG changeset patch
# User Diego 'Flameeyes' Pettenò <flameeyes@gmail.com>
# Date 1215181597 -7200
# Node ID 46f532cae19d304279f9168a92a325f90956804d
# Parent 3022ff11598508d7e994ba3f02eba36837205458
Simplify code and update code style.
diff -r 46f532cae19d304279f9168a92a325f90956804d -r \
3022ff11598508d7e994ba3f02eba36837205458 \
src/libsputext/demux_sputext.c
--- a/src/libsputext/demux_sputext.c Fri Jul 04 16:26:37 2008 +0200
+++ b/src/libsputext/demux_sputext.c Fri Jul 04 16:24:55 2008 +0200
@@ -146,8 +146,6 @@ static inline void trail_space(char *s)
*/
static char *read_line_from_input(demux_sputext_t *this, char *line, off_t len) {
off_t nread = 0;
- char *s;
- int linelen;
if ((len - this->buflen) > 512) {
if((nread = this->input->read(this->input,
@@ -160,11 +158,11 @@ static char *read_line_from_input(demux_
this->buflen += nread;
this->buf[this->buflen] = '\0';
- s = strchr(this->buf, '\n');
+ char *s = strchr(this->buf, '\n');
if (line && (s || this->buflen)) {
- linelen = s ? (s - this->buf) + 1 : this->buflen;
+ size_t linelen = s ? (s - this->buf) + 1 : this->buflen;
memcpy(line, this->buf, linelen);
line[linelen] = '\0';
@@ -183,13 +181,12 @@ static subtitle_t *sub_read_line_sami(de
static char line[LINE_LEN + 1];
static char *s = NULL;
- char text[LINE_LEN + 1], *p, *q;
- int state;
-
- p = NULL;
+ char text[LINE_LEN + 1];
+
+ char *p = NULL;
current->lines = current->start = 0;
current->end = -1;
- state = 0;
+ int state = 0;
/* read the first line */
if (!s)
@@ -229,14 +226,16 @@ static subtitle_t *sub_read_line_sami(de
continue;
case 4: /* get current->end or skip <TAG> */
- q = strstr (s, "Start=");
- if (q) {
- current->end = strtol (q + 6, &q, 0) / 10 - 1;
- *p = '\0'; trail_space (text);
- if (text[0] != '\0')
- current->text[current->lines++] = strdup (text);
- if (current->lines > 0) { state = 99; break; }
- state = 0; continue;
+ {
+ char *q = strstr (s, "Start=");
+ if (q) {
+ current->end = strtol (q + 6, &q, 0) / 10 - 1;
+ *p = '\0'; trail_space (text);
+ if (text[0] != '\0')
+ current->text[current->lines++] = strdup (text);
+ if (current->lines > 0) { state = 99; break; }
+ state = 0; continue;
+ }
}
s = strchr (s, '>');
if (s) { s++; state = 3; continue; }
@@ -254,7 +253,7 @@ static subtitle_t *sub_read_line_sami(de
static char *sub_readtext(char *source, char **dest) {
- int len=0;
+ size_t len=0;
char *p=source;
while ( !eol(*p) && *p!= '|' ) {
@@ -274,8 +273,6 @@ static subtitle_t *sub_read_line_microdv
char line[LINE_LEN + 1];
char line2[LINE_LEN + 1];
- char *p, *next;
- int i;
memset (current, 0, sizeof(subtitle_t));
@@ -286,9 +283,10 @@ static subtitle_t *sub_read_line_microdv
(sscanf (line, "{%ld}{%ld}%" LINE_LEN_QUOT "[^\r\n]", &(current->start), \
&(current->end),line2) !=3) );
- p=line2;
-
- next=p, i=0;
+ char *p=line2;
+
+ char *next=p;
+ size_t i=0;
while ((next =sub_readtext (next, &(current->text[i])))) {
if (current->text[i]==ERR) return ERR;
i++;
@@ -304,28 +302,30 @@ static subtitle_t *sub_read_line_microdv
}
static subtitle_t *sub_read_line_subviewer(demux_sputext_t *this, subtitle_t \
*current) {
-
char line[LINE_LEN + 1];
- int a1,a2,a3,a4,b1,b2,b3,b4;
- char *p=NULL, *q=NULL;
- int len;
memset (current, 0, sizeof(subtitle_t));
while (1) {
if (!read_line_from_input(this, line, LINE_LEN)) return NULL;
- if (sscanf (line, "%d:%d:%d.%d,%d:%d:%d.%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4) < \
8) {
- if (sscanf (line, "%d:%d:%d,%d,%d:%d:%d,%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4) < \
8)
- continue;
- }
- current->start = a1*360000+a2*6000+a3*100+a4;
- current->end = b1*360000+b2*6000+b3*100+b4;
-
+
+ {
+ int a1,a2,a3,a4,b1,b2,b3,b4;
+ if (sscanf (line, "%d:%d:%d.%d,%d:%d:%d.%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4) < \
8) { + if (sscanf (line, "%d:%d:%d,%d,%d:%d:%d,%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4) < \
8) + continue;
[... 917 lines omitted ...]
this->uses_time=0;
xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "aqtitle subtitle format \
detected\n"); @@ -1103,9 +1124,6 @@ static int sub_autodetect (demux_sputext
static subtitle_t *sub_read_file (demux_sputext_t *this) {
- int n_max;
- int timeout;
- subtitle_t *first;
subtitle_t * (*func[])(demux_sputext_t *this,subtitle_t *dest)=
{
sub_read_line_microdvd,
@@ -1146,23 +1164,23 @@ static subtitle_t *sub_read_file (demux_
}
this->buflen = 0;
- this->num=0;n_max=32;
- first = calloc(n_max, sizeof(subtitle_t));
+ this->num=0;
+ int n_max=32;
+ subtitle_t *first = calloc(n_max, sizeof(subtitle_t));
if(!first) return NULL;
- timeout = ((demux_sputext_class_t *)
- (this->demux_plugin.demux_class))->max_timeout;
- if (this->uses_time) timeout *= 100;
- else timeout *= 10;
+
+ const int timeout =
+ (((demux_sputext_class_t *)
+ (this->demux_plugin.demux_class))->max_timeout) *
+ (this->uses_time ? 100 : 10);
while(1) {
- subtitle_t *sub;
-
if(this->num>=n_max){
n_max+=16;
first=realloc(first,n_max*sizeof(subtitle_t));
}
- sub = func[this->format] (this, &first[this->num]);
+ subtitle_t *sub = func[this->format] (this, &first[this->num]);
if (!sub)
break; /* EOF */
@@ -1210,27 +1228,26 @@ static subtitle_t *sub_read_file (demux_
static int demux_sputext_next (demux_sputext_t *this_gen) {
demux_sputext_t *this = (demux_sputext_t *) this_gen;
- buf_element_t *buf;
- uint32_t *val;
- char *str;
- subtitle_t *sub;
- int line;
if (this->cur >= this->num)
return 0;
- sub = &this->subtitles[this->cur];
-
- buf = this->stream->video_fifo->buffer_pool_alloc(this->stream->video_fifo);
+ subtitle_t *sub = &this->subtitles[this->cur];
+
+ buf_element_t *buf = \
this->stream->video_fifo->buffer_pool_alloc(this->stream->video_fifo); buf->type = \
BUF_SPU_TEXT; buf->pts = 0;
- val = (uint32_t * )buf->content;
+ uint32_t *val = (uint32_t * )buf->content;
*val++ = sub->lines;
*val++ = this->uses_time;
*val++ = (this->uses_time) ? sub->start * 10 : sub->start;
*val++ = (this->uses_time) ? sub->end * 10 : sub->end;
- str = (char *)val;
+ char *str = (char *)val;
+
+ /** @FIXME The way this works seems wrong, SUB_BUFSIZE-1 is not the
+ right maximum, I think. */
+ int line;
for (line = 0; line < sub->lines; line++, str+=strlen(str)+1) {
strncpy(str, sub->text[line], SUB_BUFSIZE-1);
str[SUB_BUFSIZE-1] = '\0';
@@ -1244,9 +1261,10 @@ static int demux_sputext_next (demux_spu
static void demux_sputext_dispose (demux_plugin_t *this_gen) {
demux_sputext_t *this = (demux_sputext_t *) this_gen;
- int i, l;
-
+
+ int i;
for (i = 0; i < this->num; i++) {
+ int l;
for (l = 0; l < this->subtitles[i].lines; l++)
free(this->subtitles[i].text[l]);
}
@@ -1262,11 +1280,9 @@ static int demux_sputext_get_stream_leng
static int demux_sputext_get_stream_length (demux_plugin_t *this_gen) {
demux_sputext_t *this = (demux_sputext_t *) this_gen;
- if( this->uses_time && this->num ) {
- return this->subtitles[this->num-1].end * 10;
- } else {
- return 0;
- }
+ return ( this->uses_time && this->num ) ?
+ this->subtitles[this->num-1].end * 10 :
+ 0;
}
static int demux_sputext_send_chunk (demux_plugin_t *this_gen) {
@@ -1299,8 +1315,6 @@ static int demux_sputext_seek (demux_plu
static void demux_sputext_send_headers(demux_plugin_t *this_gen) {
demux_sputext_t *this = (demux_sputext_t*)this_gen;
- buf_element_t *buf;
-
lprintf("send_headers() called\n");
@@ -1309,7 +1323,7 @@ static void demux_sputext_send_headers(d
_x_stream_info_set(this->stream, XINE_STREAM_INFO_HAS_AUDIO, 0);
/* enable the SPU channel */
- buf = this->stream->video_fifo->buffer_pool_alloc(this->stream->video_fifo);
+ buf_element_t *buf = \
this->stream->video_fifo->buffer_pool_alloc(this->stream->video_fifo); buf->type = \
BUF_CONTROL_SPU_CHANNEL; buf->decoder_info[0] = buf->decoder_info[1] = \
buf->decoder_info[2] = 0; this->stream->video_fifo->put(this->stream->video_fifo, \
buf);
diff -r 46f532cae19d304279f9168a92a325f90956804d -r \
3022ff11598508d7e994ba3f02eba36837205458 \
src/libsputext/xine_sputext_decoder.c
--- a/src/libsputext/xine_sputext_decoder.c Fri Jul 04 16:26:37 2008 +0200
+++ b/src/libsputext/xine_sputext_decoder.c Fri Jul 04 16:24:55 2008 +0200
@@ -63,7 +63,7 @@
#define rgb2yuv(R,G,B) \
((((((66*R+129*G+25*B+128)>>8)+16)<<8)|(((112*R-94*G-18*B+128)>>8)+128))<<8|(((-38*R-74*G+112*B+128)>>8)+128))
-static uint32_t sub_palette[22]={
+static const uint32_t sub_palette[22]={
/* RED */
rgb2yuv(0,0,0),
rgb2yuv(0,0,0),
@@ -90,7 +90,7 @@ static uint32_t sub_palette[22]={
rgb2yuv(0,170,255)
};
-static uint8_t sub_trans[22]={
+static const uint8_t sub_trans[22]={
0, 0, 3, 6, 8, 10, 12, 14, 15, 15, 15,
0, 0, 3, 6, 8, 10, 12, 14, 15, 15, 15
};
@@ -185,7 +185,7 @@ static inline char *get_font (sputext_cl
}
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_de
}
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;
@@ -303,7 +301,7 @@ static void update_output_size (sputext_
}
}
-static int parse_utf8_size(unsigned char *c)
+static int parse_utf8_size(const uint8_t *c)
{
if ( c[0]<0x80 )
return 1;
@@ -329,13 +327,8 @@ static int parse_utf8_size(unsigned char
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) {
@@ -379,6 +372,7 @@ static int ogm_render_line_internal(sput
if (text[i] == '{') {
if (!strncmp("{\\", text+i, 2)) {
+ int value;
if (sscanf(text+i, "{\\b%d}", &value) == 1) {
if (render) {
@@ -395,7 +389,7 @@ static int ogm_render_line_internal(sput
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;
@@ -403,15 +397,20 @@ static int ogm_render_line_internal(sput
}
}
- 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;
@@ -547,15 +546,9 @@ static int is_cjk_encoding(const char *e
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 )
@@ -565,21 +558,20 @@ static void draw_subtitle(sputext_decode
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);
-
-
- rebuild_all = 0;
+ int font_size = this->font_size;
+
+ const char *const encoding = this->buf_encoding ? : this->class->src_encoding;
+ this->renderer->set_encoding(this->osd, encoding);
+
+ int rebuild_all = 0;
+ int line;
for (line = 0; line < this->lines; line++) {
int line_width = ogm_get_width(this, this->text[line]);
@@ -637,30 +629,27 @@ static void draw_subtitle(sputext_decode
/* 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];
-
- buf[0] = 0;
+ char buf[SUB_BUFSIZE * SUB_MAX_TEXT] = { 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;
- }
-
- stream = buf;
+
+ strncat(buf, this->text[line], SUB_BUFSIZE-len-1);
+ }
+
+ 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) {
-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
Xine-cvslog mailing list
Xine-cvslog@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/xine-cvslog
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic