diff --git a/ext/dash/gstdashdemux.c b/ext/dash/gstdashdemux.c index 0832e7b660..72378b9670 100644 --- a/ext/dash/gstdashdemux.c +++ b/ext/dash/gstdashdemux.c @@ -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; } diff --git a/ext/dash/gstmpdparser.c b/ext/dash/gstmpdparser.c index e0ffbb16cd..672c23cf12 100644 --- a/ext/dash/gstmpdparser.c +++ b/ext/dash/gstmpdparser.c @@ -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; } -guint gst_mpd_client_get_height_of_video_current_stream (GstRepresentationBaseType *RepresentationBase) +const gchar *gst_mpd_client_get_stream_mimeType (GstActiveStream * stream) { - g_return_val_if_fail (RepresentationBase != NULL, 0); - return RepresentationBase->height; + 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_rate_of_audio_current_stream (GstRepresentationBaseType *RepresentationBase) +guint gst_mpd_client_get_video_stream_width (GstActiveStream * stream) { - g_return_val_if_fail (RepresentationBase != NULL, 0); - return (guint) RepresentationBase->audioSamplingRate; + 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_num_channels_of_audio_current_stream (GstRepresentationBaseType *RepresentationBase) +guint gst_mpd_client_get_video_stream_height (GstActiveStream * stream) { - g_return_val_if_fail (RepresentationBase != NULL, 0); - /* TODO*/ - return 1; + 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_audio_stream_rate (GstActiveStream * stream) +{ + 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_audio_stream_num_channels (GstActiveStream * stream) +{ + 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 diff --git a/ext/dash/gstmpdparser.h b/ext/dash/gstmpdparser.h index 4ec58e939e..601016b976 100644 --- a/ext/dash/gstmpdparser.h +++ b/ext/dash/gstmpdparser.h @@ -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);