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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
|
From 379447918aafc7f38a79219511764f6c04a2cbf9 Mon Sep 17 00:00:00 2001
From: Rob Clark <rob@ti.com>
Date: Fri, 24 Dec 2010 20:55:43 -0600
Subject: [PATCH 23/24] ffmpegcolorspace: support for rowstride
---
gst/ffmpegcolorspace/avcodec.h | 2 +-
gst/ffmpegcolorspace/gstffmpegcodecmap.c | 85 +++++++++++++++++++--------
gst/ffmpegcolorspace/gstffmpegcodecmap.h | 1 +
gst/ffmpegcolorspace/gstffmpegcolorspace.c | 30 ++++++++--
gst/ffmpegcolorspace/gstffmpegcolorspace.h | 1 +
gst/ffmpegcolorspace/imgconvert.c | 12 ++--
6 files changed, 93 insertions(+), 38 deletions(-)
diff --git a/gst/ffmpegcolorspace/avcodec.h b/gst/ffmpegcolorspace/avcodec.h
index 57f551c..a4928ee 100644
--- a/gst/ffmpegcolorspace/avcodec.h
+++ b/gst/ffmpegcolorspace/avcodec.h
@@ -217,7 +217,7 @@ typedef struct AVPaletteControl {
} AVPaletteControl;
-int avpicture_get_size(int pix_fmt, int width, int height);
+int avpicture_get_size(int pix_fmt, int width, int height, int stride);
void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift);
const char *avcodec_get_pix_fmt_name(int pix_fmt);
diff --git a/gst/ffmpegcolorspace/gstffmpegcodecmap.c b/gst/ffmpegcolorspace/gstffmpegcodecmap.c
index 318a90e..9c6a123 100644
--- a/gst/ffmpegcolorspace/gstffmpegcodecmap.c
+++ b/gst/ffmpegcolorspace/gstffmpegcodecmap.c
@@ -619,7 +619,8 @@ gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
if (!raw)
return;
- if (gst_structure_has_name (structure, "video/x-raw-yuv")) {
+ if (gst_structure_has_name (structure, "video/x-raw-yuv") ||
+ gst_structure_has_name (structure, "video/x-raw-yuv-strided")) {
guint32 fourcc;
if (gst_structure_get_fourcc (structure, "format", &fourcc)) {
@@ -828,10 +829,10 @@ gst_ffmpegcsp_caps_with_codectype (enum CodecType type,
int
gst_ffmpegcsp_avpicture_fill (AVPicture * picture,
uint8_t * ptr, enum PixelFormat pix_fmt, int width, int height,
- int interlaced)
+ int stride, int interlaced)
{
int size, w2, h2, size2;
- int stride, stride2;
+ int stride2;
PixFmtInfo *pinfo;
pinfo = get_pix_fmt_info (pix_fmt);
@@ -847,11 +848,15 @@ gst_ffmpegcsp_avpicture_fill (AVPicture * picture,
case PIX_FMT_YUVJ420P:
case PIX_FMT_YUVJ422P:
case PIX_FMT_YUVJ444P:
- stride = GST_ROUND_UP_4 (width);
h2 = ROUND_UP_X (height, pinfo->y_chroma_shift);
- size = stride * h2;
w2 = DIV_ROUND_UP_X (width, pinfo->x_chroma_shift);
- stride2 = GST_ROUND_UP_4 (w2);
+ if (stride) {
+ stride2 = stride;
+ } else {
+ stride = GST_ROUND_UP_4 (width);
+ stride2 = GST_ROUND_UP_4 (w2);
+ }
+ size = stride * h2;
h2 = DIV_ROUND_UP_X (height, pinfo->y_chroma_shift);
size2 = stride2 * h2;
picture->data[0] = ptr;
@@ -864,11 +869,15 @@ gst_ffmpegcsp_avpicture_fill (AVPicture * picture,
/* PIX_FMT_YVU420P = YV12: same as PIX_FMT_YUV420P, but
* with U and V plane swapped. Strides as in videotestsrc */
case PIX_FMT_YUVA420P:
- stride = GST_ROUND_UP_4 (width);
h2 = ROUND_UP_X (height, pinfo->y_chroma_shift);
- size = stride * h2;
w2 = DIV_ROUND_UP_X (width, pinfo->x_chroma_shift);
- stride2 = GST_ROUND_UP_4 (w2);
+ if (stride) {
+ stride2 = stride;
+ } else {
+ stride = GST_ROUND_UP_4 (width);
+ stride2 = GST_ROUND_UP_4 (w2);
+ }
+ size = stride * h2;
h2 = DIV_ROUND_UP_X (height, pinfo->y_chroma_shift);
size2 = stride2 * h2;
picture->data[0] = ptr;
@@ -882,11 +891,15 @@ gst_ffmpegcsp_avpicture_fill (AVPicture * picture,
return 2 * size + 2 * size2;
case PIX_FMT_YVU410P:
case PIX_FMT_YVU420P:
- stride = GST_ROUND_UP_4 (width);
h2 = ROUND_UP_X (height, pinfo->y_chroma_shift);
- size = stride * h2;
w2 = DIV_ROUND_UP_X (width, pinfo->x_chroma_shift);
- stride2 = GST_ROUND_UP_4 (w2);
+ if (stride) {
+ stride2 = stride;
+ } else {
+ stride = GST_ROUND_UP_4 (width);
+ stride2 = GST_ROUND_UP_4 (w2);
+ }
+ size = stride * h2;
h2 = DIV_ROUND_UP_X (height, pinfo->y_chroma_shift);
size2 = stride2 * h2;
picture->data[0] = ptr;
@@ -898,11 +911,15 @@ gst_ffmpegcsp_avpicture_fill (AVPicture * picture,
return size + 2 * size2;
case PIX_FMT_NV12:
case PIX_FMT_NV21:
- stride = GST_ROUND_UP_4 (width);
h2 = ROUND_UP_X (height, pinfo->y_chroma_shift);
- size = stride * h2;
w2 = 2 * DIV_ROUND_UP_X (width, pinfo->x_chroma_shift);
- stride2 = GST_ROUND_UP_4 (w2);
+ if (stride) {
+ stride2 = stride;
+ } else {
+ stride = GST_ROUND_UP_4 (width);
+ stride2 = GST_ROUND_UP_4 (w2);
+ }
+ size = stride * h2;
h2 = DIV_ROUND_UP_X (height, pinfo->y_chroma_shift);
size2 = stride2 * h2;
picture->data[0] = ptr;
@@ -914,7 +931,9 @@ gst_ffmpegcsp_avpicture_fill (AVPicture * picture,
return size + size2;
case PIX_FMT_RGB24:
case PIX_FMT_BGR24:
- stride = GST_ROUND_UP_4 (width * 3);
+ if (!stride) {
+ stride = GST_ROUND_UP_4 (width * 3);
+ }
size = stride * height;
picture->data[0] = ptr;
picture->data[1] = NULL;
@@ -930,7 +949,9 @@ gst_ffmpegcsp_avpicture_fill (AVPicture * picture,
case PIX_FMT_ABGR32:
case PIX_FMT_xRGB32:
case PIX_FMT_BGRx32:
- stride = width * 4;
+ if (!stride) {
+ stride = width * 4;
+ }
size = stride * height;
picture->data[0] = ptr;
picture->data[1] = NULL;
@@ -942,7 +963,9 @@ gst_ffmpegcsp_avpicture_fill (AVPicture * picture,
case PIX_FMT_YUV422:
case PIX_FMT_UYVY422:
case PIX_FMT_YVYU422:
- stride = GST_ROUND_UP_4 (width * 2);
+ if (!stride) {
+ stride = GST_ROUND_UP_4 (width * 2);
+ }
size = stride * height;
picture->data[0] = ptr;
picture->data[1] = NULL;
@@ -950,7 +973,9 @@ gst_ffmpegcsp_avpicture_fill (AVPicture * picture,
picture->linesize[0] = stride;
return size;
case PIX_FMT_V308:
- stride = GST_ROUND_UP_4 (width * 3);
+ if (!stride) {
+ stride = GST_ROUND_UP_4 (width * 3);
+ }
size = stride * height;
picture->data[0] = ptr;
picture->data[1] = NULL;
@@ -958,8 +983,10 @@ gst_ffmpegcsp_avpicture_fill (AVPicture * picture,
picture->linesize[0] = stride;
return size;
case PIX_FMT_UYVY411:
- stride =
- GST_ROUND_UP_4 (GST_ROUND_UP_4 (width) + GST_ROUND_UP_4 (width) / 2);
+ if (!stride) {
+ stride = GST_ROUND_UP_4 (GST_ROUND_UP_4 (width) +
+ GST_ROUND_UP_4 (width) / 2);
+ }
size = stride * height;
picture->data[0] = ptr;
picture->data[1] = NULL;
@@ -968,7 +995,9 @@ gst_ffmpegcsp_avpicture_fill (AVPicture * picture,
return size;
case PIX_FMT_Y800:
case PIX_FMT_GRAY8:
- stride = GST_ROUND_UP_4 (width);
+ if (!stride) {
+ stride = GST_ROUND_UP_4 (width);
+ }
size = stride * height;
picture->data[0] = ptr;
picture->data[1] = NULL;
@@ -978,7 +1007,9 @@ gst_ffmpegcsp_avpicture_fill (AVPicture * picture,
case PIX_FMT_Y16:
case PIX_FMT_GRAY16_L:
case PIX_FMT_GRAY16_B:
- stride = GST_ROUND_UP_4 (width * 2);
+ if (!stride) {
+ stride = GST_ROUND_UP_4 (width * 2);
+ }
size = stride * height;
picture->data[0] = ptr;
picture->data[1] = NULL;
@@ -987,7 +1018,9 @@ gst_ffmpegcsp_avpicture_fill (AVPicture * picture,
return size;
case PIX_FMT_MONOWHITE:
case PIX_FMT_MONOBLACK:
- stride = GST_ROUND_UP_4 ((width + 7) >> 3);
+ if (!stride) {
+ stride = GST_ROUND_UP_4 ((width + 7) >> 3);
+ }
size = stride * height;
picture->data[0] = ptr;
picture->data[1] = NULL;
@@ -996,7 +1029,9 @@ gst_ffmpegcsp_avpicture_fill (AVPicture * picture,
return size;
case PIX_FMT_PAL8:
/* already forced to be with stride, so same result as other function */
- stride = GST_ROUND_UP_4 (width);
+ if (!stride) {
+ stride = GST_ROUND_UP_4 (width);
+ }
size = stride * height;
picture->data[0] = ptr;
picture->data[1] = ptr + size; /* palette is stored here as 256 32 bit words */
diff --git a/gst/ffmpegcolorspace/gstffmpegcodecmap.h b/gst/ffmpegcolorspace/gstffmpegcodecmap.h
index 515f530..bcd212a 100644
--- a/gst/ffmpegcolorspace/gstffmpegcodecmap.h
+++ b/gst/ffmpegcolorspace/gstffmpegcodecmap.h
@@ -52,6 +52,7 @@ gst_ffmpegcsp_avpicture_fill (AVPicture * picture,
enum PixelFormat pix_fmt,
int width,
int height,
+ int stride,
int interlaced);
#endif /* __GST_FFMPEG_CODECMAP_H__ */
diff --git a/gst/ffmpegcolorspace/gstffmpegcolorspace.c b/gst/ffmpegcolorspace/gstffmpegcolorspace.c
index 4ba0204..63430a0 100644
--- a/gst/ffmpegcolorspace/gstffmpegcolorspace.c
+++ b/gst/ffmpegcolorspace/gstffmpegcolorspace.c
@@ -48,6 +48,10 @@ GST_DEBUG_CATEGORY (ffmpegcolorspace_performance);
"video/x-raw-yuv, width = "GST_VIDEO_SIZE_RANGE" , " \
"height="GST_VIDEO_SIZE_RANGE",framerate="GST_VIDEO_FPS_RANGE"," \
"format= (fourcc) { I420 , NV12 , NV21 , YV12 , YUY2 , Y42B , Y444 , YUV9 , YVU9 , Y41B , Y800 , Y8 , GREY , Y16 , UYVY , YVYU , IYU1 , v308 , AYUV, A420} ;" \
+ "video/x-raw-yuv-strided, width = "GST_VIDEO_SIZE_RANGE" , " \
+ "height="GST_VIDEO_SIZE_RANGE",framerate="GST_VIDEO_FPS_RANGE"," \
+ "rowstride="GST_VIDEO_SIZE_RANGE"," \
+ "format= (fourcc) { I420 , NV12 , NV21 , YV12 , YUY2 , Y42B , Y444 , YUV9 , YVU9 , Y41B , Y800 , Y8 , GREY , Y16 , UYVY , YVYU , IYU1 , v308 , AYUV, A420} ;" \
GST_VIDEO_CAPS_RGB";" \
GST_VIDEO_CAPS_BGR";" \
GST_VIDEO_CAPS_RGBx";" \
@@ -205,8 +209,8 @@ gst_ffmpegcsp_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
{
GstFFMpegCsp *space;
GstStructure *structure;
- gint in_height, in_width;
- gint out_height, out_width;
+ gint in_height, in_width, in_stride = 0;
+ gint out_height, out_width, out_stride = 0;
const GValue *in_framerate = NULL;
const GValue *out_framerate = NULL;
const GValue *in_par = NULL;
@@ -225,6 +229,10 @@ gst_ffmpegcsp_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
if (!res)
goto no_width_height;
+ /* stride is optional: */
+ if (gst_structure_has_name (structure, "video/x-raw-yuv-strided"))
+ gst_structure_get_int (structure, "rowstride", &in_stride);
+
/* and framerate */
in_framerate = gst_structure_get_value (structure, "framerate");
if (in_framerate == NULL || !GST_VALUE_HOLDS_FRACTION (in_framerate))
@@ -241,6 +249,10 @@ gst_ffmpegcsp_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
if (!res)
goto no_width_height;
+ /* stride is optional: */
+ if (gst_structure_has_name (structure, "video/x-raw-yuv-strided"))
+ gst_structure_get_int (structure, "rowstride", &out_stride);
+
/* and framerate */
out_framerate = gst_structure_get_value (structure, "framerate");
if (out_framerate == NULL || !GST_VALUE_HOLDS_FRACTION (out_framerate))
@@ -263,6 +275,8 @@ gst_ffmpegcsp_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
space->width = ctx->width = in_width;
space->height = ctx->height = in_height;
+ space->in_stride = in_stride;
+ space->out_stride = out_stride;
space->interlaced = FALSE;
gst_structure_get_boolean (structure, "interlaced", &space->interlaced);
@@ -401,7 +415,7 @@ gst_ffmpegcsp_get_unit_size (GstBaseTransform * btrans, GstCaps * caps,
GstStructure *structure = NULL;
AVCodecContext *ctx = NULL;
gboolean ret = TRUE;
- gint width, height;
+ gint width, height, stride = 0;
g_assert (size);
@@ -409,6 +423,10 @@ gst_ffmpegcsp_get_unit_size (GstBaseTransform * btrans, GstCaps * caps,
gst_structure_get_int (structure, "width", &width);
gst_structure_get_int (structure, "height", &height);
+ /* stride is optional: */
+ if (gst_structure_has_name (structure, "video/x-raw-yuv-strided"))
+ gst_structure_get_int (structure, "rowstride", &stride);
+
ctx = avcodec_alloc_context ();
g_assert (ctx != NULL);
@@ -422,7 +440,7 @@ gst_ffmpegcsp_get_unit_size (GstBaseTransform * btrans, GstCaps * caps,
goto beach;
}
- *size = avpicture_get_size (ctx->pix_fmt, width, height);
+ *size = avpicture_get_size (ctx->pix_fmt, width, height, stride);
/* ffmpeg frames have the palette after the frame data, whereas
* GStreamer currently puts it into the caps as 'palette_data' field,
@@ -460,7 +478,7 @@ gst_ffmpegcsp_transform (GstBaseTransform * btrans, GstBuffer * inbuf,
/* fill from with source data */
gst_ffmpegcsp_avpicture_fill (&space->from_frame,
GST_BUFFER_DATA (inbuf), space->from_pixfmt, space->width, space->height,
- space->interlaced);
+ space->in_stride, space->interlaced);
/* fill optional palette */
if (space->palette)
@@ -469,7 +487,7 @@ gst_ffmpegcsp_transform (GstBaseTransform * btrans, GstBuffer * inbuf,
/* fill target frame */
gst_ffmpegcsp_avpicture_fill (&space->to_frame,
GST_BUFFER_DATA (outbuf), space->to_pixfmt, space->width, space->height,
- space->interlaced);
+ space->out_stride, space->interlaced);
/* and convert */
result = img_convert (&space->to_frame, space->to_pixfmt,
diff --git a/gst/ffmpegcolorspace/gstffmpegcolorspace.h b/gst/ffmpegcolorspace/gstffmpegcolorspace.h
index 198ab8a..bd5e01c 100644
--- a/gst/ffmpegcolorspace/gstffmpegcolorspace.h
+++ b/gst/ffmpegcolorspace/gstffmpegcolorspace.h
@@ -46,6 +46,7 @@ struct _GstFFMpegCsp {
GstVideoFilter element;
gint width, height;
+ gint in_stride, out_stride;
gboolean interlaced;
gfloat fps;
enum PixelFormat from_pixfmt, to_pixfmt;
diff --git a/gst/ffmpegcolorspace/imgconvert.c b/gst/ffmpegcolorspace/imgconvert.c
index cb145bb..414c4a0 100644
--- a/gst/ffmpegcolorspace/imgconvert.c
+++ b/gst/ffmpegcolorspace/imgconvert.c
@@ -594,12 +594,12 @@ avpicture_layout (const AVPicture * src, int pix_fmt, int width, int height,
#endif
int
-avpicture_get_size (int pix_fmt, int width, int height)
+avpicture_get_size (int pix_fmt, int width, int height, int stride)
{
AVPicture dummy_pict;
return gst_ffmpegcsp_avpicture_fill (&dummy_pict, NULL, pix_fmt, width,
- height, FALSE);
+ height, stride, FALSE);
}
/**
@@ -3518,16 +3518,16 @@ get_convert_table_entry (int src_pix_fmt, int dst_pix_fmt)
static int
avpicture_alloc (AVPicture * picture, int pix_fmt, int width, int height,
- int interlaced)
+ int stride, int interlaced)
{
unsigned int size;
void *ptr;
- size = avpicture_get_size (pix_fmt, width, height);
+ size = avpicture_get_size (pix_fmt, width, height, stride);
ptr = av_malloc (size);
if (!ptr)
goto fail;
- gst_ffmpegcsp_avpicture_fill (picture, ptr, pix_fmt, width, height,
+ gst_ffmpegcsp_avpicture_fill (picture, ptr, pix_fmt, width, height, stride,
interlaced);
return 0;
fail:
@@ -3775,7 +3775,7 @@ no_chroma_filter:
else
int_pix_fmt = PIX_FMT_RGB24;
}
- if (avpicture_alloc (tmp, int_pix_fmt, dst_width, dst_height,
+ if (avpicture_alloc (tmp, int_pix_fmt, dst_width, dst_height, 0,
dst->interlaced) < 0)
return -1;
ret = -1;
--
1.7.1
|