blob: c04edf4ed9d11287eb7205d60caf493b9c076cf7 [file] [log] [blame]
Olivier Naudanb28313f2012-04-16 08:10:18 -04001/* MPEG-PS muxer plugin for GStreamer
2 * Copyright 2008 Lin YANG <oxcsnicho@gmail.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
Sebastian Drögee6513c12013-07-14 12:12:42 +020016 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
Olivier Naudanb28313f2012-04-16 08:10:18 -040018 */
19/*
20 * Unless otherwise indicated, Source Code is licensed under MIT license.
21 * See further explanation attached in License Statement (distributed in the file
22 * LICENSE).
23 *
24 * Permission is hereby granted, free of charge, to any person obtaining a copy of
25 * this software and associated documentation files (the "Software"), to deal in
26 * the Software without restriction, including without limitation the rights to
27 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
28 * of the Software, and to permit persons to whom the Software is furnished to do
29 * so, subject to the following conditions:
30 *
31 * The above copyright notice and this permission notice shall be included in all
32 * copies or substantial portions of the Software.
33 *
34 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40 * SOFTWARE.
41 */
42
43
44
45#ifndef __MPEGPSMUX_H__
46#define __MPEGPSMUX_H__
47
48#include <gst/gst.h>
Sebastian Dröge7e661862012-05-21 15:50:23 +020049#include <gst/base/gstcollectpads.h>
Olivier Naudanb28313f2012-04-16 08:10:18 -040050#include <gst/base/gstadapter.h>
51
52G_BEGIN_DECLS
53
54#include "psmux.h"
55
56#define GST_TYPE_MPEG_PSMUX (mpegpsmux_get_type())
57#define GST_MPEG_PSMUX(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_MPEG_PSMUX, MpegPsMux))
58
59typedef struct MpegPsMux MpegPsMux;
60typedef struct MpegPsMuxClass MpegPsMuxClass;
61typedef struct MpegPsPadData MpegPsPadData;
62
63typedef GstBuffer * (*MpegPsPadDataPrepareFunction) (GstBuffer * buf,
64 MpegPsPadData * data, MpegPsMux * mux);
65
66struct MpegPsMux {
67 GstElement parent;
68
69 GstPad *srcpad;
70
71 guint video_stream_id; /* stream id of primary video stream */
72
Sebastian Dröge7e661862012-05-21 15:50:23 +020073 GstCollectPads *collect; /* pads collector */
Olivier Naudanb28313f2012-04-16 08:10:18 -040074
75 PsMux *psmux;
76
77 gboolean first;
78 GstFlowReturn last_flow_ret;
79
80 GstClockTime last_ts;
81
82 GstBufferList *gop_list;
83 gboolean aggregate_gops;
84};
85
86struct MpegPsMuxClass {
87 GstElementClass parent_class;
88};
89
90struct MpegPsPadData {
Sebastian Dröge7e661862012-05-21 15:50:23 +020091 GstCollectData collect; /* Parent */
Olivier Naudanb28313f2012-04-16 08:10:18 -040092
93 guint8 stream_id;
94 guint8 stream_id_ext;
95 PsMuxStream *stream;
96
Sebastian Drögedff36492013-01-08 13:52:02 +010097 /* Currently pulled buffer */
98 struct {
99 GstBuffer *buf;
100 GstClockTime ts; /* adjusted TS = MIN (DTS, PTS) for the pulled buffer */
101 GstClockTime pts; /* adjusted PTS (running time) */
102 GstClockTime dts; /* adjusted DTS (running time) */
103 } queued;
104
105 /* Most recent valid TS (DTS or PTS) for this stream */
106 GstClockTime last_ts;
Olivier Naudanb28313f2012-04-16 08:10:18 -0400107
108 GstBuffer * codec_data; /* Optional codec data available in the caps */
109
110 MpegPsPadDataPrepareFunction prepare_func; /* Handler to prepare input data */
111
112 gboolean eos;
113};
114
115GType mpegpsmux_get_type (void);
116
117#define CLOCK_BASE 9LL
118#define CLOCK_FREQ (CLOCK_BASE * 10000)
119
Sebastian Drögedff36492013-01-08 13:52:02 +0100120#define GSTTIME_TO_MPEGTIME(time) \
121 (GST_CLOCK_TIME_IS_VALID(time) ? \
122 gst_util_uint64_scale ((time), CLOCK_BASE, GST_MSECOND/10) : \
123 -1)
Olivier Naudanb28313f2012-04-16 08:10:18 -0400124
125#define NORMAL_TS_PACKET_LENGTH 188
126#define M2TS_PACKET_LENGTH 192
127#define STANDARD_TIME_CLOCK 27000000
128/*33 bits as 1 ie 0x1ffffffff*/
129#define TWO_POW_33_MINUS1 ((0xffffffff * 2) - 1)
130G_END_DECLS
131
132#endif