2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
22 #include "gsty4mencode.h"
24 static GstElementDetails lavencode_details = {
27 "Encodes a YUV frame into the lav format (mjpeg_tools)",
29 "Wim Taymans <wim.taymans@chello.be>",
34 /* Filter signals and args */
44 GST_PADTEMPLATE_FACTORY (lavencode_src_factory,
55 GST_PADTEMPLATE_FACTORY (lavencode_sink_factory,
62 "format", GST_PROPS_FOURCC (GST_STR_FOURCC ("I420")),
63 "width", GST_PROPS_INT_RANGE (0, G_MAXINT),
64 "height", GST_PROPS_INT_RANGE (0, G_MAXINT)
68 static void gst_lavencode_class_init (GstLavEncodeClass *klass);
69 static void gst_lavencode_init (GstLavEncode *filter);
71 static void gst_lavencode_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
72 static void gst_lavencode_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
74 static void gst_lavencode_chain (GstPad *pad, GstBuffer *buf);
75 static GstElementStateReturn gst_lavencode_change_state (GstElement *element);
78 static GstElementClass *parent_class = NULL;
79 /*static guint gst_filter_signals[LAST_SIGNAL] = { 0 }; */
82 gst_lavencode_get_type(void) {
83 static GType lavencode_type = 0;
85 if (!lavencode_type) {
86 static const GTypeInfo lavencode_info = {
87 sizeof(GstLavEncodeClass), NULL,
89 (GClassInitFunc)gst_lavencode_class_init,
94 (GInstanceInitFunc)gst_lavencode_init,
96 lavencode_type = g_type_register_static(GST_TYPE_ELEMENT, "GstLavEncode", &lavencode_info, 0);
98 return lavencode_type;
102 gst_lavencode_class_init (GstLavEncodeClass *klass)
104 GObjectClass *gobject_class;
105 GstElementClass *gstelement_class;
107 gobject_class = (GObjectClass*)klass;
108 gstelement_class = (GstElementClass*)klass;
110 parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
112 gstelement_class->change_state = gst_lavencode_change_state;
114 gobject_class->set_property = gst_lavencode_set_property;
115 gobject_class->get_property = gst_lavencode_get_property;
118 static GstPadConnectReturn
119 gst_lavencode_sinkconnect (GstPad *pad, GstCaps *caps)
121 GstLavEncode *filter;
123 filter = GST_LAVENCODE (gst_pad_get_parent (pad));
125 if (!GST_CAPS_IS_FIXED (caps))
126 return GST_PAD_CONNECT_DELAYED;
128 gst_caps_get_int (caps, "width", &filter->width);
129 gst_caps_get_int (caps, "height", &filter->height);
131 return GST_PAD_CONNECT_OK;
135 gst_lavencode_init (GstLavEncode *filter)
137 filter->sinkpad = gst_pad_new_from_template(
138 GST_PADTEMPLATE_GET (lavencode_sink_factory), "sink");
139 gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
140 gst_pad_set_chain_function (filter->sinkpad, gst_lavencode_chain);
141 gst_pad_set_connect_function (filter->sinkpad, gst_lavencode_sinkconnect);
143 filter->srcpad = gst_pad_new_from_template(
144 GST_PADTEMPLATE_GET (lavencode_src_factory), "src");
145 gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
151 gst_lavencode_chain (GstPad *pad,GstBuffer *buf)
153 GstLavEncode *filter;
158 g_return_if_fail(pad != NULL);
159 g_return_if_fail(GST_IS_PAD(pad));
160 g_return_if_fail(buf != NULL);
162 filter = GST_LAVENCODE (gst_pad_get_parent (pad));
163 g_return_if_fail(filter != NULL);
164 g_return_if_fail(GST_IS_LAVENCODE(filter));
166 outbuf = gst_buffer_new ();
167 GST_BUFFER_DATA (outbuf) = g_malloc (GST_BUFFER_SIZE (buf) + 256);
170 header = "YUV4MPEG %d %d %d\nFRAME\n";
171 filter->init = FALSE;
177 snprintf (GST_BUFFER_DATA (outbuf), 255, header, filter->width, filter->height, 3);
178 len = strlen (GST_BUFFER_DATA (outbuf));
180 memcpy (GST_BUFFER_DATA (outbuf) + len, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
181 GST_BUFFER_SIZE (outbuf) = GST_BUFFER_SIZE (buf) + len;
183 gst_buffer_unref(buf);
185 gst_pad_push(filter->srcpad,outbuf);
189 gst_lavencode_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
191 GstLavEncode *filter;
193 /* it's not null if we got it, but it might not be ours */
194 g_return_if_fail(GST_IS_LAVENCODE(object));
195 filter = GST_LAVENCODE(object);
204 gst_lavencode_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
206 GstLavEncode *filter;
208 /* it's not null if we got it, but it might not be ours */
209 g_return_if_fail(GST_IS_LAVENCODE(object));
210 filter = GST_LAVENCODE(object);
214 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
219 static GstElementStateReturn
220 gst_lavencode_change_state (GstElement *element)
222 GstLavEncode *filter;
224 g_return_val_if_fail (GST_IS_LAVENCODE (element), GST_STATE_FAILURE);
226 filter = GST_LAVENCODE(element);
228 if (GST_STATE_TRANSITION (element) == GST_STATE_NULL_TO_READY) {
232 if (GST_ELEMENT_CLASS (parent_class)->change_state)
233 return GST_ELEMENT_CLASS (parent_class)->change_state (element);
235 return GST_STATE_SUCCESS;
239 plugin_init (GModule *module, GstPlugin *plugin)
241 GstElementFactory *factory;
243 factory = gst_elementfactory_new("lavencode",GST_TYPE_LAVENCODE,
245 g_return_val_if_fail(factory != NULL, FALSE);
247 gst_elementfactory_add_padtemplate (factory,
248 GST_PADTEMPLATE_GET (lavencode_src_factory));
249 gst_elementfactory_add_padtemplate (factory,
250 GST_PADTEMPLATE_GET (lavencode_sink_factory));
252 gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
257 GstPluginDesc plugin_desc = {