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 /* RtpPcmaDepay signals and args */
42 static GstStaticPadTemplate gst_rtp_pcma_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_PCMA_STRING ", "
49 "clock-rate = (int) 8000, encoding-name = (string) \"PCMA\";"
51 "media = (string) \"audio\", "
52 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
53 "clock-rate = (int) [1, MAX ], encoding-name = (string) \"PCMA\"")
56 static GstStaticPadTemplate gst_rtp_pcma_depay_src_template =
57 GST_STATIC_PAD_TEMPLATE ("src",
60 GST_STATIC_CAPS ("audio/x-alaw, channels = (int) 1, rate = (int) [1, MAX ]")
63 static GstBuffer *gst_rtp_pcma_depay_process (GstBaseRTPDepayload * depayload,
65 static gboolean gst_rtp_pcma_depay_setcaps (GstBaseRTPDepayload * depayload,
68 GST_BOILERPLATE (GstRtpPcmaDepay, gst_rtp_pcma_depay, GstBaseRTPDepayload,
69 GST_TYPE_BASE_RTP_DEPAYLOAD);
72 gst_rtp_pcma_depay_base_init (gpointer klass)
74 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
76 gst_element_class_add_static_pad_template (element_class,
77 &gst_rtp_pcma_depay_src_template);
78 gst_element_class_add_static_pad_template (element_class,
79 &gst_rtp_pcma_depay_sink_template);
80 gst_element_class_set_details_simple (element_class, "RTP PCMA depayloader",
81 "Codec/Depayloader/Network/RTP",
82 "Extracts PCMA audio from RTP packets",
83 "Edgard Lima <edgard.lima@indt.org.br>, Zeeshan Ali <zeenix@gmail.com>");
87 gst_rtp_pcma_depay_class_init (GstRtpPcmaDepayClass * klass)
89 GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
91 gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
93 gstbasertpdepayload_class->process = gst_rtp_pcma_depay_process;
94 gstbasertpdepayload_class->set_caps = gst_rtp_pcma_depay_setcaps;
98 gst_rtp_pcma_depay_init (GstRtpPcmaDepay * rtppcmadepay,
99 GstRtpPcmaDepayClass * klass)
101 GstBaseRTPDepayload *depayload;
103 depayload = GST_BASE_RTP_DEPAYLOAD (rtppcmadepay);
105 gst_pad_use_fixed_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload));
109 gst_rtp_pcma_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
112 GstStructure *structure;
116 structure = gst_caps_get_structure (caps, 0);
118 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
119 clock_rate = 8000; /* default */
120 depayload->clock_rate = clock_rate;
122 srccaps = gst_caps_new_simple ("audio/x-alaw",
123 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, clock_rate, NULL);
124 ret = gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload), srccaps);
125 gst_caps_unref (srccaps);
131 gst_rtp_pcma_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
133 GstBuffer *outbuf = NULL;
137 marker = gst_rtp_buffer_get_marker (buf);
139 GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d",
140 GST_BUFFER_SIZE (buf), marker,
141 gst_rtp_buffer_get_timestamp (buf), gst_rtp_buffer_get_seq (buf));
143 len = gst_rtp_buffer_get_payload_len (buf);
144 outbuf = gst_rtp_buffer_get_payload_buffer (buf);
147 GST_BUFFER_DURATION (outbuf) =
148 gst_util_uint64_scale_int (len, GST_SECOND, depayload->clock_rate);
151 /* mark start of talkspurt with DISCONT */
152 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
160 gst_rtp_pcma_depay_plugin_init (GstPlugin * plugin)
162 return gst_element_register (plugin, "rtppcmadepay",
163 GST_RANK_SECONDARY, GST_TYPE_RTP_PCMA_DEPAY);