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>
25 #include <gst/video/video.h>
28 #include "gstrtpmp4vdepay.h"
29 #include "gstrtputils.h"
31 GST_DEBUG_CATEGORY_STATIC (rtpmp4vdepay_debug);
32 #define GST_CAT_DEFAULT (rtpmp4vdepay_debug)
34 static GstStaticPadTemplate gst_rtp_mp4v_depay_src_template =
35 GST_STATIC_PAD_TEMPLATE ("src",
38 GST_STATIC_CAPS ("video/mpeg,"
39 "mpegversion=(int) 4," "systemstream=(boolean)false")
42 static GstStaticPadTemplate gst_rtp_mp4v_depay_sink_template =
43 GST_STATIC_PAD_TEMPLATE ("sink",
46 GST_STATIC_CAPS ("application/x-rtp, "
47 "media = (string) \"video\", "
48 "clock-rate = (int) [1, MAX ], " "encoding-name = (string) \"MP4V-ES\""
49 /* All optional parameters
51 * "profile-level-id=[1,MAX]"
57 #define gst_rtp_mp4v_depay_parent_class parent_class
58 G_DEFINE_TYPE (GstRtpMP4VDepay, gst_rtp_mp4v_depay,
59 GST_TYPE_RTP_BASE_DEPAYLOAD);
61 static void gst_rtp_mp4v_depay_finalize (GObject * object);
63 static gboolean gst_rtp_mp4v_depay_setcaps (GstRTPBaseDepayload * depayload,
65 static GstBuffer *gst_rtp_mp4v_depay_process (GstRTPBaseDepayload * depayload,
68 static GstStateChangeReturn gst_rtp_mp4v_depay_change_state (GstElement *
69 element, GstStateChange transition);
72 gst_rtp_mp4v_depay_class_init (GstRtpMP4VDepayClass * klass)
74 GObjectClass *gobject_class;
75 GstElementClass *gstelement_class;
76 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
78 gobject_class = (GObjectClass *) klass;
79 gstelement_class = (GstElementClass *) klass;
80 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
82 gobject_class->finalize = gst_rtp_mp4v_depay_finalize;
84 gstelement_class->change_state = gst_rtp_mp4v_depay_change_state;
86 gstrtpbasedepayload_class->process_rtp_packet = gst_rtp_mp4v_depay_process;
87 gstrtpbasedepayload_class->set_caps = gst_rtp_mp4v_depay_setcaps;
89 gst_element_class_add_static_pad_template (gstelement_class,
90 &gst_rtp_mp4v_depay_src_template);
91 gst_element_class_add_static_pad_template (gstelement_class,
92 &gst_rtp_mp4v_depay_sink_template);
94 gst_element_class_set_static_metadata (gstelement_class,
95 "RTP MPEG4 video depayloader", "Codec/Depayloader/Network/RTP",
96 "Extracts MPEG4 video from RTP packets (RFC 3016)",
97 "Wim Taymans <wim.taymans@gmail.com>");
99 GST_DEBUG_CATEGORY_INIT (rtpmp4vdepay_debug, "rtpmp4vdepay", 0,
100 "MPEG4 video RTP Depayloader");
104 gst_rtp_mp4v_depay_init (GstRtpMP4VDepay * rtpmp4vdepay)
106 rtpmp4vdepay->adapter = gst_adapter_new ();
110 gst_rtp_mp4v_depay_finalize (GObject * object)
112 GstRtpMP4VDepay *rtpmp4vdepay;
114 rtpmp4vdepay = GST_RTP_MP4V_DEPAY (object);
116 g_object_unref (rtpmp4vdepay->adapter);
117 rtpmp4vdepay->adapter = NULL;
119 G_OBJECT_CLASS (parent_class)->finalize (object);
123 gst_rtp_mp4v_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
125 GstStructure *structure;
131 structure = gst_caps_get_structure (caps, 0);
133 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
134 clock_rate = 90000; /* default */
135 depayload->clock_rate = clock_rate;
137 srccaps = gst_caps_new_simple ("video/mpeg",
138 "mpegversion", G_TYPE_INT, 4,
139 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
141 if ((str = gst_structure_get_string (structure, "config"))) {
144 g_value_init (&v, GST_TYPE_BUFFER);
145 if (gst_value_deserialize (&v, str)) {
148 buffer = gst_value_get_buffer (&v);
149 gst_caps_set_simple (srccaps,
150 "codec_data", GST_TYPE_BUFFER, buffer, NULL);
154 g_warning ("cannot convert config to buffer");
157 res = gst_pad_set_caps (depayload->srcpad, srccaps);
158 gst_caps_unref (srccaps);
164 gst_rtp_mp4v_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp)
166 GstRtpMP4VDepay *rtpmp4vdepay;
167 GstBuffer *pbuf, *outbuf = NULL;
170 rtpmp4vdepay = GST_RTP_MP4V_DEPAY (depayload);
172 /* flush remaining data on discont */
173 if (GST_BUFFER_IS_DISCONT (rtp->buffer))
174 gst_adapter_clear (rtpmp4vdepay->adapter);
176 pbuf = gst_rtp_buffer_get_payload_buffer (rtp);
177 marker = gst_rtp_buffer_get_marker (rtp);
179 gst_adapter_push (rtpmp4vdepay->adapter, pbuf);
181 /* if this was the last packet of the VOP, create and push a buffer */
185 avail = gst_adapter_available (rtpmp4vdepay->adapter);
186 outbuf = gst_adapter_take_buffer (rtpmp4vdepay->adapter, avail);
188 GST_DEBUG ("gst_rtp_mp4v_depay_chain: pushing buffer of size %"
189 G_GSIZE_FORMAT, gst_buffer_get_size (outbuf));
190 gst_rtp_drop_non_video_meta (rtpmp4vdepay, outbuf);
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);