souphttpsrc: check range response when update content_size 15/120015/1
authorEunhae Choi <eunhae1.choi@samsung.com>
Mon, 20 Mar 2017 05:59:49 +0000 (14:59 +0900)
committereunhae choi <eunhae1.choi@samsung.com>
Tue, 21 Mar 2017 06:43:47 +0000 (23:43 -0700)
In case request_position is content_size,
the response content_length can be zero with status code 200.
(reproduced in Youtube http streaming)

Change-Id: If28565375e0e13dc84054fd2383268467faf68aa
(cherry picked from commit 0ae443abd9066053d0412c28fe9d9afddc8488c8)

ext/soup/gstsouphttpsrc.c

index 3adf9b9..830dd66 100644 (file)
@@ -1262,8 +1262,11 @@ gst_soup_http_src_got_headers_cb (SoupMessage * msg, GstSoupHTTPSrc * src)
   GstEvent *http_headers_event;
   GstStructure *http_headers, *headers;
   const gchar *accept_ranges;
+#ifdef TIZEN_FEATURE_SOUP_MODIFICATION
+  gint64 start = 0, stop = 0, total = 0;
+#endif
 
-  GST_INFO_OBJECT (src, "got headers");
+  GST_INFO_OBJECT (src, "got headers : %d", msg->status_code);
 #ifdef TIZEN_FEATURE_SOUP_MODIFICATION
   soup_message_headers_foreach (msg->response_headers,
       gst_soup_http_src_headers_foreach, src);
@@ -1319,7 +1322,17 @@ gst_soup_http_src_got_headers_cb (SoupMessage * msg, GstSoupHTTPSrc * src)
         newsize = src->request_position +
             soup_message_headers_get_content_length (msg->response_headers);
       } else {
-        newsize = soup_message_headers_get_content_length (msg->response_headers);
+        if (soup_message_headers_get_content_range(msg->response_headers, &start, &stop, &total) && (total > 0)) {
+          GST_DEBUG_OBJECT (src, "get range header : %" G_GINT64_FORMAT
+                                  "~%" G_GINT64_FORMAT"/%"G_GINT64_FORMAT, start, stop, total);
+          newsize = (guint64)total;
+        } else {
+          if ((src->have_size) && (src->content_size <= src->request_position)) {
+            newsize = src->content_size;
+          } else {
+            newsize = soup_message_headers_get_content_length (msg->response_headers);
+          }
+        }
       }
 #else
       newsize = src->request_position +
@@ -1350,7 +1363,8 @@ gst_soup_http_src_got_headers_cb (SoupMessage * msg, GstSoupHTTPSrc * src)
 #ifdef TIZEN_FEATURE_SOUP_MODIFICATION
   /* The Range request header is always included.
    * @ref gst_soup_http_src_add_range_header() */
-  else if (msg->status_code == SOUP_STATUS_OK) {
+  else if ((msg->status_code == SOUP_STATUS_OK) &&
+    (soup_message_headers_get_content_range(msg->response_headers, &start, &stop, &total) == FALSE)) {
     GST_DEBUG_OBJECT (src, "there is no accept range header");
     src->seekable = FALSE;
   }