scte-section: add support for parsing splice components
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-bad / gst-libs / gst / mpegts / gst-scte-section.h
1 /*
2  * gst-scte-section.h -
3  * Copyright (C) 2013, CableLabs, Louisville, CO 80027
4  *           (c) 2019, Centricular ltd
5  *
6  * Authors:
7  *   RUIH Team <ruih@cablelabs.com>
8  *   Edward Hervey <edward@centricular.com>
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the
22  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23  * Boston, MA 02110-1301, USA.
24  */
25
26 #ifndef GST_SCTE_SECTION_H
27 #define GST_SCTE_SECTION_H
28
29 #include <gst/gst.h>
30 #include <gst/mpegts/gstmpegtssection.h>
31 #include <gst/mpegts/gstmpegtsdescriptor.h>
32
33 G_BEGIN_DECLS
34
35 /**
36  * GstMpegtsScteStreamType:
37  * @GST_MPEGTS_STREAM_TYPE_SCTE_SUBTITLING:  SCTE-27 Subtitling
38  * @GST_MPEGTS_STREAM_TYPE_SCTE_ISOCH_DATA:  SCTE-19 Isochronous data
39  * @GST_MPEGTS_STREAM_TYPE_SCTE_SIT:         SCTE-35 Splice Information Table
40  * @GST_MPEGTS_STREAM_TYPE_SCTE_DST_NRT:     SCTE-07 Data Service or
41  * Network Resource Table
42  * @GST_MPEGTS_STREAM_TYPE_SCTE_DSMCC_DCB:   Type B - DSM-CC Data Carousel
43  * [IEC 13818-6])
44  * @GST_MPEGTS_STREAM_TYPE_SCTE_SIGNALING:   Enhanced Television Application
45  * Signaling (OC-SP-ETV-AM1.0.1-120614)
46  * @GST_MPEGTS_STREAM_TYPE_SCTE_SYNC_DATA:   SCTE-07 Synchronous data
47  * @GST_MPEGTS_STREAM_TYPE_SCTE_ASYNC_DATA:  SCTE-53 Asynchronous data
48  *
49  * Type of mpeg-ts streams for SCTE. Most users would want to use the
50  * #GstMpegtsATSCStreamType instead since it also covers these stream types
51  *
52  */
53 typedef enum {
54
55   /* 0x01 - 0x7f : defined in other specs */
56   GST_MPEGTS_STREAM_TYPE_SCTE_SUBTITLING = 0x82,   /* Subtitling data */
57   GST_MPEGTS_STREAM_TYPE_SCTE_ISOCH_DATA = 0x83,   /* Isochronous data */
58   /* 0x84 - 0x85 : defined in other specs */
59   GST_MPEGTS_STREAM_TYPE_SCTE_SIT        = 0x86,   /* Splice Information Table */
60   /* 0x87 - 0x94 : defined in other specs */
61   GST_MPEGTS_STREAM_TYPE_SCTE_DST_NRT    = 0x95,   /* DST / NRT data */
62   /* 0x96 - 0xaf : defined in other specs */
63   GST_MPEGTS_STREAM_TYPE_SCTE_DSMCC_DCB  = 0xb0,   /* Data Carousel Type B */
64   /* 0xb1 - 0xbf : User Private (or defined in other specs) */
65   GST_MPEGTS_STREAM_TYPE_SCTE_SIGNALING  = 0xc0,   /* EBIF Signaling */
66   GST_MPEGTS_STREAM_TYPE_SCTE_SYNC_DATA  = 0xc2,   /* Synchronous data */
67   GST_MPEGTS_STREAM_TYPE_SCTE_ASYNC_DATA = 0xc3,   /* Asynchronous data */
68   /* 0xc4 - 0xff : User Private (or defined in other specs) */
69
70 } GstMpegtsScteStreamType;
71
72
73 /**
74  * GstMpegtsSectionSCTETableID:
75  * @GST_MTS_TABLE_ID_SCTE_EAS:    SCTE-18 Emergency Alert System
76  * @GST_MTS_TABLE_ID_SCTE_EBIF:   CL-SP-ETV-AM 1.0.1 EBIF message
77  * @GST_MTS_TABLE_ID_SCTE_EISS:   CL-SP-ETV-AM 1.0.1 EBIF Int. Signaling Sect.
78  * @GST_MTS_TABLE_ID_SCTE_DII:    CL-SP-ETV-AM 1.0.1 DSMCC DII message
79  * @GST_MTS_TABLE_ID_SCTE_DDB:    CL-SP-ETV-AM 1.0.1 DSMCC Data Download Block
80  * @GST_MTS_TABLE_ID_SCTE_SPLICE: SCTE-35 splice information is carried in a
81  * section stream on a separate PID in the program’s Map Table (PMT) allowing
82  * Splice Event notifications to remain associated with the program and pass
83  * through multiplexers.
84  *
85  * Values for a #GstMpegtsSection table_id.
86  *
87  * These are the registered SCTE table_id variants.
88  *
89  * see also: #GstMpegtsSectionTableID
90  */
91 typedef enum {
92
93   /* 0x01 - 0xd7 : defined in other specs */
94   GST_MTS_TABLE_ID_SCTE_EAS      = 0xd8,     /* emergency alert information */
95   /* 0xd8 - 0xdf : defined in other specs */
96   GST_MTS_TABLE_ID_SCTE_EBIF     = 0xE0,     /* EBIF message */
97   GST_MTS_TABLE_ID_SCTE_RESERVED = 0xE1,
98   GST_MTS_TABLE_ID_SCTE_EISS     = 0xE2,     /* EBIF Int. Signaling Sect. */
99   GST_MTS_TABLE_ID_SCTE_DII      = 0xE3,     /* DSMCC DII message */
100   GST_MTS_TABLE_ID_SCTE_DDB      = 0xE4,     /* DSMCC Data Download Block */
101   /* 0xe5 - 0xfb : defined in other specs */
102   GST_MTS_TABLE_ID_SCTE_SPLICE   = 0xfc,     /* splice information table */
103
104 } GstMpegtsSectionSCTETableID;
105
106 #define GST_TYPE_MPEGTS_SCTE_SPLICE_COMPONENT (gst_mpegts_scte_splice_component_get_type())
107 typedef struct _GstMpegtsSCTESpliceComponent GstMpegtsSCTESpliceComponent;
108
109 struct _GstMpegtsSCTESpliceComponent {
110   guint8 tag;
111
112   gboolean splice_time_specified; /* Only valid for insert_event */
113   guint64 splice_time; /* Only valid for insert_event */
114
115   guint32 utc_splice_time; /* Only valid for !insert_event (schedule) */
116 };
117
118 /* Splice Information Table (SIT) */
119 #define GST_TYPE_MPEGTS_SCTE_SPLICE_EVENT (gst_mpegts_scte_splice_event_get_type())
120 typedef struct _GstMpegtsSCTESpliceEvent GstMpegtsSCTESpliceEvent;
121
122 struct _GstMpegtsSCTESpliceEvent {
123   /* TRUE if from/to an insert event (else belongs to a schedule event) */
124   gboolean insert_event;
125
126   guint32 splice_event_id;
127   gboolean splice_event_cancel_indicator;
128
129   /* If splice_event_cancel_indicator == 0 */
130   gboolean out_of_network_indicator;
131   gboolean program_splice_flag;
132   gboolean duration_flag;
133
134   gboolean splice_immediate_flag; /* Only valid for insert_event */
135
136   gboolean program_splice_time_specified; /* Only valid for insert_event && program_splice */
137   guint64 program_splice_time; /* Only valid for insert_event && program_splice */
138
139   guint32 utc_splice_time; /* Only valid for !insert_event (schedule) && program_splice */
140
141   GPtrArray *components; /* Only valid for !program_splice */
142
143   gboolean break_duration_auto_return;
144   guint64 break_duration;
145
146   guint16 unique_program_id;
147   guint8 avail_num;
148   guint8 avails_expected;
149
150 };
151
152 /*
153  * Types of descriptors
154  *
155  * Note: These are only for the descriptors *WITHIN* a SIT */
156 typedef enum {
157   GST_MTS_SCTE_DESC_AVAIL        = 0x00,
158   GST_MTS_SCTE_DESC_DTMF         = 0x01,
159   GST_MTS_SCTE_DESC_SEGMENTATION = 0x02,
160   GST_MTS_SCTE_DESC_TIME         = 0x03,
161   GST_MTS_SCTE_DESC_AUDIO        = 0x04
162 } GstMpegtsSCTESpliceDescriptor;
163
164 typedef enum {
165   GST_MTS_SCTE_SPLICE_COMMAND_NULL      = 0x00,
166   GST_MTS_SCTE_SPLICE_COMMAND_SCHEDULE  = 0x04,
167   GST_MTS_SCTE_SPLICE_COMMAND_INSERT    = 0x05,
168   GST_MTS_SCTE_SPLICE_COMMAND_TIME      = 0x06,
169   GST_MTS_SCTE_SPLICE_COMMAND_BANDWIDTH = 0x07,
170   GST_MTS_SCTE_SPLICE_COMMAND_PRIVATE   = 0xff
171 } GstMpegtsSCTESpliceCommandType;
172
173 #define GST_TYPE_MPEGTS_SCTE_SIT (gst_mpegts_scte_sit_get_type())
174
175 typedef struct _GstMpegtsSCTESIT GstMpegtsSCTESIT;
176
177 struct _GstMpegtsSCTESIT
178 {
179   gboolean encrypted_packet;
180   guint8   encryption_algorithm;
181
182   guint64  pts_adjustment;
183   guint8   cw_index;
184   guint16  tier;
185
186   guint16  splice_command_length;
187
188   /* When encrypted, or when encountering an unknown command type,
189    * we may still want to pass the sit through */
190   gboolean fully_parsed;
191
192   GstMpegtsSCTESpliceCommandType splice_command_type;
193
194   /* For time_signal commands */
195   gboolean splice_time_specified;
196   guint64  splice_time;
197
198   GPtrArray *splices;
199
200   GPtrArray *descriptors;
201 };
202
203 GST_MPEGTS_API
204 GType gst_mpegts_scte_sit_get_type (void);
205
206 GST_MPEGTS_API
207 GstMpegtsSCTESIT *gst_mpegts_scte_sit_new (void);
208
209 GST_MPEGTS_API
210 GstMpegtsSCTESIT *gst_mpegts_scte_null_new (void);
211
212 GST_MPEGTS_API
213 GstMpegtsSCTESIT *gst_mpegts_scte_cancel_new (guint32 event_id);
214
215 GST_MPEGTS_API
216 GstMpegtsSCTESIT *gst_mpegts_scte_splice_in_new (guint32 event_id,
217                                                  GstClockTime splice_time);
218
219 GST_MPEGTS_API
220 GstMpegtsSCTESIT *gst_mpegts_scte_splice_out_new (guint32 event_id,
221                                                   GstClockTime splice_time,
222                                                   GstClockTime duration);
223
224
225 GST_MPEGTS_API
226 GType gst_mpegts_scte_splice_event_get_type (void);
227
228 GST_MPEGTS_API
229 GstMpegtsSCTESpliceEvent *gst_mpegts_scte_splice_event_new (void);
230
231 GST_MPEGTS_API
232 const GstMpegtsSCTESIT *gst_mpegts_section_get_scte_sit (GstMpegtsSection *section);
233
234 GST_MPEGTS_API
235 GstMpegtsSection *gst_mpegts_section_from_scte_sit (GstMpegtsSCTESIT * sit, guint16 pid);
236
237 GST_MPEGTS_API
238 GType gst_mpegts_scte_splice_component_get_type (void);
239
240 GST_MPEGTS_API
241 GstMpegtsSCTESpliceComponent *gst_mpegts_scte_splice_component_new (guint8 tag);
242
243
244 G_END_DECLS
245
246 #endif  /* GST_SCTE_SECTION_H */