diff -up xine-lib-1.1.16.1/src/xine-engine/audio_out.c.gapless_rate_fix xine-lib-1.1.16.1/src/xine-engine/audio_out.c --- xine-lib-1.1.16.1/src/xine-engine/audio_out.c.gapless_rate_fix 2009-02-09 07:30:08.000000000 -0600 +++ xine-lib-1.1.16.1/src/xine-engine/audio_out.c 2009-02-09 07:30:08.000000000 -0600 @@ -1623,7 +1623,7 @@ static void ao_close(xine_audio_port_t * pthread_mutex_unlock(&this->streams_lock); /* close driver if no streams left */ - if (!ite && !this->grab_only && !stream->gapless_switch) { + if (!ite && !this->grab_only && !stream->keep_ao_driver_open) { xprintf (this->xine, XINE_VERBOSITY_DEBUG, "audio_out: no streams left, closing driver\n"); if (this->audio_loop_running) { diff -up xine-lib-1.1.16.1/src/xine-engine/video_decoder.c.gapless_rate_fix xine-lib-1.1.16.1/src/xine-engine/video_decoder.c --- xine-lib-1.1.16.1/src/xine-engine/video_decoder.c.gapless_rate_fix 2008-04-28 08:30:56.000000000 -0500 +++ xine-lib-1.1.16.1/src/xine-engine/video_decoder.c 2009-02-09 07:31:36.000000000 -0600 @@ -160,7 +160,7 @@ static void *video_decoder_loop (void *s running_ticket->release(running_ticket, 0); - if( !stream->gapless_switch ) + if( !(buf->decoder_flags & BUF_FLAG_GAPLESS_SW) ) stream->metronom->handle_video_discontinuity (stream->metronom, DISC_STREAMSTART, 0); diff -up xine-lib-1.1.16.1/src/xine-engine/xine.c.gapless_rate_fix xine-lib-1.1.16.1/src/xine-engine/xine.c --- xine-lib-1.1.16.1/src/xine-engine/xine.c.gapless_rate_fix 2009-02-09 07:30:08.000000000 -0600 +++ xine-lib-1.1.16.1/src/xine-engine/xine.c 2009-02-09 07:30:08.000000000 -0600 @@ -426,6 +426,7 @@ void xine_stop (xine_stream_t *stream) { static void close_internal (xine_stream_t *stream) { int i ; + int gapless_switch = stream->gapless_switch; if( stream->slave ) { xine_close( stream->slave ); @@ -436,7 +437,7 @@ static void close_internal (xine_stream_ } } - if( !stream->gapless_switch ) { + if( !gapless_switch ) { /* make sure that other threads cannot change the speed, especially pauseing the stream */ pthread_mutex_lock(&stream->speed_change_lock); stream->ignore_speed_change = 1; @@ -452,7 +453,7 @@ static void close_internal (xine_stream_ stop_internal( stream ); - if( !stream->gapless_switch ) { + if( !gapless_switch ) { if (stream->video_out) stream->video_out->set_property(stream->video_out, VO_PROP_DISCARD_FRAMES, 0); if (stream->audio_out) @@ -603,6 +604,7 @@ xine_stream_t *xine_stream_new (xine_t * stream->early_finish_event = 0; stream->delay_finish_event = 0; stream->gapless_switch = 0; + stream->keep_ao_driver_open = 0; stream->video_out = vo; if (vo) diff -up xine-lib-1.1.16.1/src/xine-engine/buffer.h.gapless_rate_fix xine-lib-1.1.16.1/src/xine-engine/buffer.h --- xine-lib-1.1.16.1/src/xine-engine/buffer.h.gapless_rate_fix 2009-01-10 19:25:34.000000000 -0600 +++ xine-lib-1.1.16.1/src/xine-engine/buffer.h 2009-02-09 07:30:08.000000000 -0600 @@ -378,6 +378,9 @@ struct buf_element_s { * decoder_info[2] carries denominator for display aspect ratio */ #define BUF_FLAG_ASPECT 0x0800 +/* represent the state of gapless_switch at the time buf was enqueued */ +#define BUF_FLAG_GAPLESS_SW 0x1000 + /* Special buffer types: * Sometimes there is a need to relay special information from a demuxer diff -up xine-lib-1.1.16.1/src/xine-engine/demux.c.gapless_rate_fix xine-lib-1.1.16.1/src/xine-engine/demux.c --- xine-lib-1.1.16.1/src/xine-engine/demux.c.gapless_rate_fix 2009-01-10 19:25:34.000000000 -0600 +++ xine-lib-1.1.16.1/src/xine-engine/demux.c 2009-02-09 07:30:08.000000000 -0600 @@ -228,15 +228,18 @@ void _x_demux_control_headers_done (xine void _x_demux_control_start( xine_stream_t *stream ) { buf_element_t *buf; + uint32_t flags = (stream->gapless_switch) ? BUF_FLAG_GAPLESS_SW : 0; pthread_mutex_lock(&stream->demux_mutex); buf = stream->video_fifo->buffer_pool_alloc (stream->video_fifo); buf->type = BUF_CONTROL_START; + buf->decoder_flags = flags; stream->video_fifo->put (stream->video_fifo, buf); buf = stream->audio_fifo->buffer_pool_alloc (stream->audio_fifo); buf->type = BUF_CONTROL_START; + buf->decoder_flags = flags; stream->audio_fifo->put (stream->audio_fifo, buf); pthread_mutex_unlock(&stream->demux_mutex); diff -up xine-lib-1.1.16.1/src/xine-engine/audio_decoder.c.gapless_rate_fix xine-lib-1.1.16.1/src/xine-engine/audio_decoder.c --- xine-lib-1.1.16.1/src/xine-engine/audio_decoder.c.gapless_rate_fix 2008-04-28 08:30:56.000000000 -0500 +++ xine-lib-1.1.16.1/src/xine-engine/audio_decoder.c 2009-02-09 07:30:08.000000000 -0600 @@ -89,16 +89,18 @@ static void *audio_decoder_loop (void *s if (stream->audio_decoder_plugin) { lprintf ("close old decoder\n"); - + + stream->keep_ao_driver_open = !!(buf->decoder_flags & BUF_FLAG_GAPLESS_SW); _x_free_audio_decoder (stream, stream->audio_decoder_plugin); stream->audio_decoder_plugin = NULL; stream->audio_track_map_entries = 0; stream->audio_type = 0; + stream->keep_ao_driver_open = 0; } running_ticket->release(running_ticket, 0); - if( !stream->gapless_switch ) + if( !(buf->decoder_flags & BUF_FLAG_GAPLESS_SW) ) stream->metronom->handle_audio_discontinuity (stream->metronom, DISC_STREAMSTART, 0); buftype_unknown = 0; diff -up xine-lib-1.1.16.1/src/xine-engine/xine_interface.c.gapless_rate_fix xine-lib-1.1.16.1/src/xine-engine/xine_interface.c --- xine-lib-1.1.16.1/src/xine-engine/xine_interface.c.gapless_rate_fix 2008-07-12 17:52:01.000000000 -0500 +++ xine-lib-1.1.16.1/src/xine-engine/xine_interface.c 2009-02-09 07:30:08.000000000 -0600 @@ -527,6 +527,9 @@ void xine_set_param (xine_stream_t *stre case XINE_PARAM_GAPLESS_SWITCH: stream->gapless_switch = !!value; + if( stream->gapless_switch && !stream->early_finish_event ) { + xprintf (stream->xine, XINE_VERBOSITY_DEBUG, "frontend possibly buggy: gapless_switch without early_finish_event\n"); + } break; default: diff -up xine-lib-1.1.16.1/src/xine-engine/xine_internal.h.gapless_rate_fix xine-lib-1.1.16.1/src/xine-engine/xine_internal.h --- xine-lib-1.1.16.1/src/xine-engine/xine_internal.h.gapless_rate_fix 2008-08-24 16:51:15.000000000 -0500 +++ xine-lib-1.1.16.1/src/xine-engine/xine_internal.h 2009-02-09 07:30:08.000000000 -0600 @@ -361,6 +361,7 @@ struct xine_stream_s { int early_finish_event; /* do not wait fifos get empty before sending event */ int gapless_switch; /* next stream switch will be gapless */ int delay_finish_event; /* delay event in 1/10 sec units. 0=>no delay, -1=>forever */ + int keep_ao_driver_open; #endif };