Implements connection with the emulator

Change-Id: Ie3910a98e927f7b8ea556c403f8ced27e06bcdec
This commit is contained in:
Vladimir Chtchetkine
2011-09-13 05:27:29 -07:00
parent 455e444a1f
commit 33bda47528
21 changed files with 2015 additions and 261 deletions

View File

@@ -0,0 +1,120 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Contains implementation of a class EmulatedQemuCamera that encapsulates
* functionality of an emulated camera connected to the host.
*/
#define LOG_NDEBUG 0
#define LOG_TAG "EmulatedCamera_QemuCamera"
#include <cutils/log.h>
#include "emulated_qemu_camera.h"
#include "emulated_camera_factory.h"
namespace android {
EmulatedQemuCamera::EmulatedQemuCamera(int cameraId, struct hw_module_t* module)
: EmulatedCamera(cameraId, module),
qemu_camera_dev_(this)
{
}
EmulatedQemuCamera::~EmulatedQemuCamera()
{
}
/****************************************************************************
* EmulatedCamera virtual overrides.
***************************************************************************/
status_t EmulatedQemuCamera::Initialize(const char* device_name,
const char* frame_dims)
{
/* Save dimensions. */
frame_dims_ = frame_dims;
/* Initialize camera device. */
status_t res = qemu_camera_dev_.Initialize(device_name);
if (res != NO_ERROR) {
return res;
}
/* Initialize base class. */
res = EmulatedCamera::Initialize();
if (res != NO_ERROR) {
return res;
}
/*
* Set customizable parameters.
*/
const char* facing = EmulatedCamera::FACING_FRONT;
if (_emulated_camera_factory.GetQemuCameraOrientation() == CAMERA_FACING_BACK) {
facing = EmulatedCamera::FACING_BACK;
}
parameters_.set(EmulatedCamera::FACING_KEY, facing);
parameters_.set(EmulatedCamera::ORIENTATION_KEY,
_emulated_camera_factory.GetQemuCameraOrientation());
parameters_.set(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES, frame_dims);
parameters_.set(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES, frame_dims);
/*
* Use first dimension reported by the device to set current preview and
* picture sizes.
*/
char first_dim[128];
/* Dimensions are separated with ',' */
const char* c = strchr(frame_dims, ',');
if (c == NULL) {
strncpy(first_dim, frame_dims, sizeof(first_dim));
first_dim[sizeof(first_dim)-1] = '\0';
} else if ((c - frame_dims) < sizeof(first_dim)) {
memcpy(first_dim, frame_dims, c - frame_dims);
first_dim[c - frame_dims] = '\0';
} else {
memcpy(first_dim, frame_dims, sizeof(first_dim));
first_dim[sizeof(first_dim)-1] = '\0';
}
/* Width and height are separated with 'x' */
char* sep = strchr(first_dim, 'x');
if (sep == NULL) {
LOGE("%s: Invalid first dimension format in %s",
__FUNCTION__, frame_dims);
return EINVAL;
}
*sep = '\0';
const int x = atoi(first_dim);
const int y = atoi(sep + 1);
parameters_.setPreviewSize(x, y);
parameters_.setPictureSize(x, y);
LOGV("%s: Qemu camera %s is initialized. Current frame is %dx%d",
__FUNCTION__, device_name, x, y);
return NO_ERROR;
}
EmulatedCameraDevice* EmulatedQemuCamera::GetCameraDevice()
{
return &qemu_camera_dev_;
}
}; /* namespace android */