diff options
author | Lasse Laukkanen <ext-lasse.2.laukkanen@nokia.com> | 2009-04-20 17:06:14 +0300 |
---|---|---|
committer | Stefan Kost <ensonic@users.sf.net> | 2009-06-05 15:51:30 +0300 |
commit | 710faaef6874b95ab629e6ed89a505469abe93e5 (patch) | |
tree | a6b391b5eb62919784e89a3a3c1c1581729db458 /gst | |
parent | 9dc5c1ffb2b7b117636cd80acfde9fa41248eb3a (diff) | |
download | gst-plugins-bad-710faaef6874b95ab629e6ed89a505469abe93e5.tar.gz gst-plugins-bad-710faaef6874b95ab629e6ed89a505469abe93e5.tar.bz2 gst-plugins-bad-710faaef6874b95ab629e6ed89a505469abe93e5.zip |
camerabin: allow configuring photography settings when in NULL state
Cache the photography settings if set in NULL state and apply them later
Diffstat (limited to 'gst')
-rw-r--r-- | gst/camerabin/gstcamerabin.c | 18 | ||||
-rw-r--r-- | gst/camerabin/gstcamerabin.h | 3 | ||||
-rw-r--r-- | gst/camerabin/gstcamerabinphotography.c | 315 |
3 files changed, 283 insertions, 53 deletions
diff --git a/gst/camerabin/gstcamerabin.c b/gst/camerabin/gstcamerabin.c index 17ca9def..707e0789 100644 --- a/gst/camerabin/gstcamerabin.c +++ b/gst/camerabin/gstcamerabin.c @@ -74,7 +74,8 @@ * of these settings require low-level support the photography interface support * is dependent on video src element. In practice photography interface settings * cannot be used successfully until in PAUSED state when the video src has - * opened the video device. + * opened the video device. However it is possible to configure photography + * settings in NULL state and camerabin will try applying them later. * </para> * </refsect2> * <refsect2> @@ -375,9 +376,8 @@ gst_camerabin_iface_supported (GstImplementsInterface * iface, GType iface_type) return FALSE; } } else if (iface_type == GST_TYPE_PHOTOGRAPHY) { - if (camera->src_vid_src) { - return GST_IS_PHOTOGRAPHY (camera->src_vid_src); - } + /* Always support photography interface */ + return TRUE; } return FALSE; @@ -470,6 +470,14 @@ camerabin_setup_src_elements (GstCameraBin * camera) 0)); } + /* Update photography interface settings */ + if (GST_IS_ELEMENT (camera->src_vid_src) && + gst_element_implements_interface (camera->src_vid_src, + GST_TYPE_PHOTOGRAPHY)) { + gst_photography_set_config (GST_PHOTOGRAPHY (camera->src_vid_src), + &camera->photo_settings); + } + if (camera->width > 0 && camera->height > 0) { gst_structure_set (st, "width", G_TYPE_INT, camera->width, @@ -2495,6 +2503,8 @@ gst_camerabin_init (GstCameraBin * camera, GstCameraBinClass * gclass) camera->view_in_sel = NULL; camera->view_scale = NULL; camera->view_sink = NULL; + + memset (&camera->photo_settings, 0, sizeof (GstPhotoSettings)); } static void diff --git a/gst/camerabin/gstcamerabin.h b/gst/camerabin/gstcamerabin.h index 1bb3f489..16b242c0 100644 --- a/gst/camerabin/gstcamerabin.h +++ b/gst/camerabin/gstcamerabin.h @@ -123,6 +123,9 @@ struct _GstCameraBin gboolean night_mode; gint pre_night_fps_n; gint pre_night_fps_d; + + /* Cache the photography interface settings */ + GstPhotoSettings photo_settings; }; /** diff --git a/gst/camerabin/gstcamerabinphotography.c b/gst/camerabin/gstcamerabinphotography.c index 8a95bcd7..de95a196 100644 --- a/gst/camerabin/gstcamerabinphotography.c +++ b/gst/camerabin/gstcamerabinphotography.c @@ -24,6 +24,7 @@ #include <config.h> #endif +#include <string.h> #include "gstcamerabinphotography.h" #include "gstcamerabin.h" @@ -32,38 +33,206 @@ GST_DEBUG_CATEGORY_STATIC (camerabinphoto_debug); #define PHOTOGRAPHY_IS_OK(photo_elem) (GST_IS_ELEMENT (photo_elem) && \ gst_element_implements_interface (photo_elem, GST_TYPE_PHOTOGRAPHY)) +static void +gst_camerabin_handle_scene_mode (GstCameraBin * camera, + GstSceneMode scene_mode); + +static gboolean +gst_camerabin_set_ev_compensation (GstPhotography * photo, + gfloat ev_compensation) +{ + GstCameraBin *camera; + gboolean ret = FALSE; + + g_return_val_if_fail (photo != NULL, FALSE); + + camera = GST_CAMERABIN (photo); + + /* Cache the setting */ + camera->photo_settings.ev_compensation = ev_compensation; + + if (PHOTOGRAPHY_IS_OK (camera->src_vid_src)) { + ret = + gst_photography_set_ev_compensation (GST_PHOTOGRAPHY + (camera->src_vid_src), ev_compensation); + } + return ret; +} + +static gboolean +gst_camerabin_get_ev_compensation (GstPhotography * photo, + gfloat * ev_compensation) +{ + GstCameraBin *camera; + gboolean ret = FALSE; + + g_return_val_if_fail (photo != NULL, FALSE); + + camera = GST_CAMERABIN (photo); + + if (PHOTOGRAPHY_IS_OK (camera->src_vid_src)) { + ret = + gst_photography_get_ev_compensation (GST_PHOTOGRAPHY + (camera->src_vid_src), ev_compensation); + } + return ret; +} + +static gboolean +gst_camerabin_set_iso_speed (GstPhotography * photo, guint iso_speed) +{ + GstCameraBin *camera; + gboolean ret = FALSE; + + g_return_val_if_fail (photo != NULL, FALSE); + + camera = GST_CAMERABIN (photo); + + /* Cache the setting */ + camera->photo_settings.iso_speed = iso_speed; + + if (PHOTOGRAPHY_IS_OK (camera->src_vid_src)) { + ret = gst_photography_set_iso_speed (GST_PHOTOGRAPHY (camera->src_vid_src), + iso_speed); + } + return ret; +} + +static gboolean +gst_camerabin_get_iso_speed (GstPhotography * photo, guint * iso_speed) +{ + GstCameraBin *camera; + gboolean ret = FALSE; + + g_return_val_if_fail (photo != NULL, FALSE); + + camera = GST_CAMERABIN (photo); -#define GST_PHOTOGRAPHY_IMPL_TEMPLATE(function_name, param_type) \ -static gboolean \ -gst_camerabin_set_ ## function_name (GstPhotography *photo, param_type param) \ -{ \ - GstCameraBin *camera; \ - gboolean ret = FALSE; \ - g_return_val_if_fail (photo != NULL, FALSE); \ - camera = GST_CAMERABIN (photo); \ - if (PHOTOGRAPHY_IS_OK (camera->src_vid_src)) { \ - ret = gst_photography_set_ ## function_name (GST_PHOTOGRAPHY (camera->src_vid_src), param); \ - } \ - return ret; \ -} \ -static gboolean \ -gst_camerabin_get_ ## function_name (GstPhotography *photo, param_type * param) \ -{ \ - GstCameraBin *camera; \ - gboolean ret = FALSE; \ - g_return_val_if_fail (photo != NULL, FALSE); \ - camera = GST_CAMERABIN (photo); \ - if (PHOTOGRAPHY_IS_OK (camera->src_vid_src)) { \ - ret = gst_photography_get_ ## function_name (GST_PHOTOGRAPHY (camera->src_vid_src), param); \ - } \ - return ret; \ -} - -GST_PHOTOGRAPHY_IMPL_TEMPLATE (ev_compensation, gfloat); -GST_PHOTOGRAPHY_IMPL_TEMPLATE (iso_speed, guint); -GST_PHOTOGRAPHY_IMPL_TEMPLATE (white_balance_mode, GstWhiteBalanceMode); -GST_PHOTOGRAPHY_IMPL_TEMPLATE (colour_tone_mode, GstColourToneMode); -GST_PHOTOGRAPHY_IMPL_TEMPLATE (flash_mode, GstFlashMode); + if (PHOTOGRAPHY_IS_OK (camera->src_vid_src)) { + ret = gst_photography_get_iso_speed (GST_PHOTOGRAPHY (camera->src_vid_src), + iso_speed); + } + return ret; +} + +static gboolean +gst_camerabin_set_white_balance_mode (GstPhotography * photo, + GstWhiteBalanceMode white_balance_mode) +{ + GstCameraBin *camera; + gboolean ret = FALSE; + + g_return_val_if_fail (photo != NULL, FALSE); + + camera = GST_CAMERABIN (photo); + + /* Cache the setting */ + camera->photo_settings.wb_mode = white_balance_mode; + + if (PHOTOGRAPHY_IS_OK (camera->src_vid_src)) { + ret = + gst_photography_set_white_balance_mode (GST_PHOTOGRAPHY + (camera->src_vid_src), white_balance_mode); + } + return ret; +} + +static gboolean +gst_camerabin_get_white_balance_mode (GstPhotography * photo, + GstWhiteBalanceMode * white_balance_mode) +{ + GstCameraBin *camera; + gboolean ret = FALSE; + + g_return_val_if_fail (photo != NULL, FALSE); + + camera = GST_CAMERABIN (photo); + + if (PHOTOGRAPHY_IS_OK (camera->src_vid_src)) { + ret = + gst_photography_get_white_balance_mode (GST_PHOTOGRAPHY + (camera->src_vid_src), white_balance_mode); + } + return ret; +} + +static gboolean +gst_camerabin_set_colour_tone_mode (GstPhotography * photo, + GstColourToneMode colour_tone_mode) +{ + GstCameraBin *camera; + gboolean ret = FALSE; + + g_return_val_if_fail (photo != NULL, FALSE); + + camera = GST_CAMERABIN (photo); + + /* Cache the setting */ + camera->photo_settings.tone_mode = colour_tone_mode; + + if (PHOTOGRAPHY_IS_OK (camera->src_vid_src)) { + ret = + gst_photography_set_colour_tone_mode (GST_PHOTOGRAPHY + (camera->src_vid_src), colour_tone_mode); + } + return ret; +} + +static gboolean +gst_camerabin_get_colour_tone_mode (GstPhotography * photo, + GstColourToneMode * colour_tone_mode) +{ + GstCameraBin *camera; + gboolean ret = FALSE; + + g_return_val_if_fail (photo != NULL, FALSE); + + camera = GST_CAMERABIN (photo); + + if (PHOTOGRAPHY_IS_OK (camera->src_vid_src)) { + ret = + gst_photography_get_colour_tone_mode (GST_PHOTOGRAPHY + (camera->src_vid_src), colour_tone_mode); + } + return ret; +} + +static gboolean +gst_camerabin_set_flash_mode (GstPhotography * photo, GstFlashMode flash_mode) +{ + GstCameraBin *camera; + gboolean ret = FALSE; + + g_return_val_if_fail (photo != NULL, FALSE); + + camera = GST_CAMERABIN (photo); + + /* Cache the setting */ + camera->photo_settings.flash_mode = flash_mode; + + if (PHOTOGRAPHY_IS_OK (camera->src_vid_src)) { + ret = gst_photography_set_flash_mode (GST_PHOTOGRAPHY (camera->src_vid_src), + flash_mode); + } + return ret; +} + +static gboolean +gst_camerabin_get_flash_mode (GstPhotography * photo, GstFlashMode * flash_mode) +{ + GstCameraBin *camera; + gboolean ret = FALSE; + + g_return_val_if_fail (photo != NULL, FALSE); + + camera = GST_CAMERABIN (photo); + + if (PHOTOGRAPHY_IS_OK (camera->src_vid_src)) { + ret = gst_photography_get_flash_mode (GST_PHOTOGRAPHY (camera->src_vid_src), + flash_mode); + } + return ret; +} static gboolean gst_camerabin_set_zoom (GstPhotography * photo, gfloat zoom) @@ -106,24 +275,10 @@ gst_camerabin_set_scene_mode (GstPhotography * photo, GstSceneMode scene_mode) camera = GST_CAMERABIN (photo); - if (scene_mode == GST_PHOTOGRAPHY_SCENE_MODE_NIGHT) { - GST_DEBUG ("enabling night mode, lowering fps"); - /* Make camerabin select the lowest allowed frame rate */ - camera->night_mode = TRUE; - /* Remember frame rate before setting night mode */ - camera->pre_night_fps_n = camera->fps_n; - camera->pre_night_fps_d = camera->fps_d; - g_signal_emit_by_name (camera, "user-res-fps", camera->width, - camera->height, 0, 0, 0); - } else { - if (camera->night_mode) { - GST_DEBUG ("disabling night mode, restoring fps to %d/%d", - camera->pre_night_fps_n, camera->pre_night_fps_d); - camera->night_mode = FALSE; - g_signal_emit_by_name (camera, "user-res-fps", camera->width, - camera->height, camera->pre_night_fps_n, camera->pre_night_fps_d, 0); - } - } + /* Cache the setting */ + camera->photo_settings.scene_mode = scene_mode; + + gst_camerabin_handle_scene_mode (camera, scene_mode); if (PHOTOGRAPHY_IS_OK (camera->src_vid_src)) { ret = gst_photography_set_scene_mode (GST_PHOTOGRAPHY (camera->src_vid_src), @@ -186,6 +341,65 @@ gst_camerabin_set_autofocus (GstPhotography * photo, gboolean on) } } +static gboolean +gst_camerabin_set_config (GstPhotography * photo, GstPhotoSettings * config) +{ + GstCameraBin *camera; + gboolean ret = FALSE; + g_return_val_if_fail (photo != NULL, FALSE); + camera = GST_CAMERABIN (photo); + + /* Cache the settings */ + memcpy (&camera->photo_settings, config, sizeof (GstPhotoSettings)); + + /* Handle night mode */ + gst_camerabin_handle_scene_mode (camera, config->scene_mode); + + if (PHOTOGRAPHY_IS_OK (camera->src_vid_src)) { + ret = + gst_photography_set_config (GST_PHOTOGRAPHY (camera->src_vid_src), + config); + } + return ret; +} + +static gboolean +gst_camerabin_get_config (GstPhotography * photo, GstPhotoSettings * config) +{ + GstCameraBin *camera; + gboolean ret = FALSE; + g_return_val_if_fail (photo != NULL, FALSE); + camera = GST_CAMERABIN (photo); + if (PHOTOGRAPHY_IS_OK (camera->src_vid_src)) { + ret = + gst_photography_get_config (GST_PHOTOGRAPHY (camera->src_vid_src), + config); + } + return ret; +} + +static void +gst_camerabin_handle_scene_mode (GstCameraBin * camera, GstSceneMode scene_mode) +{ + if (scene_mode == GST_PHOTOGRAPHY_SCENE_MODE_NIGHT) { + GST_DEBUG ("enabling night mode, lowering fps"); + /* Make camerabin select the lowest allowed frame rate */ + camera->night_mode = TRUE; + /* Remember frame rate before setting night mode */ + camera->pre_night_fps_n = camera->fps_n; + camera->pre_night_fps_d = camera->fps_d; + g_signal_emit_by_name (camera, "user-res-fps", camera->width, + camera->height, 0, 0, 0); + } else { + if (camera->night_mode) { + GST_DEBUG ("disabling night mode, restoring fps to %d/%d", + camera->pre_night_fps_n, camera->pre_night_fps_d); + camera->night_mode = FALSE; + g_signal_emit_by_name (camera, "user-res-fps", camera->width, + camera->height, camera->pre_night_fps_n, camera->pre_night_fps_d, 0); + } + } +} void gst_camerabin_photography_init (GstPhotographyInterface * iface) @@ -219,4 +433,7 @@ gst_camerabin_photography_init (GstPhotographyInterface * iface) iface->get_capabilities = gst_camerabin_get_capabilities; iface->set_autofocus = gst_camerabin_set_autofocus; + + iface->set_config = gst_camerabin_set_config; + iface->get_config = gst_camerabin_get_config; } |