Skip to content

Commit

Permalink
Fix the static analysis Issues
Browse files Browse the repository at this point in the history
Tracked-On: OAM-106688
Signed-off-by: Singh, Sapna1 <[email protected]>
  • Loading branch information
Sapna1-singh authored and sysopenci committed Mar 23, 2023
1 parent 020c733 commit 2542384
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 28 deletions.
5 changes: 5 additions & 0 deletions include/ClientCommunicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#ifndef CLIENT_COMMUNICATOR_H
#define CLIENT_COMMUNICATOR_H

#define MAX_CAM 4

#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/un.h>
Expand Down Expand Up @@ -48,6 +50,9 @@ class ClientCommunicator {
int client_id);
~ClientCommunicator();

ClientCommunicator(ClientCommunicator const&) = delete;
ClientCommunicator& operator=(const ClientCommunicator&) = delete;

int getClientId();
status_t sendCommandToClient(socket::camera_packet_t *config_cmd_packet,
size_t config_cmd_packet_size);
Expand Down
1 change: 1 addition & 0 deletions include/VirtualFakeCamera3.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <utils/Mutex.h>
#include <memory>
#include <atomic>
#include <random>
#include "ClientCommunicator.h"
#include "CameraSocketCommand.h"

Expand Down
12 changes: 9 additions & 3 deletions src/ClientCommunicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ bool ClientCommunicator::clientThread() {
} else if (header.size < sizeof(camera_info_t)) {
ALOGE("%s(%d): Invalid camera info, payload size received, size = %u",
__FUNCTION__, mClientId, header.size);
} else if(header.size > (MAX_CAM*sizeof(camera_info_t))) {
ALOGE("%s(%d): header size exceeds the max limit, size = %u",
__FUNCTION__, mClientId, header.size);
} else {
mNumOfCamerasRequested = (header.size) / sizeof(camera_info_t);
handleCameraInfo(header.size);
Expand All @@ -374,13 +377,15 @@ bool ClientCommunicator::clientThread() {
break;
case CAMERA_DATA:
if (!mIsConfigurationDone) {
ALOGE("%s(%d): Invalid camera_packet_type: %s, Configuration not completed", __FUNCTION__, mClientId,
ALOGE("%s(%d): Invalid camera_packet_type: %s,"
"Configuration not completed", __FUNCTION__, mClientId,
camera_type_to_str(header.type));
} else if (header.size > mSocketBuffer.size()) {
// maximum size of a H264 packet in any aggregation packet is 65535
// bytes. Source: https://tools.ietf.org/html/rfc6184#page-13
ALOGE("%s(%d) Fatal: Unusual encoded packet size detected: %u! Max is %zu, "
"...",__func__, mClientId, header.size, mSocketBuffer.size());
ALOGE("%s(%d) Fatal: Unusual encoded packet size detected: %u!"
"Max is %zu", __func__, mClientId, header.size,
mSocketBuffer.size());
} else {
handleIncomingFrames(header.size);
}
Expand Down Expand Up @@ -442,6 +447,7 @@ void ClientCommunicator::handleIncomingFrames(uint32_t header_size) {
case CameraSessionState::kCameraOpened:
mCameraSessionState = CameraSessionState::kDecodingStarted;
ALOGVV("%s(%d): Decoding started now.", __func__, mClientId);
[[fallthrough]];
case CameraSessionState::kDecodingStarted: {
if (mCameraBuffer == NULL) break;
mCameraBuffer->clientRevCount++;
Expand Down
40 changes: 24 additions & 16 deletions src/ConnectionsListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <sys/time.h>
#include <sys/un.h>
#include <chrono>
#include <algorithm>
#include <cutils/properties.h>
#include "CameraSocketCommand.h"

Expand Down Expand Up @@ -97,22 +98,20 @@ bool ConnectionsListener::socketListenerThreadProc() {

struct pollfd fd;
struct sockaddr_un addr_un;
int new_client_fd = -1;
memset(&addr_un, 0, sizeof(addr_un));
addr_un.sun_family = AF_UNIX;
strncpy(&addr_un.sun_path[0], mSocketPath.c_str(), strlen(mSocketPath.c_str()));
strncpy(&addr_un.sun_path[0], mSocketPath.c_str(),
std::min(strlen(mSocketPath.c_str()),sizeof(addr_un.sun_path)));

int ret = 0;
if ((access(mSocketPath.c_str(), F_OK)) != -1) {
ALOGI(" %s camera socket server file is %s", __FUNCTION__, mSocketPath.c_str());
ret = unlink(mSocketPath.c_str());
if (ret < 0) {
ALOGE(" %s Failed to unlink %s address %d, %s", __FUNCTION__,
mSocketPath.c_str(), ret, strerror(errno));
}
} else {
ALOGI(" %s camera socket server file %s will created. ", __FUNCTION__,
mSocketPath.c_str());
}
ret = unlink(mSocketPath.c_str());
if (ret < 0) {
ALOGE(" %s Failed to unlink %s address %d, %s", __FUNCTION__,
mSocketPath.c_str(), ret, strerror(errno));
}
ALOGI(" %s camera socket server file %s is created. ", __FUNCTION__,
mSocketPath.c_str());

ret = ::bind(mSocketServerFd, (struct sockaddr *)&addr_un,
sizeof(sa_family_t) + strlen(mSocketPath.c_str()) + 1);
Expand All @@ -127,8 +126,13 @@ bool ConnectionsListener::socketListenerThreadProc() {
if (fstat(mSocketServerFd, &st) == 0) {
mod |= st.st_mode;
}
chmod(mSocketPath.c_str(), mod);
stat(mSocketPath.c_str(), &st);

ret = chmod(mSocketPath.c_str(), mod);
if(ret < 0)
return false;
ret = stat(mSocketPath.c_str(), &st);
if(ret < 0)
return false;

ret = listen(mSocketServerFd, 5);
if (ret < 0) {
Expand All @@ -155,7 +159,7 @@ bool ConnectionsListener::socketListenerThreadProc() {
else if (fd.revents & POLLIN) {
socklen_t alen = sizeof(struct sockaddr_un);

int new_client_fd = ::accept(mSocketServerFd, (struct sockaddr *)&addr_un, &alen);
new_client_fd = ::accept(mSocketServerFd, (struct sockaddr *)&addr_un, &alen);
if (new_client_fd < 0) {
ALOGE(" %s: Fail to accept client. Error: [%s]", __FUNCTION__, strerror(errno));
continue;
Expand All @@ -168,6 +172,7 @@ bool ConnectionsListener::socketListenerThreadProc() {
android::socket::camera_packet_t * user_id_packet = (android::socket::camera_packet_t *)malloc(packet_size);
if (user_id_packet == NULL) {
ALOGE("%s: user_id_packet allocation failed: %d ", __FUNCTION__, __LINE__);
close(new_client_fd);
continue;
}
if (recv(new_client_fd, (char *)user_id_packet, packet_size, MSG_WAITALL) < 0) {
Expand All @@ -184,17 +189,20 @@ bool ConnectionsListener::socketListenerThreadProc() {
}
if (!status) {
free(user_id_packet);
close(new_client_fd);
continue;
}
memcpy(&client_id, user_id_packet->payload, sizeof(client_id));
free(user_id_packet);
if (client_id < 0 || client_id >= mNumConcurrentUsers) {
if (client_id >= mNumConcurrentUsers) {
ALOGE("%s: client_id = %u is not valid", __FUNCTION__, client_id);
close(new_client_fd);
continue;
}
}
if (mClientsConnected[client_id]) {
ALOGE(" %s: IGNORING clientFd[%d] for already connected Client[%d]", __FUNCTION__, new_client_fd, client_id);
close(new_client_fd);
} else {
mClientFdPromises[client_id].set_value(new_client_fd);
ALOGI(" %s: Assigned clientFd[%d] to Client[%d]", __FUNCTION__, new_client_fd, client_id);
Expand Down
20 changes: 13 additions & 7 deletions src/VirtualFakeCamera3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2139,6 +2139,9 @@ status_t VirtualFakeCamera3::process3A(CameraMetadata &settings) {

status_t VirtualFakeCamera3::doFakeAE(CameraMetadata &settings) {
camera_metadata_entry e;
std::random_device rd;
std::mt19937 mt(rd());
std::uniform_real_distribution<double> dist {1.0, 100000.0};

e = settings.find(ANDROID_CONTROL_AE_MODE);
if (e.count == 0 && hasCapability(BACKWARD_COMPATIBLE)) {
Expand Down Expand Up @@ -2217,7 +2220,7 @@ status_t VirtualFakeCamera3::doFakeAE(CameraMetadata &settings) {
mAeTargetExposureTime =
mFacePriority ? kFacePriorityExposureTime : kNormalExposureTime;
float exposureStep =
((double)rand() / RAND_MAX) * (kExposureWanderMax - kExposureWanderMin) +
(dist(mt) / RAND_MAX) * (kExposureWanderMax - kExposureWanderMin) +
kExposureWanderMin;
mAeTargetExposureTime *= std::pow(2, exposureStep);
mAeState = ANDROID_CONTROL_AE_STATE_SEARCHING;
Expand Down Expand Up @@ -2251,6 +2254,9 @@ status_t VirtualFakeCamera3::doFakeAE(CameraMetadata &settings) {

status_t VirtualFakeCamera3::doFakeAF(CameraMetadata &settings) {
camera_metadata_entry e;
std::random_device rd;
std::mt19937 mt(rd());
std::uniform_int_distribution<int> dist {1,};

e = settings.find(ANDROID_CONTROL_AF_MODE);
if (e.count == 0 && hasCapability(BACKWARD_COMPATIBLE)) {
Expand Down Expand Up @@ -2360,7 +2366,7 @@ status_t VirtualFakeCamera3::doFakeAF(CameraMetadata &settings) {
*/
if (afTriggerStart) {
// Randomly transition to focused or not focused
if (rand() % 3) {
if (dist(mt) % 3) {
mAfState = ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED;
} else {
mAfState = ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED;
Expand All @@ -2373,7 +2379,7 @@ status_t VirtualFakeCamera3::doFakeAF(CameraMetadata &settings) {
*/
else if (!afTriggerCancel) {
// Randomly transition to passive focus
if (rand() % 3 == 0) {
if (dist(mt) % 3 == 0) {
mAfState = ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED;
}
}
Expand All @@ -2382,7 +2388,7 @@ status_t VirtualFakeCamera3::doFakeAF(CameraMetadata &settings) {
case ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED:
if (afTriggerStart) {
// Randomly transition to focused or not focused
if (rand() % 3) {
if (dist(mt) % 3) {
mAfState = ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED;
} else {
mAfState = ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED;
Expand All @@ -2394,7 +2400,7 @@ status_t VirtualFakeCamera3::doFakeAF(CameraMetadata &settings) {
// Simulate AF sweep completing instantaneously

// Randomly transition to focused or not focused
if (rand() % 3) {
if (dist(mt) % 3) {
mAfState = ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED;
} else {
mAfState = ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED;
Expand Down Expand Up @@ -2725,7 +2731,7 @@ bool VirtualFakeCamera3::ReadoutThread::threadLoop() {

// Construct result for all completed buffers and results

camera3_capture_result result;
camera3_capture_result result = {};

if (mParent->hasCapability(BACKWARD_COMPATIBLE)) {
static const uint8_t sceneFlicker = ANDROID_STATISTICS_SCENE_FLICKER_NONE;
Expand Down Expand Up @@ -2795,7 +2801,7 @@ void VirtualFakeCamera3::ReadoutThread::onJpegDone(const StreamBuffer &jpegBuffe
mJpegHalBuffer.release_fence = -1;
mJpegWaiting = false;

camera3_capture_result result;
camera3_capture_result result = {};

result.frame_number = mJpegFrameNumber;
result.result = NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/fake-pipeline2/JpegCompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ status_t JpegCompressor::start(Buffers *buffers, JpegListener *listener, CameraM
if (res != OK) {
ALOGE("%s: Unable to start up compression thread: %s (%d)", __FUNCTION__, strerror(-res),
res);
delete mBuffers;
mBuffers = nullptr;
}
return res;
}
Expand Down
1 change: 1 addition & 0 deletions src/jpeg-stub/Compressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Compressor::Compressor() {}

bool Compressor::compress(const unsigned char *data, int width, int height, int quality,
ExifData *exifData) {
memset(&mCompressInfo, 0, sizeof(mCompressInfo));
if (!configureCompressor(width, height, quality)) {
// The method will have logged a more detailed error message than we can
// provide here so just return.
Expand Down
2 changes: 1 addition & 1 deletion src/onevpl-video-decode/MfxDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ mfxStatus MfxDecoder::Init(uint32_t codec_type, uint32_t width, uint32_t height)
mfxStatus mfx_sts = MFX_ERR_NONE;
uint32_t impl_index = 0;
mfxConfig cfg[2];
mfxVariant cfgVal[2];
mfxVariant cfgVal[2] = {};

ClearFrameSurface();

Expand Down

0 comments on commit 2542384

Please sign in to comment.