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 EmulatedQemuCamera that encapsulates
19 * functionality of an emulated camera connected to the host.
23 #define LOG_TAG "EmulatedCamera_QemuCamera"
24 #include <cutils/log.h>
25 #include "EmulatedQemuCamera.h"
26 #include "EmulatedCameraFactory.h"
30 EmulatedQemuCamera::EmulatedQemuCamera(int cameraId, struct hw_module_t* module)
31 : EmulatedCamera(cameraId, module),
32 mQemuCameraDevice(this)
36 EmulatedQemuCamera::~EmulatedQemuCamera()
40 /****************************************************************************
41 * EmulatedCamera virtual overrides.
42 ***************************************************************************/
44 status_t EmulatedQemuCamera::Initialize(const char* device_name,
45 const char* frame_dims,
46 const char* facing_dir)
48 ALOGV("%s:\n Name=%s\n Facing '%s'\n Dimensions=%s",
49 __FUNCTION__, device_name, facing_dir, frame_dims);
50 /* Save dimensions. */
51 mFrameDims = frame_dims;
53 /* Initialize camera device. */
54 status_t res = mQemuCameraDevice.Initialize(device_name);
55 if (res != NO_ERROR) {
59 /* Initialize base class. */
60 res = EmulatedCamera::Initialize();
61 if (res != NO_ERROR) {
66 * Set customizable parameters.
69 mParameters.set(EmulatedCamera::FACING_KEY, facing_dir);
70 mParameters.set(EmulatedCamera::ORIENTATION_KEY,
71 gEmulatedCameraFactory.getQemuCameraOrientation());
72 mParameters.set(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES, frame_dims);
73 mParameters.set(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES, frame_dims);
76 * Use first dimension reported by the device to set current preview and
81 /* Dimensions are separated with ',' */
82 const char* c = strchr(frame_dims, ',');
84 strncpy(first_dim, frame_dims, sizeof(first_dim));
85 first_dim[sizeof(first_dim)-1] = '\0';
86 } else if (static_cast<size_t>(c - frame_dims) < sizeof(first_dim)) {
87 memcpy(first_dim, frame_dims, c - frame_dims);
88 first_dim[c - frame_dims] = '\0';
90 memcpy(first_dim, frame_dims, sizeof(first_dim));
91 first_dim[sizeof(first_dim)-1] = '\0';
94 /* Width and height are separated with 'x' */
95 char* sep = strchr(first_dim, 'x');
97 ALOGE("%s: Invalid first dimension format in %s",
98 __FUNCTION__, frame_dims);
103 const int x = atoi(first_dim);
104 const int y = atoi(sep + 1);
105 mParameters.setPreviewSize(x, y);
106 mParameters.setPictureSize(x, y);
108 ALOGV("%s: Qemu camera %s is initialized. Current frame is %dx%d",
109 __FUNCTION__, device_name, x, y);
114 EmulatedCameraDevice* EmulatedQemuCamera::getCameraDevice()
116 return &mQemuCameraDevice;
119 }; /* namespace android */