blob: 72cbde29b0c05a1077a68fd4b24c7c6439b7ada8 [file] [log] [blame]
Alex Ray7ee0b7a2012-11-06 00:12:49 -08001/*
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 CAMERA_H_
18#define CAMERA_H_
19
20#include <pthread.h>
21#include <hardware/camera2.h>
22
23namespace default_camera_hal {
24// Camera represents a physical camera on a device.
25// This is constructed when the HAL module is loaded, one per physical camera.
26// It is opened by the framework, and must be closed before it can be opened
27// again.
28// Also, the framework can query for camera metadata with getCameraInfo.
29// For the first query, the metadata must first be allocated and initialized,
30// but once done it is used for all future calls.
31// It is protected by @mMutex, and functions that modify the Camera object hold
32// this lock when performing modifications. Currently these functions are:
33// @open, @close, and @init.
34class Camera {
35 public:
36 // id is used to distinguish cameras. 0 <= id < NUM_CAMERAS.
37 // module is a handle to the HAL module, used when the device is opened.
38 Camera(int id, const hw_module_t* module);
39 ~Camera();
40 // Open this camera, preparing it for use. Returns nonzero on failure.
41 int open();
42 // Close this camera. Returns nonzero on failure.
43 int close();
44 // Query for camera metadata, filling info struct. Returns nonzero if
45 // allocation or initialization failed.
46 int getCameraInfo(struct camera_info* info);
47 // Handle to this device passed to framework in response to open().
48 camera2_device_t mDevice;
49 private:
50 // One-time initialization of camera metadata.
51 void init();
52 // Identifier used by framework to distinguish cameras
53 int mId;
54 // True indicates camera is already open.
55 bool mBusy;
56 // Camera characteristics. NULL means it has not been allocated yet.
57 camera_metadata_t* mMetadata;
58 // Lock protecting the Camera object for modifications
59 pthread_mutex_t mMutex;
60};
61} // namespace default_camera_hal
62
63#endif // CAMERA_H_