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 #define gst_rtp_pcma_depay_parent_class parent_class
69 G_DEFINE_TYPE (GstRtpPcmaDepay, gst_rtp_pcma_depay,
70 GST_TYPE_BASE_RTP_DEPAYLOAD);
73 gst_rtp_pcma_depay_class_init (GstRtpPcmaDepayClass * klass)
75 GstElementClass *gstelement_class;
76 GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
78 gstelement_class = (GstElementClass *) klass;
79 gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
81 gst_element_class_add_pad_template (gstelement_class,
82 gst_static_pad_template_get (&gst_rtp_pcma_depay_src_template));
83 gst_element_class_add_pad_template (gstelement_class,
84 gst_static_pad_template_get (&gst_rtp_pcma_depay_sink_template));
86 gst_element_class_set_details_simple (gstelement_class,
87 "RTP PCMA depayloader", "Codec/Depayloader/Network/RTP",
88 "Extracts PCMA audio from RTP packets",
89 "Edgard Lima <edgard.lima@indt.org.br>, Zeeshan Ali <zeenix@gmail.com>");
91 gstbasertpdepayload_class->process = gst_rtp_pcma_depay_process;
92 gstbasertpdepayload_class->set_caps = gst_rtp_pcma_depay_setcaps;
96 gst_rtp_pcma_depay_init (GstRtpPcmaDepay * rtppcmadepay)
98 GstBaseRTPDepayload *depayload;
100 depayload = GST_BASE_RTP_DEPAYLOAD (rtppcmadepay);
102 gst_pad_use_fixed_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload));
106 gst_rtp_pcma_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
109 GstStructure *structure;
113 structure = gst_caps_get_structure (caps, 0);
115 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
116 clock_rate = 8000; /* default */
117 depayload->clock_rate = clock_rate;
119 srccaps = gst_caps_new_simple ("audio/x-alaw",
120 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, clock_rate, NULL);
121 ret = gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload), srccaps);
122 gst_caps_unref (srccaps);
128 gst_rtp_pcma_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
130 GstBuffer *outbuf = NULL;
133 GstRTPBuffer rtp = { NULL };
135 gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp);
137 marker = gst_rtp_buffer_get_marker (&rtp);
139 GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d",
140 gst_buffer_get_size (buf), marker,
141 gst_rtp_buffer_get_timestamp (&rtp), gst_rtp_buffer_get_seq (&rtp));
143 len = gst_rtp_buffer_get_payload_len (&rtp);
144 outbuf = gst_rtp_buffer_get_payload_buffer (&rtp);
145 gst_rtp_buffer_unmap (&rtp);
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);
162 gst_rtp_pcma_depay_plugin_init (GstPlugin * plugin)
164 return gst_element_register (plugin, "rtppcmadepay",
165 GST_RANK_SECONDARY, GST_TYPE_RTP_PCMA_DEPAY);