28 #include "libavutil/avstring.h"
29 #include "libavutil/intreadwrite.h"
30 #include "libavutil/mathematics.h"
31 #include "libavutil/opt.h"
32 #include "libavutil/dict.h"
33 #include "libavutil/time.h"
39 #define INITIAL_BUFFER_SIZE 32768
160 const char *
url,
const char *base)
177 int key_len,
char **dest,
int *dest_len)
179 if (!strncmp(key,
"BANDWIDTH=", key_len)) {
192 int key_len,
char **dest,
int *dest_len)
194 if (!strncmp(key,
"METHOD=", key_len)) {
196 *dest_len =
sizeof(info->
method);
197 }
else if (!strncmp(key,
"URI=", key_len)) {
199 *dest_len =
sizeof(info->
uri);
200 }
else if (!strncmp(key,
"IV=", key_len)) {
202 *dest_len =
sizeof(info->
iv);
209 int ret = 0, is_segment = 0, is_variant = 0, bandwidth = 0;
237 if (strcmp(line,
"#EXTM3U")) {
248 if (
av_strstart(line,
"#EXT-X-STREAM-INF:", &ptr)) {
254 }
else if (
av_strstart(line,
"#EXT-X-KEY:", &ptr)) {
260 if (!strcmp(info.
method,
"AES-128"))
262 if (!strncmp(info.
iv,
"0x", 2) || !strncmp(info.
iv,
"0X", 2)) {
267 }
else if (
av_strstart(line,
"#EXT-X-TARGETDURATION:", &ptr)) {
276 }
else if (
av_strstart(line,
"#EXT-X-MEDIA-SEQUENCE:", &ptr)) {
285 }
else if (
av_strstart(line,
"#EXT-X-ENDLIST", &ptr)) {
293 }
else if (line[0]) {
319 memcpy(seg->
iv, iv,
sizeof(iv));
322 memset(seg->
iv, 0,
sizeof(seg->
iv));
363 !=
sizeof(var->
key)) {
376 iv[32] = key[32] =
'\0';
377 if (strstr(seg->
url,
"://"))
430 "skipping %d segments ahead, expired from playlists\n",
490 if (
c->user_agent && !strlen(
c->user_agent))
496 if (
c->cookies && !strlen(
c->cookies))
503 if (
c->n_variants == 0) {
510 if (
c->n_variants > 1 ||
c->variants[0]->n_segments == 0) {
511 for (i = 0; i <
c->n_variants; i++) {
518 if (
c->variants[0]->n_segments == 0) {
526 if (
c->variants[0]->finished) {
528 for (i = 0; i <
c->variants[0]->n_segments; i++)
529 duration +=
c->variants[0]->segments[i]->duration;
534 for (i = 0; i <
c->n_variants; i++) {
537 char bitrate_str[20];
658 int ret, i, minvariant = -1;
714 if (minvariant < 0 || var->cur_seq_no < minvar->
cur_seq_no) {
717 int64_t dts = var->
pkt.
dts;
718 int64_t mindts = minvar->
pkt.
dts;
742 if (minvariant >= 0) {
760 int64_t timestamp,
int flags)
803 if (timestamp >= pos &&
821 if (strncmp(p->
buf,
"#EXTM3U", 7))
823 if (strstr(p->
buf,
"#EXT-X-STREAM-INF:") ||
824 strstr(p->
buf,
"#EXT-X-TARGETDURATION:") ||
825 strstr(p->
buf,
"#EXT-X-MEDIA-SEQUENCE:"))
831 .
name =
"hls,applehttp",
void ff_make_absolute_url(char *buf, int size, const char *base, const char *rel)
Convert a relative url into an absolute url, given a base url.
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]
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding) av_const
Rescale a 64-bit integer with specified rounding.
#define AV_LOG_WARNING
Something somehow does not look correct.
int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
int av_usleep(unsigned usec)
Sleep for a period of time.
void * opaque
A private pointer, passed to the read/write/seek/...
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.
AVCodecContext * codec
Codec context associated with this stream.
struct URLProtocol * prot
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
char * user_agent
holds HTTP user agent set as an AVOption to the HTTP protocol context
int ctx_flags
Format-specific flags, see AVFMTCTX_xx.
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 *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
const AVClass * priv_data_class
if((e=av_dict_get(options,"", NULL, AV_DICT_IGNORE_SUFFIX)))
unsigned char * buffer
Start of the buffer.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
int id
Format-specific stream ID.
AVInputFormat ff_hls_demuxer
static int read_data(void *opaque, uint8_t *buf, int buf_size)
static av_cold int read_close(AVFormatContext *ctx)
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
struct variant ** variants
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const
Rescale a 64-bit integer by 2 rational numbers.
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...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
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)
void * priv_data
Format private data.
char filename[1024]
input or output filename
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_dict_free(AVDictionary **m)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
New fields can be added to the end with minor version bumps.
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.
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 flags
A combination of AV_PKT_FLAG values.
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare 2 timestamps each in its own timebases.
unsigned int nb_streams
A list of all streams in the file.
int64_t av_gettime(void)
Get the current time in microseconds.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
#define AV_TIME_BASE
Internal time base represented as integer.
int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt, const char *filename, void *logctx, unsigned int offset, unsigned int max_probe_size)
Like av_probe_input_buffer2() but returns 0 on success.
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static int hls_read_packet(AVFormatContext *s, AVPacket *pkt)
AVProgram * av_new_program(AVFormatContext *s, int id)
unsigned char * buf_ptr
Current position in the buffer.
int ff_get_line(AVIOContext *s, char *buf, int maxlen)
Read a whole line of text from AVIOContext.
char * cookies
holds HTTP cookie values set in either the initial response or as an AVOption to the HTTP protocol co...
static int read_header(FFV1Context *f)
static void free_segment_list(struct variant *var)
static int open_input(HLSContext *c, struct variant *var)
static int read_chomp_line(AVIOContext *s, char *buf, int maxlen)
#define AV_LOG_INFO
Standard information.
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrup a blocking function associated with cb.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
static int hls_read_header(AVFormatContext *s)
AVIOContext * pb
I/O context.
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 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)
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. ...
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
static int parse_playlist(HLSContext *c, const char *url, struct variant *var, AVIOContext *in)
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...
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
int64_t pos
position in the file of the current buffer
int pts_wrap_bits
number of bits in pts (used for wrapping control)
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 av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
#define AVERROR_INVALIDDATA
int eof_reached
true if eof reached
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...
#define AV_NOPTS_VALUE
Undefined timestamp value.
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static av_cold void cleanup(FlashSV2Context *s)