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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
24 #include <gst/rtp/gstrtpbuffer.h>
27 #include "gstrtpmp4vdepay.h"
29 GST_DEBUG_CATEGORY_STATIC (rtpmp4vdepay_debug);
30 #define GST_CAT_DEFAULT (rtpmp4vdepay_debug)
32 static GstStaticPadTemplate gst_rtp_mp4v_depay_src_template =
33 GST_STATIC_PAD_TEMPLATE ("src",
36 GST_STATIC_CAPS ("video/mpeg,"
37 "mpegversion=(int) 4," "systemstream=(boolean)false")
40 static GstStaticPadTemplate gst_rtp_mp4v_depay_sink_template =
41 GST_STATIC_PAD_TEMPLATE ("sink",
44 GST_STATIC_CAPS ("application/x-rtp, "
45 "media = (string) \"video\", "
46 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
47 "clock-rate = (int) [1, MAX ], " "encoding-name = (string) \"MP4V-ES\""
48 /* All optional parameters
50 * "profile-level-id=[1,MAX]"
56 #define gst_rtp_mp4v_depay_parent_class parent_class
57 G_DEFINE_TYPE (GstRtpMP4VDepay, gst_rtp_mp4v_depay,
58 GST_TYPE_BASE_RTP_DEPAYLOAD);
60 static void gst_rtp_mp4v_depay_finalize (GObject * object);
62 static gboolean gst_rtp_mp4v_depay_setcaps (GstBaseRTPDepayload * depayload,
64 static GstBuffer *gst_rtp_mp4v_depay_process (GstBaseRTPDepayload * depayload,
67 static GstStateChangeReturn gst_rtp_mp4v_depay_change_state (GstElement *
68 element, GstStateChange transition);
71 gst_rtp_mp4v_depay_class_init (GstRtpMP4VDepayClass * klass)
73 GObjectClass *gobject_class;
74 GstElementClass *gstelement_class;
75 GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
77 gobject_class = (GObjectClass *) klass;
78 gstelement_class = (GstElementClass *) klass;
79 gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
81 gobject_class->finalize = gst_rtp_mp4v_depay_finalize;
83 gstelement_class->change_state = gst_rtp_mp4v_depay_change_state;
85 gstbasertpdepayload_class->process = gst_rtp_mp4v_depay_process;
86 gstbasertpdepayload_class->set_caps = gst_rtp_mp4v_depay_setcaps;
88 gst_element_class_add_pad_template (gstelement_class,
89 gst_static_pad_template_get (&gst_rtp_mp4v_depay_src_template));
90 gst_element_class_add_pad_template (gstelement_class,
91 gst_static_pad_template_get (&gst_rtp_mp4v_depay_sink_template));
93 gst_element_class_set_details_simple (gstelement_class,
94 "RTP MPEG4 video depayloader", "Codec/Depayloader/Network/RTP",
95 "Extracts MPEG4 video from RTP packets (RFC 3016)",
96 "Wim Taymans <wim.taymans@gmail.com>");
98 GST_DEBUG_CATEGORY_INIT (rtpmp4vdepay_debug, "rtpmp4vdepay", 0,
99 "MPEG4 video RTP Depayloader");
103 gst_rtp_mp4v_depay_init (GstRtpMP4VDepay * rtpmp4vdepay)
105 rtpmp4vdepay->adapter = gst_adapter_new ();
109 gst_rtp_mp4v_depay_finalize (GObject * object)
111 GstRtpMP4VDepay *rtpmp4vdepay;
113 rtpmp4vdepay = GST_RTP_MP4V_DEPAY (object);
115 g_object_unref (rtpmp4vdepay->adapter);
116 rtpmp4vdepay->adapter = NULL;
118 G_OBJECT_CLASS (parent_class)->finalize (object);
122 gst_rtp_mp4v_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
124 GstStructure *structure;
130 structure = gst_caps_get_structure (caps, 0);
132 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
133 clock_rate = 90000; /* default */
134 depayload->clock_rate = clock_rate;
136 srccaps = gst_caps_new_simple ("video/mpeg",
137 "mpegversion", G_TYPE_INT, 4,
138 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
140 if ((str = gst_structure_get_string (structure, "config"))) {
143 g_value_init (&v, GST_TYPE_BUFFER);
144 if (gst_value_deserialize (&v, str)) {
147 buffer = gst_value_get_buffer (&v);
148 gst_caps_set_simple (srccaps,
149 "codec_data", GST_TYPE_BUFFER, buffer, NULL);
153 g_warning ("cannot convert config to buffer");
156 res = gst_pad_set_caps (depayload->srcpad, srccaps);
157 gst_caps_unref (srccaps);
163 gst_rtp_mp4v_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
165 GstRtpMP4VDepay *rtpmp4vdepay;
166 GstBuffer *outbuf = NULL;
169 rtpmp4vdepay = GST_RTP_MP4V_DEPAY (depayload);
171 /* flush remaining data on discont */
172 if (GST_BUFFER_IS_DISCONT (buf))
173 gst_adapter_clear (rtpmp4vdepay->adapter);
175 gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp);
176 outbuf = gst_rtp_buffer_get_payload_buffer (&rtp);
177 gst_adapter_push (rtpmp4vdepay->adapter, outbuf);
179 /* if this was the last packet of the VOP, create and push a buffer */
180 if (gst_rtp_buffer_get_marker (&rtp)) {
183 avail = gst_adapter_available (rtpmp4vdepay->adapter);
185 outbuf = gst_adapter_take_buffer (rtpmp4vdepay->adapter, avail);
187 GST_DEBUG ("gst_rtp_mp4v_depay_chain: pushing buffer of size %d",
188 gst_buffer_get_size (outbuf));
191 gst_rtp_buffer_unmap (&rtp);
196 static GstStateChangeReturn
197 gst_rtp_mp4v_depay_change_state (GstElement * element,
198 GstStateChange transition)
200 GstRtpMP4VDepay *rtpmp4vdepay;
201 GstStateChangeReturn ret;
203 rtpmp4vdepay = GST_RTP_MP4V_DEPAY (element);
205 switch (transition) {
206 case GST_STATE_CHANGE_READY_TO_PAUSED:
207 gst_adapter_clear (rtpmp4vdepay->adapter);
213 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
215 switch (transition) {
223 gst_rtp_mp4v_depay_plugin_init (GstPlugin * plugin)
225 return gst_element_register (plugin, "rtpmp4vdepay",
226 GST_RANK_SECONDARY, GST_TYPE_RTP_MP4V_DEPAY);