~ubuntu-branches/ubuntu/natty/gst-entrans/natty

« back to all changes in this revision

Viewing changes to gst/y4m/gsty4mtrans.c

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2010-09-13 19:49:29 UTC
  • Revision ID: james.westby@ubuntu.com-20100913194929-qz90a14xyxln9yfz
Tags: upstream-0.10.2
ImportĀ upstreamĀ versionĀ 0.10.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GStreamer yuv (mjpegtools) runtime wrapper
 
2
 * Copyright (C) 2006 Mark Nauwelaerts <mnauw@users.sourceforge.net>
 
3
 *
 
4
 * gsty4mtrans.c: gstreamer yuv tool runtime wrapper
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
 
20
 */
 
21
 
 
22
/**
 
23
 * SECTION:element-y4mtrans
 
24
 *
 
25
 * <refsect2>
 
26
 * <para>
 
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.
 
31
 * </para>
 
32
 * </refsect2>
 
33
 *
 
34
 */
 
35
 
 
36
#ifdef HAVE_CONFIG_H
 
37
#include "config.h"
 
38
#endif
 
39
 
 
40
#include <gst/gst.h>
 
41
 
 
42
#include "gstproctrans.h"
 
43
 
 
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))
 
54
 
 
55
typedef struct _GstY4mTrans GstY4mTrans;
 
56
typedef struct _GstY4mTransClass GstY4mTransClass;
 
57
 
 
58
struct _GstY4mTrans {
 
59
  GstProcTrans parent;
 
60
 
 
61
  /* properties */
 
62
  gchar *args;
 
63
};
 
64
 
 
65
struct _GstY4mTransClass {
 
66
  GstProcTransClass parent_class;
 
67
};
 
68
 
 
69
GST_DEBUG_CATEGORY_STATIC (y4m_trans_debug);
 
70
#define GST_CAT_DEFAULT y4m_trans_debug
 
71
 
 
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>");
 
77
 
 
78
static GstStaticPadTemplate sink_template =
 
79
GST_STATIC_PAD_TEMPLATE (GST_PROC_TRANS_SINK_NAME,
 
80
    GST_PAD_SINK,
 
81
    GST_PAD_ALWAYS,
 
82
    GST_STATIC_CAPS ("application/x-yuv4mpeg, "
 
83
        "y4mversion = (int) 2 ")
 
84
    );
 
85
 
 
86
static GstStaticPadTemplate src_template =
 
87
GST_STATIC_PAD_TEMPLATE (GST_PROC_TRANS_SRC_NAME,
 
88
    GST_PAD_SRC,
 
89
    GST_PAD_ALWAYS,
 
90
    GST_STATIC_CAPS ("application/x-yuv4mpeg, "
 
91
        "y4mversion = (int) 2 ")
 
92
    );
 
93
 
 
94
/* properties */
 
95
enum
 
96
{
 
97
  PROP_0,
 
98
  PROP_ARGS
 
99
};
 
100
 
 
101
static gboolean gst_y4m_trans_set_caps (GstProcTrans * ptrans, GstCaps * incaps,
 
102
    GstCaps ** outcaps);
 
103
static GstStateChangeReturn gst_y4m_trans_change_state (GstElement * element,
 
104
    GstStateChange transition);
 
105
 
 
106
/* properties */
 
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);
 
111
 
 
112
static void gst_y4m_trans_finalize (GObject * object);
 
113
 
 
114
GST_BOILERPLATE (GstY4mTrans, gst_y4m_trans, GstProcTrans, GST_TYPE_PROC_TRANS);
 
115
 
 
116
static void
 
117
gst_y4m_trans_base_init (gpointer klass)
 
118
{
 
119
  GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
 
120
 
 
121
  gst_element_class_set_details (element_class, &gst_y4m_trans_details);
 
122
 
 
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));
 
127
}
 
128
 
 
129
static void
 
130
gst_y4m_trans_class_init (GstY4mTransClass * klass)
 
131
{
 
132
  GstElementClass *element_class;
 
133
  GObjectClass *gobject_class;
 
134
 
 
135
  gobject_class = G_OBJECT_CLASS (klass);
 
136
  element_class = GST_ELEMENT_CLASS (klass);
 
137
 
 
138
  GST_DEBUG_CATEGORY_INIT (y4m_trans_debug, "y4mtrans", 0, "y4m wrapper");
 
139
 
 
140
  gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_y4m_trans_finalize);
 
141
 
 
142
  gobject_class->set_property = gst_y4m_trans_set_property;
 
143
  gobject_class->get_property = gst_y4m_trans_get_property;
 
144
 
 
145
  g_object_class_install_property (gobject_class, PROP_ARGS,
 
146
      g_param_spec_string ("args", "Args", "Command arguments",
 
147
          NULL, G_PARAM_READWRITE));
 
148
 
 
149
  element_class->change_state = GST_DEBUG_FUNCPTR (gst_y4m_trans_change_state);
 
150
}
 
151
 
 
152
static void
 
153
gst_y4m_trans_init (GstY4mTrans * trans, GstY4mTransClass * klass )
 
154
{
 
155
  GstProcTransClass *proctransclass = GST_PROC_TRANS_CLASS (klass);
 
156
 
 
157
  proctransclass->set_caps = GST_DEBUG_FUNCPTR (gst_y4m_trans_set_caps);
 
158
 
 
159
  /* most properties are initialized by base element */
 
160
  trans->args = NULL;
 
161
}
 
162
 
 
163
static void
 
164
gst_y4m_trans_finalize (GObject * object)
 
165
{
 
166
  GstY4mTrans *trans = GST_Y4M_TRANS (object);
 
167
 
 
168
  g_free (trans->args);
 
169
 
 
170
  G_OBJECT_CLASS (parent_class)->finalize (object);
 
171
}
 
172
 
 
173
 
 
174
static gboolean
 
175
gst_y4m_trans_set_caps (GstProcTrans * ptrans, GstCaps * incaps,
 
176
    GstCaps ** outcaps)
 
177
{
 
178
  GstY4mTrans *trans = GST_Y4M_TRANS (ptrans);
 
179
  GstStructure *structure;
 
180
  gint version;
 
181
 
 
182
  structure = gst_caps_get_structure (incaps, 0);
 
183
 
 
184
  if (!(gst_structure_has_name (structure, "application/x-yuv4mpeg")
 
185
        && gst_structure_get_int (structure, "y4mversion", &version)
 
186
        && version == 2))
 
187
    return FALSE;
 
188
 
 
189
 
 
190
  if (trans->args) {
 
191
    gchar **args;
 
192
    gint nargs;
 
193
    GError *err = NULL;
 
194
 
 
195
    GST_INFO_OBJECT (trans, "parsing arguments %s", trans->args);
 
196
 
 
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));
 
202
      return FALSE;
 
203
    }
 
204
    g_array_append_vals (ptrans->args, args, nargs);
 
205
    /* only free the list of pointers, not their contents */
 
206
    g_free (args);
 
207
  }
 
208
 
 
209
  /* set the outgoing caps */
 
210
  *outcaps = gst_caps_new_simple ("application/x-yuv4mpeg",
 
211
      "y4mversion", G_TYPE_INT, 2, NULL);
 
212
 
 
213
  return TRUE;
 
214
}
 
215
 
 
216
static void
 
217
gst_y4m_trans_set_property (GObject * object, guint prop_id,
 
218
    const GValue * value, GParamSpec * pspec)
 
219
{
 
220
  GstY4mTrans *trans;
 
221
 
 
222
  g_return_if_fail (GST_IS_Y4M_TRANS (object));
 
223
 
 
224
  trans = GST_Y4M_TRANS (object);
 
225
 
 
226
  switch (prop_id) {
 
227
    case PROP_ARGS:
 
228
      g_free (trans->args);
 
229
      trans->args = g_value_dup_string (value);
 
230
      break;
 
231
    default:
 
232
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
233
      break;
 
234
  }
 
235
}
 
236
 
 
237
static void
 
238
gst_y4m_trans_get_property (GObject * object, guint prop_id, GValue * value,
 
239
    GParamSpec * pspec)
 
240
{
 
241
  GstY4mTrans *trans;
 
242
 
 
243
  g_return_if_fail (GST_IS_Y4M_TRANS (object));
 
244
 
 
245
  trans = GST_Y4M_TRANS (object);
 
246
 
 
247
  switch (prop_id) {
 
248
    case PROP_ARGS:
 
249
      g_value_take_string (value, g_strdup (trans->args));
 
250
      break;
 
251
    default:
 
252
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
253
      break;
 
254
  }
 
255
}
 
256
 
 
257
static GstStateChangeReturn
 
258
gst_y4m_trans_change_state (GstElement * element, GstStateChange transition)
 
259
{
 
260
  GstStateChangeReturn ret;
 
261
 
 
262
  ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
 
263
  if (ret == GST_STATE_CHANGE_FAILURE)
 
264
    goto done;
 
265
 
 
266
  switch (transition) {
 
267
    case GST_STATE_CHANGE_PAUSED_TO_READY:
 
268
      break;
 
269
    default:
 
270
      break;
 
271
  }
 
272
 
 
273
done:
 
274
  return ret;
 
275
}