Update Initialization code from Tizen 2.4
[platform/upstream/gst-plugins-tizen.git] / toggle / src / gsttoggle.c
1 /*
2  * toggle
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>
7  *
8  * This library is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU Lesser General Public License as published by the
10  * Free Software Foundation; either version 2.1 of the License, or (at your option)
11  * any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
14  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16  * License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; if not, write to the Free Software Foundation, Inc., 51
20  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #  include "config.h"
26 #endif
27
28 #include <stdlib.h>
29
30 #include "gsttoggle.h"
31
32 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
33     GST_PAD_SINK,
34     GST_PAD_ALWAYS,
35     GST_STATIC_CAPS_ANY);
36
37 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
38     GST_PAD_SRC,
39     GST_PAD_ALWAYS,
40     GST_STATIC_CAPS_ANY);
41
42 GST_DEBUG_CATEGORY_STATIC (gst_mytoggle_debug);
43 #define GST_CAT_DEFAULT gst_mytoggle_debug
44
45 enum
46 {
47   LAST_SIGNAL
48 };
49
50
51 #define DEFAULT_BLOCK_DATA        FALSE
52
53 enum
54 {
55   PROP_0,
56   PROP_BLOCK_DATA
57  
58 };
59
60
61 #define _do_init(bla) \
62     GST_DEBUG_CATEGORY_INIT (gst_mytoggle_debug, "toggle", 0, "toggle element");
63
64 G_DEFINE_TYPE_WITH_CODE (GstMytoggle, gst_mytoggle,
65     GST_TYPE_BASE_TRANSFORM, _do_init(G_TYPE_INVALID));
66
67 static void gst_mytoggle_finalize (GObject * object);
68 static void gst_mytoggle_set_property (GObject * object, guint prop_id,
69     const GValue * value, GParamSpec * pspec);
70 static void gst_mytoggle_get_property (GObject * object, guint prop_id,
71     GValue * value, GParamSpec * pspec);
72
73 static GstFlowReturn gst_mytoggle_transform_ip (GstBaseTransform * trans,
74     GstBuffer * buf);
75 static gboolean gst_mytoggle_start (GstBaseTransform * trans);
76 static gboolean gst_mytoggle_stop (GstBaseTransform * trans);
77
78 static void
79 gst_mytoggle_base_init (gpointer g_class)
80 {
81 }
82
83 static void
84 gst_mytoggle_finalize (GObject * object)
85 {
86   GstMytoggle *mytoggle;
87
88   G_OBJECT_CLASS (gst_mytoggle_parent_class)->finalize (object);
89 }
90
91 static void
92 gst_mytoggle_class_init (GstMytoggleClass * klass)
93 {
94   GObjectClass *gobject_class;
95   GstBaseTransformClass *gstbasetrans_class;
96   GstElementClass *gstelement_class;
97
98   gobject_class = G_OBJECT_CLASS (klass);
99   gstbasetrans_class = GST_BASE_TRANSFORM_CLASS (klass);
100   gstelement_class = GST_ELEMENT_CLASS (klass);
101
102   gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_mytoggle_set_property);
103   gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_mytoggle_get_property);
104
105   g_object_class_install_property (gobject_class,
106       PROP_BLOCK_DATA, g_param_spec_boolean ("block_data",
107           "Data Block",
108           "Data Block", 
109           DEFAULT_BLOCK_DATA, G_PARAM_READWRITE));
110     
111   gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_mytoggle_finalize);
112
113   gst_element_class_set_details_simple (gstelement_class,
114       "toggle",
115       "Generic",
116       "Pass data without modification", "Rahul Mittal <mittal.rahul@samsung.com>");
117   gst_element_class_add_pad_template (gstelement_class,
118       gst_static_pad_template_get (&srctemplate));
119   gst_element_class_add_pad_template (gstelement_class,
120       gst_static_pad_template_get (&sinktemplate));
121
122   gstbasetrans_class->transform_ip =
123       GST_DEBUG_FUNCPTR (gst_mytoggle_transform_ip);
124   gstbasetrans_class->start = GST_DEBUG_FUNCPTR (gst_mytoggle_start);
125   gstbasetrans_class->stop = GST_DEBUG_FUNCPTR (gst_mytoggle_stop);
126 }
127
128 static void
129 gst_mytoggle_init (GstMytoggle * mytoggle)
130 {
131   gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (mytoggle), TRUE);
132
133   mytoggle->block_data = DEFAULT_BLOCK_DATA;
134
135 }
136
137 static GstFlowReturn
138 gst_mytoggle_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
139 {
140   GstMytoggle *mytoggle = GST_MYTOGGLE (trans);
141  
142   if (mytoggle->block_data ==TRUE) 
143       return GST_BASE_TRANSFORM_FLOW_DROPPED;
144
145   return GST_FLOW_OK;
146 }
147
148 static void
149 gst_mytoggle_set_property (GObject * object, guint prop_id,
150     const GValue * value, GParamSpec * pspec)
151 {
152   GstMytoggle *mytoggle;
153
154   mytoggle = GST_MYTOGGLE (object);
155
156   switch (prop_id) {
157   
158     case PROP_BLOCK_DATA:
159       mytoggle->block_data = g_value_get_boolean (value);
160       break;
161     default:
162       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
163       break;
164   }
165 }
166
167 static void
168 gst_mytoggle_get_property (GObject * object, guint prop_id, GValue * value,
169     GParamSpec * pspec)
170 {
171   GstMytoggle *mytoggle;
172
173   mytoggle = GST_MYTOGGLE (object);
174
175   switch (prop_id) {
176       case PROP_BLOCK_DATA:
177       g_value_set_boolean (value, mytoggle->block_data);
178       break;
179     default:
180       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
181       break;
182   }
183 }
184
185 static gboolean
186 gst_mytoggle_start (GstBaseTransform * trans)
187 {
188   return TRUE;
189 }
190
191 static gboolean
192 gst_mytoggle_stop (GstBaseTransform * trans)
193 {
194   return TRUE;
195 }
196
197
198 static gboolean plugin_init(GstPlugin *plugin)
199 {
200
201         GST_DEBUG_CATEGORY_INIT (gst_mytoggle_debug, "toggle",0, "toggle");
202         return gst_element_register (plugin, "toggle",  GST_RANK_NONE, GST_TYPE_MYTOGGLE);
203 }
204 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
205         GST_VERSION_MINOR,
206         toggle,
207         "Base transform plugin template",
208         plugin_init, VERSION, "LGPL", "Samsung Electronics Co", "http://www.samsung.com/")
209         
210