30#include "config_components.h"
51#define INITIAL_BUFFER_SIZE 32768
53#define MAX_FIELD_LEN 64
54#define MAX_CHARACTERISTICS_LEN 512
56#define MPEG_TIME_BASE 90000
57#define MPEG_TIME_BASE_Q (AVRational){1, MPEG_TIME_BASE}
285 for (
i = 0;
i <
c->n_playlists;
i++) {
316 for (
i = 0;
i <
c->n_variants;
i++) {
328 for (
i = 0;
i <
c->n_renditions;
i++)
344 for (
int i = 0;
i <
c->n_playlists;
i++) {
345 if (!strcmp(
c->playlists[
i]->url, abs_url))
346 return c->playlists[
i];
379 const char *url,
const char *
base)
405 int key_len,
char **dest,
int *dest_len)
408 if (!strncmp(
key,
"BANDWIDTH=", key_len)) {
411 }
else if (!strncmp(
key,
"AUDIO=", key_len)) {
413 *dest_len =
sizeof(info->
audio);
414 }
else if (!strncmp(
key,
"VIDEO=", key_len)) {
416 *dest_len =
sizeof(info->
video);
417 }
else if (!strncmp(
key,
"SUBTITLES=", key_len)) {
430 int key_len,
char **dest,
int *dest_len)
433 if (!strncmp(
key,
"METHOD=", key_len)) {
435 *dest_len =
sizeof(info->
method);
436 }
else if (!strncmp(
key,
"URI=", key_len)) {
438 *dest_len =
sizeof(info->
uri);
439 }
else if (!strncmp(
key,
"IV=", key_len)) {
441 *dest_len =
sizeof(info->
iv);
452 const char *url_base)
500 int key_len,
char **dest,
int *dest_len)
503 if (!strncmp(
key,
"URI=", key_len)) {
505 *dest_len =
sizeof(info->
uri);
506 }
else if (!strncmp(
key,
"BYTERANGE=", key_len)) {
525 const char *url_base)
529 char *characteristic;
533 if (!strcmp(info->
type,
"AUDIO"))
535 else if (!strcmp(info->
type,
"VIDEO"))
537 else if (!strcmp(info->
type,
"SUBTITLES"))
539 else if (!strcmp(info->
type,
"CLOSED-CAPTIONS"))
580 size_t langlen = strlen(rend->
language);
581 if (langlen <
sizeof(rend->
language) - 3) {
586 sizeof(rend->
language) - langlen - 1);
587 if (langlen + assoc_len + 2 >
sizeof(rend->
language))
595 if (!strcmp(info->
forced,
"YES"))
599 while ((characteristic =
av_strtok(chr_ptr,
",", &saveptr))) {
600 if (!strcmp(characteristic,
"public.accessibility.describes-music-and-sound"))
602 else if (!strcmp(characteristic,
"public.accessibility.describes-video"))
612 int key_len,
char **dest,
int *dest_len)
616 if (!strncmp(
key,
"TYPE=", key_len)) {
618 *dest_len =
sizeof(info->
type);
619 }
else if (!strncmp(
key,
"URI=", key_len)) {
621 *dest_len =
sizeof(info->
uri);
622 }
else if (!strncmp(
key,
"GROUP-ID=", key_len)) {
625 }
else if (!strncmp(
key,
"LANGUAGE=", key_len)) {
628 }
else if (!strncmp(
key,
"ASSOC-LANGUAGE=", key_len)) {
631 }
else if (!strncmp(
key,
"NAME=", key_len)) {
633 *dest_len =
sizeof(info->
name);
634 }
else if (!strncmp(
key,
"DEFAULT=", key_len)) {
637 }
else if (!strncmp(
key,
"FORCED=", key_len)) {
639 *dest_len =
sizeof(info->
forced);
640 }
else if (!strncmp(
key,
"CHARACTERISTICS=", key_len)) {
663 *pls =
c->playlists[
c->n_playlists - 1];
669#if !CONFIG_HTTP_PROTOCOL
673 return uc && !strncmp(uc->
prot->
name,
"http", 4);
680#if !CONFIG_HTTP_PROTOCOL
686 (*pb)->eof_reached = 0;
700 const char *proto_name =
NULL;
705 if (url[6] ==
'+' || url[6] ==
':')
708 if (url[4] ==
'+' || url[4] ==
':')
720 if (strcmp(
c->allowed_extensions,
"ALL") && !
av_match_ext(url,
c->allowed_extensions)) {
722 "Filename extension of \'%s\' is not a common multimedia extension, blocked for security reasons.\n"
723 "If you wish to override this adjust allowed_extensions, you can set it to \'ALL\' to allow all\n",
734 if (!strncmp(proto_name, url, strlen(proto_name)) && url[strlen(proto_name)] ==
':')
736 else if (
av_strstart(url,
"crypto",
NULL) && !strncmp(proto_name, url + 7, strlen(proto_name)) && url[7 + strlen(proto_name)] ==
':')
738 else if (
av_strstart(url,
"data",
NULL) && !strncmp(proto_name, url + 5, strlen(proto_name)) && url[5 + strlen(proto_name)] ==
':')
740 else if (strcmp(proto_name,
"file") || !strncmp(url,
"file,", 5))
751 }
else if (ret < 0) {
754 "keepalive request failed for '%s' with error: '%s' when opening url, retrying with new connection\n",
766 char *new_cookies =
NULL;
778 *is_http_out = is_http;
789 if (!
c->extension_picky)
792 if (strcmp(
c->allowed_segment_extensions,
"ALL"))
797 av_log(
s,
AV_LOG_ERROR,
"URL %s is not in allowed_segment_extensions, consider updating hls.c and submitting a patch to ffmpeg-devel, if this should be added\n", seg->
url);
807 matchF |=
av_match_ext( seg->
url,
"ts,m2t,m2ts,mts,mpg,m4s,mpeg,mpegts,cmfv,cmfa")
808 + 2*(
ff_match_url_ext(seg->
url,
"ts,m2t,m2ts,mts,mpg,m4s,mpeg,mpegts,cmfv,cmfa") > 0);
810 }
else if (!strcmp(in_fmt->
name,
"mpegts")) {
811 const char *str =
"ts,m2t,m2ts,mts,mpg,m4s,mpeg,mpegts"
816 }
else if (!strcmp(in_fmt->
name,
"webvtt")) {
821 if (!(matchA & matchF)) {
833 int ret = 0, is_segment = 0, is_variant = 0;
844 uint8_t *new_url =
NULL;
850 int prev_n_segments = 0;
851 int64_t prev_start_seq_no = -1;
854 if (is_http && !in &&
c->http_persistent &&
c->playlist_pb) {
859 }
else if (ret < 0) {
862 "keepalive request failed for '%s' with error: '%s' when parsing playlist\n",
872 if (
c->http_persistent)
890 if (strcmp(
line,
"#EXTM3U")) {
910 "Master Playlist tag found in a Media Playlist\n");
922 if (!strcmp(info.
method,
"AES-128"))
924 if (!strcmp(info.
method,
"SAMPLE-AES"))
935 "Master Playlist tag found in a Media Playlist\n");
946 t = strtoll(ptr,
NULL, 10);
957 seq_no = strtoull(ptr,
NULL, 10);
958 if (seq_no > INT64_MAX/2) {
960 "INT64_MAX/2, mask out the highest bit\n");
961 seq_no &= INT64_MAX/2;
968 if (!strcmp(ptr,
"EVENT"))
970 else if (!strcmp(ptr,
"VOD"))
979 if (!cur_init_section) {
983 cur_init_section->
key_type = key_type;
985 memcpy(cur_init_section->
iv, iv,
sizeof(iv));
988 memset(cur_init_section->
iv, 0,
sizeof(cur_init_section->
iv));
1000 if (!cur_init_section->
key) {
1010 const char *time_offset_value =
NULL;
1015 if (
av_strstart(ptr,
"TIME-OFFSET=", &time_offset_value)) {
1022 "invalid, it will be ignored");
1026 "invalid, it will be ignored");
1034 if (d < 0 || d > INT64_MAX ||
isnan(d)) {
1041 seg_size = strtoll(ptr,
NULL, 10);
1042 ptr = strchr(ptr,
'@');
1044 seg_offset = strtoll(ptr+1,
NULL, 10);
1045 if (seg_size < 0 || seg_offset > INT64_MAX - seg_size) {
1052 }
else if (
line[0]) {
1071 memcpy(seg->
iv,
iv,
sizeof(
iv));
1074 memset(seg->
iv, 0,
sizeof(seg->
iv));
1121 " set to default value to 1ms.\n", seg->
url);
1129 seg->
size = seg_size;
1130 if (seg_size >= 0) {
1132 seg_offset += seg_size;
1143 if (prev_segments) {
1145 c->first_timestamp_pls == pls) {
1146 int64_t prev_timestamp =
c->first_timestamp;
1149 for (
i = 0;
i < prev_n_segments &&
i <
diff;
i++) {
1150 c->first_timestamp += prev_segments[
i]->
duration;
1153 " reflected in first_timestamp: %"PRId64
" -> %"PRId64
"\n",
1155 prev_timestamp,
c->first_timestamp);
1171 if (!
c->n_variants || !
c->variants[0]->n_playlists ||
1172 !
c->variants[0]->playlists[0]->n_segments)
1175 if (
c->n_variants &&
c->variants[0]->n_playlists &&
1177 !
c->variants[0]->playlists[0]->finished) {
1178 struct playlist *p =
c->variants[0]->playlists[0];
1180 for (
int i = 0;
i < p->n_segments;
i++)
1210 return in && cur && next &&
1212 cur->
size >= 0 && next->
size >= 0 &&
1216 !strcmp(next->
url, cur->
url);
1220 uint8_t *buf,
int buf_size)
1240 static const char id3_priv_owner_ts[] =
"com.apple.streaming.transportStreamTimestamp";
1241 static const char id3_priv_owner_audio_setup[] =
"com.apple.streaming.audioDescription";
1245 for (meta = *extra_meta; meta; meta = meta->
next) {
1246 if (!strcmp(meta->
tag,
"PRIV")) {
1252 if ((ts & ~((1ULL << 33) - 1)) == 0)
1259 }
else if (!strcmp(meta->
tag,
"APIC") && apic)
1273 if (!oldentry || strcmp(oldentry->
value,
entry->value) != 0)
1337 int buf_size,
int *
len)
1342 int id3_buf_pos = 0;
1360 }
else if (*
len <= 0) {
1373 int tag_got_bytes =
FFMIN(taglen, *
len);
1374 int remaining = taglen - tag_got_bytes;
1376 if (taglen > maxsize) {
1392 memcpy(pls->
id3_buf + id3_buf_pos, buf, tag_got_bytes);
1393 id3_buf_pos += tag_got_bytes;
1396 *
len -= tag_got_bytes;
1397 memmove(buf, buf + tag_got_bytes, *
len);
1400 if (remaining > 0) {
1404 id3_buf_pos += remaining;
1449 if (ret !=
sizeof(pls->
key)) {
1455 seg->
key, ret,
sizeof(pls->
key));
1479 if (seek_ret >= 0) {
1481 "HLS reusing connection for url '%s', offset %"PRId64
", playlist %d\n",
1492 if (
c->http_persistent)
1495 if (seg->
size >= 0) {
1502 while (n < pls->n_segments) {
1507 strcmp(ns->
url, seg->
url))
1532 if (strstr(seg->
url,
"://"))
1559 if (ret == 0 && !is_http && seg->
url_offset) {
1576 static const int max_init_section_size = 1024*1024;
1593 "Failed to open an initialization section in playlist %d\n",
1603 sec_size = max_init_section_size;
1606 "Downloading an initialization section of size %"PRId64
"\n",
1609 sec_size =
FFMIN(sec_size, max_init_section_size);
1642 int stream_needed = 0;
1668 for (
i = 0;
i <
s->nb_programs;
i++) {
1687 int reload_count = 0;
1713 if (reload_count >
c->max_reload)
1730 "skipping %"PRId64
" segments ahead, expired from playlists\n",
1766 int just_opened = 0;
1767 int segment_retries = 0;
1806 if (segment_retries >=
c->seg_max_retry) {
1811 segment_retries = 0;
1817 segment_retries = 0;
1823 if (
c->http_multiple == -1) {
1824 uint8_t *http_version_opt =
NULL;
1827 c->http_multiple = (!strncmp((
const char *)http_version_opt,
"1.1", 3) || !strncmp((
const char *)http_version_opt,
"2.0", 3));
1921 "A HLS playlist item '%s' referred to an external file '%s'. "
1922 "Opening this file was forbidden for security reasons\n",
1999 for (
i = 0;
i <
c->n_renditions;
i++) {
2056 0 :
c->first_timestamp;
2058 if (timestamp <
pos) {
2062 *seg_start_ts =
pos;
2071 *seg_start_ts =
pos;
2093 if (!pls->
finished && !
c->first_packet &&
2107 if (!
c->first_packet &&
2114 return c->cur_seq_no;
2118 if (
c->live_start_index < 0)
2120 c->live_start_index, 0);
2128 int64_t playlist_duration = 0;
2141 start_timestamp = cur_timestamp + playlist_duration;
2147 start_timestamp = cur_timestamp;
2150 start_timestamp = cur_timestamp + playlist_duration +
2153 start_timestamp = cur_timestamp;
2170 for (
i = 0;
i <
c->n_variants;
i++) {
2246 "Playlist has multiple timed ID3 streams; "
2247 "only stream %d will be used for metadata propagation\n",
2258 int flag_needed = 0;
2261 for (
i = 0;
i <
c->n_playlists;
i++) {
2284 if (
c->crypto_ctx.aes_ctx)
2297 int64_t highest_cur_seq_no = 0;
2300 c->interrupt_callback = &
s->interrupt_callback;
2302 c->first_packet = 1;
2304 c->first_timestamp_pls =
NULL;
2305 c->first_timestamp_locked = 0;
2315 if (
c->http_persistent) {
2317 c->http_persistent = 0;
2321 if (
c->http_multiple == -1) {
2323 c->http_multiple = 0;
2335 if (
c->n_variants == 0) {
2341 if (
c->n_playlists > 1 ||
c->playlists[0]->n_segments == 0) {
2342 for (
i = 0;
i <
c->n_playlists;
i++) {
2348 if (
c->n_playlists > 1)
2355 for (
i = 0;
i <
c->n_variants;
i++) {
2356 if (
c->variants[
i]->playlists[0]->n_segments == 0) {
2358 c->variants[
i]->playlists[0]->broken = 1;
2364 if (
c->variants[0]->playlists[0]->finished ||
2367 for (
i = 0;
i <
c->variants[0]->playlists[0]->n_segments;
i++)
2368 duration +=
c->variants[0]->playlists[0]->segments[
i]->duration;
2373 for (
i = 0;
i <
c->n_variants;
i++) {
2385 for (
i = 0;
i <
c->n_variants;
i++) {
2396 for (
i = 0;
i <
c->n_playlists;
i++) {
2406 av_dict_set(&
c->seg_format_opts,
"prefer_hls_mpegts_pts",
"1", 0);
2409 for (
i = 0;
i <
c->n_playlists;
i++) {
2434 highest_cur_seq_no < pls->start_seq_no + pls->
n_segments) {
2501 pls->
ctx->
probesize =
s->probesize > 0 ?
s->probesize : 1024 * 4;
2527 if (strstr(in_fmt->
name,
"mov")) {
2531 }
else if (!
c->crypto_ctx.aes_ctx) {
2533 if (!
c->crypto_ctx.aes_ctx) {
2621 for (
i = 0;
i <
c->n_playlists;
i++) {
2629 if (cur_needed && !pls->
needed) {
2643 }
else if (first && !cur_needed && pls->
needed) {
2727 int ret,
i, minplaylist = -1;
2730 c->first_packet = 0;
2732 for (
i = 0;
i <
c->n_playlists;
i++) {
2759 (!
c->first_timestamp_locked &&
2760 c->first_timestamp_pls == pls &&
2773 c->first_timestamp = ts;
2774 c->first_timestamp_pls = pls;
2776 }
else if (
c->first_timestamp_pls == pls) {
2784 c->first_timestamp = ts;
2785 for (
int k = 0; k <
c->n_playlists; k++)
2787 c->playlists[k]->ts_offset +=
delta;
2796 for (
unsigned k = 0; k <
s->nb_streams; k++)
2797 s->streams[k]->start_time =
2799 s->streams[k]->time_base);
2801 "First timestamp %"PRId64
" from playlist %d\n",
2802 c->first_timestamp, pls->
index);
2809 memcpy(
c->crypto_ctx.iv, seg->
iv,
sizeof(seg->
iv));
2810 memcpy(
c->crypto_ctx.key, pls->
key,
sizeof(pls->
key));
2840 struct playlist *minpls = minplaylist < 0 ?
2841 NULL :
c->playlists[minplaylist];
2842 if (minplaylist < 0) {
2856 if (minplaylist >= 0) {
2857 struct playlist *pls =
c->playlists[minplaylist];
2885 av_log(
s,
AV_LOG_ERROR,
"stream index inconsistency: index %d, %d main streams, %d subdemuxer streams\n",
2940 int stream_subdemuxer_index;
2943 int snapped_to_segment = 0;
2949 s->streams[stream_index]->time_base,
2953 for (
i = 0;
i <
c->n_playlists;
i++) {
2958 stream_subdemuxer_index = j;
2973 0 :
c->first_timestamp;
2987 0 :
c->first_timestamp;
3007 snapped_to_segment = 1;
3011 " of playlist %d (start %"PRId64
")\n",
3015 c->first_timestamp_locked = 1;
3023 for (
i = 0;
i < (int)
s->nb_streams;
i++)
3026 for (
i = 0;
i <
c->n_playlists;
i++) {
3037 pb->eof_reached = 0;
3039 pb->buf_end =
pb->buf_ptr =
pb->buffer;
3065 if (pls == seek_pls && snapped_to_segment) {
3074 if (pls != seek_pls) {
3096 if (strncmp(p->buf,
"#EXTM3U", 7))
3099 if (strstr(p->buf,
"#EXT-X-STREAM-INF:") ||
3100 strstr(p->buf,
"#EXT-X-TARGETDURATION:") ||
3101 strstr(p->buf,
"#EXT-X-MEDIA-SEQUENCE:")) {
3103 int mime_ok = p->mime_type && !(
3104 av_strcasecmp(p->mime_type,
"application/vnd.apple.mpegurl") &&
3108 int mime_x = p->mime_type && !(
3117 av_log(
NULL,
AV_LOG_ERROR,
"Not detecting m3u8/hls with non standard extension and non standard mime type\n");
3128#define OFFSET(x) offsetof(HLSContext, x)
3129#define FLAGS AV_OPT_FLAG_DECODING_PARAM
3131 {
"live_start_index",
"segment index to start live streams at (negative values are from the end)",
3133 {
"prefer_x_start",
"prefer to use #EXT-X-START if it's in playlist instead of live_start_index",
3135 {
"allowed_extensions",
"List of file extensions that hls is allowed to access",
3137 {.str =
"3gp,aac,avi,ac3,eac3,flac,mkv,m3u8,m4a,m4s,m4v,mpg,mov,mp2,mp3,mp4,mpeg,mpegts,ogg,ogv,oga,ts,vob,vtt,wav,webvtt"
3142 INT_MIN, INT_MAX,
FLAGS},
3143 {
"allowed_segment_extensions",
"List of file extensions that hls is allowed to access",
3145 {.str =
"3gp,aac,avi,ac3,eac3,flac,mkv,m3u8,m4a,m4s,m4v,mpg,mov,mp2,mp3,mp4,mpeg,mpegts,ogg,ogv,oga,ts,vob,vtt,wav,webvtt"
3151 INT_MIN, INT_MAX,
FLAGS},
3152 {
"extension_picky",
"Be picky with all extensions matching",
3154 {
"max_reload",
"Maximum number of times a insufficient list is attempted to be reloaded",
3156 {
"m3u8_hold_counters",
"The maximum number of times to load m3u8 when it refreshes without new segments",
3158 {
"http_persistent",
"Use persistent HTTP connections",
3160 {
"http_multiple",
"Use multiple HTTP connections for fetching segments",
3162 {
"http_seekable",
"Use HTTP partial requests, 0 = disable, 1 = enable, -1 = auto",
3164 {
"seg_format_options",
"Set options for segment demuxer",
3166 {
"seg_max_retry",
"Maximum number of times to reload a segment on error.",
3172 .class_name =
"hls demuxer",
static av_always_inline void update(AVFilterContext *ctx, AVFrame *insamples, int is_silence, int current_sample, int64_t nb_samples_notify, AVRational time_base)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
URLContext * ffio_geturlcontext(AVIOContext *s)
Return the URLContext associated with the AVIOContext.
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrupt a blocking function associated with cb.
const char * avio_find_protocol_name(const char *url)
Return the name of the protocol that will handle the passed URL.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
#define AVIO_FLAG_READ
read-only
int64_t avio_size(AVIOContext *s)
Get the filesize.
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
void ffio_init_context(FFIOContext *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, const uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
void ffio_init_read_context(FFIOContext *s, const uint8_t *buffer, int buffer_size)
Wrap a buffer in an AVIOContext for reading.
int ffio_copy_url_options(AVIOContext *pb, AVDictionary **avio_opts)
Read url related dictionary options from the AVIOContext and write to the given dictionary.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
int ff_get_chomp_line(AVIOContext *s, char *buf, int maxlen)
Same as ff_get_line but strip the white-space characters in the text tail.
static int FUNC metadata(CodedBitstreamContext *ctx, RWContext *rw, APVRawMetadata *current)
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
static int read_probe(const AVProbeData *p)
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
#define INITIAL_BUFFER_SIZE
static int nested_io_open(AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **opts)
#define FF_INFMT_FLAG_INIT_CLEANUP
For an FFInputFormat with this flag set read_close() needs to be called by the caller upon read_heade...
void ff_read_frame_flush(AVFormatContext *s)
Flush the frame reader.
static struct @111144215057303131116103221376075045141373005341 current
static int read_key(void)
static int read_header(FFV1Context *f, RangeCoder *c)
static av_cold void cleanup(FlashSV2Context *s)
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_DICT
Underlying C type is AVDictionary*.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
@ AVDISCARD_ALL
discard all
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
AVProgram * av_new_program(AVFormatContext *ac, int id)
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
const AVInputFormat * av_find_input_format(const char *short_name)
Find AVInputFormat based on the short name of the input format.
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
int av_probe_input_buffer(AVIOContext *pb, const AVInputFormat **fmt, const char *url, void *logctx, unsigned int offset, unsigned int max_probe_size)
Like av_probe_input_buffer2() but returns 0 on success.
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
int avformat_queue_attached_pictures(AVFormatContext *s)
int av_match_ext(const char *filename, const char *extensions)
Return a positive value if the given filename has one of the given extensions, 0 otherwise.
struct AVAES * av_aes_alloc(void)
Allocate an AVAES context.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
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 av_dict_count(const AVDictionary *m)
Get number of entries in dictionary.
#define AV_DICT_MATCH_CASE
Only get an entry with exact-case key match.
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set() that converts the value to a string and stores it.
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
#define AVERROR_PROTOCOL_NOT_FOUND
Protocol not found.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, enum AVRounding rnd)
Rescale a 64-bit integer by 2 rational numbers with specified rounding.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
int64_t av_compare_mod(uint64_t a, uint64_t b, uint64_t mod)
Compare the remainders of two integer operands divided by a common divisor.
@ AV_ROUND_DOWN
Round toward -infinity.
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
int av_match_name(const char *name, const char *names)
Match instances of a name in a comma-separated list of names.
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
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 av_strncasecmp(const char *a, const char *b, size_t n)
Locale-independent case-insensitive compare.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_TIME_BASE
Internal time base represented as integer.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
#define LIBAVUTIL_VERSION_INT
int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
static void update_noheader_flag(AVFormatContext *s)
#define MAX_CHARACTERISTICS_LEN
static int open_input(HLSContext *c, struct playlist *pls, struct segment *seg, AVIOContext **in)
static int is_native_http(AVIOContext *pb)
static int update_init_section(struct playlist *pls, struct segment *seg)
static struct rendition * new_rendition(HLSContext *c, struct rendition_info *info, const char *url_base)
static int read_from_url(struct playlist *pls, struct segment *seg, uint8_t *buf, int buf_size)
static struct segment * new_init_section(struct playlist *pls, struct init_section_info *info, const char *url_base)
static int find_timestamp_in_playlist(HLSContext *c, struct playlist *pls, int64_t timestamp, int64_t *seq_no, int64_t *seg_start_ts)
static int read_data_continuous(void *opaque, uint8_t *buf, int buf_size)
static int hls_read_header(AVFormatContext *s)
static struct playlist * new_playlist(HLSContext *c, const char *url, const char *base)
static int read_subtitle_packet(struct playlist *v, AVPacket *pkt)
static int set_stream_info_from_input_stream(AVStream *st, struct playlist *pls, AVStream *ist)
static int test_segment(AVFormatContext *s, const AVInputFormat *in_fmt, struct playlist *pls, struct segment *seg)
static void free_segment_list(struct playlist *pls)
static void handle_key_args(void *context, const char *key, int key_len, char **dest, int *dest_len)
static void free_init_section_list(struct playlist *pls)
static void add_renditions_to_variant(HLSContext *c, struct variant *var, enum AVMediaType type, const char *group_id)
static int hls_probe(const AVProbeData *p)
static int ensure_playlist(HLSContext *c, struct playlist **pls, const char *url)
static int recheck_discard_flags(AVFormatContext *s, int first)
static AVRational get_timebase(struct playlist *pls)
static void fill_timing_for_id3_timestamped_stream(struct playlist *pls)
static int64_t default_reload_interval(struct playlist *pls)
static int open_url_keepalive(AVFormatContext *s, AVIOContext **pb, const char *url, AVDictionary **options)
static void add_metadata_from_renditions(AVFormatContext *s, struct playlist *pls, enum AVMediaType type)
static int update_streams_from_subdemuxer(AVFormatContext *s, struct playlist *pls)
static void add_stream_to_programs(AVFormatContext *s, struct playlist *pls, AVStream *stream)
static int hls_close(AVFormatContext *s)
static int metadata_has_changed(const AVDictionary *current, const AVDictionary *update)
Check whether any entry in update differs from the corresponding entry in current.
static struct segment * next_segment(struct playlist *pls)
static int nested_io_open(AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **opts)
static int reload_playlist(struct playlist *v, HLSContext *c)
static void handle_id3(AVIOContext *pb, struct playlist *pls)
static void handle_rendition_args(void *vinfo, const char *key, int key_len, char **dest, int *dest_len)
static void free_segment_dynarray(struct segment **segments, int n_segments)
static int read_data_subtitle_segment(void *opaque, uint8_t *buf, int buf_size)
static int init_subtitle_context(struct playlist *pls)
static int compare_ts_with_wrapdetect(int64_t ts_a, struct playlist *pls_a, int64_t ts_b, struct playlist *pls_b)
static int parse_playlist(HLSContext *c, const char *url, struct playlist *pls, AVIOContext *in)
static int segment_reusable(AVIOContext *in, const struct segment *cur, const struct segment *next)
static void handle_variant_args(void *context, const char *key, int key_len, char **dest, int *dest_len)
static struct segment * current_segment(struct playlist *pls)
static int hls_read_packet(AVFormatContext *s, AVPacket *pkt)
static const AVOption hls_options[]
static void free_rendition_list(HLSContext *c)
static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url, AVDictionary **opts, AVDictionary *opts2, int *is_http_out)
static int id3_has_changed_values(struct playlist *pls, AVDictionary *metadata, ID3v2ExtraMetaAPIC *apic)
static void free_playlist_list(HLSContext *c)
static const AVClass hls_class
static int64_t select_cur_seq_no(HLSContext *c, struct playlist *pls)
static struct variant * new_variant(HLSContext *c, struct variant_info *info, const char *url, const char *base)
static void intercept_id3(struct playlist *pls, uint8_t *buf, int buf_size, int *len)
static int playlist_needed(struct playlist *pls)
static void free_variant_list(HLSContext *c)
static void parse_id3(AVFormatContext *s, AVIOContext *pb, AVDictionary **metadata, int64_t *dts, HLSAudioSetupInfo *audio_setup_info, ID3v2ExtraMetaAPIC **apic, ID3v2ExtraMeta **extra_meta)
static void handle_init_section_args(void *context, const char *key, int key_len, char **dest, int *dest_len)
static int hls_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
int ff_hls_senc_decrypt_frame(enum AVCodecID codec_id, HLSCryptoContext *crypto_ctx, AVPacket *pkt)
int ff_hls_senc_parse_audio_setup_info(AVStream *st, HLSAudioSetupInfo *info)
void ff_hls_senc_read_audio_setup_info(HLSAudioSetupInfo *info, const uint8_t *buf, size_t size)
Apple HTTP Live Streaming Sample Encryption https://developer.apple.com/library/ios/documentation/Aud...
#define HLS_MAX_ID3_TAGS_DATA_LEN
int ff_http_do_new_request2(URLContext *h, const char *uri, AVDictionary **opts)
Send a new HTTP request, reusing the old connection.
int ff_id3v2_tag_len(const uint8_t *buf)
Get the length of an ID3v2 tag.
int ff_id3v2_match(const uint8_t *buf, const char *magic)
Detect ID3v2 Header.
void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta)
Free memory allocated parsing special (non-text) metadata.
int ff_id3v2_parse_priv_dict(AVDictionary **metadata, ID3v2ExtraMeta *extra_meta)
Parse PRIV tags into a dictionary.
int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta *extra_meta)
Create a stream for each APIC (attached picture) extracted from the ID3v2 header.
int ff_id3v2_parse_priv(AVFormatContext *s, ID3v2ExtraMeta *extra_meta)
Add metadata for all PRIV tags in the ID3v2 header.
void ff_id3v2_read_dict(AVFormatContext *s, AVIOContext *pb, AVDictionary **metadata, const char *magic, ID3v2ExtraMeta **extra_meta)
Read an ID3v2 tag into specified dictionary and retrieve supported extra metadata.
#define ID3v2_DEFAULT_MAGIC
Default magic bytes for ID3v2 header: "ID3".
#define ID3v2_HEADER_SIZE
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static av_cold int read_close(AVFormatContext *ctx)
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
#define FFSWAP(type, a, b)
Memory handling functions.
double strtod(const char *, char **)
uint8_t * data
The data buffer.
size_t size
Size of data in bytes.
Describe the class of an AVClass context structure.
enum AVMediaType codec_type
General type of the encoded data.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int event_flags
Flags indicating events happening on the file, a combination of AVFMT_EVENT_FLAG_*.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
AVIOContext * pb
I/O context.
AVDictionary * metadata
Metadata that applies to the whole file.
int flags
Flags modifying the (de)muxer behaviour.
int64_t max_analyze_duration
Maximum duration (in AV_TIME_BASE units) of the data read from input in avformat_find_stream_info().
int ctx_flags
Flags signalling stream properties.
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
const struct AVInputFormat * iformat
The input container format.
void * priv_data
Format private data.
int64_t probesize
Maximum number of bytes read from input in order to determine stream properties.
AVStream ** streams
A list of all streams in the file.
int(* io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)
A callback for opening new IO streams.
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 seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
unsigned char * buf_ptr
Current position in the buffer.
int64_t pos
position in the file of the current buffer
unsigned char * buffer
Start of the buffer.
int eof_reached
true if was unable to read due to error or eof
Callback for checking whether to abort blocking functions.
This structure stores compressed data.
int flags
A combination of AV_PKT_FLAG values.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
This structure contains the data a format has to probe a file.
New fields can be added to the end with minor version bumps.
unsigned int nb_stream_indexes
unsigned int * stream_index
enum AVDiscard discard
selects which program to discard and which to feed to the caller
Rational number (pair of numerator and denominator).
AVCodecParameters * codecpar
Codec parameters associated with this stream.
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
int id
Format-specific stream ID.
int index
stream index in AVFormatContext
int pts_wrap_bits
Number of bits in timestamps.
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
AVPacket attached_pic
For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet will contain the attached pictu...
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int event_flags
Flags indicating events happening on the stream, a combination of AVSTREAM_EVENT_FLAG_*.
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
int64_t pts_wrap_reference
Internal data to check for wrapping of the time stamp.
int need_context_update
Whether the internal avctx needs to be updated from codecpar (after a late change to codecpar)
uint8_t setup_data_length
int first_timestamp_locked
AVDictionary * seg_format_opts
struct rendition ** renditions
AVIOInterruptCB * interrupt_callback
char * allowed_segment_extensions
struct variant ** variants
AVIOContext * playlist_pb
struct playlist * first_timestamp_pls
HLSCryptoContext crypto_ctx
struct playlist ** playlists
char * allowed_extensions
const struct URLProtocol * prot
int64_t first_read_seq_no
int64_t id3_mpegts_timestamp
struct rendition ** renditions
unsigned int init_sec_data_len
HLSAudioSetupInfo audio_setup_info
unsigned int id3_buf_size
unsigned int init_sec_buf_read_offset
struct segment * cur_init_section
char key_url[MAX_URL_SIZE]
int timed_id3_stream_index
int64_t start_time_offset
AVDictionary * timed_id3_metadata
struct segment ** segments
struct segment ** init_sections
unsigned int init_sec_buf_size
ID3v2ExtraMeta * id3_deferred_extra
AVDictionary * id3_initial
char language[MAX_FIELD_LEN]
char group_id[MAX_FIELD_LEN]
char characteristics[MAX_CHARACTERISTICS_LEN]
char assoc_language[MAX_FIELD_LEN]
char group_id[MAX_FIELD_LEN]
char language[MAX_FIELD_LEN]
struct playlist * playlist
struct segment * init_section
char video[MAX_FIELD_LEN]
char subtitles[MAX_FIELD_LEN]
char audio[MAX_FIELD_LEN]
char audio_group[MAX_FIELD_LEN]
struct playlist ** playlists
char video_group[MAX_FIELD_LEN]
char subtitles_group[MAX_FIELD_LEN]
static AVDictionary * opts
int av_usleep(unsigned usec)
Sleep for a period of time.
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
int 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.
unbuffered private I/O API
static void fill_buf(uint8_t *data, int w, int h, int linesize, uint8_t v)
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)