mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-22 07:08:23 +00:00
rpicamsrc: Implement GstVideoDirection interface
Instead of implementing a custom property, we implement that interface.
This commit is contained in:
parent
2496d0e859
commit
39afecac32
2 changed files with 65 additions and 91 deletions
|
@ -119,7 +119,6 @@ enum
|
|||
PROP_ROTATION,
|
||||
PROP_HFLIP,
|
||||
PROP_VFLIP,
|
||||
PROP_ORIENTATION,
|
||||
PROP_ROI_X,
|
||||
PROP_ROI_Y,
|
||||
PROP_ROI_W,
|
||||
|
@ -134,11 +133,12 @@ enum
|
|||
PROP_ANNOTATION_TEXT_SIZE,
|
||||
PROP_ANNOTATION_TEXT_COLOUR,
|
||||
PROP_ANNOTATION_TEXT_BG_COLOUR,
|
||||
PROP_INTRA_REFRESH_TYPE
|
||||
PROP_INTRA_REFRESH_TYPE,
|
||||
#ifdef GST_RPI_CAM_SRC_ENABLE_VIDEO_DIRECTION
|
||||
PROP_VIDEO_DIRECTION
|
||||
#endif
|
||||
};
|
||||
|
||||
#define PROP_ORIENTATION_DEFAULT GST_RPI_CAM_ORIENTATION_IDENTITY
|
||||
|
||||
#define CAMERA_DEFAULT 0
|
||||
|
||||
#define BITRATE_DEFAULT 17000000 /* 17Mbit/s default for 1080p */
|
||||
|
@ -187,6 +187,12 @@ enum
|
|||
"alignment = (string) nal, " \
|
||||
"profile = (string) { baseline, main, high }"
|
||||
|
||||
#ifdef GST_RPI_CAM_SRC_ENABLE_VIDEO_DIRECTION
|
||||
#define gst_rpi_cam_src_reset_custom_orientation(src) { src->orientation = GST_VIDEO_ORIENTATION_CUSTOM; }
|
||||
#else
|
||||
#define gst_rpi_cam_src_reset_custom_orientation(src) { }
|
||||
#endif
|
||||
|
||||
static GstStaticPadTemplate video_src_template = GST_STATIC_PAD_TEMPLATE ("src",
|
||||
GST_PAD_SRC,
|
||||
GST_PAD_ALWAYS,
|
||||
|
@ -199,6 +205,9 @@ static void gst_rpi_cam_src_finalize (GObject *object);
|
|||
static void gst_rpi_cam_src_colorbalance_init (GstColorBalanceInterface *
|
||||
iface);
|
||||
static void gst_rpi_cam_src_orientation_init (GstVideoOrientationInterface * iface);
|
||||
#ifdef GST_RPI_CAM_SRC_ENABLE_VIDEO_DIRECTION
|
||||
static void gst_rpi_cam_src_direction_init (GstVideoDirectionInterface * iface);
|
||||
#endif
|
||||
|
||||
static void gst_rpi_cam_src_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec);
|
||||
|
@ -222,42 +231,15 @@ G_DEFINE_TYPE_WITH_CODE (GstRpiCamSrc, gst_rpi_cam_src,
|
|||
GST_TYPE_PUSH_SRC,
|
||||
G_IMPLEMENT_INTERFACE (GST_TYPE_COLOR_BALANCE,
|
||||
gst_rpi_cam_src_colorbalance_init);
|
||||
#ifdef GST_RPI_CAM_SRC_ENABLE_VIDEO_DIRECTION
|
||||
G_IMPLEMENT_INTERFACE (GST_TYPE_VIDEO_DIRECTION,
|
||||
gst_rpi_cam_src_direction_init);
|
||||
#endif
|
||||
G_IMPLEMENT_INTERFACE (GST_TYPE_VIDEO_ORIENTATION,
|
||||
gst_rpi_cam_src_orientation_init));
|
||||
|
||||
#define C_ENUM(v) ((gint) v)
|
||||
|
||||
#define GST_TYPE_RPI_CAM_ORIENTATION (gst_rpi_cam_orientation_get_type())
|
||||
|
||||
static const GEnumValue video_orientation_methods[] = {
|
||||
{GST_RPI_CAM_ORIENTATION_IDENTITY, "Identity (no rotation)", "none"},
|
||||
{GST_RPI_CAM_ORIENTATION_90R, "Rotate clockwise 90 degrees", "clockwise"},
|
||||
{GST_RPI_CAM_ORIENTATION_180, "Rotate 180 degrees", "rotate-180"},
|
||||
{GST_RPI_CAM_ORIENTATION_90L, "Rotate counter-clockwise 90 degrees",
|
||||
"counterclockwise"},
|
||||
{GST_RPI_CAM_ORIENTATION_FLIP_HORIZ, "Flip horizontally", "horizontal-flip"},
|
||||
{GST_RPI_CAM_ORIENTATION_FLIP_VERT, "Flip vertically", "vertical-flip"},
|
||||
{GST_RPI_CAM_ORIENTATION_FLIP_TRANS,
|
||||
"Flip across upper left/lower right diagonal", "upper-left-diagonal"},
|
||||
{GST_RPI_CAM_ORIENTATION_FLIP_OTHER,
|
||||
"Flip across upper right/lower left diagonal", "upper-right-diagonal"},
|
||||
{GST_RPI_CAM_ORIENTATION_CUSTOM,
|
||||
"Set through custom properties", "custom"},
|
||||
{0, NULL, NULL},
|
||||
};
|
||||
|
||||
static GType
|
||||
gst_rpi_cam_orientation_get_type (void)
|
||||
{
|
||||
static GType rpi_cam_orientation_type = 0;
|
||||
|
||||
if (!rpi_cam_orientation_type) {
|
||||
rpi_cam_orientation_type = g_enum_register_static ("GstRpiCamOrientation",
|
||||
video_orientation_methods);
|
||||
}
|
||||
return rpi_cam_orientation_type;
|
||||
}
|
||||
|
||||
GType
|
||||
gst_rpi_cam_src_sensor_mode_get_type (void)
|
||||
{
|
||||
|
@ -427,11 +409,6 @@ gst_rpi_cam_src_class_init (GstRpiCamSrcClass * klass)
|
|||
g_param_spec_boolean ("vflip", "Vertical Flip",
|
||||
"Flip capture vertically", FALSE,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property (gobject_class, PROP_ORIENTATION,
|
||||
g_param_spec_enum ("orientation", "Orientation", "Orientation",
|
||||
GST_TYPE_RPI_CAM_ORIENTATION, PROP_ORIENTATION_DEFAULT,
|
||||
GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property (gobject_class, PROP_ROI_X,
|
||||
g_param_spec_float ("roi-x", "ROI X",
|
||||
"Normalised region-of-interest X coord", 0, 1.0, 0,
|
||||
|
@ -496,6 +473,10 @@ gst_rpi_cam_src_class_init (GstRpiCamSrcClass * klass)
|
|||
g_param_spec_int ("annotation-text-bg-colour", "Annotation text background colour (VUY)",
|
||||
"Set the annotation text background colour, as a VUY hex value eg #8080FF, -1 for default", -1,
|
||||
G_MAXINT, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
#ifdef GST_RPI_CAM_SRC_ENABLE_VIDEO_DIRECTION
|
||||
g_object_class_override_property (gobject_class, PROP_VIDEO_DIRECTION,
|
||||
"video-direction");
|
||||
#endif
|
||||
|
||||
gst_element_class_set_static_metadata (gstelement_class,
|
||||
"Raspberry Pi Camera Source", "Source/Video",
|
||||
|
@ -651,70 +632,78 @@ gst_rpi_cam_src_colorbalance_get_balance_type (GstColorBalance * balance)
|
|||
return GST_COLOR_BALANCE_HARDWARE;
|
||||
}
|
||||
|
||||
static void gst_rpi_cam_src_set_orientation (GstRpiCamSrc * src, GstRpiCamOrientation orientation)
|
||||
#ifdef GST_RPI_CAM_SRC_ENABLE_VIDEO_DIRECTION
|
||||
static void gst_rpi_cam_src_set_orientation (GstRpiCamSrc * src, GstVideoOrientationMethod orientation)
|
||||
{
|
||||
switch (orientation) {
|
||||
case GST_RPI_CAM_ORIENTATION_IDENTITY:
|
||||
case GST_VIDEO_ORIENTATION_IDENTITY:
|
||||
src->capture_config.camera_parameters.rotation = 0;
|
||||
src->capture_config.camera_parameters.hflip = FALSE;
|
||||
src->capture_config.camera_parameters.vflip = FALSE;
|
||||
GST_DEBUG_OBJECT (src, "set orientation identity");
|
||||
break;
|
||||
case GST_RPI_CAM_ORIENTATION_90R:
|
||||
case GST_VIDEO_ORIENTATION_90R:
|
||||
src->capture_config.camera_parameters.rotation = 90;
|
||||
src->capture_config.camera_parameters.hflip = FALSE;
|
||||
src->capture_config.camera_parameters.vflip = FALSE;
|
||||
GST_DEBUG_OBJECT (src, "set orientation 90R");
|
||||
break;
|
||||
case GST_RPI_CAM_ORIENTATION_180:
|
||||
case GST_VIDEO_ORIENTATION_180:
|
||||
src->capture_config.camera_parameters.rotation = 180;
|
||||
src->capture_config.camera_parameters.hflip = FALSE;
|
||||
src->capture_config.camera_parameters.vflip = FALSE;
|
||||
GST_DEBUG_OBJECT (src, "set orientation 180");
|
||||
break;
|
||||
case GST_RPI_CAM_ORIENTATION_90L:
|
||||
case GST_VIDEO_ORIENTATION_90L:
|
||||
src->capture_config.camera_parameters.rotation = 270;
|
||||
src->capture_config.camera_parameters.hflip = FALSE;
|
||||
src->capture_config.camera_parameters.vflip = FALSE;
|
||||
GST_DEBUG_OBJECT (src, "set orientation 90L");
|
||||
break;
|
||||
case GST_RPI_CAM_ORIENTATION_FLIP_HORIZ:
|
||||
case GST_VIDEO_ORIENTATION_HORIZ:
|
||||
src->capture_config.camera_parameters.rotation = 0;
|
||||
src->capture_config.camera_parameters.hflip = TRUE;
|
||||
src->capture_config.camera_parameters.vflip = FALSE;
|
||||
GST_DEBUG_OBJECT (src, "set orientation hflip");
|
||||
break;
|
||||
case GST_RPI_CAM_ORIENTATION_FLIP_VERT:
|
||||
case GST_VIDEO_ORIENTATION_VERT:
|
||||
src->capture_config.camera_parameters.rotation = 0;
|
||||
src->capture_config.camera_parameters.hflip = FALSE;
|
||||
src->capture_config.camera_parameters.vflip = TRUE;
|
||||
GST_DEBUG_OBJECT (src, "set orientation vflip");
|
||||
break;
|
||||
case GST_RPI_CAM_ORIENTATION_FLIP_TRANS:
|
||||
case GST_VIDEO_ORIENTATION_UL_LR:
|
||||
src->capture_config.camera_parameters.rotation = 90;
|
||||
src->capture_config.camera_parameters.hflip = FALSE;
|
||||
src->capture_config.camera_parameters.vflip = TRUE;
|
||||
GST_DEBUG_OBJECT (src, "set orientation trans");
|
||||
break;
|
||||
case GST_RPI_CAM_ORIENTATION_FLIP_OTHER:
|
||||
case GST_VIDEO_ORIENTATION_UR_LL:
|
||||
src->capture_config.camera_parameters.rotation = 270;
|
||||
src->capture_config.camera_parameters.hflip = FALSE;
|
||||
src->capture_config.camera_parameters.vflip = TRUE;
|
||||
GST_DEBUG_OBJECT (src, "set orientation trans");
|
||||
break;
|
||||
case GST_RPI_CAM_ORIENTATION_CUSTOM:
|
||||
case GST_VIDEO_ORIENTATION_CUSTOM:
|
||||
break;
|
||||
default:
|
||||
GST_WARNING_OBJECT (src, "unsupported orientation %d", orientation);
|
||||
break;
|
||||
}
|
||||
src->orientation =
|
||||
orientation >= GST_RPI_CAM_ORIENTATION_IDENTITY &&
|
||||
orientation <= GST_RPI_CAM_ORIENTATION_CUSTOM ?
|
||||
orientation : GST_RPI_CAM_ORIENTATION_CUSTOM;
|
||||
orientation >= GST_VIDEO_ORIENTATION_IDENTITY &&
|
||||
orientation <= GST_VIDEO_ORIENTATION_CUSTOM ?
|
||||
orientation : GST_VIDEO_ORIENTATION_CUSTOM;
|
||||
src->capture_config.change_flags |= PROP_CHANGE_ORIENTATION;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_rpi_cam_src_direction_init (GstVideoDirectionInterface * iface)
|
||||
{
|
||||
/* We implement the video-direction property */
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
gst_rpi_cam_src_colorbalance_init (GstColorBalanceInterface * iface)
|
||||
{
|
||||
|
@ -763,7 +752,7 @@ gst_rpi_cam_src_orientation_set_hflip (GstVideoOrientation * orientation, gboole
|
|||
g_return_val_if_fail (GST_IS_RPICAMSRC (src), FALSE);
|
||||
|
||||
g_mutex_lock (&src->config_lock);
|
||||
src->orientation = GST_RPI_CAM_ORIENTATION_CUSTOM;
|
||||
gst_rpi_cam_src_reset_custom_orientation(src);
|
||||
src->capture_config.camera_parameters.hflip = flip;
|
||||
src->capture_config.change_flags |= PROP_CHANGE_ORIENTATION;
|
||||
g_mutex_unlock (&src->config_lock);
|
||||
|
@ -780,7 +769,7 @@ gst_rpi_cam_src_orientation_set_vflip (GstVideoOrientation * orientation, gboole
|
|||
g_return_val_if_fail (GST_IS_RPICAMSRC (src), FALSE);
|
||||
|
||||
g_mutex_lock (&src->config_lock);
|
||||
src->orientation = GST_RPI_CAM_ORIENTATION_CUSTOM;
|
||||
gst_rpi_cam_src_reset_custom_orientation(src);
|
||||
src->capture_config.camera_parameters.vflip = flip;
|
||||
src->capture_config.change_flags |= PROP_CHANGE_ORIENTATION;
|
||||
g_mutex_unlock (&src->config_lock);
|
||||
|
@ -896,12 +885,9 @@ gst_rpi_cam_src_set_property (GObject * object, guint prop_id,
|
|||
src->capture_config.change_flags |= PROP_CHANGE_SENSOR_SETTINGS;
|
||||
break;
|
||||
case PROP_ROTATION:
|
||||
src->orientation = GST_RPI_CAM_ORIENTATION_CUSTOM;
|
||||
gst_rpi_cam_src_reset_custom_orientation(src);
|
||||
src->capture_config.camera_parameters.rotation = g_value_get_int (value);
|
||||
break;
|
||||
case PROP_ORIENTATION:
|
||||
gst_rpi_cam_src_set_orientation (src, g_value_get_enum (value));
|
||||
break;
|
||||
case PROP_AWB_MODE:
|
||||
src->capture_config.camera_parameters.awbMode = g_value_get_enum (value);
|
||||
src->capture_config.change_flags |= PROP_CHANGE_AWB;
|
||||
|
@ -922,12 +908,12 @@ gst_rpi_cam_src_set_property (GObject * object, guint prop_id,
|
|||
src->capture_config.change_flags |= PROP_CHANGE_IMAGE_COLOUR_EFFECT;
|
||||
break;
|
||||
case PROP_HFLIP:
|
||||
src->orientation = GST_RPI_CAM_ORIENTATION_CUSTOM;
|
||||
gst_rpi_cam_src_reset_custom_orientation(src);
|
||||
src->capture_config.camera_parameters.hflip = g_value_get_boolean (value);
|
||||
src->capture_config.change_flags |= PROP_CHANGE_ORIENTATION;
|
||||
break;
|
||||
case PROP_VFLIP:
|
||||
src->orientation = GST_RPI_CAM_ORIENTATION_CUSTOM;
|
||||
gst_rpi_cam_src_reset_custom_orientation(src);
|
||||
src->capture_config.camera_parameters.vflip = g_value_get_boolean (value);
|
||||
src->capture_config.change_flags |= PROP_CHANGE_ORIENTATION;
|
||||
break;
|
||||
|
@ -1000,6 +986,11 @@ gst_rpi_cam_src_set_property (GObject * object, guint prop_id,
|
|||
src->capture_config.intra_refresh_type = g_value_get_enum (value);
|
||||
src->capture_config.change_flags |= PROP_CHANGE_ENCODING;
|
||||
break;
|
||||
#ifdef GST_RPI_CAM_SRC_ENABLE_VIDEO_DIRECTION
|
||||
case PROP_VIDEO_DIRECTION:
|
||||
gst_rpi_cam_src_set_orientation (src, g_value_get_enum (value));
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
|
@ -1085,9 +1076,6 @@ gst_rpi_cam_src_get_property (GObject * object, guint prop_id,
|
|||
case PROP_ROTATION:
|
||||
g_value_set_int (value, src->capture_config.camera_parameters.rotation);
|
||||
break;
|
||||
case PROP_ORIENTATION:
|
||||
g_value_set_enum (value, src->orientation);
|
||||
break;
|
||||
case PROP_AWB_MODE:
|
||||
g_value_set_enum (value, src->capture_config.camera_parameters.awbMode);
|
||||
break;
|
||||
|
@ -1159,6 +1147,11 @@ gst_rpi_cam_src_get_property (GObject * object, guint prop_id,
|
|||
case PROP_INTRA_REFRESH_TYPE:
|
||||
g_value_set_enum (value, src->capture_config.intra_refresh_type);
|
||||
break;
|
||||
#ifdef GST_RPI_CAM_SRC_ENABLE_VIDEO_DIRECTION
|
||||
case PROP_VIDEO_DIRECTION:
|
||||
g_value_set_enum (value, src->orientation);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
|
|
|
@ -46,36 +46,11 @@
|
|||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/base/gstpushsrc.h>
|
||||
#include <gst/pbutils/pbutils.h> /* only used for GST_PLUGINS_BASE_VERSION_* */
|
||||
#include "RaspiCapture.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* GstRpiCamOrientation:
|
||||
* @GST_RPI_CAM_ORIENTATION_IDENTITY: Identity (no rotation)
|
||||
* @GST_RPI_CAM_ORIENTATION_90R: Rotate clockwise 90 degrees
|
||||
* @GST_RPI_CAM_ORIENTATION_180: Rotate 180 degrees
|
||||
* @GST_RPI_CAM_ORIENTATION_90L: Rotate counter-clockwise 90 degrees
|
||||
* @GST_RPI_CAM_ORIENTATION_FLIP_HORIZ: Flip horizontally
|
||||
* @GST_RPI_CAM_ORIENTATION_FLIP_VERT: Flip vertically
|
||||
* @GST_RPI_CAM_ORIENTATION_FLIP_TRANS: Flip across upper left/lower right diagonal
|
||||
* @GST_RPI_CAM_ORIENTATION_FLIP_OTHER: Flip across upper right/lower left diagonal
|
||||
* @GST_RPI_CAM_ORIENTATION_CUSTOM: Orientation is set through rotation, hflip or vflip properties.
|
||||
*
|
||||
* The different orientation methods.
|
||||
*/
|
||||
typedef enum {
|
||||
GST_RPI_CAM_ORIENTATION_IDENTITY,
|
||||
GST_RPI_CAM_ORIENTATION_90R,
|
||||
GST_RPI_CAM_ORIENTATION_180,
|
||||
GST_RPI_CAM_ORIENTATION_90L,
|
||||
GST_RPI_CAM_ORIENTATION_FLIP_HORIZ,
|
||||
GST_RPI_CAM_ORIENTATION_FLIP_VERT,
|
||||
GST_RPI_CAM_ORIENTATION_FLIP_TRANS,
|
||||
GST_RPI_CAM_ORIENTATION_FLIP_OTHER,
|
||||
GST_RPI_CAM_ORIENTATION_CUSTOM
|
||||
} GstRpiCamOrientation;
|
||||
|
||||
#define GST_TYPE_RPICAMSRC (gst_rpi_cam_src_get_type())
|
||||
#define GST_RPICAMSRC(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_RPICAMSRC,GstRpiCamSrc))
|
||||
|
@ -86,6 +61,10 @@ typedef enum {
|
|||
#define GST_IS_RPICAMSRC_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_RPICAMSRC))
|
||||
|
||||
#if GST_CHECK_PLUGINS_BASE_VERSION(1, 9, 2)
|
||||
#define GST_RPI_CAM_SRC_ENABLE_VIDEO_DIRECTION
|
||||
#endif
|
||||
|
||||
typedef struct _GstRpiCamSrc GstRpiCamSrc;
|
||||
typedef struct _GstRpiCamSrcClass GstRpiCamSrcClass;
|
||||
|
||||
|
@ -104,7 +83,9 @@ struct _GstRpiCamSrc
|
|||
/* channels for interface */
|
||||
GList *channels;
|
||||
|
||||
GstRpiCamOrientation orientation;
|
||||
#ifdef GST_RPI_CAM_SRC_ENABLE_VIDEO_DIRECTION
|
||||
GstVideoOrientationMethod orientation;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct _GstRpiCamSrcClass
|
||||
|
|
Loading…
Reference in a new issue