2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2005> Edgard Lima <edgard.lima@indt.org.br>
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., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
27 #include <gst/rtp/gstrtpbuffer.h>
28 #include "gstrtppcmudepay.h"
30 /* RtpPcmuDepay signals and args */
42 static GstStaticPadTemplate gst_rtp_pcmu_depay_sink_template =
43 GST_STATIC_PAD_TEMPLATE ("sink",
46 GST_STATIC_CAPS ("application/x-rtp, "
47 "media = (string) \"audio\", "
48 "payload = (int) " GST_RTP_PAYLOAD_PCMU_STRING ", "
49 "encoding-name = (string) \"PCMU\", clock-rate = (int) 8000; "
51 "media = (string) \"audio\", "
52 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
53 "encoding-name = (string) \"PCMU\", clock-rate = (int) [1, MAX ]")
56 static GstStaticPadTemplate gst_rtp_pcmu_depay_src_template =
57 GST_STATIC_PAD_TEMPLATE ("src",
60 GST_STATIC_CAPS ("audio/x-mulaw, "
61 "channels = (int) 1, rate = (int) [1, MAX ]")
64 static GstBuffer *gst_rtp_pcmu_depay_process (GstBaseRTPDepayload * depayload,
66 static gboolean gst_rtp_pcmu_depay_setcaps (GstBaseRTPDepayload * depayload,
69 GST_BOILERPLATE (GstRtpPcmuDepay, gst_rtp_pcmu_depay, GstBaseRTPDepayload,
70 GST_TYPE_BASE_RTP_DEPAYLOAD);
73 gst_rtp_pcmu_depay_base_init (gpointer klass)
75 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
77 gst_element_class_add_static_pad_template (element_class,
78 &gst_rtp_pcmu_depay_src_template);
79 gst_element_class_add_static_pad_template (element_class,
80 &gst_rtp_pcmu_depay_sink_template);
81 gst_element_class_set_details_simple (element_class, "RTP PCMU depayloader",
82 "Codec/Depayloader/Network/RTP",
83 "Extracts PCMU audio from RTP packets",
84 "Edgard Lima <edgard.lima@indt.org.br>, Zeeshan Ali <zeenix@gmail.com>");
88 gst_rtp_pcmu_depay_class_init (GstRtpPcmuDepayClass * klass)
90 GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
92 gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
94 gstbasertpdepayload_class->process = gst_rtp_pcmu_depay_process;
95 gstbasertpdepayload_class->set_caps = gst_rtp_pcmu_depay_setcaps;
99 gst_rtp_pcmu_depay_init (GstRtpPcmuDepay * rtppcmudepay,
100 GstRtpPcmuDepayClass * klass)
102 GstBaseRTPDepayload *depayload;
104 depayload = GST_BASE_RTP_DEPAYLOAD (rtppcmudepay);
106 gst_pad_use_fixed_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload));
110 gst_rtp_pcmu_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
113 GstStructure *structure;
117 structure = gst_caps_get_structure (caps, 0);
119 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
120 clock_rate = 8000; /* default */
121 depayload->clock_rate = clock_rate;
123 srccaps = gst_caps_new_simple ("audio/x-mulaw",
124 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, clock_rate, NULL);
125 ret = gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload), srccaps);
126 gst_caps_unref (srccaps);
132 gst_rtp_pcmu_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
134 GstBuffer *outbuf = NULL;
138 marker = gst_rtp_buffer_get_marker (buf);
140 GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d",
141 GST_BUFFER_SIZE (buf), marker,
142 gst_rtp_buffer_get_timestamp (buf), gst_rtp_buffer_get_seq (buf));
144 len = gst_rtp_buffer_get_payload_len (buf);
145 outbuf = gst_rtp_buffer_get_payload_buffer (buf);
148 GST_BUFFER_DURATION (outbuf) =
149 gst_util_uint64_scale_int (len, GST_SECOND, depayload->clock_rate);
152 /* mark start of talkspurt with DISCONT */
153 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
161 gst_rtp_pcmu_depay_plugin_init (GstPlugin * plugin)
163 return gst_element_register (plugin, "rtppcmudepay",
164 GST_RANK_SECONDARY, GST_TYPE_RTP_PCMU_DEPAY);