2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2005> Zeeshan Ali <zeenix@gmail.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
27 #include <gst/rtp/gstrtpbuffer.h>
29 #include "gstrtpgsmpay.h"
31 GST_DEBUG_CATEGORY_STATIC (rtpgsmpay_debug);
32 #define GST_CAT_DEFAULT (rtpgsmpay_debug)
34 static GstStaticPadTemplate gst_rtp_gsm_pay_sink_template =
35 GST_STATIC_PAD_TEMPLATE ("sink",
38 GST_STATIC_CAPS ("audio/x-gsm, " "rate = (int) 8000, " "channels = (int) 1")
41 static GstStaticPadTemplate gst_rtp_gsm_pay_src_template =
42 GST_STATIC_PAD_TEMPLATE ("src",
45 GST_STATIC_CAPS ("application/x-rtp, "
46 "media = (string) \"audio\", "
47 "payload = (int) " GST_RTP_PAYLOAD_GSM_STRING ", "
48 "clock-rate = (int) 8000, " "encoding-name = (string) \"GSM\"; "
50 "media = (string) \"audio\", "
51 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
52 "clock-rate = (int) 8000, " "encoding-name = (string) \"GSM\"")
55 static gboolean gst_rtp_gsm_pay_setcaps (GstBaseRTPPayload * payload,
57 static GstFlowReturn gst_rtp_gsm_pay_handle_buffer (GstBaseRTPPayload * payload,
60 GST_BOILERPLATE (GstRTPGSMPay, gst_rtp_gsm_pay, GstBaseRTPPayload,
61 GST_TYPE_BASE_RTP_PAYLOAD);
64 gst_rtp_gsm_pay_base_init (gpointer klass)
66 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
68 gst_element_class_add_static_pad_template (element_class,
69 &gst_rtp_gsm_pay_sink_template);
70 gst_element_class_add_static_pad_template (element_class,
71 &gst_rtp_gsm_pay_src_template);
72 gst_element_class_set_details_simple (element_class, "RTP GSM payloader",
73 "Codec/Payloader/Network/RTP",
74 "Payload-encodes GSM audio into a RTP packet",
75 "Zeeshan Ali <zeenix@gmail.com>");
79 gst_rtp_gsm_pay_class_init (GstRTPGSMPayClass * klass)
81 GstBaseRTPPayloadClass *gstbasertppayload_class;
83 gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass;
85 gstbasertppayload_class->set_caps = gst_rtp_gsm_pay_setcaps;
86 gstbasertppayload_class->handle_buffer = gst_rtp_gsm_pay_handle_buffer;
88 GST_DEBUG_CATEGORY_INIT (rtpgsmpay_debug, "rtpgsmpay", 0,
89 "GSM Audio RTP Payloader");
93 gst_rtp_gsm_pay_init (GstRTPGSMPay * rtpgsmpay, GstRTPGSMPayClass * klass)
95 GST_BASE_RTP_PAYLOAD (rtpgsmpay)->clock_rate = 8000;
96 GST_BASE_RTP_PAYLOAD_PT (rtpgsmpay) = GST_RTP_PAYLOAD_GSM;
100 gst_rtp_gsm_pay_setcaps (GstBaseRTPPayload * payload, GstCaps * caps)
103 GstStructure *structure;
106 structure = gst_caps_get_structure (caps, 0);
108 stname = gst_structure_get_name (structure);
110 if (strcmp ("audio/x-gsm", stname))
113 gst_basertppayload_set_options (payload, "audio", FALSE, "GSM", 8000);
114 res = gst_basertppayload_set_outcaps (payload, NULL);
121 GST_WARNING_OBJECT (payload, "invalid media type received");
127 gst_rtp_gsm_pay_handle_buffer (GstBaseRTPPayload * basepayload,
130 GstRTPGSMPay *rtpgsmpay;
131 guint size, payload_len;
133 guint8 *payload, *data;
134 GstClockTime timestamp, duration;
137 rtpgsmpay = GST_RTP_GSM_PAY (basepayload);
139 size = GST_BUFFER_SIZE (buffer);
140 timestamp = GST_BUFFER_TIMESTAMP (buffer);
141 duration = GST_BUFFER_DURATION (buffer);
143 /* FIXME, only one GSM frame per RTP packet for now */
146 /* FIXME, just error out for now */
147 if (payload_len > GST_BASE_RTP_PAYLOAD_MTU (rtpgsmpay)) {
148 GST_ELEMENT_ERROR (rtpgsmpay, STREAM, ENCODE, (NULL),
149 ("payload_len %u > mtu %u", payload_len,
150 GST_BASE_RTP_PAYLOAD_MTU (rtpgsmpay)));
151 return GST_FLOW_ERROR;
154 outbuf = gst_rtp_buffer_new_allocate (payload_len, 0, 0);
156 /* copy timestamp and duration */
157 GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
158 GST_BUFFER_DURATION (outbuf) = duration;
161 payload = gst_rtp_buffer_get_payload (outbuf);
163 data = GST_BUFFER_DATA (buffer);
165 /* copy data in payload */
166 memcpy (&payload[0], data, size);
168 gst_buffer_unref (buffer);
170 GST_DEBUG ("gst_rtp_gsm_pay_chain: pushing buffer of size %d",
171 GST_BUFFER_SIZE (outbuf));
173 ret = gst_basertppayload_push (basepayload, outbuf);
179 gst_rtp_gsm_pay_plugin_init (GstPlugin * plugin)
181 return gst_element_register (plugin, "rtpgsmpay",
182 GST_RANK_SECONDARY, GST_TYPE_RTP_GSM_PAY);