• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* 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
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
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>
49 #include <gst/base/gstcollectpads.h>
50 #include <gst/base/gstadapter.h>
51 
52 G_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 
59 typedef struct MpegPsMux MpegPsMux;
60 typedef struct MpegPsMuxClass MpegPsMuxClass;
61 typedef struct MpegPsPadData MpegPsPadData;
62 
63 typedef GstBuffer * (*MpegPsPadDataPrepareFunction) (GstBuffer * buf,
64     MpegPsPadData * data, MpegPsMux * mux);
65 
66 struct MpegPsMux {
67   GstElement parent;
68 
69   GstPad *srcpad;
70 
71   guint video_stream_id;   /* stream id of primary video stream */
72 
73   GstCollectPads *collect; /* pads collector */
74 
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 
86 struct MpegPsMuxClass  {
87   GstElementClass parent_class;
88 };
89 
90 struct MpegPsPadData {
91   GstCollectData collect; /* Parent */
92 
93   guint8 stream_id;
94   guint8 stream_id_ext;
95   PsMuxStream *stream;
96 
97   /* 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;
107 
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 
115 GType mpegpsmux_get_type (void);
116 GST_ELEMENT_REGISTER_DECLARE (mpegpsmux);
117 
118 #define CLOCK_BASE 9LL
119 #define CLOCK_FREQ (CLOCK_BASE * 10000)
120 
121 #define GSTTIME_TO_MPEGTIME(time) \
122     (GST_CLOCK_TIME_IS_VALID(time) ? \
123         gst_util_uint64_scale ((time), CLOCK_BASE, GST_MSECOND/10) : \
124             -1)
125 
126 #define NORMAL_TS_PACKET_LENGTH 188
127 #define M2TS_PACKET_LENGTH      192
128 #define STANDARD_TIME_CLOCK     27000000
129 /*33 bits as 1 ie 0x1ffffffff*/
130 #define TWO_POW_33_MINUS1     ((0xffffffff * 2) - 1)
131 G_END_DECLS
132 
133 #endif
134