video: port to new video apis

This commit is contained in:
Wim Taymans 2011-06-28 14:03:43 +02:00
parent 54c9b13ea7
commit ead60adb33
6 changed files with 301 additions and 411 deletions

View file

@ -71,49 +71,23 @@ enum
#define DEFAULT_PROP_GAMMA 1 #define DEFAULT_PROP_GAMMA 1
static GstStaticPadTemplate gst_gamma_src_template = static GstStaticPadTemplate gst_gamma_src_template =
GST_STATIC_PAD_TEMPLATE ("src", GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC, GST_PAD_SRC,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AYUV") ";" GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ AYUV, "
GST_VIDEO_CAPS_ARGB ";" GST_VIDEO_CAPS_BGRA ";" "ARGB, BGRA, ABGR, RGBA, ABGR, RGBA, Y444, "
GST_VIDEO_CAPS_ABGR ";" GST_VIDEO_CAPS_RGBA ";" "xRGB, RGBx, xBGR, BGRx, RGB, BGR, Y42B, NV12, "
GST_VIDEO_CAPS_YUV ("Y444") ";" "NV21, YUY2, UYVY, YVYU, I420, YV12, IYUV, Y41B }"))
GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_RGBx ";"
GST_VIDEO_CAPS_xBGR ";" GST_VIDEO_CAPS_BGRx ";"
GST_VIDEO_CAPS_RGB ";" GST_VIDEO_CAPS_BGR ";"
GST_VIDEO_CAPS_YUV ("Y42B") ";"
GST_VIDEO_CAPS_YUV ("NV12") ";"
GST_VIDEO_CAPS_YUV ("NV21") ";"
GST_VIDEO_CAPS_YUV ("YUY2") ";"
GST_VIDEO_CAPS_YUV ("UYVY") ";"
GST_VIDEO_CAPS_YUV ("YVYU") ";"
GST_VIDEO_CAPS_YUV ("I420") ";"
GST_VIDEO_CAPS_YUV ("YV12") ";"
GST_VIDEO_CAPS_YUV ("IYUV") ";" GST_VIDEO_CAPS_YUV ("Y41B")
)
); );
static GstStaticPadTemplate gst_gamma_sink_template = static GstStaticPadTemplate gst_gamma_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink", GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK, GST_PAD_SINK,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AYUV") ";" GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ AYUV, "
GST_VIDEO_CAPS_ARGB ";" GST_VIDEO_CAPS_BGRA ";" "ARGB, BGRA, ABGR, RGBA, ABGR, RGBA, Y444, "
GST_VIDEO_CAPS_ABGR ";" GST_VIDEO_CAPS_RGBA ";" "xRGB, RGBx, xBGR, BGRx, RGB, BGR, Y42B, NV12, "
GST_VIDEO_CAPS_YUV ("Y444") ";" "NV21, YUY2, UYVY, YVYU, I420, YV12, IYUV, Y41B }"))
GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_RGBx ";"
GST_VIDEO_CAPS_xBGR ";" GST_VIDEO_CAPS_BGRx ";"
GST_VIDEO_CAPS_RGB ";" GST_VIDEO_CAPS_BGR ";"
GST_VIDEO_CAPS_YUV ("Y42B") ";"
GST_VIDEO_CAPS_YUV ("NV12") ";"
GST_VIDEO_CAPS_YUV ("NV21") ";"
GST_VIDEO_CAPS_YUV ("YUY2") ";"
GST_VIDEO_CAPS_YUV ("UYVY") ";"
GST_VIDEO_CAPS_YUV ("YVYU") ";"
GST_VIDEO_CAPS_YUV ("I420") ";"
GST_VIDEO_CAPS_YUV ("YV12") ";"
GST_VIDEO_CAPS_YUV ("IYUV") ";" GST_VIDEO_CAPS_YUV ("Y41B")
)
); );
static void gst_gamma_set_property (GObject * object, guint prop_id, static void gst_gamma_set_property (GObject * object, guint prop_id,
@ -235,21 +209,18 @@ gst_gamma_calculate_tables (GstGamma * gamma)
} }
static void static void
gst_gamma_planar_yuv_ip (GstGamma * gamma, guint8 * data) gst_gamma_planar_yuv_ip (GstGamma * gamma, GstVideoFrame * frame)
{ {
gint i, j, height; gint i, j, height;
gint width, row_stride, row_wrap; gint width, stride, row_wrap;
const guint8 *table = gamma->gamma_table; const guint8 *table = gamma->gamma_table;
guint8 *data;
data = data = GST_VIDEO_FRAME_COMP_DATA (frame, 0);
data + gst_video_format_get_component_offset (gamma->format, 0, stride = GST_VIDEO_FRAME_COMP_STRIDE (frame, 0);
gamma->width, gamma->height); width = GST_VIDEO_FRAME_COMP_WIDTH (frame, 0);
height = GST_VIDEO_FRAME_COMP_HEIGHT (frame, 0);
width = gst_video_format_get_component_width (gamma->format, 0, gamma->width); row_wrap = stride - width;
height = gst_video_format_get_component_height (gamma->format, 0,
gamma->height);
row_stride = gst_video_format_get_row_stride (gamma->format, 0, gamma->width);
row_wrap = row_stride - width;
for (i = 0; i < height; i++) { for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) { for (j = 0; j < width; j++) {
@ -261,22 +232,20 @@ gst_gamma_planar_yuv_ip (GstGamma * gamma, guint8 * data)
} }
static void static void
gst_gamma_packed_yuv_ip (GstGamma * gamma, guint8 * data) gst_gamma_packed_yuv_ip (GstGamma * gamma, GstVideoFrame * frame)
{ {
gint i, j, height; gint i, j, height;
gint width, row_stride, row_wrap; gint width, stride, row_wrap;
gint pixel_stride; gint pixel_stride;
const guint8 *table = gamma->gamma_table; const guint8 *table = gamma->gamma_table;
guint8 *data;
data = data + gst_video_format_get_component_offset (gamma->format, 0, data = GST_VIDEO_FRAME_COMP_DATA (frame, 0);
gamma->width, gamma->height); stride = GST_VIDEO_FRAME_COMP_STRIDE (frame, 0);
width = GST_VIDEO_FRAME_COMP_WIDTH (frame, 0);
width = gst_video_format_get_component_width (gamma->format, 0, gamma->width); height = GST_VIDEO_FRAME_COMP_HEIGHT (frame, 0);
height = gst_video_format_get_component_height (gamma->format, 0, pixel_stride = GST_VIDEO_FRAME_COMP_PSTRIDE (frame, 0);
gamma->height); row_wrap = stride - pixel_stride * width;
row_stride = gst_video_format_get_row_stride (gamma->format, 0, gamma->width);
pixel_stride = gst_video_format_get_pixel_stride (gamma->format, 0);
row_wrap = row_stride - pixel_stride * width;
for (i = 0; i < height; i++) { for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) { for (j = 0; j < width; j++) {
@ -302,29 +271,28 @@ static const gint cog_rgb_to_ycbcr_matrix_8bit_sdtv[] = {
#define APPLY_MATRIX(m,o,v1,v2,v3) ((m[o*4] * v1 + m[o*4+1] * v2 + m[o*4+2] * v3 + m[o*4+3]) >> 8) #define APPLY_MATRIX(m,o,v1,v2,v3) ((m[o*4] * v1 + m[o*4+1] * v2 + m[o*4+2] * v3 + m[o*4+3]) >> 8)
static void static void
gst_gamma_packed_rgb_ip (GstGamma * gamma, guint8 * data) gst_gamma_packed_rgb_ip (GstGamma * gamma, GstVideoFrame * frame)
{ {
gint i, j, height; gint i, j, height;
gint width, row_stride, row_wrap; gint width, stride, row_wrap;
gint pixel_stride; gint pixel_stride;
const guint8 *table = gamma->gamma_table; const guint8 *table = gamma->gamma_table;
gint offsets[3]; gint offsets[3];
gint r, g, b; gint r, g, b;
gint y, u, v; gint y, u, v;
guint8 *data;
offsets[0] = gst_video_format_get_component_offset (gamma->format, 0, data = GST_VIDEO_FRAME_PLANE_DATA (frame, 0);
gamma->width, gamma->height); stride = GST_VIDEO_FRAME_PLANE_STRIDE (frame, 0);
offsets[1] = gst_video_format_get_component_offset (gamma->format, 1, width = GST_VIDEO_FRAME_COMP_WIDTH (frame, 0);
gamma->width, gamma->height); height = GST_VIDEO_FRAME_COMP_HEIGHT (frame, 0);
offsets[2] = gst_video_format_get_component_offset (gamma->format, 2,
gamma->width, gamma->height);
width = gst_video_format_get_component_width (gamma->format, 0, gamma->width); offsets[0] = GST_VIDEO_FRAME_COMP_OFFSET (frame, 0);
height = gst_video_format_get_component_height (gamma->format, 0, offsets[1] = GST_VIDEO_FRAME_COMP_OFFSET (frame, 1);
gamma->height); offsets[2] = GST_VIDEO_FRAME_COMP_OFFSET (frame, 2);
row_stride = gst_video_format_get_row_stride (gamma->format, 0, gamma->width);
pixel_stride = gst_video_format_get_pixel_stride (gamma->format, 0); pixel_stride = GST_VIDEO_FRAME_COMP_PSTRIDE (frame, 0);
row_wrap = row_stride - pixel_stride * width; row_wrap = stride - pixel_stride * width;
for (i = 0; i < height; i++) { for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) { for (j = 0; j < width; j++) {
@ -355,19 +323,18 @@ gst_gamma_set_caps (GstBaseTransform * base, GstCaps * incaps,
GstCaps * outcaps) GstCaps * outcaps)
{ {
GstGamma *gamma = GST_GAMMA (base); GstGamma *gamma = GST_GAMMA (base);
GstVideoInfo info;
GST_DEBUG_OBJECT (gamma, GST_DEBUG_OBJECT (gamma,
"setting caps: in %" GST_PTR_FORMAT " out %" GST_PTR_FORMAT, incaps, "setting caps: in %" GST_PTR_FORMAT " out %" GST_PTR_FORMAT, incaps,
outcaps); outcaps);
if (!gst_video_format_parse_caps (incaps, &gamma->format, &gamma->width, if (!gst_video_info_from_caps (&info, incaps))
&gamma->height))
goto invalid_caps; goto invalid_caps;
gamma->size = gamma->info = info;
gst_video_format_get_size (gamma->format, gamma->width, gamma->height);
switch (gamma->format) { switch (GST_VIDEO_INFO_FORMAT (&info)) {
case GST_VIDEO_FORMAT_I420: case GST_VIDEO_FORMAT_I420:
case GST_VIDEO_FORMAT_YV12: case GST_VIDEO_FORMAT_YV12:
case GST_VIDEO_FORMAT_Y41B: case GST_VIDEO_FORMAT_Y41B:
@ -403,8 +370,10 @@ gst_gamma_set_caps (GstBaseTransform * base, GstCaps * incaps,
return TRUE; return TRUE;
invalid_caps: invalid_caps:
{
GST_ERROR_OBJECT (gamma, "Invalid caps: %" GST_PTR_FORMAT, incaps); GST_ERROR_OBJECT (gamma, "Invalid caps: %" GST_PTR_FORMAT, incaps);
return FALSE; return FALSE;
}
} }
static void static void
@ -428,8 +397,7 @@ static GstFlowReturn
gst_gamma_transform_ip (GstBaseTransform * base, GstBuffer * outbuf) gst_gamma_transform_ip (GstBaseTransform * base, GstBuffer * outbuf)
{ {
GstGamma *gamma = GST_GAMMA (base); GstGamma *gamma = GST_GAMMA (base);
guint8 *data; GstVideoFrame frame;
gsize size;
if (!gamma->process) if (!gamma->process)
goto not_negotiated; goto not_negotiated;
@ -437,26 +405,23 @@ gst_gamma_transform_ip (GstBaseTransform * base, GstBuffer * outbuf)
if (base->passthrough) if (base->passthrough)
goto done; goto done;
data = gst_buffer_map (outbuf, &size, NULL, GST_MAP_READWRITE); if (!gst_video_frame_map (&frame, &gamma->info, outbuf, GST_MAP_READWRITE))
goto wrong_buffer;
if (size != gamma->size)
goto wrong_size;
GST_OBJECT_LOCK (gamma); GST_OBJECT_LOCK (gamma);
gamma->process (gamma, data); gamma->process (gamma, &frame);
GST_OBJECT_UNLOCK (gamma); GST_OBJECT_UNLOCK (gamma);
gst_buffer_unmap (outbuf, data, size); gst_video_frame_unmap (&frame);
done: done:
return GST_FLOW_OK; return GST_FLOW_OK;
/* ERRORS */ /* ERRORS */
wrong_size: wrong_buffer:
{ {
GST_ELEMENT_ERROR (gamma, STREAM, FORMAT, GST_ELEMENT_ERROR (gamma, STREAM, FORMAT,
(NULL), ("Invalid buffer size %d, expected %d", size, gamma->size)); (NULL), ("Invalid buffer received"));
gst_buffer_unmap (outbuf, data, size);
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
} }
not_negotiated: not_negotiated:

View file

@ -56,10 +56,7 @@ struct _GstGamma
/* < private > */ /* < private > */
/* format */ /* format */
GstVideoFormat format; GstVideoInfo info;
gint width;
gint height;
gint size;
/* properties */ /* properties */
gdouble gamma; gdouble gamma;
@ -67,7 +64,7 @@ struct _GstGamma
/* tables */ /* tables */
guint8 gamma_table[256]; guint8 gamma_table[256];
void (*process) (GstGamma *gamma, guint8 *data); void (*process) (GstGamma *gamma, GstVideoFrame *frame);
}; };
struct _GstGammaClass struct _GstGammaClass

View file

@ -71,50 +71,26 @@ enum
}; };
static GstStaticPadTemplate gst_video_balance_src_template = static GstStaticPadTemplate gst_video_balance_src_template =
GST_STATIC_PAD_TEMPLATE ("src", GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC, GST_PAD_SRC,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AYUV") ";" GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ AYUV, "
GST_VIDEO_CAPS_ARGB ";" GST_VIDEO_CAPS_BGRA ";" "ARGB, BGRA, ABGR, RGBA, Y444, xRGB, RGBx, "
GST_VIDEO_CAPS_ABGR ";" GST_VIDEO_CAPS_RGBA ";" "xBGR, BGRx, RGB, BGR, Y42B, YUY2, UYVY, YVYU, "
GST_VIDEO_CAPS_YUV ("Y444") ";" "I420, YV12, IYUV, Y41B }"))
GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_RGBx ";"
GST_VIDEO_CAPS_xBGR ";" GST_VIDEO_CAPS_BGRx ";"
GST_VIDEO_CAPS_RGB ";" GST_VIDEO_CAPS_BGR ";"
GST_VIDEO_CAPS_YUV ("Y42B") ";"
GST_VIDEO_CAPS_YUV ("YUY2") ";"
GST_VIDEO_CAPS_YUV ("UYVY") ";"
GST_VIDEO_CAPS_YUV ("YVYU") ";"
GST_VIDEO_CAPS_YUV ("I420") ";"
GST_VIDEO_CAPS_YUV ("YV12") ";"
GST_VIDEO_CAPS_YUV ("IYUV") ";" GST_VIDEO_CAPS_YUV ("Y41B")
)
); );
static GstStaticPadTemplate gst_video_balance_sink_template = static GstStaticPadTemplate gst_video_balance_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink", GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK, GST_PAD_SINK,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AYUV") ";" GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ AYUV, "
GST_VIDEO_CAPS_ARGB ";" GST_VIDEO_CAPS_BGRA ";" "ARGB, BGRA, ABGR, RGBA, Y444, xRGB, RGBx, "
GST_VIDEO_CAPS_ABGR ";" GST_VIDEO_CAPS_RGBA ";" "xBGR, BGRx, RGB, BGR, Y42B, YUY2, UYVY, YVYU, "
GST_VIDEO_CAPS_YUV ("Y444") ";" "I420, YV12, IYUV, Y41B }"))
GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_RGBx ";"
GST_VIDEO_CAPS_xBGR ";" GST_VIDEO_CAPS_BGRx ";"
GST_VIDEO_CAPS_RGB ";" GST_VIDEO_CAPS_BGR ";"
GST_VIDEO_CAPS_YUV ("Y42B") ";"
GST_VIDEO_CAPS_YUV ("YUY2") ";"
GST_VIDEO_CAPS_YUV ("UYVY") ";"
GST_VIDEO_CAPS_YUV ("YVYU") ";"
GST_VIDEO_CAPS_YUV ("I420") ";"
GST_VIDEO_CAPS_YUV ("YV12") ";"
GST_VIDEO_CAPS_YUV ("IYUV") ";" GST_VIDEO_CAPS_YUV ("Y41B")
)
); );
static void gst_video_balance_colorbalance_init (GstColorBalanceClass * iface); static void gst_video_balance_colorbalance_init (GstColorBalanceClass * iface);
static void gst_video_balance_interface_init (GstImplementsInterfaceClass *
klass);
static void gst_video_balance_set_property (GObject * object, guint prop_id, static void gst_video_balance_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec); const GValue * value, GParamSpec * pspec);
@ -124,8 +100,6 @@ static void gst_video_balance_get_property (GObject * object, guint prop_id,
#define gst_video_balance_parent_class parent_class #define gst_video_balance_parent_class parent_class
G_DEFINE_TYPE_WITH_CODE (GstVideoBalance, gst_video_balance, G_DEFINE_TYPE_WITH_CODE (GstVideoBalance, gst_video_balance,
GST_TYPE_VIDEO_FILTER, GST_TYPE_VIDEO_FILTER,
G_IMPLEMENT_INTERFACE (GST_TYPE_IMPLEMENTS_INTERFACE,
gst_video_balance_interface_init);
G_IMPLEMENT_INTERFACE (GST_TYPE_COLOR_BALANCE, G_IMPLEMENT_INTERFACE (GST_TYPE_COLOR_BALANCE,
gst_video_balance_colorbalance_init)); gst_video_balance_colorbalance_init));
@ -192,26 +166,24 @@ gst_video_balance_update_properties (GstVideoBalance * videobalance)
} }
static void static void
gst_video_balance_planar_yuv (GstVideoBalance * videobalance, guint8 * data) gst_video_balance_planar_yuv (GstVideoBalance * videobalance,
GstVideoFrame * frame)
{ {
gint x, y; gint x, y;
guint8 *ydata; guint8 *ydata;
guint8 *udata, *vdata; guint8 *udata, *vdata;
gint ystride, ustride, vstride; gint ystride, ustride, vstride;
GstVideoFormat format;
gint width, height; gint width, height;
gint width2, height2; gint width2, height2;
guint8 *tabley = videobalance->tabley; guint8 *tabley = videobalance->tabley;
guint8 **tableu = videobalance->tableu; guint8 **tableu = videobalance->tableu;
guint8 **tablev = videobalance->tablev; guint8 **tablev = videobalance->tablev;
format = videobalance->format; width = GST_VIDEO_FRAME_WIDTH (frame);
width = videobalance->width; height = GST_VIDEO_FRAME_HEIGHT (frame);
height = videobalance->height;
ydata = ydata = GST_VIDEO_FRAME_PLANE_DATA (frame, 0);
data + gst_video_format_get_component_offset (format, 0, width, height); ystride = GST_VIDEO_FRAME_PLANE_STRIDE (frame, 0);
ystride = gst_video_format_get_row_stride (format, 0, width);
for (y = 0; y < height; y++) { for (y = 0; y < height; y++) {
guint8 *yptr; guint8 *yptr;
@ -223,15 +195,13 @@ gst_video_balance_planar_yuv (GstVideoBalance * videobalance, guint8 * data)
} }
} }
width2 = gst_video_format_get_component_width (format, 1, width); width2 = GST_VIDEO_FRAME_COMP_WIDTH (frame, 1);
height2 = gst_video_format_get_component_height (format, 1, height); height2 = GST_VIDEO_FRAME_COMP_HEIGHT (frame, 1);
udata = udata = GST_VIDEO_FRAME_PLANE_DATA (frame, 1);
data + gst_video_format_get_component_offset (format, 1, width, height); vdata = GST_VIDEO_FRAME_PLANE_DATA (frame, 2);
vdata = ustride = GST_VIDEO_FRAME_PLANE_STRIDE (frame, 1);
data + gst_video_format_get_component_offset (format, 2, width, height); vstride = GST_VIDEO_FRAME_PLANE_STRIDE (frame, 2);
ustride = gst_video_format_get_row_stride (format, 1, width);
vstride = gst_video_format_get_row_stride (format, 1, width);
for (y = 0; y < height2; y++) { for (y = 0; y < height2; y++) {
guint8 *uptr, *vptr; guint8 *uptr, *vptr;
@ -251,57 +221,49 @@ gst_video_balance_planar_yuv (GstVideoBalance * videobalance, guint8 * data)
} }
static void static void
gst_video_balance_packed_yuv (GstVideoBalance * videobalance, guint8 * data) gst_video_balance_packed_yuv (GstVideoBalance * videobalance,
GstVideoFrame * frame)
{ {
gint x, y; gint x, y, stride;
guint8 *ydata; guint8 *ydata, *udata, *vdata;
guint8 *udata, *vdata;
gint ystride, ustride, vstride;
gint yoff, uoff, voff; gint yoff, uoff, voff;
GstVideoFormat format;
gint width, height; gint width, height;
gint width2, height2; gint width2, height2;
guint8 *tabley = videobalance->tabley; guint8 *tabley = videobalance->tabley;
guint8 **tableu = videobalance->tableu; guint8 **tableu = videobalance->tableu;
guint8 **tablev = videobalance->tablev; guint8 **tablev = videobalance->tablev;
format = videobalance->format; width = GST_VIDEO_FRAME_WIDTH (frame);
width = videobalance->width; height = GST_VIDEO_FRAME_HEIGHT (frame);
height = videobalance->height;
ydata = stride = GST_VIDEO_FRAME_PLANE_STRIDE (frame, 0);
data + gst_video_format_get_component_offset (format, 0, width, height); ydata = GST_VIDEO_FRAME_COMP_DATA (frame, 0);
ystride = gst_video_format_get_row_stride (format, 0, width); yoff = GST_VIDEO_FRAME_COMP_PSTRIDE (frame, 0);
yoff = gst_video_format_get_pixel_stride (format, 0);
for (y = 0; y < height; y++) { for (y = 0; y < height; y++) {
guint8 *yptr; guint8 *yptr;
yptr = ydata + y * ystride; yptr = ydata + y * stride;
for (x = 0; x < width; x++) { for (x = 0; x < width; x++) {
*yptr = tabley[*yptr]; *yptr = tabley[*yptr];
yptr += yoff; yptr += yoff;
} }
} }
width2 = gst_video_format_get_component_width (format, 1, width); width2 = GST_VIDEO_FRAME_COMP_WIDTH (frame, 1);
height2 = gst_video_format_get_component_height (format, 1, height); height2 = GST_VIDEO_FRAME_COMP_HEIGHT (frame, 1);
udata = udata = GST_VIDEO_FRAME_COMP_DATA (frame, 1);
data + gst_video_format_get_component_offset (format, 1, width, height); vdata = GST_VIDEO_FRAME_COMP_DATA (frame, 2);
vdata = uoff = GST_VIDEO_FRAME_COMP_PSTRIDE (frame, 1);
data + gst_video_format_get_component_offset (format, 2, width, height); voff = GST_VIDEO_FRAME_COMP_PSTRIDE (frame, 2);
ustride = gst_video_format_get_row_stride (format, 1, width);
vstride = gst_video_format_get_row_stride (format, 1, width);
uoff = gst_video_format_get_pixel_stride (format, 1);
voff = gst_video_format_get_pixel_stride (format, 2);
for (y = 0; y < height2; y++) { for (y = 0; y < height2; y++) {
guint8 *uptr, *vptr; guint8 *uptr, *vptr;
guint8 u1, v1; guint8 u1, v1;
uptr = udata + y * ustride; uptr = udata + y * stride;
vptr = vdata + y * vstride; vptr = vdata + y * stride;
for (x = 0; x < width2; x++) { for (x = 0; x < width2; x++) {
u1 = *uptr; u1 = *uptr;
@ -331,11 +293,13 @@ static const gint cog_rgb_to_ycbcr_matrix_8bit_sdtv[] = {
#define APPLY_MATRIX(m,o,v1,v2,v3) ((m[o*4] * v1 + m[o*4+1] * v2 + m[o*4+2] * v3 + m[o*4+3]) >> 8) #define APPLY_MATRIX(m,o,v1,v2,v3) ((m[o*4] * v1 + m[o*4+1] * v2 + m[o*4+2] * v3 + m[o*4+3]) >> 8)
static void static void
gst_video_balance_packed_rgb (GstVideoBalance * videobalance, guint8 * data) gst_video_balance_packed_rgb (GstVideoBalance * videobalance,
GstVideoFrame * frame)
{ {
gint i, j, height; gint i, j, height;
gint width, row_stride, row_wrap; gint width, stride, row_wrap;
gint pixel_stride; gint pixel_stride;
guint8 *data;
gint offsets[3]; gint offsets[3];
gint r, g, b; gint r, g, b;
gint y, u, v; gint y, u, v;
@ -344,24 +308,18 @@ gst_video_balance_packed_rgb (GstVideoBalance * videobalance, guint8 * data)
guint8 **tableu = videobalance->tableu; guint8 **tableu = videobalance->tableu;
guint8 **tablev = videobalance->tablev; guint8 **tablev = videobalance->tablev;
offsets[0] = gst_video_format_get_component_offset (videobalance->format, 0, width = GST_VIDEO_FRAME_WIDTH (frame);
videobalance->width, videobalance->height); height = GST_VIDEO_FRAME_HEIGHT (frame);
offsets[1] = gst_video_format_get_component_offset (videobalance->format, 1,
videobalance->width, videobalance->height);
offsets[2] = gst_video_format_get_component_offset (videobalance->format, 2,
videobalance->width, videobalance->height);
width = offsets[0] = GST_VIDEO_FRAME_COMP_OFFSET (frame, 0);
gst_video_format_get_component_width (videobalance->format, 0, offsets[1] = GST_VIDEO_FRAME_COMP_OFFSET (frame, 1);
videobalance->width); offsets[2] = GST_VIDEO_FRAME_COMP_OFFSET (frame, 2);
height =
gst_video_format_get_component_height (videobalance->format, 0, data = GST_VIDEO_FRAME_PLANE_DATA (frame, 0);
videobalance->height); stride = GST_VIDEO_FRAME_PLANE_STRIDE (frame, 0);
row_stride =
gst_video_format_get_row_stride (videobalance->format, 0, pixel_stride = GST_VIDEO_FRAME_COMP_PSTRIDE (frame, 0);
videobalance->width); row_wrap = stride - pixel_stride * width;
pixel_stride = gst_video_format_get_pixel_stride (videobalance->format, 0);
row_wrap = row_stride - pixel_stride * width;
for (i = 0; i < height; i++) { for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) { for (j = 0; j < width; j++) {
@ -400,21 +358,17 @@ gst_video_balance_set_caps (GstBaseTransform * base, GstCaps * incaps,
GstCaps * outcaps) GstCaps * outcaps)
{ {
GstVideoBalance *videobalance = GST_VIDEO_BALANCE (base); GstVideoBalance *videobalance = GST_VIDEO_BALANCE (base);
GstVideoInfo info;
GST_DEBUG_OBJECT (videobalance, GST_DEBUG_OBJECT (videobalance,
"in %" GST_PTR_FORMAT " out %" GST_PTR_FORMAT, incaps, outcaps); "in %" GST_PTR_FORMAT " out %" GST_PTR_FORMAT, incaps, outcaps);
videobalance->process = NULL; videobalance->process = NULL;
if (!gst_video_format_parse_caps (incaps, &videobalance->format, if (!gst_video_info_from_caps (&info, incaps))
&videobalance->width, &videobalance->height))
goto invalid_caps; goto invalid_caps;
videobalance->size = switch (GST_VIDEO_INFO_FORMAT (&info)) {
gst_video_format_get_size (videobalance->format, videobalance->width,
videobalance->height);
switch (videobalance->format) {
case GST_VIDEO_FORMAT_I420: case GST_VIDEO_FORMAT_I420:
case GST_VIDEO_FORMAT_YV12: case GST_VIDEO_FORMAT_YV12:
case GST_VIDEO_FORMAT_Y41B: case GST_VIDEO_FORMAT_Y41B:
@ -441,14 +395,24 @@ gst_video_balance_set_caps (GstBaseTransform * base, GstCaps * incaps,
videobalance->process = gst_video_balance_packed_rgb; videobalance->process = gst_video_balance_packed_rgb;
break; break;
default: default:
goto unknown_format;
break; break;
} }
return videobalance->process != NULL; videobalance->info = info;
return TRUE;
invalid_caps: invalid_caps:
{
GST_ERROR_OBJECT (videobalance, "Invalid caps: %" GST_PTR_FORMAT, incaps); GST_ERROR_OBJECT (videobalance, "Invalid caps: %" GST_PTR_FORMAT, incaps);
return FALSE; return FALSE;
}
unknown_format:
{
GST_ERROR_OBJECT (videobalance, "unknown format %" GST_PTR_FORMAT, incaps);
return FALSE;
}
} }
static void static void
@ -472,8 +436,7 @@ static GstFlowReturn
gst_video_balance_transform_ip (GstBaseTransform * base, GstBuffer * outbuf) gst_video_balance_transform_ip (GstBaseTransform * base, GstBuffer * outbuf)
{ {
GstVideoBalance *videobalance = GST_VIDEO_BALANCE (base); GstVideoBalance *videobalance = GST_VIDEO_BALANCE (base);
guint8 *data; GstVideoFrame frame;
gsize size;
if (!videobalance->process) if (!videobalance->process)
goto not_negotiated; goto not_negotiated;
@ -482,32 +445,31 @@ gst_video_balance_transform_ip (GstBaseTransform * base, GstBuffer * outbuf)
if (base->passthrough) if (base->passthrough)
goto done; goto done;
data = gst_buffer_map (outbuf, &size, NULL, GST_MAP_READWRITE); if (!gst_video_frame_map (&frame, &videobalance->info, outbuf,
GST_MAP_READWRITE))
if (size != videobalance->size) goto wrong_frame;
goto wrong_size;
GST_OBJECT_LOCK (videobalance); GST_OBJECT_LOCK (videobalance);
videobalance->process (videobalance, data); videobalance->process (videobalance, &frame);
GST_OBJECT_UNLOCK (videobalance); GST_OBJECT_UNLOCK (videobalance);
gst_buffer_unmap (outbuf, data, size); gst_video_frame_unmap (&frame);
done: done:
return GST_FLOW_OK; return GST_FLOW_OK;
/* ERRORS */ /* ERRORS */
wrong_size: wrong_frame:
{ {
GST_ELEMENT_ERROR (videobalance, STREAM, FORMAT, GST_ELEMENT_ERROR (videobalance, STREAM, FORMAT,
(NULL), ("Invalid buffer size %d, expected %d", size, (NULL), ("Invalid buffer received"));
videobalance->size));
gst_buffer_unmap (outbuf, data, size);
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
} }
not_negotiated: not_negotiated:
{
GST_ERROR_OBJECT (videobalance, "Not negotiated yet"); GST_ERROR_OBJECT (videobalance, "Not negotiated yet");
return GST_FLOW_NOT_NEGOTIATED; return GST_FLOW_NOT_NEGOTIATED;
}
} }
static void static void
@ -618,20 +580,6 @@ gst_video_balance_init (GstVideoBalance * videobalance)
} }
} }
static gboolean
gst_video_balance_interface_supported (GstImplementsInterface * iface,
GType type)
{
g_assert (type == GST_TYPE_COLOR_BALANCE);
return TRUE;
}
static void
gst_video_balance_interface_init (GstImplementsInterfaceClass * klass)
{
klass->supported = gst_video_balance_interface_supported;
}
static const GList * static const GList *
gst_video_balance_colorbalance_list_channels (GstColorBalance * balance) gst_video_balance_colorbalance_list_channels (GstColorBalance * balance)
{ {

View file

@ -61,17 +61,14 @@ struct _GstVideoBalance {
gdouble saturation; gdouble saturation;
/* format */ /* format */
GstVideoFormat format; GstVideoInfo info;
gint width;
gint height;
gint size;
/* tables */ /* tables */
guint8 tabley[256]; guint8 tabley[256];
guint8 *tableu[256]; guint8 *tableu[256];
guint8 *tablev[256]; guint8 *tablev[256];
void (*process) (GstVideoBalance *balance, guint8 *data); void (*process) (GstVideoBalance *balance, GstVideoFrame *frame);
}; };
struct _GstVideoBalanceClass { struct _GstVideoBalanceClass {

View file

@ -65,40 +65,21 @@ GST_DEBUG_CATEGORY_STATIC (video_flip_debug);
#define GST_CAT_DEFAULT video_flip_debug #define GST_CAT_DEFAULT video_flip_debug
static GstStaticPadTemplate gst_video_flip_src_template = static GstStaticPadTemplate gst_video_flip_src_template =
GST_STATIC_PAD_TEMPLATE ("src", GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC, GST_PAD_SRC,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AYUV") ";" GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ AYUV, "
GST_VIDEO_CAPS_ARGB ";" GST_VIDEO_CAPS_BGRA ";" "ARGB, BGRA, ABGR, RGBA, Y444, xRGB, RGBx,xBGR, BGRx, "
GST_VIDEO_CAPS_ABGR ";" GST_VIDEO_CAPS_RGBA ";" "RGB, BGR, I420, YV12, IYUV YUY2, UYVY, YVYU }"))
GST_VIDEO_CAPS_YUV ("Y444") ";"
GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_RGBx ";"
GST_VIDEO_CAPS_xBGR ";" GST_VIDEO_CAPS_BGRx ";"
GST_VIDEO_CAPS_RGB ";" GST_VIDEO_CAPS_BGR ";"
GST_VIDEO_CAPS_YUV ("I420") ";"
GST_VIDEO_CAPS_YUV ("YV12") ";" GST_VIDEO_CAPS_YUV ("IYUV") ";"
GST_VIDEO_CAPS_YUV ("YUY2") ";" GST_VIDEO_CAPS_YUV ("UYVY") ";"
GST_VIDEO_CAPS_YUV ("YVYU")
)
); );
static GstStaticPadTemplate gst_video_flip_sink_template = static GstStaticPadTemplate gst_video_flip_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink", GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK, GST_PAD_SINK,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AYUV") ";" GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ AYUV, "
GST_VIDEO_CAPS_ARGB ";" GST_VIDEO_CAPS_BGRA ";" "ARGB, BGRA, ABGR, RGBA, Y444, xRGB, RGBx,xBGR, BGRx, "
GST_VIDEO_CAPS_ABGR ";" GST_VIDEO_CAPS_RGBA ";" "RGB, BGR, I420, YV12, IYUV YUY2, UYVY, YVYU }"))
GST_VIDEO_CAPS_YUV ("Y444") ";"
GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_RGBx ";"
GST_VIDEO_CAPS_xBGR ";" GST_VIDEO_CAPS_BGRx ";"
GST_VIDEO_CAPS_RGB ";" GST_VIDEO_CAPS_BGR ";"
GST_VIDEO_CAPS_YUV ("I420") ";"
GST_VIDEO_CAPS_YUV ("YV12") ";" GST_VIDEO_CAPS_YUV ("IYUV") ";"
GST_VIDEO_CAPS_YUV ("YUY2") ";" GST_VIDEO_CAPS_YUV ("UYVY") ";"
GST_VIDEO_CAPS_YUV ("YVYU")
)
); );
#define GST_TYPE_VIDEO_FLIP_METHOD (gst_video_flip_method_get_type()) #define GST_TYPE_VIDEO_FLIP_METHOD (gst_video_flip_method_get_type())
@ -204,78 +185,62 @@ static gboolean
gst_video_flip_get_unit_size (GstBaseTransform * btrans, GstCaps * caps, gst_video_flip_get_unit_size (GstBaseTransform * btrans, GstCaps * caps,
gsize * size) gsize * size)
{ {
GstVideoFormat format; GstVideoInfo info;
gint width, height;
if (!gst_video_format_parse_caps (caps, &format, &width, &height)) if (!gst_video_info_from_caps (&info, caps))
return FALSE; return FALSE;
*size = gst_video_format_get_size (format, width, height); *size = info.size;
GST_DEBUG_OBJECT (btrans, "our frame size is %d bytes (%dx%d)", *size, GST_DEBUG_OBJECT (btrans, "our frame size is %d bytes (%dx%d)", *size,
width, height); info.width, info.height);
return TRUE; return TRUE;
} }
static void static void
gst_video_flip_planar_yuv (GstVideoFlip * videoflip, guint8 * dest, gst_video_flip_planar_yuv (GstVideoFlip * videoflip, GstVideoFrame * dest,
const guint8 * src) const GstVideoFrame * src)
{ {
gint x, y; gint x, y;
guint8 const *s; guint8 const *s;
guint8 *d; 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_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_height, src_u_height, src_v_height;
gint src_y_width, src_u_width, src_v_width; gint src_y_width, src_u_width, src_v_width;
gint dest_y_stride, dest_u_stride, dest_v_stride; 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_height, dest_u_height, dest_v_height;
gint dest_y_width, dest_u_width, dest_v_width; gint dest_y_width, dest_u_width, dest_v_width;
src_y_stride = gst_video_format_get_row_stride (format, 0, sw); src_y_stride = GST_VIDEO_FRAME_PLANE_STRIDE (src, 0);
src_u_stride = gst_video_format_get_row_stride (format, 1, sw); src_u_stride = GST_VIDEO_FRAME_PLANE_STRIDE (src, 1);
src_v_stride = gst_video_format_get_row_stride (format, 2, sw); src_v_stride = GST_VIDEO_FRAME_PLANE_STRIDE (src, 2);
dest_y_stride = gst_video_format_get_row_stride (format, 0, dw); dest_y_stride = GST_VIDEO_FRAME_PLANE_STRIDE (dest, 0);
dest_u_stride = gst_video_format_get_row_stride (format, 1, dw); dest_u_stride = GST_VIDEO_FRAME_PLANE_STRIDE (dest, 1);
dest_v_stride = gst_video_format_get_row_stride (format, 2, dw); dest_v_stride = GST_VIDEO_FRAME_PLANE_STRIDE (dest, 2);
src_y_offset = gst_video_format_get_component_offset (format, 0, sw, sh); src_y_width = GST_VIDEO_FRAME_COMP_WIDTH (src, 0);
src_u_offset = gst_video_format_get_component_offset (format, 1, sw, sh); src_u_width = GST_VIDEO_FRAME_COMP_WIDTH (src, 1);
src_v_offset = gst_video_format_get_component_offset (format, 2, sw, sh); src_v_width = GST_VIDEO_FRAME_COMP_WIDTH (src, 2);
dest_y_offset = gst_video_format_get_component_offset (format, 0, dw, dh); dest_y_width = GST_VIDEO_FRAME_COMP_WIDTH (dest, 0);
dest_u_offset = gst_video_format_get_component_offset (format, 1, dw, dh); dest_u_width = GST_VIDEO_FRAME_COMP_WIDTH (dest, 1);
dest_v_offset = gst_video_format_get_component_offset (format, 2, dw, dh); dest_v_width = GST_VIDEO_FRAME_COMP_WIDTH (dest, 2);
src_y_width = gst_video_format_get_component_width (format, 0, sw); src_y_height = GST_VIDEO_FRAME_COMP_HEIGHT (src, 0);
src_u_width = gst_video_format_get_component_width (format, 1, sw); src_u_height = GST_VIDEO_FRAME_COMP_HEIGHT (src, 1);
src_v_width = gst_video_format_get_component_width (format, 2, sw); src_v_height = GST_VIDEO_FRAME_COMP_HEIGHT (src, 2);
dest_y_width = gst_video_format_get_component_width (format, 0, dw); dest_y_height = GST_VIDEO_FRAME_COMP_HEIGHT (dest, 0);
dest_u_width = gst_video_format_get_component_width (format, 1, dw); dest_u_height = GST_VIDEO_FRAME_COMP_HEIGHT (dest, 1);
dest_v_width = gst_video_format_get_component_width (format, 2, dw); dest_v_height = GST_VIDEO_FRAME_COMP_HEIGHT (dest, 2);
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) { switch (videoflip->method) {
case GST_VIDEO_FLIP_METHOD_90R: case GST_VIDEO_FLIP_METHOD_90R:
/* Flip Y */ /* Flip Y */
s = src + src_y_offset; s = GST_VIDEO_FRAME_PLANE_DATA (src, 0);
d = dest + dest_y_offset; d = GST_VIDEO_FRAME_PLANE_DATA (dest, 0);
for (y = 0; y < dest_y_height; y++) { for (y = 0; y < dest_y_height; y++) {
for (x = 0; x < dest_y_width; x++) { for (x = 0; x < dest_y_width; x++) {
d[y * dest_y_stride + x] = d[y * dest_y_stride + x] =
@ -283,8 +248,8 @@ gst_video_flip_planar_yuv (GstVideoFlip * videoflip, guint8 * dest,
} }
} }
/* Flip U */ /* Flip U */
s = src + src_u_offset; s = GST_VIDEO_FRAME_PLANE_DATA (src, 1);
d = dest + dest_u_offset; d = GST_VIDEO_FRAME_PLANE_DATA (dest, 1);
for (y = 0; y < dest_u_height; y++) { for (y = 0; y < dest_u_height; y++) {
for (x = 0; x < dest_u_width; x++) { for (x = 0; x < dest_u_width; x++) {
d[y * dest_u_stride + x] = d[y * dest_u_stride + x] =
@ -292,8 +257,8 @@ gst_video_flip_planar_yuv (GstVideoFlip * videoflip, guint8 * dest,
} }
} }
/* Flip V */ /* Flip V */
s = src + src_v_offset; s = GST_VIDEO_FRAME_PLANE_DATA (src, 2);
d = dest + dest_v_offset; d = GST_VIDEO_FRAME_PLANE_DATA (dest, 2);
for (y = 0; y < dest_v_height; y++) { for (y = 0; y < dest_v_height; y++) {
for (x = 0; x < dest_v_width; x++) { for (x = 0; x < dest_v_width; x++) {
d[y * dest_v_stride + x] = d[y * dest_v_stride + x] =
@ -303,8 +268,8 @@ gst_video_flip_planar_yuv (GstVideoFlip * videoflip, guint8 * dest,
break; break;
case GST_VIDEO_FLIP_METHOD_90L: case GST_VIDEO_FLIP_METHOD_90L:
/* Flip Y */ /* Flip Y */
s = src + src_y_offset; s = GST_VIDEO_FRAME_PLANE_DATA (src, 0);
d = dest + dest_y_offset; d = GST_VIDEO_FRAME_PLANE_DATA (dest, 0);
for (y = 0; y < dest_y_height; y++) { for (y = 0; y < dest_y_height; y++) {
for (x = 0; x < dest_y_width; x++) { for (x = 0; x < dest_y_width; x++) {
d[y * dest_y_stride + x] = d[y * dest_y_stride + x] =
@ -312,8 +277,8 @@ gst_video_flip_planar_yuv (GstVideoFlip * videoflip, guint8 * dest,
} }
} }
/* Flip U */ /* Flip U */
s = src + src_u_offset; s = GST_VIDEO_FRAME_PLANE_DATA (src, 1);
d = dest + dest_u_offset; d = GST_VIDEO_FRAME_PLANE_DATA (dest, 1);
for (y = 0; y < dest_u_height; y++) { for (y = 0; y < dest_u_height; y++) {
for (x = 0; x < dest_u_width; x++) { for (x = 0; x < dest_u_width; x++) {
d[y * dest_u_stride + x] = d[y * dest_u_stride + x] =
@ -321,8 +286,8 @@ gst_video_flip_planar_yuv (GstVideoFlip * videoflip, guint8 * dest,
} }
} }
/* Flip V */ /* Flip V */
s = src + src_v_offset; s = GST_VIDEO_FRAME_PLANE_DATA (src, 2);
d = dest + dest_v_offset; d = GST_VIDEO_FRAME_PLANE_DATA (dest, 2);
for (y = 0; y < dest_v_height; y++) { for (y = 0; y < dest_v_height; y++) {
for (x = 0; x < dest_v_width; x++) { for (x = 0; x < dest_v_width; x++) {
d[y * dest_v_stride + x] = d[y * dest_v_stride + x] =
@ -332,8 +297,8 @@ gst_video_flip_planar_yuv (GstVideoFlip * videoflip, guint8 * dest,
break; break;
case GST_VIDEO_FLIP_METHOD_180: case GST_VIDEO_FLIP_METHOD_180:
/* Flip Y */ /* Flip Y */
s = src + src_y_offset; s = GST_VIDEO_FRAME_PLANE_DATA (src, 0);
d = dest + dest_y_offset; d = GST_VIDEO_FRAME_PLANE_DATA (dest, 0);
for (y = 0; y < dest_y_height; y++) { for (y = 0; y < dest_y_height; y++) {
for (x = 0; x < dest_y_width; x++) { for (x = 0; x < dest_y_width; x++) {
d[y * dest_y_stride + x] = d[y * dest_y_stride + x] =
@ -341,8 +306,8 @@ gst_video_flip_planar_yuv (GstVideoFlip * videoflip, guint8 * dest,
} }
} }
/* Flip U */ /* Flip U */
s = src + src_u_offset; s = GST_VIDEO_FRAME_PLANE_DATA (src, 1);
d = dest + dest_u_offset; d = GST_VIDEO_FRAME_PLANE_DATA (dest, 1);
for (y = 0; y < dest_u_height; y++) { for (y = 0; y < dest_u_height; y++) {
for (x = 0; x < dest_u_width; x++) { for (x = 0; x < dest_u_width; x++) {
d[y * dest_u_stride + x] = d[y * dest_u_stride + x] =
@ -350,8 +315,8 @@ gst_video_flip_planar_yuv (GstVideoFlip * videoflip, guint8 * dest,
} }
} }
/* Flip V */ /* Flip V */
s = src + src_v_offset; s = GST_VIDEO_FRAME_PLANE_DATA (src, 2);
d = dest + dest_v_offset; d = GST_VIDEO_FRAME_PLANE_DATA (dest, 2);
for (y = 0; y < dest_v_height; y++) { for (y = 0; y < dest_v_height; y++) {
for (x = 0; x < dest_v_width; x++) { for (x = 0; x < dest_v_width; x++) {
d[y * dest_v_stride + x] = d[y * dest_v_stride + x] =
@ -361,8 +326,8 @@ gst_video_flip_planar_yuv (GstVideoFlip * videoflip, guint8 * dest,
break; break;
case GST_VIDEO_FLIP_METHOD_HORIZ: case GST_VIDEO_FLIP_METHOD_HORIZ:
/* Flip Y */ /* Flip Y */
s = src + src_y_offset; s = GST_VIDEO_FRAME_PLANE_DATA (src, 0);
d = dest + dest_y_offset; d = GST_VIDEO_FRAME_PLANE_DATA (dest, 0);
for (y = 0; y < dest_y_height; y++) { for (y = 0; y < dest_y_height; y++) {
for (x = 0; x < dest_y_width; x++) { for (x = 0; x < dest_y_width; x++) {
d[y * dest_y_stride + x] = d[y * dest_y_stride + x] =
@ -370,8 +335,8 @@ gst_video_flip_planar_yuv (GstVideoFlip * videoflip, guint8 * dest,
} }
} }
/* Flip U */ /* Flip U */
s = src + src_u_offset; s = GST_VIDEO_FRAME_PLANE_DATA (src, 1);
d = dest + dest_u_offset; d = GST_VIDEO_FRAME_PLANE_DATA (dest, 1);
for (y = 0; y < dest_u_height; y++) { for (y = 0; y < dest_u_height; y++) {
for (x = 0; x < dest_u_width; x++) { for (x = 0; x < dest_u_width; x++) {
d[y * dest_u_stride + x] = d[y * dest_u_stride + x] =
@ -379,8 +344,8 @@ gst_video_flip_planar_yuv (GstVideoFlip * videoflip, guint8 * dest,
} }
} }
/* Flip V */ /* Flip V */
s = src + src_v_offset; s = GST_VIDEO_FRAME_PLANE_DATA (src, 2);
d = dest + dest_v_offset; d = GST_VIDEO_FRAME_PLANE_DATA (dest, 2);
for (y = 0; y < dest_v_height; y++) { for (y = 0; y < dest_v_height; y++) {
for (x = 0; x < dest_v_width; x++) { for (x = 0; x < dest_v_width; x++) {
d[y * dest_v_stride + x] = d[y * dest_v_stride + x] =
@ -390,8 +355,8 @@ gst_video_flip_planar_yuv (GstVideoFlip * videoflip, guint8 * dest,
break; break;
case GST_VIDEO_FLIP_METHOD_VERT: case GST_VIDEO_FLIP_METHOD_VERT:
/* Flip Y */ /* Flip Y */
s = src + src_y_offset; s = GST_VIDEO_FRAME_PLANE_DATA (src, 0);
d = dest + dest_y_offset; d = GST_VIDEO_FRAME_PLANE_DATA (dest, 0);
for (y = 0; y < dest_y_height; y++) { for (y = 0; y < dest_y_height; y++) {
for (x = 0; x < dest_y_width; x++) { for (x = 0; x < dest_y_width; x++) {
d[y * dest_y_stride + x] = d[y * dest_y_stride + x] =
@ -399,8 +364,8 @@ gst_video_flip_planar_yuv (GstVideoFlip * videoflip, guint8 * dest,
} }
} }
/* Flip U */ /* Flip U */
s = src + src_u_offset; s = GST_VIDEO_FRAME_PLANE_DATA (src, 1);
d = dest + dest_u_offset; d = GST_VIDEO_FRAME_PLANE_DATA (dest, 1);
for (y = 0; y < dest_u_height; y++) { for (y = 0; y < dest_u_height; y++) {
for (x = 0; x < dest_u_width; x++) { for (x = 0; x < dest_u_width; x++) {
d[y * dest_u_stride + x] = d[y * dest_u_stride + x] =
@ -408,8 +373,8 @@ gst_video_flip_planar_yuv (GstVideoFlip * videoflip, guint8 * dest,
} }
} }
/* Flip V */ /* Flip V */
s = src + src_v_offset; s = GST_VIDEO_FRAME_PLANE_DATA (src, 2);
d = dest + dest_v_offset; d = GST_VIDEO_FRAME_PLANE_DATA (dest, 2);
for (y = 0; y < dest_v_height; y++) { for (y = 0; y < dest_v_height; y++) {
for (x = 0; x < dest_v_width; x++) { for (x = 0; x < dest_v_width; x++) {
d[y * dest_v_stride + x] = d[y * dest_v_stride + x] =
@ -419,24 +384,24 @@ gst_video_flip_planar_yuv (GstVideoFlip * videoflip, guint8 * dest,
break; break;
case GST_VIDEO_FLIP_METHOD_TRANS: case GST_VIDEO_FLIP_METHOD_TRANS:
/* Flip Y */ /* Flip Y */
s = src + src_y_offset; s = GST_VIDEO_FRAME_PLANE_DATA (src, 0);
d = dest + dest_y_offset; d = GST_VIDEO_FRAME_PLANE_DATA (dest, 0);
for (y = 0; y < dest_y_height; y++) { for (y = 0; y < dest_y_height; y++) {
for (x = 0; x < dest_y_width; x++) { for (x = 0; x < dest_y_width; x++) {
d[y * dest_y_stride + x] = s[x * src_y_stride + y]; d[y * dest_y_stride + x] = s[x * src_y_stride + y];
} }
} }
/* Flip U */ /* Flip U */
s = src + src_u_offset; s = GST_VIDEO_FRAME_PLANE_DATA (src, 1);
d = dest + dest_u_offset; d = GST_VIDEO_FRAME_PLANE_DATA (dest, 1);
for (y = 0; y < dest_u_height; y++) { for (y = 0; y < dest_u_height; y++) {
for (x = 0; x < dest_u_width; x++) { for (x = 0; x < dest_u_width; x++) {
d[y * dest_u_stride + x] = s[x * src_u_stride + y]; d[y * dest_u_stride + x] = s[x * src_u_stride + y];
} }
} }
/* Flip V */ /* Flip V */
s = src + src_v_offset; s = GST_VIDEO_FRAME_PLANE_DATA (src, 2);
d = dest + dest_v_offset; d = GST_VIDEO_FRAME_PLANE_DATA (dest, 2);
for (y = 0; y < dest_u_height; y++) { for (y = 0; y < dest_u_height; y++) {
for (x = 0; x < dest_u_width; x++) { for (x = 0; x < dest_u_width; x++) {
d[y * dest_v_stride + x] = s[x * src_v_stride + y]; d[y * dest_v_stride + x] = s[x * src_v_stride + y];
@ -445,8 +410,8 @@ gst_video_flip_planar_yuv (GstVideoFlip * videoflip, guint8 * dest,
break; break;
case GST_VIDEO_FLIP_METHOD_OTHER: case GST_VIDEO_FLIP_METHOD_OTHER:
/* Flip Y */ /* Flip Y */
s = src + src_y_offset; s = GST_VIDEO_FRAME_PLANE_DATA (src, 0);
d = dest + dest_y_offset; d = GST_VIDEO_FRAME_PLANE_DATA (dest, 0);
for (y = 0; y < dest_y_height; y++) { for (y = 0; y < dest_y_height; y++) {
for (x = 0; x < dest_y_width; x++) { for (x = 0; x < dest_y_width; x++) {
d[y * dest_y_stride + x] = d[y * dest_y_stride + x] =
@ -454,8 +419,8 @@ gst_video_flip_planar_yuv (GstVideoFlip * videoflip, guint8 * dest,
} }
} }
/* Flip U */ /* Flip U */
s = src + src_u_offset; s = GST_VIDEO_FRAME_PLANE_DATA (src, 1);
d = dest + dest_u_offset; d = GST_VIDEO_FRAME_PLANE_DATA (dest, 1);
for (y = 0; y < dest_u_height; y++) { for (y = 0; y < dest_u_height; y++) {
for (x = 0; x < dest_u_width; x++) { for (x = 0; x < dest_u_width; x++) {
d[y * dest_u_stride + x] = d[y * dest_u_stride + x] =
@ -463,8 +428,8 @@ gst_video_flip_planar_yuv (GstVideoFlip * videoflip, guint8 * dest,
} }
} }
/* Flip V */ /* Flip V */
s = src + src_v_offset; s = GST_VIDEO_FRAME_PLANE_DATA (src, 2);
d = dest + dest_v_offset; d = GST_VIDEO_FRAME_PLANE_DATA (dest, 2);
for (y = 0; y < dest_v_height; y++) { for (y = 0; y < dest_v_height; y++) {
for (x = 0; x < dest_v_width; x++) { for (x = 0; x < dest_v_width; x++) {
d[y * dest_v_stride + x] = d[y * dest_v_stride + x] =
@ -482,24 +447,26 @@ gst_video_flip_planar_yuv (GstVideoFlip * videoflip, guint8 * dest,
} }
static void static void
gst_video_flip_packed_simple (GstVideoFlip * videoflip, guint8 * dest, gst_video_flip_packed_simple (GstVideoFlip * videoflip, GstVideoFrame * dest,
const guint8 * src) const GstVideoFrame * src)
{ {
gint x, y, z; gint x, y, z;
guint8 const *s = src; guint8 const *s;
guint8 *d = dest; guint8 *d;
GstVideoFormat format = videoflip->format; gint sw = GST_VIDEO_FRAME_WIDTH (src);
gint sw = videoflip->from_width; gint sh = GST_VIDEO_FRAME_HEIGHT (src);
gint sh = videoflip->from_height; gint dw = GST_VIDEO_FRAME_WIDTH (dest);
gint dw = videoflip->to_width; gint dh = GST_VIDEO_FRAME_HEIGHT (dest);
gint dh = videoflip->to_height;
gint src_stride, dest_stride; gint src_stride, dest_stride;
gint bpp; gint bpp;
src_stride = gst_video_format_get_row_stride (format, 0, sw); s = GST_VIDEO_FRAME_PLANE_DATA (src, 0);
dest_stride = gst_video_format_get_row_stride (format, 0, dw); d = GST_VIDEO_FRAME_PLANE_DATA (dest, 0);
src_stride = GST_VIDEO_FRAME_PLANE_STRIDE (src, 0);
dest_stride = GST_VIDEO_FRAME_PLANE_STRIDE (dest, 0);
/* This is only true for non-subsampled formats! */ /* This is only true for non-subsampled formats! */
bpp = gst_video_format_get_pixel_stride (format, 0); bpp = GST_VIDEO_FRAME_COMP_PSTRIDE (src, 0);
switch (videoflip->method) { switch (videoflip->method) {
case GST_VIDEO_FLIP_METHOD_90R: case GST_VIDEO_FLIP_METHOD_90R:
@ -582,17 +549,16 @@ gst_video_flip_packed_simple (GstVideoFlip * videoflip, guint8 * dest,
static void static void
gst_video_flip_y422 (GstVideoFlip * videoflip, guint8 * dest, gst_video_flip_y422 (GstVideoFlip * videoflip, GstVideoFrame * dest,
const guint8 * src) const GstVideoFrame * src)
{ {
gint x, y; gint x, y;
guint8 const *s = src; guint8 const *s;
guint8 *d = dest; guint8 *d;
GstVideoFormat format = videoflip->format; gint sw = GST_VIDEO_FRAME_WIDTH (src);
gint sw = videoflip->from_width; gint sh = GST_VIDEO_FRAME_HEIGHT (src);
gint sh = videoflip->from_height; gint dw = GST_VIDEO_FRAME_WIDTH (dest);
gint dw = videoflip->to_width; gint dh = GST_VIDEO_FRAME_HEIGHT (dest);
gint dh = videoflip->to_height;
gint src_stride, dest_stride; gint src_stride, dest_stride;
gint bpp; gint bpp;
gint y_offset; gint y_offset;
@ -600,13 +566,16 @@ gst_video_flip_y422 (GstVideoFlip * videoflip, guint8 * dest,
gint v_offset; gint v_offset;
gint y_stride; gint y_stride;
src_stride = gst_video_format_get_row_stride (format, 0, sw); s = GST_VIDEO_FRAME_PLANE_DATA (src, 0);
dest_stride = gst_video_format_get_row_stride (format, 0, dw); d = GST_VIDEO_FRAME_PLANE_DATA (dest, 0);
y_offset = gst_video_format_get_component_offset (format, 0, sw, sh); src_stride = GST_VIDEO_FRAME_PLANE_STRIDE (src, 0);
u_offset = gst_video_format_get_component_offset (format, 1, sw, sh); dest_stride = GST_VIDEO_FRAME_PLANE_STRIDE (dest, 0);
v_offset = gst_video_format_get_component_offset (format, 2, sw, sh);
y_stride = gst_video_format_get_pixel_stride (format, 0); y_offset = GST_VIDEO_FRAME_COMP_OFFSET (src, 0);
u_offset = GST_VIDEO_FRAME_COMP_OFFSET (src, 1);
v_offset = GST_VIDEO_FRAME_COMP_OFFSET (src, 2);
y_stride = GST_VIDEO_FRAME_COMP_PSTRIDE (src, 0);
bpp = y_stride; bpp = y_stride;
switch (videoflip->method) { switch (videoflip->method) {
@ -800,20 +769,17 @@ gst_video_flip_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
GstCaps * outcaps) GstCaps * outcaps)
{ {
GstVideoFlip *vf = GST_VIDEO_FLIP (btrans); GstVideoFlip *vf = GST_VIDEO_FLIP (btrans);
GstVideoFormat in_format, out_format; GstVideoInfo in_info, out_info;
gboolean ret = FALSE; gboolean ret = FALSE;
vf->process = NULL; vf->process = NULL;
if (!gst_video_format_parse_caps (incaps, &in_format, &vf->from_width, if (!gst_video_info_from_caps (&in_info, incaps)
&vf->from_height) || !gst_video_info_from_caps (&out_info, outcaps))
|| !gst_video_format_parse_caps (outcaps, &out_format, &vf->to_width,
&vf->to_height))
goto invalid_caps; goto invalid_caps;
if (in_format != out_format) if (GST_VIDEO_INFO_FORMAT (&in_info) != GST_VIDEO_INFO_FORMAT (&out_info))
goto invalid_caps; goto invalid_caps;
vf->format = in_format;
/* Check that they are correct */ /* Check that they are correct */
switch (vf->method) { switch (vf->method) {
@ -821,11 +787,11 @@ gst_video_flip_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
case GST_VIDEO_FLIP_METHOD_90L: case GST_VIDEO_FLIP_METHOD_90L:
case GST_VIDEO_FLIP_METHOD_TRANS: case GST_VIDEO_FLIP_METHOD_TRANS:
case GST_VIDEO_FLIP_METHOD_OTHER: case GST_VIDEO_FLIP_METHOD_OTHER:
if ((vf->from_width != vf->to_height) || if ((in_info.width != out_info.height) ||
(vf->from_height != vf->to_width)) { (in_info.height != out_info.width)) {
GST_ERROR_OBJECT (vf, "we are inverting width and height but caps " GST_ERROR_OBJECT (vf, "we are inverting width and height but caps "
"are not correct : %dx%d to %dx%d", vf->from_width, "are not correct : %dx%d to %dx%d", in_info.width,
vf->from_height, vf->to_width, vf->to_height); in_info.height, out_info.width, out_info.height);
goto beach; goto beach;
} }
break; break;
@ -835,11 +801,11 @@ gst_video_flip_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
case GST_VIDEO_FLIP_METHOD_180: case GST_VIDEO_FLIP_METHOD_180:
case GST_VIDEO_FLIP_METHOD_HORIZ: case GST_VIDEO_FLIP_METHOD_HORIZ:
case GST_VIDEO_FLIP_METHOD_VERT: case GST_VIDEO_FLIP_METHOD_VERT:
if ((vf->from_width != vf->to_width) || if ((in_info.width != out_info.width) ||
(vf->from_height != vf->to_height)) { (in_info.height != out_info.height)) {
GST_ERROR_OBJECT (vf, "we are keeping width and height but caps " GST_ERROR_OBJECT (vf, "we are keeping width and height but caps "
"are not correct : %dx%d to %dx%d", vf->from_width, "are not correct : %dx%d to %dx%d", in_info.width,
vf->from_height, vf->to_width, vf->to_height); in_info.height, out_info.width, out_info.height);
goto beach; goto beach;
} }
break; break;
@ -849,8 +815,10 @@ gst_video_flip_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
} }
ret = TRUE; ret = TRUE;
vf->in_info = in_info;
vf->out_info = out_info;
switch (vf->format) { switch (GST_VIDEO_INFO_FORMAT (&in_info)) {
case GST_VIDEO_FORMAT_I420: case GST_VIDEO_FORMAT_I420:
case GST_VIDEO_FORMAT_YV12: case GST_VIDEO_FORMAT_YV12:
case GST_VIDEO_FORMAT_Y444: case GST_VIDEO_FORMAT_Y444:
@ -909,32 +877,48 @@ gst_video_flip_transform (GstBaseTransform * trans, GstBuffer * in,
GstBuffer * out) GstBuffer * out)
{ {
GstVideoFlip *videoflip = GST_VIDEO_FLIP (trans); GstVideoFlip *videoflip = GST_VIDEO_FLIP (trans);
guint8 *dest; GstVideoFrame dest;
guint8 *src; GstVideoFrame src;
gsize srcsize, destsize;
if (G_UNLIKELY (videoflip->process == NULL)) if (G_UNLIKELY (videoflip->process == NULL))
goto not_negotiated; goto not_negotiated;
src = gst_buffer_map (in, &srcsize, NULL, GST_MAP_READ); if (!gst_video_frame_map (&src, &videoflip->in_info, in, GST_MAP_READ))
dest = gst_buffer_map (out, &destsize, NULL, GST_MAP_WRITE); goto invalid_in;
if (!gst_video_frame_map (&dest, &videoflip->out_info, out, GST_MAP_WRITE))
goto invalid_out;
GST_LOG_OBJECT (videoflip, "videoflip: flipping %dx%d to %dx%d (%s)", GST_LOG_OBJECT (videoflip, "videoflip: flipping %dx%d to %dx%d (%s)",
videoflip->from_width, videoflip->from_height, videoflip->to_width, videoflip->in_info.width, videoflip->in_info.height,
videoflip->to_height, video_flip_methods[videoflip->method].value_nick); videoflip->out_info.width, videoflip->out_info.height,
video_flip_methods[videoflip->method].value_nick);
GST_OBJECT_LOCK (videoflip); GST_OBJECT_LOCK (videoflip);
videoflip->process (videoflip, dest, src); videoflip->process (videoflip, &dest, &src);
GST_OBJECT_UNLOCK (videoflip); GST_OBJECT_UNLOCK (videoflip);
gst_buffer_unmap (in, src, srcsize); gst_video_frame_unmap (&src);
gst_buffer_unmap (out, dest, destsize); gst_video_frame_unmap (&dest);
return GST_FLOW_OK; return GST_FLOW_OK;
not_negotiated: not_negotiated:
{
GST_ERROR_OBJECT (videoflip, "Not negotiated yet"); GST_ERROR_OBJECT (videoflip, "Not negotiated yet");
return GST_FLOW_NOT_NEGOTIATED; return GST_FLOW_NOT_NEGOTIATED;
}
invalid_in:
{
GST_ERROR_OBJECT (videoflip, "invalid input frame");
return GST_FLOW_OK;
}
invalid_out:
{
GST_ERROR_OBJECT (videoflip, "invalid output frame");
gst_video_frame_unmap (&src);
return GST_FLOW_OK;
}
} }
static gboolean static gboolean
@ -959,31 +943,31 @@ gst_video_flip_src_event (GstBaseTransform * trans, GstEvent * event)
switch (vf->method) { switch (vf->method) {
case GST_VIDEO_FLIP_METHOD_90R: case GST_VIDEO_FLIP_METHOD_90R:
new_x = y; new_x = y;
new_y = vf->to_width - x; new_y = vf->out_info.width - x;
break; break;
case GST_VIDEO_FLIP_METHOD_90L: case GST_VIDEO_FLIP_METHOD_90L:
new_x = vf->to_height - y; new_x = vf->out_info.height - y;
new_y = x; new_y = x;
break; break;
case GST_VIDEO_FLIP_METHOD_OTHER: case GST_VIDEO_FLIP_METHOD_OTHER:
new_x = vf->to_height - y; new_x = vf->out_info.height - y;
new_y = vf->to_width - x; new_y = vf->out_info.width - x;
break; break;
case GST_VIDEO_FLIP_METHOD_TRANS: case GST_VIDEO_FLIP_METHOD_TRANS:
new_x = y; new_x = y;
new_y = x; new_y = x;
break; break;
case GST_VIDEO_FLIP_METHOD_180: case GST_VIDEO_FLIP_METHOD_180:
new_x = vf->to_width - x; new_x = vf->out_info.width - x;
new_y = vf->to_height - y; new_y = vf->out_info.height - y;
break; break;
case GST_VIDEO_FLIP_METHOD_HORIZ: case GST_VIDEO_FLIP_METHOD_HORIZ:
new_x = vf->to_width - x; new_x = vf->out_info.width - x;
new_y = y; new_y = y;
break; break;
case GST_VIDEO_FLIP_METHOD_VERT: case GST_VIDEO_FLIP_METHOD_VERT:
new_x = x; new_x = x;
new_y = vf->to_height - y; new_y = vf->out_info.height - y;
break; break;
default: default:
new_x = x; new_x = x;

View file

@ -73,12 +73,11 @@ struct _GstVideoFlip {
GstVideoFilter videofilter; GstVideoFilter videofilter;
/* < private > */ /* < private > */
GstVideoFormat format; GstVideoInfo in_info;
gint from_width, from_height; GstVideoInfo out_info;
gint to_width, to_height;
GstVideoFlipMethod method; GstVideoFlipMethod method;
void (*process) (GstVideoFlip *videoflip, guint8 *dest, const guint8 *src); void (*process) (GstVideoFlip *videoflip, GstVideoFrame *dest, const GstVideoFrame *src);
}; };
struct _GstVideoFlipClass { struct _GstVideoFlipClass {