• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * dynamic_analyzer_loader.cpp - dynamic analyzer loader
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: Wind Yuan <feng.yuan@intel.com>
19  *         Zong Wei  <wei.zong@intel.com>
20  */
21 
22 #include "dynamic_analyzer_loader.h"
23 #include "dynamic_analyzer.h"
24 #include "handler_interface.h"
25 #include <dlfcn.h>
26 
27 namespace XCam {
28 
DynamicAnalyzerLoader(const char * lib_path,const char * symbol)29 DynamicAnalyzerLoader::DynamicAnalyzerLoader (const char *lib_path, const char *symbol)
30     : AnalyzerLoader (lib_path, symbol)
31 {
32 }
33 
~DynamicAnalyzerLoader()34 DynamicAnalyzerLoader::~DynamicAnalyzerLoader ()
35 {
36 }
37 
38 SmartPtr<X3aAnalyzer>
load_analyzer(SmartPtr<AnalyzerLoader> & self)39 DynamicAnalyzerLoader::load_analyzer (SmartPtr<AnalyzerLoader> &self)
40 {
41     XCAM_ASSERT (self.ptr () == this);
42 
43     SmartPtr<X3aAnalyzer> analyzer;
44     XCam3ADescription *desc = (XCam3ADescription*)load_library (get_lib_path ());
45 
46     analyzer = new DynamicAnalyzer (desc, self);
47     if (!analyzer.ptr ()) {
48         XCAM_LOG_WARNING ("create DynamicAnalyzer from lib failed");
49         close_handle ();
50         return NULL;
51     }
52 
53     XCAM_LOG_INFO ("analyzer(%s) created from 3a lib", XCAM_STR (analyzer->get_name()));
54     return analyzer;
55 }
56 
57 void *
load_symbol(void * handle)58 DynamicAnalyzerLoader::load_symbol (void* handle)
59 {
60     XCam3ADescription *desc = NULL;
61 
62     desc = (XCam3ADescription *)AnalyzerLoader::get_symbol (handle);
63     if (!desc) {
64         XCAM_LOG_DEBUG ("get symbol failed from lib");
65         return NULL;
66     }
67     if (desc->version < xcam_version ()) {
68         XCAM_LOG_DEBUG ("get symbolfailed. version is:0x%04x, but expect:0x%04x",
69                         desc->version, xcam_version ());
70         return NULL;
71     }
72     if (desc->size < sizeof (XCam3ADescription)) {
73         XCAM_LOG_DEBUG ("get symbol failed, XCam3ADescription size is:%" PRIu32 ", but expect:%" PRIuS,
74                         desc->size, sizeof (XCam3ADescription));
75         return NULL;
76     }
77 
78     if (!desc->create_context || !desc->destroy_context ||
79             !desc->configure_3a || !desc->set_3a_stats ||
80             !desc->analyze_awb || !desc->analyze_ae ||
81             !desc->analyze_af || !desc->combine_analyze_results ||
82             !desc->free_results) {
83         XCAM_LOG_DEBUG ("some functions in symbol not set from lib");
84         return NULL;
85     }
86     return (void*)desc;
87 }
88 
89 };
90