2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2005> Edgard Lima <edgard.lima@gmail.com>
4 * Copyright (C) <2005> Zeeshan Ali <zeenix@gmail.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
27 #include <gst/rtp/gstrtpbuffer.h>
28 #include <gst/audio/audio.h>
29 #include "gstrtpelements.h"
30 #include "gstrtppcmudepay.h"
31 #include "gstrtputils.h"
33 /* RtpPcmuDepay signals and args */
45 static GstStaticPadTemplate gst_rtp_pcmu_depay_sink_template =
46 GST_STATIC_PAD_TEMPLATE ("sink",
49 GST_STATIC_CAPS ("application/x-rtp, "
50 "media = (string) \"audio\", "
51 "payload = (int) " GST_RTP_PAYLOAD_PCMU_STRING ", "
52 "clock-rate = (int) 8000; "
54 "media = (string) \"audio\", "
55 "encoding-name = (string) \"PCMU\", clock-rate = (int) [1, MAX ]")
58 static GstStaticPadTemplate gst_rtp_pcmu_depay_src_template =
59 GST_STATIC_PAD_TEMPLATE ("src",
62 GST_STATIC_CAPS ("audio/x-mulaw, "
63 "channels = (int) 1, rate = (int) [1, MAX ]")
66 static GstBuffer *gst_rtp_pcmu_depay_process (GstRTPBaseDepayload * depayload,
68 static gboolean gst_rtp_pcmu_depay_setcaps (GstRTPBaseDepayload * depayload,
71 #define gst_rtp_pcmu_depay_parent_class parent_class
72 G_DEFINE_TYPE (GstRtpPcmuDepay, gst_rtp_pcmu_depay,
73 GST_TYPE_RTP_BASE_DEPAYLOAD);
74 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (rtppcmudepay, "rtppcmudepay",
75 GST_RANK_SECONDARY, GST_TYPE_RTP_PCMU_DEPAY, rtp_element_init (plugin));
78 gst_rtp_pcmu_depay_class_init (GstRtpPcmuDepayClass * klass)
80 GstElementClass *gstelement_class;
81 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
83 gstelement_class = (GstElementClass *) klass;
84 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
86 gst_element_class_add_static_pad_template (gstelement_class,
87 &gst_rtp_pcmu_depay_src_template);
88 gst_element_class_add_static_pad_template (gstelement_class,
89 &gst_rtp_pcmu_depay_sink_template);
91 gst_element_class_set_static_metadata (gstelement_class,
92 "RTP PCMU depayloader", "Codec/Depayloader/Network/RTP",
93 "Extracts PCMU audio from RTP packets",
94 "Edgard Lima <edgard.lima@gmail.com>, Zeeshan Ali <zeenix@gmail.com>");
96 gstrtpbasedepayload_class->process_rtp_packet = gst_rtp_pcmu_depay_process;
97 gstrtpbasedepayload_class->set_caps = gst_rtp_pcmu_depay_setcaps;
101 gst_rtp_pcmu_depay_init (GstRtpPcmuDepay * rtppcmudepay)
103 GstRTPBaseDepayload *depayload;
105 depayload = GST_RTP_BASE_DEPAYLOAD (rtppcmudepay);
107 gst_pad_use_fixed_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (depayload));
111 gst_rtp_pcmu_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
114 GstStructure *structure;
118 structure = gst_caps_get_structure (caps, 0);
120 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
121 clock_rate = 8000; /* default */
122 depayload->clock_rate = clock_rate;
124 srccaps = gst_caps_new_simple ("audio/x-mulaw",
125 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, clock_rate, NULL);
126 ret = gst_pad_set_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (depayload), srccaps);
127 gst_caps_unref (srccaps);
133 gst_rtp_pcmu_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp)
135 GstBuffer *outbuf = NULL;
139 marker = gst_rtp_buffer_get_marker (rtp);
141 GST_DEBUG ("process : got %" G_GSIZE_FORMAT " bytes, mark %d ts %u seqn %d",
142 gst_buffer_get_size (rtp->buffer), marker,
143 gst_rtp_buffer_get_timestamp (rtp), gst_rtp_buffer_get_seq (rtp));
145 len = gst_rtp_buffer_get_payload_len (rtp);
146 outbuf = gst_rtp_buffer_get_payload_buffer (rtp);
149 GST_BUFFER_DURATION (outbuf) =
150 gst_util_uint64_scale_int (len, GST_SECOND, depayload->clock_rate);
153 /* mark start of talkspurt with RESYNC */
154 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_RESYNC);
157 gst_rtp_drop_non_audio_meta (depayload, outbuf);