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>
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
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/.
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
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.
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.
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., 59 Temple Place - Suite 330,
39 * Boston, MA 02111-1307, USA.
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
59 * Unless otherwise indicated, Source Code is licensed under MIT license.
60 * See further explanation attached in License Statement (distributed in the file
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:
70 * The above copyright notice and this permission notice shall be included in all
71 * copies or substantial portions of the Software.
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
83 #ifndef __MPEGTSMUX_H__
84 #define __MPEGTSMUX_H__
87 #include <gst/base/gstcollectpads.h>
88 #include <gst/base/gstadapter.h>
92 #include <tsmux/tsmux.h>
94 #define GST_TYPE_MPEG_TSMUX (mpegtsmux_get_type())
95 #define GST_MPEG_TSMUX(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_MPEG_TSMUX, MpegTsMux))
97 typedef struct MpegTsMux MpegTsMux;
98 typedef struct MpegTsMuxClass MpegTsMuxClass;
99 typedef struct MpegTsPadData MpegTsPadData;
101 typedef GstBuffer * (*MpegTsPadDataPrepareFunction) (GstBuffer * buf,
102 MpegTsPadData * data, MpegTsMux * mux);
104 typedef void (*MpegTsPadDataFreePrepareDataFunction) (gpointer prepare_data);
111 GstCollectPads *collect;
114 TsMuxProgram **programs;
115 GstStructure *prog_map;
118 GstFlowReturn last_flow_ret;
126 GstClockTime last_ts;
130 gboolean streamheader_sent;
131 GstClockTime pending_key_unit_ts;
132 GstEvent *force_key_unit_event;
135 struct MpegTsMuxClass {
136 GstElementClass parent_class;
139 #define MPEG_TS_PAD_DATA(data) ((MpegTsPadData *)(data))
141 struct MpegTsPadData {
142 GstCollectData collect; /* Parent */
147 GstBuffer *queued_buf; /* Currently pulled buffer */
148 GstClockTime cur_ts; /* Adjusted TS for the pulled buffer */
149 GstClockTime last_ts; /* Most recent valid TS for this stream */
151 GstBuffer * codec_data; /* Optional codec data available in the caps */
153 gpointer prepare_data; /* Opaque data pointer to a structure used by the
156 MpegTsPadDataPrepareFunction prepare_func; /* Handler to prepare input data */
157 MpegTsPadDataFreePrepareDataFunction free_func; /* Handler to free the private data */
161 gint prog_id; /* The program id to which it is attached to (not program pid) */
162 TsMuxProgram *prog; /* The program to which this stream belongs to */
163 GstPadEventFunction eventfunc;
166 GType mpegtsmux_get_type (void);
168 #define CLOCK_BASE 9LL
169 #define CLOCK_FREQ (CLOCK_BASE * 10000) /* 90 kHz PTS clock */
170 #define CLOCK_FREQ_SCR (CLOCK_FREQ * 300) /* 27 MHz SCR clock */
172 #define MPEGTIME_TO_GSTTIME(time) (gst_util_uint64_scale ((time), \
173 GST_MSECOND/10, CLOCK_BASE))
174 #define GSTTIME_TO_MPEGTIME(time) (gst_util_uint64_scale ((time), \
175 CLOCK_BASE, GST_MSECOND/10))
177 /* 27 MHz SCR conversions: */
178 #define MPEG_SYS_TIME_TO_GSTTIME(time) (gst_util_uint64_scale ((time), \
179 GST_USECOND, CLOCK_FREQ_SCR / 1000000))
180 #define GSTTIME_TO_MPEG_SYS_TIME(time) (gst_util_uint64_scale ((time), \
181 CLOCK_FREQ_SCR / 1000000, GST_USECOND))
183 #define NORMAL_TS_PACKET_LENGTH 188
184 #define M2TS_PACKET_LENGTH 192
186 #define MAX_PROG_NUMBER 32
187 #define DEFAULT_PROG_ID 0