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

« back to all changes in this revision

Viewing changes to gst/transcode/gstrbswap.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 Element
 
2
 * Copyright (C) 2006 Mark Nauwelaerts <mnauw@users.sourceforge.net>
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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., 51 Franklin Street, Fifth Floor,
 
17
 * Boston, MA 02110-1307, USA.
 
18
 */
 
19
 
 
20
/**
 
21
 * SECTION:element-rbswap
 
22
 *
 
23
 * <refsect2>
 
24
 * <para>
 
25
 * Swaps red (Cr) and blue (Cb) in video frames.
 
26
 * This should rarely be needed, but may be required in unusual cases,
 
27
 * e.g. if people have blue faces.
 
28
 * </para>
 
29
 * <title>History</title>
 
30
 * <para>
 
31
 * <itemizedlist>
 
32
 * <listitem>
 
33
 * It is akin to transcode's rgbswap [Thomas Oestreich]
 
34
 * </listitem>
 
35
 * <listitem>
 
36
 * Similar basic operation also available in e.g. mplayer's swapuv, etc
 
37
 * </listitem>
 
38
 * </itemizedlist>
 
39
 * </para>
 
40
 * </refsect2>
 
41
 *
 
42
 */
 
43
 
 
44
 
 
45
#ifdef HAVE_CONFIG_H
 
46
#include "config.h"
 
47
#endif
 
48
 
 
49
#include "plugin-tc.h"
 
50
 
 
51
#include <string.h>
 
52
 
 
53
 
 
54
#define GST_TYPE_RB_SWAP \
 
55
  (gst_rb_swap_get_type())
 
56
#define GST_RB_SWAP(obj) \
 
57
  (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_RB_SWAP,GstRbSwap))
 
58
#define GST_RB_SWAP_CLASS(klass) \
 
59
  (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_RB_SWAP,GstRbSwapClass))
 
60
#define GST_IS_RB_SWAP(obj) \
 
61
  (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_RB_SWAP))
 
62
#define GST_IS_RB_SWAP_CLASS(klass) \
 
63
  (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_RB_SWAP))
 
64
 
 
65
 
 
66
typedef struct _GstRbSwap GstRbSwap;
 
67
typedef struct _GstRbSwapClass GstRbSwapClass;
 
68
 
 
69
struct _GstRbSwap
 
70
{
 
71
  GstVideoFilter videofilter;
 
72
 
 
73
  gint width, height;
 
74
 
 
75
  /* properties */
 
76
  guint delay;
 
77
};
 
78
 
 
79
 
 
80
struct _GstRbSwapClass
 
81
{
 
82
  GstVideoFilterClass parent_class;
 
83
};
 
84
 
 
85
GST_DEBUG_CATEGORY_STATIC (rb_swap_debug);
 
86
#define GST_CAT_DEFAULT rb_swap_debug
 
87
 
 
88
 
 
89
/* signals and args */
 
90
enum
 
91
{
 
92
  /* FILL ME */
 
93
  LAST_SIGNAL
 
94
};
 
95
 
 
96
enum
 
97
{
 
98
  PROP_0,
 
99
  PROP_DELAY
 
100
      /* FILL ME */
 
101
};
 
102
 
 
103
#define DEFAULT_DELAY    0
 
104
 
 
105
static GstElementDetails rb_swap_details =
 
106
GST_ELEMENT_DETAILS ("Rbswap",
 
107
    "Filter/Effect/Video",
 
108
    "Swap red and blue components",
 
109
    "Mark Nauwelaerts <mnauw@users.sourceforge.net>");
 
110
 
 
111
static GstStaticPadTemplate gst_rb_swap_src_template =
 
112
GST_STATIC_PAD_TEMPLATE (GST_BASE_TRANSFORM_SRC_NAME,
 
113
    GST_PAD_SRC,
 
114
    GST_PAD_ALWAYS,
 
115
    GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("{ IYUV, I420, YV12 }"))
 
116
    );
 
117
 
 
118
static GstStaticPadTemplate gst_rb_swap_sink_template =
 
119
GST_STATIC_PAD_TEMPLATE (GST_BASE_TRANSFORM_SINK_NAME,
 
120
    GST_PAD_SINK,
 
121
    GST_PAD_ALWAYS,
 
122
    GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("{ IYUV, I420, YV12 }"))
 
123
    );
 
124
 
 
125
 
 
126
static GstCaps* gst_rb_swap_transform_caps (GstBaseTransform * trans,
 
127
    GstPadDirection direction, GstCaps * caps);
 
128
static GstFlowReturn gst_rb_swap_transform_ip (GstBaseTransform * btrans,
 
129
    GstBuffer * in);
 
130
 
 
131
static void gst_rb_swap_set_property (GObject * object, guint prop_id,
 
132
    const GValue * value, GParamSpec * pspec);
 
133
static void gst_rb_swap_get_property (GObject * object, guint prop_id,
 
134
    GValue * value, GParamSpec * pspec);
 
135
 
 
136
GST_BOILERPLATE (GstRbSwap, gst_rb_swap, GstVideoFilter, GST_TYPE_VIDEO_FILTER);
 
137
 
 
138
GST_VIDEO_FILTER_GET_UNIT_SIZE_BOILERPLATE (gst_rb_swap);
 
139
 
 
140
static void
 
141
gst_rb_swap_base_init (gpointer g_class)
 
142
{
 
143
  GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
 
144
 
 
145
  gst_element_class_set_details (element_class, &rb_swap_details);
 
146
 
 
147
  gst_element_class_add_pad_template (element_class,
 
148
      gst_static_pad_template_get (&gst_rb_swap_sink_template));
 
149
  gst_element_class_add_pad_template (element_class,
 
150
      gst_static_pad_template_get (&gst_rb_swap_src_template));
 
151
}
 
152
 
 
153
static void
 
154
gst_rb_swap_class_init (GstRbSwapClass * g_class)
 
155
{
 
156
  GObjectClass *gobject_class;
 
157
  GstBaseTransformClass *trans_class;
 
158
 
 
159
  gobject_class = G_OBJECT_CLASS (g_class);
 
160
  trans_class = GST_BASE_TRANSFORM_CLASS (g_class);
 
161
 
 
162
  GST_DEBUG_CATEGORY_INIT (rb_swap_debug, "rbswap", 0, "rbswap");
 
163
 
 
164
  gobject_class->set_property = gst_rb_swap_set_property;
 
165
  gobject_class->get_property = gst_rb_swap_get_property;
 
166
 
 
167
  trans_class->get_unit_size = GST_DEBUG_FUNCPTR (gst_rb_swap_get_unit_size);
 
168
  trans_class->transform_caps = GST_DEBUG_FUNCPTR (gst_rb_swap_transform_caps);
 
169
  /* dummy seems needed */
 
170
  trans_class->transform_ip = GST_DEBUG_FUNCPTR (gst_rb_swap_transform_ip);
 
171
}
 
172
 
 
173
static void
 
174
gst_rb_swap_init (GstRbSwap * filter, GstRbSwapClass * g_class)
 
175
{
 
176
 
 
177
}
 
178
 
 
179
static GstCaps *
 
180
gst_rb_swap_transform_caps (GstBaseTransform * trans,
 
181
    GstPadDirection direction, GstCaps * caps)
 
182
{
 
183
  GstCaps *ret;
 
184
  GstStructure *structure;
 
185
  guint32 fourcc;
 
186
 
 
187
  GST_DEBUG_OBJECT (trans, "receiving caps: %" GST_PTR_FORMAT, caps);
 
188
 
 
189
  ret = gst_caps_copy (caps);
 
190
 
 
191
  /* this function is always called with a simple caps */
 
192
  g_return_val_if_fail (GST_CAPS_IS_SIMPLE (ret), NULL);
 
193
 
 
194
  structure = gst_caps_get_structure (ret, 0);
 
195
 
 
196
  gst_structure_get_fourcc (structure, "format", &fourcc);
 
197
  switch (fourcc) {
 
198
    case GST_MAKE_FOURCC ('I', '4', '2', '0'):
 
199
    case GST_MAKE_FOURCC ('I', 'Y', 'U', 'V'):
 
200
      GST_DEBUG ("I420");
 
201
      fourcc = GST_MAKE_FOURCC ('Y', 'V', '1', '2');
 
202
      break;
 
203
    case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
 
204
      GST_DEBUG ("YV12");
 
205
      fourcc = GST_MAKE_FOURCC ('I', '4', '2', '0');
 
206
      break;
 
207
    default:
 
208
      g_return_val_if_reached (NULL);
 
209
      break;
 
210
  }
 
211
 
 
212
  gst_structure_set (structure, "format", GST_TYPE_FOURCC, fourcc, NULL);
 
213
 
 
214
  GST_DEBUG_OBJECT (trans, "returning caps: %" GST_PTR_FORMAT, ret);
 
215
 
 
216
  return ret;
 
217
}
 
218
 
 
219
static GstFlowReturn
 
220
gst_rb_swap_transform_ip (GstBaseTransform * btrans, GstBuffer * in)
 
221
{
 
222
  return GST_FLOW_OK;
 
223
}
 
224
 
 
225
static void
 
226
gst_rb_swap_set_property (GObject * object, guint prop_id,
 
227
    const GValue * value, GParamSpec * pspec)
 
228
{
 
229
  GstRbSwap *src;
 
230
 
 
231
  g_return_if_fail (GST_IS_RB_SWAP (object));
 
232
  src = GST_RB_SWAP (object);
 
233
 
 
234
  switch (prop_id) {
 
235
    default:
 
236
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
237
      break;
 
238
  }
 
239
}
 
240
 
 
241
static void
 
242
gst_rb_swap_get_property (GObject * object, guint prop_id, GValue * value,
 
243
    GParamSpec * pspec)
 
244
{
 
245
  GstRbSwap *src;
 
246
 
 
247
  g_return_if_fail (GST_IS_RB_SWAP (object));
 
248
  src = GST_RB_SWAP (object);
 
249
 
 
250
  switch (prop_id) {
 
251
    default:
 
252
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
253
      break;
 
254
  }
 
255
}