good: use new gst_element_class_add_static_pad_template()
[platform/upstream/gst-plugins-good.git] / gst / rtp / gstrtppcmapay.c
1 /* GStreamer
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  *
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 "gstrtppcmapay.h"
31
32 static GstStaticPadTemplate gst_rtp_pcma_pay_sink_template =
33 GST_STATIC_PAD_TEMPLATE ("sink",
34     GST_PAD_SINK,
35     GST_PAD_ALWAYS,
36     GST_STATIC_CAPS ("audio/x-alaw, channels=(int)1, rate=(int)8000")
37     );
38
39 static GstStaticPadTemplate gst_rtp_pcma_pay_src_template =
40     GST_STATIC_PAD_TEMPLATE ("src",
41     GST_PAD_SRC,
42     GST_PAD_ALWAYS,
43     GST_STATIC_CAPS ("application/x-rtp, "
44         "media = (string) \"audio\", "
45         "payload = (int) " GST_RTP_PAYLOAD_PCMA_STRING ", "
46         "clock-rate = (int) 8000, " "encoding-name = (string) \"PCMA\"; "
47         "application/x-rtp, "
48         "media = (string) \"audio\", "
49         "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
50         "clock-rate = (int) [1, MAX ], " "encoding-name = (string) \"PCMA\"")
51     );
52
53 static gboolean gst_rtp_pcma_pay_setcaps (GstRTPBasePayload * payload,
54     GstCaps * caps);
55
56 #define gst_rtp_pcma_pay_parent_class parent_class
57 G_DEFINE_TYPE (GstRtpPcmaPay, gst_rtp_pcma_pay,
58     GST_TYPE_RTP_BASE_AUDIO_PAYLOAD);
59
60 static void
61 gst_rtp_pcma_pay_class_init (GstRtpPcmaPayClass * klass)
62 {
63   GstElementClass *gstelement_class;
64   GstRTPBasePayloadClass *gstrtpbasepayload_class;
65
66   gstelement_class = (GstElementClass *) klass;
67   gstrtpbasepayload_class = (GstRTPBasePayloadClass *) klass;
68
69   gst_element_class_add_static_pad_template (gstelement_class,
70       &gst_rtp_pcma_pay_sink_template);
71   gst_element_class_add_static_pad_template (gstelement_class,
72       &gst_rtp_pcma_pay_src_template);
73
74   gst_element_class_set_static_metadata (gstelement_class, "RTP PCMA payloader",
75       "Codec/Payloader/Network/RTP",
76       "Payload-encodes PCMA audio into a RTP packet",
77       "Edgard Lima <edgard.lima@indt.org.br>");
78
79   gstrtpbasepayload_class->set_caps = gst_rtp_pcma_pay_setcaps;
80 }
81
82 static void
83 gst_rtp_pcma_pay_init (GstRtpPcmaPay * rtppcmapay)
84 {
85   GstRTPBaseAudioPayload *rtpbaseaudiopayload;
86
87   rtpbaseaudiopayload = GST_RTP_BASE_AUDIO_PAYLOAD (rtppcmapay);
88
89   GST_RTP_BASE_PAYLOAD (rtppcmapay)->pt = GST_RTP_PAYLOAD_PCMA;
90   GST_RTP_BASE_PAYLOAD (rtppcmapay)->clock_rate = 8000;
91
92   /* tell rtpbaseaudiopayload that this is a sample based codec */
93   gst_rtp_base_audio_payload_set_sample_based (rtpbaseaudiopayload);
94
95   /* octet-per-sample is 1 for PCM */
96   gst_rtp_base_audio_payload_set_sample_options (rtpbaseaudiopayload, 1);
97 }
98
99 static gboolean
100 gst_rtp_pcma_pay_setcaps (GstRTPBasePayload * payload, GstCaps * caps)
101 {
102   gboolean res;
103
104   gst_rtp_base_payload_set_options (payload, "audio",
105       payload->pt != GST_RTP_PAYLOAD_PCMA, "PCMA", 8000);
106   res = gst_rtp_base_payload_set_outcaps (payload, NULL);
107
108   return res;
109 }
110
111 gboolean
112 gst_rtp_pcma_pay_plugin_init (GstPlugin * plugin)
113 {
114   return gst_element_register (plugin, "rtppcmapay",
115       GST_RANK_SECONDARY, GST_TYPE_RTP_PCMA_PAY);
116 }