Olivier Naudan | b28313f | 2012-04-16 08:10:18 -0400 | [diff] [blame] | 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 |
Sebastian Dröge | e6513c1 | 2013-07-14 12:12:42 +0200 | [diff] [blame] | 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, |
| 17 | * Boston, MA 02110-1301, USA. |
Olivier Naudan | b28313f | 2012-04-16 08:10:18 -0400 | [diff] [blame] | 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> |
Sebastian Dröge | 7e66186 | 2012-05-21 15:50:23 +0200 | [diff] [blame] | 49 | #include <gst/base/gstcollectpads.h> |
Olivier Naudan | b28313f | 2012-04-16 08:10:18 -0400 | [diff] [blame] | 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 | |
Sebastian Dröge | 7e66186 | 2012-05-21 15:50:23 +0200 | [diff] [blame] | 73 | GstCollectPads *collect; /* pads collector */ |
Olivier Naudan | b28313f | 2012-04-16 08:10:18 -0400 | [diff] [blame] | 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 { |
Sebastian Dröge | 7e66186 | 2012-05-21 15:50:23 +0200 | [diff] [blame] | 91 | GstCollectData collect; /* Parent */ |
Olivier Naudan | b28313f | 2012-04-16 08:10:18 -0400 | [diff] [blame] | 92 | |
| 93 | guint8 stream_id; |
| 94 | guint8 stream_id_ext; |
| 95 | PsMuxStream *stream; |
| 96 | |
Sebastian Dröge | dff3649 | 2013-01-08 13:52:02 +0100 | [diff] [blame] | 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; |
Olivier Naudan | b28313f | 2012-04-16 08:10:18 -0400 | [diff] [blame] | 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 | |
| 117 | #define CLOCK_BASE 9LL |
| 118 | #define CLOCK_FREQ (CLOCK_BASE * 10000) |
| 119 | |
Sebastian Dröge | dff3649 | 2013-01-08 13:52:02 +0100 | [diff] [blame] | 120 | #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 Naudan | b28313f | 2012-04-16 08:10:18 -0400 | [diff] [blame] | 124 | |
| 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) |
| 130 | G_END_DECLS |
| 131 | |
| 132 | #endif |