blob: c43e207c3e2eb8100320786d84976ccb3bff27c0 [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 Raya0ed4be2013-02-25 15:02:16 -080021#include <hardware/hardware.h>
22#include <hardware/camera3.h>
Alex Raybcaf7882013-02-28 16:04:35 -080023#include "Stream.h"
Alex Ray7ee0b7a2012-11-06 00:12:49 -080024
25namespace default_camera_hal {
26// Camera represents a physical camera on a device.
27// This is constructed when the HAL module is loaded, one per physical camera.
28// It is opened by the framework, and must be closed before it can be opened
29// again.
Alex Ray7ee0b7a2012-11-06 00:12:49 -080030class Camera {
31 public:
32 // id is used to distinguish cameras. 0 <= id < NUM_CAMERAS.
33 // module is a handle to the HAL module, used when the device is opened.
Alex Raya0ed4be2013-02-25 15:02:16 -080034 Camera(int id);
Alex Ray7ee0b7a2012-11-06 00:12:49 -080035 ~Camera();
Alex Raya48dd3f2012-12-19 12:21:38 -080036
37 // Common Camera Device Operations (see <hardware/camera_common.h>)
Alex Raya0ed4be2013-02-25 15:02:16 -080038 int open(const hw_module_t *module, hw_device_t **device);
Alex Raya48dd3f2012-12-19 12:21:38 -080039 int close();
Alex Raya0ed4be2013-02-25 15:02:16 -080040
41 // Camera v3 Device Operations (see <hardware/camera3.h>)
42 int initialize(const camera3_callback_ops_t *callback_ops);
43 int configureStreams(camera3_stream_configuration_t *stream_list);
44 int registerStreamBuffers(const camera3_stream_buffer_set_t *buf_set);
45 const camera_metadata_t *constructDefaultRequestSettings(int type);
46 int processCaptureRequest(camera3_capture_request_t *request);
47 void getMetadataVendorTagOps(vendor_tag_query_ops_t *ops);
48 void dump(int fd);
49
50 // Camera device handle returned to framework for use
51 camera3_device_t mDevice;
Alex Raya48dd3f2012-12-19 12:21:38 -080052
Alex Ray7ee0b7a2012-11-06 00:12:49 -080053 private:
Alex Raybcaf7882013-02-28 16:04:35 -080054 // Reuse a stream already created by this device
55 Stream *reuseStream(camera3_stream_t *astream);
56 // Destroy all streams in a stream array, and the array itself
57 void destroyStreams(Stream **array, int count);
58 // Verify a set of streams is valid in aggregate
59 bool isValidStreamSet(Stream **array, int count);
60 // Calculate usage and max_bufs of each stream
61 void setupStreams(Stream **array, int count);
62
Alex Ray7ee0b7a2012-11-06 00:12:49 -080063 // Identifier used by framework to distinguish cameras
Alex Ray1f8af672013-02-28 15:40:08 -080064 const int mId;
Alex Raya0ed4be2013-02-25 15:02:16 -080065 // Busy flag indicates camera is in use
Alex Ray7ee0b7a2012-11-06 00:12:49 -080066 bool mBusy;
Alex Raya0ed4be2013-02-25 15:02:16 -080067 // Camera device operations handle shared by all devices
68 const static camera3_device_ops_t sOps;
69 // Methods used to call back into the framework
70 const camera3_callback_ops_t *mCallbackOps;
Alex Ray7ee0b7a2012-11-06 00:12:49 -080071 // Lock protecting the Camera object for modifications
72 pthread_mutex_t mMutex;
Alex Raybcaf7882013-02-28 16:04:35 -080073 // Array of handles to streams currently in use by the device
74 Stream **mStreams;
75 // Number of streams in mStreams
76 int mNumStreams;
Alex Ray7ee0b7a2012-11-06 00:12:49 -080077};
78} // namespace default_camera_hal
79
80#endif // CAMERA_H_