Skip to content

Conversation

@Sapna1-singh
Copy link

@Sapna1-singh Sapna1-singh commented Feb 16, 2023

Introduce a property based on which instance id is taken for socket connection for Gtest purpose. Check for this property in camera-vhal and if this set then use the instance id that is set by property for Gtest else use the default one.

Newly introduced property is ro.boot.container.testid.

Add Unit TestCases for Camera-vhal in Gtest.

Tracked-On: OAM-105831
Signed-off-by: Singh, Sapna1 sapna1.singh@intel.com

Gtest/Android.mk Outdated
LOCAL_CFLAGS += -fexceptions
LOCAL_MODULE_TAGS:= optional

LOCAL_SRC_FILES := main.cpp CameraFixture.cpp streamer_simulation_camera_client.cpp

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the same naming conventions for the files , Classes and functions ?

Gtest/Android.mk Outdated
LOCAL_MODULE_TAGS:= optional

LOCAL_SRC_FILES := main.cpp CameraFixture.cpp streamer_simulation_camera_client.cpp
LOCAL_SHARED_LIBRARIES += liblog libcutils libutils camera.cic_cloud libvhal-client

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it would be better to use camera.$(TARGET_PRODUCT) instead of hardcoding.



void CameraFixture::runStreamer(){
cc.IsRunning = true;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is IsRunning a static variable and not a member ?
Also, I think initializing it to true can be done from startDummyStreamer function internally.
Similarly setting to false can be done through a simple stopStreamer API. Thus it can be a private member too.

CameraFixture::CameraFixture()
{
SetCallback();
t1 = new thread(&CameraFixture::runStreamer, this);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Memory Leak ? This object t1 is not destructed.

#include "VirtualCameraFactory.h"
#include "streamer_simulation_camera_client.h"

#define clientId 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very common variable, and shouldn't be defined as a macro.
And, I think its better to use upper case for all macros.

[&](const VideoSink::camera_config_cmd_t& ctrl_msg) {
switch (ctrl_msg.cmd) {
case VideoSink::camera_cmd_t::CMD_OPEN: {
cout << "Received Open command from Camera VHal\n";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Printing a TAG and func might be helpful for debugging.

/*
* Returns the shared pointer for client Communicator
*/
std::vector<std::shared_ptr<ClientCommunicator>> getClientThread() { return mClientThreads; }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not pass the clientId and just return the particular ClientThread ?

val_client_cap[i].validOrientation = IsSensorOrientationValid(camera_info[i].sensorOrientation);
val_client_cap[i].validCameraFacing = IsCameraFacingValid(camera_info[i].facing);

/*switch (camera_info[i].codec_type) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can delete these lines instead of commenting out.

if (header.type != CAMERA_INFO) {
ALOGE("%s(%d): invalid camera_packet_type: %s", __FUNCTION__, mClientId,
camera_type_to_str(header.type));
if(header.type == REQUEST_CAPABILITY)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is not a valid usecase, I wouldn't recommend using a goto statement here.
If we really want to support the REQUEST_CAPABILITY dynamically, we should modularize all of these socket communication code, to save the current state, and handle the state changes accordingly.

@Sapna1-singh Sapna1-singh force-pushed the ww07_Gtest branch 6 times, most recently from 6bcebd7 to 7267fde Compare February 23, 2023 09:30
#ifndef CLIENT_COMMUNICATOR_HELPER_H
#define CLIENT_COMMUNICATOR_HELPER_H

#include <iostream>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need these 2 headers included ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its better to keep these 2 headers to avoid redefinition of header file issue.


namespace android {

class ClientCommunicatorHelper {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless we have some ClientCommunication specific contents to be added in this file, I think it would be better to rename this something like CapabilitiesHelper ?

#include <ClientCommunicatorHelper.h>
#include "CameraSocketCommand.h"
#include <log/log.h>
#include <sys/socket.h>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again please check if all these headers are required.

// Wait till complete the metadata update for a camera.
{
Mutex::Autolock al(sMutex);
// Dynamic client configuration is not supported when camera
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dynamic configuration check is not required anymore ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No its not required. Its already fixed from AIC application code.

ALOGE("%s(%d): Failed to send camera capabilities, err: %s ", __FUNCTION__, mClientId,
strerror(errno));
goto out;
free(ack_packet);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can avoid multiple free calls if you put the below logs in else block, and remove this line ?

break;
case CAMERA_DATA:
if (!mIsConfigurationDone) {
ALOGE("%s(%d): Not Valid Type.....camera_packet_type: %s, line_num = %d ", __FUNCTION__, mClientId,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you mention Configuration Incomplete in the logs to indicate why the packet is invalid.
eg.

ALOGE("%s(%d): Invalid camera_packet_type: %s, Configuration not completed", __FUNCTION__, mClientId,
                                      camera_type_to_str(header.type));```

handleIncomingFrames(header.size);
break;
default:
if (header.size > mSocketBuffer.size()) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this condition should be part of the default case, instead it can be checked before entering the switch case probably.
Even if its targeted only for data packets, I think it should be handled at the beginning of case CAMERA_DATA: .


class CameraClient {
private:
bool IsRunning;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have a uniform naming convention for the variables(at least for the newly introduced source files).
Could be mIsRunning, is_running_, but should be same across the variables used (instance_id , video_sink etc).

Modularize all the socket communication code for handling all the
incoming requests dynamically and  add a helper class that
facilitates validation of all the camera info metadata.

Tracked-On: OAM-106780
Signed-off-by: Singh, Sapna1 <sapna1.singh@intel.com>
Introduce a property based on which instance id is taken
for socket connection for Gtest purpose. Check for this
property in camera-vhal and if this set then use the
instance id that is set by property for Gtest else use
the default one.

Newly introduced property is ro.boot.container.testid.

Add Unit TestCases for Camera-vhal in Gtest.

Tracked-On: OAM-105831
Signed-off-by: Singh, Sapna1 sapna1.singh@intel.com
ConnectionsListener class was derived from Thread class
which was causing issue while calling join for this thread
from VirtualCameraFactory destructor.

The Base class from which ConnectionsListener was derived
was not the proper class.

With current implementation, instead of deriving from thread
class, a thread is introduced as a member of the class to do
the same job and it is started during creation of
ConnectionsListener object

Tracked-On: OAM-106781
Signed-off-by: Singh, Sapna1 <sapna1.singh@intel.com>
close the client thread after completing the execution of all
testcases.

An API is introduced to do cleanup and in that API, client
thread exit is requested, socket server thread exit is
requested and joins with the main thread after all the
cleanup.

Tracked-On: OAM-106783
Signed-off-by: Singh, Sapna1 <sapna1.singh@intel.com>
@sysopenci sysopenci added the Stale Stale label for inactive open prs label Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Stale Stale label for inactive open prs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants