tizen 2.3.1 release
[framework/multimedia/gst-plugins-ext0.10.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 #include <gst/gstmarshal.h>
32
33 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
34     GST_PAD_SINK,
35     GST_PAD_ALWAYS,
36     GST_STATIC_CAPS_ANY);
37
38 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
39     GST_PAD_SRC,
40     GST_PAD_ALWAYS,
41     GST_STATIC_CAPS_ANY);
42
43 GST_DEBUG_CATEGORY_STATIC (gst_mytoggle_debug);
44 #define GST_CAT_DEFAULT gst_mytoggle_debug
45
46 enum
47 {
48   LAST_SIGNAL
49 };
50
51
52 #define DEFAULT_BLOCK_DATA        FALSE
53
54 enum
55 {
56   PROP_0,
57   PROP_BLOCK_DATA
58  
59 };
60
61
62 #define _do_init(bla) \
63     GST_DEBUG_CATEGORY_INIT (gst_mytoggle_debug, "toggle", 0, "toggle element");
64
65 GST_BOILERPLATE_FULL (GstMytoggle, gst_mytoggle, GstBaseTransform,
66     GST_TYPE_BASE_TRANSFORM, _do_init);
67
68 static void gst_mytoggle_finalize (GObject * object);
69 static void gst_mytoggle_set_property (GObject * object, guint prop_id,
70     const GValue * value, GParamSpec * pspec);
71 static void gst_mytoggle_get_property (GObject * object, guint prop_id,
72     GValue * value, GParamSpec * pspec);
73
74 static gboolean gst_mytoggle_event (GstBaseTransform * trans, GstEvent * event);
75 static GstFlowReturn gst_mytoggle_transform_ip (GstBaseTransform * trans,
76     GstBuffer * buf);
77 static gboolean gst_mytoggle_start (GstBaseTransform * trans);
78 static gboolean gst_mytoggle_stop (GstBaseTransform * trans);
79
80 static void
81 gst_mytoggle_base_init (gpointer g_class)
82 {
83   GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
84
85   gst_element_class_set_details_simple (gstelement_class,
86       "toggle",
87       "Generic",
88       "Pass data without modification", "Rahul Mittal <mittal.rahul@samsung.com>");
89   gst_element_class_add_pad_template (gstelement_class,
90       gst_static_pad_template_get (&srctemplate));
91   gst_element_class_add_pad_template (gstelement_class,
92       gst_static_pad_template_get (&sinktemplate));
93 }
94
95 static void
96 gst_mytoggle_finalize (GObject * object)
97 {
98   GstMytoggle *mytoggle;
99
100   G_OBJECT_CLASS (parent_class)->finalize (object);
101 }
102
103 static void
104 gst_mytoggle_class_init (GstMytoggleClass * klass)
105 {
106   GObjectClass *gobject_class;
107   GstBaseTransformClass *gstbasetrans_class;
108
109   gobject_class = G_OBJECT_CLASS (klass);
110   gstbasetrans_class = GST_BASE_TRANSFORM_CLASS (klass);
111
112   gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_mytoggle_set_property);
113   gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_mytoggle_get_property);
114
115   g_object_class_install_property (gobject_class,
116       PROP_BLOCK_DATA, g_param_spec_boolean ("block_data",
117           "Data Block",
118           "Data Block", 
119           DEFAULT_BLOCK_DATA, G_PARAM_READWRITE));
120     
121   gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_mytoggle_finalize);
122
123   gstbasetrans_class->event = GST_DEBUG_FUNCPTR (gst_mytoggle_event);
124   gstbasetrans_class->transform_ip =
125       GST_DEBUG_FUNCPTR (gst_mytoggle_transform_ip);
126   gstbasetrans_class->start = GST_DEBUG_FUNCPTR (gst_mytoggle_start);
127   gstbasetrans_class->stop = GST_DEBUG_FUNCPTR (gst_mytoggle_stop);
128 }
129
130 static void
131 gst_mytoggle_init (GstMytoggle * mytoggle, GstMytoggleClass * g_class)
132 {
133   gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (mytoggle), TRUE);
134
135   mytoggle->block_data = DEFAULT_BLOCK_DATA;
136
137 }
138
139
140 static gboolean
141 gst_mytoggle_event (GstBaseTransform * trans, GstEvent * event)
142 {
143   return TRUE;
144 }
145
146 static GstFlowReturn
147 gst_mytoggle_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
148 {
149   GstMytoggle *mytoggle = GST_MYTOGGLE (trans);
150  
151   if (mytoggle->block_data ==TRUE) 
152       return GST_BASE_TRANSFORM_FLOW_DROPPED;
153
154   return GST_FLOW_OK;
155 }
156
157 static void
158 gst_mytoggle_set_property (GObject * object, guint prop_id,
159     const GValue * value, GParamSpec * pspec)
160 {
161   GstMytoggle *mytoggle;
162
163   mytoggle = GST_MYTOGGLE (object);
164
165   switch (prop_id) {
166   
167     case PROP_BLOCK_DATA:
168       mytoggle->block_data = g_value_get_boolean (value);
169       break;
170     default:
171       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
172       break;
173   }
174 }
175
176 static void
177 gst_mytoggle_get_property (GObject * object, guint prop_id, GValue * value,
178     GParamSpec * pspec)
179 {
180   GstMytoggle *mytoggle;
181
182   mytoggle = GST_MYTOGGLE (object);
183
184   switch (prop_id) {
185       case PROP_BLOCK_DATA:
186       g_value_set_boolean (value, mytoggle->block_data);
187       break;
188     default:
189       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
190       break;
191   }
192 }
193
194 static gboolean
195 gst_mytoggle_start (GstBaseTransform * trans)
196 {
197   return TRUE;
198 }
199
200 static gboolean
201 gst_mytoggle_stop (GstBaseTransform * trans)
202 {
203   return TRUE;
204 }
205
206
207 static gboolean plugin_init(GstPlugin *plugin)
208 {
209
210         GST_DEBUG_CATEGORY_INIT (gst_mytoggle_debug, "toggle",0, "toggle");
211         return gst_element_register (plugin, "toggle",  GST_RANK_NONE, GST_TYPE_MYTOGGLE);
212 }
213 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
214         GST_VERSION_MINOR,
215         "toggle",
216         "Base transform plugin template",
217         plugin_init, VERSION, "LGPL", "Samsung Electronics Co", "http://www.samsung.com/")
218         
219