scte-section: add support for SCHEDULE commands
[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 /* Splice Information Table (SIT) */
107 #define GST_TYPE_MPEGTS_SCTE_SPLICE_EVENT (gst_mpegts_scte_splice_event_get_type())
108 typedef struct _GstMpegtsSCTESpliceEvent GstMpegtsSCTESpliceEvent;
109
110 struct _GstMpegtsSCTESpliceEvent {
111   /* TRUE if from/to an insert event (else belongs to a schedule event) */
112   gboolean insert_event;
113
114   guint32 splice_event_id;
115   gboolean splice_event_cancel_indicator;
116
117   /* If splice_event_cancel_indicator == 0 */
118   gboolean out_of_network_indicator;
119   gboolean program_splice_flag;   /* NOTE: Only program splice are supported */
120   gboolean duration_flag;
121
122   gboolean splice_immediate_flag; /* Only valid for insert_event */
123   gboolean program_splice_time_specified; /* Only valid for insert_event */
124   guint64 program_splice_time; /* Only valid for insert_event */
125
126   guint32 utc_splice_time; /* Only valid for !insert_event (schedule) */
127
128   gboolean break_duration_auto_return;
129   guint64 break_duration;
130
131   guint16 unique_program_id;
132   guint8 avail_num;
133   guint8 avails_expected;
134
135 };
136
137 /*
138  * Types of descriptors
139  *
140  * Note: These are only for the descriptors *WITHIN* a SIT */
141 typedef enum {
142   GST_MTS_SCTE_DESC_AVAIL        = 0x00,
143   GST_MTS_SCTE_DESC_DTMF         = 0x01,
144   GST_MTS_SCTE_DESC_SEGMENTATION = 0x02,
145   GST_MTS_SCTE_DESC_TIME         = 0x03,
146   GST_MTS_SCTE_DESC_AUDIO        = 0x04
147 } GstMpegtsSCTESpliceDescriptor;
148
149 typedef enum {
150   GST_MTS_SCTE_SPLICE_COMMAND_NULL      = 0x00,
151   GST_MTS_SCTE_SPLICE_COMMAND_SCHEDULE  = 0x04,
152   GST_MTS_SCTE_SPLICE_COMMAND_INSERT    = 0x05,
153   GST_MTS_SCTE_SPLICE_COMMAND_TIME      = 0x06,
154   GST_MTS_SCTE_SPLICE_COMMAND_BANDWIDTH = 0x07,
155   GST_MTS_SCTE_SPLICE_COMMAND_PRIVATE   = 0xff
156 } GstMpegtsSCTESpliceCommandType;
157
158 #define GST_TYPE_MPEGTS_SCTE_SIT (gst_mpegts_scte_sit_get_type())
159
160 typedef struct _GstMpegtsSCTESIT GstMpegtsSCTESIT;
161
162 struct _GstMpegtsSCTESIT
163 {
164   gboolean encrypted_packet;
165   guint8   encryption_algorithm;
166
167   guint64  pts_adjustment;
168   guint8   cw_index;
169   guint16  tier;
170
171   guint16  splice_command_length;
172
173   /* When encrypted, or when encountering an unknown command type,
174    * we may still want to pass the sit through */
175   gboolean fully_parsed;
176
177   GstMpegtsSCTESpliceCommandType splice_command_type;
178
179   /* For time_signal commands */
180   gboolean splice_time_specified;
181   guint64  splice_time;
182
183   GPtrArray *splices;
184
185   GPtrArray *descriptors;
186 };
187
188 GST_MPEGTS_API
189 GType gst_mpegts_scte_sit_get_type (void);
190
191 GST_MPEGTS_API
192 GstMpegtsSCTESIT *gst_mpegts_scte_sit_new (void);
193
194 GST_MPEGTS_API
195 GstMpegtsSCTESIT *gst_mpegts_scte_null_new (void);
196
197 GST_MPEGTS_API
198 GstMpegtsSCTESIT *gst_mpegts_scte_cancel_new (guint32 event_id);
199
200 GST_MPEGTS_API
201 GstMpegtsSCTESIT *gst_mpegts_scte_splice_in_new (guint32 event_id,
202                                                  GstClockTime splice_time);
203
204 GST_MPEGTS_API
205 GstMpegtsSCTESIT *gst_mpegts_scte_splice_out_new (guint32 event_id,
206                                                   GstClockTime splice_time,
207                                                   GstClockTime duration);
208
209
210 GST_MPEGTS_API
211 GType gst_mpegts_scte_splice_event_get_type (void);
212
213 GST_MPEGTS_API
214 GstMpegtsSCTESpliceEvent *gst_mpegts_scte_splice_event_new (void);
215
216 GST_MPEGTS_API
217 const GstMpegtsSCTESIT *gst_mpegts_section_get_scte_sit (GstMpegtsSection *section);
218
219 GST_MPEGTS_API
220 GstMpegtsSection *gst_mpegts_section_from_scte_sit (GstMpegtsSCTESIT * sit, guint16 pid);
221
222
223 G_END_DECLS
224
225 #endif  /* GST_SCTE_SECTION_H */