FFmpeg  4.0
Data Structures | Macros | Enumerations | Functions | Variables
hls.c File Reference

Apple HTTP Live Streaming demuxer http://tools.ietf.org/html/draft-pantos-http-live-streaming. More...

#include "libavformat/http.h"
#include "libavutil/avstring.h"
#include "libavutil/avassert.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
#include "libavutil/dict.h"
#include "libavutil/time.h"
#include "avformat.h"
#include "internal.h"
#include "avio_internal.h"
#include "id3v2.h"

Go to the source code of this file.

Data Structures

struct  segment
 
struct  playlist
 
struct  rendition
 
struct  variant
 
struct  HLSContext
 
struct  variant_info
 
struct  key_info
 
struct  init_section_info
 
struct  rendition_info
 

Macros

#define INITIAL_BUFFER_SIZE   32768
 
#define MAX_FIELD_LEN   64
 
#define MAX_CHARACTERISTICS_LEN   512
 
#define MPEG_TIME_BASE   90000
 
#define MPEG_TIME_BASE_Q   (AVRational){1, MPEG_TIME_BASE}
 
#define OFFSET(x)   offsetof(HLSContext, x)
 
#define FLAGS   AV_OPT_FLAG_DECODING_PARAM
 

Enumerations

enum  KeyType { KEY_NONE, KEY_AES_128, KEY_SAMPLE_AES }
 
enum  PlaylistType {
  PLS_TYPE_UNSPECIFIED, PLS_TYPE_EVENT, PLS_TYPE_VOD, PLAYLIST_TYPE_NONE,
  PLAYLIST_TYPE_EVENT, PLAYLIST_TYPE_VOD, PLAYLIST_TYPE_NB
}
 
enum  ReadFromURLMode { READ_NORMAL, READ_COMPLETE, READ_NORMAL, READ_COMPLETE }
 

Functions

static void free_segment_list (struct playlist *pls)
 
static void free_init_section_list (struct playlist *pls)
 
static void free_playlist_list (HLSContext *c)
 
static void free_variant_list (HLSContext *c)
 
static void free_rendition_list (HLSContext *c)
 
static void reset_packet (AVPacket *pkt)
 
static struct playlistnew_playlist (HLSContext *c, const char *url, const char *base)
 
static struct variantnew_variant (HLSContext *c, struct variant_info *info, const char *url, const char *base)
 
static void handle_variant_args (struct variant_info *info, const char *key, int key_len, char **dest, int *dest_len)
 
static void handle_key_args (struct key_info *info, const char *key, int key_len, char **dest, int *dest_len)
 
static struct segmentnew_init_section (struct playlist *pls, struct init_section_info *info, const char *url_base)
 
static void handle_init_section_args (struct init_section_info *info, const char *key, int key_len, char **dest, int *dest_len)
 
static struct renditionnew_rendition (HLSContext *c, struct rendition_info *info, const char *url_base)
 
static void handle_rendition_args (struct rendition_info *info, const char *key, int key_len, char **dest, int *dest_len)
 
static int ensure_playlist (HLSContext *c, struct playlist **pls, const char *url)
 
static void update_options (char **dest, const char *name, void *src)
 
static int open_url_keepalive (AVFormatContext *s, AVIOContext **pb, const char *url)
 
static int open_url (AVFormatContext *s, AVIOContext **pb, const char *url, AVDictionary *opts, AVDictionary *opts2, int *is_http_out)
 
static int parse_playlist (HLSContext *c, const char *url, struct playlist *pls, AVIOContext *in)
 
static struct segmentcurrent_segment (struct playlist *pls)
 
static struct segmentnext_segment (struct playlist *pls)
 
static int read_from_url (struct playlist *pls, struct segment *seg, uint8_t *buf, int buf_size, enum ReadFromURLMode mode)
 
static void parse_id3 (AVFormatContext *s, AVIOContext *pb, AVDictionary **metadata, int64_t *dts, ID3v2ExtraMetaAPIC **apic, ID3v2ExtraMeta **extra_meta)
 
static int id3_has_changed_values (struct playlist *pls, AVDictionary *metadata, ID3v2ExtraMetaAPIC *apic)
 
static void handle_id3 (AVIOContext *pb, struct playlist *pls)
 
static void intercept_id3 (struct playlist *pls, uint8_t *buf, int buf_size, int *len)
 
static int open_input (HLSContext *c, struct playlist *pls, struct segment *seg, AVIOContext **in)
 
static int update_init_section (struct playlist *pls, struct segment *seg)
 
static int64_t default_reload_interval (struct playlist *pls)
 
static int playlist_needed (struct playlist *pls)
 
static int read_data (void *opaque, uint8_t *buf, int buf_size)
 
static void add_renditions_to_variant (HLSContext *c, struct variant *var, enum AVMediaType type, const char *group_id)
 
static void add_metadata_from_renditions (AVFormatContext *s, struct playlist *pls, enum AVMediaType type)
 
static int find_timestamp_in_playlist (HLSContext *c, struct playlist *pls, int64_t timestamp, int *seq_no)
 
static int select_cur_seq_no (HLSContext *c, struct playlist *pls)
 
static int save_avio_options (AVFormatContext *s)
 
static int nested_io_open (AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **opts)
 
static void add_stream_to_programs (AVFormatContext *s, struct playlist *pls, AVStream *stream)
 
static int set_stream_info_from_input_stream (AVStream *st, struct playlist *pls, AVStream *ist)
 
static int update_streams_from_subdemuxer (AVFormatContext *s, struct playlist *pls)
 
static void update_noheader_flag (AVFormatContext *s)
 
static int hls_close (AVFormatContext *s)
 
static int hls_read_header (AVFormatContext *s)
 
static int recheck_discard_flags (AVFormatContext *s, int first)
 
static void fill_timing_for_id3_timestamped_stream (struct playlist *pls)
 
static AVRational get_timebase (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 hls_read_packet (AVFormatContext *s, AVPacket *pkt)
 
static int hls_read_seek (AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
 
static int hls_probe (AVProbeData *p)
 

Variables

static const AVOption hls_options []
 
static const AVClass hls_class
 
AVInputFormat ff_hls_demuxer
 

Detailed Description

Apple HTTP Live Streaming demuxer http://tools.ietf.org/html/draft-pantos-http-live-streaming.

Definition in file hls.c.

Macro Definition Documentation

◆ INITIAL_BUFFER_SIZE

#define INITIAL_BUFFER_SIZE   32768

Definition at line 42 of file hls.c.

Referenced by hls_read_header().

◆ MAX_FIELD_LEN

#define MAX_FIELD_LEN   64

Definition at line 44 of file hls.c.

◆ MAX_CHARACTERISTICS_LEN

#define MAX_CHARACTERISTICS_LEN   512

Definition at line 45 of file hls.c.

◆ MPEG_TIME_BASE

#define MPEG_TIME_BASE   90000

Definition at line 47 of file hls.c.

Referenced by set_stream_info_from_input_stream().

◆ MPEG_TIME_BASE_Q

#define MPEG_TIME_BASE_Q   (AVRational){1, MPEG_TIME_BASE}

◆ OFFSET

#define OFFSET (   x)    offsetof(HLSContext, x)

Definition at line 2318 of file hls.c.

◆ FLAGS

#define FLAGS   AV_OPT_FLAG_DECODING_PARAM

Definition at line 2319 of file hls.c.

Enumeration Type Documentation

◆ KeyType

enum KeyType
Enumerator
KEY_NONE 
KEY_AES_128 
KEY_SAMPLE_AES 

Definition at line 62 of file hls.c.

◆ PlaylistType

Enumerator
PLS_TYPE_UNSPECIFIED 
PLS_TYPE_EVENT 
PLS_TYPE_VOD 
PLAYLIST_TYPE_NONE 
PLAYLIST_TYPE_EVENT 
PLAYLIST_TYPE_VOD 
PLAYLIST_TYPE_NB 

Definition at line 82 of file hls.c.

◆ ReadFromURLMode

Enumerator
READ_NORMAL 
READ_COMPLETE 
READ_NORMAL 
READ_COMPLETE 

Definition at line 940 of file hls.c.

Function Documentation

◆ free_segment_list()

static void free_segment_list ( struct playlist pls)
static

Definition at line 219 of file hls.c.

Referenced by free_playlist_list(), and parse_playlist().

◆ free_init_section_list()

static void free_init_section_list ( struct playlist pls)
static

Definition at line 231 of file hls.c.

Referenced by free_playlist_list().

◆ free_playlist_list()

static void free_playlist_list ( HLSContext c)
static

Definition at line 242 of file hls.c.

Referenced by hls_close().

◆ free_variant_list()

static void free_variant_list ( HLSContext c)
static

Definition at line 277 of file hls.c.

Referenced by hls_close().

◆ free_rendition_list()

static void free_rendition_list ( HLSContext c)
static

Definition at line 289 of file hls.c.

Referenced by hls_close().

◆ reset_packet()

static void reset_packet ( AVPacket pkt)
static

Definition at line 302 of file hls.c.

Referenced by hls_read_packet(), hls_read_seek(), and new_playlist().

◆ new_playlist()

static struct playlist* new_playlist ( HLSContext c,
const char *  url,
const char *  base 
)
static

Definition at line 308 of file hls.c.

Referenced by new_rendition(), and new_variant().

◆ new_variant()

static struct variant* new_variant ( HLSContext c,
struct variant_info info,
const char *  url,
const char *  base 
)
static

Definition at line 333 of file hls.c.

Referenced by ensure_playlist(), and parse_playlist().

◆ handle_variant_args()

static void handle_variant_args ( struct variant_info info,
const char *  key,
int  key_len,
char **  dest,
int dest_len 
)
static

Definition at line 359 of file hls.c.

Referenced by parse_playlist().

◆ handle_key_args()

static void handle_key_args ( struct key_info info,
const char *  key,
int  key_len,
char **  dest,
int dest_len 
)
static

Definition at line 383 of file hls.c.

Referenced by parse_playlist().

◆ new_init_section()

static struct segment* new_init_section ( struct playlist pls,
struct init_section_info info,
const char *  url_base 
)
static

Definition at line 403 of file hls.c.

Referenced by parse_playlist().

◆ handle_init_section_args()

static void handle_init_section_args ( struct init_section_info info,
const char *  key,
int  key_len,
char **  dest,
int dest_len 
)
static

Definition at line 440 of file hls.c.

Referenced by parse_playlist().

◆ new_rendition()

static struct rendition* new_rendition ( HLSContext c,
struct rendition_info info,
const char *  url_base 
)
static

Definition at line 464 of file hls.c.

Referenced by parse_playlist().

◆ handle_rendition_args()

static void handle_rendition_args ( struct rendition_info info,
const char *  key,
int  key_len,
char **  dest,
int dest_len 
)
static

Definition at line 542 of file hls.c.

Referenced by parse_playlist().

◆ ensure_playlist()

static int ensure_playlist ( HLSContext c,
struct playlist **  pls,
const char *  url 
)
static

Definition at line 586 of file hls.c.

Referenced by parse_playlist().

◆ update_options()

static void update_options ( char **  dest,
const char *  name,
void src 
)
static

Definition at line 596 of file hls.c.

Referenced by hls_read_header().

◆ open_url_keepalive()

static int open_url_keepalive ( AVFormatContext s,
AVIOContext **  pb,
const char *  url 
)
static

Definition at line 604 of file hls.c.

Referenced by open_url(), and parse_playlist().

◆ open_url()

static int open_url ( AVFormatContext s,
AVIOContext **  pb,
const char *  url,
AVDictionary opts,
AVDictionary opts2,
int is_http_out 
)
static

Definition at line 622 of file hls.c.

Referenced by open_input().

◆ parse_playlist()

static int parse_playlist ( HLSContext c,
const char *  url,
struct playlist pls,
AVIOContext in 
)
static

Definition at line 703 of file hls.c.

Referenced by hls_read_header(), read_data(), and select_cur_seq_no().

◆ current_segment()

static struct segment* current_segment ( struct playlist pls)
static

Definition at line 927 of file hls.c.

Referenced by intercept_id3(), and read_data().

◆ next_segment()

static struct segment* next_segment ( struct playlist pls)
static

Definition at line 932 of file hls.c.

Referenced by read_data().

◆ read_from_url()

static int read_from_url ( struct playlist pls,
struct segment seg,
uint8_t buf,
int  buf_size,
enum ReadFromURLMode  mode 
)
static

Definition at line 945 of file hls.c.

Referenced by intercept_id3(), read_data(), and update_init_section().

◆ parse_id3()

static void parse_id3 ( AVFormatContext s,
AVIOContext pb,
AVDictionary **  metadata,
int64_t *  dts,
ID3v2ExtraMetaAPIC **  apic,
ID3v2ExtraMeta **  extra_meta 
)
static

Definition at line 969 of file hls.c.

Referenced by handle_id3().

◆ id3_has_changed_values()

static int id3_has_changed_values ( struct playlist pls,
AVDictionary metadata,
ID3v2ExtraMetaAPIC apic 
)
static

Definition at line 995 of file hls.c.

Referenced by handle_id3().

◆ handle_id3()

static void handle_id3 ( AVIOContext pb,
struct playlist pls 
)
static

Definition at line 1024 of file hls.c.

Referenced by intercept_id3().

◆ intercept_id3()

static void intercept_id3 ( struct playlist pls,
uint8_t buf,
int  buf_size,
int len 
)
static

Definition at line 1066 of file hls.c.

Referenced by read_data().

◆ open_input()

static int open_input ( HLSContext c,
struct playlist pls,
struct segment seg,
AVIOContext **  in 
)
static

Definition at line 1166 of file hls.c.

Referenced by read_data(), and update_init_section().

◆ update_init_section()

static int update_init_section ( struct playlist pls,
struct segment seg 
)
static

Definition at line 1266 of file hls.c.

Referenced by read_data().

◆ default_reload_interval()

static int64_t default_reload_interval ( struct playlist pls)
static

Definition at line 1323 of file hls.c.

Referenced by read_data(), and select_cur_seq_no().

◆ playlist_needed()

static int playlist_needed ( struct playlist pls)
static

Definition at line 1330 of file hls.c.

Referenced by read_data(), and recheck_discard_flags().

◆ read_data()

static int read_data ( void opaque,
uint8_t buf,
int  buf_size 
)
static

Definition at line 1376 of file hls.c.

Referenced by hls_read_header().

◆ add_renditions_to_variant()

static void add_renditions_to_variant ( HLSContext c,
struct variant var,
enum AVMediaType  type,
const char *  group_id 
)
static

Definition at line 1524 of file hls.c.

Referenced by hls_read_header().

◆ add_metadata_from_renditions()

static void add_metadata_from_renditions ( AVFormatContext s,
struct playlist pls,
enum AVMediaType  type 
)
static

Definition at line 1548 of file hls.c.

Referenced by hls_read_header().

◆ find_timestamp_in_playlist()

static int find_timestamp_in_playlist ( HLSContext c,
struct playlist pls,
int64_t  timestamp,
int seq_no 
)
static

Definition at line 1580 of file hls.c.

Referenced by hls_read_seek(), and select_cur_seq_no().

◆ select_cur_seq_no()

static int select_cur_seq_no ( HLSContext c,
struct playlist pls 
)
static

Definition at line 1606 of file hls.c.

Referenced by hls_read_header(), and recheck_discard_flags().

◆ save_avio_options()

static int save_avio_options ( AVFormatContext s)
static

Definition at line 1645 of file hls.c.

Referenced by hls_read_header().

◆ nested_io_open()

static int nested_io_open ( AVFormatContext s,
AVIOContext **  pb,
const char *  url,
int  flags,
AVDictionary **  opts 
)
static

Definition at line 1667 of file hls.c.

Referenced by hls_read_header().

◆ add_stream_to_programs()

static void add_stream_to_programs ( AVFormatContext s,
struct playlist pls,
AVStream stream 
)
static

Definition at line 1677 of file hls.c.

Referenced by update_streams_from_subdemuxer().

◆ set_stream_info_from_input_stream()

static int set_stream_info_from_input_stream ( AVStream st,
struct playlist pls,
AVStream ist 
)
static

Definition at line 1703 of file hls.c.

Referenced by hls_read_packet(), and update_streams_from_subdemuxer().

◆ update_streams_from_subdemuxer()

static int update_streams_from_subdemuxer ( AVFormatContext s,
struct playlist pls 
)
static

Definition at line 1722 of file hls.c.

Referenced by hls_read_header(), and hls_read_packet().

◆ update_noheader_flag()

static void update_noheader_flag ( AVFormatContext s)
static

Definition at line 1747 of file hls.c.

Referenced by hls_read_header(), and hls_read_packet().

◆ hls_close()

static int hls_close ( AVFormatContext s)
static

Definition at line 1768 of file hls.c.

Referenced by hls_read_header().

◆ hls_read_header()

static int hls_read_header ( AVFormatContext s)
static

Definition at line 1782 of file hls.c.

◆ recheck_discard_flags()

static int recheck_discard_flags ( AVFormatContext s,
int  first 
)
static

Definition at line 1996 of file hls.c.

Referenced by hls_read_packet().

◆ fill_timing_for_id3_timestamped_stream()

static void fill_timing_for_id3_timestamped_stream ( struct playlist pls)
static

Definition at line 2035 of file hls.c.

Referenced by hls_read_packet().

◆ get_timebase()

static AVRational get_timebase ( struct playlist pls)
static

Definition at line 2060 of file hls.c.

Referenced by compare_ts_with_wrapdetect(), and hls_read_packet().

◆ compare_ts_with_wrapdetect()

static int compare_ts_with_wrapdetect ( int64_t  ts_a,
struct playlist pls_a,
int64_t  ts_b,
struct playlist pls_b 
)
static

Definition at line 2068 of file hls.c.

Referenced by hls_read_packet().

◆ hls_read_packet()

static int hls_read_packet ( AVFormatContext s,
AVPacket pkt 
)
static

Definition at line 2077 of file hls.c.

◆ hls_read_seek()

static int hls_read_seek ( AVFormatContext s,
int  stream_index,
int64_t  timestamp,
int  flags 
)
static

Definition at line 2219 of file hls.c.

◆ hls_probe()

static int hls_probe ( AVProbeData p)
static

Definition at line 2304 of file hls.c.

Variable Documentation

◆ hls_options

const AVOption hls_options[]
static
Initial value:
= {
{"live_start_index", "segment index to start live streams at (negative values are from the end)",
OFFSET(live_start_index), AV_OPT_TYPE_INT, {.i64 = -3}, INT_MIN, INT_MAX, FLAGS},
{"allowed_extensions", "List of file extensions that hls is allowed to access",
OFFSET(allowed_extensions), AV_OPT_TYPE_STRING,
{.str = "3gp,aac,avi,flac,mkv,m3u8,m4a,m4s,m4v,mpg,mov,mp2,mp3,mp4,mpeg,mpegts,ogg,ogv,oga,ts,vob,wav"},
INT_MIN, INT_MAX, FLAGS},
{"max_reload", "Maximum number of times a insufficient list is attempted to be reloaded",
OFFSET(max_reload), AV_OPT_TYPE_INT, {.i64 = 1000}, 0, INT_MAX, FLAGS},
{"http_persistent", "Use persistent HTTP connections",
OFFSET(http_persistent), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS },
{"http_multiple", "Use multiple HTTP connections for fetching segments",
OFFSET(http_multiple), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, FLAGS},
{NULL}
}
#define NULL
Definition: coverity.c:32
#define FLAGS
Definition: hls.c:2319
#define OFFSET(x)
Definition: hls.c:2318

Definition at line 2320 of file hls.c.

◆ hls_class

const AVClass hls_class
static
Initial value:
= {
.class_name = "hls,applehttp",
.item_name = av_default_item_name,
.option = hls_options,
}
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
static const AVOption hls_options[]
Definition: hls.c:2320

Definition at line 2336 of file hls.c.

◆ ff_hls_demuxer

AVInputFormat ff_hls_demuxer
Initial value:
= {
.name = "hls,applehttp",
.long_name = NULL_IF_CONFIG_SMALL("Apple HTTP Live Streaming"),
.priv_class = &hls_class,
.priv_data_size = sizeof(HLSContext),
}
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition: libcdio.c:153
static int flags
Definition: log.c:55
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
static const AVClass hls_class
Definition: hls.c:2336
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
static int read_probe(AVProbeData *pd)
Definition: jvdec.c:55
static int hls_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: hls.c:2077
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:530
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
#define AVFMT_NOGENSEARCH
Format does not allow to fall back on generic search.
Definition: avformat.h:476
static int hls_read_header(AVFormatContext *s)
Definition: hls.c:1782
static int hls_probe(AVProbeData *p)
Definition: hls.c:2304
static int hls_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition: hls.c:2219
static int hls_close(AVFormatContext *s)
Definition: hls.c:1768

Definition at line 2343 of file hls.c.