mpegts.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. #ifndef AVFORMAT_MPEGTS_H
  22. #define AVFORMAT_MPEGTS_H
  23. #include "avformat.h"
  24. #define TS_FEC_PACKET_SIZE 204
  25. #define TS_DVHS_PACKET_SIZE 192
  26. #define TS_PACKET_SIZE 188
  27. #define TS_MAX_PACKET_SIZE 204
  28. #define NB_PID_MAX 8192
  29. #define USUAL_SECTION_SIZE 1024 /* except EIT which is limited to 4096 */
  30. #define MAX_SECTION_SIZE 4096
  31. /* pids */
  32. #define PAT_PID 0x0000 /* Program Association Table */
  33. #define CAT_PID 0x0001 /* Conditional Access Table */
  34. #define TSDT_PID 0x0002 /* Transport Stream Description Table */
  35. #define IPMP_PID 0x0003
  36. /* PID from 0x0004 to 0x000F are reserved */
  37. #define NIT_PID 0x0010 /* Network Information Table */
  38. #define SDT_PID 0x0011 /* Service Description Table */
  39. #define BAT_PID 0x0011 /* Bouquet Association Table */
  40. #define EIT_PID 0x0012 /* Event Information Table */
  41. #define RST_PID 0x0013 /* Running Status Table */
  42. #define TDT_PID 0x0014 /* Time and Date Table */
  43. #define TOT_PID 0x0014
  44. #define NET_SYNC_PID 0x0015
  45. #define RNT_PID 0x0016 /* RAR Notification Table */
  46. /* PID from 0x0017 to 0x001B are reserved for future use */
  47. /* PID value 0x001C allocated to link-local inband signalling shall not be
  48. * used on any broadcast signals. It shall only be used between devices in a
  49. * controlled environment. */
  50. #define LINK_LOCAL_PID 0x001C
  51. #define MEASUREMENT_PID 0x001D
  52. #define DIT_PID 0x001E /* Discontinuity Information Table */
  53. #define SIT_PID 0x001F /* Selection Information Table */
  54. /* PID from 0x0020 to 0x1FFA may be assigned as needed to PMT, elementary
  55. * streams and other data tables */
  56. #define FIRST_OTHER_PID 0x0020
  57. #define LAST_OTHER_PID 0x1FFA
  58. /* PID 0x1FFB is used by DigiCipher 2/ATSC MGT metadata */
  59. /* PID from 0x1FFC to 0x1FFE may be assigned as needed to PMT, elementary
  60. * streams and other data tables */
  61. #define NULL_PID 0x1FFF /* Null packet (used for fixed bandwidth padding) */
  62. /* m2ts pids */
  63. #define M2TS_PMT_PID 0x0100
  64. #define M2TS_PCR_PID 0x1001
  65. #define M2TS_VIDEO_PID 0x1011
  66. #define M2TS_AUDIO_START_PID 0x1100
  67. #define M2TS_PGSSUB_START_PID 0x1200
  68. #define M2TS_TEXTSUB_PID 0x1800
  69. #define M2TS_SECONDARY_AUDIO_START_PID 0x1A00
  70. #define M2TS_SECONDARY_VIDEO_START_PID 0x1B00
  71. /* table ids */
  72. #define PAT_TID 0x00 /* Program Association section */
  73. #define CAT_TID 0x01 /* Conditional Access section */
  74. #define PMT_TID 0x02 /* Program Map section */
  75. #define TSDT_TID 0x03 /* Transport Stream Description section */
  76. /* TID from 0x04 to 0x3F are reserved */
  77. #define M4OD_TID 0x05
  78. #define NIT_TID 0x40 /* Network Information section - actual network */
  79. #define ONIT_TID 0x41 /* Network Information section - other network */
  80. #define SDT_TID 0x42 /* Service Description section - actual TS */
  81. /* TID from 0x43 to 0x45 are reserved for future use */
  82. #define OSDT_TID 0x46 /* Service Descrition section - other TS */
  83. /* TID from 0x47 to 0x49 are reserved for future use */
  84. #define BAT_TID 0x4A /* Bouquet Association section */
  85. #define UNT_TID 0x4B /* Update Notification Table section */
  86. #define DFI_TID 0x4C /* Downloadable Font Info section */
  87. /* TID 0x4D is reserved for future use */
  88. #define EIT_TID 0x4E /* Event Information section - actual TS */
  89. #define OEIT_TID 0x4F /* Event Information section - other TS */
  90. #define EITS_START_TID 0x50 /* Event Information section schedule - actual TS */
  91. #define EITS_END_TID 0x5F /* Event Information section schedule - actual TS */
  92. #define OEITS_START_TID 0x60 /* Event Information section schedule - other TS */
  93. #define OEITS_END_TID 0x6F /* Event Information section schedule - other TS */
  94. #define TDT_TID 0x70 /* Time Date section */
  95. #define RST_TID 0x71 /* Running Status section */
  96. #define ST_TID 0x72 /* Stuffing section */
  97. #define TOT_TID 0x73 /* Time Offset section */
  98. #define AIT_TID 0x74 /* Application Inforamtion section */
  99. #define CT_TID 0x75 /* Container section */
  100. #define RCT_TID 0x76 /* Related Content section */
  101. #define CIT_TID 0x77 /* Content Identifier section */
  102. #define MPE_FEC_TID 0x78 /* MPE-FEC section */
  103. #define RPNT_TID 0x79 /* Resolution Provider Notification section */
  104. #define MPE_IFEC_TID 0x7A /* MPE-IFEC section */
  105. #define PROTMT_TID 0x7B /* Protection Message section */
  106. /* TID from 0x7C to 0x7D are reserved for future use */
  107. #define DIT_TID 0x7E /* Discontinuity Information section */
  108. #define SIT_TID 0x7F /* Selection Information section */
  109. /* TID from 0x80 to 0xFE are user defined */
  110. /* TID 0xFF is reserved */
  111. #define STREAM_TYPE_VIDEO_MPEG1 0x01
  112. #define STREAM_TYPE_VIDEO_MPEG2 0x02
  113. #define STREAM_TYPE_AUDIO_MPEG1 0x03
  114. #define STREAM_TYPE_AUDIO_MPEG2 0x04
  115. #define STREAM_TYPE_PRIVATE_SECTION 0x05
  116. #define STREAM_TYPE_PRIVATE_DATA 0x06
  117. #define STREAM_TYPE_AUDIO_AAC 0x0f
  118. #define STREAM_TYPE_AUDIO_AAC_LATM 0x11
  119. #define STREAM_TYPE_VIDEO_MPEG4 0x10
  120. #define STREAM_TYPE_METADATA 0x15
  121. #define STREAM_TYPE_VIDEO_H264 0x1b
  122. #define STREAM_TYPE_VIDEO_HEVC 0x24
  123. #define STREAM_TYPE_VIDEO_CAVS 0x42
  124. #define STREAM_TYPE_VIDEO_VC1 0xea
  125. #define STREAM_TYPE_VIDEO_DIRAC 0xd1
  126. #define STREAM_TYPE_AUDIO_AC3 0x81
  127. #define STREAM_TYPE_AUDIO_DTS 0x82
  128. #define STREAM_TYPE_AUDIO_TRUEHD 0x83
  129. #define STREAM_TYPE_AUDIO_EAC3 0x87
  130. /* ISO/IEC 13818-1 Table 2-22 */
  131. #define STREAM_ID_PRIVATE_STREAM_1 0xbd
  132. #define STREAM_ID_AUDIO_STREAM_0 0xc0
  133. #define STREAM_ID_VIDEO_STREAM_0 0xe0
  134. #define STREAM_ID_METADATA_STREAM 0xfc
  135. #define STREAM_ID_EXTENDED_STREAM_ID 0xfd
  136. typedef struct MpegTSContext MpegTSContext;
  137. MpegTSContext *avpriv_mpegts_parse_open(AVFormatContext *s);
  138. int avpriv_mpegts_parse_packet(MpegTSContext *ts, AVPacket *pkt,
  139. const uint8_t *buf, int len);
  140. void avpriv_mpegts_parse_close(MpegTSContext *ts);
  141. typedef struct SLConfigDescr {
  142. int use_au_start;
  143. int use_au_end;
  144. int use_rand_acc_pt;
  145. int use_padding;
  146. int use_timestamps;
  147. int use_idle;
  148. int timestamp_res;
  149. int timestamp_len;
  150. int ocr_len;
  151. int au_len;
  152. int inst_bitrate_len;
  153. int degr_prior_len;
  154. int au_seq_num_len;
  155. int packet_seq_num_len;
  156. } SLConfigDescr;
  157. typedef struct Mp4Descr {
  158. int es_id;
  159. int dec_config_descr_len;
  160. uint8_t *dec_config_descr;
  161. SLConfigDescr sl;
  162. } Mp4Descr;
  163. /*
  164. * ETSI 300 468 descriptor 0x6A(AC-3)
  165. * Refer to: ETSI EN 300 468 V1.11.1 (2010-04) (SI in DVB systems)
  166. */
  167. typedef struct DVBAC3Descriptor {
  168. uint8_t component_type_flag;
  169. uint8_t bsid_flag;
  170. uint8_t mainid_flag;
  171. uint8_t asvc_flag;
  172. uint8_t reserved_flags;
  173. uint8_t component_type;
  174. uint8_t bsid;
  175. uint8_t mainid;
  176. uint8_t asvc;
  177. } DVBAC3Descriptor;
  178. /**
  179. * Parse an MPEG-2 descriptor
  180. * @param[in] fc Format context (used for logging only)
  181. * @param st Stream
  182. * @param stream_type STREAM_TYPE_xxx
  183. * @param pp Descriptor buffer pointer
  184. * @param desc_list_end End of buffer
  185. * @return <0 to stop processing
  186. */
  187. int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type,
  188. const uint8_t **pp, const uint8_t *desc_list_end,
  189. Mp4Descr *mp4_descr, int mp4_descr_count, int pid,
  190. MpegTSContext *ts);
  191. /**
  192. * Check presence of H264 startcode
  193. * @return <0 to stop processing
  194. */
  195. int ff_check_h264_startcode(AVFormatContext *s, const AVStream *st, const AVPacket *pkt);
  196. #endif /* AVFORMAT_MPEGTS_H */