blob: af1e32499a8e41fbaef43ff27897c7493a8e174f
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 EmulatedQemuCamera that encapsulates |
19 | * functionality of an emulated camera connected to the host. |
20 | */ |
21 | |
22 | #define LOG_NDEBUG 0 |
23 | #define LOG_TAG "EmulatedCamera_QemuCamera" |
24 | #include <cutils/log.h> |
25 | #include "EmulatedQemuCamera.h" |
26 | #include "EmulatedCameraFactory.h" |
27 | |
28 | namespace android { |
29 | |
30 | EmulatedQemuCamera::EmulatedQemuCamera(int cameraId, struct hw_module_t* module) |
31 | : EmulatedCamera(cameraId, module), |
32 | mQemuCameraDevice(this) |
33 | { |
34 | } |
35 | |
36 | EmulatedQemuCamera::~EmulatedQemuCamera() |
37 | { |
38 | } |
39 | |
40 | /**************************************************************************** |
41 | * EmulatedCamera virtual overrides. |
42 | ***************************************************************************/ |
43 | |
44 | status_t EmulatedQemuCamera::Initialize(const char* device_name, |
45 | const char* frame_dims, |
46 | const char* facing_dir) |
47 | { |
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; |
52 | |
53 | /* Initialize camera device. */ |
54 | status_t res = mQemuCameraDevice.Initialize(device_name); |
55 | if (res != NO_ERROR) { |
56 | return res; |
57 | } |
58 | |
59 | /* Initialize base class. */ |
60 | res = EmulatedCamera::Initialize(); |
61 | if (res != NO_ERROR) { |
62 | return res; |
63 | } |
64 | |
65 | /* |
66 | * Set customizable parameters. |
67 | */ |
68 | |
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); |
74 | |
75 | /* |
76 | * Use first dimension reported by the device to set current preview and |
77 | * picture sizes. |
78 | */ |
79 | |
80 | char first_dim[128]; |
81 | /* Dimensions are separated with ',' */ |
82 | const char* c = strchr(frame_dims, ','); |
83 | if (c == NULL) { |
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'; |
89 | } else { |
90 | memcpy(first_dim, frame_dims, sizeof(first_dim)); |
91 | first_dim[sizeof(first_dim)-1] = '\0'; |
92 | } |
93 | |
94 | /* Width and height are separated with 'x' */ |
95 | char* sep = strchr(first_dim, 'x'); |
96 | if (sep == NULL) { |
97 | ALOGE("%s: Invalid first dimension format in %s", |
98 | __FUNCTION__, frame_dims); |
99 | return EINVAL; |
100 | } |
101 | |
102 | *sep = '\0'; |
103 | const int x = atoi(first_dim); |
104 | const int y = atoi(sep + 1); |
105 | mParameters.setPreviewSize(x, y); |
106 | mParameters.setPictureSize(x, y); |
107 | |
108 | ALOGV("%s: Qemu camera %s is initialized. Current frame is %dx%d", |
109 | __FUNCTION__, device_name, x, y); |
110 | |
111 | return NO_ERROR; |
112 | } |
113 | |
114 | EmulatedCameraDevice* EmulatedQemuCamera::getCameraDevice() |
115 | { |
116 | return &mQemuCameraDevice; |
117 | } |
118 | |
119 | }; /* namespace android */ |
120 |