summaryrefslogtreecommitdiff
path: root/v3/EmulatedBaseCamera.h (plain)
blob: 53cf329eab534f04e9938d6bf3d064f500891e43
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
24namespace 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
36typedef enum camera_status {
37 CAMERA_INIT = 0,
38 CAMERA_READY_REMOVE,
39}camera_status_t;
40
41class 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 void setCameraStatus(camera_status_t status) = 0;
61 virtual camera_status_t getCameraStatus() = 0;
62 /****************************************************************************
63 * Camera API implementation
64 ***************************************************************************/
65
66 public:
67 /* Creates connection to the emulated camera device.
68 * This method is called in response to hw_module_methods_t::open callback.
69 * NOTE: When this method is called the object is locked.
70 * Note that failures in this method are reported as negative EXXX statuses.
71 */
72 virtual status_t connectCamera(hw_device_t** device) = 0;
73
74
75 /* Plug the connection for the emulated camera. Until it's plugged in
76 * calls to connectCamera should fail with -ENODEV.
77 */
78 virtual status_t plugCamera();
79
80 /* Unplug the connection from underneath the emulated camera.
81 * This is similar to closing the camera, except that
82 * all function calls into the camera device will return
83 * -EPIPE errors until the camera is reopened.
84 */
85 virtual status_t unplugCamera();
86
87 virtual camera_device_status_t getHotplugStatus();
88
89 /* Closes connection to the emulated camera.
90 * This method is called in response to camera_device::close callback.
91 * NOTE: When this method is called the object is locked.
92 * Note that failures in this method are reported as negative EXXX statuses.
93 */
94 virtual status_t closeCamera() = 0;
95
96 /* Gets camera information.
97 * This method is called in response to camera_module_t::get_camera_info
98 * callback.
99 * NOTE: When this method is called the object is locked.
100 * Note that failures in this method are reported as negative EXXX statuses.
101 */
102 virtual status_t getCameraInfo(struct camera_info* info) = 0;
103
104 /****************************************************************************
105 * Data members
106 ***************************************************************************/
107
108 protected:
109 /* Fixed camera information for camera2 devices. Must be valid to access if
110 * mCameraDeviceVersion is >= HARDWARE_DEVICE_API_VERSION(2,0) */
111 camera_metadata_t *mCameraInfo;
112
113 /* Zero-based ID assigned to this camera. */
114 int mCameraID;
115
116 private:
117
118 /* Version of the camera device HAL implemented by this camera */
119 int mCameraDeviceVersion;
120 camera_status_t mstatus;
121};
122
123} /* namespace android */
124
125#endif /* HW_EMULATOR_CAMERA_EMULATED_BASE_CAMERA_H */
126