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 \ libui \
LOCAL_SRC_FILES := \ LOCAL_SRC_FILES := \
emulated_camera_hal.cpp \ EmulatedCameraHal.cpp \
emulated_camera_factory.cpp \ EmulatedCameraFactory.cpp \
emulated_camera.cpp \ EmulatedCamera.cpp \
emulated_camera_device.cpp \ EmulatedCameraDevice.cpp \
emulated_qemu_camera.cpp \ EmulatedQemuCamera.cpp \
emulated_qemu_camera_device.cpp \ EmulatedQemuCameraDevice.cpp \
emulated_fake_camera.cpp \ EmulatedFakeCamera.cpp \
emulated_fake_camera_device.cpp \ EmulatedFakeCameraDevice.cpp \
converters.cpp \ Converters.cpp \
preview_window.cpp \ PreviewWindow.cpp \
callback_notifier.cpp \ CallbackNotifier.cpp \
QemuClient.cpp QemuClient.cpp
ifeq ($(TARGET_PRODUCT),vbox_x86) ifeq ($(TARGET_PRODUCT),vbox_x86)

View File

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

View File

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

View File

@@ -21,7 +21,7 @@
#define LOG_NDEBUG 0 #define LOG_NDEBUG 0
#define LOG_TAG "EmulatedCamera_Converter" #define LOG_TAG "EmulatedCamera_Converter"
#include <cutils/log.h> #include <cutils/log.h>
#include "converters.h" #include "Converters.h"
namespace android { namespace android {
@@ -30,26 +30,26 @@ void YV12ToRGB565(const void* yv12, void* rgb, int width, int height)
const int pix_total = width * height; const int pix_total = width * height;
uint16_t* rgb_buf = reinterpret_cast<uint16_t*>(rgb); uint16_t* rgb_buf = reinterpret_cast<uint16_t*>(rgb);
const uint8_t* Y = reinterpret_cast<const uint8_t*>(yv12); const uint8_t* Y = reinterpret_cast<const uint8_t*>(yv12);
const uint8_t* Cb_pos = Y + pix_total; const uint8_t* U_pos = Y + pix_total;
const uint8_t* Cr_pos = Cb_pos + pix_total / 4; const uint8_t* V_pos = U_pos + pix_total / 4;
const uint8_t* Cb = Cb_pos; const uint8_t* U = U_pos;
const uint8_t* Cr = Cr_pos; const uint8_t* V = V_pos;
for (int y = 0; y < height; y++) { for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x += 2) { for (int x = 0; x < width; x += 2) {
const uint8_t nCb = *Cb; Cb++; const uint8_t nU = *U; U++;
const uint8_t nCr = *Cr; Cr++; const uint8_t nV = *V; V++;
*rgb_buf = YUVToRGB565(*Y, nCb, nCr); *rgb_buf = YUVToRGB565(*Y, nU, nV);
Y++; rgb_buf++; Y++; rgb_buf++;
*rgb_buf = YUVToRGB565(*Y, nCb, nCr); *rgb_buf = YUVToRGB565(*Y, nU, nV);
Y++; rgb_buf++; Y++; rgb_buf++;
} }
if (y & 0x1) { if (y & 0x1) {
Cb_pos = Cb; U_pos = U;
Cr_pos = Cr; V_pos = V;
} else { } else {
Cb = Cb_pos; U = U_pos;
Cr = Cr_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; const int pix_total = width * height;
uint32_t* rgb_buf = reinterpret_cast<uint32_t*>(rgb); uint32_t* rgb_buf = reinterpret_cast<uint32_t*>(rgb);
const uint8_t* Y = reinterpret_cast<const uint8_t*>(yv12); const uint8_t* Y = reinterpret_cast<const uint8_t*>(yv12);
const uint8_t* Cb_pos = Y + pix_total; const uint8_t* U_pos = Y + pix_total;
const uint8_t* Cr_pos = Cb_pos + pix_total / 4; const uint8_t* V_pos = U_pos + pix_total / 4;
const uint8_t* Cb = Cb_pos; const uint8_t* U = U_pos;
const uint8_t* Cr = Cr_pos; const uint8_t* V = V_pos;
for (int y = 0; y < height; y++) { for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x += 2) { for (int x = 0; x < width; x += 2) {
const uint8_t nCb = *Cb; Cb++; const uint8_t nU = *U; U++;
const uint8_t nCr = *Cr; Cr++; const uint8_t nV = *V; V++;
*rgb_buf = YUVToRGB32(*Y, nCb, nCr); *rgb_buf = YUVToRGB32(*Y, nU, nV);
Y++; rgb_buf++; Y++; rgb_buf++;
*rgb_buf = YUVToRGB32(*Y, nCb, nCr); *rgb_buf = YUVToRGB32(*Y, nU, nV);
Y++; rgb_buf++; Y++; rgb_buf++;
} }
if (y & 0x1) { if (y & 0x1) {
Cb_pos = Cb; U_pos = U;
Cr_pos = Cr; V_pos = V;
} else { } else {
Cb = Cb_pos; U = U_pos;
Cr = Cr_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 G16(rgb) static_cast<uint8_t>((rgb & kGreen6) >> 5)
#define B16(rgb) static_cast<uint8_t>((rgb & kBlue5) >> 11) #define B16(rgb) static_cast<uint8_t>((rgb & kBlue5) >> 11)
/* Make 8 bits red, green, and blue, extracted from RGB565 word. */ /* Make 8 bits red, green, and blue, extracted from RGB565 word. */
#define R16_32(rgb) (uint8_t)(((rgb & kRed5) << 3) | ((rgb & kRed5) >> 2)) #define R16_32(rgb) static_cast<uint8_t>(((rgb & kRed5) << 3) | ((rgb & kRed5) >> 2))
#define G16_32(rgb) (uint8_t)(((rgb & kGreen6) >> 3) | ((rgb & kGreen6) >> 9)) #define G16_32(rgb) static_cast<uint8_t>(((rgb & kGreen6) >> 3) | ((rgb & kGreen6) >> 9))
#define B16_32(rgb) (uint8_t)(((rgb & kBlue5) >> 8) | ((rgb & kBlue5) >> 14)) #define B16_32(rgb) static_cast<uint8_t>(((rgb & kBlue5) >> 8) | ((rgb & kBlue5) >> 14))
/* Extract red, green, and blue bytes from RGB32 dword. */ /* Extract red, green, and blue bytes from RGB32 dword. */
#define R32(rgb) static_cast<uint8_t>(rgb & kRed8) #define R32(rgb) static_cast<uint8_t>(rgb & kRed8)
#define G32(rgb) static_cast<uint8_t>(((rgb & kGreen8) >> 8) & 0xff) #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 G16(rgb) static_cast<uint8_t>((rgb & kGreen6) >> 5)
#define B16(rgb) static_cast<uint8_t>(rgb & kBlue5) #define B16(rgb) static_cast<uint8_t>(rgb & kBlue5)
/* Make 8 bits red, green, and blue, extracted from RGB565 word. */ /* Make 8 bits red, green, and blue, extracted from RGB565 word. */
#define R16_32(rgb) (uint8_t)(((rgb & kRed5) >> 8) | ((rgb & kRed5) >> 14)) #define R16_32(rgb) static_cast<uint8_t>(((rgb & kRed5) >> 8) | ((rgb & kRed5) >> 14))
#define G16_32(rgb) (uint8_t)(((rgb & kGreen6) >> 3) | ((rgb & kGreen6) >> 9)) #define G16_32(rgb) static_cast<uint8_t>(((rgb & kGreen6) >> 3) | ((rgb & kGreen6) >> 9))
#define B16_32(rgb) (uint8_t)(((rgb & kBlue5) << 3) | ((rgb & kBlue5) >> 2)) #define B16_32(rgb) static_cast<uint8_t>(((rgb & kBlue5) << 3) | ((rgb & kBlue5) >> 2))
/* Extract red, green, and blue bytes from RGB32 dword. */ /* Extract red, green, and blue bytes from RGB32 dword. */
#define R32(rgb) static_cast<uint8_t>((rgb & kRed8) >> 16) #define R32(rgb) static_cast<uint8_t>((rgb & kRed8) >> 16)
#define G32(rgb) static_cast<uint8_t>((rgb & kGreen8) >> 8) #define G32(rgb) static_cast<uint8_t>((rgb & kGreen8) >> 8)
@@ -226,30 +226,30 @@ YUVToRGB32(int y, int u, int v)
return rgb.color; return rgb.color;
} }
/* YCbCr pixel descriptor. */ /* YUV pixel descriptor. */
struct YUVPixel { struct YUVPixel {
uint8_t Y; uint8_t Y;
uint8_t Cb; uint8_t U;
uint8_t Cr; uint8_t V;
inline YUVPixel() inline YUVPixel()
: Y(0), Cb(0), Cr(0) : Y(0), U(0), V(0)
{ {
} }
inline explicit YUVPixel(uint16_t rgb565) inline explicit YUVPixel(uint16_t rgb565)
{ {
RGB565ToYUV(rgb565, &Y, &Cb, &Cr); RGB565ToYUV(rgb565, &Y, &U, &V);
} }
inline explicit YUVPixel(uint32_t rgb32) 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" #define LOG_TAG "EmulatedCamera_Camera"
#include <cutils/log.h> #include <cutils/log.h>
#include <ui/Rect.h> #include <ui/Rect.h>
#include "emulated_camera.h" #include "EmulatedCamera.h"
#include "emulated_fake_camera_device.h" #include "EmulatedFakeCameraDevice.h"
#include "converters.h" #include "Converters.h"
/* Defines whether we should trace parameter changes. */ /* Defines whether we should trace parameter changes. */
#define DEBUG_PARAM 1 #define DEBUG_PARAM 1
@@ -42,9 +42,9 @@ namespace android {
* current - Current set of camera parameters. * current - Current set of camera parameters.
* new_par - String representation of new 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 #else
#define _PrintParamDiff(current, new_par) (void(0)) #define PrintParamDiff(current, new_par) (void(0))
#endif /* DEBUG_PARAM */ #endif /* DEBUG_PARAM */
/* A helper routine that adds a value to the camera parameter. /* 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 * a failure. If non-NULL string is returned, the caller is responsible for
* freeing it with 'free'. * 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) EmulatedCamera::EmulatedCamera(int cameraId, struct hw_module_t* module)
: preview_window_(), : mPreviewWindow(),
callback_notifier_(), mCallbackNotifier(),
camera_id_(cameraId) mCameraID(cameraId)
{ {
/* /*
* Initialize camera_device descriptor for this object. * Initialize camera_device descriptor for this object.
@@ -74,7 +74,7 @@ EmulatedCamera::EmulatedCamera(int cameraId, struct hw_module_t* module)
common.close = EmulatedCamera::close; common.close = EmulatedCamera::close;
/* camera_device fields. */ /* camera_device fields. */
ops = &device_ops_; ops = &mDeviceOps;
priv = this; priv = this;
} }
@@ -95,77 +95,77 @@ status_t EmulatedCamera::Initialize()
*/ */
/* Only RGBX are supported by the framework for preview window in the emulator! */ /* Only RGBX are supported by the framework for preview window in the emulator! */
parameters_.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS, CameraParameters::PIXEL_FORMAT_RGBA8888); mPparameters.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS, CameraParameters::PIXEL_FORMAT_RGBA8888);
parameters_.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES, "60,50,25,15,10"); mPparameters.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES, "60,50,25,15,10");
parameters_.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FPS_RANGE, "(10,60)"); mPparameters.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FPS_RANGE, "(10,60)");
parameters_.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, "10,60"); mPparameters.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, "10,60");
parameters_.set(CameraParameters::KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES, "320x240,0x0"); mPparameters.set(CameraParameters::KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES, "320x240,0x0");
parameters_.set(CameraParameters::KEY_MAX_EXPOSURE_COMPENSATION, "6"); mPparameters.set(CameraParameters::KEY_MAX_EXPOSURE_COMPENSATION, "6");
parameters_.set(CameraParameters::KEY_MIN_EXPOSURE_COMPENSATION, "-6"); mPparameters.set(CameraParameters::KEY_MIN_EXPOSURE_COMPENSATION, "-6");
parameters_.set(CameraParameters::KEY_EXPOSURE_COMPENSATION_STEP, "0.5"); mPparameters.set(CameraParameters::KEY_EXPOSURE_COMPENSATION_STEP, "0.5");
parameters_.set(CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH, "512"); mPparameters.set(CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH, "512");
parameters_.set(CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT, "384"); mPparameters.set(CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT, "384");
parameters_.set(CameraParameters::KEY_JPEG_QUALITY, "90"); mPparameters.set(CameraParameters::KEY_JPEG_QUALITY, "90");
parameters_.set(CameraParameters::KEY_FOCAL_LENGTH, "4.31"); mPparameters.set(CameraParameters::KEY_FOCAL_LENGTH, "4.31");
parameters_.set(CameraParameters::KEY_HORIZONTAL_VIEW_ANGLE, "54.8"); mPparameters.set(CameraParameters::KEY_HORIZONTAL_VIEW_ANGLE, "54.8");
parameters_.set(CameraParameters::KEY_VERTICAL_VIEW_ANGLE, "42.5"); mPparameters.set(CameraParameters::KEY_VERTICAL_VIEW_ANGLE, "42.5");
parameters_.set(CameraParameters::KEY_JPEG_THUMBNAIL_QUALITY, "90"); mPparameters.set(CameraParameters::KEY_JPEG_THUMBNAIL_QUALITY, "90");
/* Only RGB formats are supported by preview window in emulator. */ /* 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, /* 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 * since we will emulate them through timeouts in the emulated camera device
* worker thread. */ * worker thread. */
parameters_.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES, mPparameters.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES,
"30,24,20,15,10,5"); "30,24,20,15,10,5");
parameters_.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FPS_RANGE, "(5,30)"); mPparameters.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FPS_RANGE, "(5,30)");
parameters_.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, "5,30"); mPparameters.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, "5,30");
parameters_.setPreviewFrameRate(24); mPparameters.setPreviewFrameRate(24);
/* Only PIXEL_FORMAT_YUV420P is accepted by camera framework in emulator! */ /* 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); CameraParameters::PIXEL_FORMAT_YUV420P);
parameters_.set(CameraParameters::KEY_SUPPORTED_PICTURE_FORMATS, mPparameters.set(CameraParameters::KEY_SUPPORTED_PICTURE_FORMATS,
CameraParameters::PIXEL_FORMAT_YUV420P); CameraParameters::PIXEL_FORMAT_YUV420P);
parameters_.setPictureFormat(CameraParameters::PIXEL_FORMAT_YUV420P); mPparameters.setPictureFormat(CameraParameters::PIXEL_FORMAT_YUV420P);
/* /*
* Not supported features * Not supported features
*/ */
parameters_.set(CameraParameters::KEY_SUPPORTED_FOCUS_MODES, CameraParameters::FOCUS_MODE_FIXED); mPparameters.set(CameraParameters::KEY_SUPPORTED_FOCUS_MODES, CameraParameters::FOCUS_MODE_FIXED);
parameters_.set(CameraParameters::KEY_FOCUS_MODE, CameraParameters::FOCUS_MODE_FIXED); mPparameters.set(CameraParameters::KEY_FOCUS_MODE, CameraParameters::FOCUS_MODE_FIXED);
return NO_ERROR; return NO_ERROR;
} }
void EmulatedCamera::OnNextFrameAvailable(const void* frame, void EmulatedCamera::onNextFrameAvailable(const void* frame,
nsecs_t timestamp, nsecs_t timestamp,
EmulatedCameraDevice* camera_dev) EmulatedCameraDevice* camera_dev)
{ {
/* Notify the preview window first. */ /* Notify the preview window first. */
preview_window_.OnNextFrameAvailable(frame, timestamp, camera_dev); mPreviewWindow.onNextFrameAvailable(frame, timestamp, camera_dev);
/* Notify callback notifier next. */ /* Notify callback notifier next. */
callback_notifier_.OnNextFrameAvailable(frame, timestamp, camera_dev); mCallbackNotifier.onNextFrameAvailable(frame, timestamp, camera_dev);
} }
/**************************************************************************** /****************************************************************************
* Camera API implementation. * Camera API implementation.
***************************************************************************/ ***************************************************************************/
status_t EmulatedCamera::Connect(hw_device_t** device) status_t EmulatedCamera::connectCamera(hw_device_t** device)
{ {
LOGV("%s", __FUNCTION__); LOGV("%s", __FUNCTION__);
status_t res = EINVAL; 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__); LOGE_IF(camera_dev == NULL, "%s: No camera device instance.", __FUNCTION__);
if (camera_dev != NULL) { if (camera_dev != NULL) {
/* Connect to the camera device. */ /* Connect to the camera device. */
res = GetCameraDevice()->Connect(); res = getCameraDevice()->connectDevice();
if (res == NO_ERROR) { if (res == NO_ERROR) {
*device = &common; *device = &common;
} }
@@ -174,20 +174,20 @@ status_t EmulatedCamera::Connect(hw_device_t** device)
return -res; return -res;
} }
status_t EmulatedCamera::Close() status_t EmulatedCamera::closeCamera()
{ {
LOGV("%s", __FUNCTION__); 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__); LOGV("%s", __FUNCTION__);
const char* valstr = NULL; const char* valstr = NULL;
valstr = parameters_.get(EmulatedCamera::FACING_KEY); valstr = mPparameters.get(EmulatedCamera::FACING_KEY);
if (valstr != NULL) { if (valstr != NULL) {
if (strcmp(valstr, EmulatedCamera::FACING_FRONT) == 0) { if (strcmp(valstr, EmulatedCamera::FACING_FRONT) == 0) {
info->facing = CAMERA_FACING_FRONT; info->facing = CAMERA_FACING_FRONT;
@@ -199,7 +199,7 @@ status_t EmulatedCamera::GetCameraInfo(struct camera_info* info)
info->facing = CAMERA_FACING_BACK; info->facing = CAMERA_FACING_BACK;
} }
valstr = parameters_.get(EmulatedCamera::ORIENTATION_KEY); valstr = mPparameters.get(EmulatedCamera::ORIENTATION_KEY);
if (valstr != NULL) { if (valstr != NULL) {
info->orientation = atoi(valstr); info->orientation = atoi(valstr);
} else { } else {
@@ -209,86 +209,86 @@ status_t EmulatedCamera::GetCameraInfo(struct camera_info* info)
return NO_ERROR; 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. */ /* Callback should return a negative errno. */
return -preview_window_.SetPreviewWindow(window, return -mPreviewWindow.setPreviewWindow(window,
parameters_.getPreviewFrameRate()); 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_callback data_cb,
camera_data_timestamp_callback data_cb_timestamp, camera_data_timestamp_callback data_cb_timestamp,
camera_request_memory get_memory, camera_request_memory get_memory,
void* user) void* user)
{ {
callback_notifier_.SetCallbacks(notify_cb, data_cb, data_cb_timestamp, mCallbackNotifier.setCallbacks(notify_cb, data_cb, data_cb_timestamp,
get_memory, user); 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__); LOGV("%s", __FUNCTION__);
/* Callback should return a negative errno. */ /* Callback should return a negative errno. */
return -DoStartPreview(); return -doStartPreview();
} }
void EmulatedCamera::StopPreview() void EmulatedCamera::stopPreview()
{ {
LOGV("%s", __FUNCTION__); 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. */ /* 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. */ /* 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__); LOGV("%s", __FUNCTION__);
@@ -296,7 +296,7 @@ status_t EmulatedCamera::AutoFocus()
return NO_ERROR; return NO_ERROR;
} }
status_t EmulatedCamera::CancelAutoFocus() status_t EmulatedCamera::cancelAutoFocus()
{ {
LOGV("%s", __FUNCTION__); LOGV("%s", __FUNCTION__);
@@ -304,7 +304,7 @@ status_t EmulatedCamera::CancelAutoFocus()
return NO_ERROR; return NO_ERROR;
} }
status_t EmulatedCamera::TakePicture() status_t EmulatedCamera::takePicture()
{ {
LOGV("%s", __FUNCTION__); LOGV("%s", __FUNCTION__);
@@ -326,22 +326,22 @@ status_t EmulatedCamera::TakePicture()
return NO_ERROR; return NO_ERROR;
} }
status_t EmulatedCamera::CancelPicture() status_t EmulatedCamera::cancelPicture()
{ {
LOGV("%s", __FUNCTION__); LOGV("%s", __FUNCTION__);
return NO_ERROR; return NO_ERROR;
} }
status_t EmulatedCamera::SetParameters(const char* parms) status_t EmulatedCamera::setParameters(const char* parms)
{ {
LOGV("%s", __FUNCTION__); LOGV("%s", __FUNCTION__);
_PrintParamDiff(parameters_, parms); PrintParamDiff(mPparameters, parms);
CameraParameters new_param; CameraParameters new_param;
String8 str8_param(parms); String8 str8_param(parms);
new_param.unflatten(str8_param); new_param.unflatten(str8_param);
parameters_ = new_param; mPparameters = new_param;
/* /*
* In emulation, there are certain parameters that are required by the * 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. */ /* Supported preview size. */
const char* check = parameters_.get(CameraParameters::KEY_PREVIEW_SIZE); const char* check = mPparameters.get(CameraParameters::KEY_PREVIEW_SIZE);
if (check != NULL) { if (check != NULL) {
const char* current = const char* current =
parameters_.get(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES); mPparameters.get(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES);
if (strstr(current, check) == NULL) { if (strstr(current, check) == NULL) {
/* Required size doesn't exist in the list. Add it. */ /* 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) { if (to_add != NULL) {
LOGD("+++ %s: Added %s to supported preview sizes", LOGD("+++ %s: Added %s to supported preview sizes",
__FUNCTION__, check); __FUNCTION__, check);
parameters_.set(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES, to_add); mPparameters.set(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES, to_add);
free(to_add); free(to_add);
} }
} }
} }
/* Supported preview frame rate. */ /* Supported preview frame rate. */
check = parameters_.get(CameraParameters::KEY_PREVIEW_FRAME_RATE); check = mPparameters.get(CameraParameters::KEY_PREVIEW_FRAME_RATE);
if (check != NULL) { if (check != NULL) {
const char* current = const char* current =
parameters_.get(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES); mPparameters.get(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES);
if (strstr(current, check) == NULL) { if (strstr(current, check) == NULL) {
char* to_add = _AddValue(current, check); char* to_add = AddValue(current, check);
if (to_add != NULL) { if (to_add != NULL) {
LOGD("+++ %s: Added %s to supported preview frame rates", LOGD("+++ %s: Added %s to supported preview frame rates",
__FUNCTION__, check); __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); free(to_add);
} }
} }
} }
/* Supported picture size. */ /* Supported picture size. */
check = parameters_.get(CameraParameters::KEY_PICTURE_SIZE); check = mPparameters.get(CameraParameters::KEY_PICTURE_SIZE);
if (check != NULL) { if (check != NULL) {
const char* current = const char* current =
parameters_.get(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES); mPparameters.get(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES);
if (strstr(current, check) == NULL) { if (strstr(current, check) == NULL) {
char* to_add = _AddValue(current, check); char* to_add = AddValue(current, check);
if (to_add != NULL) { if (to_add != NULL) {
LOGD("+++ %s: Added %s to supported picture sizes", LOGD("+++ %s: Added %s to supported picture sizes",
__FUNCTION__, check); __FUNCTION__, check);
parameters_.set(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES, to_add); mPparameters.set(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES, to_add);
free(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 /* A dumb variable indicating "no params" / error on the exit from
* EmulatedCamera::GetParameters(). */ * EmulatedCamera::getParameters(). */
static char _no_param = '\0'; static char lNoParam = '\0';
char* EmulatedCamera::GetParameters() char* EmulatedCamera::getParameters()
{ {
String8 params(parameters_.flatten()); String8 params(mPparameters.flatten());
char* ret_str = char* ret_str =
reinterpret_cast<char*>(malloc(sizeof(char) * (params.length()+1))); reinterpret_cast<char*>(malloc(sizeof(char) * (params.length()+1)));
memset(ret_str, 0, params.length()+1); memset(ret_str, 0, params.length()+1);
@@ -417,19 +417,19 @@ char* EmulatedCamera::GetParameters()
} else { } else {
LOGE("%s: Unable to allocate string for %s", __FUNCTION__, params.string()); LOGE("%s: Unable to allocate string for %s", __FUNCTION__, params.string());
/* Apparently, we can't return NULL fron this routine. */ /* 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(). */ /* This method simply frees parameters allocated in getParameters(). */
if (params != NULL && params != &_no_param) { if (params != NULL && params != &lNoParam) {
free(params); 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); 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; return 0;
} }
void EmulatedCamera::Release() void EmulatedCamera::releaseCamera()
{ {
LOGV("%s", __FUNCTION__); LOGV("%s", __FUNCTION__);
Cleanup(); cleanupCamera();
} }
status_t EmulatedCamera::Dump(int fd) status_t EmulatedCamera::dumpCamera(int fd)
{ {
LOGV("%s", __FUNCTION__); LOGV("%s", __FUNCTION__);
@@ -456,61 +456,62 @@ status_t EmulatedCamera::Dump(int fd)
* Preview management. * Preview management.
***************************************************************************/ ***************************************************************************/
status_t EmulatedCamera::DoStartPreview() status_t EmulatedCamera::doStartPreview()
{ {
status_t res = preview_window_.Start(); status_t res = mPreviewWindow.startPreview();
/* Start the camera. */ /* Start the camera. */
if (res == NO_ERROR && !GetCameraDevice()->IsCapturing()) { if (res == NO_ERROR && !getCameraDevice()->isCapturing()) {
res = StartCamera(); res = startCamera();
if (res != NO_ERROR) { if (res != NO_ERROR) {
/* If camera didn't start, disable the preview window. */ /* If camera didn't start, disable the preview window. */
preview_window_.Stop(); mPreviewWindow.stopPreview();
} }
} }
return res; return res;
} }
status_t EmulatedCamera::DoStopPreview() status_t EmulatedCamera::doStopPreview()
{ {
status_t res = NO_ERROR; status_t res = NO_ERROR;
/* Stop the camera. */ /* Stop the camera. */
if (GetCameraDevice()->IsCapturing()) { if (getCameraDevice()->isCapturing()) {
res = StopCamera(); res = stopCamera();
} }
if (res == NO_ERROR) { if (res == NO_ERROR) {
/* Disable preview as well. */ /* Disable preview as well. */
preview_window_.Stop(); mPreviewWindow.stopPreview();
} }
return NO_ERROR; return NO_ERROR;
} }
status_t EmulatedCamera::StartCamera() status_t EmulatedCamera::startCamera()
{ {
status_t res = EINVAL; status_t res = EINVAL;
EmulatedCameraDevice* camera_dev = GetCameraDevice(); EmulatedCameraDevice* camera_dev = getCameraDevice();
if (camera_dev != NULL) { if (camera_dev != NULL) {
if (!camera_dev->IsConnected()) { if (!camera_dev->isConnected()) {
res = camera_dev->Connect(); res = camera_dev->connectDevice();
if (res != NO_ERROR) { if (res != NO_ERROR) {
return res; return res;
} }
} }
if (!camera_dev->IsCapturing()) { if (!camera_dev->isCapturing()) {
int width, height; int width, height;
/* Lets see what should we use for frame width, and height. */ /* Lets see what should we use for frame width, and height. */
if (parameters_.get(CameraParameters::KEY_VIDEO_SIZE) != NULL) { if (mPparameters.get(CameraParameters::KEY_VIDEO_SIZE) != NULL) {
parameters_.getVideoSize(&width, &height); mPparameters.getVideoSize(&width, &height);
} else { } else {
parameters_.getPreviewSize(&width, &height); mPparameters.getPreviewSize(&width, &height);
} }
/* Lets see what should we use for the frame pixel format. */ /* 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) { if (pix_fmt == NULL) {
pix_fmt = parameters_.getPreviewFormat(); pix_fmt = mPparameters.getPreviewFormat();
} }
if (pix_fmt == NULL) { if (pix_fmt == NULL) {
LOGE("%s: Unable to obtain video format", __FUNCTION__); LOGE("%s: Unable to obtain video format", __FUNCTION__);
@@ -526,7 +527,7 @@ status_t EmulatedCamera::StartCamera()
return EINVAL; return EINVAL;
} }
LOGD("Starting camera: %dx%d -> %s", width, height, pix_fmt); 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) { if (res != NO_ERROR) {
return res; return res;
} }
@@ -536,13 +537,13 @@ status_t EmulatedCamera::StartCamera()
return res; return res;
} }
status_t EmulatedCamera::StopCamera() status_t EmulatedCamera::stopCamera()
{ {
status_t res = NO_ERROR; status_t res = NO_ERROR;
EmulatedCameraDevice* const camera_dev = GetCameraDevice(); EmulatedCameraDevice* const camera_dev = getCameraDevice();
if (camera_dev != NULL) { if (camera_dev != NULL) {
if (camera_dev->IsCapturing()) { if (camera_dev->isCapturing()) {
res = camera_dev->StopCapturing(); res = camera_dev->stopCapturing();
if (res != NO_ERROR) { if (res != NO_ERROR) {
return res; return res;
} }
@@ -557,34 +558,34 @@ status_t EmulatedCamera::StopCamera()
* Private API. * Private API.
***************************************************************************/ ***************************************************************************/
status_t EmulatedCamera::Cleanup() status_t EmulatedCamera::cleanupCamera()
{ {
status_t res = NO_ERROR; status_t res = NO_ERROR;
/* If preview is running - stop it. */ /* If preview is running - stop it. */
res = DoStopPreview(); res = doStopPreview();
if (res != NO_ERROR) { if (res != NO_ERROR) {
return -res; return -res;
} }
/* Stop and disconnect the camera device. */ /* Stop and disconnect the camera device. */
EmulatedCameraDevice* const camera_dev = GetCameraDevice(); EmulatedCameraDevice* const camera_dev = getCameraDevice();
if (camera_dev != NULL) { if (camera_dev != NULL) {
if (camera_dev->IsCapturing()) { if (camera_dev->isCapturing()) {
res = camera_dev->StopCapturing(); res = camera_dev->stopCapturing();
if (res != NO_ERROR) { if (res != NO_ERROR) {
return -res; return -res;
} }
} }
if (camera_dev->IsConnected()) { if (camera_dev->isConnected()) {
res = camera_dev->Disconnect(); res = camera_dev->disconnectDevice();
if (res != NO_ERROR) { if (res != NO_ERROR) {
return -res; return -res;
} }
} }
} }
callback_notifier_.Cleanup(); mCallbackNotifier.cleanupCBNotifier();
return NO_ERROR; return NO_ERROR;
} }
@@ -604,7 +605,7 @@ int EmulatedCamera::set_preview_window(struct camera_device* dev,
LOGE("%s: Unexpected NULL camera device", __FUNCTION__); LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL; return -EINVAL;
} }
return ec->SetPreviewWindow(window); return ec->setPreviewWindow(window);
} }
void EmulatedCamera::set_callbacks( void EmulatedCamera::set_callbacks(
@@ -620,7 +621,7 @@ void EmulatedCamera::set_callbacks(
LOGE("%s: Unexpected NULL camera device", __FUNCTION__); LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return; 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) 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__); LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return; return;
} }
ec->EnableMsgType(msg_type); ec->enableMsgType(msg_type);
} }
void EmulatedCamera::disable_msg_type(struct camera_device* dev, int32_t 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__); LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return; return;
} }
ec->DisableMsgType(msg_type); ec->disableMsgType(msg_type);
} }
int EmulatedCamera::msg_type_enabled(struct camera_device* dev, int32_t 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__); LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL; return -EINVAL;
} }
return ec->MsgTypeEnabled(msg_type); return ec->isMsgTypeEnabled(msg_type);
} }
int EmulatedCamera::start_preview(struct camera_device* dev) 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__); LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL; return -EINVAL;
} }
return ec->StartPreview(); return ec->startPreview();
} }
void EmulatedCamera::stop_preview(struct camera_device* dev) 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__); LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return; return;
} }
ec->StopPreview(); ec->stopPreview();
} }
int EmulatedCamera::preview_enabled(struct camera_device* dev) 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__); LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL; return -EINVAL;
} }
return ec->PreviewEnabled(); return ec->isPreviewEnabled();
} }
int EmulatedCamera::store_meta_data_in_buffers(struct camera_device* dev, 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__); LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL; return -EINVAL;
} }
return ec->StoreMetaDataInBuffers(enable); return ec->storeMetaDataInBuffers(enable);
} }
int EmulatedCamera::start_recording(struct camera_device* dev) 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__); LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL; return -EINVAL;
} }
return ec->StartRecording(); return ec->startRecording();
} }
void EmulatedCamera::stop_recording(struct camera_device* dev) 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__); LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return; return;
} }
ec->StopRecording(); ec->stopRecording();
} }
int EmulatedCamera::recording_enabled(struct camera_device* dev) 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__); LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL; return -EINVAL;
} }
return ec->RecordingEnabled(); return ec->isRecordingEnabled();
} }
void EmulatedCamera::release_recording_frame(struct camera_device* dev, 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__); LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return; return;
} }
ec->ReleaseRecordingFrame(opaque); ec->releaseRecordingFrame(opaque);
} }
int EmulatedCamera::auto_focus(struct camera_device* dev) 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__); LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL; return -EINVAL;
} }
return ec->AutoFocus(); return ec->setAutoFocus();
} }
int EmulatedCamera::cancel_auto_focus(struct camera_device* dev) 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__); LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL; return -EINVAL;
} }
return ec->CancelAutoFocus(); return ec->cancelAutoFocus();
} }
int EmulatedCamera::take_picture(struct camera_device* dev) 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__); LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL; return -EINVAL;
} }
return ec->TakePicture(); return ec->takePicture();
} }
int EmulatedCamera::cancel_picture(struct camera_device* dev) 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__); LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL; return -EINVAL;
} }
return ec->CancelPicture(); return ec->cancelPicture();
} }
int EmulatedCamera::set_parameters(struct camera_device* dev, const char* parms) 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__); LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL; return -EINVAL;
} }
return ec->SetParameters(parms); return ec->setParameters(parms);
} }
char* EmulatedCamera::get_parameters(struct camera_device* dev) 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__); LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return NULL; return NULL;
} }
return ec->GetParameters(); return ec->getParameters();
} }
void EmulatedCamera::put_parameters(struct camera_device* dev, char* params) 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__); LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return; return;
} }
ec->PutParameters(params); ec->putParameters(params);
} }
int EmulatedCamera::send_command(struct camera_device* dev, 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__); LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL; return -EINVAL;
} }
return ec->SendCommand(cmd, arg1, arg2); return ec->sendCommand(cmd, arg1, arg2);
} }
void EmulatedCamera::release(struct camera_device* dev) 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__); LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return; return;
} }
ec->Release(); ec->releaseCamera();
} }
int EmulatedCamera::dump(struct camera_device* dev, int fd) 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__); LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL; return -EINVAL;
} }
return ec->Dump(fd); return ec->dumpCamera(fd);
} }
int EmulatedCamera::close(struct hw_device_t* device) 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__); LOGE("%s: Unexpected NULL camera device", __FUNCTION__);
return -EINVAL; return -EINVAL;
} }
return ec->Close(); return ec->closeCamera();
} }
/**************************************************************************** /****************************************************************************
* Static initializer for the camera callback API * 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_preview_window,
EmulatedCamera::set_callbacks, EmulatedCamera::set_callbacks,
EmulatedCamera::enable_msg_type, EmulatedCamera::enable_msg_type,
@@ -897,7 +898,7 @@ const char EmulatedCamera::FACING_FRONT[] = "front";
* Helper routines * 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 len1 = strlen(param);
const size_t len2 = strlen(val); const size_t len2 = strlen(val);
@@ -917,7 +918,7 @@ static char* _AddValue(const char* param, const char* val)
***************************************************************************/ ***************************************************************************/
#if DEBUG_PARAM #if DEBUG_PARAM
static void _PrintParamDiff(const CameraParameters& current, static void PrintParamDiff(const CameraParameters& current,
const char* new_par) const char* new_par)
{ {
char tmp[2048]; char tmp[2048];

View File

@@ -27,9 +27,9 @@
*/ */
#include <camera/CameraParameters.h> #include <camera/CameraParameters.h>
#include "emulated_camera_device.h" #include "EmulatedCameraDevice.h"
#include "preview_window.h" #include "PreviewWindow.h"
#include "callback_notifier.h" #include "CallbackNotifier.h"
namespace android { namespace android {
@@ -38,8 +38,8 @@ namespace android {
* *
* Note that EmulatedCameraFactory instantiates object of this class just once, * Note that EmulatedCameraFactory instantiates object of this class just once,
* when EmulatedCameraFactory instance gets constructed. Connection to / * when EmulatedCameraFactory instance gets constructed. Connection to /
* disconnection from the actual camera device is handled by calls to Connect(), * disconnection from the actual camera device is handled by calls to connectDevice(),
* and Close() methods of this class that are ivoked in response to * and closeCamera() methods of this class that are ivoked in response to
* hw_module_methods_t::open, and camera_device::close callbacks. * hw_module_methods_t::open, and camera_device::close callbacks.
*/ */
class EmulatedCamera : public camera_device { class EmulatedCamera : public camera_device {
@@ -62,7 +62,7 @@ public:
public: public:
/* Gets emulated camera device used by this instance of the emulated camera. /* Gets emulated camera device used by this instance of the emulated camera.
*/ */
virtual EmulatedCameraDevice* GetCameraDevice() = 0; virtual EmulatedCameraDevice* getCameraDevice() = 0;
/**************************************************************************** /****************************************************************************
* Public API * Public API
@@ -90,7 +90,7 @@ public:
* timestamp - Frame's timestamp. * timestamp - Frame's timestamp.
* camera_dev - Camera device instance that delivered the frame. * camera_dev - Camera device instance that delivered the frame.
*/ */
virtual void OnNextFrameAvailable(const void* frame, virtual void onNextFrameAvailable(const void* frame,
nsecs_t timestamp, nsecs_t timestamp,
EmulatedCameraDevice* camera_dev); EmulatedCameraDevice* camera_dev);
@@ -104,14 +104,14 @@ public:
* NOTE: When this method is called the object is locked. * NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses. * 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. /* Closes connection to the emulated camera.
* This method is called in response to camera_device::close callback. * This method is called in response to camera_device::close callback.
* NOTE: When this method is called the object is locked. * NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses. * Note that failures in this method are reported as negave EXXX statuses.
*/ */
virtual status_t Close(); virtual status_t closeCamera();
/* Gets camera information. /* Gets camera information.
* This method is called in response to camera_module_t::get_camera_info * 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: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses. * 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. * Camera API implementation.
@@ -131,12 +131,12 @@ protected:
* NOTE: When this method is called the object is locked. * NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses. * 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. /* Actual handler for camera_device_ops_t::set_callbacks callback.
* NOTE: When this method is called the object is locked. * 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_callback data_cb,
camera_data_timestamp_callback data_cb_timestamp, camera_data_timestamp_callback data_cb_timestamp,
camera_request_memory get_memory, camera_request_memory get_memory,
@@ -145,96 +145,96 @@ protected:
/* Actual handler for camera_device_ops_t::enable_msg_type callback. /* Actual handler for camera_device_ops_t::enable_msg_type callback.
* NOTE: When this method is called the object is locked. * 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. /* Actual handler for camera_device_ops_t::disable_msg_type callback.
* NOTE: When this method is called the object is locked. * 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. /* Actual handler for camera_device_ops_t::msg_type_enabled callback.
* NOTE: When this method is called the object is locked. * NOTE: When this method is called the object is locked.
* Return: * Return:
* 0 if message(s) is (are) disabled, != 0 if enabled. * 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. /* Actual handler for camera_device_ops_t::start_preview callback.
* NOTE: When this method is called the object is locked. * NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses. * 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. /* Actual handler for camera_device_ops_t::stop_preview callback.
* NOTE: When this method is called the object is locked. * 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. /* Actual handler for camera_device_ops_t::preview_enabled callback.
* NOTE: When this method is called the object is locked. * NOTE: When this method is called the object is locked.
* Return: * Return:
* 0 if preview is disabled, != 0 if enabled. * 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. /* Actual handler for camera_device_ops_t::store_meta_data_in_buffers callback.
* NOTE: When this method is called the object is locked. * NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses. * 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. /* Actual handler for camera_device_ops_t::start_recording callback.
* NOTE: When this method is called the object is locked. * NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses. * 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. /* Actual handler for camera_device_ops_t::stop_recording callback.
* NOTE: When this method is called the object is locked. * 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. /* Actual handler for camera_device_ops_t::recording_enabled callback.
* NOTE: When this method is called the object is locked. * NOTE: When this method is called the object is locked.
* Return: * Return:
* 0 if recording is disabled, != 0 if enabled. * 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. /* Actual handler for camera_device_ops_t::release_recording_frame callback.
* NOTE: When this method is called the object is locked. * 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. /* Actual handler for camera_device_ops_t::auto_focus callback.
* NOTE: When this method is called the object is locked. * NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses. * 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. /* Actual handler for camera_device_ops_t::cancel_auto_focus callback.
* NOTE: When this method is called the object is locked. * NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses. * 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. /* Actual handler for camera_device_ops_t::take_picture callback.
* NOTE: When this method is called the object is locked. * NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses. * 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. /* Actual handler for camera_device_ops_t::cancel_picture callback.
* NOTE: When this method is called the object is locked. * NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses. * 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. /* Actual handler for camera_device_ops_t::set_parameters callback.
* NOTE: When this method is called the object is locked. * NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses. * 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. /* Actual handler for camera_device_ops_t::get_parameters callback.
* NOTE: When this method is called the object is locked. * 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 * Flattened parameters string. The caller will free the buffer allocated
* for the string by calling camera_device_ops_t::put_parameters callback. * 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. /* Actual handler for camera_device_ops_t::put_parameters callback.
* Called to free the string returned from camera_device_ops_t::get_parameters * Called to free the string returned from camera_device_ops_t::get_parameters
@@ -250,24 +250,24 @@ protected:
* misleading. * misleading.
* NOTE: When this method is called the object is locked. * 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. /* Actual handler for camera_device_ops_t::send_command callback.
* NOTE: When this method is called the object is locked. * NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses. * 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. /* Actual handler for camera_device_ops_t::release callback.
* NOTE: When this method is called the object is locked. * 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. /* Actual handler for camera_device_ops_t::dump callback.
* NOTE: When this method is called the object is locked. * NOTE: When this method is called the object is locked.
* Note that failures in this method are reported as negave EXXX statuses. * 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. * Preview management.
@@ -275,32 +275,32 @@ protected:
protected: protected:
/* Starts preview. /* 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 * indicating that framework has an intention to start displaying video
* frames, but didn't create the preview window yet. * frames, but didn't create the preview window yet.
* Return: * Return:
* NO_ERROR on success, or an appropriate error status on failure. * NO_ERROR on success, or an appropriate error status on failure.
*/ */
virtual status_t DoStartPreview(); virtual status_t doStartPreview();
/* Stops preview. /* Stops preview.
* This method reverts DoStartPreview. * This method reverts DoStartPreview.
* Return: * Return:
* NO_ERROR on success, or an appropriate error status on failure. * NO_ERROR on success, or an appropriate error status on failure.
*/ */
virtual status_t DoStopPreview(); virtual status_t doStopPreview();
/* Starts capturing frames /* Starts capturing frames
* Return: * Return:
* NO_ERROR on success, or an appropriate error status on failure. * NO_ERROR on success, or an appropriate error status on failure.
*/ */
virtual status_t StartCamera(); virtual status_t startCamera();
/* Stops capturing frames. /* Stops capturing frames.
* Return: * Return:
* NO_ERROR on success, or an appropriate error status on failure. * NO_ERROR on success, or an appropriate error status on failure.
*/ */
virtual status_t StopCamera(); virtual status_t stopCamera();
/**************************************************************************** /****************************************************************************
* Private API. * Private API.
@@ -308,7 +308,7 @@ protected:
protected: protected:
/* Cleans up camera when released. */ /* Cleans up camera when released. */
virtual status_t Cleanup(); virtual status_t cleanupCamera();
/**************************************************************************** /****************************************************************************
* Camera API callbacks as defined by camera_device_ops structure. * Camera API callbacks as defined by camera_device_ops structure.
@@ -383,23 +383,23 @@ private:
protected: protected:
/* Locks this instance for parameters, state, etc. change. */ /* Locks this instance for parameters, state, etc. change. */
Mutex object_lock_; Mutex mObjectLock;
/* Camera parameters. */ /* Camera parameters. */
CameraParameters parameters_; CameraParameters mPparameters;
/* Preview window. */ /* Preview window. */
PreviewWindow preview_window_; PreviewWindow mPreviewWindow;
/* Callback notifier. */ /* Callback notifier. */
CallbackNotifier callback_notifier_; CallbackNotifier mCallbackNotifier;
/* Zero-based ID assigned to this camera. */ /* Zero-based ID assigned to this camera. */
int camera_id_; int mCameraID;
private: private:
/* Registered callbacks implementing camera API. */ /* Registered callbacks implementing camera API. */
static camera_device_ops_t device_ops_; static camera_device_ops_t mDeviceOps;
/**************************************************************************** /****************************************************************************
* Common keys * Common keys

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -22,21 +22,21 @@
#define LOG_NDEBUG 0 #define LOG_NDEBUG 0
#define LOG_TAG "EmulatedCamera_FakeDevice" #define LOG_TAG "EmulatedCamera_FakeDevice"
#include <cutils/log.h> #include <cutils/log.h>
#include "emulated_fake_camera.h" #include "EmulatedFakeCamera.h"
#include "emulated_fake_camera_device.h" #include "EmulatedFakeCameraDevice.h"
namespace android { namespace android {
EmulatedFakeCameraDevice::EmulatedFakeCameraDevice(EmulatedFakeCamera* camera_hal) EmulatedFakeCameraDevice::EmulatedFakeCameraDevice(EmulatedFakeCamera* camera_hal)
: EmulatedCameraDevice(camera_hal), : EmulatedCameraDevice(camera_hal),
black_YCbCr_(kBlack32), mBlackYUV(kBlack32),
white_YCbCr_(kWhite32), mWhiteYUV(kWhite32),
red_YCbCr_(kRed8), mRedYUV(kRed8),
green_YCbCr_(kGreen8), mGreenYUV(kGreen8),
blue_YCbCr_(kBlue8), mBlueYUV(kBlue8),
check_x_(0), mCheckX(0),
check_y_(0), mCheckY(0),
counter_(0) mCcounter(0)
{ {
} }
@@ -48,83 +48,83 @@ EmulatedFakeCameraDevice::~EmulatedFakeCameraDevice()
* Emulated camera device abstract interface implementation. * Emulated camera device abstract interface implementation.
***************************************************************************/ ***************************************************************************/
status_t EmulatedFakeCameraDevice::Connect() status_t EmulatedFakeCameraDevice::connectDevice()
{ {
LOGV("%s", __FUNCTION__); LOGV("%s", __FUNCTION__);
Mutex::Autolock locker(&object_lock_); Mutex::Autolock locker(&mObjectLock);
if (!IsInitialized()) { if (!isInitialized()) {
LOGE("%s: Fake camera device is not initialized.", __FUNCTION__); LOGE("%s: Fake camera device is not initialized.", __FUNCTION__);
return EINVAL; return EINVAL;
} }
if (IsConnected()) { if (isConnected()) {
LOGW("%s: Fake camera device is already connected.", __FUNCTION__); LOGW("%s: Fake camera device is already connected.", __FUNCTION__);
return NO_ERROR; return NO_ERROR;
} }
state_ = ECDS_CONNECTED; mState = ECDS_CONNECTED;
return NO_ERROR; return NO_ERROR;
} }
status_t EmulatedFakeCameraDevice::Disconnect() status_t EmulatedFakeCameraDevice::disconnectDevice()
{ {
LOGV("%s", __FUNCTION__); LOGV("%s", __FUNCTION__);
Mutex::Autolock locker(&object_lock_); Mutex::Autolock locker(&mObjectLock);
if (!IsConnected()) { if (!isConnected()) {
LOGW("%s: Fake camera device is already disconnected.", __FUNCTION__); LOGW("%s: Fake camera device is already disconnected.", __FUNCTION__);
return NO_ERROR; return NO_ERROR;
} }
if (IsCapturing()) { if (isCapturing()) {
LOGE("%s: Cannot disconnect while in the capturing state.", __FUNCTION__); LOGE("%s: Cannot disconnect while in the capturing state.", __FUNCTION__);
return EINVAL; return EINVAL;
} }
state_ = ECDS_INITIALIZED; mState = ECDS_INITIALIZED;
return NO_ERROR; return NO_ERROR;
} }
status_t EmulatedFakeCameraDevice::StartCamera() status_t EmulatedFakeCameraDevice::startDevice()
{ {
LOGV("%s", __FUNCTION__); LOGV("%s", __FUNCTION__);
Mutex::Autolock locker(&object_lock_); Mutex::Autolock locker(&mObjectLock);
if (!IsConnected()) { if (!isConnected()) {
LOGE("%s: Fake camera device is not connected.", __FUNCTION__); LOGE("%s: Fake camera device is not connected.", __FUNCTION__);
return EINVAL; return EINVAL;
} }
if (IsCapturing()) { if (isCapturing()) {
LOGW("%s: Fake camera device is already capturing.", __FUNCTION__); LOGW("%s: Fake camera device is already capturing.", __FUNCTION__);
return NO_ERROR; return NO_ERROR;
} }
/* Used in calculating Cb/Cr position when drawing the square. */ /* Used in calculating U/V position when drawing the square. */
half_width_ = frame_width_ / 2; mHalfWidth = mFrameWidth / 2;
/* Just start the worker thread: there is no real device to deal with. */ /* 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) { if (ret == NO_ERROR) {
state_ = ECDS_CAPTURING; mState = ECDS_CAPTURING;
} }
return ret; return ret;
} }
status_t EmulatedFakeCameraDevice::StopCamera() status_t EmulatedFakeCameraDevice::stopDevice()
{ {
LOGV("%s", __FUNCTION__); LOGV("%s", __FUNCTION__);
if (!IsCapturing()) { if (!isCapturing()) {
LOGW("%s: Fake camera device is not capturing.", __FUNCTION__); LOGW("%s: Fake camera device is not capturing.", __FUNCTION__);
return NO_ERROR; return NO_ERROR;
} }
/* Just stop the worker thread: there is no real device to deal with. */ /* 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) { if (ret == NO_ERROR) {
state_ = ECDS_CONNECTED; mState = ECDS_CONNECTED;
} }
return ret; return ret;
@@ -134,39 +134,39 @@ status_t EmulatedFakeCameraDevice::StopCamera()
* Worker thread management overrides. * Worker thread management overrides.
***************************************************************************/ ***************************************************************************/
bool EmulatedFakeCameraDevice::InWorkerThread() bool EmulatedFakeCameraDevice::inWorkerThread()
{ {
/* Wait till FPS timeout expires, or thread exit message is received. */ /* Wait till FPS timeout expires, or thread exit message is received. */
WorkerThread::SelectRes res = WorkerThread::SelectRes res =
worker_thread()->Select(-1, 1000000 / emulated_fps_); getWorkerThread()->Select(-1, 1000000 / mEmulatedFPS);
if (res == WorkerThread::EXIT_THREAD) { if (res == WorkerThread::EXIT_THREAD) {
LOGV("%s: Worker thread has been terminated.", __FUNCTION__); LOGV("%s: Worker thread has been terminated.", __FUNCTION__);
return false; return false;
} }
/* Lets see if we need to generate a new frame. */ /* 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. * Time to generate a new frame.
*/ */
/* Draw the checker board. */ /* Draw the checker board. */
DrawCheckerboard(); drawCheckerboard();
/* Run the square. */ /* Run the square. */
int x = ((counter_ * 3) & 255); int x = ((mCcounter * 3) & 255);
if(x > 128) x = 255 - x; if(x > 128) x = 255 - x;
int y = ((counter_ * 5) & 255); int y = ((mCcounter * 5) & 255);
if(y > 128) y = 255 - y; if(y > 128) y = 255 - y;
const int size = frame_width_ / 10; const int size = mFrameWidth / 10;
DrawSquare(x * size / 32, y * size / 32, (size * 5) >> 1, drawSquare(x * size / 32, y * size / 32, (size * 5) >> 1,
(counter_ & 0x100) ? &red_YCbCr_ : &green_YCbCr_); (mCcounter & 0x100) ? &mRedYUV : &mGreenYUV);
counter_++; mCcounter++;
} }
/* Timestamp the current frame, and notify the camera HAL about new frame. */ /* Timestamp the current frame, and notify the camera HAL about new frame. */
timestamp_ = systemTime(SYSTEM_TIME_MONOTONIC); mCurFrameTimestamp = systemTime(SYSTEM_TIME_MONOTONIC);
camera_hal_->OnNextFrameAvailable(current_frame_, timestamp_, this); mCameraHAL->onNextFrameAvailable(mCurrentFrame, mCurFrameTimestamp, this);
return true; return true;
} }
@@ -175,35 +175,35 @@ bool EmulatedFakeCameraDevice::InWorkerThread()
* Fake camera device private API * 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; bool black = true;
if((check_x_ / size) & 1) if((mCheckX / size) & 1)
black = false; black = false;
if((check_y_ / size) & 1) if((mCheckY / size) & 1)
black = !black; black = !black;
int county = check_y_ % size; int county = mCheckY % size;
int checkxremainder = check_x_ % size; int checkxremainder = mCheckX % size;
uint8_t* Y = current_frame_; uint8_t* Y = mCurrentFrame;
uint8_t* Cb_pos = frame_Cb_; uint8_t* U_pos = mFrameU;
uint8_t* Cr_pos = frame_Cr_; uint8_t* V_pos = mFrameV;
uint8_t* Cb = Cb_pos; uint8_t* U = U_pos;
uint8_t* Cr = Cr_pos; uint8_t* V = V_pos;
for(int y = 0; y < frame_height_; y++) { for(int y = 0; y < mFrameHeight; y++) {
int countx = checkxremainder; int countx = checkxremainder;
bool current = black; bool current = black;
for(int x = 0; x < frame_width_; x += 2) { for(int x = 0; x < mFrameWidth; x += 2) {
if (current) { if (current) {
black_YCbCr_.get(Y, Cb, Cr); mBlackYUV.get(Y, U, V);
} else { } else {
white_YCbCr_.get(Y, Cb, Cr); mWhiteYUV.get(Y, U, V);
} }
Y[1] = *Y; Y[1] = *Y;
Y += 2; Cb++; Cr++; Y += 2; U++; V++;
countx += 2; countx += 2;
if(countx >= size) { if(countx >= size) {
countx = 0; countx = 0;
@@ -211,43 +211,43 @@ void EmulatedFakeCameraDevice::DrawCheckerboard()
} }
} }
if (y & 0x1) { if (y & 0x1) {
Cb_pos = Cb; U_pos = U;
Cr_pos = Cr; V_pos = V;
} else { } else {
Cb = Cb_pos; U = U_pos;
Cr = Cr_pos; V = V_pos;
} }
if(county++ >= size) { if(county++ >= size) {
county = 0; county = 0;
black = !black; black = !black;
} }
} }
check_x_ += 3; mCheckX += 3;
check_y_++; mCheckY++;
} }
void EmulatedFakeCameraDevice::DrawSquare(int x, void EmulatedFakeCameraDevice::drawSquare(int x,
int y, int y,
int size, int size,
const YUVPixel* color) const YUVPixel* color)
{ {
const int half_x = x / 2; const int half_x = x / 2;
const int square_xstop = min(frame_width_, x+size); const int square_xstop = min(mFrameWidth, x+size);
const int square_ystop = min(frame_height_, y+size); const int square_ystop = min(mFrameHeight, y+size);
uint8_t* Y_pos = current_frame_ + y * frame_width_ + x; uint8_t* Y_pos = mCurrentFrame + y * mFrameWidth + x;
// Draw the square. // Draw the square.
for (; y < square_ystop; y++) { for (; y < square_ystop; y++) {
const int iCbCr = (y / 2) * half_width_ + half_x; const int iUV = (y / 2) * mHalfWidth + half_x;
uint8_t* sqCb = frame_Cb_ + iCbCr; uint8_t* sqU = mFrameU + iUV;
uint8_t* sqCr = frame_Cr_ + iCbCr; uint8_t* sqV = mFrameV + iUV;
uint8_t* sqY = Y_pos; uint8_t* sqY = Y_pos;
for (int i = x; i < square_xstop; i += 2) { for (int i = x; i < square_xstop; i += 2) {
color->get(sqY, sqCb, sqCr); color->get(sqY, sqU, sqV);
sqY[1] = *sqY; 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. * a fake camera device.
*/ */
#include "converters.h" #include "Converters.h"
#include "emulated_camera_device.h" #include "EmulatedCameraDevice.h"
namespace android { namespace android {
@@ -43,51 +43,51 @@ public:
/* Destructs EmulatedFakeCameraDevice instance. */ /* Destructs EmulatedFakeCameraDevice instance. */
~EmulatedFakeCameraDevice(); ~EmulatedFakeCameraDevice();
/**************************************************************************** /***************************************************************************
* Emulated camera device abstract interface implementation. * Emulated camera device abstract interface implementation.
* See declarations of these methods in EmulatedCameraDevice class for * See declarations of these methods in EmulatedCameraDevice class for
* information on each of these methods. * information on each of these methods.
***************************************************************************/ **************************************************************************/
public: public:
/* Connects to the camera device. /* Connects to the camera device.
* Since there is no real device to connect to, this method does nothing, but * Since there is no real device to connect to, this method does nothing,
* changes the state. * but changes the state.
*/ */
status_t Connect(); status_t connectDevice();
/* Disconnects from the camera device. /* Disconnects from the camera device.
* Since there is no real device to disconnect from, this method does * Since there is no real device to disconnect from, this method does
* nothing, but changes the state. * nothing, but changes the state.
*/ */
status_t Disconnect(); status_t disconnectDevice();
protected: protected:
/* Starts capturing frames from the camera device. /* Starts capturing frames from the camera device.
* Since there is no real device to control, this method simply starts the * Since there is no real device to control, this method simply starts the
* worker thread, and changes the state. * worker thread, and changes the state.
*/ */
status_t StartCamera(); status_t startDevice();
/* Stops capturing frames from the camera device. /* Stops capturing frames from the camera device.
* Since there is no real device to control, this method simply stops the * Since there is no real device to control, this method simply stops the
* worker thread, and changes the state. * worker thread, and changes the state.
*/ */
status_t StopCamera(); status_t stopDevice();
/**************************************************************************** /***************************************************************************
* Worker thread management overrides. * Worker thread management overrides.
* See declarations of these methods in EmulatedCameraDevice class for * See declarations of these methods in EmulatedCameraDevice class for
* information on each of these methods. * information on each of these methods.
***************************************************************************/ **************************************************************************/
protected: protected:
/* Implementation of the worker thread routine. /* Implementation of the worker thread routine.
* This method simply sleeps for a period of time defined by FPS property of * This method simply sleeps for a period of time defined by FPS property of
* the fake camera (simulating frame frequency), and then calls emulated * 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 * Fake camera device private API
@@ -95,7 +95,7 @@ protected:
private: private:
/* Draws a black and white checker board in the current frame buffer. */ /* 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. /* Draws a square of the given color in the current frame buffer.
* Param: * Param:
@@ -103,7 +103,7 @@ private:
* size - Size of the square's side. * size - Size of the square's side.
* color - Square's color. * 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 * Fake camera device data members
@@ -111,31 +111,31 @@ private:
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 mBlackYUV;
YUVPixel white_YCbCr_; YUVPixel mWhiteYUV;
YUVPixel red_YCbCr_; YUVPixel mRedYUV;
YUVPixel green_YCbCr_; YUVPixel mGreenYUV;
YUVPixel blue_YCbCr_; YUVPixel mBlueYUV;
/* /*
* Drawing related stuff * Drawing related stuff
*/ */
int check_x_; int mCheckX;
int check_y_; int mCheckY;
int counter_; int mCcounter;
int half_width_; int mHalfWidth;
/* Emulated FPS (frames per second). /* Emulated FPS (frames per second).
* We will emulate 50 FPS. */ * 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. /* Defines time (in nanoseconds) between redrawing the checker board.
* We will redraw the checker board every 15 milliseconds. */ * We will redraw the checker board every 15 milliseconds. */
static const nsecs_t redraw_after_ = 15000000LL; static const nsecs_t mRedrawAfter = 15000000LL;
}; };
}; /* namespace android */ }; /* namespace android */

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -40,9 +40,9 @@ public:
/* Destructs PreviewWindow instance. */ /* Destructs PreviewWindow instance. */
~PreviewWindow(); ~PreviewWindow();
/**************************************************************************** /***************************************************************************
* Camera API * Camera API
***************************************************************************/ **************************************************************************/
public: public:
/* Actual handler for camera_device_ops_t::set_preview_window callback. /* 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 * window - Preview window to set. This parameter might be NULL, which
* indicates preview window reset. * indicates preview window reset.
* preview_fps - Preview's frame frequency. This parameter determins when * preview_fps - Preview's frame frequency. This parameter determins when
* a frame received via OnNextFrameAvailable call will be pushed to the * a frame received via onNextFrameAvailable call will be pushed to
* preview window. If 'window' parameter passed to this method is NULL, * the preview window. If 'window' parameter passed to this method is
* this parameter is ignored. * NULL, this parameter is ignored.
* Return: * Return:
* NO_ERROR on success, or an appropriate error status. * 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); int preview_fps);
/* Starts the preview. /* Starts the preview.
* This method is called by the containing emulated camera object when it is * This method is called by the containing emulated camera object when it is
* handing the camera_device_ops_t::start_preview callback. * handing the camera_device_ops_t::start_preview callback.
*/ */
status_t Start(); status_t startPreview();
/* Stops the preview. /* Stops the preview.
* This method is called by the containing emulated camera object when it is * This method is called by the containing emulated camera object when it is
* handing the camera_device_ops_t::start_preview callback. * handing the camera_device_ops_t::start_preview callback.
*/ */
void Stop(); void stopPreview();
/* Checks if preview is enabled. */ /* Checks if preview is enabled. */
bool IsEnabled(); bool isPreviewEnabled();
/**************************************************************************** /****************************************************************************
* Public API * Public API
@@ -96,13 +96,13 @@ public:
* timestamp - Frame's timestamp. * timestamp - Frame's timestamp.
* camera_dev - Camera device instance that delivered the frame. * camera_dev - Camera device instance that delivered the frame.
*/ */
void OnNextFrameAvailable(const void* frame, void onNextFrameAvailable(const void* frame,
nsecs_t timestamp, nsecs_t timestamp,
EmulatedCameraDevice* camera_dev); EmulatedCameraDevice* camera_dev);
/**************************************************************************** /***************************************************************************
* Private API * Private API
***************************************************************************/ **************************************************************************/
protected: protected:
/* Adjusts cached dimensions of the preview window frame according to the /* 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 * 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, * 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, * 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 * in order to be always in sync with frame dimensions, this method is
* for each frame passed to OnNextFrameAvailable method, in order to properly * called for each frame passed to onNextFrameAvailable method, in order to
* adjust frame dimensions, used by the preview window. * properly adjust frame dimensions, used by the preview window.
* Note that this method must be called while object is locked. * Note that this method must be called while object is locked.
* Param: * Param:
* camera_dev - Camera device, prpviding frames displayed in the preview * 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 * true if cached dimensions have been adjusted, or false if cached
* dimensions match device's frame dimensions. * 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. /* 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. */ * Note that this method must be called while object is locked. */
bool IsTimeToPreview(); bool isPreviewTime();
/**************************************************************************** /***************************************************************************
* Data members * Data members
***************************************************************************/ **************************************************************************/
protected: protected:
/* Locks this instance for data changes. */ /* Locks this instance for data changes. */
Mutex object_lock_; Mutex mObjectLock;
/* Preview window instance. */ /* Preview window instance. */
preview_stream_ops* preview_window_; preview_stream_ops* mPreviewWindow;
/* Timestamp (abs. microseconds) when last frame has been pushed to the /* Timestamp (abs. microseconds) when last frame has been pushed to the
* preview window. */ * preview window. */
uint64_t last_previewed_; uint64_t mLastPreviewed;
/* Preview frequency in microseconds. */ /* Preview frequency in microseconds. */
uint32_t preview_after_; uint32_t mPreviewAfter;
/* /*
* Cached preview window frame dimensions. * Cached preview window frame dimensions.
*/ */
int preview_frame_width_; int mPreviewFrameWidth;
int preview_frame_height_; int mPreviewFrameHeight;
/* Preview status. */ /* Preview status. */
bool preview_enabled_; bool mPreviewEnabled;
}; };
}; /* namespace android */ }; /* 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_NDEBUG 0
#define LOG_TAG "EmulatedCamera_QemuClient" #define LOG_TAG "EmulatedCamera_QemuClient"
#include <cutils/log.h> #include <cutils/log.h>
#include "emulated_camera.h" #include "EmulatedCamera.h"
#include "QemuClient.h" #include "QemuClient.h"
namespace android { namespace android {
@@ -32,50 +32,50 @@ namespace android {
***************************************************************************/ ***************************************************************************/
QemuQuery::QemuQuery() QemuQuery::QemuQuery()
: query_(query_prealloc_), : mQuery(mQueryPrealloc),
query_status_(NO_ERROR), mQueryStatus(NO_ERROR),
reply_buffer_(NULL), mReplyBuffer(NULL),
reply_data_(NULL), mReplyData(NULL),
reply_size_(0), mReplySize(0),
reply_data_size_(0), mReplyDataSize(0),
reply_status_(0) mReplyStatus(0)
{ {
*query_ = '\0'; *mQuery = '\0';
} }
QemuQuery::QemuQuery(const char* query_string) QemuQuery::QemuQuery(const char* query_string)
: query_(query_prealloc_), : mQuery(mQueryPrealloc),
query_status_(NO_ERROR), mQueryStatus(NO_ERROR),
reply_buffer_(NULL), mReplyBuffer(NULL),
reply_data_(NULL), mReplyData(NULL),
reply_size_(0), mReplySize(0),
reply_data_size_(0), mReplyDataSize(0),
reply_status_(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) QemuQuery::QemuQuery(const char* query_name, const char* query_param)
: query_(query_prealloc_), : mQuery(mQueryPrealloc),
query_status_(NO_ERROR), mQueryStatus(NO_ERROR),
reply_buffer_(NULL), mReplyBuffer(NULL),
reply_data_(NULL), mReplyData(NULL),
reply_size_(0), mReplySize(0),
reply_data_size_(0), mReplyDataSize(0),
reply_status_(0) mReplyStatus(0)
{ {
query_status_ = QemuQuery::Create(query_name, query_param); mQueryStatus = QemuQuery::createQuery(query_name, query_param);
} }
QemuQuery::~QemuQuery() 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 from the previous use. */
Reset(); resetQuery();
/* Query name cannot be NULL or an empty string. */ /* Query name cannot be NULL or an empty string. */
if (name == NULL || *name == '\0') { 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 param_len = (param != NULL) ? strlen(param) : 0;
const size_t required = strlen(name) + (param_len ? (param_len + 2) : 1); 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. */ /* Preallocated buffer was too small. Allocate a bigger query buffer. */
query_ = new char[required]; mQuery = new char[required];
if (query_ == NULL) { if (mQuery == NULL) {
LOGE("%s: Unable to allocate %d bytes for query buffer", LOGE("%s: Unable to allocate %d bytes for query buffer",
__FUNCTION__, required); __FUNCTION__, required);
query_status_ = ENOMEM; mQueryStatus = ENOMEM;
return 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) { if (param_len) {
sprintf(query_, "%s %s", name, param); sprintf(mQuery, "%s %s", name, param);
} else { } else {
memcpy(query_, name, name_len + 1); memcpy(mQuery, name, name_len + 1);
} }
return NO_ERROR; return NO_ERROR;
} }
status_t QemuQuery::Completed(status_t status) status_t QemuQuery::completeQuery(status_t status)
{ {
/* Save query completion status. */ /* Save query completion status. */
query_status_ = status; mQueryStatus = status;
if (query_status_ != NO_ERROR) { if (mQueryStatus != NO_ERROR) {
return query_status_; return mQueryStatus;
} }
/* Make sure reply buffer contains at least 'ok', or 'ko'. /* 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' * 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 * 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. */ * 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__); LOGE("%s: Invalid reply to the query", __FUNCTION__);
query_status_ = EINVAL; mQueryStatus = EINVAL;
return EINVAL; return EINVAL;
} }
/* Lets see the reply status. */ /* Lets see the reply status. */
if (!memcmp(reply_buffer_, "ok", 2)) { if (!memcmp(mReplyBuffer, "ok", 2)) {
reply_status_ = 1; mReplyStatus = 1;
} else if (!memcmp(reply_buffer_, "ko", 2)) { } else if (!memcmp(mReplyBuffer, "ko", 2)) {
reply_status_ = 0; mReplyStatus = 0;
} else { } else {
LOGE("%s: Invalid query reply: '%s'", __FUNCTION__, reply_buffer_); LOGE("%s: Invalid query reply: '%s'", __FUNCTION__, mReplyBuffer);
query_status_ = EINVAL; mQueryStatus = EINVAL;
return EINVAL; return EINVAL;
} }
/* Lets see if there are reply data that follow. */ /* 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 /* There are extra data. Make sure they are separated from the status
* with a ':' */ * with a ':' */
if (reply_buffer_[2] != ':') { if (mReplyBuffer[2] != ':') {
LOGE("%s: Invalid query reply: '%s'", __FUNCTION__, reply_buffer_); LOGE("%s: Invalid query reply: '%s'", __FUNCTION__, mReplyBuffer);
query_status_ = EINVAL; mQueryStatus = EINVAL;
return EINVAL; return EINVAL;
} }
reply_data_ = reply_buffer_ + 3; mReplyData = mReplyBuffer + 3;
reply_data_size_ = reply_size_ - 3; mReplyDataSize = mReplySize - 3;
} else { } else {
/* Make sure reply buffer containing just 'ok'/'ko' ends with /* Make sure reply buffer containing just 'ok'/'ko' ends with
* zero-terminator. */ * zero-terminator. */
if (reply_buffer_[2] != '\0') { if (mReplyBuffer[2] != '\0') {
LOGE("%s: Invalid query reply: '%s'", __FUNCTION__, reply_buffer_); LOGE("%s: Invalid query reply: '%s'", __FUNCTION__, mReplyBuffer);
query_status_ = EINVAL; mQueryStatus = EINVAL;
return EINVAL; return EINVAL;
} }
} }
@@ -163,21 +163,21 @@ status_t QemuQuery::Completed(status_t status)
return NO_ERROR; return NO_ERROR;
} }
void QemuQuery::Reset() void QemuQuery::resetQuery()
{ {
if (query_ != NULL && query_ != query_prealloc_) { if (mQuery != NULL && mQuery != mQueryPrealloc) {
delete[] query_; delete[] mQuery;
} }
query_ = query_prealloc_; mQuery = mQueryPrealloc;
query_status_ = NO_ERROR; mQueryStatus = NO_ERROR;
if (reply_buffer_ != NULL) { if (mReplyBuffer != NULL) {
free(reply_buffer_); free(mReplyBuffer);
reply_buffer_ = NULL; mReplyBuffer = NULL;
} }
reply_data_ = NULL; mReplyData = NULL;
reply_size_ = 0; mReplySize = 0;
reply_data_size_ = 0; mReplyDataSize = 0;
reply_status_ = 0; mReplyStatus = 0;
} }
/**************************************************************************** /****************************************************************************
@@ -185,17 +185,17 @@ void QemuQuery::Reset()
***************************************************************************/ ***************************************************************************/
/* Camera service name. */ /* Camera service name. */
const char QemuClient::camera_service_name_[] = "camera"; const char QemuClient::mCameraServiceName[] = "camera";
QemuClient::QemuClient() QemuClient::QemuClient()
: fd_(-1) : mPipeFD(-1)
{ {
} }
QemuClient::~QemuClient() QemuClient::~QemuClient()
{ {
if (fd_ >= 0) { if (mPipeFD >= 0) {
close(fd_); close(mPipeFD);
} }
} }
@@ -203,12 +203,12 @@ QemuClient::~QemuClient()
* Qemu client API * Qemu client API
***************************************************************************/ ***************************************************************************/
status_t QemuClient::Connect(const char* param) status_t QemuClient::connectClient(const char* param)
{ {
LOGV("%s: '%s'", __FUNCTION__, param ? param : ""); LOGV("%s: '%s'", __FUNCTION__, param ? param : "");
/* Make sure that client is not connected already. */ /* Make sure that client is not connected already. */
if (fd_ >= 0) { if (mPipeFD >= 0) {
LOGE("%s: Qemu client is already connected", __FUNCTION__); LOGE("%s: Qemu client is already connected", __FUNCTION__);
return EINVAL; return EINVAL;
} }
@@ -217,19 +217,19 @@ status_t QemuClient::Connect(const char* param)
if (param == NULL || *param == '\0') { if (param == NULL || *param == '\0') {
/* No parameters: connect to the factory service. */ /* No parameters: connect to the factory service. */
char pipe_name[512]; char pipe_name[512];
snprintf(pipe_name, sizeof(pipe_name), "qemud:%s", camera_service_name_); snprintf(pipe_name, sizeof(pipe_name), "qemud:%s", mCameraServiceName);
fd_ = qemu_pipe_open(pipe_name); mPipeFD = qemu_pipe_open(pipe_name);
} else { } else {
/* One extra char ':' that separates service name and parameters + six /* One extra char ':' that separates service name and parameters + six
* characters for 'qemud:'. This is required by qemu pipe protocol. */ * 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]; 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; delete[] connection_str;
} }
if (fd_ < 0) { if (mPipeFD < 0) {
LOGE("%s: Unable to connect to the camera service '%s': %s", LOGE("%s: Unable to connect to the camera service '%s': %s",
__FUNCTION__, param ? param : "Factory", strerror(errno)); __FUNCTION__, param ? param : "Factory", strerror(errno));
return errno ? errno : EINVAL; return errno ? errno : EINVAL;
@@ -238,17 +238,17 @@ status_t QemuClient::Connect(const char* param)
return NO_ERROR; return NO_ERROR;
} }
void QemuClient::Disconnect() void QemuClient::disconnectClient()
{ {
if (fd_ >= 0) { if (mPipeFD >= 0) {
close(fd_); close(mPipeFD);
fd_ = -1; 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__); LOGE("%s: Qemu client is not connected", __FUNCTION__);
return EINVAL; 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 * 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 * 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. */ * 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) { if (written == data_size) {
return NO_ERROR; return NO_ERROR;
} else { } 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 = NULL;
*data_size = 0; *data_size = 0;
if (fd_ < 0) { if (mPipeFD < 0) {
LOGE("%s: Qemu client is not connected", __FUNCTION__); LOGE("%s: Qemu client is not connected", __FUNCTION__);
return EINVAL; 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. */ * value. Note also, that the string doesn't contain zero-terminator. */
size_t payload_size; size_t payload_size;
char payload_size_str[9]; 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) { if (rd_res != 8) {
LOGE("%s: Unable to obtain payload size: %s", LOGE("%s: Unable to obtain payload size: %s",
__FUNCTION__, strerror(errno)); __FUNCTION__, strerror(errno));
@@ -306,7 +306,7 @@ status_t QemuClient::Receive(void** data, size_t* data_size)
__FUNCTION__, payload_size); __FUNCTION__, payload_size);
return ENOMEM; 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) { if (static_cast<size_t>(rd_res) == payload_size) {
*data_size = payload_size; *data_size = payload_size;
return NO_ERROR; 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. */ /* 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__); LOGE("%s: Query is invalid", __FUNCTION__);
return query->query_status_; return query->mQueryStatus;
} }
/* Send the query. */ /* 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) { if (res == NO_ERROR) {
/* Read the response. */ /* Read the response. */
res = Receive(reinterpret_cast<void**>(&query->reply_buffer_), res = receiveMessage(reinterpret_cast<void**>(&query->mReplyBuffer),
&query->reply_size_); &query->mReplySize);
if (res != NO_ERROR) { if (res != NO_ERROR) {
LOGE("%s Response to query '%s' has failed: %s", LOGE("%s Response to query '%s' has failed: %s",
__FUNCTION__, query->query_, strerror(res)); __FUNCTION__, query->mQuery, strerror(res));
} }
} else { } else {
LOGE("%s: Send query '%s' failed: %s", 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. */ /* 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. */ /* Queries list of cameras connected to the host. */
const char FactoryQemuClient::query_list_[] = "list"; const char FactoryQemuClient::mQueryList[] = "list";
FactoryQemuClient::FactoryQemuClient() FactoryQemuClient::FactoryQemuClient()
: QemuClient() : QemuClient()
@@ -366,29 +366,29 @@ FactoryQemuClient::~FactoryQemuClient()
{ {
} }
status_t FactoryQemuClient::ListCameras(char** list) status_t FactoryQemuClient::listCameras(char** list)
{ {
QemuQuery query(query_list_); QemuQuery query(mQueryList);
Query(&query); doQuery(&query);
if (!query.IsSucceeded()) { if (!query.isQuerySucceeded()) {
return query.GetCompletionStatus(); return query.getCompletionStatus();
} }
/* Make sure there is a list returned. */ /* 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__); LOGE("%s: No camera list is returned.", __FUNCTION__);
return EINVAL; return EINVAL;
} }
/* Copy the list over. */ /* Copy the list over. */
*list = (char*)malloc(query.reply_data_size_); *list = (char*)malloc(query.mReplyDataSize);
if (*list != NULL) { if (*list != NULL) {
memcpy(*list, query.reply_data_, query.reply_data_size_); memcpy(*list, query.mReplyData, query.mReplyDataSize);
LOGD("Emulated camera list: %s", *list); LOGD("Emulated camera list: %s", *list);
return NO_ERROR; return NO_ERROR;
} else { } else {
LOGE("%s: Unable to allocate %d bytes", LOGE("%s: Unable to allocate %d bytes",
__FUNCTION__, query.reply_data_size_); __FUNCTION__, query.mReplyDataSize);
return ENOMEM; return ENOMEM;
} }
} }
@@ -402,15 +402,15 @@ status_t FactoryQemuClient::ListCameras(char** list)
*/ */
/* Connect to the camera device. */ /* Connect to the camera device. */
const char CameraQemuClient::query_connect_[] = "connect"; const char CameraQemuClient::mQueryConnect[] = "connect";
/* Disconect from the camera device. */ /* Disconect from the camera device. */
const char CameraQemuClient::query_disconnect_[] = "disconnect"; const char CameraQemuClient::mQueryDisconnect[] = "disconnect";
/* Start capturing video from the camera device. */ /* 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. */ /* 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. */ /* Get next video frame from the camera device. */
const char CameraQemuClient::query_frame_[] = "frame"; const char CameraQemuClient::mQueryFrame[] = "frame";
CameraQemuClient::CameraQemuClient() CameraQemuClient::CameraQemuClient()
: QemuClient() : QemuClient()
@@ -422,94 +422,94 @@ CameraQemuClient::~CameraQemuClient()
} }
status_t CameraQemuClient::QueryConnect() status_t CameraQemuClient::queryConnect()
{ {
QemuQuery query(query_connect_); QemuQuery query(mQueryConnect);
Query(&query); doQuery(&query);
const status_t res = query.GetCompletionStatus(); const status_t res = query.getCompletionStatus();
LOGE_IF(res != NO_ERROR, "%s failed: %s", LOGE_IF(res != NO_ERROR, "%s failed: %s",
__FUNCTION__, query.reply_data_ ? query.reply_data_ : __FUNCTION__, query.mReplyData ? query.mReplyData :
"No error message"); "No error message");
return res; return res;
} }
status_t CameraQemuClient::QueryDisconnect() status_t CameraQemuClient::queryDisconnect()
{ {
QemuQuery query(query_disconnect_); QemuQuery query(mQueryDisconnect);
Query(&query); doQuery(&query);
const status_t res = query.GetCompletionStatus(); const status_t res = query.getCompletionStatus();
LOGE_IF(res != NO_ERROR, "%s failed: %s", LOGE_IF(res != NO_ERROR, "%s failed: %s",
__FUNCTION__, query.reply_data_ ? query.reply_data_ : __FUNCTION__, query.mReplyData ? query.mReplyData :
"No error message"); "No error message");
return res; return res;
} }
status_t CameraQemuClient::QueryStart(uint32_t pixel_format, status_t CameraQemuClient::queryStart(uint32_t pixel_format,
int width, int width,
int height) int height)
{ {
char query_str[256]; char query_str[256];
snprintf(query_str, sizeof(query_str), "%s dim=%dx%d pix=%d", 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); QemuQuery query(query_str);
Query(&query); doQuery(&query);
const status_t res = query.GetCompletionStatus(); const status_t res = query.getCompletionStatus();
LOGE_IF(res != NO_ERROR, "%s failed: %s", LOGE_IF(res != NO_ERROR, "%s failed: %s",
__FUNCTION__, query.reply_data_ ? query.reply_data_ : __FUNCTION__, query.mReplyData ? query.mReplyData :
"No error message"); "No error message");
return res; return res;
} }
status_t CameraQemuClient::QueryStop() status_t CameraQemuClient::queryStop()
{ {
QemuQuery query(query_stop_); QemuQuery query(mQueryStop);
Query(&query); doQuery(&query);
const status_t res = query.GetCompletionStatus(); const status_t res = query.getCompletionStatus();
LOGE_IF(res != NO_ERROR, "%s failed: %s", LOGE_IF(res != NO_ERROR, "%s failed: %s",
__FUNCTION__, query.reply_data_ ? query.reply_data_ : __FUNCTION__, query.mReplyData ? query.mReplyData :
"No error message"); "No error message");
return res; return res;
} }
status_t CameraQemuClient::QueryFrame(void* vframe, status_t CameraQemuClient::queryFrame(void* vframe,
void* pframe, void* pframe,
size_t vframe_size, size_t vframe_size,
size_t pframe_size) size_t pframe_size)
{ {
char query_str[256]; char query_str[256];
snprintf(query_str, sizeof(query_str), "%s video=%d preview=%d", 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); (pframe && pframe_size) ? pframe_size : 0);
QemuQuery query(query_str); QemuQuery query(query_str);
Query(&query); doQuery(&query);
const status_t res = query.GetCompletionStatus(); const status_t res = query.getCompletionStatus();
LOGE_IF(res != NO_ERROR, "%s failed: %s", LOGE_IF(res != NO_ERROR, "%s failed: %s",
__FUNCTION__, query.reply_data_ ? query.reply_data_ : __FUNCTION__, query.mReplyData ? query.mReplyData :
"No error message"); "No error message");
if (res == NO_ERROR) { if (res == NO_ERROR) {
/* Copy requested frames. */ /* Copy requested frames. */
size_t cur_offset = 0; 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. */ /* Video frame is always first. */
if (vframe != NULL && vframe_size != 0) { if (vframe != NULL && vframe_size != 0) {
/* Make sure that video frame is in. */ /* 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); memcpy(vframe, frame, vframe_size);
cur_offset += vframe_size; cur_offset += vframe_size;
} else { } else {
LOGE("%s: Reply (%d bytes) is to small to contain video frame (%d bytes)", 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; return EINVAL;
} }
} }
if (pframe != NULL && pframe_size != 0) { if (pframe != NULL && pframe_size != 0) {
/* Make sure that preview frame is in. */ /* 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); memcpy(pframe, frame + cur_offset, pframe_size);
cur_offset += pframe_size; cur_offset += pframe_size;
} else { } else {
LOGE("%s: Reply (%d bytes) is to small to contain preview frame (%d bytes)", 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; return EINVAL;
} }
} }

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

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