Go to the documentation of this file.
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}
238 for (
i = 0;
i < n_segments;
i++) {
267 for (
i = 0;
i <
c->n_playlists;
i++) {
296 for (
i = 0;
i <
c->n_variants;
i++) {
308 for (
i = 0;
i <
c->n_renditions;
i++)
349 const char *
url,
const char *
base)
375 int key_len,
char **dest,
int *dest_len)
377 if (!strncmp(
key,
"BANDWIDTH=", key_len)) {
378 *dest =
info->bandwidth;
379 *dest_len =
sizeof(
info->bandwidth);
380 }
else if (!strncmp(
key,
"AUDIO=", key_len)) {
382 *dest_len =
sizeof(
info->audio);
383 }
else if (!strncmp(
key,
"VIDEO=", key_len)) {
385 *dest_len =
sizeof(
info->video);
386 }
else if (!strncmp(
key,
"SUBTITLES=", key_len)) {
387 *dest =
info->subtitles;
388 *dest_len =
sizeof(
info->subtitles);
399 int key_len,
char **dest,
int *dest_len)
401 if (!strncmp(
key,
"METHOD=", key_len)) {
402 *dest =
info->method;
403 *dest_len =
sizeof(
info->method);
404 }
else if (!strncmp(
key,
"URI=", key_len)) {
406 *dest_len =
sizeof(
info->uri);
407 }
else if (!strncmp(
key,
"IV=", key_len)) {
409 *dest_len =
sizeof(
info->iv);
420 const char *url_base)
447 if (
info->byterange[0]) {
449 ptr = strchr(
info->byterange,
'@');
463 int key_len,
char **dest,
int *dest_len)
465 if (!strncmp(
key,
"URI=", key_len)) {
467 *dest_len =
sizeof(
info->uri);
468 }
else if (!strncmp(
key,
"BYTERANGE=", key_len)) {
469 *dest =
info->byterange;
470 *dest_len =
sizeof(
info->byterange);
487 const char *url_base)
491 char *characteristic;
495 if (!strcmp(
info->type,
"AUDIO"))
497 else if (!strcmp(
info->type,
"VIDEO"))
499 else if (!strcmp(
info->type,
"SUBTITLES"))
501 else if (!strcmp(
info->type,
"CLOSED-CAPTIONS"))
543 if (
info->assoc_language[0]) {
544 size_t langlen = strlen(rend->
language);
545 if (langlen <
sizeof(rend->
language) - 3) {
549 info->assoc_language,
550 sizeof(rend->
language) - langlen - 1);
551 if (langlen + assoc_len + 2 >
sizeof(rend->
language))
553 info->assoc_language);
557 if (!strcmp(
info->defaultr,
"YES"))
559 if (!strcmp(
info->forced,
"YES"))
562 chr_ptr =
info->characteristics;
563 while ((characteristic =
av_strtok(chr_ptr,
",", &saveptr))) {
564 if (!strcmp(characteristic,
"public.accessibility.describes-music-and-sound"))
566 else if (!strcmp(characteristic,
"public.accessibility.describes-video"))
576 int key_len,
char **dest,
int *dest_len)
578 if (!strncmp(
key,
"TYPE=", key_len)) {
580 *dest_len =
sizeof(
info->type);
581 }
else if (!strncmp(
key,
"URI=", key_len)) {
583 *dest_len =
sizeof(
info->uri);
584 }
else if (!strncmp(
key,
"GROUP-ID=", key_len)) {
585 *dest =
info->group_id;
586 *dest_len =
sizeof(
info->group_id);
587 }
else if (!strncmp(
key,
"LANGUAGE=", key_len)) {
588 *dest =
info->language;
589 *dest_len =
sizeof(
info->language);
590 }
else if (!strncmp(
key,
"ASSOC-LANGUAGE=", key_len)) {
591 *dest =
info->assoc_language;
592 *dest_len =
sizeof(
info->assoc_language);
593 }
else if (!strncmp(
key,
"NAME=", key_len)) {
595 *dest_len =
sizeof(
info->name);
596 }
else if (!strncmp(
key,
"DEFAULT=", key_len)) {
597 *dest =
info->defaultr;
598 *dest_len =
sizeof(
info->defaultr);
599 }
else if (!strncmp(
key,
"FORCED=", key_len)) {
600 *dest =
info->forced;
601 *dest_len =
sizeof(
info->forced);
602 }
else if (!strncmp(
key,
"CHARACTERISTICS=", key_len)) {
603 *dest =
info->characteristics;
604 *dest_len =
sizeof(
info->characteristics);
625 *pls =
c->playlists[
c->n_playlists - 1];
632 #if !CONFIG_HTTP_PROTOCOL
638 (*pb)->eof_reached = 0;
652 const char *proto_name =
NULL;
657 if (url[6] ==
'+' || url[6] ==
':')
660 if (url[4] ==
'+' || url[4] ==
':')
672 if (strcmp(
c->allowed_extensions,
"ALL") && !
av_match_ext(url,
c->allowed_extensions)) {
674 "Filename extension of \'%s\' is not a common multimedia extension, blocked for security reasons.\n"
675 "If you wish to override this adjust allowed_extensions, you can set it to \'ALL\' to allow all\n",
686 if (!strncmp(proto_name, url, strlen(proto_name)) && url[strlen(proto_name)] ==
':')
688 else if (
av_strstart(url,
"crypto",
NULL) && !strncmp(proto_name, url + 7, strlen(proto_name)) && url[7 + strlen(proto_name)] ==
':')
690 else if (
av_strstart(url,
"data",
NULL) && !strncmp(proto_name, url + 5, strlen(proto_name)) && url[5 + strlen(proto_name)] ==
':')
692 else if (strcmp(proto_name,
"file") || !strncmp(url,
"file,", 5))
698 if (is_http &&
c->http_persistent && *pb) {
703 }
else if (
ret < 0) {
706 "keepalive request failed for '%s' with error: '%s' when opening url, retrying with new connection\n",
717 char *new_cookies =
NULL;
729 *is_http_out = is_http;
737 int ret = 0, is_segment = 0, is_variant = 0;
748 uint8_t *new_url =
NULL;
754 int prev_n_segments = 0;
755 int64_t prev_start_seq_no = -1;
757 if (is_http && !in &&
c->http_persistent &&
c->playlist_pb) {
762 }
else if (
ret < 0) {
765 "keepalive request failed for '%s' with error: '%s' when parsing playlist\n",
775 if (
c->http_persistent)
783 if (is_http &&
c->http_persistent)
793 if (strcmp(
line,
"#EXTM3U")) {
821 if (!strcmp(
info.method,
"AES-128"))
823 if (!strcmp(
info.method,
"SAMPLE-AES"))
840 t = strtoll(ptr,
NULL, 10);
851 seq_no = strtoull(ptr,
NULL, 10);
852 if (seq_no > INT64_MAX/2) {
854 "INT64_MAX/2, mask out the highest bit\n");
855 seq_no &= INT64_MAX/2;
862 if (!strcmp(ptr,
"EVENT"))
864 else if (!strcmp(ptr,
"VOD"))
874 if (!cur_init_section) {
878 cur_init_section->
key_type = key_type;
880 memcpy(cur_init_section->
iv, iv,
sizeof(iv));
883 memset(cur_init_section->
iv, 0,
sizeof(cur_init_section->
iv));
895 if (!cur_init_section->
key) {
905 const char *time_offset_value =
NULL;
910 if (
av_strstart(ptr,
"TIME-OFFSET=", &time_offset_value)) {
911 float offset = strtof(time_offset_value,
NULL);
916 "invalid, it will be ignored");
926 seg_size = strtoll(ptr,
NULL, 10);
927 ptr = strchr(ptr,
'@');
929 seg_offset = strtoll(ptr+1,
NULL, 10);
933 }
else if (
line[0]) {
952 memcpy(seg->
iv,
iv,
sizeof(
iv));
955 memset(seg->
iv, 0,
sizeof(seg->
iv));
994 " set to default value to 1ms.\n", seg->
url);
1002 seg->
size = seg_size;
1003 if (seg_size >= 0) {
1005 seg_offset += seg_size;
1016 if (prev_segments) {
1018 int64_t prev_timestamp =
c->first_timestamp;
1021 for (
i = 0;
i < prev_n_segments &&
i <
diff;
i++) {
1022 c->first_timestamp += prev_segments[
i]->
duration;
1025 " reflected in first_timestamp: %"PRId64
" -> %"PRId64
"\n",
1027 prev_timestamp,
c->first_timestamp);
1043 if (!
c->n_variants || !
c->variants[0]->n_playlists ||
1044 !(
c->variants[0]->playlists[0]->finished ||
1067 uint8_t *buf,
int buf_size)
1087 static const char id3_priv_owner_ts[] =
"com.apple.streaming.transportStreamTimestamp";
1088 static const char id3_priv_owner_audio_setup[] =
"com.apple.streaming.audioDescription";
1092 for (meta = *extra_meta; meta; meta = meta->
next) {
1093 if (!strcmp(meta->
tag,
"PRIV")) {
1099 if ((ts & ~((1ULL << 33) - 1)) == 0)
1106 }
else if (!strcmp(meta->
tag,
"APIC") && apic)
1120 if (!oldentry || strcmp(oldentry->
value,
entry->value) != 0)
1184 int buf_size,
int *
len)
1189 int id3_buf_pos = 0;
1207 }
else if (*
len <= 0) {
1220 int tag_got_bytes =
FFMIN(taglen, *
len);
1221 int remaining = taglen - tag_got_bytes;
1223 if (taglen > maxsize) {
1239 memcpy(pls->
id3_buf + id3_buf_pos, buf, tag_got_bytes);
1240 id3_buf_pos += tag_got_bytes;
1243 *
len -= tag_got_bytes;
1244 memmove(buf, buf + tag_got_bytes, *
len);
1247 if (remaining > 0) {
1251 id3_buf_pos += remaining;
1289 if (
c->http_persistent)
1292 if (seg->
size >= 0) {
1307 if (
ret !=
sizeof(pls->
key)) {
1324 if (strstr(seg->
url,
"://"))
1368 static const int max_init_section_size = 1024*1024;
1385 "Failed to open an initialization section in playlist %d\n",
1395 sec_size = max_init_section_size;
1398 "Downloading an initialization section of size %"PRId64
"\n",
1401 sec_size =
FFMIN(sec_size, max_init_section_size);
1434 int stream_needed = 0;
1460 for (
i = 0;
i <
s->nb_programs;
i++) {
1463 for (j = 0; j <
program->nb_stream_indexes; j++) {
1464 if (
program->stream_index[j] == first_st) {
1476 static int read_data(
void *opaque, uint8_t *buf,
int buf_size)
1481 int just_opened = 0;
1482 int reload_count = 0;
1483 int segment_retries = 0;
1509 if (reload_count >
c->max_reload)
1526 "skipping %"PRId64
" segments ahead, expired from playlists\n",
1575 if (segment_retries >=
c->seg_max_retry) {
1580 segment_retries = 0;
1586 segment_retries = 0;
1590 if (
c->http_multiple == -1) {
1591 uint8_t *http_version_opt =
NULL;
1594 c->http_multiple = (!strncmp((
const char *)http_version_opt,
"1.1", 3) || !strncmp((
const char *)http_version_opt,
"2.0", 3));
1633 if (
c->http_persistent &&
1651 for (
i = 0;
i <
c->n_renditions;
i++) {
1708 0 :
c->first_timestamp;
1710 if (timestamp <
pos) {
1720 *seg_start_ts =
pos;
1736 if (!pls->
finished && !
c->first_packet &&
1750 if (!
c->first_packet &&
1757 return c->cur_seq_no;
1761 if (
c->live_start_index < 0)
1763 c->live_start_index, 0);
1771 int64_t playlist_duration = 0;
1784 start_timestamp = cur_timestamp + playlist_duration;
1790 start_timestamp = cur_timestamp;
1793 start_timestamp = cur_timestamp + playlist_duration +
1796 start_timestamp = cur_timestamp;
1811 "A HLS playlist item '%s' referred to an external file '%s'. "
1812 "Opening this file was forbidden for security reasons\n",
1823 for (
i = 0;
i <
c->n_variants;
i++) {
1895 int flag_needed = 0;
1898 for (
i = 0;
i <
c->n_playlists;
i++) {
1921 if (
c->crypto_ctx.aes_ctx)
1934 int64_t highest_cur_seq_no = 0;
1937 c->interrupt_callback = &
s->interrupt_callback;
1939 c->first_packet = 1;
1954 if (
c->n_variants == 0) {
1960 if (
c->n_playlists > 1 ||
c->playlists[0]->n_segments == 0) {
1961 for (
i = 0;
i <
c->n_playlists;
i++) {
1967 if (
c->n_playlists > 1)
1974 for (
i = 0;
i <
c->n_variants;
i++) {
1975 if (
c->variants[
i]->playlists[0]->n_segments == 0) {
1977 c->variants[
i]->playlists[0]->broken = 1;
1983 if (
c->variants[0]->playlists[0]->finished) {
1985 for (
i = 0;
i <
c->variants[0]->playlists[0]->n_segments;
i++)
1986 duration +=
c->variants[0]->playlists[0]->segments[
i]->duration;
1991 for (
i = 0;
i <
c->n_variants;
i++) {
2003 for (
i = 0;
i <
c->n_variants;
i++) {
2014 for (
i = 0;
i <
c->n_playlists;
i++) {
2025 for (
i = 0;
i <
c->n_playlists;
i++) {
2050 highest_cur_seq_no < pls->start_seq_no + pls->
n_segments) {
2112 pls->
ctx->
probesize =
s->probesize > 0 ?
s->probesize : 1024 * 4;
2133 if (strstr(in_fmt->
name,
"mov")) {
2137 }
else if (!
c->crypto_ctx.aes_ctx) {
2139 if (!
c->crypto_ctx.aes_ctx) {
2220 for (
i = 0;
i <
c->n_playlists;
i++) {
2228 if (cur_needed && !pls->
needed) {
2298 int ret,
i, minplaylist = -1;
2301 c->first_packet = 0;
2303 for (
i = 0;
i <
c->n_playlists;
i++) {
2333 memcpy(
c->crypto_ctx.iv, seg->
iv,
sizeof(seg->
iv));
2334 memcpy(
c->crypto_ctx.key, pls->
key,
sizeof(pls->
key));
2364 struct playlist *minpls = minplaylist < 0 ?
2365 NULL :
c->playlists[minplaylist];
2366 if (minplaylist < 0) {
2380 if (minplaylist >= 0) {
2381 struct playlist *pls =
c->playlists[minplaylist];
2409 av_log(
s,
AV_LOG_ERROR,
"stream index inconsistency: index %d, %d main streams, %d subdemuxer streams\n",
2446 int stream_subdemuxer_index;
2454 0 :
c->first_timestamp;
2457 s->streams[stream_index]->time_base.den,
2467 for (
i = 0;
i <
c->n_playlists;
i++) {
2472 stream_subdemuxer_index = j;
2493 for (
i = 0;
i <
c->n_playlists;
i++) {
2502 pb->eof_reached = 0;
2504 pb->buf_end =
pb->buf_ptr =
pb->buffer;
2516 if (pls != seek_pls) {
2536 if (strncmp(p->
buf,
"#EXTM3U", 7))
2539 if (strstr(p->
buf,
"#EXT-X-STREAM-INF:") ||
2540 strstr(p->
buf,
"#EXT-X-TARGETDURATION:") ||
2541 strstr(p->
buf,
"#EXT-X-MEDIA-SEQUENCE:")) {
2557 av_log(
NULL,
AV_LOG_ERROR,
"Not detecting m3u8/hls with non standard extension and non standard mime type\n");
2568 #define OFFSET(x) offsetof(HLSContext, x)
2569 #define FLAGS AV_OPT_FLAG_DECODING_PARAM
2571 {
"live_start_index",
"segment index to start live streams at (negative values are from the end)",
2573 {
"prefer_x_start",
"prefer to use #EXT-X-START if it's in playlist instead of live_start_index",
2575 {
"allowed_extensions",
"List of file extensions that hls is allowed to access",
2577 {.str =
"3gp,aac,avi,ac3,eac3,flac,mkv,m3u8,m4a,m4s,m4v,mpg,mov,mp2,mp3,mp4,mpeg,mpegts,ogg,ogv,oga,ts,vob,wav"},
2578 INT_MIN, INT_MAX,
FLAGS},
2579 {
"max_reload",
"Maximum number of times a insufficient list is attempted to be reloaded",
2581 {
"m3u8_hold_counters",
"The maximum number of times to load m3u8 when it refreshes without new segments",
2583 {
"http_persistent",
"Use persistent HTTP connections",
2585 {
"http_multiple",
"Use multiple HTTP connections for fetching segments",
2587 {
"http_seekable",
"Use HTTP partial requests, 0 = disable, 1 = enable, -1 = auto",
2589 {
"seg_format_options",
"Set options for segment demuxer",
2591 {
"seg_max_retry",
"Maximum number of times to reload a segment on error.",
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
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.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define MAX_CHARACTERISTICS_LEN
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C program
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))
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 void free_segment_dynarray(struct segment **segments, int n_segments)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
enum AVMediaType codec_type
General type of the encoded data.
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AVERROR_EOF
End of file.
uint8_t * data
The data buffer.
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
char subtitles[MAX_FIELD_LEN]
int64_t id3_mpegts_timestamp
static struct segment * new_init_section(struct playlist *pls, struct init_section_info *info, const char *url_base)
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
char assoc_language[MAX_FIELD_LEN]
static av_cold void cleanup(FlashSV2Context *s)
AVStream ** streams
A list of all streams in the file.
char subtitles_group[MAX_FIELD_LEN]
static int compare_ts_with_wrapdetect(int64_t ts_a, struct playlist *pls_a, int64_t ts_b, struct playlist *pls_b)
struct segment ** segments
static int nested_io_open(AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **opts)
#define AV_LOG_VERBOSE
Detailed information.
uint8_t setup_data_length
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
void ffio_init_read_context(FFIOContext *s, const uint8_t *buffer, int buffer_size)
Wrap a buffer in an AVIOContext for reading.
int64_t probesize
Maximum number of bytes read from input in order to determine stream properties.
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
void ff_read_frame_flush(AVFormatContext *s)
Flush the frame reader.
int64_t avio_size(AVIOContext *s)
Get the filesize.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
char key_url[MAX_URL_SIZE]
int64_t start_time_offset
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Callback for checking whether to abort blocking functions.
int avformat_queue_attached_pictures(AVFormatContext *s)
static int hls_close(AVFormatContext *s)
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
char audio_group[MAX_FIELD_LEN]
static int recheck_discard_flags(AVFormatContext *s, int first)
static const AVClass hls_class
static struct variant * new_variant(HLSContext *c, struct variant_info *info, const char *url, const char *base)
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
static av_cold int read_close(AVFormatContext *ctx)
int64_t pos
position in the file of the current buffer
void ff_hls_senc_read_audio_setup_info(HLSAudioSetupInfo *info, const uint8_t *buf, size_t size)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
AVProgram * av_new_program(AVFormatContext *ac, int id)
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrupt a blocking function associated with cb.
#define HLS_MAX_ID3_TAGS_DATA_LEN
static void handle_rendition_args(struct rendition_info *info, const char *key, int key_len, char **dest, int *dest_len)
int event_flags
Flags indicating events happening on the file, a combination of AVFMT_EVENT_FLAG_*.
AVPacket attached_pic
For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet will contain the attached pictu...
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url, AVDictionary **opts, AVDictionary *opts2, int *is_http_out)
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But first
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVDictionary * metadata
Metadata that applies to the whole file.
const char * mime_type
mime_type, when known.
int ctx_flags
Flags signalling stream properties.
static void free_rendition_list(HLSContext *c)
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
static const AVOption hls_options[]
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
static void fill_timing_for_id3_timestamped_stream(struct playlist *pls)
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.
static int playlist_needed(struct playlist *pls)
int flags
Flags modifying the (de)muxer behaviour.
const struct AVInputFormat * iformat
The input container format.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
unsigned int init_sec_buf_read_offset
char video[MAX_FIELD_LEN]
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_match_ext(const char *filename, const char *extensions)
Return a positive value if the given filename has one of the given extensions, 0 otherwise.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
char audio[MAX_FIELD_LEN]
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
struct segment ** init_sections
static void add_renditions_to_variant(HLSContext *c, struct variant *var, enum AVMediaType type, const char *group_id)
char * allowed_extensions
HLSCryptoContext crypto_ctx
int av_usleep(unsigned usec)
Sleep for a period of time.
unsigned int id3_buf_size
AVDictionary * seg_format_opts
static int hls_read_header(AVFormatContext *s)
int64_t max_analyze_duration
Maximum duration (in AV_TIME_BASE units) of the data read from input in avformat_find_stream_info().
static void handle_id3(AVIOContext *pb, struct playlist *pls)
static void free_variant_list(HLSContext *c)
#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...
char group_id[MAX_FIELD_LEN]
@ AVDISCARD_ALL
discard all
const FFInputFormat ff_hls_demuxer
AVIOInterruptCB * interrupt_callback
AVCodecParameters * codecpar
Codec parameters associated with this stream.
#define LIBAVUTIL_VERSION_INT
static int read_header(FFV1Context *f)
static struct segment * current_segment(struct playlist *pls)
Describe the class of an AVClass context structure.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
struct playlist ** playlists
static int ensure_playlist(HLSContext *c, struct playlist **pls, const char *url)
static void fill_buf(uint8_t *data, int w, int h, int linesize, uint8_t v)
struct rendition ** renditions
AVIOContext * playlist_pb
Rational number (pair of numerator and denominator).
static void free_init_section_list(struct playlist *pls)
struct variant ** variants
static int update_streams_from_subdemuxer(AVFormatContext *s, struct playlist *pls)
@ AV_OPT_TYPE_DICT
Underlying C type is AVDictionary*.
const char * av_default_item_name(void *ptr)
Return the context name.
int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta *extra_meta)
Create a stream for each APIC (attached picture) extracted from the ID3v2 header.
AVIOContext * pb
I/O context.
int ff_http_do_new_request2(URLContext *h, const char *uri, AVDictionary **opts)
Send a new HTTP request, reusing the old connection.
This structure contains the data a format has to probe a file.
struct AVAES * av_aes_alloc(void)
Allocate an AVAES context.
URLContext * ffio_geturlcontext(AVIOContext *s)
Return the URLContext associated with the AVIOContext.
ID3v2ExtraMeta * id3_deferred_extra
struct playlist ** playlists
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
static void handle_init_section_args(struct init_section_info *info, const char *key, int key_len, char **dest, int *dest_len)
#define INITIAL_BUFFER_SIZE
#define ID3v2_HEADER_SIZE
static int id3_has_changed_values(struct playlist *pls, AVDictionary *metadata, ID3v2ExtraMetaAPIC *apic)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
AVCodecID
Identify the syntax and semantics of the bitstream.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
@ AV_ROUND_DOWN
Round toward -infinity.
int av_strncasecmp(const char *a, const char *b, size_t n)
Locale-independent case-insensitive compare.
unsigned int init_sec_buf_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.
const OptionDef options[]
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
struct segment * cur_init_section
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
unsigned char * buf_end
End of the data, may be less than buffer+buffer_size if the read function returned less data than req...
static struct rendition * new_rendition(HLSContext *c, struct rendition_info *info, const char *url_base)
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define ID3v2_DEFAULT_MAGIC
Default magic bytes for ID3v2 header: "ID3".
#define AV_NOPTS_VALUE
Undefined timestamp value.
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
int event_flags
Flags indicating events happening on the stream, a combination of AVSTREAM_EVENT_FLAG_*.
char characteristics[MAX_CHARACTERISTICS_LEN]
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
static AVRational get_timebase(struct playlist *pls)
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
static int update_init_section(struct playlist *pls, struct segment *seg)
int flags
A combination of AV_PKT_FLAG values.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
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.
static int read_data(void *opaque, uint8_t *buf, int buf_size)
struct playlist * playlist
size_t size
Size of data in bytes.
#define AV_LOG_INFO
Standard information.
static void free_segment_list(struct playlist *pls)
int ff_hls_senc_decrypt_frame(enum AVCodecID codec_id, HLSCryptoContext *crypto_ctx, AVPacket *pkt)
static void add_metadata_from_renditions(AVFormatContext *s, struct playlist *pls, enum AVMediaType type)
static struct segment * next_segment(struct playlist *pls)
static void update_noheader_flag(AVFormatContext *s)
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_TIME_BASE
Internal time base represented as integer.
void ff_id3v2_read_dict(AVIOContext *pb, AVDictionary **metadata, const char *magic, ID3v2ExtraMeta **extra_meta)
Read an ID3v2 tag into specified dictionary and retrieve supported extra metadata.
static int64_t select_cur_seq_no(HLSContext *c, struct playlist *pls)
char video_group[MAX_FIELD_LEN]
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
static int64_t default_reload_interval(struct playlist *pls)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
New fields can be added to the end with minor version bumps.
static int open_url_keepalive(AVFormatContext *s, AVIOContext **pb, const char *url, AVDictionary **options)
static void free_playlist_list(HLSContext *c)
int ff_hls_senc_parse_audio_setup_info(AVStream *st, HLSAudioSetupInfo *info)
char language[MAX_FIELD_LEN]
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
int ff_id3v2_tag_len(const uint8_t *buf)
Get the length of an ID3v2 tag.
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.
int id
Format-specific stream ID.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
#define FFSWAP(type, a, b)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
HLSAudioSetupInfo audio_setup_info
#define AV_INPUT_BUFFER_PADDING_SIZE
#define AV_DICT_MATCH_CASE
Only get an entry with exact-case key match.
static int open_input(HLSContext *c, struct playlist *pls, struct segment *seg, AVIOContext **in)
static int hls_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
static struct playlist * new_playlist(HLSContext *c, const char *url, const char *base)
static int set_stream_info_from_input_stream(AVStream *st, struct playlist *pls, AVStream *ist)
int index
stream index in AVFormatContext
AVDictionary * id3_initial
static int parse_playlist(HLSContext *c, const char *url, struct playlist *pls, AVIOContext *in)
@ AV_OPT_TYPE_INT
Underlying C type is int.
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
int(* io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)
A callback for opening new IO streams.
int eof_reached
true if was unable to read due to error or eof
const AVInputFormat * av_find_input_format(const char *short_name)
Find AVInputFormat based on the short name of the input format.
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 AVIO_FLAG_READ
read-only
static void add_stream_to_programs(AVFormatContext *s, struct playlist *pls, AVStream *stream)
char * av_strdup(const char *s)
Duplicate a string.
static int hls_probe(const AVProbeData *p)
static int read_probe(const AVProbeData *p)
unsigned int init_sec_data_len
static int hls_read_packet(AVFormatContext *s, AVPacket *pkt)
unsigned char * buffer
Start of the buffer.
static void handle_variant_args(struct variant_info *info, const char *key, int key_len, char **dest, int *dest_len)
static int find_timestamp_in_playlist(HLSContext *c, struct playlist *pls, int64_t timestamp, int64_t *seq_no, int64_t *seg_start_ts)
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.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
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_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta)
Free memory allocated parsing special (non-text) metadata.
struct segment * init_section
const char * avio_find_protocol_name(const char *url)
Return the name of the protocol that will handle the passed URL.
int need_context_update
Whether the internal avctx needs to be updated from codecpar (after a late change to codecpar)
#define flags(name, subs,...)
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
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_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
int ff_id3v2_parse_priv(AVFormatContext *s, ID3v2ExtraMeta *extra_meta)
Add metadata for all PRIV tags in the ID3v2 header.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
@ 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...
static void handle_key_args(struct key_info *info, const char *key, int key_len, char **dest, int *dest_len)
int pts_wrap_bits
Number of bits in timestamps.
static void parse_id3(AVFormatContext *s, AVIOContext *pb, AVDictionary **metadata, int64_t *dts, HLSAudioSetupInfo *audio_setup_info, ID3v2ExtraMetaAPIC **apic, ID3v2ExtraMeta **extra_meta)
unsigned char * buf_ptr
Current position in the buffer.
static int read_from_url(struct playlist *pls, struct segment *seg, uint8_t *buf, int buf_size)
int ff_id3v2_parse_priv_dict(AVDictionary **metadata, ID3v2ExtraMeta *extra_meta)
Parse PRIV tags into a dictionary.
#define AVERROR_PROTOCOL_NOT_FOUND
Protocol not found.
void * priv_data
Format private data.
static void intercept_id3(struct playlist *pls, uint8_t *buf, int buf_size, int *len)
char language[MAX_FIELD_LEN]
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_RB64
struct rendition ** renditions
char group_id[MAX_FIELD_LEN]
int ff_id3v2_match(const uint8_t *buf, const char *magic)
Detect ID3v2 Header.
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.