gst_plugins_good/gst/camerabin/gstcamerabinphotography.c
branchRCL_3
changeset 30 7e817e7e631c
parent 2 5505e8908944
equal deleted inserted replaced
29:567bb019e3e3 30:7e817e7e631c
       
     1 /*
       
     2  * GStreamer
       
     3  * Copyright (C) 2008 Nokia Corporation <multimedia@maemo.org>
       
     4  *
       
     5  * Photography interface implementation for camerabin.
       
     6  *
       
     7  * This library is free software; you can redistribute it and/or
       
     8  * modify it under the terms of the GNU Library General Public
       
     9  * License as published by the Free Software Foundation; either
       
    10  * version 2 of the License, or (at your option) any later version.
       
    11  *
       
    12  * This library is distributed in the hope that it will be useful,
       
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    15  * Library General Public License for more details.
       
    16  *
       
    17  * You should have received a copy of the GNU Library General Public
       
    18  * License along with this library; if not, write to the
       
    19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
       
    20  * Boston, MA 02111-1307, USA.
       
    21  */
       
    22 
       
    23 #ifdef HAVE_CONFIG_H
       
    24 #include <config.h>
       
    25 #endif
       
    26 
       
    27 #include "gstcamerabinphotography.h"
       
    28 #include "gstcamerabin.h"
       
    29 
       
    30 GST_DEBUG_CATEGORY_STATIC (camerabinphoto_debug);
       
    31 #define GST_CAT_DEFAULT camerabinphoto_debug
       
    32 
       
    33 #define PHOTOGRAPHY_IS_OK(photo_elem) (GST_IS_ELEMENT (photo_elem) && \
       
    34                                        gst_element_implements_interface (photo_elem, GST_TYPE_PHOTOGRAPHY))
       
    35 
       
    36 #define GST_PHOTOGRAPHY_IMPL_TEMPLATE(function_name, param_type) \
       
    37 static gboolean \
       
    38 gst_camerabin_set_ ## function_name (GstPhotography *photo, param_type param) \
       
    39 { \
       
    40   GstCameraBin *camera; \
       
    41   gboolean ret = FALSE; \
       
    42   g_return_val_if_fail (photo != NULL, FALSE); \
       
    43   camera = GST_CAMERABIN (photo); \
       
    44   if (PHOTOGRAPHY_IS_OK (camera->src_vid_src)) { \
       
    45     ret = gst_photography_set_ ## function_name (GST_PHOTOGRAPHY (camera->src_vid_src), param); \
       
    46   } \
       
    47   return ret; \
       
    48 } \
       
    49 static gboolean \
       
    50 gst_camerabin_get_ ## function_name (GstPhotography *photo, param_type * param) \
       
    51 { \
       
    52   GstCameraBin *camera; \
       
    53   gboolean ret = FALSE; \
       
    54   g_return_val_if_fail (photo != NULL, FALSE); \
       
    55   camera = GST_CAMERABIN (photo); \
       
    56   if (PHOTOGRAPHY_IS_OK (camera->src_vid_src)) { \
       
    57     ret = gst_photography_get_ ## function_name (GST_PHOTOGRAPHY (camera->src_vid_src), param); \
       
    58   } \
       
    59   return ret; \
       
    60 }
       
    61 
       
    62 GST_PHOTOGRAPHY_IMPL_TEMPLATE (ev_compensation, gfloat);
       
    63 GST_PHOTOGRAPHY_IMPL_TEMPLATE (iso_speed, guint);
       
    64 GST_PHOTOGRAPHY_IMPL_TEMPLATE (white_balance_mode, GstWhiteBalanceMode);
       
    65 GST_PHOTOGRAPHY_IMPL_TEMPLATE (colour_tone_mode, GstColourToneMode);
       
    66 GST_PHOTOGRAPHY_IMPL_TEMPLATE (flash_mode, GstFlashMode);
       
    67 
       
    68 static gboolean
       
    69 gst_camerabin_set_zoom (GstPhotography * photo, gfloat zoom)
       
    70 {
       
    71   GstCameraBin *camera;
       
    72 
       
    73   g_return_val_if_fail (photo != NULL, FALSE);
       
    74 
       
    75   camera = GST_CAMERABIN (photo);
       
    76 
       
    77   /* camerabin can zoom by itself */
       
    78   g_object_set (camera, "zoom", (gint) (CLAMP (zoom, 1.0, 10.0) * 100), NULL);
       
    79 
       
    80   return TRUE;
       
    81 }
       
    82 
       
    83 static gboolean
       
    84 gst_camerabin_get_zoom (GstPhotography * photo, gfloat * zoom)
       
    85 {
       
    86   GstCameraBin *camera;
       
    87   gint cb_zoom = 0;
       
    88 
       
    89   g_return_val_if_fail (photo != NULL, FALSE);
       
    90 
       
    91   camera = GST_CAMERABIN (photo);
       
    92 
       
    93   g_object_get (camera, "zoom", &cb_zoom, NULL);
       
    94   *zoom = (gfloat) (cb_zoom / 100.0);
       
    95 
       
    96   return TRUE;
       
    97 }
       
    98 
       
    99 static gboolean
       
   100 gst_camerabin_set_scene_mode (GstPhotography * photo, GstSceneMode scene_mode)
       
   101 {
       
   102   GstCameraBin *camera;
       
   103   gboolean ret = FALSE;
       
   104 
       
   105   g_return_val_if_fail (photo != NULL, FALSE);
       
   106 
       
   107   camera = GST_CAMERABIN (photo);
       
   108 
       
   109   if (scene_mode == GST_PHOTOGRAPHY_SCENE_MODE_NIGHT) {
       
   110     GST_DEBUG ("enabling night mode, lowering fps");
       
   111     /* Make camerabin select the lowest allowed frame rate */
       
   112     camera->night_mode = TRUE;
       
   113     /* Remember frame rate before setting night mode */
       
   114     camera->pre_night_fps_n = camera->fps_n;
       
   115     camera->pre_night_fps_d = camera->fps_d;
       
   116     g_signal_emit_by_name (camera, "user-res-fps", camera->width,
       
   117         camera->height, 0, 0, 0);
       
   118   } else {
       
   119     if (camera->night_mode) {
       
   120       GST_DEBUG ("disabling night mode, restoring fps to %d/%d",
       
   121           camera->pre_night_fps_n, camera->pre_night_fps_d);
       
   122       camera->night_mode = FALSE;
       
   123       g_signal_emit_by_name (camera, "user-res-fps", camera->width,
       
   124           camera->height, camera->pre_night_fps_n, camera->pre_night_fps_d, 0);
       
   125     }
       
   126   }
       
   127 
       
   128   if (PHOTOGRAPHY_IS_OK (camera->src_vid_src)) {
       
   129     ret = gst_photography_set_scene_mode (GST_PHOTOGRAPHY (camera->src_vid_src),
       
   130         scene_mode);
       
   131   }
       
   132   return ret;
       
   133 }
       
   134 
       
   135 static gboolean
       
   136 gst_camerabin_get_scene_mode (GstPhotography * photo, GstSceneMode * scene_mode)
       
   137 {
       
   138   GstCameraBin *camera;
       
   139   gboolean ret = FALSE;
       
   140 
       
   141   g_return_val_if_fail (photo != NULL, FALSE);
       
   142 
       
   143   camera = GST_CAMERABIN (photo);
       
   144 
       
   145   if (PHOTOGRAPHY_IS_OK (camera->src_vid_src)) {
       
   146     ret = gst_photography_get_scene_mode (GST_PHOTOGRAPHY (camera->src_vid_src),
       
   147         scene_mode);
       
   148   }
       
   149   return ret;
       
   150 }
       
   151 
       
   152 static GstPhotoCaps
       
   153 gst_camerabin_get_capabilities (GstPhotography * photo)
       
   154 {
       
   155   GstCameraBin *camera;
       
   156   /* camerabin can zoom by itself */
       
   157   GstPhotoCaps pcaps = GST_PHOTOGRAPHY_CAPS_ZOOM;
       
   158 
       
   159   g_return_val_if_fail (photo != NULL, FALSE);
       
   160 
       
   161   camera = GST_CAMERABIN (photo);
       
   162 
       
   163   if (GST_IS_ELEMENT (camera->src_vid_src) &&
       
   164       gst_element_implements_interface (camera->src_vid_src,
       
   165           GST_TYPE_PHOTOGRAPHY)) {
       
   166     GstPhotography *p2 = GST_PHOTOGRAPHY (camera->src_vid_src);
       
   167     pcaps |= gst_photography_get_capabilities (p2);
       
   168   }
       
   169 
       
   170   return pcaps;
       
   171 }
       
   172 
       
   173 static void
       
   174 gst_camerabin_set_autofocus (GstPhotography * photo, gboolean on)
       
   175 {
       
   176   GstCameraBin *camera;
       
   177 
       
   178   g_return_if_fail (photo != NULL);
       
   179 
       
   180   camera = GST_CAMERABIN (photo);
       
   181 
       
   182   GST_DEBUG_OBJECT (camera, "setting autofocus %s", on ? "ON" : "OFF");
       
   183 
       
   184   if (PHOTOGRAPHY_IS_OK (camera->src_vid_src)) {
       
   185     gst_photography_set_autofocus (GST_PHOTOGRAPHY (camera->src_vid_src), on);
       
   186   }
       
   187 }
       
   188 
       
   189 
       
   190 void
       
   191 gst_camerabin_photography_init (GstPhotographyInterface * iface)
       
   192 {
       
   193   GST_DEBUG_CATEGORY_INIT (camerabinphoto_debug, "camerabinphoto", 0,
       
   194       "Camerabin photography interface debugging");
       
   195 
       
   196   GST_INFO ("initing");
       
   197 
       
   198   iface->set_ev_compensation = gst_camerabin_set_ev_compensation;
       
   199   iface->get_ev_compensation = gst_camerabin_get_ev_compensation;
       
   200 
       
   201   iface->set_iso_speed = gst_camerabin_set_iso_speed;
       
   202   iface->get_iso_speed = gst_camerabin_get_iso_speed;
       
   203 
       
   204   iface->set_white_balance_mode = gst_camerabin_set_white_balance_mode;
       
   205   iface->get_white_balance_mode = gst_camerabin_get_white_balance_mode;
       
   206 
       
   207   iface->set_colour_tone_mode = gst_camerabin_set_colour_tone_mode;
       
   208   iface->get_colour_tone_mode = gst_camerabin_get_colour_tone_mode;
       
   209 
       
   210   iface->set_scene_mode = gst_camerabin_set_scene_mode;
       
   211   iface->get_scene_mode = gst_camerabin_get_scene_mode;
       
   212 
       
   213   iface->set_flash_mode = gst_camerabin_set_flash_mode;
       
   214   iface->get_flash_mode = gst_camerabin_get_flash_mode;
       
   215 
       
   216   iface->set_zoom = gst_camerabin_set_zoom;
       
   217   iface->get_zoom = gst_camerabin_get_zoom;
       
   218 
       
   219   iface->get_capabilities = gst_camerabin_get_capabilities;
       
   220 
       
   221   iface->set_autofocus = gst_camerabin_set_autofocus;
       
   222 }