]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/hlsproto.c
riff: Factor out WAVEFORMATEX parsing
[ffmpeg] / libavformat / hlsproto.c
index 244f2703987db1cc8638cdb4bdee120fbe0e91b5..72b6c7236f7ca312c297b7be53586dbb7218ad16 100644 (file)
  */
 
 #include "libavutil/avstring.h"
+#include "libavutil/time.h"
 #include "avformat.h"
 #include "internal.h"
 #include "url.h"
 #include "version.h"
-#include <unistd.h>
 
 /*
  * An apple http stream consists of a playlist with media segment files,
  * played sequentially. There may be several playlists with the same
  * video content, in different bandwidth variants, that are played in
- * parallel (preferrably only one bandwidth variant at a time). In this case,
+ * parallel (preferably only one bandwidth variant at a time). In this case,
  * the user supplied the url to a main playlist that only lists the variant
  * playlists.
  *
@@ -54,7 +54,7 @@ struct variant {
     char url[MAX_URL_SIZE];
 };
 
-typedef struct AppleHTTPContext {
+typedef struct HLSContext {
     char playlisturl[MAX_URL_SIZE];
     int target_duration;
     int start_seq_no;
@@ -66,17 +66,17 @@ typedef struct AppleHTTPContext {
     int cur_seq_no;
     URLContext *seg_hd;
     int64_t last_load_time;
-} AppleHTTPContext;
+} HLSContext;
 
 static int read_chomp_line(AVIOContext *s, char *buf, int maxlen)
 {
     int len = ff_get_line(s, buf, maxlen);
-    while (len > 0 && isspace(buf[len - 1]))
+    while (len > 0 && av_isspace(buf[len - 1]))
         buf[--len] = '\0';
     return len;
 }
 
-static void free_segment_list(AppleHTTPContext *s)
+static void free_segment_list(HLSContext *s)
 {
     int i;
     for (i = 0; i < s->n_segments; i++)
@@ -85,7 +85,7 @@ static void free_segment_list(AppleHTTPContext *s)
     s->n_segments = 0;
 }
 
-static void free_variant_list(AppleHTTPContext *s)
+static void free_variant_list(HLSContext *s)
 {
     int i;
     for (i = 0; i < s->n_variants; i++)
@@ -109,7 +109,7 @@ static void handle_variant_args(struct variant_info *info, const char *key,
 
 static int parse_playlist(URLContext *h, const char *url)
 {
-    AppleHTTPContext *s = h->priv_data;
+    HLSContext *s = h->priv_data;
     AVIOContext *in;
     int ret = 0, duration = 0, is_segment = 0, is_variant = 0, bandwidth = 0;
     char line[1024];
@@ -175,9 +175,9 @@ fail:
     return ret;
 }
 
-static int applehttp_close(URLContext *h)
+static int hls_close(URLContext *h)
 {
-    AppleHTTPContext *s = h->priv_data;
+    HLSContext *s = h->priv_data;
 
     free_segment_list(s);
     free_variant_list(s);
@@ -185,9 +185,9 @@ static int applehttp_close(URLContext *h)
     return 0;
 }
 
-static int applehttp_open(URLContext *h, const char *uri, int flags)
+static int hls_open(URLContext *h, const char *uri, int flags)
 {
-    AppleHTTPContext *s = h->priv_data;
+    HLSContext *s = h->priv_data;
     int ret, i;
     const char *nested_url;
 
@@ -204,24 +204,17 @@ static int applehttp_open(URLContext *h, const char *uri, int flags)
                nested_url);
         ret = AVERROR(EINVAL);
         goto fail;
-#if FF_API_APPLEHTTP_PROTO
-    } else if (av_strstart(uri, "applehttp+", &nested_url)) {
-        av_strlcpy(s->playlisturl, nested_url, sizeof(s->playlisturl));
-        av_log(h, AV_LOG_WARNING,
-               "The applehttp protocol is deprecated, use hls+%s as url "
-               "instead.\n", nested_url);
-    } else if (av_strstart(uri, "applehttp://", &nested_url)) {
-        av_strlcpy(s->playlisturl, "http://", sizeof(s->playlisturl));
-        av_strlcat(s->playlisturl, nested_url, sizeof(s->playlisturl));
-        av_log(h, AV_LOG_WARNING,
-               "The applehttp protocol is deprecated, use hls+http://%s as url "
-               "instead.\n", nested_url);
-#endif
     } else {
         av_log(h, AV_LOG_ERROR, "Unsupported url %s\n", uri);
         ret = AVERROR(EINVAL);
         goto fail;
     }
+    av_log(h, AV_LOG_WARNING,
+           "Using the hls protocol is discouraged, please try using the "
+           "hls demuxer instead. The hls demuxer should be more complete "
+           "and work as well as the protocol implementation. (If not, "
+           "please report it.) To use the demuxer, simply use %s as url.\n",
+           s->playlisturl);
 
     if ((ret = parse_playlist(h, s->playlisturl)) < 0)
         goto fail;
@@ -252,13 +245,13 @@ static int applehttp_open(URLContext *h, const char *uri, int flags)
     return 0;
 
 fail:
-    applehttp_close(h);
+    hls_close(h);
     return ret;
 }
 
-static int applehttp_read(URLContext *h, uint8_t *buf, int size)
+static int hls_read(URLContext *h, uint8_t *buf, int size)
 {
-    AppleHTTPContext *s = h->priv_data;
+    HLSContext *s = h->priv_data;
     const char *url;
     int ret;
     int64_t reload_interval;
@@ -302,7 +295,7 @@ retry:
         while (av_gettime() - s->last_load_time < reload_interval) {
             if (ff_check_interrupt(&h->interrupt_callback))
                 return AVERROR_EXIT;
-            usleep(100*1000);
+            av_usleep(100*1000);
         }
         goto retry;
     }
@@ -320,22 +313,11 @@ retry:
     goto start;
 }
 
-#if FF_API_APPLEHTTP_PROTO
-URLProtocol ff_applehttp_protocol = {
-    .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),
-};
-#endif
-
 URLProtocol ff_hls_protocol = {
     .name           = "hls",
-    .url_open       = applehttp_open,
-    .url_read       = applehttp_read,
-    .url_close      = applehttp_close,
+    .url_open       = hls_open,
+    .url_read       = hls_read,
+    .url_close      = hls_close,
     .flags          = URL_PROTOCOL_FLAG_NESTED_SCHEME,
-    .priv_data_size = sizeof(AppleHTTPContext),
+    .priv_data_size = sizeof(HLSContext),
 };