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