* http://tools.ietf.org/html/draft-pantos-http-live-streaming
*/
-#define _XOPEN_SOURCE 600
#include "libavutil/avstring.h"
#include "avformat.h"
#include "internal.h"
+#include "url.h"
#include <unistd.h>
/*
return len;
}
-static void make_absolute_url(char *buf, int size, const char *base,
- const char *rel)
-{
- char *sep;
- /* Absolute path, relative to the current server */
- if (base && strstr(base, "://") && rel[0] == '/') {
- if (base != buf)
- av_strlcpy(buf, base, size);
- sep = strstr(buf, "://");
- if (sep) {
- sep += 3;
- sep = strchr(sep, '/');
- if (sep)
- *sep = '\0';
- }
- av_strlcat(buf, rel, size);
- return;
- }
- /* If rel actually is an absolute url, just copy it */
- if (!base || strstr(rel, "://") || rel[0] == '/') {
- av_strlcpy(buf, rel, size);
- return;
- }
- if (base != buf)
- av_strlcpy(buf, base, size);
- /* Remove the file name from the base url */
- sep = strrchr(buf, '/');
- if (sep)
- sep[1] = '\0';
- else
- buf[0] = '\0';
- while (av_strstart(rel, "../", NULL) && sep) {
- /* Remove the path delimiter at the end */
- sep[0] = '\0';
- sep = strrchr(buf, '/');
- /* If the next directory name to pop off is "..", break here */
- if (!strcmp(sep ? &sep[1] : buf, "..")) {
- /* Readd the slash we just removed */
- av_strlcat(buf, "/", size);
- break;
- }
- /* Cut off the directory name */
- if (sep)
- sep[1] = '\0';
- else
- buf[0] = '\0';
- rel += 3;
- }
- av_strlcat(buf, rel, size);
-}
-
static void free_segment_list(AppleHTTPContext *s)
{
int i;
char line[1024];
const char *ptr;
- if ((ret = avio_open(&in, url, URL_RDONLY)) < 0)
+ if ((ret = avio_open(&in, url, AVIO_FLAG_READ)) < 0)
return ret;
read_chomp_line(in, line, sizeof(line));
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(&s->segments, &s->n_segments, seg);
is_segment = 0;
} else if (is_variant) {
goto fail;
}
var->bandwidth = bandwidth;
- make_absolute_url(var->url, sizeof(var->url), url, line);
+ ff_make_absolute_url(var->url, sizeof(var->url), url, line);
dynarray_add(&s->variants, &s->n_variants, var);
is_variant = 0;
}
int ret, i;
const char *nested_url;
- if (flags & (URL_WRONLY | URL_RDWR))
- return AVERROR_NOTSUPP;
+ if (flags & AVIO_FLAG_WRITE)
+ return AVERROR(ENOSYS);
s = av_mallocz(sizeof(AppleHTTPContext));
if (!s)
av_strlcpy(s->playlisturl, "http://", sizeof(s->playlisturl));
av_strlcat(s->playlisturl, nested_url, sizeof(s->playlisturl));
} else {
- av_log(NULL, AV_LOG_ERROR, "Unsupported url %s\n", uri);
+ av_log(h, AV_LOG_ERROR, "Unsupported url %s\n", uri);
ret = AVERROR(EINVAL);
goto fail;
}
}
if (s->n_segments == 0) {
- av_log(NULL, AV_LOG_WARNING, "Empty playlist\n");
+ av_log(h, AV_LOG_WARNING, "Empty playlist\n");
ret = AVERROR(EIO);
goto fail;
}
start:
if (s->seg_hd) {
- ret = url_read(s->seg_hd, buf, size);
+ ret = ffurl_read(s->seg_hd, buf, size);
if (ret > 0)
return ret;
}
if (s->seg_hd) {
- url_close(s->seg_hd);
+ ffurl_close(s->seg_hd);
s->seg_hd = NULL;
s->cur_seq_no++;
}
return ret;
}
if (s->cur_seq_no < s->start_seq_no) {
- av_log(NULL, AV_LOG_WARNING,
+ av_log(h, AV_LOG_WARNING,
"skipping %d segments ahead, expired from playlist\n",
s->start_seq_no - s->cur_seq_no);
s->cur_seq_no = s->start_seq_no;
return AVERROR_EOF;
while (av_gettime() - s->last_load_time < s->target_duration*1000000) {
if (url_interrupt_cb())
- return AVERROR(EINTR);
+ return AVERROR_EXIT;
usleep(100*1000);
}
goto retry;
}
url = s->segments[s->cur_seq_no - s->start_seq_no]->url,
- av_log(NULL, AV_LOG_DEBUG, "opening %s\n", url);
- ret = url_open(&s->seg_hd, url, URL_RDONLY);
+ av_log(h, AV_LOG_DEBUG, "opening %s\n", url);
+ ret = ffurl_open(&s->seg_hd, url, AVIO_FLAG_READ);
if (ret < 0) {
if (url_interrupt_cb())
- return AVERROR(EINTR);
- av_log(NULL, AV_LOG_WARNING, "Unable to open %s\n", url);
+ return AVERROR_EXIT;
+ av_log(h, AV_LOG_WARNING, "Unable to open %s\n", url);
s->cur_seq_no++;
goto retry;
}
free_segment_list(s);
free_variant_list(s);
- url_close(s->seg_hd);
+ ffurl_close(s->seg_hd);
av_free(s);
return 0;
}
URLProtocol ff_applehttp_protocol = {
- "applehttp",
- applehttp_open,
- applehttp_read,
- NULL, /* write */
- NULL, /* seek */
- applehttp_close,
- .flags = URL_PROTOCOL_FLAG_NESTED_SCHEME,
+ .name = "applehttp",
+ .url_open = applehttp_open,
+ .url_read = applehttp_read,
+ .url_close = applehttp_close,
+ .flags = URL_PROTOCOL_FLAG_NESTED_SCHEME,
};