mirror of https://git.ffmpeg.org/ffmpeg.git
hlsproto: Store all durations in AV_TIME_BASE
Also parse segment durations as floating point, which is allowed since HLS version 3. Signed-off-by: Martin Storsjö <martin@martin.st>
This commit is contained in:
parent
c441910399
commit
a2b7eeeb06
|
@ -45,7 +45,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct segment {
|
struct segment {
|
||||||
int duration;
|
int64_t duration;
|
||||||
char url[MAX_URL_SIZE];
|
char url[MAX_URL_SIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ struct variant {
|
||||||
|
|
||||||
typedef struct HLSContext {
|
typedef struct HLSContext {
|
||||||
char playlisturl[MAX_URL_SIZE];
|
char playlisturl[MAX_URL_SIZE];
|
||||||
int target_duration;
|
int64_t target_duration;
|
||||||
int start_seq_no;
|
int start_seq_no;
|
||||||
int finished;
|
int finished;
|
||||||
int n_segments;
|
int n_segments;
|
||||||
|
@ -111,7 +111,8 @@ static int parse_playlist(URLContext *h, const char *url)
|
||||||
{
|
{
|
||||||
HLSContext *s = h->priv_data;
|
HLSContext *s = h->priv_data;
|
||||||
AVIOContext *in;
|
AVIOContext *in;
|
||||||
int ret = 0, duration = 0, is_segment = 0, is_variant = 0, bandwidth = 0;
|
int ret = 0, is_segment = 0, is_variant = 0, bandwidth = 0;
|
||||||
|
int64_t duration = 0;
|
||||||
char line[1024];
|
char line[1024];
|
||||||
const char *ptr;
|
const char *ptr;
|
||||||
|
|
||||||
|
@ -134,14 +135,14 @@ static int parse_playlist(URLContext *h, const char *url)
|
||||||
&info);
|
&info);
|
||||||
bandwidth = atoi(info.bandwidth);
|
bandwidth = atoi(info.bandwidth);
|
||||||
} else if (av_strstart(line, "#EXT-X-TARGETDURATION:", &ptr)) {
|
} else if (av_strstart(line, "#EXT-X-TARGETDURATION:", &ptr)) {
|
||||||
s->target_duration = atoi(ptr);
|
s->target_duration = atoi(ptr) * AV_TIME_BASE;
|
||||||
} else if (av_strstart(line, "#EXT-X-MEDIA-SEQUENCE:", &ptr)) {
|
} else if (av_strstart(line, "#EXT-X-MEDIA-SEQUENCE:", &ptr)) {
|
||||||
s->start_seq_no = atoi(ptr);
|
s->start_seq_no = atoi(ptr);
|
||||||
} else if (av_strstart(line, "#EXT-X-ENDLIST", &ptr)) {
|
} else if (av_strstart(line, "#EXT-X-ENDLIST", &ptr)) {
|
||||||
s->finished = 1;
|
s->finished = 1;
|
||||||
} else if (av_strstart(line, "#EXTINF:", &ptr)) {
|
} else if (av_strstart(line, "#EXTINF:", &ptr)) {
|
||||||
is_segment = 1;
|
is_segment = 1;
|
||||||
duration = atoi(ptr);
|
duration = atof(ptr) * AV_TIME_BASE;
|
||||||
} else if (av_strstart(line, "#", NULL)) {
|
} else if (av_strstart(line, "#", NULL)) {
|
||||||
continue;
|
continue;
|
||||||
} else if (line[0]) {
|
} else if (line[0]) {
|
||||||
|
@ -270,7 +271,6 @@ start:
|
||||||
reload_interval = s->n_segments > 0 ?
|
reload_interval = s->n_segments > 0 ?
|
||||||
s->segments[s->n_segments - 1]->duration :
|
s->segments[s->n_segments - 1]->duration :
|
||||||
s->target_duration;
|
s->target_duration;
|
||||||
reload_interval *= 1000000;
|
|
||||||
retry:
|
retry:
|
||||||
if (!s->finished) {
|
if (!s->finished) {
|
||||||
int64_t now = av_gettime();
|
int64_t now = av_gettime();
|
||||||
|
@ -280,7 +280,7 @@ retry:
|
||||||
/* If we need to reload the playlist again below (if
|
/* If we need to reload the playlist again below (if
|
||||||
* there's still no more segments), switch to a reload
|
* there's still no more segments), switch to a reload
|
||||||
* interval of half the target duration. */
|
* interval of half the target duration. */
|
||||||
reload_interval = s->target_duration * 500000;
|
reload_interval = s->target_duration / 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (s->cur_seq_no < s->start_seq_no) {
|
if (s->cur_seq_no < s->start_seq_no) {
|
||||||
|
|
Loading…
Reference in New Issue