Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 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_common.h" |
Wind Yuan | 8810a79 | 2015-01-22 15:20:23 +0800 | [diff] [blame^] | 25 | #include "xcam_utils.h" |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 26 | #include "smartptr.h" |
| 27 | #include "v4l2_device.h" |
| 28 | #include "v4l2_buffer_proxy.h" |
| 29 | #include "x3a_analyzer.h" |
| 30 | #include "image_processor.h" |
| 31 | #include "x3a_statistics_queue.h" |
| 32 | #include "poll_thread.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 | |
| 57 | class MessageThread; |
| 58 | class X3aImageProcessCenter; |
| 59 | |
| 60 | class DeviceManager |
| 61 | : public PollCallback |
| 62 | , public AnalyzerCallback |
| 63 | , public ImageProcessCallback |
| 64 | { |
| 65 | friend class MessageThread; |
| 66 | |
| 67 | public: |
| 68 | DeviceManager(); |
| 69 | virtual ~DeviceManager(); |
| 70 | |
| 71 | bool set_capture_device (SmartPtr<V4l2Device> &device); |
| 72 | bool set_event_device (SmartPtr<V4l2SubDevice> &device); |
| 73 | bool set_isp_controller (SmartPtr<IspController> &controller); |
| 74 | bool set_analyzer (SmartPtr<X3aAnalyzer> &analyzer); |
| 75 | bool add_image_processor (SmartPtr<ImageProcessor> &processor); |
| 76 | |
| 77 | bool is_running () const { |
| 78 | return _is_running; |
| 79 | } |
| 80 | bool has_3a () const { |
| 81 | return _has_3a; |
| 82 | } |
| 83 | |
| 84 | XCamReturn start (); |
| 85 | XCamReturn stop (); |
| 86 | |
| 87 | protected: |
| 88 | virtual void handle_message (SmartPtr<XCamMessage> &msg) = 0; |
| 89 | virtual void handle_buffer (SmartPtr<VideoBuffer> &buf) = 0; |
| 90 | |
| 91 | protected: |
| 92 | //virtual functions derived from PollCallback |
| 93 | virtual XCamReturn poll_buffer_ready (SmartPtr<V4l2BufferProxy> &buf); |
| 94 | virtual XCamReturn poll_buffer_failed (int64_t timestamp, const char *msg); |
| 95 | virtual XCamReturn poll_3a_stats_ready (SmartPtr<X3aIspStatistics> &stats); |
| 96 | virtual XCamReturn poll_dvs_stats_ready (); |
| 97 | |
| 98 | //virtual functions derived from AnalyzerCallback |
| 99 | virtual void x3a_calculation_done (X3aAnalyzer *analyzer, X3aResultList &results); |
| 100 | virtual void x3a_calculation_failed (X3aAnalyzer *analyzer, int64_t timestamp, const char *msg); |
| 101 | |
| 102 | //virtual functions derived from ImageProcessCallback |
| 103 | virtual void process_buffer_done (ImageProcessor *processor, SmartPtr<VideoBuffer> &buf); |
| 104 | virtual void process_buffer_failed (ImageProcessor *processor, SmartPtr<VideoBuffer> &buf); |
| 105 | virtual void process_image_result_done (ImageProcessor *processor, SmartPtr<X3aResult> &result); |
| 106 | |
| 107 | private: |
| 108 | void post_message (XCamMessageType type, int64_t timestamp, const char *msg); |
| 109 | XCamReturn message_loop (); |
| 110 | |
| 111 | XCAM_DEAD_COPY (DeviceManager); |
| 112 | |
| 113 | protected: |
| 114 | SmartPtr<V4l2Device> _device; |
| 115 | SmartPtr<V4l2SubDevice> _subdevice; |
| 116 | SmartPtr<PollThread> _poll_thread; |
| 117 | SmartPtr<IspController> _isp_controller; |
| 118 | |
| 119 | /* 3A calculation and image processing*/ |
| 120 | bool _has_3a; |
| 121 | SmartPtr<X3aAnalyzer> _3a_analyzer; |
| 122 | SmartPtr<X3aImageProcessCenter> _3a_process_center; |
| 123 | |
| 124 | /* msg queue */ |
| 125 | SafeList<XCamMessage> _msg_queue; |
| 126 | SmartPtr<MessageThread> _msg_thread; |
| 127 | |
| 128 | bool _is_running; |
| 129 | }; |
| 130 | |
| 131 | }; |
| 132 | |
| 133 | #endif //XCAM_DEVICE_MANAGER_H |