blob: ca6640639584670d568d15a3717c7cb177f645bd [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>
Alex Raya48dd3f2012-12-19 12:21:38 -080021#include <hardware/camera_common.h>
Alex Ray7ee0b7a2012-11-06 00:12:49 -080022#include <hardware/camera2.h>
23
24namespace default_camera_hal {
25// Camera represents a physical camera on a device.
26// This is constructed when the HAL module is loaded, one per physical camera.
27// It is opened by the framework, and must be closed before it can be opened
28// again.
29// Also, the framework can query for camera metadata with getCameraInfo.
30// For the first query, the metadata must first be allocated and initialized,
31// but once done it is used for all future calls.
32// It is protected by @mMutex, and functions that modify the Camera object hold
33// this lock when performing modifications. Currently these functions are:
34// @open, @close, and @init.
35class Camera {
36 public:
37 // id is used to distinguish cameras. 0 <= id < NUM_CAMERAS.
38 // module is a handle to the HAL module, used when the device is opened.
39 Camera(int id, const hw_module_t* module);
40 ~Camera();
Alex Raya48dd3f2012-12-19 12:21:38 -080041
42 // Common Camera Device Operations (see <hardware/camera_common.h>)
Alex Ray7ee0b7a2012-11-06 00:12:49 -080043 camera2_device_t mDevice;
Alex Raya48dd3f2012-12-19 12:21:38 -080044 int open();
45 int close();
46 int getCameraInfo(struct camera_info* info);
47
Alex Ray7ee0b7a2012-11-06 00:12:49 -080048 private:
49 // One-time initialization of camera metadata.
50 void init();
51 // Identifier used by framework to distinguish cameras
52 int mId;
53 // True indicates camera is already open.
54 bool mBusy;
55 // Camera characteristics. NULL means it has not been allocated yet.
56 camera_metadata_t* mMetadata;
57 // Lock protecting the Camera object for modifications
58 pthread_mutex_t mMutex;
59};
60} // namespace default_camera_hal
61
62#endif // CAMERA_H_