adaptive: extract variant info
[platform/upstream/gstreamer.git] / ext / dash / gstdashdemux.c
index 0f96e33..2436502 100644 (file)
@@ -678,6 +678,13 @@ gst_dash_demux_setup_all_streams (GstDashDemux * demux)
 
     caps = gst_dash_demux_get_input_caps (demux, active_stream);
     GST_LOG_OBJECT (demux, "Creating stream %d %" GST_PTR_FORMAT, i, caps);
+#ifdef TIZEN_FEATURE_ADAPTIVE_MODIFICATION
+    caps = gst_caps_make_writable (caps);
+    gst_caps_set_simple (caps, "adaptive_stream", G_TYPE_BOOLEAN, TRUE,
+        "dash_stream", G_TYPE_BOOLEAN, TRUE, NULL);
+    GST_LOG_OBJECT (demux,
+        "*** modified caps for dash streaming = %" GST_PTR_FORMAT, caps);
+#endif
 
     if (active_stream->cur_adapt_set) {
       GstAdaptationSetNode *adp_set = active_stream->cur_adapt_set;
@@ -695,6 +702,20 @@ gst_dash_demux_setup_all_streams (GstDashDemux * demux)
           }
         }
       }
+
+#ifdef TIZEN_FEATURE_ADAPTIVE_MODIFICATION
+      if (active_stream->mimeType == GST_STREAM_VIDEO
+          && adp_set->VariantInfo != NULL) {
+        GST_LOG_OBJECT (demux,
+            "post msg about video active stream variant info");
+
+        gst_element_post_message (GST_ELEMENT_CAST (demux),
+            gst_message_new_element (GST_OBJECT_CAST (demux),
+                gst_structure_new (GST_ADAPTIVE_DEMUX_VARIANT_MESSAGE_NAME,
+                    "video-variant-info", G_TYPE_POINTER, adp_set->VariantInfo,
+                    NULL)));
+      }
+#endif
     }
 
     if (lang) {
@@ -1575,6 +1596,25 @@ gst_dash_demux_stream_select_bitrate (GstAdaptiveDemuxStream * stream,
     bitrate = MIN (demux->max_bitrate, bitrate);
   }
 
+#ifdef TIZEN_FEATURE_ADAPTIVE_MODIFICATION
+  bitrate = (base_demux->max_bandwidth > DEFAULT_ADAPTIVE_VARIANT)?
+                          (guint64)(base_demux->max_bandwidth):(bitrate);
+  GST_DEBUG_OBJECT (stream->pad,
+      "Trying to change to bitrate under : %" G_GUINT64_FORMAT, bitrate);
+
+  /* get representation index with current max_bandwidth */
+  if ((base_demux->segment.flags & GST_SEGMENT_FLAG_TRICKMODE_KEY_UNITS) ||
+      ABS (base_demux->segment.rate) <= 1.0) {
+    new_index =
+        gst_mpdparser_get_rep_idx_with_max_bandwidth (rep_list, (gint)bitrate,
+        demux->max_video_width, demux->max_video_height);
+  } else {
+    new_index =
+        gst_mpdparser_get_rep_idx_with_max_bandwidth (rep_list,
+        (gint)(bitrate / ABS (base_demux->segment.rate)), demux->max_video_width,
+        demux->max_video_height);
+  }
+#else
   /* get representation index with current max_bandwidth */
   if ((base_demux->segment.flags & GST_SEGMENT_FLAG_TRICKMODE_KEY_UNITS) ||
       ABS (base_demux->segment.rate) <= 1.0) {
@@ -1589,6 +1629,7 @@ gst_dash_demux_stream_select_bitrate (GstAdaptiveDemuxStream * stream,
         demux->max_video_height, demux->max_video_framerate_n,
         demux->max_video_framerate_d);
   }
+#endif
 
   /* if no representation has the required bandwidth, take the lowest one */
   if (new_index == -1)
@@ -2948,7 +2989,7 @@ struct Rfc5322TimeZone
 
 /*
  Parse an RFC5322 (section 3.3) date-time from the Date: field in the
- HTTP response. 
+ HTTP response.
  See https://tools.ietf.org/html/rfc5322#section-3.3
 */
 static GstDateTime *
@@ -3175,6 +3216,14 @@ gst_dash_demux_poll_clock_drift (GstDashDemux * demux)
       gst_adaptive_demux_get_client_now_utc (GST_ADAPTIVE_DEMUX_CAST (demux));
   if (!value) {
     GstFragment *download;
+#ifdef TIZEN_FEATURE_ADAPTIVE_MODIFICATION
+  GST_DEBUG_OBJECT (demux, "Fetching current time from %s",
+      urls[clock_drift->selected_url]);
+  download = gst_uri_downloader_fetch_uri (GST_ADAPTIVE_DEMUX_CAST
+      (demux)->downloader, urls[clock_drift->selected_url], NULL, NULL, NULL,
+      DEFAULT_ADAPTIVE_RETRY, DEFAULT_ADAPTIVE_TIMEOUT, TRUE, FALSE, TRUE,
+      NULL);
+#else
     gint64 range_start = 0, range_end = -1;
     GST_DEBUG_OBJECT (demux, "Fetching current time from %s",
         urls[clock_drift->selected_url]);
@@ -3185,6 +3234,7 @@ gst_dash_demux_poll_clock_drift (GstDashDemux * demux)
         gst_uri_downloader_fetch_uri_with_range (GST_ADAPTIVE_DEMUX_CAST
         (demux)->downloader, urls[clock_drift->selected_url], NULL, TRUE, TRUE,
         TRUE, range_start, range_end, NULL);
+#endif
     if (download) {
       if (method == GST_MPD_UTCTIMING_TYPE_HTTP_HEAD && download->headers) {
         value = gst_dash_demux_parse_http_head (clock_drift, download);