39 #define INITIAL_BUFFER_SIZE 32768
111 while (len > 0 && isspace(buf[len - 1]))
156 const char *
url,
const char *base)
173 int key_len,
char **dest,
int *dest_len)
175 if (!strncmp(key,
"BANDWIDTH=", key_len)) {
188 int key_len,
char **dest,
int *dest_len)
190 if (!strncmp(key,
"METHOD=", key_len)) {
192 *dest_len =
sizeof(info->
method);
193 }
else if (!strncmp(key,
"URI=", key_len)) {
195 *dest_len =
sizeof(info->
uri);
196 }
else if (!strncmp(key,
"IV=", key_len)) {
198 *dest_len =
sizeof(info->
iv);
205 int ret = 0,
duration = 0, is_segment = 0, is_variant = 0, bandwidth = 0;
222 if (strcmp(line,
"#EXTM3U")) {
233 if (
av_strstart(line,
"#EXT-X-STREAM-INF:", &ptr)) {
239 }
else if (
av_strstart(line,
"#EXT-X-KEY:", &ptr)) {
245 if (!strcmp(info.
method,
"AES-128"))
247 if (!strncmp(info.
iv,
"0x", 2) || !strncmp(info.
iv,
"0X", 2)) {
252 }
else if (
av_strstart(line,
"#EXT-X-TARGETDURATION:", &ptr)) {
261 }
else if (
av_strstart(line,
"#EXT-X-MEDIA-SEQUENCE:", &ptr)) {
270 }
else if (
av_strstart(line,
"#EXT-X-ENDLIST", &ptr)) {
278 }
else if (line[0]) {
304 memcpy(seg->
iv, iv,
sizeof(iv));
307 memset(seg->
iv, 0,
sizeof(seg->
iv));
340 !=
sizeof(var->
key)) {
353 iv[32] = key[32] =
'\0';
354 if (strstr(seg->
url,
"://"))
355 snprintf(url,
sizeof(url),
"crypto+%s", seg->
url);
357 snprintf(url,
sizeof(url),
"crypto:%s", seg->
url);
386 reload_interval *= 1000000;
400 "skipping %d segments ahead, expired from playlists\n",
490 char bitrate_str[20];
529 snprintf(bitrate_str,
sizeof(bitrate_str),
"%d", v->
bandwidth);
594 int ret, i, minvariant = -1;
643 if (minvariant < 0 ||
653 if (minvariant >= 0) {
671 int64_t timestamp,
int flags)
716 if (timestamp >= pos &&
734 if (strncmp(p->
buf,
"#EXTM3U", 7))
736 if (strstr(p->
buf,
"#EXT-X-STREAM-INF:") ||
737 strstr(p->
buf,
"#EXT-X-TARGETDURATION:") ||
738 strstr(p->
buf,
"#EXT-X-MEDIA-SEQUENCE:"))
744 .
name =
"hls,applehttp",
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
void av_free_packet(AVPacket *pkt)
Free a packet.
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
char key_url[MAX_URL_SIZE]
struct HLSContext HLSContext
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.
unsigned char * buf_ptr
Current position in the buffer.
unsigned char * buf_end
End of the data, may be less than buffer+buffer_size if the read function returned less data than req...
int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
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.
unsigned char * buffer
Start of the buffer.
int av_usleep(unsigned usec)
Sleep for a period of time.
static void reset_packet(AVPacket *pkt)
int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
Copy the settings of the source AVCodecContext into the destination AVCodecContext.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
int id
Format-specific stream ID.
AVInputFormat ff_hls_demuxer
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
static int read_data(void *opaque, uint8_t *buf, int buf_size)
static av_cold int read_close(AVFormatContext *ctx)
static int open_input(struct variant *var)
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(). ...
AVIOInterruptCB * interrupt_callback
static struct variant * new_variant(HLSContext *c, int bandwidth, const char *url, const char *base)
static void handle_key_args(struct key_info *info, const char *key, int key_len, char **dest, int *dest_len)
#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.
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.
int flags
A combination of AV_PKT_FLAG values.
AVCodecContext * codec
Codec context associated with this stream.
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
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 hls_read_packet(AVFormatContext *s, AVPacket *pkt)
int ff_get_line(AVIOContext *s, char *buf, int maxlen)
Read a whole line of text from AVIOContext.
static int read_header(FFV1Context *f)
int64_t av_gettime(void)
Get the current time in microseconds.
static void free_segment_list(struct variant *var)
#define AVSEEK_FLAG_BACKWARD
static int read_chomp_line(AVIOContext *s, char *buf, int maxlen)
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrup a blocking function associated with cb.
AVIOContext * pb
I/O context.
static int hls_read_header(AVFormatContext *s)
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.
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.
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
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.
static void handle_variant_args(struct variant_info *info, const char *key, int key_len, char **dest, int *dest_len)
int ffurl_close(URLContext *h)
Close the resource accessed by the URLContext h, and free the memory used by it.
static int recheck_discard_flags(AVFormatContext *s, int first)
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
#define INITIAL_BUFFER_SIZE
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. ...
static int parse_playlist(HLSContext *c, const char *url, struct variant *var, AVIOContext *in)
#define AVERROR_INVALIDDATA
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...
#define AVPROBE_SCORE_MAX
int64_t pos
position in the file of the current buffer
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
static int hls_probe(AVProbeData *p)
static int hls_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
int eof_reached
true if eof reached
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
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
static void free_variant_list(HLSContext *c)
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
static int hls_close(AVFormatContext *s)
This structure stores compressed data.
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...
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...