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 Nokia Corporation <kai.vehmanen@nokia.com>
5 * Copyright (C) 2007,2008 Axis Communications <dev-gstreamer@axis.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
29 #include <gst/rtp/gstrtpbuffer.h>
31 #include "gstrtpg726pay.h"
33 static const GstElementDetails gst_rtp_g726_pay_details =
34 GST_ELEMENT_DETAILS ("RTP G.726 payloader",
35 "Codec/Payloader/Network",
36 "Payload-encodes G.726 audio into a RTP packet",
37 "Axis Communications <dev-gstreamer@axis.com>");
39 static GstStaticPadTemplate gst_rtp_g726_pay_sink_template =
40 GST_STATIC_PAD_TEMPLATE ("sink",
43 GST_STATIC_CAPS ("audio/x-adpcm, "
44 "channels = (int) 1, "
46 "bitrate = (int) { 16000, 24000, 32000, 40000 }, "
47 "layout = (string) \"g726\"")
50 static GstStaticPadTemplate gst_rtp_g726_pay_src_template =
51 GST_STATIC_PAD_TEMPLATE ("src",
54 GST_STATIC_CAPS ("application/x-rtp, "
55 "media = (string) \"audio\", "
56 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
57 "clock-rate = (int) 8000, "
58 "encoding-name = (string) { \"G726-16\", \"G726-24\", \"G726-32\", \"G726-40\" } ")
61 static gboolean gst_rtp_g726_pay_setcaps (GstBaseRTPPayload * payload,
64 GST_BOILERPLATE (GstRtpG726Pay, gst_rtp_g726_pay, GstBaseRTPAudioPayload,
65 GST_TYPE_BASE_RTP_AUDIO_PAYLOAD);
68 gst_rtp_g726_pay_base_init (gpointer klass)
70 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
72 gst_element_class_add_pad_template (element_class,
73 gst_static_pad_template_get (&gst_rtp_g726_pay_sink_template));
74 gst_element_class_add_pad_template (element_class,
75 gst_static_pad_template_get (&gst_rtp_g726_pay_src_template));
76 gst_element_class_set_details (element_class, &gst_rtp_g726_pay_details);
80 gst_rtp_g726_pay_class_init (GstRtpG726PayClass * klass)
82 GObjectClass *gobject_class;
83 GstElementClass *gstelement_class;
84 GstBaseRTPPayloadClass *gstbasertppayload_class;
86 gobject_class = (GObjectClass *) klass;
87 gstelement_class = (GstElementClass *) klass;
88 gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass;
90 parent_class = g_type_class_peek_parent (klass);
92 gstbasertppayload_class->set_caps = gst_rtp_g726_pay_setcaps;
96 gst_rtp_g726_pay_init (GstRtpG726Pay * rtpg726pay, GstRtpG726PayClass * klass)
98 GstBaseRTPAudioPayload *basertpaudiopayload;
100 basertpaudiopayload = GST_BASE_RTP_AUDIO_PAYLOAD (rtpg726pay);
102 GST_BASE_RTP_PAYLOAD (rtpg726pay)->clock_rate = 8000;
104 /* sample based codec */
105 gst_base_rtp_audio_payload_set_sample_based (basertpaudiopayload);
109 gst_rtp_g726_pay_setcaps (GstBaseRTPPayload * payload, GstCaps * caps)
111 gchar *encoding_name;
112 GstStructure *structure = gst_caps_get_structure (caps, 0);
113 GstBaseRTPAudioPayload *basertpaudiopayload;
116 basertpaudiopayload = GST_BASE_RTP_AUDIO_PAYLOAD (payload);
118 if (!gst_structure_get_int (structure, "bitrate", &bitrate))
123 encoding_name = g_strdup ("G726-16");
124 gst_base_rtp_audio_payload_set_samplebits_options (basertpaudiopayload,
128 encoding_name = g_strdup ("G726-24");
129 gst_base_rtp_audio_payload_set_samplebits_options (basertpaudiopayload,
133 encoding_name = g_strdup ("G726-32");
134 gst_base_rtp_audio_payload_set_samplebits_options (basertpaudiopayload,
138 encoding_name = g_strdup ("G726-40");
139 gst_base_rtp_audio_payload_set_samplebits_options (basertpaudiopayload,
143 goto invalid_bitrate;
146 gst_basertppayload_set_options (payload, "audio", TRUE, encoding_name, 8000);
147 gst_basertppayload_set_outcaps (payload, NULL);
149 g_free (encoding_name);
156 GST_ERROR_OBJECT (payload, "invalid bitrate %d specified", bitrate);
162 gst_rtp_g726_pay_plugin_init (GstPlugin * plugin)
164 return gst_element_register (plugin, "rtpg726pay",
165 GST_RANK_NONE, GST_TYPE_RTP_G726_PAY);