• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * smart_analysis_handler.h - smart analysis handler
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: Zong Wei <wei.zong@intel.com>
19  *             Wind Yuan <feng.yuan@intel.com>
20  */
21 #ifndef XCAM_SMART_ANALYSIS_HANDLER_H
22 #define XCAM_SMART_ANALYSIS_HANDLER_H
23 
24 #include <xcam_std.h>
25 #include <base/xcam_smart_description.h>
26 #include <map>
27 #include <x3a_result_factory.h>
28 
29 namespace XCam {
30 
31 class VideoBuffer;
32 class SmartAnalysisHandler;
33 class SmartAnalyzerLoader;
34 class SmartAnalyzer;
35 
36 typedef std::list<SmartPtr<SmartAnalysisHandler>> SmartHandlerList;
37 
38 class SmartAnalysisHandler
39 {
40     typedef std::map<XCamSmartAnalysisContext*, SmartPtr<SmartAnalysisHandler>> SmartHandlerMap;
41 
42 public:
43     SmartAnalysisHandler (XCamSmartAnalysisDescription *desc, SmartPtr<SmartAnalyzerLoader> &loader, const char *name = "SmartHandler");
44     ~SmartAnalysisHandler ();
set_analyzer(SmartAnalyzer * analyzer)45     void set_analyzer (SmartAnalyzer *analyzer) {
46         _analyzer = analyzer;
47     }
48 
49     XCamReturn create_context (SmartPtr<SmartAnalysisHandler> &self);
50     void destroy_context ();
is_valid()51     bool is_valid () const {
52         return (_context != NULL);
53     }
54 
55     XCamReturn update_params (XCamSmartAnalysisParam &params);
56     XCamReturn analyze (const SmartPtr<VideoBuffer> &buffer, X3aResultList &results);
get_name()57     const char * get_name () const {
58         return _name;
59     }
get_priority()60     uint32_t get_priority () const {
61         if (_desc)
62             return _desc->priority;
63         return 0;
64     }
65 
66 protected:
67     XCamReturn post_smart_results (const XCamVideoBuffer *buffer, XCam3aResultHead *results[], uint32_t res_count);
68     static XCamReturn post_aync_results (
69         XCamSmartAnalysisContext *context,
70         const XCamVideoBuffer *buffer,
71         XCam3aResultHead *results[], uint32_t res_count);
72 
73 private:
74     XCamReturn convert_results (XCam3aResultHead *from[], uint32_t from_count, X3aResultList &to);
75     XCAM_DEAD_COPY (SmartAnalysisHandler);
76 
77 //
78 private:
79     static SmartHandlerMap          _handler_map;
80     static Mutex                    _handler_map_lock;
81 
82 private:
83     XCamSmartAnalysisDescription   *_desc;
84     SmartPtr<SmartAnalyzerLoader>   _loader;
85     SmartAnalyzer                  *_analyzer;
86     char                           *_name;
87     XCamSmartAnalysisContext       *_context;
88     bool                            _async_mode;
89 };
90 
91 }
92 
93 #endif //XCAM_SMART_ANALYSIS_HANDLER_H
94