1 /*
2 * Copyright (C) 2011 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 /*
18 * Contains implementation of a class EmulatedFakeCamera that encapsulates
19 * functionality of a fake camera.
20 */
21
22 #define LOG_NDEBUG 0
23 #define LOG_TAG "EmulatedCamera_FakeCamera"
24 #include <log/log.h>
25 #include <cutils/properties.h>
26 #include "EmulatedFakeCamera.h"
27 #include "EmulatedCameraFactory.h"
28 #include "EmulatedFakeCameraDevice.h"
29 #include "EmulatedFakeRotatingCameraDevice.h"
30
31 namespace android {
32
EmulatedFakeCamera(int cameraId,bool facingBack,struct hw_module_t * module,GraphicBufferMapper * gbm)33 EmulatedFakeCamera::EmulatedFakeCamera(int cameraId,
34 bool facingBack,
35 struct hw_module_t* module,
36 GraphicBufferMapper* gbm)
37 : EmulatedCamera(cameraId, module, gbm),
38 mFacingBack(facingBack),
39 mFakeCameraDevice(nullptr)
40 {
41 const char *key = "ro.kernel.qemu.camera.fake.rotating";
42 char prop[PROPERTY_VALUE_MAX];
43 if (property_get(key, prop, nullptr) > 0) {
44 mFakeCameraDevice = new EmulatedFakeRotatingCameraDevice(this);
45 } else {
46 mFakeCameraDevice = new EmulatedFakeCameraDevice(this);
47 }
48 }
49
~EmulatedFakeCamera()50 EmulatedFakeCamera::~EmulatedFakeCamera()
51 {
52 delete mFakeCameraDevice;
53 }
54
55 /****************************************************************************
56 * Public API overrides
57 ***************************************************************************/
58
Initialize()59 status_t EmulatedFakeCamera::Initialize()
60 {
61 status_t res = mFakeCameraDevice->Initialize();
62 if (res != NO_ERROR) {
63 return res;
64 }
65
66 const char* facing = mFacingBack ? EmulatedCamera::FACING_BACK :
67 EmulatedCamera::FACING_FRONT;
68
69 mParameters.set(EmulatedCamera::FACING_KEY, facing);
70 ALOGD("%s: Fake camera is facing %s", __FUNCTION__, facing);
71
72 mParameters.set(EmulatedCamera::ORIENTATION_KEY,
73 gEmulatedCameraFactory.getFakeCameraOrientation());
74 mParameters.set(CameraParameters::KEY_ROTATION,
75 gEmulatedCameraFactory.getFakeCameraOrientation());
76
77 res = EmulatedCamera::Initialize();
78 if (res != NO_ERROR) {
79 return res;
80 }
81
82 /*
83 * Parameters provided by the camera device.
84 */
85
86 /* 352x288, 320x240 and 176x144 frame dimensions are required by
87 * the framework for video mode preview and video recording. */
88 mParameters.set(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES,
89 "1920x1080,1280x720,640x480,352x288,320x240");
90 mParameters.set(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES,
91 "1920x1080,1280x720,640x480,352x288,320x240,176x144");
92 mParameters.set(CameraParameters::KEY_SUPPORTED_VIDEO_SIZES,
93 "1920x1080,1280x720,640x480,352x288,320x240,176x144");
94 mParameters.set(CameraParameters::KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO,
95 "1920x1080");
96
97 mParameters.setPreviewSize(1920, 1080);
98 mParameters.setPictureSize(1920, 1080);
99
100 return NO_ERROR;
101 }
102
getCameraDevice()103 EmulatedCameraDevice* EmulatedFakeCamera::getCameraDevice()
104 {
105 return mFakeCameraDevice;
106 }
107
108 }; /* namespace android */
109