Home | History | Annotate | Download | only in gstreamer
      1 /*
      2  * gstxcamsrc.cpp - gst xcamsrc plugin
      3  *
      4  *  Copyright (c) 2015 Intel Corporation
      5  *
      6  * Licensed under the Apache License, Version 2.0 (the "License");
      7  * you may not use this file except in compliance with the License.
      8  * You may obtain a copy of the License at
      9  *
     10  *      http://www.apache.org/licenses/LICENSE-2.0
     11  *
     12  * Unless required by applicable law or agreed to in writing, software
     13  * distributed under the License is distributed on an "AS IS" BASIS,
     14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15  * See the License for the specific language governing permissions and
     16  * limitations under the License.
     17  *
     18  * Author: John Ye <john.ye (at) intel.com>
     19  * Author: Wind Yuan <feng.yuan (at) intel.com>
     20  * Author: Jia Meng <jia.meng (at) intel.com>
     21  */
     22 
     23 /**
     24  * SECTION:element-xcamsrc
     25  *
     26  * FIXME:Describe xcamsrc here.
     27  *
     28  * <refsect2>
     29  * <title>Example launch line</title>
     30  * |[
     31  * gst-launch-1.0 xcamsrc io-mode=4 sensor-id=0 imageprocessor=0 analyzer=1 \
     32  *  ! video/x-raw, format=NV12, width=1920, height=1080, framerate=25/1     \
     33  *  ! vaapiencode_h264 ! fakesink
     34  * ]|
     35  * </refsect2>
     36  */
     37 
     38 #include "gstxcamsrc.h"
     39 #include "gstxcambufferpool.h"
     40 #if HAVE_IA_AIQ
     41 #include "gstxcaminterface.h"
     42 #include "dynamic_analyzer_loader.h"
     43 #include "isp/hybrid_analyzer_loader.h"
     44 #include "x3a_analyze_tuner.h"
     45 #include "isp/isp_poll_thread.h"
     46 #endif
     47 #if HAVE_LIBCL
     48 #include "smart_analyzer_loader.h"
     49 #include "smart_analysis_handler.h"
     50 #endif
     51 #include "fake_poll_thread.h"
     52 #include "fake_v4l2_device.h"
     53 
     54 #include <signal.h>
     55 #include <uvc_device.h>
     56 
     57 using namespace XCam;
     58 using namespace GstXCam;
     59 
     60 #define CAPTURE_DEVICE_STILL    "/dev/video0"
     61 #define CAPTURE_DEVICE_VIDEO    "/dev/video3"
     62 #define DEFAULT_EVENT_DEVICE    "/dev/v4l-subdev6"
     63 #if HAVE_IA_AIQ
     64 #define DEFAULT_CPF_FILE_NAME   "/etc/atomisp/imx185.cpf"
     65 #define DEFAULT_DYNAMIC_3A_LIB  "/usr/lib/xcam/plugins/3a/libxcam_3a_aiq.so"
     66 #endif
     67 
     68 #define V4L2_CAPTURE_MODE_STILL 0x2000
     69 #define V4L2_CAPTURE_MODE_VIDEO 0x4000
     70 #define V4L2_CAPTURE_MODE_PREVIEW 0x8000
     71 
     72 #define DEFAULT_PROP_SENSOR             0
     73 #define DEFAULT_PROP_MEM_MODE           V4L2_MEMORY_DMABUF
     74 #if HAVE_IA_AIQ
     75 #define DEFAULT_PROP_ENABLE_3A          TRUE
     76 #endif
     77 #define DEFAULT_PROP_ENABLE_USB         FALSE
     78 #define DEFAULT_PROP_BUFFERCOUNT        8
     79 #define DEFAULT_PROP_PIXELFORMAT        V4L2_PIX_FMT_NV12 //420 instead of 0
     80 #define DEFAULT_PROP_FIELD              V4L2_FIELD_NONE // 0
     81 #define DEFAULT_PROP_ANALYZER           SIMPLE_ANALYZER
     82 #if HAVE_IA_AIQ
     83 #define DEFAULT_PROP_IMAGE_PROCESSOR    ISP_IMAGE_PROCESSOR
     84 #elif HAVE_LIBCL
     85 #define DEFAULT_PROP_IMAGE_PROCESSOR    CL_IMAGE_PROCESSOR
     86 #endif
     87 #if HAVE_LIBCL
     88 #define DEFAULT_PROP_WDR_MODE           NONE_WDR
     89 #define DEFAULT_PROP_DEFOG_MODE         DEFOG_NONE
     90 #define DEFAULT_PROP_3D_DENOISE_MODE    DENOISE_3D_NONE
     91 #define DEFAULT_PROP_WAVELET_MODE       CL_WAVELET_DISABLED
     92 #define DEFAULT_PROP_ENABLE_WIREFRAME   FALSE
     93 #define DEFAULT_PROP_ENABLE_IMAGE_WARP  FALSE
     94 #define DEFAULT_PROP_CL_PIPE_PROFILE    0
     95 #define DEFAULT_SMART_ANALYSIS_LIB_DIR "/usr/lib/xcam/plugins/smart"
     96 #endif
     97 
     98 #define DEFAULT_VIDEO_WIDTH             1920
     99 #define DEFAULT_VIDEO_HEIGHT            1080
    100 
    101 #define GST_XCAM_INTERFACE_HEADER(from, src, device_manager, analyzer)     \
    102     GstXCamSrc  *src = GST_XCAM_SRC (from);                              \
    103     XCAM_ASSERT (src);                                                     \
    104     SmartPtr<MainDeviceManager> device_manager = src->device_manager;      \
    105     XCAM_ASSERT (src->device_manager.ptr ());                              \
    106     SmartPtr<X3aAnalyzer> analyzer = device_manager->get_analyzer ();      \
    107     XCAM_ASSERT (analyzer.ptr ())
    108 
    109 
    110 XCAM_BEGIN_DECLARE
    111 
    112 static GstStaticPadTemplate gst_xcam_src_factory =
    113     GST_STATIC_PAD_TEMPLATE ("src",
    114                              GST_PAD_SRC,
    115                              GST_PAD_ALWAYS,
    116                              GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS_ALL)));
    117 
    118 
    119 GST_DEBUG_CATEGORY (gst_xcam_src_debug);
    120 #define GST_CAT_DEFAULT gst_xcam_src_debug
    121 
    122 #define GST_TYPE_XCAM_SRC_MEM_MODE (gst_xcam_src_mem_mode_get_type ())
    123 static GType
    124 gst_xcam_src_mem_mode_get_type (void)
    125 {
    126     static GType g_type = 0;
    127 
    128     if (!g_type) {
    129         static const GEnumValue mem_types [] = {
    130             {V4L2_MEMORY_MMAP, "memory map mode", "mmap"},
    131             {V4L2_MEMORY_USERPTR, "user pointer mode", "userptr"},
    132             {V4L2_MEMORY_OVERLAY, "overlay mode", "overlay"},
    133             {V4L2_MEMORY_DMABUF, "dmabuf mode", "dmabuf"},
    134             {0, NULL, NULL}
    135         };
    136         g_type = g_enum_register_static ("GstXCamMemoryModeType", mem_types);
    137     }
    138     return g_type;
    139 }
    140 
    141 #define GST_TYPE_XCAM_SRC_FIELD (gst_xcam_src_field_get_type ())
    142 static GType
    143 gst_xcam_src_field_get_type (void)
    144 {
    145     static GType g_type = 0;
    146 
    147     if (!g_type) {
    148         static const GEnumValue field_types [] = {
    149             {V4L2_FIELD_NONE, "no field", "none"},
    150             {V4L2_FIELD_TOP, "top field", "top"},
    151             {V4L2_FIELD_BOTTOM, "bottom field", "bottom"},
    152             {V4L2_FIELD_INTERLACED, "interlaced fields", "interlaced"},
    153             {V4L2_FIELD_SEQ_TB, "both fields sequential, top first", "seq-tb"},
    154             {V4L2_FIELD_SEQ_BT, "both fields sequential, bottom first", "seq-bt"},
    155             {V4L2_FIELD_ALTERNATE, "both fields alternating", "alternate"},
    156             {V4L2_FIELD_INTERLACED_TB, "interlaced fields, top first", "interlaced-tb"},
    157             {V4L2_FIELD_INTERLACED_BT, "interlaced fields, bottom first", "interlaced-bt"},
    158             {0, NULL, NULL}
    159         };
    160         g_type = g_enum_register_static ("GstXCamSrcFieldType", field_types);
    161     }
    162     return g_type;
    163 }
    164 
    165 
    166 #define GST_TYPE_XCAM_SRC_IMAGE_PROCESSOR (gst_xcam_src_image_processor_get_type ())
    167 static GType
    168 gst_xcam_src_image_processor_get_type (void)
    169 {
    170     static GType g_type = 0;
    171     static const GEnumValue image_processor_types[] = {
    172 #if HAVE_IA_AIQ
    173         {ISP_IMAGE_PROCESSOR, "ISP image processor", "isp"},
    174 #endif
    175 #if HAVE_LIBCL
    176         {CL_IMAGE_PROCESSOR, "CL image processor", "cl"},
    177 #endif
    178         {0, NULL, NULL},
    179     };
    180 
    181     if (g_once_init_enter (&g_type)) {
    182         const GType type =
    183             g_enum_register_static ("GstXCamSrcImageProcessorType", image_processor_types);
    184         g_once_init_leave (&g_type, type);
    185     }
    186 
    187     return g_type;
    188 }
    189 
    190 #define GST_TYPE_XCAM_SRC_ANALYZER (gst_xcam_src_analyzer_get_type ())
    191 static GType
    192 gst_xcam_src_analyzer_get_type (void)
    193 {
    194     static GType g_type = 0;
    195     static const GEnumValue analyzer_types[] = {
    196         {SIMPLE_ANALYZER, "simple 3A analyzer", "simple"},
    197 #if HAVE_IA_AIQ
    198         {AIQ_TUNER_ANALYZER, "aiq 3A analyzer", "aiq"},
    199 #if HAVE_LIBCL
    200         {DYNAMIC_ANALYZER, "dynamic load 3A analyzer", "dynamic"},
    201         {HYBRID_ANALYZER, "hybrid 3A analyzer", "hybrid"},
    202 #endif
    203 #endif
    204         {0, NULL, NULL},
    205     };
    206 
    207     if (g_once_init_enter (&g_type)) {
    208         const GType type =
    209             g_enum_register_static ("GstXCamSrcAnalyzerType", analyzer_types);
    210         g_once_init_leave (&g_type, type);
    211     }
    212 
    213     return g_type;
    214 }
    215 
    216 #if HAVE_LIBCL
    217 #define GST_TYPE_XCAM_SRC_WDR_MODE (gst_xcam_src_wdr_mode_get_type ())
    218 static GType
    219 gst_xcam_src_wdr_mode_get_type (void)
    220 {
    221     static GType g_type = 0;
    222     static const GEnumValue wdr_mode_types[] = {
    223         {NONE_WDR, "WDR disabled", "none"},
    224         {GAUSSIAN_WDR, "Gaussian WDR mode", "gaussian"},
    225         {HALEQ_WDR, "Haleq WDR mode", "haleq"},
    226         {0, NULL, NULL},
    227     };
    228 
    229     if (g_once_init_enter (&g_type)) {
    230         const GType type =
    231             g_enum_register_static ("GstXCamSrcWDRModeType", wdr_mode_types);
    232         g_once_init_leave (&g_type, type);
    233     }
    234 
    235     return g_type;
    236 }
    237 
    238 #define GST_TYPE_XCAM_SRC_DEFOG_MODE (gst_xcam_src_defog_mode_get_type ())
    239 static GType
    240 gst_xcam_src_defog_mode_get_type (void)
    241 {
    242     static GType g_type = 0;
    243     static const GEnumValue defog_mode_types [] = {
    244         {DEFOG_NONE, "Defog disabled", "none"},
    245         {DEFOG_RETINEX, "Defog retinex", "retinex"},
    246         {DEFOG_DCP, "Defog dark channel prior", "dcp"},
    247         {0, NULL, NULL}
    248     };
    249 
    250     if (g_once_init_enter (&g_type)) {
    251         const GType type =
    252             g_enum_register_static ("GstXCamSrcDefogModeType", defog_mode_types);
    253         g_once_init_leave (&g_type, type);
    254     }
    255 
    256     return g_type;
    257 }
    258 
    259 #define GST_TYPE_XCAM_SRC_3D_DENOISE_MODE (gst_xcam_src_3d_denoise_mode_get_type ())
    260 static GType
    261 gst_xcam_src_3d_denoise_mode_get_type (void)
    262 {
    263     static GType g_type = 0;
    264     static const GEnumValue denoise_3d_mode_types [] = {
    265         {DENOISE_3D_NONE, "3D Denoise disabled", "none"},
    266         {DENOISE_3D_YUV, "3D Denoise yuv", "yuv"},
    267         {DENOISE_3D_UV, "3D Denoise uv", "uv"},
    268         {0, NULL, NULL}
    269     };
    270 
    271     if (g_once_init_enter (&g_type)) {
    272         const GType type =
    273             g_enum_register_static ("GstXCamSrc3DDenoiseModeType", denoise_3d_mode_types);
    274         g_once_init_leave (&g_type, type);
    275     }
    276 
    277     return g_type;
    278 }
    279 
    280 #define GST_TYPE_XCAM_SRC_WAVELET_MODE (gst_xcam_src_wavelet_mode_get_type ())
    281 static GType
    282 gst_xcam_src_wavelet_mode_get_type (void)
    283 {
    284     static GType g_type = 0;
    285     static const GEnumValue wavelet_mode_types[] = {
    286         {NONE_WAVELET, "Wavelet disabled", "none"},
    287         {HAT_WAVELET_Y, "Hat wavelet Y", "hat Y"},
    288         {HAT_WAVELET_UV, "Hat wavelet UV", "hat UV"},
    289         {HARR_WAVELET_Y, "Haar wavelet Y", "haar Y"},
    290         {HARR_WAVELET_UV, "Haar wavelet UV", "haar UV"},
    291         {HARR_WAVELET_YUV, "Haar wavelet YUV", "haar YUV"},
    292         {HARR_WAVELET_BAYES, "Haar wavelet bayes shrink", "haar Bayes"},
    293         {0, NULL, NULL},
    294     };
    295 
    296     if (g_once_init_enter (&g_type)) {
    297         const GType type =
    298             g_enum_register_static ("GstXCamSrcWaveletModeType", wavelet_mode_types);
    299         g_once_init_leave (&g_type, type);
    300     }
    301 
    302     return g_type;
    303 }
    304 
    305 
    306 #define GST_TYPE_XCAM_SRC_CL_PIPE_PROFILE (gst_xcam_src_cl_pipe_profile_get_type ())
    307 static GType
    308 gst_xcam_src_cl_pipe_profile_get_type (void)
    309 {
    310     static GType g_type = 0;
    311     static const GEnumValue profile_types[] = {
    312         {CL3aImageProcessor::BasicPipelineProfile, "cl basic pipe profile", "basic"},
    313         {CL3aImageProcessor::AdvancedPipelineProfile, "cl advanced pipe profile", "advanced"},
    314         {CL3aImageProcessor::ExtremePipelineProfile, "cl extreme pipe profile", "extreme"},
    315         {0, NULL, NULL},
    316     };
    317 
    318     if (g_once_init_enter (&g_type)) {
    319         const GType type =
    320             g_enum_register_static ("GstXCamSrcCLPipeProfile", profile_types);
    321         g_once_init_leave (&g_type, type);
    322     }
    323 
    324     return g_type;
    325 }
    326 #endif
    327 
    328 enum {
    329     PROP_0,
    330     PROP_DEVICE,
    331     PROP_SENSOR,
    332     PROP_MEM_MODE,
    333     PROP_BUFFERCOUNT,
    334     PROP_FIELD,
    335     PROP_IMAGE_PROCESSOR,
    336     PROP_WDR_MODE,
    337     PROP_3A_ANALYZER,
    338     PROP_PIPE_PROFLE,
    339     PROP_CPF,
    340 #if HAVE_IA_AIQ
    341     PROP_ENABLE_3A,
    342     PROP_3A_LIB,
    343 #endif
    344     PROP_INPUT_FMT,
    345     PROP_ENABLE_USB,
    346     PROP_WAVELET_MODE,
    347     PROP_DEFOG_MODE,
    348     PROP_DENOISE_3D_MODE,
    349     PROP_ENABLE_WIREFRAME,
    350     PROP_ENABLE_IMAGE_WARP,
    351     PROP_FAKE_INPUT
    352 };
    353 
    354 #if HAVE_IA_AIQ
    355 static void gst_xcam_src_xcam_3a_interface_init (GstXCam3AInterface *iface);
    356 
    357 G_DEFINE_TYPE_WITH_CODE  (GstXCamSrc, gst_xcam_src, GST_TYPE_PUSH_SRC,
    358                           G_IMPLEMENT_INTERFACE (GST_TYPE_XCAM_3A_IF,
    359                                   gst_xcam_src_xcam_3a_interface_init));
    360 #else
    361 G_DEFINE_TYPE (GstXCamSrc, gst_xcam_src, GST_TYPE_PUSH_SRC);
    362 #endif
    363 
    364 #define parent_class gst_xcam_src_parent_class
    365 
    366 static void gst_xcam_src_finalize (GObject * object);
    367 static void gst_xcam_src_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
    368 static void gst_xcam_src_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
    369 static GstCaps* gst_xcam_src_get_caps (GstBaseSrc *src, GstCaps *filter);
    370 static gboolean gst_xcam_src_set_caps (GstBaseSrc *src, GstCaps *caps);
    371 static gboolean gst_xcam_src_decide_allocation (GstBaseSrc *src, GstQuery *query);
    372 static gboolean gst_xcam_src_start (GstBaseSrc *src);
    373 static gboolean gst_xcam_src_stop (GstBaseSrc *src);
    374 static gboolean gst_xcam_src_unlock (GstBaseSrc *src);
    375 static gboolean gst_xcam_src_unlock_stop (GstBaseSrc *src);
    376 static GstFlowReturn gst_xcam_src_alloc (GstBaseSrc *src, guint64 offset, guint size, GstBuffer **buffer);
    377 static GstFlowReturn gst_xcam_src_fill (GstPushSrc *src, GstBuffer *out);
    378 
    379 #if HAVE_IA_AIQ
    380 /* GstXCamInterface implementation */
    381 static gboolean gst_xcam_src_set_white_balance_mode (GstXCam3A *xcam3a, XCamAwbMode mode);
    382 static gboolean gst_xcam_src_set_awb_speed (GstXCam3A *xcam3a, double speed);
    383 static gboolean gst_xcam_src_set_wb_color_temperature_range (GstXCam3A *xcam3a, guint cct_min, guint cct_max);
    384 static gboolean gst_xcam_src_set_manual_wb_gain (GstXCam3A *xcam3a, double gr, double r, double b, double gb);
    385 static gboolean gst_xcam_src_set_exposure_mode (GstXCam3A *xcam3a, XCamAeMode mode);
    386 static gboolean gst_xcam_src_set_ae_metering_mode (GstXCam3A *xcam3a, XCamAeMeteringMode mode);
    387 static gboolean gst_xcam_src_set_exposure_window (GstXCam3A *xcam3a, XCam3AWindow *window, guint8 count = 1);
    388 static gboolean gst_xcam_src_set_exposure_value_offset (GstXCam3A *xcam3a, double ev_offset);
    389 static gboolean gst_xcam_src_set_ae_speed (GstXCam3A *xcam3a, double speed);
    390 static gboolean gst_xcam_src_set_exposure_flicker_mode (GstXCam3A *xcam3a, XCamFlickerMode flicker);
    391 static XCamFlickerMode gst_xcam_src_get_exposure_flicker_mode (GstXCam3A *xcam3a);
    392 static gint64 gst_xcam_src_get_current_exposure_time (GstXCam3A *xcam3a);
    393 static double gst_xcam_src_get_current_analog_gain (GstXCam3A *xcam3a);
    394 static gboolean gst_xcam_src_set_manual_exposure_time (GstXCam3A *xcam3a, gint64 time_in_us);
    395 static gboolean gst_xcam_src_set_manual_analog_gain (GstXCam3A *xcam3a, double gain);
    396 static gboolean gst_xcam_src_set_aperture (GstXCam3A *xcam3a, double fn);
    397 static gboolean gst_xcam_src_set_max_analog_gain (GstXCam3A *xcam3a, double max_gain);
    398 static double gst_xcam_src_get_max_analog_gain (GstXCam3A *xcam3a);
    399 static gboolean gst_xcam_src_set_exposure_time_range (GstXCam3A *xcam3a, gint64 min_time_in_us, gint64 max_time_in_us);
    400 static gboolean gst_xcam_src_get_exposure_time_range (GstXCam3A *xcam3a, gint64 *min_time_in_us, gint64 *max_time_in_us);
    401 static gboolean gst_xcam_src_set_noise_reduction_level (GstXCam3A *xcam3a, guint8 level);
    402 static gboolean gst_xcam_src_set_temporal_noise_reduction_level (GstXCam3A *xcam3a, guint8 level, gint8 mode);
    403 static gboolean gst_xcam_src_set_gamma_table (GstXCam3A *xcam3a, double *r_table, double *g_table, double *b_table);
    404 static gboolean gst_xcam_src_set_gbce (GstXCam3A *xcam3a, gboolean enable);
    405 static gboolean gst_xcam_src_set_manual_brightness (GstXCam3A *xcam3a, guint8 value);
    406 static gboolean gst_xcam_src_set_manual_contrast (GstXCam3A *xcam3a, guint8 value);
    407 static gboolean gst_xcam_src_set_manual_hue (GstXCam3A *xcam3a, guint8 value);
    408 static gboolean gst_xcam_src_set_manual_saturation (GstXCam3A *xcam3a, guint8 value);
    409 static gboolean gst_xcam_src_set_manual_sharpness (GstXCam3A *xcam3a, guint8 value);
    410 static gboolean gst_xcam_src_set_dvs (GstXCam3A *xcam3a, gboolean enable);
    411 static gboolean gst_xcam_src_set_night_mode (GstXCam3A *xcam3a, gboolean enable);
    412 static gboolean gst_xcam_src_set_hdr_mode (GstXCam3A *xcam3a, guint8 mode);
    413 static gboolean gst_xcam_src_set_denoise_mode (GstXCam3A *xcam3a, guint32 mode);
    414 static gboolean gst_xcam_src_set_gamma_mode (GstXCam3A *xcam3a, gboolean enable);
    415 static gboolean gst_xcam_src_set_dpc_mode(GstXCam3A * xcam3a, gboolean enable);
    416 #endif
    417 
    418 static gboolean gst_xcam_src_plugin_init (GstPlugin * xcamsrc);
    419 
    420 XCAM_END_DECLARE
    421 
    422 static void
    423 gst_xcam_src_class_init (GstXCamSrcClass * class_self)
    424 {
    425     GObjectClass *gobject_class;
    426     GstElementClass *element_class;
    427     GstBaseSrcClass *basesrc_class;
    428     GstPushSrcClass *pushsrc_class;
    429 
    430     gobject_class = (GObjectClass *) class_self;
    431     element_class = (GstElementClass *) class_self;
    432     basesrc_class = GST_BASE_SRC_CLASS (class_self);
    433     pushsrc_class = GST_PUSH_SRC_CLASS (class_self);
    434 
    435     GST_DEBUG_CATEGORY_INIT (gst_xcam_src_debug, "xcamsrc", 0, "libXCam source plugin");
    436 
    437     gobject_class->finalize = gst_xcam_src_finalize;
    438     gobject_class->set_property = gst_xcam_src_set_property;
    439     gobject_class->get_property = gst_xcam_src_get_property;
    440 
    441     g_object_class_install_property (
    442         gobject_class, PROP_DEVICE,
    443         g_param_spec_string ("device", "device", "Device location",
    444                              NULL, (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
    445 
    446     g_object_class_install_property (
    447         gobject_class, PROP_SENSOR,
    448         g_param_spec_int ("sensor-id", "sensor id", "Sensor ID to select",
    449                           0, G_MAXINT, DEFAULT_PROP_SENSOR,
    450                           (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS) ));
    451 
    452     g_object_class_install_property (
    453         gobject_class, PROP_MEM_MODE,
    454         g_param_spec_enum ("io-mode", "memory mode", "Memory mode",
    455                            GST_TYPE_XCAM_SRC_MEM_MODE, DEFAULT_PROP_MEM_MODE,
    456                            (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
    457 
    458     g_object_class_install_property (
    459         gobject_class, PROP_FIELD,
    460         g_param_spec_enum ("field", "field", "field",
    461                            GST_TYPE_XCAM_SRC_FIELD, DEFAULT_PROP_FIELD,
    462                            (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
    463 
    464     g_object_class_install_property (
    465         gobject_class, PROP_ENABLE_USB,
    466         g_param_spec_boolean ("enable-usb", "enable usbcam", "Enable USB camera",
    467                               DEFAULT_PROP_ENABLE_USB, (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
    468 
    469     g_object_class_install_property (
    470         gobject_class, PROP_BUFFERCOUNT,
    471         g_param_spec_int ("buffercount", "buffer count", "buffer count",
    472                           0, G_MAXINT, DEFAULT_PROP_BUFFERCOUNT,
    473                           (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS) ));
    474 
    475     g_object_class_install_property (
    476         gobject_class, PROP_INPUT_FMT,
    477         g_param_spec_string ("input-format", "input format", "Input pixel format",
    478                              NULL, (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
    479 
    480     g_object_class_install_property (
    481         gobject_class, PROP_FAKE_INPUT,
    482         g_param_spec_string ("fake-input", "fake input", "Use the specified raw file as fake input instead of live camera",
    483                              NULL, (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
    484 
    485     g_object_class_install_property (
    486         gobject_class, PROP_IMAGE_PROCESSOR,
    487         g_param_spec_enum ("imageprocessor", "image processor", "Image Processor",
    488                            GST_TYPE_XCAM_SRC_IMAGE_PROCESSOR, DEFAULT_PROP_IMAGE_PROCESSOR,
    489                            (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
    490 
    491     g_object_class_install_property (
    492         gobject_class, PROP_3A_ANALYZER,
    493         g_param_spec_enum ("analyzer", "3a analyzer", "3A Analyzer",
    494                            GST_TYPE_XCAM_SRC_ANALYZER, DEFAULT_PROP_ANALYZER,
    495                            (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
    496 
    497 #if HAVE_IA_AIQ
    498     g_object_class_install_property (
    499         gobject_class, PROP_ENABLE_3A,
    500         g_param_spec_boolean ("enable-3a", "enable 3a", "Enable 3A",
    501                               DEFAULT_PROP_ENABLE_3A, (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
    502 
    503     g_object_class_install_property (
    504         gobject_class, PROP_CPF,
    505         g_param_spec_string ("path-cpf", "cpf", "Path to cpf",
    506                              NULL, (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
    507 
    508     g_object_class_install_property (
    509         gobject_class, PROP_3A_LIB,
    510         g_param_spec_string ("path-3alib", "3a lib", "Path to dynamic 3A library",
    511                              NULL, (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
    512 #endif
    513 
    514 #if HAVE_LIBCL
    515     g_object_class_install_property (
    516         gobject_class, PROP_PIPE_PROFLE,
    517         g_param_spec_enum ("pipe-profile", "cl pipe profile", "CL pipeline profile (only for cl imageprocessor)",
    518                            GST_TYPE_XCAM_SRC_CL_PIPE_PROFILE, DEFAULT_PROP_CL_PIPE_PROFILE,
    519                            (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
    520 
    521     g_object_class_install_property (
    522         gobject_class, PROP_DENOISE_3D_MODE,
    523         g_param_spec_enum ("denoise-3d", "3D Denoise mode", "3D Denoise mode",
    524                            GST_TYPE_XCAM_SRC_3D_DENOISE_MODE, DEFAULT_PROP_3D_DENOISE_MODE,
    525                            (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
    526 
    527     g_object_class_install_property (
    528         gobject_class, PROP_WDR_MODE,
    529         g_param_spec_enum ("wdr-mode", "wdr mode", "WDR Mode",
    530                            GST_TYPE_XCAM_SRC_WDR_MODE,  DEFAULT_PROP_WDR_MODE,
    531                            (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
    532 
    533     g_object_class_install_property (
    534         gobject_class, PROP_WAVELET_MODE,
    535         g_param_spec_enum ("wavelet-mode", "wavelet mode", "WAVELET Mode",
    536                            GST_TYPE_XCAM_SRC_WAVELET_MODE,  DEFAULT_PROP_WAVELET_MODE,
    537                            (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
    538 
    539     g_object_class_install_property (
    540         gobject_class, PROP_DEFOG_MODE,
    541         g_param_spec_enum ("defog-mode", "defog mode", "Defog mode",
    542                            GST_TYPE_XCAM_SRC_DEFOG_MODE, DEFAULT_PROP_DEFOG_MODE,
    543                            (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
    544 
    545     g_object_class_install_property (
    546         gobject_class, PROP_ENABLE_WIREFRAME,
    547         g_param_spec_boolean ("enable-wireframe", "enable wire frame", "Enable wire frame",
    548                               DEFAULT_PROP_ENABLE_WIREFRAME, (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
    549 
    550     g_object_class_install_property (
    551         gobject_class, PROP_ENABLE_IMAGE_WARP,
    552         g_param_spec_boolean ("enable-warp", "enable image warp", "Enable Image Warp",
    553                               DEFAULT_PROP_ENABLE_IMAGE_WARP, (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
    554 #endif
    555 
    556     gst_element_class_set_details_simple (element_class,
    557                                           "Libxcam Source",
    558                                           "Source/Base",
    559                                           "Capture camera video using xcam library",
    560                                           "John Ye <john.ye (at) intel.com> & Wind Yuan <feng.yuan (at) intel.com>");
    561 
    562     gst_element_class_add_pad_template (
    563         element_class,
    564         gst_static_pad_template_get (&gst_xcam_src_factory));
    565 
    566     basesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_xcam_src_get_caps);
    567     basesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_xcam_src_set_caps);
    568     basesrc_class->decide_allocation = GST_DEBUG_FUNCPTR (gst_xcam_src_decide_allocation);
    569 
    570     basesrc_class->start = GST_DEBUG_FUNCPTR (gst_xcam_src_start);
    571     basesrc_class->stop = GST_DEBUG_FUNCPTR (gst_xcam_src_stop);
    572     basesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_xcam_src_unlock);
    573     basesrc_class->unlock_stop = GST_DEBUG_FUNCPTR (gst_xcam_src_unlock_stop);
    574     basesrc_class->alloc = GST_DEBUG_FUNCPTR (gst_xcam_src_alloc);
    575     pushsrc_class->fill = GST_DEBUG_FUNCPTR (gst_xcam_src_fill);
    576 }
    577 
    578 // FIXME remove this function?
    579 static void
    580 gst_xcam_src_init (GstXCamSrc *xcamsrc)
    581 {
    582     gst_base_src_set_format (GST_BASE_SRC (xcamsrc), GST_FORMAT_TIME);
    583     gst_base_src_set_live (GST_BASE_SRC (xcamsrc), TRUE);
    584     gst_base_src_set_do_timestamp (GST_BASE_SRC (xcamsrc), TRUE);
    585 
    586     xcamsrc->buf_count = DEFAULT_PROP_BUFFERCOUNT;
    587     xcamsrc->sensor_id = 0;
    588     xcamsrc->capture_mode = V4L2_CAPTURE_MODE_VIDEO;
    589     xcamsrc->device = NULL;
    590     xcamsrc->enable_usb = DEFAULT_PROP_ENABLE_USB;
    591 
    592 #if HAVE_IA_AIQ
    593     xcamsrc->enable_3a = DEFAULT_PROP_ENABLE_3A;
    594     xcamsrc->path_to_cpf = strndup(DEFAULT_CPF_FILE_NAME, XCAM_MAX_STR_SIZE);
    595     xcamsrc->path_to_3alib = strndup(DEFAULT_DYNAMIC_3A_LIB, XCAM_MAX_STR_SIZE);
    596 #endif
    597 
    598 #if HAVE_LIBCL
    599     xcamsrc->cl_pipe_profile = DEFAULT_PROP_CL_PIPE_PROFILE;
    600     xcamsrc->wdr_mode_type = DEFAULT_PROP_WDR_MODE;
    601     xcamsrc->wavelet_mode = NONE_WAVELET;
    602     xcamsrc->defog_mode = DEFAULT_PROP_DEFOG_MODE;
    603     xcamsrc->denoise_3d_mode = DEFAULT_PROP_3D_DENOISE_MODE;
    604     xcamsrc->denoise_3d_ref_count = 2;
    605     xcamsrc->enable_wireframe = DEFAULT_PROP_ENABLE_WIREFRAME;
    606 #endif
    607 
    608     xcamsrc->path_to_fake = NULL;
    609     xcamsrc->time_offset_ready = FALSE;
    610     xcamsrc->time_offset = -1;
    611     xcamsrc->buf_mark = 0;
    612     xcamsrc->duration = 0;
    613     xcamsrc->mem_type = DEFAULT_PROP_MEM_MODE;
    614     xcamsrc->field = DEFAULT_PROP_FIELD;
    615 
    616     xcamsrc->in_format = 0;
    617     if (xcamsrc->enable_usb) {
    618         xcamsrc->out_format = GST_VIDEO_FORMAT_YUY2;
    619     }
    620     else {
    621         xcamsrc->out_format = DEFAULT_PROP_PIXELFORMAT;
    622     }
    623 
    624     gst_video_info_init (&xcamsrc->gst_video_info);
    625     if (xcamsrc->enable_usb) {
    626         gst_video_info_set_format (&xcamsrc->gst_video_info, GST_VIDEO_FORMAT_YUY2, DEFAULT_VIDEO_WIDTH, DEFAULT_VIDEO_HEIGHT);
    627     }
    628     else {
    629         gst_video_info_set_format (&xcamsrc->gst_video_info, GST_VIDEO_FORMAT_NV12, DEFAULT_VIDEO_WIDTH, DEFAULT_VIDEO_HEIGHT);
    630     }
    631 
    632     XCAM_CONSTRUCTOR (xcamsrc->xcam_video_info, VideoBufferInfo);
    633     xcamsrc->xcam_video_info.init (DEFAULT_PROP_PIXELFORMAT, DEFAULT_VIDEO_WIDTH, DEFAULT_VIDEO_HEIGHT);
    634     xcamsrc->image_processor_type = DEFAULT_PROP_IMAGE_PROCESSOR;
    635     xcamsrc->analyzer_type = DEFAULT_PROP_ANALYZER;
    636     XCAM_CONSTRUCTOR (xcamsrc->device_manager, SmartPtr<MainDeviceManager>);
    637     xcamsrc->device_manager = new MainDeviceManager;
    638 }
    639 
    640 static void
    641 gst_xcam_src_finalize (GObject * object)
    642 {
    643     GstXCamSrc *xcamsrc = GST_XCAM_SRC (object);
    644 
    645     xcamsrc->device_manager.release ();
    646     XCAM_DESTRUCTOR (xcamsrc->device_manager, SmartPtr<MainDeviceManager>);
    647 
    648     G_OBJECT_CLASS (parent_class)->finalize (object);
    649 }
    650 
    651 static void
    652 gst_xcam_src_get_property (
    653     GObject *object,
    654     guint prop_id,
    655     GValue *value,
    656     GParamSpec *pspec)
    657 {
    658     GstXCamSrc *src = GST_XCAM_SRC (object);
    659 
    660     switch (prop_id) {
    661     case PROP_DEVICE:
    662         g_value_set_string (value, src->device);
    663         break;
    664     case PROP_SENSOR:
    665         g_value_set_int (value, src->sensor_id);
    666         break;
    667     case PROP_MEM_MODE:
    668         g_value_set_enum (value, src->mem_type);
    669         break;
    670     case PROP_FIELD:
    671         g_value_set_enum (value, src->field);
    672         break;
    673     case PROP_BUFFERCOUNT:
    674         g_value_set_int (value, src->buf_count);
    675         break;
    676     case PROP_INPUT_FMT:
    677         g_value_set_string (value, xcam_fourcc_to_string (src->in_format));
    678         break;
    679     case PROP_ENABLE_USB:
    680         g_value_set_boolean (value, src->enable_usb);
    681         break;
    682     case PROP_FAKE_INPUT:
    683         g_value_set_string (value, src->path_to_fake);
    684         break;
    685     case PROP_IMAGE_PROCESSOR:
    686         g_value_set_enum (value, src->image_processor_type);
    687         break;
    688     case PROP_3A_ANALYZER:
    689         g_value_set_enum (value, src->analyzer_type);
    690         break;
    691 
    692 #if HAVE_IA_AIQ
    693     case PROP_ENABLE_3A:
    694         g_value_set_boolean (value, src->enable_3a);
    695         break;
    696     case PROP_CPF:
    697         g_value_set_string (value, src->path_to_cpf);
    698         break;
    699     case PROP_3A_LIB:
    700         g_value_set_string (value, src->path_to_3alib);
    701         break;
    702 #endif
    703 
    704 #if HAVE_LIBCL
    705     case PROP_PIPE_PROFLE:
    706         g_value_set_enum (value, src->cl_pipe_profile);
    707         break;
    708     case PROP_DENOISE_3D_MODE:
    709         g_value_set_enum (value, src->denoise_3d_mode);
    710         break;
    711     case PROP_WDR_MODE:
    712         g_value_set_enum (value, src->wdr_mode_type);
    713         break;
    714     case PROP_WAVELET_MODE:
    715         g_value_set_enum (value, src->wavelet_mode);
    716         break;
    717     case PROP_DEFOG_MODE:
    718         g_value_set_enum (value, src->defog_mode);
    719         break;
    720     case PROP_ENABLE_WIREFRAME:
    721         g_value_set_boolean (value, src->enable_wireframe);
    722         break;
    723     case PROP_ENABLE_IMAGE_WARP:
    724         g_value_set_boolean (value, src->enable_image_warp);
    725         break;
    726 #endif
    727     default:
    728         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    729         break;
    730     }
    731 }
    732 
    733 static void
    734 gst_xcam_src_set_property (
    735     GObject *object,
    736     guint prop_id,
    737     const GValue *value,
    738     GParamSpec *pspec)
    739 {
    740     GstXCamSrc *src = GST_XCAM_SRC (object);
    741 
    742     switch (prop_id) {
    743     case PROP_DEVICE: {
    744         const char * device = g_value_get_string (value);
    745         if (src->device)
    746             xcam_free (src->device);
    747         src->device = NULL;
    748         if (device)
    749             src->device = strndup (device, XCAM_MAX_STR_SIZE);
    750         break;
    751     }
    752     case PROP_SENSOR:
    753         src->sensor_id = g_value_get_int (value);
    754         break;
    755     case PROP_MEM_MODE:
    756         src->mem_type = (enum v4l2_memory)g_value_get_enum (value);
    757         break;
    758     case PROP_BUFFERCOUNT:
    759         src->buf_count = g_value_get_int (value);
    760         break;
    761     case PROP_FIELD:
    762         src->field = (enum v4l2_field) g_value_get_enum (value);
    763         break;
    764     case PROP_INPUT_FMT: {
    765         const char * fmt = g_value_get_string (value);
    766         if (strlen (fmt) == 4)
    767             src->in_format = v4l2_fourcc ((unsigned)fmt[0],
    768                                           (unsigned)fmt[1],
    769                                           (unsigned)fmt[2],
    770                                           (unsigned)fmt[3]);
    771         else
    772             GST_ERROR_OBJECT (src, "Invalid input format: not fourcc");
    773         break;
    774     }
    775     case PROP_ENABLE_USB:
    776         src->enable_usb = g_value_get_boolean (value);
    777         break;
    778     case PROP_FAKE_INPUT: {
    779         const char * raw_path = g_value_get_string (value);
    780         if (src->path_to_fake)
    781             xcam_free (src->path_to_fake);
    782         src->path_to_fake = NULL;
    783         if (raw_path)
    784             src->path_to_fake = strndup (raw_path, XCAM_MAX_STR_SIZE);
    785         break;
    786     }
    787     case PROP_IMAGE_PROCESSOR:
    788         src->image_processor_type = (ImageProcessorType)g_value_get_enum (value);
    789         if (src->image_processor_type == ISP_IMAGE_PROCESSOR) {
    790             src->capture_mode = V4L2_CAPTURE_MODE_VIDEO;
    791         }
    792 #if HAVE_LIBCL
    793         else if (src->image_processor_type == CL_IMAGE_PROCESSOR) {
    794             src->capture_mode = V4L2_CAPTURE_MODE_STILL;
    795         }
    796 #else
    797         else {
    798             XCAM_LOG_WARNING ("this release only supports ISP image processor");
    799             src->image_processor_type = ISP_IMAGE_PROCESSOR;
    800             src->capture_mode = V4L2_CAPTURE_MODE_VIDEO;
    801         }
    802 #endif
    803         break;
    804     case PROP_3A_ANALYZER:
    805         src->analyzer_type = (AnalyzerType)g_value_get_enum (value);
    806         break;
    807 
    808 #if HAVE_IA_AIQ
    809     case PROP_ENABLE_3A:
    810         src->enable_3a = g_value_get_boolean (value);
    811         break;
    812     case PROP_CPF: {
    813         const char * cpf = g_value_get_string (value);
    814         if (src->path_to_cpf)
    815             xcam_free (src->path_to_cpf);
    816         src->path_to_cpf = NULL;
    817         if (cpf)
    818             src->path_to_cpf = strndup (cpf, XCAM_MAX_STR_SIZE);
    819         break;
    820     }
    821     case PROP_3A_LIB: {
    822         const char * path = g_value_get_string (value);
    823         if (src->path_to_3alib)
    824             xcam_free (src->path_to_3alib);
    825         src->path_to_3alib = NULL;
    826         if (path)
    827             src->path_to_3alib = strndup (path, XCAM_MAX_STR_SIZE);
    828         break;
    829     }
    830 #endif
    831 
    832 #if HAVE_LIBCL
    833     case PROP_PIPE_PROFLE:
    834         src->cl_pipe_profile = g_value_get_enum (value);
    835         break;
    836     case PROP_DENOISE_3D_MODE:
    837         src->denoise_3d_mode = (Denoise3DModeType) g_value_get_enum (value);
    838         break;
    839     case PROP_WDR_MODE:
    840         src->wdr_mode_type = (WDRModeType)g_value_get_enum (value);
    841         break;
    842     case PROP_WAVELET_MODE:
    843         src->wavelet_mode = (WaveletModeType)g_value_get_enum (value);
    844         break;
    845     case PROP_DEFOG_MODE:
    846         src->defog_mode = (DefogModeType) g_value_get_enum (value);
    847         break;
    848     case PROP_ENABLE_WIREFRAME:
    849         src->enable_wireframe = g_value_get_boolean (value);
    850         break;
    851     case PROP_ENABLE_IMAGE_WARP:
    852         src->enable_image_warp = g_value_get_boolean (value);
    853         break;
    854 #endif
    855     default:
    856         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    857         break;
    858     }
    859 }
    860 
    861 #if HAVE_IA_AIQ
    862 static void
    863 gst_xcam_src_xcam_3a_interface_init (GstXCam3AInterface *iface)
    864 {
    865     iface->set_white_balance_mode = gst_xcam_src_set_white_balance_mode;
    866     iface->set_awb_speed = gst_xcam_src_set_awb_speed;
    867 
    868     iface->set_wb_color_temperature_range = gst_xcam_src_set_wb_color_temperature_range;
    869     iface->set_manual_wb_gain = gst_xcam_src_set_manual_wb_gain;
    870 
    871     iface->set_exposure_mode = gst_xcam_src_set_exposure_mode;
    872     iface->set_ae_metering_mode = gst_xcam_src_set_ae_metering_mode;
    873     iface->set_exposure_window = gst_xcam_src_set_exposure_window;
    874     iface->set_exposure_value_offset = gst_xcam_src_set_exposure_value_offset;
    875     iface->set_ae_speed = gst_xcam_src_set_ae_speed;
    876 
    877     iface->set_exposure_flicker_mode = gst_xcam_src_set_exposure_flicker_mode;
    878     iface->get_exposure_flicker_mode = gst_xcam_src_get_exposure_flicker_mode;
    879     iface->get_current_exposure_time = gst_xcam_src_get_current_exposure_time;
    880     iface->get_current_analog_gain = gst_xcam_src_get_current_analog_gain;
    881     iface->set_manual_exposure_time = gst_xcam_src_set_manual_exposure_time;
    882     iface->set_manual_analog_gain = gst_xcam_src_set_manual_analog_gain;
    883     iface->set_aperture = gst_xcam_src_set_aperture;
    884     iface->set_max_analog_gain = gst_xcam_src_set_max_analog_gain;
    885     iface->get_max_analog_gain = gst_xcam_src_get_max_analog_gain;
    886     iface->set_exposure_time_range = gst_xcam_src_set_exposure_time_range;
    887     iface->get_exposure_time_range = gst_xcam_src_get_exposure_time_range;
    888     iface->set_dvs = gst_xcam_src_set_dvs;
    889     iface->set_noise_reduction_level = gst_xcam_src_set_noise_reduction_level;
    890     iface->set_temporal_noise_reduction_level = gst_xcam_src_set_temporal_noise_reduction_level;
    891     iface->set_gamma_table = gst_xcam_src_set_gamma_table;
    892     iface->set_gbce = gst_xcam_src_set_gbce;
    893     iface->set_manual_brightness = gst_xcam_src_set_manual_brightness;
    894     iface->set_manual_contrast = gst_xcam_src_set_manual_contrast;
    895     iface->set_manual_hue = gst_xcam_src_set_manual_hue;
    896     iface->set_manual_saturation = gst_xcam_src_set_manual_saturation;
    897     iface->set_manual_sharpness = gst_xcam_src_set_manual_sharpness;
    898     iface->set_night_mode = gst_xcam_src_set_night_mode;
    899     iface->set_hdr_mode = gst_xcam_src_set_hdr_mode;
    900     iface->set_denoise_mode = gst_xcam_src_set_denoise_mode;
    901     iface->set_gamma_mode = gst_xcam_src_set_gamma_mode;
    902     iface->set_dpc_mode = gst_xcam_src_set_dpc_mode;
    903 }
    904 #endif
    905 
    906 static gboolean
    907 gst_xcam_src_start (GstBaseSrc *src)
    908 {
    909     GstXCamSrc *xcamsrc = GST_XCAM_SRC (src);
    910     SmartPtr<MainDeviceManager> device_manager = xcamsrc->device_manager;
    911     SmartPtr<X3aAnalyzer> analyzer;
    912 #if HAVE_IA_AIQ
    913     SmartPtr<ImageProcessor> isp_processor;
    914     SmartPtr<IspController> isp_controller;
    915 #endif
    916 #if HAVE_LIBCL
    917     SmartPtr<SmartAnalyzer> smart_analyzer;
    918     SmartPtr<CL3aImageProcessor> cl_processor;
    919     SmartPtr<CLPostImageProcessor> cl_post_processor;
    920 #endif
    921     SmartPtr<V4l2Device> capture_device;
    922     SmartPtr<V4l2SubDevice> event_device;
    923     SmartPtr<PollThread> poll_thread;
    924 
    925     // Check device
    926     if (xcamsrc->device == NULL) {
    927         if (xcamsrc->capture_mode == V4L2_CAPTURE_MODE_STILL)
    928             xcamsrc->device = strndup (CAPTURE_DEVICE_STILL, XCAM_MAX_STR_SIZE);
    929         else
    930             xcamsrc->device = strndup (CAPTURE_DEVICE_VIDEO, XCAM_MAX_STR_SIZE);
    931     }
    932     XCAM_ASSERT (xcamsrc->device);
    933 
    934     // set default input format if set prop wasn't called
    935     if (xcamsrc->in_format == 0) {
    936         if (xcamsrc->image_processor_type == CL_IMAGE_PROCESSOR)
    937             xcamsrc->in_format = V4L2_PIX_FMT_SGRBG10;
    938         else if (xcamsrc->enable_usb)
    939             xcamsrc->in_format = V4L2_PIX_FMT_YUYV;
    940         else
    941             xcamsrc->in_format = V4L2_PIX_FMT_NV12;
    942     }
    943 
    944     if (xcamsrc->path_to_fake) {
    945         capture_device = new FakeV4l2Device ();
    946     } else if (xcamsrc->enable_usb) {
    947         capture_device = new UVCDevice (xcamsrc->device);
    948     }
    949 #if HAVE_IA_AIQ
    950     else {
    951         capture_device = new AtomispDevice (xcamsrc->device);
    952     }
    953 #endif
    954 
    955     capture_device->set_sensor_id (xcamsrc->sensor_id);
    956     capture_device->set_capture_mode (xcamsrc->capture_mode);
    957     capture_device->set_mem_type (xcamsrc->mem_type);
    958     capture_device->set_buffer_count (xcamsrc->buf_count);
    959     capture_device->open ();
    960     device_manager->set_capture_device (capture_device);
    961 
    962 #if HAVE_IA_AIQ
    963     if (!xcamsrc->enable_usb && !xcamsrc->path_to_fake) {
    964         event_device = new V4l2SubDevice (DEFAULT_EVENT_DEVICE);
    965         XCamReturn ret = event_device->open ();
    966         if (ret == XCAM_RETURN_NO_ERROR) {
    967             event_device->subscribe_event (V4L2_EVENT_ATOMISP_3A_STATS_READY);
    968             device_manager->set_event_device (event_device);
    969         }
    970     }
    971 
    972     isp_controller = new IspController (capture_device);
    973 #endif
    974 
    975     switch (xcamsrc->image_processor_type) {
    976 #if HAVE_LIBCL
    977     case CL_IMAGE_PROCESSOR: {
    978 #if HAVE_IA_AIQ
    979         isp_processor = new IspExposureImageProcessor (isp_controller);
    980         XCAM_ASSERT (isp_processor.ptr ());
    981         device_manager->add_image_processor (isp_processor);
    982 #endif
    983         cl_processor = new CL3aImageProcessor ();
    984         cl_processor->set_stats_callback (device_manager);
    985         if(xcamsrc->wdr_mode_type != NONE_WDR)
    986         {
    987             cl_processor->set_gamma (false);
    988             xcamsrc->in_format = V4L2_PIX_FMT_SGRBG12;
    989             cl_processor->set_3a_stats_bits(12);
    990             setenv ("AIQ_CPF_PATH", "/etc/atomisp/imx185_wdr.cpf", 1);
    991 
    992             if(xcamsrc->wdr_mode_type == GAUSSIAN_WDR)
    993             {
    994                 cl_processor->set_tonemapping(CL3aImageProcessor::CLTonemappingMode::Gaussian);
    995             }
    996             else if(xcamsrc->wdr_mode_type == HALEQ_WDR)
    997             {
    998                 cl_processor->set_tonemapping(CL3aImageProcessor::CLTonemappingMode::Haleq);
    999             }
   1000         }
   1001 
   1002         cl_processor->set_profile ((CL3aImageProcessor::PipelineProfile)xcamsrc->cl_pipe_profile);
   1003         device_manager->add_image_processor (cl_processor);
   1004         device_manager->set_cl_image_processor (cl_processor);
   1005         break;
   1006     }
   1007 #endif
   1008 #if HAVE_IA_AIQ
   1009     case ISP_IMAGE_PROCESSOR: {
   1010         isp_processor = new IspImageProcessor (isp_controller);
   1011         device_manager->add_image_processor (isp_processor);
   1012         break;
   1013     }
   1014 #endif
   1015     default:
   1016         XCAM_LOG_ERROR ("unknown image processor type");
   1017         return false;
   1018     }
   1019 
   1020 #if HAVE_LIBCL
   1021     cl_post_processor = new CLPostImageProcessor ();
   1022 
   1023     cl_post_processor->set_stats_callback (device_manager);
   1024     cl_post_processor->set_defog_mode ((CLPostImageProcessor::CLDefogMode) xcamsrc->defog_mode);
   1025     cl_post_processor->set_3ddenoise_mode (
   1026         (CLPostImageProcessor::CL3DDenoiseMode) xcamsrc->denoise_3d_mode, xcamsrc->denoise_3d_ref_count);
   1027 
   1028     if (NONE_WAVELET != xcamsrc->wavelet_mode) {
   1029         if (HAT_WAVELET_Y == xcamsrc->wavelet_mode) {
   1030             cl_post_processor->set_wavelet (CL_WAVELET_HAT, CL_IMAGE_CHANNEL_Y, false);
   1031         } else if (HAT_WAVELET_UV == xcamsrc->wavelet_mode) {
   1032             cl_post_processor->set_wavelet (CL_WAVELET_HAT, CL_IMAGE_CHANNEL_UV, false);
   1033         } else if (HARR_WAVELET_Y == xcamsrc->wavelet_mode) {
   1034             cl_post_processor->set_wavelet (CL_WAVELET_HAAR, CL_IMAGE_CHANNEL_Y, false);
   1035         } else if (HARR_WAVELET_UV == xcamsrc->wavelet_mode) {
   1036             cl_post_processor->set_wavelet (CL_WAVELET_HAAR, CL_IMAGE_CHANNEL_UV, false);
   1037         } else if (HARR_WAVELET_YUV == xcamsrc->wavelet_mode) {
   1038             cl_post_processor->set_wavelet (CL_WAVELET_HAAR, CL_IMAGE_CHANNEL_UV | CL_IMAGE_CHANNEL_Y, false);
   1039         } else if (HARR_WAVELET_BAYES == xcamsrc->wavelet_mode) {
   1040             cl_post_processor->set_wavelet (CL_WAVELET_HAAR, CL_IMAGE_CHANNEL_UV | CL_IMAGE_CHANNEL_Y, true);
   1041         } else {
   1042             cl_post_processor->set_wavelet (CL_WAVELET_DISABLED, CL_IMAGE_CHANNEL_UV, false);
   1043         }
   1044     }
   1045 
   1046     cl_post_processor->set_wireframe (xcamsrc->enable_wireframe);
   1047 
   1048     device_manager->add_image_processor (cl_post_processor);
   1049     device_manager->set_cl_post_image_processor (cl_post_processor);
   1050 #endif
   1051 
   1052     switch (xcamsrc->analyzer_type) {
   1053     case SIMPLE_ANALYZER: {
   1054         analyzer = new X3aAnalyzerSimple ();
   1055         break;
   1056     }
   1057 #if HAVE_IA_AIQ
   1058     case AIQ_TUNER_ANALYZER: {
   1059         XCAM_LOG_INFO ("cpf: %s", xcamsrc->path_to_cpf);
   1060         SmartPtr<X3aAnalyzer> aiq_analyzer = new X3aAnalyzerAiq (isp_controller, xcamsrc->path_to_cpf);
   1061         SmartPtr<X3aAnalyzeTuner> tuner_analyzer = new X3aAnalyzeTuner ();
   1062         XCAM_ASSERT (aiq_analyzer.ptr () && tuner_analyzer.ptr ());
   1063         tuner_analyzer->set_analyzer (aiq_analyzer);
   1064         analyzer = tuner_analyzer;
   1065         break;
   1066     }
   1067 #if HAVE_LIBCL
   1068     case DYNAMIC_ANALYZER: {
   1069         XCAM_LOG_INFO ("dynamic 3a library: %s", xcamsrc->path_to_3alib);
   1070         SmartPtr<DynamicAnalyzerLoader> dynamic_loader = new DynamicAnalyzerLoader (xcamsrc->path_to_3alib);
   1071         SmartPtr<AnalyzerLoader> loader = dynamic_loader.dynamic_cast_ptr<AnalyzerLoader> ();
   1072         analyzer = dynamic_loader->load_analyzer (loader);
   1073         if (!analyzer.ptr ()) {
   1074             XCAM_LOG_ERROR ("load dynamic analyzer(%s) failed, please check.", xcamsrc->path_to_3alib);
   1075             return FALSE;
   1076         }
   1077         break;
   1078     }
   1079     case HYBRID_ANALYZER: {
   1080         XCAM_LOG_INFO ("hybrid 3a library: %s", xcamsrc->path_to_3alib);
   1081         SmartPtr<HybridAnalyzerLoader> hybrid_loader = new HybridAnalyzerLoader (xcamsrc->path_to_3alib);
   1082         hybrid_loader->set_cpf_path (DEFAULT_CPF_FILE_NAME);
   1083         hybrid_loader->set_isp_controller (isp_controller);
   1084         SmartPtr<AnalyzerLoader> loader = hybrid_loader.dynamic_cast_ptr<AnalyzerLoader> ();
   1085         analyzer = hybrid_loader->load_analyzer (loader);
   1086         if (!analyzer.ptr ()) {
   1087             XCAM_LOG_ERROR ("load hybrid analyzer(%s) failed, please check.", xcamsrc->path_to_3alib);
   1088             return FALSE;
   1089         }
   1090         break;
   1091     }
   1092 #endif
   1093 #endif
   1094     default:
   1095         XCAM_LOG_ERROR ("unknown analyzer type");
   1096         return false;
   1097     }
   1098 
   1099     XCAM_ASSERT (analyzer.ptr ());
   1100     if (analyzer->prepare_handlers () != XCAM_RETURN_NO_ERROR) {
   1101         XCAM_LOG_ERROR ("analyzer(%s) prepare handlers failed", analyzer->get_name ());
   1102         return FALSE;
   1103     }
   1104 
   1105     if(xcamsrc->wdr_mode_type != NONE_WDR)
   1106     {
   1107         analyzer->set_ae_exposure_time_range (80 * 1110 * 1000 / 37125, 1120 * 1110 * 1000 / 37125);
   1108         analyzer->set_ae_max_analog_gain (3.98);
   1109     }
   1110     device_manager->set_3a_analyzer (analyzer);
   1111 
   1112 #if HAVE_LIBCL
   1113     SmartHandlerList smart_handlers = SmartAnalyzerLoader::load_smart_handlers (DEFAULT_SMART_ANALYSIS_LIB_DIR);
   1114     if (!smart_handlers.empty ()) {
   1115         smart_analyzer = new SmartAnalyzer ();
   1116         if (smart_analyzer.ptr ()) {
   1117             SmartHandlerList::iterator i_handler = smart_handlers.begin ();
   1118             for (; i_handler != smart_handlers.end ();  ++i_handler)
   1119             {
   1120                 XCAM_ASSERT ((*i_handler).ptr ());
   1121                 smart_analyzer->add_handler (*i_handler);
   1122             }
   1123         } else {
   1124             XCAM_LOG_WARNING ("load smart analyzer(%s) failed, please check.", DEFAULT_SMART_ANALYSIS_LIB_DIR);
   1125         }
   1126     }
   1127 
   1128     if (smart_analyzer.ptr ()) {
   1129         if (cl_post_processor.ptr () && xcamsrc->enable_wireframe) {
   1130             cl_post_processor->set_scaler (true);
   1131             cl_post_processor->set_scaler_factor (640.0 / DEFAULT_VIDEO_WIDTH);
   1132         }
   1133         if (smart_analyzer->prepare_handlers () != XCAM_RETURN_NO_ERROR) {
   1134             XCAM_LOG_INFO ("analyzer(%s) prepare handlers failed", smart_analyzer->get_name ());
   1135             return TRUE;
   1136         }
   1137         device_manager->set_smart_analyzer (smart_analyzer);
   1138     }
   1139 #endif
   1140 
   1141     if (xcamsrc->enable_usb) {
   1142         poll_thread = new PollThread ();
   1143     } else if (xcamsrc->path_to_fake) {
   1144         poll_thread = new FakePollThread (xcamsrc->path_to_fake);
   1145     }
   1146 #if HAVE_IA_AIQ
   1147     else {
   1148         SmartPtr<IspPollThread> isp_poll_thread = new IspPollThread ();
   1149         isp_poll_thread->set_isp_controller (isp_controller);
   1150         poll_thread = isp_poll_thread;
   1151     }
   1152 #endif
   1153     device_manager->set_poll_thread (poll_thread);
   1154 
   1155     return TRUE;
   1156 }
   1157 
   1158 static gboolean
   1159 gst_xcam_src_stop (GstBaseSrc *src)
   1160 {
   1161     SmartPtr<V4l2SubDevice> event_device;
   1162     GstXCamSrc *xcamsrc = GST_XCAM_SRC_CAST (src);
   1163     SmartPtr<MainDeviceManager> device_manager = xcamsrc->device_manager;
   1164     XCAM_ASSERT (device_manager.ptr ());
   1165 
   1166     device_manager->stop();
   1167     device_manager->get_capture_device()->close ();
   1168 
   1169     event_device = device_manager->get_event_device();
   1170     // For USB camera case, the event_device ptr will be NULL
   1171     if (event_device.ptr())
   1172         event_device->close ();
   1173 
   1174     device_manager->pause_dequeue ();
   1175     return TRUE;
   1176 }
   1177 
   1178 static gboolean
   1179 gst_xcam_src_unlock (GstBaseSrc *src)
   1180 {
   1181     GstXCamSrc *xcamsrc = GST_XCAM_SRC_CAST (src);
   1182     SmartPtr<MainDeviceManager> device_manager = xcamsrc->device_manager;
   1183     XCAM_ASSERT (device_manager.ptr ());
   1184 
   1185     device_manager->pause_dequeue ();
   1186     return TRUE;
   1187 }
   1188 
   1189 static gboolean
   1190 gst_xcam_src_unlock_stop (GstBaseSrc *src)
   1191 {
   1192     GstXCamSrc *xcamsrc = GST_XCAM_SRC_CAST (src);
   1193     SmartPtr<MainDeviceManager> device_manager = xcamsrc->device_manager;
   1194     XCAM_ASSERT (device_manager.ptr ());
   1195 
   1196     device_manager->resume_dequeue ();
   1197     return TRUE;
   1198 }
   1199 
   1200 static GstCaps*
   1201 gst_xcam_src_get_caps (GstBaseSrc *src, GstCaps *filter)
   1202 {
   1203     GstXCamSrc *xcamsrc = GST_XCAM_SRC (src);
   1204     XCAM_UNUSED (filter);
   1205 
   1206     return gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (xcamsrc));
   1207 }
   1208 
   1209 static uint32_t
   1210 translate_format_to_xcam (GstVideoFormat format)
   1211 {
   1212     switch (format) {
   1213     case GST_VIDEO_FORMAT_NV12:
   1214         return V4L2_PIX_FMT_NV12;
   1215     case GST_VIDEO_FORMAT_I420:
   1216         return V4L2_PIX_FMT_YUV420;
   1217     case GST_VIDEO_FORMAT_YUY2:
   1218         return V4L2_PIX_FMT_YUYV;
   1219     case GST_VIDEO_FORMAT_Y42B:
   1220         return V4L2_PIX_FMT_YUV422P;
   1221 
   1222         //RGB
   1223     case GST_VIDEO_FORMAT_RGBx:
   1224         return V4L2_PIX_FMT_RGB32;
   1225     case GST_VIDEO_FORMAT_BGRx:
   1226         return V4L2_PIX_FMT_BGR32;
   1227     default:
   1228         break;
   1229     }
   1230     return 0;
   1231 }
   1232 
   1233 static gboolean
   1234 gst_xcam_src_set_caps (GstBaseSrc *src, GstCaps *caps)
   1235 {
   1236     GstXCamSrc *xcamsrc = GST_XCAM_SRC (src);
   1237     struct v4l2_format format;
   1238     uint32_t out_format = 0;
   1239     GstVideoInfo info;
   1240 
   1241     gst_video_info_from_caps (&info, caps);
   1242     XCAM_ASSERT ((GST_VIDEO_INFO_FORMAT (&info) == GST_VIDEO_FORMAT_NV12) ||
   1243                  (GST_VIDEO_INFO_FORMAT (&info) == GST_VIDEO_FORMAT_YUY2));
   1244 
   1245     out_format = translate_format_to_xcam (GST_VIDEO_INFO_FORMAT (&info));
   1246     if (!out_format) {
   1247         GST_WARNING ("format doesn't support:%s", GST_VIDEO_INFO_NAME (&info));
   1248         return FALSE;
   1249     }
   1250 #if HAVE_LIBCL
   1251     SmartPtr<CLPostImageProcessor> processor = xcamsrc->device_manager->get_cl_post_image_processor ();
   1252     XCAM_ASSERT (processor.ptr ());
   1253     if (!processor->set_output_format (out_format)) {
   1254         GST_ERROR ("pipeline doesn't support output format:%" GST_FOURCC_FORMAT,
   1255                    GST_FOURCC_ARGS (out_format));
   1256         return FALSE;
   1257     }
   1258 #endif
   1259 
   1260     xcamsrc->out_format = out_format;
   1261 
   1262     SmartPtr<MainDeviceManager> device_manager = xcamsrc->device_manager;
   1263     SmartPtr<V4l2Device> capture_device = device_manager->get_capture_device ();
   1264     capture_device->set_framerate (GST_VIDEO_INFO_FPS_N (&info), GST_VIDEO_INFO_FPS_D (&info));
   1265     capture_device->set_format (
   1266         GST_VIDEO_INFO_WIDTH (&info),
   1267         GST_VIDEO_INFO_HEIGHT(&info),
   1268         xcamsrc->in_format,
   1269         xcamsrc->field,
   1270         info.stride [0]);
   1271 
   1272     if (device_manager->start () != XCAM_RETURN_NO_ERROR)
   1273         return FALSE;
   1274 
   1275     capture_device->get_format (format);
   1276     xcamsrc->gst_video_info = info;
   1277     size_t offset = 0;
   1278     for (uint32_t n = 0; n < GST_VIDEO_INFO_N_PLANES (&xcamsrc->gst_video_info); n++) {
   1279         GST_VIDEO_INFO_PLANE_OFFSET (&xcamsrc->gst_video_info, n) = offset;
   1280         if (out_format == V4L2_PIX_FMT_NV12) {
   1281             GST_VIDEO_INFO_PLANE_STRIDE (&xcamsrc->gst_video_info, n) = format.fmt.pix.bytesperline * 2 / 3;
   1282         }
   1283         else if (format.fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV) {
   1284             // for 4:2:2 format, stride is widthx2
   1285             GST_VIDEO_INFO_PLANE_STRIDE (&xcamsrc->gst_video_info, n) = format.fmt.pix.bytesperline;
   1286         }
   1287         else {
   1288             GST_VIDEO_INFO_PLANE_STRIDE (&xcamsrc->gst_video_info, n) = format.fmt.pix.bytesperline / 2;
   1289         }
   1290         offset += GST_VIDEO_INFO_PLANE_STRIDE (&xcamsrc->gst_video_info, n) * format.fmt.pix.height;
   1291         //TODO, need set offsets
   1292     }
   1293 
   1294     // TODO, need calculate aligned width/height
   1295     xcamsrc->xcam_video_info.init (out_format, GST_VIDEO_INFO_WIDTH (&info),  GST_VIDEO_INFO_HEIGHT (&info));
   1296 
   1297     xcamsrc->duration = gst_util_uint64_scale_int (
   1298                             GST_SECOND,
   1299                             GST_VIDEO_INFO_FPS_D(&xcamsrc->gst_video_info),
   1300                             GST_VIDEO_INFO_FPS_N(&xcamsrc->gst_video_info));
   1301     xcamsrc->pool = gst_xcam_buffer_pool_new (xcamsrc, caps, xcamsrc->device_manager);
   1302 
   1303     return TRUE;
   1304 }
   1305 
   1306 static gboolean
   1307 gst_xcam_src_decide_allocation (GstBaseSrc *src, GstQuery *query)
   1308 {
   1309     GstXCamSrc *xcamsrc = GST_XCAM_SRC (src);
   1310     GstBufferPool *pool = NULL;
   1311     uint32_t pool_num = 0;
   1312 
   1313     XCAM_ASSERT (xcamsrc);
   1314     XCAM_ASSERT (xcamsrc->pool);
   1315 
   1316     pool_num = gst_query_get_n_allocation_pools (query);
   1317     if (pool_num > 0) {
   1318         for (uint32_t i = pool_num - 1; i > 0; --i) {
   1319             gst_query_remove_nth_allocation_pool (query, i);
   1320         }
   1321         gst_query_parse_nth_allocation_pool (query, 0, &pool, NULL, NULL, NULL);
   1322         if (pool == xcamsrc->pool)
   1323             return TRUE;
   1324         gst_object_unref (pool);
   1325         gst_query_remove_nth_allocation_pool (query, 0);
   1326     }
   1327 
   1328     gst_query_add_allocation_pool (
   1329         query, xcamsrc->pool,
   1330         GST_VIDEO_INFO_WIDTH (&xcamsrc->gst_video_info),
   1331         GST_XCAM_SRC_BUF_COUNT (xcamsrc),
   1332         GST_XCAM_SRC_BUF_COUNT (xcamsrc));
   1333 
   1334     return GST_BASE_SRC_CLASS (parent_class)->decide_allocation (src, query);
   1335 }
   1336 
   1337 static GstFlowReturn
   1338 gst_xcam_src_alloc (GstBaseSrc *src, guint64 offset, guint size, GstBuffer **buffer)
   1339 {
   1340     GstFlowReturn ret;
   1341     GstXCamSrc *xcamsrc = GST_XCAM_SRC (src);
   1342 
   1343     XCAM_UNUSED (offset);
   1344     XCAM_UNUSED (size);
   1345 
   1346     ret = gst_buffer_pool_acquire_buffer (xcamsrc->pool, buffer, NULL);
   1347     XCAM_ASSERT (*buffer);
   1348     return ret;
   1349 }
   1350 
   1351 static GstFlowReturn
   1352 gst_xcam_src_fill (GstPushSrc *basesrc, GstBuffer *buf)
   1353 {
   1354     GstXCamSrc *src = GST_XCAM_SRC_CAST (basesrc);
   1355 
   1356     GST_BUFFER_OFFSET (buf) = src->buf_mark;
   1357     GST_BUFFER_OFFSET_END (buf) = GST_BUFFER_OFFSET (buf) + 1;
   1358     ++src->buf_mark;
   1359 
   1360     if (!GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (buf)))
   1361         return GST_FLOW_OK;
   1362 
   1363     if (!src->time_offset_ready) {
   1364         GstClock *clock = GST_ELEMENT_CLOCK (src);
   1365         GstClockTime actual_time = 0;
   1366 
   1367         if (!clock)
   1368             return GST_FLOW_OK;
   1369 
   1370         actual_time = gst_clock_get_time (clock) - GST_ELEMENT_CAST (src)->base_time;
   1371         src->time_offset = actual_time - GST_BUFFER_TIMESTAMP (buf);
   1372         src->time_offset_ready = TRUE;
   1373         gst_object_ref (clock);
   1374     }
   1375 
   1376     GST_BUFFER_TIMESTAMP (buf) += src->time_offset;
   1377     //GST_BUFFER_DURATION (buf) = src->duration;
   1378 
   1379     XCAM_STATIC_FPS_CALCULATION (gstxcamsrc, XCAM_OBJ_DUR_FRAME_NUM);
   1380     return GST_FLOW_OK;
   1381 }
   1382 
   1383 #if HAVE_IA_AIQ
   1384 static gboolean
   1385 gst_xcam_src_set_white_balance_mode (GstXCam3A *xcam3a, XCamAwbMode mode)
   1386 {
   1387     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1388 
   1389     return analyzer->set_awb_mode (mode);
   1390 }
   1391 
   1392 static gboolean
   1393 gst_xcam_src_set_awb_speed (GstXCam3A *xcam3a, double speed)
   1394 {
   1395     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1396 
   1397     return analyzer->set_awb_speed (speed);
   1398 }
   1399 
   1400 static gboolean
   1401 gst_xcam_src_set_wb_color_temperature_range (GstXCam3A *xcam3a, guint cct_min, guint cct_max)
   1402 {
   1403     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1404 
   1405     return analyzer->set_awb_color_temperature_range (cct_min, cct_max);
   1406 }
   1407 
   1408 static gboolean
   1409 gst_xcam_src_set_manual_wb_gain (GstXCam3A *xcam3a, double gr, double r, double b, double gb)
   1410 {
   1411     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1412 
   1413     return analyzer->set_awb_manual_gain (gr, r, b, gb);
   1414 }
   1415 
   1416 
   1417 static gboolean
   1418 gst_xcam_src_set_exposure_mode (GstXCam3A *xcam3a, XCamAeMode mode)
   1419 {
   1420     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1421 
   1422     return analyzer->set_ae_mode (mode);
   1423 }
   1424 
   1425 static gboolean
   1426 gst_xcam_src_set_ae_metering_mode (GstXCam3A *xcam3a, XCamAeMeteringMode mode)
   1427 {
   1428     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1429 
   1430     return analyzer->set_ae_metering_mode (mode);
   1431 }
   1432 
   1433 static gboolean
   1434 gst_xcam_src_set_exposure_window (GstXCam3A *xcam3a, XCam3AWindow *window, guint8 count)
   1435 {
   1436     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1437 
   1438     return analyzer->set_ae_window (window, count);
   1439 }
   1440 
   1441 static gboolean
   1442 gst_xcam_src_set_exposure_value_offset (GstXCam3A *xcam3a, double ev_offset)
   1443 {
   1444     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1445 
   1446     return analyzer->set_ae_ev_shift (ev_offset);
   1447 }
   1448 
   1449 static gboolean
   1450 gst_xcam_src_set_ae_speed (GstXCam3A *xcam3a, double speed)
   1451 {
   1452     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1453 
   1454     return analyzer->set_ae_speed (speed);
   1455 }
   1456 
   1457 static gboolean
   1458 gst_xcam_src_set_exposure_flicker_mode (GstXCam3A *xcam3a, XCamFlickerMode flicker)
   1459 {
   1460     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1461 
   1462     return analyzer->set_ae_flicker_mode (flicker);
   1463 }
   1464 
   1465 static XCamFlickerMode
   1466 gst_xcam_src_get_exposure_flicker_mode (GstXCam3A *xcam3a)
   1467 {
   1468     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1469 
   1470     return analyzer->get_ae_flicker_mode ();
   1471 }
   1472 
   1473 static gint64
   1474 gst_xcam_src_get_current_exposure_time (GstXCam3A *xcam3a)
   1475 {
   1476     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1477 
   1478     return analyzer->get_ae_current_exposure_time ();
   1479 }
   1480 
   1481 static double
   1482 gst_xcam_src_get_current_analog_gain (GstXCam3A *xcam3a)
   1483 {
   1484     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1485 
   1486     return analyzer->get_ae_current_analog_gain ();
   1487 }
   1488 
   1489 static gboolean
   1490 gst_xcam_src_set_manual_exposure_time (GstXCam3A *xcam3a, gint64 time_in_us)
   1491 {
   1492     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1493 
   1494     return analyzer->set_ae_manual_exposure_time (time_in_us);
   1495 }
   1496 
   1497 static gboolean
   1498 gst_xcam_src_set_manual_analog_gain (GstXCam3A *xcam3a, double gain)
   1499 {
   1500     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1501 
   1502     return analyzer->set_ae_manual_analog_gain (gain);
   1503 }
   1504 
   1505 static gboolean
   1506 gst_xcam_src_set_aperture (GstXCam3A *xcam3a, double fn)
   1507 {
   1508     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1509 
   1510     return analyzer->set_ae_aperture (fn);
   1511 }
   1512 
   1513 static gboolean
   1514 gst_xcam_src_set_max_analog_gain (GstXCam3A *xcam3a, double max_gain)
   1515 {
   1516     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1517 
   1518     return analyzer->set_ae_max_analog_gain (max_gain);
   1519 }
   1520 
   1521 static double
   1522 gst_xcam_src_get_max_analog_gain (GstXCam3A *xcam3a)
   1523 {
   1524     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1525 
   1526     return analyzer->get_ae_max_analog_gain ();
   1527 }
   1528 
   1529 static gboolean
   1530 gst_xcam_src_set_exposure_time_range (GstXCam3A *xcam3a, gint64 min_time_in_us, gint64 max_time_in_us)
   1531 {
   1532     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1533 
   1534     return analyzer->set_ae_exposure_time_range (min_time_in_us, max_time_in_us);
   1535 }
   1536 
   1537 static gboolean
   1538 gst_xcam_src_get_exposure_time_range (GstXCam3A *xcam3a, gint64 *min_time_in_us, gint64 *max_time_in_us)
   1539 {
   1540     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1541 
   1542     return analyzer->get_ae_exposure_time_range (min_time_in_us, max_time_in_us);
   1543 }
   1544 
   1545 static gboolean
   1546 gst_xcam_src_set_noise_reduction_level (GstXCam3A *xcam3a, guint8 level)
   1547 {
   1548     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1549 
   1550     return analyzer->set_noise_reduction_level ((level - 128) / 128.0);
   1551 }
   1552 
   1553 static gboolean
   1554 gst_xcam_src_set_temporal_noise_reduction_level (GstXCam3A *xcam3a, guint8 level, gint8 mode)
   1555 {
   1556     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1557 
   1558     bool ret = analyzer->set_temporal_noise_reduction_level ((level - 128) / 128.0);
   1559 #if HAVE_LIBCL
   1560     SmartPtr<CL3aImageProcessor> cl_image_processor = device_manager->get_cl_image_processor ();
   1561     if (cl_image_processor.ptr ()) {
   1562         ret = cl_image_processor->set_tnr(mode, level);
   1563     }
   1564     else {
   1565         ret = false;
   1566     }
   1567 #else
   1568     XCAM_UNUSED (mode);
   1569 #endif
   1570     return (gboolean)ret;
   1571 }
   1572 
   1573 static gboolean
   1574 gst_xcam_src_set_gamma_table (GstXCam3A *xcam3a, double *r_table, double *g_table, double *b_table)
   1575 {
   1576     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1577 
   1578     return analyzer->set_gamma_table (r_table, g_table, b_table);
   1579 }
   1580 
   1581 static gboolean
   1582 gst_xcam_src_set_gbce (GstXCam3A *xcam3a, gboolean enable)
   1583 {
   1584     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1585 
   1586     return analyzer->set_gbce (enable);
   1587 }
   1588 
   1589 static gboolean
   1590 gst_xcam_src_set_manual_brightness (GstXCam3A *xcam3a, guint8 value)
   1591 {
   1592     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1593 
   1594     return analyzer->set_manual_brightness ((value - 128) / 128.0);
   1595 }
   1596 
   1597 static gboolean
   1598 gst_xcam_src_set_manual_contrast (GstXCam3A *xcam3a, guint8 value)
   1599 {
   1600     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1601 
   1602     return analyzer->set_manual_contrast ((value - 128) / 128.0);
   1603 }
   1604 
   1605 static gboolean
   1606 gst_xcam_src_set_manual_hue (GstXCam3A *xcam3a, guint8 value)
   1607 {
   1608     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1609 
   1610     return analyzer->set_manual_hue ((value - 128) / 128.0);
   1611 }
   1612 
   1613 static gboolean
   1614 gst_xcam_src_set_manual_saturation (GstXCam3A *xcam3a, guint8 value)
   1615 {
   1616     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1617 
   1618     return analyzer->set_manual_saturation ((value - 128) / 128.0);
   1619 }
   1620 
   1621 static gboolean
   1622 gst_xcam_src_set_manual_sharpness (GstXCam3A *xcam3a, guint8 value)
   1623 {
   1624     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1625 
   1626     return analyzer->set_manual_sharpness ((value - 128) / 128.0);
   1627 }
   1628 
   1629 static gboolean
   1630 gst_xcam_src_set_dvs (GstXCam3A *xcam3a, gboolean enable)
   1631 {
   1632     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1633 
   1634     return analyzer->set_dvs (enable);
   1635 }
   1636 
   1637 static gboolean
   1638 gst_xcam_src_set_night_mode (GstXCam3A *xcam3a, gboolean enable)
   1639 {
   1640     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1641 
   1642     return analyzer->set_night_mode (enable);
   1643 }
   1644 
   1645 static gboolean
   1646 gst_xcam_src_set_hdr_mode (GstXCam3A *xcam3a, guint8 mode)
   1647 {
   1648     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1649     XCAM_UNUSED (analyzer);
   1650 
   1651 #if HAVE_LIBCL
   1652     SmartPtr<CL3aImageProcessor> cl_image_processor = device_manager->get_cl_image_processor ();
   1653     CL3aImageProcessor::CLTonemappingMode tone_map_value =
   1654         (mode ? CL3aImageProcessor::Haleq : CL3aImageProcessor::WDRdisabled);
   1655     if (cl_image_processor.ptr ())
   1656         return (gboolean) cl_image_processor->set_tonemapping(tone_map_value);
   1657     else
   1658         return false;
   1659 #else
   1660     XCAM_UNUSED (mode);
   1661     return true;
   1662 #endif
   1663 }
   1664 
   1665 static gboolean
   1666 gst_xcam_src_set_denoise_mode (GstXCam3A *xcam3a, guint32 mode)
   1667 {
   1668     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1669     XCAM_UNUSED (analyzer);
   1670 
   1671 #if HAVE_LIBCL
   1672     gboolean ret;
   1673     SmartPtr<CL3aImageProcessor> cl_image_processor = device_manager->get_cl_image_processor ();
   1674     if (cl_image_processor.ptr ()) {
   1675         ret = cl_image_processor->set_denoise (mode);
   1676         return ret;
   1677     }
   1678     else
   1679         return false;
   1680 #else
   1681     XCAM_UNUSED (mode);
   1682     return true;
   1683 #endif
   1684 }
   1685 
   1686 static gboolean
   1687 gst_xcam_src_set_gamma_mode (GstXCam3A *xcam3a, gboolean enable)
   1688 {
   1689     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1690     XCAM_UNUSED (analyzer);
   1691 
   1692 #if HAVE_LIBCL
   1693     SmartPtr<CL3aImageProcessor> cl_image_processor = device_manager->get_cl_image_processor ();
   1694     if (cl_image_processor.ptr ())
   1695         return cl_image_processor->set_gamma (enable);
   1696     else
   1697         return false;
   1698 #else
   1699     XCAM_UNUSED (enable);
   1700     return true;
   1701 #endif
   1702 }
   1703 
   1704 static gboolean
   1705 gst_xcam_src_set_dpc_mode (GstXCam3A *xcam3a, gboolean enable)
   1706 {
   1707     GST_XCAM_INTERFACE_HEADER (xcam3a, src, device_manager, analyzer);
   1708     XCAM_UNUSED (analyzer);
   1709     XCAM_UNUSED (enable);
   1710 
   1711     XCAM_LOG_WARNING ("xcamsrc: dpc is not supported");
   1712     return true;
   1713 }
   1714 #endif
   1715 
   1716 static gboolean
   1717 gst_xcam_src_plugin_init (GstPlugin * xcamsrc)
   1718 {
   1719     return gst_element_register (xcamsrc, "xcamsrc", GST_RANK_NONE,
   1720                                  GST_TYPE_XCAM_SRC);
   1721 }
   1722 
   1723 #ifndef PACKAGE
   1724 #define PACKAGE "libxam"
   1725 #endif
   1726 
   1727 GST_PLUGIN_DEFINE (
   1728     GST_VERSION_MAJOR,
   1729     GST_VERSION_MINOR,
   1730     xcamsrc,
   1731     "xcamsrc",
   1732     gst_xcam_src_plugin_init,
   1733     VERSION,
   1734     GST_LICENSE_UNKNOWN,
   1735     "libxcamsrc",
   1736     "https://github.com/01org/libxcam"
   1737 )
   1738