FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
dashenc.c File Reference
#include "config.h"
#include "libavutil/avassert.h"
#include "libavutil/avutil.h"
#include "libavutil/avstring.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
#include "libavutil/rational.h"
#include "libavutil/time.h"
#include "libavutil/time_internal.h"
#include "av1.h"
#include "avc.h"
#include "avformat.h"
#include "avio_internal.h"
#include "hlsplaylist.h"
#include "internal.h"
#include "isom.h"
#include "os_support.h"
#include "url.h"
#include "vpcc.h"
#include "dash.h"

Go to the source code of this file.

Data Structures

struct  Segment
 
struct  AdaptationSet
 
struct  OutputStream
 
struct  DASHContext
 
struct  codec_string
 
struct  format_string
 

Macros

#define OFFSET(x)   offsetof(DASHContext, x)
 
#define E   AV_OPT_FLAG_ENCODING_PARAM
 

Enumerations

enum  SegmentType {
  PALETTE_SEGMENT = 0x14, OBJECT_SEGMENT = 0x15, PRESENTATION_SEGMENT = 0x16, WINDOW_SEGMENT = 0x17,
  DISPLAY_SEGMENT = 0x80, SEGMENT_TYPE_AUTO = 0, SEGMENT_TYPE_MP4, SEGMENT_TYPE_WEBM,
  SEGMENT_TYPE_NB, SEGMENT_TYPE_MPEGTS, SEGMENT_TYPE_FMP4
}
 

Functions

static int dashenc_io_open (AVFormatContext *s, AVIOContext **pb, char *filename, AVDictionary **options)
 
static void dashenc_io_close (AVFormatContext *s, AVIOContext **pb, char *filename)
 
static const char * get_format_str (SegmentType segment_type)
 
static const char * get_extension_str (SegmentType type, int single_file)
 
static int handle_io_open_error (AVFormatContext *s, int err, char *url)
 
static SegmentType select_segment_type (SegmentType segment_type, enum AVCodecID codec_id)
 
static int init_segment_types (AVFormatContext *s)
 
static int check_file_extension (const char *filename, const char *extension)
 
static void set_vp9_codec_str (AVFormatContext *s, AVCodecParameters *par, AVRational *frame_rate, char *str, int size)
 
static void set_codec_str (AVFormatContext *s, AVCodecParameters *par, AVRational *frame_rate, char *str, int size)
 
static int flush_dynbuf (DASHContext *c, OutputStream *os, int *range_length)
 
static void set_http_options (AVDictionary **options, DASHContext *c)
 
static void get_hls_playlist_name (char *playlist_name, int string_size, const char *base_url, int id)
 
static void get_start_index_number (OutputStream *os, DASHContext *c, int *start_index, int *start_number)
 
static void write_hls_media_playlist (OutputStream *os, AVFormatContext *s, int representation_id, int final, char *prefetch_url)
 
static int flush_init_segment (AVFormatContext *s, OutputStream *os)
 
static void dash_free (AVFormatContext *s)
 
static void output_segment_list (OutputStream *os, AVIOContext *out, AVFormatContext *s, int representation_id, int final)
 
static char * xmlescape (const char *str)
 
static void write_time (AVIOContext *out, int64_t time)
 
static void format_date_now (char *buf, int size)
 
static int write_adaptation_set (AVFormatContext *s, AVIOContext *out, int as_index, int final)
 
static int add_adaptation_set (AVFormatContext *s, AdaptationSet **as, enum AVMediaType type)
 
static int adaptation_set_add_stream (AVFormatContext *s, int as_idx, int i)
 
static int parse_adaptation_sets (AVFormatContext *s)
 
static int write_manifest (AVFormatContext *s, int final)
 
static int dict_copy_entry (AVDictionary **dst, const AVDictionary *src, const char *key)
 
static int dash_init (AVFormatContext *s)
 
static int dash_write_header (AVFormatContext *s)
 
static int add_segment (OutputStream *os, const char *file, int64_t time, int64_t duration, int64_t start_pos, int64_t range_length, int64_t index_length, int next_exp_index)
 
static void write_styp (AVIOContext *pb)
 
static void find_index_range (AVFormatContext *s, const char *full_path, int64_t pos, int *index_length)
 
static int update_stream_extradata (AVFormatContext *s, OutputStream *os, AVPacket *pkt, AVRational *frame_rate)
 
static void dashenc_delete_file (AVFormatContext *s, char *filename)
 
static int dashenc_delete_segment_file (AVFormatContext *s, const char *file)
 
static void dashenc_delete_media_segments (AVFormatContext *s, OutputStream *os, int remove_count)
 
static int dash_flush (AVFormatContext *s, int final, int stream)
 
static int dash_write_packet (AVFormatContext *s, AVPacket *pkt)
 
static int dash_write_trailer (AVFormatContext *s)
 
static int dash_check_bitstream (struct AVFormatContext *s, const AVPacket *avpkt)
 

Variables

static struct codec_string codecs []
 
static struct format_string formats []
 
static const AVOption options []
 
static const AVClass dash_class
 
AVOutputFormat ff_dash_muxer
 

Macro Definition Documentation

◆ OFFSET

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

Definition at line 1890 of file dashenc.c.

◆ E

Definition at line 1891 of file dashenc.c.

Enumeration Type Documentation

◆ SegmentType

Enumerator
PALETTE_SEGMENT 
OBJECT_SEGMENT 
PRESENTATION_SEGMENT 
WINDOW_SEGMENT 
DISPLAY_SEGMENT 
SEGMENT_TYPE_AUTO 
SEGMENT_TYPE_MP4 
SEGMENT_TYPE_WEBM 
SEGMENT_TYPE_NB 
SEGMENT_TYPE_MPEGTS 
SEGMENT_TYPE_FMP4 

Definition at line 53 of file dashenc.c.

Function Documentation

◆ dashenc_io_open()

static int dashenc_io_open ( AVFormatContext s,
AVIOContext **  pb,
char *  filename,
AVDictionary **  options 
)
static

◆ dashenc_io_close()

static void dashenc_io_close ( AVFormatContext s,
AVIOContext **  pb,
char *  filename 
)
static

◆ get_format_str()

static const char* get_format_str ( SegmentType  segment_type)
static

Definition at line 214 of file dashenc.c.

Referenced by init_segment_types().

◆ get_extension_str()

static const char* get_extension_str ( SegmentType  type,
int  single_file 
)
static

Definition at line 222 of file dashenc.c.

Referenced by init_segment_types().

◆ handle_io_open_error()

static int handle_io_open_error ( AVFormatContext s,
int  err,
char *  url 
)
static

Definition at line 232 of file dashenc.c.

Referenced by dash_write_packet(), write_hls_media_playlist(), and write_manifest().

◆ select_segment_type()

static SegmentType select_segment_type ( SegmentType  segment_type,
enum AVCodecID  codec_id 
)
inlinestatic

Definition at line 241 of file dashenc.c.

Referenced by init_segment_types().

◆ init_segment_types()

static int init_segment_types ( AVFormatContext s)
static

Definition at line 255 of file dashenc.c.

Referenced by dash_init().

◆ check_file_extension()

static int check_file_extension ( const char *  filename,
const char *  extension 
)
static

Definition at line 286 of file dashenc.c.

Referenced by dash_init().

◆ set_vp9_codec_str()

static void set_vp9_codec_str ( AVFormatContext s,
AVCodecParameters par,
AVRational frame_rate,
char *  str,
int  size 
)
static

Definition at line 296 of file dashenc.c.

Referenced by set_codec_str().

◆ set_codec_str()

static void set_codec_str ( AVFormatContext s,
AVCodecParameters par,
AVRational frame_rate,
char *  str,
int  size 
)
static

Definition at line 311 of file dashenc.c.

Referenced by dash_init(), and update_stream_extradata().

◆ flush_dynbuf()

static int flush_dynbuf ( DASHContext c,
OutputStream os,
int range_length 
)
static

Definition at line 407 of file dashenc.c.

Referenced by dash_flush(), and flush_init_segment().

◆ set_http_options()

static void set_http_options ( AVDictionary **  options,
DASHContext c 
)
static

◆ get_hls_playlist_name()

static void get_hls_playlist_name ( char *  playlist_name,
int  string_size,
const char *  base_url,
int  id 
)
static

Definition at line 448 of file dashenc.c.

Referenced by dash_write_trailer(), write_hls_media_playlist(), and write_manifest().

◆ get_start_index_number()

static void get_start_index_number ( OutputStream os,
DASHContext c,
int start_index,
int start_number 
)
static

Definition at line 456 of file dashenc.c.

Referenced by dash_flush(), output_segment_list(), and write_hls_media_playlist().

◆ write_hls_media_playlist()

static void write_hls_media_playlist ( OutputStream os,
AVFormatContext s,
int  representation_id,
int  final,
char *  prefetch_url 
)
static

Definition at line 466 of file dashenc.c.

Referenced by dash_write_packet(), and output_segment_list().

◆ flush_init_segment()

static int flush_init_segment ( AVFormatContext s,
OutputStream os 
)
static

Definition at line 547 of file dashenc.c.

Referenced by dash_write_header(), and dash_write_packet().

◆ dash_free()

static void dash_free ( AVFormatContext s)
static

Definition at line 565 of file dashenc.c.

◆ output_segment_list()

static void output_segment_list ( OutputStream os,
AVIOContext out,
AVFormatContext s,
int  representation_id,
int  final 
)
static

Definition at line 603 of file dashenc.c.

Referenced by write_adaptation_set().

◆ xmlescape()

static char* xmlescape ( const char *  str)
static

Definition at line 672 of file dashenc.c.

Referenced by write_manifest().

◆ write_time()

static void write_time ( AVIOContext out,
int64_t  time 
)
static

Definition at line 712 of file dashenc.c.

Referenced by write_manifest().

◆ format_date_now()

static void format_date_now ( char *  buf,
int  size 
)
static

Definition at line 728 of file dashenc.c.

Referenced by dash_write_packet(), and write_manifest().

◆ write_adaptation_set()

static int write_adaptation_set ( AVFormatContext s,
AVIOContext out,
int  as_index,
int  final 
)
static

Definition at line 747 of file dashenc.c.

Referenced by write_manifest().

◆ add_adaptation_set()

static int add_adaptation_set ( AVFormatContext s,
AdaptationSet **  as,
enum AVMediaType  type 
)
static

Definition at line 800 of file dashenc.c.

Referenced by parse_adaptation_sets().

◆ adaptation_set_add_stream()

static int adaptation_set_add_stream ( AVFormatContext s,
int  as_idx,
int  i 
)
static

Definition at line 817 of file dashenc.c.

Referenced by parse_adaptation_sets().

◆ parse_adaptation_sets()

static int parse_adaptation_sets ( AVFormatContext s)
static

Definition at line 835 of file dashenc.c.

Referenced by dash_init().

◆ write_manifest()

static int write_manifest ( AVFormatContext s,
int  final 
)
static

Definition at line 934 of file dashenc.c.

Referenced by dash_flush().

◆ dict_copy_entry()

static int dict_copy_entry ( AVDictionary **  dst,
const AVDictionary src,
const char *  key 
)
static

Definition at line 1112 of file dashenc.c.

Referenced by dash_init().

◆ dash_init()

static int dash_init ( AVFormatContext s)
static

Definition at line 1120 of file dashenc.c.

◆ dash_write_header()

static int dash_write_header ( AVFormatContext s)
static

Definition at line 1360 of file dashenc.c.

◆ add_segment()

static int add_segment ( OutputStream os,
const char *  file,
int64_t  time,
int64_t  duration,
int64_t  start_pos,
int64_t  range_length,
int64_t  index_length,
int  next_exp_index 
)
static

Definition at line 1379 of file dashenc.c.

Referenced by dash_flush().

◆ write_styp()

static void write_styp ( AVIOContext pb)
static

Definition at line 1419 of file dashenc.c.

Referenced by dash_flush(), and dash_write_packet().

◆ find_index_range()

static void find_index_range ( AVFormatContext s,
const char *  full_path,
int64_t  pos,
int index_length 
)
static

Definition at line 1429 of file dashenc.c.

Referenced by dash_flush().

◆ update_stream_extradata()

static int update_stream_extradata ( AVFormatContext s,
OutputStream os,
AVPacket pkt,
AVRational frame_rate 
)
static

Definition at line 1452 of file dashenc.c.

Referenced by dash_write_packet().

◆ dashenc_delete_file()

static void dashenc_delete_file ( AVFormatContext s,
char *  filename 
)
static

Definition at line 1477 of file dashenc.c.

Referenced by dash_write_trailer(), and dashenc_delete_segment_file().

◆ dashenc_delete_segment_file()

static int dashenc_delete_segment_file ( AVFormatContext s,
const char *  file 
)
static

Definition at line 1504 of file dashenc.c.

Referenced by dash_write_trailer(), and dashenc_delete_media_segments().

◆ dashenc_delete_media_segments()

static void dashenc_delete_media_segments ( AVFormatContext s,
OutputStream os,
int  remove_count 
)
inlinestatic

Definition at line 1532 of file dashenc.c.

Referenced by dash_flush(), and dash_write_trailer().

◆ dash_flush()

static int dash_flush ( AVFormatContext s,
int  final,
int  stream 
)
static

Definition at line 1545 of file dashenc.c.

Referenced by dash_write_packet(), and dash_write_trailer().

◆ dash_write_packet()

static int dash_write_packet ( AVFormatContext s,
AVPacket pkt 
)
static

Definition at line 1679 of file dashenc.c.

◆ dash_write_trailer()

static int dash_write_trailer ( AVFormatContext s)
static

Definition at line 1825 of file dashenc.c.

◆ dash_check_bitstream()

static int dash_check_bitstream ( struct AVFormatContext s,
const AVPacket avpkt 
)
static

Definition at line 1867 of file dashenc.c.

Variable Documentation

◆ codecs

struct codec_string codecs[]
static
Initial value:
= {
{ AV_CODEC_ID_VP8, "vp8" },
{ AV_CODEC_ID_VP9, "vp9" },
{ AV_CODEC_ID_VORBIS, "vorbis" },
{ AV_CODEC_ID_OPUS, "opus" },
{ AV_CODEC_ID_FLAC, "flac" },
{ 0, NULL }
}

Referenced by ff_hls_write_stream_info(), get_codecs_sorted(), print_codecs(), set_codec_str(), and show_codecs().

◆ formats

struct format_string formats[]
static
Initial value:
= {
{ SEGMENT_TYPE_AUTO, "auto" },
{ SEGMENT_TYPE_MP4, "mp4" },
{ SEGMENT_TYPE_WEBM, "webm" },
{ 0, NULL }
}

◆ options

const AVOption options[]
static

Definition at line 1892 of file dashenc.c.

Referenced by dashenc_io_open(), and set_http_options().

◆ dash_class

const AVClass dash_class
static
Initial value:
= {
.class_name = "dash muxer",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 1927 of file dashenc.c.

◆ ff_dash_muxer

AVOutputFormat ff_dash_muxer
Initial value:
= {
.name = "dash",
.long_name = NULL_IF_CONFIG_SMALL("DASH Muxer"),
.extensions = "mpd",
.priv_data_size = sizeof(DASHContext),
.audio_codec = AV_CODEC_ID_AAC,
.video_codec = AV_CODEC_ID_H264,
.deinit = dash_free,
.check_bitstream = dash_check_bitstream,
.priv_class = &dash_class,
}

Definition at line 1934 of file dashenc.c.

options
static const AVOption options[]
Definition: dashenc.c:1892
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
dash_init
static int dash_init(AVFormatContext *s)
Definition: dashenc.c:1120
AV_CODEC_ID_FLAC
@ AV_CODEC_ID_FLAC
Definition: avcodec.h:576
SEGMENT_TYPE_MP4
@ SEGMENT_TYPE_MP4
Definition: dashenc.c:55
DASHContext
Definition: dashdec.c:122
SEGMENT_TYPE_AUTO
@ SEGMENT_TYPE_AUTO
Definition: dashenc.c:54
AV_CODEC_ID_VP9
@ AV_CODEC_ID_VP9
Definition: avcodec.h:386
dash_check_bitstream
static int dash_check_bitstream(struct AVFormatContext *s, const AVPacket *avpkt)
Definition: dashenc.c:1867
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: avcodec.h:245
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
NULL
#define NULL
Definition: coverity.c:32
SEGMENT_TYPE_WEBM
@ SEGMENT_TYPE_WEBM
Definition: dashenc.c:56
dash_write_packet
static int dash_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: dashenc.c:1679
write_trailer
static int write_trailer(AVFormatContext *s1)
Definition: v4l2enc.c:94
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
AV_CODEC_ID_AAC
@ AV_CODEC_ID_AAC
Definition: avcodec.h:566
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:188
AV_CODEC_ID_OPUS
@ AV_CODEC_ID_OPUS
Definition: avcodec.h:624
AVFMT_NOFILE
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:463
write_packet
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
Definition: ffmpeg.c:690
AVFMT_GLOBALHEADER
#define AVFMT_GLOBALHEADER
Format wants global header.
Definition: avformat.h:466
AVFMT_TS_NEGATIVE
#define AVFMT_TS_NEGATIVE
Format allows muxing negative timestamps.
Definition: avformat.h:480
dash_write_header
static int dash_write_header(AVFormatContext *s)
Definition: dashenc.c:1360
dash_write_trailer
static int dash_write_trailer(AVFormatContext *s)
Definition: dashenc.c:1825
AV_CODEC_ID_VP8
@ AV_CODEC_ID_VP8
Definition: avcodec.h:358
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
dash_class
static const AVClass dash_class
Definition: dashenc.c:1927
AV_CODEC_ID_VORBIS
@ AV_CODEC_ID_VORBIS
Definition: avcodec.h:569
write_header
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:337
dash_free
static void dash_free(AVFormatContext *s)
Definition: dashenc.c:565