diff --git a/camera/hal/adapter/platform/v4l2/src/device_manager/sensor_controller.cpp b/camera/hal/adapter/platform/v4l2/src/device_manager/sensor_controller.cpp index 56db3b84381774bcb7365d1e24e7e397ea38ab5c..19e8f9496096df2b8e0c394737de91ed67cd1fc5 100644 --- a/camera/hal/adapter/platform/v4l2/src/device_manager/sensor_controller.cpp +++ b/camera/hal/adapter/platform/v4l2/src/device_manager/sensor_controller.cpp @@ -133,6 +133,7 @@ void SensorController::SetNodeCallBack(const NodeBufferCb cb) void SensorController::SetMetaDataCallBack(const MetaDataCb cb) { CAMERA_LOGI("SensorController line: %{public}d", __LINE__); + std::lock_guard lock(metaDataFlaglock_); metaDataCb_ = cb; } @@ -142,6 +143,12 @@ void SensorController::BufferCallback(std::shared_ptr buffer) CAMERA_LOGE("nodeBufferCb_ is nullptr"); return; } + + constexpr uint32_t UNIT_COUNT = 1000; + struct timeval tv; + gettimeofday(&tv, NULL); + int64_t timestamp = static_cast(tv.tv_sec) * UNIT_COUNT * UNIT_COUNT + tv.tv_usec; + buffer->buffer_->SetEsTimestamp(timestamp); nodeBufferCb_(buffer); const int ENTRY_CAPACITY = 30; // 30:entry capacity diff --git a/camera/hal/hdi_impl/src/stream_operator/stream_tunnel/standard/stream_tunnel.cpp b/camera/hal/hdi_impl/src/stream_operator/stream_tunnel/standard/stream_tunnel.cpp index f80ffca335f5a6ff8b808fbfd51fc62febea0eaf..ce9bef09d4384b514d67eac9f859d497c251a227 100644 --- a/camera/hal/hdi_impl/src/stream_operator/stream_tunnel/standard/stream_tunnel.cpp +++ b/camera/hal/hdi_impl/src/stream_operator/stream_tunnel/standard/stream_tunnel.cpp @@ -137,6 +137,8 @@ RetCode StreamTunnel::PutBuffer(const std::shared_ptr& buffer) extraData->ExtraSet(OHOS::Camera::dataSize, esInfo.size); extraData->ExtraSet(OHOS::Camera::isKeyFrame, esInfo.isKey); extraData->ExtraSet(OHOS::Camera::timeStamp, esInfo.timestamp); + extraData->ExtraSet(OHOS::Camera::streamId, buffer->GetStreamId()); + extraData->ExtraSet(OHOS::Camera::captureId, buffer->GetCaptureId()); } } bufferQueue_->FlushBuffer(sb, fence, flushConfig_); diff --git a/camera/hal/pipeline_core/ipp/src/ipp_node.cpp b/camera/hal/pipeline_core/ipp/src/ipp_node.cpp index 6c715706e1d0bc5f045fde52906e21c68e05e198..16537f313756bf136614b8353937a1b9a32d844b 100644 --- a/camera/hal/pipeline_core/ipp/src/ipp_node.cpp +++ b/camera/hal/pipeline_core/ipp/src/ipp_node.cpp @@ -21,7 +21,13 @@ IppNode::IppNode(const std::string& name, const std::string& type) { } -IppNode::~IppNode() {} +IppNode::~IppNode() +{ + GetDeviceController(); + sensorController_->SetMetaDataCallBack([this](const std::shared_ptr& metadata) { + CAMERA_LOGE("V4L2 ipp node already been destroyed!"); + }); +} RetCode IppNode::Init(const int32_t streamId) { @@ -61,8 +67,13 @@ RetCode IppNode::Flush(const int32_t streamId) return RC_OK; } - algoPlugin_->Flush(); - NodeBase::Flush(streamId); + if (algoPlugin_ == nullptr) { + CAMERA_LOGW("IppNode algoPlugin_ is null"); + return RC_ERROR; + } else { + algoPlugin_->Flush(); + NodeBase::Flush(streamId); + } return RC_OK; } @@ -83,7 +94,6 @@ void IppNode::OnMetadataChanged(const std::shared_ptr& metadata) CAMERA_LOGE("meta is nullptr"); return; } - CAMERA_LOGI("IppNode line: %{public}d", __LINE__); // device metadata changed callback GetNodeMetaData(metadata); if (metaDataCb_ == nullptr) { @@ -95,11 +105,6 @@ void IppNode::OnMetadataChanged(const std::shared_ptr& metadata) void IppNode::GetNodeMetaData(std::shared_ptr metadata) { - CAMERA_LOGI("IppNode line: %{public}d", __LINE__); - GetCameraFaceDetectSwitch(metadata); - GetCameraFaceRectangles(metadata); - GetCameraFaceIds(metadata); - GetTimestamp(metadata); GetFocusMode(metadata); GetFocusState(metadata); GetExposureMode(metadata); @@ -108,94 +113,44 @@ void IppNode::GetNodeMetaData(std::shared_ptr metadata) GetExposureState(metadata); } -void IppNode::GetCameraFaceDetectSwitch(std::shared_ptr meta) -{ - CAMERA_LOGI("IppNode line: %{public}d", __LINE__); - uint8_t faceDetectSwitch = OHOS_CAMERA_FACE_DETECT_MODE_SIMPLE; - meta->addEntry(OHOS_STATISTICS_FACE_DETECT_SWITCH, &faceDetectSwitch, sizeof(faceDetectSwitch)); -} - -void IppNode::GetCameraFaceIds(std::shared_ptr meta) -{ - CAMERA_LOGI("IppNode line: %{public}d", __LINE__); - std::vector vFaceIds; - vFaceIds.push_back(0); - meta->addEntry(OHOS_STATISTICS_FACE_IDS, - vFaceIds.data(), - vFaceIds.size()); -} - -void IppNode::GetTimestamp(std::shared_ptr meta) -{ - CAMERA_LOGI("IppNode line: %{public}d", __LINE__); - int64_t timestamp = 0; - struct timeval tv; - gettimeofday(&tv, NULL); - timestamp = static_cast(tv.tv_sec) * 1000 * 1000 + tv.tv_usec; // 1000:microsecond - meta->addEntry(OHOS_SENSOR_INFO_TIMESTAMP, ×tamp, sizeof(timestamp)); -} - -void IppNode::GetCameraFaceRectangles(std::shared_ptr meta) -{ - CAMERA_LOGI("IppNode line: %{public}d", __LINE__); - std::vector> vFaceRectangles; - std::vector vFaceRectangle; - int32_t faceRectangle = 1; - vFaceRectangle.push_back(faceRectangle); - vFaceRectangle.push_back(faceRectangle); - vFaceRectangle.push_back(faceRectangle); - vFaceRectangle.push_back(faceRectangle); - vFaceRectangles.push_back(vFaceRectangle); - meta->addEntry(OHOS_STATISTICS_FACE_RECTANGLES, - vFaceRectangles.data(), - vFaceRectangles.size()); -} - void IppNode::GetFocusMode(std::shared_ptr meta) { - CAMERA_LOGI("IppNode line: %{public}d", __LINE__); uint8_t focusMode = OHOS_CAMERA_FOCUS_MODE_LOCKED; meta->addEntry(OHOS_CONTROL_FOCUS_MODE, &focusMode, sizeof(focusMode)); } void IppNode::GetFocusState(std::shared_ptr meta) { - CAMERA_LOGI("IppNode line: %{public}d", __LINE__); uint8_t focusState = OHOS_CAMERA_FOCUS_STATE_UNFOCUSED; meta->addEntry(OHOS_CONTROL_FOCUS_STATE, &focusState, sizeof(focusState)); } void IppNode::GetExposureMode(std::shared_ptr meta) { - CAMERA_LOGI("IppNode line: %{public}d", __LINE__); uint8_t exposureMode = OHOS_CAMERA_EXPOSURE_MODE_AUTO; meta->addEntry(OHOS_CONTROL_EXPOSURE_MODE, &exposureMode, sizeof(exposureMode)); } void IppNode::GetExposureTime(std::shared_ptr meta) { - CAMERA_LOGI("IppNode line: %{public}d", __LINE__); int64_t exposureTime = 1; meta->addEntry(OHOS_SENSOR_EXPOSURE_TIME, &exposureTime, sizeof(exposureTime)); } void IppNode::GetExposureCompensation(std::shared_ptr meta) { - CAMERA_LOGI("IppNode line: %{public}d", __LINE__); int32_t exposureCompensation = 1; meta->addEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &exposureCompensation, sizeof(exposureCompensation)); } void IppNode::GetExposureState(std::shared_ptr meta) { - CAMERA_LOGI("IppNode line: %{public}d", __LINE__); uint8_t exposureState = OHOS_CAMERA_EXPOSURE_STATE_SCAN; meta->addEntry(OHOS_CONTROL_EXPOSURE_STATE, &exposureState, sizeof(exposureState)); } RetCode IppNode::GetDeviceController() { - CAMERA_LOGI("IppNode line: %{public}d", __LINE__); deviceManager_ = IDeviceManager::GetInstance(); if (deviceManager_ == nullptr) { CAMERA_LOGE("get device manager failed."); diff --git a/camera/hal/pipeline_core/nodes/src/fork_node/fork_node.cpp b/camera/hal/pipeline_core/nodes/src/fork_node/fork_node.cpp index 78f0608c7bf96ace8fcdee5c9d890370b024c52c..9f18222acb77497d451862c5fb2458714f2797be 100644 --- a/camera/hal/pipeline_core/nodes/src/fork_node/fork_node.cpp +++ b/camera/hal/pipeline_core/nodes/src/fork_node/fork_node.cpp @@ -192,6 +192,7 @@ RetCode ForkNode::CopyBuffer(uint64_t poolId, std::shared_ptr& buffer) tmpBuffer_->GetVirAddress(), tmpBuffer_->GetSize()) != 0) { CAMERA_LOGE("memcpy_s failed."); } + buffer->SetEsTimestamp(tmpBuffer_->GetEsFrameInfo().timestamp); return RC_OK; } diff --git a/camera/hal/test/v4l2/BUILD.gn b/camera/hal/test/v4l2/BUILD.gn index eb0b3756a006b7a798366311948cd77f2a65585c..36fba7bda31078a72f27023186bdde3caf9775df 100644 --- a/camera/hal/test/v4l2/BUILD.gn +++ b/camera/hal/test/v4l2/BUILD.gn @@ -127,6 +127,7 @@ if (defined(ohos_lite)) { testonly = true module_out_path = module_output_path sources = [ + "./src/hdfcamera_facedetect.cpp", "./src/open_camera_test.cpp", "./src/preview_test.cpp", "./src/stream_customer.cpp", @@ -144,7 +145,6 @@ if (defined(ohos_lite)) { "$camera_path/../interfaces/hdi_ipc/callback/host/include", "$camera_path/../interfaces/hdi_ipc/callback/device/include", "$camera_path/../interfaces/hdi_ipc/callback/operator/include", - "//foundation/graphic/graphic/frameworks/surface/include", "$camera_path/include", "$camera_path/hdi_impl", "$camera_path/hdi_impl/include", @@ -155,11 +155,6 @@ if (defined(ohos_lite)) { "$camera_path/hdi_impl/src/stream_operator/stream_tunnel/standard", "$camera_path/device_manager/include/", "$camera_path/device_manager/include/v4l2", - "//foundation/graphic/utils/interfaces/kits", - "//foundation/graphic/graphic/interfaces/kits", - "//foundation/graphic/graphic/interfaces/inner_api/surface", - "//foundation/graphic/graphic/interfaces/inner_api/common", - "//foundation/graphic/graphic/utils/buffer_handle/export", "//base/startup/syspara_lite/adapter/native/syspara/include", "$camera_path/utils/event", "//drivers/peripheral/camera/interfaces/metadata/include", diff --git a/camera/hal/test/v4l2/include/hdfcamera_facedetect.h b/camera/hal/test/v4l2/include/hdfcamera_facedetect.h new file mode 100644 index 0000000000000000000000000000000000000000..272912dfc867987bf2006cc4cc0bc59249a27248 --- /dev/null +++ b/camera/hal/test/v4l2/include/hdfcamera_facedetect.h @@ -0,0 +1,29 @@ +/* + * 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 HDF_CAMERA_FACE_DETECT_H +#define HDF_CAMERA_FACE_DETECT_H + +#include "test_display.h" + +class HdfCameraFaceDetect : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(void); + void TearDown(void); + std::shared_ptr display_ = nullptr; +}; +#endif /* HDF_CAMERA_FACE_DETECT_H */ \ No newline at end of file diff --git a/camera/hal/test/v4l2/include/test_display.h b/camera/hal/test/v4l2/include/test_display.h index bdced51a4caa61a453493397133ad6f9b4f6d367..fff59fd4745add1d988afa07f33de7925d81d602 100644 --- a/camera/hal/test/v4l2/include/test_display.h +++ b/camera/hal/test/v4l2/include/test_display.h @@ -73,6 +73,10 @@ #define PREVIEW_HEIGHT 480 #define CAPTURE_WIDTH 1280 #define CAPTURE_HEIGHT 960 +#define VIDEO_WIDTH 1280 +#define VIDEO_HEIGHT 960 +#define ANALYZE_WIDTH 640 +#define ANALYZE_HEIGHT 480 class TestDisplay { public: @@ -94,6 +98,7 @@ public: std::shared_ptr streamCustomerPreview_ = nullptr; std::shared_ptr streamCustomerCapture_ = nullptr; std::shared_ptr streamCustomerVideo_ = nullptr; + std::shared_ptr streamCustomerAnalyze_ = nullptr; OHOS::sptr streamOperator = nullptr; std::shared_ptr streamOperatorCallback = nullptr; std::shared_ptr captureInfo = nullptr; @@ -102,9 +107,7 @@ public: std::shared_ptr streamInfoPre = nullptr; std::shared_ptr streamInfoVideo = nullptr; std::shared_ptr streamInfoCapture = nullptr; - std::shared_ptr producer = nullptr; - std::shared_ptr producerCapture = nullptr; - std::shared_ptr producerVideo = nullptr; + std::shared_ptr streamInfoAnalyze = nullptr; OHOS::sptr cameraHost = nullptr; OHOS::sptr cameraDevice = nullptr; std::shared_ptr ability = nullptr; @@ -116,14 +119,17 @@ public: streamId_preview = 1000, // 1000:preview streamID streamId_capture, streamId_video, + streamId_analyze, captureId_preview = 2000, // 2000:preview captureId captureId_capture, - captureId_video + captureId_video, + captureId_analyze }; enum { preview_mode = 0, capture_mode, - video_mode + video_mode, + analyze_mode, }; OHOS::Camera::CamRetCode rc; int init_flag = 0; @@ -149,5 +155,10 @@ public: void StopStream(std::vector& captureIds, std::vector& streamIds); void StartCapture(int streamId, int captureId, bool shutterCallback, bool isStreaming); float calTime(struct timeval start, struct timeval end); + void StoreImage(const void *bufStart, const uint32_t size) const; + void StoreVideo(const void *bufStart, const uint32_t size) const; + void OpenVideoFile(); + void PrintFaceDetectInfo(const void *bufStart, const uint32_t size) const; + int videoFd_ = -1; }; #endif diff --git a/camera/hal/test/v4l2/src/hdfcamera_facedetect.cpp b/camera/hal/test/v4l2/src/hdfcamera_facedetect.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ecd72f257ba40c20f050114bb28d37b1705168c2 --- /dev/null +++ b/camera/hal/test/v4l2/src/hdfcamera_facedetect.cpp @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file expected 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 "hdfcamera_facedetect.h" + +using namespace testing::ext; + +void HdfCameraFaceDetect::SetUpTestCase(void) +{} +void HdfCameraFaceDetect::TearDownTestCase(void) +{} +void HdfCameraFaceDetect::SetUp(void) +{ + if (display_ == nullptr) { + display_ = std::make_shared(); + } + display_->Init(); +} +void HdfCameraFaceDetect::TearDown(void) +{ + display_->Close(); +} + +/** + * @tc.name: preview and capture and face detect + * @tc.desc: Commit 3 streams together, Preview , still_capture and analyze streams, isStreaming is true. + * @tc.level: Level0 + * @tc.size: MediumTest + * @tc.type: Function + */ +static HWTEST_F(HdfCameraFaceDetect, CameraFaceDetect_001, TestSize.Level1) +{ + // Get the stream manager + display_->AchieveStreamOperator(); + // start stream + display_->intents = {OHOS::Camera::PREVIEW, OHOS::Camera::STILL_CAPTURE, OHOS::Camera::ANALYZE}; + display_->StartStream(display_->intents); + // Get preview + display_->StartCapture(display_->streamId_preview, display_->captureId_preview, false, true); + display_->StartCapture(display_->streamId_analyze, display_->captureId_analyze, false, true); + + // add dumy exif info + constexpr double latitude = 27.987500; // dummy data: Qomolangma latitde + constexpr double longitude = 86.927500; // dummy data: Qomolangma longituude + constexpr double altitude = 8848.86; // dummy data: Qomolangma altitude + constexpr size_t entryCapacity = 100; + constexpr size_t dataCapacity = 2000; + std::shared_ptr captureSetting = + std::make_shared(entryCapacity, dataCapacity); + uint8_t captureQuality = OHOS_CAMERA_JPEG_LEVEL_HIGH; + int32_t captureOrientation = OHOS_CAMERA_JPEG_ROTATION_270; + uint8_t mirrorSwitch = OHOS_CAMERA_MIRROR_ON; + std::vector gps; + gps.push_back(latitude); + gps.push_back(longitude); + gps.push_back(altitude); + captureSetting->addEntry(OHOS_JPEG_QUALITY, static_cast(&captureQuality), + sizeof(captureQuality)); + captureSetting->addEntry(OHOS_JPEG_ORIENTATION, static_cast(&captureOrientation), + sizeof(captureOrientation)); + captureSetting->addEntry(OHOS_CONTROL_CAPTURE_MIRROR, static_cast(&mirrorSwitch), + sizeof(mirrorSwitch)); + captureSetting->addEntry(OHOS_JPEG_GPS_COORDINATES, gps.data(), gps.size()); + + std::shared_ptr captureInfo = std::make_shared(); + captureInfo->streamIds_ = {display_->streamId_capture}; + captureInfo->captureSetting_ = captureSetting; + captureInfo->enableShutterCallback_ = false; + display_->rc = display_->streamOperator->Capture(display_->captureId_capture, captureInfo, true); + EXPECT_EQ(true, display_->rc == OHOS::Camera::NO_ERROR); + if (display_->rc == OHOS::Camera::NO_ERROR) { + std::cout << "==========[test log]check Capture: Capture success, " << display_->captureId_capture << std::endl; + } else { + std::cout << "==========[test log]check Capture: Capture fail, rc = " << display_->rc + << display_->captureId_capture << std::endl; + } + display_->streamCustomerCapture_->ReceiveFrameOn([this](void* addr, const uint32_t size) { + display_->StoreImage(addr, size); + }); + sleep(2); + // release stream + display_->captureIds = {display_->captureId_preview, display_->captureId_capture, display_->captureId_analyze}; + display_->streamIds = {display_->streamId_preview, display_->streamId_capture, display_->streamId_analyze}; + display_->StopStream(display_->captureIds, display_->streamIds); +} + +/** + * @tc.name: preview and capture and face detect + * @tc.desc: Commit 2 streams together, Preview and analyze streams, isStreaming is true. + * @tc.level: Level0 + * @tc.size: MediumTest + * @tc.type: Function + */ +static HWTEST_F(HdfCameraFaceDetect, CameraFaceDetect_002, TestSize.Level1) +{ + // Get the stream manager + display_->AchieveStreamOperator(); + // start stream + display_->intents = {OHOS::Camera::PREVIEW, OHOS::Camera::ANALYZE}; + display_->StartStream(display_->intents); + // Get preview + display_->StartCapture(display_->streamId_preview, display_->captureId_preview, false, true); + display_->StartCapture(display_->streamId_analyze, display_->captureId_analyze, false, true); + sleep(2); + // release stream + display_->captureIds = {display_->captureId_preview, display_->captureId_analyze}; + display_->streamIds = {display_->streamId_preview, display_->streamId_analyze}; + display_->StopStream(display_->captureIds, display_->streamIds); +} \ No newline at end of file diff --git a/camera/hal/test/v4l2/src/stream_customer.cpp b/camera/hal/test/v4l2/src/stream_customer.cpp index c136b4101b50b0e3bf82af4d461adf5381a89642..648fb4b34a3f70318416a768608bd7f031649b47 100644 --- a/camera/hal/test/v4l2/src/stream_customer.cpp +++ b/camera/hal/test/v4l2/src/stream_customer.cpp @@ -22,20 +22,6 @@ StreamCustomer::~StreamCustomer() {} void StreamCustomer::CamFrame(const std::function callback) { CAMERA_LOGD("test:enter CamFrame thread ++ \n"); -#ifdef CAMERA_BUILT_ON_OHOS_LITE - do { - OHOS::SurfaceBuffer* buffer = consumer_->AcquireBuffer(); - if (buffer != nullptr) { - if (callback != nullptr) { - void* addr = buffer->GetVirAddr(); - int32_t size = 0; - buffer->GetInt32(VIDEO_KEY_INFO_DATA_SIZE, size); - callback(addr, size); - } - consumer_->ReleaseBuffer(buffer); - } - } while (camFrameExit_ == 0); -#else OHOS::Rect damage; int32_t flushFence = 0; int64_t timestamp = 0; @@ -52,35 +38,18 @@ void StreamCustomer::CamFrame(const std::function callbac 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); - CAMERA_LOGE("test:CamFrame callback +++++++ Size == %d frameNum = %d timestamp == %lld\n", - gotSize, frameNum, timestamp); - callback(addr, gotSize); + callback(addr, size); } consumer_->ReleaseBuffer(buff, -1); } usleep(delayTime); } while (camFrameExit_ == 0); -#endif CAMERA_LOGD("test:Exiting CamFrame thread -- \n"); } -#ifdef CAMERA_BUILT_ON_OHOS_LITE -std::shared_ptr StreamCustomer::CreateProducer() -#else OHOS::sptr StreamCustomer::CreateProducer() -#endif { -#ifdef CAMERA_BUILT_ON_OHOS_LITE - consumer_ = std::shared_ptr(OHOS::Surface::CreateSurface()); - if (consumer_ == nullptr) { - return nullptr; - } - return consumer_; -#else consumer_ = OHOS::Surface::CreateSurfaceAsConsumer(); if (consumer_ == nullptr) { return nullptr; @@ -95,7 +64,6 @@ OHOS::sptr StreamCustomer::CreateProducer() CAMERA_LOGI("test, create a buffer queue producer %{public}p", producer.GetRefPtr()); return producer; -#endif } OHOS::Camera::RetCode StreamCustomer::ReceiveFrameOn(const std::function callback) diff --git a/camera/hal/test/v4l2/src/test_display.cpp b/camera/hal/test/v4l2/src/test_display.cpp index 118e9b42ecf43625862ff1fd096ec3b3a3b33127..e251faeaff5f71d46083800d3cb357aef8d097a7 100644 --- a/camera/hal/test/v4l2/src/test_display.cpp +++ b/camera/hal/test/v4l2/src/test_display.cpp @@ -29,6 +29,125 @@ uint64_t TestDisplay::GetCurrentLocalTimeStamp() return tmp.count(); } +void TestDisplay::StoreImage(const void *bufStart, const uint32_t size) const +{ + constexpr uint32_t pathLen = 64; + char path[pathLen] = {0}; +#ifdef CAMERA_BUILT_ON_OHOS_LITE + char prefix[] = "/userdata/photo/"; +#else + char prefix[] = "/data/"; +#endif + + int imgFD = 0; + int ret = 0; + + struct timeval start = {}; + gettimeofday(&start, nullptr); + if (sprintf_s(path, sizeof(path), "%spicture_%ld.jpeg", prefix, start.tv_usec) < 0) { + CAMERA_LOGE("sprintf_s error .....\n"); + return; + } + + imgFD = open(path, O_RDWR | O_CREAT, 00766); // 00766:file operate permission + if (imgFD == -1) { + CAMERA_LOGE("demo test:open image file error %{public}s.....\n", strerror(errno)); + return; + } + + CAMERA_LOGD("demo test:StoreImage %{public}s buf_start == %{public}p size == %{public}d\n", path, bufStart, size); + + ret = write(imgFD, bufStart, size); + if (ret == -1) { + CAMERA_LOGE("demo test:write image file error %{public}s.....\n", strerror(errno)); + } + + close(imgFD); +} + +void TestDisplay::StoreVideo(const void *bufStart, const uint32_t size) const +{ + int ret = 0; + + ret = write(videoFd_, bufStart, size); + if (ret == -1) { + CAMERA_LOGE("demo test:write video file error %{public}s.....\n", strerror(errno)); + } + CAMERA_LOGD("demo test:StoreVideo buf_start == %{public}p size == %{public}d\n", bufStart, size); +} + +void TestDisplay::OpenVideoFile() +{ + constexpr uint32_t pathLen = 64; + char path[pathLen] = {0}; +#ifdef CAMERA_BUILT_ON_OHOS_LITE + char prefix[] = "/userdata/video/"; +#else + char prefix[] = "/data/"; +#endif + auto seconds = time(nullptr); + if (sprintf_s(path, sizeof(path), "%svideo%ld.h264", prefix, seconds) < 0) { + CAMERA_LOGE("%{public}s: sprintf failed", __func__); + return; + } + videoFd_ = open(path, O_RDWR | O_CREAT, 00766); // 00766:file operate permission + if (videoFd_ < 0) { + CAMERA_LOGE("demo test: StartVideo open %s %{public}s failed", path, strerror(errno)); + } +} + +void TestDisplay::PrintFaceDetectInfo(const void *bufStart, const uint32_t size) const +{ + common_metadata_header_t* data = static_cast((const_cast(bufStart))); + camera_metadata_item_t entry; + int ret = 0; + ret = FindCameraMetadataItem(data, OHOS_STATISTICS_FACE_DETECT_SWITCH, &entry); + if (ret != 0) { + CAMERA_LOGE("demo test: get OHOS_STATISTICS_FACE_DETECT_SWITCH error\n"); + return; + } + uint8_t switchValue = *(entry.data.u8); + CAMERA_LOGI("demo test: switchValue=%{public}d", switchValue); + + ret = FindCameraMetadataItem(data, OHOS_STATISTICS_FACE_RECTANGLES, &entry); + if (ret != 0) { + CAMERA_LOGE("demo test: get OHOS_STATISTICS_FACE_RECTANGLES error\n"); + return; + } + uint32_t rectCount = entry.count; + std::cout << "==========[test log] PrintFaceDetectInfo rectCount=" << rectCount << std::endl; + CAMERA_LOGI("demo test: rectCount=%{public}d", rectCount); + std::vector> faceRectangles; + std::vector faceRectangle; + for (int i = 0; i < rectCount; i++) { + faceRectangle.push_back(*(entry.data.f + i)); + } + faceRectangles.push_back(faceRectangle); + for (std::vector>::iterator it = faceRectangles.begin(); it < faceRectangles.end(); it++) { + for (std::vector::iterator innerIt = (*it).begin(); innerIt < (*it).end(); innerIt++) { + std::cout << "==========[test log] PrintFaceDetectInfo innerIt : " << *innerIt << std::endl; + CAMERA_LOGI("demo test: innerIt : %{public}f \n", *innerIt); + } + } + + ret = FindCameraMetadataItem(data, OHOS_STATISTICS_FACE_IDS, &entry); + if (ret != 0) { + CAMERA_LOGE("demo test: get OHOS_STATISTICS_FACE_IDS error\n"); + return; + } + uint32_t idCount = entry.count; + std::cout << "==========[test log] PrintFaceDetectInfo idCount=" << idCount << std::endl; + CAMERA_LOGI("demo test: idCount=%{public}d", idCount); + std::vector faceIds; + for (int i = 0; i < idCount; i++) { + faceIds.push_back(*(entry.data.i32 + i)); + } + for (auto it = faceIds.begin(); it != faceIds.end(); it++) { + std::cout << "==========[test log] PrintFaceDetectInfo faceIds : " << *it << std::endl; + CAMERA_LOGI("demo test: faceIds : %{public}d\n", *it); + } +} + int32_t TestDisplay::SaveYUV(char* type, unsigned char* buffer, int32_t size) { int ret; @@ -327,13 +446,11 @@ void TestDisplay::StartStream(std::vector intents) streamInfoPre = std::make_shared(); streamInfoCapture = std::make_shared(); streamInfoVideo = std::make_shared(); + streamInfoAnalyze = std::make_shared(); for (auto& intent : intents) { - if (intent == 0) { - streamCustomerPreview_ = std::make_shared(); - OHOS::sptr producer = streamCustomerPreview_->CreateProducer(); - producer->SetQueueSize(8); // 8:set bufferQueue size - if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size - std::cout << "~~~~~~~" << std::endl; + if (intent == OHOS::Camera::PREVIEW) { + if (streamCustomerPreview_ == nullptr) { + streamCustomerPreview_ = std::make_shared(); } streamInfoPre->streamId_ = streamId_preview; streamInfoPre->width_ = PREVIEW_WIDTH; // 640:picture width @@ -342,48 +459,61 @@ void TestDisplay::StartStream(std::vector intents) streamInfoPre->datasapce_ = 8; // 8:picture datasapce streamInfoPre->intent_ = intent; streamInfoPre->tunneledMode_ = 5; // 5:tunnel mode - streamInfoPre->bufferQueue_ = producer; + streamInfoPre->bufferQueue_ = streamCustomerPreview_->CreateProducer(); + streamInfoPre->bufferQueue_->SetQueueSize(8); // 8:set bufferQueue size std::cout << "==========[test log]preview success." << std::endl; std::vector>().swap(streamInfos); streamInfos.push_back(streamInfoPre); - } else if (intent == 1) { - streamCustomerVideo_ = std::make_shared(); - OHOS::sptr producerVideo = streamCustomerVideo_->CreateProducer(); - producerVideo->SetQueueSize(8); // 8:set bufferQueue size - if (producerVideo->GetQueueSize() != 8) { // 8:get bufferQueue size - std::cout << "~~~~~~~" << std::endl; + } else if (intent == OHOS::Camera::VIDEO) { + if (streamCustomerVideo_ == nullptr) { + streamCustomerVideo_ = std::make_shared(); } streamInfoVideo->streamId_ = streamId_video; - streamInfoVideo->width_ = CAPTURE_WIDTH; // 640:picture width - streamInfoVideo->height_ = CAPTURE_HEIGHT; // 480:picture height + streamInfoVideo->width_ = VIDEO_WIDTH; // 1280:picture width + streamInfoVideo->height_ = VIDEO_HEIGHT; // 960:picture height streamInfoVideo->format_ = PIXEL_FMT_RGBA_8888; streamInfoVideo->datasapce_ = 8; // 8:picture datasapce streamInfoVideo->intent_ = intent; streamInfoVideo->encodeType_ = OHOS::Camera::ENCODE_TYPE_H264; streamInfoVideo->tunneledMode_ = 5; // 5:tunnel mode - streamInfoVideo->bufferQueue_ = producerVideo; + streamInfoVideo->bufferQueue_ = streamCustomerVideo_->CreateProducer(); + streamInfoVideo->bufferQueue_->SetQueueSize(8); // 8:set bufferQueue size std::cout << "==========[test log]video success." << std::endl; std::vector>().swap(streamInfos); streamInfos.push_back(streamInfoVideo); - } else { - streamCustomerCapture_ = std::make_shared(); - OHOS::sptr producerCapture = streamCustomerCapture_->CreateProducer(); - producerCapture->SetQueueSize(8); // 8:set bufferQueue size - if (producerCapture->GetQueueSize() != 8) { // 8:get bufferQueue size - std::cout << "~~~~~~~" << std::endl; + } else if (intent == OHOS::Camera::STILL_CAPTURE) { + if (streamCustomerCapture_ == nullptr) { + streamCustomerCapture_ = std::make_shared(); } streamInfoCapture->streamId_ = streamId_capture; - streamInfoCapture->width_ = CAPTURE_WIDTH; // 640:picture width - streamInfoCapture->height_ = CAPTURE_HEIGHT; // 480:picture height + streamInfoCapture->width_ = CAPTURE_WIDTH; // 1280:picture width + streamInfoCapture->height_ = CAPTURE_HEIGHT; // 960:picture height streamInfoCapture->format_ = PIXEL_FMT_RGBA_8888; streamInfoCapture->datasapce_ = 8; // 8:picture datasapce streamInfoCapture->intent_ = intent; streamInfoCapture->encodeType_ = OHOS::Camera::ENCODE_TYPE_JPEG; streamInfoCapture->tunneledMode_ = 5; // 5:tunnel mode - streamInfoCapture->bufferQueue_ = producerCapture; + streamInfoCapture->bufferQueue_ = streamCustomerCapture_->CreateProducer(); + streamInfoCapture->bufferQueue_->SetQueueSize(8); // 8:set bufferQueue size std::cout << "==========[test log]capture success." << std::endl; std::vector>().swap(streamInfos); streamInfos.push_back(streamInfoCapture); + } else if (intent == OHOS::Camera::ANALYZE) { + if (streamCustomerAnalyze_ == nullptr) { + streamCustomerAnalyze_ = std::make_shared(); + } + streamInfoAnalyze->streamId_ = streamId_analyze; + streamInfoAnalyze->width_ = ANALYZE_WIDTH; // 640:picture width + streamInfoAnalyze->height_ = ANALYZE_HEIGHT; // 480:picture height + streamInfoAnalyze->format_ = PIXEL_FMT_RGBA_8888; + streamInfoAnalyze->datasapce_ = 8; // 8:picture datasapce + streamInfoAnalyze->intent_ = intent; + streamInfoAnalyze->tunneledMode_ = 5; // 5:tunnel mode + streamInfoAnalyze->bufferQueue_ = streamCustomerAnalyze_->CreateProducer(); + streamInfoAnalyze->bufferQueue_->SetQueueSize(8); // 8:set bufferQueue size + std::cout << "==========[test log]analyze success." << std::endl; + std::vector>().swap(streamInfos); + streamInfos.push_back(streamInfoAnalyze); } rc = streamOperator->CreateStreams(streamInfos); EXPECT_EQ(false, rc != OHOS::Camera::NO_ERROR); @@ -420,13 +550,16 @@ void TestDisplay::StartCapture(int streamId, int captureId, bool shutterCallback streamCustomerPreview_->ReceiveFrameOn(nullptr); } else if (captureId == captureId_capture) { streamCustomerCapture_->ReceiveFrameOn([this](void* addr, const uint32_t size) { - BufferCallback(addr, capture_mode); - return; + StoreImage(addr, size); }); } else if (captureId == captureId_video) { + OpenVideoFile(); streamCustomerVideo_->ReceiveFrameOn([this](void* addr, const uint32_t size) { - BufferCallback(addr, video_mode); - return; + StoreVideo(addr, size); + }); + } else if (captureId == captureId_analyze) { + streamCustomerAnalyze_->ReceiveFrameOn([this](void* addr, const uint32_t size) { + PrintFaceDetectInfo(addr, size); }); } sleep(2); // 2:sleep two second @@ -438,10 +571,14 @@ void TestDisplay::StopStream(std::vector& captureIds, std::vector& str for (auto &captureId : captureIds) { if (captureId == captureId_preview) { streamCustomerPreview_->ReceiveFrameOff(); - } else if (captureId == captureId_capture) { + } else if (captureId == captureId_capture) { streamCustomerCapture_->ReceiveFrameOff(); - } else if (captureId == captureId_video) { + } else if (captureId == captureId_video) { streamCustomerVideo_->ReceiveFrameOff(); + close(videoFd_); + videoFd_ = -1; + } else if (captureId == captureId_analyze) { + streamCustomerAnalyze_->ReceiveFrameOff(); } std::cout << "==========[test log]check Capture: CancelCapture success," << captureId << std::endl; rc = streamOperator->CancelCapture(captureId); diff --git a/camera/interfaces/include/video_key_info.h b/camera/interfaces/include/video_key_info.h index b3830d7573949d35d91ae56df65b2ecf97be29e5..7e9d2d1260b30d304ece36c14d77e981a9c451c0 100644 --- a/camera/interfaces/include/video_key_info.h +++ b/camera/interfaces/include/video_key_info.h @@ -51,10 +51,12 @@ const int32_t VIDEO_KEY_INFO_IS_KEY_FRAME = 0x03; * @brief Indicates the stream id corresponding to the image data. The value type is int32_t. */ const std::string streamId = "streamId"; +const int32_t VIDEO_KEY_STREAM_ID = 0x04; /** * @brief Indicates the capture id corresponding to the image data. The value type is int32_t. */ const std::string captureId = "captureId"; +const int32_t VIDEO_KEY_CAPTRUE_ID = 0x05; } // end namespace OHOS::Camera #endif