blob: c34b3ea28addd635501b71d7569de04ac7282176 [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;
54};
55
56class Camera :
57 public CameraBase<Camera>,
58 public BnCameraClient
Mathias Agopian3cf61352010-02-09 17:46:37 -080059{
60public:
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080061 enum {
Igor Murashkinc073ba52013-02-26 14:32:34 -080062 USE_CALLING_UID = ICameraService::USE_CALLING_UID
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080063 };
64
Mathias Agopian3cf61352010-02-09 17:46:37 -080065 // construct a camera client from an existing remote
66 static sp<Camera> create(const sp<ICamera>& camera);
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080067 static sp<Camera> connect(int cameraId,
68 const String16& clientPackageName,
69 int clientUid);
70
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080071 virtual ~Camera();
Mathias Agopian3cf61352010-02-09 17:46:37 -080072
73 status_t reconnect();
Mathias Agopian3cf61352010-02-09 17:46:37 -080074 status_t lock();
75 status_t unlock();
76
Andy McFadden8ba01022012-12-18 09:46:54 -080077 // pass the buffered IGraphicBufferProducer to the camera service
78 status_t setPreviewTexture(const sp<IGraphicBufferProducer>& bufferProducer);
Jamie Gennisbfa33aa2010-12-20 11:51:31 -080079
Mathias Agopian3cf61352010-02-09 17:46:37 -080080 // start preview mode, must call setPreviewDisplay first
81 status_t startPreview();
82
83 // stop preview mode
84 void stopPreview();
85
86 // get preview state
87 bool previewEnabled();
88
89 // start recording mode, must call setPreviewDisplay first
90 status_t startRecording();
91
92 // stop recording mode
93 void stopRecording();
94
95 // get recording state
96 bool recordingEnabled();
97
98 // release a recording frame
99 void releaseRecordingFrame(const sp<IMemory>& mem);
100
101 // autoFocus - status returned from callback
102 status_t autoFocus();
103
104 // cancel auto focus
105 status_t cancelAutoFocus();
106
107 // take a picture - picture returned from callback
James Donge468ac52011-02-17 16:38:06 -0800108 status_t takePicture(int msgType);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800109
110 // set preview/capture parameters - key/value pairs
111 status_t setParameters(const String8& params);
112
113 // get preview/capture parameters - key/value pairs
114 String8 getParameters() const;
115
116 // send command to camera driver
117 status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
118
James Donge2ad6732010-10-18 20:42:51 -0700119 // tell camera hal to store meta data or real YUV in video buffers.
120 status_t storeMetaDataInBuffers(bool enabled);
121
Mathias Agopian3cf61352010-02-09 17:46:37 -0800122 void setListener(const sp<CameraListener>& listener);
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800123 void setRecordingProxyListener(const sp<ICameraRecordingProxyListener>& listener);
Eino-Ville Talvala3ee35502013-04-02 15:45:11 -0700124
125 // Configure preview callbacks to app. Only one of the older
126 // callbacks or the callback surface can be active at the same time;
127 // enabling one will disable the other if active. Flags can be
128 // disabled by calling it with CAMERA_FRAME_CALLBACK_FLAG_NOOP, and
129 // Target by calling it with a NULL interface.
Mathias Agopian3cf61352010-02-09 17:46:37 -0800130 void setPreviewCallbackFlags(int preview_callback_flag);
Eino-Ville Talvala3ee35502013-04-02 15:45:11 -0700131 status_t setPreviewCallbackTarget(
132 const sp<IGraphicBufferProducer>& callbackProducer);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800133
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800134 sp<ICameraRecordingProxy> getRecordingProxy();
135
Mathias Agopian3cf61352010-02-09 17:46:37 -0800136 // ICameraClient interface
137 virtual void notifyCallback(int32_t msgType, int32_t ext, int32_t ext2);
Wu-cheng Li57c86182011-07-30 05:00:37 +0800138 virtual void dataCallback(int32_t msgType, const sp<IMemory>& dataPtr,
139 camera_frame_metadata_t *metadata);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800140 virtual void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr);
141
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800142 class RecordingProxy : public BnCameraRecordingProxy
143 {
144 public:
145 RecordingProxy(const sp<Camera>& camera);
146
147 // ICameraRecordingProxy interface
148 virtual status_t startRecording(const sp<ICameraRecordingProxyListener>& listener);
149 virtual void stopRecording();
150 virtual void releaseRecordingFrame(const sp<IMemory>& mem);
151
152 private:
153 sp<Camera> mCamera;
154 };
155
Igor Murashkin1d880232013-02-20 16:50:13 -0800156protected:
Igor Murashkinc073ba52013-02-26 14:32:34 -0800157 Camera(int cameraId);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800158 Camera(const Camera&);
159 Camera& operator=(const Camera);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800160
Igor Murashkinc073ba52013-02-26 14:32:34 -0800161 sp<ICameraRecordingProxyListener> mRecordingProxyListener;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800162
Igor Murashkinc073ba52013-02-26 14:32:34 -0800163 friend class CameraBase;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800164};
165
166}; // namespace android
167
168#endif