dashdemux: reworked caps detection
authorGianluca Gennari <gennarone@gmail.com>
Fri, 19 Oct 2012 18:12:09 +0000 (20:12 +0200)
committerThiago Santos <thiago.sousa.santos@collabora.com>
Wed, 8 May 2013 21:14:06 +0000 (18:14 -0300)
also reworked the API to extract audio/video parameters from the manifest file
(mimeType, width, height, rate, num channels)

ext/dash/gstdashdemux.c
ext/dash/gstmpdparser.c
ext/dash/gstmpdparser.h

index 0832e7b..72378b9 100644 (file)
@@ -1328,47 +1328,29 @@ gst_dash_demux_prepend_header (GstDashDemux * demux,
   return res;
 }
 
-const gchar *
-gst_mpd_mimetype_to_caps (const gchar * mimeType)
-{
-  if (mimeType == NULL)
-    return NULL;
-  if (strcmp (mimeType, "video/mp2t") == 0) {
-    return "video/mpegts";
-  } else if (strcmp (mimeType, "video/mp4") == 0) {
-    return "video/quicktime";
-  } else if (strcmp (mimeType, "audio/mp4") == 0) {
-    return "audio/x-m4a";
-  } else
-    return mimeType;
-}
-
 static GstCaps *
 gst_dash_demux_get_video_input_caps (GstDashDemux * demux,
     GstActiveStream * stream)
 {
   guint width, height;
-  const gchar *mimeType;
+  const gchar *mimeType = NULL;
   GstCaps *caps = NULL;
-  GstRepresentationBaseType *RepresentationBase;
+
   if (stream == NULL)
     return NULL;
 
-  if (stream->cur_representation->RepresentationBase) {
-    RepresentationBase = stream->cur_representation->RepresentationBase;
-  } else {
-    RepresentationBase = stream->cur_adapt_set->RepresentationBase;
-  }
-  if (RepresentationBase == NULL)
+  width = gst_mpd_client_get_video_stream_width (stream);
+  height = gst_mpd_client_get_video_stream_height (stream);
+  mimeType = gst_mpd_client_get_stream_mimeType (stream);
+  if (mimeType == NULL)
     return NULL;
 
-  width = gst_mpd_client_get_width_of_video_current_stream (RepresentationBase);
-  height =
-      gst_mpd_client_get_height_of_video_current_stream (RepresentationBase);
-  mimeType = gst_mpd_mimetype_to_caps (RepresentationBase->mimeType);
-  caps =
-      gst_caps_new_simple (mimeType, "width", G_TYPE_INT, width, "height",
-      G_TYPE_INT, height, NULL);
+  caps = gst_caps_new_simple (mimeType, NULL);
+  if (width > 0 && height > 0) {
+    gst_caps_set_simple (caps, "width", G_TYPE_INT, width, "height",
+        G_TYPE_INT, height, NULL);
+  }
+
   return caps;
 }
 
@@ -1379,26 +1361,24 @@ gst_dash_demux_get_audio_input_caps (GstDashDemux * demux,
   guint rate, channels;
   const gchar *mimeType;
   GstCaps *caps = NULL;
-  GstRepresentationBaseType *RepresentationBase;
+
   if (stream == NULL)
     return NULL;
 
-  if (stream->cur_representation->RepresentationBase) {
-    RepresentationBase = stream->cur_representation->RepresentationBase;
-  } else {
-    RepresentationBase = stream->cur_adapt_set->RepresentationBase;
-  }
-  if (RepresentationBase == NULL)
+  channels = gst_mpd_client_get_audio_stream_num_channels (stream);
+  rate = gst_mpd_client_get_audio_stream_rate (stream);
+  mimeType = gst_mpd_client_get_stream_mimeType (stream);
+  if (mimeType == NULL)
     return NULL;
 
-  channels =
-      gst_mpd_client_get_num_channels_of_audio_current_stream
-      (RepresentationBase);
-  rate = gst_mpd_client_get_rate_of_audio_current_stream (RepresentationBase);
-  mimeType = gst_mpd_mimetype_to_caps (RepresentationBase->mimeType);
-  caps =
-      gst_caps_new_simple (mimeType, "channels", G_TYPE_INT, channels, "rate",
-      G_TYPE_INT, rate, NULL);
+  caps = gst_caps_new_simple (mimeType, NULL);
+  if (rate > 0) {
+    gst_caps_set_simple (caps, "rate", G_TYPE_INT, rate, NULL);
+  }
+  if (channels > 0) {
+    gst_caps_set_simple (caps, "channels", G_TYPE_INT, channels, NULL);
+  }
+
   return caps;
 }
 
@@ -1408,20 +1388,16 @@ gst_dash_demux_get_application_input_caps (GstDashDemux * demux,
 {
   const gchar *mimeType;
   GstCaps *caps = NULL;
-  GstRepresentationBaseType *RepresentationBase;
+
   if (stream == NULL)
     return NULL;
 
-  if (stream->cur_representation->RepresentationBase) {
-    RepresentationBase = stream->cur_representation->RepresentationBase;
-  } else {
-    RepresentationBase = stream->cur_adapt_set->RepresentationBase;
-  }
-  if (RepresentationBase == NULL)
+  mimeType = gst_mpd_client_get_stream_mimeType (stream);
+  if (mimeType == NULL)
     return NULL;
 
-  mimeType = gst_mpd_mimetype_to_caps (RepresentationBase->mimeType);
   caps = gst_caps_new_simple (mimeType, NULL);
+
   return caps;
 }
 
index e0ffbb1..672c23c 100644 (file)
@@ -80,6 +80,7 @@ static gchar *gst_mpdparser_get_mediaURL (GstSegmentURLNode *segmentURL);
 static gchar *gst_mpdparser_get_initializationURL (GstURLType *InitializationURL);
 static gchar *gst_mpdparser_build_URL_from_template (const gchar *url_template, const gchar *id, guint number, guint bandwidth, guint time);
 static gboolean gst_mpd_client_add_media_segment (GstActiveStream *stream, GstSegmentURLNode *url_node, guint number, guint start, GstClockTime start_time, GstClockTime duration);
+static const gchar *gst_mpdparser_mimetype_to_caps (const gchar * mimeType);
 
 /* Period */
 static GstPeriodNode *gst_mpdparser_get_next_period (GList *Periods, GstPeriodNode *prev_period);
@@ -2736,7 +2737,7 @@ gst_mpd_client_setup_streaming (GstMpdClient * client,
             gst_mpdparser_get_first_adapt_set_with_mimeType (client->
             cur_period->AdaptationSets, "audio");
       if (!adapt_set) {
-        GST_INFO ("No audio adaptation set found, aborting...");
+        GST_INFO ("No audio adaptation set found");
         return FALSE;
       }
       rep_list = adapt_set->Representations;
@@ -2761,7 +2762,7 @@ gst_mpd_client_setup_streaming (GstMpdClient * client,
             gst_mpdparser_get_first_adapt_set_with_mimeType (client->
             cur_period->AdaptationSets, "application");
       if (!adapt_set) {
-        GST_INFO ("No application adaptation set found, aborting...");
+        GST_INFO ("No application adaptation set found");
         return FALSE;
       }
       rep_list = adapt_set->Representations;
@@ -3011,29 +3012,87 @@ GstActiveStream *gst_mpdparser_get_active_stream_by_index (GstMpdClient *client,
             stream_idx);
 }
 
-guint gst_mpd_client_get_width_of_video_current_stream (GstRepresentationBaseType *RepresentationBase)
+static const gchar *
+gst_mpdparser_mimetype_to_caps (const gchar * mimeType)
 {
- g_return_val_if_fail (RepresentationBase != NULL, 0);
- return RepresentationBase->width;
+  if (mimeType == NULL)
+    return NULL;
+  if (strcmp (mimeType, "video/mp2t") == 0) {
+    return "video/mpegts";
+  } else if (strcmp (mimeType, "video/mp4") == 0) {
+    return "video/quicktime";
+  } else if (strcmp (mimeType, "audio/mp4") == 0) {
+    return "audio/x-m4a";
+  } else
+    return mimeType;
+}
+
+const gchar *gst_mpd_client_get_stream_mimeType (GstActiveStream * stream)
+{
+  const gchar *mimeType;
+
+  if (stream == NULL || stream->cur_adapt_set == NULL || stream->cur_representation == NULL)
+    return NULL;
+
+  mimeType = stream->cur_representation->RepresentationBase->mimeType;
+  if (mimeType == NULL) {
+    mimeType = stream->cur_adapt_set->RepresentationBase->mimeType;
+  }
+
+  return gst_mpdparser_mimetype_to_caps (mimeType);
+}
+
+guint gst_mpd_client_get_video_stream_width (GstActiveStream * stream)
+{
+  guint width;
+
+  if (stream == NULL || stream->cur_adapt_set == NULL || stream->cur_representation == NULL)
+    return 0;
+
+  width = stream->cur_representation->RepresentationBase->width;
+  if (width == 0) {
+    width = stream->cur_adapt_set->RepresentationBase->width;
+  }
+
+  return width;
 }
 
-guint gst_mpd_client_get_height_of_video_current_stream (GstRepresentationBaseType *RepresentationBase)
+guint gst_mpd_client_get_video_stream_height (GstActiveStream * stream)
 {
- g_return_val_if_fail (RepresentationBase != NULL, 0);
- return RepresentationBase->height;
+  guint height;
+
+  if (stream == NULL || stream->cur_adapt_set == NULL || stream->cur_representation == NULL)
+    return 0;
+
+  height = stream->cur_representation->RepresentationBase->height;
+  if (height == 0) {
+    height = stream->cur_adapt_set->RepresentationBase->height;
+  }
+
+  return height;
 }
 
-guint gst_mpd_client_get_rate_of_audio_current_stream (GstRepresentationBaseType *RepresentationBase)
+guint gst_mpd_client_get_audio_stream_rate (GstActiveStream * stream)
 {
- g_return_val_if_fail (RepresentationBase != NULL, 0);
- return (guint) RepresentationBase->audioSamplingRate;
+  const gchar *rate;
+
+  if (stream == NULL || stream->cur_adapt_set == NULL || stream->cur_representation == NULL)
+    return 0;
+
+  rate = stream->cur_representation->RepresentationBase->audioSamplingRate;
+  if (rate == NULL) {
+    rate = stream->cur_adapt_set->RepresentationBase->audioSamplingRate;
+  }
+
+  return rate ? atoi (rate) : 0;
 }
 
-guint gst_mpd_client_get_num_channels_of_audio_current_stream (GstRepresentationBaseType *RepresentationBase)
+guint gst_mpd_client_get_audio_stream_num_channels (GstActiveStream * stream)
 {
- g_return_val_if_fail (RepresentationBase != NULL, 0);
- /* TODO*/
- return 1;
+  if (stream == NULL || stream->cur_adapt_set == NULL || stream->cur_representation == NULL)
+    return 0;
+  /* TODO: here we have to parse the AudioChannelConfiguration descriptors */
+  return 0;
 }
 
 guint
index 4ec58e9..601016b 100644 (file)
@@ -468,13 +468,12 @@ GstActiveStream *gst_mpdparser_get_active_stream_by_index (GstMpdClient *client,
 /* AdaptationSet */
 guint gst_mpdparser_get_nb_adaptationSet(GstMpdClient *client);
 
-/* Get With and high of video parameter by stream */
-guint  gst_mpd_client_get_width_of_video_current_stream (GstRepresentationBaseType *RepresentationBase);
-guint  gst_mpd_client_get_height_of_video_current_stream (GstRepresentationBaseType *RepresentationBase);
-
-/* Get channel and rate of audio parameter by stream */
-guint  gst_mpd_client_get_rate_of_audio_current_stream (GstRepresentationBaseType *RepresentationBase);
-guint  gst_mpd_client_get_num_channels_of_audio_current_stream (GstRepresentationBaseType *RepresentationBase);
+/* Get audio/video stream parameters (mimeType, width, height, rate, number of channels) */
+const gchar *gst_mpd_client_get_stream_mimeType (GstActiveStream * stream);
+guint  gst_mpd_client_get_video_stream_width (GstActiveStream * stream);
+guint  gst_mpd_client_get_video_stream_height (GstActiveStream * stream);
+guint  gst_mpd_client_get_audio_stream_rate (GstActiveStream * stream);
+guint  gst_mpd_client_get_audio_stream_num_channels (GstActiveStream * stream);
 
 /* Support multi language */
 guint gst_mpdparser_get_list_and_nb_of_audio_language(GList **lang, GList *AdaptationSets);