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

« back to all changes in this revision

Viewing changes to gst-libs/gst/video/video-utils.h

  • 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 video utils
 
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:video-utils
 
22
 * @short_description: Useful boilerplate for video filters
 
23
 */
 
24
 
 
25
#ifndef __GST_VIDEO_UTILS_H__
 
26
#define __GST_VIDEO_UTILS_H__
 
27
 
 
28
 
 
29
G_BEGIN_DECLS
 
30
 
 
31
/**
 
32
 * GST_VIDEO_FILTER_SET_CAPS_BOILERPLATE_FULL:
 
33
 * @type:             the name of the type struct
 
34
 * @type_as_function: the prefix for the functions
 
35
 * @hook_function:    a function with #GstBaseTransform set_caps signature
 
36
 *                    that can extract custom additional info or accept/reject caps
 
37
 *
 
38
 * Define a typical set_caps function for a video filter,
 
39
 * allowing for additional custom verification and initialization.
 
40
 */
 
41
#define GST_VIDEO_FILTER_SET_CAPS_BOILERPLATE_FULL(type, type_as_function, hook_function)  \
 
42
static gboolean \
 
43
type_as_function ## _set_caps (GstBaseTransform * btrans, GstCaps * incaps, \
 
44
    GstCaps * outcaps) \
 
45
{ \
 
46
  type *filter = (type *) (btrans); \
 
47
  GstStructure *structure;  \
 
48
  gboolean ret = FALSE; \
 
49
\
 
50
  structure = gst_caps_get_structure (incaps, 0); \
 
51
\
 
52
  if (gst_structure_get_int (structure, "width", &filter->width) && \
 
53
      gst_structure_get_int (structure, "height", &filter->height)) { \
 
54
    ret = hook_function (filter, incaps, outcaps); \
 
55
  } \
 
56
\
 
57
  return ret;\
 
58
}
 
59
 
 
60
 
 
61
#define __GST_NO_HOOK(filter, incaps, outcaps)  TRUE
 
62
 
 
63
/**
 
64
 * GST_VIDEO_FILTER_SET_CAPS_BOILERPLATE:
 
65
 * @type:             the name of the type struct
 
66
 * @type_as_function: the prefix for the functions
 
67
 *
 
68
 * Define a typical set_caps function for a video filter.
 
69
 */
 
70
#define GST_VIDEO_FILTER_SET_CAPS_BOILERPLATE(type, type_as_function)  \
 
71
  GST_VIDEO_FILTER_SET_CAPS_BOILERPLATE_FULL(type, type_as_function, \
 
72
    __GST_NO_HOOK)
 
73
 
 
74
 
 
75
/**
 
76
 * GST_VIDEO_FILTER_GET_UNIT_SIZE_BOILERPLATE:
 
77
 * @type_as_function: the prefix for the functions
 
78
 *
 
79
 * Define a typical get_unit_size function for a video filter that provides
 
80
 * proper unit size for x-raw-rgb and some standard x-raw-yuv
 
81
 * colorspaces (YUY2, YUYV, YVYU, IYUV, I420, YV12).
 
82
 */
 
83
#define GST_VIDEO_FILTER_GET_UNIT_SIZE_BOILERPLATE(type_as_function)  \
 
84
static gboolean \
 
85
type_as_function ## _get_unit_size (GstBaseTransform * btrans, GstCaps * caps, \
 
86
    guint * size) \
 
87
{ \
 
88
  GstStructure *structure; \
 
89
  gboolean ret = FALSE; \
 
90
  gint width, height; \
 
91
 \
 
92
  structure = gst_caps_get_structure (caps, 0); \
 
93
 \
 
94
  if (gst_structure_get_int (structure, "width", &width) && \
 
95
      gst_structure_get_int (structure, "height", &height)) { \
 
96
    if (gst_structure_has_name (structure, "video/x-raw-rgb")) { \
 
97
      gint bpp; \
 
98
 \
 
99
      if (gst_structure_get_int (structure, "bpp", &bpp)) { \
 
100
        ret = TRUE; \
 
101
        *size = width * height * bpp / 8; \
 
102
      } \
 
103
    } \
 
104
    else { \
 
105
      guint32 fourcc; \
 
106
 \
 
107
      if (gst_structure_get_fourcc (structure, "format", &fourcc)) { \
 
108
        ret = TRUE; \
 
109
        switch (fourcc) { \
 
110
          case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'): \
 
111
          case GST_MAKE_FOURCC ('Y', 'U', 'Y', 'V'): \
 
112
          case GST_MAKE_FOURCC ('Y', 'V', 'Y', 'U'): \
 
113
            *size = width * height * 2; \
 
114
            break; \
 
115
          case GST_MAKE_FOURCC ('I', 'Y', 'U', 'V'): \
 
116
          case GST_MAKE_FOURCC ('I', '4', '2', '0'): \
 
117
          case GST_MAKE_FOURCC ('Y', 'V', '1', '2'): \
 
118
          default: \
 
119
            *size = GST_VIDEO_I420_SIZE (width, height); \
 
120
        } \
 
121
      } \
 
122
    } \
 
123
    GST_DEBUG_OBJECT (btrans, "our frame size is %d bytes (%dx%d)", *size, \
 
124
        width, height); \
 
125
  } \
 
126
 \
 
127
  return ret; \
 
128
}
 
129
 
 
130
G_END_DECLS
 
131
 
 
132
#endif /* __GST_VIDEO_UTILS_H__ */