From ca41892abac38e06702874e53e260354aecda6c3 Mon Sep 17 00:00:00 2001 From: liuxiang Date: Tue, 9 Sep 2025 16:39:13 +0800 Subject: [PATCH] =?UTF-8?q?NativeRecorderUnitTest=20=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liuxiang --- .../recorder/server/media_library_adapter.cpp | 3 +- .../recorder/server/recorder_server.cpp | 2 +- .../capi/src/recorder_unit_test.cpp | 140 ++++++++++++++++++ 3 files changed, 143 insertions(+), 2 deletions(-) diff --git a/services/services/recorder/server/media_library_adapter.cpp b/services/services/recorder/server/media_library_adapter.cpp index 8d1b8c4ec..5048f2e1a 100644 --- a/services/services/recorder/server/media_library_adapter.cpp +++ b/services/services/recorder/server/media_library_adapter.cpp @@ -205,8 +205,9 @@ bool CreateMediaLibrary(int32_t &fd, std::string &uri) recorderPhotoProxy->SetDisplayName(CreateDisplayName()); photoAssetProxy->AddPhotoProxy((sptr&)recorderPhotoProxy); uri = photoAssetProxy->GetPhotoAssetUri(); - MEDIA_LOGD("video uri:%{public}s", uri.c_str()); + MEDIA_LOGI("video uri:%{public}s", uri.c_str()); fd = mediaLibraryManager->OpenAsset(uri, "rw"); + MEDIA_LOGI("video fd:%{public}d", fd); return true; } } // namespace MeidaLibraryAdapter diff --git a/services/services/recorder/server/recorder_server.cpp b/services/services/recorder/server/recorder_server.cpp index ee0c3d144..94241a3e6 100644 --- a/services/services/recorder/server/recorder_server.cpp +++ b/services/services/recorder/server/recorder_server.cpp @@ -725,7 +725,7 @@ int32_t RecorderServer::SetFileGenerationMode(FileGenerationMode mode) CHECK_AND_RETURN_RET_LOG(config_.withVideo, MSERR_INVALID_OPERATION, "Audio-only scenarios are not supported"); CHECK_AND_RETURN_RET_LOG(MeidaLibraryAdapter::CreateMediaLibrary(config_.url, config_.uri), MSERR_UNKNOWN, "get fd failed"); - MEDIA_LOGD("video Fd:%{public}d", config_.url); + MEDIA_LOGI("video Fd:%{public}d", config_.url); config_.fileGenerationMode = mode; OutFd outFileFd(config_.url); auto task = std::make_shared>([&, this] { diff --git a/test/unittest/recorder_test/capi/src/recorder_unit_test.cpp b/test/unittest/recorder_test/capi/src/recorder_unit_test.cpp index 62077fe86..f42ebf0fe 100644 --- a/test/unittest/recorder_test/capi/src/recorder_unit_test.cpp +++ b/test/unittest/recorder_test/capi/src/recorder_unit_test.cpp @@ -603,6 +603,55 @@ HWTEST_F(NativeRecorderUnitTest, Recorder_Prepare_007, TestSize.Level2) MEDIA_LOGI("NativeRecorderUnitTest Recorder_Prepare_007 out."); } +/** + * @tc.name: Recorder_Prepare_008 + * @tc.desc: Test recorder preparation process success situation + * @tc.type: FUNC + */ +HWTEST_F(NativeRecorderUnitTest, Recorder_Prepare_008, TestSize.Level2) +{ + MEDIA_LOGI("NativeRecorderUnitTest Recorder_Prepare_008 in."); + + OH_AVRecorder_Config config = config_; + config.url = strdup(""); + config.metadata.genre = strdup(""); + config.metadata.videoOrientation = nullptr; + config.metadata.customInfo.key = strdup("abc"); + config.metadata.customInfo.value = strdup("123"); + config.profile.audioBitrate = 96000; + config.profile.audioChannels = 2; + config.profile.audioCodec = OH_AVRecorder_CodecMimeType::AVRECORDER_AUDIO_AAC; + config.profile.audioSampleRate = 48000; + config.profile.fileFormat = OH_AVRecorder_ContainerFormatType::AVRECORDER_CFT_MPEG_4; + config.profile.videoBitrate = 2000000; + config.profile.videoCodec = OH_AVRecorder_CodecMimeType::AVRECORDER_VIDEO_AVC; + config.profile.videoFrameWidth = 1280; + config.profile.videoFrameHeight = 720; + config.profile.videoFrameRate = 30; + config.profile.isHdr = false; + config.profile.enableTemporalScale = false; + config.audioSourceType = OH_AVRecorder_AudioSourceType::AVRECORDER_MIC; + config.videoSourceType = OH_AVRecorder_VideoSourceType::AVRECORDER_SURFACE_YUV; + config.fileGenerationMode = OH_AVRecorder_FileGenerationMode::AVRECORDER_AUTO_CREATE_CAMERA_SCENE; + + int32_t ret = AV_ERR_OK; + ret = OH_AVRecorder_Prepare(recorder_, &config); + + #ifdef SUPPORT_RECORDER_CREATE_FILE + EXPECT_EQ(ret, AV_ERR_OK); + #else + EXPECT_EQ(ret, AV_ERR_INVALID_VAL); + #endif + + free(config.url); + free(config.metadata.genre); + free(config.metadata.videoOrientation); + free(config.metadata.customInfo.key); + free(config.metadata.customInfo.value); + + MEDIA_LOGI("NativeRecorderUnitTest Recorder_Prepare_008 out."); +} + /** * @tc.name: Recorder_Prepare_009 * @tc.desc: Test recorder preparation process success situation 2 @@ -950,6 +999,97 @@ HWTEST_F(NativeRecorderUnitTest, Recorder_UpdateRotation_002, TestSize.Level2) MEDIA_LOGI("NativeRecorderUnitTest Recorder_UpdateRotation_002 out."); } +/** + * @tc.name: Recorder_UpdateRotation_003 + * @tc.desc: Test recorder UpdateRotation process 003 + * @tc.type: FUNC + */ +HWTEST_F(NativeRecorderUnitTest, Recorder_UpdateRotation_003, TestSize.Level2) +{ + MEDIA_LOGI("NativeRecorderUnitTest Recorder_UpdateRotation_003 in."); + + OH_AVRecorder_Config config = config_; + config.url = strdup(""); + config.metadata.genre = strdup(""); + config.metadata.videoOrientation = strdup("0"); + config.metadata.customInfo.key = strdup(""); + config.metadata.customInfo.value = strdup(""); + config.fileGenerationMode = OH_AVRecorder_FileGenerationMode::AVRECORDER_AUTO_CREATE_CAMERA_SCENE; + + int32_t rotation = 90; + + int32_t ret = AV_ERR_OK; + + ret = OH_AVRecorder_Prepare(recorder_, &config); + #ifdef SUPPORT_RECORDER_CREATE_FILE + EXPECT_EQ(ret, AV_ERR_OK); + #else + EXPECT_EQ(ret, AV_ERR_INVALID_VAL); + #endif + ret = OH_AVRecorder_UpdateRotation(recorder_, rotation); + EXPECT_EQ(ret, AV_ERR_OK); + + + free(config.url); + free(config.metadata.genre); + free(config.metadata.videoOrientation); + free(config.metadata.customInfo.key); + free(config.metadata.customInfo.value); + + MEDIA_LOGI("NativeRecorderUnitTest Recorder_UpdateRotation_003 out."); +} + +/** + * @tc.name: Recorder_UpdateRotation_004 + * @tc.desc: Test recorder UpdateRotation process 004 + * @tc.type: FUNC + */ +HWTEST_F(NativeRecorderUnitTest, Recorder_UpdateRotation_004, TestSize.Level2) +{ + MEDIA_LOGI("NativeRecorderUnitTest Recorder_UpdateRotation_004 in."); + + OH_AVRecorder_Config config = config_; + config.url = strdup(""); + config.metadata.genre = strdup(""); + config.metadata.videoOrientation = strdup("0"); + config.metadata.customInfo.key = strdup(""); + config.metadata.customInfo.value = strdup(""); + config.fileGenerationMode = OH_AVRecorder_FileGenerationMode::AVRECORDER_AUTO_CREATE_CAMERA_SCENE; + + int32_t ret = AV_ERR_OK; + + ret = OH_AVRecorder_Prepare(recorder_, &config); + #ifdef SUPPORT_RECORDER_CREATE_FILE + EXPECT_EQ(ret, AV_ERR_OK); + #else + EXPECT_EQ(ret, AV_ERR_INVALID_VAL); + #endif + + int32_t rotation = 0; + ret = OH_AVRecorder_UpdateRotation(recorder_, rotation); + EXPECT_EQ(ret, AV_ERR_OK); + + rotation = 90; + ret = OH_AVRecorder_UpdateRotation(recorder_, rotation); + EXPECT_EQ(ret, AV_ERR_OK); + + rotation = 180; + ret = OH_AVRecorder_UpdateRotation(recorder_, rotation); + EXPECT_EQ(ret, AV_ERR_OK); + + rotation = 270; + ret = OH_AVRecorder_UpdateRotation(recorder_, rotation); + EXPECT_EQ(ret, AV_ERR_OK); + + free(config.url); + free(config.metadata.genre); + free(config.metadata.videoOrientation); + free(config.metadata.customInfo.key); + free(config.metadata.customInfo.value); + + MEDIA_LOGI("NativeRecorderUnitTest Recorder_UpdateRotation_004 out."); +} + /** * @tc.name: Recorder_Start_001 * @tc.desc: Test recorder start process 001 -- Gitee