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 "gstrtpmpadepay.h"
29 GST_DEBUG_CATEGORY_STATIC (rtpmpadepay_debug);
30 #define GST_CAT_DEFAULT (rtpmpadepay_debug)
32 static GstStaticPadTemplate gst_rtp_mpa_depay_src_template =
33 GST_STATIC_PAD_TEMPLATE ("src",
36 GST_STATIC_CAPS ("audio/mpeg, " "mpegversion = (int) 1")
39 static GstStaticPadTemplate gst_rtp_mpa_depay_sink_template =
40 GST_STATIC_PAD_TEMPLATE ("sink",
43 GST_STATIC_CAPS ("application/x-rtp, "
44 "media = (string) \"audio\", "
45 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
46 "clock-rate = (int) 90000, " "encoding-name = (string) \"MPA\";"
48 "media = (string) \"audio\", "
49 "payload = (int) " GST_RTP_PAYLOAD_MPA_STRING ", "
50 "clock-rate = (int) 90000")
53 #define gst_rtp_mpa_depay_parent_class parent_class
54 G_DEFINE_TYPE (GstRtpMPADepay, gst_rtp_mpa_depay, GST_TYPE_RTP_BASE_DEPAYLOAD);
56 static gboolean gst_rtp_mpa_depay_setcaps (GstRTPBaseDepayload * depayload,
58 static GstBuffer *gst_rtp_mpa_depay_process (GstRTPBaseDepayload * depayload,
62 gst_rtp_mpa_depay_class_init (GstRtpMPADepayClass * klass)
64 GstElementClass *gstelement_class;
65 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
67 GST_DEBUG_CATEGORY_INIT (rtpmpadepay_debug, "rtpmpadepay", 0,
68 "MPEG Audio RTP Depayloader");
70 gstelement_class = (GstElementClass *) klass;
71 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
73 gst_element_class_add_pad_template (gstelement_class,
74 gst_static_pad_template_get (&gst_rtp_mpa_depay_src_template));
75 gst_element_class_add_pad_template (gstelement_class,
76 gst_static_pad_template_get (&gst_rtp_mpa_depay_sink_template));
78 gst_element_class_set_static_metadata (gstelement_class,
79 "RTP MPEG audio depayloader", "Codec/Depayloader/Network/RTP",
80 "Extracts MPEG audio from RTP packets (RFC 2038)",
81 "Wim Taymans <wim.taymans@gmail.com>");
83 gstrtpbasedepayload_class->set_caps = gst_rtp_mpa_depay_setcaps;
84 gstrtpbasedepayload_class->process = gst_rtp_mpa_depay_process;
88 gst_rtp_mpa_depay_init (GstRtpMPADepay * rtpmpadepay)
93 gst_rtp_mpa_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
95 GstStructure *structure;
100 structure = gst_caps_get_structure (caps, 0);
102 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
104 depayload->clock_rate = clock_rate;
107 gst_caps_new_simple ("audio/mpeg", "mpegversion", G_TYPE_INT, 1, NULL);
108 res = gst_pad_set_caps (depayload->srcpad, outcaps);
109 gst_caps_unref (outcaps);
115 gst_rtp_mpa_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf)
117 GstRtpMPADepay *rtpmpadepay;
119 GstRTPBuffer rtp = { NULL };
127 rtpmpadepay = GST_RTP_MPA_DEPAY (depayload);
129 gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp);
131 payload_len = gst_rtp_buffer_get_payload_len (&rtp);
133 if (payload_len <= 4)
137 payload = gst_rtp_buffer_get_payload (&rtp);
141 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
142 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
143 * | MBZ | Frag_offset |
144 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
146 frag_offset = (payload[2] << 8) | payload[3];
149 /* subbuffer skipping the 4 header bytes */
150 outbuf = gst_rtp_buffer_get_payload_subbuffer (&rtp, 4, -1);
151 marker = gst_rtp_buffer_get_marker (&rtp);
154 /* mark start of talkspurt with discont */
155 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
157 GST_DEBUG_OBJECT (rtpmpadepay,
158 "gst_rtp_mpa_depay_chain: pushing buffer of size %" G_GSIZE_FORMAT "",
159 gst_buffer_get_size (outbuf));
161 gst_rtp_buffer_unmap (&rtp);
163 /* FIXME, we can push half mpeg frames when they are split over multiple
170 GST_ELEMENT_WARNING (rtpmpadepay, STREAM, DECODE,
171 ("Empty Payload."), (NULL));
172 gst_rtp_buffer_unmap (&rtp);
178 gst_rtp_mpa_depay_plugin_init (GstPlugin * plugin)
180 return gst_element_register (plugin, "rtpmpadepay",
181 GST_RANK_SECONDARY, GST_TYPE_RTP_MPA_DEPAY);