2
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3
* Copyright (C) <2003> David Schleef <ds@schleef.org>
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Library General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Library General Public License for more details.
15
* You should have received a copy of the GNU Library General Public
16
* License along with this library; if not, write to the
17
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
* Boston, MA 02111-1307, USA.
22
* This file was (probably) generated from
23
* gstvideotemplate.c,v 1.18 2005/11/14 02:13:34 thomasvs Exp
25
* $Id: make_filter,v 1.8 2004/04/19 22:51:57 ds Exp $
33
#include <gst/base/gstbasetransform.h>
34
#include <gst/video/video.h>
38
#include <cog/cogvirtframe.h>
40
#define GST_TYPE_COGDOWNSAMPLE \
41
(gst_cogdownsample_get_type())
42
#define GST_COGDOWNSAMPLE(obj) \
43
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_COGDOWNSAMPLE,GstCogdownsample))
44
#define GST_COGDOWNSAMPLE_CLASS(klass) \
45
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_COGDOWNSAMPLE,GstCogdownsampleClass))
46
#define GST_IS_COGDOWNSAMPLE(obj) \
47
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_COGDOWNSAMPLE))
48
#define GST_IS_COGDOWNSAMPLE_CLASS(obj) \
49
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_COGDOWNSAMPLE))
51
typedef struct _GstCogdownsample GstCogdownsample;
52
typedef struct _GstCogdownsampleClass GstCogdownsampleClass;
54
struct _GstCogdownsample
56
GstBaseTransform base_transform;
60
struct _GstCogdownsampleClass
62
GstBaseTransformClass parent_class;
66
GType gst_cogdownsample_get_type (void);
68
/* GstCogdownsample signals and args */
83
static void gst_cogdownsample_base_init (gpointer g_class);
84
static void gst_cogdownsample_class_init (gpointer g_class,
86
static void gst_cogdownsample_init (GTypeInstance * instance, gpointer g_class);
88
static void gst_cogdownsample_set_property (GObject * object, guint prop_id,
89
const GValue * value, GParamSpec * pspec);
90
static void gst_cogdownsample_get_property (GObject * object, guint prop_id,
91
GValue * value, GParamSpec * pspec);
93
static GstCaps *gst_cogdownsample_transform_caps (GstBaseTransform *
94
base_transform, GstPadDirection direction, GstCaps * caps);
95
static GstFlowReturn gst_cogdownsample_transform (GstBaseTransform *
96
base_transform, GstBuffer * inbuf, GstBuffer * outbuf);
97
static gboolean gst_cogdownsample_get_unit_size (GstBaseTransform *
98
base_transform, GstCaps * caps, guint * size);
100
static GstStaticPadTemplate gst_cogdownsample_sink_template =
101
GST_STATIC_PAD_TEMPLATE ("sink",
104
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("{ I420, YV12, YUY2, UYVY, AYUV }"))
107
static GstStaticPadTemplate gst_cogdownsample_src_template =
108
GST_STATIC_PAD_TEMPLATE ("src",
111
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("{ I420, YV12, YUY2, UYVY, AYUV }"))
115
gst_cogdownsample_get_type (void)
117
static GType compress_type = 0;
119
if (!compress_type) {
120
static const GTypeInfo compress_info = {
121
sizeof (GstCogdownsampleClass),
122
gst_cogdownsample_base_init,
124
gst_cogdownsample_class_init,
127
sizeof (GstCogdownsample),
129
gst_cogdownsample_init,
132
compress_type = g_type_register_static (GST_TYPE_BASE_TRANSFORM,
133
"GstCogdownsample", &compress_info, 0);
135
return compress_type;
140
gst_cogdownsample_base_init (gpointer g_class)
142
static GstElementDetails compress_details =
143
GST_ELEMENT_DETAILS ("Downsample video",
144
"Filter/Effect/Video",
145
"Decreases size of video by a factor of 2",
146
"David Schleef <ds@schleef.org>");
147
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
149
gst_element_class_add_pad_template (element_class,
150
gst_static_pad_template_get (&gst_cogdownsample_src_template));
151
gst_element_class_add_pad_template (element_class,
152
gst_static_pad_template_get (&gst_cogdownsample_sink_template));
154
gst_element_class_set_details (element_class, &compress_details);
158
gst_cogdownsample_class_init (gpointer g_class, gpointer class_data)
160
GObjectClass *gobject_class;
161
GstBaseTransformClass *base_transform_class;
162
GstCogdownsampleClass *downsample_class;
164
gobject_class = G_OBJECT_CLASS (g_class);
165
base_transform_class = GST_BASE_TRANSFORM_CLASS (g_class);
166
downsample_class = GST_COGDOWNSAMPLE_CLASS (g_class);
168
gobject_class->set_property = gst_cogdownsample_set_property;
169
gobject_class->get_property = gst_cogdownsample_get_property;
172
g_object_class_install_property (gobject_class, ARG_WAVELET_TYPE,
173
g_param_spec_int ("wavelet-type", "wavelet type", "wavelet type",
174
0, 4, 0, G_PARAM_READWRITE));
175
g_object_class_install_property (gobject_class, ARG_LEVEL,
176
g_param_spec_int ("level", "level", "level",
177
0, 100, 0, G_PARAM_READWRITE));
180
base_transform_class->transform = gst_cogdownsample_transform;
181
base_transform_class->transform_caps = gst_cogdownsample_transform_caps;
182
base_transform_class->get_unit_size = gst_cogdownsample_get_unit_size;
186
gst_cogdownsample_init (GTypeInstance * instance, gpointer g_class)
189
GST_DEBUG ("gst_cogdownsample_init");
193
gst_cogdownsample_set_property (GObject * object, guint prop_id,
194
const GValue * value, GParamSpec * pspec)
196
GstCogdownsample *src;
198
g_return_if_fail (GST_IS_COGDOWNSAMPLE (object));
199
src = GST_COGDOWNSAMPLE (object);
201
GST_DEBUG ("gst_cogdownsample_set_property");
209
gst_cogdownsample_get_property (GObject * object, guint prop_id, GValue * value,
212
GstCogdownsample *src;
214
g_return_if_fail (GST_IS_COGDOWNSAMPLE (object));
215
src = GST_COGDOWNSAMPLE (object);
219
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
225
transform_value (GValue * dest, const GValue * src, GstPadDirection dir)
227
g_value_init (dest, G_VALUE_TYPE (src));
229
if (G_VALUE_HOLDS_INT (src)) {
232
x = g_value_get_int (src);
233
if (dir == GST_PAD_SINK) {
234
g_value_set_int (dest, x / 2);
236
g_value_set_int (dest, x * 2);
238
} else if (GST_VALUE_HOLDS_INT_RANGE (src)) {
241
min = gst_value_get_int_range_min (src);
242
max = gst_value_get_int_range_max (src);
244
if (dir == GST_PAD_SINK) {
246
if (max == G_MAXINT) {
252
if (max > G_MAXINT / 2) {
257
if (min > G_MAXINT / 2) {
263
gst_value_set_int_range (dest, min, max);
266
g_warning ("case not handled");
267
g_value_set_int (dest, 100);
272
gst_cogdownsample_transform_caps (GstBaseTransform * base_transform,
273
GstPadDirection direction, GstCaps * caps)
276
GstStructure *structure;
277
GValue new_value = { 0 };
280
caps = gst_caps_copy (caps);
282
for (i = 0; i < gst_caps_get_size (caps); i++) {
283
structure = gst_caps_get_structure (caps, i);
285
value = gst_structure_get_value (structure, "width");
286
transform_value (&new_value, value, direction);
287
gst_structure_set_value (structure, "width", &new_value);
288
g_value_unset (&new_value);
290
value = gst_structure_get_value (structure, "height");
291
transform_value (&new_value, value, direction);
292
gst_structure_set_value (structure, "height", &new_value);
293
g_value_unset (&new_value);
300
gst_cogdownsample_get_unit_size (GstBaseTransform * base_transform,
301
GstCaps * caps, guint * size)
306
gst_structure_get_fourcc (gst_caps_get_structure (caps, 0),
308
gst_structure_get_int (gst_caps_get_structure (caps, 0), "width", &width);
309
gst_structure_get_int (gst_caps_get_structure (caps, 0), "height", &height);
312
case GST_MAKE_FOURCC ('I', '4', '2', '0'):
313
case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
314
*size = width * height * 3 / 2;
316
case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
317
case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
318
*size = width * height * 2;
320
case GST_MAKE_FOURCC ('A', 'Y', 'U', 'V'):
321
*size = width * height * 4;
324
g_assert_not_reached ();
331
gst_cogdownsample_transform (GstBaseTransform * base_transform,
332
GstBuffer * inbuf, GstBuffer * outbuf)
334
GstCogdownsample *compress;
340
g_return_val_if_fail (GST_IS_COGDOWNSAMPLE (base_transform), GST_FLOW_ERROR);
341
compress = GST_COGDOWNSAMPLE (base_transform);
343
gst_structure_get_fourcc (gst_caps_get_structure (inbuf->caps, 0),
345
gst_structure_get_int (gst_caps_get_structure (inbuf->caps, 0),
347
gst_structure_get_int (gst_caps_get_structure (inbuf->caps, 0),
351
case GST_MAKE_FOURCC ('I', '4', '2', '0'):
352
frame = cog_frame_new_from_data_I420 (GST_BUFFER_DATA (inbuf),
354
outframe = cog_frame_new_from_data_I420 (GST_BUFFER_DATA (outbuf),
355
width / 2, height / 2);
357
case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
358
frame = cog_frame_new_from_data_YV12 (GST_BUFFER_DATA (inbuf),
360
outframe = cog_frame_new_from_data_YV12 (GST_BUFFER_DATA (outbuf),
361
width / 2, height / 2);
363
case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
364
frame = cog_frame_new_from_data_YUY2 (GST_BUFFER_DATA (inbuf),
366
outframe = cog_frame_new_from_data_YUY2 (GST_BUFFER_DATA (outbuf),
367
width / 2, height / 2);
369
case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
370
frame = cog_frame_new_from_data_UYVY (GST_BUFFER_DATA (inbuf),
372
outframe = cog_frame_new_from_data_UYVY (GST_BUFFER_DATA (outbuf),
373
width / 2, height / 2);
375
case GST_MAKE_FOURCC ('A', 'Y', 'U', 'V'):
376
frame = cog_frame_new_from_data_AYUV (GST_BUFFER_DATA (inbuf),
378
outframe = cog_frame_new_from_data_AYUV (GST_BUFFER_DATA (outbuf),
379
width / 2, height / 2);
382
g_assert_not_reached ();
385
frame = cog_virt_frame_new_unpack (frame);
386
frame = cog_virt_frame_new_horiz_downsample (frame, 3);
387
frame = cog_virt_frame_new_vert_downsample (frame, 2);
390
case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
391
frame = cog_virt_frame_new_pack_YUY2 (frame);
393
case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
394
frame = cog_virt_frame_new_pack_UYVY (frame);
396
case GST_MAKE_FOURCC ('A', 'Y', 'U', 'V'):
397
frame = cog_virt_frame_new_pack_AYUV (frame);
403
cog_virt_frame_render (frame, outframe);
404
cog_frame_unref (frame);
405
cog_frame_unref (outframe);