diff options
author | František Dvořák <valtri@users.sourceforge.net> | 2004-04-07 18:10:20 +0000 |
---|---|---|
committer | František Dvořák <valtri@users.sourceforge.net> | 2004-04-07 18:10:20 +0000 |
commit | ef959e21c2fb8688ff2bfcf7758e9323be8b65f7 (patch) | |
tree | 927f4649c5e410adcf7cc8cadf26148befcf15f2 | |
parent | 25bbdcdc14a1a470c405882368ff9466ba418b6e (diff) | |
download | xine-lib-ef959e21c2fb8688ff2bfcf7758e9323be8b65f7.tar.gz xine-lib-ef959e21c2fb8688ff2bfcf7758e9323be8b65f7.tar.bz2 |
Michael's patch for improving playback with subtitles, fix the long seeking.
CVS patchset: 6342
CVS date: 2004/04/07 18:10:20
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | src/libsputext/xine_decoder.c | 50 | ||||
-rw-r--r-- | src/xine-engine/demux.c | 12 | ||||
-rw-r--r-- | src/xine-engine/spu_decoder.h | 27 | ||||
-rw-r--r-- | src/xine-engine/video_decoder.c | 39 |
5 files changed, 95 insertions, 34 deletions
@@ -10,6 +10,7 @@ xine-lib (1-rc3c) * preparing for future MinGW port * improved network buffer management policy. * asf/mmst/mmsh proper support for "media changing" command. + * improve playback with subtitles, fix the seeking xine-lib (1-rc3b) * fix SDL plugin that was broken in rc3 diff --git a/src/libsputext/xine_decoder.c b/src/libsputext/xine_decoder.c index 40d853f6f..c63eca435 100644 --- a/src/libsputext/xine_decoder.c +++ b/src/libsputext/xine_decoder.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: xine_decoder.c,v 1.78 2004/03/13 13:59:19 mroi Exp $ + * $Id: xine_decoder.c,v 1.79 2004/04/07 18:10:20 valtri Exp $ * */ @@ -36,9 +36,6 @@ #define LOG */ -/* FIXME: evil, evil, evil! */ -#define XINE_ENGINE_INTERNAL - #include "buffer.h" #include "xine_internal.h" #include "xineutils.h" @@ -512,14 +509,13 @@ static void spudec_decode_data (spu_decoder_t *this_gen, buf_element_t *buf) { diff = start - extra_info.frame_number; - /* draw it if less than 1/2 second left */ - if( diff < 90000/2 / this->img_duration ) { - start_vpts = extra_info.vpts + diff * this->img_duration; - end_vpts = start_vpts + (end-start) * this->img_duration; - - draw_subtitle(this, start_vpts, end_vpts); - return; - } + start_vpts = extra_info.vpts + diff * this->img_duration; + end_vpts = start_vpts + (end-start) * this->img_duration; + + _x_spu_decoder_sleep(this->stream, start_vpts); + draw_subtitle(this, start_vpts, end_vpts); + + return; } else { @@ -540,31 +536,21 @@ static void spudec_decode_data (spu_decoder_t *this_gen, buf_element_t *buf) { diff = start - extra_info.input_time; - /* draw it if less than 1/2 second left */ - if( diff < 500 || this->ogm ) { - start_vpts = extra_info.vpts + diff * 90; - end_vpts = start_vpts + (end-start) * 90; - - draw_subtitle(this, start_vpts, end_vpts); - return; - } + start_vpts = extra_info.vpts + diff * 90; + end_vpts = start_vpts + (end-start) * 90; + + _x_spu_decoder_sleep(this->stream, start_vpts); + draw_subtitle(this, start_vpts, end_vpts); + + return; } } } - /* we may never block on ogm mode because we are on the same thread - * as the video decoder. therefore nothing will possibly happen - * (like frames being displayed) if we hang here doing nothing. - * it is possible, but unlikely, that the very first ogm subtitle - * gets dropped because of the following return. - */ - if( this->ogm ) + if (_x_spu_decoder_sleep(this->stream, 0)) + xine_usec_sleep (50000); + else return; - - if (this->class->xine->port_ticket->ticket_revoked) - this->class->xine->port_ticket->renew(this->class->xine->port_ticket, 0); - xine_usec_sleep (50000); - } } diff --git a/src/xine-engine/demux.c b/src/xine-engine/demux.c index 716b4e974..0708d3e51 100644 --- a/src/xine-engine/demux.c +++ b/src/xine-engine/demux.c @@ -20,7 +20,7 @@ * Demuxer helper functions * hide some xine engine details from demuxers and reduce code duplication * - * $Id: demux.c,v 1.47 2004/03/03 20:09:16 mroi Exp $ + * $Id: demux.c,v 1.48 2004/04/07 18:10:20 valtri Exp $ */ @@ -93,6 +93,11 @@ void _x_demux_flush_engine (xine_stream_t *stream) { _x_demux_control_headers_done (stream); if (stream->video_out) { + video_overlay_manager_t *ovl = stream->video_out->get_overlay_manager(stream->video_out); + ovl->flush_events(ovl); + } + + if (stream->video_out) { stream->video_out->flush(stream->video_out); stream->video_out->set_property(stream->video_out, VO_PROP_DISCARD_FRAMES, 0); } @@ -144,6 +149,9 @@ void _x_demux_control_headers_done (xine_stream_t *stream) { header_count_audio = 0; } + /* we use demux_action_pending to wake up sleeping spu decoders */ + stream->demux_action_pending = 1; + buf = stream->video_fifo->buffer_pool_alloc (stream->video_fifo); buf->type = BUF_CONTROL_HEADERS_DONE; stream->video_fifo->put (stream->video_fifo, buf); @@ -168,6 +176,8 @@ void _x_demux_control_headers_done (xine_stream_t *stream) { pthread_cond_timedwait (&stream->counter_changed, &stream->counter_lock, &ts); } + stream->demux_action_pending = 0; + lprintf ("headers processed.\n"); pthread_mutex_unlock (&stream->counter_lock); diff --git a/src/xine-engine/spu_decoder.h b/src/xine-engine/spu_decoder.h index d4bd691f1..24afd745b 100644 --- a/src/xine-engine/spu_decoder.h +++ b/src/xine-engine/spu_decoder.h @@ -114,4 +114,31 @@ struct spu_decoder_s { void *node; /* used by plugin loader */ }; + +/* SPU decoders differ from video and audio decoders in one significant + * way: unlike audio and video, SPU streams are not continuous; + * this results in another difference, programmers have to consider: + * while both audio and video decoders are automatically blocked in + * their get_buffer()/get_frame() methods when the output cannot take + * any more data, this does not work for SPU, because it could take + * minutes before the next free slot becomes available and we must not + * block the decoder thread for that long; + * therefore, we provide a convenience function for SPU decoders which + * implements a wait until a timestamp sufficiently close to the VPTS + * of the next SPU is reached, but the waiting will end before that, + * if some outside condition requires us to release the decoder thread + * to other tasks; + * if this functions returns with 1, noone needs the decoder thread and + * you may continue waiting; if it returns 0, finish whatever you are + * doing and return; + * the usual pattern for SPU decoders is this: + * + * do { + * spu = prepare_spu(); + * int thread_vacant = _x_spu_decoder_sleep(this->stream, spu->vpts); + * int success = process_spu(spu); + * } while (!success && thread_vacant); + */ +int _x_spu_decoder_sleep(xine_stream_t *, int64_t next_spu_vpts); + #endif /* HAVE_SPUDEC_H */ diff --git a/src/xine-engine/video_decoder.c b/src/xine-engine/video_decoder.c index e02838f48..a783cc497 100644 --- a/src/xine-engine/video_decoder.c +++ b/src/xine-engine/video_decoder.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: video_decoder.c,v 1.145 2004/03/28 19:51:56 mroi Exp $ + * $Id: video_decoder.c,v 1.146 2004/04/07 18:10:21 valtri Exp $ * */ @@ -58,6 +58,43 @@ static void update_spu_decoder (xine_stream_t *stream, int type) { return ; } +int _x_spu_decoder_sleep(xine_stream_t *stream, int64_t next_spu_vpts) +{ + int64_t time, wait; + int thread_vacant = 1; + + /* we wait until one second before the next SPU is due */ + next_spu_vpts -= 90000; + + do { + if (next_spu_vpts) + time = stream->xine->clock->get_current_time(stream->xine->clock); + else + time = 0; + + /* wait in pieces of one half second */ + if (next_spu_vpts - time < 90000/2) + wait = next_spu_vpts - time; + else + wait = 90000/2; + + if (wait > 0) xine_usec_sleep(wait * 11); + + if (stream->xine->port_ticket->ticket_revoked) + stream->xine->port_ticket->renew(stream->xine->port_ticket, 0); + + /* we have to return if video out calls for the decoder */ + if (stream->video_fifo->first) + thread_vacant = (stream->video_fifo->first->type != BUF_CONTROL_FLUSH_DECODER); + /* we have to return if the demuxer needs us to release a buffer */ + if (thread_vacant) + thread_vacant = !stream->demux_action_pending; + + } while (wait == 90000/2 && thread_vacant); + + return thread_vacant; +} + static void *video_decoder_loop (void *stream_gen) { buf_element_t *buf; |