FFmpeg
Loading...
Searching...
No Matches
mpegts.h
Go to the documentation of this file.
1/*
2 * MPEG-2 transport stream defines
3 * Copyright (c) 2003 Fabrice Bellard
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#ifndef AVFORMAT_MPEGTS_H
23#define AVFORMAT_MPEGTS_H
24
25#include "avformat.h"
26
27#define TS_FEC_PACKET_SIZE 204
28#define TS_DVHS_PACKET_SIZE 192
29#define TS_PACKET_SIZE 188
30#define TS_MAX_PACKET_SIZE 204
31
32#define NB_PID_MAX 8192
33#define USUAL_SECTION_SIZE 1024 /* except EIT which is limited to 4096 */
34#define MAX_SECTION_SIZE 4096
35
36#define SYNC_BYTE 0x47
37#define STUFFING_BYTE 0xFF
38#define SYSTEM_CLOCK_FREQUENCY_DIVISOR 300 /* convert 27 MHz to 90 kHz */
39
40/* pids */
41#define PAT_PID 0x0000 /* Program Association Table */
42#define CAT_PID 0x0001 /* Conditional Access Table */
43#define TSDT_PID 0x0002 /* Transport Stream Description Table */
44#define IPMP_PID 0x0003
45/* PID from 0x0004 to 0x000F are reserved */
46#define NIT_PID 0x0010 /* Network Information Table */
47#define SDT_PID 0x0011 /* Service Description Table */
48#define BAT_PID 0x0011 /* Bouquet Association Table */
49#define EIT_PID 0x0012 /* Event Information Table */
50#define RST_PID 0x0013 /* Running Status Table */
51#define TDT_PID 0x0014 /* Time and Date Table */
52#define TOT_PID 0x0014
53#define NET_SYNC_PID 0x0015
54#define RNT_PID 0x0016 /* RAR Notification Table */
55/* PID from 0x0017 to 0x001B are reserved for future use */
56/* PID value 0x001C allocated to link-local inband signalling shall not be
57 * used on any broadcast signals. It shall only be used between devices in a
58 * controlled environment. */
59#define LINK_LOCAL_PID 0x001C
60#define MEASUREMENT_PID 0x001D
61#define DIT_PID 0x001E /* Discontinuity Information Table */
62#define SIT_PID 0x001F /* Selection Information Table */
63/* PID from 0x0020 to 0x1FFA may be assigned as needed to PMT, elementary
64 * streams and other data tables */
65#define FIRST_OTHER_PID 0x0020
66#define LAST_OTHER_PID 0x1FFA
67/* PID 0x1FFB is used by DigiCipher 2/ATSC MGT metadata */
68/* PID from 0x1FFC to 0x1FFE may be assigned as needed to PMT, elementary
69 * streams and other data tables */
70#define NULL_PID 0x1FFF /* Null packet (used for fixed bandwidth padding) */
71
72/* m2ts pids */
73#define M2TS_PMT_PID 0x0100
74#define M2TS_PCR_PID 0x1001
75#define M2TS_VIDEO_PID 0x1011
76#define M2TS_VIDEO_EL_PID 0x1015
77#define M2TS_AUDIO_START_PID 0x1100
78#define M2TS_PGSSUB_START_PID 0x1200
79#define M2TS_TEXTSUB_PID 0x1800
80#define M2TS_SECONDARY_AUDIO_START_PID 0x1A00
81#define M2TS_SECONDARY_VIDEO_START_PID 0x1B00
82
83/* table ids */
84#define PAT_TID 0x00 /* Program Association section */
85#define CAT_TID 0x01 /* Conditional Access section */
86#define PMT_TID 0x02 /* Program Map section */
87#define TSDT_TID 0x03 /* Transport Stream Description section */
88/* TID from 0x04 to 0x3F are reserved */
89#define M4OD_TID 0x05
90#define NIT_TID 0x40 /* Network Information section - actual network */
91#define ONIT_TID 0x41 /* Network Information section - other network */
92#define SDT_TID 0x42 /* Service Description section - actual TS */
93/* TID from 0x43 to 0x45 are reserved for future use */
94#define OSDT_TID 0x46 /* Service Description section - other TS */
95/* TID from 0x47 to 0x49 are reserved for future use */
96#define BAT_TID 0x4A /* Bouquet Association section */
97#define UNT_TID 0x4B /* Update Notification Table section */
98#define DFI_TID 0x4C /* Downloadable Font Info section */
99/* TID 0x4D is reserved for future use */
100#define EIT_TID 0x4E /* Event Information section - actual TS */
101#define OEIT_TID 0x4F /* Event Information section - other TS */
102#define EITS_START_TID 0x50 /* Event Information section schedule - actual TS */
103#define EITS_END_TID 0x5F /* Event Information section schedule - actual TS */
104#define OEITS_START_TID 0x60 /* Event Information section schedule - other TS */
105#define OEITS_END_TID 0x6F /* Event Information section schedule - other TS */
106#define TDT_TID 0x70 /* Time Date section */
107#define RST_TID 0x71 /* Running Status section */
108#define ST_TID 0x72 /* Stuffing section */
109#define TOT_TID 0x73 /* Time Offset section */
110#define AIT_TID 0x74 /* Application Information section */
111#define CT_TID 0x75 /* Container section */
112#define RCT_TID 0x76 /* Related Content section */
113#define CIT_TID 0x77 /* Content Identifier section */
114#define MPE_FEC_TID 0x78 /* MPE-FEC section */
115#define RPNT_TID 0x79 /* Resolution Provider Notification section */
116#define MPE_IFEC_TID 0x7A /* MPE-IFEC section */
117#define PROTMT_TID 0x7B /* Protection Message section */
118/* TID from 0x7C to 0x7D are reserved for future use */
119#define DIT_TID 0x7E /* Discontinuity Information section */
120#define SIT_TID 0x7F /* Selection Information section */
121/* TID from 0x80 to 0xFE are user defined */
122/* TID 0xFF is reserved */
123
124/* ISO/IEC 13818-1 Table 2-34 - Stream type assignments */
125#define STREAM_TYPE_VIDEO_MPEG1 0x01
126#define STREAM_TYPE_VIDEO_MPEG2 0x02
127#define STREAM_TYPE_AUDIO_MPEG1 0x03
128#define STREAM_TYPE_AUDIO_MPEG2 0x04
129#define STREAM_TYPE_PRIVATE_SECTION 0x05
130#define STREAM_TYPE_PRIVATE_DATA 0x06
131#define STREAM_TYPE_AUDIO_AAC 0x0f
132#define STREAM_TYPE_AUDIO_AAC_LATM 0x11
133#define STREAM_TYPE_VIDEO_MPEG4 0x10
134/** ISO/IEC 14496-1 (MPEG-4 Systems) SL-packetized stream or FlexMux stream
135 carried in PES packets */
136#define STREAM_TYPE_ISO_IEC_14496_PES 0x12
137/** ISO/IEC 14496-1 (MPEG-4 Systems) SL-packetized stream or FlexMux stream
138 carried in ISO_IEC_14496_section()s */
139#define STREAM_TYPE_ISO_IEC_14496_SECTION 0x13
140#define STREAM_TYPE_METADATA 0x15
141#define STREAM_TYPE_VIDEO_H264 0x1b
142/** ISO/IEC 14496-3 Audio, without using any additional transport syntax,
143 such as DST, ALS and SLS */
144#define STREAM_TYPE_AUDIO_MPEG4 0x1c
145#define STREAM_TYPE_VIDEO_MVC 0x20
146#define STREAM_TYPE_VIDEO_JPEG2000 0x21
147#define STREAM_TYPE_VIDEO_HEVC 0x24
148#define STREAM_TYPE_VIDEO_JPEGXS 0x32
149#define STREAM_TYPE_VIDEO_VVC 0x33
150#define STREAM_TYPE_VIDEO_LCEVC 0x36
151#define STREAM_TYPE_VIDEO_CAVS 0x42
152#define STREAM_TYPE_VIDEO_AVS2 0xd2
153#define STREAM_TYPE_VIDEO_AVS3 0xd4
154#define STREAM_TYPE_VIDEO_VC1 0xea
155#define STREAM_TYPE_VIDEO_DIRAC 0xd1
156
157/* stream_type values [0x80, 0xff] are User Private */
158#define STREAM_TYPE_BLURAY_AUDIO_PCM_BLURAY 0x80
159#define STREAM_TYPE_BLURAY_AUDIO_AC3 0x81
160#define STREAM_TYPE_BLURAY_AUDIO_DTS 0x82
161#define STREAM_TYPE_BLURAY_AUDIO_TRUEHD 0x83
162#define STREAM_TYPE_BLURAY_AUDIO_EAC3 0x84
163#define STREAM_TYPE_BLURAY_AUDIO_DTS_HD 0x85
164#define STREAM_TYPE_BLURAY_AUDIO_DTS_HD_MASTER 0x86
165#define STREAM_TYPE_BLURAY_AUDIO_EAC3_SECONDARY 0xa1
166#define STREAM_TYPE_BLURAY_AUDIO_DTS_EXPRESS_SECONDARY 0xa2
167#define STREAM_TYPE_BLURAY_SUBTITLE_PGS 0x90
168#define STREAM_TYPE_BLURAY_SUBTITLE_TEXT 0x92
169
170#define STREAM_TYPE_SCTE_DATA_SCTE_35 0x86 /* ANSI/SCTE 35 */
171
172#define STREAM_TYPE_ATSC_AUDIO_AC3 0x81 /* ATSC A/52 */
173#define STREAM_TYPE_ATSC_AUDIO_EAC3 0x87 /* ATSC A/52 */
174
175/* HTTP Live Streaming (HLS) Sample Encryption
176 see "MPEG-2 Stream Encryption Format for HTTP Live Streaming",
177https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/HLS_Sample_Encryption/ */
178#define STREAM_TYPE_HLS_SE_VIDEO_H264 0xdb
179#define STREAM_TYPE_HLS_SE_AUDIO_AAC 0xcf
180#define STREAM_TYPE_HLS_SE_AUDIO_AC3 0xc1
181#define STREAM_TYPE_HLS_SE_AUDIO_EAC3 0xc2
182
183
184/* ISO/IEC 13818-1 Table 2-22 */
185#define STREAM_ID_PROGRAM_STREAM_MAP 0xbc
186#define STREAM_ID_PRIVATE_STREAM_1 0xbd
187#define STREAM_ID_PADDING_STREAM 0xbe
188#define STREAM_ID_PRIVATE_STREAM_2 0xbf
189#define STREAM_ID_AUDIO_STREAM_0 0xc0
190#define STREAM_ID_VIDEO_STREAM_0 0xe0
191#define STREAM_ID_ECM_STREAM 0xf0
192#define STREAM_ID_EMM_STREAM 0xf1
193#define STREAM_ID_DSMCC_STREAM 0xf2
194#define STREAM_ID_TYPE_E_STREAM 0xf8
195#define STREAM_ID_METADATA_STREAM 0xfc
196#define STREAM_ID_EXTENDED_STREAM_ID 0xfd
197#define STREAM_ID_PROGRAM_STREAM_DIRECTORY 0xff
198
199/* ISO/IEC 13818-1 Table 2-45 */
200#define VIDEO_STREAM_DESCRIPTOR 0x02
201#define REGISTRATION_DESCRIPTOR 0x05
202#define ISO_639_LANGUAGE_DESCRIPTOR 0x0a
203#define IOD_DESCRIPTOR 0x1d
204#define SL_DESCRIPTOR 0x1e
205#define FMC_DESCRIPTOR 0x1f
206#define METADATA_DESCRIPTOR 0x26
207#define METADATA_STD_DESCRIPTOR 0x27
208#define EXTENSION_DESCRIPTOR 0x3f
209/* descriptor_tag values [0x40, 0xff] are User Private */
210
211/* ISO/IEC 13818-1 Table 2-109 */
212#define JXS_VIDEO_DESCRIPTOR 0x14 /* JPEG-XS descriptor */
213#define LCEVC_VIDEO_DESCRIPTOR 0x17 /* LCEVC video descriptor */
214#define LCEVC_LINKAGE_DESCRIPTOR 0x18 /* LCEVC linkage descriptor */
215
216/* DVB descriptor tag values [0x40, 0x7F] from
217 ETSI EN 300 468 Table 12: Possible locations of descriptors */
218#define NETWORK_NAME_DESCRIPTOR 0x40
219#define SERVICE_LIST_DESCRIPTOR 0x41
220#define SERVICE_DESCRIPTOR 0x48
221#define STREAM_IDENTIFIER_DESCRIPTOR 0x52
222#define TELETEXT_DESCRIPTOR 0x56
223#define SUBTITLING_DESCRIPTOR 0x59
224#define AC3_DESCRIPTOR 0x6a /* AC-3_descriptor */
225#define ENHANCED_AC3_DESCRIPTOR 0x7a /* enhanced_AC-3_descriptor */
226#define DTS_DESCRIPTOR 0x7b
227#define DVB_EXTENSION_DESCRIPTOR 0x7f
228
229/* DVB descriptor_tag_extension values from
230 ETSI EN 300 468 Table 109: Possible locations of extended descriptors */
231#define SUPPLEMENTARY_AUDIO_DESCRIPTOR 0x06
232#define AC4_DESCRIPTOR 0x15
233
234/** see "Dolby Vision Streams Within the MPEG-2 Transport Stream Format"
235https://professional.dolby.com/siteassets/content-creation/dolby-vision-for-content-creators/dolby-vision-bitstreams-in-mpeg-2-transport-stream-multiplex-v1.2.pdf */
236#define DOVI_VIDEO_STREAM_DESCRIPTOR 0xb0
237
238#define DATA_COMPONENT_DESCRIPTOR 0xfd /* ARIB STD-B10 */
239
240typedef struct MpegTSContext MpegTSContext;
241
244 const uint8_t *buf, int len);
246
263
270
271/*
272 * ETSI 300 468 descriptor 0x6A(AC-3)
273 * Refer to: ETSI EN 300 468 V1.11.1 (2010-04) (SI in DVB systems)
274 */
275typedef struct DVBAC3Descriptor {
277 uint8_t bsid_flag;
278 uint8_t mainid_flag;
279 uint8_t asvc_flag;
282 uint8_t bsid;
283 uint8_t mainid;
284 uint8_t asvc;
286
287/**
288 * Parse an MPEG-2 descriptor
289 * @param[in] fc Format context (used for logging only)
290 * @param st Stream
291 * @param stream_type STREAM_TYPE_xxx
292 * @param pp Descriptor buffer pointer
293 * @param desc_list_end End of buffer
294 * @return <0 to stop processing
295 */
296int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type, int prg_id,
297 const uint8_t **pp, const uint8_t *desc_list_end,
298 Mp4Descr *mp4_descr, int mp4_descr_count, int pid,
299 MpegTSContext *ts);
300
301/**
302 * Check presence of H264 startcode
303 * @return <0 to stop processing
304 */
306
307#endif /* AVFORMAT_MPEGTS_H */
Main libavformat public API header.
#define s(width, name)
Definition cbs_vp9.c:198
static const uint16_t fc[]
Definition dcaenc.h:43
static AVPacket * pkt
void avpriv_mpegts_parse_close(MpegTSContext *ts)
Definition mpegts.c:3871
int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type, int prg_id, const uint8_t **pp, const uint8_t *desc_list_end, Mp4Descr *mp4_descr, int mp4_descr_count, int pid, MpegTSContext *ts)
Parse an MPEG-2 descriptor.
Definition mpegts.c:2077
int ff_check_h264_startcode(AVFormatContext *s, const AVStream *st, const AVPacket *pkt)
Check presence of H264 startcode.
Definition mpegtsenc.c:1839
MpegTSContext * avpriv_mpegts_parse_open(AVFormatContext *s)
Definition mpegts.c:3824
int avpriv_mpegts_parse_packet(MpegTSContext *ts, AVPacket *pkt, const uint8_t *buf, int len)
Definition mpegts.c:3846
Format I/O context.
Definition avformat.h:1333
This structure stores compressed data.
Definition packet.h:580
Stream structure.
Definition avformat.h:766
uint8_t asvc
Definition mpegts.h:284
uint8_t bsid_flag
Definition mpegts.h:277
uint8_t mainid_flag
Definition mpegts.h:278
uint8_t bsid
Definition mpegts.h:282
uint8_t reserved_flags
Definition mpegts.h:280
uint8_t component_type_flag
Definition mpegts.h:276
uint8_t mainid
Definition mpegts.h:283
uint8_t component_type
Definition mpegts.h:281
uint8_t asvc_flag
Definition mpegts.h:279
int es_id
Definition mpegts.h:265
uint8_t * dec_config_descr
Definition mpegts.h:267
SLConfigDescr sl
Definition mpegts.h:268
int dec_config_descr_len
Definition mpegts.h:266
int use_au_start
Definition mpegts.h:248
int timestamp_res
Definition mpegts.h:254
int timestamp_len
Definition mpegts.h:255
int degr_prior_len
Definition mpegts.h:259
int au_seq_num_len
Definition mpegts.h:260
int packet_seq_num_len
Definition mpegts.h:261
int use_rand_acc_pt
Definition mpegts.h:250
int use_au_end
Definition mpegts.h:249
int inst_bitrate_len
Definition mpegts.h:258
int use_timestamps
Definition mpegts.h:252
int use_padding
Definition mpegts.h:251
int len