blob: 09e88c43698360e17b8f72b730edd4ca2bac5e94 [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);
Iliyan Malchev85fb61e2011-07-26 15:56:44 -0700389 if (mDevice->ops->put_parameters)
390 mDevice->ops->put_parameters(mDevice, temp);
391 else
392 free(temp);
Iliyan Malchev8951a972011-04-14 16:55:59 -0700393 parms.unflatten(str_parms);
394 }
395 return parms;
396 }
397
398 /**
399 * Send command to camera driver.
400 */
401 status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2)
402 {
403 LOGV("%s(%s)", __FUNCTION__, mName.string());
404 if (mDevice->ops->send_command)
405 return mDevice->ops->send_command(mDevice, cmd, arg1, arg2);
406 return INVALID_OPERATION;
407 }
408
409 /**
410 * Release the hardware resources owned by this object. Note that this is
411 * *not* done in the destructor.
412 */
413 void release() {
414 LOGV("%s(%s)", __FUNCTION__, mName.string());
415 if (mDevice->ops->release)
416 mDevice->ops->release(mDevice);
417 }
418
419 /**
420 * Dump state of the camera hardware
421 */
422 status_t dump(int fd, const Vector<String16>& args) const
423 {
424 LOGV("%s(%s)", __FUNCTION__, mName.string());
425 if (mDevice->ops->dump)
426 return mDevice->ops->dump(mDevice, fd);
427 return OK; // It's fine if the HAL doesn't implement dump()
428 }
429
430private:
431 camera_device_t *mDevice;
432 String8 mName;
433
434 static void __notify_cb(int32_t msg_type, int32_t ext1,
435 int32_t ext2, void *user)
436 {
437 LOGV("%s", __FUNCTION__);
438 CameraHardwareInterface *__this =
439 static_cast<CameraHardwareInterface *>(user);
440 __this->mNotifyCb(msg_type, ext1, ext2, __this->mCbUser);
441 }
442
443 static void __data_cb(int32_t msg_type,
Iliyan Malchev26adde82011-06-06 17:21:32 -0700444 const camera_memory_t *data, unsigned int index,
Iliyan Malchev8951a972011-04-14 16:55:59 -0700445 void *user)
446 {
447 LOGV("%s", __FUNCTION__);
448 CameraHardwareInterface *__this =
449 static_cast<CameraHardwareInterface *>(user);
450 sp<CameraHeapMemory> mem(static_cast<CameraHeapMemory *>(data->handle));
Iliyan Malchev26adde82011-06-06 17:21:32 -0700451 if (index >= mem->mNumBufs) {
452 LOGE("%s: invalid buffer index %d, max allowed is %d", __FUNCTION__,
453 index, mem->mNumBufs);
454 return;
455 }
456 __this->mDataCb(msg_type, mem->mBuffers[index], __this->mCbUser);
Iliyan Malchev8951a972011-04-14 16:55:59 -0700457 }
458
459 static void __data_cb_timestamp(nsecs_t timestamp, int32_t msg_type,
Iliyan Malchev26adde82011-06-06 17:21:32 -0700460 const camera_memory_t *data, unsigned index,
Iliyan Malchev8951a972011-04-14 16:55:59 -0700461 void *user)
462 {
463 LOGV("%s", __FUNCTION__);
464 CameraHardwareInterface *__this =
465 static_cast<CameraHardwareInterface *>(user);
466 // Start refcounting the heap object from here on. When the clients
467 // drop all references, it will be destroyed (as well as the enclosed
468 // MemoryHeapBase.
469 sp<CameraHeapMemory> mem(static_cast<CameraHeapMemory *>(data->handle));
Iliyan Malchev26adde82011-06-06 17:21:32 -0700470 if (index >= mem->mNumBufs) {
471 LOGE("%s: invalid buffer index %d, max allowed is %d", __FUNCTION__,
472 index, mem->mNumBufs);
473 return;
474 }
475 __this->mDataCbTimestamp(timestamp, msg_type, mem->mBuffers[index], __this->mCbUser);
Iliyan Malchev8951a972011-04-14 16:55:59 -0700476 }
477
478 // This is a utility class that combines a MemoryHeapBase and a MemoryBase
479 // in one. Since we tend to use them in a one-to-one relationship, this is
480 // handy.
481
Iliyan Malchev26adde82011-06-06 17:21:32 -0700482 class CameraHeapMemory : public RefBase {
Iliyan Malchev8951a972011-04-14 16:55:59 -0700483 public:
Iliyan Malchev26adde82011-06-06 17:21:32 -0700484 CameraHeapMemory(int fd, size_t buf_size, uint_t num_buffers = 1) :
485 mBufSize(buf_size),
486 mNumBufs(num_buffers)
Iliyan Malchev8951a972011-04-14 16:55:59 -0700487 {
Iliyan Malchev26adde82011-06-06 17:21:32 -0700488 mHeap = new MemoryHeapBase(fd, buf_size * num_buffers);
489 commonInitialization();
Iliyan Malchev8951a972011-04-14 16:55:59 -0700490 }
491
Iliyan Malchev26adde82011-06-06 17:21:32 -0700492 CameraHeapMemory(size_t buf_size, uint_t num_buffers = 1) :
493 mBufSize(buf_size),
494 mNumBufs(num_buffers)
495 {
496 mHeap = new MemoryHeapBase(buf_size * num_buffers);
497 commonInitialization();
498 }
499
500 void commonInitialization()
501 {
502 handle.data = mHeap->base();
503 handle.size = mBufSize * mNumBufs;
504 handle.handle = this;
505
506 mBuffers = new sp<MemoryBase>[mNumBufs];
507 for (uint_t i = 0; i < mNumBufs; i++)
508 mBuffers[i] = new MemoryBase(mHeap,
509 i * mBufSize,
510 mBufSize);
511
512 handle.release = __put_memory;
513 }
514
515 virtual ~CameraHeapMemory()
516 {
517 delete [] mBuffers;
518 }
519
520 size_t mBufSize;
521 uint_t mNumBufs;
522 sp<MemoryHeapBase> mHeap;
523 sp<MemoryBase> *mBuffers;
524
Iliyan Malchev8951a972011-04-14 16:55:59 -0700525 camera_memory_t handle;
526 };
527
Iliyan Malchev26adde82011-06-06 17:21:32 -0700528 static camera_memory_t* __get_memory(int fd, size_t buf_size, uint_t num_bufs,
529 void *user __attribute__((unused)))
Iliyan Malchev8951a972011-04-14 16:55:59 -0700530 {
Iliyan Malchev26adde82011-06-06 17:21:32 -0700531 CameraHeapMemory *mem;
532 if (fd < 0)
533 mem = new CameraHeapMemory(buf_size, num_bufs);
534 else
535 mem = new CameraHeapMemory(fd, buf_size, num_bufs);
536 mem->incStrong(mem);
Iliyan Malchev8951a972011-04-14 16:55:59 -0700537 return &mem->handle;
538 }
539
Iliyan Malchev26adde82011-06-06 17:21:32 -0700540 static void __put_memory(camera_memory_t *data)
541 {
542 if (!data)
543 return;
544
545 CameraHeapMemory *mem = static_cast<CameraHeapMemory *>(data->handle);
546 mem->decStrong(mem);
547 }
548
Iliyan Malchev8951a972011-04-14 16:55:59 -0700549 static ANativeWindow *__to_anw(void *user)
550 {
551 CameraHardwareInterface *__this =
552 reinterpret_cast<CameraHardwareInterface *>(user);
553 return __this->mPreviewWindow.get();
554 }
555#define anw(n) __to_anw(((struct camera_preview_window *)n)->user)
556
557 static int __dequeue_buffer(struct preview_stream_ops* w,
Iliyan Malchevafcedc92011-06-10 16:05:23 -0700558 buffer_handle_t** buffer, int *stride)
Iliyan Malchev8951a972011-04-14 16:55:59 -0700559 {
560 int rc;
561 ANativeWindow *a = anw(w);
Iliyan Malchev8ce23642011-05-01 11:33:26 -0700562 ANativeWindowBuffer* anb;
Iliyan Malchev8951a972011-04-14 16:55:59 -0700563 rc = a->dequeueBuffer(a, &anb);
564 if (!rc) {
Sundar Raman1e06f432011-06-17 09:05:09 -0500565 *buffer = &anb->handle;
566 *stride = anb->stride;
Iliyan Malchev8951a972011-04-14 16:55:59 -0700567 }
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
Sundar Raman1e06f432011-06-17 09:05:09 -0500577 static int __lock_buffer(struct preview_stream_ops* w,
578 buffer_handle_t* buffer)
579 {
580 ANativeWindow *a = anw(w);
581 return a->lockBuffer(a,
582 container_of(buffer, ANativeWindowBuffer, handle));
583 }
584
Iliyan Malchev8951a972011-04-14 16:55:59 -0700585 static int __enqueue_buffer(struct preview_stream_ops* w,
586 buffer_handle_t* buffer)
587 {
588 ANativeWindow *a = anw(w);
589 return a->queueBuffer(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 __cancel_buffer(struct preview_stream_ops* w,
594 buffer_handle_t* buffer)
595 {
596 ANativeWindow *a = anw(w);
597 return a->cancelBuffer(a,
Iliyan Malchev8ce23642011-05-01 11:33:26 -0700598 container_of(buffer, ANativeWindowBuffer, handle));
Iliyan Malchev8951a972011-04-14 16:55:59 -0700599 }
600
601 static int __set_buffer_count(struct preview_stream_ops* w, int count)
602 {
603 ANativeWindow *a = anw(w);
Iliyan Malchev26adde82011-06-06 17:21:32 -0700604 return native_window_set_buffer_count(a, count);
Iliyan Malchev8951a972011-04-14 16:55:59 -0700605 }
606
607 static int __set_buffers_geometry(struct preview_stream_ops* w,
608 int width, int height, int format)
609 {
610 ANativeWindow *a = anw(w);
Iliyan Malchev8ce23642011-05-01 11:33:26 -0700611 return native_window_set_buffers_geometry(a,
Iliyan Malchev8951a972011-04-14 16:55:59 -0700612 width, height, format);
613 }
614
615 static int __set_crop(struct preview_stream_ops *w,
616 int left, int top, int right, int bottom)
617 {
618 ANativeWindow *a = anw(w);
619 android_native_rect_t crop;
620 crop.left = left;
621 crop.top = top;
622 crop.right = right;
623 crop.bottom = bottom;
Iliyan Malchev8ce23642011-05-01 11:33:26 -0700624 return native_window_set_crop(a, &crop);
Iliyan Malchev8951a972011-04-14 16:55:59 -0700625 }
626
627 static int __set_usage(struct preview_stream_ops* w, int usage)
628 {
629 ANativeWindow *a = anw(w);
Iliyan Malchev8ce23642011-05-01 11:33:26 -0700630 return native_window_set_usage(a, usage);
Iliyan Malchev8951a972011-04-14 16:55:59 -0700631 }
632
633 static int __set_swap_interval(struct preview_stream_ops *w, int interval)
634 {
635 ANativeWindow *a = anw(w);
636 return a->setSwapInterval(a, interval);
637 }
638
639 static int __get_min_undequeued_buffer_count(
640 const struct preview_stream_ops *w,
641 int *count)
642 {
643 ANativeWindow *a = anw(w);
644 return a->query(a, NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, count);
645 }
646
647 void initHalPreviewWindow()
648 {
649 mHalPreviewWindow.nw.cancel_buffer = __cancel_buffer;
Sundar Raman1e06f432011-06-17 09:05:09 -0500650 mHalPreviewWindow.nw.lock_buffer = __lock_buffer;
Iliyan Malchev8951a972011-04-14 16:55:59 -0700651 mHalPreviewWindow.nw.dequeue_buffer = __dequeue_buffer;
652 mHalPreviewWindow.nw.enqueue_buffer = __enqueue_buffer;
653 mHalPreviewWindow.nw.set_buffer_count = __set_buffer_count;
654 mHalPreviewWindow.nw.set_buffers_geometry = __set_buffers_geometry;
655 mHalPreviewWindow.nw.set_crop = __set_crop;
656 mHalPreviewWindow.nw.set_usage = __set_usage;
657 mHalPreviewWindow.nw.set_swap_interval = __set_swap_interval;
658
659 mHalPreviewWindow.nw.get_min_undequeued_buffer_count =
660 __get_min_undequeued_buffer_count;
661 }
662
663 sp<ANativeWindow> mPreviewWindow;
664
665 struct camera_preview_window {
666 struct preview_stream_ops nw;
667 void *user;
668 };
669
670 struct camera_preview_window mHalPreviewWindow;
671
672 notify_callback mNotifyCb;
673 data_callback mDataCb;
674 data_callback_timestamp mDataCbTimestamp;
675 void *mCbUser;
676};
677
678}; // namespace android
679
680#endif