blob: 57dc22887b3e35f5a5665785ad29a8a6d22faf61 [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>
27#include <camera/ICameraRecordingProxyListener.h>
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080028#include <camera/android/hardware/ICamera.h>
29#include <camera/android/hardware/ICameraClient.h>
Igor Murashkinc073ba52013-02-26 14:32:34 -080030#include <camera/CameraBase.h>
Mathias Agopian3cf61352010-02-09 17:46:37 -080031
32namespace android {
33
Mathias Agopian3cf61352010-02-09 17:46:37 -080034class Surface;
Mathias Agopian3cf61352010-02-09 17:46:37 -080035class String8;
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080036class String16;
Mathias Agopian3cf61352010-02-09 17:46:37 -080037
38// ref-counted object for callbacks
39class CameraListener: virtual public RefBase
40{
41public:
42 virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2) = 0;
Wu-cheng Li57c86182011-07-30 05:00:37 +080043 virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr,
44 camera_frame_metadata_t *metadata) = 0;
Mathias Agopian3cf61352010-02-09 17:46:37 -080045 virtual void postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) = 0;
Chien-Yu Chen2d13b1d2016-04-28 12:11:20 -070046 virtual void postRecordingFrameHandleTimestamp(nsecs_t timestamp, native_handle_t* handle) = 0;
Mathias Agopian3cf61352010-02-09 17:46:37 -080047};
48
Igor Murashkinc073ba52013-02-26 14:32:34 -080049class Camera;
50
51template <>
52struct CameraTraits<Camera>
53{
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080054 typedef CameraListener TCamListener;
55 typedef ::android::hardware::ICamera TCamUser;
56 typedef ::android::hardware::ICameraClient TCamCallbacks;
57 typedef ::android::binder::Status(::android::hardware::ICameraService::*TCamConnectService)
58 (const sp<::android::hardware::ICameraClient>&,
59 int, const String16&, int, int,
60 /*out*/
61 sp<::android::hardware::ICamera>*);
Ruben Brunk0f61d8f2013-08-08 13:07:18 -070062 static TCamConnectService fnConnectService;
Igor Murashkinc073ba52013-02-26 14:32:34 -080063};
64
Ruben Brunk0f61d8f2013-08-08 13:07:18 -070065
Igor Murashkinc073ba52013-02-26 14:32:34 -080066class Camera :
67 public CameraBase<Camera>,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080068 public ::android::hardware::BnCameraClient
Mathias Agopian3cf61352010-02-09 17:46:37 -080069{
70public:
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080071 enum {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080072 USE_CALLING_UID = ::android::hardware::ICameraService::USE_CALLING_UID
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080073 };
Chien-Yu Chen98a668f2015-12-18 14:10:33 -080074 enum {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080075 USE_CALLING_PID = ::android::hardware::ICameraService::USE_CALLING_PID
Chien-Yu Chen98a668f2015-12-18 14:10:33 -080076 };
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080077
Mathias Agopian3cf61352010-02-09 17:46:37 -080078 // construct a camera client from an existing remote
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080079 static sp<Camera> create(const sp<::android::hardware::ICamera>& camera);
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080080 static sp<Camera> connect(int cameraId,
Svetoslav Ganov280405a2015-05-12 02:19:27 +000081 const String16& clientPackageName,
Chien-Yu Chen98a668f2015-12-18 14:10:33 -080082 int clientUid, int clientPid);
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080083
Zhijun Heb10cdad2014-06-16 16:38:35 -070084 static status_t connectLegacy(int cameraId, int halVersion,
Svetoslav Ganov280405a2015-05-12 02:19:27 +000085 const String16& clientPackageName,
Zhijun Heb10cdad2014-06-16 16:38:35 -070086 int clientUid, sp<Camera>& camera);
87
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080088 virtual ~Camera();
Mathias Agopian3cf61352010-02-09 17:46:37 -080089
90 status_t reconnect();
Mathias Agopian3cf61352010-02-09 17:46:37 -080091 status_t lock();
92 status_t unlock();
93
Andy McFadden8ba01022012-12-18 09:46:54 -080094 // pass the buffered IGraphicBufferProducer to the camera service
Eino-Ville Talvala4b820b02013-08-21 14:39:05 -070095 status_t setPreviewTarget(const sp<IGraphicBufferProducer>& bufferProducer);
Jamie Gennisbfa33aa2010-12-20 11:51:31 -080096
Eino-Ville Talvala4b820b02013-08-21 14:39:05 -070097 // start preview mode, must call setPreviewTarget first
Mathias Agopian3cf61352010-02-09 17:46:37 -080098 status_t startPreview();
99
100 // stop preview mode
101 void stopPreview();
102
103 // get preview state
104 bool previewEnabled();
105
Eino-Ville Talvala4b820b02013-08-21 14:39:05 -0700106 // start recording mode, must call setPreviewTarget first
Mathias Agopian3cf61352010-02-09 17:46:37 -0800107 status_t startRecording();
108
109 // stop recording mode
110 void stopRecording();
111
112 // get recording state
113 bool recordingEnabled();
114
115 // release a recording frame
116 void releaseRecordingFrame(const sp<IMemory>& mem);
117
Chien-Yu Chen2d13b1d2016-04-28 12:11:20 -0700118 // release a recording frame handle
119 void releaseRecordingFrameHandle(native_handle_t *handle);
120
Mathias Agopian3cf61352010-02-09 17:46:37 -0800121 // autoFocus - status returned from callback
122 status_t autoFocus();
123
124 // cancel auto focus
125 status_t cancelAutoFocus();
126
127 // take a picture - picture returned from callback
James Donge468ac52011-02-17 16:38:06 -0800128 status_t takePicture(int msgType);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800129
130 // set preview/capture parameters - key/value pairs
131 status_t setParameters(const String8& params);
132
133 // get preview/capture parameters - key/value pairs
134 String8 getParameters() const;
135
136 // send command to camera driver
137 status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
138
Chien-Yu Chen8cca0752015-11-13 15:28:48 -0800139 // Tell camera how to pass video buffers. videoBufferMode is one of VIDEO_BUFFER_MODE_*.
140 // Returns OK if the specified video buffer mode is supported. If videoBufferMode is
141 // VIDEO_BUFFER_MODE_BUFFER_QUEUE, setVideoTarget() must be called before starting
142 // video recording.
143 status_t setVideoBufferMode(int32_t videoBufferMode);
144
145 // Set the video buffer producer for camera to use in VIDEO_BUFFER_MODE_BUFFER_QUEUE
146 // mode.
147 status_t setVideoTarget(const sp<IGraphicBufferProducer>& bufferProducer);
James Donge2ad6732010-10-18 20:42:51 -0700148
Mathias Agopian3cf61352010-02-09 17:46:37 -0800149 void setListener(const sp<CameraListener>& listener);
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800150 void setRecordingProxyListener(const sp<ICameraRecordingProxyListener>& listener);
Eino-Ville Talvala3ee35502013-04-02 15:45:11 -0700151
152 // Configure preview callbacks to app. Only one of the older
153 // callbacks or the callback surface can be active at the same time;
154 // enabling one will disable the other if active. Flags can be
155 // disabled by calling it with CAMERA_FRAME_CALLBACK_FLAG_NOOP, and
156 // Target by calling it with a NULL interface.
Mathias Agopian3cf61352010-02-09 17:46:37 -0800157 void setPreviewCallbackFlags(int preview_callback_flag);
Eino-Ville Talvala3ee35502013-04-02 15:45:11 -0700158 status_t setPreviewCallbackTarget(
159 const sp<IGraphicBufferProducer>& callbackProducer);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800160
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800161 sp<ICameraRecordingProxy> getRecordingProxy();
162
Mathias Agopian3cf61352010-02-09 17:46:37 -0800163 // ICameraClient interface
164 virtual void notifyCallback(int32_t msgType, int32_t ext, int32_t ext2);
Wu-cheng Li57c86182011-07-30 05:00:37 +0800165 virtual void dataCallback(int32_t msgType, const sp<IMemory>& dataPtr,
166 camera_frame_metadata_t *metadata);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800167 virtual void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr);
Chien-Yu Chen2d13b1d2016-04-28 12:11:20 -0700168 virtual void recordingFrameHandleCallbackTimestamp(nsecs_t timestamp, native_handle_t* handle);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800169
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800170 class RecordingProxy : public BnCameraRecordingProxy
171 {
172 public:
Chih-Hung Hsiehd19d9942016-08-29 14:21:14 -0700173 explicit RecordingProxy(const sp<Camera>& camera);
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800174
175 // ICameraRecordingProxy interface
176 virtual status_t startRecording(const sp<ICameraRecordingProxyListener>& listener);
177 virtual void stopRecording();
178 virtual void releaseRecordingFrame(const sp<IMemory>& mem);
Chien-Yu Chen2d13b1d2016-04-28 12:11:20 -0700179 virtual void releaseRecordingFrameHandle(native_handle_t* handle);
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800180
181 private:
182 sp<Camera> mCamera;
183 };
184
Igor Murashkin1d880232013-02-20 16:50:13 -0800185protected:
Chih-Hung Hsiehd19d9942016-08-29 14:21:14 -0700186 explicit Camera(int cameraId);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800187 Camera(const Camera&);
188 Camera& operator=(const Camera);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800189
Igor Murashkinc073ba52013-02-26 14:32:34 -0800190 sp<ICameraRecordingProxyListener> mRecordingProxyListener;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800191
Igor Murashkinc073ba52013-02-26 14:32:34 -0800192 friend class CameraBase;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800193};
194
195}; // namespace android
196
197#endif