From 736cc44919cb9b010e4784821afb060b1352945a Mon Sep 17 00:00:00 2001 From: Carlo Bramini Date: Tue, 13 Oct 2009 22:06:09 +0100 Subject: #include guards and __attribute__ fixups --- src/demuxers/demux_flac.c | 3 +++ src/demuxers/demux_real.c | 3 +++ src/demuxers/demux_tta.c | 2 +- src/input/libdvdnav/dvd_reader.c | 2 ++ src/xine-engine/alphablend.c | 4 ++-- src/xine-engine/scratch.c | 2 +- src/xine-engine/scratch.h | 5 +---- 7 files changed, 13 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_flac.c b/src/demuxers/demux_flac.c index c14536040..c4132b767 100644 --- a/src/demuxers/demux_flac.c +++ b/src/demuxers/demux_flac.c @@ -33,6 +33,9 @@ #include #include #include +#ifdef HAVE_MALLOC_H +#include +#endif #define LOG_MODULE "demux_flac" #define LOG_VERBOSE diff --git a/src/demuxers/demux_real.c b/src/demuxers/demux_real.c index 8f1e4f539..774c74e2c 100644 --- a/src/demuxers/demux_real.c +++ b/src/demuxers/demux_real.c @@ -42,6 +42,9 @@ #include #include #include +#ifdef HAVE_MALLOC_H +#include +#endif #define LOG_MODULE "demux_real" #define LOG_VERBOSE diff --git a/src/demuxers/demux_tta.c b/src/demuxers/demux_tta.c index 24a983157..7853c8182 100644 --- a/src/demuxers/demux_tta.c +++ b/src/demuxers/demux_tta.c @@ -58,7 +58,7 @@ typedef struct { uint32_t samplerate; uint32_t data_length; uint32_t crc32; - } __attribute__((__packed__)) tta; + } XINE_PACKED tta; uint8_t buffer[22]; /* This is the size of the header */ } header; } demux_tta_t; diff --git a/src/input/libdvdnav/dvd_reader.c b/src/input/libdvdnav/dvd_reader.c index eff1977fc..1e0d3016b 100644 --- a/src/input/libdvdnav/dvd_reader.c +++ b/src/input/libdvdnav/dvd_reader.c @@ -30,7 +30,9 @@ #include #include #include +#ifdef HAVE_DIRENT_H #include +#endif #ifndef HAVE_GETTIMEOFDAY # ifdef WIN32 diff --git a/src/xine-engine/alphablend.c b/src/xine-engine/alphablend.c index a9b015209..1dcd47eb7 100644 --- a/src/xine-engine/alphablend.c +++ b/src/xine-engine/alphablend.c @@ -1108,7 +1108,7 @@ static void blend_yuv_exact(uint8_t *dst_cr, uint8_t *dst_cb, int src_width, static uint8_t *(*blend_yuv_grow_extra_data(alphablend_t *extra_data, int osd_width))[ 3 ][ 2 ] { - struct __attribute__((packed)) header_s { + struct XINE_PACKED header_s { int id; int max_width; uint8_t *data[ 3 ][ 2 ]; @@ -1550,7 +1550,7 @@ static void blend_yuy2_exact(uint8_t *dst_cr, uint8_t *dst_cb, int src_width, static uint8_t *(*blend_yuy2_grow_extra_data(alphablend_t *extra_data, int osd_width))[ 3 ] { - struct __attribute__((packed)) header_s { + struct XINE_PACKED header_s { int id; int max_width; uint8_t *data[ 3 ]; diff --git a/src/xine-engine/scratch.c b/src/xine-engine/scratch.c index 696e99ffb..980af2f71 100644 --- a/src/xine-engine/scratch.c +++ b/src/xine-engine/scratch.c @@ -37,7 +37,7 @@ #include "xineutils.h" #include "scratch.h" -static void __attribute__((__format__(__printf__, 2, 0))) +static void XINE_FORMAT_PRINTF(2, 0) scratch_printf (scratch_buffer_t *this, const char *format, va_list argp) { time_t t; diff --git a/src/xine-engine/scratch.h b/src/xine-engine/scratch.h index 1029276e3..c45af198f 100644 --- a/src/xine-engine/scratch.h +++ b/src/xine-engine/scratch.h @@ -32,10 +32,7 @@ typedef struct scratch_buffer_s scratch_buffer_t; struct scratch_buffer_s { - void -#if __GNUC__ >= 3 - __attribute__((__format__(__printf__, 2, 0))) -#endif + void XINE_FORMAT_PRINTF(2, 0) (*scratch_printf) (scratch_buffer_t *this, const char *format, va_list ap); char **(*get_content) (scratch_buffer_t *this); -- cgit v1.2.3 From b014f51562c06d6451fc8ec35fa9d08209c9852b Mon Sep 17 00:00:00 2001 From: Carlo Bramini Date: Tue, 13 Oct 2009 22:12:21 +0100 Subject: profiler: use uint64_t & replace arrays with a struct MSVC complained about a memset to a const object and all "long long" variables that are GNU only. I fixed it by grouping the fields into a structure and now even GCC is more happy. --- src/xine-utils/monitor.c | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/xine-utils/monitor.c b/src/xine-utils/monitor.c index 650c10f99..77280ffc6 100644 --- a/src/xine-utils/monitor.c +++ b/src/xine-utils/monitor.c @@ -32,41 +32,42 @@ #ifndef NDEBUG -static long long int profiler_times[MAX_ID] ; -static long long int profiler_start[MAX_ID] ; -static long profiler_calls[MAX_ID] ; -static const char *profiler_label[MAX_ID] ; +typedef struct { + uint64_t p_times; + uint64_t p_start; + long p_calls; + const char *p_label; +} xine_profiler_t; + +static xine_profiler_t profiler[MAX_ID]; void xine_profiler_init () { - memset(profiler_times, 0, sizeof(profiler_times)); - memset(profiler_start, 0, sizeof(profiler_start)); - memset(profiler_calls, 0, sizeof(profiler_calls)); - memset(profiler_label, 0, sizeof(profiler_label)); + memset(profiler, 0, sizeof(profiler)); } int xine_profiler_allocate_slot (const char *label) { int id; - for (id = 0; id < MAX_ID && profiler_label[id] != NULL; id++) + for (id = 0; id < MAX_ID && profiler[id].p_label != NULL; id++) ; if (id >= MAX_ID) return -1; - profiler_label[id] = label; + profiler[id].p_label = label; return id; } #if defined(ARCH_X86_32) -static __inline__ unsigned long long int rdtsc(void) +static __inline__ uint64_t rdtsc(void) { unsigned long long int x; __asm__ volatile ("rdtsc\n\t" : "=A" (x)); return x; } #elif defined(ARCH_X86_64) -static __inline__ unsigned long long int rdtsc(void) +static __inline__ uint64_t rdtsc(void) { unsigned long long int a, d; __asm__ volatile ("rdtsc\n\t" : "=a" (a), "=d" (d)); @@ -78,7 +79,7 @@ void xine_profiler_start_count (int id) { if ( id >= MAX_ID || id < 0 ) return; #if defined(ARCH_X86) || defined(ARCH_X86_64) - profiler_start[id] = rdtsc(); + profiler[id].p_start = rdtsc(); #endif } @@ -86,18 +87,19 @@ void xine_profiler_stop_count (int id) { if ( id >= MAX_ID || id < 0 ) return; #if defined(ARCH_X86) || defined(ARCH_X86_64) - profiler_times[id] += rdtsc() - profiler_start[id]; + profiler[id].p_times += rdtsc() - profiler[id].p_start; #endif - profiler_calls[id]++; + profiler[id].p_calls++; } void xine_profiler_print_results (void) { int i; #if defined(ARCH_X86) || defined(ARCH_X86_64) - static long long int cpu_speed; /* cpu cyles/usec */ + static uint64_t cpu_speed; /* cpu cyles/usec */ + if (!cpu_speed) { - long long int tsc_start, tsc_end; + uint64_t tsc_start, tsc_end; struct timeval tv_start, tv_end; tsc_start = rdtsc(); @@ -119,13 +121,13 @@ void xine_profiler_print_results (void) { "----------------------------------------------------------------------------\n", "ID", "name", "cpu cycles", "calls", "cycles/call", "usec/call"); for (i=0; i Date: Thu, 15 Oct 2009 21:59:29 +0100 Subject: Quick hack to prevent segfaulting at end-of-stream when this->context == NULL. --- src/combined/ffmpeg/ff_video_decoder.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/combined/ffmpeg/ff_video_decoder.c b/src/combined/ffmpeg/ff_video_decoder.c index 2742e3f2e..60f2c5d9c 100644 --- a/src/combined/ffmpeg/ff_video_decoder.c +++ b/src/combined/ffmpeg/ff_video_decoder.c @@ -1194,7 +1194,8 @@ static void ff_handle_buffer (ff_video_decoder_t *this, buf_element_t *buf) { if (this->size == 0) { /* take over pts when we are about to buffer a frame */ this->av_frame->reordered_opaque = ff_tag_pts(this, this->pts); - this->context->reordered_opaque = ff_tag_pts(this, this->pts); + if (this->context) /* shouldn't be NULL */ + this->context->reordered_opaque = ff_tag_pts(this, this->pts); this->pts = 0; } #endif /* AVCODEC_HAS_REORDERED_OPAQUE */ -- cgit v1.2.3 From 6efc8270ef8f75a842930a0f703cb3539f106d4b Mon Sep 17 00:00:00 2001 From: Matt Kraai Date: Thu, 15 Oct 2009 22:01:24 +0100 Subject: Make the XML lexer and parser re-entrant --- src/demuxers/demux_asf.c | 9 ++- src/libspucmml/xine_cmml_decoder.c | 8 ++- src/xine-utils/xmllexer.c | 139 ++++++++++++++++++++----------------- src/xine-utils/xmllexer.h | 25 ++++++- src/xine-utils/xmlparser.c | 45 ++++++++---- src/xine-utils/xmlparser.h | 17 ++++- 6 files changed, 158 insertions(+), 85 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_asf.c b/src/demuxers/demux_asf.c index d79782026..6c9ea631c 100644 --- a/src/demuxers/demux_asf.c +++ b/src/demuxers/demux_asf.c @@ -1544,6 +1544,7 @@ static int demux_asf_parse_asx_references( demux_asf_t *this) { int buf_used = 0; int len; xml_node_t *xml_tree, *asx_entry, *asx_ref; + xml_parser_t *xml_parser; int result; @@ -1566,9 +1567,13 @@ static int demux_asf_parse_asx_references( demux_asf_t *this) { if(buf_used) buf[buf_used] = '\0'; - xml_parser_init(buf, buf_used, XML_PARSER_CASE_INSENSITIVE); - if((result = xml_parser_build_tree(&xml_tree)) != XML_PARSER_OK) + xml_parser = xml_parser_init_r(buf, buf_used, XML_PARSER_CASE_INSENSITIVE); + if((result = xml_parser_build_tree_r(xml_parser, &xml_tree)) != XML_PARSER_OK) { + xml_parser_finalize_r(xml_parser); goto failure; + } + + xml_parser_finalize_r(xml_parser); if(!strcasecmp(xml_tree->name, "ASX")) { /* Attributes: VERSION, PREVIEWMODE, BANNERBAR diff --git a/src/libspucmml/xine_cmml_decoder.c b/src/libspucmml/xine_cmml_decoder.c index c3da1b0fd..9cd446988 100644 --- a/src/libspucmml/xine_cmml_decoder.c +++ b/src/libspucmml/xine_cmml_decoder.c @@ -239,6 +239,7 @@ static void spudec_decode_data (spu_decoder_t *this_gen, buf_element_t *buf) { spucmml_decoder_t *this = (spucmml_decoder_t *) this_gen; + xml_parser_t *xml_parser; xml_node_t *packet_xml_root; char * anchor_text = NULL; @@ -248,12 +249,15 @@ static void spudec_decode_data (spu_decoder_t *this_gen, buf_element_t *buf) { /* parse the CMML */ - xml_parser_init (str, strlen (str), XML_PARSER_CASE_INSENSITIVE); - if (xml_parser_build_tree(&packet_xml_root) != XML_PARSER_OK) { + xml_parser = xml_parser_init_r (str, strlen (str), XML_PARSER_CASE_INSENSITIVE); + if (xml_parser_build_tree_r(xml_parser, &packet_xml_root) != XML_PARSER_OK) { lprintf ("warning: invalid XML packet detected in CMML track\n"); + xml_parser_finalize_r(xml_parser); return; } + xml_parser_finalize_r(xml_parser); + if (strcasecmp(packet_xml_root->name, "head") == 0) { /* found a ... packet: need to parse the title */ diff --git a/src/xine-utils/xmllexer.c b/src/xine-utils/xmllexer.c index 08c56e88e..696c18011 100644 --- a/src/xine-utils/xmllexer.c +++ b/src/xine-utils/xmllexer.c @@ -50,16 +50,11 @@ #define DATA 1 /* data lex mode */ /* private global variables */ -static const char * lexbuf; -static int lexbuf_size = 0; -static int lexbuf_pos = 0; -static int lex_mode = NORMAL; -static int in_comment = 0; -static char *lex_malloc = NULL; +struct lexer * static_lexer; enum utf { UTF32BE, UTF32LE, UTF16BE, UTF16LE }; -static void lex_convert (const char * buf, int size, enum utf utf) +static void lex_convert (struct lexer * lexer, const char * buf, int size, enum utf utf) { char *utf8 = malloc (size * (utf >= UTF16BE ? 3 : 6) + 1); char *bp = utf8; @@ -91,42 +86,60 @@ static void lex_convert (const char * buf, int size, enum utf utf) } } *bp = 0; - lexbuf_size = bp - utf8; - lexbuf = lex_malloc = realloc (utf8, lexbuf_size + 1); + lexer->lexbuf_size = bp - utf8; + lexer->lexbuf = lexer->lex_malloc = realloc (utf8, lexer->lexbuf_size + 1); } +/* for ABI compatibility */ void lexer_init(const char * buf, int size) { + if (static_lexer) { + lexer_finalize_r(static_lexer); + } + static_lexer = lexer_init_r(buf, size); +} + +struct lexer *lexer_init_r(const char * buf, int size) { static const char boms[] = { 0xFF, 0xFE, 0, 0, 0xFE, 0xFF }, bom_utf8[] = { 0xEF, 0xBB, 0xBF }; + struct lexer * lexer = calloc (1, sizeof (*lexer)); - free (lex_malloc); - lex_malloc = NULL; - - lexbuf = buf; - lexbuf_size = size; + lexer->lexbuf = buf; + lexer->lexbuf_size = size; if (size >= 4 && !memcmp (buf, boms + 2, 4)) - lex_convert (buf + 4, size - 4, UTF32BE); + lex_convert (lexer, buf + 4, size - 4, UTF32BE); else if (size >= 4 && !memcmp (buf, boms, 4)) - lex_convert (buf + 4, size - 4, UTF32LE); + lex_convert (lexer, buf + 4, size - 4, UTF32LE); else if (size >= 3 && !memcmp (buf, bom_utf8, 3)) { - lexbuf += 3; - lexbuf_size -= 3; + lexer->lexbuf += 3; + lexer->lexbuf_size -= 3; } else if (size >= 2 && !memcmp (buf, boms + 4, 2)) - lex_convert (buf + 2, size - 2, UTF16BE); + lex_convert (lexer, buf + 2, size - 2, UTF16BE); else if (size >= 2 && !memcmp (buf, boms, 2)) - lex_convert (buf + 2, size - 2, UTF16LE); + lex_convert (lexer, buf + 2, size - 2, UTF16LE); - lexbuf_pos = 0; - lex_mode = NORMAL; - in_comment = 0; + lexer->lexbuf_pos = 0; + lexer->lex_mode = NORMAL; + lexer->in_comment = 0; lprintf("buffer length %d\n", size); + return lexer; } +void lexer_finalize_r(struct lexer * lexer) +{ + free(lexer->lex_malloc); + free(lexer); +} + +/* for ABI compatibility */ int lexer_get_token_d(char ** _tok, int * _tok_size, int fixed) { + return lexer_get_token_d_r(static_lexer, _tok, _tok_size, fixed); +} + +int lexer_get_token_d_r(struct lexer * lexer, char ** _tok, int * _tok_size, int fixed) { char *tok = *_tok; int tok_size = *_tok_size; @@ -135,11 +148,11 @@ int lexer_get_token_d(char ** _tok, int * _tok_size, int fixed) { char c; if (tok) { - while ((tok_pos < tok_size) && (lexbuf_pos < lexbuf_size)) { - c = lexbuf[lexbuf_pos]; - lprintf("c=%c, state=%d, in_comment=%d\n", c, state, in_comment); + while ((tok_pos < tok_size) && (lexer->lexbuf_pos < lexer->lexbuf_size)) { + c = lexer->lexbuf[lexer->lexbuf_pos]; + lprintf("c=%c, state=%d, in_comment=%d\n", c, state, lexer->in_comment); - if (lex_mode == NORMAL) { + if (lexer->lex_mode == NORMAL) { /* normal mode */ switch (state) { /* init state */ @@ -172,7 +185,7 @@ int lexer_get_token_d(char ** _tok, int * _tok_size, int fixed) { break; case '/': - if (!in_comment) + if (!lexer->in_comment) state = 5; tok[tok_pos] = c; tok_pos++; @@ -210,14 +223,14 @@ int lexer_get_token_d(char ** _tok, int * _tok_size, int fixed) { tok_pos++; break; } - lexbuf_pos++; + lexer->lexbuf_pos++; break; /* end of line */ case 1: if (c == '\n' || (c == '\r')) { tok[tok_pos] = c; - lexbuf_pos++; + lexer->lexbuf_pos++; tok_pos++; } else { tok[tok_pos] = '\0'; @@ -229,7 +242,7 @@ int lexer_get_token_d(char ** _tok, int * _tok_size, int fixed) { case 2: if (c == ' ' || (c == '\t')) { tok[tok_pos] = c; - lexbuf_pos++; + lexer->lexbuf_pos++; tok_pos++; } else { tok[tok_pos] = '\0'; @@ -242,20 +255,20 @@ int lexer_get_token_d(char ** _tok, int * _tok_size, int fixed) { switch (c) { case '/': tok[tok_pos] = c; - lexbuf_pos++; + lexer->lexbuf_pos++; tok_pos++; /* FIXME */ tok[tok_pos] = '\0'; return T_M_START_2; break; case '!': tok[tok_pos] = c; - lexbuf_pos++; + lexer->lexbuf_pos++; tok_pos++; state = 8; break; case '?': tok[tok_pos] = c; - lexbuf_pos++; + lexer->lexbuf_pos++; tok_pos++; /* FIXME */ tok[tok_pos] = '\0'; return T_TI_START; @@ -269,8 +282,8 @@ int lexer_get_token_d(char ** _tok, int * _tok_size, int fixed) { /* T_M_STOP_1 */ case 4: tok[tok_pos] = '\0'; - if (!in_comment) - lex_mode = DATA; + if (!lexer->in_comment) + lexer->lex_mode = DATA; return T_M_STOP_1; break; @@ -278,11 +291,11 @@ int lexer_get_token_d(char ** _tok, int * _tok_size, int fixed) { case 5: if (c == '>') { tok[tok_pos] = c; - lexbuf_pos++; + lexer->lexbuf_pos++; tok_pos++; /* FIXME */ tok[tok_pos] = '\0'; - if (!in_comment) - lex_mode = DATA; + if (!lexer->in_comment) + lexer->lex_mode = DATA; return T_M_STOP_2; } else { tok[tok_pos] = '\0'; @@ -299,7 +312,7 @@ int lexer_get_token_d(char ** _tok, int * _tok_size, int fixed) { /* T_STRING */ case 7: tok[tok_pos] = c; - lexbuf_pos++; + lexer->lexbuf_pos++; if (c == '\"') { /* " */ tok[tok_pos] = '\0'; /* FIXME */ return T_STRING; @@ -311,22 +324,22 @@ int lexer_get_token_d(char ** _tok, int * _tok_size, int fixed) { case 8: switch (c) { case '-': - lexbuf_pos++; - if (lexbuf[lexbuf_pos] == '-') + lexer->lexbuf_pos++; + if (lexer->lexbuf[lexer->lexbuf_pos] == '-') { - lexbuf_pos++; + lexer->lexbuf_pos++; tok[tok_pos++] = '-'; /* FIXME */ tok[tok_pos++] = '-'; tok[tok_pos] = '\0'; - in_comment = 1; + lexer->in_comment = 1; return T_C_START; } break; case 'D': - lexbuf_pos++; - if (strncmp(lexbuf + lexbuf_pos, "OCTYPE", 6) == 0) { + lexer->lexbuf_pos++; + if (strncmp(lexer->lexbuf + lexer->lexbuf_pos, "OCTYPE", 6) == 0) { strncpy(tok + tok_pos, "DOCTYPE", 7); /* FIXME */ - lexbuf_pos += 6; + lexer->lexbuf_pos += 6; return T_DOCTYPE_START; } else { return T_ERROR; @@ -342,7 +355,7 @@ int lexer_get_token_d(char ** _tok, int * _tok_size, int fixed) { case 9: if (c == '>') { tok[tok_pos] = c; - lexbuf_pos++; + lexer->lexbuf_pos++; tok_pos++; /* FIXME */ tok[tok_pos] = '\0'; return T_TI_STOP; @@ -358,13 +371,13 @@ int lexer_get_token_d(char ** _tok, int * _tok_size, int fixed) { case '-': tok[tok_pos] = c; tok_pos++; - lexbuf_pos++; + lexer->lexbuf_pos++; state = 11; break; default: tok[tok_pos] = c; tok_pos++; - lexbuf_pos++; + lexer->lexbuf_pos++; state = 100; } break; @@ -375,21 +388,21 @@ int lexer_get_token_d(char ** _tok, int * _tok_size, int fixed) { case '>': tok[tok_pos] = c; tok_pos++; - lexbuf_pos++; + lexer->lexbuf_pos++; tok[tok_pos] = '\0'; /* FIX ME */ if (strlen(tok) != 3) { tok[tok_pos - 3] = '\0'; - lexbuf_pos -= 3; + lexer->lexbuf_pos -= 3; return T_IDENT; } else { - in_comment = 0; + lexer->in_comment = 0; return T_C_STOP; } break; default: tok[tok_pos] = c; tok_pos++; - lexbuf_pos++; + lexer->lexbuf_pos++; state = 100; } break; @@ -397,7 +410,7 @@ int lexer_get_token_d(char ** _tok, int * _tok_size, int fixed) { /* T_STRING (single quotes) */ case 12: tok[tok_pos] = c; - lexbuf_pos++; + lexer->lexbuf_pos++; if (c == '\'') { /* " */ tok[tok_pos] = '\0'; /* FIXME */ return T_STRING; @@ -424,19 +437,19 @@ int lexer_get_token_d(char ** _tok, int * _tok_size, int fixed) { case '?': tok[tok_pos] = c; tok_pos++; - lexbuf_pos++; + lexer->lexbuf_pos++; state = 9; break; case '-': tok[tok_pos] = c; tok_pos++; - lexbuf_pos++; + lexer->lexbuf_pos++; state = 10; break; default: tok[tok_pos] = c; tok_pos++; - lexbuf_pos++; + lexer->lexbuf_pos++; } break; default: @@ -449,17 +462,17 @@ int lexer_get_token_d(char ** _tok, int * _tok_size, int fixed) { { case '<': tok[tok_pos] = '\0'; - lex_mode = NORMAL; + lexer->lex_mode = NORMAL; return T_DATA; default: tok[tok_pos] = c; tok_pos++; - lexbuf_pos++; + lexer->lexbuf_pos++; } } } lprintf ("loop done tok_pos = %d, tok_size=%d, lexbuf_pos=%d, lexbuf_size=%d\n", - tok_pos, tok_size, lexbuf_pos, lexbuf_size); + tok_pos, tok_size, lexer->lexbuf_pos, lexer->lexbuf_size); /* pb */ if (tok_pos >= tok_size) { @@ -470,12 +483,12 @@ int lexer_get_token_d(char ** _tok, int * _tok_size, int fixed) { lprintf("token buffer is too small\n"); lprintf("increasing buffer size to %d bytes\n", *_tok_size); if (*_tok) { - return lexer_get_token_d (_tok, _tok_size, 0); + return lexer_get_token_d_r (lexer, _tok, _tok_size, 0); } else { return T_ERROR; } } else { - if (lexbuf_pos >= lexbuf_size) { + if (lexer->lexbuf_pos >= lexer->lexbuf_size) { /* Terminate the current token */ tok[tok_pos] = '\0'; switch (state) { diff --git a/src/xine-utils/xmllexer.h b/src/xine-utils/xmllexer.h index 425d0e70a..bcea7d6b4 100644 --- a/src/xine-utils/xmllexer.h +++ b/src/xine-utils/xmllexer.h @@ -23,6 +23,10 @@ #ifndef XML_LEXER_H #define XML_LEXER_H +#ifndef XINE_DEPRECATED +#define XINE_DEPRECATED +#endif + #ifndef XINE_PROTECTED #define XINE_PROTECTED #endif @@ -49,10 +53,25 @@ #define T_DOCTYPE_STOP 17 /* > */ +/* public structure */ +struct lexer +{ + const char * lexbuf; + int lexbuf_size; + int lexbuf_pos; + int lex_mode; + int in_comment; + char *lex_malloc; +}; + + /* public functions */ -void lexer_init(const char * buf, int size) XINE_PROTECTED; -int lexer_get_token_d(char ** tok, int * tok_size, int fixed) XINE_PROTECTED; -int lexer_get_token(char * tok, int tok_size) XINE_PROTECTED; +void lexer_init(const char * buf, int size) XINE_DEPRECATED XINE_PROTECTED; +struct lexer *lexer_init_r(const char * buf, int size) XINE_PROTECTED; +void lexer_finalize_r(struct lexer * lexer) XINE_PROTECTED; +int lexer_get_token_d_r(struct lexer * lexer, char ** tok, int * tok_size, int fixed) XINE_PROTECTED; +int lexer_get_token_d(char ** tok, int * tok_size, int fixed) XINE_DEPRECATED XINE_PROTECTED; +int lexer_get_token(char * tok, int tok_size) XINE_DEPRECATED XINE_PROTECTED; char *lexer_decode_entities (const char *tok) XINE_PROTECTED; #endif diff --git a/src/xine-utils/xmlparser.c b/src/xine-utils/xmlparser.c index 93a707993..2e93da4e9 100644 --- a/src/xine-utils/xmlparser.c +++ b/src/xine-utils/xmlparser.c @@ -51,7 +51,7 @@ #define MAX_RECURSION 10 /* private global variables */ -static int xml_parser_mode; +xml_parser_t * static_xml_parser; /* private functions */ @@ -99,10 +99,24 @@ static void free_xml_property(xml_property_t * property) { free(property); } +/* for ABI compatibility */ void xml_parser_init(const char * buf, int size, int mode) { + if (static_xml_parser) { + xml_parser_finalize_r(static_xml_parser); + } + static_xml_parser = xml_parser_init_r(buf, size, mode); +} + +xml_parser_t *xml_parser_init_r(const char * buf, int size, int mode) { + xml_parser_t *xml_parser = malloc(sizeof(*xml_parser)); + xml_parser->lexer = lexer_init_r(buf, size); + xml_parser->mode = mode; + return xml_parser; +} - lexer_init(buf, size); - xml_parser_mode = mode; +void xml_parser_finalize_r(xml_parser_t *xml_parser) { + lexer_finalize_r(xml_parser->lexer); + free(xml_parser); } static void xml_parser_free_props(xml_property_t *current_property) { @@ -157,9 +171,9 @@ void xml_parser_free_tree(xml_node_t *current_node) { #define STATE_NODE 1 #define STATE_COMMENT 7 -static int xml_parser_get_node (xml_node_t *current_node, char *root_name, int rec); +static int xml_parser_get_node (xml_parser_t *xml_parser, xml_node_t *current_node, char *root_name, int rec); -static int _xml_parser_get_node (char ** token_buffer, int * token_buffer_size, +static int _xml_parser_get_node (xml_parser_t *xml_parser, char ** token_buffer, int * token_buffer_size, char ** pname_buffer, int * pname_buffer_size, char ** nname_buffer, int * nname_buffer_size, xml_node_t *current_node, char *root_name, int rec) { @@ -179,7 +193,7 @@ static int _xml_parser_get_node (char ** token_buffer, int * token_buffer_size, memset (tok, 0, *token_buffer_size); - while ((bypass_get_token) || (res = lexer_get_token_d(token_buffer, token_buffer_size, 0)) != T_ERROR) { + while ((bypass_get_token) || (res = lexer_get_token_d_r(xml_parser->lexer, token_buffer, token_buffer_size, 0)) != T_ERROR) { tok = *token_buffer; bypass_get_token = 0; lprintf("info: %d - %d : '%s'\n", state, res, tok); @@ -232,7 +246,7 @@ static int _xml_parser_get_node (char ** token_buffer, int * token_buffer_size, current_property = NULL; /* save node name */ - if (xml_parser_mode == XML_PARSER_CASE_INSENSITIVE) { + if (xml_parser->mode == XML_PARSER_CASE_INSENSITIVE) { strtoupper(tok); } /* make sure the buffer for the node name is big enough */ @@ -267,7 +281,7 @@ static int _xml_parser_get_node (char ** token_buffer, int * token_buffer_size, /* set node propertys */ subtree->props = properties; lprintf("info: rec %d new subtree %s\n", rec, node_name); - parse_res = xml_parser_get_node(subtree, node_name, rec + 1); + parse_res = xml_parser_get_node(xml_parser, subtree, node_name, rec + 1); if (parse_res != 0) { return parse_res; } @@ -304,7 +318,7 @@ static int _xml_parser_get_node (char ** token_buffer, int * token_buffer_size, break; case (T_IDENT): /* save property name */ - if (xml_parser_mode == XML_PARSER_CASE_INSENSITIVE) { + if (xml_parser->mode == XML_PARSER_CASE_INSENSITIVE) { strtoupper(tok); } /* make sure the buffer for the property name is big enough */ @@ -328,7 +342,7 @@ static int _xml_parser_get_node (char ** token_buffer, int * token_buffer_size, switch (res) { case (T_IDENT): /* must be equal to root_name */ - if (xml_parser_mode == XML_PARSER_CASE_INSENSITIVE) { + if (xml_parser->mode == XML_PARSER_CASE_INSENSITIVE) { strtoupper(tok); } if (strcmp(tok, root_name) == 0) { @@ -474,7 +488,7 @@ static int _xml_parser_get_node (char ** token_buffer, int * token_buffer_size, } } -static int xml_parser_get_node (xml_node_t *current_node, char *root_name, int rec) +static int xml_parser_get_node (xml_parser_t *xml_parser, xml_node_t *current_node, char *root_name, int rec) { int res = 0; int token_buffer_size = TOKEN_SIZE; @@ -484,7 +498,7 @@ static int xml_parser_get_node (xml_node_t *current_node, char *root_name, int r char *pname_buffer = calloc(1, pname_buffer_size); char *nname_buffer = calloc(1, nname_buffer_size); - res = _xml_parser_get_node(&token_buffer, &token_buffer_size, + res = _xml_parser_get_node(xml_parser, &token_buffer, &token_buffer_size, &pname_buffer, &pname_buffer_size, &nname_buffer, &nname_buffer_size, current_node, root_name, rec); @@ -496,12 +510,17 @@ static int xml_parser_get_node (xml_node_t *current_node, char *root_name, int r return res; } +/* for ABI compatibility */ int xml_parser_build_tree(xml_node_t **root_node) { + return xml_parser_build_tree_r(static_xml_parser, root_node); +} + +int xml_parser_build_tree_r(xml_parser_t *xml_parser, xml_node_t **root_node) { xml_node_t *tmp_node; int res; tmp_node = new_xml_node(); - res = xml_parser_get_node(tmp_node, "", 0); + res = xml_parser_get_node(xml_parser, tmp_node, "", 0); if ((tmp_node->child) && (!tmp_node->child->next)) { *root_node = tmp_node->child; free_xml_node(tmp_node); diff --git a/src/xine-utils/xmlparser.h b/src/xine-utils/xmlparser.h index 98695a756..fe94e4b76 100644 --- a/src/xine-utils/xmlparser.h +++ b/src/xine-utils/xmlparser.h @@ -22,6 +22,10 @@ #ifndef XML_PARSER_H #define XML_PARSER_H +#ifndef XINE_DEPRECATED +#define XINE_DEPRECATED +#endif + #ifndef XINE_PROTECTED #define XINE_PROTECTED #endif @@ -51,9 +55,18 @@ typedef struct xml_node_s { struct xml_node_s *next; } xml_node_t; -void xml_parser_init(const char * buf, int size, int mode) XINE_PROTECTED; +/* xml parser */ +typedef struct xml_parser_s { + struct lexer *lexer; + int mode; +} xml_parser_t; + +void xml_parser_init(const char * buf, int size, int mode) XINE_DEPRECATED XINE_PROTECTED; +xml_parser_t *xml_parser_init_r(const char * buf, int size, int mode) XINE_PROTECTED; +void xml_parser_finalize_r(xml_parser_t *xml_parser) XINE_PROTECTED; -int xml_parser_build_tree(xml_node_t **root_node) XINE_PROTECTED; +int xml_parser_build_tree(xml_node_t **root_node) XINE_DEPRECATED XINE_PROTECTED; +int xml_parser_build_tree_r(xml_parser_t *xml_parser, xml_node_t **root_node) XINE_PROTECTED; void xml_parser_free_tree(xml_node_t *root_node) XINE_PROTECTED; -- cgit v1.2.3 From 13644839b68d174ed745710c2b6ae592e7f771d6 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Wed, 21 Oct 2009 18:23:15 +0100 Subject: Fixed a bug which prevented "dvb://" working with the default configuration. --- src/input/input_dvb.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/input/input_dvb.c b/src/input/input_dvb.c index 5060757e4..54c40087e 100644 --- a/src/input/input_dvb.c +++ b/src/input/input_dvb.c @@ -2875,6 +2875,8 @@ static int dvb_plugin_open(input_plugin_t * this_gen) if (lastchannel.num_value) { if (xine_config_lookup_entry(this->class->xine, "media.dvb.last_channel", &lastchannel)){ this->channel = lastchannel.num_value -1; + if (this->channel < 0 || this->channel >= num_channels) + this->channel = 0; /* out of range? default */ }else{ xprintf(this->class->xine, XINE_VERBOSITY_LOG, _("input_dvb: invalid channel specification, defaulting to channel 0\n")); this->channel = 0; -- cgit v1.2.3 From f7ceeba7f05e6f511a70c5737740802685c18585 Mon Sep 17 00:00:00 2001 From: Petri Hintukainen Date: Tue, 3 Nov 2009 21:34:50 +0200 Subject: Moved struct declarations & list handling to beginning of the file. Cosmetics. --- src/libspuhdmv/xine_hdmv_decoder.c | 132 ++++++++++++++++--------------------- 1 file changed, 57 insertions(+), 75 deletions(-) (limited to 'src') diff --git a/src/libspuhdmv/xine_hdmv_decoder.c b/src/libspuhdmv/xine_hdmv_decoder.c index 358cb0b72..96acf0c11 100644 --- a/src/libspuhdmv/xine_hdmv_decoder.c +++ b/src/libspuhdmv/xine_hdmv_decoder.c @@ -47,7 +47,7 @@ #define TRACE(x...) printf(x) /*#define TRACE(x...) */ -#define ERROR(x...) fprintf(stderr, x) +#define ERROR(x...) fprintf(stderr, "spuhdmv: " x) /*#define ERROR(x...) lprintf(x) */ /* @@ -112,6 +112,57 @@ struct composition_object_s { composition_object_t *next; }; +typedef struct composition_descriptor_s composition_descriptor_t; +struct composition_descriptor_s { + uint16_t number; + uint8_t state; +}; + +typedef struct presentation_segment_s presentation_segment_t; +struct presentation_segment_s { + composition_descriptor_t comp_descr; + + uint8_t palette_update_flag; + uint8_t palette_id_ref; + uint8_t object_number; + + composition_object_t *comp_objs; + + //presentation_segment_t *next; + + int64_t pts; +}; + +/* + * list handling + */ + +#define LIST_REPLACE(list, obj) \ + do { \ + uint id = obj->id; \ + \ + /* insert to list */ \ + obj->next = list; \ + list = obj; \ + \ + /* remove old */ \ + while (obj->next && obj->next->id != id) \ + obj = obj->next; \ + if (obj->next) { \ + void *tmp = (void*)obj->next; \ + obj->next = obj->next->next; \ + free(tmp); \ + } \ + } while (0); + +#define LIST_DESTROY(list) \ + while (list) { \ + void *tmp = (void*)list; \ + list = list->next; \ + free (tmp); \ + } + + /* * segment_buffer_t * @@ -443,12 +494,6 @@ static int segbuf_decode_video_descriptor(segment_buffer_t *buf) return buf->error; } -typedef struct composition_descriptor_s composition_descriptor_t; -struct composition_descriptor_s { - uint16_t number; - uint8_t state; -}; - static int segbuf_decode_composition_descriptor(segment_buffer_t *buf, composition_descriptor_t *descr) { descr->number = segbuf_get_u16(buf); @@ -492,7 +537,7 @@ static composition_object_t *segbuf_decode_composition_object(segment_buffer_t * static rle_elem_t *copy_crop_rle(subtitle_object_t *obj, composition_object_t *cobj) { - /* TODO: exec cropping here (w,h sized image from pos x,y) */ + /* TODO: cropping (w,h sized image from pos x,y) */ rle_elem_t *rle = calloc (obj->num_rle, sizeof(rle_elem_t)); memcpy (rle, obj->rle, obj->num_rle * sizeof(rle_elem_t)); @@ -516,57 +561,15 @@ typedef struct spuhdmv_decoder_s { segment_buffer_t *buf; - subtitle_clut_t *cluts; - subtitle_object_t *objects; - window_def_t *windows; + subtitle_clut_t *cluts; + subtitle_object_t *objects; + window_def_t *windows; int overlay_handles[MAX_OBJECTS]; int64_t pts; } spuhdmv_decoder_t; -#define LIST_REPLACE_OLD(type, list, obj) \ - do { \ - /* insert to list */ \ - obj->next = list; \ - list = obj; \ -\ - /* remove old */ \ - type *i = list; \ - while (i->next && i->next->id != obj->id) \ - i = i->next; \ - if (i->next) { \ - void *tmp = (void*)i->next; \ - i->next = i->next->next; \ - free(tmp); \ - } \ - } while (0); - -#define LIST_REPLACE(list, obj) \ - do { \ - uint id = obj->id; \ - \ - /* insert to list */ \ - obj->next = list; \ - list = obj; \ - \ - /* remove old */ \ - while (obj->next && obj->next->id != id) \ - obj = obj->next; \ - if (obj->next) { \ - void *tmp = (void*)obj->next; \ - obj->next = obj->next->next; \ - free(tmp); \ - } \ - } while (0); - -#define LIST_DESTROY(list) \ - while (list) { \ - void *tmp = (void*)list; \ - list = list->next; \ - free (tmp); \ - } - static int decode_palette(spuhdmv_decoder_t *this) { /* decode */ @@ -693,21 +696,6 @@ static int show_overlay(spuhdmv_decoder_t *this, composition_object_t *cobj, uin return 0; } -typedef struct presentation_segment_s presentation_segment_t; -struct presentation_segment_s { - composition_descriptor_t comp_descr; - - uint8_t palette_update_flag; - uint8_t palette_id_ref; - uint8_t object_number; - - composition_object_t *comp_objs; - - presentation_segment_t *next; - - int64_t pts; -}; - static void show_overlays(spuhdmv_decoder_t *this, presentation_segment_t *pseg) { composition_object_t *cobj = pseg->comp_objs; @@ -809,12 +797,6 @@ static void decode_segment(spuhdmv_decoder_t *this) break; case 0x80: TRACE(" segment: END OF DISPLAY\n"); - { - int64_t pts = xine_get_current_vpts(this->stream) - - this->stream->metronom->get_option(this->stream->metronom, - METRONOM_VPTS_OFFSET); - TRACE(" * current pts = %ld\n", pts); - } break; default: @@ -828,7 +810,7 @@ static void decode_segment(spuhdmv_decoder_t *this) static void close_osd(spuhdmv_decoder_t *this) { - video_overlay_manager_t *ovl_manager = this->stream->video_out->get_overlay_manager (this->stream->video_out); + video_overlay_manager_t *ovl_manager = this->stream->video_out->get_overlay_manager (this->stream->video_out); int i = 0; while (this->overlay_handles[i] >= 0) { -- cgit v1.2.3 From 4345dc27aa5bb6b816759f3d7276baad601ff5bd Mon Sep 17 00:00:00 2001 From: Petri Hintukainen Date: Tue, 3 Nov 2009 21:34:50 +0200 Subject: =?UTF-8?q?Copy=20palette=20only=20if=20all=20objects=20have=20bee?= =?UTF-8?q?n=20found;=20ERROR=E2=86=92TRACE=20in=20show=5Foverlay().?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libspuhdmv/xine_hdmv_decoder.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/libspuhdmv/xine_hdmv_decoder.c b/src/libspuhdmv/xine_hdmv_decoder.c index 96acf0c11..1a6b71523 100644 --- a/src/libspuhdmv/xine_hdmv_decoder.c +++ b/src/libspuhdmv/xine_hdmv_decoder.c @@ -74,9 +74,11 @@ struct subtitle_object_s { uint num_rle; size_t data_size; +#if 0 uint8_t *raw_data; /* partial RLE data in HDMV format */ size_t raw_data_len; size_t raw_data_size; +#endif subtitle_object_t *next; }; @@ -619,21 +621,16 @@ static int show_overlay(spuhdmv_decoder_t *this, composition_object_t *cobj, uin while (clut && clut->id != palette_id_ref) clut = clut->next; if (!clut) { - ERROR(" fill_overlay: clut %d not found !\n", palette_id_ref); + TRACE(" show_overlay: clut %d not found !\n", palette_id_ref); return -1; } - /* copy palette to xine overlay */ - overlay.rgb_clut = 0; - memcpy(overlay.color, clut->color, sizeof(uint32_t) * 256); - memcpy(overlay.trans, clut->trans, sizeof(uint8_t) * 256); - /* find RLE image */ subtitle_object_t *obj = this->objects; while (obj && obj->id != cobj->object_id_ref) obj = obj->next; if (!obj) { - ERROR(" fill_overlay: object %d not found !\n", cobj->object_id_ref); + TRACE(" show_overlay: object %d not found !\n", cobj->object_id_ref); return -1; } @@ -642,10 +639,15 @@ static int show_overlay(spuhdmv_decoder_t *this, composition_object_t *cobj, uin while (wnd && wnd->id != cobj->window_id_ref) wnd = wnd->next; if (!wnd) { - ERROR(" fill_overlay: window %d not found !\n", cobj->window_id_ref); + TRACE(" show_overlay: window %d not found !\n", cobj->window_id_ref); return -1; } + /* copy palette to xine overlay */ + overlay.rgb_clut = 0; + memcpy(overlay.color, clut->color, sizeof(uint32_t) * 256); + memcpy(overlay.trans, clut->trans, sizeof(uint8_t) * 256); + /* copy and crop RLE image to xine overlay */ overlay.width = obj->width; overlay.height = obj->height; -- cgit v1.2.3 From a9bcaea82059a72fa899f9ed9a69cabfd3ceacc5 Mon Sep 17 00:00:00 2001 From: Petri Hintukainen Date: Tue, 3 Nov 2009 21:37:45 +0200 Subject: Do not update overlay if all elements are unchanged --- src/libspuhdmv/xine_hdmv_decoder.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/libspuhdmv/xine_hdmv_decoder.c b/src/libspuhdmv/xine_hdmv_decoder.c index 1a6b71523..13f56b528 100644 --- a/src/libspuhdmv/xine_hdmv_decoder.c +++ b/src/libspuhdmv/xine_hdmv_decoder.c @@ -59,6 +59,8 @@ struct subtitle_clut_s { uint32_t color[256]; uint8_t trans[256]; subtitle_clut_t *next; + + int shown; }; /* @@ -81,6 +83,8 @@ struct subtitle_object_s { #endif subtitle_object_t *next; + + int shown; }; /* @@ -93,6 +97,8 @@ struct window_def_s { uint16_t width, height; window_def_t *next; + + int shown; }; @@ -112,6 +118,8 @@ struct composition_object_s { uint16_t crop_width, crop_height; composition_object_t *next; + + int shown; }; typedef struct composition_descriptor_s composition_descriptor_t; @@ -133,6 +141,7 @@ struct presentation_segment_s { //presentation_segment_t *next; int64_t pts; + int shown; }; /* @@ -609,7 +618,7 @@ static int decode_window_definition(spuhdmv_decoder_t *this) } static int show_overlay(spuhdmv_decoder_t *this, composition_object_t *cobj, uint palette_id_ref, - int overlay_index, int64_t pts) + int overlay_index, int64_t pts, int force_update) { video_overlay_manager_t *ovl_manager = this->stream->video_out->get_overlay_manager(this->stream->video_out); metronom_t *metronom = this->stream->metronom; @@ -643,6 +652,11 @@ static int show_overlay(spuhdmv_decoder_t *this, composition_object_t *cobj, uin return -1; } + /* do not show again if all elements are unchanged */ + if (!force_update && clut->shown && obj->shown && wnd->shown && cobj->shown) + return 0; + clut->shown = obj->shown = wnd->shown = cobj->shown = 1; + /* copy palette to xine overlay */ overlay.rgb_clut = 0; memcpy(overlay.color, clut->color, sizeof(uint32_t) * 256); @@ -707,10 +721,12 @@ static void show_overlays(spuhdmv_decoder_t *this, presentation_segment_t *pseg) if (!cobj) { ERROR("show_overlays: composition object %d missing !\n", i); } else { - show_overlay(this, cobj, pseg->palette_id_ref, i, pseg->pts); + show_overlay(this, cobj, pseg->palette_id_ref, i, pseg->pts, !pseg->shown); cobj = cobj->next; } } + + pseg->shown = 1; } static void hide_overlays(spuhdmv_decoder_t *this, int64_t pts) -- cgit v1.2.3 From 145602985c83694699c4984a21ad61165e2c8859 Mon Sep 17 00:00:00 2001 From: Petri Hintukainen Date: Tue, 3 Nov 2009 21:46:56 +0200 Subject: Fixed memory leaks (RLE data) --- src/libspuhdmv/xine_hdmv_decoder.c | 56 +++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/libspuhdmv/xine_hdmv_decoder.c b/src/libspuhdmv/xine_hdmv_decoder.c index 13f56b528..04586d750 100644 --- a/src/libspuhdmv/xine_hdmv_decoder.c +++ b/src/libspuhdmv/xine_hdmv_decoder.c @@ -148,7 +148,7 @@ struct presentation_segment_s { * list handling */ -#define LIST_REPLACE(list, obj) \ +#define LIST_REPLACE(list, obj, FREE_FUNC) \ do { \ uint id = obj->id; \ \ @@ -162,17 +162,33 @@ struct presentation_segment_s { if (obj->next) { \ void *tmp = (void*)obj->next; \ obj->next = obj->next->next; \ - free(tmp); \ + FREE_FUNC(tmp); \ } \ } while (0); -#define LIST_DESTROY(list) \ +#define LIST_DESTROY(list, FREE_FUNC) \ while (list) { \ void *tmp = (void*)list; \ list = list->next; \ - free (tmp); \ + FREE_FUNC(tmp); \ } +static void free_subtitle_object(void *ptr) +{ + if (ptr) { + free(((subtitle_object_t*)ptr)->rle); + free(ptr); + } +} +static void free_presentation_segment(void *ptr) +{ + if (ptr) { + presentation_segment_t *seg = (presentation_segment_t*)ptr; + LIST_DESTROY(seg->comp_objs, free); + free(ptr); + } +} + /* * segment_buffer_t @@ -459,14 +475,14 @@ static subtitle_object_t *segbuf_decode_object(segment_buffer_t *buf) segbuf_decode_rle (buf, obj); if (buf->error) { - free(obj); + free_subtitle_object(obj); return NULL; } } else { ERROR(" TODO: APPEND RLE, length %d bytes\n", buf->segment_len - 4); /* TODO */ - free(obj); + free_subtitle_object(obj); return NULL; } @@ -588,7 +604,7 @@ static int decode_palette(spuhdmv_decoder_t *this) if (!clut) return 1; - LIST_REPLACE (this->cluts, clut); + LIST_REPLACE (this->cluts, clut, free); return 0; } @@ -600,7 +616,7 @@ static int decode_object(spuhdmv_decoder_t *this) if (!obj) return 1; - LIST_REPLACE (this->objects, obj); + LIST_REPLACE (this->objects, obj, free_subtitle_object); return 0; } @@ -612,7 +628,7 @@ static int decode_window_definition(spuhdmv_decoder_t *this) if (!wnd) return 1; - LIST_REPLACE (this->windows, wnd); + LIST_REPLACE (this->windows, wnd, free); return 0; } @@ -707,8 +723,6 @@ static int show_overlay(spuhdmv_decoder_t *this, composition_object_t *cobj, uin ovl_manager->add_event (ovl_manager, (void *)&event); - obj->rle = NULL; - return 0; } @@ -782,12 +796,19 @@ static int decode_presentation_segment(spuhdmv_decoder_t *this) hide_overlays (this, this->pts); } else { show_overlays (this, &p); - LIST_DESTROY (p.comp_objs); + LIST_DESTROY (p.comp_objs, free); } return buf->error; } +static void free_objs(spuhdmv_decoder_t *this) +{ + LIST_DESTROY (this->cluts, free); + LIST_DESTROY (this->objects, free_subtitle_object); + LIST_DESTROY (this->windows, free); +} + static void decode_segment(spuhdmv_decoder_t *this) { TRACE("*** new segment, pts %010ld: 0x%02x (%8d bytes)", @@ -815,7 +836,8 @@ static void decode_segment(spuhdmv_decoder_t *this) break; case 0x80: TRACE(" segment: END OF DISPLAY\n"); - + /* drop all cached objects */ + free_objs(this); break; default: ERROR(" segment type 0x%x unknown, skipping\n", this->buf->segment_type); @@ -873,9 +895,7 @@ static void spudec_reset (spu_decoder_t * this_gen) if (this->buf) segbuf_reset(this->buf); - LIST_DESTROY (this->cluts); - LIST_DESTROY (this->objects); - LIST_DESTROY (this->windows); + free_objs(this); close_osd(this); } @@ -894,9 +914,7 @@ static void spudec_dispose (spu_decoder_t *this_gen) close_osd (this); segbuf_dispose (this->buf); - LIST_DESTROY (this->cluts); - LIST_DESTROY (this->objects); - LIST_DESTROY (this->windows); + free_objs(this); free (this); } -- cgit v1.2.3 From 9b0a520a6e0d09daefd4916a4298f099907f44f3 Mon Sep 17 00:00:00 2001 From: Petri Hintukainen Date: Tue, 3 Nov 2009 22:32:05 +0200 Subject: =?UTF-8?q?show=5Foverlays()=20=E2=86=92=20update=5Foverlays()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libspuhdmv/xine_hdmv_decoder.c | 51 +++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/libspuhdmv/xine_hdmv_decoder.c b/src/libspuhdmv/xine_hdmv_decoder.c index 04586d750..8ffd4e3aa 100644 --- a/src/libspuhdmv/xine_hdmv_decoder.c +++ b/src/libspuhdmv/xine_hdmv_decoder.c @@ -726,23 +726,6 @@ static int show_overlay(spuhdmv_decoder_t *this, composition_object_t *cobj, uin return 0; } -static void show_overlays(spuhdmv_decoder_t *this, presentation_segment_t *pseg) -{ - composition_object_t *cobj = pseg->comp_objs; - int i; - - for (i = 0; i < pseg->object_number; i++) { - if (!cobj) { - ERROR("show_overlays: composition object %d missing !\n", i); - } else { - show_overlay(this, cobj, pseg->palette_id_ref, i, pseg->pts, !pseg->shown); - cobj = cobj->next; - } - } - - pseg->shown = 1; -} - static void hide_overlays(spuhdmv_decoder_t *this, int64_t pts) { video_overlay_event_t event = {0}; @@ -768,6 +751,33 @@ static void hide_overlays(spuhdmv_decoder_t *this, int64_t pts) } } +static void update_overlays(spuhdmv_decoder_t *this, presentation_segment_t *pseg) +{ + if (!pseg->comp_descr.state) { + + /* HIDE */ + if (!pseg->shown) + hide_overlays (this, pseg->pts); + + } else { + + /* SHOW */ + composition_object_t *cobj = pseg->comp_objs; + int i; + + for (i = 0; i < pseg->object_number; i++) { + if (!cobj) { + ERROR("show_overlays: composition object %d missing !\n", i); + } else { + show_overlay(this, cobj, pseg->palette_id_ref, i, pseg->pts, !pseg->shown); + cobj = cobj->next; + } + } + } + + pseg->shown = 1; +} + static int decode_presentation_segment(spuhdmv_decoder_t *this) { presentation_segment_t p = {}; @@ -792,12 +802,7 @@ static int decode_presentation_segment(spuhdmv_decoder_t *this) p.comp_objs = cobj; } - if (!p.comp_descr.state) { - hide_overlays (this, this->pts); - } else { - show_overlays (this, &p); - LIST_DESTROY (p.comp_objs, free); - } + update_overlays (this, &p); return buf->error; } -- cgit v1.2.3 From f7301e347937dfa9fa6879ff9376f1b3a2642e78 Mon Sep 17 00:00:00 2001 From: Petri Hintukainen Date: Tue, 3 Nov 2009 22:40:07 +0200 Subject: Fixed timing of subtitles. Splitted decode_presentation_segment() - Store presentation segments in decoder instance data. - Try to update overlays after every decoded object. --- src/libspuhdmv/xine_hdmv_decoder.c | 87 +++++++++++++++++++++++++------------- 1 file changed, 58 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/libspuhdmv/xine_hdmv_decoder.c b/src/libspuhdmv/xine_hdmv_decoder.c index 8ffd4e3aa..ba4487bf6 100644 --- a/src/libspuhdmv/xine_hdmv_decoder.c +++ b/src/libspuhdmv/xine_hdmv_decoder.c @@ -138,7 +138,7 @@ struct presentation_segment_s { composition_object_t *comp_objs; - //presentation_segment_t *next; + presentation_segment_t *next; int64_t pts; int shown; @@ -562,6 +562,35 @@ static composition_object_t *segbuf_decode_composition_object(segment_buffer_t * return cobj; } +static presentation_segment_t *segbuf_decode_presentation_segment(segment_buffer_t *buf) +{ + presentation_segment_t *seg = calloc(1, sizeof(presentation_segment_t)); + int index; + + segbuf_decode_video_descriptor (buf); + segbuf_decode_composition_descriptor (buf, &seg->comp_descr); + + seg->palette_update_flag = !!((segbuf_get_u8(buf)) & 0x80); + seg->palette_id_ref = segbuf_get_u8 (buf); + seg->object_number = segbuf_get_u8 (buf); + + TRACE(" presentation_segment: object_number %d, palette %d\n", + seg->object_number, seg->palette_id_ref); + + for (index = 0; index < seg->object_number; index++) { + composition_object_t *cobj = segbuf_decode_composition_object (buf); + cobj->next = seg->comp_objs; + seg->comp_objs = cobj; + } + + if (buf->error) { + free_presentation_segment(seg); + return NULL; + } + + return seg; +} + static rle_elem_t *copy_crop_rle(subtitle_object_t *obj, composition_object_t *cobj) { /* TODO: cropping (w,h sized image from pos x,y) */ @@ -591,6 +620,8 @@ typedef struct spuhdmv_decoder_s { subtitle_clut_t *cluts; subtitle_object_t *objects; window_def_t *windows; + presentation_segment_t *segments; + int overlay_handles[MAX_OBJECTS]; int64_t pts; @@ -633,6 +664,23 @@ static int decode_window_definition(spuhdmv_decoder_t *this) return 0; } +static int decode_presentation_segment(spuhdmv_decoder_t *this) +{ + /* decode */ + presentation_segment_t *seg = segbuf_decode_presentation_segment(this->buf); + if (!seg) + return 1; + + seg->pts = this->pts; + + /* replace */ + if (this->segments) + LIST_DESTROY(this->segments, free_presentation_segment); + this->segments = seg; + + return 0; +} + static int show_overlay(spuhdmv_decoder_t *this, composition_object_t *cobj, uint palette_id_ref, int overlay_index, int64_t pts, int force_update) { @@ -751,8 +799,12 @@ static void hide_overlays(spuhdmv_decoder_t *this, int64_t pts) } } -static void update_overlays(spuhdmv_decoder_t *this, presentation_segment_t *pseg) +static void update_overlays(spuhdmv_decoder_t *this) { + presentation_segment_t *pseg = this->segments; + + while (pseg) { + if (!pseg->comp_descr.state) { /* HIDE */ @@ -776,35 +828,9 @@ static void update_overlays(spuhdmv_decoder_t *this, presentation_segment_t *pse } pseg->shown = 1; -} - -static int decode_presentation_segment(spuhdmv_decoder_t *this) -{ - presentation_segment_t p = {}; - segment_buffer_t *buf = this->buf; - int index; - - segbuf_decode_video_descriptor (this->buf); - segbuf_decode_composition_descriptor (this->buf, &p.comp_descr); - - p.palette_update_flag = !!((segbuf_get_u8(buf)) & 0x80); - p.palette_id_ref = segbuf_get_u8 (buf); - p.object_number = segbuf_get_u8 (buf); - - TRACE(" presentation_segment: object_number %d, palette %d\n", - p.object_number, p.palette_id_ref); - p.pts = this->pts; /* !! todo - use it ? */ - - for (index = 0; index < p.object_number; index++) { - composition_object_t *cobj = segbuf_decode_composition_object (this->buf); - cobj->next = p.comp_objs; - p.comp_objs = cobj; + pseg = pseg->next; } - - update_overlays (this, &p); - - return buf->error; } static void free_objs(spuhdmv_decoder_t *this) @@ -812,6 +838,7 @@ static void free_objs(spuhdmv_decoder_t *this) LIST_DESTROY (this->cluts, free); LIST_DESTROY (this->objects, free_subtitle_object); LIST_DESTROY (this->windows, free); + LIST_DESTROY (this->segments, free_presentation_segment); } static void decode_segment(spuhdmv_decoder_t *this) @@ -851,6 +878,8 @@ static void decode_segment(spuhdmv_decoder_t *this) if (this->buf->error) { ERROR("*** DECODE ERROR ***\n"); } + + update_overlays (this); } static void close_osd(spuhdmv_decoder_t *this) -- cgit v1.2.3