1 /* GStreamer
2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2005> Edgard Lima <edgard.lima@gmail.com>
4 * Copyright (C) <2005> Nokia Corporation <kai.vehmanen@nokia.com>
5 *
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.
10 *
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.
15 *
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., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22 #ifdef HAVE_CONFIG_H
23 # include "config.h"
24 #endif
25
26 #include <stdlib.h>
27 #include <string.h>
28 #include <gst/rtp/gstrtpbuffer.h>
29
30 #include "gstrtpelements.h"
31 #include "gstrtppcmapay.h"
32
33 static GstStaticPadTemplate gst_rtp_pcma_pay_sink_template =
34 GST_STATIC_PAD_TEMPLATE ("sink",
35 GST_PAD_SINK,
36 GST_PAD_ALWAYS,
37 GST_STATIC_CAPS ("audio/x-alaw, channels=(int)1, rate=(int)8000")
38 );
39
40 static GstStaticPadTemplate gst_rtp_pcma_pay_src_template =
41 GST_STATIC_PAD_TEMPLATE ("src",
42 GST_PAD_SRC,
43 GST_PAD_ALWAYS,
44 GST_STATIC_CAPS ("application/x-rtp, "
45 "media = (string) \"audio\", "
46 "payload = (int) " GST_RTP_PAYLOAD_PCMA_STRING ", "
47 "clock-rate = (int) 8000, " "encoding-name = (string) \"PCMA\"; "
48 "application/x-rtp, "
49 "media = (string) \"audio\", "
50 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
51 "clock-rate = (int) [1, MAX ], " "encoding-name = (string) \"PCMA\"")
52 );
53
54 static gboolean gst_rtp_pcma_pay_setcaps (GstRTPBasePayload * payload,
55 GstCaps * caps);
56
57 #define gst_rtp_pcma_pay_parent_class parent_class
58 G_DEFINE_TYPE (GstRtpPcmaPay, gst_rtp_pcma_pay,
59 GST_TYPE_RTP_BASE_AUDIO_PAYLOAD);
60 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (rtppcmapay, "rtppcmapay",
61 GST_RANK_SECONDARY, GST_TYPE_RTP_PCMA_PAY, rtp_element_init (plugin));
62
63 static void
gst_rtp_pcma_pay_class_init(GstRtpPcmaPayClass * klass)64 gst_rtp_pcma_pay_class_init (GstRtpPcmaPayClass * klass)
65 {
66 GstElementClass *gstelement_class;
67 GstRTPBasePayloadClass *gstrtpbasepayload_class;
68
69 gstelement_class = (GstElementClass *) klass;
70 gstrtpbasepayload_class = (GstRTPBasePayloadClass *) klass;
71
72 gst_element_class_add_static_pad_template (gstelement_class,
73 &gst_rtp_pcma_pay_sink_template);
74 gst_element_class_add_static_pad_template (gstelement_class,
75 &gst_rtp_pcma_pay_src_template);
76
77 gst_element_class_set_static_metadata (gstelement_class, "RTP PCMA payloader",
78 "Codec/Payloader/Network/RTP",
79 "Payload-encodes PCMA audio into a RTP packet",
80 "Edgard Lima <edgard.lima@gmail.com>");
81
82 gstrtpbasepayload_class->set_caps = gst_rtp_pcma_pay_setcaps;
83 }
84
85 static void
gst_rtp_pcma_pay_init(GstRtpPcmaPay * rtppcmapay)86 gst_rtp_pcma_pay_init (GstRtpPcmaPay * rtppcmapay)
87 {
88 GstRTPBaseAudioPayload *rtpbaseaudiopayload;
89
90 rtpbaseaudiopayload = GST_RTP_BASE_AUDIO_PAYLOAD (rtppcmapay);
91
92 GST_RTP_BASE_PAYLOAD (rtppcmapay)->pt = GST_RTP_PAYLOAD_PCMA;
93 GST_RTP_BASE_PAYLOAD (rtppcmapay)->clock_rate = 8000;
94
95 /* tell rtpbaseaudiopayload that this is a sample based codec */
96 gst_rtp_base_audio_payload_set_sample_based (rtpbaseaudiopayload);
97
98 /* octet-per-sample is 1 for PCM */
99 gst_rtp_base_audio_payload_set_sample_options (rtpbaseaudiopayload, 1);
100 }
101
102 static gboolean
gst_rtp_pcma_pay_setcaps(GstRTPBasePayload * payload,GstCaps * caps)103 gst_rtp_pcma_pay_setcaps (GstRTPBasePayload * payload, GstCaps * caps)
104 {
105 gboolean res;
106
107 gst_rtp_base_payload_set_options (payload, "audio",
108 payload->pt != GST_RTP_PAYLOAD_PCMA, "PCMA", 8000);
109 res = gst_rtp_base_payload_set_outcaps (payload, NULL);
110
111 return res;
112 }
113