• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * device_manager.h - device 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 #ifndef XCAM_DEVICE_MANAGER_H
22 #define XCAM_DEVICE_MANAGER_H
23 
24 #include <xcam_std.h>
25 #include <v4l2_device.h>
26 #include <v4l2_buffer_proxy.h>
27 #include <x3a_analyzer.h>
28 #include <smart_analyzer.h>
29 #include <x3a_image_process_center.h>
30 #include <image_processor.h>
31 #include <poll_thread.h>
32 #include <stats_callback_interface.h>
33 
34 namespace XCam {
35 
36 enum XCamMessageType {
37     XCAM_MESSAGE_BUF_OK = 0,
38     XCAM_MESSAGE_BUF_ERROR,
39     XCAM_MESSAGE_STATS_OK,
40     XCAM_MESSAGE_STATS_ERROR,
41     XCAM_MESSAGE_3A_RESULTS_OK,
42     XCAM_MESSAGE_3A_RESULTS_ERROR,
43 };
44 
45 struct XCamMessage {
46     int64_t          timestamp;
47     XCamMessageType  msg_id;
48     char            *msg;
49 
50     XCamMessage (
51         XCamMessageType type,
52         int64_t timestamp = InvalidTimestamp,
53         const char *message = NULL);
54     ~XCamMessage ();
55 
56     XCAM_DEAD_COPY (XCamMessage);
57 };
58 
59 class MessageThread;
60 
61 class DeviceManager
62     : public PollCallback
63     , public StatsCallback
64     , public AnalyzerCallback
65     , public ImageProcessCallback
66 {
67     friend class MessageThread;
68 
69 public:
70     DeviceManager();
71     virtual ~DeviceManager();
72 
73     bool set_capture_device (SmartPtr<V4l2Device> device);
74     bool set_event_device (SmartPtr<V4l2SubDevice> device);
75     bool set_3a_analyzer (SmartPtr<X3aAnalyzer> analyzer);
76     bool set_smart_analyzer (SmartPtr<SmartAnalyzer> analyzer);
77     bool add_image_processor (SmartPtr<ImageProcessor> processor);
78     bool set_poll_thread (SmartPtr<PollThread> thread);
79 
get_capture_device()80     SmartPtr<V4l2Device>& get_capture_device () {
81         return _device;
82     }
get_event_device()83     SmartPtr<V4l2SubDevice>& get_event_device () {
84         return _subdevice;
85     }
get_analyzer()86     SmartPtr<X3aAnalyzer>& get_analyzer () {
87         return _3a_analyzer;
88     }
89 
is_running()90     bool is_running () const {
91         return _is_running;
92     }
has_3a()93     bool has_3a () const {
94         return _has_3a;
95     }
96 
97     XCamReturn start ();
98     XCamReturn stop ();
99 
100 protected:
101     virtual void handle_message (const SmartPtr<XCamMessage> &msg) = 0;
102     virtual void handle_buffer (const SmartPtr<VideoBuffer> &buf) = 0;
103 
104 protected:
105     //virtual functions derived from PollCallback
106     virtual XCamReturn poll_buffer_ready (SmartPtr<VideoBuffer> &buf);
107     virtual XCamReturn poll_buffer_failed (int64_t timestamp, const char *msg);
108     virtual XCamReturn x3a_stats_ready (const SmartPtr<X3aStats> &stats);
109     virtual XCamReturn dvs_stats_ready ();
110     virtual XCamReturn scaled_image_ready (const SmartPtr<VideoBuffer> &buffer);
111 
112     //virtual functions derived from AnalyzerCallback
113     virtual void x3a_calculation_done (XAnalyzer *analyzer, X3aResultList &results);
114     virtual void x3a_calculation_failed (XAnalyzer *analyzer, int64_t timestamp, const char *msg);
115 
116     //virtual functions derived from ImageProcessCallback
117     virtual void process_buffer_done (ImageProcessor *processor, const SmartPtr<VideoBuffer> &buf);
118     virtual void process_buffer_failed (ImageProcessor *processor, const SmartPtr<VideoBuffer> &buf);
119     virtual void process_image_result_done (ImageProcessor *processor, const SmartPtr<X3aResult> &result);
120 
121 private:
122     void post_message (XCamMessageType type, int64_t timestamp, const char *msg);
123     XCamReturn message_loop ();
124 
125     XCAM_DEAD_COPY (DeviceManager);
126 
127 protected:
128     SmartPtr<V4l2Device>             _device;
129     SmartPtr<V4l2SubDevice>          _subdevice;
130     SmartPtr<PollThread>             _poll_thread;
131 
132     /* 3A calculation and image processing*/
133     bool                             _has_3a;
134     SmartPtr<X3aAnalyzer>            _3a_analyzer;
135     SmartPtr<X3aImageProcessCenter>  _3a_process_center;
136 
137     /* msg queue */
138     SafeList<XCamMessage>            _msg_queue;
139     SmartPtr<MessageThread>          _msg_thread;
140 
141     bool                             _is_running;
142 
143     /* smart analysis */
144     SmartPtr<SmartAnalyzer>         _smart_analyzer;
145 };
146 
147 };
148 
149 #endif //XCAM_DEVICE_MANAGER_H
150