dashdemux: new API to set/get segment index and period index

TODO: rework segment selection to support Representations or Adaptation Sets with segments not aligned
This commit is contained in:
Gianluca Gennari 2012-12-17 15:04:45 +01:00 committed by Thiago Santos
parent e7fad847bb
commit 7371b7997b
3 changed files with 42 additions and 18 deletions

View file

@ -525,10 +525,10 @@ gst_dash_demux_src_event (GstPad * pad, GstEvent * event)
GST_WARNING_OBJECT (demux, "Could not find seeked Period");
return FALSE;
}
if (current_period != demux->client->period_idx) {
if (current_period != gst_mpd_client_get_period_index (demux->client)) {
GST_DEBUG_OBJECT (demux, "Seeking to Period %d", current_period);
/* setup video, audio and subtitle streams, starting from the new Period */
if (!gst_mpd_client_get_period_by_index (demux->client, current_period) ||
if (!gst_mpd_client_set_period_index (demux->client, current_period) ||
!gst_dash_demux_setup_all_streams (demux))
return FALSE;
}
@ -582,8 +582,7 @@ gst_dash_demux_src_event (GstPad * pad, GstEvent * event)
stream =
gst_mpdparser_get_active_stream_by_index (demux->client,
stream_idx);
/* FIXME: we should'nt fiddle with stream internals like that */
stream->segment_idx = current_sequence;
gst_mpd_client_set_segment_index (stream, current_sequence);
}
/* Calculate offset in the next fragment */
demux->position = gst_mpd_client_get_current_position (demux->client);
@ -708,7 +707,7 @@ gst_dash_demux_sink_event (GstPad * pad, GstEvent * event)
}
/* setup video, audio and subtitle streams, starting from first Period */
if (!gst_mpd_client_get_period_by_index (demux->client, 0) ||
if (!gst_mpd_client_set_period_index (demux->client, 0) ||
!gst_dash_demux_setup_all_streams (demux))
return FALSE;
@ -1197,7 +1196,7 @@ gst_dash_demux_download_loop (GstDashDemux * demux)
if (demux->end_of_period) {
GST_INFO_OBJECT (demux, "Reached the end of the Period");
/* setup video, audio and subtitle streams, starting from the next Period */
if (!gst_mpd_client_get_period_by_index (demux->client, demux->client->period_idx + 1) ||
if (!gst_mpd_client_set_period_index (demux->client, gst_mpd_client_get_period_index (demux->client) + 1) ||
!gst_dash_demux_setup_all_streams (demux)) {
GST_INFO_OBJECT (demux, "Reached the end of the manifest file");
demux->end_of_manifest = TRUE;
@ -1568,8 +1567,8 @@ gst_dash_demux_get_next_fragment_set (GstDashDemux * demux)
gst_mpdparser_get_active_stream_by_index (demux->client, stream_idx);
if (stream == NULL)
return FALSE;
/* FIXME: we should'nt fiddle with stream internals like that */
download->index = stream->segment_idx - 1;
download->index = gst_mpd_client_get_segment_index (stream) - 1;
GstCaps *caps = gst_dash_demux_get_input_caps (demux, stream);

View file

@ -2258,7 +2258,7 @@ gst_mpdparser_get_stream_period (GstMpdClient * client)
g_return_val_if_fail (client != NULL, NULL);
g_return_val_if_fail (client->periods != NULL, NULL);
return g_list_nth_data (client->periods, client->period_idx);
return g_list_nth_data (client->periods, gst_mpd_client_get_period_index (client));
}
/* select a stream and extract the baseURL (if present) */
@ -2880,8 +2880,8 @@ gst_mpd_client_setup_streaming (GstMpdClient * client,
stream->baseURL_idx = 0;
stream->mimeType = mimeType;
stream->representation_idx = 0;
stream->segment_idx = 0;
stream->cur_adapt_set = adapt_set;
gst_mpd_client_set_segment_index (stream, 0);
/* retrive representation list */
if (stream->cur_adapt_set != NULL)
@ -2925,6 +2925,7 @@ gst_mpd_client_get_next_fragment (GstMpdClient * client,
GstActiveStream *stream = NULL;
GstMediaSegment *currentChunk;
gchar *mediaURL = NULL;
guint segment_idx;
/* select stream */
g_return_val_if_fail (client != NULL, FALSE);
@ -2935,9 +2936,10 @@ gst_mpd_client_get_next_fragment (GstMpdClient * client,
g_return_val_if_fail (discontinuity != NULL, FALSE);
GST_MPD_CLIENT_LOCK (client);
GST_DEBUG ("Looking for fragment sequence chunk %d", stream->segment_idx);
segment_idx = gst_mpd_client_get_segment_index (stream);
GST_DEBUG ("Looking for fragment sequence chunk %d", segment_idx);
currentChunk = gst_mpdparser_get_chunk_by_index (client, indexStream, stream->segment_idx);
currentChunk = gst_mpdparser_get_chunk_by_index (client, indexStream, segment_idx);
if (currentChunk == NULL) {
GST_MPD_CLIENT_UNLOCK (client);
return FALSE;
@ -2952,7 +2954,7 @@ gst_mpd_client_get_next_fragment (GstMpdClient * client,
*timestamp = currentChunk->start_time;
*duration = currentChunk->duration;
*discontinuity = stream->segment_idx != currentChunk->number;
*discontinuity = segment_idx != currentChunk->number;
if (mediaURL == NULL) {
/* single segment with URL encoded in the baseURL syntax element */
*uri = g_strdup (gst_mpdparser_get_baseURL (client));
@ -2962,7 +2964,7 @@ gst_mpd_client_get_next_fragment (GstMpdClient * client,
} else {
*uri = mediaURL;
}
stream->segment_idx += 1;
gst_mpd_client_set_segment_index (stream, segment_idx + 1);
GST_MPD_CLIENT_UNLOCK (client);
GST_DEBUG ("Loading chunk with URL %s", *uri);
@ -3014,7 +3016,7 @@ gst_mpd_client_get_current_position (GstMpdClient * client)
stream = g_list_nth_data (client->active_streams, client->stream_idx);
g_return_val_if_fail (stream != NULL, GST_CLOCK_TIME_NONE);
media_segment = g_list_nth_data (stream->segments, stream->segment_idx);
media_segment = g_list_nth_data (stream->segments, gst_mpd_client_get_segment_index (stream));
g_return_val_if_fail (media_segment != NULL, GST_CLOCK_TIME_NONE);
return media_segment->start_time;
@ -3029,7 +3031,7 @@ gst_mpd_client_get_next_fragment_duration (GstMpdClient * client)
stream = g_list_nth_data (client->active_streams, client->stream_idx);
g_return_val_if_fail (stream != NULL, 0);
media_segment = g_list_nth_data (stream->segments, stream->segment_idx);
media_segment = g_list_nth_data (stream->segments, gst_mpd_client_get_segment_index (stream));
return media_segment == NULL ? 0 : media_segment->duration;
}
@ -3054,7 +3056,7 @@ gst_mpd_client_get_media_presentation_duration (GstMpdClient * client)
}
gboolean
gst_mpd_client_get_period_by_index (GstMpdClient *client, guint period_idx)
gst_mpd_client_set_period_index (GstMpdClient *client, guint period_idx)
{
GstStreamPeriod *next_stream_period;
@ -3070,6 +3072,24 @@ gst_mpd_client_get_period_by_index (GstMpdClient *client, guint period_idx)
return TRUE;
}
guint
gst_mpd_client_get_period_index (GstMpdClient *client)
{
return client->period_idx;
}
void
gst_mpd_client_set_segment_index (GstActiveStream * stream, guint segment_idx)
{
stream->segment_idx = segment_idx;
}
guint
gst_mpd_client_get_segment_index (GstActiveStream * stream)
{
return stream->segment_idx;
}
gboolean
gst_mpd_client_is_live (GstMpdClient * client)
{

View file

@ -475,7 +475,8 @@ gboolean gst_mpd_client_get_next_header (GstMpdClient *client, const gchar **uri
gboolean gst_mpd_client_is_live (GstMpdClient * client);
/* Period selection */
gboolean gst_mpd_client_get_period_by_index (GstMpdClient *client, guint period_idx);
gboolean gst_mpd_client_set_period_index (GstMpdClient *client, guint period_idx);
guint gst_mpd_client_get_period_index (GstMpdClient *client);
/* Representation selection */
gint gst_mpdparser_get_rep_idx_with_max_bandwidth (GList *Representations, gint max_bandwidth);
@ -491,6 +492,10 @@ GstActiveStream *gst_mpdparser_get_active_stream_by_index (GstMpdClient *client,
/* AdaptationSet */
guint gst_mpdparser_get_nb_adaptationSet (GstMpdClient *client);
/* Segment */
void gst_mpd_client_set_segment_index (GstActiveStream * stream, guint segment_idx);
guint gst_mpd_client_get_segment_index (GstActiveStream * stream);
/* 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);