!817 DefferStream&QuickThumbnail

Merge pull request !817 from dongshaomin/master
This commit is contained in:
openharmony_ci 2023-09-02 06:59:26 +00:00 committed by Gitee
commit e5a1c4c0e5
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 296 additions and 4 deletions

View File

@ -42,6 +42,7 @@ enum CameraUtConstants {
UT_SECOND_TIMES,
UT_TUNNEL_MODE = 5,
UT_DATA_SIZE = 8,
UT_PREVIEW_SIZE = 3112960,
};
enum ImageDataSaveSwitch {
@ -116,7 +117,7 @@ public:
int streamIdAnalyze = 103;
std::vector<int> captureIds;
std::vector<int> streamIds;
int32_t imageDataSaveSwitch = SWITCH_OFF;
int32_t imageDataSaveSwitch = SWITCH_ON;
int32_t rc;
bool status;
@ -149,6 +150,7 @@ public:
class StreamConsumer {
public:
void CalculateFps(int64_t timestamp, int32_t streamId);
void ReturnTimeStamp(int64_t *g_timestamp, uint32_t lenght,int64_t timestamp, int32_t gotSize);
OHOS::sptr<OHOS::IBufferProducer> CreateProducer(std::function<void(void*, uint32_t)> callback);
OHOS::sptr<BufferProducerSequenceable> CreateProducerSeq(std::function<void(void*, uint32_t)> callback);
void TakeSnapshoe()
@ -179,6 +181,7 @@ public:
std::function<void(void*, uint32_t)> callback_ = nullptr;
bool isFirstCalculateFps_ = false;
int timestampCount_ = 0;
static int64_t g_timestamp[2];
int64_t intervalTimestamp_ = 0;
const int64_t ONESECOND_OF_MICROSECOND_UNIT = 1000000000;
int64_t interval_ = ONESECOND_OF_MICROSECOND_UNIT;

View File

@ -18,7 +18,7 @@ using namespace OHOS;
using namespace std;
using namespace testing::ext;
using namespace OHOS::Camera;
int64_t OHOS::Camera::Test::StreamConsumer::g_timestamp[2] = {0};
void CameraHdiTestV1_1::SetUpTestCase(void) {}
void CameraHdiTestV1_1::TearDownTestCase(void) {}
void CameraHdiTestV1_1::SetUp(void)
@ -222,4 +222,281 @@ HWTEST_F(CameraHdiTestV1_1, SUB_DriverSystem_CameraHdiMg_0680, TestSize.Level1)
if (!metastrings.empty()) {
std::cout << "DefaultSettings1 = " << metastrings << std::endl;
}
}
/**
* @tc.name: GetStreamOperator_V1_1,defer_stream
* @tc.desc: GetStreamOperator_V1_1,defer_stream
* @tc.size: MediumTest
* @tc.type: Function
*/
HWTEST_F(CameraHdiTestV1_1, SUB_DriverSystem_CameraHdiMg_0690, TestSize.Level1)
{
cameraTest->Init();
if (cameraTest->serviceV1_1 == nullptr) {
return;
}
cameraTest->Open();
if (cameraTest->cameraDeviceV1_1 == nullptr) {
return;
}
cameraTest->streamOperatorCallback = new OHOS::Camera::Test::TestStreamOperatorCallback();
cameraTest->rc = cameraTest->cameraDeviceV1_1->GetStreamOperator_V1_1(cameraTest->streamOperatorCallback,
cameraTest->streamOperator_V1_1);
// Create stream
cameraTest->streamInfoV1_1 = std::make_shared<OHOS::HDI::Camera::V1_1::StreamInfo_V1_1>();
cameraTest->DefaultPreview(cameraTest->streamInfoV1_1);
cameraTest->streamInfosV1_1.push_back(*cameraTest->streamInfoV1_1);
cameraTest->rc = cameraTest->streamOperator_V1_1->CreateStreams_V1_1(cameraTest->streamInfosV1_1);
EXPECT_EQ(HDI::Camera::V1_0::NO_ERROR, cameraTest->rc);
cameraTest->rc = cameraTest->streamOperator_V1_1->CommitStreams(OperationMode::NORMAL, cameraTest->abilityVec);
EXPECT_EQ(HDI::Camera::V1_0::NO_ERROR, cameraTest->rc);
// Attach bufferqueue
std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer =
std::make_shared<OHOS::Camera::Test::StreamConsumer>();
OHOS::sptr<BufferProducerSequenceable> bufferQueue =
consumer->CreateProducerSeq([this](void* addr, uint32_t size) {
cameraTest->DumpImageFile(111, "yuv", addr, size);
});
EXPECT_NE(bufferQueue, nullptr);
EXPECT_NE(bufferQueue->producer_, nullptr);
bufferQueue->producer_->SetQueueSize(UT_DATA_SIZE);
cameraTest->rc = cameraTest->streamOperator_V1_1->AttachBufferQueue(
cameraTest->streamInfoV1_1->v1_0.streamId_, bufferQueue);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
// Capture
cameraTest->StartCapture(cameraTest->streamIdPreview, cameraTest->captureIdPreview, false, true);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
sleep(UT_SECOND_TIMES);
// Release
cameraTest->rc = cameraTest->streamOperator_V1_1->DetachBufferQueue(cameraTest->streamInfoV1_1->v1_0.streamId_);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
std::vector<int> streamIds = {cameraTest->streamInfoV1_1->v1_0.streamId_};
cameraTest->rc = cameraTest->streamOperator_V1_1->ReleaseStreams(streamIds);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
}
/**
* @tc.name: Quick Thumbnail
* @tc.desc: OHOS_ABILITY_STREAM_QUICK_THUMBNAIL_AVAILABLE
* @tc.size: MediumTest
* @tc.type: Function
*/
HWTEST_F(CameraHdiTestV1_1, SUB_DriverSystem_CameraHdiMg_0700, TestSize.Level1)
{
cameraTest->Init();
if (cameraTest->serviceV1_1 == nullptr) {
return;
}
cameraTest->Open();
if (cameraTest->cameraDeviceV1_1 == nullptr) {
return;
}
EXPECT_NE(cameraTest->ability, nullptr);
common_metadata_header_t* data = cameraTest->ability->get();
EXPECT_NE(data, nullptr);
camera_metadata_item_t entry;
int ret = FindCameraMetadataItem(data,OHOS_ABILITY_STREAM_QUICK_THUMBNAIL_AVAILABLE, &entry);
EXPECT_EQ(ret, CAM_META_SUCCESS);
std::cout << "OHOS_ABILITY_STREAM_QUICK_THUMBNAIL_AVAILABLE value is " << static_cast<int>(entry.data.i32[0]) << std::endl;
}
/**
* @tc.name: Quick Thumbnail
* @tc.desc: timestamp query,EXTENDED_STREAM_INFO_QUICK_THUMBNAIL set 0
* @tc.size: MediumTest
* @tc.type: Function
*/
HWTEST_F(CameraHdiTestV1_1, SUB_DriverSystem_CameraHdiMg_0710, TestSize.Level1)
{
int64_t timeStampCapture = 0;
int64_t timeStampThumbnail = 0;
cameraTest->Init();
if (cameraTest->serviceV1_1 == nullptr) {
return;
}
cameraTest->Open();
if (cameraTest->cameraDeviceV1_1 == nullptr) {
return;
}
cameraTest->streamOperatorCallback = new OHOS::Camera::Test::TestStreamOperatorCallback();
cameraTest->rc = cameraTest->cameraDeviceV1_1->GetStreamOperator_V1_1(
cameraTest->streamOperatorCallback, cameraTest->streamOperator_V1_1);
EXPECT_NE(cameraTest->streamOperator_V1_1, nullptr);
EXPECT_EQ(HDI::Camera::V1_0::NO_ERROR, cameraTest->rc);
// preview streamInfo
cameraTest->streamInfoV1_1 = std::make_shared<OHOS::HDI::Camera::V1_1::StreamInfo_V1_1>();
cameraTest->DefaultInfosPreview(cameraTest->streamInfoV1_1);
cameraTest->streamInfosV1_1.push_back(*cameraTest->streamInfoV1_1);
// capture extended streamInfo
OHOS::HDI::Camera::V1_1::ExtendedStreamInfo extendedStreamInfo;
extendedStreamInfo.type = OHOS::HDI::Camera::V1_1::EXTENDED_STREAM_INFO_QUICK_THUMBNAIL;
std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer2 =
std::make_shared<OHOS::Camera::Test::StreamConsumer>();
extendedStreamInfo.bufferQueue = consumer2->CreateProducerSeq([this](void *addr, uint32_t size) {
cameraTest->DumpImageFile(105, "yuv", addr, size);
});
EXPECT_NE(extendedStreamInfo.bufferQueue, nullptr);
EXPECT_NE(extendedStreamInfo.bufferQueue->producer_, nullptr);
extendedStreamInfo.bufferQueue->producer_->SetQueueSize(UT_DATA_SIZE);
// quikThumbnial do not need these param
extendedStreamInfo.width = 0;
extendedStreamInfo.height = 0;
extendedStreamInfo.format = 0;
extendedStreamInfo.dataspace = 0;
// capture streamInfo
cameraTest->streamInfoCapture = std::make_shared<OHOS::HDI::Camera::V1_1::StreamInfo_V1_1>();
cameraTest->streamInfoCapture->extendedStreamInfos = {extendedStreamInfo};
cameraTest->DefaultInfosCapture(cameraTest->streamInfoCapture);
cameraTest->streamInfosV1_1.push_back(*cameraTest->streamInfoCapture);
cameraTest->rc = cameraTest->streamOperator_V1_1->CreateStreams_V1_1(cameraTest->streamInfosV1_1);
EXPECT_EQ(HDI::Camera::V1_0::NO_ERROR, cameraTest->rc);
cameraTest->rc = cameraTest->streamOperator_V1_1->CommitStreams(OperationMode::NORMAL, cameraTest->abilityVec);
EXPECT_EQ(HDI::Camera::V1_0::NO_ERROR, cameraTest->rc);
sleep(UT_SECOND_TIMES);
cameraTest->StartCapture(cameraTest->streamIdPreview, cameraTest->captureIdPreview, false, true);
cameraTest->StartCapture(cameraTest->streamIdCapture, cameraTest->captureIdCapture, false, false);
timeStampThumbnail = OHOS::Camera::Test::StreamConsumer::g_timestamp[0];
timeStampCapture = OHOS::Camera::Test::StreamConsumer::g_timestamp[1];
EXPECT_EQ(true, timeStampThumbnail == timeStampCapture);
cameraTest->captureIds = {cameraTest->captureIdPreview};
cameraTest->streamIds = {cameraTest->streamIdPreview};
cameraTest->StopStream(cameraTest->captureIds, cameraTest->streamIds);
}
/**
* @tc.name: Quick Thumbnail
* @tc.desc: XTENDED_STREAM_INFO_QUICK_THUMBNAIL set 0
* @tc.size: MediumTest
* @tc.type: Function
*/
HWTEST_F(CameraHdiTestV1_1, SUB_DriverSystem_CameraHdiMg_0720, TestSize.Level1)
{
cameraTest->Init();
if (cameraTest->serviceV1_1 == nullptr) {
return;
}
cameraTest->Open();
if (cameraTest->cameraDeviceV1_1 == nullptr) {
return;
}
cameraTest->streamOperatorCallback = new OHOS::Camera::Test::TestStreamOperatorCallback();
cameraTest->rc = cameraTest->cameraDeviceV1_1->GetStreamOperator_V1_1(
cameraTest->streamOperatorCallback, cameraTest->streamOperator_V1_1);
EXPECT_NE(cameraTest->streamOperator_V1_1, nullptr);
EXPECT_EQ(HDI::Camera::V1_0::NO_ERROR, cameraTest->rc);
// preview streamInfo
cameraTest->streamInfoV1_1 = std::make_shared<OHOS::HDI::Camera::V1_1::StreamInfo_V1_1>();
cameraTest->DefaultInfosPreview(cameraTest->streamInfoV1_1);
cameraTest->streamInfosV1_1.push_back(*cameraTest->streamInfoV1_1);
// capture extended streamInfo
OHOS::HDI::Camera::V1_1::ExtendedStreamInfo extendedStreamInfo;
extendedStreamInfo.type = OHOS::HDI::Camera::V1_1::EXTENDED_STREAM_INFO_QUICK_THUMBNAIL;
std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer2 =
std::make_shared<OHOS::Camera::Test::StreamConsumer>();
extendedStreamInfo.bufferQueue = consumer2->CreateProducerSeq([this](void *addr, uint32_t size) {
cameraTest->DumpImageFile(105, "yuv", addr, size);
});
EXPECT_NE(extendedStreamInfo.bufferQueue, nullptr);
EXPECT_NE(extendedStreamInfo.bufferQueue->producer_, nullptr);
extendedStreamInfo.bufferQueue->producer_->SetQueueSize(UT_DATA_SIZE);
// quikThumbnial do not need these param
extendedStreamInfo.width = 0;
extendedStreamInfo.height = 0;
extendedStreamInfo.format = 0;
extendedStreamInfo.dataspace = 0;
// capture streamInfo
cameraTest->streamInfoCapture = std::make_shared<OHOS::HDI::Camera::V1_1::StreamInfo_V1_1>();
cameraTest->streamInfoCapture->extendedStreamInfos = {extendedStreamInfo};
cameraTest->DefaultInfosCapture(cameraTest->streamInfoCapture);
cameraTest->streamInfosV1_1.push_back(*cameraTest->streamInfoCapture);
cameraTest->rc = cameraTest->streamOperator_V1_1->CreateStreams_V1_1(cameraTest->streamInfosV1_1);
EXPECT_EQ(HDI::Camera::V1_0::NO_ERROR, cameraTest->rc);
cameraTest->rc = cameraTest->streamOperator_V1_1->CommitStreams(OperationMode::NORMAL, cameraTest->abilityVec);
EXPECT_EQ(HDI::Camera::V1_0::NO_ERROR, cameraTest->rc);
sleep(UT_SECOND_TIMES);
cameraTest->StartCapture(cameraTest->streamIdPreview, cameraTest->captureIdPreview, false, true);
cameraTest->StartCapture(cameraTest->streamIdCapture, cameraTest->captureIdCapture, false, false);
cameraTest->captureIds = {cameraTest->captureIdPreview};
cameraTest->streamIds = {cameraTest->streamIdPreview};
cameraTest->StopStream(cameraTest->captureIds, cameraTest->streamIds);
}
/**
* @tc.name: Quick Thumbnail
* @tc.desc: Quick Thumbnail BufferSize Set different,Size = 40
* @tc.size: MediumTest
* @tc.type: Function
*/
HWTEST_F(CameraHdiTestV1_1, SUB_DriverSystem_CameraHdiMg_0750, TestSize.Level1)
{
cameraTest->Init();
if (cameraTest->serviceV1_1 == nullptr) {
return;
}
cameraTest->Open();
if (cameraTest->cameraDeviceV1_1 == nullptr) {
return;
}
cameraTest->streamOperatorCallback = new OHOS::Camera::Test::TestStreamOperatorCallback();
cameraTest->rc = cameraTest->cameraDeviceV1_1->GetStreamOperator_V1_1(
cameraTest->streamOperatorCallback, cameraTest->streamOperator_V1_1);
EXPECT_NE(cameraTest->streamOperator_V1_1, nullptr);
EXPECT_EQ(HDI::Camera::V1_0::NO_ERROR, cameraTest->rc);
// preview streamInfo
cameraTest->streamInfoV1_1 = std::make_shared<OHOS::HDI::Camera::V1_1::StreamInfo_V1_1>();
cameraTest->DefaultInfosPreview(cameraTest->streamInfoV1_1);
cameraTest->streamInfosV1_1.push_back(*cameraTest->streamInfoV1_1);
// capture extended streamInfo
OHOS::HDI::Camera::V1_1::ExtendedStreamInfo extendedStreamInfo;
extendedStreamInfo.type = OHOS::HDI::Camera::V1_1::EXTENDED_STREAM_INFO_QUICK_THUMBNAIL;
std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer2 =
std::make_shared<OHOS::Camera::Test::StreamConsumer>();
extendedStreamInfo.bufferQueue = consumer2->CreateProducerSeq([this](void *addr, uint32_t size) {
cameraTest->DumpImageFile(105, "yuv", addr, 40);
});
EXPECT_NE(extendedStreamInfo.bufferQueue, nullptr);
EXPECT_NE(extendedStreamInfo.bufferQueue->producer_, nullptr);
extendedStreamInfo.bufferQueue->producer_->SetQueueSize(UT_DATA_SIZE);
// quikThumbnial do not need these param
extendedStreamInfo.width = 0;
extendedStreamInfo.height = 0;
extendedStreamInfo.format = 0;
extendedStreamInfo.dataspace = 0;
// capture streamInfo
cameraTest->streamInfoCapture = std::make_shared<OHOS::HDI::Camera::V1_1::StreamInfo_V1_1>();
cameraTest->streamInfoCapture->extendedStreamInfos = {extendedStreamInfo};
cameraTest->DefaultInfosCapture(cameraTest->streamInfoCapture);
cameraTest->streamInfosV1_1.push_back(*cameraTest->streamInfoCapture);
cameraTest->rc = cameraTest->streamOperator_V1_1->CreateStreams_V1_1(cameraTest->streamInfosV1_1);
EXPECT_EQ(HDI::Camera::V1_0::NO_ERROR, cameraTest->rc);
cameraTest->rc = cameraTest->streamOperator_V1_1->CommitStreams(OperationMode::NORMAL, cameraTest->abilityVec);
EXPECT_EQ(HDI::Camera::V1_0::NO_ERROR, cameraTest->rc);
sleep(UT_SECOND_TIMES);
cameraTest->StartCapture(cameraTest->streamIdPreview, cameraTest->captureIdPreview, false, true);
cameraTest->StartCapture(cameraTest->streamIdCapture, cameraTest->captureIdCapture, false, false);
cameraTest->captureIds = {cameraTest->captureIdPreview};
cameraTest->streamIds = {cameraTest->streamIdPreview};
cameraTest->StopStream(cameraTest->captureIds, cameraTest->streamIds);
}

View File

@ -45,7 +45,7 @@ int32_t Test::DumpImageFile(int streamId, std::string suffix, const void* buffer
return -1;
}
system(mkdirCmd);
ret = sprintf_s(path, sizeof(path) / sizeof(path[0]), "data/stream-%d/%lld.%s",
ret = sprintf_s(path, sizeof(path) / sizeof(path[0]), "/data/stream-%d/%lld.%s",
streamId, GetCurrentLocalTimeStamp(), suffix.c_str());
if (ret < 0) {
return -1;
@ -183,7 +183,7 @@ void Test::DefaultInfosCapture(
DefaultCapture(infos);
std::shared_ptr<StreamConsumer> consumer_capture = std::make_shared<StreamConsumer>();
infos->v1_0.bufferQueue_ = consumer_capture->CreateProducerSeq([this](void* addr, uint32_t size) {
DumpImageFile(streamIdCapture, "yuv", addr, size);
DumpImageFile(streamIdCapture, "jpeg", addr, size);
});
infos->v1_0.bufferQueue_->producer_->SetQueueSize(UT_DATA_SIZE);
consumerMap_[StreamIntent::STILL_CAPTURE] = consumer_capture;
@ -372,6 +372,17 @@ void Test::StreamConsumer::CalculateFps(int64_t timestamp, int32_t streamId)
timestampCount_++;
}
void Test::StreamConsumer::ReturnTimeStamp(int64_t *g_timestamp, uint32_t lenght, int64_t timestamp, int32_t gotSize)
{
if (gotSize != UT_PREVIEW_SIZE) {
if (g_timestamp[0] == 0) {
g_timestamp[0] = timestamp;
} else {
g_timestamp[1] = timestamp;
}
}
}
OHOS::sptr<OHOS::IBufferProducer> Test::StreamConsumer::CreateProducer(std::function<void(void*, uint32_t)> callback)
{
consumer_ = OHOS::IConsumerSurface::Create();
@ -408,6 +419,7 @@ OHOS::sptr<OHOS::IBufferProducer> Test::StreamConsumer::CreateProducer(std::func
buffer->GetExtraData()->ExtraGet(OHOS::Camera::timeStamp, timestamp);
buffer->GetExtraData()->ExtraGet(OHOS::Camera::streamId, streamId);
buffer->GetExtraData()->ExtraGet(OHOS::Camera::captureId, captureId);
ReturnTimeStamp(g_timestamp, sizeof(g_timestamp) / sizeof(g_timestamp[0]), timestamp, gotSize);
if (gotSize) {
CalculateFps(timestamp, streamId);
callback_(addr, gotSize);