blob: 0bf894804f559eb77d6fdbc72447340a577f252f
1 | /* |
2 | * Copyright (C) 2012 The Android Open Source Project |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | |
17 | #ifndef HW_EMULATOR_CAMERA_EMULATED_BASE_CAMERA_H |
18 | #define HW_EMULATOR_CAMERA_EMULATED_BASE_CAMERA_H |
19 | |
20 | #include <hardware/camera_common.h> |
21 | #include <utils/Errors.h> |
22 | #include "DebugUtils.h" |
23 | |
24 | namespace android { |
25 | |
26 | /* |
27 | * Contains declaration of a class EmulatedBaseCamera that encapsulates |
28 | * functionality common to all emulated camera device versions ("fake", |
29 | * "webcam", "video file", etc.). Instances of this class (for each emulated |
30 | * camera) are created during the construction of the EmulatedCameraFactory |
31 | * instance. This class serves as an entry point for all camera API calls that |
32 | * are common across all versions of the camera_device_t/camera_module_t |
33 | * structures. |
34 | */ |
35 | |
36 | typedef enum camera_status { |
37 | CAMERA_INIT = 0, |
38 | CAMERA_READY_REMOVE, |
39 | }camera_status_t; |
40 | |
41 | class EmulatedBaseCamera { |
42 | public: |
43 | EmulatedBaseCamera(int cameraId, |
44 | uint32_t cameraVersion, |
45 | struct hw_device_t* device, |
46 | struct hw_module_t* module); |
47 | |
48 | virtual ~EmulatedBaseCamera(); |
49 | |
50 | /**************************************************************************** |
51 | * Public API |
52 | ***************************************************************************/ |
53 | |
54 | public: |
55 | /* Initializes EmulatedCamera instance. |
56 | * Return: |
57 | * NO_ERROR on success, or an appropriate error status on failure. |
58 | */ |
59 | virtual status_t Initialize() = 0; |
60 | virtual bool getCameraStatus() = 0; |
61 | /**************************************************************************** |
62 | * Camera API implementation |
63 | ***************************************************************************/ |
64 | |
65 | public: |
66 | /* Creates connection to the emulated camera device. |
67 | * This method is called in response to hw_module_methods_t::open callback. |
68 | * NOTE: When this method is called the object is locked. |
69 | * Note that failures in this method are reported as negative EXXX statuses. |
70 | */ |
71 | virtual status_t connectCamera(hw_device_t** device) = 0; |
72 | |
73 | |
74 | /* Plug the connection for the emulated camera. Until it's plugged in |
75 | * calls to connectCamera should fail with -ENODEV. |
76 | */ |
77 | virtual status_t plugCamera(); |
78 | |
79 | /* Unplug the connection from underneath the emulated camera. |
80 | * This is similar to closing the camera, except that |
81 | * all function calls into the camera device will return |
82 | * -EPIPE errors until the camera is reopened. |
83 | */ |
84 | virtual status_t unplugCamera(); |
85 | |
86 | virtual camera_device_status_t getHotplugStatus(); |
87 | |
88 | /* Closes connection to the emulated camera. |
89 | * This method is called in response to camera_device::close callback. |
90 | * NOTE: When this method is called the object is locked. |
91 | * Note that failures in this method are reported as negative EXXX statuses. |
92 | */ |
93 | virtual status_t closeCamera() = 0; |
94 | |
95 | /* Gets camera information. |
96 | * This method is called in response to camera_module_t::get_camera_info |
97 | * callback. |
98 | * NOTE: When this method is called the object is locked. |
99 | * Note that failures in this method are reported as negative EXXX statuses. |
100 | */ |
101 | virtual status_t getCameraInfo(struct camera_info* info) = 0; |
102 | |
103 | /**************************************************************************** |
104 | * Data members |
105 | ***************************************************************************/ |
106 | |
107 | protected: |
108 | /* Fixed camera information for camera2 devices. Must be valid to access if |
109 | * mCameraDeviceVersion is >= HARDWARE_DEVICE_API_VERSION(2,0) */ |
110 | camera_metadata_t *mCameraInfo; |
111 | |
112 | /* Zero-based ID assigned to this camera. */ |
113 | int mCameraID; |
114 | |
115 | private: |
116 | |
117 | /* Version of the camera device HAL implemented by this camera */ |
118 | int mCameraDeviceVersion; |
119 | camera_status_t mstatus; |
120 | }; |
121 | |
122 | } /* namespace android */ |
123 | |
124 | #endif /* HW_EMULATOR_CAMERA_EMULATED_BASE_CAMERA_H */ |
125 |