39 #define INITIAL_BUFFER_SIZE 32768
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, is_segment = 0, is_variant = 0, bandwidth = 0;
227 if (strcmp(line,
"#EXTM3U")) {
238 if (
av_strstart(line,
"#EXT-X-STREAM-INF:", &ptr)) {
244 }
else if (
av_strstart(line,
"#EXT-X-KEY:", &ptr)) {
250 if (!strcmp(info.
method,
"AES-128"))
252 if (!strncmp(info.
iv,
"0x", 2) || !strncmp(info.
iv,
"0X", 2)) {
257 }
else if (
av_strstart(line,
"#EXT-X-TARGETDURATION:", &ptr)) {
266 }
else if (
av_strstart(line,
"#EXT-X-MEDIA-SEQUENCE:", &ptr)) {
275 }
else if (
av_strstart(line,
"#EXT-X-ENDLIST", &ptr)) {
283 }
else if (line[0]) {
309 memcpy(seg->
iv, iv,
sizeof(iv));
312 memset(seg->
iv, 0,
sizeof(seg->
iv));
346 !=
sizeof(var->
key)) {
359 iv[32] = key[32] =
'\0';
360 if (strstr(seg->
url,
"://"))
361 snprintf(url,
sizeof(url),
"crypto+%s", seg->
url);
363 snprintf(url,
sizeof(url),
"crypto:%s", seg->
url);
405 "skipping %d segments ahead, expired from playlists\n",
496 char bitrate_str[20];
542 snprintf(bitrate_str,
sizeof(bitrate_str),
"%d", v->
bandwidth);
616 int ret, i, minvariant = -1;
671 struct variant *minvar = minvariant < 0 ?
673 if (minvariant < 0 || var->cur_seq_no < minvar->
cur_seq_no) {
676 int64_t dts = var->
pkt.
dts;
677 int64_t mindts = minvar->
pkt.
dts;
701 if (minvariant >= 0) {
719 int64_t timestamp,
int flags)
762 if (timestamp >= pos &&
780 if (strncmp(p->
buf,
"#EXTM3U", 7))
782 if (strstr(p->
buf,
"#EXT-X-STREAM-INF:") ||
783 strstr(p->
buf,
"#EXT-X-TARGETDURATION:") ||
784 strstr(p->
buf,
"#EXT-X-MEDIA-SEQUENCE:"))
790 .
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 ff_make_absolute_url(char *buf, int size, const char *base, const char *rel)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
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 rnd)
Rescale a 64-bit integer with specified rounding.
#define AV_LOG_WARNING
Something somehow does not look correct.
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.
#define AVIO_FLAG_READ
read-only
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){if(!*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));if(!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=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);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);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) 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
unsigned char * buffer
Start of the buffer.
int av_usleep(unsigned usec)
Sleep for a period of time.
int ctx_flags
Flags signalling stream properties.
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
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
AVStream ** streams
A list of all streams in the file.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
AVProgram * av_new_program(AVFormatContext *s, int id)
static int read_data(void *opaque, uint8_t *buf, int buf_size)
#define AVERROR_EOF
End of file.
static av_cold int read_close(AVFormatContext *ctx)
static int open_input(struct variant *var)
#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)
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(). ...
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,...)
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.
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.
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
Number of elements in AVFormatContext.streams.
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.
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
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.
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
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)
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.
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. ...
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 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...
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)
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
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 ...
#define AV_NOPTS_VALUE
Undefined timestamp value.