videosignal: add support for all planar YUV formats, using gstvideo
This commit is contained in:
parent
5b87b537be
commit
d171d713f3
@ -145,14 +145,14 @@ static GstStaticPadTemplate gst_video_detect_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 ("{ I420, YV12 }"))
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("{ I420, YV12, Y41B, Y42B, Y444 }"))
|
||||||
);
|
);
|
||||||
|
|
||||||
static GstStaticPadTemplate gst_video_detect_sink_template =
|
static GstStaticPadTemplate gst_video_detect_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 ("{ I420, YV12 }"))
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("{ I420, YV12, Y41B, Y42B, Y444 }"))
|
||||||
);
|
);
|
||||||
|
|
||||||
static GstVideoFilterClass *parent_class = NULL;
|
static GstVideoFilterClass *parent_class = NULL;
|
||||||
@ -163,6 +163,7 @@ gst_video_detect_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
|
|||||||
{
|
{
|
||||||
GstVideoDetect *vf;
|
GstVideoDetect *vf;
|
||||||
GstStructure *in_s;
|
GstStructure *in_s;
|
||||||
|
guint32 fourcc;
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
|
|
||||||
vf = GST_VIDEO_DETECT (btrans);
|
vf = GST_VIDEO_DETECT (btrans);
|
||||||
@ -171,13 +172,14 @@ gst_video_detect_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
|
|||||||
|
|
||||||
ret = gst_structure_get_int (in_s, "width", &vf->width);
|
ret = gst_structure_get_int (in_s, "width", &vf->width);
|
||||||
ret &= gst_structure_get_int (in_s, "height", &vf->height);
|
ret &= gst_structure_get_int (in_s, "height", &vf->height);
|
||||||
ret &= gst_structure_get_fourcc (in_s, "format", &vf->format);
|
ret &= gst_structure_get_fourcc (in_s, "format", &fourcc);
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
vf->format = gst_video_format_from_fourcc (fourcc);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define GST_VIDEO_I420_Y_ROWSTRIDE(width) (GST_ROUND_UP_4(width))
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_video_detect_post_message (GstVideoDetect * videodetect, GstBuffer * buffer,
|
gst_video_detect_post_message (GstVideoDetect * videodetect, GstBuffer * buffer,
|
||||||
guint data)
|
guint data)
|
||||||
@ -227,8 +229,9 @@ gst_video_detect_calc_brightness (GstVideoDetect * videodetect, guint8 * data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_video_detect_420 (GstVideoDetect * videodetect, GstBuffer * buffer)
|
gst_video_detect_yuv (GstVideoDetect * videodetect, GstBuffer * buffer)
|
||||||
{
|
{
|
||||||
|
GstVideoFormat format;
|
||||||
gdouble brightness;
|
gdouble brightness;
|
||||||
gint i, pw, ph, stride, width, height;
|
gint i, pw, ph, stride, width, height;
|
||||||
gint req_width, req_height;
|
gint req_width, req_height;
|
||||||
@ -237,12 +240,13 @@ gst_video_detect_420 (GstVideoDetect * videodetect, GstBuffer * buffer)
|
|||||||
|
|
||||||
data = GST_BUFFER_DATA (buffer);
|
data = GST_BUFFER_DATA (buffer);
|
||||||
|
|
||||||
|
format = videodetect->format;
|
||||||
width = videodetect->width;
|
width = videodetect->width;
|
||||||
height = videodetect->height;
|
height = videodetect->height;
|
||||||
|
|
||||||
pw = videodetect->pattern_width;
|
pw = videodetect->pattern_width;
|
||||||
ph = videodetect->pattern_height;
|
ph = videodetect->pattern_height;
|
||||||
stride = GST_VIDEO_I420_Y_ROWSTRIDE (width);
|
stride = gst_video_format_get_row_stride (format, 0, width);
|
||||||
|
|
||||||
req_width =
|
req_width =
|
||||||
(videodetect->pattern_count + videodetect->pattern_data_count) * pw +
|
(videodetect->pattern_count + videodetect->pattern_data_count) * pw +
|
||||||
@ -331,7 +335,7 @@ gst_video_detect_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
|
|||||||
|
|
||||||
videodetect = GST_VIDEO_DETECT (trans);
|
videodetect = GST_VIDEO_DETECT (trans);
|
||||||
|
|
||||||
gst_video_detect_420 (videodetect, buf);
|
gst_video_detect_yuv (videodetect, buf);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#define __GST_VIDEO_DETECT_H__
|
#define __GST_VIDEO_DETECT_H__
|
||||||
|
|
||||||
#include <gst/video/gstvideofilter.h>
|
#include <gst/video/gstvideofilter.h>
|
||||||
|
#include <gst/video/video.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
@ -47,7 +48,7 @@ struct _GstVideoDetect {
|
|||||||
GstVideoFilter videofilter;
|
GstVideoFilter videofilter;
|
||||||
|
|
||||||
gint width, height;
|
gint width, height;
|
||||||
guint32 format;
|
GstVideoFormat format;
|
||||||
|
|
||||||
gboolean message;
|
gboolean message;
|
||||||
gint pattern_width;
|
gint pattern_width;
|
||||||
|
@ -92,14 +92,14 @@ static GstStaticPadTemplate gst_video_mark_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 ("{ I420, YV12 }"))
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("{ I420, YV12, Y41B, Y42B, Y444 }"))
|
||||||
);
|
);
|
||||||
|
|
||||||
static GstStaticPadTemplate gst_video_mark_sink_template =
|
static GstStaticPadTemplate gst_video_mark_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 ("{ I420, YV12 }"))
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("{ I420, YV12, Y41B, Y42B, Y444 }"))
|
||||||
);
|
);
|
||||||
|
|
||||||
static GstVideoFilterClass *parent_class = NULL;
|
static GstVideoFilterClass *parent_class = NULL;
|
||||||
@ -110,6 +110,7 @@ gst_video_mark_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
|
|||||||
{
|
{
|
||||||
GstVideoMark *vf;
|
GstVideoMark *vf;
|
||||||
GstStructure *in_s;
|
GstStructure *in_s;
|
||||||
|
guint32 fourcc;
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
|
|
||||||
vf = GST_VIDEO_MARK (btrans);
|
vf = GST_VIDEO_MARK (btrans);
|
||||||
@ -118,13 +119,14 @@ gst_video_mark_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
|
|||||||
|
|
||||||
ret = gst_structure_get_int (in_s, "width", &vf->width);
|
ret = gst_structure_get_int (in_s, "width", &vf->width);
|
||||||
ret &= gst_structure_get_int (in_s, "height", &vf->height);
|
ret &= gst_structure_get_int (in_s, "height", &vf->height);
|
||||||
ret &= gst_structure_get_fourcc (in_s, "format", &vf->format);
|
ret &= gst_structure_get_fourcc (in_s, "format", &fourcc);
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
vf->format = gst_video_format_from_fourcc (fourcc);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define GST_VIDEO_I420_Y_ROWSTRIDE(width) (GST_ROUND_UP_4(width))
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_video_mark_draw_box (GstVideoMark * videomark, guint8 * data,
|
gst_video_mark_draw_box (GstVideoMark * videomark, guint8 * data,
|
||||||
gint width, gint height, gint stride, guint8 color)
|
gint width, gint height, gint stride, guint8 color)
|
||||||
@ -141,8 +143,9 @@ gst_video_mark_draw_box (GstVideoMark * videomark, guint8 * data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_video_mark_420 (GstVideoMark * videomark, GstBuffer * buffer)
|
gst_video_mark_yuv (GstVideoMark * videomark, GstBuffer * buffer)
|
||||||
{
|
{
|
||||||
|
GstVideoFormat format;
|
||||||
gint i, pw, ph, stride, width, height;
|
gint i, pw, ph, stride, width, height;
|
||||||
gint req_width, req_height;
|
gint req_width, req_height;
|
||||||
guint8 *d, *data;
|
guint8 *d, *data;
|
||||||
@ -151,12 +154,13 @@ gst_video_mark_420 (GstVideoMark * videomark, GstBuffer * buffer)
|
|||||||
|
|
||||||
data = GST_BUFFER_DATA (buffer);
|
data = GST_BUFFER_DATA (buffer);
|
||||||
|
|
||||||
|
format = videomark->format;
|
||||||
width = videomark->width;
|
width = videomark->width;
|
||||||
height = videomark->height;
|
height = videomark->height;
|
||||||
|
|
||||||
pw = videomark->pattern_width;
|
pw = videomark->pattern_width;
|
||||||
ph = videomark->pattern_height;
|
ph = videomark->pattern_height;
|
||||||
stride = GST_VIDEO_I420_Y_ROWSTRIDE (width);
|
stride = gst_video_format_get_row_stride (format, 0, width);
|
||||||
|
|
||||||
req_width =
|
req_width =
|
||||||
(videomark->pattern_count + videomark->pattern_data_count) * pw +
|
(videomark->pattern_count + videomark->pattern_data_count) * pw +
|
||||||
@ -223,7 +227,7 @@ gst_video_mark_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
|
|||||||
videomark = GST_VIDEO_MARK (trans);
|
videomark = GST_VIDEO_MARK (trans);
|
||||||
|
|
||||||
if (videomark->enabled)
|
if (videomark->enabled)
|
||||||
return gst_video_mark_420 (videomark, buf);
|
return gst_video_mark_yuv (videomark, buf);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#define __GST_VIDEO_MARK_H__
|
#define __GST_VIDEO_MARK_H__
|
||||||
|
|
||||||
#include <gst/video/gstvideofilter.h>
|
#include <gst/video/gstvideofilter.h>
|
||||||
|
#include <gst/video/video.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
@ -47,7 +48,7 @@ struct _GstVideoMark {
|
|||||||
GstVideoFilter videofilter;
|
GstVideoFilter videofilter;
|
||||||
|
|
||||||
gint width, height;
|
gint width, height;
|
||||||
guint32 format;
|
GstVideoFormat format;
|
||||||
|
|
||||||
gint pattern_width;
|
gint pattern_width;
|
||||||
gint pattern_height;
|
gint pattern_height;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user