Support Multi languages (need a decodebin2 patch)

This commit is contained in:
Hamid ZAKARI 2012-09-29 03:13:29 +02:00 committed by Thiago Santos
parent a4ac4a3117
commit 713d02b81a
4 changed files with 101 additions and 22 deletions

View file

@ -534,23 +534,35 @@ gst_dash_demux_sink_event (GstPad * pad, GstEvent * event)
gst_buffer_unref (demux->playlist);
demux->playlist = NULL;
if (!gst_mpd_client_setup_streaming (demux->client, GST_STREAM_VIDEO)) {
if (!gst_mpd_client_setup_streaming (demux->client, GST_STREAM_VIDEO, "")) {
GST_ELEMENT_ERROR (demux, STREAM, DECODE,
("Incompatible manifest file."), (NULL));
return FALSE;
}
if (gst_mpdparser_get_nb_adaptationSet (demux->client) > 1)
if (!gst_mpd_client_setup_streaming (demux->client, GST_STREAM_AUDIO))
GST_INFO_OBJECT (demux, "No audio adaptation set found");
guint nb_audio =
gst_mpdparser_get_nb_audio_adapt_set (demux->client->
cur_period->AdaptationSets);
GST_INFO_OBJECT (demux, "Number of language is=%d", nb_audio);
if (nb_audio == 0)
nb_audio = 1;
GList *listLang = NULL;
gst_mpdparser_get_list_of_audio_language (&listLang,
demux->client->cur_period->AdaptationSets);
guint i = 0;
for (i = 0; i < nb_audio; i++) {
gchar *lang = (gchar *) g_list_nth_data (listLang, i);
if (gst_mpdparser_get_nb_adaptationSet (demux->client) > 1)
if (!gst_mpd_client_setup_streaming (demux->client, GST_STREAM_AUDIO,
lang))
GST_INFO_OBJECT (demux, "No audio adaptation set found");
if (gst_mpdparser_get_nb_adaptationSet (demux->client) > 2)
if (!gst_mpd_client_setup_streaming (demux->client,
GST_STREAM_APPLICATION)) {
GST_INFO_OBJECT (demux, "No application adaptation set found");
}
demux->client->stream_idx = 0;
if (gst_mpdparser_get_nb_adaptationSet (demux->client) > nb_audio)
if (!gst_mpd_client_setup_streaming (demux->client,
GST_STREAM_APPLICATION, lang)) {
GST_INFO_OBJECT (demux, "No application adaptation set found");
}
}
/* Send duration message */
if (!gst_mpd_client_is_live (demux->client)) {
@ -697,7 +709,7 @@ gst_dash_demux_stop (GstDashDemux * demux)
static void
switch_pads (GstDashDemux * demux, guint nb_adaptation_set)
{
GstPad *oldpad[3];
GstPad *oldpad[MAX_LANGUAGES];
guint i = 0;
while (i < nb_adaptation_set) {
oldpad[i] = demux->srcpad[i];
@ -782,6 +794,7 @@ gst_dash_demux_stream_loop (GstDashDemux * demux)
GstFlowReturn ret;
GstBufferList *buffer_list;
guint nb_adaptation_set = 0;
GstActiveStream *stream;
/* Loop for the source pad task.
*
* Startup:
@ -833,6 +846,7 @@ gst_dash_demux_stream_loop (GstDashDemux * demux)
guint i = 0;
for (i = 0; i < nb_adaptation_set; i++) {
GstFragment *fragment = g_list_nth_data (listfragment, i);
stream = gst_mpdparser_get_active_stream_by_index (demux->client, i);
if (demux->need_segment) {
GstClockTime start = fragment->start_time + demux->position_shift;
/* And send a newsegment */
@ -849,7 +863,7 @@ gst_dash_demux_stream_loop (GstDashDemux * demux)
buffer_list = gst_fragment_get_buffer_list (fragment);
g_object_unref (fragment);
ret = gst_pad_push_list (demux->srcpad[i], buffer_list);
if (ret != GST_FLOW_OK)
if ((ret != GST_FLOW_OK)&& (stream->mimeType == GST_STREAM_VIDEO))
goto error_pushing;
}
if (GST_STATE (demux) == GST_STATE_PLAYING) {
@ -896,7 +910,7 @@ gst_dash_demux_reset (GstDashDemux * demux, gboolean dispose)
demux->cancelled = FALSE;
guint i = 0;
for (i = 0; i < 3; i++)
for (i = 0; i < MAX_LANGUAGES; i++)
if (demux->input_caps[i]) {
gst_caps_unref (demux->input_caps[i]);
demux->input_caps[i] = NULL;

View file

@ -50,6 +50,7 @@ G_BEGIN_DECLS
//
typedef struct _GstDashDemux GstDashDemux;
typedef struct _GstDashDemuxClass GstDashDemuxClass;
#define MAX_LANGUAGES 20
/**
* GstDashDemux:
*
@ -59,9 +60,9 @@ struct _GstDashDemux
{
GstElement parent;
GstPad *sinkpad;
GstPad *srcpad[3]; /*Video/Audio/Application src pad*/
GstCaps *output_caps[3]; /*Video/Audio/Application output buf caps*/
GstCaps *input_caps[3]; /*Video/Audio/Application input caps*/
GstPad *srcpad[MAX_LANGUAGES]; /*Video/Audio/Application src pad*/
GstCaps *output_caps[MAX_LANGUAGES]; /*Video/Audio/Application output buf caps*/
GstCaps *input_caps[MAX_LANGUAGES]; /*Video/Audio/Application input caps*/
GstBuffer *playlist;
GstUriDownloader *downloader;

View file

@ -2562,7 +2562,7 @@ gst_mpd_client_setup_representation (GstMpdClient * client, GstActiveStream *str
gboolean
gst_mpd_client_setup_streaming (GstMpdClient * client,
GstStreamMimeType mimeType)
GstStreamMimeType mimeType, gchar* lang)
{
GstActiveStream *stream;
GstAdaptationSetNode *adapt_set;
@ -2607,7 +2607,7 @@ gst_mpd_client_setup_streaming (GstMpdClient * client,
#endif
adapt_set =
gst_mpdparser_get_first_adapt_set_with_mimeType_and_lang (client->
cur_period->AdaptationSets, "audio", "en");
cur_period->AdaptationSets, "audio", lang);
/* if we did not found the requested audio language, get the first one */
if (!adapt_set)
adapt_set =
@ -2632,7 +2632,7 @@ gst_mpd_client_setup_streaming (GstMpdClient * client,
#endif
adapt_set =
gst_mpdparser_get_first_adapt_set_with_mimeType_and_lang (client->
cur_period->AdaptationSets, "application", "en");
cur_period->AdaptationSets, "application", lang);
/* if we did not found the requested subtitles language, get the first one */
if (!adapt_set)
adapt_set =
@ -2877,6 +2877,7 @@ guint gst_mpd_client_get_width_of_video_current_stream (GstMpdClient *client, Gs
g_return_val_if_fail (stream != NULL, FALSE);
return stream->cur_representation->RepresentationBase->width;
}
guint gst_mpd_client_get_height_of_video_current_stream (GstMpdClient *client, GstActiveStream *stream){
g_return_val_if_fail (stream != NULL, FALSE);
@ -2886,8 +2887,9 @@ guint gst_mpd_client_get_height_of_video_current_stream (GstMpdClient *client, G
guint gst_mpd_client_get_rate_of_audio_current_stream (GstMpdClient *client, GstActiveStream *stream){
g_return_val_if_fail (stream != NULL, FALSE);
return stream->cur_representation->RepresentationBase->audioSamplingRate;
return (guint) stream->cur_representation->RepresentationBase->audioSamplingRate;
}
guint gst_mpd_client_get_num_channels_of_audio_current_stream (GstMpdClient *client, GstActiveStream *stream){
g_return_val_if_fail (stream != NULL, FALSE);
@ -2895,3 +2897,62 @@ guint gst_mpd_client_get_num_channels_of_audio_current_stream (GstMpdClient *cli
return 1;
}
guint
gst_mpdparser_get_nb_audio_adapt_set(GList * AdaptationSets)
{
GList *list;
GstAdaptationSetNode *adapt_set;
guint nb_adapatation_set = 0;
gchar *this_mimeType = "audio";
gchar *mimeType = NULL;
if (AdaptationSets == NULL)
return 0;
for (list = g_list_first (AdaptationSets); list; list = g_list_next (list)) {
adapt_set = (GstAdaptationSetNode *) list->data;
if (adapt_set) {
GstRepresentationNode *rep;
rep =
gst_mpdparser_get_lowest_representation (adapt_set->Representations);
if (rep->RepresentationBase)
mimeType = rep->RepresentationBase->mimeType;
if (!mimeType && adapt_set->RepresentationBase) {
mimeType = adapt_set->RepresentationBase->mimeType;
}
if (strncmp_ext (mimeType, this_mimeType) == 0)
nb_adapatation_set++;
}
}
return nb_adapatation_set;
}
void gst_mpdparser_get_list_of_audio_language(GList** lang, GList * AdaptationSets)
{
GList *list;
GstAdaptationSetNode *adapt_set;
gchar *this_mimeType = "audio";
gchar *mimeType = NULL;
if (AdaptationSets == NULL)
return ;
for (list = g_list_first (AdaptationSets); list; list = g_list_next (list)) {
adapt_set = (GstAdaptationSetNode *) list->data;
if (adapt_set) {
gchar *this_lang = adapt_set->lang;
GstRepresentationNode *rep;
rep =
gst_mpdparser_get_lowest_representation (adapt_set->Representations);
if (rep->RepresentationBase)
mimeType = rep->RepresentationBase->mimeType;
if (!mimeType && adapt_set->RepresentationBase) {
mimeType = adapt_set->RepresentationBase->mimeType;
}
if (strncmp_ext (mimeType, this_mimeType) == 0){
if(this_lang){
*lang = g_list_append (*lang, this_lang);
}
}
}
}
}

View file

@ -452,7 +452,7 @@ void gst_mpd_client_free (GstMpdClient * client);
/* Basic parsing */
gboolean gst_mpd_parse (GstMpdClient *client, const gchar *data, gint size);
gboolean gst_mpd_client_setup_streaming (GstMpdClient *client, GstStreamMimeType mimeType);
gboolean gst_mpd_client_setup_streaming (GstMpdClient *client, GstStreamMimeType mimeType, gchar* lang);
gboolean gst_mpd_client_setup_representation (GstMpdClient *client, GstActiveStream *stream, GstRepresentationNode *representation);
void gst_mpd_client_get_current_position (GstMpdClient *client, GstClockTime * timestamp);
GstClockTime gst_mpd_client_get_duration (GstMpdClient *client);
@ -483,6 +483,9 @@ guint gst_mpd_client_get_height_of_video_current_stream (GstMpdClient *client,
guint gst_mpd_client_get_rate_of_audio_current_stream (GstMpdClient *client, GstActiveStream *stream);
guint gst_mpd_client_get_num_channels_of_audio_current_stream (GstMpdClient *client, GstActiveStream *stream);
/* To support multi language */
guint gst_mpdparser_get_nb_audio_adapt_set(GList *AdaptationSets);
void gst_mpdparser_get_list_of_audio_language(GList** lang, GList * AdaptationSets);
G_END_DECLS
#endif /* __GST_MPDPARSER_H__ */