[FFmpeg-devel] [PATCH 1/2] applehttp: Implement seeking in the protocol handler

Martin Storsjö martin
Mon Mar 7 14:18:14 CET 2011


---
 libavformat/applehttpproto.c |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/libavformat/applehttpproto.c b/libavformat/applehttpproto.c
index 471f94b..8bd5244 100644
--- a/libavformat/applehttpproto.c
+++ b/libavformat/applehttpproto.c
@@ -347,6 +347,29 @@ static int applehttp_close(URLContext *h)
     return 0;
 }
 
+static int64_t applehttp_read_seek(URLContext *h, int stream_index,
+                                   int64_t timestamp, int flags)
+{
+    AppleHTTPContext *s = h->priv_data;
+    int pos = 0, i;
+    if ((flags & AVSEEK_FLAG_BYTE) || !s->finished)
+        return AVERROR(ENOSYS);
+    url_close(s->seg_hd);
+    s->seg_hd = NULL;
+    timestamp = av_rescale_rnd(timestamp, 1,
+                               stream_index >= 0 ? 90000 : AV_TIME_BASE,
+                               flags & AVSEEK_FLAG_BACKWARD ?
+                               AV_ROUND_DOWN : AV_ROUND_UP);
+    for (i = 0; i < s->n_segments; i++) {
+        if (timestamp >= pos && timestamp < pos + s->segments[i]->duration) {
+            s->cur_seq_no = s->start_seq_no + i;
+            return pos * AV_TIME_BASE;
+        }
+        pos += s->segments[i]->duration;
+    }
+    return AVERROR(EIO);
+}
+
 URLProtocol ff_applehttp_protocol = {
     "applehttp",
     applehttp_open,
@@ -354,5 +377,6 @@ URLProtocol ff_applehttp_protocol = {
     NULL, /* write */
     NULL, /* seek */
     applehttp_close,
+    .url_read_seek = applehttp_read_seek,
     .flags = URL_PROTOCOL_FLAG_NESTED_SCHEME,
 };
-- 
1.7.3.1




More information about the ffmpeg-devel mailing list