blob: e519b04cdd533216a2c2496733865ea39e9de763 [file] [log] [blame]
Iliyan Malchev8951a972011-04-14 16:55:59 -07001/*
2 * Copyright (C) 2008 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 ANDROID_HARDWARE_CAMERA_HARDWARE_INTERFACE_H
18#define ANDROID_HARDWARE_CAMERA_HARDWARE_INTERFACE_H
19
Yin-Chia Yeh4717c472017-02-13 10:56:40 -080020#include <unordered_map>
Iliyan Malchev8951a972011-04-14 16:55:59 -070021#include <binder/IMemory.h>
22#include <binder/MemoryBase.h>
23#include <binder/MemoryHeapBase.h>
24#include <utils/RefBase.h>
Iliyan Malchev8951a972011-04-14 16:55:59 -070025#include <ui/GraphicBuffer.h>
26#include <camera/Camera.h>
27#include <camera/CameraParameters.h>
28#include <system/window.h>
29#include <hardware/camera.h>
30
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080031#include <common/CameraProviderManager.h>
32
Iliyan Malchev8951a972011-04-14 16:55:59 -070033namespace android {
34
35typedef void (*notify_callback)(int32_t msgType,
36 int32_t ext1,
37 int32_t ext2,
38 void* user);
39
40typedef void (*data_callback)(int32_t msgType,
41 const sp<IMemory> &dataPtr,
Wu-cheng Liff09ef82011-07-28 05:30:59 +080042 camera_frame_metadata_t *metadata,
Iliyan Malchev8951a972011-04-14 16:55:59 -070043 void* user);
44
45typedef void (*data_callback_timestamp)(nsecs_t timestamp,
46 int32_t msgType,
47 const sp<IMemory> &dataPtr,
48 void *user);
49
Yin-Chia Yehb5df5472017-03-20 19:32:19 -070050struct HandleTimestampMessage {
51 nsecs_t timestamp;
52 const sp<IMemory> dataPtr;
53};
54
55typedef void (*data_callback_timestamp_batch)(
56 int32_t msgType,
57 const std::vector<HandleTimestampMessage>&, void* user);
58
Iliyan Malchev8951a972011-04-14 16:55:59 -070059/**
60 * CameraHardwareInterface.h defines the interface to the
61 * camera hardware abstraction layer, used for setting and getting
Eino-Ville Talvalab99c5b82013-02-06 17:20:07 -080062 * parameters, live previewing, and taking pictures. It is used for
63 * HAL devices with version CAMERA_DEVICE_API_VERSION_1_0 only.
Iliyan Malchev8951a972011-04-14 16:55:59 -070064 *
65 * It is a referenced counted interface with RefBase as its base class.
66 * CameraService calls openCameraHardware() to retrieve a strong pointer to the
67 * instance of this interface and may be called multiple times. The
68 * following steps describe a typical sequence:
69 *
70 * -# After CameraService calls openCameraHardware(), getParameters() and
71 * setParameters() are used to initialize the camera instance.
Eino-Ville Talvalab99c5b82013-02-06 17:20:07 -080072 * -# startPreview() is called.
Iliyan Malchev8951a972011-04-14 16:55:59 -070073 *
Eino-Ville Talvalab99c5b82013-02-06 17:20:07 -080074 * Prior to taking a picture, CameraService often calls autofocus(). When auto
Iliyan Malchev8951a972011-04-14 16:55:59 -070075 * focusing has completed, the camera instance sends a CAMERA_MSG_FOCUS notification,
76 * which informs the application whether focusing was successful. The camera instance
77 * only sends this message once and it is up to the application to call autoFocus()
78 * again if refocusing is desired.
79 *
80 * CameraService calls takePicture() to request the camera instance take a
Eino-Ville Talvalab99c5b82013-02-06 17:20:07 -080081 * picture. At this point, if a shutter, postview, raw, and/or compressed
82 * callback is desired, the corresponding message must be enabled. Any memory
83 * provided in a data callback must be copied if it's needed after returning.
Iliyan Malchev8951a972011-04-14 16:55:59 -070084 */
85
Yin-Chia Yeh4717c472017-02-13 10:56:40 -080086class CameraHardwareInterface :
87 public virtual RefBase,
88 public virtual hardware::camera::device::V1_0::ICameraDeviceCallback,
89 public virtual hardware::camera::device::V1_0::ICameraDevicePreviewCallback {
90
Iliyan Malchev8951a972011-04-14 16:55:59 -070091public:
Chih-Hung Hsieh8b0b9712016-08-09 14:25:53 -070092 explicit CameraHardwareInterface(const char *name):
Yin-Chia Yeh4717c472017-02-13 10:56:40 -080093 mHidlDevice(nullptr),
Eino-Ville Talvalaf7351172016-02-09 12:13:57 -080094 mName(name),
95 mPreviewScalingMode(NOT_SET),
96 mPreviewTransform(NOT_SET),
97 mPreviewWidth(NOT_SET),
98 mPreviewHeight(NOT_SET),
99 mPreviewFormat(NOT_SET),
100 mPreviewUsage(0),
101 mPreviewSwapInterval(NOT_SET),
102 mPreviewCrop{NOT_SET,NOT_SET,NOT_SET,NOT_SET}
Iliyan Malchev8951a972011-04-14 16:55:59 -0700103 {
Iliyan Malchev8951a972011-04-14 16:55:59 -0700104 }
105
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800106 ~CameraHardwareInterface();
Tyler Luu5861a9a2011-10-06 00:00:03 -0500107
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800108 status_t initialize(sp<CameraProviderManager> manager);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800109
Iliyan Malchev8951a972011-04-14 16:55:59 -0700110 /** Set the ANativeWindow to which preview frames are sent */
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800111 status_t setPreviewWindow(const sp<ANativeWindow>& buf);
Iliyan Malchev8951a972011-04-14 16:55:59 -0700112
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800113 status_t setPreviewScalingMode(int scalingMode);
Eino-Ville Talvalaf7351172016-02-09 12:13:57 -0800114
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800115 status_t setPreviewTransform(int transform);
Eino-Ville Talvalaf7351172016-02-09 12:13:57 -0800116
Iliyan Malchev8951a972011-04-14 16:55:59 -0700117 /** Set the notification and data callbacks */
118 void setCallbacks(notify_callback notify_cb,
119 data_callback data_cb,
120 data_callback_timestamp data_cb_timestamp,
Yin-Chia Yehb5df5472017-03-20 19:32:19 -0700121 data_callback_timestamp_batch data_cb_timestamp_batch,
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800122 void* user);
Iliyan Malchev8951a972011-04-14 16:55:59 -0700123
124 /**
125 * The following three functions all take a msgtype,
126 * which is a bitmask of the messages defined in
127 * include/ui/Camera.h
128 */
129
130 /**
131 * Enable a message, or set of messages.
132 */
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800133 void enableMsgType(int32_t msgType);
Iliyan Malchev8951a972011-04-14 16:55:59 -0700134
135 /**
136 * Disable a message, or a set of messages.
137 *
138 * Once received a call to disableMsgType(CAMERA_MSG_VIDEO_FRAME), camera hal
139 * should not rely on its client to call releaseRecordingFrame() to release
140 * video recording frames sent out by the cameral hal before and after the
141 * disableMsgType(CAMERA_MSG_VIDEO_FRAME) call. Camera hal clients must not
142 * modify/access any video recording frame after calling
143 * disableMsgType(CAMERA_MSG_VIDEO_FRAME).
144 */
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800145 void disableMsgType(int32_t msgType);
Iliyan Malchev8951a972011-04-14 16:55:59 -0700146
147 /**
148 * Query whether a message, or a set of messages, is enabled.
149 * Note that this is operates as an AND, if any of the messages
150 * queried are off, this will return false.
151 */
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800152 int msgTypeEnabled(int32_t msgType);
Iliyan Malchev8951a972011-04-14 16:55:59 -0700153
154 /**
155 * Start preview mode.
156 */
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800157 status_t startPreview();
Iliyan Malchev8951a972011-04-14 16:55:59 -0700158
159 /**
160 * Stop a previously started preview.
161 */
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800162 void stopPreview();
Iliyan Malchev8951a972011-04-14 16:55:59 -0700163
164 /**
165 * Returns true if preview is enabled.
166 */
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800167 int previewEnabled();
Iliyan Malchev8951a972011-04-14 16:55:59 -0700168
169 /**
170 * Request the camera hal to store meta data or real YUV data in
171 * the video buffers send out via CAMERA_MSG_VIDEO_FRRAME for a
172 * recording session. If it is not called, the default camera
173 * hal behavior is to store real YUV data in the video buffers.
174 *
175 * This method should be called before startRecording() in order
176 * to be effective.
177 *
178 * If meta data is stored in the video buffers, it is up to the
179 * receiver of the video buffers to interpret the contents and
180 * to find the actual frame data with the help of the meta data
181 * in the buffer. How this is done is outside of the scope of
182 * this method.
183 *
184 * Some camera hal may not support storing meta data in the video
185 * buffers, but all camera hal should support storing real YUV data
186 * in the video buffers. If the camera hal does not support storing
187 * the meta data in the video buffers when it is requested to do
188 * do, INVALID_OPERATION must be returned. It is very useful for
189 * the camera hal to pass meta data rather than the actual frame
190 * data directly to the video encoder, since the amount of the
191 * uncompressed frame data can be very large if video size is large.
192 *
193 * @param enable if true to instruct the camera hal to store
194 * meta data in the video buffers; false to instruct
195 * the camera hal to store real YUV data in the video
196 * buffers.
197 *
198 * @return OK on success.
199 */
200
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800201 status_t storeMetaDataInBuffers(int enable);
Iliyan Malchev8951a972011-04-14 16:55:59 -0700202
203 /**
204 * Start record mode. When a record image is available a CAMERA_MSG_VIDEO_FRAME
205 * message is sent with the corresponding frame. Every record frame must be released
206 * by a cameral hal client via releaseRecordingFrame() before the client calls
207 * disableMsgType(CAMERA_MSG_VIDEO_FRAME). After the client calls
208 * disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is camera hal's responsibility
209 * to manage the life-cycle of the video recording frames, and the client must
210 * not modify/access any video recording frames.
211 */
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800212 status_t startRecording();
Iliyan Malchev8951a972011-04-14 16:55:59 -0700213
214 /**
215 * Stop a previously started recording.
216 */
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800217 void stopRecording();
Iliyan Malchev8951a972011-04-14 16:55:59 -0700218
219 /**
220 * Returns true if recording is enabled.
221 */
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800222 int recordingEnabled();
Iliyan Malchev8951a972011-04-14 16:55:59 -0700223
224 /**
225 * Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME.
226 *
227 * It is camera hal client's responsibility to release video recording
228 * frames sent out by the camera hal before the camera hal receives
229 * a call to disableMsgType(CAMERA_MSG_VIDEO_FRAME). After it receives
230 * the call to disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is camera hal's
231 * responsibility of managing the life-cycle of the video recording
232 * frames.
233 */
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800234 void releaseRecordingFrame(const sp<IMemory>& mem);
Iliyan Malchev8951a972011-04-14 16:55:59 -0700235
236 /**
Yin-Chia Yehb5df5472017-03-20 19:32:19 -0700237 * Release a batch of recording frames previously returned by
238 * CAMERA_MSG_VIDEO_FRAME. This method only supports frames that are
239 * stored as VideoNativeHandleMetadata.
240 *
241 * It is camera hal client's responsibility to release video recording
242 * frames sent out by the camera hal before the camera hal receives
243 * a call to disableMsgType(CAMERA_MSG_VIDEO_FRAME). After it receives
244 * the call to disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is camera hal's
245 * responsibility of managing the life-cycle of the video recording
246 * frames.
247 */
248 void releaseRecordingFrameBatch(const std::vector<sp<IMemory>>& frames);
249
250 /**
Iliyan Malchev8951a972011-04-14 16:55:59 -0700251 * Start auto focus, the notification callback routine is called
252 * with CAMERA_MSG_FOCUS once when focusing is complete. autoFocus()
253 * will be called again if another auto focus is needed.
254 */
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800255 status_t autoFocus();
Iliyan Malchev8951a972011-04-14 16:55:59 -0700256
257 /**
258 * Cancels auto-focus function. If the auto-focus is still in progress,
259 * this function will cancel it. Whether the auto-focus is in progress
260 * or not, this function will return the focus position to the default.
261 * If the camera does not support auto-focus, this is a no-op.
262 */
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800263 status_t cancelAutoFocus();
Iliyan Malchev8951a972011-04-14 16:55:59 -0700264
265 /**
266 * Take a picture.
267 */
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800268 status_t takePicture();
Iliyan Malchev8951a972011-04-14 16:55:59 -0700269
270 /**
271 * Cancel a picture that was started with takePicture. Calling this
272 * method when no picture is being taken is a no-op.
273 */
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800274 status_t cancelPicture();
Iliyan Malchev8951a972011-04-14 16:55:59 -0700275
276 /**
277 * Set the camera parameters. This returns BAD_VALUE if any parameter is
278 * invalid or not supported. */
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800279 status_t setParameters(const CameraParameters &params);
Iliyan Malchev8951a972011-04-14 16:55:59 -0700280
281 /** Return the camera parameters. */
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800282 CameraParameters getParameters() const;
Iliyan Malchev8951a972011-04-14 16:55:59 -0700283
284 /**
285 * Send command to camera driver.
286 */
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800287 status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
Iliyan Malchev8951a972011-04-14 16:55:59 -0700288
289 /**
290 * Release the hardware resources owned by this object. Note that this is
291 * *not* done in the destructor.
292 */
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800293 void release();
Iliyan Malchev8951a972011-04-14 16:55:59 -0700294
295 /**
296 * Dump state of the camera hardware
297 */
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800298 status_t dump(int fd, const Vector<String16>& /*args*/) const;
Iliyan Malchev8951a972011-04-14 16:55:59 -0700299
300private:
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800301 sp<hardware::camera::device::V1_0::ICameraDevice> mHidlDevice;
Iliyan Malchev8951a972011-04-14 16:55:59 -0700302 String8 mName;
303
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800304 static void sNotifyCb(int32_t msg_type, int32_t ext1,
305 int32_t ext2, void *user);
Iliyan Malchev8951a972011-04-14 16:55:59 -0700306
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800307 static void sDataCb(int32_t msg_type,
Iliyan Malchev26adde82011-06-06 17:21:32 -0700308 const camera_memory_t *data, unsigned int index,
Wu-cheng Liff09ef82011-07-28 05:30:59 +0800309 camera_frame_metadata_t *metadata,
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800310 void *user);
Iliyan Malchev8951a972011-04-14 16:55:59 -0700311
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800312 static void sDataCbTimestamp(nsecs_t timestamp, int32_t msg_type,
Iliyan Malchev26adde82011-06-06 17:21:32 -0700313 const camera_memory_t *data, unsigned index,
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800314 void *user);
315
Iliyan Malchev8951a972011-04-14 16:55:59 -0700316 // This is a utility class that combines a MemoryHeapBase and a MemoryBase
317 // in one. Since we tend to use them in a one-to-one relationship, this is
318 // handy.
Iliyan Malchev26adde82011-06-06 17:21:32 -0700319 class CameraHeapMemory : public RefBase {
Iliyan Malchev8951a972011-04-14 16:55:59 -0700320 public:
Iliyan Malchev26adde82011-06-06 17:21:32 -0700321 CameraHeapMemory(int fd, size_t buf_size, uint_t num_buffers = 1) :
322 mBufSize(buf_size),
323 mNumBufs(num_buffers)
Iliyan Malchev8951a972011-04-14 16:55:59 -0700324 {
Iliyan Malchev26adde82011-06-06 17:21:32 -0700325 mHeap = new MemoryHeapBase(fd, buf_size * num_buffers);
326 commonInitialization();
Iliyan Malchev8951a972011-04-14 16:55:59 -0700327 }
328
Chih-Hung Hsieh8b0b9712016-08-09 14:25:53 -0700329 explicit CameraHeapMemory(size_t buf_size, uint_t num_buffers = 1) :
330 mBufSize(buf_size),
331 mNumBufs(num_buffers)
Iliyan Malchev26adde82011-06-06 17:21:32 -0700332 {
333 mHeap = new MemoryHeapBase(buf_size * num_buffers);
334 commonInitialization();
335 }
336
337 void commonInitialization()
338 {
339 handle.data = mHeap->base();
340 handle.size = mBufSize * mNumBufs;
341 handle.handle = this;
342
343 mBuffers = new sp<MemoryBase>[mNumBufs];
344 for (uint_t i = 0; i < mNumBufs; i++)
345 mBuffers[i] = new MemoryBase(mHeap,
346 i * mBufSize,
347 mBufSize);
348
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800349 handle.release = sPutMemory;
Iliyan Malchev26adde82011-06-06 17:21:32 -0700350 }
351
352 virtual ~CameraHeapMemory()
353 {
354 delete [] mBuffers;
355 }
356
357 size_t mBufSize;
358 uint_t mNumBufs;
359 sp<MemoryHeapBase> mHeap;
360 sp<MemoryBase> *mBuffers;
361
Iliyan Malchev8951a972011-04-14 16:55:59 -0700362 camera_memory_t handle;
363 };
364
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800365 static camera_memory_t* sGetMemory(int fd, size_t buf_size, uint_t num_bufs,
366 void *user __attribute__((unused)));
Iliyan Malchev8951a972011-04-14 16:55:59 -0700367
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800368 static void sPutMemory(camera_memory_t *data);
Iliyan Malchev26adde82011-06-06 17:21:32 -0700369
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800370 std::pair<bool, uint64_t> getBufferId(ANativeWindowBuffer* anb);
371 void cleanupCirculatingBuffers();
372
373 /**
374 * Implementation of android::hardware::camera::device::V1_0::ICameraDeviceCallback
375 */
376 hardware::Return<void> notifyCallback(
377 hardware::camera::device::V1_0::NotifyCallbackMsg msgType,
378 int32_t ext1, int32_t ext2) override;
379 hardware::Return<uint32_t> registerMemory(
380 const hardware::hidl_handle& descriptor,
381 uint32_t bufferSize, uint32_t bufferCount) override;
382 hardware::Return<void> unregisterMemory(uint32_t memId) override;
383 hardware::Return<void> dataCallback(
384 hardware::camera::device::V1_0::DataCallbackMsg msgType,
385 uint32_t data, uint32_t bufferIndex,
386 const hardware::camera::device::V1_0::CameraFrameMetadata& metadata) override;
387 hardware::Return<void> dataCallbackTimestamp(
388 hardware::camera::device::V1_0::DataCallbackMsg msgType,
389 uint32_t data, uint32_t bufferIndex, int64_t timestamp) override;
390 hardware::Return<void> handleCallbackTimestamp(
391 hardware::camera::device::V1_0::DataCallbackMsg msgType,
392 const hardware::hidl_handle& frameData, uint32_t data,
393 uint32_t bufferIndex, int64_t timestamp) override;
Yin-Chia Yehb5df5472017-03-20 19:32:19 -0700394 hardware::Return<void> handleCallbackTimestampBatch(
395 hardware::camera::device::V1_0::DataCallbackMsg msgType,
396 const hardware::hidl_vec<
397 hardware::camera::device::V1_0::HandleTimestampMessage>&) override;
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800398
399 /**
400 * Implementation of android::hardware::camera::device::V1_0::ICameraDevicePreviewCallback
401 */
402 hardware::Return<void> dequeueBuffer(dequeueBuffer_cb _hidl_cb) override;
403 hardware::Return<hardware::camera::common::V1_0::Status>
404 enqueueBuffer(uint64_t bufferId) override;
405 hardware::Return<hardware::camera::common::V1_0::Status>
406 cancelBuffer(uint64_t bufferId) override;
407 hardware::Return<hardware::camera::common::V1_0::Status>
408 setBufferCount(uint32_t count) override;
409 hardware::Return<hardware::camera::common::V1_0::Status>
410 setBuffersGeometry(uint32_t w, uint32_t h,
411 hardware::graphics::common::V1_0::PixelFormat format) override;
412 hardware::Return<hardware::camera::common::V1_0::Status>
413 setCrop(int32_t left, int32_t top, int32_t right, int32_t bottom) override;
414 hardware::Return<hardware::camera::common::V1_0::Status>
Chia-I Wu67a0c0e2017-04-06 13:37:01 -0700415 setUsage(hardware::graphics::common::V1_0::BufferUsage usage) override;
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800416 hardware::Return<hardware::camera::common::V1_0::Status>
417 setSwapInterval(int32_t interval) override;
418 hardware::Return<void> getMinUndequeuedBufferCount(
419 getMinUndequeuedBufferCount_cb _hidl_cb) override;
420 hardware::Return<hardware::camera::common::V1_0::Status>
421 setTimestamp(int64_t timestamp) override;
Iliyan Malchev8951a972011-04-14 16:55:59 -0700422
423 sp<ANativeWindow> mPreviewWindow;
424
Yin-Chia Yehb5df5472017-03-20 19:32:19 -0700425 notify_callback mNotifyCb;
426 data_callback mDataCb;
427 data_callback_timestamp mDataCbTimestamp;
428 data_callback_timestamp_batch mDataCbTimestampBatch;
Iliyan Malchev8951a972011-04-14 16:55:59 -0700429 void *mCbUser;
Eino-Ville Talvalaf7351172016-02-09 12:13:57 -0800430
431 // Cached values for preview stream parameters
432 static const int NOT_SET = -1;
433 int mPreviewScalingMode;
434 int mPreviewTransform;
435 int mPreviewWidth;
436 int mPreviewHeight;
437 int mPreviewFormat;
Emilian Peev050f5dc2017-05-18 14:43:56 +0100438 uint64_t mPreviewUsage;
Eino-Ville Talvalaf7351172016-02-09 12:13:57 -0800439 int mPreviewSwapInterval;
440 android_native_rect_t mPreviewCrop;
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800441
442 struct BufferHasher {
443 size_t operator()(const buffer_handle_t& buf) const {
444 if (buf == nullptr)
445 return 0;
446
447 size_t result = 1;
448 result = 31 * result + buf->numFds;
449 result = 31 * result + buf->numInts;
450 int length = buf->numFds + buf->numInts;
451 for (int i = 0; i < length; i++) {
452 result = 31 * result + buf->data[i];
453 }
454 return result;
455 }
456 };
457
458 struct BufferComparator {
459 bool operator()(const buffer_handle_t& buf1, const buffer_handle_t& buf2) const {
460 if (buf1->numFds == buf2->numFds && buf1->numInts == buf2->numInts) {
461 int length = buf1->numFds + buf1->numInts;
462 for (int i = 0; i < length; i++) {
463 if (buf1->data[i] != buf2->data[i]) {
464 return false;
465 }
466 }
467 return true;
468 }
469 return false;
470 }
471 };
472
473 std::mutex mBufferIdMapLock; // protecting mBufferIdMap and mNextBufferId
474 typedef std::unordered_map<const buffer_handle_t, uint64_t,
475 BufferHasher, BufferComparator> BufferIdMap;
476 // stream ID -> per stream buffer ID map
477 BufferIdMap mBufferIdMap;
478 std::unordered_map<uint64_t, ANativeWindowBuffer*> mReversedBufMap;
479 uint64_t mNextBufferId = 1;
480 static const uint64_t BUFFER_ID_NO_BUFFER = 0;
481
Yin-Chia Yehb2a65612017-09-07 16:30:46 -0700482 std::mutex mHidlMemPoolMapLock; // protecting mHidlMemPoolMap
Yin-Chia Yeh4717c472017-02-13 10:56:40 -0800483 std::unordered_map<int, camera_memory_t*> mHidlMemPoolMap;
Iliyan Malchev8951a972011-04-14 16:55:59 -0700484};
485
486}; // namespace android
487
488#endif