transcodebin: Create the decodebin in _init
[platform/upstream/gstreamer.git] / gst / mpegtsmux / gstbasetsmux.h
1 /*
2  * Copyright 2006, 2007, 2008, 2009, 2010 Fluendo S.A.
3  *  Authors: Jan Schmidt <jan@fluendo.com>
4  *           Kapil Agrawal <kapil@fluendo.com>
5  *           Julien Moutte <julien@fluendo.com>
6  *
7  * This library is licensed under 4 different licenses and you
8  * can choose to use it under the terms of any one of them. The
9  * four licenses are the MPL 1.1, the LGPL, the GPL and the MIT
10  * license.
11  *
12  * MPL:
13  *
14  * The contents of this file are subject to the Mozilla Public License
15  * Version 1.1 (the "License"); you may not use this file except in
16  * compliance with the License. You may obtain a copy of the License at
17  * http://www.mozilla.org/MPL/.
18  *
19  * Software distributed under the License is distributed on an "AS IS"
20  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
21  * License for the specific language governing rights and limitations
22  * under the License.
23  *
24  * LGPL:
25  *
26  * This library is free software; you can redistribute it and/or
27  * modify it under the terms of the GNU Library General Public
28  * License as published by the Free Software Foundation; either
29  * version 2 of the License, or (at your option) any later version.
30  *
31  * This library is distributed in the hope that it will be useful,
32  * but WITHOUT ANY WARRANTY; without even the implied warranty of
33  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
34  * Library General Public License for more details.
35  *
36  * You should have received a copy of the GNU Library General Public
37  * License along with this library; if not, write to the
38  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
39  * Boston, MA 02110-1301, USA.
40  *
41  * GPL:
42  *
43  * This program is free software; you can redistribute it and/or modify
44  * it under the terms of the GNU General Public License as published by
45  * the Free Software Foundation; either version 2 of the License, or
46  * (at your option) any later version.
47  *
48  * This program is distributed in the hope that it will be useful,
49  * but WITHOUT ANY WARRANTY; without even the implied warranty of
50  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
51  * GNU General Public License for more details.
52  *
53  * You should have received a copy of the GNU General Public License
54  * along with this program; if not, write to the Free Software
55  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
56  *
57  * MIT:
58  *
59  * Unless otherwise indicated, Source Code is licensed under MIT license.
60  * See further explanation attached in License Statement (distributed in the file
61  * LICENSE).
62  *
63  * Permission is hereby granted, free of charge, to any person obtaining a copy of
64  * this software and associated documentation files (the "Software"), to deal in
65  * the Software without restriction, including without limitation the rights to
66  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
67  * of the Software, and to permit persons to whom the Software is furnished to do
68  * so, subject to the following conditions:
69  *
70  * The above copyright notice and this permission notice shall be included in all
71  * copies or substantial portions of the Software.
72  *
73  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
74  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
75  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
76  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
77  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
78  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
79  * SOFTWARE.
80  *
81  */
82
83 #ifndef __BASETSMUX_H__
84 #define __BASETSMUX_H__
85
86 #include <gst/gst.h>
87 #include <gst/base/gstcollectpads.h>
88 #include <gst/base/gstadapter.h>
89 #include <gst/base/gstaggregator.h>
90
91 G_BEGIN_DECLS
92
93 #include "tsmux/tsmux.h"
94
95 #define GST_TYPE_BASE_TS_MUX_PAD (gst_base_ts_mux_pad_get_type())
96 #define GST_BASE_TS_MUX_PAD(obj) \
97         (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BASE_TS_MUX_PAD, GstBaseTsMuxPad))
98 #define GST_BASE_TS_MUX_PAD_CAST(obj) ((GstBaseTsMuxPad *)(obj))
99 #define GST_BASE_TS_MUX_PAD_CLASS(klass) \
100         (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_BASE_TS_MUX_PAD, GstBaseTsMuxPadClass))
101 #define GST_IS_BASE_TS_MUX_PAD(obj) \
102         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BASE_TS_MUX_PAD))
103 #define GST_IS_BASE_TS_MUX_PAD_CLASS(klass) \
104         (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_TS_MUX_PAD))
105 #define GST_BASE_TS_MUX_PAD_GET_CLASS(obj) \
106         (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_BASE_TS_MUX_PAD,GstBaseTsMuxPadClass))
107
108 typedef struct _GstBaseTsMuxPad GstBaseTsMuxPad;
109 typedef struct _GstBaseTsMuxPadClass GstBaseTsMuxPadClass;
110 typedef struct _GstBaseTsMuxPadPrivate GstBaseTsMuxPadPrivate;
111 typedef struct GstBaseTsMux GstBaseTsMux;
112 typedef struct GstBaseTsMuxClass GstBaseTsMuxClass;
113 typedef struct GstBaseTsPadData GstBaseTsPadData;
114
115 typedef GstBuffer * (*GstBaseTsMuxPadPrepareFunction) (GstBuffer * buf,
116     GstBaseTsMuxPad * data, GstBaseTsMux * mux);
117
118 typedef void (*GstBaseTsMuxPadFreePrepareDataFunction) (gpointer prepare_data);
119
120 struct _GstBaseTsMuxPad
121 {
122   GstAggregatorPad              parent;
123
124   gint pid;
125   TsMuxStream *stream;
126
127   /* most recent DTS */
128   gint64 dts;
129
130   /* optional codec data available in the caps */
131   GstBuffer *codec_data;
132
133   /* Opaque data pointer to a structure used by the prepare function */
134   gpointer prepare_data;
135
136   /* handler to prepare input data */
137   GstBaseTsMuxPadPrepareFunction prepare_func;
138   /* handler to free the private data */
139   GstBaseTsMuxPadFreePrepareDataFunction free_func;
140
141   /* program id to which it is attached to (not program pid) */
142   gint prog_id;
143   /* program this stream belongs to */
144   TsMuxProgram *prog;
145
146   gchar *language;
147 };
148
149 struct _GstBaseTsMuxPadClass
150 {
151   GstAggregatorPadClass parent_class;
152 };
153
154 GType gst_base_ts_mux_pad_get_type   (void);
155
156 #define GST_TYPE_BASE_TS_MUX  (gst_base_ts_mux_get_type())
157 #define GST_BASE_TS_MUX(obj)  (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_BASE_TS_MUX, GstBaseTsMux))
158 #define GST_BASE_TS_MUX_CLASS(klass)            (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_BASE_TS_MUX, GstBaseTsMuxClass))
159 #define GST_BASE_TS_MUX_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_BASE_TS_MUX,GstBaseTsMuxClass))
160
161 #define GST_BASE_TS_MUX_NORMAL_PACKET_LENGTH 188
162
163 struct GstBaseTsMux {
164   GstAggregator parent;
165
166   TsMux *tsmux;
167   GHashTable *programs;
168
169   /* properties */
170   GstStructure *prog_map;
171   guint pat_interval;
172   guint pmt_interval;
173   gint alignment;
174   guint si_interval;
175   guint64 bitrate;
176   guint pcr_interval;
177   guint scte35_pid;
178   guint scte35_null_interval;
179
180   /* state */
181   gboolean first;
182   GstClockTime pending_key_unit_ts;
183   GstEvent *force_key_unit_event;
184   GstMpegtsSection *pending_scte35_section;
185
186   /* write callback handling/state */
187   GstFlowReturn last_flow_ret;
188   GQueue streamheader;
189   gboolean streamheader_sent;
190   gboolean is_delta;
191   gboolean is_header;
192   GstClockTime last_ts;
193
194   gsize packet_size;
195   gsize automatic_alignment;
196
197   /* output buffer aggregation */
198   GstAdapter *out_adapter;
199   GstBuffer *out_buffer;
200 };
201
202 /**
203  * GstBaseTsMuxClass:
204  * @create_ts_mux: Optional.
205  *                 Called in order to create the #TsMux object.
206  * @handle_media_type: Optional.
207  *                 Called in order to determine the stream-type for a given
208  *                 @media_type (eg. video/x-h264).
209  * @allocate_packet: Optional.
210  *                 Called when the underlying #TsMux object needs a packet
211  *                 to write into.
212  * @output_packet: Optional.
213  *                 Called when the underlying #TsMux object has a packet
214  *                 ready to output.
215  * @reset:         Optional.
216  *                 Called when the subclass needs to reset.
217  * @drain:         Optional.
218  *                 Called at EOS, if the subclass has data it needs to drain.
219  */
220 struct GstBaseTsMuxClass {
221   GstAggregatorClass parent_class;
222
223   TsMux *   (*create_ts_mux) (GstBaseTsMux *mux);
224   guint     (*handle_media_type) (GstBaseTsMux *mux, const gchar *media_type, GstBaseTsMuxPad * pad);
225   void      (*allocate_packet) (GstBaseTsMux *mux, GstBuffer **buffer);
226   gboolean  (*output_packet) (GstBaseTsMux *mux, GstBuffer *buffer, gint64 new_pcr);
227   void      (*reset) (GstBaseTsMux *mux);
228   gboolean  (*drain) (GstBaseTsMux *mux);
229 };
230
231 void gst_base_ts_mux_set_packet_size (GstBaseTsMux *mux, gsize size);
232 void gst_base_ts_mux_set_automatic_alignment (GstBaseTsMux *mux, gsize alignment);
233
234 typedef GstBuffer * (*GstBaseTsPadDataPrepareFunction) (GstBuffer * buf,
235     GstBaseTsPadData * data, GstBaseTsMux * mux);
236
237 typedef void (*GstBaseTsPadDataFreePrepareDataFunction) (gpointer prepare_data);
238
239 struct GstBaseTsPadData {
240   /* parent */
241   GstCollectData collect;
242
243   gint pid;
244   TsMuxStream *stream;
245
246   /* most recent DTS */
247   gint64 dts;
248
249   /* optional codec data available in the caps */
250   GstBuffer *codec_data;
251
252   /* Opaque data pointer to a structure used by the prepare function */
253   gpointer prepare_data;
254
255   /* handler to prepare input data */
256   GstBaseTsPadDataPrepareFunction prepare_func;
257   /* handler to free the private data */
258   GstBaseTsPadDataFreePrepareDataFunction free_func;
259
260   /* program id to which it is attached to (not program pid) */
261   gint prog_id;
262   /* program this stream belongs to */
263   TsMuxProgram *prog;
264
265   gchar *language;
266 };
267
268 GType gst_base_ts_mux_get_type (void);
269
270 G_END_DECLS
271
272 #endif