[vlc-devel] [PATCH] Fix TTA inaccurate seek

vincent.163 at outlook.com vincent.163 at outlook.com
Thu Mar 12 05:49:29 CET 2020


From: vincent163 <vincent.163 at outlook.com>

---
 modules/demux/tta.c | 37 +++++++++++++------------------------
 1 file changed, 13 insertions(+), 24 deletions(-)

diff --git a/modules/demux/tta.c b/modules/demux/tta.c
index 81c162cd25..db2cfbc629 100644
--- a/modules/demux/tta.c
+++ b/modules/demux/tta.c
@@ -234,34 +234,23 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
 
         case DEMUX_GET_POSITION:
             pf = va_arg( args, double * );
-            i64 = stream_Size( p_demux->s ) - p_sys->i_start;
-            if( i64 > 0 )
-            {
-                *pf = (double)(vlc_stream_Tell( p_demux->s ) - p_sys->i_start )/ (double)i64;
-            }
-            else
-            {
-                *pf = 0.0;
-            }
+			*pf = (double)p_sys->i_currentframe / (double)p_sys->i_totalframes;
             return VLC_SUCCESS;
 
         case DEMUX_SET_POSITION:
+		{
             f = va_arg( args, double );
-            i64 = (int64_t)(f * (stream_Size( p_demux->s ) - p_sys->i_start));
-            if( i64 > 0 )
-            {
-                int64_t tmp = 0;
-                uint32_t i;
-                for( i=0; i < p_sys->i_totalframes && tmp+p_sys->pi_seektable[i] < i64; i++)
-                {
-                    tmp += p_sys->pi_seektable[i];
-                }
-                if( vlc_stream_Seek( p_demux->s, tmp+p_sys->i_start ) )
-                    return VLC_EGENERIC;
-                p_sys->i_currentframe = i;
-                return VLC_SUCCESS;
-            }
-            return VLC_EGENERIC;
+			uint32_t j = (uint32_t)(f * p_sys->i_totalframes);
+			i64 = p_sys->i_start;
+			for( uint32_t i=0; i<j; i++)
+			{
+				i64 += p_sys->pi_seektable[i];
+			}
+			if( vlc_stream_Seek( p_demux->s, i64 ) )
+				return VLC_EGENERIC;
+			p_sys->i_currentframe = j;
+			return VLC_SUCCESS;
+		}
 
         case DEMUX_GET_LENGTH:
             *va_arg( args, vlc_tick_t * ) =
-- 
2.17.1



More information about the vlc-devel mailing list