blob: 539b2156d62e9337d1008147f4588094ef56c35f
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 | class EmulatedBaseCamera { |
37 | public: |
38 | EmulatedBaseCamera(int cameraId, |
39 | uint32_t cameraVersion, |
40 | struct hw_device_t* device, |
41 | struct hw_module_t* module); |
42 | |
43 | virtual ~EmulatedBaseCamera(); |
44 | |
45 | /**************************************************************************** |
46 | * Public API |
47 | ***************************************************************************/ |
48 | |
49 | public: |
50 | /* Initializes EmulatedCamera instance. |
51 | * Return: |
52 | * NO_ERROR on success, or an appropriate error status on failure. |
53 | */ |
54 | virtual status_t Initialize() = 0; |
55 | |
56 | /**************************************************************************** |
57 | * Camera API implementation |
58 | ***************************************************************************/ |
59 | |
60 | public: |
61 | /* Creates connection to the emulated camera device. |
62 | * This method is called in response to hw_module_methods_t::open callback. |
63 | * NOTE: When this method is called the object is locked. |
64 | * Note that failures in this method are reported as negative EXXX statuses. |
65 | */ |
66 | virtual status_t connectCamera(hw_device_t** device) = 0; |
67 | |
68 | |
69 | /* Plug the connection for the emulated camera. Until it's plugged in |
70 | * calls to connectCamera should fail with -ENODEV. |
71 | */ |
72 | virtual status_t plugCamera(); |
73 | |
74 | /* Unplug the connection from underneath the emulated camera. |
75 | * This is similar to closing the camera, except that |
76 | * all function calls into the camera device will return |
77 | * -EPIPE errors until the camera is reopened. |
78 | */ |
79 | virtual status_t unplugCamera(); |
80 | |
81 | virtual camera_device_status_t getHotplugStatus(); |
82 | |
83 | /* Closes connection to the emulated camera. |
84 | * This method is called in response to camera_device::close callback. |
85 | * NOTE: When this method is called the object is locked. |
86 | * Note that failures in this method are reported as negative EXXX statuses. |
87 | */ |
88 | virtual status_t closeCamera() = 0; |
89 | |
90 | /* Gets camera information. |
91 | * This method is called in response to camera_module_t::get_camera_info |
92 | * callback. |
93 | * NOTE: When this method is called the object is locked. |
94 | * Note that failures in this method are reported as negative EXXX statuses. |
95 | */ |
96 | virtual status_t getCameraInfo(struct camera_info* info) = 0; |
97 | |
98 | /**************************************************************************** |
99 | * Data members |
100 | ***************************************************************************/ |
101 | |
102 | protected: |
103 | /* Fixed camera information for camera2 devices. Must be valid to access if |
104 | * mCameraDeviceVersion is >= HARDWARE_DEVICE_API_VERSION(2,0) */ |
105 | camera_metadata_t *mCameraInfo; |
106 | |
107 | /* Zero-based ID assigned to this camera. */ |
108 | int mCameraID; |
109 | |
110 | private: |
111 | |
112 | /* Version of the camera device HAL implemented by this camera */ |
113 | int mCameraDeviceVersion; |
114 | }; |
115 | |
116 | } /* namespace android */ |
117 | |
118 | #endif /* HW_EMULATOR_CAMERA_EMULATED_BASE_CAMERA_H */ |
119 |