Move files from gst-plugins-bad into the "subprojects/gst-plugins-bad/" subdir
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-bad / gst-libs / gst / mpegts / gstmpegtsdescriptor.h
1 /*
2  * gstmpegtsdescriptor.h -
3  * Copyright (C) 2013 Edward Hervey
4  *
5  * Authors:
6  *   Edward Hervey <edward@collabora.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  * Some parts of this code come from the Fluendo MPEG Demuxer plugin.
24  *
25  * The Initial Developer of the Original Code is Fluendo, S.L.
26  * Portions created by Fluendo, S.L. are Copyright (C) 2005
27  * Fluendo, S.L. All Rights Reserved.
28  *
29  * Contributor(s): Wim Taymans <wim@fluendo.com>
30  */
31
32 #ifndef GST_MPEGTS_DESCRIPTOR_H
33 #define GST_MPEGTS_DESCRIPTOR_H
34
35 #include <gst/gst.h>
36 #include <gst/mpegts/mpegts-prelude.h>
37
38 G_BEGIN_DECLS
39
40 /*
41  * descriptor_tag TS  PS                      Identification
42  *        0       n/a n/a Reserved
43  *        1       n/a n/a Reserved
44  *        2        X   X  video_stream_descriptor
45  *        3        X   X  audio_stream_descriptor
46  *        4        X   X  hierarchy_descriptor
47  *        5        X   X  registration_descriptor
48  *        6        X   X  data_stream_alignment_descriptor
49  *        7        X   X  target_background_grid_descriptor
50  *        8        X   X  video_window_descriptor
51  *        9        X   X  CA_descriptor
52  *       10        X   X  ISO_639_language_descriptor
53  *       11        X   X  system_clock_descriptor
54  *       12        X   X  multiplex_buffer_utilization_descriptor
55  *       13        X   X  copyright_descriptor
56  *       14        X      maximum bitrate descriptor
57  *       15        X   X  private data indicator descriptor
58  *       16        X   X  smoothing buffer descriptor
59  *       17        X      STD_descriptor
60  *       18        X   X  IBP descriptor
61  *      19-63     n/a n/a ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Reserved
62  *     64-255     n/a n/a User Private
63  */
64
65 /**
66  * GstMpegtsDescriptorType:
67  *
68  * The type of #GstMpegtsDescriptor
69  *
70  * These values correspond to the registered descriptor type from
71  * the base MPEG-TS specifications (ITU H.222.0 | ISO/IEC 13818-1).
72  *
73  * Consult the relevant specifications for more details.
74  */
75 typedef enum {
76   /* 0-18 ISO/IEC 13818-1 (H222.0 06/2012) */
77   GST_MTS_DESC_RESERVED_00                      = 0x00,
78   GST_MTS_DESC_RESERVED_01                      = 0x01,
79   GST_MTS_DESC_VIDEO_STREAM                     = 0x02,
80   GST_MTS_DESC_AUDIO_STREAM                     = 0x03,
81   GST_MTS_DESC_HIERARCHY                        = 0x04,
82   GST_MTS_DESC_REGISTRATION                     = 0x05,
83   GST_MTS_DESC_DATA_STREAM_ALIGNMENT            = 0x06,
84   GST_MTS_DESC_TARGET_BACKGROUND_GRID           = 0x07,
85   GST_MTS_DESC_VIDEO_WINDOW                     = 0x08,
86   GST_MTS_DESC_CA                               = 0x09,
87   GST_MTS_DESC_ISO_639_LANGUAGE                 = 0x0A,
88   GST_MTS_DESC_SYSTEM_CLOCK                     = 0x0B,
89   GST_MTS_DESC_MULTIPLEX_BUFFER_UTILISATION     = 0x0C,
90   GST_MTS_DESC_COPYRIGHT                        = 0x0D,
91   GST_MTS_DESC_MAXIMUM_BITRATE                  = 0x0E,
92   GST_MTS_DESC_PRIVATE_DATA_INDICATOR           = 0x0F,
93   GST_MTS_DESC_SMOOTHING_BUFFER                 = 0x10,
94   GST_MTS_DESC_STD                              = 0x11,
95   GST_MTS_DESC_IBP                              = 0x12,
96
97   /* 19-26 Defined in ISO/IEC 13818-6 (Extensions for DSM-CC) */
98   GST_MTS_DESC_DSMCC_CAROUSEL_IDENTIFIER        = 0x13,
99   GST_MTS_DESC_DSMCC_ASSOCIATION_TAG            = 0x14,
100   GST_MTS_DESC_DSMCC_DEFERRED_ASSOCIATION_TAG   = 0x15,
101   /* 0x16 is reserved (so far) */
102   GST_MTS_DESC_DSMCC_NPT_REFERENCE              = 0x17,
103   GST_MTS_DESC_DSMCC_NPT_ENDPOINT               = 0x18,
104   GST_MTS_DESC_DSMCC_STREAM_MODE                = 0x19,
105   GST_MTS_DESC_DSMCC_STREAM_EVENT               = 0x1A,
106
107   /* 27-54 Later additions to ISO/IEC 13818-1 (H222.0 06/2012) */
108   GST_MTS_DESC_MPEG4_VIDEO                      = 0x1B,
109   GST_MTS_DESC_MPEG4_AUDIO                      = 0x1C,
110   GST_MTS_DESC_IOD                              = 0x1D,
111   GST_MTS_DESC_SL                               = 0x1E,
112   GST_MTS_DESC_FMC                              = 0x1F,
113   GST_MTS_DESC_EXTERNAL_ES_ID                   = 0x20,
114   GST_MTS_DESC_MUX_CODE                         = 0x21,
115   GST_MTS_DESC_FMX_BUFFER_SIZE                  = 0x22,
116   GST_MTS_DESC_MULTIPLEX_BUFFER                 = 0x23,
117   GST_MTS_DESC_CONTENT_LABELING                 = 0x24,
118   GST_MTS_DESC_METADATA_POINTER                 = 0x25,
119   GST_MTS_DESC_METADATA                         = 0x26,
120   GST_MTS_DESC_METADATA_STD                     = 0x27,
121   GST_MTS_DESC_AVC_VIDEO                        = 0x28,
122   /* defined in ISO/IEC 13818-11, MPEG-2 IPMP */
123   GST_MTS_DESC_IPMP                             = 0x29,
124   GST_MTS_DESC_AVC_TIMING_AND_HRD               = 0x2A,
125   GST_MTS_DESC_MPEG2_AAC_AUDIO                  = 0x2B,
126   GST_MTS_DESC_FLEX_MUX_TIMING                  = 0x2C,
127   GST_MTS_DESC_MPEG4_TEXT                       = 0x2D,
128   GST_MTS_DESC_MPEG4_AUDIO_EXTENSION            = 0x2E,
129   GST_MTS_DESC_AUXILIARY_VIDEO_STREAM           = 0x2F,
130   GST_MTS_DESC_SVC_EXTENSION                    = 0x30,
131   GST_MTS_DESC_MVC_EXTENSION                    = 0x31,
132   GST_MTS_DESC_J2K_VIDEO                        = 0x32,
133   GST_MTS_DESC_MVC_OPERATION_POINT              = 0x33,
134   GST_MTS_DESC_MPEG2_STEREOSCOPIC_VIDEO_FORMAT  = 0x34,
135   GST_MTS_DESC_STEREOSCOPIC_PROGRAM_INFO        = 0x35,
136   GST_MTS_DESC_STEREOSCOPIC_VIDEO_INFO          = 0x36,
137
138   /* 55-63 ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Reserved */
139 } GstMpegtsDescriptorType;
140
141 /**
142  * GstMpegtsMiscDescriptorType:
143  *
144  * The type of #GstMpegtsDescriptor
145  *
146  * These values correspond to miscellaneous descriptor types that are
147  * not yet identified from known specifications.
148  */
149 typedef enum {
150   /* 0x80 - 0xFE are user defined */
151   GST_MTS_DESC_DTG_LOGICAL_CHANNEL              = 0x83,    /* from DTG D-Book, only present in NIT */
152 } GstMpegtsMiscDescriptorType;
153
154 /**
155  * GstMpegtsSCTEDescriptorType:
156  *
157  * These values correspond to the ones defined by SCTE (amongst other in ANSI/SCTE 57)
158  *
159  * Since: 1.20
160  */
161 typedef enum {
162   GST_MTS_DESC_SCTE_STUFFING                    = 0x80,
163   GST_MTS_DESC_SCTE_AC3                         = 0x81,
164   GST_MTS_DESC_SCTE_FRAME_RATE                  = 0x82,
165   GST_MTS_DESC_SCTE_EXTENDED_VIDEO              = 0x83,
166   GST_MTS_DESC_SCTE_COMPONENT_NAME              = 0x84,
167   GST_MTS_DESC_SCTE_FREQUENCY_SPEC              = 0x90,
168   GST_MTS_DESC_SCTE_MODULATION_PARAMS           = 0x91,
169   GST_MTS_DESC_SCTE_TRANSPORT_STREAM_ID         = 0x92
170 } GstMpegtsSCTEDescriptorType;
171
172
173
174 typedef struct _GstMpegtsDescriptor GstMpegtsDescriptor;
175
176 #define GST_TYPE_MPEGTS_DESCRIPTOR (gst_mpegts_descriptor_get_type())
177 GST_MPEGTS_API
178 GType gst_mpegts_descriptor_get_type (void);
179
180 /**
181  * GstMpegtsDescriptor:
182  * @tag: the type of descriptor
183  * @tag_extension: the extended type (if @descriptor_tag is 0x7f)
184  * @length: the length of the descriptor content (excluding tag/length field)
185  * @data: the full descriptor data (including tag, extension, length). The first
186  * two bytes are the @tag and @length.
187  *
188  * Mpeg-TS descriptor (ISO/IEC 13818-1).
189  */
190 struct _GstMpegtsDescriptor
191 {
192   guint8 tag;
193   guint8 tag_extension;
194   guint8 length;
195   guint8 *data;
196
197   /*< private >*/
198   /* Padding for future extension */
199   gpointer _gst_reserved[GST_PADDING];
200 };
201
202 GST_MPEGTS_API
203 void       gst_mpegts_descriptor_free (GstMpegtsDescriptor *desc);
204
205 GST_MPEGTS_API
206 GPtrArray *gst_mpegts_parse_descriptors (guint8 * buffer, gsize buf_len);
207
208 GST_MPEGTS_API
209 const GstMpegtsDescriptor * gst_mpegts_find_descriptor (GPtrArray *descriptors,
210                                                         guint8 tag);
211
212 GST_MPEGTS_API
213 const GstMpegtsDescriptor * gst_mpegts_find_descriptor_with_extension (GPtrArray *descriptors,
214                                                         guint8 tag, guint8 tag_extension);
215 /**
216  * GstMpegtsRegistrationId:
217  * @GST_MTS_REGISTRATION_0: Undefined registration id
218  * @GST_MTS_REGISTRATION_AC_3: Audio AC-3, ATSC A/52
219  * @GST_MTS_REGISTRATION_AC_4: Audio AC-4, ETSI 103 190-2
220  * @GST_MTS_REGISTRATION_CUEI: SCTE 35, "Digital Program Insertion Cueing Message"
221  * @GST_MTS_REGISTRATION_drac: Dirac Video codec
222  * @GST_MTS_REGISTRATION_DTS1: DTS Audio
223  * @GST_MTS_REGISTRATION_DTS2: DTS Audio
224  * @GST_MTS_REGISTRATION_DTS3: DTS Audio
225  * @GST_MTS_REGISTRATION_EAC3: Enhanced AC-3 (i.e. EAC3)
226  * @GST_MTS_REGISTRATION_ETV1: Cablelabs ETV
227  * @GST_MTS_REGISTRATION_BSSD: SMPTE 302M, Mapping of AES3 Data in mpeg-ts
228  * @GST_MTS_REGISTRATION_GA94: ATSC A/53 compliant stream (i.e. ATSC)
229  * @GST_MTS_REGISTRATION_HDMV: Blu-ray, "System Description Blu-ray Disc
230  *             Read-Only Format part 3 Audio Visual Basic Specifications" 
231  * @GST_MTS_REGISTRATION_KLVA: SMPTE RP217 : Non-synchronized Mapping of KLV
232  *             Packets in mpeg-ts
233  * @GST_MTS_REGISTRATION_OPUS: Opus Audio
234  * @GST_MTS_REGISTRATION_TSHV: HDV (Sony)
235  * @GST_MTS_REGISTRATION_VC_1: Video VC-1, SMPTE RP227 "VC-1 Bitstream Transport Encodings"
236  * @GST_MTS_REGISTRATION_OTHER_HEVC: HEVC / h265
237  *
238  * Well-known registration ids, expressed as native-endian 32bit integers. These
239  * are used in descriptors of type %GST_MTS_DESC_REGISTRATION. Unless specified
240  * otherwise (by use of the "OTHER" prefix), they are all registered by the
241  * [SMPTE Registration Authority](https://smpte-ra.org/) or specified in
242  * "official" documentation for the given format.
243  *
244  * Since: 1.20
245  */
246
247 /**
248  * REG_TO_UINT32: (skip) (attributes doc.skip=true)
249  */
250 #define REG_TO_UINT32(a,b,c,d)((a) << 24 | (b) << 16 | (c) << 8 | (d))
251
252 typedef enum {
253   GST_MTS_REGISTRATION_0 = 0,
254
255   /* SMPTE-RA registered */
256   GST_MTS_REGISTRATION_AC_3 = REG_TO_UINT32 ('A', 'C', '-', '3'),
257   GST_MTS_REGISTRATION_CUEI = REG_TO_UINT32 ('C', 'U', 'E', 'I'),
258   GST_MTS_REGISTRATION_drac = REG_TO_UINT32 ('d', 'r', 'a', 'c'),
259   GST_MTS_REGISTRATION_DTS1 = REG_TO_UINT32 ('D', 'T', 'S', '1'),
260   GST_MTS_REGISTRATION_DTS2 = REG_TO_UINT32 ('D', 'T', 'S', '2'),
261   GST_MTS_REGISTRATION_DTS3 = REG_TO_UINT32 ('D', 'T', 'S', '3'),
262   GST_MTS_REGISTRATION_BSSD = REG_TO_UINT32 ('B', 'S', 'S', 'D'),
263   GST_MTS_REGISTRATION_EAC3 = REG_TO_UINT32 ('E', 'A', 'C', '3'),
264   GST_MTS_REGISTRATION_ETV1 = REG_TO_UINT32 ('E', 'T', 'V', '1'),
265   GST_MTS_REGISTRATION_GA94 = REG_TO_UINT32 ('G', 'A', '9', '4'),
266   GST_MTS_REGISTRATION_HDMV = REG_TO_UINT32 ('H', 'D', 'M', 'V'),
267   GST_MTS_REGISTRATION_KLVA = REG_TO_UINT32 ('K', 'L', 'V', 'A'),
268   GST_MTS_REGISTRATION_OPUS = REG_TO_UINT32 ('O', 'P', 'U', 'S'),
269   GST_MTS_REGISTRATION_TSHV = REG_TO_UINT32 ('T', 'S', 'H', 'V'),
270   GST_MTS_REGISTRATION_VC_1 = REG_TO_UINT32 ('V', 'C', '-', '1'),
271
272   /* Self-registered by formats, but not in SMPTE-RA registry */
273   GST_MTS_REGISTRATION_AC_4 = REG_TO_UINT32 ('A', 'C', '-', '4'),
274
275   /* Found elsewhere */
276   GST_MTS_REGISTRATION_OTHER_HEVC = REG_TO_UINT32 ('H', 'E', 'V', 'C')
277 } GstMpegtsRegistrationId;
278
279 /* GST_MTS_DESC_REGISTRATION (0x05) */
280
281 GST_MPEGTS_API
282 GstMpegtsDescriptor *gst_mpegts_descriptor_from_registration (
283     const gchar *format_identifier,
284     guint8 *additional_info, gsize additional_info_length);
285
286 GST_MPEGTS_API
287 gboolean gst_mpegts_descriptor_parse_registration(GstMpegtsDescriptor *descriptor,
288                                                   guint32 *registration_id,
289                                                   guint8 **additional_info,
290                                                   gsize *additional_info_length);
291
292 /* GST_MTS_DESC_CA (0x09) */
293
294 GST_MPEGTS_API
295 gboolean  gst_mpegts_descriptor_parse_ca (GstMpegtsDescriptor *descriptor,
296                                           guint16 *ca_system_id,
297                                           guint16 *ca_pid,
298                                           const guint8 **private_data,
299                                           gsize *private_data_size);
300
301 /* GST_MTS_DESC_ISO_639_LANGUAGE (0x0A) */
302 /**
303  * GstMpegtsISO639AudioType:
304  *
305  * Type of audio streams
306  *
307  * Defined in ITU H.222.0 Table 2-60
308  */
309 typedef enum {
310   GST_MPEGTS_AUDIO_TYPE_UNDEFINED = 0,
311   GST_MPEGTS_AUDIO_TYPE_CLEAN_EFFECTS,
312   GST_MPEGTS_AUDIO_TYPE_HEARING_IMPAIRED,
313   GST_MPEGTS_AUDIO_TYPE_VISUAL_IMPAIRED_COMMENTARY
314 } GstMpegtsIso639AudioType;
315
316 typedef struct _GstMpegtsISO639LanguageDescriptor GstMpegtsISO639LanguageDescriptor;
317 struct _GstMpegtsISO639LanguageDescriptor
318 {
319   guint                    nb_language;
320   gchar                    *language[64];
321   GstMpegtsIso639AudioType audio_type[64];
322 };
323
324 #define GST_TYPE_MPEGTS_ISO_639_LANGUAGE (gst_mpegts_iso_639_language_get_type ())
325 GST_MPEGTS_API
326 GType gst_mpegts_iso_639_language_get_type (void);
327
328 GST_MPEGTS_API
329 void gst_mpegts_iso_639_language_descriptor_free (GstMpegtsISO639LanguageDescriptor * desc);
330
331 GST_MPEGTS_API
332 gboolean gst_mpegts_descriptor_parse_iso_639_language (const GstMpegtsDescriptor *descriptor,
333                                                        GstMpegtsISO639LanguageDescriptor **res);
334
335 GST_MPEGTS_API
336 gboolean gst_mpegts_descriptor_parse_iso_639_language_idx (const GstMpegtsDescriptor *descriptor,
337                                                            guint idx, gchar **lang,
338                                                            GstMpegtsIso639AudioType *audio_type);
339
340 GST_MPEGTS_API
341 guint gst_mpegts_descriptor_parse_iso_639_language_nb (const GstMpegtsDescriptor *descriptor);
342
343 GST_MPEGTS_API
344 GstMpegtsDescriptor * gst_mpegts_descriptor_from_iso_639_language (const gchar * language);
345
346
347
348 /* GST_MTS_DESC_DTG_LOGICAL_CHANNEL (0x83) */
349 typedef struct _GstMpegtsLogicalChannelDescriptor GstMpegtsLogicalChannelDescriptor;
350 typedef struct _GstMpegtsLogicalChannel GstMpegtsLogicalChannel;
351
352 struct _GstMpegtsLogicalChannel
353 {
354   guint16   service_id;
355   gboolean  visible_service;
356   guint16   logical_channel_number;
357 };
358
359 struct _GstMpegtsLogicalChannelDescriptor
360 {
361   guint                   nb_channels;
362   GstMpegtsLogicalChannel channels[64];
363 };
364
365 #define GST_TYPE_MPEGTS_LOGICAL_CHANNEL_DESCRIPTOR (gst_mpegts_logical_channel_descriptor_get_type())
366
367 GST_MPEGTS_API
368 GType gst_mpegts_logical_channel_descriptor_get_type(void);
369
370 #define GST_TYPE_MPEGTS_LOGICAL_CHANNEL (gst_mpegts_logical_channel_get_type())
371
372 GST_MPEGTS_API
373 GType gst_mpegts_logical_channel_get_type(void);
374
375 /* FIXME : Maybe make two methods. One for getting the number of channels,
376  * and the other for getting the content for one channel ? */
377 GST_MPEGTS_API
378 gboolean
379 gst_mpegts_descriptor_parse_logical_channel (const GstMpegtsDescriptor *descriptor,
380                                              GstMpegtsLogicalChannelDescriptor *res);
381
382 GST_MPEGTS_API
383 GstMpegtsDescriptor *
384 gst_mpegts_descriptor_from_custom (guint8 tag, const guint8 *data, gsize length);
385
386
387 GST_MPEGTS_API
388 GstMpegtsDescriptor *
389 gst_mpegts_descriptor_from_custom_with_extension (guint8 tag, guint8 tag_extension, const guint8 *data, gsize length);
390
391 G_END_DECLS
392
393 #endif                          /* GST_MPEGTS_DESCRIPTOR_H */