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 "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 "clock-rate = (int) 90000, " "encoding-name = (string) \"MPA\";"
47 "media = (string) \"audio\", "
48 "payload = (int) " GST_RTP_PAYLOAD_MPA_STRING ", "
49 "clock-rate = (int) 90000")
52 #define gst_rtp_mpa_depay_parent_class parent_class
53 G_DEFINE_TYPE (GstRtpMPADepay, gst_rtp_mpa_depay, GST_TYPE_RTP_BASE_DEPAYLOAD);
55 static gboolean gst_rtp_mpa_depay_setcaps (GstRTPBaseDepayload * depayload,
57 static GstBuffer *gst_rtp_mpa_depay_process (GstRTPBaseDepayload * depayload,
61 gst_rtp_mpa_depay_class_init (GstRtpMPADepayClass * klass)
63 GstElementClass *gstelement_class;
64 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
66 GST_DEBUG_CATEGORY_INIT (rtpmpadepay_debug, "rtpmpadepay", 0,
67 "MPEG Audio RTP Depayloader");
69 gstelement_class = (GstElementClass *) klass;
70 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
72 gst_element_class_add_pad_template (gstelement_class,
73 gst_static_pad_template_get (&gst_rtp_mpa_depay_src_template));
74 gst_element_class_add_pad_template (gstelement_class,
75 gst_static_pad_template_get (&gst_rtp_mpa_depay_sink_template));
77 gst_element_class_set_static_metadata (gstelement_class,
78 "RTP MPEG audio depayloader", "Codec/Depayloader/Network/RTP",
79 "Extracts MPEG audio from RTP packets (RFC 2038)",
80 "Wim Taymans <wim.taymans@gmail.com>");
82 gstrtpbasedepayload_class->set_caps = gst_rtp_mpa_depay_setcaps;
83 gstrtpbasedepayload_class->process = gst_rtp_mpa_depay_process;
87 gst_rtp_mpa_depay_init (GstRtpMPADepay * rtpmpadepay)
92 gst_rtp_mpa_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
94 GstStructure *structure;
99 structure = gst_caps_get_structure (caps, 0);
101 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
103 depayload->clock_rate = clock_rate;
106 gst_caps_new_simple ("audio/mpeg", "mpegversion", G_TYPE_INT, 1, NULL);
107 res = gst_pad_set_caps (depayload->srcpad, outcaps);
108 gst_caps_unref (outcaps);
114 gst_rtp_mpa_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf)
116 GstRtpMPADepay *rtpmpadepay;
118 GstRTPBuffer rtp = { NULL };
126 rtpmpadepay = GST_RTP_MPA_DEPAY (depayload);
128 gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp);
130 payload_len = gst_rtp_buffer_get_payload_len (&rtp);
132 if (payload_len <= 4)
136 payload = gst_rtp_buffer_get_payload (&rtp);
140 * 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
141 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
142 * | MBZ | Frag_offset |
143 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
145 frag_offset = (payload[2] << 8) | payload[3];
148 /* subbuffer skipping the 4 header bytes */
149 outbuf = gst_rtp_buffer_get_payload_subbuffer (&rtp, 4, -1);
150 marker = gst_rtp_buffer_get_marker (&rtp);
153 /* mark start of talkspurt with RESYNC */
154 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_RESYNC);
156 GST_DEBUG_OBJECT (rtpmpadepay,
157 "gst_rtp_mpa_depay_chain: pushing buffer of size %" G_GSIZE_FORMAT "",
158 gst_buffer_get_size (outbuf));
160 gst_rtp_buffer_unmap (&rtp);
162 /* FIXME, we can push half mpeg frames when they are split over multiple
169 GST_ELEMENT_WARNING (rtpmpadepay, STREAM, DECODE,
170 ("Empty Payload."), (NULL));
171 gst_rtp_buffer_unmap (&rtp);
177 gst_rtp_mpa_depay_plugin_init (GstPlugin * plugin)
179 return gst_element_register (plugin, "rtpmpadepay",
180 GST_RANK_SECONDARY, GST_TYPE_RTP_MPA_DEPAY);