diff mbox

[FFmpeg-devel] Download dash content with byte range info

Message ID DM5PR22MB06816D28600D6DBBB42FF9C6FE290@DM5PR22MB0681.namprd22.prod.outlook.com
State Superseded
Headers show

Commit Message

Colin NG Nov. 15, 2017, 2:14 a.m. UTC

diff mbox

Patch

diff --git a/doc/examples/Makefile b/doc/examples/Makefile
index 58afd71..bff4af6 100644
--- a/doc/examples/Makefile
+++ b/doc/examples/Makefile
@@ -1,3 +1,16 @@ 
+# use pkg-config for getting CFLAGS and LDLIBS
+FFMPEG_LIBS=    libavdevice                        \
+                libavformat                        \
+                libavfilter                        \
+                libavcodec                         \
+                libswresample                      \
+                libswscale                         \
+                libavutil                          \
+
+CFLAGS += -Wall -g
+CFLAGS := $(shell pkg-config --cflags $(FFMPEG_LIBS)) $(CFLAGS)
+LDLIBS := $(shell pkg-config --libs $(FFMPEG_LIBS)) $(LDLIBS)
+
 EXAMPLES-$(CONFIG_AVIO_DIR_CMD_EXAMPLE)      += avio_dir_cmd
 EXAMPLES-$(CONFIG_AVIO_READING_EXAMPLE)      += avio_reading
 EXAMPLES-$(CONFIG_DECODE_AUDIO_EXAMPLE)      += decode_audio
@@ -19,6 +32,7 @@  EXAMPLES-$(CONFIG_RESAMPLING_AUDIO_EXAMPLE)  += resampling_audio
 EXAMPLES-$(CONFIG_SCALING_VIDEO_EXAMPLE)     += scaling_video
 EXAMPLES-$(CONFIG_TRANSCODE_AAC_EXAMPLE)     += transcode_aac
 EXAMPLES-$(CONFIG_TRANSCODING_EXAMPLE)       += transcoding
+EXAMPLES-$(CONFIG_SAMPLE_EXAMPLE)       += sample
 
 EXAMPLES       := $(EXAMPLES-yes:%=doc/examples/%$(PROGSSUF)$(EXESUF))
 EXAMPLES_G     := $(EXAMPLES-yes:%=doc/examples/%$(PROGSSUF)_g$(EXESUF))
diff --git a/doc/examples/avio_reading.c b/doc/examples/avio_reading.c
index 7860fd5..c77b8f9 100644
--- a/doc/examples/avio_reading.c
+++ b/doc/examples/avio_reading.c
@@ -39,6 +39,15 @@  struct buffer_data {
     size_t size; ///< size left in the buffer
 };
 
+static int isLocal(char *url)
+{
+   if (av_strstart(url, "http://", NULL) || av_strstart(url, "https://", NULL))
+   {
+      return FALSE;
+   }
+   return TRUE;
+}
+
 static int read_packet(void *opaque, uint8_t *buf, int buf_size)
 {
     struct buffer_data *bd = (struct buffer_data *)opaque;
@@ -78,7 +87,28 @@  int main(int argc, char *argv[])
     av_register_all();
 
     /* slurp file content into buffer */
-    ret = av_file_map(input_filename, &buffer, &buffer_size, 0, NULL);
+
+   if (isLocal(input_filename) == TRUE) 
+   {
+      ret = av_file_map(input_filename, &buffer, &buffer_size, 0, NULL);
+   }
+   else
+   {
+      AVIOContext *in = NULL;
+
+      ret = avio_open2(&in, input_filename, AVIO_FLAG_READ, NULL, NULL);
+
+      buffer_size = avio_size(in);
+
+      if (buffer_size <= 0) {
+         buffer_size = 8 * 1024;
+      }
+
+      if (buffer = av_mallocz(buffer_size) == NULL) {
+         return AVERROR(ENOMEM);
+      }
+      buffer_size = avio_read(in, buffer, buffer_size);
+   }
     if (ret < 0)
         goto end;
 
diff --git a/libavcodec/dsd.c b/libavcodec/dsd.c
index 9104f38..6742f53 100644
--- a/libavcodec/dsd.c
+++ b/libavcodec/dsd.c
@@ -21,7 +21,9 @@ 
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+
 #include "libavcodec/internal.h"
+#include "libavutil/reverse.h"
 #include "libavcodec/mathops.h"
 #include "avcodec.h"
 #include "dsd_tablegen.h"
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 1b332a7..2d77088 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -24,6 +24,8 @@ 
  * @author Konstantin Shishkov
  */
 
+#include "libavutil/reverse.h"
+
 #include "config.h"
 #if CONFIG_ZLIB
 #include <zlib.h>
diff --git a/libavcodec/xsubdec.c b/libavcodec/xsubdec.c
index 93fd0f4..2cfe24b 100644
--- a/libavcodec/xsubdec.c
+++ b/libavcodec/xsubdec.c
@@ -21,6 +21,8 @@ 
 
 #include "libavutil/mathematics.h"
 #include "libavutil/imgutils.h"
+#include "libavutil/intmath.h"
+
 #include "avcodec.h"
 #include "get_bits.h"
 #include "bytestream.h"
diff --git a/libavdevice/v4l2-common.c b/libavdevice/v4l2-common.c
index 196c09b..80cd524 100644
--- a/libavdevice/v4l2-common.c
+++ b/libavdevice/v4l2-common.c
@@ -43,9 +43,9 @@  const struct fmt_map ff_fmt_conversion_table[] = {
     { AV_PIX_FMT_NV12,    AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_NV12    },
     { AV_PIX_FMT_NONE,    AV_CODEC_ID_MJPEG,    V4L2_PIX_FMT_MJPEG   },
     { AV_PIX_FMT_NONE,    AV_CODEC_ID_MJPEG,    V4L2_PIX_FMT_JPEG    },
-#ifdef V4L2_PIX_FMT_H264
+//#ifdef V4L2_PIX_FMT_H264
     { AV_PIX_FMT_NONE,    AV_CODEC_ID_H264,     V4L2_PIX_FMT_H264    },
-#endif
+//#endif
 #ifdef V4L2_PIX_FMT_MPEG4
     { AV_PIX_FMT_NONE,    AV_CODEC_ID_MPEG4,    V4L2_PIX_FMT_MPEG4   },
 #endif
diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
index 0e3afd2..68196e9 100644
--- a/libavformat/dashdec.c
+++ b/libavformat/dashdec.c
@@ -522,6 +522,22 @@  static enum AVMediaType get_content_type(xmlNodePtr node)
     return type;
 }
 
+static struct fragment * getFragment(char *range)
+{
+    struct fragment * seg =  av_mallocz(sizeof(struct fragment));
+
+    memset(seg, 0, sizeof(struct fragment));
+    seg->size = -1;
+    if (range)  {
+        char *str_end_offset;
+        char *str_offset = av_strtok(range, "-", &str_end_offset);
+        seg->url_offset = strtoll(str_offset, NULL, 10);
+        seg->size = strtoll(str_end_offset, NULL, 10) -seg->url_offset;
+    }
+
+    return seg;
+}
+
 static int parse_manifest_segmenturlnode(AVFormatContext *s, struct representation *rep,
                                          xmlNodePtr fragmenturl_node,
                                          xmlNodePtr *baseurl_nodes,
@@ -530,11 +546,13 @@  static int parse_manifest_segmenturlnode(AVFormatContext *s, struct representati
 {
     char *initialization_val = NULL;
     char *media_val = NULL;
+    char *range_val = NULL;
 
     if (!av_strcasecmp(fragmenturl_node->name, (const char *)"Initialization")) {
         initialization_val = xmlGetProp(fragmenturl_node, "sourceURL");
-        if (initialization_val) {
-            rep->init_section = av_mallocz(sizeof(struct fragment));
+        range_val = xmlGetProp(fragmenturl_node, "range");
+        if (initialization_val || range_val) {
+            rep->init_section = getFragment(range_val);// byte range on
             if (!rep->init_section) {
                 xmlFree(initialization_val);
                 return AVERROR(ENOMEM);
@@ -550,11 +568,13 @@  static int parse_manifest_segmenturlnode(AVFormatContext *s, struct representati
             }
             rep->init_section->size = -1;
             xmlFree(initialization_val);
+            xmlFree(range_val);
         }
     } else if (!av_strcasecmp(fragmenturl_node->name, (const char *)"SegmentURL")) {
         media_val = xmlGetProp(fragmenturl_node, "media");
-        if (media_val) {
-            struct fragment *seg = av_mallocz(sizeof(struct fragment));
+        range_val = xmlGetProp(fragmenturl_node, "mediaRange");
+        if (media_val || range_val) {
+            struct fragment *seg =  getFragment(range_val);// byte range on
             if (!seg) {
                 xmlFree(media_val);
                 return AVERROR(ENOMEM);
@@ -571,12 +591,12 @@  static int parse_manifest_segmenturlnode(AVFormatContext *s, struct representati
             seg->size = -1;
             dynarray_add(&rep->fragments, &rep->n_fragments, seg);
             xmlFree(media_val);
+            xmlFree(range_val);
         }
     }
 
     return 0;
 }
-
 static int parse_manifest_segmenttimeline(AVFormatContext *s, struct representation *rep,
                                           xmlNodePtr fragment_timeline_node)
 {