blob: f19d29668892c7d074db8fac8f119e7ce8e98e73 [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>
Andy McFadden8ba01022012-12-18 09:46:54 -080021#include <gui/IGraphicBufferProducer.h>
Iliyan Malchev9e626522011-04-14 16:51:21 -070022#include <system/camera.h>
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080023#include <camera/ICameraClient.h>
24#include <camera/ICameraRecordingProxy.h>
25#include <camera/ICameraRecordingProxyListener.h>
Igor Murashkinc073ba52013-02-26 14:32:34 -080026#include <camera/ICameraService.h>
27#include <camera/ICamera.h>
28#include <camera/CameraBase.h>
Mathias Agopian3cf61352010-02-09 17:46:37 -080029
30namespace android {
31
Mathias Agopian3cf61352010-02-09 17:46:37 -080032class Surface;
Mathias Agopian3cf61352010-02-09 17:46:37 -080033class String8;
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080034class String16;
Mathias Agopian3cf61352010-02-09 17:46:37 -080035
36// ref-counted object for callbacks
37class CameraListener: virtual public RefBase
38{
39public:
40 virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2) = 0;
Wu-cheng Li57c86182011-07-30 05:00:37 +080041 virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr,
42 camera_frame_metadata_t *metadata) = 0;
Mathias Agopian3cf61352010-02-09 17:46:37 -080043 virtual void postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) = 0;
44};
45
Igor Murashkinc073ba52013-02-26 14:32:34 -080046class Camera;
47
48template <>
49struct CameraTraits<Camera>
50{
51 typedef CameraListener TCamListener;
52 typedef ICamera TCamUser;
53 typedef ICameraClient TCamCallbacks;
Ruben Brunk0f61d8f2013-08-08 13:07:18 -070054 typedef status_t (ICameraService::*TCamConnectService)(const sp<ICameraClient>&,
Chien-Yu Chen98a668f2015-12-18 14:10:33 -080055 int, const String16&, int, int,
Ruben Brunk0f61d8f2013-08-08 13:07:18 -070056 /*out*/
57 sp<ICamera>&);
58 static TCamConnectService fnConnectService;
Igor Murashkinc073ba52013-02-26 14:32:34 -080059};
60
Ruben Brunk0f61d8f2013-08-08 13:07:18 -070061
Igor Murashkinc073ba52013-02-26 14:32:34 -080062class Camera :
63 public CameraBase<Camera>,
64 public BnCameraClient
Mathias Agopian3cf61352010-02-09 17:46:37 -080065{
66public:
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080067 enum {
Igor Murashkinc073ba52013-02-26 14:32:34 -080068 USE_CALLING_UID = ICameraService::USE_CALLING_UID
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080069 };
Chien-Yu Chen98a668f2015-12-18 14:10:33 -080070 enum {
71 USE_CALLING_PID = ICameraService::USE_CALLING_PID
72 };
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080073
Mathias Agopian3cf61352010-02-09 17:46:37 -080074 // construct a camera client from an existing remote
75 static sp<Camera> create(const sp<ICamera>& camera);
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080076 static sp<Camera> connect(int cameraId,
Svetoslav Ganov280405a2015-05-12 02:19:27 +000077 const String16& clientPackageName,
Chien-Yu Chen98a668f2015-12-18 14:10:33 -080078 int clientUid, int clientPid);
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080079
Zhijun Heb10cdad2014-06-16 16:38:35 -070080 static status_t connectLegacy(int cameraId, int halVersion,
Svetoslav Ganov280405a2015-05-12 02:19:27 +000081 const String16& clientPackageName,
Zhijun Heb10cdad2014-06-16 16:38:35 -070082 int clientUid, sp<Camera>& camera);
83
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080084 virtual ~Camera();
Mathias Agopian3cf61352010-02-09 17:46:37 -080085
86 status_t reconnect();
Mathias Agopian3cf61352010-02-09 17:46:37 -080087 status_t lock();
88 status_t unlock();
89
Andy McFadden8ba01022012-12-18 09:46:54 -080090 // pass the buffered IGraphicBufferProducer to the camera service
Eino-Ville Talvala4b820b02013-08-21 14:39:05 -070091 status_t setPreviewTarget(const sp<IGraphicBufferProducer>& bufferProducer);
Jamie Gennisbfa33aa2010-12-20 11:51:31 -080092
Eino-Ville Talvala4b820b02013-08-21 14:39:05 -070093 // start preview mode, must call setPreviewTarget first
Mathias Agopian3cf61352010-02-09 17:46:37 -080094 status_t startPreview();
95
96 // stop preview mode
97 void stopPreview();
98
99 // get preview state
100 bool previewEnabled();
101
Eino-Ville Talvala4b820b02013-08-21 14:39:05 -0700102 // start recording mode, must call setPreviewTarget first
Mathias Agopian3cf61352010-02-09 17:46:37 -0800103 status_t startRecording();
104
105 // stop recording mode
106 void stopRecording();
107
108 // get recording state
109 bool recordingEnabled();
110
111 // release a recording frame
112 void releaseRecordingFrame(const sp<IMemory>& mem);
113
114 // autoFocus - status returned from callback
115 status_t autoFocus();
116
117 // cancel auto focus
118 status_t cancelAutoFocus();
119
120 // take a picture - picture returned from callback
James Donge468ac52011-02-17 16:38:06 -0800121 status_t takePicture(int msgType);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800122
123 // set preview/capture parameters - key/value pairs
124 status_t setParameters(const String8& params);
125
126 // get preview/capture parameters - key/value pairs
127 String8 getParameters() const;
128
129 // send command to camera driver
130 status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
131
Chien-Yu Chen8cca0752015-11-13 15:28:48 -0800132 // Tell camera how to pass video buffers. videoBufferMode is one of VIDEO_BUFFER_MODE_*.
133 // Returns OK if the specified video buffer mode is supported. If videoBufferMode is
134 // VIDEO_BUFFER_MODE_BUFFER_QUEUE, setVideoTarget() must be called before starting
135 // video recording.
136 status_t setVideoBufferMode(int32_t videoBufferMode);
137
138 // Set the video buffer producer for camera to use in VIDEO_BUFFER_MODE_BUFFER_QUEUE
139 // mode.
140 status_t setVideoTarget(const sp<IGraphicBufferProducer>& bufferProducer);
James Donge2ad6732010-10-18 20:42:51 -0700141
Mathias Agopian3cf61352010-02-09 17:46:37 -0800142 void setListener(const sp<CameraListener>& listener);
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800143 void setRecordingProxyListener(const sp<ICameraRecordingProxyListener>& listener);
Eino-Ville Talvala3ee35502013-04-02 15:45:11 -0700144
145 // Configure preview callbacks to app. Only one of the older
146 // callbacks or the callback surface can be active at the same time;
147 // enabling one will disable the other if active. Flags can be
148 // disabled by calling it with CAMERA_FRAME_CALLBACK_FLAG_NOOP, and
149 // Target by calling it with a NULL interface.
Mathias Agopian3cf61352010-02-09 17:46:37 -0800150 void setPreviewCallbackFlags(int preview_callback_flag);
Eino-Ville Talvala3ee35502013-04-02 15:45:11 -0700151 status_t setPreviewCallbackTarget(
152 const sp<IGraphicBufferProducer>& callbackProducer);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800153
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800154 sp<ICameraRecordingProxy> getRecordingProxy();
155
Mathias Agopian3cf61352010-02-09 17:46:37 -0800156 // ICameraClient interface
157 virtual void notifyCallback(int32_t msgType, int32_t ext, int32_t ext2);
Wu-cheng Li57c86182011-07-30 05:00:37 +0800158 virtual void dataCallback(int32_t msgType, const sp<IMemory>& dataPtr,
159 camera_frame_metadata_t *metadata);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800160 virtual void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr);
161
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800162 class RecordingProxy : public BnCameraRecordingProxy
163 {
164 public:
165 RecordingProxy(const sp<Camera>& camera);
166
167 // ICameraRecordingProxy interface
168 virtual status_t startRecording(const sp<ICameraRecordingProxyListener>& listener);
169 virtual void stopRecording();
170 virtual void releaseRecordingFrame(const sp<IMemory>& mem);
171
172 private:
173 sp<Camera> mCamera;
174 };
175
Igor Murashkin1d880232013-02-20 16:50:13 -0800176protected:
Igor Murashkinc073ba52013-02-26 14:32:34 -0800177 Camera(int cameraId);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800178 Camera(const Camera&);
179 Camera& operator=(const Camera);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800180
Igor Murashkinc073ba52013-02-26 14:32:34 -0800181 sp<ICameraRecordingProxyListener> mRecordingProxyListener;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800182
Igor Murashkinc073ba52013-02-26 14:32:34 -0800183 friend class CameraBase;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800184};
185
186}; // namespace android
187
188#endif