Tizen 2.0 Release
[framework/multimedia/gst-plugins-good0.10.git] / gst / rtp / gstrtppcmupay.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., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, 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 "gstrtppcmupay.h"
31
32 static GstStaticPadTemplate gst_rtp_pcmu_pay_sink_template =
33 GST_STATIC_PAD_TEMPLATE ("sink",
34     GST_PAD_SINK,
35     GST_PAD_ALWAYS,
36     GST_STATIC_CAPS ("audio/x-mulaw, channels=(int)1, rate=(int)8000")
37     );
38
39 static GstStaticPadTemplate gst_rtp_pcmu_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_PCMU_STRING ", "
46         "clock-rate = (int) 8000, " "encoding-name = (string) \"PCMU\"; "
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) \"PCMU\"")
51     );
52
53 static gboolean gst_rtp_pcmu_pay_setcaps (GstBaseRTPPayload * payload,
54     GstCaps * caps);
55
56 GST_BOILERPLATE (GstRtpPcmuPay, gst_rtp_pcmu_pay, GstBaseRTPAudioPayload,
57     GST_TYPE_BASE_RTP_AUDIO_PAYLOAD);
58
59 static void
60 gst_rtp_pcmu_pay_base_init (gpointer klass)
61 {
62   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
63
64   gst_element_class_add_static_pad_template (element_class,
65       &gst_rtp_pcmu_pay_sink_template);
66   gst_element_class_add_static_pad_template (element_class,
67       &gst_rtp_pcmu_pay_src_template);
68   gst_element_class_set_details_simple (element_class, "RTP PCMU payloader",
69       "Codec/Payloader/Network/RTP",
70       "Payload-encodes PCMU audio into a RTP packet",
71       "Edgard Lima <edgard.lima@indt.org.br>");
72 }
73
74 static void
75 gst_rtp_pcmu_pay_class_init (GstRtpPcmuPayClass * klass)
76 {
77   GstBaseRTPPayloadClass *gstbasertppayload_class;
78
79   gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass;
80
81   gstbasertppayload_class->set_caps = gst_rtp_pcmu_pay_setcaps;
82 }
83
84 static void
85 gst_rtp_pcmu_pay_init (GstRtpPcmuPay * rtppcmupay, GstRtpPcmuPayClass * klass)
86 {
87   GstBaseRTPAudioPayload *basertpaudiopayload;
88
89   basertpaudiopayload = GST_BASE_RTP_AUDIO_PAYLOAD (rtppcmupay);
90
91   GST_BASE_RTP_PAYLOAD (rtppcmupay)->clock_rate = 8000;
92
93   /* tell basertpaudiopayload that this is a sample based codec */
94   gst_base_rtp_audio_payload_set_sample_based (basertpaudiopayload);
95
96   /* octet-per-sample is 1 for PCM */
97   gst_base_rtp_audio_payload_set_sample_options (basertpaudiopayload, 1);
98 }
99
100 static gboolean
101 gst_rtp_pcmu_pay_setcaps (GstBaseRTPPayload * payload, GstCaps * caps)
102 {
103   gboolean res;
104
105   payload->pt = GST_RTP_PAYLOAD_PCMU;
106
107   gst_basertppayload_set_options (payload, "audio", FALSE, "PCMU", 8000);
108   res = gst_basertppayload_set_outcaps (payload, NULL);
109
110   return res;
111 }
112
113 gboolean
114 gst_rtp_pcmu_pay_plugin_init (GstPlugin * plugin)
115 {
116   return gst_element_register (plugin, "rtppcmupay",
117       GST_RANK_SECONDARY, GST_TYPE_RTP_PCMU_PAY);
118 }