/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* Copyright (C) <2003> David Schleef <ds@schleef.org>
+ * Copyright (C) <2010> Sebastian Dröge <sebastian.droege@collabora.co.uk>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
GST_BOILERPLATE (GstVideoFlip, gst_video_flip, GstVideoFilter,
GST_TYPE_VIDEO_FILTER);
-static gboolean
-gst_video_flip_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
- GstCaps * outcaps)
-{
- GstVideoFlip *vf = GST_VIDEO_FLIP (btrans);
- GstStructure *in_s, *out_s;
- gboolean ret = FALSE;
-
- in_s = gst_caps_get_structure (incaps, 0);
- out_s = gst_caps_get_structure (outcaps, 0);
-
- if (gst_structure_get_int (in_s, "width", &vf->from_width) &&
- gst_structure_get_int (in_s, "height", &vf->from_height) &&
- gst_structure_get_int (out_s, "width", &vf->to_width) &&
- gst_structure_get_int (out_s, "height", &vf->to_height)) {
- /* Check that they are correct */
- switch (vf->method) {
- case GST_VIDEO_FLIP_METHOD_90R:
- case GST_VIDEO_FLIP_METHOD_90L:
- case GST_VIDEO_FLIP_METHOD_TRANS:
- case GST_VIDEO_FLIP_METHOD_OTHER:
- if ((vf->from_width != vf->to_height) ||
- (vf->from_height != vf->to_width)) {
- GST_DEBUG_OBJECT (vf, "we are inverting width and height but caps "
- "are not correct : %dx%d to %dx%d", vf->from_width,
- vf->from_height, vf->to_width, vf->to_height);
- goto beach;
- }
- break;
- case GST_VIDEO_FLIP_METHOD_IDENTITY:
-
- break;
- case GST_VIDEO_FLIP_METHOD_180:
- case GST_VIDEO_FLIP_METHOD_HORIZ:
- case GST_VIDEO_FLIP_METHOD_VERT:
- if ((vf->from_width != vf->to_width) ||
- (vf->from_height != vf->to_height)) {
- GST_DEBUG_OBJECT (vf, "we are keeping width and height but caps "
- "are not correct : %dx%d to %dx%d", vf->from_width,
- vf->from_height, vf->to_width, vf->to_height);
- goto beach;
- }
- break;
- default:
- g_assert_not_reached ();
- break;
- }
- }
-
- ret = TRUE;
-
-beach:
- return ret;
-}
-
static GstCaps *
gst_video_flip_transform_caps (GstBaseTransform * trans,
GstPadDirection direction, GstCaps * caps)
return ret;
}
-/* Useful macros */
-#define GST_VIDEO_I420_Y_ROWSTRIDE(width) (GST_ROUND_UP_4(width))
-#define GST_VIDEO_I420_U_ROWSTRIDE(width) (GST_ROUND_UP_8(width)/2)
-#define GST_VIDEO_I420_V_ROWSTRIDE(width) ((GST_ROUND_UP_8(GST_VIDEO_I420_Y_ROWSTRIDE(width)))/2)
-
-#define GST_VIDEO_I420_Y_OFFSET(w,h) (0)
-#define GST_VIDEO_I420_U_OFFSET(w,h) (GST_VIDEO_I420_Y_OFFSET(w,h)+(GST_VIDEO_I420_Y_ROWSTRIDE(w)*GST_ROUND_UP_2(h)))
-#define GST_VIDEO_I420_V_OFFSET(w,h) (GST_VIDEO_I420_U_OFFSET(w,h)+(GST_VIDEO_I420_U_ROWSTRIDE(w)*GST_ROUND_UP_2(h)/2))
-
-#define GST_VIDEO_I420_SIZE(w,h) (GST_VIDEO_I420_V_OFFSET(w,h)+(GST_VIDEO_I420_V_ROWSTRIDE(w)*GST_ROUND_UP_2(h)/2))
-
static gboolean
gst_video_flip_get_unit_size (GstBaseTransform * btrans, GstCaps * caps,
guint * size)
{
GstVideoFlip *videoflip = GST_VIDEO_FLIP (btrans);
- GstStructure *structure;
- gboolean ret = FALSE;
+ GstVideoFormat format;
gint width, height;
- structure = gst_caps_get_structure (caps, 0);
- if (gst_structure_get_int (structure, "width", &width) &&
- gst_structure_get_int (structure, "height", &height)) {
- *size = GST_VIDEO_I420_SIZE (width, height);
- ret = TRUE;
- GST_DEBUG_OBJECT (videoflip, "our frame size is %d bytes (%dx%d)", *size,
- width, height);
- }
+ if (!gst_video_format_parse_caps (caps, &format, &width, &height))
+ return FALSE;
- return ret;
+ *size = gst_video_format_get_size (format, width, height);
+
+ GST_DEBUG_OBJECT (videoflip, "our frame size is %d bytes (%dx%d)", *size,
+ width, height);
+
+ return TRUE;
}
-static GstFlowReturn
-gst_video_flip_flip (GstVideoFlip * videoflip, guint8 * dest,
- const guint8 * src, int sw, int sh, int dw, int dh)
+static void
+gst_video_flip_planar_yuv (GstVideoFlip * videoflip, guint8 * dest,
+ const guint8 * src)
{
- GstFlowReturn ret = GST_FLOW_OK;
- int x, y;
- guint8 const *s = src;
- guint8 *d = dest;
+ gint x, y;
+ guint8 const *s;
+ guint8 *d;
+ GstVideoFormat format = videoflip->format;
+ gint sw = videoflip->from_width;
+ gint sh = videoflip->from_height;
+ gint dw = videoflip->to_width;
+ gint dh = videoflip->to_height;
+ gint src_y_stride, src_u_stride, src_v_stride;
+ gint src_y_offset, src_u_offset, src_v_offset;
+ gint src_y_height, src_u_height, src_v_height;
+ gint src_y_width, src_u_width, src_v_width;
+ gint dest_y_stride, dest_u_stride, dest_v_stride;
+ gint dest_y_offset, dest_u_offset, dest_v_offset;
+ gint dest_y_height, dest_u_height, dest_v_height;
+ gint dest_y_width, dest_u_width, dest_v_width;
+
+ src_y_stride = gst_video_format_get_row_stride (format, 0, sw);
+ src_u_stride = gst_video_format_get_row_stride (format, 1, sw);
+ src_v_stride = gst_video_format_get_row_stride (format, 2, sw);
+
+ dest_y_stride = gst_video_format_get_row_stride (format, 0, dw);
+ dest_u_stride = gst_video_format_get_row_stride (format, 1, dw);
+ dest_v_stride = gst_video_format_get_row_stride (format, 2, dw);
+
+ src_y_offset = gst_video_format_get_component_offset (format, 0, sw, sh);
+ src_u_offset = gst_video_format_get_component_offset (format, 1, sw, sh);
+ src_v_offset = gst_video_format_get_component_offset (format, 2, sw, sh);
+
+ dest_y_offset = gst_video_format_get_component_offset (format, 0, dw, dh);
+ dest_u_offset = gst_video_format_get_component_offset (format, 1, dw, dh);
+ dest_v_offset = gst_video_format_get_component_offset (format, 2, dw, dh);
+
+ src_y_width = gst_video_format_get_component_width (format, 0, sw);
+ src_u_width = gst_video_format_get_component_width (format, 1, sw);
+ src_v_width = gst_video_format_get_component_width (format, 2, sw);
+
+ dest_y_width = gst_video_format_get_component_width (format, 0, dw);
+ dest_u_width = gst_video_format_get_component_width (format, 1, dw);
+ dest_v_width = gst_video_format_get_component_width (format, 2, dw);
+
+ src_y_height = gst_video_format_get_component_height (format, 0, sh);
+ src_u_height = gst_video_format_get_component_height (format, 1, sh);
+ src_v_height = gst_video_format_get_component_height (format, 2, sh);
+
+ dest_y_height = gst_video_format_get_component_height (format, 0, dh);
+ dest_u_height = gst_video_format_get_component_height (format, 1, dh);
+ dest_v_height = gst_video_format_get_component_height (format, 2, dh);
switch (videoflip->method) {
case GST_VIDEO_FLIP_METHOD_90R:
/* Flip Y */
- for (y = 0; y < dh; y++) {
- for (x = 0; x < dw; x++) {
- d[y * GST_VIDEO_I420_Y_ROWSTRIDE (dw) + x] =
- s[(sh - 1 - x) * GST_VIDEO_I420_Y_ROWSTRIDE (sw) + y];
+ s = src + src_y_offset;
+ d = dest + dest_y_offset;
+ for (y = 0; y < dest_y_height; y++) {
+ for (x = 0; x < dest_y_width; x++) {
+ d[y * dest_y_stride + x] =
+ s[(src_y_height - 1 - x) * src_y_stride + y];
}
}
/* Flip U */
- s = src + GST_VIDEO_I420_U_OFFSET (sw, sh);
- d = dest + GST_VIDEO_I420_U_OFFSET (dw, dh);
- for (y = 0; y < dh / 2; y++) {
- for (x = 0; x < dw / 2; x++) {
- d[y * GST_VIDEO_I420_U_ROWSTRIDE (dw) + x] =
- s[(sh / 2 - 1 - x) * GST_VIDEO_I420_U_ROWSTRIDE (sw) + y];
+ s = src + src_u_offset;
+ d = dest + dest_u_offset;
+ for (y = 0; y < dest_u_height; y++) {
+ for (x = 0; x < dest_u_width; x++) {
+ d[y * dest_u_stride + x] =
+ s[(src_u_height - 1 - x) * src_u_stride + y];
}
}
/* Flip V */
- s = src + GST_VIDEO_I420_V_OFFSET (sw, sh);
- d = dest + GST_VIDEO_I420_V_OFFSET (dw, dh);
- for (y = 0; y < dh / 2; y++) {
- for (x = 0; x < dw / 2; x++) {
- d[y * GST_VIDEO_I420_V_ROWSTRIDE (dw) + x] =
- s[(sh / 2 - 1 - x) * GST_VIDEO_I420_V_ROWSTRIDE (sw) + y];
+ s = src + src_v_offset;
+ d = dest + dest_v_offset;
+ for (y = 0; y < dest_v_height; y++) {
+ for (x = 0; x < dest_v_width; x++) {
+ d[y * dest_v_stride + x] =
+ s[(src_v_height - 1 - x) * src_v_stride + y];
}
}
break;
case GST_VIDEO_FLIP_METHOD_90L:
/* Flip Y */
- for (y = 0; y < dh; y++) {
- for (x = 0; x < dw; x++) {
- d[y * GST_VIDEO_I420_Y_ROWSTRIDE (dw) + x] =
- s[x * GST_VIDEO_I420_Y_ROWSTRIDE (sw) + (sw - 1 - y)];
+ s = src + src_y_offset;
+ d = dest + dest_y_offset;
+ for (y = 0; y < dest_y_height; y++) {
+ for (x = 0; x < dest_y_width; x++) {
+ d[y * dest_y_stride + x] =
+ s[x * src_y_stride + (src_y_width - 1 - y)];
}
}
/* Flip U */
- s = src + GST_VIDEO_I420_U_OFFSET (sw, sh);
- d = dest + GST_VIDEO_I420_U_OFFSET (dw, dh);
- for (y = 0; y < dh / 2; y++) {
- for (x = 0; x < dw / 2; x++) {
- d[y * GST_VIDEO_I420_U_ROWSTRIDE (dw) + x] =
- s[x * GST_VIDEO_I420_U_ROWSTRIDE (sw) + (sw / 2 - 1 - y)];
+ s = src + src_u_offset;
+ d = dest + dest_u_offset;
+ for (y = 0; y < dest_u_height; y++) {
+ for (x = 0; x < dest_u_width; x++) {
+ d[y * dest_u_stride + x] =
+ s[x * src_u_stride + (src_u_width - 1 - y)];
}
}
/* Flip V */
- s = src + GST_VIDEO_I420_V_OFFSET (sw, sh);
- d = dest + GST_VIDEO_I420_V_OFFSET (dw, dh);
- for (y = 0; y < dh / 2; y++) {
- for (x = 0; x < dw / 2; x++) {
- d[y * GST_VIDEO_I420_V_ROWSTRIDE (dw) + x] =
- s[x * GST_VIDEO_I420_V_ROWSTRIDE (sw) + (sw / 2 - 1 - y)];
+ s = src + src_v_offset;
+ d = dest + dest_v_offset;
+ for (y = 0; y < dest_v_height; y++) {
+ for (x = 0; x < dest_v_width; x++) {
+ d[y * dest_v_stride + x] =
+ s[x * src_v_stride + (src_v_width - 1 - y)];
}
}
break;
case GST_VIDEO_FLIP_METHOD_180:
/* Flip Y */
- for (y = 0; y < dh; y++) {
- for (x = 0; x < dw; x++) {
- d[y * GST_VIDEO_I420_Y_ROWSTRIDE (dw) + x] =
- s[(sh - 1 - y) * GST_VIDEO_I420_Y_ROWSTRIDE (sw) + (sw - 1 - x)];
+ s = src + src_y_offset;
+ d = dest + dest_y_offset;
+ for (y = 0; y < dest_y_height; y++) {
+ for (x = 0; x < dest_y_width; x++) {
+ d[y * dest_y_stride + x] =
+ s[(src_y_height - 1 - y) * src_y_stride + (src_y_width - 1 - x)];
}
}
/* Flip U */
- s = src + GST_VIDEO_I420_U_OFFSET (sw, sh);
- d = dest + GST_VIDEO_I420_U_OFFSET (dw, dh);
- for (y = 0; y < dh / 2; y++) {
- for (x = 0; x < dw / 2; x++) {
- d[y * GST_VIDEO_I420_U_ROWSTRIDE (dw) + x] =
- s[(sh / 2 - 1 - y) * GST_VIDEO_I420_U_ROWSTRIDE (sw) + (sw / 2 -
- 1 - x)];
+ s = src + src_u_offset;
+ d = dest + dest_u_offset;
+ for (y = 0; y < dest_u_height; y++) {
+ for (x = 0; x < dest_u_width; x++) {
+ d[y * dest_u_stride + x] =
+ s[(src_u_height - 1 - y) * src_u_stride + (src_u_width - 1 - x)];
}
}
/* Flip V */
- s = src + GST_VIDEO_I420_V_OFFSET (sw, sh);
- d = dest + GST_VIDEO_I420_V_OFFSET (dw, dh);
- for (y = 0; y < dh / 2; y++) {
- for (x = 0; x < dw / 2; x++) {
- d[y * GST_VIDEO_I420_V_ROWSTRIDE (dw) + x] =
- s[(sh / 2 - 1 - y) * GST_VIDEO_I420_V_ROWSTRIDE (sw) + (sw / 2 -
- 1 - x)];
+ s = src + src_v_offset;
+ d = dest + dest_v_offset;
+ for (y = 0; y < dest_v_height; y++) {
+ for (x = 0; x < dest_v_width; x++) {
+ d[y * dest_v_stride + x] =
+ s[(src_v_height - 1 - y) * src_v_stride + (src_v_width - 1 - x)];
}
}
break;
case GST_VIDEO_FLIP_METHOD_HORIZ:
/* Flip Y */
- for (y = 0; y < dh; y++) {
- for (x = 0; x < dw; x++) {
- d[y * GST_VIDEO_I420_Y_ROWSTRIDE (dw) + x] =
- s[y * GST_VIDEO_I420_Y_ROWSTRIDE (sw) + (sw - 1 - x)];
+ s = src + src_y_offset;
+ d = dest + dest_y_offset;
+ for (y = 0; y < dest_y_height; y++) {
+ for (x = 0; x < dest_y_width; x++) {
+ d[y * dest_y_stride + x] =
+ s[y * src_y_stride + (src_y_width - 1 - x)];
}
}
/* Flip U */
- s = src + GST_VIDEO_I420_U_OFFSET (sw, sh);
- d = dest + GST_VIDEO_I420_U_OFFSET (dw, dh);
- for (y = 0; y < dh / 2; y++) {
- for (x = 0; x < dw / 2; x++) {
- d[y * GST_VIDEO_I420_U_ROWSTRIDE (dw) + x] =
- s[y * GST_VIDEO_I420_U_ROWSTRIDE (sw) + (sw / 2 - 1 - x)];
+ s = src + src_u_offset;
+ d = dest + dest_u_offset;
+ for (y = 0; y < dest_u_height; y++) {
+ for (x = 0; x < dest_u_width; x++) {
+ d[y * dest_u_stride + x] =
+ s[y * src_u_stride + (src_u_width - 1 - x)];
}
}
/* Flip V */
- s = src + GST_VIDEO_I420_V_OFFSET (sw, sh);
- d = dest + GST_VIDEO_I420_V_OFFSET (dw, dh);
- for (y = 0; y < dh / 2; y++) {
- for (x = 0; x < dw / 2; x++) {
- d[y * GST_VIDEO_I420_V_ROWSTRIDE (dw) + x] =
- s[y * GST_VIDEO_I420_V_ROWSTRIDE (sw) + (sw / 2 - 1 - x)];
+ s = src + src_v_offset;
+ d = dest + dest_v_offset;
+ for (y = 0; y < dest_v_height; y++) {
+ for (x = 0; x < dest_v_width; x++) {
+ d[y * dest_v_stride + x] =
+ s[y * src_v_stride + (src_v_width - 1 - x)];
}
}
break;
case GST_VIDEO_FLIP_METHOD_VERT:
/* Flip Y */
- for (y = 0; y < dh; y++) {
- for (x = 0; x < dw; x++) {
- d[y * GST_VIDEO_I420_Y_ROWSTRIDE (dw) + x] =
- s[(sh - 1 - y) * GST_VIDEO_I420_Y_ROWSTRIDE (sw) + x];
+ s = src + src_y_offset;
+ d = dest + dest_y_offset;
+ for (y = 0; y < dest_y_height; y++) {
+ for (x = 0; x < dest_y_width; x++) {
+ d[y * dest_y_stride + x] =
+ s[(src_y_height - 1 - y) * src_y_stride + x];
}
}
/* Flip U */
- s = src + GST_VIDEO_I420_U_OFFSET (sw, sh);
- d = dest + GST_VIDEO_I420_U_OFFSET (dw, dh);
- for (y = 0; y < dh / 2; y++) {
- for (x = 0; x < dw / 2; x++) {
- d[y * GST_VIDEO_I420_U_ROWSTRIDE (dw) + x] =
- s[(sh / 2 - 1 - y) * GST_VIDEO_I420_U_ROWSTRIDE (sw) + x];
+ s = src + src_u_offset;
+ d = dest + dest_u_offset;
+ for (y = 0; y < dest_u_height; y++) {
+ for (x = 0; x < dest_u_width; x++) {
+ d[y * dest_u_stride + x] =
+ s[(src_u_height - 1 - y) * src_u_stride + x];
}
}
/* Flip V */
- s = src + GST_VIDEO_I420_V_OFFSET (sw, sh);
- d = dest + GST_VIDEO_I420_V_OFFSET (dw, dh);
- for (y = 0; y < dh / 2; y++) {
- for (x = 0; x < dw / 2; x++) {
- d[y * GST_VIDEO_I420_V_ROWSTRIDE (dw) + x] =
- s[(sh / 2 - 1 - y) * GST_VIDEO_I420_V_ROWSTRIDE (sw) + x];
+ s = src + src_v_offset;
+ d = dest + dest_v_offset;
+ for (y = 0; y < dest_v_height; y++) {
+ for (x = 0; x < dest_v_width; x++) {
+ d[y * dest_v_stride + x] =
+ s[(src_v_height - 1 - y) * src_v_stride + x];
}
}
break;
case GST_VIDEO_FLIP_METHOD_TRANS:
/* Flip Y */
- for (y = 0; y < dh; y++) {
- for (x = 0; x < dw; x++) {
- d[y * GST_VIDEO_I420_Y_ROWSTRIDE (dw) + x] =
- s[x * GST_VIDEO_I420_Y_ROWSTRIDE (sw) + y];
+ s = src + src_y_offset;
+ d = dest + dest_y_offset;
+ for (y = 0; y < dest_y_height; y++) {
+ for (x = 0; x < dest_y_width; x++) {
+ d[y * dest_y_stride + x] = s[x * src_y_stride + y];
}
}
/* Flip U */
- s = src + GST_VIDEO_I420_U_OFFSET (sw, sh);
- d = dest + GST_VIDEO_I420_U_OFFSET (dw, dh);
- for (y = 0; y < dh / 2; y++) {
- for (x = 0; x < dw / 2; x++) {
- d[y * GST_VIDEO_I420_U_ROWSTRIDE (dw) + x] =
- s[x * GST_VIDEO_I420_U_ROWSTRIDE (sw) + y];
+ s = src + src_u_offset;
+ d = dest + dest_u_offset;
+ for (y = 0; y < dest_u_height; y++) {
+ for (x = 0; x < dest_u_width; x++) {
+ d[y * dest_u_stride + x] = s[x * src_u_stride + y];
}
}
/* Flip V */
- s = src + GST_VIDEO_I420_V_OFFSET (sw, sh);
- d = dest + GST_VIDEO_I420_V_OFFSET (dw, dh);
- for (y = 0; y < dh / 2; y++) {
- for (x = 0; x < dw / 2; x++) {
- d[y * GST_VIDEO_I420_V_ROWSTRIDE (dw) + x] =
- s[x * GST_VIDEO_I420_V_ROWSTRIDE (sw) + y];
+ s = src + src_v_offset;
+ d = dest + dest_v_offset;
+ for (y = 0; y < dest_u_height; y++) {
+ for (x = 0; x < dest_u_width; x++) {
+ d[y * dest_v_stride + x] = s[x * src_v_stride + y];
}
}
break;
case GST_VIDEO_FLIP_METHOD_OTHER:
/* Flip Y */
- for (y = 0; y < dh; y++) {
- for (x = 0; x < dw; x++) {
- d[y * GST_VIDEO_I420_Y_ROWSTRIDE (dw) + x] =
- s[(sh - 1 - x) * GST_VIDEO_I420_Y_ROWSTRIDE (sw) + (sw - 1 - y)];
+ s = src + src_y_offset;
+ d = dest + dest_y_offset;
+ for (y = 0; y < dest_y_height; y++) {
+ for (x = 0; x < dest_y_width; x++) {
+ d[y * dest_y_stride + x] =
+ s[(src_y_height - 1 - x) * src_y_stride + (src_y_width - 1 - y)];
}
}
/* Flip U */
- s = src + GST_VIDEO_I420_U_OFFSET (sw, sh);
- d = dest + GST_VIDEO_I420_U_OFFSET (dw, dh);
- for (y = 0; y < dh / 2; y++) {
- for (x = 0; x < dw / 2; x++) {
- d[y * GST_VIDEO_I420_U_ROWSTRIDE (dw) + x] =
- s[(sh / 2 - 1 - x) * GST_VIDEO_I420_U_ROWSTRIDE (sw) + (sw / 2 -
- 1 - y)];
+ s = src + src_u_offset;
+ d = dest + dest_u_offset;
+ for (y = 0; y < dest_u_height; y++) {
+ for (x = 0; x < dest_u_width; x++) {
+ d[y * dest_u_stride + x] =
+ s[(src_u_height - 1 - x) * src_u_stride + (src_u_width - 1 - y)];
}
}
/* Flip V */
- s = src + GST_VIDEO_I420_V_OFFSET (sw, sh);
- d = dest + GST_VIDEO_I420_V_OFFSET (dw, dh);
- for (y = 0; y < dh / 2; y++) {
- for (x = 0; x < dw / 2; x++) {
- d[y * GST_VIDEO_I420_V_ROWSTRIDE (dw) + x] =
- s[(sh / 2 - 1 - x) * GST_VIDEO_I420_V_ROWSTRIDE (sw) + (sw / 2 -
- 1 - y)];
+ s = src + src_v_offset;
+ d = dest + dest_v_offset;
+ for (y = 0; y < dest_v_height; y++) {
+ for (x = 0; x < dest_v_width; x++) {
+ d[y * dest_v_stride + x] =
+ s[(src_v_height - 1 - x) * src_v_stride + (src_v_width - 1 - y)];
}
}
break;
case GST_VIDEO_FLIP_METHOD_IDENTITY:
- memcpy (d, s, GST_VIDEO_I420_SIZE (dw, dh));
+ g_assert_not_reached ();
break;
default:
- ret = GST_FLOW_ERROR;
+ g_assert_not_reached ();
break;
}
+}
- return ret;
+static gboolean
+gst_video_flip_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
+ GstCaps * outcaps)
+{
+ GstVideoFlip *vf = GST_VIDEO_FLIP (btrans);
+ GstVideoFormat in_format, out_format;
+ gboolean ret = FALSE;
+
+ vf->process = NULL;
+
+ if (!gst_video_format_parse_caps (incaps, &in_format, &vf->from_width,
+ &vf->from_height)
+ || !gst_video_format_parse_caps (outcaps, &out_format, &vf->to_width,
+ &vf->to_height))
+ goto invalid_caps;
+
+ if (in_format != out_format)
+ goto invalid_caps;
+ vf->format = in_format;
+
+ /* Check that they are correct */
+ switch (vf->method) {
+ case GST_VIDEO_FLIP_METHOD_90R:
+ case GST_VIDEO_FLIP_METHOD_90L:
+ case GST_VIDEO_FLIP_METHOD_TRANS:
+ case GST_VIDEO_FLIP_METHOD_OTHER:
+ if ((vf->from_width != vf->to_height) ||
+ (vf->from_height != vf->to_width)) {
+ GST_ERROR_OBJECT (vf, "we are inverting width and height but caps "
+ "are not correct : %dx%d to %dx%d", vf->from_width,
+ vf->from_height, vf->to_width, vf->to_height);
+ goto beach;
+ }
+ break;
+ case GST_VIDEO_FLIP_METHOD_IDENTITY:
+
+ break;
+ case GST_VIDEO_FLIP_METHOD_180:
+ case GST_VIDEO_FLIP_METHOD_HORIZ:
+ case GST_VIDEO_FLIP_METHOD_VERT:
+ if ((vf->from_width != vf->to_width) ||
+ (vf->from_height != vf->to_height)) {
+ GST_ERROR_OBJECT (vf, "we are keeping width and height but caps "
+ "are not correct : %dx%d to %dx%d", vf->from_width,
+ vf->from_height, vf->to_width, vf->to_height);
+ goto beach;
+ }
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+
+ ret = TRUE;
+
+ switch (vf->format) {
+ case GST_VIDEO_FORMAT_I420:
+ case GST_VIDEO_FORMAT_YV12:
+ vf->process = gst_video_flip_planar_yuv;
+ break;
+ default:
+ break;
+ }
+
+beach:
+ return ret && (vf->process != NULL);
+
+invalid_caps:
+ GST_ERROR_OBJECT (vf, "Invalid caps: %" GST_PTR_FORMAT " -> %" GST_PTR_FORMAT,
+ incaps, outcaps);
+ return FALSE;
}
-static GstFlowReturn
-gst_video_flip_transform (GstBaseTransform * trans, GstBuffer * in,
- GstBuffer * out)
+static void
+gst_video_flip_before_transform (GstBaseTransform * trans, GstBuffer * in)
{
GstVideoFlip *videoflip = GST_VIDEO_FLIP (trans);
- gpointer dest;
- gconstpointer src;
- int sw, sh, dw, dh;
- GstFlowReturn ret = GST_FLOW_OK;
GstClockTime timestamp, stream_time;
- timestamp = GST_BUFFER_TIMESTAMP (out);
+ timestamp = GST_BUFFER_TIMESTAMP (in);
stream_time =
gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME, timestamp);
if (GST_CLOCK_TIME_IS_VALID (stream_time))
gst_object_sync_values (G_OBJECT (videoflip), stream_time);
+}
+
+static GstFlowReturn
+gst_video_flip_transform (GstBaseTransform * trans, GstBuffer * in,
+ GstBuffer * out)
+{
+ GstVideoFlip *videoflip = GST_VIDEO_FLIP (trans);
+ guint8 *dest;
+ const guint8 *src;
+
+ if (G_UNLIKELY (videoflip->process == NULL))
+ goto not_negotiated;
src = GST_BUFFER_DATA (in);
dest = GST_BUFFER_DATA (out);
- sw = videoflip->from_width;
- sh = videoflip->from_height;
- dw = videoflip->to_width;
- dh = videoflip->to_height;
GST_LOG_OBJECT (videoflip, "videoflip: flipping %dx%d to %dx%d (%s)",
- sw, sh, dw, dh, video_flip_methods[videoflip->method].value_nick);
+ videoflip->from_width, videoflip->from_height, videoflip->to_width,
+ videoflip->to_height, video_flip_methods[videoflip->method].value_nick);
- ret = gst_video_flip_flip (videoflip, dest, src, sw, sh, dw, dh);
+ videoflip->process (videoflip, dest, src);
- return ret;
+ return GST_FLOW_OK;
+
+not_negotiated:
+ GST_ERROR_OBJECT (videoflip, "Not negotiated yet");
+ return GST_FLOW_NOT_NEGOTIATED;
}
static gboolean
new_y = y;
break;
}
- GST_DEBUG_OBJECT (vf, "to %fx%f", x, y);
+ GST_DEBUG_OBJECT (vf, "to %fx%f", new_x, new_y);
gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE, new_x,
"pointer_y", G_TYPE_DOUBLE, new_y, NULL);
}
if (method != videoflip->method) {
GstBaseTransform *btrans = GST_BASE_TRANSFORM (videoflip);
+ gst_base_transform_set_passthrough (btrans,
+ method == GST_VIDEO_FLIP_METHOD_IDENTITY);
+
GST_DEBUG_OBJECT (videoflip, "Changing method from %s to %s",
video_flip_methods[videoflip->method].value_nick,
video_flip_methods[method].value_nick);
trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_video_flip_set_caps);
trans_class->get_unit_size = GST_DEBUG_FUNCPTR (gst_video_flip_get_unit_size);
trans_class->transform = GST_DEBUG_FUNCPTR (gst_video_flip_transform);
+ trans_class->before_transform =
+ GST_DEBUG_FUNCPTR (gst_video_flip_before_transform);
trans_class->src_event = GST_DEBUG_FUNCPTR (gst_video_flip_src_event);
}