!83 【分布式硬件子系统】新增DCTS测试用例

Merge pull request !83 from bjliang/master
This commit is contained in:
openharmony_ci 2022-08-04 03:49:34 +00:00 committed by Gitee
commit f3a41a5e51
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 750 additions and 0 deletions

View File

@ -0,0 +1,20 @@
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# 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.
import("//build/ohos_var.gni")
group("distributedcameratest") {
testonly = true
if (is_standard_system) {
deps = [ "distributedcameratest:DctsdisCameraTest" ]
}
}

View File

@ -0,0 +1,82 @@
# Copyright (C) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# 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.
import("//test/xts/tools/build/suite.gni")
module_output_path = "dcts/distributedhardware"
###############################################################################################
config("module_private_config") {
visibility = [ ":*" ]
include_dirs = [
"//drivers/peripheral/camera/interfaces/metadata/include",
"//third_party/jsoncpp/include",
"//utils/native/base/include",
"//utils/system/safwk/native/include",
"//foundation/graphic/graphic_2d/frameworks/surface/include",
"//foundation/multimedia/camera_standard/interfaces/inner_api/native/camera/include",
"//foundation/multimedia/camera_standard/interfaces/inner_api/native/camera/include/input",
"//foundation/multimedia/camera_standard/interfaces/inner_api/native/camera/include/output",
"//foundation/multimedia/camera_standard/interfaces/inner_api/native/camera/include/session",
"//foundation/multimedia/camera_standard/services/camera_service/binder/base/include",
"//foundation/multimedia/camera_standard/services/camera_service/binder/client/include",
"//foundation/multimedia/camera_standard/services/camera_service/binder/server/include",
"//foundation/multimedia/camera_standard/services/camera_service/include",
"//foundation/distributedhardware/distributed_hardware_fwk/common/log/include",
"//foundation/distributedhardware/distributed_hardware_fwk/common/utils/include",
"//foundation/distributedhardware/distributed_hardware_fwk/utils/include/log",
"//foundation/distributedhardware/distributed_hardware_fwk/utils/include",
"//foundation/distributedhardware/distributed_camera/common/include/constants",
"//foundation/distributedhardware/distributed_camera/common/include/utils",
"//foundation/distributedhardware/distributed_camera/services/cameraservice/base/include",
"//foundation/distributedhardware/distributed_camera/services/cameraservice/cameraoperator/client/include",
"//foundation/distributedhardware/distributed_camera/services/cameraservice/cameraoperator/client/include/callback",
"//foundation/distributedhardware/distributed_camera/services/cameraservice/cameraoperator/client/include/listener",
]
}
ohos_moduletest_suite("DctsdisCameraTest") {
module_out_path = module_output_path
sources = [
"dcamera_automat_test.cpp",
"dcamera_client_test.cpp",
]
configs = [ ":module_private_config" ]
defines = [
"HI_LOG_ENABLE",
"DH_LOG_TAG=\"DCameraClientTest\"",
"LOG_DOMAIN=0xD004100",
]
deps = [
"//drivers/peripheral/camera/interfaces/metadata:metadata",
"//foundation/distributedhardware/distributed_camera/common:distributed_camera_utils",
"//foundation/distributedhardware/distributed_camera/services/cameraservice/cameraoperator/client:distributed_camera_client",
"//foundation/distributedhardware/distributed_camera/services/cameraservice/sinkservice:distributed_camera_sink",
"//foundation/distributedhardware/distributed_hardware_fwk/utils:distributedhardwareutils",
"//foundation/graphic/graphic_2d:libsurface",
"//foundation/multimedia/camera_standard/frameworks/native/camera:camera_framework",
"//third_party/googletest:gtest_main",
"//third_party/jsoncpp:jsoncpp",
"//utils/native/base:utils",
]
external_deps = [
"drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.0",
"hiviewdfx_hilog_native:libhilog",
"multimedia_player_framework:media_client",
]
}
###########################################################################################

View File

@ -0,0 +1,22 @@
{
"description": "Config for disCamera test cases",
"driver": {
"module-name": "DctsdisCameraTest",
"native-test-timeout": "120000",
"native-test-device-path": "/data/local/tmp",
"runtime-hint": "1s",
"type": "CppTest"
},
"kits": [
{
"post-push" : [
"chmod -R 777 /data/local/tmp/*"
],
"push": [
"DctsdisCameraTest->/data/local/tmp/DctsdisCameraTest"
],
"type": "PushKit"
}
]
}

View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* 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.
*/
#include <gtest/gtest.h>
#include "dcamera_client_test.h"
using namespace testing::ext;
int32_t DCAMERA_OK = 0;
class DCameraAutomatTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
DCameraAutomatTest();
};
void DCameraAutomatTest::SetUpTestCase(void) {}
void DCameraAutomatTest::TearDownTestCase(void)
{
int ret = ReleaseDCamera();
EXPECT_EQ(DCAMERA_OK, ret) << "ReleaseDCamera fail";
}
void DCameraAutomatTest::SetUp(void) {}
void DCameraAutomatTest::TearDown(void) {}
DCameraAutomatTest::DCameraAutomatTest(void) {}
HWTEST_F(DCameraAutomatTest, DCameraTest_0100, TestSize.Level1)
{
int ret = InitDCamera();
EXPECT_EQ(DCAMERA_OK, ret) << "InitDCamera fail";
ret = DCameraPreview();
EXPECT_EQ(DCAMERA_OK, ret) << "DCameraPreview fail";
ret = DCameraPhoto();
EXPECT_EQ(DCAMERA_OK, ret) << "DCameraPhoto fail";
}

View File

@ -0,0 +1,284 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* 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.
*/
#include "dcamera_client_test.h"
#include <fstream>
using namespace OHOS;
using namespace OHOS::Camera;
using namespace OHOS::CameraStandard;
using namespace OHOS::DistributedHardware;
static int32_t rotationNum = 0;
static int32_t qualityNum = 0;
constexpr double LATITUDE = 22.306;
constexpr double LONGITUDE = 52.12;
constexpr double ALTITUDE = 2.365;
constexpr int32_t PHOTO_WIDTH = 640;
constexpr int32_t PHOTO_HEIGTH = 480;
constexpr int32_t PREVIEW_WIDTH = 640;
constexpr int32_t PREVIEW_HEIGTH = 480;
constexpr int32_t VIDEO_WIDTH = 640;
constexpr int32_t VIDEO_HEIGTH = 480;
constexpr int32_t SLEEP_FIVE_SECOND = 5;
constexpr int32_t SLEEP_TWENTY_SECOND = 20;
static sptr<CameraInfo> g_cameraInfo = nullptr;
static sptr<CameraManager> g_cameraManager = nullptr;
static sptr<CaptureInput> g_cameraInput = nullptr;
static sptr<CaptureOutput> g_photoOutput = nullptr;
static sptr<CaptureOutput> g_previewOutput = nullptr;
static sptr<CaptureOutput> g_videoOutput = nullptr;
static sptr<CaptureSession> g_captureSession = nullptr;
static std::shared_ptr<DCameraCaptureInfo> g_photoInfo = nullptr;
static std::shared_ptr<DCameraCaptureInfo> g_previewInfo = nullptr;
static std::shared_ptr<DCameraCaptureInfo> g_videoInfo = nullptr;
static sptr<DemoDCameraPreviewSurfaceListener> previewInfo = nullptr;
#ifdef PRODUCT_M40
constexpr int32_t PHOTO_FORMAT = camera_format_t::OHOS_CAMERA_FORMAT_JPEG;
constexpr int32_t PREVIEW_FORMAT = camera_format_t::OHOS_CAMERA_FORMAT_YCRCB_420_SP;
constexpr int32_t VIDEO_FORMAT = camera_format_t::OHOS_CAMERA_FORMAT_YCRCB_420_SP;
#else
constexpr int32_t PHOTO_FORMAT = camera_format_t::OHOS_CAMERA_FORMAT_RGBA_8888;
constexpr int32_t PREVIEW_FORMAT = camera_format_t::OHOS_CAMERA_FORMAT_RGBA_8888;
constexpr int32_t VIDEO_FORMAT = camera_format_t::OHOS_CAMERA_FORMAT_RGBA_8888;
#endif
static int32_t InitCameraStandard()
{
g_cameraManager = CameraManager::GetInstance();
g_cameraManager->SetCallback(std::make_shared<DemoDCameraManagerCallback>());
g_captureSession = g_cameraManager->CreateCaptureSession();
g_captureSession->SetCallback(std::make_shared<DemoDCameraSessionCallback>());
std::vector<sptr<CameraInfo>> cameraObjList = g_cameraManager->GetCameras();
for (auto info : cameraObjList) {
DHLOGI("Camera: %s, position: %d, camera type: %d, connection type: %d", GetAnonyString(info->GetID()).c_str(),
info->GetPosition(), info->GetCameraType(), info->GetConnectionType());
// OHOS_CAMERA_POSITION_FRONT or OHOS_CAMERA_POSITION_BACK
if ((info->GetPosition() == OHOS_CAMERA_POSITION_FRONT) &&
(info->GetConnectionType() == OHOS_CAMERA_CONNECTION_TYPE_REMOTE)) {
g_cameraInfo = info;
break;
}
}
if (g_cameraInfo == nullptr) {
DHLOGE("Distributed Camera Demo: have no remote camera");
return DCAMERA_BAD_VALUE;
}
g_cameraInput = g_cameraManager->CreateCameraInput(g_cameraInfo);
std::shared_ptr<DemoDCameraInputCallback> inputCallback = std::make_shared<DemoDCameraInputCallback>();
((sptr<CameraInput> &)g_cameraInput)->SetErrorCallback(inputCallback);
((sptr<CameraInput> &)g_cameraInput)->SetFocusCallback(inputCallback);
return DCAMERA_OK;
}
static void InitCaptureInfo()
{
g_photoInfo = std::make_shared<DCameraCaptureInfo>();
g_photoInfo->width_ = PHOTO_WIDTH;
g_photoInfo->height_ = PHOTO_HEIGTH;
g_photoInfo->format_ = PHOTO_FORMAT;
g_previewInfo = std::make_shared<DCameraCaptureInfo>();
g_previewInfo->width_ = PREVIEW_WIDTH;
g_previewInfo->height_ = PREVIEW_HEIGTH;
g_previewInfo->format_ = PREVIEW_FORMAT;
g_videoInfo = std::make_shared<DCameraCaptureInfo>();
g_videoInfo->width_ = VIDEO_WIDTH;
g_videoInfo->height_ = VIDEO_HEIGTH;
g_videoInfo->format_ = VIDEO_FORMAT;
}
static void InitPhotoOutput()
{
DHLOGI("Distributed Camera Demo: Create PhotoOutput, width = %d, height = %d, format = %d",
g_photoInfo->width_, g_photoInfo->height_, g_photoInfo->format_);
sptr<Surface> photoSurface = Surface::CreateSurfaceAsConsumer();
sptr<IBufferConsumerListener> photoListener = new DemoDCameraPhotoSurfaceListener(photoSurface);
photoSurface->SetDefaultWidthAndHeight(g_photoInfo->width_, g_photoInfo->height_);
photoSurface->SetUserData(CAMERA_SURFACE_FORMAT, std::to_string(g_photoInfo->format_));
photoSurface->RegisterConsumerListener(photoListener);
g_photoOutput = g_cameraManager->CreatePhotoOutput(photoSurface);
((sptr<PhotoOutput> &)g_photoOutput)->SetCallback(std::make_shared<DemoDCameraPhotoCallback>());
}
static void InitPreviewOutput()
{
DHLOGI("Distributed Camera Demo: Create PreviewOutput, width = %d, height = %d, format = %d",
g_previewInfo->width_, g_previewInfo->height_, g_previewInfo->format_);
sptr<Surface> previewSurface = Surface::CreateSurfaceAsConsumer();
sptr<IBufferConsumerListener> previewListener = new DemoDCameraPreviewSurfaceListener(previewSurface);
previewSurface->SetDefaultWidthAndHeight(g_previewInfo->width_, g_previewInfo->height_);
previewSurface->SetUserData(CAMERA_SURFACE_FORMAT, std::to_string(g_previewInfo->format_));
previewSurface->RegisterConsumerListener(previewListener);
g_previewOutput = g_cameraManager->CreatePreviewOutput(previewSurface);
((sptr<PreviewOutput> &)g_previewOutput)->SetCallback(std::make_shared<DemoDCameraPreviewCallback>());
}
static void InitVideoOutput()
{
DHLOGI("Distributed Camera Demo: Create VideoOutput, width = %d, height = %d, format = %d",
g_videoInfo->width_, g_videoInfo->height_, g_videoInfo->format_);
sptr<Surface> videoSurface = Surface::CreateSurfaceAsConsumer();
sptr<IBufferConsumerListener> videoListener = new DemoDCameraVideoSurfaceListener(videoSurface);
videoSurface->SetDefaultWidthAndHeight(g_videoInfo->width_, g_videoInfo->height_);
videoSurface->SetUserData(CAMERA_SURFACE_FORMAT, std::to_string(g_videoInfo->format_));
videoSurface->RegisterConsumerListener(videoListener);
g_videoOutput = g_cameraManager->CreateVideoOutput(videoSurface);
((sptr<VideoOutput> &)g_videoOutput)->SetCallback(std::make_shared<DemoDCameraVideoCallback>());
}
static void ConfigFocusAndExposure()
{
((sptr<CameraInput> &)g_cameraInput)->LockForControl();
camera_focus_mode_enum_t focusMode = OHOS_CAMERA_FOCUS_MODE_AUTO;
camera_exposure_mode_enum_t exposureMode = OHOS_CAMERA_EXPOSURE_MODE_AUTO;
int32_t exposureValue = 0;
std::vector<int32_t> biasRange = ((sptr<CameraInput> &)g_cameraInput)->GetExposureBiasRange();
if (!biasRange.empty()) {
DHLOGI("Distributed Camera Demo: get %d exposure compensation range", biasRange.size());
exposureValue = biasRange[0];
}
((sptr<CameraInput> &)g_cameraInput)->SetFocusMode(focusMode);
((sptr<CameraInput> &)g_cameraInput)->SetExposureMode(exposureMode);
((sptr<CameraInput> &)g_cameraInput)->SetExposureBias(exposureValue);
((sptr<CameraInput> &)g_cameraInput)->UnlockForControl();
}
static std::shared_ptr<PhotoCaptureSetting> ConfigPhotoCaptureSetting()
{
std::shared_ptr<PhotoCaptureSetting> photoCaptureSettings = std::make_shared<PhotoCaptureSetting>();
// Rotation
PhotoCaptureSetting::RotationConfig rotation = PhotoCaptureSetting::RotationConfig::Rotation_0;
photoCaptureSettings->SetRotation(rotation);
// QualityLevel
PhotoCaptureSetting::QualityLevel quality = PhotoCaptureSetting::QualityLevel::HIGH_QUALITY;
photoCaptureSettings->SetQuality(quality);
// Location
std::unique_ptr<Location> location = std::make_unique<Location>();
location->latitude = LATITUDE;
location->longitude = LONGITUDE;
location->altitude = ALTITUDE;
photoCaptureSettings->SetLocation(location);
sleep(SLEEP_FIVE_SECOND);
PhotoCaptureSetting::RotationConfig getrotation = photoCaptureSettings->GetRotation();
if (getrotation != PhotoCaptureSetting::RotationConfig::Rotation_0) {
std::cout << "photo getrotation failed.." << std::endl;
DHLOGI("photo getrotation failed..");
rotationNum = 1;
}
PhotoCaptureSetting::QualityLevel getquality = photoCaptureSettings->GetQuality();
if (getquality != PhotoCaptureSetting::QualityLevel::HIGH_QUALITY) {
std::cout << "photo getquality failed.." << std::endl;
DHLOGI("photo getquality failed..");
qualityNum = 1;
}
return photoCaptureSettings;
}
int InitDCamera(void)
{
DHLOGI("========== Distributed Camera Demo Start ==========");
int32_t ret = InitCameraStandard();
if (ret != DCAMERA_OK) {
std::cout << "have no remote camera" << std::endl;
return -1;
}
InitCaptureInfo();
InitPhotoOutput();
InitPreviewOutput();
InitVideoOutput();
g_captureSession->BeginConfig();
g_captureSession->AddInput(g_cameraInput);
g_captureSession->AddOutput(g_previewOutput);
g_captureSession->AddOutput(g_videoOutput);
g_captureSession->AddOutput(g_photoOutput);
g_captureSession->CommitConfig();
return 0;
}
int DCameraPreview(void)
{
g_captureSession->Start();
sleep(SLEEP_FIVE_SECOND);
((sptr<VideoOutput> &)g_videoOutput)->Start();
sleep(SLEEP_FIVE_SECOND);
std::string fileNameTest = "/data/log/dcamera_preview_test.yuv";
std::fstream _file;
_file.open(fileNameTest.c_str(), std::ios::in);
if (!_file) {
return -1;
}
return 0;
}
int DCameraPhoto(void)
{
rotationNum = -1;
qualityNum = -1;
ConfigFocusAndExposure();
sleep(SLEEP_FIVE_SECOND);
if (rotationNum == 1 || qualityNum == 1) {
return -1;
}
((sptr<PhotoOutput> &)g_photoOutput)->Capture(ConfigPhotoCaptureSetting());
sleep(SLEEP_TWENTY_SECOND);
std::string fileNamePhoto = "/data/log/dcamera_photo_test.jpg";
std::fstream _file;
_file.open(fileNamePhoto, std::ios::in);
if (!_file) {
return -1;
}
return 0;
}
int ReleaseDCamera(void)
{
((sptr<VideoOutput> &)g_videoOutput)->Stop();
sleep(SLEEP_FIVE_SECOND);
g_captureSession->Stop();
g_captureSession->Release();
g_cameraInput->Release();
std::string fileNamePhoto = "/data/log/dcamera_photo_test.jpg";
std::string fileNameTest = "/data/log/dcamera_preview_test.yuv";
(void)remove(fileNamePhoto.c_str());
(void)remove(fileNameTest.c_str());
DHLOGI("========== Distributed Camera Demo End ==========");
return 0;
}

View File

@ -0,0 +1,288 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* 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.
*/
#ifndef OHOS_DCAMERA_CLIENT_DEMO_H
#define OHOS_DCAMERA_CLIENT_DEMO_H
#include <fstream>
#include "anonymous_string.h"
#include "camera_device_ability_items.h"
#include "camera_info.h"
#include "camera_input.h"
#include "camera_manager.h"
#include "camera_metadata_operator.h"
#include "capture_input.h"
#include "capture_output.h"
#include "capture_session.h"
#include "dcamera_capture_info_cmd.h"
#include "dcamera_utils_tools.h"
#include "distributed_camera_constants.h"
#include "distributed_camera_errno.h"
#include "distributed_hardware_log.h"
#include "metadata_utils.h"
#include "photo_output.h"
#include "preview_output.h"
#include "surface.h"
#include "video_output.h"
namespace OHOS {
namespace DistributedHardware {
class DemoDCameraBufferConsumerListener : public IBufferConsumerListener {
public:
explicit DemoDCameraBufferConsumerListener(const sptr<Surface>& surface) : surface_(surface)
{
}
void OnBufferAvailable()
{
DHLOGI("DemoDCameraBufferConsumerListener::OnBufferAvailable");
if (surface_ == nullptr) {
DHLOGE("DemoDCameraBufferConsumerListener surface is null");
return;
}
int32_t flushFence = 0;
int64_t timestamp = 0;
OHOS::Rect damage;
OHOS::sptr<OHOS::SurfaceBuffer> buffer = nullptr;
surface_->AcquireBuffer(buffer, flushFence, timestamp, damage);
if (buffer == nullptr) {
DHLOGE("DemoDCameraBufferConsumerListener AcquireBuffer failed");
return;
}
width_ = buffer->GetWidth();
height_ = buffer->GetHeight();
size_ = buffer->GetSize();
address_ = static_cast<char *>(buffer->GetVirAddr());
buffer->GetExtraData()->ExtraGet("dataSize", dataSize_);
#ifdef PRODUCT_M40
actualSize_ = width_ * height_ * YUV_BYTES_PER_PIXEL / Y2UV_RATIO;
#else
actualSize_ = width_ * height_ * RGB_BYTES_PER_PIXEL;
#endif
SaveFile();
surface_->ReleaseBuffer(buffer, -1);
}
protected:
virtual void SaveFile() const = 0;
protected:
constexpr static int32_t Y2UV_RATIO = 2;
constexpr static int32_t YUV_BYTES_PER_PIXEL = 3;
constexpr static int32_t RGB_BYTES_PER_PIXEL = 4;
char *address_ = nullptr;
int32_t actualSize_ = 0;
int32_t dataSize_ = 0;
int32_t height_ = 0;
int32_t width_ = 0;
int32_t size_ = 0;
sptr<Surface> surface_;
};
class DemoDCameraPhotoSurfaceListener : public DemoDCameraBufferConsumerListener {
public:
explicit DemoDCameraPhotoSurfaceListener(const sptr<Surface>& surface)
: DemoDCameraBufferConsumerListener(surface)
{
}
protected:
void SaveFile() const override
{
DHLOGI("DemoDCameraPhotoSurfaceListener::SaveFile width: %d, height: %d, size: %d, dataSize: %d, " +
"actualSize: %d", width_, height_, size_, dataSize_, actualSize_);
if ((address_ == nullptr) || (dataSize_ <= 0)) {
DHLOGE("DemoDCameraPhotoSurfaceListener invalid params, dataSize: %d", dataSize_);
return;
}
std::ofstream ofs;
std::string fileName = "/data/log/dcamera_photo_test.jpg";
ofs.open(fileName, std::ios::binary | std::ios::out);
if (!ofs.is_open()) {
DHLOGE("DemoDCameraPhotoSurfaceListener open file failed");
return;
}
ofs.write(address_, dataSize_);
ofs.close();
}
};
class DemoDCameraPreviewSurfaceListener : public DemoDCameraBufferConsumerListener {
public:
explicit DemoDCameraPreviewSurfaceListener(const sptr<Surface>& surface)
: DemoDCameraBufferConsumerListener(surface)
{
}
protected:
void SaveFile() const override
{
DHLOGI("DemoDCameraPreviewSurfaceListener::SaveFile width: %d, height: %d, size: %d, dataSize: %d, " +
"actualSize: %d", width_, height_, size_, dataSize_, actualSize_);
if ((address_ == nullptr) || (actualSize_ <= 0)) {
DHLOGE("DemoDCameraPreviewSurfaceListener invalid params, actualSize: %d", actualSize_);
return;
}
std::ofstream ofs;
std::string fileName = "/data/log/dcamera_preview_test.yuv";
ofs.open(fileName, std::ios::binary | std::ios::out | std::ios::app);
if (!ofs.is_open()) {
DHLOGE("DemoDCameraPreviewSurfaceListener open file failed");
return;
}
ofs.write(address_, actualSize_);
ofs.close();
}
};
class DemoDCameraVideoSurfaceListener : public DemoDCameraBufferConsumerListener {
public:
explicit DemoDCameraVideoSurfaceListener(const sptr<Surface>& surface)
: DemoDCameraBufferConsumerListener(surface)
{
}
protected:
void SaveFile() const override
{
DHLOGI("DemoDCameraVideoSurfaceListener::SaveFile width: %d, height: %d, size: %d, dataSize: %d, " +
"actualSize: %d", width_, height_, size_, dataSize_, actualSize_);
if ((address_ == nullptr) || (actualSize_ <= 0)) {
DHLOGE("DemoDCameraVideoSurfaceListener invalid params, actualSize: %d", actualSize_);
return;
}
std::ofstream ofs;
std::string resolution = std::to_string(width_) + "_" + std::to_string(height_);
std::string fileName = "/data/log/dcamera_video_" + resolution + ".yuv";
ofs.open(fileName, std::ios::binary | std::ios::out | std::ios::app);
if (!ofs.is_open()) {
DHLOGE("DemoDCameraVideoSurfaceListener open file failed");
return;
}
ofs.write(address_, actualSize_);
ofs.close();
}
};
class DemoDCameraPhotoCallback : public CameraStandard::PhotoCallback {
public:
void OnCaptureStarted(const int32_t captureID) const
{
DHLOGI("DemoDCameraPhotoCallback::OnCaptureStarted captureID: %d", captureID);
}
void OnCaptureEnded(const int32_t captureID, int32_t frameCount) const
{
DHLOGI("DemoDCameraPhotoCallback::OnCaptureEnded captureID: %d frameCount: %d", captureID, frameCount);
}
void OnFrameShutter(const int32_t captureId, const uint64_t timestamp) const
{
DHLOGI("DemoDCameraPhotoCallback::OnFrameShutter captureID: %d timestamp: %llu", captureId, timestamp);
}
void OnCaptureError(const int32_t captureId, const int32_t errorCode) const
{
DHLOGI("DemoDCameraPhotoCallback::OnCaptureError captureID: %d errorCode: %d", captureId, errorCode);
}
};
class DemoDCameraPreviewCallback : public CameraStandard::PreviewCallback {
public:
void OnFrameStarted() const
{
DHLOGI("DemoDCameraPreviewCallback::OnFrameStarted.");
}
void OnFrameEnded(const int32_t frameCount) const
{
DHLOGI("DemoDCameraPreviewCallback::OnFrameEnded frameCount: %d", frameCount);
}
void OnError(const int32_t errorCode) const
{
DHLOGI("DemoDCameraPreviewCallback::OnError errorCode: %d", errorCode);
}
};
class DemoDCameraVideoCallback : public CameraStandard::VideoCallback {
public:
void OnFrameStarted() const
{
DHLOGI("DemoDCameraVideoCallback::OnFrameStarted.");
}
void OnFrameEnded(const int32_t frameCount) const
{
DHLOGI("DemoDCameraVideoCallback::OnFrameEnded frameCount: %d", frameCount);
}
void OnError(const int32_t errorCode) const
{
DHLOGI("DemoDCameraVideoCallback::OnError errorCode: %d", errorCode);
}
};
class DemoDCameraInputCallback : public CameraStandard::ErrorCallback, public CameraStandard::FocusCallback {
public:
void OnError(const int32_t errorType, const int32_t errorMsg) const
{
DHLOGI("DemoDCameraInputCallback::OnError errorType: %d errorMsg: %d", errorType, errorMsg);
}
void OnFocusState(FocusState state)
{
DHLOGI("DemoDCameraInputCallback::OnFocusState state: %d", state);
}
};
class DemoDCameraManagerCallback : public CameraStandard::CameraManagerCallback {
public:
void OnCameraStatusChanged(const CameraStandard::CameraStatusInfo &cameraStatusInfo) const
{
DHLOGI("DemoDCameraManagerCallback::OnCameraStatusChanged cameraStatus: %d", cameraStatusInfo.cameraStatus);
}
void OnFlashlightStatusChanged(const std::string &cameraID,
const CameraStandard::FlashlightStatus flashStatus) const
{
DHLOGI("DemoDCameraManagerCallback::OnFlashlightStatusChanged cameraID: %s, flashStatus: %d",
GetAnonyString(cameraID).c_str(), flashStatus);
}
};
class DemoDCameraSessionCallback : public CameraStandard::SessionCallback {
public:
void OnError(int32_t errorCode)
{
DHLOGI("DemoDCameraSessionCallback::OnError errorCode: %d", errorCode);
}
};
} // namespace DistributedHardware
} // namespace OHOS
int InitDCamera(void);
int DCameraPreview(void);
int DCameraPhoto(void);
int ReleaseDCamera(void);
#endif // OHOS_DCAMERA_CLIENT_DEMO_H

View File

@ -14,6 +14,7 @@
import("//test/xts/tools/build/suite.gni")
_all_test_packages = [
"${DCTS_ROOT}/distributedhardware:distributedcameratest",
"${DCTS_ROOT}/distributeddatamgr:distributeddatatest",
"${DCTS_ROOT}/communication:communication",
]