/*
* Each variant has its own demuxer. If it currently is active,
- * it has an open ByteIOContext too, and potentially an AVPacket
+ * it has an open AVIOContext too, and potentially an AVPacket
* containing the next packet from this stream.
*/
struct variant {
int bandwidth;
char url[MAX_URL_SIZE];
- ByteIOContext *pb;
+ AVIOContext *pb;
AVFormatContext *ctx;
AVPacket pkt;
int stream_offset;
int max_start_seq, min_end_seq;
} AppleHTTPContext;
-static int read_chomp_line(ByteIOContext *s, char *buf, int maxlen)
+static int read_chomp_line(AVIOContext *s, char *buf, int maxlen)
{
int len = ff_get_line(s, buf, maxlen);
while (len > 0 && isspace(buf[len - 1]))
return len;
}
-static void make_absolute_url(char *buf, int size, const char *base,
- const char *rel)
-{
- char *sep;
- if (!base || strstr(rel, "://")) {
- av_strlcpy(buf, rel, size);
- return;
- }
- if (base != buf)
- av_strlcpy(buf, base, size);
- sep = strrchr(buf, '/');
- if (sep)
- sep[1] = '\0';
- while (av_strstart(rel, "../", NULL)) {
- if (sep) {
- sep[0] = '\0';
- sep = strrchr(buf, '/');
- if (sep)
- sep[1] = '\0';
- }
- rel += 3;
- }
- av_strlcat(buf, rel, size);
-}
-
static void free_segment_list(struct variant *var)
{
int i;
free_segment_list(var);
av_free_packet(&var->pkt);
if (var->pb)
- url_fclose(var->pb);
+ avio_close(var->pb);
if (var->ctx) {
var->ctx->pb = NULL;
av_close_input_file(var->ctx);
return NULL;
reset_packet(&var->pkt);
var->bandwidth = bandwidth;
- make_absolute_url(var->url, sizeof(var->url), base, url);
+ ff_make_absolute_url(var->url, sizeof(var->url), base, url);
dynarray_add(&c->variants, &c->n_variants, var);
return var;
}
static void handle_variant_args(struct variant_info *info, const char *key,
int key_len, char **dest, int *dest_len)
{
- if (strncmp(key, "BANDWIDTH", key_len)) {
+ if (!strncmp(key, "BANDWIDTH=", key_len)) {
*dest = info->bandwidth;
*dest_len = sizeof(info->bandwidth);
}
}
static int parse_playlist(AppleHTTPContext *c, const char *url,
- struct variant *var, ByteIOContext *in)
+ struct variant *var, AVIOContext *in)
{
int ret = 0, duration = 0, is_segment = 0, is_variant = 0, bandwidth = 0;
char line[1024];
if (!in) {
close_in = 1;
- if ((ret = url_fopen(&in, url, URL_RDONLY)) < 0)
+ if ((ret = avio_open(&in, url, URL_RDONLY)) < 0)
return ret;
}
goto fail;
}
seg->duration = duration;
- make_absolute_url(seg->url, sizeof(seg->url), url, line);
+ ff_make_absolute_url(seg->url, sizeof(seg->url), url, line);
dynarray_add(&var->segments, &var->n_segments, seg);
is_segment = 0;
}
fail:
if (close_in)
- url_fclose(in);
+ avio_close(in);
return ret;
}
/* If this isn't a live stream, calculate the total duration of the
* stream. */
if (c->finished) {
- int duration = 0;
+ int64_t duration = 0;
for (i = 0; i < c->variants[0]->n_segments; i++)
duration += c->variants[0]->segments[i]->duration;
s->duration = duration * AV_TIME_BASE;
ret = av_open_input_file(&v->ctx, v->segments[0]->url, NULL, 0, NULL);
if (ret < 0)
goto fail;
- url_fclose(v->ctx->pb);
+ avio_close(v->ctx->pb);
v->ctx->pb = NULL;
v->stream_offset = stream_offset;
/* Create new AVStreams for each stream in this variant */
}
if (c->cur_seq_no - var->start_seq_no >= var->n_segments)
return c->finished ? AVERROR_EOF : 0;
- ret = url_fopen(&var->pb,
+ ret = avio_open(&var->pb,
var->segments[c->cur_seq_no - var->start_seq_no]->url,
URL_RDONLY);
if (ret < 0)
"Closing variant stream %d, no longer needed\n", i);
av_free_packet(&var->pkt);
reset_packet(&var->pkt);
- url_fclose(var->pb);
+ avio_close(var->pb);
var->pb = NULL;
changed = 1;
} else if (!var->pb && var->needed) {
for (i = 0; i < c->n_variants; i++) {
struct variant *var = c->variants[i];
if (var->pb) {
- url_fclose(var->pb);
+ avio_close(var->pb);
var->pb = NULL;
}
}
c->max_start_seq - c->cur_seq_no);
c->cur_seq_no = c->max_start_seq;
}
- /* If more segments exit, open the next one */
+ /* If more segments exist, open the next one */
if (c->cur_seq_no < c->min_end_seq)
goto start;
/* We've reached the end of the playlists - return eof if this is a
return AVERROR_EOF;
while (av_gettime() - c->last_load_time < c->target_duration*1000000) {
if (url_interrupt_cb())
- return AVERROR(EINTR);
+ return AVERROR_EXIT;
usleep(100*1000);
}
/* Enough time has elapsed since the last reload */
int64_t timestamp, int flags)
{
AppleHTTPContext *c = s->priv_data;
- int pos = 0, i;
+ int64_t pos = 0;
+ int i;
struct variant *var = c->variants[0];
if ((flags & AVSEEK_FLAG_BYTE) || !c->finished)
for (i = 0; i < c->n_variants; i++) {
struct variant *var = c->variants[i];
if (var->pb) {
- url_fclose(var->pb);
+ avio_close(var->pb);
var->pb = NULL;
}
av_free_packet(&var->pkt);
return 0;
}
-AVInputFormat applehttp_demuxer = {
+AVInputFormat ff_applehttp_demuxer = {
"applehttp",
NULL_IF_CONFIG_SMALL("Apple HTTP Live Streaming format"),
sizeof(AppleHTTPContext),