Libav
Data Structures | Macros | Functions | Variables
mpegtsenc.c File Reference
#include "libavutil/bswap.h"
#include "libavutil/crc.h"
#include "libavutil/dict.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
#include "libavcodec/internal.h"
#include "avformat.h"
#include "avio_internal.h"
#include "internal.h"
#include "mpegts.h"

Go to the source code of this file.

Data Structures

struct  MpegTSSection
 
struct  MpegTSService
 
struct  MpegTSWrite
 
struct  MpegTSWriteStream
 

Macros

#define PCR_TIME_BASE   27000000
 
#define DVB_PRIVATE_NETWORK_START   0xff01
 
#define MPEGTS_FLAG_REEMIT_PAT_PMT   0x01
 
#define MPEGTS_FLAG_AAC_LATM   0x02
 
#define MPEGTS_FLAG_SYSTEM_B   0x04
 
#define DEFAULT_PES_HEADER_FREQ   16
 
#define DEFAULT_PES_PAYLOAD_SIZE   ((DEFAULT_PES_HEADER_FREQ - 1) * 184 + 170)
 
#define SECTION_LENGTH   1020
 
#define DEFAULT_PROVIDER_NAME   "Libav"
 
#define DEFAULT_SERVICE_NAME   "Service01"
 
#define SDT_RETRANS_TIME   500
 
#define PAT_RETRANS_TIME   100
 
#define PCR_RETRANS_TIME   20
 

Functions

static void mpegts_write_section (MpegTSSection *s, uint8_t *buf, int len)
 
static void put16 (uint8_t **q_ptr, int val)
 
static int mpegts_write_section1 (MpegTSSection *s, int tid, int id, int version, int sec_num, int last_sec_num, uint8_t *buf, int len)
 
static void mpegts_write_pat (AVFormatContext *s)
 
static void mpegts_write_pmt (AVFormatContext *s, MpegTSService *service)
 
static void putstr8 (uint8_t **q_ptr, const char *str)
 
static void mpegts_write_sdt (AVFormatContext *s)
 
static MpegTSServicempegts_add_service (MpegTSWrite *ts, int sid, const char *provider_name, const char *name)
 
static int64_t get_pcr (const MpegTSWrite *ts, AVIOContext *pb)
 
static void mpegts_prefix_m2ts_header (AVFormatContext *s)
 
static void section_write_packet (MpegTSSection *s, const uint8_t *packet)
 
static int mpegts_write_header (AVFormatContext *s)
 
static void retransmit_si_info (AVFormatContext *s)
 
static int write_pcr_bits (uint8_t *buf, int64_t pcr)
 
static void mpegts_insert_null_packet (AVFormatContext *s)
 
static void mpegts_insert_pcr_only (AVFormatContext *s, AVStream *st)
 
static void write_pts (uint8_t *q, int fourbits, int64_t pts)
 
static void set_af_flag (uint8_t *pkt, int flag)
 
static void extend_af (uint8_t *pkt, int size)
 
static uint8_tget_ts_payload_start (uint8_t *pkt)
 
static void mpegts_write_pes (AVFormatContext *s, AVStream *st, const uint8_t *payload, int payload_size, int64_t pts, int64_t dts, int key)
 
static int mpegts_write_packet_internal (AVFormatContext *s, AVPacket *pkt)
 
static void mpegts_write_flush (AVFormatContext *s)
 
static int mpegts_write_packet (AVFormatContext *s, AVPacket *pkt)
 
static int mpegts_write_end (AVFormatContext *s)
 

Variables

static const AVOption options []
 
static const AVClass mpegts_muxer_class
 
AVOutputFormat ff_mpegts_muxer
 

Macro Definition Documentation

◆ PCR_TIME_BASE

#define PCR_TIME_BASE   27000000

Definition at line 36 of file mpegtsenc.c.

Referenced by get_pcr(), and mpegts_write_header().

◆ DVB_PRIVATE_NETWORK_START

#define DVB_PRIVATE_NETWORK_START   0xff01

Definition at line 40 of file mpegtsenc.c.

◆ MPEGTS_FLAG_REEMIT_PAT_PMT

#define MPEGTS_FLAG_REEMIT_PAT_PMT   0x01

Definition at line 89 of file mpegtsenc.c.

Referenced by mpegts_write_packet_internal().

◆ MPEGTS_FLAG_AAC_LATM

#define MPEGTS_FLAG_AAC_LATM   0x02

Definition at line 90 of file mpegtsenc.c.

Referenced by mpegts_write_header(), and mpegts_write_pmt().

◆ MPEGTS_FLAG_SYSTEM_B

#define MPEGTS_FLAG_SYSTEM_B   0x04

Definition at line 91 of file mpegtsenc.c.

Referenced by mpegts_write_pmt().

◆ DEFAULT_PES_HEADER_FREQ

#define DEFAULT_PES_HEADER_FREQ   16

Definition at line 96 of file mpegtsenc.c.

◆ DEFAULT_PES_PAYLOAD_SIZE

#define DEFAULT_PES_PAYLOAD_SIZE   ((DEFAULT_PES_HEADER_FREQ - 1) * 184 + 170)

Definition at line 97 of file mpegtsenc.c.

◆ SECTION_LENGTH

#define SECTION_LENGTH   1020

Definition at line 101 of file mpegtsenc.c.

Referenced by mpegts_write_pat(), mpegts_write_pmt(), and mpegts_write_sdt().

◆ DEFAULT_PROVIDER_NAME

#define DEFAULT_PROVIDER_NAME   "Libav"

Definition at line 191 of file mpegtsenc.c.

Referenced by mpegts_write_header().

◆ DEFAULT_SERVICE_NAME

#define DEFAULT_SERVICE_NAME   "Service01"

Definition at line 192 of file mpegtsenc.c.

Referenced by mpegts_write_header().

◆ SDT_RETRANS_TIME

#define SDT_RETRANS_TIME   500

Definition at line 195 of file mpegtsenc.c.

Referenced by mpegts_write_header().

◆ PAT_RETRANS_TIME

#define PAT_RETRANS_TIME   100

Definition at line 196 of file mpegtsenc.c.

Referenced by mpegts_write_header().

◆ PCR_RETRANS_TIME

#define PCR_RETRANS_TIME   20

Definition at line 197 of file mpegtsenc.c.

Function Documentation

◆ mpegts_write_section()

static void mpegts_write_section ( MpegTSSection s,
uint8_t buf,
int  len 
)
static

Definition at line 104 of file mpegtsenc.c.

Referenced by mpegts_write_section1().

◆ put16()

static void put16 ( uint8_t **  q_ptr,
int  val 
)
inlinestatic

◆ mpegts_write_section1()

static int mpegts_write_section1 ( MpegTSSection s,
int  tid,
int  id,
int  version,
int  sec_num,
int  last_sec_num,
uint8_t buf,
int  len 
)
static

Definition at line 161 of file mpegtsenc.c.

Referenced by mpegts_write_pat(), mpegts_write_pmt(), and mpegts_write_sdt().

◆ mpegts_write_pat()

static void mpegts_write_pat ( AVFormatContext s)
static

Definition at line 213 of file mpegtsenc.c.

Referenced by retransmit_si_info().

◆ mpegts_write_pmt()

static void mpegts_write_pmt ( AVFormatContext s,
MpegTSService service 
)
static

Definition at line 230 of file mpegtsenc.c.

Referenced by retransmit_si_info().

◆ putstr8()

static void putstr8 ( uint8_t **  q_ptr,
const char *  str 
)
static

Definition at line 403 of file mpegtsenc.c.

Referenced by mpegts_write_sdt().

◆ mpegts_write_sdt()

static void mpegts_write_sdt ( AVFormatContext s)
static

Definition at line 419 of file mpegtsenc.c.

Referenced by retransmit_si_info().

◆ mpegts_add_service()

static MpegTSService* mpegts_add_service ( MpegTSWrite ts,
int  sid,
const char *  provider_name,
const char *  name 
)
static

Definition at line 457 of file mpegtsenc.c.

Referenced by mpegts_write_header().

◆ get_pcr()

static int64_t get_pcr ( const MpegTSWrite ts,
AVIOContext pb 
)
static

◆ mpegts_prefix_m2ts_header()

static void mpegts_prefix_m2ts_header ( AVFormatContext s)
static

◆ section_write_packet()

static void section_write_packet ( MpegTSSection s,
const uint8_t packet 
)
static

Definition at line 499 of file mpegtsenc.c.

Referenced by mpegts_write_header().

◆ mpegts_write_header()

static int mpegts_write_header ( AVFormatContext s)
static

Definition at line 506 of file mpegtsenc.c.

◆ retransmit_si_info()

static void retransmit_si_info ( AVFormatContext s)
static

Definition at line 732 of file mpegtsenc.c.

Referenced by mpegts_write_pes().

◆ write_pcr_bits()

static int write_pcr_bits ( uint8_t buf,
int64_t  pcr 
)
static

Definition at line 749 of file mpegtsenc.c.

Referenced by mpegts_insert_pcr_only(), and mpegts_write_pes().

◆ mpegts_insert_null_packet()

static void mpegts_insert_null_packet ( AVFormatContext s)
static

Definition at line 764 of file mpegtsenc.c.

Referenced by mpegts_write_pes().

◆ mpegts_insert_pcr_only()

static void mpegts_insert_pcr_only ( AVFormatContext s,
AVStream st 
)
static

Definition at line 780 of file mpegtsenc.c.

Referenced by mpegts_write_pes().

◆ write_pts()

static void write_pts ( uint8_t q,
int  fourbits,
int64_t  pts 
)
static

Definition at line 805 of file mpegtsenc.c.

Referenced by mpegts_write_pes().

◆ set_af_flag()

static void set_af_flag ( uint8_t pkt,
int  flag 
)
static

Definition at line 820 of file mpegtsenc.c.

Referenced by mpegts_write_pes().

◆ extend_af()

static void extend_af ( uint8_t pkt,
int  size 
)
static

Definition at line 836 of file mpegtsenc.c.

Referenced by mpegts_write_pes().

◆ get_ts_payload_start()

static uint8_t* get_ts_payload_start ( uint8_t pkt)
static

Definition at line 844 of file mpegtsenc.c.

Referenced by mpegts_write_pes().

◆ mpegts_write_pes()

static void mpegts_write_pes ( AVFormatContext s,
AVStream st,
const uint8_t payload,
int  payload_size,
int64_t  pts,
int64_t  dts,
int  key 
)
static

Definition at line 856 of file mpegtsenc.c.

Referenced by mpegts_write_flush(), and mpegts_write_packet_internal().

◆ mpegts_write_packet_internal()

static int mpegts_write_packet_internal ( AVFormatContext s,
AVPacket pkt 
)
static

Definition at line 1039 of file mpegtsenc.c.

Referenced by mpegts_write_packet().

◆ mpegts_write_flush()

static void mpegts_write_flush ( AVFormatContext s)
static

Definition at line 1175 of file mpegtsenc.c.

Referenced by mpegts_write_end(), and mpegts_write_packet().

◆ mpegts_write_packet()

static int mpegts_write_packet ( AVFormatContext s,
AVPacket pkt 
)
static

Definition at line 1193 of file mpegtsenc.c.

◆ mpegts_write_end()

static int mpegts_write_end ( AVFormatContext s)
static

Definition at line 1203 of file mpegtsenc.c.

Variable Documentation

◆ options

const AVOption options[]
static

Definition at line 1233 of file mpegtsenc.c.

◆ mpegts_muxer_class

const AVClass mpegts_muxer_class
static
Initial value:
= {
.class_name = "MPEGTS muxer",
.item_name = av_default_item_name,
.option = options,
}
static const AVOption options[]
Definition: mpegtsenc.c:1233
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
av_default_item_name
Definition: dnxhdenc.c:55

Definition at line 1280 of file mpegtsenc.c.

◆ ff_mpegts_muxer

AVOutputFormat ff_mpegts_muxer
Initial value:
= {
.name = "mpegts",
.long_name = NULL_IF_CONFIG_SMALL("MPEG-TS (MPEG-2 Transport Stream)"),
.mime_type = "video/MP2T",
.extensions = "ts,m2t,m2ts,mts",
.priv_data_size = sizeof(MpegTSWrite),
.audio_codec = AV_CODEC_ID_MP2,
.video_codec = AV_CODEC_ID_MPEG2VIDEO,
.priv_class = &mpegts_muxer_class,
}
#define AVFMT_ALLOW_FLUSH
Format allows flushing.
Definition: avformat.h:429
static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: mpegtsenc.c:1193
static int flags
Definition: log.c:50
static int write_trailer(AVFormatContext *s)
Definition: assenc.c:64
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:148
static int mpegts_write_header(AVFormatContext *s)
Definition: mpegtsenc.c:506
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:198
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
Definition: avconv.c:278
static int mpegts_write_end(AVFormatContext *s)
Definition: mpegtsenc.c:1203
#define AVFMT_VARIABLE_FPS
Format allows variable fps.
Definition: avformat.h:423
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:373
static const AVClass mpegts_muxer_class
Definition: mpegtsenc.c:1280

Definition at line 1287 of file mpegtsenc.c.