]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/applehttp.c
ape: check that number of seektable entries is equal to number of frames
[ffmpeg] / libavformat / applehttp.c
index e35aaa8ac4c07832b1ad503e447904633eb6af42..56fb795ecf866d7e63b7645c1cfa90d09d9a072f 100644 (file)
@@ -2,20 +2,20 @@
  * Apple HTTP Live Streaming demuxer
  * Copyright (c) 2010 Martin Storsjo
  *
- * This file is part of FFmpeg.
+ * This file is part of Libav.
  *
- * FFmpeg is free software; you can redistribute it and/or
+ * Libav is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
- * FFmpeg is distributed in the hope that it will be useful,
+ * Libav is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
+ * License along with Libav; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
@@ -86,57 +86,6 @@ static int read_chomp_line(AVIOContext *s, char *buf, int maxlen)
     return len;
 }
 
-static void make_absolute_url(char *buf, int size, const char *base,
-                              const char *rel)
-{
-    char *sep;
-    /* Absolute path, relative to the current server */
-    if (base && strstr(base, "://") && rel[0] == '/') {
-        if (base != buf)
-            av_strlcpy(buf, base, size);
-        sep = strstr(buf, "://");
-        if (sep) {
-            sep += 3;
-            sep = strchr(sep, '/');
-            if (sep)
-                *sep = '\0';
-        }
-        av_strlcat(buf, rel, size);
-        return;
-    }
-    /* If rel actually is an absolute url, just copy it */
-    if (!base || strstr(rel, "://") || rel[0] == '/') {
-        av_strlcpy(buf, rel, size);
-        return;
-    }
-    if (base != buf)
-        av_strlcpy(buf, base, size);
-    /* Remove the file name from the base url */
-    sep = strrchr(buf, '/');
-    if (sep)
-        sep[1] = '\0';
-    else
-        buf[0] = '\0';
-    while (av_strstart(rel, "../", NULL) && sep) {
-        /* Remove the path delimiter at the end */
-        sep[0] = '\0';
-        sep = strrchr(buf, '/');
-        /* If the next directory name to pop off is "..", break here */
-        if (!strcmp(sep ? &sep[1] : buf, "..")) {
-            /* Readd the slash we just removed */
-            av_strlcat(buf, "/", size);
-            break;
-        }
-        /* Cut off the directory name */
-        if (sep)
-            sep[1] = '\0';
-        else
-            buf[0] = '\0';
-        rel += 3;
-    }
-    av_strlcat(buf, rel, size);
-}
-
 static void free_segment_list(struct variant *var)
 {
     int i;
@@ -154,7 +103,7 @@ static void free_variant_list(AppleHTTPContext *c)
         free_segment_list(var);
         av_free_packet(&var->pkt);
         if (var->pb)
-            url_fclose(var->pb);
+            avio_close(var->pb);
         if (var->ctx) {
             var->ctx->pb = NULL;
             av_close_input_file(var->ctx);
@@ -183,7 +132,7 @@ static struct variant *new_variant(AppleHTTPContext *c, int bandwidth,
         return NULL;
     reset_packet(&var->pkt);
     var->bandwidth = bandwidth;
-    make_absolute_url(var->url, sizeof(var->url), base, url);
+    ff_make_absolute_url(var->url, sizeof(var->url), base, url);
     dynarray_add(&c->variants, &c->n_variants, var);
     return var;
 }
@@ -211,7 +160,7 @@ static int parse_playlist(AppleHTTPContext *c, const char *url,
 
     if (!in) {
         close_in = 1;
-        if ((ret = url_fopen(&in, url, URL_RDONLY)) < 0)
+        if ((ret = avio_open(&in, url, URL_RDONLY)) < 0)
             return ret;
     }
 
@@ -224,7 +173,7 @@ static int parse_playlist(AppleHTTPContext *c, const char *url,
     if (var)
         free_segment_list(var);
     c->finished = 0;
-    while (!url_feof(in)) {
+    while (!in->eof_reached) {
         read_chomp_line(in, line, sizeof(line));
         if (av_strstart(line, "#EXT-X-STREAM-INF:", &ptr)) {
             struct variant_info info = {{0}};
@@ -274,7 +223,7 @@ static int parse_playlist(AppleHTTPContext *c, const char *url,
                     goto fail;
                 }
                 seg->duration = duration;
-                make_absolute_url(seg->url, sizeof(seg->url), url, line);
+                ff_make_absolute_url(seg->url, sizeof(seg->url), url, line);
                 dynarray_add(&var->segments, &var->n_segments, seg);
                 is_segment = 0;
             }
@@ -284,7 +233,7 @@ static int parse_playlist(AppleHTTPContext *c, const char *url,
 
 fail:
     if (close_in)
-        url_fclose(in);
+        avio_close(in);
     return ret;
 }
 
@@ -338,7 +287,7 @@ static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap)
         ret = av_open_input_file(&v->ctx, v->segments[0]->url, NULL, 0, NULL);
         if (ret < 0)
             goto fail;
-        url_fclose(v->ctx->pb);
+        avio_close(v->ctx->pb);
         v->ctx->pb = NULL;
         v->stream_offset = stream_offset;
         /* Create new AVStreams for each stream in this variant */
@@ -378,7 +327,7 @@ static int open_variant(AppleHTTPContext *c, struct variant *var, int skip)
     }
     if (c->cur_seq_no - var->start_seq_no >= var->n_segments)
         return c->finished ? AVERROR_EOF : 0;
-    ret = url_fopen(&var->pb,
+    ret = avio_open(&var->pb,
                     var->segments[c->cur_seq_no - var->start_seq_no]->url,
                     URL_RDONLY);
     if (ret < 0)
@@ -435,7 +384,7 @@ start:
                    "Closing variant stream %d, no longer needed\n", i);
             av_free_packet(&var->pkt);
             reset_packet(&var->pkt);
-            url_fclose(var->pb);
+            avio_close(var->pb);
             var->pb = NULL;
             changed = 1;
         } else if (!var->pb && var->needed) {
@@ -457,7 +406,7 @@ start:
         if (var->pb && !var->pkt.data) {
             ret = av_read_frame(var->ctx, &var->pkt);
             if (ret < 0) {
-                if (!url_feof(var->pb))
+                if (!var->pb->eof_reached)
                     return ret;
                 reset_packet(&var->pkt);
             }
@@ -484,7 +433,7 @@ start:
     for (i = 0; i < c->n_variants; i++) {
         struct variant *var = c->variants[i];
         if (var->pb) {
-            url_fclose(var->pb);
+            avio_close(var->pb);
             var->pb = NULL;
         }
     }
@@ -519,7 +468,7 @@ reload:
                c->max_start_seq - c->cur_seq_no);
         c->cur_seq_no = c->max_start_seq;
     }
-    /* If more segments exit, open the next one */
+    /* If more segments exist, open the next one */
     if (c->cur_seq_no < c->min_end_seq)
         goto start;
     /* We've reached the end of the playlists - return eof if this is a
@@ -528,7 +477,7 @@ reload:
         return AVERROR_EOF;
     while (av_gettime() - c->last_load_time < c->target_duration*1000000) {
         if (url_interrupt_cb())
-            return AVERROR(EINTR);
+            return AVERROR_EXIT;
         usleep(100*1000);
     }
     /* Enough time has elapsed since the last reload */
@@ -547,7 +496,8 @@ static int applehttp_read_seek(AVFormatContext *s, int stream_index,
                                int64_t timestamp, int flags)
 {
     AppleHTTPContext *c = s->priv_data;
-    int pos = 0, i;
+    int64_t pos = 0;
+    int i;
     struct variant *var = c->variants[0];
 
     if ((flags & AVSEEK_FLAG_BYTE) || !c->finished)
@@ -558,7 +508,7 @@ static int applehttp_read_seek(AVFormatContext *s, int stream_index,
     for (i = 0; i < c->n_variants; i++) {
         struct variant *var = c->variants[i];
         if (var->pb) {
-            url_fclose(var->pb);
+            avio_close(var->pb);
             var->pb = NULL;
         }
         av_free_packet(&var->pkt);