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 GST_BOILERPLATE (GstRtpMPADepay, gst_rtp_mpa_depay, GstBaseRTPDepayload,
54 GST_TYPE_BASE_RTP_DEPAYLOAD);
56 static gboolean gst_rtp_mpa_depay_setcaps (GstBaseRTPDepayload * depayload,
58 static GstBuffer *gst_rtp_mpa_depay_process (GstBaseRTPDepayload * depayload,
62 gst_rtp_mpa_depay_base_init (gpointer klass)
64 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
66 gst_element_class_add_static_pad_template (element_class,
67 &gst_rtp_mpa_depay_src_template);
68 gst_element_class_add_static_pad_template (element_class,
69 &gst_rtp_mpa_depay_sink_template);
71 gst_element_class_set_details_simple (element_class,
72 "RTP MPEG audio depayloader", "Codec/Depayloader/Network/RTP",
73 "Extracts MPEG audio from RTP packets (RFC 2038)",
74 "Wim Taymans <wim.taymans@gmail.com>");
78 gst_rtp_mpa_depay_class_init (GstRtpMPADepayClass * klass)
80 GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
82 gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
84 gstbasertpdepayload_class->set_caps = gst_rtp_mpa_depay_setcaps;
85 gstbasertpdepayload_class->process = gst_rtp_mpa_depay_process;
87 GST_DEBUG_CATEGORY_INIT (rtpmpadepay_debug, "rtpmpadepay", 0,
88 "MPEG Audio RTP Depayloader");
92 gst_rtp_mpa_depay_init (GstRtpMPADepay * rtpmpadepay,
93 GstRtpMPADepayClass * klass)
95 /* needed because of GST_BOILERPLATE */
99 gst_rtp_mpa_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
101 GstStructure *structure;
106 structure = gst_caps_get_structure (caps, 0);
108 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
110 depayload->clock_rate = clock_rate;
113 gst_caps_new_simple ("audio/mpeg", "mpegversion", G_TYPE_INT, 1, NULL);
114 res = gst_pad_set_caps (depayload->srcpad, outcaps);
115 gst_caps_unref (outcaps);
121 gst_rtp_mpa_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
123 GstRtpMPADepay *rtpmpadepay;
126 rtpmpadepay = GST_RTP_MPA_DEPAY (depayload);
132 payload_len = gst_rtp_buffer_get_payload_len (buf);
134 if (payload_len <= 4)
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]; */
147 /* subbuffer skipping the 4 header bytes */
148 outbuf = gst_rtp_buffer_get_payload_subbuffer (buf, 4, -1);
149 marker = gst_rtp_buffer_get_marker (buf);
152 /* mark start of talkspurt with discont */
153 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
155 GST_DEBUG_OBJECT (rtpmpadepay,
156 "gst_rtp_mpa_depay_chain: pushing buffer of size %d",
157 GST_BUFFER_SIZE (outbuf));
159 /* FIXME, we can push half mpeg frames when they are split over multiple
169 GST_ELEMENT_WARNING (rtpmpadepay, STREAM, DECODE,
170 ("Empty Payload."), (NULL));
176 gst_rtp_mpa_depay_plugin_init (GstPlugin * plugin)
178 return gst_element_register (plugin, "rtpmpadepay",
179 GST_RANK_SECONDARY, GST_TYPE_RTP_MPA_DEPAY);