Excluded the fix for byte range issue and update some coding style issues.

________________________________
From: Colin NG <colin...@hotmail.com>
Sent: November 15, 2017 10:58 AM
To: FFmpeg development discussions and patches
Subject: Re: [FFmpeg-devel] [Patch] Fix for ticket 6658 (Dash demuxer segfault)


Have submitted already for the byte range issue in another email with title 
"Download dash content with byte range info"


________________________________
From: ffmpeg-devel <ffmpeg-devel-boun...@ffmpeg.org> on behalf of Carl Eugen 
Hoyos <ceffm...@gmail.com>
Sent: November 15, 2017 10:54 AM
To: FFmpeg development discussions and patches
Subject: Re: [FFmpeg-devel] [Patch] Fix for ticket 6658 (Dash demuxer segfault)

2017-11-15 3:54 GMT+01:00 Colin NG <colin...@hotmail.com>:
> - Add a function to handle the base URL Processing described in section 5.6.5 
> of IEC_23009-1.
>
> - Fix for downloading dash content with byte range info

As said: If these are two separate issues, please send two patches.

Use tools/patcheck to check your patch for many style issues.
(No Changelog entry necessary.)

Try to avoid if ((var1 = var2) > 1), instead add an additional line.

Carl Eugen
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
ffmpeg-devel Info Page<http://ffmpeg.org/mailman/listinfo/ffmpeg-devel>
ffmpeg.org
This list is about FFmpeg development discussions and patches; but not for 
bug-reports. Please read the Code-of-conduct. To see the collection of prior 
postings to ...



diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
index 0e3afd2..4d89374 100644
--- a/libavformat/dashdec.c
+++ b/libavformat/dashdec.c
@@ -148,6 +148,11 @@ static uint64_t get_current_time_in_sec(void)
     return  av_gettime() / 1000000;
 }
 
+static char * ishttp(char *url) {
+    char *proto_name = avio_find_protocol_name(url);
+    return av_strstart(proto_name, "http", NULL);
+}
+
 static uint64_t get_utc_date_time_insec(AVFormatContext *s, const char 
*datetime)
 {
     struct tm timeinfo;
@@ -392,7 +397,10 @@ static int open_url(AVFormatContext *s, AVIOContext **pb, 
const char *url,
     else if (strcmp(proto_name, "file") || !strncmp(url, "file,", 5))
         return AVERROR_INVALIDDATA;
 
-    ret = s->io_open(s, pb, url, AVIO_FLAG_READ, &tmp);
+    if (pb) av_freep(pb);
+   // set_httpheader_options(c, &tmp);
+    ret = avio_open2(pb, url, AVIO_FLAG_READ, c->interrupt_callback, &tmp);
+
     if (ret >= 0) {
         // update cookies on http response with setcookies.
         char *new_cookies = NULL;
@@ -613,6 +621,77 @@ static int parse_manifest_segmenttimeline(AVFormatContext 
*s, struct representat
     return 0;
 }
 
+
+static int resolve_content_path(AVFormatContext *s, const char *url,  
xmlNodePtr *baseurl_nodes,  int n_baseurl_nodes) {
+
+    int i;
+    char *text;
+    char tmp_str[MAX_URL_SIZE];
+    char tmp_str_2[MAX_URL_SIZE];
+
+    char *path = av_mallocz(MAX_URL_SIZE);
+    int nameSize = 0;
+    int updated = 0;
+
+    av_strlcpy(tmp_str, url, strlen(url)+1);
+    char *mpdName = strtok (tmp_str," /");
+
+    while ((mpdName =strtok (NULL, "/"))) {
+        nameSize = strlen(mpdName);
+    }
+
+    av_strlcpy (path, url, strlen(url)-nameSize+1 );
+
+    int rootId = 0;
+    xmlNodePtr  *node = NULL;
+    char *proto_name = NULL;
+    for (rootId = n_baseurl_nodes-1; rootId >0; rootId--)  {
+        if (!(node = baseurl_nodes[rootId])) continue;
+
+       if (ishttp(xmlNodeGetContent(node)))  {
+            break;
+        }
+    }
+
+    node = baseurl_nodes[rootId];
+    char *baseurl = xmlNodeGetContent(node);
+    char *root_url = (!av_strcasecmp(baseurl, ""))? path: baseurl;
+
+    if (node)  {
+        xmlNodeSetContent(node, root_url);
+    }
+
+    int size = strlen(root_url);
+    char *isRootHttp= ishttp(root_url);
+
+    char token ='/';
+    if (strncmp(&root_url[size-1],&token, 1) != 0) {
+        av_strlcat(root_url, "/", size+2);
+        size+=2;
+    }
+
+    for (i = 0; i < n_baseurl_nodes; ++i)  {
+        if (i==rootId) continue;
+        text = xmlNodeGetContent(baseurl_nodes[i]);
+        if (text) {
+            memset(tmp_str, 0, sizeof(tmp_str));
+
+            if (!ishttp(text) && isRootHttp)  {
+                av_strlcpy(tmp_str, root_url, size+1);
+            }
+            int start = (strncmp(text, &token, 1) == 0) ? 1: 0;
+            memset(tmp_str_2, 0, sizeof(tmp_str_2));
+            av_strlcat(tmp_str, text+start, MAX_URL_SIZE);
+            xmlFree(text);
+            xmlNodeSetContent(baseurl_nodes[i], tmp_str);
+            updated = 1;
+        }
+    }
+
+    av_free(path);
+    return updated;
+
+}
 static int parse_manifest_representation(AVFormatContext *s, const char *url,
                                          xmlNodePtr node,
                                          xmlNodePtr adaptionset_node,
@@ -672,6 +751,8 @@ static int parse_manifest_representation(AVFormatContext 
*s, const char *url,
         baseurl_nodes[2] = adaptionset_baseurl_node;
         baseurl_nodes[3] = representation_baseurl_node;
 
+        resolve_content_path(s, url, baseurl_nodes, 4);
+
         if (representation_segmenttemplate_node || fragment_template_node) {
             fragment_timeline_node = NULL;
             fragment_templates_tab[0] = representation_segmenttemplate_node;
@@ -967,6 +1048,9 @@ static int parse_manifest(AVFormatContext *s, const char 
*url, AVIOContext *in)
         }
 
         mpd_baseurl_node = find_child_node_by_name(node, "BaseURL");
+        if (!mpd_baseurl_node) {
+            mpd_baseurl_node = xmlNewNode(node, "BaseURL");
+        }
 
         // at now we can handle only one period, with the longest duration
         node = xmlFirstElementChild(node);
@@ -1307,11 +1391,13 @@ static int open_input(DASHContext *c, struct 
representation *pls, struct fragmen
          * (if this is in fact a HTTP request) */
         av_dict_set_int(&opts, "offset", seg->url_offset, 0);
         av_dict_set_int(&opts, "end_offset", seg->url_offset + seg->size, 0);
+
     }
 
     ff_make_absolute_url(url, MAX_URL_SIZE, c->base_url, seg->url);
     av_log(pls->parent, AV_LOG_VERBOSE, "DASH request for url '%s', offset 
%"PRId64", playlist %d\n",
            url, seg->url_offset, pls->rep_idx);
+
     ret = open_url(pls->parent, &pls->input, url, c->avio_opts, opts, NULL);
     if (ret < 0) {
         goto cleanup;
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to