blob: bcd7762a4938d057c530bb79bd97710b2b028270 [file] [log] [blame]
Wind Yuan75564b12015-01-15 06:51:15 -05001/*
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
Wind Yuan8810a792015-01-22 15:20:23 +080024#include "xcam_utils.h"
Wind Yuan75564b12015-01-15 06:51:15 -050025#include "smartptr.h"
26#include "v4l2_device.h"
27#include "v4l2_buffer_proxy.h"
28#include "x3a_analyzer.h"
29#include "image_processor.h"
30#include "x3a_statistics_queue.h"
31#include "poll_thread.h"
32
33namespace XCam {
34
35enum XCamMessageType {
36 XCAM_MESSAGE_BUF_OK = 0,
37 XCAM_MESSAGE_BUF_ERROR,
38 XCAM_MESSAGE_STATS_OK,
39 XCAM_MESSAGE_STATS_ERROR,
40 XCAM_MESSAGE_3A_RESULTS_OK,
41 XCAM_MESSAGE_3A_RESULTS_ERROR,
42};
43
44struct XCamMessage {
45 int64_t timestamp;
46 XCamMessageType msg_id;
47 char *msg;
48
49 XCamMessage (
50 XCamMessageType type,
51 int64_t timestamp = InvalidTimestamp,
52 const char *message = NULL);
53 ~XCamMessage ();
54};
55
56class MessageThread;
57class X3aImageProcessCenter;
58
59class DeviceManager
60 : public PollCallback
61 , public AnalyzerCallback
62 , public ImageProcessCallback
63{
64 friend class MessageThread;
65
66public:
67 DeviceManager();
68 virtual ~DeviceManager();
69
Wind Yuan5820c392015-02-11 16:07:36 +080070 bool set_capture_device (SmartPtr<V4l2Device> device);
71 bool set_event_device (SmartPtr<V4l2SubDevice> device);
72 bool set_isp_controller (SmartPtr<IspController> controller);
73 bool set_analyzer (SmartPtr<X3aAnalyzer> analyzer);
74 bool add_image_processor (SmartPtr<ImageProcessor> processor);
Wind Yuan75564b12015-01-15 06:51:15 -050075
76 bool is_running () const {
77 return _is_running;
78 }
79 bool has_3a () const {
80 return _has_3a;
81 }
82
83 XCamReturn start ();
84 XCamReturn stop ();
85
86protected:
87 virtual void handle_message (SmartPtr<XCamMessage> &msg) = 0;
88 virtual void handle_buffer (SmartPtr<VideoBuffer> &buf) = 0;
89
90protected:
91 //virtual functions derived from PollCallback
92 virtual XCamReturn poll_buffer_ready (SmartPtr<V4l2BufferProxy> &buf);
93 virtual XCamReturn poll_buffer_failed (int64_t timestamp, const char *msg);
94 virtual XCamReturn poll_3a_stats_ready (SmartPtr<X3aIspStatistics> &stats);
95 virtual XCamReturn poll_dvs_stats_ready ();
96
97 //virtual functions derived from AnalyzerCallback
98 virtual void x3a_calculation_done (X3aAnalyzer *analyzer, X3aResultList &results);
99 virtual void x3a_calculation_failed (X3aAnalyzer *analyzer, int64_t timestamp, const char *msg);
100
101 //virtual functions derived from ImageProcessCallback
102 virtual void process_buffer_done (ImageProcessor *processor, SmartPtr<VideoBuffer> &buf);
103 virtual void process_buffer_failed (ImageProcessor *processor, SmartPtr<VideoBuffer> &buf);
104 virtual void process_image_result_done (ImageProcessor *processor, SmartPtr<X3aResult> &result);
105
106private:
107 void post_message (XCamMessageType type, int64_t timestamp, const char *msg);
108 XCamReturn message_loop ();
109
110 XCAM_DEAD_COPY (DeviceManager);
111
112protected:
113 SmartPtr<V4l2Device> _device;
114 SmartPtr<V4l2SubDevice> _subdevice;
115 SmartPtr<PollThread> _poll_thread;
116 SmartPtr<IspController> _isp_controller;
117
118 /* 3A calculation and image processing*/
119 bool _has_3a;
120 SmartPtr<X3aAnalyzer> _3a_analyzer;
121 SmartPtr<X3aImageProcessCenter> _3a_process_center;
122
123 /* msg queue */
124 SafeList<XCamMessage> _msg_queue;
125 SmartPtr<MessageThread> _msg_thread;
126
127 bool _is_running;
128};
129
130};
131
132#endif //XCAM_DEVICE_MANAGER_H