Home | History | Annotate | Download | only in capi
      1 /*
      2  * context_priv.h - capi private context
      3  *
      4  *  Copyright (c) 2017 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: Wind Yuan <feng.yuan (at) intel.com>
     19  */
     20 
     21 #ifndef XCAM_CONTEXT_PRIV_H
     22 #define XCAM_CONTEXT_PRIV_H
     23 
     24 #include <xcam_utils.h>
     25 #include <string.h>
     26 #include <ocl/cl_image_handler.h>
     27 #include <ocl/cl_context.h>
     28 #include <ocl/cl_blender.h>
     29 #include <interface/stitcher.h>
     30 
     31 using namespace XCam;
     32 
     33 enum HandleType {
     34     HandleTypeNone = 0,
     35     HandleType3DNR,
     36     HandleTypeWaveletNR,
     37     HandleTypeFisheye,
     38     HandleTypeDefog,
     39     HandleTypeDVS,
     40     HandleTypeStitch,
     41 };
     42 
     43 #define CONTEXT_CAST(Type, handle) (Type*)(handle)
     44 #define CONTEXT_BASE_CAST(handle) (ContextBase*)(handle)
     45 #define HANDLE_CAST(context) (XCamHandle*)(context)
     46 
     47 bool handle_name_equal (const char *name, HandleType type);
     48 
     49 typedef struct _CompareStr {
     50     bool operator() (const char* str1, const char* str2) const {
     51         return strncmp(str1, str2, 1024) < 0;
     52     }
     53 } CompareStr;
     54 
     55 typedef std::map<const char*, const char*, CompareStr> ContextParams;
     56 
     57 class ContextBase {
     58 public:
     59     virtual ~ContextBase ();
     60 
     61     virtual XCamReturn set_parameters (ContextParams &param_list);
     62     virtual const char* get_usage () const {
     63         return _usage;
     64     }
     65     XCamReturn init_handler ();
     66     XCamReturn uinit_handler ();
     67 
     68     XCamReturn execute (SmartPtr<VideoBuffer> &buf_in, SmartPtr<VideoBuffer> &buf_out);
     69 
     70     SmartPtr<CLImageHandler> get_handler() const {
     71         return  _handler;
     72     }
     73     SmartPtr<BufferPool> get_input_buffer_pool() const {
     74         return  _inbuf_pool;
     75     }
     76     HandleType get_type () const {
     77         return _type;
     78     }
     79     const char* get_type_name () const;
     80 
     81 protected:
     82     ContextBase (HandleType type);
     83     void set_handler (const SmartPtr<CLImageHandler> &ptr) {
     84         _handler = ptr;
     85     }
     86 
     87     virtual SmartPtr<CLImageHandler> create_handler (SmartPtr<CLContext> &context) = 0;
     88 
     89 private:
     90     XCAM_DEAD_COPY (ContextBase);
     91 
     92 protected:
     93     HandleType                       _type;
     94     char                            *_usage;
     95     SmartPtr<CLImageHandler>         _handler;
     96     SmartPtr<BufferPool>             _inbuf_pool;
     97 
     98     //parameters
     99     uint32_t                         _image_width;
    100     uint32_t                         _image_height;
    101     bool                             _alloc_out_buf;
    102 };
    103 
    104 class NR3DContext
    105     : public ContextBase
    106 {
    107 public:
    108     NR3DContext ()
    109         : ContextBase (HandleType3DNR)
    110     {}
    111 
    112     virtual SmartPtr<CLImageHandler> create_handler (SmartPtr<CLContext> &context);
    113 };
    114 
    115 class NRWaveletContext
    116     : public ContextBase
    117 {
    118 public:
    119     NRWaveletContext ()
    120         : ContextBase (HandleTypeWaveletNR)
    121     {}
    122 
    123     virtual SmartPtr<CLImageHandler> create_handler (SmartPtr<CLContext> &context);
    124 };
    125 
    126 class FisheyeContext
    127     : public ContextBase
    128 {
    129 public:
    130     FisheyeContext ()
    131         : ContextBase (HandleTypeFisheye)
    132     {}
    133 
    134     virtual SmartPtr<CLImageHandler> create_handler (SmartPtr<CLContext> &context);
    135 };
    136 
    137 class DefogContext
    138     : public ContextBase
    139 {
    140 public:
    141     DefogContext ()
    142         : ContextBase (HandleTypeDefog)
    143     {}
    144 
    145     virtual SmartPtr<CLImageHandler> create_handler (SmartPtr<CLContext> &context);
    146 };
    147 
    148 class DVSContext
    149     : public ContextBase
    150 {
    151 public:
    152     DVSContext ()
    153         : ContextBase (HandleTypeDVS)
    154     {}
    155 
    156     virtual SmartPtr<CLImageHandler> create_handler (SmartPtr<CLContext> &context);
    157 };
    158 
    159 class StitchContext
    160     : public ContextBase
    161 {
    162 public:
    163     StitchContext ()
    164         : ContextBase (HandleTypeStitch)
    165         , _need_seam (false)
    166         , _fisheye_map (false)
    167         , _need_lsc (false)
    168         , _fm_ocl (false)
    169         , _scale_mode (CLBlenderScaleLocal)
    170         , _res_mode (StitchRes1080P)
    171     {}
    172 
    173     virtual SmartPtr<CLImageHandler> create_handler (SmartPtr<CLContext> &context);
    174 
    175 private:
    176     bool                  _need_seam;
    177     bool                  _fisheye_map;
    178     bool                  _need_lsc;
    179     bool                  _fm_ocl;
    180     CLBlenderScaleMode    _scale_mode;
    181     StitchResMode         _res_mode;
    182 };
    183 
    184 #endif //XCAM_CONTEXT_PRIV_H
    185