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/bprint.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
#include "libavutil/parseutils.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 MPD_PROFILE_DASH   1
 
#define MPD_PROFILE_DVB   2
 
#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
}
 
enum  {
  FRAG_TYPE_NONE = 0, FRAG_TYPE_EVERY_FRAME, FRAG_TYPE_DURATION, FRAG_TYPE_PFRAMES,
  FRAG_TYPE_NB
}
 

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 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 (char *buf, int size, int64_t time_us)
 
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_parse_prft (DASHContext *c, AVPacket *pkt)
 
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
 
const AVOutputFormat ff_dash_muxer
 

Macro Definition Documentation

◆ MPD_PROFILE_DASH

#define MPD_PROFILE_DASH   1

Definition at line 70 of file dashenc.c.

◆ MPD_PROFILE_DVB

#define MPD_PROFILE_DVB   2

Definition at line 71 of file dashenc.c.

◆ OFFSET

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

Definition at line 2357 of file dashenc.c.

◆ E

Definition at line 2358 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 55 of file dashenc.c.

◆ anonymous enum

anonymous enum
Enumerator
FRAG_TYPE_NONE 
FRAG_TYPE_EVERY_FRAME 
FRAG_TYPE_DURATION 
FRAG_TYPE_PFRAMES 
FRAG_TYPE_NB 

Definition at line 62 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 262 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 270 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 280 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 289 of file dashenc.c.

Referenced by init_segment_types().

◆ init_segment_types()

static int init_segment_types ( AVFormatContext s)
static

Definition at line 303 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 334 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 349 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 445 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 487 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 495 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 505 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 584 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 602 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 643 of file dashenc.c.

Referenced by write_adaptation_set().

◆ xmlescape()

static char* xmlescape ( const char *  str)
static

Definition at line 718 of file dashenc.c.

Referenced by write_manifest().

◆ write_time()

static void write_time ( AVIOContext out,
int64_t  time 
)
static

Definition at line 758 of file dashenc.c.

Referenced by write_manifest().

◆ format_date()

static void format_date ( char *  buf,
int  size,
int64_t  time_us 
)
static

Definition at line 774 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 792 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 881 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 905 of file dashenc.c.

Referenced by parse_adaptation_sets().

◆ parse_adaptation_sets()

static int parse_adaptation_sets ( AVFormatContext s)
static

Definition at line 928 of file dashenc.c.

Referenced by dash_init().

◆ write_manifest()

static int write_manifest ( AVFormatContext s,
int  final 
)
static

Definition at line 1132 of file dashenc.c.

Referenced by dash_flush(), and dash_write_packet().

◆ dict_copy_entry()

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

Definition at line 1367 of file dashenc.c.

Referenced by dash_init().

◆ dash_init()

static int dash_init ( AVFormatContext s)
static

Definition at line 1375 of file dashenc.c.

◆ dash_write_header()

static int dash_write_header ( AVFormatContext s)
static

Definition at line 1730 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 1749 of file dashenc.c.

Referenced by dash_flush().

◆ write_styp()

static void write_styp ( AVIOContext pb)
static

Definition at line 1789 of file dashenc.c.

Referenced by 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 1799 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 1822 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 1848 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 1875 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 1895 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 1908 of file dashenc.c.

Referenced by dash_write_packet(), and dash_write_trailer().

◆ dash_parse_prft()

static int dash_parse_prft ( DASHContext c,
AVPacket pkt 
)
static

Definition at line 2042 of file dashenc.c.

Referenced by dash_write_packet().

◆ dash_write_packet()

static int dash_write_packet ( AVFormatContext s,
AVPacket pkt 
)
static

Definition at line 2068 of file dashenc.c.

◆ dash_write_trailer()

static int dash_write_trailer ( AVFormatContext s)
static

Definition at line 2294 of file dashenc.c.

◆ dash_check_bitstream()

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

Definition at line 2336 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 2359 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 2408 of file dashenc.c.

◆ ff_dash_muxer

const 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,
.priv_class = &dash_class,
}

Definition at line 2415 of file dashenc.c.

options
static const AVOption options[]
Definition: dashenc.c:2359
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
dash_init
static int dash_init(AVFormatContext *s)
Definition: dashenc.c:1375
AV_CODEC_ID_FLAC
@ AV_CODEC_ID_FLAC
Definition: codec_id.h:434
SEGMENT_TYPE_MP4
@ SEGMENT_TYPE_MP4
Definition: dashenc.c:57
DASHContext
Definition: dashdec.c:122
SEGMENT_TYPE_AUTO
@ SEGMENT_TYPE_AUTO
Definition: dashenc.c:56
AV_CODEC_ID_VP9
@ AV_CODEC_ID_VP9
Definition: codec_id.h:218
dash_check_bitstream
static int dash_check_bitstream(struct AVFormatContext *s, const AVPacket *avpkt)
Definition: dashenc.c:2336
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:77
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:58
dash_write_packet
static int dash_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: dashenc.c:2068
write_trailer
static int write_trailer(AVFormatContext *s1)
Definition: v4l2enc.c:98
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
AV_CODEC_ID_AAC
@ AV_CODEC_ID_AAC
Definition: codec_id.h:424
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:116
AV_CODEC_ID_OPUS
@ AV_CODEC_ID_OPUS
Definition: codec_id.h:482
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:729
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:1730
dash_write_trailer
static int dash_write_trailer(AVFormatContext *s)
Definition: dashenc.c:2294
AV_CODEC_ID_VP8
@ AV_CODEC_ID_VP8
Definition: codec_id.h:190
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
dash_class
static const AVClass dash_class
Definition: dashenc.c:2408
AV_CODEC_ID_VORBIS
@ AV_CODEC_ID_VORBIS
Definition: codec_id.h:427
write_header
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:347
check_bitstream
static int check_bitstream(AVFormatContext *s, AVStream *st, AVPacket *pkt)
Definition: mux.c:1058
dash_free
static void dash_free(AVFormatContext *s)
Definition: dashenc.c:602