2 * Copyright (C) <2005> Wim Taymans <wim.taymans@gmail.com>
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.
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.
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.
24 #include <gst/rtp/gstrtpbuffer.h>
27 #include "gstrtpmp2tdepay.h"
28 #include "gstrtputils.h"
30 /* RtpMP2TDepay signals and args */
37 #define DEFAULT_SKIP_FIRST_BYTES 0
45 static GstStaticPadTemplate gst_rtp_mp2t_depay_src_template =
46 GST_STATIC_PAD_TEMPLATE ("src",
49 GST_STATIC_CAPS ("video/mpegts,"
50 "packetsize=(int)188," "systemstream=(boolean)true")
53 static GstStaticPadTemplate gst_rtp_mp2t_depay_sink_template =
54 GST_STATIC_PAD_TEMPLATE ("sink",
57 GST_STATIC_CAPS ("application/x-rtp, "
58 "media = (string) \"video\", "
59 "clock-rate = (int) [1, MAX ], "
60 "encoding-name = (string) { MP2T, MP2T-ES } ;"
61 /* All optional parameters
63 * "profile-level-id=[1,MAX]"
67 "media = (string) \"video\", "
68 "payload = (int) " GST_RTP_PAYLOAD_MP2T_STRING ", "
69 "clock-rate = (int) [1, MAX ]")
72 G_DEFINE_TYPE (GstRtpMP2TDepay, gst_rtp_mp2t_depay,
73 GST_TYPE_RTP_BASE_DEPAYLOAD);
75 static gboolean gst_rtp_mp2t_depay_setcaps (GstRTPBaseDepayload * depayload,
77 static GstBuffer *gst_rtp_mp2t_depay_process (GstRTPBaseDepayload * depayload,
80 static void gst_rtp_mp2t_depay_set_property (GObject * object, guint prop_id,
81 const GValue * value, GParamSpec * pspec);
82 static void gst_rtp_mp2t_depay_get_property (GObject * object, guint prop_id,
83 GValue * value, GParamSpec * pspec);
86 gst_rtp_mp2t_depay_class_init (GstRtpMP2TDepayClass * klass)
88 GObjectClass *gobject_class;
89 GstElementClass *gstelement_class;
90 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
92 gobject_class = (GObjectClass *) klass;
93 gstelement_class = (GstElementClass *) klass;
94 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
96 gstrtpbasedepayload_class->process_rtp_packet = gst_rtp_mp2t_depay_process;
97 gstrtpbasedepayload_class->set_caps = gst_rtp_mp2t_depay_setcaps;
99 gobject_class->set_property = gst_rtp_mp2t_depay_set_property;
100 gobject_class->get_property = gst_rtp_mp2t_depay_get_property;
102 gst_element_class_add_static_pad_template (gstelement_class,
103 &gst_rtp_mp2t_depay_src_template);
104 gst_element_class_add_static_pad_template (gstelement_class,
105 &gst_rtp_mp2t_depay_sink_template);
107 gst_element_class_set_static_metadata (gstelement_class,
108 "RTP MPEG Transport Stream depayloader", "Codec/Depayloader/Network/RTP",
109 "Extracts MPEG2 TS from RTP packets (RFC 2250)",
110 "Wim Taymans <wim.taymans@gmail.com>, "
111 "Thijs Vermeir <thijs.vermeir@barco.com>");
113 g_object_class_install_property (gobject_class, PROP_SKIP_FIRST_BYTES,
114 g_param_spec_uint ("skip-first-bytes",
116 "The amount of bytes that need to be skipped at the beginning of the payload",
117 0, G_MAXUINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
122 gst_rtp_mp2t_depay_init (GstRtpMP2TDepay * rtpmp2tdepay)
124 rtpmp2tdepay->skip_first_bytes = DEFAULT_SKIP_FIRST_BYTES;
128 gst_rtp_mp2t_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
131 GstStructure *structure;
135 structure = gst_caps_get_structure (caps, 0);
136 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
137 clock_rate = 90000; /* default */
138 depayload->clock_rate = clock_rate;
140 srccaps = gst_caps_new_simple ("video/mpegts",
141 "packetsize", G_TYPE_INT, 188,
142 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
143 res = gst_pad_set_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (depayload), srccaps);
144 gst_caps_unref (srccaps);
150 gst_rtp_mp2t_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp)
152 GstRtpMP2TDepay *rtpmp2tdepay;
154 gint payload_len, leftover;
156 rtpmp2tdepay = GST_RTP_MP2T_DEPAY (depayload);
158 payload_len = gst_rtp_buffer_get_payload_len (rtp);
160 if (G_UNLIKELY (payload_len <= rtpmp2tdepay->skip_first_bytes))
163 payload_len -= rtpmp2tdepay->skip_first_bytes;
167 * 2. Encapsulation of MPEG System and Transport Streams
169 * For MPEG2 Transport Streams the RTP payload will contain an integral
170 * number of MPEG transport packets.
172 leftover = payload_len % 188;
173 if (G_UNLIKELY (leftover)) {
174 GST_WARNING ("We don't have an integral number of buffers (leftover: %d)",
177 payload_len -= leftover;
181 gst_rtp_buffer_get_payload_subbuffer (rtp,
182 rtpmp2tdepay->skip_first_bytes, payload_len);
185 GST_DEBUG ("gst_rtp_mp2t_depay_chain: pushing buffer of size %"
186 G_GSIZE_FORMAT, gst_buffer_get_size (outbuf));
188 gst_rtp_drop_meta (GST_ELEMENT_CAST (depayload), outbuf, 0);
196 GST_ELEMENT_WARNING (rtpmp2tdepay, STREAM, DECODE,
197 (NULL), ("Packet was empty"));
203 gst_rtp_mp2t_depay_set_property (GObject * object, guint prop_id,
204 const GValue * value, GParamSpec * pspec)
206 GstRtpMP2TDepay *rtpmp2tdepay;
208 rtpmp2tdepay = GST_RTP_MP2T_DEPAY (object);
211 case PROP_SKIP_FIRST_BYTES:
212 rtpmp2tdepay->skip_first_bytes = g_value_get_uint (value);
215 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
221 gst_rtp_mp2t_depay_get_property (GObject * object, guint prop_id,
222 GValue * value, GParamSpec * pspec)
224 GstRtpMP2TDepay *rtpmp2tdepay;
226 rtpmp2tdepay = GST_RTP_MP2T_DEPAY (object);
229 case PROP_SKIP_FIRST_BYTES:
230 g_value_set_uint (value, rtpmp2tdepay->skip_first_bytes);
233 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
239 gst_rtp_mp2t_depay_plugin_init (GstPlugin * plugin)
241 return gst_element_register (plugin, "rtpmp2tdepay",
242 GST_RANK_SECONDARY, GST_TYPE_RTP_MP2T_DEPAY);