blob: 7a18831f6fc4af1d216e2bec3a24a780070af85d [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
20#include <binder/IMemory.h>
21#include <binder/MemoryBase.h>
22#include <binder/MemoryHeapBase.h>
23#include <utils/RefBase.h>
24#include <surfaceflinger/ISurface.h>
25#include <ui/android_native_buffer.h>
26#include <ui/GraphicBuffer.h>
27#include <camera/Camera.h>
28#include <camera/CameraParameters.h>
29#include <system/window.h>
30#include <hardware/camera.h>
31
32namespace android {
33
34typedef void (*notify_callback)(int32_t msgType,
35 int32_t ext1,
36 int32_t ext2,
37 void* user);
38
39typedef void (*data_callback)(int32_t msgType,
40 const sp<IMemory> &dataPtr,
41 void* user);
42
43typedef void (*data_callback_timestamp)(nsecs_t timestamp,
44 int32_t msgType,
45 const sp<IMemory> &dataPtr,
46 void *user);
47
48/**
49 * CameraHardwareInterface.h defines the interface to the
50 * camera hardware abstraction layer, used for setting and getting
51 * parameters, live previewing, and taking pictures.
52 *
53 * It is a referenced counted interface with RefBase as its base class.
54 * CameraService calls openCameraHardware() to retrieve a strong pointer to the
55 * instance of this interface and may be called multiple times. The
56 * following steps describe a typical sequence:
57 *
58 * -# After CameraService calls openCameraHardware(), getParameters() and
59 * setParameters() are used to initialize the camera instance.
60 * CameraService calls getPreviewHeap() to establish access to the
61 * preview heap so it can be registered with SurfaceFlinger for
62 * efficient display updating while in preview mode.
63 * -# startPreview() is called. The camera instance then periodically
64 * sends the message CAMERA_MSG_PREVIEW_FRAME (if enabled) each time
65 * a new preview frame is available. If data callback code needs to use
66 * this memory after returning, it must copy the data.
67 *
68 * Prior to taking a picture, CameraService calls autofocus(). When auto
69 * focusing has completed, the camera instance sends a CAMERA_MSG_FOCUS notification,
70 * which informs the application whether focusing was successful. The camera instance
71 * only sends this message once and it is up to the application to call autoFocus()
72 * again if refocusing is desired.
73 *
74 * CameraService calls takePicture() to request the camera instance take a
75 * picture. At this point, if a shutter, postview, raw, and/or compressed callback
76 * is desired, the corresponding message must be enabled. As with CAMERA_MSG_PREVIEW_FRAME,
77 * any memory provided in a data callback must be copied if it's needed after returning.
78 */
79
80class CameraHardwareInterface : public virtual RefBase {
81public:
82 CameraHardwareInterface(hw_module_t *module, const char *name)
83 {
84 mDevice = 0;
85 mName = name;
86 LOGI("Opening camera %s, this %p", name, this);
87 int rc = module->methods->open(module, name,
88 (hw_device_t **)&mDevice);
89 if (rc != OK)
90 LOGE("Could not open camera %s: %d", name, rc);
91 initHalPreviewWindow();
92 }
93
94 ~CameraHardwareInterface()
95 {
96 LOGI("Destroying camera %s", mName.string());
97 int rc = mDevice->common.close(&mDevice->common);
98 if (rc != OK)
99 LOGE("Could not close camera %s: %d", mName.string(), rc);
100 }
101
102 /** Set the ANativeWindow to which preview frames are sent */
103 status_t setPreviewWindow(const sp<ANativeWindow>& buf)
104 {
105 LOGV("%s(%s) buf %p", __FUNCTION__, mName.string(), buf.get());
106
107 if (mDevice->ops->set_preview_window) {
108 mPreviewWindow = buf;
109 mHalPreviewWindow.user = this;
110 LOGV("%s &mHalPreviewWindow %p mHalPreviewWindow.user %p", __FUNCTION__,
111 &mHalPreviewWindow, mHalPreviewWindow.user);
112 return mDevice->ops->set_preview_window(mDevice,
113 buf.get() ? &mHalPreviewWindow.nw : 0);
114 }
115 return INVALID_OPERATION;
116 }
117
118 /** Set the notification and data callbacks */
119 void setCallbacks(notify_callback notify_cb,
120 data_callback data_cb,
121 data_callback_timestamp data_cb_timestamp,
122 void* user)
123 {
124 mNotifyCb = notify_cb;
125 mDataCb = data_cb;
126 mDataCbTimestamp = data_cb_timestamp;
127 mCbUser = user;
128
129 LOGV("%s(%s)", __FUNCTION__, mName.string());
130
131 if (mDevice->ops->set_callbacks) {
132 mDevice->ops->set_callbacks(mDevice,
133 __notify_cb,
134 __data_cb,
135 __data_cb_timestamp,
136 __get_memory,
137 this);
138 }
139 }
140
141 /**
142 * The following three functions all take a msgtype,
143 * which is a bitmask of the messages defined in
144 * include/ui/Camera.h
145 */
146
147 /**
148 * Enable a message, or set of messages.
149 */
150 void enableMsgType(int32_t msgType)
151 {
152 LOGV("%s(%s)", __FUNCTION__, mName.string());
153 if (mDevice->ops->enable_msg_type)
154 mDevice->ops->enable_msg_type(mDevice, msgType);
155 }
156
157 /**
158 * Disable a message, or a set of messages.
159 *
160 * Once received a call to disableMsgType(CAMERA_MSG_VIDEO_FRAME), camera hal
161 * should not rely on its client to call releaseRecordingFrame() to release
162 * video recording frames sent out by the cameral hal before and after the
163 * disableMsgType(CAMERA_MSG_VIDEO_FRAME) call. Camera hal clients must not
164 * modify/access any video recording frame after calling
165 * disableMsgType(CAMERA_MSG_VIDEO_FRAME).
166 */
167 void disableMsgType(int32_t msgType)
168 {
169 LOGV("%s(%s)", __FUNCTION__, mName.string());
170 if (mDevice->ops->disable_msg_type)
171 mDevice->ops->disable_msg_type(mDevice, msgType);
172 }
173
174 /**
175 * Query whether a message, or a set of messages, is enabled.
176 * Note that this is operates as an AND, if any of the messages
177 * queried are off, this will return false.
178 */
179 int msgTypeEnabled(int32_t msgType)
180 {
181 LOGV("%s(%s)", __FUNCTION__, mName.string());
182 if (mDevice->ops->msg_type_enabled)
183 return mDevice->ops->msg_type_enabled(mDevice, msgType);
184 return false;
185 }
186
187 /**
188 * Start preview mode.
189 */
190 status_t startPreview()
191 {
192 LOGV("%s(%s)", __FUNCTION__, mName.string());
193 if (mDevice->ops->start_preview)
194 return mDevice->ops->start_preview(mDevice);
195 return INVALID_OPERATION;
196 }
197
198 /**
199 * Stop a previously started preview.
200 */
201 void stopPreview()
202 {
203 LOGV("%s(%s)", __FUNCTION__, mName.string());
204 if (mDevice->ops->stop_preview)
205 mDevice->ops->stop_preview(mDevice);
206 }
207
208 /**
209 * Returns true if preview is enabled.
210 */
211 int previewEnabled()
212 {
213 LOGV("%s(%s)", __FUNCTION__, mName.string());
214 if (mDevice->ops->preview_enabled)
215 return mDevice->ops->preview_enabled(mDevice);
216 return false;
217 }
218
219 /**
220 * Request the camera hal to store meta data or real YUV data in
221 * the video buffers send out via CAMERA_MSG_VIDEO_FRRAME for a
222 * recording session. If it is not called, the default camera
223 * hal behavior is to store real YUV data in the video buffers.
224 *
225 * This method should be called before startRecording() in order
226 * to be effective.
227 *
228 * If meta data is stored in the video buffers, it is up to the
229 * receiver of the video buffers to interpret the contents and
230 * to find the actual frame data with the help of the meta data
231 * in the buffer. How this is done is outside of the scope of
232 * this method.
233 *
234 * Some camera hal may not support storing meta data in the video
235 * buffers, but all camera hal should support storing real YUV data
236 * in the video buffers. If the camera hal does not support storing
237 * the meta data in the video buffers when it is requested to do
238 * do, INVALID_OPERATION must be returned. It is very useful for
239 * the camera hal to pass meta data rather than the actual frame
240 * data directly to the video encoder, since the amount of the
241 * uncompressed frame data can be very large if video size is large.
242 *
243 * @param enable if true to instruct the camera hal to store
244 * meta data in the video buffers; false to instruct
245 * the camera hal to store real YUV data in the video
246 * buffers.
247 *
248 * @return OK on success.
249 */
250
251 status_t storeMetaDataInBuffers(int enable)
252 {
253 LOGV("%s(%s)", __FUNCTION__, mName.string());
254 if (mDevice->ops->store_meta_data_in_buffers)
255 return mDevice->ops->store_meta_data_in_buffers(mDevice, enable);
256 return enable ? INVALID_OPERATION: OK;
257 }
258
259 /**
260 * Start record mode. When a record image is available a CAMERA_MSG_VIDEO_FRAME
261 * message is sent with the corresponding frame. Every record frame must be released
262 * by a cameral hal client via releaseRecordingFrame() before the client calls
263 * disableMsgType(CAMERA_MSG_VIDEO_FRAME). After the client calls
264 * disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is camera hal's responsibility
265 * to manage the life-cycle of the video recording frames, and the client must
266 * not modify/access any video recording frames.
267 */
268 status_t startRecording()
269 {
270 LOGV("%s(%s)", __FUNCTION__, mName.string());
271 if (mDevice->ops->start_recording)
272 return mDevice->ops->start_recording(mDevice);
273 return INVALID_OPERATION;
274 }
275
276 /**
277 * Stop a previously started recording.
278 */
279 void stopRecording()
280 {
281 LOGV("%s(%s)", __FUNCTION__, mName.string());
282 if (mDevice->ops->stop_recording)
283 mDevice->ops->stop_recording(mDevice);
284 }
285
286 /**
287 * Returns true if recording is enabled.
288 */
289 int recordingEnabled()
290 {
291 LOGV("%s(%s)", __FUNCTION__, mName.string());
292 if (mDevice->ops->recording_enabled)
293 return mDevice->ops->recording_enabled(mDevice);
294 return false;
295 }
296
297 /**
298 * Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME.
299 *
300 * It is camera hal client's responsibility to release video recording
301 * frames sent out by the camera hal before the camera hal receives
302 * a call to disableMsgType(CAMERA_MSG_VIDEO_FRAME). After it receives
303 * the call to disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is camera hal's
304 * responsibility of managing the life-cycle of the video recording
305 * frames.
306 */
307 void releaseRecordingFrame(const sp<IMemory>& mem)
308 {
309 LOGV("%s(%s)", __FUNCTION__, mName.string());
310 if (mDevice->ops->release_recording_frame) {
311 ssize_t offset;
312 size_t size;
313 sp<IMemoryHeap> heap = mem->getMemory(&offset, &size);
314 void *data = ((uint8_t *)heap->base()) + offset;
315 return mDevice->ops->release_recording_frame(mDevice, data);
316 }
317 }
318
319 /**
320 * Start auto focus, the notification callback routine is called
321 * with CAMERA_MSG_FOCUS once when focusing is complete. autoFocus()
322 * will be called again if another auto focus is needed.
323 */
324 status_t autoFocus()
325 {
326 LOGV("%s(%s)", __FUNCTION__, mName.string());
327 if (mDevice->ops->auto_focus)
328 return mDevice->ops->auto_focus(mDevice);
329 return INVALID_OPERATION;
330 }
331
332 /**
333 * Cancels auto-focus function. If the auto-focus is still in progress,
334 * this function will cancel it. Whether the auto-focus is in progress
335 * or not, this function will return the focus position to the default.
336 * If the camera does not support auto-focus, this is a no-op.
337 */
338 status_t cancelAutoFocus()
339 {
340 LOGV("%s(%s)", __FUNCTION__, mName.string());
341 if (mDevice->ops->cancel_auto_focus)
342 return mDevice->ops->cancel_auto_focus(mDevice);
343 return INVALID_OPERATION;
344 }
345
346 /**
347 * Take a picture.
348 */
349 status_t takePicture()
350 {
351 LOGV("%s(%s)", __FUNCTION__, mName.string());
352 if (mDevice->ops->take_picture)
353 return mDevice->ops->take_picture(mDevice);
354 return INVALID_OPERATION;
355 }
356
357 /**
358 * Cancel a picture that was started with takePicture. Calling this
359 * method when no picture is being taken is a no-op.
360 */
361 status_t cancelPicture()
362 {
363 LOGV("%s(%s)", __FUNCTION__, mName.string());
364 if (mDevice->ops->cancel_picture)
365 return mDevice->ops->cancel_picture(mDevice);
366 return INVALID_OPERATION;
367 }
368
369 /**
370 * Set the camera parameters. This returns BAD_VALUE if any parameter is
371 * invalid or not supported. */
372 status_t setParameters(const CameraParameters &params)
373 {
374 LOGV("%s(%s)", __FUNCTION__, mName.string());
375 if (mDevice->ops->set_parameters)
376 return mDevice->ops->set_parameters(mDevice,
377 params.flatten().string());
378 return INVALID_OPERATION;
379 }
380
381 /** Return the camera parameters. */
382 CameraParameters getParameters() const
383 {
384 LOGV("%s(%s)", __FUNCTION__, mName.string());
385 CameraParameters parms;
386 if (mDevice->ops->get_parameters) {
387 char *temp = mDevice->ops->get_parameters(mDevice);
388 String8 str_parms(temp);
389 free(temp);
390 parms.unflatten(str_parms);
391 }
392 return parms;
393 }
394
395 /**
396 * Send command to camera driver.
397 */
398 status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2)
399 {
400 LOGV("%s(%s)", __FUNCTION__, mName.string());
401 if (mDevice->ops->send_command)
402 return mDevice->ops->send_command(mDevice, cmd, arg1, arg2);
403 return INVALID_OPERATION;
404 }
405
406 /**
407 * Release the hardware resources owned by this object. Note that this is
408 * *not* done in the destructor.
409 */
410 void release() {
411 LOGV("%s(%s)", __FUNCTION__, mName.string());
412 if (mDevice->ops->release)
413 mDevice->ops->release(mDevice);
414 }
415
416 /**
417 * Dump state of the camera hardware
418 */
419 status_t dump(int fd, const Vector<String16>& args) const
420 {
421 LOGV("%s(%s)", __FUNCTION__, mName.string());
422 if (mDevice->ops->dump)
423 return mDevice->ops->dump(mDevice, fd);
424 return OK; // It's fine if the HAL doesn't implement dump()
425 }
426
427private:
428 camera_device_t *mDevice;
429 String8 mName;
430
431 static void __notify_cb(int32_t msg_type, int32_t ext1,
432 int32_t ext2, void *user)
433 {
434 LOGV("%s", __FUNCTION__);
435 CameraHardwareInterface *__this =
436 static_cast<CameraHardwareInterface *>(user);
437 __this->mNotifyCb(msg_type, ext1, ext2, __this->mCbUser);
438 }
439
440 static void __data_cb(int32_t msg_type,
Iliyan Malchev26adde82011-06-06 17:21:32 -0700441 const camera_memory_t *data, unsigned int index,
Iliyan Malchev8951a972011-04-14 16:55:59 -0700442 void *user)
443 {
444 LOGV("%s", __FUNCTION__);
445 CameraHardwareInterface *__this =
446 static_cast<CameraHardwareInterface *>(user);
447 sp<CameraHeapMemory> mem(static_cast<CameraHeapMemory *>(data->handle));
Iliyan Malchev26adde82011-06-06 17:21:32 -0700448 if (index >= mem->mNumBufs) {
449 LOGE("%s: invalid buffer index %d, max allowed is %d", __FUNCTION__,
450 index, mem->mNumBufs);
451 return;
452 }
453 __this->mDataCb(msg_type, mem->mBuffers[index], __this->mCbUser);
Iliyan Malchev8951a972011-04-14 16:55:59 -0700454 }
455
456 static void __data_cb_timestamp(nsecs_t timestamp, int32_t msg_type,
Iliyan Malchev26adde82011-06-06 17:21:32 -0700457 const camera_memory_t *data, unsigned index,
Iliyan Malchev8951a972011-04-14 16:55:59 -0700458 void *user)
459 {
460 LOGV("%s", __FUNCTION__);
461 CameraHardwareInterface *__this =
462 static_cast<CameraHardwareInterface *>(user);
463 // Start refcounting the heap object from here on. When the clients
464 // drop all references, it will be destroyed (as well as the enclosed
465 // MemoryHeapBase.
466 sp<CameraHeapMemory> mem(static_cast<CameraHeapMemory *>(data->handle));
Iliyan Malchev26adde82011-06-06 17:21:32 -0700467 if (index >= mem->mNumBufs) {
468 LOGE("%s: invalid buffer index %d, max allowed is %d", __FUNCTION__,
469 index, mem->mNumBufs);
470 return;
471 }
472 __this->mDataCbTimestamp(timestamp, msg_type, mem->mBuffers[index], __this->mCbUser);
Iliyan Malchev8951a972011-04-14 16:55:59 -0700473 }
474
475 // This is a utility class that combines a MemoryHeapBase and a MemoryBase
476 // in one. Since we tend to use them in a one-to-one relationship, this is
477 // handy.
478
Iliyan Malchev26adde82011-06-06 17:21:32 -0700479 class CameraHeapMemory : public RefBase {
Iliyan Malchev8951a972011-04-14 16:55:59 -0700480 public:
Iliyan Malchev26adde82011-06-06 17:21:32 -0700481 CameraHeapMemory(int fd, size_t buf_size, uint_t num_buffers = 1) :
482 mBufSize(buf_size),
483 mNumBufs(num_buffers)
Iliyan Malchev8951a972011-04-14 16:55:59 -0700484 {
Iliyan Malchev26adde82011-06-06 17:21:32 -0700485 mHeap = new MemoryHeapBase(fd, buf_size * num_buffers);
486 commonInitialization();
Iliyan Malchev8951a972011-04-14 16:55:59 -0700487 }
488
Iliyan Malchev26adde82011-06-06 17:21:32 -0700489 CameraHeapMemory(size_t buf_size, uint_t num_buffers = 1) :
490 mBufSize(buf_size),
491 mNumBufs(num_buffers)
492 {
493 mHeap = new MemoryHeapBase(buf_size * num_buffers);
494 commonInitialization();
495 }
496
497 void commonInitialization()
498 {
499 handle.data = mHeap->base();
500 handle.size = mBufSize * mNumBufs;
501 handle.handle = this;
502
503 mBuffers = new sp<MemoryBase>[mNumBufs];
504 for (uint_t i = 0; i < mNumBufs; i++)
505 mBuffers[i] = new MemoryBase(mHeap,
506 i * mBufSize,
507 mBufSize);
508
509 handle.release = __put_memory;
510 }
511
512 virtual ~CameraHeapMemory()
513 {
514 delete [] mBuffers;
515 }
516
517 size_t mBufSize;
518 uint_t mNumBufs;
519 sp<MemoryHeapBase> mHeap;
520 sp<MemoryBase> *mBuffers;
521
Iliyan Malchev8951a972011-04-14 16:55:59 -0700522 camera_memory_t handle;
523 };
524
Iliyan Malchev26adde82011-06-06 17:21:32 -0700525 static camera_memory_t* __get_memory(int fd, size_t buf_size, uint_t num_bufs,
526 void *user __attribute__((unused)))
Iliyan Malchev8951a972011-04-14 16:55:59 -0700527 {
Iliyan Malchev26adde82011-06-06 17:21:32 -0700528 CameraHeapMemory *mem;
529 if (fd < 0)
530 mem = new CameraHeapMemory(buf_size, num_bufs);
531 else
532 mem = new CameraHeapMemory(fd, buf_size, num_bufs);
533 mem->incStrong(mem);
Iliyan Malchev8951a972011-04-14 16:55:59 -0700534 return &mem->handle;
535 }
536
Iliyan Malchev26adde82011-06-06 17:21:32 -0700537 static void __put_memory(camera_memory_t *data)
538 {
539 if (!data)
540 return;
541
542 CameraHeapMemory *mem = static_cast<CameraHeapMemory *>(data->handle);
543 mem->decStrong(mem);
544 }
545
Iliyan Malchev8951a972011-04-14 16:55:59 -0700546 static ANativeWindow *__to_anw(void *user)
547 {
548 CameraHardwareInterface *__this =
549 reinterpret_cast<CameraHardwareInterface *>(user);
550 return __this->mPreviewWindow.get();
551 }
552#define anw(n) __to_anw(((struct camera_preview_window *)n)->user)
553
554 static int __dequeue_buffer(struct preview_stream_ops* w,
555 buffer_handle_t** buffer)
556 {
557 int rc;
558 ANativeWindow *a = anw(w);
Iliyan Malchev8ce23642011-05-01 11:33:26 -0700559 ANativeWindowBuffer* anb;
Iliyan Malchev8951a972011-04-14 16:55:59 -0700560 rc = a->dequeueBuffer(a, &anb);
561 if (!rc) {
562 rc = a->lockBuffer(a, anb);
563 if (!rc)
564 *buffer = &anb->handle;
565 else
566 a->cancelBuffer(a, anb);
567 }
568 return rc;
569 }
570
571#ifndef container_of
572#define container_of(ptr, type, member) ({ \
573 const typeof(((type *) 0)->member) *__mptr = (ptr); \
574 (type *) ((char *) __mptr - (char *)(&((type *)0)->member)); })
575#endif
576
577 static int __enqueue_buffer(struct preview_stream_ops* w,
578 buffer_handle_t* buffer)
579 {
580 ANativeWindow *a = anw(w);
581 return a->queueBuffer(a,
Iliyan Malchev8ce23642011-05-01 11:33:26 -0700582 container_of(buffer, ANativeWindowBuffer, handle));
Iliyan Malchev8951a972011-04-14 16:55:59 -0700583 }
584
585 static int __cancel_buffer(struct preview_stream_ops* w,
586 buffer_handle_t* buffer)
587 {
588 ANativeWindow *a = anw(w);
589 return a->cancelBuffer(a,
Iliyan Malchev8ce23642011-05-01 11:33:26 -0700590 container_of(buffer, ANativeWindowBuffer, handle));
Iliyan Malchev8951a972011-04-14 16:55:59 -0700591 }
592
593 static int __set_buffer_count(struct preview_stream_ops* w, int count)
594 {
595 ANativeWindow *a = anw(w);
Iliyan Malchev26adde82011-06-06 17:21:32 -0700596 return native_window_set_buffer_count(a, count);
Iliyan Malchev8951a972011-04-14 16:55:59 -0700597 }
598
599 static int __set_buffers_geometry(struct preview_stream_ops* w,
600 int width, int height, int format)
601 {
602 ANativeWindow *a = anw(w);
Iliyan Malchev8ce23642011-05-01 11:33:26 -0700603 return native_window_set_buffers_geometry(a,
Iliyan Malchev8951a972011-04-14 16:55:59 -0700604 width, height, format);
605 }
606
607 static int __set_crop(struct preview_stream_ops *w,
608 int left, int top, int right, int bottom)
609 {
610 ANativeWindow *a = anw(w);
611 android_native_rect_t crop;
612 crop.left = left;
613 crop.top = top;
614 crop.right = right;
615 crop.bottom = bottom;
Iliyan Malchev8ce23642011-05-01 11:33:26 -0700616 return native_window_set_crop(a, &crop);
Iliyan Malchev8951a972011-04-14 16:55:59 -0700617 }
618
619 static int __set_usage(struct preview_stream_ops* w, int usage)
620 {
621 ANativeWindow *a = anw(w);
Iliyan Malchev8ce23642011-05-01 11:33:26 -0700622 return native_window_set_usage(a, usage);
Iliyan Malchev8951a972011-04-14 16:55:59 -0700623 }
624
625 static int __set_swap_interval(struct preview_stream_ops *w, int interval)
626 {
627 ANativeWindow *a = anw(w);
628 return a->setSwapInterval(a, interval);
629 }
630
631 static int __get_min_undequeued_buffer_count(
632 const struct preview_stream_ops *w,
633 int *count)
634 {
635 ANativeWindow *a = anw(w);
636 return a->query(a, NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, count);
637 }
638
639 void initHalPreviewWindow()
640 {
641 mHalPreviewWindow.nw.cancel_buffer = __cancel_buffer;
642 mHalPreviewWindow.nw.dequeue_buffer = __dequeue_buffer;
643 mHalPreviewWindow.nw.enqueue_buffer = __enqueue_buffer;
644 mHalPreviewWindow.nw.set_buffer_count = __set_buffer_count;
645 mHalPreviewWindow.nw.set_buffers_geometry = __set_buffers_geometry;
646 mHalPreviewWindow.nw.set_crop = __set_crop;
647 mHalPreviewWindow.nw.set_usage = __set_usage;
648 mHalPreviewWindow.nw.set_swap_interval = __set_swap_interval;
649
650 mHalPreviewWindow.nw.get_min_undequeued_buffer_count =
651 __get_min_undequeued_buffer_count;
652 }
653
654 sp<ANativeWindow> mPreviewWindow;
655
656 struct camera_preview_window {
657 struct preview_stream_ops nw;
658 void *user;
659 };
660
661 struct camera_preview_window mHalPreviewWindow;
662
663 notify_callback mNotifyCb;
664 data_callback mDataCb;
665 data_callback_timestamp mDataCbTimestamp;
666 void *mCbUser;
667};
668
669}; // namespace android
670
671#endif