mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 05:46:13 +00:00
dashdemux: Fix segfault introduced by segment iteration refactoring (2105a310).
The functions to get the next fragment, next fragment timestamp and to advance to the next fragment need to work differently when stream->segments is NULL. Use logic similar to that introduced by commit 2105a310 to perform these functions. https://bugzilla.gnome.org/show_bug.cgi?id=749684
This commit is contained in:
parent
0910540d58
commit
c4ff5359aa
1 changed files with 123 additions and 57 deletions
|
@ -3580,15 +3580,26 @@ gst_mpd_client_get_next_fragment_timestamp (GstMpdClient * client,
|
||||||
stream = g_list_nth_data (client->active_streams, stream_idx);
|
stream = g_list_nth_data (client->active_streams, stream_idx);
|
||||||
g_return_val_if_fail (stream != NULL, 0);
|
g_return_val_if_fail (stream != NULL, 0);
|
||||||
|
|
||||||
GST_DEBUG ("Looking for fragment sequence chunk %d / %d",
|
if (stream->segments) {
|
||||||
stream->segment_index, stream->segments->len);
|
GST_DEBUG ("Looking for fragment sequence chunk %d / %d",
|
||||||
if (stream->segment_index >= stream->segments->len)
|
stream->segment_index, stream->segments->len);
|
||||||
return FALSE;
|
if (stream->segment_index >= stream->segments->len)
|
||||||
currentChunk = g_ptr_array_index (stream->segments, stream->segment_index);
|
return FALSE;
|
||||||
|
currentChunk = g_ptr_array_index (stream->segments, stream->segment_index);
|
||||||
|
|
||||||
*ts =
|
*ts =
|
||||||
currentChunk->start +
|
currentChunk->start +
|
||||||
(currentChunk->duration * stream->segment_repeat_index);
|
(currentChunk->duration * stream->segment_repeat_index);
|
||||||
|
} else {
|
||||||
|
GstClockTime duration =
|
||||||
|
gst_mpd_client_get_segment_duration (client, stream, NULL);
|
||||||
|
g_return_val_if_fail (stream->cur_seg_template->
|
||||||
|
MultSegBaseType->SegmentTimeline == NULL, FALSE);
|
||||||
|
if (!GST_CLOCK_TIME_IS_VALID (duration)) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
*ts = stream->segment_index * duration;
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -3624,43 +3635,22 @@ gst_mpd_client_get_next_fragment (GstMpdClient * client,
|
||||||
g_return_val_if_fail (stream != NULL, FALSE);
|
g_return_val_if_fail (stream != NULL, FALSE);
|
||||||
g_return_val_if_fail (stream->cur_representation != NULL, FALSE);
|
g_return_val_if_fail (stream->cur_representation != NULL, FALSE);
|
||||||
|
|
||||||
GST_DEBUG ("Looking for fragment sequence chunk %d / %d",
|
if (stream->segments) {
|
||||||
stream->segment_index, stream->segments->len);
|
GST_DEBUG ("Looking for fragment sequence chunk %d / %d",
|
||||||
if (stream->segment_index >= stream->segments->len)
|
stream->segment_index, stream->segments->len);
|
||||||
return FALSE;
|
if (stream->segment_index >= stream->segments->len)
|
||||||
currentChunk = g_ptr_array_index (stream->segments, stream->segment_index);
|
return FALSE;
|
||||||
|
} else {
|
||||||
GST_DEBUG ("currentChunk->SegmentURL = %p", currentChunk->SegmentURL);
|
GstClockTime duration = gst_mpd_client_get_segment_duration (client,
|
||||||
if (currentChunk->SegmentURL != NULL) {
|
stream, NULL);
|
||||||
mediaURL =
|
g_return_val_if_fail (stream->cur_seg_template->
|
||||||
g_strdup (gst_mpdparser_get_mediaURL (stream,
|
MultSegBaseType->SegmentTimeline == NULL, FALSE);
|
||||||
currentChunk->SegmentURL));
|
if (!GST_CLOCK_TIME_IS_VALID (duration)) {
|
||||||
indexURL = currentChunk->SegmentURL->index;
|
return FALSE;
|
||||||
} else if (stream->cur_seg_template != NULL) {
|
|
||||||
mediaURL =
|
|
||||||
gst_mpdparser_build_URL_from_template (stream->cur_seg_template->media,
|
|
||||||
stream->cur_representation->id,
|
|
||||||
currentChunk->number + stream->segment_repeat_index,
|
|
||||||
stream->cur_representation->bandwidth,
|
|
||||||
currentChunk->scale_start +
|
|
||||||
stream->segment_repeat_index * currentChunk->scale_duration);
|
|
||||||
if (stream->cur_seg_template->index) {
|
|
||||||
indexURL =
|
|
||||||
gst_mpdparser_build_URL_from_template (stream->
|
|
||||||
cur_seg_template->index, stream->cur_representation->id,
|
|
||||||
currentChunk->number + stream->segment_repeat_index,
|
|
||||||
stream->cur_representation->bandwidth,
|
|
||||||
currentChunk->scale_start +
|
|
||||||
stream->segment_repeat_index * currentChunk->scale_duration);
|
|
||||||
}
|
}
|
||||||
|
fragment->duration = duration;
|
||||||
}
|
}
|
||||||
GST_DEBUG ("mediaURL = %s", mediaURL);
|
|
||||||
GST_DEBUG ("indexURL = %s", indexURL);
|
|
||||||
|
|
||||||
fragment->timestamp =
|
|
||||||
currentChunk->start +
|
|
||||||
stream->segment_repeat_index * currentChunk->duration;
|
|
||||||
fragment->duration = currentChunk->duration;
|
|
||||||
/* FIXME rework discont checking */
|
/* FIXME rework discont checking */
|
||||||
/* fragment->discontinuity = segment_idx != currentChunk.number; */
|
/* fragment->discontinuity = segment_idx != currentChunk.number; */
|
||||||
fragment->range_start = 0;
|
fragment->range_start = 0;
|
||||||
|
@ -3668,18 +3658,77 @@ gst_mpd_client_get_next_fragment (GstMpdClient * client,
|
||||||
fragment->index_uri = NULL;
|
fragment->index_uri = NULL;
|
||||||
fragment->index_range_start = 0;
|
fragment->index_range_start = 0;
|
||||||
fragment->index_range_end = -1;
|
fragment->index_range_end = -1;
|
||||||
if (currentChunk->SegmentURL) {
|
|
||||||
if (currentChunk->SegmentURL->mediaRange) {
|
if (stream->segments) {
|
||||||
fragment->range_start =
|
currentChunk = g_ptr_array_index (stream->segments, stream->segment_index);
|
||||||
currentChunk->SegmentURL->mediaRange->first_byte_pos;
|
|
||||||
fragment->range_end = currentChunk->SegmentURL->mediaRange->last_byte_pos;
|
GST_DEBUG ("currentChunk->SegmentURL = %p", currentChunk->SegmentURL);
|
||||||
|
if (currentChunk->SegmentURL != NULL) {
|
||||||
|
mediaURL =
|
||||||
|
g_strdup (gst_mpdparser_get_mediaURL (stream,
|
||||||
|
currentChunk->SegmentURL));
|
||||||
|
indexURL = currentChunk->SegmentURL->index;
|
||||||
|
} else if (stream->cur_seg_template != NULL) {
|
||||||
|
mediaURL =
|
||||||
|
gst_mpdparser_build_URL_from_template (stream->
|
||||||
|
cur_seg_template->media, stream->cur_representation->id,
|
||||||
|
currentChunk->number + stream->segment_repeat_index,
|
||||||
|
stream->cur_representation->bandwidth,
|
||||||
|
currentChunk->scale_start +
|
||||||
|
stream->segment_repeat_index * currentChunk->scale_duration);
|
||||||
|
if (stream->cur_seg_template->index) {
|
||||||
|
indexURL =
|
||||||
|
gst_mpdparser_build_URL_from_template (stream->
|
||||||
|
cur_seg_template->index, stream->cur_representation->id,
|
||||||
|
currentChunk->number + stream->segment_repeat_index,
|
||||||
|
stream->cur_representation->bandwidth,
|
||||||
|
currentChunk->scale_start +
|
||||||
|
stream->segment_repeat_index * currentChunk->scale_duration);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (currentChunk->SegmentURL->indexRange) {
|
GST_DEBUG ("mediaURL = %s", mediaURL);
|
||||||
fragment->index_range_start =
|
GST_DEBUG ("indexURL = %s", indexURL);
|
||||||
currentChunk->SegmentURL->indexRange->first_byte_pos;
|
|
||||||
fragment->index_range_end =
|
fragment->timestamp =
|
||||||
currentChunk->SegmentURL->indexRange->last_byte_pos;
|
currentChunk->start +
|
||||||
|
stream->segment_repeat_index * currentChunk->duration;
|
||||||
|
fragment->duration = currentChunk->duration;
|
||||||
|
if (currentChunk->SegmentURL) {
|
||||||
|
if (currentChunk->SegmentURL->mediaRange) {
|
||||||
|
fragment->range_start =
|
||||||
|
currentChunk->SegmentURL->mediaRange->first_byte_pos;
|
||||||
|
fragment->range_end =
|
||||||
|
currentChunk->SegmentURL->mediaRange->last_byte_pos;
|
||||||
|
}
|
||||||
|
if (currentChunk->SegmentURL->indexRange) {
|
||||||
|
fragment->index_range_start =
|
||||||
|
currentChunk->SegmentURL->indexRange->first_byte_pos;
|
||||||
|
fragment->index_range_end =
|
||||||
|
currentChunk->SegmentURL->indexRange->last_byte_pos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (stream->cur_seg_template != NULL) {
|
||||||
|
mediaURL =
|
||||||
|
gst_mpdparser_build_URL_from_template (stream->
|
||||||
|
cur_seg_template->media, stream->cur_representation->id,
|
||||||
|
stream->segment_index, stream->cur_representation->bandwidth,
|
||||||
|
stream->segment_index * fragment->duration);
|
||||||
|
if (stream->cur_seg_template->index) {
|
||||||
|
indexURL =
|
||||||
|
gst_mpdparser_build_URL_from_template (stream->
|
||||||
|
cur_seg_template->index, stream->cur_representation->id,
|
||||||
|
stream->segment_index, stream->cur_representation->bandwidth,
|
||||||
|
stream->segment_index * fragment->duration);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_DEBUG ("mediaURL = %s", mediaURL);
|
||||||
|
GST_DEBUG ("indexURL = %s", indexURL);
|
||||||
|
|
||||||
|
fragment->timestamp = stream->segment_index * fragment->duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
base_url = gst_uri_from_string (stream->baseURL);
|
base_url = gst_uri_from_string (stream->baseURL);
|
||||||
|
@ -3725,6 +3774,8 @@ gst_mpd_client_has_next_segment (GstMpdClient * client,
|
||||||
GstActiveStream * stream, gboolean forward)
|
GstActiveStream * stream, gboolean forward)
|
||||||
{
|
{
|
||||||
if (forward) {
|
if (forward) {
|
||||||
|
if (stream->segments == NULL)
|
||||||
|
return TRUE;
|
||||||
if (stream->segment_index >= stream->segments->len)
|
if (stream->segment_index >= stream->segments->len)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
} else {
|
} else {
|
||||||
|
@ -3740,13 +3791,22 @@ gst_mpd_client_advance_segment (GstMpdClient * client, GstActiveStream * stream,
|
||||||
gboolean forward)
|
gboolean forward)
|
||||||
{
|
{
|
||||||
GstMediaSegment *segment;
|
GstMediaSegment *segment;
|
||||||
|
guint segments_count = gst_mpd_client_get_segments_counts (stream);
|
||||||
|
|
||||||
GST_DEBUG ("Advancing segment. Current: %d / %d r:%d", stream->segment_index,
|
GST_DEBUG ("Advancing segment. Current: %d / %d r:%d", stream->segment_index,
|
||||||
stream->segments->len, stream->segment_repeat_index);
|
segments_count, stream->segment_repeat_index);
|
||||||
|
|
||||||
/* handle special cases first */
|
/* handle special cases first */
|
||||||
if (forward) {
|
if (forward) {
|
||||||
if (stream->segment_index >= stream->segments->len)
|
if (stream->segments == NULL) {
|
||||||
|
if (stream->segment_index < 0)
|
||||||
|
stream->segment_index = 0;
|
||||||
|
else
|
||||||
|
stream->segment_index++;
|
||||||
|
return GST_FLOW_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stream->segment_index >= segments_count)
|
||||||
return GST_FLOW_EOS;
|
return GST_FLOW_EOS;
|
||||||
|
|
||||||
/* special case for when playback direction is reverted right at *
|
/* special case for when playback direction is reverted right at *
|
||||||
|
@ -3756,13 +3816,19 @@ gst_mpd_client_advance_segment (GstMpdClient * client, GstActiveStream * stream,
|
||||||
return GST_FLOW_OK;
|
return GST_FLOW_OK;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (stream->segment_index < 0)
|
if (stream->segments == NULL)
|
||||||
|
stream->segment_index--;
|
||||||
|
if (stream->segment_index < 0) {
|
||||||
|
stream->segment_index = -1;
|
||||||
return GST_FLOW_EOS;
|
return GST_FLOW_EOS;
|
||||||
|
}
|
||||||
|
if (stream->segments == NULL)
|
||||||
|
return GST_FLOW_OK;
|
||||||
|
|
||||||
/* special case for when playback direction is reverted right at *
|
/* special case for when playback direction is reverted right at *
|
||||||
* the end of the segment list */
|
* the end of the segment list */
|
||||||
if (stream->segment_index >= stream->segments->len) {
|
if (stream->segment_index >= segments_count) {
|
||||||
stream->segment_index = stream->segments->len - 1;
|
stream->segment_index = segments_count - 1;
|
||||||
segment = g_ptr_array_index (stream->segments, stream->segment_index);
|
segment = g_ptr_array_index (stream->segments, stream->segment_index);
|
||||||
stream->segment_repeat_index = segment->repeat;
|
stream->segment_repeat_index = segment->repeat;
|
||||||
return GST_FLOW_OK;
|
return GST_FLOW_OK;
|
||||||
|
|
Loading…
Reference in a new issue