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 "gstrtppcmadepay.h"
30 /* elementfactory information */
31 static const GstElementDetails gst_rtp_pcmadepay_details =
32 GST_ELEMENT_DETAILS ("RTP PCMA depayloader",
33 "Codec/Depayloader/Network",
34 "Extracts PCMA audio from RTP packets",
35 "Edgard Lima <edgard.lima@indt.org.br>, Zeeshan Ali <zeenix@gmail.com>");
37 /* RtpPcmaDepay signals and args */
49 static GstStaticPadTemplate gst_rtp_pcma_depay_sink_template =
50 GST_STATIC_PAD_TEMPLATE ("sink",
53 GST_STATIC_CAPS ("application/x-rtp, "
54 "media = (string) \"audio\", "
55 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
56 "clock-rate = (int) 8000, " "encoding-name = (string) \"PCMA\";"
58 "media = (string) \"audio\", "
59 "payload = (int) " GST_RTP_PAYLOAD_PCMA_STRING ", "
60 "clock-rate = (int) 8000")
63 static GstStaticPadTemplate gst_rtp_pcma_depay_src_template =
64 GST_STATIC_PAD_TEMPLATE ("src",
67 GST_STATIC_CAPS ("audio/x-alaw, channels = (int) 1, rate = (int) 8000")
70 static GstBuffer *gst_rtp_pcma_depay_process (GstBaseRTPDepayload * depayload,
72 static gboolean gst_rtp_pcma_depay_setcaps (GstBaseRTPDepayload * depayload,
75 GST_BOILERPLATE (GstRtpPcmaDepay, gst_rtp_pcma_depay, GstBaseRTPDepayload,
76 GST_TYPE_BASE_RTP_DEPAYLOAD);
79 gst_rtp_pcma_depay_base_init (gpointer klass)
81 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
83 gst_element_class_add_pad_template (element_class,
84 gst_static_pad_template_get (&gst_rtp_pcma_depay_src_template));
85 gst_element_class_add_pad_template (element_class,
86 gst_static_pad_template_get (&gst_rtp_pcma_depay_sink_template));
87 gst_element_class_set_details (element_class, &gst_rtp_pcmadepay_details);
91 gst_rtp_pcma_depay_class_init (GstRtpPcmaDepayClass * klass)
93 GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
95 gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
97 parent_class = g_type_class_peek_parent (klass);
99 gstbasertpdepayload_class->process = gst_rtp_pcma_depay_process;
100 gstbasertpdepayload_class->set_caps = gst_rtp_pcma_depay_setcaps;
104 gst_rtp_pcma_depay_init (GstRtpPcmaDepay * rtppcmadepay,
105 GstRtpPcmaDepayClass * klass)
107 GstBaseRTPDepayload *depayload;
109 depayload = GST_BASE_RTP_DEPAYLOAD (rtppcmadepay);
111 gst_pad_use_fixed_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload));
115 gst_rtp_pcma_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
118 GstStructure *structure;
122 structure = gst_caps_get_structure (caps, 0);
124 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
125 clock_rate = 8000; /* default */
126 depayload->clock_rate = clock_rate;
128 srccaps = gst_caps_new_simple ("audio/x-alaw",
129 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, clock_rate, NULL);
130 ret = gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload), srccaps);
131 gst_caps_unref (srccaps);
137 gst_rtp_pcma_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
139 GstBuffer *outbuf = NULL;
143 marker = gst_rtp_buffer_get_marker (buf);
145 GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d",
146 GST_BUFFER_SIZE (buf), marker,
147 gst_rtp_buffer_get_timestamp (buf), gst_rtp_buffer_get_seq (buf));
149 len = gst_rtp_buffer_get_payload_len (buf);
150 outbuf = gst_rtp_buffer_get_payload_buffer (buf);
152 GST_BUFFER_DURATION (outbuf) =
153 gst_util_uint64_scale_int (len, GST_SECOND, depayload->clock_rate);
156 /* mark start of talkspurt with DISCONT */
157 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
164 gst_rtp_pcma_depay_plugin_init (GstPlugin * plugin)
166 return gst_element_register (plugin, "rtppcmadepay",
167 GST_RANK_MARGINAL, GST_TYPE_RTP_PCMA_DEPAY);