Refactored emulated camera HAL to comply with code style

Change-Id: If57b536ae6b1f9bad4213630488591a3b3cc9fdd
This commit is contained in:
Vladimir Chtchetkine
2011-09-13 14:35:25 -07:00
parent 492332c295
commit 5467be2eef
25 changed files with 1091 additions and 1088 deletions

22
tools/emulator/system/camera/Android.mk Normal file → Executable file
View File

@@ -29,17 +29,17 @@ LOCAL_SHARED_LIBRARIES:= \
libui \
LOCAL_SRC_FILES := \
emulated_camera_hal.cpp \
emulated_camera_factory.cpp \
emulated_camera.cpp \
emulated_camera_device.cpp \
emulated_qemu_camera.cpp \
emulated_qemu_camera_device.cpp \
emulated_fake_camera.cpp \
emulated_fake_camera_device.cpp \
converters.cpp \
preview_window.cpp \
callback_notifier.cpp \
EmulatedCameraHal.cpp \
EmulatedCameraFactory.cpp \
EmulatedCamera.cpp \
EmulatedCameraDevice.cpp \
EmulatedQemuCamera.cpp \
EmulatedQemuCameraDevice.cpp \
EmulatedFakeCamera.cpp \
EmulatedFakeCameraDevice.cpp \
Converters.cpp \
PreviewWindow.cpp \
CallbackNotifier.cpp \
QemuClient.cpp
ifeq ($(TARGET_PRODUCT),vbox_x86)

View File

@@ -23,13 +23,13 @@
#define LOG_TAG "EmulatedCamera_CallbackNotifier"
#include <cutils/log.h>
#include <media/stagefright/MetadataBufferType.h>
#include "emulated_camera_device.h"
#include "callback_notifier.h"
#include "EmulatedCameraDevice.h"
#include "CallbackNotifier.h"
namespace android {
/* String representation of camera messages. */
static const char* _camera_messages[] =
static const char* lCameraMessages[] =
{
"CAMERA_MSG_ERROR",
"CAMERA_MSG_SHUTTER",
@@ -43,7 +43,7 @@ static const char* _camera_messages[] =
"CAMERA_MSG_RAW_IMAGE_NOTIFY",
"CAMERA_MSG_PREVIEW_METADATA"
};
static const int _camera_messages_num = sizeof(_camera_messages) / sizeof(char*);
static const int lCameraMessagesNum = sizeof(lCameraMessages) / sizeof(char*);
/* Builds an array of strings for the given set of messages.
* Param:
@@ -53,17 +53,17 @@ static const int _camera_messages_num = sizeof(_camera_messages) / sizeof(char*)
* Return:
* Number of strings saved into the 'strings' array.
*/
static int _GetMessageStrings(uint32_t msg, const char** strings, int max)
static int GetMessageStrings(uint32_t msg, const char** strings, int max)
{
int index = 0;
int out = 0;
while (msg != 0 && out < max && index < _camera_messages_num) {
while ((msg & 0x1) == 0 && index < _camera_messages_num) {
while (msg != 0 && out < max && index < lCameraMessagesNum) {
while ((msg & 0x1) == 0 && index < lCameraMessagesNum) {
msg >>= 1;
index++;
}
if ((msg & 0x1) != 0 && index < _camera_messages_num) {
strings[out] = _camera_messages[index];
if ((msg & 0x1) != 0 && index < lCameraMessagesNum) {
strings[out] = lCameraMessages[index];
out++;
msg >>= 1;
index++;
@@ -74,25 +74,25 @@ static int _GetMessageStrings(uint32_t msg, const char** strings, int max)
}
/* Logs messages, enabled by the mask. */
static void _PrintMessages(uint32_t msg)
static void PrintMessages(uint32_t msg)
{
const char* strs[_camera_messages_num];
const int translated = _GetMessageStrings(msg, strs, _camera_messages_num);
const char* strs[lCameraMessagesNum];
const int translated = GetMessageStrings(msg, strs, lCameraMessagesNum);
for (int n = 0; n < translated; n++) {
LOGV(" %s", strs[n]);
}
}
CallbackNotifier::CallbackNotifier()
: notify_cb_(NULL),
data_cb_(NULL),
data_cb_timestamp_(NULL),
get_memory_(NULL),
cb_opaque_(NULL),
last_frame_(0),
frame_after_(0),
message_enabler_(0),
video_recording_enabled_(false)
: mNotifyCB(NULL),
mDataCB(NULL),
mDdataCBTimestamp(NULL),
mGetMemoryCB(NULL),
mCBOpaque(NULL),
mLastFrameTimestamp(0),
mFrameRefreshFreq(0),
mMessageEnabler(0),
mVideoRecEnabled(false)
{
}
@@ -104,7 +104,7 @@ CallbackNotifier::~CallbackNotifier()
* Camera API
***************************************************************************/
void CallbackNotifier::SetCallbacks(camera_notify_callback notify_cb,
void CallbackNotifier::setCallbacks(camera_notify_callback notify_cb,
camera_data_callback data_cb,
camera_data_timestamp_callback data_cb_timestamp,
camera_request_memory get_memory,
@@ -113,77 +113,77 @@ void CallbackNotifier::SetCallbacks(camera_notify_callback notify_cb,
LOGV("%s: %p, %p, %p, %p (%p)",
__FUNCTION__, notify_cb, data_cb, data_cb_timestamp, get_memory, user);
Mutex::Autolock locker(&object_lock_);
notify_cb_ = notify_cb;
data_cb_ = data_cb;
data_cb_timestamp_ = data_cb_timestamp;
get_memory_ = get_memory;
cb_opaque_ = user;
Mutex::Autolock locker(&mObjectLock);
mNotifyCB = notify_cb;
mDataCB = data_cb;
mDdataCBTimestamp = data_cb_timestamp;
mGetMemoryCB = get_memory;
mCBOpaque = user;
}
void CallbackNotifier::EnableMessage(uint msg_type)
void CallbackNotifier::enableMessage(uint msg_type)
{
LOGV("%s: msg_type = 0x%x", __FUNCTION__, msg_type);
_PrintMessages(msg_type);
PrintMessages(msg_type);
Mutex::Autolock locker(&object_lock_);
message_enabler_ |= msg_type;
Mutex::Autolock locker(&mObjectLock);
mMessageEnabler |= msg_type;
LOGV("**** Currently enabled messages:");
_PrintMessages(message_enabler_);
PrintMessages(mMessageEnabler);
}
void CallbackNotifier::DisableMessage(uint msg_type)
void CallbackNotifier::disableMessage(uint msg_type)
{
LOGV("%s: msg_type = 0x%x", __FUNCTION__, msg_type);
_PrintMessages(msg_type);
PrintMessages(msg_type);
Mutex::Autolock locker(&object_lock_);
message_enabler_ &= ~msg_type;
Mutex::Autolock locker(&mObjectLock);
mMessageEnabler &= ~msg_type;
LOGV("**** Currently enabled messages:");
_PrintMessages(message_enabler_);
PrintMessages(mMessageEnabler);
}
int CallbackNotifier::IsMessageEnabled(uint msg_type)
int CallbackNotifier::isMessageEnabled(uint msg_type)
{
Mutex::Autolock locker(&object_lock_);
return message_enabler_ & ~msg_type;
Mutex::Autolock locker(&mObjectLock);
return mMessageEnabler & ~msg_type;
}
status_t CallbackNotifier::EnableVideoRecording(int fps)
status_t CallbackNotifier::enableVideoRecording(int fps)
{
LOGV("%s: FPS = %d", __FUNCTION__, fps);
Mutex::Autolock locker(&object_lock_);
video_recording_enabled_ = true;
last_frame_ = 0;
frame_after_ = 1000000000LL / fps;
Mutex::Autolock locker(&mObjectLock);
mVideoRecEnabled = true;
mLastFrameTimestamp = 0;
mFrameRefreshFreq = 1000000000LL / fps;
return NO_ERROR;
}
void CallbackNotifier::DisableVideoRecording()
void CallbackNotifier::disableVideoRecording()
{
LOGV("%s:", __FUNCTION__);
Mutex::Autolock locker(&object_lock_);
video_recording_enabled_ = false;
last_frame_ = 0;
frame_after_ = 0;
Mutex::Autolock locker(&mObjectLock);
mVideoRecEnabled = false;
mLastFrameTimestamp = 0;
mFrameRefreshFreq = 0;
}
bool CallbackNotifier::IsVideoRecordingEnabled()
bool CallbackNotifier::isVideoRecordingEnabled()
{
Mutex::Autolock locker(&object_lock_);
return video_recording_enabled_;
Mutex::Autolock locker(&mObjectLock);
return mVideoRecEnabled;
}
void CallbackNotifier::ReleaseRecordingFrame(const void* opaque)
void CallbackNotifier::releaseRecordingFrame(const void* opaque)
{
/* We don't really have anything to release here, since we report video
* frames by copying them directly to the camera memory. */
}
status_t CallbackNotifier::StoreMetaDataInBuffers(bool enable)
status_t CallbackNotifier::storeMetaDataInBuffers(bool enable)
{
/* Return INVALID_OPERATION means HAL does not support metadata. So HAL will
* return actual frame data with CAMERA_MSG_VIDEO_FRRAME. Return
@@ -195,35 +195,35 @@ status_t CallbackNotifier::StoreMetaDataInBuffers(bool enable)
* Public API
***************************************************************************/
void CallbackNotifier::Cleanup()
void CallbackNotifier::cleanupCBNotifier()
{
Mutex::Autolock locker(&object_lock_);
message_enabler_ = 0;
notify_cb_ = NULL;
data_cb_ = NULL;
data_cb_timestamp_ = NULL;
get_memory_ = NULL;
cb_opaque_ = NULL;
last_frame_ = 0;
frame_after_ = 0;
video_recording_enabled_ = false;
Mutex::Autolock locker(&mObjectLock);
mMessageEnabler = 0;
mNotifyCB = NULL;
mDataCB = NULL;
mDdataCBTimestamp = NULL;
mGetMemoryCB = NULL;
mCBOpaque = NULL;
mLastFrameTimestamp = 0;
mFrameRefreshFreq = 0;
mVideoRecEnabled = false;
}
void CallbackNotifier::OnNextFrameAvailable(const void* frame,
void CallbackNotifier::onNextFrameAvailable(const void* frame,
nsecs_t timestamp,
EmulatedCameraDevice* camera_dev)
{
Mutex::Autolock locker(&object_lock_);
Mutex::Autolock locker(&mObjectLock);
if ((message_enabler_ & CAMERA_MSG_VIDEO_FRAME) != 0 &&
data_cb_timestamp_ != NULL && video_recording_enabled_ &&
IsTimeForNewVideoFrame(timestamp)) {
if ((mMessageEnabler & CAMERA_MSG_VIDEO_FRAME) != 0 &&
mDdataCBTimestamp != NULL && mVideoRecEnabled &&
isNewVideoFrameTime(timestamp)) {
camera_memory_t* cam_buff =
get_memory_(-1, camera_dev->GetFrameBufferSize(), 1, NULL);
mGetMemoryCB(-1, camera_dev->getFrameBufferSize(), 1, NULL);
if (NULL != cam_buff && NULL != cam_buff->data) {
memcpy(cam_buff->data, frame, camera_dev->GetFrameBufferSize());
data_cb_timestamp_(timestamp, CAMERA_MSG_VIDEO_FRAME,
cam_buff, 0, cb_opaque_);
memcpy(cam_buff->data, frame, camera_dev->getFrameBufferSize());
mDdataCBTimestamp(timestamp, CAMERA_MSG_VIDEO_FRAME,
cam_buff, 0, mCBOpaque);
} else {
LOGE("%s: Memory failure in CAMERA_MSG_VIDEO_FRAME", __FUNCTION__);
}
@@ -234,10 +234,10 @@ void CallbackNotifier::OnNextFrameAvailable(const void* frame,
* Private API
***************************************************************************/
bool CallbackNotifier::IsTimeForNewVideoFrame(nsecs_t timestamp)
bool CallbackNotifier::isNewVideoFrameTime(nsecs_t timestamp)
{
if ((timestamp - last_frame_) >= frame_after_) {
last_frame_ = timestamp;
if ((timestamp - mLastFrameTimestamp) >= mFrameRefreshFreq) {
mLastFrameTimestamp = timestamp;
return true;
}
return false;

View File

@@ -49,7 +49,7 @@ public:
* This method is called by the containing emulated camera object when it is
* handing the camera_device_ops_t::set_callbacks callback.
*/
void SetCallbacks(camera_notify_callback notify_cb,
void setCallbacks(camera_notify_callback notify_cb,
camera_data_callback data_cb,
camera_data_timestamp_callback data_cb_timestamp,
camera_request_memory get_memory,
@@ -59,13 +59,13 @@ public:
* This method is called by the containing emulated camera object when it is
* handing the camera_device_ops_t::enable_msg_type callback.
*/
void EnableMessage(uint msg_type);
void enableMessage(uint msg_type);
/* Actual handler for camera_device_ops_t::disable_msg_type callback.
* This method is called by the containing emulated camera object when it is
* handing the camera_device_ops_t::disable_msg_type callback.
*/
void DisableMessage(uint msg_type);
void disableMessage(uint msg_type);
/* Actual handler for camera_device_ops_t::msg_type_enabled callback.
* This method is called by the containing emulated camera object when it is
@@ -73,7 +73,7 @@ public:
* Return:
* 0 if message is disabled, or non-zero value, if message is enabled.
*/
int IsMessageEnabled(uint msg_type);
int isMessageEnabled(uint msg_type);
/* Actual handler for camera_device_ops_t::store_meta_data_in_buffers
* callback. This method is called by the containing emulated camera object
@@ -82,25 +82,25 @@ public:
* Return:
* NO_ERROR on success, or an appropriate error status.
*/
status_t StoreMetaDataInBuffers(bool enable);
status_t storeMetaDataInBuffers(bool enable);
/* Enables video recording.
* This method is called by the containing emulated camera object when it is
* handing the camera_device_ops_t::start_recording callback.
* Param:
* fps - Video frame frequency. This parameter determins when a frame
* received via OnNextFrameAvailable call will be pushed through the
* received via onNextFrameAvailable call will be pushed through the
* callback.
* Return:
* NO_ERROR on success, or an appropriate error status.
*/
status_t EnableVideoRecording(int fps);
status_t enableVideoRecording(int fps);
/* Disables video recording.
* This method is called by the containing emulated camera object when it is
* handing the camera_device_ops_t::stop_recording callback.
*/
void DisableVideoRecording();
void disableVideoRecording();
/* Checks id video recording is enabled.
* This method is called by the containing emulated camera object when it is
@@ -108,13 +108,13 @@ public:
* Return:
* true if video recording is enabled, or false if it is disabled.
*/
bool IsVideoRecordingEnabled();
bool isVideoRecordingEnabled();
/* Releases video frame, sent to the framework.
* This method is called by the containing emulated camera object when it is
* handing the camera_device_ops_t::release_recording_frame callback.
*/
void ReleaseRecordingFrame(const void* opaque);
void releaseRecordingFrame(const void* opaque);
/****************************************************************************
* Public API
@@ -122,7 +122,7 @@ public:
public:
/* Resets the callback notifier. */
void Cleanup();
void cleanupCBNotifier();
/* Next frame is available in the camera device.
* This is a notification callback that is invoked by the camera device when
@@ -139,7 +139,7 @@ public:
* timestamp - Frame's timestamp.
* camera_dev - Camera device instance that delivered the frame.
*/
void OnNextFrameAvailable(const void* frame,
void onNextFrameAvailable(const void* frame,
nsecs_t timestamp,
EmulatedCameraDevice* camera_dev);
@@ -152,7 +152,7 @@ protected:
* Note that this method must be called while object is locked.
* Param:
* timestamp - Timestamp for the new frame. */
bool IsTimeForNewVideoFrame(nsecs_t timestamp);
bool isNewVideoFrameTime(nsecs_t timestamp);
/****************************************************************************
* Data members
@@ -160,29 +160,29 @@ protected:
protected:
/* Locks this instance for data change. */
Mutex object_lock_;
Mutex mObjectLock;
/*
* Callbacks, registered in set_callbacks.
*/
camera_notify_callback notify_cb_;
camera_data_callback data_cb_;
camera_data_timestamp_callback data_cb_timestamp_;
camera_request_memory get_memory_;
void* cb_opaque_;
camera_notify_callback mNotifyCB;
camera_data_callback mDataCB;
camera_data_timestamp_callback mDdataCBTimestamp;
camera_request_memory mGetMemoryCB;
void* mCBOpaque;
/* Timestamp when last frame has been delivered to the framework. */
nsecs_t last_frame_;
nsecs_t mLastFrameTimestamp;
/* Video frequency in nanosec. */
nsecs_t frame_after_;
nsecs_t mFrameRefreshFreq;
/* Message enabler. */
uint32_t message_enabler_;
uint32_t mMessageEnabler;
/* Video recording status. */
bool video_recording_enabled_;
bool mVideoRecEnabled;
};
}; /* namespace android */

View File

@@ -21,7 +21,7 @@
#define LOG_NDEBUG 0
#define LOG_TAG "EmulatedCamera_Converter"
#include <cutils/log.h>
#include "converters.h"
#include "Converters.h"
namespace android {
@@ -30,26 +30,26 @@ void YV12ToRGB565(const void* yv12, void* rgb, int width, int height)
const int pix_total = width * height;
uint16_t* rgb_buf = reinterpret_cast<uint16_t*>(rgb);
const uint8_t* Y = reinterpret_cast<const uint8_t*>(yv12);
const uint8_t* Cb_pos = Y + pix_total;
const uint8_t* Cr_pos = Cb_pos + pix_total / 4;
const uint8_t* Cb = Cb_pos;
const uint8_t* Cr = Cr_pos;
const uint8_t* U_pos = Y + pix_total;
const uint8_t* V_pos = U_pos + pix_total / 4;
const uint8_t* U = U_pos;
const uint8_t* V = V_pos;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x += 2) {
const uint8_t nCb = *Cb; Cb++;
const uint8_t nCr = *Cr; Cr++;
*rgb_buf = YUVToRGB565(*Y, nCb, nCr);
const uint8_t nU = *U; U++;
const uint8_t nV = *V; V++;
*rgb_buf = YUVToRGB565(*Y, nU, nV);
Y++; rgb_buf++;
*rgb_buf = YUVToRGB565(*Y, nCb, nCr);
*rgb_buf = YUVToRGB565(*Y, nU, nV);
Y++; rgb_buf++;
}
if (y & 0x1) {
Cb_pos = Cb;
Cr_pos = Cr;
U_pos = U;
V_pos = V;
} else {
Cb = Cb_pos;
Cr = Cr_pos;
U = U_pos;
V = V_pos;
}
}
}
@@ -59,26 +59,26 @@ void YV12ToRGB32(const void* yv12, void* rgb, int width, int height)
const int pix_total = width * height;
uint32_t* rgb_buf = reinterpret_cast<uint32_t*>(rgb);
const uint8_t* Y = reinterpret_cast<const uint8_t*>(yv12);
const uint8_t* Cb_pos = Y + pix_total;
const uint8_t* Cr_pos = Cb_pos + pix_total / 4;
const uint8_t* Cb = Cb_pos;
const uint8_t* Cr = Cr_pos;
const uint8_t* U_pos = Y + pix_total;
const uint8_t* V_pos = U_pos + pix_total / 4;
const uint8_t* U = U_pos;
const uint8_t* V = V_pos;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x += 2) {
const uint8_t nCb = *Cb; Cb++;
const uint8_t nCr = *Cr; Cr++;
*rgb_buf = YUVToRGB32(*Y, nCb, nCr);
const uint8_t nU = *U; U++;
const uint8_t nV = *V; V++;
*rgb_buf = YUVToRGB32(*Y, nU, nV);
Y++; rgb_buf++;
*rgb_buf = YUVToRGB32(*Y, nCb, nCr);
*rgb_buf = YUVToRGB32(*Y, nU, nV);
Y++; rgb_buf++;
}
if (y & 0x1) {
Cb_pos = Cb;
Cr_pos = Cr;
U_pos = U;
V_pos = V;
} else {
Cb = Cb_pos;
Cr = Cr_pos;
U = U_pos;
V = V_pos;
}
}
}

View File

@@ -83,9 +83,9 @@ static const uint32_t kWhite32 = kRed8 | kGreen8 | kBlue8;
#define G16(rgb) static_cast<uint8_t>((rgb & kGreen6) >> 5)
#define B16(rgb) static_cast<uint8_t>((rgb & kBlue5) >> 11)
/* Make 8 bits red, green, and blue, extracted from RGB565 word. */
#define R16_32(rgb) (uint8_t)(((rgb & kRed5) << 3) | ((rgb & kRed5) >> 2))
#define G16_32(rgb) (uint8_t)(((rgb & kGreen6) >> 3) | ((rgb & kGreen6) >> 9))
#define B16_32(rgb) (uint8_t)(((rgb & kBlue5) >> 8) | ((rgb & kBlue5) >> 14))
#define R16_32(rgb) static_cast<uint8_t>(((rgb & kRed5) << 3) | ((rgb & kRed5) >> 2))
#define G16_32(rgb) static_cast<uint8_t>(((rgb & kGreen6) >> 3) | ((rgb & kGreen6) >> 9))
#define B16_32(rgb) static_cast<uint8_t>(((rgb & kBlue5) >> 8) | ((rgb & kBlue5) >> 14))
/* Extract red, green, and blue bytes from RGB32 dword. */
#define R32(rgb) static_cast<uint8_t>(rgb & kRed8)
#define G32(rgb) static_cast<uint8_t>(((rgb & kGreen8) >> 8) & 0xff)
@@ -100,9 +100,9 @@ static const uint32_t kWhite32 = kRed8 | kGreen8 | kBlue8;
#define G16(rgb) static_cast<uint8_t>((rgb & kGreen6) >> 5)
#define B16(rgb) static_cast<uint8_t>(rgb & kBlue5)
/* Make 8 bits red, green, and blue, extracted from RGB565 word. */
#define R16_32(rgb) (uint8_t)(((rgb & kRed5) >> 8) | ((rgb & kRed5) >> 14))
#define G16_32(rgb) (uint8_t)(((rgb & kGreen6) >> 3) | ((rgb & kGreen6) >> 9))
#define B16_32(rgb) (uint8_t)(((rgb & kBlue5) << 3) | ((rgb & kBlue5) >> 2))
#define R16_32(rgb) static_cast<uint8_t>(((rgb & kRed5) >> 8) | ((rgb & kRed5) >> 14))
#define G16_32(rgb) static_cast<uint8_t>(((rgb & kGreen6) >> 3) | ((rgb & kGreen6) >> 9))
#define B16_32(rgb) static_cast<uint8_t>(((rgb & kBlue5) << 3) | ((rgb & kBlue5) >> 2))
/* Extract red, green, and blue bytes from RGB32 dword. */
#define R32(rgb) static_cast<uint8_t>((rgb & kRed8) >> 16)
#define G32(rgb) static_cast<uint8_t>((rgb & kGreen8) >> 8)
@@ -226,30 +226,30 @@ YUVToRGB32(int y, int u, int v)
return rgb.color;
}
/* YCbCr pixel descriptor. */
/* YUV pixel descriptor. */
struct YUVPixel {
uint8_t Y;
uint8_t Cb;
uint8_t Cr;
uint8_t U;
uint8_t V;
inline YUVPixel()
: Y(0), Cb(0), Cr(0)
: Y(0), U(0), V(0)
{
}
inline explicit YUVPixel(uint16_t rgb565)
{
RGB565ToYUV(rgb565, &Y, &Cb, &Cr);
RGB565ToYUV(rgb565, &Y, &U, &V);
}
inline explicit YUVPixel(uint32_t rgb32)
{
RGB32ToYUV(rgb32, &Y, &Cb, &Cr);
RGB32ToYUV(rgb32, &Y, &U, &V);
}
inline void get(uint8_t* pY, uint8_t* pCb, uint8_t* pCr) const
inline void get(uint8_t* pY, uint8_t* pU, uint8_t* pV) const
{
*pY = Y; *pCb = Cb; *pCr = Cr;
*pY = Y; *pU = U; *pV = V;
}
};

View File

@@ -27,9 +27,9 @@
#define LOG_TAG "EmulatedCamera_Camera"
#include <cutils/log.h>
#include <ui/Rect.h>
#include "emulated_camera.h"
#include "emulated_fake_camera_device.h"
#include "converters.h"
#include "EmulatedCamera.h"
#include "EmulatedFakeCameraDevice.h"
#include "Converters.h"
/* Defines whether we should trace parameter changes. */
#define DEBUG_PARAM 1
@@ -42,9 +42,9 @@ namespace android {
* current - Current set of camera parameters.
* new_par - String representation of new parameters.
*/
static void _PrintParamDiff(const CameraParameters& current, const char* new_par);
static void PrintParamDiff(const CameraParameters& current, const char* new_par);
#else
#define _PrintParamDiff(current, new_par) (void(0))
#define PrintParamDiff(current, new_par) (void(0))
#endif /* DEBUG_PARAM */
/* A helper routine that adds a value to the camera parameter.
@@ -56,12 +56,12 @@ static void _PrintParamDiff(const CameraParameters& current, const char* new_par
* a failure. If non-NULL string is returned, the caller is responsible for
* freeing it with 'free'.
*/
static char* _AddValue(const char* param, const char* val);
static char* AddValue(const char* param, const char* val);
EmulatedCamera::EmulatedCamera(int cameraId, struct hw_module_t* module)
: preview_window_(),
callback_notifier_(),
camera_id_(cameraId)
: mPreviewWindow(),
mCallbackNotifier(),
mCameraID(cameraId)
{
/*
* Initialize camera_device descriptor for this object.
@@ -74,7 +74,7 @@ EmulatedCamera::EmulatedCamera(int cameraId, struct hw_module_t* module)
common.close = EmulatedCamera::close;
/* camera_device fields. */
ops = &device_ops_;
ops = &mDeviceOps;
priv = this;
}
@@ -95,77 +95,77 @@ status_t EmulatedCamera::Initialize()
*/
/* Only RGBX are supported by the framework for preview window in the emulator! */
parameters_.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS, CameraParameters::PIXEL_FORMAT_RGBA8888);
parameters_.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES, "60,50,25,15,10");
parameters_.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FPS_RANGE, "(10,60)");
parameters_.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, "10,60");
parameters_.set(CameraParameters::KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES, "320x240,0x0");
parameters_.set(CameraParameters::KEY_MAX_EXPOSURE_COMPENSATION, "6");
parameters_.set(CameraParameters::KEY_MIN_EXPOSURE_COMPENSATION, "-6");
parameters_.set(CameraParameters::KEY_EXPOSURE_COMPENSATION_STEP, "0.5");
parameters_.set(CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH, "512");
parameters_.set(CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT, "384");
parameters_.set(CameraParameters::KEY_JPEG_QUALITY, "90");
parameters_.set(CameraParameters::KEY_FOCAL_LENGTH, "4.31");
parameters_.set(CameraParameters::KEY_HORIZONTAL_VIEW_ANGLE, "54.8");
parameters_.set(CameraParameters::KEY_VERTICAL_VIEW_ANGLE, "42.5");
parameters_.set(CameraParameters::KEY_JPEG_THUMBNAIL_QUALITY, "90");
mPparameters.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS, CameraParameters::PIXEL_FORMAT_RGBA8888);
mPparameters.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES, "60,50,25,15,10");
mPparameters.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FPS_RANGE, "(10,60)");
mPparameters.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, "10,60");
mPparameters.set(CameraParameters::KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES, "320x240,0x0");
mPparameters.set(CameraParameters::KEY_MAX_EXPOSURE_COMPENSATION, "6");
mPparameters.set(CameraParameters::KEY_MIN_EXPOSURE_COMPENSATION, "-6");
mPparameters.set(CameraParameters::KEY_EXPOSURE_COMPENSATION_STEP, "0.5");
mPparameters.set(CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH, "512");
mPparameters.set(CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT, "384");
mPparameters.set(CameraParameters::KEY_JPEG_QUALITY, "90");
mPparameters.set(CameraParameters::KEY_FOCAL_LENGTH, "4.31");
mPparameters.set(CameraParameters::KEY_HORIZONTAL_VIEW_ANGLE, "54.8");
mPparameters.set(CameraParameters::KEY_VERTICAL_VIEW_ANGLE, "42.5");
mPparameters.set(CameraParameters::KEY_JPEG_THUMBNAIL_QUALITY, "90");
/* Only RGB formats are supported by preview window in emulator. */
parameters_.setPreviewFormat(CameraParameters::PIXEL_FORMAT_RGBA8888);
mPparameters.setPreviewFormat(CameraParameters::PIXEL_FORMAT_RGBA8888);
/* We don't relay on the actual frame rates supported by the camera device,
* since we will emulate them through timeouts in the emulated camera device
* worker thread. */
parameters_.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES,
mPparameters.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES,
"30,24,20,15,10,5");
parameters_.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FPS_RANGE, "(5,30)");
parameters_.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, "5,30");
parameters_.setPreviewFrameRate(24);
mPparameters.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FPS_RANGE, "(5,30)");
mPparameters.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, "5,30");
mPparameters.setPreviewFrameRate(24);
/* Only PIXEL_FORMAT_YUV420P is accepted by camera framework in emulator! */
parameters_.set(CameraParameters::KEY_VIDEO_FRAME_FORMAT,
mPparameters.set(CameraParameters::KEY_VIDEO_FRAME_FORMAT,
CameraParameters::PIXEL_FORMAT_YUV420P);
parameters_.set(CameraParameters::KEY_SUPPORTED_PICTURE_FORMATS,
mPparameters.set(CameraParameters::KEY_SUPPORTED_PICTURE_FORMATS,
CameraParameters::PIXEL_FORMAT_YUV420P);
parameters_.setPictureFormat(CameraParameters::PIXEL_FORMAT_YUV420P);
mPparameters.setPictureFormat(CameraParameters::PIXEL_FORMAT_YUV420P);
/*
* Not supported features
*/
parameters_.set(CameraParameters::KEY_SUPPORTED_FOCUS_MODES, CameraParameters::FOCUS_MODE_FIXED);
parameters_.set(CameraParameters::KEY_FOCUS_MODE, CameraParameters::FOCUS_MODE_FIXED);
mPparameters.set(CameraParameters::KEY_SUPPORTED_FOCUS_MODES, CameraParameters::FOCUS_MODE_FIXED);
mPparameters.set(CameraParameters::KEY_FOCUS_MODE, CameraParameters::FOCUS_MODE_FIXED);
return NO_ERROR;
}
void EmulatedCamera::OnNextFrameAvailable(const void* frame,
void EmulatedCamera::onNextFrameAvailable(const void* frame,
nsecs_t timestamp,
EmulatedCameraDevice* camera_dev)
{
/* Notify the preview window first. */
preview_window_.OnNextFrameAvailable(frame, timestamp, camera_dev);
mPreviewWindow.onNextFrameAvailable(frame, timestamp, camera_dev);
/* Notify callback notifier next. */
callback_notifier_.OnNextFrameAvailable(frame, timestamp, camera_dev);
mCallbackNotifier.onNextFrameAvailable(frame, timestamp, camera_dev);
}
/****************************************************************************
* Camera API implementation.
***************************************************************************/
status_t EmulatedCamera::Connect(hw_device_t** device)
status_t EmulatedCamera::connectCamera(hw_device_t** device)
{
LOGV("%s", __FUNCTION__);
status_t res = EINVAL;
EmulatedCameraDevice* const camera_dev = GetCameraDevice();
EmulatedCameraDevice* const camera_dev = getCameraDevice();
LOGE_IF(camera_dev == NULL, "%s: No camera device instance.", __FUNCTION__);
if (camera_dev != NULL) {
/* Connect to the camera device. */
res = GetCameraDevice()->Connect();
res = getCameraDevice()->connectDevice();
if (res == NO_ERROR) {
*device = &common;
}
@@ -174,20 +174,20 @@ status_t EmulatedCamera::Connect(hw_device_t** device)
return -res;
}
status_t EmulatedCamera::Close()
status_t EmulatedCamera::closeCamera()
{
LOGV("%s", __FUNCTION__);
return Cleanup();
return cleanupCamera();
}
status_t EmulatedCamera::GetCameraInfo(struct camera_info* info)
status_t EmulatedCamera::getCameraInfo(struct camera_info* info)
{
LOGV("%s", __FUNCTION__);
const char* valstr = NULL;
valstr = parameters_.get(EmulatedCamera::FACING_KEY);
valstr = mPparameters.get(EmulatedCamera::FACING_KEY);
if (valstr != NULL) {
if (strcmp(valstr, EmulatedCamera::FACING_FRONT) == 0) {
info->facing = CAMERA_FACING_FRONT;
@@ -199,7 +199,7 @@ status_t EmulatedCamera::GetCameraInfo(struct camera_info* info)
info->facing = CAMERA_FACING_BACK;
}
valstr = parameters_.get(EmulatedCamera::ORIENTATION_KEY);
valstr = mPparameters.get(EmulatedCamera::ORIENTATION_KEY);
if (valstr != NULL) {
info->orientation = atoi(valstr);
} else {
@@ -209,86 +209,86 @@ status_t EmulatedCamera::GetCameraInfo(struct camera_info* info)
return NO_ERROR;
}
status_t EmulatedCamera::SetPreviewWindow(struct preview_stream_ops* window)
status_t EmulatedCamera::setPreviewWindow(struct preview_stream_ops* window)
{
/* Callback should return a negative errno. */
return -preview_window_.SetPreviewWindow(window,
parameters_.getPreviewFrameRate());
return -mPreviewWindow.setPreviewWindow(window,
mPparameters.getPreviewFrameRate());
}
void EmulatedCamera::SetCallbacks(camera_notify_callback notify_cb,
void EmulatedCamera::setCallbacks(camera_notify_callback notify_cb,
camera_data_callback data_cb,
camera_data_timestamp_callback data_cb_timestamp,
camera_request_memory get_memory,
void* user)
{
callback_notifier_.SetCallbacks(notify_cb, data_cb, data_cb_timestamp,
mCallbackNotifier.setCallbacks(notify_cb, data_cb, data_cb_timestamp,
get_memory, user);
}
void EmulatedCamera::EnableMsgType(int32_t msg_type)
void EmulatedCamera::enableMsgType(int32_t msg_type)
{
callback_notifier_.EnableMessage(msg_type);
mCallbackNotifier.enableMessage(msg_type);
}
void EmulatedCamera::DisableMsgType(int32_t msg_type)
void EmulatedCamera::disableMsgType(int32_t msg_type)
{
callback_notifier_.DisableMessage(msg_type);
mCallbackNotifier.disableMessage(msg_type);
}
int EmulatedCamera::MsgTypeEnabled(int32_t msg_type)
int EmulatedCamera::isMsgTypeEnabled(int32_t msg_type)
{
return callback_notifier_.IsMessageEnabled(msg_type);
return mCallbackNotifier.isMessageEnabled(msg_type);
}
status_t EmulatedCamera::StartPreview()
status_t EmulatedCamera::startPreview()
{
LOGV("%s", __FUNCTION__);
/* Callback should return a negative errno. */
return -DoStartPreview();
return -doStartPreview();
}
void EmulatedCamera::StopPreview()
void EmulatedCamera::stopPreview()
{
LOGV("%s", __FUNCTION__);
DoStopPreview();
doStopPreview();
}
int EmulatedCamera::PreviewEnabled()
int EmulatedCamera::isPreviewEnabled()
{
return preview_window_.IsEnabled();
return mPreviewWindow.isPreviewEnabled();
}
status_t EmulatedCamera::StoreMetaDataInBuffers(int enable)
status_t EmulatedCamera::storeMetaDataInBuffers(int enable)
{
/* Callback should return a negative errno. */
return -callback_notifier_.StoreMetaDataInBuffers(enable);
return -mCallbackNotifier.storeMetaDataInBuffers(enable);
}
status_t EmulatedCamera::StartRecording()
status_t EmulatedCamera::startRecording()
{
/* Callback should return a negative errno. */
return -callback_notifier_.EnableVideoRecording(parameters_.getPreviewFrameRate());
return -mCallbackNotifier.enableVideoRecording(mPparameters.getPreviewFrameRate());
}
void EmulatedCamera::StopRecording()
void EmulatedCamera::stopRecording()
{
callback_notifier_.DisableVideoRecording();
mCallbackNotifier.disableVideoRecording();
}
int EmulatedCamera::RecordingEnabled()
int EmulatedCamera::isRecordingEnabled()
{
return callback_notifier_.IsVideoRecordingEnabled();
return mCallbackNotifier.isVideoRecordingEnabled();
}
void EmulatedCamera::ReleaseRecordingFrame(const void* opaque)
void EmulatedCamera::releaseRecordingFrame(const void* opaque)
{
callback_notifier_.ReleaseRecordingFrame(opaque);
mCallbackNotifier.releaseRecordingFrame(opaque);
}
status_t EmulatedCamera::AutoFocus()
status_t EmulatedCamera::setAutoFocus()
{
LOGV("%s", __FUNCTION__);
@@ -296,7 +296,7 @@ status_t EmulatedCamera::AutoFocus()
return NO_ERROR;
}
status_t EmulatedCamera::CancelAutoFocus()
status_t EmulatedCamera::cancelAutoFocus()
{
LOGV("%s", __FUNCTION__);
@@ -304,7 +304,7 @@ status_t EmulatedCamera::CancelAutoFocus()
return NO_ERROR;
}
status_t EmulatedCamera::TakePicture()
status_t EmulatedCamera::takePicture()
{
LOGV("%s", __FUNCTION__);
@@ -326,22 +326,22 @@ status_t EmulatedCamera::TakePicture()
return NO_ERROR;
}
status_t EmulatedCamera::CancelPicture()
status_t EmulatedCamera::cancelPicture()
{
LOGV("%s", __FUNCTION__);
return NO_ERROR;
}
status_t EmulatedCamera::SetParameters(const char* parms)
status_t EmulatedCamera::setParameters(const char* parms)
{
LOGV("%s", __FUNCTION__);
_PrintParamDiff(parameters_, parms);
PrintParamDiff(mPparameters, parms);
CameraParameters new_param;
String8 str8_param(parms);
new_param.unflatten(str8_param);
parameters_ = new_param;
mPparameters = new_param;
/*
* In emulation, there are certain parameters that are required by the
@@ -351,49 +351,49 @@ status_t EmulatedCamera::SetParameters(const char* parms)
*/
/* Supported preview size. */
const char* check = parameters_.get(CameraParameters::KEY_PREVIEW_SIZE);
const char* check = mPparameters.get(CameraParameters::KEY_PREVIEW_SIZE);
if (check != NULL) {
const char* current =
parameters_.get(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES);
mPparameters.get(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES);
if (strstr(current, check) == NULL) {
/* Required size doesn't exist in the list. Add it. */
char* to_add = _AddValue(current, check);
char* to_add = AddValue(current, check);
if (to_add != NULL) {
LOGD("+++ %s: Added %s to supported preview sizes",
__FUNCTION__, check);
parameters_.set(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES, to_add);
mPparameters.set(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES, to_add);
free(to_add);
}
}
}
/* Supported preview frame rate. */
check = parameters_.get(CameraParameters::KEY_PREVIEW_FRAME_RATE);
check = mPparameters.get(CameraParameters::KEY_PREVIEW_FRAME_RATE);
if (check != NULL) {
const char* current =
parameters_.get(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES);
mPparameters.get(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES);
if (strstr(current, check) == NULL) {
char* to_add = _AddValue(current, check);
char* to_add = AddValue(current, check);
if (to_add != NULL) {
LOGD("+++ %s: Added %s to supported preview frame rates",
__FUNCTION__, check);
parameters_.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES, to_add);
mPparameters.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES, to_add);
free(to_add);
}
}
}
/* Supported picture size. */
check = parameters_.get(CameraParameters::KEY_PICTURE_SIZE);
check = mPparameters.get(CameraParameters::KEY_PICTURE_SIZE);
if (check != NULL) {
const char* current =
parameters_.get(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES);
mPparameters.get(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES);
if (strstr(current, check) == NULL) {
char* to_add = _AddValue(current, check);
char* to_add = AddValue(current, check);
if (to_add != NULL) {
LOGD("+++ %s: Added %s to supported picture sizes",
__FUNCTION__, check);
parameters_.set(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES, to_add);
mPparameters.set(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES, to_add);
free(to_add);
}
}
@@ -403,11 +403,11 @@ status_t EmulatedCamera::SetParameters(const char* parms)
}
/* A dumb variable indicating "no params" / error on the exit from
* EmulatedCamera::GetParameters(). */
static char _no_param = '\0';
char* EmulatedCamera::GetParameters()
* EmulatedCamera::getParameters(). */
static char lNoParam = '\0';
char* EmulatedCamera::getParameters()
{
String8 params(parameters_.flatten());
String8 params(mPparameters.flatten());
char* ret_str =
reinterpret_cast<char*>(malloc(sizeof(char) * (params.length()+1)));
memset(ret_str, 0, params.length()+1);
@@ -417,19 +417,19 @@ char* EmulatedCamera::GetParameters()
} else {
LOGE("%s: Unable to allocate string for %s", __FUNCTION__, params.string());
/* Apparently, we can't return NULL fron this routine. */
return &_no_param;
return &lNoParam;
}
}
void EmulatedCamera::PutParameters(char* params)
void EmulatedCamera::putParameters(char* params)
{
/* This method simply frees parameters allocated in GetParameters(). */
if (params != NULL && params != &_no_param) {
/* This method simply frees parameters allocated in getParameters(). */
if (params != NULL && params != &lNoParam) {
free(params);
}
}
status_t EmulatedCamera::SendCommand(int32_t cmd, int32_t arg1, int32_t arg2)
status_t EmulatedCamera::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2)
{
LOGV("%s: cmd = %d, arg1 = %d, arg2 = %d", __FUNCTION__, cmd, arg1, arg2);
@@ -437,14 +437,14 @@ status_t EmulatedCamera::SendCommand(int32_t cmd, int32_t arg1, int32_t arg2)
return 0;
}
void EmulatedCamera::Release()
void EmulatedCamera::releaseCamera()
{
LOGV("%s", __FUNCTION__);
Cleanup();
cleanupCamera();
}
status_t EmulatedCamera::Dump(int fd)
status_t EmulatedCamera::dumpCamera(int fd)
{
LOGV("%s", __FUNCTION__);
@@ -456,61 +456,62 @@ status_t EmulatedCamera::Dump(int fd)
* Preview management.
***************************************************************************/
status_t EmulatedCamera::DoStartPreview()
status_t EmulatedCamera::doStartPreview()
{
status_t res = preview_window_.Start();
status_t res = mPreviewWindow.startPreview();
/* Start the camera. */
if (res == NO_ERROR && !GetCameraDevice()->IsCapturing()) {
res = StartCamera();
if (res == NO_ERROR && !getCameraDevice()->isCapturing()) {
res = startCamera();
if (res != NO_ERROR) {
/* If camera didn't start, disable the preview window. */
preview_window_.Stop();
mPreviewWindow.stopPreview();
}
}
return res;
}
status_t EmulatedCamera::DoStopPreview()
status_t EmulatedCamera::doStopPreview()
{
status_t res = NO_ERROR;
/* Stop the camera. */
if (GetCameraDevice()->IsCapturing()) {
res = StopCamera();
if (getCameraDevice()->isCapturing()) {
res = stopCamera();
}
if (res == NO_ERROR) {
/* Disable preview as well. */
preview_window_.Stop();
mPreviewWindow.stopPreview();
}
return NO_ERROR;
}
status_t EmulatedCamera::StartCamera()
status_t EmulatedCamera::startCamera()
{
status_t res = EINVAL;
EmulatedCameraDevice* camera_dev = GetCameraDevice();
EmulatedCameraDevice* camera_dev = getCameraDevice();
if (camera_dev != NULL) {
if (!camera_dev->IsConnected()) {
res = camera_dev->Connect();
if (!camera_dev->isConnected()) {
res = camera_dev->connectDevice();
if (res != NO_ERROR) {
return res;
}
}
if (!camera_dev->IsCapturing()) {
if (!camera_dev->isCapturing()) {
int width, height;
/* Lets see what should we use for frame width, and height. */
if (parameters_.get(CameraParameters::KEY_VIDEO_SIZE) != NULL) {
parameters_.getVideoSize(&width, &height);
if (mPparameters.get(CameraParameters::KEY_VIDEO_SIZE) != NULL) {
mPparameters.getVideoSize(&width, &height);
} else {
parameters_.getPreviewSize(&width, &height);
mPparameters.getPreviewSize(&width, &height);
}
/* Lets see what should we use for the frame pixel format. */
const char* pix_fmt = parameters_.get(CameraParameters::KEY_VIDEO_FRAME_FORMAT);
const char* pix_fmt =
mPparameters.get(CameraParameters::KEY_VIDEO_FRAME_FORMAT);
if (pix_fmt == NULL) {
pix_fmt = parameters_.getPreviewFormat();
pix_fmt = mPparameters.getPreviewFormat();
}
if (pix_fmt == NULL) {
LOGE("%s: Unable to obtain video format", __FUNCTION__);
@@ -526,7 +527,7 @@ status_t EmulatedCamera::StartCamera()
return EINVAL;
}
LOGD("Starting camera: %dx%d -> %s", width, height, pix_fmt);
res = camera_dev->StartCapturing(width, height, org_fmt);
res = camera_dev->startCapturing(width, height, org_fmt);
if (res != NO_ERROR) {
return res;
}
@@ -536,13 +537,13 @@ status_t EmulatedCamera::StartCamera()
return res;
}
status_t EmulatedCamera::StopCamera()
status_t EmulatedCamera::stopCamera()
{
status_t res = NO_ERROR;
EmulatedCameraDevice* const camera_dev = GetCameraDevice();
EmulatedCameraDevice* const camera_dev = getCameraDevice();
if (camera_dev != NULL) {
if (camera_dev->IsCapturing()) {
res = camera_dev->StopCapturing();
if (camera_dev->isCapturing()) {
res = camera_dev->stopCapturing();
if (res != NO_ERROR) {
return res;
}
@@ -557,34 +558,34 @@ status_t EmulatedCamera::StopCamera()
* Private API.
***************************************************************************/
status_t EmulatedCamera::Cleanup()
status_t EmulatedCamera::cleanupCamera()
{
status_t res = NO_ERROR;
/* If preview is running - stop it. */
res = DoStopPreview();
res = doStopPreview();
if (res != NO_ERROR) {
return -res;
}
/* Stop and disconnect the camera device. */
EmulatedCameraDevice* const camera_dev = GetCameraDevice();
EmulatedCameraDevice* const camera_dev = getCameraDevice();
if (camera_dev != NULL) {
if (camera_dev->IsCapturing()) {
res = camera_dev->StopCapturing();
if (camera_dev->isCapturing()) {
res = camera_dev->stopCapturing();
if (res != NO_ERROR) {
return -res;
}
}
if (camera_dev->IsConnected()) {
res = camera_dev->Disconnect();
if (camera_dev->isConnected()) {
res = camera_dev->disconnectDevice();
if (res != NO_ERROR) {
return -res;
}
}
}
callback_notifier_.Cleanup();
mCallbackNotifier.cleanupCBNotifier();
return NO_ERROR;
}
@@ -604,7 +605,7 @@ int EmulatedCamera::set_preview_window(struct camera_device* dev,
LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL;
}
return ec->SetPreviewWindow(window);
return ec->setPreviewWindow(window);
}
void EmulatedCamera::set_callbacks(
@@ -620,7 +621,7 @@ void EmulatedCamera::set_callbacks(
LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return;
}
ec->SetCallbacks(notify_cb, data_cb, data_cb_timestamp, get_memory, user);
ec->setCallbacks(notify_cb, data_cb, data_cb_timestamp, get_memory, user);
}
void EmulatedCamera::enable_msg_type(struct camera_device* dev, int32_t msg_type)
@@ -630,7 +631,7 @@ void EmulatedCamera::enable_msg_type(struct camera_device* dev, int32_t msg_type
LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return;
}
ec->EnableMsgType(msg_type);
ec->enableMsgType(msg_type);
}
void EmulatedCamera::disable_msg_type(struct camera_device* dev, int32_t msg_type)
@@ -640,7 +641,7 @@ void EmulatedCamera::disable_msg_type(struct camera_device* dev, int32_t msg_typ
LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return;
}
ec->DisableMsgType(msg_type);
ec->disableMsgType(msg_type);
}
int EmulatedCamera::msg_type_enabled(struct camera_device* dev, int32_t msg_type)
@@ -650,7 +651,7 @@ int EmulatedCamera::msg_type_enabled(struct camera_device* dev, int32_t msg_type
LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL;
}
return ec->MsgTypeEnabled(msg_type);
return ec->isMsgTypeEnabled(msg_type);
}
int EmulatedCamera::start_preview(struct camera_device* dev)
@@ -660,7 +661,7 @@ int EmulatedCamera::start_preview(struct camera_device* dev)
LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL;
}
return ec->StartPreview();
return ec->startPreview();
}
void EmulatedCamera::stop_preview(struct camera_device* dev)
@@ -670,7 +671,7 @@ void EmulatedCamera::stop_preview(struct camera_device* dev)
LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return;
}
ec->StopPreview();
ec->stopPreview();
}
int EmulatedCamera::preview_enabled(struct camera_device* dev)
@@ -680,7 +681,7 @@ int EmulatedCamera::preview_enabled(struct camera_device* dev)
LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL;
}
return ec->PreviewEnabled();
return ec->isPreviewEnabled();
}
int EmulatedCamera::store_meta_data_in_buffers(struct camera_device* dev,
@@ -691,7 +692,7 @@ int EmulatedCamera::store_meta_data_in_buffers(struct camera_device* dev,
LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL;
}
return ec->StoreMetaDataInBuffers(enable);
return ec->storeMetaDataInBuffers(enable);
}
int EmulatedCamera::start_recording(struct camera_device* dev)
@@ -701,7 +702,7 @@ int EmulatedCamera::start_recording(struct camera_device* dev)
LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL;
}
return ec->StartRecording();
return ec->startRecording();
}
void EmulatedCamera::stop_recording(struct camera_device* dev)
@@ -711,7 +712,7 @@ void EmulatedCamera::stop_recording(struct camera_device* dev)
LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return;
}
ec->StopRecording();
ec->stopRecording();
}
int EmulatedCamera::recording_enabled(struct camera_device* dev)
@@ -721,7 +722,7 @@ int EmulatedCamera::recording_enabled(struct camera_device* dev)
LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL;
}
return ec->RecordingEnabled();
return ec->isRecordingEnabled();
}
void EmulatedCamera::release_recording_frame(struct camera_device* dev,
@@ -732,7 +733,7 @@ void EmulatedCamera::release_recording_frame(struct camera_device* dev,
LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return;
}
ec->ReleaseRecordingFrame(opaque);
ec->releaseRecordingFrame(opaque);
}
int EmulatedCamera::auto_focus(struct camera_device* dev)
@@ -742,7 +743,7 @@ int EmulatedCamera::auto_focus(struct camera_device* dev)
LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL;
}
return ec->AutoFocus();
return ec->setAutoFocus();
}
int EmulatedCamera::cancel_auto_focus(struct camera_device* dev)
@@ -752,7 +753,7 @@ int EmulatedCamera::cancel_auto_focus(struct camera_device* dev)
LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL;
}
return ec->CancelAutoFocus();
return ec->cancelAutoFocus();
}
int EmulatedCamera::take_picture(struct camera_device* dev)
@@ -762,7 +763,7 @@ int EmulatedCamera::take_picture(struct camera_device* dev)
LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL;
}
return ec->TakePicture();
return ec->takePicture();
}
int EmulatedCamera::cancel_picture(struct camera_device* dev)
@@ -772,7 +773,7 @@ int EmulatedCamera::cancel_picture(struct camera_device* dev)
LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL;
}
return ec->CancelPicture();
return ec->cancelPicture();
}
int EmulatedCamera::set_parameters(struct camera_device* dev, const char* parms)
@@ -782,7 +783,7 @@ int EmulatedCamera::set_parameters(struct camera_device* dev, const char* parms)
LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL;
}
return ec->SetParameters(parms);
return ec->setParameters(parms);
}
char* EmulatedCamera::get_parameters(struct camera_device* dev)
@@ -792,7 +793,7 @@ char* EmulatedCamera::get_parameters(struct camera_device* dev)
LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return NULL;
}
return ec->GetParameters();
return ec->getParameters();
}
void EmulatedCamera::put_parameters(struct camera_device* dev, char* params)
@@ -802,7 +803,7 @@ void EmulatedCamera::put_parameters(struct camera_device* dev, char* params)
LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return;
}
ec->PutParameters(params);
ec->putParameters(params);
}
int EmulatedCamera::send_command(struct camera_device* dev,
@@ -815,7 +816,7 @@ int EmulatedCamera::send_command(struct camera_device* dev,
LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL;
}
return ec->SendCommand(cmd, arg1, arg2);
return ec->sendCommand(cmd, arg1, arg2);
}
void EmulatedCamera::release(struct camera_device* dev)
@@ -825,7 +826,7 @@ void EmulatedCamera::release(struct camera_device* dev)
LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return;
}
ec->Release();
ec->releaseCamera();
}
int EmulatedCamera::dump(struct camera_device* dev, int fd)
@@ -835,7 +836,7 @@ int EmulatedCamera::dump(struct camera_device* dev, int fd)
LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL;
}
return ec->Dump(fd);
return ec->dumpCamera(fd);
}
int EmulatedCamera::close(struct hw_device_t* device)
@@ -846,14 +847,14 @@ int EmulatedCamera::close(struct hw_device_t* device)
LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL;
}
return ec->Close();
return ec->closeCamera();
}
/****************************************************************************
* Static initializer for the camera callback API
****************************************************************************/
camera_device_ops_t EmulatedCamera::device_ops_ = {
camera_device_ops_t EmulatedCamera::mDeviceOps = {
EmulatedCamera::set_preview_window,
EmulatedCamera::set_callbacks,
EmulatedCamera::enable_msg_type,
@@ -897,7 +898,7 @@ const char EmulatedCamera::FACING_FRONT[] = "front";
* Helper routines
***************************************************************************/
static char* _AddValue(const char* param, const char* val)
static char* AddValue(const char* param, const char* val)
{
const size_t len1 = strlen(param);
const size_t len2 = strlen(val);
@@ -917,7 +918,7 @@ static char* _AddValue(const char* param, const char* val)
***************************************************************************/
#if DEBUG_PARAM
static void _PrintParamDiff(const CameraParameters& current,
static void PrintParamDiff(const CameraParameters& current,
const char* new_par)
{
char tmp[2048];

View File

@@ -27,9 +27,9 @@
*/
#include <camera/CameraParameters.h>
#include "emulated_camera_device.h"
#include "preview_window.h"
#include "callback_notifier.h"
#include "EmulatedCameraDevice.h"
#include "PreviewWindow.h"
#include "CallbackNotifier.h"
namespace android {
@@ -38,8 +38,8 @@ namespace android {
*
* Note that EmulatedCameraFactory instantiates object of this class just once,
* when EmulatedCameraFactory instance gets constructed. Connection to /
* disconnection from the actual camera device is handled by calls to Connect(),
* and Close() methods of this class that are ivoked in response to
* disconnection from the actual camera device is handled by calls to connectDevice(),
* and closeCamera() methods of this class that are ivoked in response to
* hw_module_methods_t::open, and camera_device::close callbacks.
*/
class EmulatedCamera : public camera_device {
@@ -62,7 +62,7 @@ public:
public:
/* Gets emulated camera device used by this instance of the emulated camera.
*/
virtual EmulatedCameraDevice* GetCameraDevice() = 0;
virtual EmulatedCameraDevice* getCameraDevice() = 0;
/****************************************************************************
* Public API
@@ -90,7 +90,7 @@ public:
* timestamp - Frame's timestamp.
* camera_dev - Camera device instance that delivered the frame.
*/
virtual void OnNextFrameAvailable(const void* frame,
virtual void onNextFrameAvailable(const void* frame,
nsecs_t timestamp,
EmulatedCameraDevice* camera_dev);
@@ -104,14 +104,14 @@ public:
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
virtual status_t Connect(hw_device_t** device);
virtual status_t connectCamera(hw_device_t** device);
/* Closes connection to the emulated camera.
* This method is called in response to camera_device::close callback.
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
virtual status_t Close();
virtual status_t closeCamera();
/* Gets camera information.
* This method is called in response to camera_module_t::get_camera_info
@@ -119,7 +119,7 @@ public:
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
virtual status_t GetCameraInfo(struct camera_info* info);
virtual status_t getCameraInfo(struct camera_info* info);
/****************************************************************************
* Camera API implementation.
@@ -131,12 +131,12 @@ protected:
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
virtual status_t SetPreviewWindow(struct preview_stream_ops *window);
virtual status_t setPreviewWindow(struct preview_stream_ops *window);
/* Actual handler for camera_device_ops_t::set_callbacks callback.
* NOTE: When this method is called the object is locked.
*/
virtual void SetCallbacks(camera_notify_callback notify_cb,
virtual void setCallbacks(camera_notify_callback notify_cb,
camera_data_callback data_cb,
camera_data_timestamp_callback data_cb_timestamp,
camera_request_memory get_memory,
@@ -145,96 +145,96 @@ protected:
/* Actual handler for camera_device_ops_t::enable_msg_type callback.
* NOTE: When this method is called the object is locked.
*/
virtual void EnableMsgType(int32_t msg_type);
virtual void enableMsgType(int32_t msg_type);
/* Actual handler for camera_device_ops_t::disable_msg_type callback.
* NOTE: When this method is called the object is locked.
*/
virtual void DisableMsgType(int32_t msg_type);
virtual void disableMsgType(int32_t msg_type);
/* Actual handler for camera_device_ops_t::msg_type_enabled callback.
* NOTE: When this method is called the object is locked.
* Return:
* 0 if message(s) is (are) disabled, != 0 if enabled.
*/
virtual int MsgTypeEnabled(int32_t msg_type);
virtual int isMsgTypeEnabled(int32_t msg_type);
/* Actual handler for camera_device_ops_t::start_preview callback.
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
virtual status_t StartPreview();
virtual status_t startPreview();
/* Actual handler for camera_device_ops_t::stop_preview callback.
* NOTE: When this method is called the object is locked.
*/
virtual void StopPreview();
virtual void stopPreview();
/* Actual handler for camera_device_ops_t::preview_enabled callback.
* NOTE: When this method is called the object is locked.
* Return:
* 0 if preview is disabled, != 0 if enabled.
*/
virtual int PreviewEnabled();
virtual int isPreviewEnabled();
/* Actual handler for camera_device_ops_t::store_meta_data_in_buffers callback.
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
virtual status_t StoreMetaDataInBuffers(int enable);
virtual status_t storeMetaDataInBuffers(int enable);
/* Actual handler for camera_device_ops_t::start_recording callback.
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
virtual status_t StartRecording();
virtual status_t startRecording();
/* Actual handler for camera_device_ops_t::stop_recording callback.
* NOTE: When this method is called the object is locked.
*/
virtual void StopRecording();
virtual void stopRecording();
/* Actual handler for camera_device_ops_t::recording_enabled callback.
* NOTE: When this method is called the object is locked.
* Return:
* 0 if recording is disabled, != 0 if enabled.
*/
virtual int RecordingEnabled();
virtual int isRecordingEnabled();
/* Actual handler for camera_device_ops_t::release_recording_frame callback.
* NOTE: When this method is called the object is locked.
*/
virtual void ReleaseRecordingFrame(const void* opaque);
virtual void releaseRecordingFrame(const void* opaque);
/* Actual handler for camera_device_ops_t::auto_focus callback.
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
virtual status_t AutoFocus();
virtual status_t setAutoFocus();
/* Actual handler for camera_device_ops_t::cancel_auto_focus callback.
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
virtual status_t CancelAutoFocus();
virtual status_t cancelAutoFocus();
/* Actual handler for camera_device_ops_t::take_picture callback.
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
virtual status_t TakePicture();
virtual status_t takePicture();
/* Actual handler for camera_device_ops_t::cancel_picture callback.
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
virtual status_t CancelPicture();
virtual status_t cancelPicture();
/* Actual handler for camera_device_ops_t::set_parameters callback.
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
virtual status_t SetParameters(const char* parms);
virtual status_t setParameters(const char* parms);
/* Actual handler for camera_device_ops_t::get_parameters callback.
* NOTE: When this method is called the object is locked.
@@ -242,7 +242,7 @@ protected:
* Flattened parameters string. The caller will free the buffer allocated
* for the string by calling camera_device_ops_t::put_parameters callback.
*/
virtual char* GetParameters();
virtual char* getParameters();
/* Actual handler for camera_device_ops_t::put_parameters callback.
* Called to free the string returned from camera_device_ops_t::get_parameters
@@ -250,24 +250,24 @@ protected:
* misleading.
* NOTE: When this method is called the object is locked.
*/
virtual void PutParameters(char* params);
virtual void putParameters(char* params);
/* Actual handler for camera_device_ops_t::send_command callback.
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
virtual status_t SendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
/* Actual handler for camera_device_ops_t::release callback.
* NOTE: When this method is called the object is locked.
*/
virtual void Release();
virtual void releaseCamera();
/* Actual handler for camera_device_ops_t::dump callback.
* NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses.
*/
virtual status_t Dump(int fd);
virtual status_t dumpCamera(int fd);
/****************************************************************************
* Preview management.
@@ -275,32 +275,32 @@ protected:
protected:
/* Starts preview.
* Note that when this method is called preview_window_ may be NULL,
* Note that when this method is called mPreviewWindow may be NULL,
* indicating that framework has an intention to start displaying video
* frames, but didn't create the preview window yet.
* Return:
* NO_ERROR on success, or an appropriate error status on failure.
*/
virtual status_t DoStartPreview();
virtual status_t doStartPreview();
/* Stops preview.
* This method reverts DoStartPreview.
* Return:
* NO_ERROR on success, or an appropriate error status on failure.
*/
virtual status_t DoStopPreview();
virtual status_t doStopPreview();
/* Starts capturing frames
* Return:
* NO_ERROR on success, or an appropriate error status on failure.
*/
virtual status_t StartCamera();
virtual status_t startCamera();
/* Stops capturing frames.
* Return:
* NO_ERROR on success, or an appropriate error status on failure.
*/
virtual status_t StopCamera();
virtual status_t stopCamera();
/****************************************************************************
* Private API.
@@ -308,7 +308,7 @@ protected:
protected:
/* Cleans up camera when released. */
virtual status_t Cleanup();
virtual status_t cleanupCamera();
/****************************************************************************
* Camera API callbacks as defined by camera_device_ops structure.
@@ -383,23 +383,23 @@ private:
protected:
/* Locks this instance for parameters, state, etc. change. */
Mutex object_lock_;
Mutex mObjectLock;
/* Camera parameters. */
CameraParameters parameters_;
CameraParameters mPparameters;
/* Preview window. */
PreviewWindow preview_window_;
PreviewWindow mPreviewWindow;
/* Callback notifier. */
CallbackNotifier callback_notifier_;
CallbackNotifier mCallbackNotifier;
/* Zero-based ID assigned to this camera. */
int camera_id_;
int mCameraID;
private:
/* Registered callbacks implementing camera API. */
static camera_device_ops_t device_ops_;
static camera_device_ops_t mDeviceOps;
/****************************************************************************
* Common keys

View File

@@ -33,18 +33,18 @@ class HWERoutineTracker {
public:
/* Constructor that prints an "entry" trace message. */
explicit HWERoutineTracker(const char* name)
: name_(name) {
LOGV("Entering %s", name_);
: mName(name) {
LOGV("Entering %s", mName);
}
/* Destructor that prints a "leave" trace message. */
~HWERoutineTracker() {
LOGV("Leaving %s", name_);
LOGV("Leaving %s", mName);
}
private:
/* Stores the routine name. */
const char* name_;
const char* mName;
};
/* Logs an execution of a routine / method. */

View File

@@ -27,24 +27,24 @@
#define LOG_TAG "EmulatedCamera_Device"
#include <cutils/log.h>
#include <sys/select.h>
#include "emulated_camera_device.h"
#include "converters.h"
#include "EmulatedCameraDevice.h"
#include "Converters.h"
namespace android {
EmulatedCameraDevice::EmulatedCameraDevice(EmulatedCamera* camera_hal)
: object_lock_(),
timestamp_(0),
camera_hal_(camera_hal),
current_frame_(NULL),
state_(ECDS_CONSTRUCTED)
: mObjectLock(),
mCurFrameTimestamp(0),
mCameraHAL(camera_hal),
mCurrentFrame(NULL),
mState(ECDS_CONSTRUCTED)
{
}
EmulatedCameraDevice::~EmulatedCameraDevice()
{
if (current_frame_ != NULL) {
delete[] current_frame_;
if (mCurrentFrame != NULL) {
delete[] mCurrentFrame;
}
}
@@ -56,25 +56,25 @@ status_t EmulatedCameraDevice::Initialize()
{
LOGV("%s", __FUNCTION__);
if (IsInitialized()) {
LOGW("%s: Emulated camera device is already initialized: state_ = %d",
__FUNCTION__, state_);
if (isInitialized()) {
LOGW("%s: Emulated camera device is already initialized: mState = %d",
__FUNCTION__, mState);
return NO_ERROR;
}
/* Instantiate worker thread object. */
worker_thread_ = new WorkerThread(this);
if (worker_thread() == NULL) {
mWorkerThread = new WorkerThread(this);
if (getWorkerThread() == NULL) {
LOGE("%s: Unable to instantiate worker thread object", __FUNCTION__);
return ENOMEM;
}
state_ = ECDS_INITIALIZED;
mState = ECDS_INITIALIZED;
return NO_ERROR;
}
status_t EmulatedCameraDevice::StartCapturing(int width,
status_t EmulatedCameraDevice::startCapturing(int width,
int height,
uint32_t pix_fmt)
{
@@ -83,7 +83,7 @@ status_t EmulatedCameraDevice::StartCapturing(int width,
/* Validate pixel format, and calculate framebuffer size at the same time. */
switch (pix_fmt) {
case V4L2_PIX_FMT_YVU420:
framebuffer_size_ = (width * height * 12) / 8;
mFrameBufferSize = (width * height * 12) / 8;
break;
default:
@@ -93,87 +93,87 @@ status_t EmulatedCameraDevice::StartCapturing(int width,
}
/* Cache framebuffer info. */
frame_width_ = width;
frame_height_ = height;
pixel_format_ = pix_fmt;
total_pixels_ = width * height;
mFrameWidth = width;
mFrameHeight = height;
mPixelFormat = pix_fmt;
mTotalPixels = width * height;
/* Allocate framebuffer. */
current_frame_ = new uint8_t[framebuffer_size_];
if (current_frame_ == NULL) {
mCurrentFrame = new uint8_t[mFrameBufferSize];
if (mCurrentFrame == NULL) {
LOGE("%s: Unable to allocate framebuffer", __FUNCTION__);
return ENOMEM;
}
/* Calculate Cb/Cr panes inside the framebuffer. */
frame_Cb_ = current_frame_ + total_pixels_;
frame_Cr_ = frame_Cb_ + total_pixels_ / 4;
/* Calculate U/V panes inside the framebuffer. */
mFrameU = mCurrentFrame + mTotalPixels;
mFrameV = mFrameU + mTotalPixels / 4;
/* Start the camera. */
const status_t res = StartCamera();
const status_t res = startDevice();
if (res == NO_ERROR) {
LOGD("Camera device is started:\n"
" Framebuffer dimensions: %dx%d.\n"
" Pixel format: %.4s",
frame_width_, frame_height_,
reinterpret_cast<const char*>(&pixel_format_));
mFrameWidth, mFrameHeight,
reinterpret_cast<const char*>(&mPixelFormat));
} else {
delete[] current_frame_;
current_frame_ = NULL;
delete[] mCurrentFrame;
mCurrentFrame = NULL;
}
return res;
}
status_t EmulatedCameraDevice::StopCapturing()
status_t EmulatedCameraDevice::stopCapturing()
{
LOGV("%s", __FUNCTION__);
/* Stop the camera. */
const status_t res = StopCamera();
const status_t res = stopDevice();
if (res == NO_ERROR) {
/* Release resources allocated for capturing. */
if (current_frame_ != NULL) {
delete[] current_frame_;
current_frame_ = NULL;
if (mCurrentFrame != NULL) {
delete[] mCurrentFrame;
mCurrentFrame = NULL;
}
}
return res;
}
status_t EmulatedCameraDevice::GetCurrentFrame(void* buffer)
status_t EmulatedCameraDevice::getCurrentFrame(void* buffer)
{
Mutex::Autolock locker(&object_lock_);
Mutex::Autolock locker(&mObjectLock);
if (!IsCapturing() || current_frame_ == NULL) {
if (!isCapturing() || mCurrentFrame == NULL) {
LOGE("%s is called on a device that is not in the capturing state",
__FUNCTION__);
return EINVAL;
}
memcpy(buffer, current_frame_, framebuffer_size_);
memcpy(buffer, mCurrentFrame, mFrameBufferSize);
return NO_ERROR;
}
status_t EmulatedCameraDevice::GetCurrentPreviewFrame(void* buffer)
status_t EmulatedCameraDevice::getCurrentPreviewFrame(void* buffer)
{
Mutex::Autolock locker(&object_lock_);
Mutex::Autolock locker(&mObjectLock);
if (!IsCapturing() || current_frame_ == NULL) {
if (!isCapturing() || mCurrentFrame == NULL) {
LOGE("%s is called on a device that is not in the capturing state",
__FUNCTION__);
return EINVAL;
}
/* In emulation the framebuffer is never RGB. */
switch (pixel_format_) {
switch (mPixelFormat) {
case V4L2_PIX_FMT_YVU420:
YV12ToRGB32(current_frame_, buffer, frame_width_, frame_height_);
YV12ToRGB32(mCurrentFrame, buffer, mFrameWidth, mFrameHeight);
return NO_ERROR;
default:
LOGE("%s: Unknown pixel format %d", __FUNCTION__, pixel_format_);
LOGE("%s: Unknown pixel format %d", __FUNCTION__, mPixelFormat);
return EINVAL;
}
}
@@ -182,37 +182,37 @@ status_t EmulatedCameraDevice::GetCurrentPreviewFrame(void* buffer)
* Worker thread management.
***************************************************************************/
status_t EmulatedCameraDevice::StartWorkerThread()
status_t EmulatedCameraDevice::startWorkerThread()
{
LOGV("%s", __FUNCTION__);
if (!IsInitialized()) {
if (!isInitialized()) {
LOGE("%s: Emulated camera device is not initialized", __FUNCTION__);
return EINVAL;
}
const status_t ret = worker_thread()->Start();
const status_t ret = getWorkerThread()->startThread();
LOGE_IF(ret != NO_ERROR, "%s: Unable to start worker thread: %d -> %s",
__FUNCTION__, ret, strerror(ret));
return ret;
}
status_t EmulatedCameraDevice::StopWorkerThread()
status_t EmulatedCameraDevice::stopWorkerThread()
{
LOGV("%s", __FUNCTION__);
if (!IsInitialized()) {
if (!isInitialized()) {
LOGE("%s: Emulated camera device is not initialized", __FUNCTION__);
return EINVAL;
}
worker_thread()->Stop();
getWorkerThread()->stopThread();
return NO_ERROR;
}
bool EmulatedCameraDevice::InWorkerThread()
bool EmulatedCameraDevice::inWorkerThread()
{
/* This will end the thread loop, and will terminate the thread. */
return false;
@@ -226,13 +226,13 @@ status_t EmulatedCameraDevice::WorkerThread::readyToRun()
{
LOGV("Starting emulated camera device worker thread...");
LOGW_IF(thread_control_ >= 0 || control_fd_ >= 0,
LOGW_IF(mThreadControl >= 0 || mControlFD >= 0,
"%s: Thread control FDs are opened", __FUNCTION__);
/* Create a pair of FDs that would be used to control the thread. */
int thread_fds[2];
if (pipe(thread_fds) == 0) {
thread_control_ = thread_fds[1];
control_fd_ = thread_fds[0];
mThreadControl = thread_fds[1];
mControlFD = thread_fds[0];
LOGV("Emulated device's worker thread has been started.");
return NO_ERROR;
} else {
@@ -242,28 +242,28 @@ status_t EmulatedCameraDevice::WorkerThread::readyToRun()
}
}
status_t EmulatedCameraDevice::WorkerThread::Stop()
status_t EmulatedCameraDevice::WorkerThread::stopThread()
{
LOGV("Stopping emulated camera device's worker thread...");
status_t res = EINVAL;
if (thread_control_ >= 0) {
if (mThreadControl >= 0) {
/* Send "stop" message to the thread loop. */
const ControlMessage msg = THREAD_STOP;
const int wres =
TEMP_FAILURE_RETRY(write(thread_control_, &msg, sizeof(msg)));
TEMP_FAILURE_RETRY(write(mThreadControl, &msg, sizeof(msg)));
if (wres == sizeof(msg)) {
/* Stop the thread, and wait till it's terminated. */
res = requestExitAndWait();
if (res == NO_ERROR) {
/* Close control FDs. */
if (thread_control_ >= 0) {
close(thread_control_);
thread_control_ = -1;
if (mThreadControl >= 0) {
close(mThreadControl);
mThreadControl = -1;
}
if (control_fd_ >= 0) {
close(control_fd_);
control_fd_ = -1;
if (mControlFD >= 0) {
close(mControlFD);
mControlFD = -1;
}
LOGV("Emulated camera device's worker thread has been stopped.");
} else {
@@ -288,10 +288,10 @@ EmulatedCameraDevice::WorkerThread::Select(int fd, int timeout)
fd_set fds[1];
struct timeval tv, *tvp = NULL;
const int fd_num = (fd >= 0) ? max(fd, control_fd_) + 1 :
control_fd_ + 1;
const int fd_num = (fd >= 0) ? max(fd, mControlFD) + 1 :
mControlFD + 1;
FD_ZERO(fds);
FD_SET(control_fd_, fds);
FD_SET(mControlFD, fds);
if (fd >= 0) {
FD_SET(fd, fds);
}
@@ -308,10 +308,10 @@ EmulatedCameraDevice::WorkerThread::Select(int fd, int timeout)
} else if (res == 0) {
/* Timeout. */
return TIMEOUT;
} else if (FD_ISSET(control_fd_, fds)) {
} else if (FD_ISSET(mControlFD, fds)) {
/* A control event. Lets read the message. */
ControlMessage msg;
res = TEMP_FAILURE_RETRY(read(control_fd_, &msg, sizeof(msg)));
res = TEMP_FAILURE_RETRY(read(mControlFD, &msg, sizeof(msg)));
if (res != sizeof(msg)) {
LOGE("%s: Unexpected message size %d, or an error %d -> %s",
__FUNCTION__, res, errno, strerror(errno));

View File

@@ -27,14 +27,14 @@
*/
#include <utils/threads.h>
#include "emulated_camera_common.h"
#include "EmulatedCameraCommon.h"
namespace android {
class EmulatedCamera;
/* Encapsulates an abstract class EmulatedCameraDevice that defines functionality
* expected from an emulated physical camera device:
/* Encapsulates an abstract class EmulatedCameraDevice that defines
* functionality expected from an emulated physical camera device:
* - Obtaining and setting camera device parameters
* - Capturing frames
* - Streaming video
@@ -52,9 +52,9 @@ public:
/* Destructs EmulatedCameraDevice instance. */
virtual ~EmulatedCameraDevice();
/****************************************************************************
/***************************************************************************
* Emulated camera device abstract interface
***************************************************************************/
**************************************************************************/
public:
/* Connects to the camera device.
@@ -62,7 +62,7 @@ public:
* Return:
* NO_ERROR on success, or an appropriate error status.
*/
virtual status_t Connect() = 0;
virtual status_t connectDevice() = 0;
/* Disconnects from the camera device.
* Return:
@@ -72,7 +72,7 @@ public:
* called for an instance that is in "capturing" state, this method must
* return a failure.
*/
virtual status_t Disconnect() = 0;
virtual status_t disconnectDevice() = 0;
protected:
/* Starts capturing frames from the camera device.
@@ -81,26 +81,27 @@ protected:
* requested by the framework through the camera HAL, and starts a worker
* thread that will listen to the physical device for available frames. When
* new frame becomes available, it will be cached in current_framebuffer_,
* and the containing emulated camera object will be notified via call to its
* OnNextFrameAvailable method. This method must be called on a connected
* instance of this class. If it is called on a disconnected instance, this
* method must return a failure.
* and the containing emulated camera object will be notified via call to
* its onNextFrameAvailable method. This method must be called on a
* connected instance of this class. If it is called on a disconnected
* instance, this method must return a failure.
* Return:
* NO_ERROR on success, or an appropriate error status.
*/
virtual status_t StartCamera() = 0;
virtual status_t startDevice() = 0;
/* Stops capturing frames from the camera device.
* Return:
* NO_ERROR on success, or an appropriate error status. If this method is
* called for an object that is not capturing frames, or is disconnected, or
* is uninitialized, a successful status must be returned from this method.
* called for an object that is not capturing frames, or is disconnected,
* or is uninitialized, a successful status must be returned from this
* method.
*/
virtual status_t StopCamera() = 0;
virtual status_t stopDevice() = 0;
/****************************************************************************
/***************************************************************************
* Emulated camera device public API
***************************************************************************/
**************************************************************************/
public:
/* Initializes EmulatedCameraDevice instance.
@@ -116,25 +117,26 @@ public:
/* Starts capturing frames from the camera device.
*
* Typically, this method caches desired frame parameters, and calls
* StartCamera method to start capturing video frames from the camera device.
* This method must be called on a connected instance of this class. If it is
* called on a disconnected instance, this method must return a failure.
* startDevice method to start capturing video frames from the camera
* device. This method must be called on a connected instance of this class.
* If it is called on a disconnected instance, this method must return a
* failure.
* Return:
* NO_ERROR on success, or an appropriate error status.
*/
virtual status_t StartCapturing(int width, int height, uint32_t pix_fmt);
virtual status_t startCapturing(int width, int height, uint32_t pix_fmt);
/* Stops capturing frames from the camera device.
*
* Typically, this method calls StopCamera method of this class, and
* Typically, this method calls stopDevice method of this class, and
* uninitializes frame properties, saved in StartCapturing method of this
* class.
* This method must be called on a connected instance of this class. If it is
* called on a disconnected instance, this method must return a failure.
* This method must be called on a connected instance of this class. If it
* is called on a disconnected instance, this method must return a failure.
* Return:
* NO_ERROR on success, or an appropriate error status.
*/
virtual status_t StopCapturing();
virtual status_t stopCapturing();
/* Gets current fame into provided buffer.
* Typically, this method is called by the emulated camera (HAL) in response
@@ -148,7 +150,7 @@ public:
* large enough to contain the entire frame, as defined by frame's width,
* height, and pixel format that are current for the camera device.
*/
virtual status_t GetCurrentFrame(void* buffer);
virtual status_t getCurrentFrame(void* buffer);
/* Gets current preview fame into provided buffer.
* Param:
@@ -158,30 +160,30 @@ public:
* due to the the limitations of the camera framework in emulator, the
* preview frame is always formatted with RGBA8888.
*/
virtual status_t GetCurrentPreviewFrame(void* buffer);
virtual status_t getCurrentPreviewFrame(void* buffer);
/* Gets width of the frame obtained from the physical device. */
inline int GetFrameWidth() const
inline int getFrameWidth() const
{
return frame_width_;
return mFrameWidth;
}
/* Gets height of the frame obtained from the physical device. */
inline int GetFrameHeight() const
inline int getFrameHeight() const
{
return frame_height_;
return mFrameHeight;
}
/* Gets byte size of the current frame buffer. */
inline size_t GetFrameBufferSize() const
inline size_t getFrameBufferSize() const
{
return framebuffer_size_;
return mFrameBufferSize;
}
/* Gets number of pixels in the current frame buffer. */
inline int GetPixelNum() const
inline int getPixelNum() const
{
return total_pixels_;
return mTotalPixels;
}
/* Gets pixel format of the frame that physical device streams.
@@ -205,28 +207,28 @@ public:
* Return:
* Current framebuffer's pixel format.
*/
inline uint32_t GetOriginalPixelFormat() const
inline uint32_t getOriginalPixelFormat() const
{
return pixel_format_;
return mPixelFormat;
}
/*
* State checkers.
*/
inline bool IsInitialized() const {
inline bool isInitialized() const {
/* Instance is initialized when the worker thread has been successfuly
* created (but not necessarily started). */
return worker_thread_.get() != NULL && state_ != ECDS_CONSTRUCTED;
return mWorkerThread.get() != NULL && mState != ECDS_CONSTRUCTED;
}
inline bool IsConnected() const {
inline bool isConnected() const {
/* Instance is connected when it is initialized and its status is either
* "connected", or "capturing". */
return IsInitialized() &&
(state_ == ECDS_CONNECTED || state_ == ECDS_CAPTURING);
return isInitialized() &&
(mState == ECDS_CONNECTED || mState == ECDS_CAPTURING);
}
inline bool IsCapturing() const {
return IsInitialized() && state_ == ECDS_CAPTURING;
inline bool isCapturing() const {
return isInitialized() && mState == ECDS_CAPTURING;
}
/****************************************************************************
@@ -245,14 +247,14 @@ protected:
* Return:
* NO_ERROR on success, or an appropriate error status.
*/
virtual status_t StartWorkerThread();
virtual status_t startWorkerThread();
/* Stops the worker thread.
* Note that this method will always wait for the worker thread to terminate.
* Return:
* NO_ERROR on success, or an appropriate error status.
*/
virtual status_t StopWorkerThread();
virtual status_t stopWorkerThread();
/* Implementation of the worker thread routine.
* In the default implementation of the worker thread routine we simply
@@ -263,7 +265,7 @@ protected:
* true To continue thread loop (this method will be called again), or false
* to exit the thread loop and to terminate the thread.
*/
virtual bool InWorkerThread();
virtual bool inWorkerThread();
/* Encapsulates a worker thread used by the emulated camera device.
*/
@@ -277,27 +279,27 @@ protected:
public:
inline explicit WorkerThread(EmulatedCameraDevice* camera_dev)
: Thread(true), // Callbacks may involve Java calls.
camera_dev_(camera_dev),
thread_control_(-1),
control_fd_(-1)
mCameraDevice(camera_dev),
mThreadControl(-1),
mControlFD(-1)
{
}
inline ~WorkerThread()
{
LOGW_IF(thread_control_ >= 0 || control_fd_ >= 0,
LOGW_IF(mThreadControl >= 0 || mControlFD >= 0,
"%s: Control FDs are opened in the destructor",
__FUNCTION__);
if (thread_control_ >= 0) {
close(thread_control_);
if (mThreadControl >= 0) {
close(mThreadControl);
}
if (control_fd_ >= 0) {
close(control_fd_);
if (mControlFD >= 0) {
close(mControlFD);
}
}
/* Starts the thread */
inline status_t Start()
inline status_t startThread()
{
return run(NULL, ANDROID_PRIORITY_URGENT_DISPLAY, 0);
}
@@ -309,7 +311,7 @@ protected:
status_t readyToRun();
/* Stops the thread. */
status_t Stop();
status_t stopThread();
/* Values returned from the Select method of this class. */
enum SelectRes {
@@ -344,17 +346,17 @@ protected:
inline bool threadLoop()
{
/* Simply dispatch the call to the containing camera device. */
return camera_dev_->InWorkerThread();
return mCameraDevice->inWorkerThread();
}
/* Containing camera device object. */
EmulatedCameraDevice* camera_dev_;
EmulatedCameraDevice* mCameraDevice;
/* FD that is used to send control messages into the thread. */
int thread_control_;
int mThreadControl;
/* FD that thread uses to receive control messages. */
int control_fd_;
int mControlFD;
/* Enumerates control messages that can be sent into the thread. */
enum ControlMessage {
@@ -364,9 +366,9 @@ protected:
};
/* Worker thread accessor. */
inline WorkerThread* worker_thread() const
inline WorkerThread* getWorkerThread() const
{
return worker_thread_.get();
return mWorkerThread.get();
}
/****************************************************************************
@@ -375,45 +377,45 @@ protected:
protected:
/* Locks this instance for parameters, state, etc. change. */
Mutex object_lock_;
Mutex mObjectLock;
/* Worker thread that is used in frame capturing. */
sp<WorkerThread> worker_thread_;
sp<WorkerThread> mWorkerThread;
/* Timestamp of the current frame. */
nsecs_t timestamp_;
nsecs_t mCurFrameTimestamp;
/* Emulated camera object containing this instance. */
EmulatedCamera* camera_hal_;
EmulatedCamera* mCameraHAL;
/* Framebuffer containing the current frame. */
uint8_t* current_frame_;
uint8_t* mCurrentFrame;
/* Cb panel inside the framebuffer. */
uint8_t* frame_Cb_;
/* U panel inside the framebuffer. */
uint8_t* mFrameU;
/* Cr panel inside the framebuffer. */
uint8_t* frame_Cr_;
/* V panel inside the framebuffer. */
uint8_t* mFrameV;
/*
* Framebuffer properties.
*/
/* Byte size of the framebuffer. */
size_t framebuffer_size_;
size_t mFrameBufferSize;
/* Original pixel format (one of the V4L2_PIX_FMT_XXX values, as defined in
* bionic/libc/kernel/common/linux/videodev2.h */
uint32_t pixel_format_;
uint32_t mPixelFormat;
/* Frame width */
int frame_width_;
int mFrameWidth;
/* Frame height */
int frame_height_;
int mFrameHeight;
/* Total number of pixels */
int total_pixels_;
int mTotalPixels;
/* Defines possible states of the emulated camera device object.
*/
@@ -429,7 +431,7 @@ protected:
};
/* Object state. */
EmulatedCameraDeviceState state_;
EmulatedCameraDeviceState mState;
};
}; /* namespace android */

View File

@@ -22,83 +22,83 @@
#define LOG_NDEBUG 0
#define LOG_TAG "EmulatedCamera_Factory"
#include <cutils/log.h>
#include "emulated_qemu_camera.h"
#include "emulated_fake_camera.h"
#include "emulated_camera_factory.h"
#include "EmulatedQemuCamera.h"
#include "EmulatedFakeCamera.h"
#include "EmulatedCameraFactory.h"
extern camera_module_t HAL_MODULE_INFO_SYM;
/* A global instance of EmulatedCameraFactory is statically instantiated and
* initialized when camera emulation HAL is loaded.
*/
android::EmulatedCameraFactory _emulated_camera_factory;
android::EmulatedCameraFactory gEmulatedCameraFactory;
namespace android {
EmulatedCameraFactory::EmulatedCameraFactory()
: qemu_client_(),
emulated_cameras_(NULL),
emulated_camera_num_(0),
fake_camera_id_(-1),
constructed_ok_(false)
: mQemuClient(),
mEmulatedCameras(NULL),
mEmulatedCameraNum(0),
mFakeCameraID(-1),
mConstructedOK(false)
{
/* If qemu camera emulation is on, try to connect to the factory service in
* the emulator. */
if (IsQemuCameraEmulationOn() && qemu_client_.Connect(NULL) == NO_ERROR) {
if (isQemuCameraEmulationOn() && mQemuClient.connectClient(NULL) == NO_ERROR) {
/* Connection has succeeded. Create emulated cameras for each camera
* device, reported by the service. */
CreateQemuCameras();
createQemuCameras();
}
if (IsFakeCameraEmulationOn()) {
if (isFakeCameraEmulationOn()) {
/* ID fake camera with the number of created 'qemud' cameras. */
fake_camera_id_ = emulated_camera_num_;
emulated_camera_num_++;
mFakeCameraID = mEmulatedCameraNum;
mEmulatedCameraNum++;
/* Make sure that array is allocated (in case there were no 'qemu'
* cameras created. */
if (emulated_cameras_ == NULL) {
emulated_cameras_ = new EmulatedCamera*[emulated_camera_num_];
if (emulated_cameras_ == NULL) {
if (mEmulatedCameras == NULL) {
mEmulatedCameras = new EmulatedCamera*[mEmulatedCameraNum];
if (mEmulatedCameras == NULL) {
LOGE("%s: Unable to allocate emulated camera array for %d entries",
__FUNCTION__, emulated_camera_num_);
__FUNCTION__, mEmulatedCameraNum);
return;
}
memset(emulated_cameras_, 0, emulated_camera_num_ * sizeof(EmulatedCamera*));
memset(mEmulatedCameras, 0, mEmulatedCameraNum * sizeof(EmulatedCamera*));
}
/* Create, and initialize the fake camera */
emulated_cameras_[fake_camera_id_] =
new EmulatedFakeCamera(fake_camera_id_, &HAL_MODULE_INFO_SYM.common);
if (emulated_cameras_[fake_camera_id_] != NULL) {
if (emulated_cameras_[fake_camera_id_]->Initialize() != NO_ERROR) {
delete emulated_cameras_[fake_camera_id_];
emulated_cameras_--;
fake_camera_id_ = -1;
mEmulatedCameras[mFakeCameraID] =
new EmulatedFakeCamera(mFakeCameraID, &HAL_MODULE_INFO_SYM.common);
if (mEmulatedCameras[mFakeCameraID] != NULL) {
if (mEmulatedCameras[mFakeCameraID]->Initialize() != NO_ERROR) {
delete mEmulatedCameras[mFakeCameraID];
mEmulatedCameras--;
mFakeCameraID = -1;
}
} else {
emulated_cameras_--;
fake_camera_id_ = -1;
mEmulatedCameras--;
mFakeCameraID = -1;
LOGE("%s: Unable to instantiate fake camera class", __FUNCTION__);
}
}
LOGV("%d cameras are being emulated. Fake camera ID is %d",
emulated_camera_num_, fake_camera_id_);
mEmulatedCameraNum, mFakeCameraID);
constructed_ok_ = true;
mConstructedOK = true;
}
EmulatedCameraFactory::~EmulatedCameraFactory()
{
if (emulated_cameras_ != NULL) {
for (int n = 0; n < emulated_camera_num_; n++) {
if (emulated_cameras_[n] != NULL) {
delete emulated_cameras_[n];
if (mEmulatedCameras != NULL) {
for (int n = 0; n < mEmulatedCameraNum; n++) {
if (mEmulatedCameras[n] != NULL) {
delete mEmulatedCameras[n];
}
}
delete[] emulated_cameras_;
delete[] mEmulatedCameras;
}
}
@@ -110,38 +110,38 @@ EmulatedCameraFactory::~EmulatedCameraFactory()
*
***************************************************************************/
int EmulatedCameraFactory::CameraDeviceOpen(int camera_id, hw_device_t** device)
int EmulatedCameraFactory::cameraDeviceOpen(int camera_id, hw_device_t** device)
{
*device = NULL;
if (!constructed_ok()) {
if (!isConstructedOK()) {
LOGE("%s: EmulatedCameraFactory has failed to initialize", __FUNCTION__);
return -EINVAL;
}
if (camera_id >= emulated_camera_num()) {
if (camera_id >= getEmulatedCameraNum()) {
LOGE("%s: Camera id %d is out of bounds (%d)",
__FUNCTION__, camera_id, emulated_camera_num());
__FUNCTION__, camera_id, getEmulatedCameraNum());
return -EINVAL;
}
return emulated_cameras_[camera_id]->Connect(device);
return mEmulatedCameras[camera_id]->connectCamera(device);
}
int EmulatedCameraFactory::GetCameraInfo(int camera_id, struct camera_info* info)
int EmulatedCameraFactory::getCameraInfo(int camera_id, struct camera_info* info)
{
if (!constructed_ok()) {
if (!isConstructedOK()) {
LOGE("%s: EmulatedCameraFactory has failed to initialize", __FUNCTION__);
return -EINVAL;
}
if (camera_id >= emulated_camera_num()) {
if (camera_id >= getEmulatedCameraNum()) {
LOGE("%s: Camera id %d is out of bounds (%d)",
__FUNCTION__, camera_id, emulated_camera_num());
__FUNCTION__, camera_id, getEmulatedCameraNum());
return -EINVAL;
}
return emulated_cameras_[camera_id]->GetCameraInfo(info);
return mEmulatedCameras[camera_id]->getCameraInfo(info);
}
/****************************************************************************
@@ -167,18 +167,18 @@ int EmulatedCameraFactory::device_open(const hw_module_t* module,
return -EINVAL;
}
return _emulated_camera_factory.CameraDeviceOpen(atoi(name), device);
return gEmulatedCameraFactory.cameraDeviceOpen(atoi(name), device);
}
int EmulatedCameraFactory::get_number_of_cameras(void)
{
return _emulated_camera_factory.emulated_camera_num();
return gEmulatedCameraFactory.getEmulatedCameraNum();
}
int EmulatedCameraFactory::get_camera_info(int camera_id,
struct camera_info* info)
{
return _emulated_camera_factory.GetCameraInfo(camera_id, info);
return gEmulatedCameraFactory.getCameraInfo(camera_id, info);
}
/********************************************************************************
@@ -190,15 +190,15 @@ int EmulatedCameraFactory::get_camera_info(int camera_id,
*/
/* Device name token. */
static const char _list_name_token[] = "name=";
static const char lListNameToken[] = "name=";
/* Frame dimensions token. */
static const char _list_dims_token[] = "framedims=";
static const char lListDimsToken[] = "framedims=";
void EmulatedCameraFactory::CreateQemuCameras()
void EmulatedCameraFactory::createQemuCameras()
{
/* Obtain camera list. */
char* camera_list = NULL;
status_t res = qemu_client_.ListCameras(&camera_list);
status_t res = mQemuClient.listCameras(&camera_list);
/* Empty list, or list containing just an EOL means that there were no
* connected cameras found. */
if (res != NO_ERROR || camera_list == NULL || *camera_list == '\0' ||
@@ -223,14 +223,14 @@ void EmulatedCameraFactory::CreateQemuCameras()
/* Allocate the array for emulated camera instances. Note that we allocate
* one more entry for the fake camera emulation. */
emulated_cameras_ = new EmulatedCamera*[num + 1];
if (emulated_cameras_ == NULL) {
mEmulatedCameras = new EmulatedCamera*[num + 1];
if (mEmulatedCameras == NULL) {
LOGE("%s: Unable to allocate emulated camera array for %d entries",
__FUNCTION__, num + 1);
free(camera_list);
return;
}
memset(emulated_cameras_, 0, sizeof(EmulatedCamera*) * (num + 1));
memset(mEmulatedCameras, 0, sizeof(EmulatedCamera*) * (num + 1));
/*
* Iterate the list, creating, and initializin emulated qemu cameras for each
@@ -249,12 +249,12 @@ void EmulatedCameraFactory::CreateQemuCameras()
}
/* Find 'name', and 'framedims' tokens that are required here. */
char* name_start = strstr(cur_entry, _list_name_token);
char* dim_start = strstr(cur_entry, _list_dims_token);
char* name_start = strstr(cur_entry, lListNameToken);
char* dim_start = strstr(cur_entry, lListDimsToken);
if (name_start != NULL && dim_start != NULL) {
/* Advance to the token values. */
name_start += strlen(_list_name_token);
dim_start += strlen(_list_dims_token);
name_start += strlen(lListNameToken);
dim_start += strlen(lListDimsToken);
/* Terminate token values with zero. */
char* s = strchr(name_start, ' ');
@@ -272,7 +272,7 @@ void EmulatedCameraFactory::CreateQemuCameras()
if (NULL != qemu_cam) {
res = qemu_cam->Initialize(name_start, dim_start);
if (res == NO_ERROR) {
emulated_cameras_[index] = qemu_cam;
mEmulatedCameras[index] = qemu_cam;
index++;
} else {
delete qemu_cam;
@@ -288,16 +288,16 @@ void EmulatedCameraFactory::CreateQemuCameras()
cur_entry = next_entry;
}
emulated_camera_num_ = index;
mEmulatedCameraNum = index;
}
bool EmulatedCameraFactory::IsQemuCameraEmulationOn()
bool EmulatedCameraFactory::isQemuCameraEmulationOn()
{
/* TODO: Have a boot property that controls that! */
return true;
}
bool EmulatedCameraFactory::IsFakeCameraEmulationOn()
bool EmulatedCameraFactory::isFakeCameraEmulationOn()
{
/* TODO: Have a boot property that controls that! */
return true;
@@ -308,7 +308,7 @@ bool EmulatedCameraFactory::IsFakeCameraEmulationOn()
*******************************************************************************/
/* Entry point for camera HAL API. */
struct hw_module_methods_t EmulatedCameraFactory::camera_module_methods_ = {
struct hw_module_methods_t EmulatedCameraFactory::mCameraModuleMethods = {
open: EmulatedCameraFactory::device_open
};

View File

@@ -17,7 +17,7 @@
#ifndef HW_EMULATOR_CAMERA_EMULATED_CAMERA_FACTORY_H
#define HW_EMULATOR_CAMERA_EMULATED_CAMERA_FACTORY_H
#include "emulated_camera.h"
#include "EmulatedCamera.h"
#include "QemuClient.h"
namespace android {
@@ -50,7 +50,7 @@ public:
/* Constructs EmulatedCameraFactory instance.
* In this constructor the factory will create and initialize a list of
* emulated cameras. All errors that occur on this constructor are reported
* via constructed_ok_ data member of this class.
* via mConstructedOK data member of this class.
*/
EmulatedCameraFactory();
@@ -65,12 +65,12 @@ public:
/* Opens (connects to) a camera device.
* This method is called in response to hw_module_methods_t::open callback.
*/
int CameraDeviceOpen(int camera_id, hw_device_t** device);
int cameraDeviceOpen(int camera_id, hw_device_t** device);
/* Gets emulated camera information.
* This method is called in response to camera_module_t::get_camera_info callback.
*/
int GetCameraInfo(int camera_id, struct camera_info *info);
int getCameraInfo(int camera_id, struct camera_info *info);
/****************************************************************************
* Camera HAL API callbacks.
@@ -95,39 +95,39 @@ private:
public:
/* Gets fake camera facing. */
int GetFakeCameraFacing() {
int getFakeCameraFacing() {
/* TODO: Have a boot property that controls that. */
return CAMERA_FACING_BACK;
}
/* Gets fake camera orientation. */
int GetFakeCameraOrientation() {
int getFakeCameraOrientation() {
/* TODO: Have a boot property that controls that. */
return 90;
}
/* Gets qemu camera facing. */
int GetQemuCameraFacing() {
int getQemuCameraFacing() {
/* TODO: Have a boot property that controls that. */
return CAMERA_FACING_FRONT;
}
/* Gets qemu camera orientation. */
int GetQemuCameraOrientation() {
int getQemuCameraOrientation() {
/* TODO: Have a boot property that controls that. */
return 270;
}
/* Gets number of emulated cameras.
*/
int emulated_camera_num() const {
return emulated_camera_num_;
int getEmulatedCameraNum() const {
return mEmulatedCameraNum;
}
/* Checks whether or not the constructor has succeeded.
*/
bool constructed_ok() const {
return constructed_ok_;
bool isConstructedOK() const {
return mConstructedOK;
}
/****************************************************************************
@@ -137,16 +137,16 @@ public:
private:
/* Populates emulated cameras array with cameras that are available via
* 'camera' service in the emulator. For each such camera and instance of
* the EmulatedCameraQemud will be created and added to the emulated_cameras_
* the EmulatedCameraQemud will be created and added to the mEmulatedCameras
* array.
*/
void CreateQemuCameras();
void createQemuCameras();
/* Checks if qemu camera emulation is on. */
bool IsQemuCameraEmulationOn();
bool isQemuCameraEmulationOn();
/* Checks if fake camera emulation is on. */
bool IsFakeCameraEmulationOn();
bool isFakeCameraEmulationOn();
/****************************************************************************
* Data members.
@@ -154,28 +154,28 @@ private:
private:
/* Connection to the camera service in the emulator. */
FactoryQemuClient qemu_client_;
FactoryQemuClient mQemuClient;
/* Array of cameras available for the emulation. */
EmulatedCamera** emulated_cameras_;
EmulatedCamera** mEmulatedCameras;
/* Number of emulated cameras (including the fake one). */
int emulated_camera_num_;
int mEmulatedCameraNum;
/* Fake camera ID. */
int fake_camera_id_;
int mFakeCameraID;
/* Flags whether or not constructor has succeeded. */
bool constructed_ok_;
bool mConstructedOK;
public:
/* Contains device open entry point, as required by HAL API. */
static struct hw_module_methods_t camera_module_methods_;
static struct hw_module_methods_t mCameraModuleMethods;
};
}; /* namespace android */
/* References the global EmulatedCameraFactory instance. */
extern android::EmulatedCameraFactory _emulated_camera_factory;
extern android::EmulatedCameraFactory gEmulatedCameraFactory;
#endif /* HW_EMULATOR_CAMERA_EMULATED_CAMERA_FACTORY_H */

View File

@@ -23,7 +23,7 @@
* managing emulated cameras.
*/
#include "emulated_camera_factory.h"
#include "EmulatedCameraFactory.h"
/*
* Required HAL header.
@@ -36,7 +36,7 @@ camera_module_t HAL_MODULE_INFO_SYM = {
id: CAMERA_HARDWARE_MODULE_ID,
name: "Emulated Camera Module",
author: "The Android Open Source Project",
methods: &android::EmulatedCameraFactory::camera_module_methods_,
methods: &android::EmulatedCameraFactory::mCameraModuleMethods,
dso: NULL,
reserved: {0},
},

View File

@@ -22,14 +22,14 @@
#define LOG_NDEBUG 0
#define LOG_TAG "EmulatedCamera_FakeCamera"
#include <cutils/log.h>
#include "emulated_fake_camera.h"
#include "emulated_camera_factory.h"
#include "EmulatedFakeCamera.h"
#include "EmulatedCameraFactory.h"
namespace android {
EmulatedFakeCamera::EmulatedFakeCamera(int cameraId, struct hw_module_t* module)
: EmulatedCamera(cameraId, module),
fake_camera_dev_(this)
mFakeCameraDevice(this)
{
}
@@ -45,19 +45,19 @@ status_t EmulatedFakeCamera::Initialize()
{
LOGV("%s", __FUNCTION__);
status_t res = fake_camera_dev_.Initialize();
status_t res = mFakeCameraDevice.Initialize();
if (res != NO_ERROR) {
return res;
}
const char* facing = EmulatedCamera::FACING_BACK;
if (_emulated_camera_factory.GetFakeCameraOrientation() == CAMERA_FACING_FRONT) {
if (gEmulatedCameraFactory.getFakeCameraOrientation() == CAMERA_FACING_FRONT) {
facing = EmulatedCamera::FACING_FRONT;
}
parameters_.set(EmulatedCamera::FACING_KEY, facing);
mPparameters.set(EmulatedCamera::FACING_KEY, facing);
parameters_.set(EmulatedCamera::ORIENTATION_KEY,
_emulated_camera_factory.GetFakeCameraOrientation());
mPparameters.set(EmulatedCamera::ORIENTATION_KEY,
gEmulatedCameraFactory.getFakeCameraOrientation());
res = EmulatedCamera::Initialize();
if (res != NO_ERROR) {
@@ -68,17 +68,17 @@ status_t EmulatedFakeCamera::Initialize()
* Parameters provided by the camera device.
*/
parameters_.set(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES, "640x480");
parameters_.set(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES, "640x480");
parameters_.setPreviewSize(640, 480);
parameters_.setPictureSize(640, 480);
mPparameters.set(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES, "640x480");
mPparameters.set(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES, "640x480");
mPparameters.setPreviewSize(640, 480);
mPparameters.setPictureSize(640, 480);
return NO_ERROR;
}
EmulatedCameraDevice* EmulatedFakeCamera::GetCameraDevice()
EmulatedCameraDevice* EmulatedFakeCamera::getCameraDevice()
{
return &fake_camera_dev_;
return &mFakeCameraDevice;
}
}; /* namespace android */

View File

@@ -23,8 +23,8 @@
* for EmulatedFakeCameraDevice instance.
*/
#include "emulated_camera.h"
#include "emulated_fake_camera_device.h"
#include "EmulatedCamera.h"
#include "EmulatedFakeCameraDevice.h"
namespace android {
@@ -59,7 +59,7 @@ public:
protected:
/* Gets emulated camera device ised by this instance of the emulated camera.
*/
EmulatedCameraDevice* GetCameraDevice();
EmulatedCameraDevice* getCameraDevice();
/****************************************************************************
* Data memebers.
@@ -67,7 +67,7 @@ protected:
protected:
/* Contained fake camera device object. */
EmulatedFakeCameraDevice fake_camera_dev_;
EmulatedFakeCameraDevice mFakeCameraDevice;
};
}; /* namespace android */

View File

@@ -22,21 +22,21 @@
#define LOG_NDEBUG 0
#define LOG_TAG "EmulatedCamera_FakeDevice"
#include <cutils/log.h>
#include "emulated_fake_camera.h"
#include "emulated_fake_camera_device.h"
#include "EmulatedFakeCamera.h"
#include "EmulatedFakeCameraDevice.h"
namespace android {
EmulatedFakeCameraDevice::EmulatedFakeCameraDevice(EmulatedFakeCamera* camera_hal)
: EmulatedCameraDevice(camera_hal),
black_YCbCr_(kBlack32),
white_YCbCr_(kWhite32),
red_YCbCr_(kRed8),
green_YCbCr_(kGreen8),
blue_YCbCr_(kBlue8),
check_x_(0),
check_y_(0),
counter_(0)
mBlackYUV(kBlack32),
mWhiteYUV(kWhite32),
mRedYUV(kRed8),
mGreenYUV(kGreen8),
mBlueYUV(kBlue8),
mCheckX(0),
mCheckY(0),
mCcounter(0)
{
}
@@ -48,83 +48,83 @@ EmulatedFakeCameraDevice::~EmulatedFakeCameraDevice()
* Emulated camera device abstract interface implementation.
***************************************************************************/
status_t EmulatedFakeCameraDevice::Connect()
status_t EmulatedFakeCameraDevice::connectDevice()
{
LOGV("%s", __FUNCTION__);
Mutex::Autolock locker(&object_lock_);
if (!IsInitialized()) {
Mutex::Autolock locker(&mObjectLock);
if (!isInitialized()) {
LOGE("%s: Fake camera device is not initialized.", __FUNCTION__);
return EINVAL;
}
if (IsConnected()) {
if (isConnected()) {
LOGW("%s: Fake camera device is already connected.", __FUNCTION__);
return NO_ERROR;
}
state_ = ECDS_CONNECTED;
mState = ECDS_CONNECTED;
return NO_ERROR;
}
status_t EmulatedFakeCameraDevice::Disconnect()
status_t EmulatedFakeCameraDevice::disconnectDevice()
{
LOGV("%s", __FUNCTION__);
Mutex::Autolock locker(&object_lock_);
if (!IsConnected()) {
Mutex::Autolock locker(&mObjectLock);
if (!isConnected()) {
LOGW("%s: Fake camera device is already disconnected.", __FUNCTION__);
return NO_ERROR;
}
if (IsCapturing()) {
if (isCapturing()) {
LOGE("%s: Cannot disconnect while in the capturing state.", __FUNCTION__);
return EINVAL;
}
state_ = ECDS_INITIALIZED;
mState = ECDS_INITIALIZED;
return NO_ERROR;
}
status_t EmulatedFakeCameraDevice::StartCamera()
status_t EmulatedFakeCameraDevice::startDevice()
{
LOGV("%s", __FUNCTION__);
Mutex::Autolock locker(&object_lock_);
if (!IsConnected()) {
Mutex::Autolock locker(&mObjectLock);
if (!isConnected()) {
LOGE("%s: Fake camera device is not connected.", __FUNCTION__);
return EINVAL;
}
if (IsCapturing()) {
if (isCapturing()) {
LOGW("%s: Fake camera device is already capturing.", __FUNCTION__);
return NO_ERROR;
}
/* Used in calculating Cb/Cr position when drawing the square. */
half_width_ = frame_width_ / 2;
/* Used in calculating U/V position when drawing the square. */
mHalfWidth = mFrameWidth / 2;
/* Just start the worker thread: there is no real device to deal with. */
const status_t ret = StartWorkerThread();
const status_t ret = startWorkerThread();
if (ret == NO_ERROR) {
state_ = ECDS_CAPTURING;
mState = ECDS_CAPTURING;
}
return ret;
}
status_t EmulatedFakeCameraDevice::StopCamera()
status_t EmulatedFakeCameraDevice::stopDevice()
{
LOGV("%s", __FUNCTION__);
if (!IsCapturing()) {
if (!isCapturing()) {
LOGW("%s: Fake camera device is not capturing.", __FUNCTION__);
return NO_ERROR;
}
/* Just stop the worker thread: there is no real device to deal with. */
const status_t ret = StopWorkerThread();
const status_t ret = stopWorkerThread();
if (ret == NO_ERROR) {
state_ = ECDS_CONNECTED;
mState = ECDS_CONNECTED;
}
return ret;
@@ -134,39 +134,39 @@ status_t EmulatedFakeCameraDevice::StopCamera()
* Worker thread management overrides.
***************************************************************************/
bool EmulatedFakeCameraDevice::InWorkerThread()
bool EmulatedFakeCameraDevice::inWorkerThread()
{
/* Wait till FPS timeout expires, or thread exit message is received. */
WorkerThread::SelectRes res =
worker_thread()->Select(-1, 1000000 / emulated_fps_);
getWorkerThread()->Select(-1, 1000000 / mEmulatedFPS);
if (res == WorkerThread::EXIT_THREAD) {
LOGV("%s: Worker thread has been terminated.", __FUNCTION__);
return false;
}
/* Lets see if we need to generate a new frame. */
if ((systemTime(SYSTEM_TIME_MONOTONIC) - timestamp_) >= redraw_after_) {
if ((systemTime(SYSTEM_TIME_MONOTONIC) - mCurFrameTimestamp) >= mRedrawAfter) {
/*
* Time to generate a new frame.
*/
/* Draw the checker board. */
DrawCheckerboard();
drawCheckerboard();
/* Run the square. */
int x = ((counter_ * 3) & 255);
int x = ((mCcounter * 3) & 255);
if(x > 128) x = 255 - x;
int y = ((counter_ * 5) & 255);
int y = ((mCcounter * 5) & 255);
if(y > 128) y = 255 - y;
const int size = frame_width_ / 10;
DrawSquare(x * size / 32, y * size / 32, (size * 5) >> 1,
(counter_ & 0x100) ? &red_YCbCr_ : &green_YCbCr_);
counter_++;
const int size = mFrameWidth / 10;
drawSquare(x * size / 32, y * size / 32, (size * 5) >> 1,
(mCcounter & 0x100) ? &mRedYUV : &mGreenYUV);
mCcounter++;
}
/* Timestamp the current frame, and notify the camera HAL about new frame. */
timestamp_ = systemTime(SYSTEM_TIME_MONOTONIC);
camera_hal_->OnNextFrameAvailable(current_frame_, timestamp_, this);
mCurFrameTimestamp = systemTime(SYSTEM_TIME_MONOTONIC);
mCameraHAL->onNextFrameAvailable(mCurrentFrame, mCurFrameTimestamp, this);
return true;
}
@@ -175,35 +175,35 @@ bool EmulatedFakeCameraDevice::InWorkerThread()
* Fake camera device private API
***************************************************************************/
void EmulatedFakeCameraDevice::DrawCheckerboard()
void EmulatedFakeCameraDevice::drawCheckerboard()
{
const int size = frame_width_ / 10;
const int size = mFrameWidth / 10;
bool black = true;
if((check_x_ / size) & 1)
if((mCheckX / size) & 1)
black = false;
if((check_y_ / size) & 1)
if((mCheckY / size) & 1)
black = !black;
int county = check_y_ % size;
int checkxremainder = check_x_ % size;
uint8_t* Y = current_frame_;
uint8_t* Cb_pos = frame_Cb_;
uint8_t* Cr_pos = frame_Cr_;
uint8_t* Cb = Cb_pos;
uint8_t* Cr = Cr_pos;
int county = mCheckY % size;
int checkxremainder = mCheckX % size;
uint8_t* Y = mCurrentFrame;
uint8_t* U_pos = mFrameU;
uint8_t* V_pos = mFrameV;
uint8_t* U = U_pos;
uint8_t* V = V_pos;
for(int y = 0; y < frame_height_; y++) {
for(int y = 0; y < mFrameHeight; y++) {
int countx = checkxremainder;
bool current = black;
for(int x = 0; x < frame_width_; x += 2) {
for(int x = 0; x < mFrameWidth; x += 2) {
if (current) {
black_YCbCr_.get(Y, Cb, Cr);
mBlackYUV.get(Y, U, V);
} else {
white_YCbCr_.get(Y, Cb, Cr);
mWhiteYUV.get(Y, U, V);
}
Y[1] = *Y;
Y += 2; Cb++; Cr++;
Y += 2; U++; V++;
countx += 2;
if(countx >= size) {
countx = 0;
@@ -211,43 +211,43 @@ void EmulatedFakeCameraDevice::DrawCheckerboard()
}
}
if (y & 0x1) {
Cb_pos = Cb;
Cr_pos = Cr;
U_pos = U;
V_pos = V;
} else {
Cb = Cb_pos;
Cr = Cr_pos;
U = U_pos;
V = V_pos;
}
if(county++ >= size) {
county = 0;
black = !black;
}
}
check_x_ += 3;
check_y_++;
mCheckX += 3;
mCheckY++;
}
void EmulatedFakeCameraDevice::DrawSquare(int x,
void EmulatedFakeCameraDevice::drawSquare(int x,
int y,
int size,
const YUVPixel* color)
{
const int half_x = x / 2;
const int square_xstop = min(frame_width_, x+size);
const int square_ystop = min(frame_height_, y+size);
uint8_t* Y_pos = current_frame_ + y * frame_width_ + x;
const int square_xstop = min(mFrameWidth, x+size);
const int square_ystop = min(mFrameHeight, y+size);
uint8_t* Y_pos = mCurrentFrame + y * mFrameWidth + x;
// Draw the square.
for (; y < square_ystop; y++) {
const int iCbCr = (y / 2) * half_width_ + half_x;
uint8_t* sqCb = frame_Cb_ + iCbCr;
uint8_t* sqCr = frame_Cr_ + iCbCr;
const int iUV = (y / 2) * mHalfWidth + half_x;
uint8_t* sqU = mFrameU + iUV;
uint8_t* sqV = mFrameV + iUV;
uint8_t* sqY = Y_pos;
for (int i = x; i < square_xstop; i += 2) {
color->get(sqY, sqCb, sqCr);
color->get(sqY, sqU, sqV);
sqY[1] = *sqY;
sqY += 2; sqCb++; sqCr++;
sqY += 2; sqU++; sqV++;
}
Y_pos += frame_width_;
Y_pos += mFrameWidth;
}
}

View File

@@ -22,8 +22,8 @@
* a fake camera device.
*/
#include "converters.h"
#include "emulated_camera_device.h"
#include "Converters.h"
#include "EmulatedCameraDevice.h"
namespace android {
@@ -43,51 +43,51 @@ public:
/* Destructs EmulatedFakeCameraDevice instance. */
~EmulatedFakeCameraDevice();
/****************************************************************************
/***************************************************************************
* Emulated camera device abstract interface implementation.
* See declarations of these methods in EmulatedCameraDevice class for
* information on each of these methods.
***************************************************************************/
**************************************************************************/
public:
/* Connects to the camera device.
* Since there is no real device to connect to, this method does nothing, but
* changes the state.
* Since there is no real device to connect to, this method does nothing,
* but changes the state.
*/
status_t Connect();
status_t connectDevice();
/* Disconnects from the camera device.
* Since there is no real device to disconnect from, this method does
* nothing, but changes the state.
*/
status_t Disconnect();
status_t disconnectDevice();
protected:
/* Starts capturing frames from the camera device.
* Since there is no real device to control, this method simply starts the
* worker thread, and changes the state.
*/
status_t StartCamera();
status_t startDevice();
/* Stops capturing frames from the camera device.
* Since there is no real device to control, this method simply stops the
* worker thread, and changes the state.
*/
status_t StopCamera();
status_t stopDevice();
/****************************************************************************
/***************************************************************************
* Worker thread management overrides.
* See declarations of these methods in EmulatedCameraDevice class for
* information on each of these methods.
***************************************************************************/
**************************************************************************/
protected:
/* Implementation of the worker thread routine.
* This method simply sleeps for a period of time defined by FPS property of
* the fake camera (simulating frame frequency), and then calls emulated
* camera's OnNextFrameAvailable method.
* camera's onNextFrameAvailable method.
*/
bool InWorkerThread();
bool inWorkerThread();
/****************************************************************************
* Fake camera device private API
@@ -95,7 +95,7 @@ protected:
private:
/* Draws a black and white checker board in the current frame buffer. */
void DrawCheckerboard();
void drawCheckerboard();
/* Draws a square of the given color in the current frame buffer.
* Param:
@@ -103,7 +103,7 @@ private:
* size - Size of the square's side.
* color - Square's color.
*/
void DrawSquare(int x, int y, int size, const YUVPixel* color);
void drawSquare(int x, int y, int size, const YUVPixel* color);
/****************************************************************************
* Fake camera device data members
@@ -111,31 +111,31 @@ private:
private:
/*
* Pixel colors in YCbCr format used when drawing the checker board.
* Pixel colors in YUV format used when drawing the checker board.
*/
YUVPixel black_YCbCr_;
YUVPixel white_YCbCr_;
YUVPixel red_YCbCr_;
YUVPixel green_YCbCr_;
YUVPixel blue_YCbCr_;
YUVPixel mBlackYUV;
YUVPixel mWhiteYUV;
YUVPixel mRedYUV;
YUVPixel mGreenYUV;
YUVPixel mBlueYUV;
/*
* Drawing related stuff
*/
int check_x_;
int check_y_;
int counter_;
int half_width_;
int mCheckX;
int mCheckY;
int mCcounter;
int mHalfWidth;
/* Emulated FPS (frames per second).
* We will emulate 50 FPS. */
static const int emulated_fps_ = 50;
static const int mEmulatedFPS = 50;
/* Defines time (in nanoseconds) between redrawing the checker board.
* We will redraw the checker board every 15 milliseconds. */
static const nsecs_t redraw_after_ = 15000000LL;
static const nsecs_t mRedrawAfter = 15000000LL;
};
}; /* namespace android */

View File

@@ -22,14 +22,14 @@
#define LOG_NDEBUG 0
#define LOG_TAG "EmulatedCamera_QemuCamera"
#include <cutils/log.h>
#include "emulated_qemu_camera.h"
#include "emulated_camera_factory.h"
#include "EmulatedQemuCamera.h"
#include "EmulatedCameraFactory.h"
namespace android {
EmulatedQemuCamera::EmulatedQemuCamera(int cameraId, struct hw_module_t* module)
: EmulatedCamera(cameraId, module),
qemu_camera_dev_(this)
mQemuCameraDevice(this)
{
}
@@ -45,10 +45,10 @@ status_t EmulatedQemuCamera::Initialize(const char* device_name,
const char* frame_dims)
{
/* Save dimensions. */
frame_dims_ = frame_dims;
mFrameDims = frame_dims;
/* Initialize camera device. */
status_t res = qemu_camera_dev_.Initialize(device_name);
status_t res = mQemuCameraDevice.Initialize(device_name);
if (res != NO_ERROR) {
return res;
}
@@ -64,14 +64,14 @@ status_t EmulatedQemuCamera::Initialize(const char* device_name,
*/
const char* facing = EmulatedCamera::FACING_FRONT;
if (_emulated_camera_factory.GetQemuCameraOrientation() == CAMERA_FACING_BACK) {
if (gEmulatedCameraFactory.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);
mPparameters.set(EmulatedCamera::FACING_KEY, facing);
mPparameters.set(EmulatedCamera::ORIENTATION_KEY,
gEmulatedCameraFactory.getQemuCameraOrientation());
mPparameters.set(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES, frame_dims);
mPparameters.set(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES, frame_dims);
/*
* Use first dimension reported by the device to set current preview and
@@ -103,8 +103,8 @@ status_t EmulatedQemuCamera::Initialize(const char* device_name,
*sep = '\0';
const int x = atoi(first_dim);
const int y = atoi(sep + 1);
parameters_.setPreviewSize(x, y);
parameters_.setPictureSize(x, y);
mPparameters.setPreviewSize(x, y);
mPparameters.setPictureSize(x, y);
LOGV("%s: Qemu camera %s is initialized. Current frame is %dx%d",
__FUNCTION__, device_name, x, y);
@@ -112,9 +112,9 @@ status_t EmulatedQemuCamera::Initialize(const char* device_name,
return NO_ERROR;
}
EmulatedCameraDevice* EmulatedQemuCamera::GetCameraDevice()
EmulatedCameraDevice* EmulatedQemuCamera::getCameraDevice()
{
return &qemu_camera_dev_;
return &mQemuCameraDevice;
}
}; /* namespace android */

View File

@@ -22,8 +22,8 @@
* functionality of an emulated camera connected to the host.
*/
#include "emulated_camera.h"
#include "emulated_qemu_camera_device.h"
#include "EmulatedCamera.h"
#include "EmulatedQemuCameraDevice.h"
namespace android {
@@ -37,9 +37,9 @@ public:
/* Destructs EmulatedQemuCamera instance. */
~EmulatedQemuCamera();
/****************************************************************************
/***************************************************************************
* EmulatedCamera virtual overrides.
***************************************************************************/
**************************************************************************/
public:
/* Initializes EmulatedQemuCamera instance.
@@ -49,25 +49,25 @@ public:
*/
status_t Initialize(const char* device_name, const char* frame_dims);
/****************************************************************************
/***************************************************************************
* EmulatedCamera abstract API implementation.
***************************************************************************/
**************************************************************************/
protected:
/* Gets emulated camera device ised by this instance of the emulated camera.
*/
EmulatedCameraDevice* GetCameraDevice();
EmulatedCameraDevice* getCameraDevice();
/****************************************************************************
/***************************************************************************
* Data memebers.
***************************************************************************/
**************************************************************************/
protected:
/* Contained qemu camera device object. */
EmulatedQemuCameraDevice qemu_camera_dev_;
EmulatedQemuCameraDevice mQemuCameraDevice;
/* Supported frame dimensions reported by the camera device. */
String8 frame_dims_;
String8 mFrameDims;
};
}; /* namespace android */

View File

@@ -22,22 +22,22 @@
#define LOG_NDEBUG 0
#define LOG_TAG "EmulatedCamera_QemuDevice"
#include <cutils/log.h>
#include "emulated_qemu_camera.h"
#include "emulated_qemu_camera_device.h"
#include "EmulatedQemuCamera.h"
#include "EmulatedQemuCameraDevice.h"
namespace android {
EmulatedQemuCameraDevice::EmulatedQemuCameraDevice(EmulatedQemuCamera* camera_hal)
: EmulatedCameraDevice(camera_hal),
qemu_client_(),
preview_frame_(NULL)
mQemuClient(),
mPreviewFrame(NULL)
{
}
EmulatedQemuCameraDevice::~EmulatedQemuCameraDevice()
{
if (preview_frame_ != NULL) {
delete[] preview_frame_;
if (mPreviewFrame != NULL) {
delete[] mPreviewFrame;
}
}
@@ -50,7 +50,7 @@ status_t EmulatedQemuCameraDevice::Initialize(const char* device_name)
/* Connect to the service. */
char connect_str[256];
snprintf(connect_str, sizeof(connect_str), "name=%s", device_name);
status_t res = qemu_client_.Connect(connect_str);
status_t res = mQemuClient.connectClient(connect_str);
if (res != NO_ERROR) {
return res;
}
@@ -60,9 +60,9 @@ status_t EmulatedQemuCameraDevice::Initialize(const char* device_name)
if (res == NO_ERROR) {
LOGV("%s: Connected to the emulated camera service '%s'",
__FUNCTION__, device_name);
device_name_ = device_name;
mDeviceName = device_name;
} else {
qemu_client_.Disconnect();
mQemuClient.disconnectDevice();
}
return res;
@@ -72,24 +72,24 @@ status_t EmulatedQemuCameraDevice::Initialize(const char* device_name)
* Emulated camera device abstract interface implementation.
***************************************************************************/
status_t EmulatedQemuCameraDevice::Connect()
status_t EmulatedQemuCameraDevice::connectDevice()
{
LOGV("%s", __FUNCTION__);
Mutex::Autolock locker(&object_lock_);
if (!IsInitialized()) {
Mutex::Autolock locker(&mObjectLock);
if (!isInitialized()) {
LOGE("%s: Qemu camera device is not initialized.", __FUNCTION__);
return EINVAL;
}
if (IsConnected()) {
if (isConnected()) {
LOGW("%s: Qemu camera device is already connected.", __FUNCTION__);
return NO_ERROR;
}
const status_t res = qemu_client_.QueryConnect();
const status_t res = mQemuClient.queryConnect();
if (res == NO_ERROR) {
LOGV("%s: Connected", __FUNCTION__);
state_ = ECDS_CONNECTED;
mState = ECDS_CONNECTED;
} else {
LOGE("%s: Connection failed", __FUNCTION__);
}
@@ -97,24 +97,24 @@ status_t EmulatedQemuCameraDevice::Connect()
return res;
}
status_t EmulatedQemuCameraDevice::Disconnect()
status_t EmulatedQemuCameraDevice::disconnectDevice()
{
LOGV("%s", __FUNCTION__);
Mutex::Autolock locker(&object_lock_);
if (!IsConnected()) {
Mutex::Autolock locker(&mObjectLock);
if (!isConnected()) {
LOGW("%s: Qemu camera device is already disconnected.", __FUNCTION__);
return NO_ERROR;
}
if (IsCapturing()) {
if (isCapturing()) {
LOGE("%s: Cannot disconnect while in the capturing state.", __FUNCTION__);
return EINVAL;
}
const status_t res = qemu_client_.QueryDisconnect();
const status_t res = mQemuClient.queryDisconnect();
if (res == NO_ERROR) {
LOGV("%s: Disonnected", __FUNCTION__);
state_ = ECDS_INITIALIZED;
mState = ECDS_INITIALIZED;
} else {
LOGE("%s: Disconnection failed", __FUNCTION__);
}
@@ -122,16 +122,16 @@ status_t EmulatedQemuCameraDevice::Disconnect()
return res;
}
status_t EmulatedQemuCameraDevice::StartCamera()
status_t EmulatedQemuCameraDevice::startDevice()
{
LOGV("%s", __FUNCTION__);
Mutex::Autolock locker(&object_lock_);
if (!IsConnected()) {
Mutex::Autolock locker(&mObjectLock);
if (!isConnected()) {
LOGE("%s: Qemu camera device is not connected.", __FUNCTION__);
return EINVAL;
}
if (IsCapturing()) {
if (isCapturing()) {
LOGW("%s: Qemu camera device is already capturing.", __FUNCTION__);
return NO_ERROR;
}
@@ -139,24 +139,24 @@ status_t EmulatedQemuCameraDevice::StartCamera()
/* Allocate preview frame buffer. */
/* TODO: Watch out for preview format changes! At this point we implement
* RGB32 only.*/
preview_frame_ = new uint16_t[total_pixels_ * 4];
if (preview_frame_ == NULL) {
mPreviewFrame = new uint16_t[mTotalPixels * 4];
if (mPreviewFrame == NULL) {
LOGE("%s: Unable to allocate %d bytes for preview frame",
__FUNCTION__, total_pixels_ * 4);
__FUNCTION__, mTotalPixels * 4);
return ENOMEM;
}
memset(preview_frame_, 0, total_pixels_ * 4);
memset(mPreviewFrame, 0, mTotalPixels * 4);
/* Start the actual camera device. */
status_t res =
qemu_client_.QueryStart(pixel_format_, frame_width_, frame_height_);
mQemuClient.queryStart(mPixelFormat, mFrameWidth, mFrameHeight);
if (res == NO_ERROR) {
/* Start the worker thread. */
res = StartWorkerThread();
res = startWorkerThread();
if (res == NO_ERROR) {
state_ = ECDS_CAPTURING;
mState = ECDS_CAPTURING;
} else {
qemu_client_.QueryStop();
mQemuClient.queryStop();
}
} else {
LOGE("%s: Start failed", __FUNCTION__);
@@ -165,27 +165,27 @@ status_t EmulatedQemuCameraDevice::StartCamera()
return res;
}
status_t EmulatedQemuCameraDevice::StopCamera()
status_t EmulatedQemuCameraDevice::stopDevice()
{
LOGV("%s", __FUNCTION__);
Mutex::Autolock locker(&object_lock_);
if (!IsCapturing()) {
Mutex::Autolock locker(&mObjectLock);
if (!isCapturing()) {
LOGW("%s: Qemu camera device is not capturing.", __FUNCTION__);
return NO_ERROR;
}
/* Stop the actual camera device. */
status_t res = qemu_client_.QueryStop();
status_t res = mQemuClient.queryStop();
if (res == NO_ERROR) {
/* Stop the worker thread. */
res = StopWorkerThread();
res = stopWorkerThread();
if (res == NO_ERROR) {
if (preview_frame_ == NULL) {
delete[] preview_frame_;
preview_frame_ = NULL;
if (mPreviewFrame == NULL) {
delete[] mPreviewFrame;
mPreviewFrame = NULL;
}
state_ = ECDS_CONNECTED;
mState = ECDS_CONNECTED;
LOGV("%s: Stopped", __FUNCTION__);
}
} else {
@@ -199,14 +199,14 @@ status_t EmulatedQemuCameraDevice::StopCamera()
* EmulatedCameraDevice virtual overrides
***************************************************************************/
status_t EmulatedQemuCameraDevice::GetCurrentPreviewFrame(void* buffer)
status_t EmulatedQemuCameraDevice::getCurrentPreviewFrame(void* buffer)
{
LOGW_IF(preview_frame_ == NULL, "%s: No preview frame", __FUNCTION__);
if (preview_frame_ != NULL) {
memcpy(buffer, preview_frame_, total_pixels_ * 4);
LOGW_IF(mPreviewFrame == NULL, "%s: No preview frame", __FUNCTION__);
if (mPreviewFrame != NULL) {
memcpy(buffer, mPreviewFrame, mTotalPixels * 4);
return 0;
} else {
return EmulatedCameraDevice::GetCurrentPreviewFrame(buffer);
return EmulatedCameraDevice::getCurrentPreviewFrame(buffer);
}
}
@@ -214,24 +214,24 @@ status_t EmulatedQemuCameraDevice::GetCurrentPreviewFrame(void* buffer)
* Worker thread management overrides.
***************************************************************************/
bool EmulatedQemuCameraDevice::InWorkerThread()
bool EmulatedQemuCameraDevice::inWorkerThread()
{
/* Wait till FPS timeout expires, or thread exit message is received. */
WorkerThread::SelectRes res =
worker_thread()->Select(-1, 1000000 / emulated_fps_);
getWorkerThread()->Select(-1, 1000000 / mEmulatedFPS);
if (res == WorkerThread::EXIT_THREAD) {
LOGV("%s: Worker thread has been terminated.", __FUNCTION__);
return false;
}
/* Query frames from the service. */
status_t query_res = qemu_client_.QueryFrame(current_frame_, preview_frame_,
framebuffer_size_,
total_pixels_ * 4);
status_t query_res = mQemuClient.queryFrame(mCurrentFrame, mPreviewFrame,
mFrameBufferSize,
mTotalPixels * 4);
if (query_res == NO_ERROR) {
/* Timestamp the current frame, and notify the camera HAL. */
timestamp_ = systemTime(SYSTEM_TIME_MONOTONIC);
camera_hal_->OnNextFrameAvailable(current_frame_, timestamp_, this);
mCurFrameTimestamp = systemTime(SYSTEM_TIME_MONOTONIC);
mCameraHAL->onNextFrameAvailable(mCurrentFrame, mCurFrameTimestamp, this);
} else {
LOGE("%s: Unable to get current video frame: %s",
__FUNCTION__, strerror(query_res));

View File

@@ -22,7 +22,7 @@
* an emulated camera device connected to the host.
*/
#include "emulated_camera_device.h"
#include "EmulatedCameraDevice.h"
#include "QemuClient.h"
namespace android {
@@ -39,9 +39,9 @@ public:
/* Destructs EmulatedQemuCameraDevice instance. */
~EmulatedQemuCameraDevice();
/****************************************************************************
/***************************************************************************
* Public API
***************************************************************************/
**************************************************************************/
public:
/* Initializes EmulatedQemuCameraDevice instance.
@@ -54,65 +54,65 @@ public:
*/
status_t Initialize(const char* device_name);
/****************************************************************************
/***************************************************************************
* Emulated camera device abstract interface implementation.
* See declarations of these methods in EmulatedCameraDevice class for
* information on each of these methods.
***************************************************************************/
**************************************************************************/
public:
/* Connects to the camera device. */
status_t Connect();
status_t connectDevice();
/* Disconnects from the camera device. */
status_t Disconnect();
status_t disconnectDevice();
protected:
/* Starts capturing frames from the camera device. */
status_t StartCamera();
status_t startDevice();
/* Stops capturing frames from the camera device. */
status_t StopCamera();
status_t stopDevice();
/****************************************************************************
/***************************************************************************
* EmulatedCameraDevice virtual overrides
***************************************************************************/
**************************************************************************/
public:
/* Gets current preview fame into provided buffer.
* We override this method in order to provide preview frames cached in this
* object.
*/
status_t GetCurrentPreviewFrame(void* buffer);
status_t getCurrentPreviewFrame(void* buffer);
/****************************************************************************
/***************************************************************************
* Worker thread management overrides.
* See declarations of these methods in EmulatedCameraDevice class for
* information on each of these methods.
***************************************************************************/
**************************************************************************/
protected:
/* Implementation of the worker thread routine. */
bool InWorkerThread();
bool inWorkerThread();
/****************************************************************************
/***************************************************************************
* Qemu camera device data members
***************************************************************************/
**************************************************************************/
private:
/* Qemu client that is used to communicate with the 'emulated camera' service,
* created for this instance in the emulator. */
CameraQemuClient qemu_client_;
/* Qemu client that is used to communicate with the 'emulated camera'
* service, created for this instance in the emulator. */
CameraQemuClient mQemuClient;
/* Name of the camera device connected to the host. */
String8 device_name_;
String8 mDeviceName;
/* Current preview framebuffer. */
uint16_t* preview_frame_;
uint16_t* mPreviewFrame;
/* Emulated FPS (frames per second).
* We will emulate 50 FPS. */
static const int emulated_fps_ = 50;
static const int mEmulatedFPS = 50;
};
}; /* namespace android */

View File

@@ -24,17 +24,17 @@
#include <cutils/log.h>
#include <ui/Rect.h>
#include <ui/GraphicBufferMapper.h>
#include "emulated_camera_device.h"
#include "preview_window.h"
#include "EmulatedCameraDevice.h"
#include "PreviewWindow.h"
namespace android {
PreviewWindow::PreviewWindow()
: preview_window_(NULL),
last_previewed_(0),
preview_frame_width_(0),
preview_frame_height_(0),
preview_enabled_(false)
: mPreviewWindow(NULL),
mLastPreviewed(0),
mPreviewFrameWidth(0),
mPreviewFrameHeight(0),
mPreviewEnabled(false)
{
}
@@ -46,18 +46,18 @@ PreviewWindow::~PreviewWindow()
* Camera API
***************************************************************************/
status_t PreviewWindow::SetPreviewWindow(struct preview_stream_ops* window,
status_t PreviewWindow::setPreviewWindow(struct preview_stream_ops* window,
int preview_fps)
{
LOGV("%s: current: %p -> new: %p", __FUNCTION__, preview_window_, window);
LOGV("%s: current: %p -> new: %p", __FUNCTION__, mPreviewWindow, window);
status_t res = NO_ERROR;
Mutex::Autolock locker(&object_lock_);
Mutex::Autolock locker(&mObjectLock);
/* Reset preview info. */
preview_frame_width_ = preview_frame_height_ = 0;
preview_after_ = 0;
last_previewed_ = 0;
mPreviewFrameWidth = mPreviewFrameHeight = 0;
mPreviewAfter = 0;
mLastPreviewed = 0;
if (window != NULL) {
/* The CPU will write each frame to the preview window buffer.
@@ -66,7 +66,7 @@ status_t PreviewWindow::SetPreviewWindow(struct preview_stream_ops* window,
res = window->set_usage(window, GRALLOC_USAGE_SW_WRITE_OFTEN);
if (res == NO_ERROR) {
/* Set preview frequency. */
preview_after_ = 1000000 / preview_fps;
mPreviewAfter = 1000000 / preview_fps;
} else {
window = NULL;
res = -res; // set_usage returns a negative errno.
@@ -74,61 +74,61 @@ status_t PreviewWindow::SetPreviewWindow(struct preview_stream_ops* window,
__FUNCTION__, res, strerror(res));
}
}
preview_window_ = window;
mPreviewWindow = window;
return res;
}
status_t PreviewWindow::Start()
status_t PreviewWindow::startPreview()
{
LOGV("%s", __FUNCTION__);
Mutex::Autolock locker(&object_lock_);
preview_enabled_ = true;
Mutex::Autolock locker(&mObjectLock);
mPreviewEnabled = true;
return NO_ERROR;
}
void PreviewWindow::Stop()
void PreviewWindow::stopPreview()
{
LOGV("%s", __FUNCTION__);
Mutex::Autolock locker(&object_lock_);
preview_enabled_ = false;
Mutex::Autolock locker(&mObjectLock);
mPreviewEnabled = false;
}
bool PreviewWindow::IsEnabled()
bool PreviewWindow::isPreviewEnabled()
{
Mutex::Autolock locker(&object_lock_);
return preview_enabled_;
Mutex::Autolock locker(&mObjectLock);
return mPreviewEnabled;
}
/****************************************************************************
* Public API
***************************************************************************/
void PreviewWindow::OnNextFrameAvailable(const void* frame,
void PreviewWindow::onNextFrameAvailable(const void* frame,
nsecs_t timestamp,
EmulatedCameraDevice* camera_dev)
{
int res;
Mutex::Autolock locker(&object_lock_);
Mutex::Autolock locker(&mObjectLock);
if (!preview_enabled_ || preview_window_ == NULL || !IsTimeToPreview()) {
if (!mPreviewEnabled || mPreviewWindow == NULL || !isPreviewTime()) {
return;
}
/* Make sure that preview window dimensions are OK with the camera device. */
if (AdjustPreviewDimensions(camera_dev)) {
/* Make sure that preview window dimensions are OK with the camera device */
if (adjustPreviewDimensions(camera_dev)) {
/* Need to set / adjust buffer geometry for the preview window.
* Note that in the emulator preview window uses only RGB for pixel
* formats. */
LOGV("%s: Adjusting preview windows %p geometry to %dx%d",
__FUNCTION__, preview_window_, preview_frame_width_,
preview_frame_height_);
res = preview_window_->set_buffers_geometry(preview_window_,
preview_frame_width_,
preview_frame_height_,
__FUNCTION__, mPreviewWindow, mPreviewFrameWidth,
mPreviewFrameHeight);
res = mPreviewWindow->set_buffers_geometry(mPreviewWindow,
mPreviewFrameWidth,
mPreviewFrameHeight,
HAL_PIXEL_FORMAT_RGBA_8888);
if (res != NO_ERROR) {
LOGE("%s: Error in set_buffers_geometry %d -> %s",
@@ -144,7 +144,7 @@ void PreviewWindow::OnNextFrameAvailable(const void* frame,
/* Dequeue preview window buffer for the frame. */
buffer_handle_t* buffer = NULL;
int stride = 0;
res = preview_window_->dequeue_buffer(preview_window_, &buffer, &stride);
res = mPreviewWindow->dequeue_buffer(mPreviewWindow, &buffer, &stride);
if (res != NO_ERROR || buffer == NULL) {
LOGE("%s: Unable to dequeue preview window buffer: %d -> %s",
__FUNCTION__, -res, strerror(-res));
@@ -152,63 +152,63 @@ void PreviewWindow::OnNextFrameAvailable(const void* frame,
}
/* Let the preview window to lock the buffer. */
res = preview_window_->lock_buffer(preview_window_, buffer);
res = mPreviewWindow->lock_buffer(mPreviewWindow, buffer);
if (res != NO_ERROR) {
LOGE("%s: Unable to lock preview window buffer: %d -> %s",
__FUNCTION__, -res, strerror(-res));
preview_window_->cancel_buffer(preview_window_, buffer);
mPreviewWindow->cancel_buffer(mPreviewWindow, buffer);
return;
}
/* Now let the graphics framework to lock the buffer, and provide
* us with the framebuffer data address. */
void* img = NULL;
const Rect rect(preview_frame_width_, preview_frame_height_);
const Rect rect(mPreviewFrameWidth, mPreviewFrameHeight);
GraphicBufferMapper& grbuffer_mapper(GraphicBufferMapper::get());
res = grbuffer_mapper.lock(*buffer, GRALLOC_USAGE_SW_WRITE_OFTEN, rect, &img);
if (res != NO_ERROR) {
LOGE("%s: grbuffer_mapper.lock failure: %d -> %s",
__FUNCTION__, res, strerror(res));
preview_window_->cancel_buffer(preview_window_, buffer);
mPreviewWindow->cancel_buffer(mPreviewWindow, buffer);
return;
}
/* Frames come in in YV12/NV12/NV21 format. Since preview window doesn't
* supports those formats, we need to obtain the frame in RGB565. */
res = camera_dev->GetCurrentPreviewFrame(img);
res = camera_dev->getCurrentPreviewFrame(img);
if (res == NO_ERROR) {
/* Show it. */
preview_window_->enqueue_buffer(preview_window_, buffer);
mPreviewWindow->enqueue_buffer(mPreviewWindow, buffer);
} else {
LOGE("%s: Unable to obtain preview frame: %d", __FUNCTION__, res);
preview_window_->cancel_buffer(preview_window_, buffer);
mPreviewWindow->cancel_buffer(mPreviewWindow, buffer);
}
grbuffer_mapper.unlock(*buffer);
}
bool PreviewWindow::AdjustPreviewDimensions(EmulatedCameraDevice* camera_dev)
bool PreviewWindow::adjustPreviewDimensions(EmulatedCameraDevice* camera_dev)
{
/* Match the cached frame dimensions against the actual ones. */
if (preview_frame_width_ == camera_dev->GetFrameWidth() &&
preview_frame_height_ == camera_dev->GetFrameHeight()) {
if (mPreviewFrameWidth == camera_dev->getFrameWidth() &&
mPreviewFrameHeight == camera_dev->getFrameHeight()) {
/* They match. */
return false;
}
/* They don't match: adjust the cache. */
preview_frame_width_ = camera_dev->GetFrameWidth();
preview_frame_height_ = camera_dev->GetFrameHeight();
mPreviewFrameWidth = camera_dev->getFrameWidth();
mPreviewFrameHeight = camera_dev->getFrameHeight();
return true;
}
bool PreviewWindow::IsTimeToPreview()
bool PreviewWindow::isPreviewTime()
{
timeval cur_time;
gettimeofday(&cur_time, NULL);
const uint64_t cur_mks = cur_time.tv_sec * 1000000LL + cur_time.tv_usec;
if ((cur_mks - last_previewed_) >= preview_after_) {
last_previewed_ = cur_mks;
if ((cur_mks - mLastPreviewed) >= mPreviewAfter) {
mLastPreviewed = cur_mks;
return true;
}
return false;

View File

@@ -40,9 +40,9 @@ public:
/* Destructs PreviewWindow instance. */
~PreviewWindow();
/****************************************************************************
/***************************************************************************
* Camera API
***************************************************************************/
**************************************************************************/
public:
/* Actual handler for camera_device_ops_t::set_preview_window callback.
@@ -52,29 +52,29 @@ public:
* window - Preview window to set. This parameter might be NULL, which
* indicates preview window reset.
* preview_fps - Preview's frame frequency. This parameter determins when
* a frame received via OnNextFrameAvailable call will be pushed to the
* preview window. If 'window' parameter passed to this method is NULL,
* this parameter is ignored.
* a frame received via onNextFrameAvailable call will be pushed to
* the preview window. If 'window' parameter passed to this method is
* NULL, this parameter is ignored.
* Return:
* NO_ERROR on success, or an appropriate error status.
*/
status_t SetPreviewWindow(struct preview_stream_ops* window,
status_t setPreviewWindow(struct preview_stream_ops* window,
int preview_fps);
/* Starts the preview.
* This method is called by the containing emulated camera object when it is
* handing the camera_device_ops_t::start_preview callback.
*/
status_t Start();
status_t startPreview();
/* Stops the preview.
* This method is called by the containing emulated camera object when it is
* handing the camera_device_ops_t::start_preview callback.
*/
void Stop();
void stopPreview();
/* Checks if preview is enabled. */
bool IsEnabled();
bool isPreviewEnabled();
/****************************************************************************
* Public API
@@ -96,13 +96,13 @@ public:
* timestamp - Frame's timestamp.
* camera_dev - Camera device instance that delivered the frame.
*/
void OnNextFrameAvailable(const void* frame,
void onNextFrameAvailable(const void* frame,
nsecs_t timestamp,
EmulatedCameraDevice* camera_dev);
/****************************************************************************
/***************************************************************************
* Private API
***************************************************************************/
**************************************************************************/
protected:
/* Adjusts cached dimensions of the preview window frame according to the
@@ -111,9 +111,9 @@ protected:
* When preview is started, it's not known (hard to define) what are going
* to be the dimensions of the frames that are going to be displayed. Plus,
* it might be possible, that such dimensions can be changed on the fly. So,
* in order to be always in sync with frame dimensions, this method is called
* for each frame passed to OnNextFrameAvailable method, in order to properly
* adjust frame dimensions, used by the preview window.
* in order to be always in sync with frame dimensions, this method is
* called for each frame passed to onNextFrameAvailable method, in order to
* properly adjust frame dimensions, used by the preview window.
* Note that this method must be called while object is locked.
* Param:
* camera_dev - Camera device, prpviding frames displayed in the preview
@@ -122,39 +122,39 @@ protected:
* true if cached dimensions have been adjusted, or false if cached
* dimensions match device's frame dimensions.
*/
bool AdjustPreviewDimensions(EmulatedCameraDevice* camera_dev);
bool adjustPreviewDimensions(EmulatedCameraDevice* camera_dev);
/* Checks if it's the time to push new frame to the preview window.
* Note that this method must be called while object is locked. */
bool IsTimeToPreview();
bool isPreviewTime();
/****************************************************************************
/***************************************************************************
* Data members
***************************************************************************/
**************************************************************************/
protected:
/* Locks this instance for data changes. */
Mutex object_lock_;
Mutex mObjectLock;
/* Preview window instance. */
preview_stream_ops* preview_window_;
preview_stream_ops* mPreviewWindow;
/* Timestamp (abs. microseconds) when last frame has been pushed to the
* preview window. */
uint64_t last_previewed_;
uint64_t mLastPreviewed;
/* Preview frequency in microseconds. */
uint32_t preview_after_;
uint32_t mPreviewAfter;
/*
* Cached preview window frame dimensions.
*/
int preview_frame_width_;
int preview_frame_height_;
int mPreviewFrameWidth;
int mPreviewFrameHeight;
/* Preview status. */
bool preview_enabled_;
bool mPreviewEnabled;
};
}; /* namespace android */

290
tools/emulator/system/camera/QemuClient.cpp Normal file → Executable file
View File

@@ -22,7 +22,7 @@
#define LOG_NDEBUG 0
#define LOG_TAG "EmulatedCamera_QemuClient"
#include <cutils/log.h>
#include "emulated_camera.h"
#include "EmulatedCamera.h"
#include "QemuClient.h"
namespace android {
@@ -32,50 +32,50 @@ namespace android {
***************************************************************************/
QemuQuery::QemuQuery()
: query_(query_prealloc_),
query_status_(NO_ERROR),
reply_buffer_(NULL),
reply_data_(NULL),
reply_size_(0),
reply_data_size_(0),
reply_status_(0)
: mQuery(mQueryPrealloc),
mQueryStatus(NO_ERROR),
mReplyBuffer(NULL),
mReplyData(NULL),
mReplySize(0),
mReplyDataSize(0),
mReplyStatus(0)
{
*query_ = '\0';
*mQuery = '\0';
}
QemuQuery::QemuQuery(const char* query_string)
: query_(query_prealloc_),
query_status_(NO_ERROR),
reply_buffer_(NULL),
reply_data_(NULL),
reply_size_(0),
reply_data_size_(0),
reply_status_(0)
: mQuery(mQueryPrealloc),
mQueryStatus(NO_ERROR),
mReplyBuffer(NULL),
mReplyData(NULL),
mReplySize(0),
mReplyDataSize(0),
mReplyStatus(0)
{
query_status_ = QemuQuery::Create(query_string, NULL);
mQueryStatus = QemuQuery::createQuery(query_string, NULL);
}
QemuQuery::QemuQuery(const char* query_name, const char* query_param)
: query_(query_prealloc_),
query_status_(NO_ERROR),
reply_buffer_(NULL),
reply_data_(NULL),
reply_size_(0),
reply_data_size_(0),
reply_status_(0)
: mQuery(mQueryPrealloc),
mQueryStatus(NO_ERROR),
mReplyBuffer(NULL),
mReplyData(NULL),
mReplySize(0),
mReplyDataSize(0),
mReplyStatus(0)
{
query_status_ = QemuQuery::Create(query_name, query_param);
mQueryStatus = QemuQuery::createQuery(query_name, query_param);
}
QemuQuery::~QemuQuery()
{
QemuQuery::Reset();
QemuQuery::resetQuery();
}
status_t QemuQuery::Create(const char* name, const char* param)
status_t QemuQuery::createQuery(const char* name, const char* param)
{
/* Reset from the previous use. */
Reset();
resetQuery();
/* Query name cannot be NULL or an empty string. */
if (name == NULL || *name == '\0') {
@@ -88,33 +88,33 @@ status_t QemuQuery::Create(const char* name, const char* param)
const size_t param_len = (param != NULL) ? strlen(param) : 0;
const size_t required = strlen(name) + (param_len ? (param_len + 2) : 1);
if (required > sizeof(query_prealloc_)) {
if (required > sizeof(mQueryPrealloc)) {
/* Preallocated buffer was too small. Allocate a bigger query buffer. */
query_ = new char[required];
if (query_ == NULL) {
mQuery = new char[required];
if (mQuery == NULL) {
LOGE("%s: Unable to allocate %d bytes for query buffer",
__FUNCTION__, required);
query_status_ = ENOMEM;
mQueryStatus = ENOMEM;
return ENOMEM;
}
}
/* At this point query_ buffer is big enough for the query. */
/* At this point mQuery buffer is big enough for the query. */
if (param_len) {
sprintf(query_, "%s %s", name, param);
sprintf(mQuery, "%s %s", name, param);
} else {
memcpy(query_, name, name_len + 1);
memcpy(mQuery, name, name_len + 1);
}
return NO_ERROR;
}
status_t QemuQuery::Completed(status_t status)
status_t QemuQuery::completeQuery(status_t status)
{
/* Save query completion status. */
query_status_ = status;
if (query_status_ != NO_ERROR) {
return query_status_;
mQueryStatus = status;
if (mQueryStatus != NO_ERROR) {
return mQueryStatus;
}
/* Make sure reply buffer contains at least 'ok', or 'ko'.
@@ -122,40 +122,40 @@ status_t QemuQuery::Completed(status_t status)
* there are more data in the reply, that data will be separated from 'ok'/'ko'
* with a ':'. If there is no more data in the reply, the prefix will be
* zero-terminated, and the terminator will be inculded in the reply. */
if (reply_buffer_ == NULL || reply_size_ < 3) {
if (mReplyBuffer == NULL || mReplySize < 3) {
LOGE("%s: Invalid reply to the query", __FUNCTION__);
query_status_ = EINVAL;
mQueryStatus = EINVAL;
return EINVAL;
}
/* Lets see the reply status. */
if (!memcmp(reply_buffer_, "ok", 2)) {
reply_status_ = 1;
} else if (!memcmp(reply_buffer_, "ko", 2)) {
reply_status_ = 0;
if (!memcmp(mReplyBuffer, "ok", 2)) {
mReplyStatus = 1;
} else if (!memcmp(mReplyBuffer, "ko", 2)) {
mReplyStatus = 0;
} else {
LOGE("%s: Invalid query reply: '%s'", __FUNCTION__, reply_buffer_);
query_status_ = EINVAL;
LOGE("%s: Invalid query reply: '%s'", __FUNCTION__, mReplyBuffer);
mQueryStatus = EINVAL;
return EINVAL;
}
/* Lets see if there are reply data that follow. */
if (reply_size_ > 3) {
if (mReplySize > 3) {
/* There are extra data. Make sure they are separated from the status
* with a ':' */
if (reply_buffer_[2] != ':') {
LOGE("%s: Invalid query reply: '%s'", __FUNCTION__, reply_buffer_);
query_status_ = EINVAL;
if (mReplyBuffer[2] != ':') {
LOGE("%s: Invalid query reply: '%s'", __FUNCTION__, mReplyBuffer);
mQueryStatus = EINVAL;
return EINVAL;
}
reply_data_ = reply_buffer_ + 3;
reply_data_size_ = reply_size_ - 3;
mReplyData = mReplyBuffer + 3;
mReplyDataSize = mReplySize - 3;
} else {
/* Make sure reply buffer containing just 'ok'/'ko' ends with
* zero-terminator. */
if (reply_buffer_[2] != '\0') {
LOGE("%s: Invalid query reply: '%s'", __FUNCTION__, reply_buffer_);
query_status_ = EINVAL;
if (mReplyBuffer[2] != '\0') {
LOGE("%s: Invalid query reply: '%s'", __FUNCTION__, mReplyBuffer);
mQueryStatus = EINVAL;
return EINVAL;
}
}
@@ -163,21 +163,21 @@ status_t QemuQuery::Completed(status_t status)
return NO_ERROR;
}
void QemuQuery::Reset()
void QemuQuery::resetQuery()
{
if (query_ != NULL && query_ != query_prealloc_) {
delete[] query_;
if (mQuery != NULL && mQuery != mQueryPrealloc) {
delete[] mQuery;
}
query_ = query_prealloc_;
query_status_ = NO_ERROR;
if (reply_buffer_ != NULL) {
free(reply_buffer_);
reply_buffer_ = NULL;
mQuery = mQueryPrealloc;
mQueryStatus = NO_ERROR;
if (mReplyBuffer != NULL) {
free(mReplyBuffer);
mReplyBuffer = NULL;
}
reply_data_ = NULL;
reply_size_ = 0;
reply_data_size_ = 0;
reply_status_ = 0;
mReplyData = NULL;
mReplySize = 0;
mReplyDataSize = 0;
mReplyStatus = 0;
}
/****************************************************************************
@@ -185,17 +185,17 @@ void QemuQuery::Reset()
***************************************************************************/
/* Camera service name. */
const char QemuClient::camera_service_name_[] = "camera";
const char QemuClient::mCameraServiceName[] = "camera";
QemuClient::QemuClient()
: fd_(-1)
: mPipeFD(-1)
{
}
QemuClient::~QemuClient()
{
if (fd_ >= 0) {
close(fd_);
if (mPipeFD >= 0) {
close(mPipeFD);
}
}
@@ -203,12 +203,12 @@ QemuClient::~QemuClient()
* Qemu client API
***************************************************************************/
status_t QemuClient::Connect(const char* param)
status_t QemuClient::connectClient(const char* param)
{
LOGV("%s: '%s'", __FUNCTION__, param ? param : "");
/* Make sure that client is not connected already. */
if (fd_ >= 0) {
if (mPipeFD >= 0) {
LOGE("%s: Qemu client is already connected", __FUNCTION__);
return EINVAL;
}
@@ -217,19 +217,19 @@ status_t QemuClient::Connect(const char* param)
if (param == NULL || *param == '\0') {
/* No parameters: connect to the factory service. */
char pipe_name[512];
snprintf(pipe_name, sizeof(pipe_name), "qemud:%s", camera_service_name_);
fd_ = qemu_pipe_open(pipe_name);
snprintf(pipe_name, sizeof(pipe_name), "qemud:%s", mCameraServiceName);
mPipeFD = qemu_pipe_open(pipe_name);
} else {
/* One extra char ':' that separates service name and parameters + six
* characters for 'qemud:'. This is required by qemu pipe protocol. */
char* connection_str = new char[strlen(camera_service_name_) +
char* connection_str = new char[strlen(mCameraServiceName) +
strlen(param) + 8];
sprintf(connection_str, "qemud:%s:%s", camera_service_name_, param);
sprintf(connection_str, "qemud:%s:%s", mCameraServiceName, param);
fd_ = qemu_pipe_open(connection_str);
mPipeFD = qemu_pipe_open(connection_str);
delete[] connection_str;
}
if (fd_ < 0) {
if (mPipeFD < 0) {
LOGE("%s: Unable to connect to the camera service '%s': %s",
__FUNCTION__, param ? param : "Factory", strerror(errno));
return errno ? errno : EINVAL;
@@ -238,17 +238,17 @@ status_t QemuClient::Connect(const char* param)
return NO_ERROR;
}
void QemuClient::Disconnect()
void QemuClient::disconnectClient()
{
if (fd_ >= 0) {
close(fd_);
fd_ = -1;
if (mPipeFD >= 0) {
close(mPipeFD);
mPipeFD = -1;
}
}
status_t QemuClient::Send(const void* data, size_t data_size)
status_t QemuClient::sendMessage(const void* data, size_t data_size)
{
if (fd_ < 0) {
if (mPipeFD < 0) {
LOGE("%s: Qemu client is not connected", __FUNCTION__);
return EINVAL;
}
@@ -257,7 +257,7 @@ status_t QemuClient::Send(const void* data, size_t data_size)
* don't need to provide payload size prior to payload when we're writing to
* the pipe. So, we can use simple write, and qemu pipe will take care of the
* rest, calling the receiving end with the number of bytes transferred. */
const size_t written = qemud_fd_write(fd_, data, data_size);
const size_t written = qemud_fd_write(mPipeFD, data, data_size);
if (written == data_size) {
return NO_ERROR;
} else {
@@ -267,12 +267,12 @@ status_t QemuClient::Send(const void* data, size_t data_size)
}
}
status_t QemuClient::Receive(void** data, size_t* data_size)
status_t QemuClient::receiveMessage(void** data, size_t* data_size)
{
*data = NULL;
*data_size = 0;
if (fd_ < 0) {
if (mPipeFD < 0) {
LOGE("%s: Qemu client is not connected", __FUNCTION__);
return EINVAL;
}
@@ -283,7 +283,7 @@ status_t QemuClient::Receive(void** data, size_t* data_size)
* value. Note also, that the string doesn't contain zero-terminator. */
size_t payload_size;
char payload_size_str[9];
int rd_res = qemud_fd_read(fd_, payload_size_str, 8);
int rd_res = qemud_fd_read(mPipeFD, payload_size_str, 8);
if (rd_res != 8) {
LOGE("%s: Unable to obtain payload size: %s",
__FUNCTION__, strerror(errno));
@@ -306,7 +306,7 @@ status_t QemuClient::Receive(void** data, size_t* data_size)
__FUNCTION__, payload_size);
return ENOMEM;
}
rd_res = qemud_fd_read(fd_, *data, payload_size);
rd_res = qemud_fd_read(mPipeFD, *data, payload_size);
if (static_cast<size_t>(rd_res) == payload_size) {
*data_size = payload_size;
return NO_ERROR;
@@ -319,31 +319,31 @@ status_t QemuClient::Receive(void** data, size_t* data_size)
}
}
status_t QemuClient::Query(QemuQuery* query)
status_t QemuClient::doQuery(QemuQuery* query)
{
/* Make sure that query has been successfuly constructed. */
if (query->query_status_ != NO_ERROR) {
if (query->mQueryStatus != NO_ERROR) {
LOGE("%s: Query is invalid", __FUNCTION__);
return query->query_status_;
return query->mQueryStatus;
}
/* Send the query. */
status_t res = Send(query->query_, strlen(query->query_) + 1);
status_t res = sendMessage(query->mQuery, strlen(query->mQuery) + 1);
if (res == NO_ERROR) {
/* Read the response. */
res = Receive(reinterpret_cast<void**>(&query->reply_buffer_),
&query->reply_size_);
res = receiveMessage(reinterpret_cast<void**>(&query->mReplyBuffer),
&query->mReplySize);
if (res != NO_ERROR) {
LOGE("%s Response to query '%s' has failed: %s",
__FUNCTION__, query->query_, strerror(res));
__FUNCTION__, query->mQuery, strerror(res));
}
} else {
LOGE("%s: Send query '%s' failed: %s",
__FUNCTION__, query->query_, strerror(res));
__FUNCTION__, query->mQuery, strerror(res));
}
/* Complete the query, and return its completion handling status. */
return query->Completed(res);
return query->completeQuery(res);
}
/****************************************************************************
@@ -355,7 +355,7 @@ status_t QemuClient::Query(QemuQuery* query)
*/
/* Queries list of cameras connected to the host. */
const char FactoryQemuClient::query_list_[] = "list";
const char FactoryQemuClient::mQueryList[] = "list";
FactoryQemuClient::FactoryQemuClient()
: QemuClient()
@@ -366,29 +366,29 @@ FactoryQemuClient::~FactoryQemuClient()
{
}
status_t FactoryQemuClient::ListCameras(char** list)
status_t FactoryQemuClient::listCameras(char** list)
{
QemuQuery query(query_list_);
Query(&query);
if (!query.IsSucceeded()) {
return query.GetCompletionStatus();
QemuQuery query(mQueryList);
doQuery(&query);
if (!query.isQuerySucceeded()) {
return query.getCompletionStatus();
}
/* Make sure there is a list returned. */
if (query.reply_data_size_ == 0) {
if (query.mReplyDataSize == 0) {
LOGE("%s: No camera list is returned.", __FUNCTION__);
return EINVAL;
}
/* Copy the list over. */
*list = (char*)malloc(query.reply_data_size_);
*list = (char*)malloc(query.mReplyDataSize);
if (*list != NULL) {
memcpy(*list, query.reply_data_, query.reply_data_size_);
memcpy(*list, query.mReplyData, query.mReplyDataSize);
LOGD("Emulated camera list: %s", *list);
return NO_ERROR;
} else {
LOGE("%s: Unable to allocate %d bytes",
__FUNCTION__, query.reply_data_size_);
__FUNCTION__, query.mReplyDataSize);
return ENOMEM;
}
}
@@ -402,15 +402,15 @@ status_t FactoryQemuClient::ListCameras(char** list)
*/
/* Connect to the camera device. */
const char CameraQemuClient::query_connect_[] = "connect";
const char CameraQemuClient::mQueryConnect[] = "connect";
/* Disconect from the camera device. */
const char CameraQemuClient::query_disconnect_[] = "disconnect";
const char CameraQemuClient::mQueryDisconnect[] = "disconnect";
/* Start capturing video from the camera device. */
const char CameraQemuClient::query_start_[] = "start";
const char CameraQemuClient::mQueryStart[] = "start";
/* Stop capturing video from the camera device. */
const char CameraQemuClient::query_stop_[] = "stop";
const char CameraQemuClient::mQueryStop[] = "stop";
/* Get next video frame from the camera device. */
const char CameraQemuClient::query_frame_[] = "frame";
const char CameraQemuClient::mQueryFrame[] = "frame";
CameraQemuClient::CameraQemuClient()
: QemuClient()
@@ -422,94 +422,94 @@ CameraQemuClient::~CameraQemuClient()
}
status_t CameraQemuClient::QueryConnect()
status_t CameraQemuClient::queryConnect()
{
QemuQuery query(query_connect_);
Query(&query);
const status_t res = query.GetCompletionStatus();
QemuQuery query(mQueryConnect);
doQuery(&query);
const status_t res = query.getCompletionStatus();
LOGE_IF(res != NO_ERROR, "%s failed: %s",
__FUNCTION__, query.reply_data_ ? query.reply_data_ :
__FUNCTION__, query.mReplyData ? query.mReplyData :
"No error message");
return res;
}
status_t CameraQemuClient::QueryDisconnect()
status_t CameraQemuClient::queryDisconnect()
{
QemuQuery query(query_disconnect_);
Query(&query);
const status_t res = query.GetCompletionStatus();
QemuQuery query(mQueryDisconnect);
doQuery(&query);
const status_t res = query.getCompletionStatus();
LOGE_IF(res != NO_ERROR, "%s failed: %s",
__FUNCTION__, query.reply_data_ ? query.reply_data_ :
__FUNCTION__, query.mReplyData ? query.mReplyData :
"No error message");
return res;
}
status_t CameraQemuClient::QueryStart(uint32_t pixel_format,
status_t CameraQemuClient::queryStart(uint32_t pixel_format,
int width,
int height)
{
char query_str[256];
snprintf(query_str, sizeof(query_str), "%s dim=%dx%d pix=%d",
query_start_, width, height, pixel_format);
mQueryStart, width, height, pixel_format);
QemuQuery query(query_str);
Query(&query);
const status_t res = query.GetCompletionStatus();
doQuery(&query);
const status_t res = query.getCompletionStatus();
LOGE_IF(res != NO_ERROR, "%s failed: %s",
__FUNCTION__, query.reply_data_ ? query.reply_data_ :
__FUNCTION__, query.mReplyData ? query.mReplyData :
"No error message");
return res;
}
status_t CameraQemuClient::QueryStop()
status_t CameraQemuClient::queryStop()
{
QemuQuery query(query_stop_);
Query(&query);
const status_t res = query.GetCompletionStatus();
QemuQuery query(mQueryStop);
doQuery(&query);
const status_t res = query.getCompletionStatus();
LOGE_IF(res != NO_ERROR, "%s failed: %s",
__FUNCTION__, query.reply_data_ ? query.reply_data_ :
__FUNCTION__, query.mReplyData ? query.mReplyData :
"No error message");
return res;
}
status_t CameraQemuClient::QueryFrame(void* vframe,
status_t CameraQemuClient::queryFrame(void* vframe,
void* pframe,
size_t vframe_size,
size_t pframe_size)
{
char query_str[256];
snprintf(query_str, sizeof(query_str), "%s video=%d preview=%d",
query_frame_, (vframe && vframe_size) ? vframe_size : 0,
mQueryFrame, (vframe && vframe_size) ? vframe_size : 0,
(pframe && pframe_size) ? pframe_size : 0);
QemuQuery query(query_str);
Query(&query);
const status_t res = query.GetCompletionStatus();
doQuery(&query);
const status_t res = query.getCompletionStatus();
LOGE_IF(res != NO_ERROR, "%s failed: %s",
__FUNCTION__, query.reply_data_ ? query.reply_data_ :
__FUNCTION__, query.mReplyData ? query.mReplyData :
"No error message");
if (res == NO_ERROR) {
/* Copy requested frames. */
size_t cur_offset = 0;
const uint8_t* frame = reinterpret_cast<const uint8_t*>(query.reply_data_);
const uint8_t* frame = reinterpret_cast<const uint8_t*>(query.mReplyData);
/* Video frame is always first. */
if (vframe != NULL && vframe_size != 0) {
/* Make sure that video frame is in. */
if ((query.reply_data_size_ - cur_offset) >= vframe_size) {
if ((query.mReplyDataSize - cur_offset) >= vframe_size) {
memcpy(vframe, frame, vframe_size);
cur_offset += vframe_size;
} else {
LOGE("%s: Reply (%d bytes) is to small to contain video frame (%d bytes)",
__FUNCTION__, query.reply_data_size_ - cur_offset, vframe_size);
__FUNCTION__, query.mReplyDataSize - cur_offset, vframe_size);
return EINVAL;
}
}
if (pframe != NULL && pframe_size != 0) {
/* Make sure that preview frame is in. */
if ((query.reply_data_size_ - cur_offset) >= pframe_size) {
if ((query.mReplyDataSize - cur_offset) >= pframe_size) {
memcpy(pframe, frame + cur_offset, pframe_size);
cur_offset += pframe_size;
} else {
LOGE("%s: Reply (%d bytes) is to small to contain preview frame (%d bytes)",
__FUNCTION__, query.reply_data_size_ - cur_offset, pframe_size);
__FUNCTION__, query.mReplyDataSize - cur_offset, pframe_size);
return EINVAL;
}
}

82
tools/emulator/system/camera/QemuClient.h Normal file → Executable file
View File

@@ -103,7 +103,7 @@ public:
* Return:
* NO_ERROR on success, or an appropriate error status.
*/
status_t Create(const char* name, const char* param);
status_t createQuery(const char* name, const char* param);
/* Completes the query after a reply from the emulator.
* This method will parse the reply buffer, and calculate the final query
@@ -119,32 +119,32 @@ public:
* Return:
* NO_ERROR on success, or an appropriate error status on failure. Note that
* status returned here just signals whether or not the method has succeeded.
* Use IsSucceeded() / GetCompletionStatus() methods to check the final
* Use isQuerySucceeded() / getCompletionStatus() methods to check the final
* query status.
*/
status_t Completed(status_t status);
status_t completeQuery(status_t status);
/* Resets the query from a previous use. */
void Reset();
void resetQuery();
/* Checks if query has succeeded.
* Note that this method must be called after Completed() method of this
* Note that this method must be called after completeQuery() method of this
* class has been executed.
*/
inline bool IsSucceeded() const {
return query_status_ == NO_ERROR && reply_status_ != 0;
inline bool isQuerySucceeded() const {
return mQueryStatus == NO_ERROR && mReplyStatus != 0;
}
/* Gets final completion status of the query.
* Note that this method must be called after Completed() method of this
* Note that this method must be called after completeQuery() method of this
* class has been executed.
* NO_ERROR on success, or an appropriate error status on failure.
*/
inline status_t GetCompletionStatus() const {
if (IsSucceeded()) {
inline status_t getCompletionStatus() const {
if (isQuerySucceeded()) {
return NO_ERROR;
}
return (query_status_ != NO_ERROR) ? query_status_ : EINVAL;
return (mQueryStatus != NO_ERROR) ? mQueryStatus : EINVAL;
}
/****************************************************************************
@@ -153,19 +153,19 @@ public:
public:
/* Query string. */
char* query_;
char* mQuery;
/* Query status. */
status_t query_status_;
status_t mQueryStatus;
/* Reply buffer */
char* reply_buffer_;
char* mReplyBuffer;
/* Reply data (past 'ok'/'ko'). If NULL, there were no data in reply. */
char* reply_data_;
char* mReplyData;
/* Reply buffer size. */
size_t reply_size_;
size_t mReplySize;
/* Reply data size. */
size_t reply_data_size_;
size_t mReplyDataSize;
/* Reply status: 1 - ok, 0 - ko. */
int reply_status_;
int mReplyStatus;
/****************************************************************************
* Private data memebers
@@ -173,7 +173,7 @@ public:
protected:
/* Preallocated buffer for small queries. */
char query_prealloc_[256];
char mQueryPrealloc[256];
};
/****************************************************************************
@@ -223,10 +223,10 @@ public:
* Return:
* NO_ERROR on success, or an appropriate error status.
*/
virtual status_t Connect(const char* param);
virtual status_t connectClient(const char* param);
/* Disconnects from the service. */
virtual void Disconnect();
virtual void disconnectClient();
/* Sends data to the service.
* Param:
@@ -234,7 +234,7 @@ public:
* Return:
* NO_ERROR on success, or an appropriate error status on failure.
*/
virtual status_t Send(const void* data, size_t data_size);
virtual status_t sendMessage(const void* data, size_t data_size);
/* Receives data from the service.
* This method assumes that data to receive will come in two chunks: 8
@@ -250,7 +250,7 @@ public:
* Return:
* NO_ERROR on success, or an appropriate error status on failure.
*/
virtual status_t Receive(void** data, size_t* data_size);
virtual status_t receiveMessage(void** data, size_t* data_size);
/* Sends a query, and receives a response from the service.
* Param:
@@ -258,14 +258,14 @@ public:
* is completed, and all its relevant data members are properly initialized.
* Return:
* NO_ERROR on success, or an appropriate error status on failure. Note that
* status returned here is not the final query status. Use IsSucceeded(), or
* GetCompletionStatus() method on the query to see if it has succeeded.
* status returned here is not the final query status. Use isQuerySucceeded(),
* or getCompletionStatus() method on the query to see if it has succeeded.
* However, if this method returns a failure, it means that the query has
* failed, and there is no guarantee that its data members are properly
* initialized (except for the 'query_status_', which is always in the
* initialized (except for the 'mQueryStatus', which is always in the
* proper state).
*/
virtual status_t Query(QemuQuery* query);
virtual status_t doQuery(QemuQuery* query);
/****************************************************************************
* Data members
@@ -273,11 +273,11 @@ public:
protected:
/* Qemu pipe handle. */
int fd_;
int mPipeFD;
private:
/* Camera service name. */
static const char camera_service_name_[];
static const char mCameraServiceName[];
};
/****************************************************************************
@@ -322,7 +322,7 @@ public:
* Return:
* NO_ERROR on success, or an appropriate error status on failure.
*/
status_t ListCameras(char** list);
status_t listCameras(char** list);
/****************************************************************************
* Names of the queries available for the emulated camera factory.
@@ -330,7 +330,7 @@ public:
private:
/* List cameras connected to the host. */
static const char query_list_[];
static const char mQueryList[];
};
/****************************************************************************
@@ -356,13 +356,13 @@ public:
* Return:
* NO_ERROR on success, or an appropriate error status on failure.
*/
status_t QueryConnect();
status_t queryConnect();
/* Queries camera disconnection.
* Return:
* NO_ERROR on success, or an appropriate error status on failure.
*/
status_t QueryDisconnect();
status_t queryDisconnect();
/* Queries camera to start capturing video.
* Param:
@@ -372,13 +372,13 @@ public:
* Return:
* NO_ERROR on success, or an appropriate error status on failure.
*/
status_t QueryStart(uint32_t pixel_format, int width, int height);
status_t queryStart(uint32_t pixel_format, int width, int height);
/* Queries camera to stop capturing video.
* Return:
* NO_ERROR on success, or an appropriate error status on failure.
*/
status_t QueryStop();
status_t queryStop();
/* Queries camera for the next video frame.
* Param:
@@ -391,7 +391,7 @@ public:
* Return:
* NO_ERROR on success, or an appropriate error status on failure.
*/
status_t QueryFrame(void* vframe,
status_t queryFrame(void* vframe,
void* pframe,
size_t vframe_size,
size_t pframe_size);
@@ -402,15 +402,15 @@ public:
private:
/* Connect to the camera. */
static const char query_connect_[];
static const char mQueryConnect[];
/* Disconnect from the camera. */
static const char query_disconnect_[];
static const char mQueryDisconnect[];
/* Start video capturing. */
static const char query_start_[];
static const char mQueryStart[];
/* Stop video capturing. */
static const char query_stop_[];
static const char mQueryStop[];
/* Query frame(s). */
static const char query_frame_[];
static const char mQueryFrame[];
};
}; /* namespace android */