2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * Contains implementation of a class EmulatedCamera that encapsulates
19 * functionality common to all emulated cameras ("fake", "webcam", "video file",
20 * etc.). Instances of this class (for each emulated camera) are created during
21 * the construction of the EmulatedCameraFactory instance. This class serves as
22 * an entry point for all camera API calls that defined by camera_device_ops_t
27 #define LOG_TAG "EmulatedCamera_Camera"
28 #include <cutils/log.h>
30 #include "EmulatedCamera.h"
31 //#include "EmulatedFakeCameraDevice.h"
32 #include "Converters.h"
34 /* Defines whether we should trace parameter changes. */
40 /* Calculates and logs parameter changes.
42 * current - Current set of camera parameters.
43 * new_par - String representation of new parameters.
45 static void PrintParamDiff(const CameraParameters& current, const char* new_par);
47 #define PrintParamDiff(current, new_par) (void(0))
48 #endif /* DEBUG_PARAM */
50 /* A helper routine that adds a value to the camera parameter.
52 * param - Camera parameter to add a value to.
55 * A new string containing parameter with the added value on success, or NULL on
56 * a failure. If non-NULL string is returned, the caller is responsible for
57 * freeing it with 'free'.
59 static char* AddValue(const char* param, const char* val);
61 EmulatedCamera::EmulatedCamera(int cameraId,
62 struct hw_module_t* module)
63 : EmulatedBaseCamera(cameraId,
64 HARDWARE_DEVICE_API_VERSION(1, 0),
70 /* camera_device v1 fields. */
71 common.close = EmulatedCamera::close;
76 EmulatedCamera::~EmulatedCamera()
80 /****************************************************************************
82 ***************************************************************************/
84 status_t EmulatedCamera::Initialize()
86 /* Preview formats supported by this HAL. */
87 char preview_formats[1024];
88 snprintf(preview_formats, sizeof(preview_formats), "%s,%s,%s",
89 CameraParameters::PIXEL_FORMAT_YUV420SP,
90 CameraParameters::PIXEL_FORMAT_YUV420P,
91 CameraParameters::PIXEL_FORMAT_RGBA8888);
94 * Fake required parameters.
97 mParameters.set(CameraParameters::KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES, "320x240,0x0");
99 mParameters.set(CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH, "512");
100 mParameters.set(CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT, "384");
101 mParameters.set(CameraParameters::KEY_JPEG_QUALITY, "90");
102 mParameters.set(CameraParameters::KEY_FOCAL_LENGTH, "4.31");
103 mParameters.set(CameraParameters::KEY_HORIZONTAL_VIEW_ANGLE, "54.8");
104 mParameters.set(CameraParameters::KEY_VERTICAL_VIEW_ANGLE, "42.5");
105 mParameters.set(CameraParameters::KEY_JPEG_THUMBNAIL_QUALITY, "90");
107 /* Preview format settings used here are related to panoramic view only. It's
108 * not related to the preview window that works only with RGB frames, which
109 * is explicitly stated when set_buffers_geometry is called on the preview
111 mParameters.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS,
113 mParameters.setPreviewFormat(CameraParameters::PIXEL_FORMAT_YUV420SP);
115 /* We don't relay on the actual frame rates supported by the camera device,
116 * since we will emulate them through timeouts in the emulated camera device
118 mParameters.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES,
120 mParameters.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FPS_RANGE, "(5,30)");
121 mParameters.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, "5,30");
122 mParameters.setPreviewFrameRate(24);
124 /* Only PIXEL_FORMAT_YUV420P is accepted by video framework in emulator! */
125 mParameters.set(CameraParameters::KEY_VIDEO_FRAME_FORMAT,
126 CameraParameters::PIXEL_FORMAT_YUV420P);
127 mParameters.set(CameraParameters::KEY_SUPPORTED_PICTURE_FORMATS,
128 CameraParameters::PIXEL_FORMAT_JPEG);
129 mParameters.setPictureFormat(CameraParameters::PIXEL_FORMAT_JPEG);
131 /* Set exposure compensation. */
132 mParameters.set(CameraParameters::KEY_MAX_EXPOSURE_COMPENSATION, "6");
133 mParameters.set(CameraParameters::KEY_MIN_EXPOSURE_COMPENSATION, "-6");
134 mParameters.set(CameraParameters::KEY_EXPOSURE_COMPENSATION_STEP, "0.5");
135 mParameters.set(CameraParameters::KEY_EXPOSURE_COMPENSATION, "0");
137 /* Sets the white balance modes and the device-dependent scale factors. */
138 char supported_white_balance[1024];
139 snprintf(supported_white_balance, sizeof(supported_white_balance),
141 CameraParameters::WHITE_BALANCE_AUTO,
142 CameraParameters::WHITE_BALANCE_INCANDESCENT,
143 CameraParameters::WHITE_BALANCE_DAYLIGHT,
144 CameraParameters::WHITE_BALANCE_TWILIGHT);
145 mParameters.set(CameraParameters::KEY_SUPPORTED_WHITE_BALANCE,
146 supported_white_balance);
147 mParameters.set(CameraParameters::KEY_WHITE_BALANCE,
148 CameraParameters::WHITE_BALANCE_AUTO);
149 getCameraDevice()->initializeWhiteBalanceModes(
150 CameraParameters::WHITE_BALANCE_AUTO, 1.0f, 1.0f);
151 getCameraDevice()->initializeWhiteBalanceModes(
152 CameraParameters::WHITE_BALANCE_INCANDESCENT, 1.38f, 0.60f);
153 getCameraDevice()->initializeWhiteBalanceModes(
154 CameraParameters::WHITE_BALANCE_DAYLIGHT, 1.09f, 0.92f);
155 getCameraDevice()->initializeWhiteBalanceModes(
156 CameraParameters::WHITE_BALANCE_TWILIGHT, 0.92f, 1.22f);
157 getCameraDevice()->setWhiteBalanceMode(CameraParameters::WHITE_BALANCE_AUTO);
159 /* Not supported features
161 mParameters.set(CameraParameters::KEY_SUPPORTED_FOCUS_MODES,
162 CameraParameters::FOCUS_MODE_FIXED);
163 mParameters.set(CameraParameters::KEY_FOCUS_MODE,
164 CameraParameters::FOCUS_MODE_FIXED);
169 void EmulatedCamera::onNextFrameAvailable(const void* frame,
171 EmulatedCameraDevice* camera_dev)
173 /* Notify the preview window first. */
174 mPreviewWindow.onNextFrameAvailable(frame, timestamp, camera_dev);
176 /* Notify callback notifier next. */
177 mCallbackNotifier.onNextFrameAvailable(frame, timestamp, camera_dev);
180 void EmulatedCamera::onCameraDeviceError(int err)
182 /* Errors are reported through the callback notifier */
183 mCallbackNotifier.onCameraDeviceError(err);
186 /****************************************************************************
187 * Camera API implementation.
188 ***************************************************************************/
190 status_t EmulatedCamera::connectCamera(hw_device_t** device)
192 ALOGV("%s", __FUNCTION__);
194 status_t res = EINVAL;
195 EmulatedCameraDevice* const camera_dev = getCameraDevice();
196 ALOGE_IF(camera_dev == NULL, "%s: No camera device instance.", __FUNCTION__);
198 if (camera_dev != NULL) {
199 /* Connect to the camera device. */
200 res = getCameraDevice()->connectDevice();
201 if (res == NO_ERROR) {
209 status_t EmulatedCamera::closeCamera()
211 ALOGV("%s", __FUNCTION__);
213 return cleanupCamera();
216 status_t EmulatedCamera::getCameraInfo(struct camera_info* info)
218 ALOGV("%s", __FUNCTION__);
220 const char* valstr = NULL;
222 valstr = mParameters.get(EmulatedCamera::FACING_KEY);
223 if (valstr != NULL) {
224 if (strcmp(valstr, EmulatedCamera::FACING_FRONT) == 0) {
225 info->facing = CAMERA_FACING_FRONT;
227 else if (strcmp(valstr, EmulatedCamera::FACING_BACK) == 0) {
228 info->facing = CAMERA_FACING_BACK;
231 info->facing = CAMERA_FACING_BACK;
234 valstr = mParameters.get(EmulatedCamera::ORIENTATION_KEY);
235 if (valstr != NULL) {
236 info->orientation = atoi(valstr);
238 info->orientation = 0;
241 return EmulatedBaseCamera::getCameraInfo(info);
244 status_t EmulatedCamera::setPreviewWindow(struct preview_stream_ops* window)
246 /* Callback should return a negative errno. */
247 return -mPreviewWindow.setPreviewWindow(window,
248 mParameters.getPreviewFrameRate());
251 void EmulatedCamera::setCallbacks(camera_notify_callback notify_cb,
252 camera_data_callback data_cb,
253 camera_data_timestamp_callback data_cb_timestamp,
254 camera_request_memory get_memory,
257 mCallbackNotifier.setCallbacks(notify_cb, data_cb, data_cb_timestamp,
261 void EmulatedCamera::enableMsgType(int32_t msg_type)
263 mCallbackNotifier.enableMessage(msg_type);
266 void EmulatedCamera::disableMsgType(int32_t msg_type)
268 mCallbackNotifier.disableMessage(msg_type);
271 int EmulatedCamera::isMsgTypeEnabled(int32_t msg_type)
273 return mCallbackNotifier.isMessageEnabled(msg_type);
276 status_t EmulatedCamera::startPreview()
278 /* Callback should return a negative errno. */
279 return -doStartPreview();
282 void EmulatedCamera::stopPreview()
287 int EmulatedCamera::isPreviewEnabled()
289 return mPreviewWindow.isPreviewEnabled();
292 status_t EmulatedCamera::storeMetaDataInBuffers(int enable)
294 /* Callback should return a negative errno. */
295 return -mCallbackNotifier.storeMetaDataInBuffers(enable);
298 status_t EmulatedCamera::startRecording()
300 /* Callback should return a negative errno. */
301 return -mCallbackNotifier.enableVideoRecording(mParameters.getPreviewFrameRate());
304 void EmulatedCamera::stopRecording()
306 mCallbackNotifier.disableVideoRecording();
309 int EmulatedCamera::isRecordingEnabled()
311 return mCallbackNotifier.isVideoRecordingEnabled();
314 void EmulatedCamera::releaseRecordingFrame(const void* opaque)
316 mCallbackNotifier.releaseRecordingFrame(opaque);
319 status_t EmulatedCamera::setAutoFocus()
321 ALOGV("%s", __FUNCTION__);
323 /* TODO: Future enhancements. */
327 status_t EmulatedCamera::cancelAutoFocus()
329 ALOGV("%s", __FUNCTION__);
331 /* TODO: Future enhancements. */
335 status_t EmulatedCamera::takePicture()
337 ALOGV("%s", __FUNCTION__);
343 /* Collect frame info for the picture. */
344 mParameters.getPictureSize(&width, &height);
345 const char* pix_fmt = mParameters.getPictureFormat();
346 if (strcmp(pix_fmt, CameraParameters::PIXEL_FORMAT_YUV420P) == 0) {
347 org_fmt = V4L2_PIX_FMT_YUV420;
348 } else if (strcmp(pix_fmt, CameraParameters::PIXEL_FORMAT_RGBA8888) == 0) {
349 org_fmt = V4L2_PIX_FMT_RGB32;
350 } else if (strcmp(pix_fmt, CameraParameters::PIXEL_FORMAT_YUV420SP) == 0) {
351 org_fmt = V4L2_PIX_FMT_NV21;
352 } else if (strcmp(pix_fmt, CameraParameters::PIXEL_FORMAT_JPEG) == 0) {
353 /* We only have JPEG converted for NV21 format. */
354 org_fmt = V4L2_PIX_FMT_NV21;
356 ALOGE("%s: Unsupported pixel format %s", __FUNCTION__, pix_fmt);
359 /* Get JPEG quality. */
360 int jpeg_quality = mParameters.getInt(CameraParameters::KEY_JPEG_QUALITY);
361 if (jpeg_quality <= 0) {
362 jpeg_quality = 90; /* Fall back to default. */
366 * Make sure preview is not running, and device is stopped before taking
370 const bool preview_on = mPreviewWindow.isPreviewEnabled();
375 /* Camera device should have been stopped when the shutter message has been
377 EmulatedCameraDevice* const camera_dev = getCameraDevice();
378 if (camera_dev->isStarted()) {
379 ALOGW("%s: Camera device is started", __FUNCTION__);
380 camera_dev->stopDeliveringFrames();
381 camera_dev->stopDevice();
385 * Take the picture now.
388 /* Start camera device for the picture frame. */
389 ALOGD("Starting camera for picture: %.4s(%s)[%dx%d]",
390 reinterpret_cast<const char*>(&org_fmt), pix_fmt, width, height);
391 res = camera_dev->startDevice(width, height, org_fmt);
392 if (res != NO_ERROR) {
399 /* Deliver one frame only. */
400 mCallbackNotifier.setJpegQuality(jpeg_quality);
401 mCallbackNotifier.setTakingPicture(true);
402 res = camera_dev->startDeliveringFrames(true);
403 if (res != NO_ERROR) {
404 mCallbackNotifier.setTakingPicture(false);
412 status_t EmulatedCamera::cancelPicture()
414 ALOGV("%s", __FUNCTION__);
419 status_t EmulatedCamera::setParameters(const char* parms)
421 ALOGV("%s", __FUNCTION__);
422 PrintParamDiff(mParameters, parms);
424 CameraParameters new_param;
425 String8 str8_param(parms);
426 new_param.unflatten(str8_param);
429 * Check for new exposure compensation parameter.
431 int new_exposure_compensation = new_param.getInt(
432 CameraParameters::KEY_EXPOSURE_COMPENSATION);
433 const int min_exposure_compensation = new_param.getInt(
434 CameraParameters::KEY_MIN_EXPOSURE_COMPENSATION);
435 const int max_exposure_compensation = new_param.getInt(
436 CameraParameters::KEY_MAX_EXPOSURE_COMPENSATION);
438 // Checks if the exposure compensation change is supported.
439 if ((min_exposure_compensation != 0) || (max_exposure_compensation != 0)) {
440 if (new_exposure_compensation > max_exposure_compensation) {
441 new_exposure_compensation = max_exposure_compensation;
443 if (new_exposure_compensation < min_exposure_compensation) {
444 new_exposure_compensation = min_exposure_compensation;
447 const int current_exposure_compensation = mParameters.getInt(
448 CameraParameters::KEY_EXPOSURE_COMPENSATION);
449 if (current_exposure_compensation != new_exposure_compensation) {
450 const float exposure_value = new_exposure_compensation *
452 CameraParameters::KEY_EXPOSURE_COMPENSATION_STEP);
454 getCameraDevice()->setExposureCompensation(
459 const char* new_white_balance = new_param.get(
460 CameraParameters::KEY_WHITE_BALANCE);
461 const char* supported_white_balance = new_param.get(
462 CameraParameters::KEY_SUPPORTED_WHITE_BALANCE);
464 if ((supported_white_balance != NULL) && (new_white_balance != NULL) &&
465 (strstr(supported_white_balance, new_white_balance) != NULL)) {
467 const char* current_white_balance = mParameters.get(
468 CameraParameters::KEY_WHITE_BALANCE);
469 if ((current_white_balance == NULL) ||
470 (strcmp(current_white_balance, new_white_balance) != 0)) {
471 ALOGV("Setting white balance to %s", new_white_balance);
472 getCameraDevice()->setWhiteBalanceMode(new_white_balance);
476 mParameters = new_param;
481 /* A dumb variable indicating "no params" / error on the exit from
482 * EmulatedCamera::getParameters(). */
483 static char lNoParam = '\0';
484 char* EmulatedCamera::getParameters()
486 String8 params(mParameters.flatten());
488 reinterpret_cast<char*>(malloc(sizeof(char) * (params.length()+1)));
489 memset(ret_str, 0, params.length()+1);
490 if (ret_str != NULL) {
491 strncpy(ret_str, params.string(), params.length()+1);
494 ALOGE("%s: Unable to allocate string for %s", __FUNCTION__, params.string());
495 /* Apparently, we can't return NULL fron this routine. */
500 void EmulatedCamera::putParameters(char* params)
502 /* This method simply frees parameters allocated in getParameters(). */
503 if (params != NULL && params != &lNoParam) {
508 status_t EmulatedCamera::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2)
510 ALOGV("%s: cmd = %d, arg1 = %d, arg2 = %d", __FUNCTION__, cmd, arg1, arg2);
512 /* TODO: Future enhancements. */
516 void EmulatedCamera::releaseCamera()
518 ALOGV("%s", __FUNCTION__);
523 status_t EmulatedCamera::dumpCamera(int fd)
525 ALOGV("%s", __FUNCTION__);
527 /* TODO: Future enhancements. */
531 /****************************************************************************
532 * Preview management.
533 ***************************************************************************/
535 status_t EmulatedCamera::doStartPreview()
537 ALOGV("%s", __FUNCTION__);
539 EmulatedCameraDevice* camera_dev = getCameraDevice();
540 if (camera_dev->isStarted()) {
541 camera_dev->stopDeliveringFrames();
542 camera_dev->stopDevice();
545 status_t res = mPreviewWindow.startPreview();
546 if (res != NO_ERROR) {
550 /* Make sure camera device is connected. */
551 if (!camera_dev->isConnected()) {
552 res = camera_dev->connectDevice();
553 if (res != NO_ERROR) {
554 mPreviewWindow.stopPreview();
560 /* Lets see what should we use for frame width, and height. */
561 if (mParameters.get(CameraParameters::KEY_VIDEO_SIZE) != NULL) {
562 mParameters.getVideoSize(&width, &height);
564 mParameters.getPreviewSize(&width, &height);
566 /* Lets see what should we use for the frame pixel format. Note that there
567 * are two parameters that define pixel formats for frames sent to the
568 * application via notification callbacks:
569 * - KEY_VIDEO_FRAME_FORMAT, that is used when recording video, and
570 * - KEY_PREVIEW_FORMAT, that is used for preview frame notification.
571 * We choose one or the other, depending on "recording-hint" property set by
572 * the framework that indicating intention: video, or preview. */
573 const char* pix_fmt = NULL;
574 const char* is_video = mParameters.get(EmulatedCamera::RECORDING_HINT_KEY);
575 if (is_video == NULL) {
576 is_video = CameraParameters::FALSE;
578 if (strcmp(is_video, CameraParameters::TRUE) == 0) {
579 /* Video recording is requested. Lets see if video frame format is set. */
580 pix_fmt = mParameters.get(CameraParameters::KEY_VIDEO_FRAME_FORMAT);
582 /* If this was not video recording, or video frame format is not set, lets
583 * use preview pixel format for the main framebuffer. */
584 if (pix_fmt == NULL) {
585 pix_fmt = mParameters.getPreviewFormat();
587 if (pix_fmt == NULL) {
588 ALOGE("%s: Unable to obtain video format", __FUNCTION__);
589 mPreviewWindow.stopPreview();
593 /* Convert framework's pixel format to the FOURCC one. */
595 if (strcmp(pix_fmt, CameraParameters::PIXEL_FORMAT_YUV420P) == 0) {
596 org_fmt = V4L2_PIX_FMT_YUV420;
597 } else if (strcmp(pix_fmt, CameraParameters::PIXEL_FORMAT_RGBA8888) == 0) {
598 org_fmt = V4L2_PIX_FMT_RGB32;
599 } else if (strcmp(pix_fmt, CameraParameters::PIXEL_FORMAT_YUV420SP) == 0) {
600 org_fmt = V4L2_PIX_FMT_NV21;
602 ALOGE("%s: Unsupported pixel format %s", __FUNCTION__, pix_fmt);
603 mPreviewWindow.stopPreview();
606 ALOGD("Starting camera: %dx%d -> %.4s(%s)",
607 width, height, reinterpret_cast<const char*>(&org_fmt), pix_fmt);
608 res = camera_dev->startDevice(width, height, org_fmt);
609 if (res != NO_ERROR) {
610 mPreviewWindow.stopPreview();
614 res = camera_dev->startDeliveringFrames(false);
615 if (res != NO_ERROR) {
616 camera_dev->stopDevice();
617 mPreviewWindow.stopPreview();
623 status_t EmulatedCamera::doStopPreview()
625 ALOGV("%s", __FUNCTION__);
627 status_t res = NO_ERROR;
628 if (mPreviewWindow.isPreviewEnabled()) {
629 /* Stop the camera. */
630 if (getCameraDevice()->isStarted()) {
631 getCameraDevice()->stopDeliveringFrames();
632 res = getCameraDevice()->stopDevice();
635 if (res == NO_ERROR) {
636 /* Disable preview as well. */
637 mPreviewWindow.stopPreview();
644 /****************************************************************************
646 ***************************************************************************/
648 status_t EmulatedCamera::cleanupCamera()
650 status_t res = NO_ERROR;
652 /* If preview is running - stop it. */
653 res = doStopPreview();
654 if (res != NO_ERROR) {
658 /* Stop and disconnect the camera device. */
659 EmulatedCameraDevice* const camera_dev = getCameraDevice();
660 if (camera_dev != NULL) {
661 if (camera_dev->isStarted()) {
662 camera_dev->stopDeliveringFrames();
663 res = camera_dev->stopDevice();
664 if (res != NO_ERROR) {
668 if (camera_dev->isConnected()) {
669 res = camera_dev->disconnectDevice();
670 if (res != NO_ERROR) {
676 mCallbackNotifier.cleanupCBNotifier();
681 /****************************************************************************
682 * Camera API callbacks as defined by camera_device_ops structure.
684 * Callbacks here simply dispatch the calls to an appropriate method inside
685 * EmulatedCamera instance, defined by the 'dev' parameter.
686 ***************************************************************************/
688 int EmulatedCamera::set_preview_window(struct camera_device* dev,
689 struct preview_stream_ops* window)
691 EmulatedCamera* ec = reinterpret_cast<EmulatedCamera*>(dev->priv);
693 ALOGE("%s: Unexpected NULL camera device", __FUNCTION__);
696 return ec->setPreviewWindow(window);
699 void EmulatedCamera::set_callbacks(
700 struct camera_device* dev,
701 camera_notify_callback notify_cb,
702 camera_data_callback data_cb,
703 camera_data_timestamp_callback data_cb_timestamp,
704 camera_request_memory get_memory,
707 EmulatedCamera* ec = reinterpret_cast<EmulatedCamera*>(dev->priv);
709 ALOGE("%s: Unexpected NULL camera device", __FUNCTION__);
712 ec->setCallbacks(notify_cb, data_cb, data_cb_timestamp, get_memory, user);
715 void EmulatedCamera::enable_msg_type(struct camera_device* dev, int32_t msg_type)
717 EmulatedCamera* ec = reinterpret_cast<EmulatedCamera*>(dev->priv);
719 ALOGE("%s: Unexpected NULL camera device", __FUNCTION__);
722 ec->enableMsgType(msg_type);
725 void EmulatedCamera::disable_msg_type(struct camera_device* dev, int32_t msg_type)
727 EmulatedCamera* ec = reinterpret_cast<EmulatedCamera*>(dev->priv);
729 ALOGE("%s: Unexpected NULL camera device", __FUNCTION__);
732 ec->disableMsgType(msg_type);
735 int EmulatedCamera::msg_type_enabled(struct camera_device* dev, int32_t msg_type)
737 EmulatedCamera* ec = reinterpret_cast<EmulatedCamera*>(dev->priv);
739 ALOGE("%s: Unexpected NULL camera device", __FUNCTION__);
742 return ec->isMsgTypeEnabled(msg_type);
745 int EmulatedCamera::start_preview(struct camera_device* dev)
747 EmulatedCamera* ec = reinterpret_cast<EmulatedCamera*>(dev->priv);
749 ALOGE("%s: Unexpected NULL camera device", __FUNCTION__);
752 return ec->startPreview();
755 void EmulatedCamera::stop_preview(struct camera_device* dev)
757 EmulatedCamera* ec = reinterpret_cast<EmulatedCamera*>(dev->priv);
759 ALOGE("%s: Unexpected NULL camera device", __FUNCTION__);
765 int EmulatedCamera::preview_enabled(struct camera_device* dev)
767 EmulatedCamera* ec = reinterpret_cast<EmulatedCamera*>(dev->priv);
769 ALOGE("%s: Unexpected NULL camera device", __FUNCTION__);
772 return ec->isPreviewEnabled();
775 int EmulatedCamera::store_meta_data_in_buffers(struct camera_device* dev,
778 EmulatedCamera* ec = reinterpret_cast<EmulatedCamera*>(dev->priv);
780 ALOGE("%s: Unexpected NULL camera device", __FUNCTION__);
783 return ec->storeMetaDataInBuffers(enable);
786 int EmulatedCamera::start_recording(struct camera_device* dev)
788 EmulatedCamera* ec = reinterpret_cast<EmulatedCamera*>(dev->priv);
790 ALOGE("%s: Unexpected NULL camera device", __FUNCTION__);
793 return ec->startRecording();
796 void EmulatedCamera::stop_recording(struct camera_device* dev)
798 EmulatedCamera* ec = reinterpret_cast<EmulatedCamera*>(dev->priv);
800 ALOGE("%s: Unexpected NULL camera device", __FUNCTION__);
806 int EmulatedCamera::recording_enabled(struct camera_device* dev)
808 EmulatedCamera* ec = reinterpret_cast<EmulatedCamera*>(dev->priv);
810 ALOGE("%s: Unexpected NULL camera device", __FUNCTION__);
813 return ec->isRecordingEnabled();
816 void EmulatedCamera::release_recording_frame(struct camera_device* dev,
819 EmulatedCamera* ec = reinterpret_cast<EmulatedCamera*>(dev->priv);
821 ALOGE("%s: Unexpected NULL camera device", __FUNCTION__);
824 ec->releaseRecordingFrame(opaque);
827 int EmulatedCamera::auto_focus(struct camera_device* dev)
829 EmulatedCamera* ec = reinterpret_cast<EmulatedCamera*>(dev->priv);
831 ALOGE("%s: Unexpected NULL camera device", __FUNCTION__);
834 return ec->setAutoFocus();
837 int EmulatedCamera::cancel_auto_focus(struct camera_device* dev)
839 EmulatedCamera* ec = reinterpret_cast<EmulatedCamera*>(dev->priv);
841 ALOGE("%s: Unexpected NULL camera device", __FUNCTION__);
844 return ec->cancelAutoFocus();
847 int EmulatedCamera::take_picture(struct camera_device* dev)
849 EmulatedCamera* ec = reinterpret_cast<EmulatedCamera*>(dev->priv);
851 ALOGE("%s: Unexpected NULL camera device", __FUNCTION__);
854 return ec->takePicture();
857 int EmulatedCamera::cancel_picture(struct camera_device* dev)
859 EmulatedCamera* ec = reinterpret_cast<EmulatedCamera*>(dev->priv);
861 ALOGE("%s: Unexpected NULL camera device", __FUNCTION__);
864 return ec->cancelPicture();
867 int EmulatedCamera::set_parameters(struct camera_device* dev, const char* parms)
869 EmulatedCamera* ec = reinterpret_cast<EmulatedCamera*>(dev->priv);
871 ALOGE("%s: Unexpected NULL camera device", __FUNCTION__);
874 return ec->setParameters(parms);
877 char* EmulatedCamera::get_parameters(struct camera_device* dev)
879 EmulatedCamera* ec = reinterpret_cast<EmulatedCamera*>(dev->priv);
881 ALOGE("%s: Unexpected NULL camera device", __FUNCTION__);
884 return ec->getParameters();
887 void EmulatedCamera::put_parameters(struct camera_device* dev, char* params)
889 EmulatedCamera* ec = reinterpret_cast<EmulatedCamera*>(dev->priv);
891 ALOGE("%s: Unexpected NULL camera device", __FUNCTION__);
894 ec->putParameters(params);
897 int EmulatedCamera::send_command(struct camera_device* dev,
902 EmulatedCamera* ec = reinterpret_cast<EmulatedCamera*>(dev->priv);
904 ALOGE("%s: Unexpected NULL camera device", __FUNCTION__);
907 return ec->sendCommand(cmd, arg1, arg2);
910 void EmulatedCamera::release(struct camera_device* dev)
912 EmulatedCamera* ec = reinterpret_cast<EmulatedCamera*>(dev->priv);
914 ALOGE("%s: Unexpected NULL camera device", __FUNCTION__);
920 int EmulatedCamera::dump(struct camera_device* dev, int fd)
922 EmulatedCamera* ec = reinterpret_cast<EmulatedCamera*>(dev->priv);
924 ALOGE("%s: Unexpected NULL camera device", __FUNCTION__);
927 return ec->dumpCamera(fd);
930 int EmulatedCamera::close(struct hw_device_t* device)
933 reinterpret_cast<EmulatedCamera*>(reinterpret_cast<struct camera_device*>(device)->priv);
935 ALOGE("%s: Unexpected NULL camera device", __FUNCTION__);
938 return ec->closeCamera();
941 /****************************************************************************
942 * Static initializer for the camera callback API
943 ****************************************************************************/
945 camera_device_ops_t EmulatedCamera::mDeviceOps = {
946 EmulatedCamera::set_preview_window,
947 EmulatedCamera::set_callbacks,
948 EmulatedCamera::enable_msg_type,
949 EmulatedCamera::disable_msg_type,
950 EmulatedCamera::msg_type_enabled,
951 EmulatedCamera::start_preview,
952 EmulatedCamera::stop_preview,
953 EmulatedCamera::preview_enabled,
954 EmulatedCamera::store_meta_data_in_buffers,
955 EmulatedCamera::start_recording,
956 EmulatedCamera::stop_recording,
957 EmulatedCamera::recording_enabled,
958 EmulatedCamera::release_recording_frame,
959 EmulatedCamera::auto_focus,
960 EmulatedCamera::cancel_auto_focus,
961 EmulatedCamera::take_picture,
962 EmulatedCamera::cancel_picture,
963 EmulatedCamera::set_parameters,
964 EmulatedCamera::get_parameters,
965 EmulatedCamera::put_parameters,
966 EmulatedCamera::send_command,
967 EmulatedCamera::release,
971 /****************************************************************************
973 ***************************************************************************/
975 const char EmulatedCamera::FACING_KEY[] = "prop-facing";
976 const char EmulatedCamera::ORIENTATION_KEY[] = "prop-orientation";
977 const char EmulatedCamera::RECORDING_HINT_KEY[] = "recording-hint";
979 /****************************************************************************
980 * Common string values
981 ***************************************************************************/
983 const char EmulatedCamera::FACING_BACK[] = "back";
984 const char EmulatedCamera::FACING_FRONT[] = "front";
986 /****************************************************************************
988 ***************************************************************************/
990 static char* AddValue(const char* param, const char* val)
992 const size_t len1 = strlen(param);
993 const size_t len2 = strlen(val);
994 char* ret = reinterpret_cast<char*>(malloc(len1 + len2 + 2));
995 ALOGE_IF(ret == NULL, "%s: Memory failure", __FUNCTION__);
997 memcpy(ret, param, len1);
999 memcpy(ret + len1 + 1, val, len2);
1000 ret[len1 + len2 + 1] = '\0';
1005 /****************************************************************************
1006 * Parameter debugging helpers
1007 ***************************************************************************/
1010 static void PrintParamDiff(const CameraParameters& current,
1011 const char* new_par)
1014 const char* wrk = new_par;
1016 /* Divided with ';' */
1017 const char* next = strchr(wrk, ';');
1018 while (next != NULL) {
1019 snprintf(tmp, sizeof(tmp), "%.*s", (int)(intptr_t)(next-wrk), wrk);
1020 /* in the form key=value */
1021 char* val = strchr(tmp, '=');
1024 const char* in_current = current.get(tmp);
1025 if (in_current != NULL) {
1026 if (strcmp(in_current, val)) {
1027 ALOGD("=== Value changed: %s: %s -> %s", tmp, in_current, val);
1030 ALOGD("+++ New parameter: %s=%s", tmp, val);
1033 ALOGW("No value separator in %s", tmp);
1036 next = strchr(wrk, ';');
1039 #endif /* DEBUG_PARAM */
1041 }; /* namespace android */