!115 【hdf】【matser】DCTS分布式相机测试用例维护

Merge pull request !115 from bjliang/master
This commit is contained in:
openharmony_ci 2022-09-08 01:38:16 +00:00 committed by Gitee
commit 6442489884
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 81 additions and 145 deletions

View File

@ -9,7 +9,7 @@
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
module_output_path = "dcts/hdf"
@ -52,6 +52,11 @@ ohos_moduletest_suite("DctsdisCameraTest") {
"//third_party/jsoncpp:jsoncpp",
]
cflags = [
"-fPIC",
"-Wall",
]
external_deps = [
"drivers_interface_camera:libcamera_proxy_1.0",
"graphic_chipsetsdk:surface",
@ -66,9 +71,7 @@ ohos_moduletest_suite("DctsdisCameraTest") {
"LOG_DOMAIN=0xD004100",
]
public_configs = [ ":dcamera_hdf_demo_config" ]
install_enable = true
install_images = [ chipset_base_dir ]
cflags_cc = cflags
subsystem_name = "hdf"
part_name = "drivers_peripheral_distributed_camera"
}

View File

@ -52,6 +52,7 @@ HWTEST_F(DCameraAutomatTest, DCameraTest_0100, TestSize.Level1)
ret = mainDemo->InitCameraDevice();
EXPECT_EQ(cameraOk, ret) << "InitCameraDevice fail";
sleep(sleepOk);
mainDemo->SetEnableResult();
ret = PreviewOn(0, mainDemo);
EXPECT_EQ(cameraOk, ret) << "PreviewOn fail";
sleep(sleepOk);

View File

@ -48,18 +48,26 @@ void DcameraHdfDemo::SetStreamInfo(StreamInfo& streamInfo,
constexpr uint32_t height = CAMERA_PREVIEW_HEIGHT;
streamInfo.width_ = width;
streamInfo.height_ = height;
producer = streamCustomer->CreateProducer(CAPTURE_PREVIEW, nullptr);
} else if (intent == OHOS::HDI::Camera::V1_0::STILL_CAPTURE) {
constexpr uint32_t width = CAMERA_CAPTURE_WIDTH;
constexpr uint32_t height = CAMERA_CAPTURE_HEIGHT;
streamInfo.width_ = width;
streamInfo.height_ = height;
streamInfo.encodeType_ = CAMERA_CAPTURE_ENCODE_TYPE;
producer = streamCustomer->CreateProducer(CAPTURE_SNAPSHOT, [this](void* addr, const uint32_t size) {
StoreImage((char*)addr, size);
});
} else {
constexpr uint32_t width = CAMERA_VIDEO_WIDTH;
constexpr uint32_t height = CAMERA_VIDEO_HEIGHT;
streamInfo.width_ = width;
streamInfo.height_ = height;
streamInfo.encodeType_ = CAMERA_VIDEO_ENCODE_TYPE;
OpenVideoFile();
producer = streamCustomer->CreateProducer(CAPTURE_VIDEO, [this](void* addr, const uint32_t size) {
StoreVideo((char*)addr, size);
});
}
streamInfo.streamId_ = streamId;
@ -68,7 +76,6 @@ void DcameraHdfDemo::SetStreamInfo(StreamInfo& streamInfo,
streamInfo.intent_ = intent;
streamInfo.tunneledMode_ = tunneledMode;
producer = streamCustomer->CreateProducer();
streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
streamInfo.bufferQueue_->producer_->SetQueueSize(8); // 8:set bufferQueue size
}
@ -121,9 +128,8 @@ RetCode DcameraHdfDemo::CaptureON(const int streamId, const int captureId, Captu
bool iscapture = true;
if (mode == CAPTURE_SNAPSHOT) {
CaptureSet(setting);
}else
{
CaptureSet(setting);
} else {
OHOS::Camera::MetadataUtils::ConvertMetadataToVec(captureSetting_, setting);
}
@ -142,19 +148,7 @@ RetCode DcameraHdfDemo::CaptureON(const int streamId, const int captureId, Captu
streamOperator_->ReleaseStreams(captureInfo_.streamIds_);
return RC_ERROR;
}
DHLOGI("demo test: CaptureStart Capture success");
if (mode == CAPTURE_PREVIEW) {
streamCustomerPreview_->ReceiveFrameOn(nullptr);
} else if (mode == CAPTURE_SNAPSHOT) {
streamCustomerCapture_->ReceiveFrameOn([this](void* addr, const uint32_t size) {
StoreImage((char*)addr, size);
});
} else if (mode == CAPTURE_VIDEO) {
OpenVideoFile();
streamCustomerVideo_->ReceiveFrameOn([this](void* addr, const uint32_t size) {
StoreVideo((char*)addr, size);
});
}
DHLOGI("demo test: CaptureON exit");
return RC_OK;
}
@ -170,13 +164,10 @@ RetCode DcameraHdfDemo::CaptureOff(const int captureId, const CaptureMode mode)
}
if (mode == CAPTURE_PREVIEW) {
streamCustomerPreview_->ReceiveFrameOff();
rc = streamOperator_->CancelCapture(captureId);
} else if (mode == CAPTURE_SNAPSHOT) {
streamCustomerCapture_->ReceiveFrameOff();
rc = streamOperator_->CancelCapture(captureId);
} else if (mode == CAPTURE_VIDEO) {
streamCustomerVideo_->ReceiveFrameOff();
rc = streamOperator_->CancelCapture(captureId);
close(videoFd_);
videoFd_ = -1;
@ -201,7 +192,6 @@ RetCode DcameraHdfDemo::CreateStreamInfo(const int streamId, std::shared_ptr<Str
}
StreamInfo streamInfo = {0};
SetStreamInfo(streamInfo, streamCustomer, streamId, intent);
if (streamInfo.bufferQueue_->producer_ == nullptr) {
DHLOGE("demo test: CreateStream CreateProducer(); is nullptr");
@ -236,7 +226,6 @@ RetCode DcameraHdfDemo::CreateStream()
RetCode DcameraHdfDemo::InitCameraDevice()
{
int rc = 0;
DHLOGI("demo test: InitCameraDevice enter");
if (demoCameraHost_ == nullptr) {
@ -251,7 +240,6 @@ RetCode DcameraHdfDemo::InitCameraDevice()
const std::string cameraId = cameraIds_.front();
demoCameraHost_->GetCameraAbility(cameraId, cameraAbility_);
OHOS::Camera::MetadataUtils::ConvertVecToMetadata(cameraAbility_, ability_);
GetFaceDetectMode(ability_);
@ -397,7 +385,6 @@ RetCode DcameraHdfDemo::CreateStreams(const int streamIdSecond, StreamIntent int
streamInfos.push_back(previewStreamInfo);
StreamInfo secondStreamInfo = {0};
if (streamIdSecond == STREAM_ID_CAPTURE) {
SetStreamInfo(secondStreamInfo, streamCustomerCapture_, STREAM_ID_CAPTURE, intent);
} else {
@ -442,7 +429,6 @@ RetCode DcameraHdfDemo::CaptureOnDualStreams(const int streamIdSecond)
streamOperator_->ReleaseStreams(previewCaptureInfo.streamIds_);
return RC_ERROR;
}
streamCustomerPreview_->ReceiveFrameOn(nullptr);
CaptureInfo secondCaptureInfo;
secondCaptureInfo.streamIds_ = {streamIdSecond};
@ -456,10 +442,6 @@ RetCode DcameraHdfDemo::CaptureOnDualStreams(const int streamIdSecond)
streamOperator_->ReleaseStreams(secondCaptureInfo.streamIds_);
return RC_ERROR;
}
streamCustomerCapture_->ReceiveFrameOn([this](void *addr, const uint32_t size) {
StoreImage((char*)addr, size);
});
} else {
rc = streamOperator_->Capture(CAPTURE_ID_VIDEO, secondCaptureInfo, true);
if (rc != HDI::Camera::V1_0::NO_ERROR) {
@ -467,11 +449,6 @@ RetCode DcameraHdfDemo::CaptureOnDualStreams(const int streamIdSecond)
streamOperator_->ReleaseStreams(secondCaptureInfo.streamIds_);
return RC_ERROR;
}
OpenVideoFile();
streamCustomerVideo_->ReceiveFrameOn([this](void* addr, const uint32_t size) {
StoreVideo((char*)addr, size);
});
}
DHLOGI("demo test: CaptuCaptureOnDualStreamsreON exit");
@ -660,7 +637,6 @@ RetCode DcameraHdfDemo::SetAwbMode(const int mode) const
RetCode DcameraHdfDemo::SetAeExpo()
{
int32_t expo;
DHLOGI("demo test: SetAeExpo enter");
constexpr size_t entryCapacity = 100;
@ -804,7 +780,6 @@ RetCode DcameraHdfDemo::StreamOffline(const int streamId)
return RC_ERROR;
}
}
streamCustomerCapture_->ReceiveFrameOff();
DHLOGI("demo test: StreamOffline exit");
return RC_OK;
@ -1281,7 +1256,7 @@ RetCode OfflineTest(const std::shared_ptr<DcameraHdfDemo>& mainDemo)
RetCode CaptureTest(const std::shared_ptr<DcameraHdfDemo>& mainDemo)
{
RetCode rc = RC_OK;
constexpr size_t delayTime = 10;
constexpr size_t delayTime = 5;
rc = mainDemo->CaptureON(STREAM_ID_CAPTURE, CAPTURE_ID_CAPTURE, CAPTURE_SNAPSHOT);
if (rc != RC_OK) {
@ -1302,7 +1277,7 @@ RetCode CaptureTest(const std::shared_ptr<DcameraHdfDemo>& mainDemo)
RetCode VideoTest(const std::shared_ptr<DcameraHdfDemo>& mainDemo)
{
RetCode rc = RC_OK;
constexpr size_t delayTime = 10;
constexpr size_t delayTime = 5;
PreviewOff(mainDemo);
mainDemo->StartDualStreams(STREAM_ID_VIDEO);

View File

@ -45,18 +45,7 @@ using namespace OHOS::Camera;
using namespace OHOS::HDI::Camera::V1_0;
#define CAMERA_CAPTURE_ENCODE_TYPE OHOS::HDI::Camera::V1_0::ENCODE_TYPE_JPEG
#define CAMERA_VIDEO_ENCODE_TYPE OHOS::HDI::Camera::V1_0::ENCODE_TYPE_H264
#ifdef DCAMERA_YUV
#define CAMERA_FORMAT PIXEL_FMT_YCRCB_420_SP
#else
#define CAMERA_FORMAT PIXEL_FMT_RGBA_8888
#endif
typedef enum {
CAPTURE_PREVIEW = 0,
CAPTURE_SNAPSHOT,
CAPTURE_VIDEO,
} CaptureMode;
#define CAMERA_FORMAT PIXEL_FMT_YCRCB_420_SP
typedef enum {
STREAM_ID_PREVIEW = 1001,
@ -169,6 +158,7 @@ private:
OHOS::sptr<ICameraDevice> demoCameraDevice_ = nullptr;
std::vector<std::string> cameraIds_ = {};
friend class StreamCustomer;
};
class DemoCameraDeviceCallback : public ICameraDeviceCallback {

View File

@ -22,46 +22,20 @@ namespace DistributedHardware {
StreamCustomer::StreamCustomer() {}
StreamCustomer::~StreamCustomer() {}
void StreamCustomer::CamFrame(const std::function<void(void*, uint32_t)> callback)
{
DHLOGI("demo test:enter CamFrame thread ++ ");
OHOS::Rect damage;
int32_t flushFence = 0;
int64_t newTimeStamp = 0;
constexpr uint32_t delayTime = 5000;
do {
OHOS::sptr<OHOS::SurfaceBuffer> buff = nullptr;
consumer_->AcquireBuffer(buff, flushFence, newTimeStamp, damage);
if (buff != nullptr) {
void* addr = buff->GetVirAddr();
if (callback != nullptr) {
int32_t gotSize = 0;
int32_t frameNum = 0;
int isKey = 0;
int64_t timestamp;
buff->GetExtraData()->ExtraGet(OHOS::Camera::dataSize, gotSize);
buff->GetExtraData()->ExtraGet(OHOS::Camera::isKeyFrame, isKey);
buff->GetExtraData()->ExtraGet(OHOS::Camera::timeStamp, timestamp);
DHLOGE("demo test:CamFrame callback +++++++ Size == %d frameNum = %d timestamp == %lld",
gotSize, frameNum, timestamp);
callback(addr, gotSize);
}
consumer_->ReleaseBuffer(buff, -1);
}
usleep(delayTime);
} while (camFrameExit_ == 0);
DHLOGI("demo test:Exiting CamFrame thread -- ");
}
sptr<OHOS::IBufferProducer> StreamCustomer::CreateProducer()
sptr<OHOS::IBufferProducer> StreamCustomer::CreateProducer(CaptureMode mode,
const std::function<void(void*, uint32_t)> callback)
{
consumer_ = OHOS::Surface::CreateSurfaceAsConsumer();
if (consumer_ == nullptr) {
return nullptr;
}
sptr<IBufferConsumerListener> listener = new TestBuffersConsumerListener();
sptr<IBufferConsumerListener> listener = nullptr;
if (mode == CAPTURE_PREVIEW) {
} else if (mode == CAPTURE_SNAPSHOT) {
listener = new TestBuffersConsumerListener(consumer_, callback);
} else if (mode == CAPTURE_VIDEO) {
listener = new TestBuffersConsumerListener(consumer_, callback);
}
consumer_->RegisterConsumerListener(listener);
auto producer = consumer_->GetProducer();
@ -72,38 +46,5 @@ sptr<OHOS::IBufferProducer> StreamCustomer::CreateProducer()
DHLOGI("demo test, create a buffer queue producer %p", producer.GetRefPtr());
return producer;
}
RetCode StreamCustomer::ReceiveFrameOn(const std::function<void(void*, uint32_t)> callback)
{
DHLOGI("demo test:ReceiveFrameOn enter");
if (camFrameExit_ == 1) {
camFrameExit_ = 0;
previewThreadId_ = new (std::nothrow) std::thread(&StreamCustomer::CamFrame, this, callback);
if (previewThreadId_ == nullptr) {
DHLOGE("demo test:ReceiveFrameOn failed");
return RC_ERROR;
}
} else {
DHLOGI("demo test:ReceiveFrameOn loop thread is running");
}
DHLOGI("demo test:ReceiveFrameOn exit");
return RC_OK;
}
void StreamCustomer::ReceiveFrameOff()
{
DHLOGI("demo test:ReceiveFrameOff enter");
if (camFrameExit_ == 0) {
camFrameExit_ = 1;
if (previewThreadId_ != nullptr) {
previewThreadId_->join();
delete previewThreadId_;
previewThreadId_ = nullptr;
}
}
DHLOGI("demo test:ReceiveFrameOff exit");
}
}
}

View File

@ -16,11 +16,11 @@
#ifndef DISTRIBUTED_STREAM_CUSTOMER_H
#define DISTRIBUTED_STREAM_CUSTOMER_H
#include <fstream>
#include <iostream>
#include <thread>
#include <vector>
#include <map>
#include <hdf_log.h>
#include <surface.h>
#include <display_type.h>
#include "constants.h"
@ -30,35 +30,61 @@
namespace OHOS {
namespace DistributedHardware {
typedef enum {
CAPTURE_PREVIEW = 0,
CAPTURE_SNAPSHOT,
CAPTURE_VIDEO,
} CaptureMode;
class TestBuffersConsumerListener : public IBufferConsumerListener {
public:
TestBuffersConsumerListener(const sptr<Surface>& surface,
const std::function<void(void*, const uint32_t)> callback):callback_(callback), consumer_(surface)
{
}
~TestBuffersConsumerListener()
{
}
void OnBufferAvailable()
{
DHLOGI("demo test:enter OnBufferAvailable start");
OHOS::Rect damage;
int32_t flushFence = 0;
int64_t timestamp = 0;
OHOS::sptr<OHOS::SurfaceBuffer> buff = nullptr;
consumer_->AcquireBuffer(buff, flushFence, timestamp, damage);
if (buff != nullptr) {
void* addr = buff->GetVirAddr();
if (callback_ != nullptr) {
int32_t size = buff->GetSize();
callback_(addr, size);
}
consumer_->ReleaseBuffer(buff, -1);
DHLOGI("demo test:Exiting OnBufferAvailable end");
}
}
void SetCallback(const std::function<void(void*, const uint32_t)> callback)
{
callback_ = callback;
}
private:
std::function<void(void*, uint32_t)> callback_;
sptr<Surface> consumer_;
};
class StreamCustomer {
public:
StreamCustomer();
~StreamCustomer();
sptr<OHOS::IBufferProducer> CreateProducer();
void CamFrame(const std::function<void(void*, const uint32_t)> callback);
sptr<OHOS::IBufferProducer> CreateProducer(CaptureMode mode,
const std::function<void(void*, uint32_t)> callback);
RetCode ReceiveFrameOn(const std::function<void(void*, const uint32_t)> callback);
void ReceiveFrameOff();
class TestBuffersConsumerListener : public IBufferConsumerListener {
public:
TestBuffersConsumerListener()
{
}
~TestBuffersConsumerListener()
{
}
void OnBufferAvailable()
{
}
};
private:
unsigned int camFrameExit_ = 1;
sptr<OHOS::Surface> consumer_ = nullptr;
std::thread* previewThreadId_ = nullptr;
};
} // namespace OHOS::Camera
}