diff options
Diffstat (limited to 'src/xine-engine')
-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 |
3 files changed, 76 insertions, 2 deletions
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; |