diff options
-rw-r--r-- | configure.ac | 13 | ||||
-rw-r--r-- | lib/os_internal.h | 7 | ||||
-rw-r--r-- | m4/pthreads.m4 | 3 | ||||
-rw-r--r-- | src/demuxers/demux_ac3.c | 3 | ||||
-rw-r--r-- | src/demuxers/demux_dts.c | 3 | ||||
-rw-r--r-- | src/demuxers/demux_yuv4mpeg2.c | 72 | ||||
-rw-r--r-- | src/demuxers/demux_yuv_frames.c | 7 | ||||
-rw-r--r-- | src/input/input_cdda.c | 1 | ||||
-rw-r--r-- | src/input/vcd/libcdio/FreeBSD/freebsd.c | 2 | ||||
-rw-r--r-- | src/libspucmml/xine_cmml_decoder.c | 99 | ||||
-rw-r--r-- | src/libspudec/xine_spu_decoder.c | 17 | ||||
-rw-r--r-- | src/libspudvb/xine_spudvb_decoder.c | 494 | ||||
-rw-r--r-- | src/libsputext/demux_sputext.c | 818 | ||||
-rw-r--r-- | src/libsputext/xine_sputext_decoder.c | 83 | ||||
-rw-r--r-- | src/post/deinterlace/Makefile.am | 2 | ||||
-rw-r--r-- | src/xine-engine/Makefile.am | 4 | ||||
-rw-r--r-- | src/xine-engine/load_plugins.c | 2 | ||||
-rw-r--r-- | src/xine-engine/post.c | 2 | ||||
-rw-r--r-- | src/xine-utils/Makefile.am | 2 | ||||
-rw-r--r-- | src/xine-utils/utils.c | 7 |
20 files changed, 781 insertions, 860 deletions
diff --git a/configure.ac b/configure.ac index e15311cdf..e8abfc211 100644 --- a/configure.ac +++ b/configure.ac @@ -228,6 +228,8 @@ dnl --------------------------------------------- CC_PTHREAD_FLAGS(, [AC_MSG_ERROR([Pthread support is needed])]) CC_PTHREAD_RECURSIVE_MUTEX(, [AC_MSG_ERROR([recursive mutex support is needed - please report])]) +dnl <pthread.h> is implicitly included by xine-internals.h, so the include dir is needed everywhere +CPPFLAGS="$CPPFLAGS $PTHREAD_CFLAGS" AC_CHECK_DECL(sysi86,[ AC_DEFINE(HAVE_SYSI86,1,[Define this if the 'sysi86' function is declared in sys/sysi86.h]) @@ -2157,10 +2159,10 @@ AC_CHECK_FUNC(opendir, AC_MSG_ERROR([dirent is needed (opendir, readdir, ...)]) fi]) -XINE_CHECK_MINMAX([], [ - AC_DEFINE([MIN(x, y)], [(x > y) ? y : x], [Get the minimum value between two]) - AC_DEFINE([MAX(x, y)], [(x > y) ? x : y], [Get the maximum value between two]) - ]) +XINE_CHECK_MINMAX([ + AC_DEFINE(HAVE_MAX_MACRO, 1, [Define to 1 if you have 'MAX' macro in sys/param.h]) + AC_DEFINE(HAVE_MIN_MACRO, 1, [Define to 1 if you have 'MIN' macro in sys/param.h]) + ],[]) dnl --------------------------------------------- dnl cflags and debug cflags @@ -2456,7 +2458,8 @@ else AC_DEFINE_UNQUOTED(XINE_FONTDIR,"$XINE_FONTPATH",[Define this to osd fonts dir location]) AC_DEFINE_UNQUOTED(XINE_LOCALEDIR, "$XINE_LOCALEPATH",[Path where catalog files will be.]) fi -AC_DEFINE_UNQUOTED(XINE_REL_PLUGINDIR,"$XINE_REL_PLUGINDIR",[Define this to plugin directory relative to execution prefix]) +AC_DEFINE_UNQUOTED(XINE_REL_PLUGINDIR,"$XINE_REL_PLUGINDIR",[Define this to specific plugin directory relative to execution prefix]) +AC_DEFINE_UNQUOTED(XINE_REL_PLUGINROOT,"$XINE_REL_PLUGINROOT",[Define this to general plugin directory relative to execution prefix]) AC_DEFINE_UNQUOTED(XINE_REL_FONTDIR,"$XINE_REL_FONTDIR",[Define this to font directory relative to prefix]) AC_DEFINE_UNQUOTED(XINE_REL_LOCALEDIR,"$XINE_REL_LOCALEDIR",[Define this to font directory relative to prefix]) AC_SUBST(XINE_CONFIG_PREFIX) diff --git a/lib/os_internal.h b/lib/os_internal.h index 968b8f02f..fe406a747 100644 --- a/lib/os_internal.h +++ b/lib/os_internal.h @@ -36,6 +36,13 @@ # define XINE_DIRECTORY_SEPARATOR_CHAR '/' #endif +/* replacement of min/max macros */ +#ifndef HAVE_MAX_MACRO +#define MAX(a,b) (((a)>(b))?(a):(b)) +#endif +#ifndef HAVE_MIN_MACRO +#define MIN(a,b) (((a)<(b))?(a):(b)) +#endif /* replacement of strndup */ #ifndef HAVE_STRNDUP diff --git a/m4/pthreads.m4 b/m4/pthreads.m4 index 8438cde0b..d1d1c0a62 100644 --- a/m4/pthreads.m4 +++ b/m4/pthreads.m4 @@ -86,11 +86,8 @@ AC_DEFUN([CC_PTHREAD_RECURSIVE_MUTEX], [ [AC_LANG_PROGRAM([ #include <pthread.h> ], [ -int main() { pthread_mutexattr_t attr; pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - return 0; -} ]) ], [cc_cv_pthread_recursive_mutex=yes], diff --git a/src/demuxers/demux_ac3.c b/src/demuxers/demux_ac3.c index 85852b33a..1acb12fcd 100644 --- a/src/demuxers/demux_ac3.c +++ b/src/demuxers/demux_ac3.c @@ -37,6 +37,9 @@ #ifdef HAVE_ALLOCA_H #include <alloca.h> #endif +#ifdef HAVE_MALLOC_H +#include <malloc.h> +#endif #define LOG_MODULE "demux_ac3" #define LOG_VERBOSE diff --git a/src/demuxers/demux_dts.c b/src/demuxers/demux_dts.c index 1b276c600..24a31c1cb 100644 --- a/src/demuxers/demux_dts.c +++ b/src/demuxers/demux_dts.c @@ -33,6 +33,9 @@ #ifdef HAVE_ALLOCA_H #include <alloca.h> #endif +#ifdef HAVE_MALLOC_H +#include <malloc.h> +#endif #define LOG_MODULE "demux_dts" #define LOG_VERBOSE diff --git a/src/demuxers/demux_yuv4mpeg2.c b/src/demuxers/demux_yuv4mpeg2.c index ca8234d96..2387fc7a7 100644 --- a/src/demuxers/demux_yuv4mpeg2.c +++ b/src/demuxers/demux_yuv4mpeg2.c @@ -197,21 +197,13 @@ static int open_yuv4mpeg2_file(demux_yuv4mpeg2_t *this) { this->frame_pts_inc = (90000 * this->fps_d) / this->fps_n; /* finally, look for the first frame */ - while ((header_ptr - header) < (Y4M_HEADER_BYTES - 4)) { - if((header_ptr[0] == 'F') && - (header_ptr[1] == 'R') && - (header_ptr[2] == 'A') && - (header_ptr[3] == 'M') && - (header_ptr[4] == 'E')) { - this->data_start = header_ptr - header; - break; - } else - header_ptr++; - } - + char *data_start_ptr = memmem(header_ptr, Y4M_HEADER_BYTES, "FRAME", 5); + /* make sure the first frame was found */ - if(!this->data_start) + if ( !data_start_ptr ) return 0; + + this->data_start = data_start_ptr - header; /* compute size of all frames */ if (INPUT_IS_SEEKABLE(this->input)) { @@ -228,29 +220,26 @@ static int open_yuv4mpeg2_file(demux_yuv4mpeg2_t *this) { static int demux_yuv4mpeg2_send_chunk(demux_plugin_t *this_gen) { demux_yuv4mpeg2_t *this = (demux_yuv4mpeg2_t *) this_gen; - buf_element_t *buf = NULL; - unsigned char preamble[Y4M_FRAME_SIGNATURE_SIZE]; - int bytes_remaining; - off_t current_file_pos; - int64_t pts; - /* validate that this is an actual frame boundary */ - if (this->input->read(this->input, preamble, Y4M_FRAME_SIGNATURE_SIZE) != - Y4M_FRAME_SIGNATURE_SIZE) { - this->status = DEMUX_FINISHED; - return this->status; - } - if (memcmp(preamble, Y4M_FRAME_SIGNATURE, Y4M_FRAME_SIGNATURE_SIZE) != - 0) { - this->status = DEMUX_FINISHED; - return this->status; + { + uint8_t preamble[Y4M_FRAME_SIGNATURE_SIZE]; + if (this->input->read(this->input, preamble, Y4M_FRAME_SIGNATURE_SIZE) != + Y4M_FRAME_SIGNATURE_SIZE) { + this->status = DEMUX_FINISHED; + return this->status; + } + if (memcmp(preamble, Y4M_FRAME_SIGNATURE, Y4M_FRAME_SIGNATURE_SIZE) != + 0) { + this->status = DEMUX_FINISHED; + return this->status; + } } /* load and dispatch the raw frame */ - bytes_remaining = this->frame_size; - current_file_pos = + int bytes_remaining = this->frame_size; + off_t current_file_pos = this->input->get_current_pos(this->input) - this->data_start; - pts = current_file_pos; + int64_t pts = current_file_pos; pts /= (this->frame_size + Y4M_FRAME_SIGNATURE_SIZE); pts *= this->frame_pts_inc; @@ -261,17 +250,14 @@ static int demux_yuv4mpeg2_send_chunk(demux_plugin_t *this_gen) { } while(bytes_remaining) { - buf = this->video_fifo->buffer_pool_alloc (this->video_fifo); + buf_element_t *buf = this->video_fifo->buffer_pool_alloc (this->video_fifo); buf->type = BUF_VIDEO_I420; if( this->data_size ) buf->extra_info->input_normpos = (int)((double) current_file_pos * 65535 / this->data_size); buf->extra_info->input_time = pts / 90; buf->pts = pts; - if (bytes_remaining > buf->max_size) - buf->size = buf->max_size; - else - buf->size = bytes_remaining; + buf->size = MIN(bytes_remaining, buf->max_size); bytes_remaining -= buf->size; if (this->input->read(this->input, buf->content, buf->size) != @@ -291,7 +277,6 @@ static int demux_yuv4mpeg2_send_chunk(demux_plugin_t *this_gen) { static void demux_yuv4mpeg2_send_headers(demux_plugin_t *this_gen) { demux_yuv4mpeg2_t *this = (demux_yuv4mpeg2_t *) this_gen; - buf_element_t *buf; this->video_fifo = this->stream->video_fifo; this->audio_fifo = this->stream->audio_fifo; @@ -310,7 +295,7 @@ static void demux_yuv4mpeg2_send_headers(demux_plugin_t *this_gen) { _x_demux_control_start(this->stream); /* send init info to decoders */ - buf = this->video_fifo->buffer_pool_alloc (this->video_fifo); + buf_element_t *buf = this->video_fifo->buffer_pool_alloc (this->video_fifo); buf->decoder_flags = BUF_FLAG_HEADER|BUF_FLAG_STDHEADER|BUF_FLAG_FRAMERATE| BUF_FLAG_FRAME_END; buf->decoder_info[0] = this->frame_pts_inc; /* initial video step */ @@ -400,10 +385,7 @@ static int demux_yuv4mpeg2_get_optional_data(demux_plugin_t *this_gen, static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *stream, input_plugin_t *input) { - - demux_yuv4mpeg2_t *this; - - this = calloc(1, sizeof(demux_yuv4mpeg2_t)); + demux_yuv4mpeg2_t *this = calloc(1, sizeof(demux_yuv4mpeg2_t)); this->stream = stream; this->input = input; @@ -422,10 +404,8 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *str switch (stream->content_detection_method) { case METHOD_BY_EXTENSION: { - const char *extensions, *mrl; - - mrl = input->get_mrl (input); - extensions = class_gen->get_extensions (class_gen); + const char *const mrl = input->get_mrl (input); + const char *const extensions = class_gen->get_extensions (class_gen); if (!_x_demux_check_extension (mrl, extensions)) { free (this); diff --git a/src/demuxers/demux_yuv_frames.c b/src/demuxers/demux_yuv_frames.c index f53ca78ee..c5ca363ed 100644 --- a/src/demuxers/demux_yuv_frames.c +++ b/src/demuxers/demux_yuv_frames.c @@ -70,8 +70,6 @@ static int demux_yuv_frames_get_status (demux_plugin_t *this_gen) { } static int switch_buf(demux_yuv_frames_t *this , buf_element_t *buf){ - int result = 0; - if (!buf) return 0; @@ -88,8 +86,7 @@ static int switch_buf(demux_yuv_frames_t *this , buf_element_t *buf){ case BUF_VIDEO_I420: case BUF_VIDEO_YUY2: this->video_fifo->put(this->video_fifo, buf); - result = 1; /* 1, we still should read audio */ - break; + return 1; /* 1, we still should read audio */ case BUF_AUDIO_LPCM_LE: if (!_x_stream_info_get(this->stream, XINE_STREAM_INFO_HAS_VIDEO)) _x_demux_control_newpts(this->stream, buf->pts, 0); @@ -100,7 +97,7 @@ static int switch_buf(demux_yuv_frames_t *this , buf_element_t *buf){ buf->free_buffer(buf); } - return result; + return 0; } static int demux_yuv_frames_send_chunk (demux_plugin_t *this_gen){ diff --git a/src/input/input_cdda.c b/src/input/input_cdda.c index 92eca7559..7b2ebf660 100644 --- a/src/input/input_cdda.c +++ b/src/input/input_cdda.c @@ -44,6 +44,7 @@ # include <sys/ioctl.h> #else /* for WIN32 */ +# include <windef.h> # include <winioctl.h> #endif diff --git a/src/input/vcd/libcdio/FreeBSD/freebsd.c b/src/input/vcd/libcdio/FreeBSD/freebsd.c index 5a3443e95..bcfe674a5 100644 --- a/src/input/vcd/libcdio/FreeBSD/freebsd.c +++ b/src/input/vcd/libcdio/FreeBSD/freebsd.c @@ -29,11 +29,11 @@ static const char _rcsid[] = "$Id: freebsd.c,v 1.1 2005/01/01 02:43:57 rockyb Exp $"; -#include <arpa/inet.h> #include "freebsd.h" #ifdef HAVE_FREEBSD_CDROM +#include <arpa/inet.h> #include <cdio/sector.h> static access_mode_t diff --git a/src/libspucmml/xine_cmml_decoder.c b/src/libspucmml/xine_cmml_decoder.c index 206d8c567..1a8f65e14 100644 --- a/src/libspucmml/xine_cmml_decoder.c +++ b/src/libspucmml/xine_cmml_decoder.c @@ -88,14 +88,13 @@ static void video_frame_format_change_callback (void *user_data, const xine_even static void update_font_size (spucmml_decoder_t *this) { - static int sizes[SUBTITLE_SIZE_NUM][4] = { + static const int sizes[SUBTITLE_SIZE_NUM][4] = { { 16, 16, 16, 20 }, /* SUBTITLE_SIZE_SMALL */ { 16, 16, 20, 24 }, /* SUBTITLE_SIZE_NORMAL */ { 16, 20, 24, 32 }, /* SUBTITLE_SIZE_LARGE */ }; - 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); @@ -505,10 +497,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.get_identifier = spucmml_class_get_identifier; diff --git a/src/libspudec/xine_spu_decoder.c b/src/libspudec/xine_spu_decoder.c index c604686e9..e63bdf8b9 100644 --- a/src/libspudec/xine_spu_decoder.c +++ b/src/libspudec/xine_spu_decoder.c @@ -68,11 +68,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); @@ -177,7 +175,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 ) @@ -185,6 +182,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, @@ -225,11 +223,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 */ @@ -313,7 +309,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)); @@ -337,6 +332,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/libspudvb/xine_spudvb_decoder.c b/src/libspudvb/xine_spudvb_decoder.c index 40d2a205a..957374799 100644 --- a/src/libspudvb/xine_spudvb_decoder.c +++ b/src/libspudvb/xine_spudvb_decoder.c @@ -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_decoder_t * this, int region_id, int region_w /* 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_decoder_t * this, int region_id, int region_w 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; + dvbsub_func_t *const dvbsub = this->dvbsub; - i = (y * dvbsub->regions[r].width) + x; + 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 * this, int r, int run_length, unsigned char 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 * this, int r, int run_length, unsigned char } } -static unsigned char next_nibble (dvb_spu_decoder_t * this) +static uint8_t 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); + 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); bits += 4; } else { bits += 4; - data = next_nibble (this); - switch_1 = (data & 0x08) >> 3; + const uint8_t data = next_nibble (this); + const uint8_t switch_1 = (data & 0x08) >> 3; bits++; if (switch_1 == 0) { - run_length = (data & 0x07); + const uint8_t run_length = (data & 0x07); bits += 3; if (run_length != 0) { - plot (this, r, run_length + 2, pixel_code); + plot (this, r, run_length + 2, 0); } else { break; } } else { - switch_2 = (data & 0x04) >> 2; + const uint8_t switch_2 = (data & 0x04) >> 2; bits++; if (switch_2 == 0) { - run_length = (data & 0x03); + const uint8_t run_length = (data & 0x03); bits += 2; - pixel_code = next_nibble (this); + const uint8_t pixel_code = next_nibble (this); bits += 4; plot (this, r, run_length + 4, pixel_code); } else { - switch_3 = (data & 0x03); + const uint8_t switch_3 = (data & 0x03); bits += 2; switch (switch_3) { case 0: - plot (this, r, 1, pixel_code); + plot (this, r, 1, 0); break; case 1: - plot (this, r, 2, pixel_code); + plot (this, r, 2, 0); break; case 2: - run_length = next_nibble (this); - bits += 4; - pixel_code = next_nibble (this); - bits += 4; - plot (this, r, run_length + 9, pixel_code); + { + const uint8_t run_length = next_nibble (this); + bits += 4; + const uint8_t pixel_code = next_nibble (this); + bits += 4; + plot (this, r, run_length + 9, pixel_code); + } break; case 3: - run_length = next_nibble (this); - run_length = (run_length << 4) | next_nibble (this); - bits += 8; - pixel_code = next_nibble (this); - bits += 4; - plot (this, r, run_length + 25, pixel_code); + { + uint8_t run_length = next_nibble (this); + run_length = (run_length << 4) | next_nibble (this); + bits += 8; + const uint8_t pixel_code = next_nibble (this); + bits += 4; + plot (this, r, run_length + 25, pixel_code); + } } } } @@ -337,41 +326,31 @@ static void set_clut(dvb_spu_decoder_t *this,int CLUT_id,int CLUT_entry_id,int Y } static void process_CLUT_definition_segment(dvb_spu_decoder_t *this) { - int page_id, - segment_length, - CLUT_id, - CLUT_version_number; - - int CLUT_entry_id, - CLUT_flag_8_bit, - CLUT_flag_4_bit, - CLUT_flag_2_bit, - full_range_flag, - Y_value, - Cr_value, - Cb_value, - T_value; dvbsub_func_t *dvbsub = this->dvbsub; - int j; - - page_id=(dvbsub->buf[dvbsub->i]<<8)|dvbsub->buf[dvbsub->i+1]; dvbsub->i+=2; - segment_length=(dvbsub->buf[dvbsub->i]<<8)|dvbsub->buf[dvbsub->i+1]; dvbsub->i+=2; - j=dvbsub->i+segment_length; + const uint16_t page_id= _X_BE_16(&dvbsub->buf[dvbsub->i]); + dvbsub->i+=2; + const uint16_t segment_length= _X_BE_16(&dvbsub->buf[dvbsub->i]); + dvbsub->i+=2; + const int j=dvbsub->i+segment_length; - CLUT_id=dvbsub->buf[dvbsub->i++]; - CLUT_version_number=(dvbsub->buf[dvbsub->i]&0xf0)>>4; + const uint8_t CLUT_id=dvbsub->buf[dvbsub->i++]; + const uint8_t CLUT_version_number=(dvbsub->buf[dvbsub->i]&0xf0)>>4; dvbsub->i++; while (dvbsub->i < j) { - CLUT_entry_id=dvbsub->buf[dvbsub->i++]; + const uint8_t CLUT_entry_id=dvbsub->buf[dvbsub->i++]; - CLUT_flag_2_bit=(dvbsub->buf[dvbsub->i]&0x80)>>7; - CLUT_flag_4_bit=(dvbsub->buf[dvbsub->i]&0x40)>>6; - CLUT_flag_8_bit=(dvbsub->buf[dvbsub->i]&0x20)>>5; - full_range_flag=dvbsub->buf[dvbsub->i]&1; + const uint8_t CLUT_flag_2_bit=(dvbsub->buf[dvbsub->i]&0x80)>>7; + const uint8_t CLUT_flag_4_bit=(dvbsub->buf[dvbsub->i]&0x40)>>6; + const uint8_t CLUT_flag_8_bit=(dvbsub->buf[dvbsub->i]&0x20)>>5; + const uint8_t full_range_flag=dvbsub->buf[dvbsub->i]&1; dvbsub->i++; + int Y_value, + Cr_value, + Cb_value, + T_value; if (full_range_flag==1) { Y_value=dvbsub->buf[dvbsub->i++]; Cr_value=dvbsub->buf[dvbsub->i++]; @@ -390,17 +369,14 @@ static void process_CLUT_definition_segment(dvb_spu_decoder_t *this) { static void process_pixel_data_sub_block (dvb_spu_decoder_t * this, int r, int o, int ofs, int n) { - int data_type; - int j; - dvbsub_func_t *dvbsub = this->dvbsub; - j = dvbsub->i + n; + const int j = dvbsub->i + n; dvbsub->x = (dvbsub->regions[r].object_pos[o]) >> 16; dvbsub->y = ((dvbsub->regions[r].object_pos[o]) & 0xffff) + ofs; while (dvbsub->i < j) { - data_type = dvbsub->buf[dvbsub->i++]; + const uint8_t data_type = dvbsub->buf[dvbsub->i++]; switch (data_type) { case 0: @@ -423,18 +399,14 @@ static void process_pixel_data_sub_block (dvb_spu_decoder_t * this, int r, int o static void process_page_composition_segment (dvb_spu_decoder_t * this) { - int segment_length; - int region_id, region_x, region_y; - int j; - int r; dvbsub_func_t *dvbsub = this->dvbsub; - dvbsub->page.page_id = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + dvbsub->page.page_id = _X_BE_16(&dvbsub->buf[dvbsub->i]); dvbsub->i += 2; - segment_length = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + const uint16_t segment_length = _X_BE_16(&dvbsub->buf[dvbsub->i]); dvbsub->i += 2; - j = dvbsub->i + segment_length; + const int j = dvbsub->i + segment_length; dvbsub->page.page_time_out = dvbsub->buf[dvbsub->i++]; @@ -442,6 +414,7 @@ static void process_page_composition_segment (dvb_spu_decoder_t * this) dvbsub->page.page_state = (dvbsub->buf[dvbsub->i] & 0x0c) >> 2; dvbsub->i++; if (dvbsub->page.page_state==2) { + int r; for (r=0; r<MAX_REGIONS; r++) dvbsub->page.regions[r].is_visible = 0; } @@ -450,11 +423,11 @@ static void process_page_composition_segment (dvb_spu_decoder_t * this) } while (dvbsub->i < j) { - region_id = dvbsub->buf[dvbsub->i++]; + const uint8_t region_id = dvbsub->buf[dvbsub->i++]; dvbsub->i++; /* reserved */ - region_x = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + const uint16_t region_x = _X_BE_16(&dvbsub->buf[dvbsub->i]); dvbsub->i += 2; - region_y = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + const uint16_t region_y = _X_BE_16(&dvbsub->buf[dvbsub->i]); dvbsub->i += 2; dvbsub->page.regions[region_id].x = region_x; @@ -465,36 +438,29 @@ static void process_page_composition_segment (dvb_spu_decoder_t * this) static void process_region_composition_segment (dvb_spu_decoder_t * this) { - int segment_length, - region_id, - region_version_number, - region_fill_flag, region_width, region_height, region_level_of_compatibility, region_depth, CLUT_id, region_8_bit_pixel_code, region_4_bit_pixel_code, region_2_bit_pixel_code; - int object_id, object_type, object_provider_flag, object_x, object_y, foreground_pixel_code, background_pixel_code; - int j; - int o; dvbsub_func_t *dvbsub = this->dvbsub; - dvbsub->page.page_id = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + dvbsub->page.page_id = _X_BE_16(&dvbsub->buf[dvbsub->i]); dvbsub->i += 2; - segment_length = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + const uint16_t segment_length = _X_BE_16(&dvbsub->buf[dvbsub->i]); dvbsub->i += 2; - j = dvbsub->i + segment_length; + const int j = dvbsub->i + segment_length; - region_id = dvbsub->buf[dvbsub->i++]; - region_version_number = (dvbsub->buf[dvbsub->i] & 0xf0) >> 4; - region_fill_flag = (dvbsub->buf[dvbsub->i] & 0x08) >> 3; + const uint8_t region_id = dvbsub->buf[dvbsub->i++]; + const uint8_t region_version_number = (dvbsub->buf[dvbsub->i] & 0xf0) >> 4; + const uint8_t region_fill_flag = (dvbsub->buf[dvbsub->i] & 0x08) >> 3; dvbsub->i++; - region_width = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + const uint16_t region_width = _X_BE_16(&dvbsub->buf[dvbsub->i]); dvbsub->i += 2; - region_height = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + const uint16_t region_height = _X_BE_16(&dvbsub->buf[dvbsub->i]); dvbsub->i += 2; - region_level_of_compatibility = (dvbsub->buf[dvbsub->i] & 0xe0) >> 5; - region_depth = (dvbsub->buf[dvbsub->i] & 0x1c) >> 2; + const uint8_t region_level_of_compatibility = (dvbsub->buf[dvbsub->i] & 0xe0) >> 5; + const uint8_t region_depth = (dvbsub->buf[dvbsub->i] & 0x1c) >> 2; dvbsub->i++; - CLUT_id = dvbsub->buf[dvbsub->i++]; - region_8_bit_pixel_code = dvbsub->buf[dvbsub->i++]; - region_4_bit_pixel_code = (dvbsub->buf[dvbsub->i] & 0xf0) >> 4; - region_2_bit_pixel_code = (dvbsub->buf[dvbsub->i] & 0x0c) >> 2; + const uint8_t CLUT_id = dvbsub->buf[dvbsub->i++]; + const uint8_t region_8_bit_pixel_code = dvbsub->buf[dvbsub->i++]; + const uint8_t region_4_bit_pixel_code = (dvbsub->buf[dvbsub->i] & 0xf0) >> 4; + const uint8_t region_2_bit_pixel_code = (dvbsub->buf[dvbsub->i] & 0x0c) >> 2; dvbsub->i++; if(region_id>=MAX_REGIONS) @@ -508,25 +474,28 @@ static void process_region_composition_segment (dvb_spu_decoder_t * this) dvbsub->regions[region_id].objects_start = dvbsub->i; dvbsub->regions[region_id].objects_end = j; - for (o = 0; o < 65536; o++) { - dvbsub->regions[region_id].object_pos[o] = 0xffffffff; + { + int o; + for (o = 0; o < 65536; o++) { + dvbsub->regions[region_id].object_pos[o] = 0xffffffff; + } } while (dvbsub->i < j) { - object_id = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + const uint16_t object_id = _X_BE_16(&dvbsub->buf[dvbsub->i]); dvbsub->i += 2; - object_type = (dvbsub->buf[dvbsub->i] & 0xc0) >> 6; - object_provider_flag = (dvbsub->buf[dvbsub->i] & 0x30) >> 4; - object_x = ((dvbsub->buf[dvbsub->i] & 0x0f) << 8) | dvbsub->buf[dvbsub->i + 1]; + const uint8_t object_type = (dvbsub->buf[dvbsub->i] & 0xc0) >> 6; + const uint8_t object_provider_flag = (dvbsub->buf[dvbsub->i] & 0x30) >> 4; + const uint16_t object_x = ((dvbsub->buf[dvbsub->i] & 0x0f) << 8) | dvbsub->buf[dvbsub->i + 1]; dvbsub->i += 2; - object_y = ((dvbsub->buf[dvbsub->i] & 0x0f) << 8) | dvbsub->buf[dvbsub->i + 1]; + const uint16_t object_y = ((dvbsub->buf[dvbsub->i] & 0x0f) << 8) | dvbsub->buf[dvbsub->i + 1]; dvbsub->i += 2; dvbsub->regions[region_id].object_pos[object_id] = (object_x << 16) | object_y; if ((object_type == 0x01) || (object_type == 0x02)) { - foreground_pixel_code = dvbsub->buf[dvbsub->i++]; - background_pixel_code = dvbsub->buf[dvbsub->i++]; + const uint8_t foreground_pixel_code = dvbsub->buf[dvbsub->i++]; + const uint8_t background_pixel_code = dvbsub->buf[dvbsub->i++]; } } @@ -534,49 +503,45 @@ static void process_region_composition_segment (dvb_spu_decoder_t * this) static void process_object_data_segment (dvb_spu_decoder_t * this) { - int segment_length, object_id, object_version_number, object_coding_method, non_modifying_colour_flag; - - int top_field_data_block_length, bottom_field_data_block_length; - dvbsub_func_t *dvbsub = this->dvbsub; - int j; - int old_i; - int r; - dvbsub->page.page_id = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; dvbsub->i += 2; - segment_length = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + const uint16_t segment_length = _X_BE_16(&dvbsub->buf[dvbsub->i]); dvbsub->i += 2; - j = dvbsub->i + segment_length; + const int j = dvbsub->i + segment_length; - object_id = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + const uint16_t object_id = _X_BE_16(&dvbsub->buf[dvbsub->i]); dvbsub->i += 2; dvbsub->curr_obj = object_id; - object_version_number = (dvbsub->buf[dvbsub->i] & 0xf0) >> 4; - object_coding_method = (dvbsub->buf[dvbsub->i] & 0x0c) >> 2; - non_modifying_colour_flag = (dvbsub->buf[dvbsub->i] & 0x02) >> 1; + const uint8_t object_version_number = (dvbsub->buf[dvbsub->i] & 0xf0) >> 4; + const uint8_t object_coding_method = (dvbsub->buf[dvbsub->i] & 0x0c) >> 2; + const uint8_t non_modifying_colour_flag = (dvbsub->buf[dvbsub->i] & 0x02) >> 1; dvbsub->i++; - old_i = dvbsub->i; + if ( object_coding_method != 0 ) + return; + + const int old_i = dvbsub->i; + int r; for (r = 0; r < MAX_REGIONS; r++) { /* If this object is in this region... */ - if (dvbsub->regions[r].img) { - if (dvbsub->regions[r].object_pos[object_id] != 0xffffffff) { - dvbsub->i = old_i; - if (object_coding_method == 0) { - top_field_data_block_length = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; - dvbsub->i += 2; - bottom_field_data_block_length = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; - dvbsub->i += 2; - - process_pixel_data_sub_block (this, r, object_id, 0, top_field_data_block_length); - - process_pixel_data_sub_block (this, r, object_id, 1, bottom_field_data_block_length); - } - } - } + if (!dvbsub->regions[r].img) + continue; + + if (dvbsub->regions[r].object_pos[object_id] == 0xffffffff) + continue; + + dvbsub->i = old_i; + + const uint16_t top_field_data_block_length = _X_BE_16(&dvbsub->buf[dvbsub->i]); + dvbsub->i += 2; + const uint16_t bottom_field_data_block_length = _X_BE_16(&dvbsub->buf[dvbsub->i]); + dvbsub->i += 2; + + process_pixel_data_sub_block (this, r, object_id, 0, top_field_data_block_length); + process_pixel_data_sub_block (this, r, object_id, 1, bottom_field_data_block_length); } } @@ -603,38 +568,37 @@ static void* dvbsub_timer_func(void *this_gen) { dvb_spu_decoder_t *this = (dvb_spu_decoder_t *) this_gen; pthread_mutex_lock(&this->dvbsub_osd_mutex); - int i; /* If we're cancelled via pthread_cancel, unlock the mutex */ pthread_cleanup_push(unlock_mutex_cancellation_func, &this->dvbsub_osd_mutex); - while(1) - { + while(1) { /* Record the current timeout, and wait - note that pthread_cond_timedwait will unlock the mutex on entry, and lock it on exit */ struct timespec timeout = this->dvbsub_hide_timeout; - int result = pthread_cond_timedwait(&this->dvbsub_restart_timeout, - &this->dvbsub_osd_mutex, - &this->dvbsub_hide_timeout); - if(result == ETIMEDOUT && - timeout.tv_sec == this->dvbsub_hide_timeout.tv_sec && - timeout.tv_nsec == this->dvbsub_hide_timeout.tv_nsec) - { - /* We timed out, and no-one changed the timeout underneath us. - Hide the OSD, then wait until we're signalled. */ - if(this && this->stream && this->stream->osd_renderer) - { - for ( i=0; i<MAX_REGIONS; i++ ) { - if ( this->dvbsub->regions[i].osd ) { - this->stream->osd_renderer->hide( this->dvbsub->regions[i].osd, 0 ); + const int result = pthread_cond_timedwait(&this->dvbsub_restart_timeout, + &this->dvbsub_osd_mutex, + &this->dvbsub_hide_timeout); + if(result != ETIMEDOUT || + timeout.tv_sec != this->dvbsub_hide_timeout.tv_sec || + timeout.tv_nsec != this->dvbsub_hide_timeout.tv_nsec) + continue; + + /* We timed out, and no-one changed the timeout underneath us. + Hide the OSD, then wait until we're signalled. */ + if(this && this->stream && this->stream->osd_renderer) { + int i; + for ( i=0; i<MAX_REGIONS; i++ ) { + if ( !this->dvbsub->regions[i].osd ) + continue; + + this->stream->osd_renderer->hide( this->dvbsub->regions[i].osd, 0 ); #ifdef LOG - printf("SPUDVB: thread hiding = %d\n",i); + printf("SPUDVB: thread hiding = %d\n",i); #endif - } - } } - pthread_cond_wait(&this->dvbsub_restart_timeout, &this->dvbsub_osd_mutex); } + pthread_cond_wait(&this->dvbsub_restart_timeout, &this->dvbsub_osd_mutex); } pthread_cleanup_pop(1); @@ -654,26 +618,29 @@ static void downscale_region_image( region_t *reg, unsigned char *dest, int dest static void draw_subtitles (dvb_spu_decoder_t * this) { - int r; - int display=0; int64_t dum; - int dest_width=0, dest_height, reg_width; + int dest_width=0, dest_height; this->stream->video_out->status(this->stream->video_out, NULL, &dest_width, &dest_height, &dum); - unsigned char tmp[dest_width*576]; - unsigned char *reg; if ( !dest_width ) return; /* render all regions onto the page */ - for ( r=0; r<MAX_REGIONS; r++ ) { - if ( this->dvbsub->page.regions[r].is_visible ) - display++; + { + int r; + int display = 0; + for ( r=0; r<MAX_REGIONS; r++ ) { + if ( this->dvbsub->page.regions[r].is_visible ) { + display = 1; + break; + } + } + if ( !display ) + return; } - if ( !display ) - return; + int r; for (r = 0; r < MAX_REGIONS; r++) { if (this->dvbsub->regions[r].img) { if (this->dvbsub->page.regions[r].is_visible && !this->dvbsub->regions[r].empty) { @@ -682,6 +649,10 @@ static void draw_subtitles (dvb_spu_decoder_t * this) continue; /* clear osd */ this->stream->osd_renderer->clear( this->dvbsub->regions[r].osd ); + + uint8_t *reg; + int reg_width; + uint8_t tmp[dest_width*576]; if (this->dvbsub->regions[r].width>dest_width) { downscale_region_image(&this->dvbsub->regions[r], tmp, dest_width); reg = tmp; @@ -731,12 +702,6 @@ static void draw_subtitles (dvb_spu_decoder_t * this) static void spudec_decode_data (spu_decoder_t * this_gen, buf_element_t * buf) { dvb_spu_decoder_t *this = (dvb_spu_decoder_t *) this_gen; - int new_i; - int data_identifier, subtitle_stream_id; - int segment_length, segment_type; - int PES_header_data_length; - int PES_packet_length; - int i; if((buf->type & 0xffff0000)!=BUF_SPU_DVB) return; @@ -746,6 +711,7 @@ static void spudec_decode_data (spu_decoder_t * this_gen, buf_element_t * buf) if (buf->decoder_info[2] == 0) { /* Hide the osd - note that if the timeout thread times out, it'll rehide, which is harmless */ pthread_mutex_lock(&this->dvbsub_osd_mutex); + int i; for ( i=0; i<MAX_REGIONS; i++ ) { if ( this->dvbsub->regions[i].osd ) this->stream->osd_renderer->hide( this->dvbsub->regions[i].osd, 0 ); @@ -779,12 +745,12 @@ static void spudec_decode_data (spu_decoder_t * this_gen, buf_element_t * buf) * because buf->pts could be too far in future and metronom won't accept * further backwards pts (see metronom_got_spu_packet) */ if (buf->pts) { - metronom_t *metronom = this->stream->metronom; - int64_t vpts_offset = metronom->get_option( metronom, METRONOM_VPTS_OFFSET ); - int64_t spu_offset = metronom->get_option( metronom, METRONOM_SPU_OFFSET ); - int64_t vpts = (int64_t)(buf->pts)+vpts_offset+spu_offset; - metronom_clock_t *clock = this->stream->xine->clock; - int64_t curvpts = clock->get_current_time( clock ); + metronom_t *const metronom = this->stream->metronom; + const int64_t vpts_offset = metronom->get_option( metronom, METRONOM_VPTS_OFFSET ); + const int64_t spu_offset = metronom->get_option( metronom, METRONOM_SPU_OFFSET ); + const int64_t vpts = (int64_t)(buf->pts)+vpts_offset+spu_offset; + metronom_clock_t *const clock = this->stream->xine->clock; + const int64_t curvpts = clock->get_current_time( clock ); /* if buf->pts is unreliable, show page asap (better than nothing) */ #ifdef LOG printf("SPUDVB: spu_vpts=%lld - current_vpts=%lld\n", vpts, curvpts); @@ -797,56 +763,55 @@ static void spudec_decode_data (spu_decoder_t * this_gen, buf_element_t * buf) /* process the pes section */ - PES_packet_length = this->pes_pkt_size; + const int PES_packet_length = this->pes_pkt_size; - this->dvbsub->buf = this->pes_pkt; + this->dvbsub->buf = this->pes_pkt; - PES_header_data_length = 0; - this->dvbsub->i = 0; + int PES_header_data_length = 0; + this->dvbsub->i = 0; - data_identifier = this->dvbsub->buf[this->dvbsub->i++]; - subtitle_stream_id = this->dvbsub->buf[this->dvbsub->i++]; + const uint8_t data_identifier = this->dvbsub->buf[this->dvbsub->i++]; + const uint8_t subtitle_stream_id = this->dvbsub->buf[this->dvbsub->i++]; - while (this->dvbsub->i <= (PES_packet_length)) { - /* SUBTITLING SEGMENT */ - this->dvbsub->i++; - segment_type = this->dvbsub->buf[this->dvbsub->i++]; + while (this->dvbsub->i <= (PES_packet_length)) { + /* SUBTITLING SEGMENT */ + this->dvbsub->i++; + const uint8_t segment_type = this->dvbsub->buf[this->dvbsub->i++]; - this->dvbsub->page.page_id = (this->dvbsub->buf[this->dvbsub->i] << 8) | this->dvbsub->buf[this->dvbsub->i + 1]; - segment_length = (this->dvbsub->buf[this->dvbsub->i + 2] << 8) | this->dvbsub->buf[this->dvbsub->i + 3]; - new_i = this->dvbsub->i + segment_length + 4; + 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 & 0xff) { - 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; - } + /* only process complete segments */ + if(new_i > (this->pes_pkt_wrptr - this->pes_pkt)) + break; - return; + /* 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_discontinuity (spu_decoder_t * this_gen) 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,7 +869,7 @@ static spu_decoder_t *dvb_spu_class_open_plugin (spu_decoder_class_t * class_gen 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); @@ -924,13 +877,6 @@ static spu_decoder_t *dvb_spu_class_open_plugin (spu_decoder_class_t * class_gen 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); this->dvbsub_hide_timeout.tv_nsec = 0; @@ -957,9 +903,7 @@ static char *dvb_spu_class_get_description (spu_decoder_class_t * this) 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; diff --git a/src/libsputext/demux_sputext.c b/src/libsputext/demux_sputext.c index 741d0612b..3e9efb079 100644 --- a/src/libsputext/demux_sputext.c +++ b/src/libsputext/demux_sputext.c @@ -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_sputext_t *this, char *line, off_t len) 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(demux_sputext_t *this, subtitle_t *current static char line[LINE_LEN + 1]; static char *s = NULL; - char text[LINE_LEN + 1], *p, *q; - int state; + char text[LINE_LEN + 1]; - p = NULL; + 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(demux_sputext_t *this, subtitle_t *current 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(demux_sputext_t *this, subtitle_t *current 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_microdvd(demux_sputext_t *this, subtitle_t *cur 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_microdvd(demux_sputext_t *this, subtitle_t *cur (sscanf (line, "{%ld}{%ld}%" LINE_LEN_QUOT "[^\r\n]", &(current->start), &(current->end),line2) !=3) ); - p=line2; + char *p=line2; - next=p, i=0; + 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_microdvd(demux_sputext_t *this, subtitle_t *cur } 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; + + { + 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; + } + + current->start = a1*360000+a2*6000+a3*100+a4; + current->end = b1*360000+b2*6000+b3*100+b4; } - current->start = a1*360000+a2*6000+a3*100+a4; - current->end = b1*360000+b2*6000+b3*100+b4; - + if (!read_line_from_input(this, line, LINE_LEN)) return NULL; - p=q=line; + char *p = line, *q = line; for (current->lines=1; current->lines <= SUB_MAX_TEXT; current->lines++) { + size_t len; for (q=p,len=0; *p && *p!='\r' && *p!='\n' && *p!='|' && strncasecmp(p,"[br]",4); p++,len++); current->text[current->lines-1] = strndup(q, len); if (!current->text[current->lines-1]) return ERR; @@ -340,25 +340,27 @@ static subtitle_t *sub_read_line_subviewer(demux_sputext_t *this, subtitle_t *cu } static subtitle_t *sub_read_line_subrip(demux_sputext_t *this,subtitle_t *current) { - char line[LINE_LEN + 1]; - int a1,a2,a3,a4,b1,b2,b3,b4; - int i,end_sub; - memset(current,0,sizeof(subtitle_t)); - do { - if(!read_line_from_input(this,line,LINE_LEN)) - return NULL; - i = sscanf(line,"%d:%d:%d%*[,.]%d --> %d:%d:%d%*[,.]%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4); - } while(i < 8); - current->start = a1*360000+a2*6000+a3*100+a4/10; - current->end = b1*360000+b2*6000+b3*100+b4/10; - i=0; - end_sub=0; + + { + int a1,a2,a3,a4,b1,b2,b3,b4,i; + do { + char line[LINE_LEN + 1]; + if(!read_line_from_input(this,line,LINE_LEN)) + return NULL; + i = sscanf(line,"%d:%d:%d%*[,.]%d --> %d:%d:%d%*[,.]%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4); + } while(i < 8); + current->start = a1*360000+a2*6000+a3*100+a4/10; + current->end = b1*360000+b2*6000+b3*100+b4/10; + } + + int i=0; + int end_sub=0; do { char *p; /* pointer to the curently read char */ - char temp_line[SUB_BUFSIZE]; /* subtitle line that will be transfered to current->text[i] */ - int temp_index; /* ... and its index wich 'points' to the first EMPTY place -> last read char is at temp_index-1 if temp_index>0 */ - temp_line[SUB_BUFSIZE-1]='\0'; /* just in case... */ + char line[LINE_LEN + 1]; + char temp_line[SUB_BUFSIZE] = { 0, }; /* subtitle line that will be transfered to current->text[i] */ + size_t temp_index; /* ... and its index wich 'points' to the first EMPTY place -> last read char is at temp_index-1 if temp_index>0 */ if(!read_line_from_input(this,line,LINE_LEN)) { if(i) break; /* if something was read, transmit it */ @@ -408,9 +410,6 @@ static subtitle_t *sub_read_line_subrip(demux_sputext_t *this,subtitle_t *curren static subtitle_t *sub_read_line_vplayer(demux_sputext_t *this,subtitle_t *current) { char line[LINE_LEN + 1]; - int a1,a2,a3,b1,b2,b3; - char *p=NULL, *next, *p2; - int i; memset (current, 0, sizeof(subtitle_t)); @@ -428,24 +427,32 @@ static subtitle_t *sub_read_line_vplayer(demux_sputext_t *this,subtitle_t *curre this->next_line[0] = '\0'; return NULL; } - if( (sscanf( line, "%d:%d:%d:", &a1, &a2, &a3) < 3) || - (sscanf( this->next_line, "%d:%d:%d:", &b1, &b2, &b3) < 3) ) - continue; - current->start = a1*360000+a2*6000+a3*100; - current->end = b1*360000+b2*6000+b3*100; + + { + int a1,a2,a3,b1,b2,b3; + if( (sscanf( line, "%d:%d:%d:", &a1, &a2, &a3) < 3) || + (sscanf( this->next_line, "%d:%d:%d:", &b1, &b2, &b3) < 3) ) + continue; + current->start = a1*360000+a2*6000+a3*100; + current->end = b1*360000+b2*6000+b3*100; + } + if ((current->end - current->start) > LINE_LEN) current->end = current->start + LINE_LEN; /* not too long though. */ /* teraz czas na wkopiowanie stringu */ - p=line; + char *p=line; /* finds the body of the subtitle_t */ - for (i=0; i<3; i++){ - p2=strchr( p, ':'); - if( p2 == NULL ) break; - p=p2+1; - } + { + int i; + for (i=0; i<3; i++){ + char *p2=strchr( p, ':'); + if( p2 == NULL ) break; + p=p2+1; + } + } - next=p; - i=0; + char *next=p; + int i=0; while( (next = sub_readtext( next, &(current->text[i]))) ) { if (current->text[i]==ERR) return ERR; @@ -467,35 +474,40 @@ static subtitle_t *sub_read_line_rt(demux_sputext_t *this,subtitle_t *current) { * I couldn't check it since DTD is not included. * WARNING: full XML parses can be required for proper parsing */ - char line[LINE_LEN + 1]; - int a1,a2,a3,a4,b1,b2,b3,b4; - char *p=NULL,*next=NULL; - int i,len,plen; - memset (current, 0, sizeof(subtitle_t)); while (!current->text[0]) { + char line[LINE_LEN + 1]; if (!read_line_from_input(this, line, LINE_LEN)) return NULL; + + char *p = line; /* * TODO: it seems that format of time is not easily determined, it may be 1:12, 1:12.0 or 0:1:12.0 * to describe the same moment in time. Maybe there are even more formats in use. */ - if ((len=sscanf (line, "<Time Begin=\"%d:%d:%d.%d\" End=\"%d:%d:%d.%d\"",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4)) < 8) - - plen=a1=a2=a3=a4=b1=b2=b3=b4=0; - if ( - ((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d\" %*[Ee]nd=\"%d:%d\"%*[^<]<clear/>%n",&a2,&a3,&b2,&b3,&plen)) < 4) && - ((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d\" %*[Ee]nd=\"%d:%d.%d\"%*[^<]<clear/>%n",&a2,&a3,&b2,&b3,&b4,&plen)) < 5) && - /* ((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d.%d\" %*[Ee]nd=\"%d:%d\"%*[^<]<clear/>%n",&a2,&a3,&a4,&b2,&b3,&plen)) < 5) && */ - ((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d.%d\" %*[Ee]nd=\"%d:%d.%d\"%*[^<]<clear/>%n",&a2,&a3,&a4,&b2,&b3,&b4,&plen)) < 6) && - ((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d:%d.%d\" %*[Ee]nd=\"%d:%d:%d.%d\"%*[^<]<clear/>%n",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4,&plen)) < 8) - ) - continue; - current->start = a1*360000+a2*6000+a3*100+a4/10; - current->end = b1*360000+b2*6000+b3*100+b4/10; - p=line; p+=plen;i=0; + { + int a1,a2,a3,a4,b1,b2,b3,b4,len,plen; + if ((len=sscanf (line, "<Time Begin=\"%d:%d:%d.%d\" End=\"%d:%d:%d.%d\"",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4)) < 8) + + a1=a2=a3=a4=b1=b2=b3=b4=0; + if ( + ((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d\" %*[Ee]nd=\"%d:%d\"%*[^<]<clear/>%n",&a2,&a3,&b2,&b3,&plen)) < 4) && + ((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d\" %*[Ee]nd=\"%d:%d.%d\"%*[^<]<clear/>%n",&a2,&a3,&b2,&b3,&b4,&plen)) < 5) && + /* ((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d.%d\" %*[Ee]nd=\"%d:%d\"%*[^<]<clear/>%n",&a2,&a3,&a4,&b2,&b3,&plen)) < 5) && */ + ((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d.%d\" %*[Ee]nd=\"%d:%d.%d\"%*[^<]<clear/>%n",&a2,&a3,&a4,&b2,&b3,&b4,&plen)) < 6) && + ((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d:%d.%d\" %*[Ee]nd=\"%d:%d:%d.%d\"%*[^<]<clear/>%n",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4,&plen)) < 8) + ) + continue; + + current->start = a1*360000+a2*6000+a3*100+a4/10; + current->end = b1*360000+b2*6000+b3*100+b4/10; + + p += plen; + } + + int i=0; /* TODO: I don't know what kind of convention is here for marking multiline subs, maybe <br/> like in xml? */ - next = strstr(line,"<clear/>")+8;i=0; + char *next = strstr(line,"<clear/>")+8;i=0; while ((next =sub_readtext (next, &(current->text[i])))) { if (current->text[i]==ERR) return ERR; @@ -512,50 +524,52 @@ static subtitle_t *sub_read_line_rt(demux_sputext_t *this,subtitle_t *current) { } static subtitle_t *sub_read_line_ssa(demux_sputext_t *this,subtitle_t *current) { - int comma; static int max_comma = 32; /* let's use 32 for the case that the */ /* amount of commas increase with newer SSA versions */ int hour1, min1, sec1, hunsec1, hour2, min2, sec2, hunsec2, nothing; - int num; - char line[LINE_LEN + 1], line3[LINE_LEN + 1], *line2; - char *tmp; + char line3[LINE_LEN + 1]; - do { - if (!read_line_from_input(this, line, LINE_LEN)) return NULL; - } while (sscanf (line, "Dialogue: Marked=%d,%d:%d:%d.%d,%d:%d:%d.%d," - "%[^\n\r]", ¬hing, - &hour1, &min1, &sec1, &hunsec1, - &hour2, &min2, &sec2, &hunsec2, - line3) < 9 - && - sscanf (line, "Dialogue: %d,%d:%d:%d.%d,%d:%d:%d.%d," - "%[^\n\r]", ¬hing, - &hour1, &min1, &sec1, &hunsec1, - &hour2, &min2, &sec2, &hunsec2, - line3) < 9 ); + { + char line[LINE_LEN + 1]; + do { + if (!read_line_from_input(this, line, LINE_LEN)) return NULL; + } while (sscanf (line, "Dialogue: Marked=%d,%d:%d:%d.%d,%d:%d:%d.%d," + "%[^\n\r]", ¬hing, + &hour1, &min1, &sec1, &hunsec1, + &hour2, &min2, &sec2, &hunsec2, + line3) < 9 + && + sscanf (line, "Dialogue: %d,%d:%d:%d.%d,%d:%d:%d.%d," + "%[^\n\r]", ¬hing, + &hour1, &min1, &sec1, &hunsec1, + &hour2, &min2, &sec2, &hunsec2, + line3) < 9 ); + } - line2=strchr(line3, ','); + char *line2=strchr(line3, ','); if (!line2) return NULL; - for (comma = 4; comma < max_comma; comma ++) - { - tmp = line2; - if(!(tmp=strchr(++tmp, ','))) break; - if(*(++tmp) == ' ') break; - /* a space after a comma means we're already in a sentence */ - line2 = tmp; - } + int comma; + for (comma = 4; comma < max_comma; comma ++) { + char *tmp = line2; + if(!(tmp=strchr(++tmp, ','))) break; + if(*(++tmp) == ' ') break; + /* a space after a comma means we're already in a sentence */ + line2 = tmp; + } if(comma < max_comma)max_comma = comma; /* eliminate the trailing comma */ if(*line2 == ',') line2++; - current->lines=0;num=0; + current->lines=0; current->start = 360000*hour1 + 6000*min1 + 100*sec1 + hunsec1; current->end = 360000*hour2 + 6000*min2 + 100*sec2 + hunsec2; + int num=0; + char *tmp; while (((tmp=strstr(line2, "\\n")) != NULL) || ((tmp=strstr(line2, "\\N")) != NULL) ){ current->text[num] = strndup(line2, tmp-line2); line2=tmp+2; @@ -583,8 +597,7 @@ static subtitle_t *sub_read_line_ssa(demux_sputext_t *this,subtitle_t *current) static subtitle_t *sub_read_line_pjs (demux_sputext_t *this, subtitle_t *current) { char line[LINE_LEN + 1]; - char text[LINE_LEN + 1]; - char *s, *d; + char *s; memset (current, 0, sizeof(subtitle_t)); @@ -610,6 +623,8 @@ static subtitle_t *sub_read_line_pjs (demux_sputext_t *this, subtitle_t *current return ERR; } /* copy the string to the text buffer */ + char text[LINE_LEN + 1]; + char *d = NULL; for (s++, d=text; *s && *s!='"'; s++, d++) *d=*s; *d=0; @@ -621,25 +636,26 @@ static subtitle_t *sub_read_line_pjs (demux_sputext_t *this, subtitle_t *current static subtitle_t *sub_read_line_mpsub (demux_sputext_t *this, subtitle_t *current) { char line[LINE_LEN + 1]; - float a,b; - int num=0; - char *p, *q; - do { - if (!read_line_from_input(this, line, LINE_LEN)) - return NULL; - } while (sscanf (line, "%f %f", &a, &b) !=2); - - this->mpsub_position += (a*100.0); - current->start = (int) this->mpsub_position; - this->mpsub_position += (b*100.0); - current->end = (int) this->mpsub_position; + { + float a,b; + do { + if (!read_line_from_input(this, line, LINE_LEN)) + return NULL; + } while (sscanf (line, "%f %f", &a, &b) !=2); + + this->mpsub_position += (a*100.0); + current->start = (int) this->mpsub_position; + this->mpsub_position += (b*100.0); + current->end = (int) this->mpsub_position; + } + int num = 0; while (num < SUB_MAX_TEXT) { if (!read_line_from_input(this, line, LINE_LEN)) return NULL; - p=line; + char *p=line; while (isspace(*p)) p++; @@ -649,17 +665,15 @@ static subtitle_t *sub_read_line_mpsub (demux_sputext_t *this, subtitle_t *curre if (eol(*p)) return NULL; + char *q; for (q=p; !eol(*q); q++); *q='\0'; - if (strlen(p)) { + if (*p) { current->text[num]=strdup(p); xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, ">%s<\n",p); current->lines = ++num; } else { - if (num) - return current; - else - return NULL; + return num ? current : NULL; } } @@ -667,11 +681,10 @@ static subtitle_t *sub_read_line_mpsub (demux_sputext_t *this, subtitle_t *curre } static subtitle_t *sub_read_line_aqt (demux_sputext_t *this, subtitle_t *current) { - char line[LINE_LEN + 1]; - memset (current, 0, sizeof(subtitle_t)); while (1) { + char line[LINE_LEN + 1]; /* try to locate next subtitle_t */ if (!read_line_from_input(this, line, LINE_LEN)) return NULL; @@ -679,6 +692,7 @@ static subtitle_t *sub_read_line_aqt (demux_sputext_t *this, subtitle_t *current break; } + char line[LINE_LEN + 1]; if (!read_line_from_input(this, line, LINE_LEN)) return NULL; @@ -700,250 +714,252 @@ static subtitle_t *sub_read_line_aqt (demux_sputext_t *this, subtitle_t *current } static subtitle_t *sub_read_line_jacobsub(demux_sputext_t *this, subtitle_t *current) { - char line1[LINE_LEN], line2[LINE_LEN], directive[LINE_LEN], *p, *q; - unsigned a1, a2, a3, a4, b1, b2, b3, b4, comment = 0; - static unsigned jacoTimeres = 30; - static int jacoShift = 0; - - memset(current, 0, sizeof(subtitle_t)); - memset(line1, 0, LINE_LEN); - memset(line2, 0, LINE_LEN); - memset(directive, 0, LINE_LEN); - while (!current->text[0]) { - if (!read_line_from_input(this, line1, LINE_LEN)) { - return NULL; - } - if (sscanf - (line1, "%u:%u:%u.%u %u:%u:%u.%u %" LINE_LEN_QUOT "[^\n\r]", &a1, &a2, &a3, &a4, - &b1, &b2, &b3, &b4, line2) < 9) { - if (sscanf(line1, "@%u @%u %" LINE_LEN_QUOT "[^\n\r]", &a4, &b4, line2) < 3) { - if (line1[0] == '#') { - int hours = 0, minutes = 0, seconds, delta, inverter = - 1; - unsigned units = jacoShift; - switch (toupper(line1[1])) { - case 'S': - if (isalpha(line1[2])) { - delta = 6; - } else { - delta = 2; - } - if (sscanf(&line1[delta], "%d", &hours)) { - if (hours < 0) { - hours *= -1; - inverter = -1; - } - if (sscanf(&line1[delta], "%*d:%d", &minutes)) { - if (sscanf - (&line1[delta], "%*d:%*d:%d", - &seconds)) { - sscanf(&line1[delta], "%*d:%*d:%*d.%d", - &units); - } else { - hours = 0; - sscanf(&line1[delta], "%d:%d.%d", - &minutes, &seconds, &units); - minutes *= inverter; - } - } else { - hours = minutes = 0; - sscanf(&line1[delta], "%d.%d", &seconds, - &units); - seconds *= inverter; - } - jacoShift = - ((hours * 3600 + minutes * 60 + - seconds) * jacoTimeres + - units) * inverter; - } - break; - case 'T': - if (isalpha(line1[2])) { - delta = 8; - } else { - delta = 2; - } - sscanf(&line1[delta], "%u", &jacoTimeres); - break; - } - } - continue; + char line1[LINE_LEN] = { 0, }, line2[LINE_LEN] = { 0, }, directive[LINE_LEN] = { 0, }, *p, *q; + unsigned a1, a2, a3, a4, b1, b2, b3, b4, comment = 0; + static unsigned jacoTimeres = 30; + static int jacoShift = 0; + + memset(current, 0, sizeof(subtitle_t)); + while (!current->text[0]) { + if (!read_line_from_input(this, line1, LINE_LEN)) { + return NULL; + } + if (sscanf + (line1, "%u:%u:%u.%u %u:%u:%u.%u %" LINE_LEN_QUOT "[^\n\r]", &a1, &a2, &a3, &a4, + &b1, &b2, &b3, &b4, line2) < 9) { + if (sscanf(line1, "@%u @%u %" LINE_LEN_QUOT "[^\n\r]", &a4, &b4, line2) < 3) { + if (line1[0] == '#') { + int hours = 0, minutes = 0, seconds, delta, inverter = + 1; + unsigned units = jacoShift; + switch (toupper(line1[1])) { + case 'S': + if (isalpha(line1[2])) { + delta = 6; } else { - current->start = - (unsigned long) ((a4 + jacoShift) * 100.0 / - jacoTimeres); - current->end = - (unsigned long) ((b4 + jacoShift) * 100.0 / - jacoTimeres); + delta = 2; } - } else { - current->start = - (unsigned - long) (((a1 * 3600 + a2 * 60 + a3) * jacoTimeres + a4 + - jacoShift) * 100.0 / jacoTimeres); - current->end = - (unsigned - long) (((b1 * 3600 + b2 * 60 + b3) * jacoTimeres + b4 + - jacoShift) * 100.0 / jacoTimeres); - } - current->lines = 0; - p = line2; - while ((*p == ' ') || (*p == '\t')) { - ++p; - } - if (isalpha(*p)||*p == '[') { - if (sscanf(p, "%s %" LINE_LEN_QUOT "[^\n\r]", directive, line1) < 2) - return ERR; - if ((strcasestr(directive, "RDB") != NULL) - || (strcasestr(directive, "RDC") != NULL) - || (strcasestr(directive, "RLB") != NULL) - || (strcasestr(directive, "RLG") != NULL)) { - continue; + if (sscanf(&line1[delta], "%d", &hours)) { + if (hours < 0) { + hours *= -1; + inverter = -1; + } + if (sscanf(&line1[delta], "%*d:%d", &minutes)) { + if (sscanf + (&line1[delta], "%*d:%*d:%d", + &seconds)) { + sscanf(&line1[delta], "%*d:%*d:%*d.%d", + &units); + } else { + hours = 0; + sscanf(&line1[delta], "%d:%d.%d", + &minutes, &seconds, &units); + minutes *= inverter; + } + } else { + hours = minutes = 0; + sscanf(&line1[delta], "%d.%d", &seconds, + &units); + seconds *= inverter; + } + jacoShift = + ((hours * 3600 + minutes * 60 + + seconds) * jacoTimeres + + units) * inverter; } - /* no alignment */ -#if 0 - if (strcasestr(directive, "JL") != NULL) { - current->alignment = SUB_ALIGNMENT_HLEFT; - } else if (strcasestr(directive, "JR") != NULL) { - current->alignment = SUB_ALIGNMENT_HRIGHT; + break; + case 'T': + if (isalpha(line1[2])) { + delta = 8; } else { - current->alignment = SUB_ALIGNMENT_HCENTER; + delta = 2; } + sscanf(&line1[delta], "%u", &jacoTimeres); + break; + } + } + continue; + } else { + current->start = + (unsigned long) ((a4 + jacoShift) * 100.0 / + jacoTimeres); + current->end = + (unsigned long) ((b4 + jacoShift) * 100.0 / + jacoTimeres); + } + } else { + current->start = + (unsigned + long) (((a1 * 3600 + a2 * 60 + a3) * jacoTimeres + a4 + + jacoShift) * 100.0 / jacoTimeres); + current->end = + (unsigned + long) (((b1 * 3600 + b2 * 60 + b3) * jacoTimeres + b4 + + jacoShift) * 100.0 / jacoTimeres); + } + current->lines = 0; + p = line2; + while ((*p == ' ') || (*p == '\t')) { + ++p; + } + if (isalpha(*p)||*p == '[') { + if (sscanf(p, "%s %" LINE_LEN_QUOT "[^\n\r]", directive, line1) < 2) + return ERR; + if ((strcasestr(directive, "RDB") != NULL) + || (strcasestr(directive, "RDC") != NULL) + || (strcasestr(directive, "RLB") != NULL) + || (strcasestr(directive, "RLG") != NULL)) { + continue; + } + /* no alignment */ +#if 0 + if (strcasestr(directive, "JL") != NULL) { + current->alignment = SUB_ALIGNMENT_HLEFT; + } else if (strcasestr(directive, "JR") != NULL) { + current->alignment = SUB_ALIGNMENT_HRIGHT; + } else { + current->alignment = SUB_ALIGNMENT_HCENTER; + } #endif - strcpy(line2, line1); - p = line2; + strcpy(line2, line1); + p = line2; + } + for (q = line1; (!eol(*p)) && (current->lines < SUB_MAX_TEXT); ++p) { + switch (*p) { + case '{': + comment++; + break; + case '}': + if (comment) { + --comment; + /* the next line to get rid of a blank after the comment */ + if ((*(p + 1)) == ' ') + p++; } - for (q = line1; (!eol(*p)) && (current->lines < SUB_MAX_TEXT); ++p) { - switch (*p) { - case '{': - comment++; - break; - case '}': - if (comment) { - --comment; - /* the next line to get rid of a blank after the comment */ - if ((*(p + 1)) == ' ') - p++; - } - break; - case '~': - if (!comment) { - *q = ' '; - ++q; - } - break; - case ' ': - case '\t': - if ((*(p + 1) == ' ') || (*(p + 1) == '\t')) - break; - if (!comment) { - *q = ' '; - ++q; - } - break; - case '\\': - if (*(p + 1) == 'n') { - *q = '\0'; - q = line1; - current->text[current->lines++] = strdup(line1); - ++p; - break; - } - if ((toupper(*(p + 1)) == 'C') - || (toupper(*(p + 1)) == 'F')) { - ++p,++p; - break; - } - if ((*(p + 1) == 'B') || (*(p + 1) == 'b') || - /* actually this means "insert current date here" */ - (*(p + 1) == 'D') || - (*(p + 1) == 'I') || (*(p + 1) == 'i') || - (*(p + 1) == 'N') || - /* actually this means "insert current time here" */ - (*(p + 1) == 'T') || - (*(p + 1) == 'U') || (*(p + 1) == 'u')) { - ++p; - break; - } - if ((*(p + 1) == '\\') || - (*(p + 1) == '~') || (*(p + 1) == '{')) { - ++p; - } else if (eol(*(p + 1))) { - if (!read_line_from_input(this, directive, LINE_LEN)) - return NULL; - trail_space(directive); - strncat(line2, directive, - ((LINE_LEN > 511) ? LINE_LEN-1 : 511) - - strlen(line2)); - break; - } - default: - if (!comment) { - *q = *p; - ++q; - } - } + break; + case '~': + if (!comment) { + *q = ' '; + ++q; + } + break; + case ' ': + case '\t': + if ((*(p + 1) == ' ') || (*(p + 1) == '\t')) + break; + if (!comment) { + *q = ' '; + ++q; + } + break; + case '\\': + if (*(p + 1) == 'n') { + *q = '\0'; + q = line1; + current->text[current->lines++] = strdup(line1); + ++p; + break; } - *q = '\0'; - if (current->lines < SUB_MAX_TEXT) - current->text[current->lines] = strdup(line1); - else - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "Too many lines in a subtitle\n"); + if ((toupper(*(p + 1)) == 'C') + || (toupper(*(p + 1)) == 'F')) { + ++p,++p; + break; + } + if ((*(p + 1) == 'B') || (*(p + 1) == 'b') || + /* actually this means "insert current date here" */ + (*(p + 1) == 'D') || + (*(p + 1) == 'I') || (*(p + 1) == 'i') || + (*(p + 1) == 'N') || + /* actually this means "insert current time here" */ + (*(p + 1) == 'T') || + (*(p + 1) == 'U') || (*(p + 1) == 'u')) { + ++p; + break; + } + if ((*(p + 1) == '\\') || + (*(p + 1) == '~') || (*(p + 1) == '{')) { + ++p; + } else if (eol(*(p + 1))) { + if (!read_line_from_input(this, directive, LINE_LEN)) + return NULL; + trail_space(directive); + strncat(line2, directive, + ((LINE_LEN > 511) ? LINE_LEN-1 : 511) + - strlen(line2)); + break; + } + default: + if (!comment) { + *q = *p; + ++q; + } + } } - current->lines++; - return current; + *q = '\0'; + if (current->lines < SUB_MAX_TEXT) + current->text[current->lines] = strdup(line1); + else + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "Too many lines in a subtitle\n"); + } + current->lines++; + return current; } static subtitle_t *sub_read_line_subviewer2(demux_sputext_t *this, subtitle_t *current) { + char *p=NULL; + + while (!current->text[0]) { char line[LINE_LEN+1]; - int a1,a2,a3,a4; - char *p=NULL; - int i,len; - - while (!current->text[0]) { - if (!read_line_from_input(this, line, LINE_LEN)) return NULL; - if (line[0]!='{') - continue; - if ((len=sscanf (line, "{T %d:%d:%d:%d",&a1,&a2,&a3,&a4)) < 4) - continue; - current->start = a1*360000+a2*6000+a3*100+a4/10; - for (i=0; i<SUB_MAX_TEXT;) { - if (!read_line_from_input(this, line, LINE_LEN)) break; - if (line[0]=='}') break; - len=0; - for (p=line; *p!='\n' && *p!='\r' && *p; ++p,++len); - if (len) { - current->text[i] = strndup(line, len); - if (!current->text[i]) return ERR; - ++i; - } else { - break; - } - } - current->lines=i; + if (!read_line_from_input(this, line, LINE_LEN)) return NULL; + if (line[0]!='{') + continue; + + { + int a1,a2,a3,a4; + const int len = sscanf (line, "{T %d:%d:%d:%d",&a1,&a2,&a3,&a4); + if (len < 4) + continue; + current->start = a1*360000+a2*6000+a3*100+a4/10; } - return current; + + int i; + for (i=0; i<SUB_MAX_TEXT;) { + if (!read_line_from_input(this, line, LINE_LEN)) break; + if (line[0]=='}') break; + size_t len=0; + for (p=line; *p!='\n' && *p!='\r' && *p; ++p,++len); + if (len) { + current->text[i] = strndup(line, len); + if (!current->text[i]) return ERR; + ++i; + } else { + break; + } + } + current->lines=i; + } + return current; } static subtitle_t *sub_read_line_subrip09 (demux_sputext_t *this, subtitle_t *current) { - char line[LINE_LEN + 1]; - char *next; - int h, m, s; - int i; - memset (current, 0, sizeof(subtitle_t)); - - do { - if (!read_line_from_input (this, line, LINE_LEN)) return NULL; - } while (sscanf (line, "[%d:%d:%d]", &h, &m, &s) != 3); + int h, m, s; + { + char line[LINE_LEN + 1]; + do { + if (!read_line_from_input (this, line, LINE_LEN)) return NULL; + } while (sscanf (line, "[%d:%d:%d]", &h, &m, &s) != 3); + } + + char line[LINE_LEN + 1]; if (!read_line_from_input (this, line, LINE_LEN)) return NULL; current->start = 360000 * h + 6000 * m + 100 * s; current->end = -1; - next=line; - i=0; + char *next = line; + int i=0; while ((next = sub_readtext (next, &(current->text[i])))) { if (current->text[i]==ERR) return ERR; i++; @@ -963,22 +979,27 @@ static subtitle_t *sub_read_line_subrip09 (demux_sputext_t *this, subtitle_t *cu */ static subtitle_t *sub_read_line_mpl2(demux_sputext_t *this, subtitle_t *current) { - char line[LINE_LEN+1]; char line2[LINE_LEN+1]; - char *p, *next; - int i; memset (current, 0, sizeof(subtitle_t)); - do { - if (!read_line_from_input (this, line, LINE_LEN)) return NULL; - } while ((sscanf (line, + + { + char line[LINE_LEN+1]; + long start, end; + + do { + if (!read_line_from_input (this, line, LINE_LEN)) return NULL; + } while ((sscanf (line, "[%ld][%ld]%[^\r\n]", - &(current->start), &(current->end), line2) < 3)); - current->start *= 10; - current->end *= 10; - p=line2; + &start, &end, line2) < 3)); + + current->start = start * 10; + current->end = end * 10; + } + + char *p = line2, *next = p; + int i = 0; - next=p, i=0; while ((next = sub_readtext (next, &(current->text[i])))) { if (current->text[i] == ERR) {return ERR;} i++; @@ -996,16 +1017,13 @@ static subtitle_t *sub_read_line_mpl2(demux_sputext_t *this, subtitle_t *current static int sub_autodetect (demux_sputext_t *this) { - - char line[LINE_LEN + 1]; - int i, j=0; - char p; - - while (j < 100) { - j++; + int j; + for(j = 1; j < 100; j++) { + char line[LINE_LEN + 1]; if (!read_line_from_input(this, line, LINE_LEN)) return FORMAT_UNKNOWN; + int i; if ((sscanf (line, "{%d}{}", &i)==1) || (sscanf (line, "{%d}{%d}", &i, &i)==2)) { this->uses_time=0; @@ -1065,11 +1083,14 @@ static int sub_autodetect (demux_sputext_t *this) { xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "mpsub subtitle format detected\n"); return FORMAT_MPSUB; } + + char p; if (sscanf (line, "FORMAT=TIM%c", &p)==1 && p=='E') { this->uses_time=1; xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "mpsub subtitle format detected\n"); return FORMAT_MPSUB; } + if (strstr (line, "-->>")) { 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_t *this) { 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_sputext_t *this) { } 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; - while(1) { - subtitle_t *sub; + const int timeout = + (((demux_sputext_class_t *) + (this->demux_plugin.demux_class))->max_timeout) * + (this->uses_time ? 100 : 10); + while(1) { 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_sputext_t *this) { 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]; + subtitle_t *sub = &this->subtitles[this->cur]; - 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_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_sputext_t *this_gen) { 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_status (demux_plugin_t *this_gen) { 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_plugin_t *this_gen, 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(demux_plugin_t *this_gen) { _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 --git a/src/libsputext/xine_sputext_decoder.c b/src/libsputext/xine_sputext_decoder.c index 55082476f..5da948f4e 100644 --- a/src/libsputext/xine_sputext_decoder.c +++ b/src/libsputext/xine_sputext_decoder.c @@ -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_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; @@ -303,7 +301,7 @@ static void update_output_size (sputext_decoder_t *this) { } } -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 *c) 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(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) { @@ -395,7 +389,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; @@ -403,15 +397,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; @@ -547,15 +546,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 ) @@ -565,21 +558,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]); @@ -637,30 +629,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) { diff --git a/src/post/deinterlace/Makefile.am b/src/post/deinterlace/Makefile.am index d382a2e98..c9e09ee23 100644 --- a/src/post/deinterlace/Makefile.am +++ b/src/post/deinterlace/Makefile.am @@ -8,7 +8,7 @@ xinepost_LTLIBRARIES = xineplug_post_tvtime.la xineplug_post_tvtime_la_SOURCES = xine_plugin.c \ deinterlace.c pulldown.c speedy.c tvtime.c -xineplug_post_tvtime_la_LIBADD = $(XINE_LIB) $(LTLIBINTL) \ +xineplug_post_tvtime_la_LIBADD = $(XINE_LIB) $(LTLIBINTL) $(PTHREAD_LIBS) \ $(top_builddir)/src/post/deinterlace/plugins/libdeinterlaceplugins.la xineplug_post_tvtime_la_CFLAGS = $(VISIBILITY_FLAG) diff --git a/src/xine-engine/Makefile.am b/src/xine-engine/Makefile.am index 03176fb80..17dd96b10 100644 --- a/src/xine-engine/Makefile.am +++ b/src/xine-engine/Makefile.am @@ -1,8 +1,8 @@ include $(top_srcdir)/misc/Makefile.common include $(top_srcdir)/lib/Makefile.common -AM_CFLAGS = $(X_CFLAGS) $(FT2_CFLAGS) $(FONTCONFIG_CFLAGS) $(PTHREAD_CFLAGS) $(VISIBILITY_FLAG) -AM_CPPFLAGS = $(ZLIB_CPPFLAGS) $(PTHREAD_CFLAGS) -DXINE_LIBRARY_COMPILE +AM_CFLAGS = $(X_CFLAGS) $(FT2_CFLAGS) $(FONTCONFIG_CFLAGS) $(VISIBILITY_FLAG) +AM_CPPFLAGS = $(ZLIB_CPPFLAGS) -DXINE_LIBRARY_COMPILE LIBTOOL = $(SHELL) $(top_builddir)/libtool lib_LTLIBRARIES = libxine.la diff --git a/src/xine-engine/load_plugins.c b/src/xine-engine/load_plugins.c index a71092761..3d1c0e4a8 100644 --- a/src/xine-engine/load_plugins.c +++ b/src/xine-engine/load_plugins.c @@ -592,7 +592,7 @@ static void collect_plugins(xine_t *this, char *path){ #if defined(__hpux) if(!strstr(str, ".sl") #elif defined(__CYGWIN__) || defined(WIN32) - if(!strstr(str, ".dll") + if(!strstr(str, ".dll") || strstr(str, ".dll.a") #else if(!strstr(str, ".so") #endif diff --git a/src/xine-engine/post.c b/src/xine-engine/post.c index af791c1f7..aa182d627 100644 --- a/src/xine-engine/post.c +++ b/src/xine-engine/post.c @@ -33,7 +33,7 @@ void _x_post_init(post_plugin_t *post, int num_audio_inputs, int num_video_input post->input = xine_list_new(); post->output = xine_list_new(); post->xine_post.audio_input = calloc(num_audio_inputs + 1, sizeof(xine_audio_port_t *)); - post->xine_post.audio_input = calloc(num_video_inputs + 1, sizeof(xine_video_port_t *)); + post->xine_post.video_input = calloc(num_video_inputs + 1, sizeof(xine_video_port_t *)); } diff --git a/src/xine-utils/Makefile.am b/src/xine-utils/Makefile.am index a599f9b12..8a3d88ddd 100644 --- a/src/xine-utils/Makefile.am +++ b/src/xine-utils/Makefile.am @@ -12,7 +12,7 @@ endif endif AM_CFLAGS = $(X_CFLAGS) $(VISIBILITY_FLAG) -AM_CPPFLAGS= $(PTHREAD_CFLAGS) -DXINE_LIBRARY_COMPILE +AM_CPPFLAGS= -DXINE_LIBRARY_COMPILE libxineutils_la_SOURCES = $(pppc_files) \ cpu_accel.c \ diff --git a/src/xine-utils/utils.c b/src/xine-utils/utils.c index f533d69e5..57a92623c 100644 --- a/src/xine-utils/utils.c +++ b/src/xine-utils/utils.c @@ -393,11 +393,8 @@ const char *xine_get_pluginroot(void) { static char pluginroot[1024] = {0, }; if (!pluginroot[0]) { - char *sep, *sep2; - strcpy (pluginroot, xine_get_plugindir ()); - sep = strrchr (pluginroot, '/'); - sep2 = strrchr (pluginroot, '\\'); - *(sep < sep2 ? sep : sep2) = 0; + xine_get_rootdir(pluginroot, sizeof(pluginroot) - strlen(XINE_REL_PLUGINROOT) - 1); + strcat(pluginroot, XINE_DIRECTORY_SEPARATOR_STRING XINE_REL_PLUGINROOT); } return pluginroot; |