mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-18 14:26:43 +00:00
camerabin: Change zoom property from int to float
Updates zoom property for a more natural type and makes it consistent with the photography API
This commit is contained in:
parent
c3527e2653
commit
19981f2787
4 changed files with 37 additions and 25 deletions
|
@ -186,7 +186,7 @@ static guint camerabin_signals[LAST_SIGNAL];
|
||||||
/* default and range values for args */
|
/* default and range values for args */
|
||||||
|
|
||||||
#define DEFAULT_MODE MODE_IMAGE
|
#define DEFAULT_MODE MODE_IMAGE
|
||||||
#define DEFAULT_ZOOM 100
|
#define DEFAULT_ZOOM 1.0
|
||||||
#define DEFAULT_WIDTH 640
|
#define DEFAULT_WIDTH 640
|
||||||
#define DEFAULT_HEIGHT 480
|
#define DEFAULT_HEIGHT 480
|
||||||
#define DEFAULT_CAPTURE_WIDTH 800
|
#define DEFAULT_CAPTURE_WIDTH 800
|
||||||
|
@ -205,8 +205,8 @@ static guint camerabin_signals[LAST_SIGNAL];
|
||||||
/* Using "bilinear" as default zoom method */
|
/* Using "bilinear" as default zoom method */
|
||||||
#define CAMERABIN_DEFAULT_ZOOM_METHOD 1
|
#define CAMERABIN_DEFAULT_ZOOM_METHOD 1
|
||||||
|
|
||||||
#define MIN_ZOOM 100
|
#define MIN_ZOOM 1.0
|
||||||
#define MAX_ZOOM 1000
|
#define MAX_ZOOM 10.0
|
||||||
#define ZOOM_1X MIN_ZOOM
|
#define ZOOM_1X MIN_ZOOM
|
||||||
|
|
||||||
/* FIXME: this is v4l2camsrc specific */
|
/* FIXME: this is v4l2camsrc specific */
|
||||||
|
@ -1019,14 +1019,26 @@ gst_camerabin_change_filename (GstCameraBin * camera, const gchar * name)
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_camerabin_set_videosrc_zoom (GstCameraBin * camera, gint zoom)
|
gst_camerabin_set_videosrc_zoom (GstCameraBin * camera, gfloat zoom)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
|
GParamSpec *spec;
|
||||||
|
|
||||||
if (g_object_class_find_property (G_OBJECT_GET_CLASS (camera->src_vid_src),
|
spec = g_object_class_find_property (G_OBJECT_GET_CLASS (camera->src_vid_src),
|
||||||
"zoom")) {
|
"zoom");
|
||||||
g_object_set (G_OBJECT (camera->src_vid_src), "zoom",
|
if (spec) {
|
||||||
(gfloat) zoom / 100, NULL);
|
GValue value = { 0 };
|
||||||
|
|
||||||
|
g_value_init (&value, G_TYPE_FLOAT);
|
||||||
|
g_value_set_float (&value, zoom);
|
||||||
|
|
||||||
|
/* puts zoom into the valid range of the src element */
|
||||||
|
if (g_param_value_validate (spec, &value)) {
|
||||||
|
GST_DEBUG_OBJECT (camera, "Modified zoom from %f to %f", zoom,
|
||||||
|
g_value_get_float (&value));
|
||||||
|
zoom = g_value_get_float (&value);
|
||||||
|
}
|
||||||
|
g_object_set (G_OBJECT (camera->src_vid_src), "zoom", zoom, NULL);
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1034,7 +1046,7 @@ gst_camerabin_set_videosrc_zoom (GstCameraBin * camera, gint zoom)
|
||||||
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_camerabin_set_element_zoom (GstCameraBin * camera, gint zoom)
|
gst_camerabin_set_element_zoom (GstCameraBin * camera, gfloat zoom)
|
||||||
{
|
{
|
||||||
gint w2_crop = 0, h2_crop = 0;
|
gint w2_crop = 0, h2_crop = 0;
|
||||||
GstPad *pad_zoom_sink = NULL;
|
GstPad *pad_zoom_sink = NULL;
|
||||||
|
@ -1046,7 +1058,7 @@ gst_camerabin_set_element_zoom (GstCameraBin * camera, gint zoom)
|
||||||
|
|
||||||
if (camera->src_zoom_crop) {
|
if (camera->src_zoom_crop) {
|
||||||
/* Update capsfilters to apply the zoom */
|
/* Update capsfilters to apply the zoom */
|
||||||
GST_INFO_OBJECT (camera, "zoom: %d, orig size: %dx%d", zoom,
|
GST_INFO_OBJECT (camera, "zoom: %f, orig size: %dx%d", zoom,
|
||||||
camera->width, camera->height);
|
camera->width, camera->height);
|
||||||
|
|
||||||
if (zoom != ZOOM_1X) {
|
if (zoom != ZOOM_1X) {
|
||||||
|
@ -1088,15 +1100,15 @@ gst_camerabin_set_element_zoom (GstCameraBin * camera, gint zoom)
|
||||||
static void
|
static void
|
||||||
gst_camerabin_setup_zoom (GstCameraBin * camera)
|
gst_camerabin_setup_zoom (GstCameraBin * camera)
|
||||||
{
|
{
|
||||||
gint zoom;
|
gfloat zoom;
|
||||||
|
|
||||||
g_return_if_fail (camera != NULL);
|
g_return_if_fail (camera != NULL);
|
||||||
|
|
||||||
zoom = g_atomic_int_get (&camera->zoom);
|
zoom = camera->zoom;
|
||||||
|
|
||||||
g_return_if_fail (zoom);
|
g_return_if_fail (zoom);
|
||||||
|
|
||||||
GST_INFO_OBJECT (camera, "setting zoom %d", zoom);
|
GST_INFO_OBJECT (camera, "setting zoom %f", zoom);
|
||||||
|
|
||||||
if (gst_camerabin_set_videosrc_zoom (camera, zoom)) {
|
if (gst_camerabin_set_videosrc_zoom (camera, zoom)) {
|
||||||
gst_camerabin_set_element_zoom (camera, ZOOM_1X);
|
gst_camerabin_set_element_zoom (camera, ZOOM_1X);
|
||||||
|
@ -1294,7 +1306,7 @@ gst_camerabin_get_internal_tags (GstCameraBin * camera)
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
|
gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
|
||||||
GST_TAG_CAPTURING_DIGITAL_ZOOM_RATIO, camera->zoom / 100.0, NULL);
|
GST_TAG_CAPTURING_DIGITAL_ZOOM_RATIO, (gdouble) camera->zoom, NULL);
|
||||||
|
|
||||||
if (gst_element_implements_interface (GST_ELEMENT (camera),
|
if (gst_element_implements_interface (GST_ELEMENT (camera),
|
||||||
GST_TYPE_COLOR_BALANCE)) {
|
GST_TYPE_COLOR_BALANCE)) {
|
||||||
|
@ -2633,8 +2645,8 @@ gst_camerabin_class_init (GstCameraBinClass * klass)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class, ARG_ZOOM,
|
g_object_class_install_property (gobject_class, ARG_ZOOM,
|
||||||
g_param_spec_int ("zoom", "Zoom",
|
g_param_spec_float ("zoom", "Zoom",
|
||||||
"The zoom. 100 for 1x, 200 for 2x and so on",
|
"The zoom. 1.0 for 1x, 2.0 for 2x and so on",
|
||||||
MIN_ZOOM, MAX_ZOOM, DEFAULT_ZOOM,
|
MIN_ZOOM, MAX_ZOOM, DEFAULT_ZOOM,
|
||||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
|
@ -3172,7 +3184,7 @@ gst_camerabin_set_property (GObject * object, guint prop_id,
|
||||||
g_value_get_boolean (value));
|
g_value_get_boolean (value));
|
||||||
break;
|
break;
|
||||||
case ARG_ZOOM:
|
case ARG_ZOOM:
|
||||||
g_atomic_int_set (&camera->zoom, g_value_get_int (value));
|
camera->zoom = g_value_get_float (value);
|
||||||
/* does not set it if in NULL, the src is not created yet */
|
/* does not set it if in NULL, the src is not created yet */
|
||||||
if (GST_STATE (camera) != GST_STATE_NULL)
|
if (GST_STATE (camera) != GST_STATE_NULL)
|
||||||
gst_camerabin_setup_zoom (camera);
|
gst_camerabin_setup_zoom (camera);
|
||||||
|
@ -3419,7 +3431,7 @@ gst_camerabin_get_property (GObject * object, guint prop_id,
|
||||||
gst_camerabin_video_get_mute (GST_CAMERABIN_VIDEO (camera->vidbin)));
|
gst_camerabin_video_get_mute (GST_CAMERABIN_VIDEO (camera->vidbin)));
|
||||||
break;
|
break;
|
||||||
case ARG_ZOOM:
|
case ARG_ZOOM:
|
||||||
g_value_set_int (value, g_atomic_int_get (&camera->zoom));
|
g_value_set_float (value, camera->zoom);
|
||||||
break;
|
break;
|
||||||
case ARG_IMAGE_POST:
|
case ARG_IMAGE_POST:
|
||||||
g_value_set_object (value,
|
g_value_set_object (value,
|
||||||
|
|
|
@ -97,8 +97,8 @@ struct _GstCameraBin
|
||||||
/* Caps used to create video preview image */
|
/* Caps used to create video preview image */
|
||||||
GstCaps *video_preview_caps;
|
GstCaps *video_preview_caps;
|
||||||
|
|
||||||
/* The digital zoom (from 100% to 1000%) */
|
/* The digital zoom (from 1.0 to 10.0) */
|
||||||
gint zoom;
|
gfloat zoom;
|
||||||
|
|
||||||
/* concurrency control */
|
/* concurrency control */
|
||||||
GMutex *capture_mutex;
|
GMutex *capture_mutex;
|
||||||
|
|
|
@ -346,7 +346,7 @@ static void
|
||||||
test_camerabin_properties (GstElement * cam)
|
test_camerabin_properties (GstElement * cam)
|
||||||
{
|
{
|
||||||
guint flags;
|
guint flags;
|
||||||
gint zoom;
|
gfloat zoom;
|
||||||
gboolean mute;
|
gboolean mute;
|
||||||
|
|
||||||
flags = 0x1f;
|
flags = 0x1f;
|
||||||
|
@ -354,11 +354,11 @@ test_camerabin_properties (GstElement * cam)
|
||||||
g_object_get (G_OBJECT (cam), "flags", &flags, NULL);
|
g_object_get (G_OBJECT (cam), "flags", &flags, NULL);
|
||||||
fail_if (flags != 0x1f, "setting camerabin flags failed");
|
fail_if (flags != 0x1f, "setting camerabin flags failed");
|
||||||
|
|
||||||
zoom = 200;
|
zoom = 2.0;
|
||||||
g_object_set (G_OBJECT (cam), "zoom", zoom, NULL);
|
g_object_set (G_OBJECT (cam), "zoom", zoom, NULL);
|
||||||
g_object_get (G_OBJECT (cam), "zoom", &zoom, NULL);
|
g_object_get (G_OBJECT (cam), "zoom", &zoom, NULL);
|
||||||
fail_if (zoom != 200, "setting camerabin zoom failed");
|
fail_if (zoom != 2.0, "setting camerabin zoom failed");
|
||||||
g_object_set (G_OBJECT (cam), "zoom", 100, NULL);
|
g_object_set (G_OBJECT (cam), "zoom", 1.0f, NULL);
|
||||||
|
|
||||||
mute = TRUE;
|
mute = TRUE;
|
||||||
g_object_set (G_OBJECT (cam), "mute", mute, NULL);
|
g_object_set (G_OBJECT (cam), "mute", mute, NULL);
|
||||||
|
|
|
@ -580,7 +580,7 @@ run_pipeline (gpointer user_data)
|
||||||
g_object_unref (video_source);
|
g_object_unref (video_source);
|
||||||
}
|
}
|
||||||
g_object_set (camera_bin, "mute", mute, NULL);
|
g_object_set (camera_bin, "mute", mute, NULL);
|
||||||
g_object_set (camera_bin, "zoom", zoom, NULL);
|
g_object_set (camera_bin, "zoom", zoom / 100.0f, NULL);
|
||||||
|
|
||||||
capture_count++;
|
capture_count++;
|
||||||
g_signal_emit_by_name (camera_bin, "capture-start", 0);
|
g_signal_emit_by_name (camera_bin, "capture-start", 0);
|
||||||
|
|
Loading…
Reference in a new issue