• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * x3a_analyzer_manager.cpp - analyzer manager
3  *
4  *  Copyright (c) 2014-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  */
20 
21 #include "x3a_analyzer_manager.h"
22 #include "x3a_analyzer_simple.h"
23 #include <sys/types.h>
24 #include <dirent.h>
25 
26 namespace XCam {
27 
28 #define XCAM_DEFAULT_3A_LIB_DIR "/usr/lib/xcam/plugins/3a"
29 
30 SmartPtr<X3aAnalyzerManager> X3aAnalyzerManager::_instance(NULL);
31 Mutex X3aAnalyzerManager::_mutex;
32 
33 SmartPtr<X3aAnalyzerManager>
instance()34 X3aAnalyzerManager::instance()
35 {
36     SmartLock lock(_mutex);
37     if (_instance.ptr())
38         return _instance;
39     _instance = new X3aAnalyzerManager;
40     return _instance;
41 }
42 
X3aAnalyzerManager()43 X3aAnalyzerManager::X3aAnalyzerManager ()
44 {
45     XCAM_LOG_DEBUG ("X3aAnalyzerManager construction");
46 }
~X3aAnalyzerManager()47 X3aAnalyzerManager::~X3aAnalyzerManager ()
48 {
49     XCAM_LOG_DEBUG ("X3aAnalyzerManager destruction");
50 }
51 
52 SmartPtr<X3aAnalyzer>
create_analyzer()53 X3aAnalyzerManager::create_analyzer()
54 {
55     SmartPtr<X3aAnalyzer> analyzer = find_analyzer();
56     if (!analyzer.ptr())
57         analyzer = new X3aAnalyzerSimple;
58     return analyzer;
59 }
60 
61 SmartPtr<X3aAnalyzer>
find_analyzer()62 X3aAnalyzerManager::find_analyzer ()
63 {
64     char lib_path[512];
65     const char *dir_path = NULL;
66     DIR  *dir_3a = NULL;
67     struct dirent *dirent_3a = NULL;
68     SmartPtr<X3aAnalyzer> analyzer;
69 
70     dir_path = getenv ("XCAM_3A_LIB");
71     if (!dir_path) {
72         dir_path = XCAM_DEFAULT_3A_LIB_DIR;
73         XCAM_LOG_INFO ("doesn't find environment=>XCAM_3A_LIB, change to default dir:%s", dir_path);
74     }
75     dir_3a = opendir (dir_path);
76     if (dir_3a) {
77         while ((dirent_3a = readdir (dir_3a)) != NULL) {
78             if (dirent_3a->d_type != DT_LNK &&
79                     dirent_3a->d_type != DT_REG)
80                 continue;
81             snprintf (lib_path, sizeof(lib_path), "%s/%s", dir_path, dirent_3a->d_name);
82             analyzer = load_analyzer_from_binary (lib_path);
83             if (analyzer.ptr())
84                 break;
85         }
86     }
87     if (dir_3a)
88         closedir (dir_3a);
89     return analyzer;
90 }
91 
92 SmartPtr<X3aAnalyzer>
load_analyzer_from_binary(const char * path)93 X3aAnalyzerManager::load_analyzer_from_binary (const char *path)
94 {
95     SmartPtr<X3aAnalyzer> analyzer;
96 
97     XCAM_ASSERT (path);
98 
99     _loader.release ();
100     _loader = new DynamicAnalyzerLoader (path);
101 
102     SmartPtr<AnalyzerLoader> loader = _loader.dynamic_cast_ptr<AnalyzerLoader> ();
103     analyzer = _loader->load_analyzer (loader);
104 
105     if (analyzer.ptr ())
106         return analyzer;
107 
108     XCAM_LOG_WARNING ("load 3A analyzer failed from: %s", path);
109     return NULL;
110 }
111 
112 };
113 
114