]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/applehttpproto.c
Merge remote-tracking branch 'qatar/master'
[ffmpeg] / libavformat / applehttpproto.c
index 1476ea28f2ca0fa6f6c85ca5ef38d285e29bb218..8295ccc5f5ea6a0615512aa2d88ddd99270f59cf 100644 (file)
@@ -2,20 +2,20 @@
  * Apple HTTP Live Streaming Protocol Handler
  * Copyright (c) 2010 Martin Storsjo
  *
- * This file is part of Libav.
+ * This file is part of FFmpeg.
  *
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
  *
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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 Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
@@ -114,7 +114,8 @@ static int parse_playlist(URLContext *h, const char *url)
     char line[1024];
     const char *ptr;
 
-    if ((ret = avio_open(&in, url, AVIO_FLAG_READ)) < 0)
+    if ((ret = avio_open2(&in, url, AVIO_FLAG_READ,
+                          &h->interrupt_callback, NULL)) < 0)
         return ret;
 
     read_chomp_line(in, line, sizeof(line));
@@ -123,7 +124,7 @@ static int parse_playlist(URLContext *h, const char *url)
 
     free_segment_list(s);
     s->finished = 0;
-    while (!in->eof_reached) {
+    while (!url_feof(in)) {
         read_chomp_line(in, line, sizeof(line));
         if (av_strstart(line, "#EXT-X-STREAM-INF:", &ptr)) {
             struct variant_info info = {{0}};
@@ -173,19 +174,25 @@ fail:
     return ret;
 }
 
+static int applehttp_close(URLContext *h)
+{
+    AppleHTTPContext *s = h->priv_data;
+
+    free_segment_list(s);
+    free_variant_list(s);
+    ffurl_close(s->seg_hd);
+    return 0;
+}
+
 static int applehttp_open(URLContext *h, const char *uri, int flags)
 {
-    AppleHTTPContext *s;
+    AppleHTTPContext *s = h->priv_data;
     int ret, i;
     const char *nested_url;
 
     if (flags & AVIO_FLAG_WRITE)
         return AVERROR(ENOSYS);
 
-    s = av_mallocz(sizeof(AppleHTTPContext));
-    if (!s)
-        return AVERROR(ENOMEM);
-    h->priv_data = s;
     h->is_streamed = 1;
 
     if (av_strstart(uri, "applehttp+", &nested_url)) {
@@ -228,7 +235,7 @@ static int applehttp_open(URLContext *h, const char *uri, int flags)
     return 0;
 
 fail:
-    av_free(s);
+    applehttp_close(h);
     return ret;
 }
 
@@ -274,7 +281,8 @@ retry:
     }
     url = s->segments[s->cur_seq_no - s->start_seq_no]->url,
     av_log(h, AV_LOG_DEBUG, "opening %s\n", url);
-    ret = ffurl_open(&s->seg_hd, url, AVIO_FLAG_READ);
+    ret = ffurl_open(&s->seg_hd, url, AVIO_FLAG_READ,
+                     &h->interrupt_callback, NULL);
     if (ret < 0) {
         if (ff_check_interrupt(&h->interrupt_callback))
             return AVERROR_EXIT;
@@ -285,21 +293,11 @@ retry:
     goto start;
 }
 
-static int applehttp_close(URLContext *h)
-{
-    AppleHTTPContext *s = h->priv_data;
-
-    free_segment_list(s);
-    free_variant_list(s);
-    ffurl_close(s->seg_hd);
-    av_free(s);
-    return 0;
-}
-
 URLProtocol ff_applehttp_protocol = {
-    .name      = "applehttp",
-    .url_open  = applehttp_open,
-    .url_read  = applehttp_read,
-    .url_close = applehttp_close,
-    .flags     = URL_PROTOCOL_FLAG_NESTED_SCHEME,
+    .name           = "applehttp",
+    .url_open       = applehttp_open,
+    .url_read       = applehttp_read,
+    .url_close      = applehttp_close,
+    .flags          = URL_PROTOCOL_FLAG_NESTED_SCHEME,
+    .priv_data_size = sizeof(AppleHTTPContext),
 };