FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
dashenc.c File Reference
#include "config.h"
#include "config_components.h"
#include <time.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/mem.h"
#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
#include "libavutil/rational.h"
#include "libavutil/time_internal.h"
#include "libavcodec/avcodec.h"
#include "av1.h"
#include "avc.h"
#include "avformat.h"
#include "avio_internal.h"
#include "hlsplaylist.h"
#include "internal.h"
#include "isom.h"
#include "mux.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
 

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 (AVFormatContext *s, AVStream *st, const AVPacket *avpkt)
 

Variables

static const struct codec_string codecs []
 
static const AVOption options []
 
static const AVClass dash_class
 
const FFOutputFormat ff_dash_muxer
 

Macro Definition Documentation

◆ MPD_PROFILE_DASH

#define MPD_PROFILE_DASH   1

Definition at line 76 of file dashenc.c.

◆ MPD_PROFILE_DVB

#define MPD_PROFILE_DVB   2

Definition at line 77 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 61 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 68 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 259 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 268 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 278 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 287 of file dashenc.c.

Referenced by init_segment_types().

◆ init_segment_types()

static int init_segment_types ( AVFormatContext s)
static

Definition at line 301 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 332 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 347 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 443 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 485 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 493 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 503 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 582 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 600 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 642 of file dashenc.c.

Referenced by write_adaptation_set().

◆ xmlescape()

static char* xmlescape ( const char *  str)
static

Definition at line 717 of file dashenc.c.

Referenced by write_manifest().

◆ write_time()

static void write_time ( AVIOContext out,
int64_t  time 
)
static

Definition at line 757 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 773 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 791 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 880 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 904 of file dashenc.c.

Referenced by parse_adaptation_sets().

◆ parse_adaptation_sets()

static int parse_adaptation_sets ( AVFormatContext s)
static

Definition at line 927 of file dashenc.c.

Referenced by dash_init().

◆ write_manifest()

static int write_manifest ( AVFormatContext s,
int  final 
)
static

Definition at line 1131 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 ( AVFormatContext s,
AVStream st,
const AVPacket avpkt 
)
static

Definition at line 2336 of file dashenc.c.

Variable Documentation

◆ codecs

const 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" },
}

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

◆ options

const AVOption options[]
static

Definition at line 2359 of file dashenc.c.

◆ 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 FFOutputFormat ff_dash_muxer
Initial value:
= {
.p.name = "dash",
.p.long_name = NULL_IF_CONFIG_SMALL("DASH Muxer"),
.p.extensions = "mpd",
.p.audio_codec = AV_CODEC_ID_AAC,
.p.video_codec = AV_CODEC_ID_H264,
.p.priv_class = &dash_class,
.priv_data_size = sizeof(DASHContext),
}

Definition at line 2415 of file dashenc.c.

options
static const AVOption options[]
Definition: dashenc.c:2359
dash_check_bitstream
static int dash_check_bitstream(AVFormatContext *s, AVStream *st, const AVPacket *avpkt)
Definition: dashenc.c:2336
deinit
static void deinit(AVFormatContext *s)
Definition: chromaprint.c:52
dash_init
static int dash_init(AVFormatContext *s)
Definition: dashenc.c:1375
AV_CODEC_ID_FLAC
@ AV_CODEC_ID_FLAC
Definition: codec_id.h:458
DASHContext
Definition: dashdec.c:123
AV_CODEC_ID_VP9
@ AV_CODEC_ID_VP9
Definition: codec_id.h:222
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
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:101
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
AV_CODEC_ID_AAC
@ AV_CODEC_ID_AAC
Definition: codec_id.h:448
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
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:94
AV_CODEC_ID_OPUS
@ AV_CODEC_ID_OPUS
Definition: codec_id.h:506
AVFMT_NOFILE
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:468
AVFMT_GLOBALHEADER
#define AVFMT_GLOBALHEADER
Format wants global header.
Definition: avformat.h:478
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
check_bitstream
static int check_bitstream(AVFormatContext *s, FFStream *sti, AVPacket *pkt)
Definition: mux.c:1116
write_packet
static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
Definition: ffmpeg_mux.c:209
AVFMT_TS_NEGATIVE
#define AVFMT_TS_NEGATIVE
Format allows muxing negative timestamps.
Definition: avformat.h:494
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:192
dash_class
static const AVClass dash_class
Definition: dashenc.c:2408
AV_CODEC_ID_VORBIS
@ AV_CODEC_ID_VORBIS
Definition: codec_id.h:451
write_header
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:348
dash_free
static void dash_free(AVFormatContext *s)
Definition: dashenc.c:600