39 #define INITIAL_BUFFER_SIZE 32768
109 while (len > 0 && isspace(buf[len - 1]))
154 const char *
url,
const char *base)
171 int key_len,
char **dest,
int *dest_len)
173 if (!strncmp(key,
"BANDWIDTH=", key_len)) {
186 int key_len,
char **dest,
int *dest_len)
188 if (!strncmp(key,
"METHOD=", key_len)) {
190 *dest_len =
sizeof(info->
method);
191 }
else if (!strncmp(key,
"URI=", key_len)) {
193 *dest_len =
sizeof(info->
uri);
194 }
else if (!strncmp(key,
"IV=", key_len)) {
196 *dest_len =
sizeof(info->
iv);
203 int ret = 0,
duration = 0, is_segment = 0, is_variant = 0, bandwidth = 0;
220 if (strcmp(line,
"#EXTM3U")) {
231 if (
av_strstart(line,
"#EXT-X-STREAM-INF:", &ptr)) {
237 }
else if (
av_strstart(line,
"#EXT-X-KEY:", &ptr)) {
243 if (!strcmp(info.
method,
"AES-128"))
245 if (!strncmp(info.
iv,
"0x", 2) || !strncmp(info.
iv,
"0X", 2)) {
250 }
else if (
av_strstart(line,
"#EXT-X-TARGETDURATION:", &ptr)) {
259 }
else if (
av_strstart(line,
"#EXT-X-MEDIA-SEQUENCE:", &ptr)) {
268 }
else if (
av_strstart(line,
"#EXT-X-ENDLIST", &ptr)) {
276 }
else if (line[0]) {
302 memcpy(seg->
iv, iv,
sizeof(iv));
305 memset(seg->
iv, 0,
sizeof(seg->
iv));
338 !=
sizeof(var->
key)) {
351 iv[32] = key[32] =
'\0';
352 if (strstr(seg->
url,
"://"))
353 snprintf(url,
sizeof(url),
"crypto+%s", seg->
url);
355 snprintf(url,
sizeof(url),
"crypto:%s", seg->
url);
371 static int read_data(
void *opaque, uint8_t *buf,
int buf_size)
384 reload_interval *= 1000000;
398 "skipping %d segments ahead, expired from playlists\n",
490 char bitrate_str[20];
529 snprintf(bitrate_str,
sizeof(bitrate_str),
"%d", v->
bandwidth);
593 int ret, i, minvariant = -1;
619 if (minvariant < 0 ||
629 if (minvariant >= 0) {
647 int64_t timestamp,
int flags)
677 if (timestamp >= pos &&
693 if (strncmp(p->
buf,
"#EXTM3U", 7))
695 if (strstr(p->
buf,
"#EXT-X-STREAM-INF:") ||
696 strstr(p->
buf,
"#EXT-X-TARGETDURATION:") ||
697 strstr(p->
buf,
"#EXT-X-MEDIA-SEQUENCE:"))
struct AppleHTTPContext AppleHTTPContext
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
char key_url[MAX_URL_SIZE]
#define INITIAL_BUFFER_SIZE
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd)
Rescale a 64-bit integer with specified rounding.
int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
#define AV_LOG_WARNING
Something somehow does not look correct.
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
int ffurl_connect(URLContext *uc, AVDictionary **options)
Connect an URLContext that has been allocated by ffurl_alloc.
static struct variant * new_variant(AppleHTTPContext *c, int bandwidth, const char *url, const char *base)
#define AVIO_FLAG_READ
read-only
unsigned char * buffer
Start of the buffer.
static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap)
static void handle_key_args(struct key_info *info, const char *key, int key_len, char **dest, int *dest_len)
AVIOInterruptCB * interrupt_callback
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
int id
format-specific stream ID
static void reset_packet(AVPacket *pkt)
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
static int read_header(FFV1Context *f)
static int applehttp_close(AVFormatContext *s)
static int applehttp_probe(AVProbeData *p)
void av_free_packet(AVPacket *pkt)
Free a packet.
#define AVERROR_EOF
End of file.
static av_cold int read_close(AVFormatContext *ctx)
struct variant ** variants
Callback for checking whether to abort blocking functions.
struct segment ** segments
int ffurl_alloc(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb)
Create a URLContext for accessing to the resource indicated by url, but do not initiate the connectio...
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
static int applehttp_read_packet(AVFormatContext *s, AVPacket *pkt)
void av_log(void *avcl, int level, const char *fmt,...)
AVStream * avformat_new_stream(AVFormatContext *s, AVCodec *c)
Add a new stream to a media file.
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
AVCodecContext * codec
codec context
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
unsigned int nb_streams
A list of all streams in the file.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
char filename[1024]
input or output filename
#define AV_TIME_BASE
Internal time base represented as integer.
int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
Copy the settings of the source AVCodecContext into the destination AVCodecContext.
int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt, const char *filename, void *logctx, unsigned int offset, unsigned int max_probe_size)
Probe a bytestream to determine the input format.
static int read_probe(AVProbeData *p)
int ff_get_line(AVIOContext *s, char *buf, int maxlen)
Read a whole line of text from AVIOContext.
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
static int open_input(struct variant *var)
static int applehttp_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
static void free_variant_list(AppleHTTPContext *c)
static void free_segment_list(struct variant *var)
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrup a blocking function associated with cb.
static void handle_variant_args(struct variant_info *info, const char *key, int key_len, char **dest, int *dest_len)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int avio_open2(AVIOContext **s, const char *url, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create and initialize a AVIOContext for accessing the resource indicated by url.
static int read_chomp_line(AVIOContext *s, char *buf, int maxlen)
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
static int read_data(void *opaque, uint8_t *buf, int buf_size)
This structure contains the data a format has to probe a file.
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
int ffurl_close(URLContext *h)
Close the resource accessed by the URLContext h, and free the memory used by it.
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
int ffio_init_context(AVIOContext *s, unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
int ffurl_open(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create an URLContext for accessing to the resource indicated by url, and open it. ...
int ffurl_read_complete(URLContext *h, unsigned char *buf, int size)
Read as many bytes as possible (up to size), calling the read function multiple times if necessary...
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
int eof_reached
true if eof reached
static int parse_playlist(AppleHTTPContext *c, const char *url, struct variant *var, AVIOContext *in)
void * priv_data
Format private data.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
int64_t duration
Decoding: duration of the stream, in AV_TIME_BASE fractional seconds.
unbuffered private I/O API
static int recheck_discard_flags(AVFormatContext *s, int first)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
int ffurl_read(URLContext *h, unsigned char *buf, int size)
Read up to size bytes from the resource accessed by h, and store the read bytes in buf...
#define AV_NOPTS_VALUE
Undefined timestamp value.
AVInputFormat ff_applehttp_demuxer
int64_t av_gettime(void)
Get the current time in microseconds.