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/audio/audio.h>
28 #include "gstrtpmpadepay.h"
29 #include "gstrtputils.h"
31 GST_DEBUG_CATEGORY_STATIC (rtpmpadepay_debug);
32 #define GST_CAT_DEFAULT (rtpmpadepay_debug)
34 static GstStaticPadTemplate gst_rtp_mpa_depay_src_template =
35 GST_STATIC_PAD_TEMPLATE ("src",
38 GST_STATIC_CAPS ("audio/mpeg, " "mpegversion = (int) 1")
41 static GstStaticPadTemplate gst_rtp_mpa_depay_sink_template =
42 GST_STATIC_PAD_TEMPLATE ("sink",
45 GST_STATIC_CAPS ("application/x-rtp, "
46 "media = (string) \"audio\", "
47 "payload = (int) " GST_RTP_PAYLOAD_MPA_STRING ", "
48 "clock-rate = (int) 90000 ;"
50 "media = (string) \"audio\", "
51 "encoding-name = (string) \"MPA\", clock-rate = (int) [1, MAX]")
54 #define gst_rtp_mpa_depay_parent_class parent_class
55 G_DEFINE_TYPE (GstRtpMPADepay, gst_rtp_mpa_depay, GST_TYPE_RTP_BASE_DEPAYLOAD);
57 static gboolean gst_rtp_mpa_depay_setcaps (GstRTPBaseDepayload * depayload,
59 static GstBuffer *gst_rtp_mpa_depay_process (GstRTPBaseDepayload * depayload,
63 gst_rtp_mpa_depay_class_init (GstRtpMPADepayClass * klass)
65 GstElementClass *gstelement_class;
66 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
68 GST_DEBUG_CATEGORY_INIT (rtpmpadepay_debug, "rtpmpadepay", 0,
69 "MPEG Audio RTP Depayloader");
71 gstelement_class = (GstElementClass *) klass;
72 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
74 gst_element_class_add_static_pad_template (gstelement_class,
75 &gst_rtp_mpa_depay_src_template);
76 gst_element_class_add_static_pad_template (gstelement_class,
77 &gst_rtp_mpa_depay_sink_template);
79 gst_element_class_set_static_metadata (gstelement_class,
80 "RTP MPEG audio depayloader", "Codec/Depayloader/Network/RTP",
81 "Extracts MPEG audio from RTP packets (RFC 2038)",
82 "Wim Taymans <wim.taymans@gmail.com>");
84 gstrtpbasedepayload_class->set_caps = gst_rtp_mpa_depay_setcaps;
85 gstrtpbasedepayload_class->process_rtp_packet = gst_rtp_mpa_depay_process;
89 gst_rtp_mpa_depay_init (GstRtpMPADepay * rtpmpadepay)
94 gst_rtp_mpa_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
96 GstStructure *structure;
101 structure = gst_caps_get_structure (caps, 0);
103 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
105 depayload->clock_rate = clock_rate;
108 gst_caps_new_simple ("audio/mpeg", "mpegversion", G_TYPE_INT, 1, NULL);
109 res = gst_pad_set_caps (depayload->srcpad, outcaps);
110 gst_caps_unref (outcaps);
116 gst_rtp_mpa_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp)
118 GstRtpMPADepay *rtpmpadepay;
127 rtpmpadepay = GST_RTP_MPA_DEPAY (depayload);
129 payload_len = gst_rtp_buffer_get_payload_len (rtp);
131 if (payload_len <= 4)
135 payload = gst_rtp_buffer_get_payload (&rtp);
139 * 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
140 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
141 * | MBZ | Frag_offset |
142 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
144 frag_offset = (payload[2] << 8) | payload[3];
147 /* subbuffer skipping the 4 header bytes */
148 outbuf = gst_rtp_buffer_get_payload_subbuffer (rtp, 4, -1);
149 marker = gst_rtp_buffer_get_marker (rtp);
152 /* mark start of talkspurt with RESYNC */
153 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_RESYNC);
155 GST_DEBUG_OBJECT (rtpmpadepay,
156 "gst_rtp_mpa_depay_chain: pushing buffer of size %" G_GSIZE_FORMAT "",
157 gst_buffer_get_size (outbuf));
160 gst_rtp_drop_meta (GST_ELEMENT_CAST (rtpmpadepay), outbuf,
161 g_quark_from_static_string (GST_META_TAG_AUDIO_STR));
164 /* FIXME, we can push half mpeg frames when they are split over multiple
171 GST_ELEMENT_WARNING (rtpmpadepay, STREAM, DECODE,
172 ("Empty Payload."), (NULL));
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);