1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
From ecac5f6e2cab295e742784f6d4d11800b1f37c6d Mon Sep 17 00:00:00 2001
From: Rob Clark <rob@ti.com>
Date: Mon, 13 Sep 2010 19:04:47 -0500
Subject: [PATCH 19/24] video: more flexible video caps utility
Add gst_video_format_new_caps_simple() to allow for more flexible video
caps builder, which could be used for template caps and non-fixed caps.
---
gst-libs/gst/video/video.c | 129 ++++++++++++++++++++++++++------------------
gst-libs/gst/video/video.h | 2 +
2 files changed, 78 insertions(+), 53 deletions(-)
diff --git a/gst-libs/gst/video/video.c b/gst-libs/gst/video/video.c
index ff9c4fb..ef8edcc 100644
--- a/gst-libs/gst/video/video.c
+++ b/gst-libs/gst/video/video.c
@@ -590,15 +590,12 @@ gst_video_format_new_caps_interlaced (GstVideoFormat format,
}
/**
- * gst_video_format_new_caps_strided:
+ * gst_video_format_new_caps_simple:
* @format: the #GstVideoFormat describing the raw video format
- * @width: width of video
- * @height: height of video
- * @rowstride: the rowstride (in bytes), or 0 if no rowstride
- * @framerate_n: numerator of frame rate
- * @framerate_d: denominator of frame rate
- * @par_n: numerator of pixel aspect ratio
- * @par_d: denominator of pixel aspect ratio
+ * @rowstride: 0 for unstrided, -1 for any stride (unfixed), or other
+ * for fixed stride
+ * @fieldname: first field to set
+ * @...: additional arguments
*
* Creates a new #GstCaps object based on the parameters provided.
*
@@ -607,25 +604,20 @@ gst_video_format_new_caps_interlaced (GstVideoFormat format,
* Returns: a new #GstCaps object, or NULL if there was an error
*/
GstCaps *
-gst_video_format_new_caps_strided (GstVideoFormat format,
- int width, int height, int rowstride,
- int framerate_n, int framerate_d, int par_n, int par_d)
+gst_video_format_new_caps_simple (GstVideoFormat format, int rowstride,
+ const char *fieldname, ...)
{
- GstCaps *caps = NULL;
+ va_list varargs;
+ GstStructure *s;
g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, NULL);
- g_return_val_if_fail (width > 0 && height > 0, NULL);
if (gst_video_format_is_yuv (format)) {
- caps = gst_caps_new_simple (
- rowstride ? "video/x-raw-yuv-strided" : "video/x-raw-yuv",
+ s = gst_structure_new (rowstride ?
+ "video/x-raw-yuv-strided" : "video/x-raw-yuv",
"format", GST_TYPE_FOURCC, gst_video_format_to_fourcc (format),
- "width", G_TYPE_INT, width,
- "height", G_TYPE_INT, height,
- "framerate", GST_TYPE_FRACTION, framerate_n, framerate_d,
- "pixel-aspect-ratio", GST_TYPE_FRACTION, par_n, par_d, NULL);
+ NULL);
} else if (gst_video_format_is_rgb (format)) {
- GstCaps *caps;
int red_mask = 0;
int blue_mask = 0;
int green_mask = 0;
@@ -684,15 +676,12 @@ gst_video_format_new_caps_strided (GstVideoFormat format,
} else {
mask = 0xff0000;
}
- red_mask =
- mask >> (8 * gst_video_format_get_component_offset (format, 0,
- width, height));
- green_mask =
- mask >> (8 * gst_video_format_get_component_offset (format, 1,
- width, height));
- blue_mask =
- mask >> (8 * gst_video_format_get_component_offset (format, 2,
- width, height));
+ red_mask = mask >>
+ (8 * gst_video_format_get_component_offset (format, 0, 1, 1));
+ green_mask = mask >>
+ (8 * gst_video_format_get_component_offset (format, 1, 1, 1));
+ blue_mask = mask >>
+ (8 * gst_video_format_get_component_offset (format, 2, 1, 1));
} else if (bpp == 16) {
switch (format) {
case GST_VIDEO_FORMAT_RGB16:
@@ -723,17 +712,13 @@ gst_video_format_new_caps_strided (GstVideoFormat format,
return NULL;
}
- caps = gst_caps_new_simple (
+ s = gst_structure_new (
rowstride ? "video/x-raw-rgb-strided" : "video/x-raw-rgb",
"bpp", G_TYPE_INT, bpp,
- "depth", G_TYPE_INT, depth,
- "width", G_TYPE_INT, width,
- "height", G_TYPE_INT, height,
- "framerate", GST_TYPE_FRACTION, framerate_n, framerate_d,
- "pixel-aspect-ratio", GST_TYPE_FRACTION, par_n, par_d, NULL);
+ "depth", G_TYPE_INT, depth, NULL);
if (bpp != 8) {
- gst_caps_set_simple (caps,
+ gst_structure_set (s,
"endianness", G_TYPE_INT, G_BIG_ENDIAN,
"red_mask", G_TYPE_INT, red_mask,
"green_mask", G_TYPE_INT, green_mask,
@@ -741,10 +726,12 @@ gst_video_format_new_caps_strided (GstVideoFormat format,
}
if (have_alpha) {
- alpha_mask =
- mask >> (8 * gst_video_format_get_component_offset (format, 3,
- width, height));
- gst_caps_set_simple (caps, "alpha_mask", G_TYPE_INT, alpha_mask, NULL);
+ /* note: we are passing a bogus width/height to get_component_offset(),
+ * but those parameters are ignored for the packed formats so it is ok
+ */
+ alpha_mask = mask >>
+ (8 * gst_video_format_get_component_offset (format, 3, 1, 1));
+ gst_structure_set (s, "alpha_mask", G_TYPE_INT, alpha_mask, NULL);
}
} else if (gst_video_format_is_gray (format)) {
int bpp;
@@ -770,32 +757,68 @@ gst_video_format_new_caps_strided (GstVideoFormat format,
}
if (bpp > 8) {
- caps = gst_caps_new_simple ("video/x-raw-gray",
+ s = gst_structure_new (rowstride ?
+ "video/x-raw-gray-strided" : "video/x-raw-gray",
"bpp", G_TYPE_INT, bpp,
"depth", G_TYPE_INT, depth,
- "width", G_TYPE_INT, width,
- "height", G_TYPE_INT, height,
- "framerate", GST_TYPE_FRACTION, framerate_n, framerate_d,
- "pixel-aspect-ratio", GST_TYPE_FRACTION, par_n, par_d, NULL);
+ NULL);
} else {
- caps = gst_caps_new_simple ("video/x-raw-gray",
+ s = gst_structure_new (rowstride ?
+ "video/x-raw-gray-strided" : "video/x-raw-gray",
"bpp", G_TYPE_INT, bpp,
"depth", G_TYPE_INT, depth,
"endianness", G_TYPE_INT, G_BIG_ENDIAN,
- "width", G_TYPE_INT, width,
- "height", G_TYPE_INT, height,
- "framerate", GST_TYPE_FRACTION, framerate_n, framerate_d,
- "pixel-aspect-ratio", GST_TYPE_FRACTION, par_n, par_d, NULL);
+ NULL);
}
} else {
return NULL;
}
- if (rowstride) {
- gst_caps_set_simple (caps, "rowstride", G_TYPE_INT, rowstride, NULL);
+ if (rowstride > 0) {
+ gst_structure_set (s, "rowstride",
+ G_TYPE_INT, rowstride, NULL);
+ } else if (rowstride < 0) {
+ gst_structure_set (s, "rowstride",
+ GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
}
- return caps;
+ va_start (varargs, fieldname);
+ gst_structure_set_valist (s, fieldname, varargs);
+ va_end (varargs);
+
+ return gst_caps_new_full (s, NULL);
+}
+
+/**
+ * gst_video_format_new_caps_strided:
+ * @format: the #GstVideoFormat describing the raw video format
+ * @width: width of video
+ * @height: height of video
+ * @rowstride: the rowstride (in bytes), or 0 if no rowstride
+ * @framerate_n: numerator of frame rate
+ * @framerate_d: denominator of frame rate
+ * @par_n: numerator of pixel aspect ratio
+ * @par_d: denominator of pixel aspect ratio
+ *
+ * Creates a new #GstCaps object based on the parameters provided.
+ *
+ * Since: ???
+ *
+ * Returns: a new #GstCaps object, or NULL if there was an error
+ */
+GstCaps *
+gst_video_format_new_caps_strided (GstVideoFormat format,
+ int width, int height, int rowstride,
+ int framerate_n, int framerate_d, int par_n, int par_d)
+{
+ g_return_val_if_fail (width > 0 && height > 0, NULL);
+
+ return gst_video_format_new_caps_simple (format, rowstride,
+ "width", G_TYPE_INT, width,
+ "height", G_TYPE_INT, height,
+ "framerate", GST_TYPE_FRACTION, framerate_n, framerate_d,
+ "pixel-aspect-ratio", GST_TYPE_FRACTION, par_n, par_d,
+ NULL);
}
/**
diff --git a/gst-libs/gst/video/video.h b/gst-libs/gst/video/video.h
index 5bac21f..bbd33f7 100644
--- a/gst-libs/gst/video/video.h
+++ b/gst-libs/gst/video/video.h
@@ -430,6 +430,8 @@ GstCaps * gst_video_format_new_caps_interlaced (GstVideoFormat format,
GstCaps * gst_video_format_new_caps_strided (GstVideoFormat format,
int width, int height, int rowstride,
int framerate_n, int framerate_d, int par_n, int par_d);
+GstCaps * gst_video_format_new_caps_simple (GstVideoFormat format,
+ int rowstride, const char *fieldname, ...);
GstVideoFormat gst_video_format_from_fourcc (guint32 fourcc);
guint32 gst_video_format_to_fourcc (GstVideoFormat format);
gboolean gst_video_format_is_rgb (GstVideoFormat format);
--
1.7.1
|