[vlc-commits] demux: mkv: don't flush buffers on failed seek
Francois Cartegnie
git at videolan.org
Tue Apr 4 14:17:29 CEST 2017
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Apr 4 14:08:04 2017 +0200| [a61302e11446cc2b035dc1ffee1f4f1f7ab20896] | committer: Francois Cartegnie
demux: mkv: don't flush buffers on failed seek
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a61302e11446cc2b035dc1ffee1f4f1f7ab20896
---
modules/demux/mkv/matroska_segment.cpp | 19 +++++++-----
modules/demux/mkv/matroska_segment.hpp | 4 +--
modules/demux/mkv/mkv.cpp | 54 ++++++++++++++++++++--------------
modules/demux/mkv/virtual_segment.cpp | 8 +++--
modules/demux/mkv/virtual_segment.hpp | 2 +-
5 files changed, 52 insertions(+), 35 deletions(-)
diff --git a/modules/demux/mkv/matroska_segment.cpp b/modules/demux/mkv/matroska_segment.cpp
index c486dd0..415f77f 100644
--- a/modules/demux/mkv/matroska_segment.cpp
+++ b/modules/demux/mkv/matroska_segment.cpp
@@ -796,15 +796,18 @@ bool matroska_segment_c::LoadSeekHeadItem( const EbmlCallbacks & ClassInfos, int
return true;
}
-void matroska_segment_c::FastSeek( mtime_t i_mk_date, mtime_t i_mk_time_offset )
+bool matroska_segment_c::FastSeek( mtime_t i_mk_date, mtime_t i_mk_time_offset )
{
- Seek( i_mk_date, i_mk_time_offset );
-
- sys.i_start_pts = sys.i_pts;
- es_out_Control( sys.demuxer.out, ES_OUT_SET_NEXT_DISPLAY_TIME, sys.i_start_pts );
+ if( Seek( i_mk_date, i_mk_time_offset ) )
+ {
+ sys.i_start_pts = sys.i_pts;
+ es_out_Control( sys.demuxer.out, ES_OUT_SET_NEXT_DISPLAY_TIME, sys.i_start_pts );
+ return true;
+ }
+ return false;
}
-void matroska_segment_c::Seek( mtime_t i_absolute_mk_date, mtime_t i_mk_time_offset )
+bool matroska_segment_c::Seek( mtime_t i_absolute_mk_date, mtime_t i_mk_time_offset )
{
SegmentSeeker::tracks_seekpoint_t seekpoints;
@@ -830,7 +833,7 @@ void matroska_segment_c::Seek( mtime_t i_absolute_mk_date, mtime_t i_mk_time_off
catch( std::exception const& e )
{
msg_Err( &sys.demuxer, "error during seek: \"%s\", aborting!", e.what() );
- return;
+ return false;
}
// initialize seek information in order to set up playback //
@@ -869,6 +872,8 @@ void matroska_segment_c::Seek( mtime_t i_absolute_mk_date, mtime_t i_mk_time_off
msg_Dbg( &sys.demuxer, "seek: preroll{ start-pts: %" PRId64 ", start-fpos: %" PRIu64 "} ",
sys.i_pts, i_seek_position );
+
+ return true;
}
diff --git a/modules/demux/mkv/matroska_segment.hpp b/modules/demux/mkv/matroska_segment.hpp
index edf3600..062ab89 100644
--- a/modules/demux/mkv/matroska_segment.hpp
+++ b/modules/demux/mkv/matroska_segment.hpp
@@ -138,8 +138,8 @@ public:
bool PreloadClusters( uint64 i_cluster_position );
void InformationCreate();
- void FastSeek( mtime_t i_mk_date, mtime_t i_mk_time_offset );
- void Seek( mtime_t i_mk_date, mtime_t i_mk_time_offset );
+ bool FastSeek( mtime_t i_mk_date, mtime_t i_mk_time_offset );
+ bool Seek( mtime_t i_mk_date, mtime_t i_mk_time_offset );
int BlockGet( KaxBlock * &, KaxSimpleBlock * &, bool *, bool *, int64_t *);
diff --git a/modules/demux/mkv/mkv.cpp b/modules/demux/mkv/mkv.cpp
index 8fc2132..d7d969a 100644
--- a/modules/demux/mkv/mkv.cpp
+++ b/modules/demux/mkv/mkv.cpp
@@ -83,7 +83,7 @@ struct demux_sys_t;
static int Demux ( demux_t * );
static int Control( demux_t *, int, va_list );
-static void Seek ( demux_t *, mtime_t i_mk_date, double f_percent, virtual_chapter_c *p_vchapter, bool b_precise = true );
+static int Seek ( demux_t *, mtime_t i_mk_date, double f_percent, virtual_chapter_c *p_vchapter, bool b_precise = true );
/*****************************************************************************
* Open: initializes matroska demux structures
@@ -355,8 +355,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
{
f = va_arg( args, double );
b = va_arg( args, int ); /* precise? */
- Seek( p_demux, -1, f, NULL, b );
- return VLC_SUCCESS;
+ return Seek( p_demux, -1, f, NULL, b );
}
return VLC_EGENERIC;
@@ -385,15 +384,24 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
i_idx = va_arg( args, int );
if(i_idx < p_sys->titles.size() && p_sys->titles[i_idx]->i_seekpoint)
{
+ const int i_edition = p_sys->p_current_vsegment->i_current_edition;
+ const int i_title = p_sys->i_current_title;
p_sys->p_current_vsegment->i_current_edition = i_idx;
p_sys->i_current_title = i_idx;
-
- Seek( p_demux, static_cast<int64_t>( p_sys->titles[i_idx]->seekpoint[0]->i_time_offset ), -1, NULL);
- p_demux->info.i_update |= INPUT_UPDATE_SEEKPOINT|INPUT_UPDATE_TITLE;
- p_demux->info.i_seekpoint = 0;
- p_demux->info.i_title = i_idx;
- p_sys->f_duration = (float) p_sys->titles[i_idx]->i_length / 1000.f;
- return VLC_SUCCESS;
+ if( VLC_SUCCESS ==
+ Seek( p_demux, static_cast<int64_t>( p_sys->titles[i_idx]->seekpoint[0]->i_time_offset ), -1, NULL) )
+ {
+ p_demux->info.i_update |= INPUT_UPDATE_SEEKPOINT|INPUT_UPDATE_TITLE;
+ p_demux->info.i_seekpoint = 0;
+ p_demux->info.i_title = i_idx;
+ p_sys->f_duration = (float) p_sys->titles[i_idx]->i_length / 1000.f;
+ return VLC_SUCCESS;
+ }
+ else
+ {
+ p_sys->p_current_vsegment->i_current_edition = i_edition;
+ p_sys->i_current_title = i_title;
+ }
}
return VLC_EGENERIC;
@@ -403,10 +411,13 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
// TODO change the way it works with the << & >> buttons on the UI (+1/-1 instead of a number)
if( p_sys->titles.size() && i_skp < p_sys->titles[p_sys->i_current_title]->i_seekpoint)
{
- Seek( p_demux, static_cast<int64_t>( p_sys->titles[p_sys->i_current_title]->seekpoint[i_skp]->i_time_offset ), -1, NULL);
- p_demux->info.i_update |= INPUT_UPDATE_SEEKPOINT;
- p_demux->info.i_seekpoint = i_skp;
- return VLC_SUCCESS;
+ int i_ret = Seek( p_demux, static_cast<int64_t>( p_sys->titles[p_sys->i_current_title]->seekpoint[i_skp]->i_time_offset ), -1, NULL);
+ if( i_ret == VLC_SUCCESS )
+ {
+ p_demux->info.i_update |= INPUT_UPDATE_SEEKPOINT;
+ p_demux->info.i_seekpoint = i_skp;
+ }
+ return i_ret;
}
return VLC_EGENERIC;
@@ -435,15 +446,14 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
i64 = va_arg( args, int64_t );
b = va_arg( args, int ); /* precise? */
msg_Dbg(p_demux,"SET_TIME to %" PRId64, i64 );
- Seek( p_demux, i64, -1, NULL, b );
- return VLC_SUCCESS;
+ return Seek( p_demux, i64, -1, NULL, b );
default:
return VLC_EGENERIC;
}
}
/* Seek */
-static void Seek( demux_t *p_demux, mtime_t i_mk_date, double f_percent, virtual_chapter_c *p_vchapter, bool b_precise )
+static int Seek( demux_t *p_demux, mtime_t i_mk_date, double f_percent, virtual_chapter_c *p_vchapter, bool b_precise )
{
demux_sys_t *p_sys = p_demux->p_sys;
virtual_segment_c *p_vsegment = p_sys->p_current_vsegment;
@@ -455,22 +465,22 @@ static void Seek( demux_t *p_demux, mtime_t i_mk_date, double f_percent, virtual
if( i_mk_date < 0 && f_percent < 0 )
{
msg_Warn( p_demux, "cannot seek nowhere!" );
- return;
+ return VLC_EGENERIC;
}
if( f_percent > 1.0 )
{
msg_Warn( p_demux, "cannot seek so far!" );
- return;
+ return VLC_EGENERIC;
}
if( p_sys->f_duration < 0 )
{
msg_Warn( p_demux, "cannot seek without duration!");
- return;
+ return VLC_EGENERIC;
}
if( !p_segment )
{
msg_Warn( p_demux, "cannot seek without valid segment position");
- return;
+ return VLC_EGENERIC;
}
/* seek without index or without date */
@@ -478,7 +488,7 @@ static void Seek( demux_t *p_demux, mtime_t i_mk_date, double f_percent, virtual
{
i_mk_date = int64_t( f_percent * p_sys->f_duration * 1000.0 );
}
- p_vsegment->Seek( *p_demux, i_mk_date, p_vchapter, b_precise );
+ return p_vsegment->Seek( *p_demux, i_mk_date, p_vchapter, b_precise ) ? VLC_SUCCESS : VLC_EGENERIC;
}
/* Needed by matroska_segment::Seek() and Seek */
diff --git a/modules/demux/mkv/virtual_segment.cpp b/modules/demux/mkv/virtual_segment.cpp
index 6d1863b..ee9a385 100644
--- a/modules/demux/mkv/virtual_segment.cpp
+++ b/modules/demux/mkv/virtual_segment.cpp
@@ -513,7 +513,7 @@ bool virtual_chapter_c::EnterAndLeave( virtual_chapter_c *p_leaving_vchapter, bo
return p_chapter->EnterAndLeave( p_leaving_vchapter->p_chapter, b_enter );
}
-void virtual_segment_c::Seek( demux_t & demuxer, mtime_t i_mk_date,
+bool virtual_segment_c::Seek( demux_t & demuxer, mtime_t i_mk_date,
virtual_chapter_c *p_vchapter, bool b_precise )
{
demux_sys_t *p_sys = demuxer.p_sys;
@@ -545,10 +545,11 @@ void virtual_segment_c::Seek( demux_t & demuxer, mtime_t i_mk_date,
msg_Dbg( &demuxer, "SWITCH CHAPTER uid=%" PRId64, p_vchapter->p_chapter ? p_vchapter->p_chapter->i_uid : 0 );
p_current_vchapter = p_vchapter;
p_sys->PreparePlayback( *this, i_mk_date );
+ return true;
}
else
{
- typedef void( matroska_segment_c::* seek_callback_t )( mtime_t, mtime_t );
+ typedef bool( matroska_segment_c::* seek_callback_t )( mtime_t, mtime_t );
seek_callback_t pf_seek = &matroska_segment_c::Seek;
@@ -557,9 +558,10 @@ void virtual_segment_c::Seek( demux_t & demuxer, mtime_t i_mk_date,
p_current_vchapter = p_vchapter;
- ( p_current_vchapter->segment.*pf_seek )( i_mk_date, i_mk_time_offset );
+ return ( p_current_vchapter->segment.*pf_seek )( i_mk_date, i_mk_time_offset );
}
}
+ return false;
}
virtual_chapter_c * virtual_chapter_c::FindChapter( int64_t i_find_uid )
diff --git a/modules/demux/mkv/virtual_segment.hpp b/modules/demux/mkv/virtual_segment.hpp
index d4e3510..cd9dd2a 100644
--- a/modules/demux/mkv/virtual_segment.hpp
+++ b/modules/demux/mkv/virtual_segment.hpp
@@ -160,7 +160,7 @@ public:
virtual_chapter_c * FindChapter( int64_t i_find_uid );
bool UpdateCurrentToChapter( demux_t & demux );
- void Seek( demux_t & demuxer, mtime_t i_mk_date, virtual_chapter_c *p_vchapter, bool b_precise = true );
+ bool Seek( demux_t & demuxer, mtime_t i_mk_date, virtual_chapter_c *p_vchapter, bool b_precise = true );
private:
void KeepTrackSelection( matroska_segment_c & old, matroska_segment_c & next );
};
More information about the vlc-commits
mailing list