blob: 6655f82b583a6800e29d9583769ceb9a61f6315d [file] [log] [blame]
Mathias Agopian3cf61352010-02-09 17:46:37 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
Mathias Agopian3cf61352010-02-09 17:46:37 -08003 *
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 ANDROID_HARDWARE_CAMERA_H
18#define ANDROID_HARDWARE_CAMERA_H
19
20#include <utils/Timers.h>
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080021
22#include <android/hardware/ICameraService.h>
23
Andy McFadden8ba01022012-12-18 09:46:54 -080024#include <gui/IGraphicBufferProducer.h>
Iliyan Malchev9e626522011-04-14 16:51:21 -070025#include <system/camera.h>
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080026#include <camera/ICameraRecordingProxy.h>
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080027#include <camera/android/hardware/ICamera.h>
28#include <camera/android/hardware/ICameraClient.h>
Igor Murashkinc073ba52013-02-26 14:32:34 -080029#include <camera/CameraBase.h>
Mathias Agopian3cf61352010-02-09 17:46:37 -080030
31namespace android {
32
Mathias Agopian3cf61352010-02-09 17:46:37 -080033class Surface;
Mathias Agopian3cf61352010-02-09 17:46:37 -080034class String8;
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080035class String16;
Mathias Agopian3cf61352010-02-09 17:46:37 -080036
37// ref-counted object for callbacks
38class CameraListener: virtual public RefBase
39{
40public:
41 virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2) = 0;
Wu-cheng Li57c86182011-07-30 05:00:37 +080042 virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr,
43 camera_frame_metadata_t *metadata) = 0;
Mathias Agopian3cf61352010-02-09 17:46:37 -080044 virtual void postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) = 0;
Chien-Yu Chen2d13b1d2016-04-28 12:11:20 -070045 virtual void postRecordingFrameHandleTimestamp(nsecs_t timestamp, native_handle_t* handle) = 0;
Yin-Chia Yehb5df5472017-03-20 19:32:19 -070046 virtual void postRecordingFrameHandleTimestampBatch(
47 const std::vector<nsecs_t>& timestamps,
48 const std::vector<native_handle_t*>& handles) = 0;
Mathias Agopian3cf61352010-02-09 17:46:37 -080049};
50
Igor Murashkinc073ba52013-02-26 14:32:34 -080051class Camera;
52
53template <>
54struct CameraTraits<Camera>
55{
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080056 typedef CameraListener TCamListener;
57 typedef ::android::hardware::ICamera TCamUser;
58 typedef ::android::hardware::ICameraClient TCamCallbacks;
Austin Borger0fb3ad92023-06-01 16:51:35 -070059 typedef ::android::binder::Status (::android::hardware::ICameraService::*TCamConnectService)
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080060 (const sp<::android::hardware::ICameraClient>&,
Austin Borger0fb3ad92023-06-01 16:51:35 -070061 int, const std::string&, int, int, int, bool, bool,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080062 /*out*/
63 sp<::android::hardware::ICamera>*);
Ruben Brunk0f61d8f2013-08-08 13:07:18 -070064 static TCamConnectService fnConnectService;
Igor Murashkinc073ba52013-02-26 14:32:34 -080065};
66
Ruben Brunk0f61d8f2013-08-08 13:07:18 -070067
Igor Murashkinc073ba52013-02-26 14:32:34 -080068class Camera :
69 public CameraBase<Camera>,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080070 public ::android::hardware::BnCameraClient
Mathias Agopian3cf61352010-02-09 17:46:37 -080071{
72public:
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080073 enum {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080074 USE_CALLING_UID = ::android::hardware::ICameraService::USE_CALLING_UID
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080075 };
Chien-Yu Chen98a668f2015-12-18 14:10:33 -080076 enum {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080077 USE_CALLING_PID = ::android::hardware::ICameraService::USE_CALLING_PID
Chien-Yu Chen98a668f2015-12-18 14:10:33 -080078 };
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080079
Mathias Agopian3cf61352010-02-09 17:46:37 -080080 // construct a camera client from an existing remote
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080081 static sp<Camera> create(const sp<::android::hardware::ICamera>& camera);
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080082 static sp<Camera> connect(int cameraId,
Austin Borger0fb3ad92023-06-01 16:51:35 -070083 const std::string& clientPackageName,
Austin Borger3560b7e2022-10-27 12:20:29 -070084 int clientUid, int clientPid, int targetSdkVersion,
Chengfei Tao4094e1f2023-01-31 18:52:49 +000085 bool overrideToPortrait, bool forceSlowJpegMode);
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080086
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080087 virtual ~Camera();
Mathias Agopian3cf61352010-02-09 17:46:37 -080088
89 status_t reconnect();
Mathias Agopian3cf61352010-02-09 17:46:37 -080090 status_t lock();
91 status_t unlock();
92
Andy McFadden8ba01022012-12-18 09:46:54 -080093 // pass the buffered IGraphicBufferProducer to the camera service
Eino-Ville Talvala4b820b02013-08-21 14:39:05 -070094 status_t setPreviewTarget(const sp<IGraphicBufferProducer>& bufferProducer);
Jamie Gennisbfa33aa2010-12-20 11:51:31 -080095
Eino-Ville Talvala4b820b02013-08-21 14:39:05 -070096 // start preview mode, must call setPreviewTarget first
Mathias Agopian3cf61352010-02-09 17:46:37 -080097 status_t startPreview();
98
99 // stop preview mode
100 void stopPreview();
101
102 // get preview state
103 bool previewEnabled();
104
Eino-Ville Talvala4b820b02013-08-21 14:39:05 -0700105 // start recording mode, must call setPreviewTarget first
Mathias Agopian3cf61352010-02-09 17:46:37 -0800106 status_t startRecording();
107
108 // stop recording mode
109 void stopRecording();
110
111 // get recording state
112 bool recordingEnabled();
113
114 // release a recording frame
115 void releaseRecordingFrame(const sp<IMemory>& mem);
116
Chien-Yu Chen2d13b1d2016-04-28 12:11:20 -0700117 // release a recording frame handle
118 void releaseRecordingFrameHandle(native_handle_t *handle);
119
Yin-Chia Yehb5df5472017-03-20 19:32:19 -0700120 // release a batch of recording frame handles
121 void releaseRecordingFrameHandleBatch(
122 const std::vector<native_handle_t*> handles);
123
Mathias Agopian3cf61352010-02-09 17:46:37 -0800124 // autoFocus - status returned from callback
125 status_t autoFocus();
126
127 // cancel auto focus
128 status_t cancelAutoFocus();
129
130 // take a picture - picture returned from callback
James Donge468ac52011-02-17 16:38:06 -0800131 status_t takePicture(int msgType);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800132
133 // set preview/capture parameters - key/value pairs
134 status_t setParameters(const String8& params);
135
136 // get preview/capture parameters - key/value pairs
137 String8 getParameters() const;
138
139 // send command to camera driver
140 status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
141
Chien-Yu Chen8cca0752015-11-13 15:28:48 -0800142 // Tell camera how to pass video buffers. videoBufferMode is one of VIDEO_BUFFER_MODE_*.
143 // Returns OK if the specified video buffer mode is supported. If videoBufferMode is
144 // VIDEO_BUFFER_MODE_BUFFER_QUEUE, setVideoTarget() must be called before starting
145 // video recording.
146 status_t setVideoBufferMode(int32_t videoBufferMode);
147
148 // Set the video buffer producer for camera to use in VIDEO_BUFFER_MODE_BUFFER_QUEUE
149 // mode.
150 status_t setVideoTarget(const sp<IGraphicBufferProducer>& bufferProducer);
James Donge2ad6732010-10-18 20:42:51 -0700151
Mathias Agopian3cf61352010-02-09 17:46:37 -0800152 void setListener(const sp<CameraListener>& listener);
Eino-Ville Talvala3ee35502013-04-02 15:45:11 -0700153
154 // Configure preview callbacks to app. Only one of the older
155 // callbacks or the callback surface can be active at the same time;
156 // enabling one will disable the other if active. Flags can be
157 // disabled by calling it with CAMERA_FRAME_CALLBACK_FLAG_NOOP, and
158 // Target by calling it with a NULL interface.
Mathias Agopian3cf61352010-02-09 17:46:37 -0800159 void setPreviewCallbackFlags(int preview_callback_flag);
Eino-Ville Talvala3ee35502013-04-02 15:45:11 -0700160 status_t setPreviewCallbackTarget(
161 const sp<IGraphicBufferProducer>& callbackProducer);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800162
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800163 sp<ICameraRecordingProxy> getRecordingProxy();
164
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -0700165 status_t setAudioRestriction(int32_t mode);
166 int32_t getGlobalAudioRestriction();
Yin-Chia Yehdba03232019-08-19 15:54:28 -0700167
Mathias Agopian3cf61352010-02-09 17:46:37 -0800168 // ICameraClient interface
169 virtual void notifyCallback(int32_t msgType, int32_t ext, int32_t ext2);
Wu-cheng Li57c86182011-07-30 05:00:37 +0800170 virtual void dataCallback(int32_t msgType, const sp<IMemory>& dataPtr,
171 camera_frame_metadata_t *metadata);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800172 virtual void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr);
Chien-Yu Chen2d13b1d2016-04-28 12:11:20 -0700173 virtual void recordingFrameHandleCallbackTimestamp(nsecs_t timestamp, native_handle_t* handle);
Yin-Chia Yehb5df5472017-03-20 19:32:19 -0700174 virtual void recordingFrameHandleCallbackTimestampBatch(
175 const std::vector<nsecs_t>& timestamps,
176 const std::vector<native_handle_t*>& handles);
177
Mathias Agopian3cf61352010-02-09 17:46:37 -0800178
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800179 class RecordingProxy : public BnCameraRecordingProxy
180 {
181 public:
Chih-Hung Hsiehd19d9942016-08-29 14:21:14 -0700182 explicit RecordingProxy(const sp<Camera>& camera);
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800183
184 // ICameraRecordingProxy interface
Eino-Ville Talvalab8ed8ef2020-06-22 16:59:48 -0700185 virtual status_t startRecording();
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800186 virtual void stopRecording();
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800187
188 private:
189 sp<Camera> mCamera;
190 };
191
Igor Murashkin1d880232013-02-20 16:50:13 -0800192protected:
Chih-Hung Hsiehd19d9942016-08-29 14:21:14 -0700193 explicit Camera(int cameraId);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800194 Camera(const Camera&);
195 Camera& operator=(const Camera);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800196
Igor Murashkinc073ba52013-02-26 14:32:34 -0800197 friend class CameraBase;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800198};
199
200}; // namespace android
201
202#endif