1
/* GStreamer yuv (mjpegtools) runtime wrapper
2
* Copyright (C) 2006 Mark Nauwelaerts <mnauw@users.sourceforge.net>
4
* gsty4mtrans.c: gstreamer yuv tool runtime wrapper
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.
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.
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., 51 Franklin Street, Fifth Floor,
19
* Boston, MA 02110-1307, USA.
23
* SECTION:element-y4mtrans
27
* This filter is a special case of <link linkend="GstProcPipe">procpipe</link>,
28
* in as much that both the input to and output from the child process are
29
* in YUV4MPEG2 format, as e.g. used by various tools in the
30
* <ulink url="http://mjpeg.sourceforge.net/">mjpegtools</ulink> suite.
42
#include "gstproctrans.h"
44
#define GST_TYPE_Y4M_TRANS \
45
gst_y4m_trans_get_type ()
46
#define GST_Y4M_TRANS(obj) \
47
(G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_Y4M_TRANS, GstY4mTrans))
48
#define GST_Y4M_TRANS_CLASS(klass) \
49
(G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_Y4M_TRANS, GstY4mTransClass))
50
#define GST_IS_Y4M_TRANS(obj) \
51
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_Y4M_TRANS))
52
#define GST_IS_Y4M_TRANS_CLASS(klass) \
53
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_Y4M_TRANS))
55
typedef struct _GstY4mTrans GstY4mTrans;
56
typedef struct _GstY4mTransClass GstY4mTransClass;
65
struct _GstY4mTransClass {
66
GstProcTransClass parent_class;
69
GST_DEBUG_CATEGORY_STATIC (y4m_trans_debug);
70
#define GST_CAT_DEFAULT y4m_trans_debug
72
static GstElementDetails gst_y4m_trans_details =
73
GST_ELEMENT_DETAILS ("y4m runtime wrapper",
74
"Filter/Effect/Video",
75
"yuv/y4m mjpegtools runtime wrapper",
76
"Mark Nauwelaerts <mnauw@users.sourceforge.net>");
78
static GstStaticPadTemplate sink_template =
79
GST_STATIC_PAD_TEMPLATE (GST_PROC_TRANS_SINK_NAME,
82
GST_STATIC_CAPS ("application/x-yuv4mpeg, "
83
"y4mversion = (int) 2 ")
86
static GstStaticPadTemplate src_template =
87
GST_STATIC_PAD_TEMPLATE (GST_PROC_TRANS_SRC_NAME,
90
GST_STATIC_CAPS ("application/x-yuv4mpeg, "
91
"y4mversion = (int) 2 ")
101
static gboolean gst_y4m_trans_set_caps (GstProcTrans * ptrans, GstCaps * incaps,
103
static GstStateChangeReturn gst_y4m_trans_change_state (GstElement * element,
104
GstStateChange transition);
107
static void gst_y4m_trans_set_property (GObject * object,
108
guint prop_id, const GValue * value, GParamSpec * pspec);
109
static void gst_y4m_trans_get_property (GObject * object,
110
guint prop_id, GValue * value, GParamSpec * pspec);
112
static void gst_y4m_trans_finalize (GObject * object);
114
GST_BOILERPLATE (GstY4mTrans, gst_y4m_trans, GstProcTrans, GST_TYPE_PROC_TRANS);
117
gst_y4m_trans_base_init (gpointer klass)
119
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
121
gst_element_class_set_details (element_class, &gst_y4m_trans_details);
123
gst_element_class_add_pad_template (element_class,
124
gst_static_pad_template_get (&src_template));
125
gst_element_class_add_pad_template (element_class,
126
gst_static_pad_template_get (&sink_template));
130
gst_y4m_trans_class_init (GstY4mTransClass * klass)
132
GstElementClass *element_class;
133
GObjectClass *gobject_class;
135
gobject_class = G_OBJECT_CLASS (klass);
136
element_class = GST_ELEMENT_CLASS (klass);
138
GST_DEBUG_CATEGORY_INIT (y4m_trans_debug, "y4mtrans", 0, "y4m wrapper");
140
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_y4m_trans_finalize);
142
gobject_class->set_property = gst_y4m_trans_set_property;
143
gobject_class->get_property = gst_y4m_trans_get_property;
145
g_object_class_install_property (gobject_class, PROP_ARGS,
146
g_param_spec_string ("args", "Args", "Command arguments",
147
NULL, G_PARAM_READWRITE));
149
element_class->change_state = GST_DEBUG_FUNCPTR (gst_y4m_trans_change_state);
153
gst_y4m_trans_init (GstY4mTrans * trans, GstY4mTransClass * klass )
155
GstProcTransClass *proctransclass = GST_PROC_TRANS_CLASS (klass);
157
proctransclass->set_caps = GST_DEBUG_FUNCPTR (gst_y4m_trans_set_caps);
159
/* most properties are initialized by base element */
164
gst_y4m_trans_finalize (GObject * object)
166
GstY4mTrans *trans = GST_Y4M_TRANS (object);
168
g_free (trans->args);
170
G_OBJECT_CLASS (parent_class)->finalize (object);
175
gst_y4m_trans_set_caps (GstProcTrans * ptrans, GstCaps * incaps,
178
GstY4mTrans *trans = GST_Y4M_TRANS (ptrans);
179
GstStructure *structure;
182
structure = gst_caps_get_structure (incaps, 0);
184
if (!(gst_structure_has_name (structure, "application/x-yuv4mpeg")
185
&& gst_structure_get_int (structure, "y4mversion", &version)
195
GST_INFO_OBJECT (trans, "parsing arguments %s", trans->args);
197
if (!g_shell_parse_argv (trans->args, &nargs, &args, &err)) {
198
g_return_val_if_fail (err != NULL, FALSE);
199
GST_ELEMENT_ERROR (trans, RESOURCE, FAILED,
200
("glib error %s", err->message ? err->message : ""),
201
("parsing %s", trans->args));
204
g_array_append_vals (ptrans->args, args, nargs);
205
/* only free the list of pointers, not their contents */
209
/* set the outgoing caps */
210
*outcaps = gst_caps_new_simple ("application/x-yuv4mpeg",
211
"y4mversion", G_TYPE_INT, 2, NULL);
217
gst_y4m_trans_set_property (GObject * object, guint prop_id,
218
const GValue * value, GParamSpec * pspec)
222
g_return_if_fail (GST_IS_Y4M_TRANS (object));
224
trans = GST_Y4M_TRANS (object);
228
g_free (trans->args);
229
trans->args = g_value_dup_string (value);
232
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
238
gst_y4m_trans_get_property (GObject * object, guint prop_id, GValue * value,
243
g_return_if_fail (GST_IS_Y4M_TRANS (object));
245
trans = GST_Y4M_TRANS (object);
249
g_value_take_string (value, g_strdup (trans->args));
252
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
257
static GstStateChangeReturn
258
gst_y4m_trans_change_state (GstElement * element, GstStateChange transition)
260
GstStateChangeReturn ret;
262
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
263
if (ret == GST_STATE_CHANGE_FAILURE)
266
switch (transition) {
267
case GST_STATE_CHANGE_PAUSED_TO_READY: