From 3b437887605114fb103ab9d235b636820691d025 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 7 May 2025 17:41:58 +0800 Subject: [PATCH] fix SetOrientationHint function Signed-off-by: Steven --- .../capi/recorder/native_avrecorder.cpp | 8 +++++-- frameworks/native/recorder/recorder_impl.cpp | 14 +++++------- frameworks/native/recorder/recorder_impl.h | 4 ++-- interfaces/inner_api/native/recorder.h | 4 ++-- services/include/i_recorder_service.h | 4 ++-- .../recorder/client/recorder_client.cpp | 12 +++++----- .../recorder/client/recorder_client.h | 4 ++-- .../recorder/server/recorder_server.cpp | 22 +++++++++---------- .../recorder/server/recorder_server.h | 4 ++-- 9 files changed, 39 insertions(+), 37 deletions(-) diff --git a/frameworks/native/capi/recorder/native_avrecorder.cpp b/frameworks/native/capi/recorder/native_avrecorder.cpp index 195f91142..728f1517d 100644 --- a/frameworks/native/capi/recorder/native_avrecorder.cpp +++ b/frameworks/native/capi/recorder/native_avrecorder.cpp @@ -456,7 +456,10 @@ OH_AVErrCode Configure(OH_AVRecorder *recorder, OH_AVRecorder_Config *config) if (videoOrientation == -1) { // -1 invalid value return AV_ERR_INVALID_VAL; } - recorderObj->recorder_->SetOrientationHint(videoOrientation); + int32_t ret = recorderObj->recorder_->SetOrientationHint(videoOrientation); + if (ret != MSERR_OK) { + MEDIA_LOGI("SetOrientationHint failed!"); + } } if (config->maxDuration < 1) { @@ -631,7 +634,8 @@ OH_AVErrCode OH_AVRecorder_UpdateRotation(OH_AVRecorder *recorder, int32_t rotat CHECK_AND_RETURN_RET_LOG(recorderObj->recorder_ != nullptr, AV_ERR_INVALID_VAL, "recorder_ is null"); CHECK_AND_RETURN_RET_LOG(rotation == ROTATION_0 || rotation == ROTATION_90 || rotation == ROTATION_180 || rotation == ROTATION_270, AV_ERR_INVALID_VAL, "Invalid rotation value. Must be 0, 90, 180, or 270."); - recorderObj->recorder_->SetOrientationHint(rotation); + int32_t ret = recorderObj->recorder_->SetOrientationHint(rotation); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, AV_ERR_INVALID_VAL, "SetOrientationHint failed!"); MEDIA_LOGD("Native AVRecorder: OH_AVRecorder_UpdateRotation out."); return AV_ERR_OK; diff --git a/frameworks/native/recorder/recorder_impl.cpp b/frameworks/native/recorder/recorder_impl.cpp index 6fdad1a87..ac2f07638 100644 --- a/frameworks/native/recorder/recorder_impl.cpp +++ b/frameworks/native/recorder/recorder_impl.cpp @@ -282,21 +282,19 @@ int32_t RecorderImpl::SetMaxFileSize(int64_t size) return recorderService_->SetMaxFileSize(size); } -void RecorderImpl::SetLocation(float latitude, float longitude) +int32_t RecorderImpl::SetLocation(float latitude, float longitude) { MEDIA_LOGI("RecorderImpl:0x%{public}06" PRIXPTR " SetLocation in", FAKE_POINTER(this)); - CHECK_AND_RETURN_LOG(recorderService_ != nullptr, "recorder service does not exist.."); - recorderService_->SetLocation(latitude, longitude); - return; + CHECK_AND_RETURN_RET_LOG(recorderService_ != nullptr, MSERR_INVALID_OPERATION, "recorder service does not exist.."); + return recorderService_->SetLocation(latitude, longitude); } -void RecorderImpl::SetOrientationHint(int32_t rotation) +int32_t RecorderImpl::SetOrientationHint(int32_t rotation) { MEDIA_LOGI("RecorderImpl:0x%{public}06" PRIXPTR " SetOrientationHint in, rotation is %{public}d", FAKE_POINTER(this), rotation); - CHECK_AND_RETURN_LOG(recorderService_ != nullptr, "recorder service does not exist.."); - recorderService_->SetOrientationHint(rotation); - return; + CHECK_AND_RETURN_RET_LOG(recorderService_ != nullptr, MSERR_INVALID_OPERATION, "recorder service does not exist.."); + return recorderService_->SetOrientationHint(rotation); } int32_t RecorderImpl::SetRecorderCallback(const std::shared_ptr &callback) diff --git a/frameworks/native/recorder/recorder_impl.h b/frameworks/native/recorder/recorder_impl.h index 1b8792ede..20074bb3e 100644 --- a/frameworks/native/recorder/recorder_impl.h +++ b/frameworks/native/recorder/recorder_impl.h @@ -56,8 +56,8 @@ public: int32_t SetFileGenerationMode(FileGenerationMode mode) override; int32_t SetNextOutputFile(int32_t fd) override; int32_t SetMaxFileSize(int64_t size) override; - void SetLocation(float latitude, float longitude) override; - void SetOrientationHint(int32_t rotation) override; + int32_t SetLocation(float latitude, float longitude) override; + int32_t SetOrientationHint(int32_t rotation) override; int32_t SetRecorderCallback(const std::shared_ptr &callback) override; int32_t Prepare() override; int32_t Start() override; diff --git a/interfaces/inner_api/native/recorder.h b/interfaces/inner_api/native/recorder.h index 11cd175cf..4546d4104 100644 --- a/interfaces/inner_api/native/recorder.h +++ b/interfaces/inner_api/native/recorder.h @@ -851,7 +851,7 @@ public: * @since openharmony 3.1 * @version 1.0 */ - virtual void SetLocation(float latitude, float longitude) = 0; + virtual int32_t SetLocation(float latitude, float longitude) = 0; /** * @brief set the orientation hint in output file, and for the file to playback. mp4 support. @@ -861,7 +861,7 @@ public: * @since openharmony 3.1 * @version 1.0 */ - virtual void SetOrientationHint(int32_t rotation) = 0; + virtual int32_t SetOrientationHint(int32_t rotation) = 0; /** * @brief Registers a recording listener. diff --git a/services/include/i_recorder_service.h b/services/include/i_recorder_service.h index b458c95ad..90557fd96 100644 --- a/services/include/i_recorder_service.h +++ b/services/include/i_recorder_service.h @@ -439,7 +439,7 @@ public: * @since openharmony 3.1 * @version 1.0 */ - virtual void SetLocation(float latitude, float longitude) = 0; + virtual int32_t SetLocation(float latitude, float longitude) = 0; /** * @brief set the orientation hint in output file, and for the file to playback. mp4 support. @@ -449,7 +449,7 @@ public: * @since openharmony 3.1 * @version 1.0 */ - virtual void SetOrientationHint(int32_t rotation) = 0; + virtual int32_t SetOrientationHint(int32_t rotation) = 0; /** * @brief Registers a recording listener. diff --git a/services/services/recorder/client/recorder_client.cpp b/services/services/recorder/client/recorder_client.cpp index e61a4a581..76bbc1811 100644 --- a/services/services/recorder/client/recorder_client.cpp +++ b/services/services/recorder/client/recorder_client.cpp @@ -358,21 +358,21 @@ int32_t RecorderClient::SetMaxFileSize(int64_t size) return recorderProxy_->SetMaxFileSize(size); } -void RecorderClient::SetLocation(float latitude, float longitude) +int32_t RecorderClient::SetLocation(float latitude, float longitude) { std::lock_guard lock(mutex_); - CHECK_AND_RETURN_LOG(recorderProxy_ != nullptr, "recorder service does not exist."); + CHECK_AND_RETURN_RET_LOG(recorderProxy_ != nullptr, MSERR_NO_MEMORY, "recorder service does not exist."); - recorderProxy_->SetLocation(latitude, longitude); + return recorderProxy_->SetLocation(latitude, longitude); } -void RecorderClient::SetOrientationHint(int32_t rotation) +int32_t RecorderClient::SetOrientationHint(int32_t rotation) { std::lock_guard lock(mutex_); - CHECK_AND_RETURN_LOG(recorderProxy_ != nullptr, "recorder service does not exist."); + CHECK_AND_RETURN_RET_LOG(recorderProxy_ != nullptr, MSERR_NO_MEMORY, "recorder service does not exist."); MEDIA_LOGD ("SetLocation orientation hint: %{public}d", rotation); - recorderProxy_->SetOrientationHint(rotation); + return recorderProxy_->SetOrientationHint(rotation); } int32_t RecorderClient::SetRecorderCallback(const std::shared_ptr &callback) diff --git a/services/services/recorder/client/recorder_client.h b/services/services/recorder/client/recorder_client.h index bd3a86768..81cf03315 100644 --- a/services/services/recorder/client/recorder_client.h +++ b/services/services/recorder/client/recorder_client.h @@ -60,8 +60,8 @@ public: int32_t SetFileGenerationMode(FileGenerationMode mode) override; int32_t SetNextOutputFile(int32_t fd) override; int32_t SetMaxFileSize(int64_t size) override; - void SetLocation(float latitude, float longitude) override; - void SetOrientationHint(int32_t rotation) override; + int32_t SetLocation(float latitude, float longitude) override; + int32_t SetOrientationHint(int32_t rotation) override; int32_t SetRecorderCallback(const std::shared_ptr &callback) override; int32_t Prepare() override; int32_t Start() override; diff --git a/services/services/recorder/server/recorder_server.cpp b/services/services/recorder/server/recorder_server.cpp index 06f64fb9c..e119bbdde 100644 --- a/services/services/recorder/server/recorder_server.cpp +++ b/services/services/recorder/server/recorder_server.cpp @@ -754,14 +754,14 @@ int32_t RecorderServer::SetMaxFileSize(int64_t size) return result.Value(); } -void RecorderServer::SetLocation(float latitude, float longitude) +int32_t RecorderServer::SetLocation(float latitude, float longitude) { MEDIA_LOGI("RecorderServer:0x%{public}06" PRIXPTR " SetLocation in", FAKE_POINTER(this)); std::lock_guard lock(mutex_); if (status_ != REC_CONFIGURED) { - return; + return MSERR_INVALID_OPERATION; } - CHECK_AND_RETURN_LOG(recorderEngine_ != nullptr, "engine is nullptr"); + CHECK_AND_RETURN_RET_LOG(recorderEngine_ != nullptr, MSERR_NO_MEMORY, "engine is nullptr"); config_.latitude = latitude; config_.longitude = longitude; config_.withLocation = true; @@ -770,28 +770,28 @@ void RecorderServer::SetLocation(float latitude, float longitude) return recorderEngine_->Configure(DUMMY_SOURCE_ID, geoLocation); }); int32_t ret = taskQue_.EnqueueTask(task); - CHECK_AND_RETURN_LOG(ret == MSERR_OK, "EnqueueTask failed"); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "EnqueueTask failed"); - (void)task->GetResult(); - return; + auto result = task->GetResult(); + return result.Value(); } -void RecorderServer::SetOrientationHint(int32_t rotation) +int32_t RecorderServer::SetOrientationHint(int32_t rotation) { MEDIA_LOGI("RecorderServer:0x%{public}06" PRIXPTR " SetOrientationHint in, rotation: %{public}d", FAKE_POINTER(this), rotation); std::lock_guard lock(mutex_); - CHECK_AND_RETURN_LOG(recorderEngine_ != nullptr, "engine is nullptr"); + CHECK_AND_RETURN_RET_LOG(recorderEngine_ != nullptr, MSERR_NO_MEMORY, "engine is nullptr"); config_.rotation = rotation; RotationAngle rotationAngle(rotation); auto task = std::make_shared>([&, this] { return recorderEngine_->Configure(DUMMY_SOURCE_ID, rotationAngle); }); int32_t ret = taskQue_.EnqueueTask(task); - CHECK_AND_RETURN_LOG(ret == MSERR_OK, "EnqueueTask failed"); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "EnqueueTask failed"); - (void)task->GetResult(); - return; + auto result = task->GetResult(); + return result.Value(); } int32_t RecorderServer::SetRecorderCallback(const std::shared_ptr &callback) diff --git a/services/services/recorder/server/recorder_server.h b/services/services/recorder/server/recorder_server.h index 424ad99ce..ec94cf046 100644 --- a/services/services/recorder/server/recorder_server.h +++ b/services/services/recorder/server/recorder_server.h @@ -99,8 +99,8 @@ public: int32_t SetFileGenerationMode(FileGenerationMode mode) override; int32_t SetNextOutputFile(int32_t fd) override; int32_t SetMaxFileSize(int64_t size) override; - void SetLocation(float latitude, float longitude) override; - void SetOrientationHint(int32_t rotation) override; + int32_t SetLocation(float latitude, float longitude) override; + int32_t SetOrientationHint(int32_t rotation) override; int32_t SetRecorderCallback(const std::shared_ptr &callback) override; int32_t Prepare() override; int32_t Start() override; -- Gitee