camerabin: allow configuring photography settings when in NULL state

Cache the photography settings if set in NULL state and apply them later
This commit is contained in:
Lasse Laukkanen 2009-04-20 17:06:14 +03:00 committed by Stefan Kost
parent 9dc5c1ffb2
commit 710faaef68
3 changed files with 281 additions and 51 deletions

View file

@ -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

View file

@ -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;
};
/**

View file

@ -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);
#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; \
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;
}
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);
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);
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;
}