gst-plugins-good/gst/rtp/: Fixed payload range in payloder caps. Removed payload...
[platform/upstream/gstreamer.git] / gst / rtp / gstrtpgsmdepay.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  * Copyright (C) <2005> Zeeshan Ali <zeenix@gmail.com>
4  *
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.
9  *
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 
14  */
15
16 #ifdef HAVE_CONFIG_H
17 #  include "config.h"
18 #endif
19
20 #include <string.h>
21 #include <gst/rtp/gstrtpbuffer.h>
22 #include "gstrtpgsmdepay.h"
23
24 /* elementfactory information */
25 static GstElementDetails gst_rtp_gsmdepay_details = {
26   "RTP packet parser",
27   "Codec/Depayr/Network",
28   "Extracts GSM audio from RTP packets",
29   "Zeeshan Ali <zeenix@gmail.com>"
30 };
31
32 /* RTPGSMDepay signals and args */
33 enum
34 {
35   /* FILL ME */
36   LAST_SIGNAL
37 };
38
39 static GstStaticPadTemplate gst_rtp_gsm_depay_src_template =
40 GST_STATIC_PAD_TEMPLATE ("src",
41     GST_PAD_SRC,
42     GST_PAD_ALWAYS,
43     GST_STATIC_CAPS ("audio/x-gsm, " "rate = (int) 8000, " "channels = 1")
44     );
45
46 static GstStaticPadTemplate gst_rtp_gsm_depay_sink_template =
47 GST_STATIC_PAD_TEMPLATE ("sink",
48     GST_PAD_SINK,
49     GST_PAD_ALWAYS,
50     GST_STATIC_CAPS ("application/x-rtp, "
51         "media = (string) \"audio\", "
52         "clock-rate = (int) 8000, " "encoding-name = (string) \"GSM\"")
53     );
54
55 static GstBuffer *gst_rtp_gsm_depay_process (GstBaseRTPDepayload * _depayload,
56     GstBuffer * buf);
57 static gboolean gst_rtp_gsm_depay_setcaps (GstBaseRTPDepayload * _depayload,
58     GstCaps * caps);
59
60 GST_BOILERPLATE (GstRTPGSMDepay, gst_rtp_gsm_depay, GstBaseRTPDepayload,
61     GST_TYPE_BASE_RTP_DEPAYLOAD);
62
63 static void
64 gst_rtp_gsm_depay_base_init (gpointer klass)
65 {
66   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
67
68   gst_element_class_add_pad_template (element_class,
69       gst_static_pad_template_get (&gst_rtp_gsm_depay_src_template));
70   gst_element_class_add_pad_template (element_class,
71       gst_static_pad_template_get (&gst_rtp_gsm_depay_sink_template));
72   gst_element_class_set_details (element_class, &gst_rtp_gsmdepay_details);
73 }
74
75 static void
76 gst_rtp_gsm_depay_class_init (GstRTPGSMDepayClass * klass)
77 {
78   GObjectClass *gobject_class;
79   GstElementClass *gstelement_class;
80   GstBaseRTPDepayloadClass *gstbasertp_depayload_class;
81
82   gobject_class = (GObjectClass *) klass;
83   gstelement_class = (GstElementClass *) klass;
84   gstbasertp_depayload_class = (GstBaseRTPDepayloadClass *) klass;
85
86   parent_class = g_type_class_ref (GST_TYPE_BASE_RTP_DEPAYLOAD);
87
88   gstbasertp_depayload_class->process = gst_rtp_gsm_depay_process;
89   gstbasertp_depayload_class->set_caps = gst_rtp_gsm_depay_setcaps;
90 }
91
92 static void
93 gst_rtp_gsm_depay_init (GstRTPGSMDepay * rtpgsmdepay,
94     GstRTPGSMDepayClass * klass)
95 {
96   GST_BASE_RTP_DEPAYLOAD (rtpgsmdepay)->clock_rate = 8000;
97 }
98
99 static gboolean
100 gst_rtp_gsm_depay_setcaps (GstBaseRTPDepayload * _depayload, GstCaps * caps)
101 {
102   GstCaps *srccaps;
103   gboolean ret;
104
105   srccaps = gst_static_pad_template_get_caps (&gst_rtp_gsm_depay_src_template);
106   ret = gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (_depayload), srccaps);
107
108   gst_caps_unref (srccaps);
109   return ret;
110 }
111
112 static GstBuffer *
113 gst_rtp_gsm_depay_process (GstBaseRTPDepayload * _depayload, GstBuffer * buf)
114 {
115   GstBuffer *outbuf = NULL;
116   gint payload_len;
117   guint8 *payload;
118
119   GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d",
120       GST_BUFFER_SIZE (buf),
121       gst_rtp_buffer_get_marker (buf),
122       gst_rtp_buffer_get_timestamp (buf), gst_rtp_buffer_get_seq (buf));
123
124   payload_len = gst_rtp_buffer_get_payload_len (buf);
125   payload = gst_rtp_buffer_get_payload (buf);
126
127   outbuf = gst_buffer_new_and_alloc (payload_len);
128   memcpy (GST_BUFFER_DATA (outbuf), payload, payload_len);
129   return outbuf;
130 }
131
132 gboolean
133 gst_rtp_gsm_depay_plugin_init (GstPlugin * plugin)
134 {
135   return gst_element_register (plugin, "rtpgsmdepay",
136       GST_RANK_NONE, GST_TYPE_RTP_GSM_DEPAY);
137 }