[vlc-commits] stream: avoid seeking within the peek buffer

Rémi Denis-Courmont git at videolan.org
Wed Sep 2 21:54:13 CEST 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Sep  2 18:45:34 2015 +0300| [f3888615a1194cd95782e25b383110f7cac39fb4] | committer: Rémi Denis-Courmont

stream: avoid seeking within the peek buffer

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f3888615a1194cd95782e25b383110f7cac39fb4
---

 src/input/stream.c |   28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/src/input/stream.c b/src/input/stream.c
index 0c412c8..309e66f 100644
--- a/src/input/stream.c
+++ b/src/input/stream.c
@@ -449,6 +449,33 @@ int stream_Seek(stream_t *s, uint64_t offset)
 {
     stream_priv_t *priv = (stream_priv_t *)s;
 
+    block_t *peek = priv->peek;
+    if (peek != NULL)
+    {
+        if (priv->offset >= offset)
+        {
+            uint64_t fwd = priv->offset - offset;
+            if (fwd <= peek->i_buffer)
+            {   /* Seeking within the peek buffer */
+                peek->p_buffer += fwd;
+                peek->i_buffer -= fwd;
+
+                if (peek->i_buffer == 0)
+                {
+                    priv->peek = NULL;
+                    block_Release(peek);
+                }
+
+                return VLC_SUCCESS;
+            }
+        }
+    }
+    else
+    {
+        if (priv->offset == offset)
+            return VLC_SUCCESS; /* Nothing to do! */
+    }
+
     if (s->pf_seek == NULL)
         return VLC_EGENERIC;
 
@@ -458,7 +485,6 @@ int stream_Seek(stream_t *s, uint64_t offset)
 
     priv->offset = offset;
 
-    block_t *peek = priv->peek;
     if (peek != NULL)
     {
         priv->peek = NULL;



More information about the vlc-commits mailing list