[vlc-devel] [PATCH 20/48] hls: Fix seeking

Hugo Beauzée-Luyssen beauze.h at gmail.com
Mon Jan 9 16:16:29 CET 2012


From: Luc Saillard <luc.saillard at sfr.com>

---
 modules/stream_filter/httplive.c |   25 +++++++++++++++++++++++--
 1 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/modules/stream_filter/httplive.c b/modules/stream_filter/httplive.c
index ff8bf33..5583393 100644
--- a/modules/stream_filter/httplive.c
+++ b/modules/stream_filter/httplive.c
@@ -2507,20 +2507,41 @@ static int segment_Seek(stream_t *s, const uint64_t pos)
 
         /* Wake up download thread */
         vlc_mutex_lock(&p_sys->download.lock_wait);
-        p_sys->download.seek = p_sys->playback.segment;
+        int seek_to_segment = p_sys->download.seek = p_sys->playback.segment;
         vlc_cond_signal(&p_sys->download.wait);
         vlc_mutex_unlock(&p_sys->download.lock_wait);
 
         /* Wait for download to be finished */
+
         vlc_mutex_lock(&p_sys->download.lock_wait);
         msg_Info(s, "seek to segment %d", p_sys->playback.segment);
         while (((p_sys->download.seek != -1) ||
                 (p_sys->download.segment - p_sys->playback.segment < 3)) &&
                 (p_sys->download.segment < (count - 6)))
         {
+             int i;
+             /* Download like Prefetch(), 3 segments in advance */
+             for (i = 0; i < 3; i++) {
+                     segment_t *segment = segment_GetSegment(hls, seek_to_segment + i);
+                     if (segment == NULL)
+                             goto end;
+                     vlc_mutex_lock(&segment->lock);
+                     if (segment->data == NULL)
+                     {
+                             /* The data is not ready, break, to sleep a little */
+                             vlc_mutex_unlock(&segment->lock);
+                             break;
+                     }
+                     vlc_mutex_unlock(&segment->lock);
+             }
+             if (i == 3)
+                     goto end;
+
             vlc_cond_wait(&p_sys->download.wait, &p_sys->download.lock_wait);
-            if (!vlc_object_alive(s) || s->b_error || p_sys->b_quit) break;
+            if (!vlc_object_alive(s) || s->b_error || p_sys->b_quit)
+                break;
         }
+end:
         vlc_mutex_unlock(&p_sys->download.lock_wait);
 
         return VLC_SUCCESS;
-- 
1.7.8.3




More information about the vlc-devel mailing list