Skip to content

Commit

Permalink
dash_period_find return period index(same as dash_representation_find)
Browse files Browse the repository at this point in the history
  • Loading branch information
ireader committed Jun 6, 2020
1 parent d0742b3 commit e70ab62
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 15 deletions.
12 changes: 6 additions & 6 deletions libdash/include/dash-parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,9 @@ int dash_mpd_free(struct dash_mpd_t** mpd);
/// Period

/// location period by time
/// @param[in] now play time
/// @return NULL if don't find period
const struct dash_period_t* dash_period_find(const struct dash_mpd_t* mpd, int64_t now);
/// @param[in] time from previous period end to current perid end, range: (period-m-end, period-n-end]
/// @return >=0-period index, -1-if don't find, other-undefined
int dash_period_find(const struct dash_mpd_t* mpd, int64_t time);

/// @param[in] media DASH_MEDIA_AUDIO/DASH_MEDIA_VIDEO/xxx
/// @param[in] id adaptation set id, 0 if unknown
Expand All @@ -454,9 +454,9 @@ const struct dash_url_t* dash_representation_get_base_url(const struct dash_repr
const struct dash_segment_t* dash_representation_get_segment(const struct dash_representation_t* representation);

/// Find segment by start time
/// @param[in] start segment start time
/// @return -1-not found, >=0-segment item index
int dash_representation_find(const struct dash_representation_t* representation, int64_t start);
/// @param[in] time segment time, range: (previous segment end, segment start + duration)
/// @return -1-not found, >=0-segment item index(index is not the startnumber)
int dash_representation_find(const struct dash_representation_t* representation, int64_t time);

/// @return -1-segment template, >=0-segment count
int dash_segment_count(const struct dash_segment_t* segment);
Expand Down
28 changes: 25 additions & 3 deletions libdash/src/dash-period.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,38 @@
#include <assert.h>
#include "cstringext.h"

const struct dash_period_t* dash_period_find(const struct dash_mpd_t* mpd, int64_t now)
int dash_period_find(const struct dash_mpd_t* mpd, int64_t time)
{
size_t i;
int64_t t, start;
const struct dash_period_t* period;

if (1 == mpd->period_count)
return 0; // only one period

t = 0;
for (i = 0; i < mpd->period_count; i++)
{
// 5.3.2.1 Overview (p27)
// 1. If the attribute @start is present in the Period, then the Period
// is a regular Period or an earlyterminated Period and the PeriodStart
// is equal to the value of this attribute.
// 2. If the @start attribute is absent, but the previous Period element
// contains a @duration attributethen this new Period is also a regular
// Period or an early terminated Period. The start time of the new Period
// PeriodStart is the sum of the start time of the previous Period PeriodStart
// and the value of the attribute @duration of the previous Period.
// 3. If (i) @start attribute is absent, and (ii) the Period element is the
// first in the MPD, and (iii) the MPD@type is 'static', then the PeriodStart
// time shall be set to zero
// 4. If (i) @start attribute is absent, and (ii) the previous Period element does
// not contain a @durationattribute or the Period element is the first in the
// MPD, and (iii) the MPD@type is 'dynamic', then thisPeriod is an Early Available
// Period (see below for details)
// 5. If (i) @duration attribute is present, and (ii) the next Period element contains
// a @start attribute orthe @minimumUpdatePeriod is present, then this Period
// is an Early Terminated Period (see below for details)

period = &mpd->periods[i];
if (period->start > 0)
{
Expand Down Expand Up @@ -59,11 +81,11 @@ const struct dash_period_t* dash_period_find(const struct dash_mpd_t* mpd, int64
t = start; // ???
}

if (start <= now && now <= t)
if (time < t)
return period;
}

return mpd->period_count > 0 ? &mpd->periods[mpd->period_count - 1] : NULL;
return -1; // not found
}

const struct dash_adaptation_set_t* dash_period_select(const struct dash_period_t* period, int media, unsigned int id, unsigned int group, const char* lang, const char* codecs)
Expand Down
6 changes: 3 additions & 3 deletions libdash/src/dash-representation.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const struct dash_segment_t* dash_representation_get_segment(const struct dash_r
return &representation->segment;
}

int dash_representation_find(const struct dash_representation_t* representation, int64_t start)
int dash_representation_find(const struct dash_representation_t* representation, int64_t time)
{
int r, n, i, mid;
int64_t number, t, d;
Expand All @@ -62,9 +62,9 @@ int dash_representation_find(const struct dash_representation_t* representation,
if (0 != r)
return r;

if (start < t)
if (time < t)
n = mid;
else if (start > t + d)
else if (time > t + d)
i = mid + 1;
else
break;
Expand Down
4 changes: 3 additions & 1 deletion libdash/src/dash-segment.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int dash_segment_timeline(const struct dash_segment_timeline_t* timeline, size_t
*number = timeline->S[i].n + (index - j);
*start = (timeline->S[i].t ? timeline->S[i].t : t) + (index - j) * timeline->S[i].d;
*duration = timeline->S[i].d;
break;
return 0;
}

j += step;
Expand Down Expand Up @@ -134,6 +134,8 @@ int dash_segment_information(const struct dash_segment_t* segment, size_t index,
if (segment->segment_timeline.count > 0)
{
r = dash_segment_timeline(&segment->segment_timeline, index, number, start, duration);
if (0 != r)
return -1;
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions libhls/source/hls-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ int hls_master_parse(struct hls_master_t** master, const char* m3u8, size_t len)
r = hls_parser_input(&parser, ptr, len);
if (0 != r)
{
free(parser.master);
hls_master_free(&parser.master);
return r;
}

Expand All @@ -711,7 +711,7 @@ int hls_playlist_parse(struct hls_playlist_t** playlist, const char* m3u8, size_
r = hls_parser_input(&parser, ptr, len);
if (0 != r)
{
free(parser.playlist);
hls_playlist_free(&parser.playlist);
return r;
}

Expand Down

0 comments on commit e70ab62

Please sign in to comment.