]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/applehttp.c
avconv: print the codecs names in the stream mapping.
[ffmpeg] / libavformat / applehttp.c
index 2e0e8a1b3ad988e81d041f9935b11770ec9dab27..10f58afde5fbb7d555d88d99d0f4d4d8115406a4 100644 (file)
  * http://tools.ietf.org/html/draft-pantos-http-live-streaming
  */
 
-#define _XOPEN_SOURCE 600
 #include "libavutil/avstring.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mathematics.h"
 #include "libavutil/opt.h"
+#include "libavutil/dict.h"
 #include "avformat.h"
 #include "internal.h"
 #include <unistd.h>
@@ -411,7 +412,7 @@ reload:
     c->end_of_segment = 1;
     c->cur_seq_no = v->cur_seq_no;
 
-    if (v->ctx) {
+    if (v->ctx && v->ctx->nb_streams) {
         v->needed = 0;
         for (i = v->stream_offset; i < v->stream_offset + v->ctx->nb_streams;
              i++) {
@@ -473,6 +474,11 @@ static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap)
         if (v->n_segments == 0)
             continue;
 
+        if (!(v->ctx = avformat_alloc_context())) {
+            ret = AVERROR(ENOMEM);
+            goto fail;
+        }
+
         v->index  = i;
         v->needed = 1;
         v->parent = s;
@@ -491,8 +497,8 @@ static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap)
                                     NULL, 0, 0);
         if (ret < 0)
             goto fail;
-        ret = av_open_input_stream(&v->ctx, &v->pb, v->segments[0]->url,
-                                   in_fmt, NULL);
+        v->ctx->pb       = &v->pb;
+        ret = avformat_open_input(&v->ctx, v->segments[0]->url, in_fmt, NULL);
         if (ret < 0)
             goto fail;
         v->stream_offset = stream_offset;
@@ -505,7 +511,9 @@ static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap)
                 goto fail;
             }
             avcodec_copy_context(st->codec, v->ctx->streams[j]->codec);
-            av_metadata_set2(&st->metadata, "variant_bitrate", bitrate_str, 0);
+            if (v->bandwidth)
+                av_dict_set(&st->metadata, "variant_bitrate", bitrate_str,
+                                 0);
         }
         stream_offset += v->ctx->nb_streams;
     }
@@ -660,12 +668,12 @@ static int applehttp_probe(AVProbeData *p)
 }
 
 AVInputFormat ff_applehttp_demuxer = {
-    "applehttp",
-    NULL_IF_CONFIG_SMALL("Apple HTTP Live Streaming format"),
-    sizeof(AppleHTTPContext),
-    applehttp_probe,
-    applehttp_read_header,
-    applehttp_read_packet,
-    applehttp_close,
-    applehttp_read_seek,
+    .name           = "applehttp",
+    .long_name      = NULL_IF_CONFIG_SMALL("Apple HTTP Live Streaming format"),
+    .priv_data_size = sizeof(AppleHTTPContext),
+    .read_probe     = applehttp_probe,
+    .read_header    = applehttp_read_header,
+    .read_packet    = applehttp_read_packet,
+    .read_close     = applehttp_close,
+    .read_seek      = applehttp_read_seek,
 };