diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 39c9baa811611367f759a128ac707b401dad9044..0000000000000000000000000000000000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "files.associations": { - "chrono": "cpp", - "filesystem": "cpp", - "format": "cpp", - "regex": "cpp", - "thread": "cpp", - "vector": "cpp" - } -} \ No newline at end of file diff --git a/frameworks/cj/avrecorder/BUILD.gn b/frameworks/cj/avrecorder/BUILD.gn index cba3e35f59181b3b1dce79c5e44e146700f782e0..51df1fccd7973c73cd77fc3a965dbf42d0500f30 100644 --- a/frameworks/cj/avrecorder/BUILD.gn +++ b/frameworks/cj/avrecorder/BUILD.gn @@ -59,6 +59,7 @@ ohos_shared_library("cj_media_avrecorder_ffi") { "eventhandler:libeventhandler", "hilog:libhilog", "hisysevent:libhisysevent", + "hitrace:hitrace_meter", "image_framework:image", "image_framework:image_native", "ipc:ipc_core", diff --git a/frameworks/cj/avtranscoder/include/cj_avtranscoder.h b/frameworks/cj/avtranscoder/include/cj_avtranscoder.h index 28183d2f2bc2aa105ed61537764153748fc37116..aaefdc72eebf52661e296cff07ebd1c13f71c3d6 100644 --- a/frameworks/cj/avtranscoder/include/cj_avtranscoder.h +++ b/frameworks/cj/avtranscoder/include/cj_avtranscoder.h @@ -30,8 +30,7 @@ constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_PLAYER, "CJA namespace OHOS { namespace Media { -struct EnumClassHash -{ +struct EnumClassHash { template std::size_t operator()(T t) const { diff --git a/frameworks/cj/avtranscoder/src/cj_avtranscoder.cpp b/frameworks/cj/avtranscoder/src/cj_avtranscoder.cpp index 14fcd6feb5e80c00b241420c922e54a0dbfad58a..7b734cd76a397e6fee3edbf53ced7b6e4c753c89 100644 --- a/frameworks/cj/avtranscoder/src/cj_avtranscoder.cpp +++ b/frameworks/cj/avtranscoder/src/cj_avtranscoder.cpp @@ -179,7 +179,7 @@ int32_t CJAVTranscoder::GetConfig(const CAVTransCoderConfig &cconfig, CjAVTransC void CJAVTranscoder::StateCallback(CjAVTransCoderState state) { - if (STATE2CSTR.find(state) != STATE2CSTR.end()){ + if (STATE2CSTR.find(state) != STATE2CSTR.end()) { MEDIA_LOGI("Change state to %{public}s", STATE2CSTR.at(state)); } else { MEDIA_LOGW("state %{public}d is not in STATE2CSTR", static_cast(state)); diff --git a/frameworks/cj/avtranscoder/src/cj_avtranscoder_callback.cpp b/frameworks/cj/avtranscoder/src/cj_avtranscoder_callback.cpp index c4d3c95e84c810733c2963b50a031f850ca35ed4..20607af7c3219f4d9ac8de10345ab519b9666517 100644 --- a/frameworks/cj/avtranscoder/src/cj_avtranscoder_callback.cpp +++ b/frameworks/cj/avtranscoder/src/cj_avtranscoder_callback.cpp @@ -57,7 +57,7 @@ void CJAVTranscoderCallback::SaveCallbackReference(CJAVTranscoderEvent event, in }; } - if (EVENT2CSTR.find(event) != EVENT2CSTR.end()){ + if (EVENT2CSTR.find(event) != EVENT2CSTR.end()) { MEDIA_LOGI("Set callback type: %{public}s", EVENT2CSTR.at(event)); } else { MEDIA_LOGW("event %{public}d is not in EVENT2CSTR", static_cast(event)); @@ -75,7 +75,7 @@ void CJAVTranscoderCallback::CancelCallbackReference(CJAVTranscoderEvent event) onerrorfunc = nullptr; } - if (EVENT2CSTR.find(event) != EVENT2CSTR.end()){ + if (EVENT2CSTR.find(event) != EVENT2CSTR.end()) { MEDIA_LOGI("Cancel callback type: %{public}s", EVENT2CSTR.at(event)); } else { MEDIA_LOGW("event %{public}d is not in EVENT2CSTR", static_cast(event)); @@ -135,8 +135,9 @@ CjAVTransCoderState CJAVTranscoderCallback::GetState() void CJAVTranscoderCallback::OnError(int32_t errCode, const std::string &errorMsg) { - MEDIA_LOGE("CJAVTranscoderCallback::OnError: %{public}d, %{public}s", errCode, errorMsg.c_str()); - SendErrorCallback(errCode, errorMsg); + MediaServiceExtErrCodeAPI9 exErr = MSErrorToExtErrorAPI9(static_cast(errCode)); + MEDIA_LOGE("CJAVTranscoderCallback::OnError: %{public}d, %{public}s", exErr, errorMsg.c_str()); + SendErrorCallback(exErr, errorMsg); SendStateCallback(CjAVTransCoderState::STATE_ERROR, StateChangeReason::BACKGROUND); } diff --git a/frameworks/js/audio_haptic/BUILD.gn b/frameworks/js/audio_haptic/BUILD.gn index d029212c6e774e9c31b368f9d1145d614608ad60..3926aa29f4b43378f72b074253a494ba3a916f3d 100644 --- a/frameworks/js/audio_haptic/BUILD.gn +++ b/frameworks/js/audio_haptic/BUILD.gn @@ -37,6 +37,7 @@ ohos_shared_library("audiohaptic_napi") { sources = [ "./src/audio_haptic_common_napi.cpp", + "./src/audio_haptic_file_descriptor_napi.cpp", "./src/audio_haptic_manager_napi.cpp", "./src/audio_haptic_player/audio_haptic_player_callback_napi.cpp", "./src/audio_haptic_player/audio_haptic_player_napi.cpp", @@ -46,6 +47,8 @@ ohos_shared_library("audiohaptic_napi") { deps = [ "./../../native/audio_haptic:audio_haptic" ] external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", "audio_framework:audio_client", "c_utils:utils", "hilog:libhilog", diff --git a/frameworks/js/audio_haptic/include/audio_haptic_common_napi.h b/frameworks/js/audio_haptic/include/audio_haptic_common_napi.h index 026cf9a92b6c6b42447bd8b1306c0551a78ae264..6eef0e71e034d57950020950a9a6795097966d4b 100644 --- a/frameworks/js/audio_haptic/include/audio_haptic_common_napi.h +++ b/frameworks/js/audio_haptic/include/audio_haptic_common_napi.h @@ -28,6 +28,26 @@ const int32_t NAPI_ERR_OPERATE_NOT_ALLOWED = 5400102; const int32_t NAPI_ERR_IO_ERROR = 5400103; const int32_t NAPI_ERR_SERVICE_DIED = 5400105; const int32_t NAPI_ERR_UNSUPPORTED_FORMAT = 5400106; +const int32_t NAPI_ERR_PARAM_OUT_OF_RANGE = 5400108; +const int32_t NAPI_ERR_PERMISSION_DENIED = 202; + +const std::string NAPI_ERR_PERMISSION_DENIED_INFO = "Caller is not a system application"; + +/* Constants for array index */ +const int32_t PARAM0 = 0; +const int32_t PARAM1 = 1; + +/* Constants for array size */ +const int32_t ARGS_ZERO = 0; +const int32_t ARGS_ONE = 1; +const int32_t ARGS_TWO = 2; + +struct AsyncContext { + napi_async_work work; + napi_deferred deferred = nullptr; + napi_value argv[ARGS_TWO] = {0}; + void* objectInfo = nullptr; +}; class AudioHapticCommonNapi { public: @@ -37,6 +57,13 @@ public: static void ThrowError(napi_env env, int32_t code, const std::string &errMessage); static std::string GetMessageByCode(int32_t &code); static std::string GetStringArgument(napi_env env, napi_value value); + static void PromiseReject(napi_env env, napi_deferred deferred, + const int32_t &errCode, const std::string &errMessage); + static bool InitPromiseFunc(napi_env env, napi_callback_info info, + AsyncContext* asyncContext, napi_value* promise, size_t paramLength); + static bool VerifySelfSystemPermission(); + static bool InitNormalFunc(napi_env env, napi_callback_info info, + void **native, napi_value *argv, size_t paramLength); }; struct AutoRef { diff --git a/frameworks/js/audio_haptic/include/audio_haptic_file_descriptor_napi.h b/frameworks/js/audio_haptic/include/audio_haptic_file_descriptor_napi.h new file mode 100644 index 0000000000000000000000000000000000000000..568f368b5bbe7cf9ae8518b91ee4c3b420181be3 --- /dev/null +++ b/frameworks/js/audio_haptic/include/audio_haptic_file_descriptor_napi.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 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 AUDIO_HAPTIC_FILE_DESCRIPTOR_NAPI_H +#define AUDIO_HAPTIC_FILE_DESCRIPTOR_NAPI_H + +#include "napi/native_api.h" +#include "napi/native_node_api.h" + +namespace OHOS { +namespace Media { +static const std::string AUDIO_HAPTIC_FILE_DESCRIPTOR_NAPI_CLASS_NAME = "AudioHapticFileDescriptor"; + +class AudioHapticFileDescriptorNapi { +public: + AudioHapticFileDescriptorNapi(); + ~AudioHapticFileDescriptorNapi(); + + static napi_value Init(napi_env env, napi_value exports); + static napi_value CreateAudioHapticFileDescriptorWrapper(napi_env env, + int32_t fd, int64_t length, int64_t offset); +private: + static void Destructor(napi_env env, void *nativeObject, void *finalize_hint); + static napi_value Construct(napi_env env, napi_callback_info info); + static napi_value GetFd(napi_env env, napi_callback_info info); + static napi_value SetFd(napi_env env, napi_callback_info info); + static napi_value GetLength(napi_env env, napi_callback_info info); + static napi_value SetLength(napi_env env, napi_callback_info info); + static napi_value GetOffset(napi_env env, napi_callback_info info); + static napi_value SetOffset(napi_env env, napi_callback_info info); + + static thread_local napi_ref sConstructor_; + + static int32_t sFd_; + static int64_t sLength_; + static int64_t sOffset_; + + int32_t fd_ = 0; + int64_t length_ = 0; + int64_t offset_ = 0; + napi_env env_; +}; +} +} +#endif // AUDIO_HAPTIC_FILE_DESCRIPTOR_NAPI_H \ No newline at end of file diff --git a/frameworks/js/audio_haptic/include/audio_haptic_manager_napi.h b/frameworks/js/audio_haptic/include/audio_haptic_manager_napi.h index 4733bdbceef87ed7ebf921bcda00a17a3c1e7fc4..adea2abf78eab3cbe7ff958a6b55f9228cbd2ab2 100644 --- a/frameworks/js/audio_haptic/include/audio_haptic_manager_napi.h +++ b/frameworks/js/audio_haptic/include/audio_haptic_manager_napi.h @@ -41,6 +41,12 @@ static const std::map audioHapticTypeMap = { {"AUDIO_HAPTIC_TYPE_HAPTIC", AUDIO_HAPTIC_TYPE_HAPTIC} }; +struct RegisterFromFdContext : public AsyncContext { + AudioHapticFileDescriptor audioFd; + AudioHapticFileDescriptor hapticFd; + int32_t sourceID; +}; + class AudioHapticManagerNapi { public: static napi_value Init(napi_env env, napi_value exports); @@ -58,6 +64,8 @@ private: static napi_value RegisterSource(napi_env env, napi_callback_info info); static void AsyncRegisterSource(napi_env env, void *data); + static napi_value RegisterSourceFromFd(napi_env env, napi_callback_info info); + static void AsyncRegisterSourceFromFd(napi_env env, void *data); static napi_value UnregisterSource(napi_env env, napi_callback_info info); static napi_value SetAudioLatencyMode(napi_env env, napi_callback_info info); static napi_value SetStreamUsage(napi_env env, napi_callback_info info); @@ -65,11 +73,14 @@ private: static void AsyncCreatePlayer(napi_env env, void *data); static void RegisterSourceAsyncCallbackComp(napi_env env, napi_status status, void *data); + static void RegisterSourceFromFdAsyncCallbackComp(napi_env env, napi_status status, void *data); static void UnregisterSourceAsyncCallbackComp(napi_env env, napi_status status, void *data); static void CreatePlayerAsyncCallbackComp(napi_env env, napi_status status, void *data); static bool IsLegalAudioLatencyMode(int32_t latencyMode); static bool IsLegalAudioStreamUsage(int32_t streamUsage); + static int32_t GetAudioHapticFileDescriptorValue(napi_env env, napi_value object, + AudioHapticFileDescriptor& audioHapticFd); static thread_local napi_ref sConstructor_; static thread_local napi_ref sAudioLatencyMode_; diff --git a/frameworks/js/audio_haptic/include/audio_haptic_player/audio_haptic_player_napi.h b/frameworks/js/audio_haptic/include/audio_haptic_player/audio_haptic_player_napi.h index cc0bf3b9e5dfffaa8c56d7ceb325cb2981fb867e..6e1d2cc78bd1f64a12cbeb17d92f2c43f7e6b0d4 100644 --- a/frameworks/js/audio_haptic/include/audio_haptic_player/audio_haptic_player_napi.h +++ b/frameworks/js/audio_haptic/include/audio_haptic_player/audio_haptic_player_napi.h @@ -32,6 +32,16 @@ namespace OHOS { namespace Media { static const std::string AUDIO_HAPTIC_PLAYER_NAPI_CLASS_NAME = "AudioHapticPlayer"; +struct VolumeContext : public AsyncContext { + float volume = 1.0f; + int32_t result = 0; +}; + +struct VibrationContext : public AsyncContext { + float intensity = 1.0f; + int32_t result = 0; +}; + class AudioHapticPlayerNapi { public: static napi_value Init(napi_env env, napi_value exports); @@ -49,6 +59,10 @@ private: static napi_value Release(napi_env env, napi_callback_info info); static napi_value On(napi_env env, napi_callback_info info); static napi_value Off(napi_env env, napi_callback_info info); + static napi_value SetVolume(napi_env env, napi_callback_info info); + static napi_value SetHapticsIntensity(napi_env env, napi_callback_info info); + static napi_value EnableHapticsInSilentMode(napi_env env, napi_callback_info info); + static napi_value IsHapticsIntensityAdjustmentSupported(napi_env env, napi_callback_info info); static napi_value RegisterCallback(napi_env env, napi_value jsThis, napi_value* argv, const std::string& cbName); static napi_value RegisterAudioHapticPlayerCallback(napi_env env, napi_value* argv, const std::string& cbName, @@ -60,6 +74,9 @@ private: static void CommonAsyncCallbackComp(napi_env env, napi_status status, void *data); static bool IsLegalAudioHapticType(int32_t audioHapticType); + static bool IsLegalVolumeOrIntensity(double volume); + static bool JudgeVolume(napi_env env, std::unique_ptr& asyncContext); + static bool JudgeIntensity(napi_env env, std::unique_ptr& asyncContext); napi_env env_; std::shared_ptr audioHapticPlayer_; diff --git a/frameworks/js/audio_haptic/src/audio_haptic_common_napi.cpp b/frameworks/js/audio_haptic/src/audio_haptic_common_napi.cpp index 173472fe29a086cf8a51dbdfcf3da515394ef67a..4b28a3b3241d572232539865601e1a5fbb49fb03 100644 --- a/frameworks/js/audio_haptic/src/audio_haptic_common_napi.cpp +++ b/frameworks/js/audio_haptic/src/audio_haptic_common_napi.cpp @@ -15,6 +15,11 @@ #include "audio_haptic_common_napi.h" +#include "access_token.h" +#include "accesstoken_kit.h" +#include "ipc_skeleton.h" +#include "tokenid_kit.h" + #include "audio_haptic_log.h" namespace { @@ -40,6 +45,86 @@ void AudioHapticCommonNapi::ThrowError(napi_env env, int32_t code, const std::st napi_throw_error(env, (std::to_string(code)).c_str(), errMessage.c_str()); } +void AudioHapticCommonNapi::PromiseReject(napi_env env, napi_deferred deferred, + const int32_t& errCode, const std::string& errMessage) +{ + napi_value error = nullptr; + napi_value message = nullptr; + napi_value code = nullptr; + napi_create_string_utf8(env, (std::to_string(errCode)).c_str(), NAPI_AUTO_LENGTH, &code); + napi_create_string_utf8(env, errMessage.c_str(), NAPI_AUTO_LENGTH, &message); + napi_create_error(env, code, message, &error); + napi_reject_deferred(env, deferred, error); +} + +bool AudioHapticCommonNapi::InitNormalFunc(napi_env env, napi_callback_info info, + void** native, napi_value* argv, size_t paramLength) +{ + napi_value thisVar = nullptr; + size_t argc = paramLength; + napi_status status = napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); + if (status != napi_ok || thisVar == nullptr) { + MEDIA_LOGE("napi_get_cb_info fail"); + AudioHapticCommonNapi::ThrowError(env, NAPI_ERR_SERVICE_DIED, "napi_get_cb_info fail"); + return false; + } + + if (argc != paramLength) { + MEDIA_LOGE("invalid parameters"); + std::string logMsg = "requires " + std::to_string(paramLength) + " parameters"; + AudioHapticCommonNapi::ThrowError(env, NAPI_ERR_INPUT_INVALID, logMsg); + return false; + } + + status = napi_unwrap(env, thisVar, native); + if (status != napi_ok || *native == nullptr) { + MEDIA_LOGE("Failed to unwrap object"); + AudioHapticCommonNapi::ThrowError(env, NAPI_ERR_OPERATE_NOT_ALLOWED, "Failed to unwrap object"); + return false; + } + return true; +} + +bool AudioHapticCommonNapi::InitPromiseFunc(napi_env env, napi_callback_info info, + AsyncContext* asyncContext, napi_value* promise, size_t paramLength) +{ + if (asyncContext == nullptr) { + AudioHapticCommonNapi::ThrowError(env, NAPI_ERR_SERVICE_DIED, "error create promise"); + return false; + } + napi_create_promise(env, &asyncContext->deferred, promise); + napi_value thisVar = nullptr; + size_t argc = paramLength; + napi_status status = napi_get_cb_info(env, info, &argc, asyncContext->argv, &thisVar, nullptr); + if (status != napi_ok || thisVar == nullptr) { + MEDIA_LOGE("napi_get_cb_info fail"); + AudioHapticCommonNapi::PromiseReject(env, asyncContext->deferred, + NAPI_ERR_SERVICE_DIED, "napi_get_cb_info fail"); + return false; + } + + if (argc != paramLength) { + MEDIA_LOGE("invalid parameters"); + std::string logMsg = "requires " + std::to_string(paramLength) + " parameters"; + AudioHapticCommonNapi::ThrowError(env, NAPI_ERR_INPUT_INVALID, logMsg); + return false; + } + status = napi_unwrap(env, thisVar, &asyncContext->objectInfo); + if (status != napi_ok) { + MEDIA_LOGE("Failed to unwrap object"); + AudioHapticCommonNapi::PromiseReject(env, asyncContext->deferred, + NAPI_ERR_SERVICE_DIED, "Failed to unwrap object"); + return false; + } + return true; +} + +bool AudioHapticCommonNapi::VerifySelfSystemPermission() +{ + Security::AccessToken::FullTokenID selfTokenID = IPCSkeleton::GetSelfTokenID(); + return Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(selfTokenID); +} + std::string AudioHapticCommonNapi::GetMessageByCode(int32_t &code) { std::string errMessage; diff --git a/frameworks/js/audio_haptic/src/audio_haptic_file_descriptor_napi.cpp b/frameworks/js/audio_haptic/src/audio_haptic_file_descriptor_napi.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e0ded095d3bf2f4a4d4a922f849fc2526815ef25 --- /dev/null +++ b/frameworks/js/audio_haptic/src/audio_haptic_file_descriptor_napi.cpp @@ -0,0 +1,314 @@ +/* + * Copyright (c) 2025 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 "audio_haptic_file_descriptor_napi.h" +#include "audio_haptic_log.h" + +using namespace std; + +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_AUDIO_NAPI, "AudioHapticFileDescriptorNapi"}; +} + +namespace OHOS { +namespace Media { +thread_local napi_ref AudioHapticFileDescriptorNapi::sConstructor_ = nullptr; + +int32_t AudioHapticFileDescriptorNapi::sFd_ = 0; +int64_t AudioHapticFileDescriptorNapi::sLength_ = 0; +int64_t AudioHapticFileDescriptorNapi::sOffset_ = 0; + +AudioHapticFileDescriptorNapi::AudioHapticFileDescriptorNapi() : env_(nullptr) +{ +} + +AudioHapticFileDescriptorNapi::~AudioHapticFileDescriptorNapi() = default; + +void AudioHapticFileDescriptorNapi::Destructor(napi_env env, void *nativeObject, void *finalize_hint) +{ + if (nativeObject != nullptr) { + auto obj = static_cast(nativeObject); + delete obj; + obj = nullptr; + } +} + +napi_value AudioHapticFileDescriptorNapi::Init(napi_env env, napi_value exports) +{ + napi_status status; + napi_value constructor; + napi_value result = nullptr; + napi_get_undefined(env, &result); + + napi_property_descriptor audio_haptic_file_descriptor_properties[] = { + DECLARE_NAPI_GETTER_SETTER("fd", GetFd, SetFd), + DECLARE_NAPI_GETTER_SETTER("length", GetLength, SetLength), + DECLARE_NAPI_GETTER_SETTER("offset", GetOffset, SetOffset) + }; + + status = napi_define_class(env, AUDIO_HAPTIC_FILE_DESCRIPTOR_NAPI_CLASS_NAME.c_str(), NAPI_AUTO_LENGTH, Construct, + nullptr, sizeof(audio_haptic_file_descriptor_properties) / sizeof(audio_haptic_file_descriptor_properties[0]), + audio_haptic_file_descriptor_properties, &constructor); + if (status != napi_ok) { + return result; + } + + status = napi_create_reference(env, constructor, 1, &sConstructor_); + if (status == napi_ok) { + status = napi_set_named_property(env, exports, + AUDIO_HAPTIC_FILE_DESCRIPTOR_NAPI_CLASS_NAME.c_str(), constructor); + if (status == napi_ok) { + return exports; + } + } + MEDIA_LOGE("Failure in AudioHapticFileDescriptorNapi::Init()"); + + return result; +} + +napi_value AudioHapticFileDescriptorNapi::Construct(napi_env env, napi_callback_info info) +{ + napi_status status; + napi_value jsThis = nullptr; + size_t argCount = 0; + + status = napi_get_cb_info(env, info, &argCount, nullptr, &jsThis, nullptr); + if (status == napi_ok) { + unique_ptr obj = make_unique(); + if (obj != nullptr) { + obj->env_ = env; + obj->fd_ = sFd_; + obj->length_ = sLength_; + obj->offset_ = sOffset_; + status = napi_wrap(env, jsThis, static_cast(obj.get()), + AudioHapticFileDescriptorNapi::Destructor, nullptr, nullptr); + if (status == napi_ok) { + obj.release(); + return jsThis; + } + } + } + + MEDIA_LOGE("Failed in AudioHapticFileDescriptorNapi::Construct()!"); + napi_get_undefined(env, &jsThis); + + return jsThis; +} + +napi_value AudioHapticFileDescriptorNapi::CreateAudioHapticFileDescriptorWrapper(napi_env env, + int32_t fd, int64_t length, int64_t offset) +{ + napi_status status; + napi_value result = nullptr; + napi_value constructor; + + status = napi_get_reference_value(env, sConstructor_, &constructor); + if (status == napi_ok) { + sFd_ = fd; + sLength_ = length; + sOffset_ = offset; + status = napi_new_instance(env, constructor, 0, nullptr, &result); + if (status == napi_ok) { + return result; + } + } + MEDIA_LOGE("Failed in CreateAudioHapticFileDescriptorWrapper, %{public}d", status); + + napi_get_undefined(env, &result); + + return result; +} + +napi_value AudioHapticFileDescriptorNapi::GetFd(napi_env env, napi_callback_info info) +{ + napi_status status; + AudioHapticFileDescriptorNapi *audioHapticFileDescriptorNapi = nullptr; + size_t argc = 0; + napi_value jsThis = nullptr; + napi_value jsResult = nullptr; + napi_get_undefined(env, &jsResult); + + status = napi_get_cb_info(env, info, &argc, nullptr, &jsThis, nullptr); + if (status != napi_ok || jsThis == nullptr) { + MEDIA_LOGE("GetFd: failed for napi_get_cb_info"); + return jsResult; + } + + status = napi_unwrap(env, jsThis, (void **)&audioHapticFileDescriptorNapi); + if (status == napi_ok && audioHapticFileDescriptorNapi != nullptr) { + status = napi_create_int32(env, audioHapticFileDescriptorNapi->fd_, &jsResult); + if (status == napi_ok) { + return jsResult; + } + } + + return jsResult; +} + +napi_value AudioHapticFileDescriptorNapi::SetFd(napi_env env, napi_callback_info info) +{ + napi_status status; + AudioHapticFileDescriptorNapi *audioHapticFileDescriptorNapi = nullptr; + size_t argc = 1; + napi_value args[1] = { nullptr }; + napi_value jsThis = nullptr; + int32_t fd = 0; + napi_value jsResult = nullptr; + napi_get_undefined(env, &jsResult); + + status = napi_get_cb_info(env, info, &argc, args, &jsThis, nullptr); + if (status != napi_ok || jsThis == nullptr || args[0] == nullptr) { + MEDIA_LOGE("SetFd: failed for napi_get_cb_info"); + return jsResult; + } + + status = napi_unwrap(env, jsThis, (void **)&audioHapticFileDescriptorNapi); + if (status == napi_ok && audioHapticFileDescriptorNapi != nullptr) { + napi_valuetype valueType = napi_undefined; + if (napi_typeof(env, args[0], &valueType) != napi_ok || valueType != napi_number) { + MEDIA_LOGE("SetFd: failed for wrong data type"); + return jsResult; + } + } + + status = napi_get_value_int32(env, args[0], &fd); + if (status == napi_ok) { + audioHapticFileDescriptorNapi->fd_ = fd; + } + + return jsResult; +} + +napi_value AudioHapticFileDescriptorNapi::GetLength(napi_env env, napi_callback_info info) +{ + napi_status status; + AudioHapticFileDescriptorNapi *audioHapticFileDescriptorNapi = nullptr; + size_t argc = 0; + napi_value jsThis = nullptr; + napi_value jsResult = nullptr; + napi_get_undefined(env, &jsResult); + + status = napi_get_cb_info(env, info, &argc, nullptr, &jsThis, nullptr); + if (status != napi_ok || jsThis == nullptr) { + MEDIA_LOGE("GetLength: failed for napi_get_cb_info"); + return jsResult; + } + + status = napi_unwrap(env, jsThis, (void **)&audioHapticFileDescriptorNapi); + if (status == napi_ok && audioHapticFileDescriptorNapi != nullptr) { + status = napi_create_int64(env, audioHapticFileDescriptorNapi->length_, &jsResult); + if (status == napi_ok) { + return jsResult; + } + } + + return jsResult; +} + +napi_value AudioHapticFileDescriptorNapi::SetLength(napi_env env, napi_callback_info info) +{ + napi_status status; + AudioHapticFileDescriptorNapi *audioHapticFileDescriptorNapi = nullptr; + size_t argc = 1; + napi_value args[1] = { nullptr }; + napi_value jsThis = nullptr; + int64_t length = 0; + napi_value jsResult = nullptr; + napi_get_undefined(env, &jsResult); + + status = napi_get_cb_info(env, info, &argc, args, &jsThis, nullptr); + if (status != napi_ok || jsThis == nullptr || args[0] == nullptr) { + MEDIA_LOGE("SetLength: failed for napi_get_cb_info"); + return jsResult; + } + + status = napi_unwrap(env, jsThis, (void **)&audioHapticFileDescriptorNapi); + if (status == napi_ok && audioHapticFileDescriptorNapi != nullptr) { + napi_valuetype valueType = napi_undefined; + if (napi_typeof(env, args[0], &valueType) != napi_ok || valueType != napi_number) { + MEDIA_LOGE("SetLength: failed for wrong data type"); + return jsResult; + } + } + + status = napi_get_value_int64(env, args[0], &length); + if (status == napi_ok) { + audioHapticFileDescriptorNapi->length_ = length; + } + + return jsResult; +} + +napi_value AudioHapticFileDescriptorNapi::GetOffset(napi_env env, napi_callback_info info) +{ + napi_status status; + AudioHapticFileDescriptorNapi *audioHapticFileDescriptorNapi = nullptr; + size_t argc = 0; + napi_value jsThis = nullptr; + napi_value jsResult = nullptr; + napi_get_undefined(env, &jsResult); + + status = napi_get_cb_info(env, info, &argc, nullptr, &jsThis, nullptr); + if (status != napi_ok || jsThis == nullptr) { + MEDIA_LOGE("GetOffset: failed for napi_get_cb_info"); + return jsResult; + } + + status = napi_unwrap(env, jsThis, (void **)&audioHapticFileDescriptorNapi); + if (status == napi_ok && audioHapticFileDescriptorNapi != nullptr) { + status = napi_create_int64(env, audioHapticFileDescriptorNapi->offset_, &jsResult); + if (status == napi_ok) { + return jsResult; + } + } + + return jsResult; +} + +napi_value AudioHapticFileDescriptorNapi::SetOffset(napi_env env, napi_callback_info info) +{ + napi_status status; + AudioHapticFileDescriptorNapi *audioHapticFileDescriptorNapi = nullptr; + size_t argc = 1; + napi_value args[1] = { nullptr }; + napi_value jsThis = nullptr; + int64_t offset = 0; + napi_value jsResult = nullptr; + napi_get_undefined(env, &jsResult); + + status = napi_get_cb_info(env, info, &argc, args, &jsThis, nullptr); + if (status != napi_ok || jsThis == nullptr || args[0] == nullptr) { + MEDIA_LOGE("SetOffset: failed for napi_get_cb_info"); + return jsResult; + } + + status = napi_unwrap(env, jsThis, (void **)&audioHapticFileDescriptorNapi); + if (status == napi_ok && audioHapticFileDescriptorNapi != nullptr) { + napi_valuetype valueType = napi_undefined; + if (napi_typeof(env, args[0], &valueType) != napi_ok || valueType != napi_number) { + MEDIA_LOGE("SetOffset: failed for wrong data type"); + return jsResult; + } + } + + status = napi_get_value_int64(env, args[0], &offset); + if (status == napi_ok) { + audioHapticFileDescriptorNapi->offset_ = offset; + } + + return jsResult; +} +} // namespace Media +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/js/audio_haptic/src/audio_haptic_manager_napi.cpp b/frameworks/js/audio_haptic/src/audio_haptic_manager_napi.cpp index 8c25a9f18faa678bd362996596e16b4ebda26680..adb1c145cfaf979ebdfb3fc7ab2c3a3e41757c5d 100644 --- a/frameworks/js/audio_haptic/src/audio_haptic_manager_napi.cpp +++ b/frameworks/js/audio_haptic/src/audio_haptic_manager_napi.cpp @@ -15,18 +15,12 @@ #include "audio_haptic_manager_napi.h" +#include "audio_haptic_file_descriptor_napi.h" #include "audio_haptic_player_napi.h" #include "audio_haptic_log.h" namespace { -/* Constants for array index */ -const int32_t PARAM0 = 0; -const int32_t PARAM1 = 1; - -/* Constants for array size */ -const int32_t ARGS_ONE = 1; -const int32_t ARGS_TWO = 2; const int32_t SIZE = 1024; const int ERROR = -1; @@ -126,6 +120,7 @@ napi_value AudioHapticManagerNapi::Init(napi_env env, napi_value exports) napi_property_descriptor audioHapticMgrProp[] = { DECLARE_NAPI_FUNCTION("registerSource", RegisterSource), + DECLARE_NAPI_FUNCTION("registerSourceFromFd", RegisterSourceFromFd), DECLARE_NAPI_FUNCTION("unregisterSource", UnregisterSource), DECLARE_NAPI_FUNCTION("setAudioLatencyMode", SetAudioLatencyMode), DECLARE_NAPI_FUNCTION("setStreamUsage", SetStreamUsage), @@ -214,6 +209,111 @@ napi_value AudioHapticManagerNapi::GetAudioHapticManager(napi_env env, napi_call return result; } +napi_value AudioHapticManagerNapi::RegisterSourceFromFd(napi_env env, napi_callback_info info) +{ + std::unique_ptr asyncContext = std::make_unique(); + napi_value promise = nullptr; + if (!AudioHapticCommonNapi::InitPromiseFunc(env, info, asyncContext.get(), &promise, ARGS_TWO)) { + return promise; + } + + if (!AudioHapticCommonNapi::VerifySelfSystemPermission()) { + AudioHapticCommonNapi::PromiseReject(env, asyncContext->deferred, + NAPI_ERR_PERMISSION_DENIED, NAPI_ERR_PERMISSION_DENIED_INFO); + return promise; + } + + AudioHapticFileDescriptor audioFd; + if (GetAudioHapticFileDescriptorValue(env, asyncContext->argv[PARAM0], audioFd) != SUCCESS) { + AudioHapticCommonNapi::ThrowError(env, NAPI_ERR_INPUT_INVALID, "Invalid first parameter"); + return promise; + } + asyncContext->audioFd = audioFd; + + AudioHapticFileDescriptor hapticFd; + if (GetAudioHapticFileDescriptorValue(env, asyncContext->argv[PARAM1], hapticFd) != SUCCESS) { + AudioHapticCommonNapi::ThrowError(env, NAPI_ERR_INPUT_INVALID, "Invalid second parameter"); + return promise; + } + asyncContext->hapticFd = hapticFd; + + napi_value funcName = nullptr; + napi_create_string_utf8(env, "RegisterSourceFromFd", NAPI_AUTO_LENGTH, &funcName); + napi_status status = napi_create_async_work( + env, + nullptr, + funcName, + AsyncRegisterSourceFromFd, + RegisterSourceFromFdAsyncCallbackComp, + static_cast(asyncContext.get()), + &asyncContext->work); + if (status != napi_ok) { + MEDIA_LOGE("Failed to get create async work"); + AudioHapticCommonNapi::PromiseReject(env, asyncContext->deferred, + status, "Failed to get create async work"); + } else { + napi_queue_async_work(env, asyncContext->work); + asyncContext.release(); + } + + return promise; +} + +void AudioHapticManagerNapi::AsyncRegisterSourceFromFd(napi_env env, void *data) +{ + RegisterFromFdContext *context = static_cast(data); + AudioHapticManagerNapi* object = reinterpret_cast(context->objectInfo); + if (context->audioFd.fd == -1 || context->hapticFd.fd == -1) { + context->sourceID = ERROR; + } else { + context->sourceID = object->audioHapticMgrClient_-> + RegisterSourceFromFd(context->audioFd, context->hapticFd); + } +} + +void AudioHapticManagerNapi::RegisterSourceFromFdAsyncCallbackComp(napi_env env, napi_status status, void *data) +{ + RegisterFromFdContext *context = static_cast(data); + napi_value result = nullptr; + + if (context->deferred) { + if (context->sourceID > ERROR) { + napi_create_int32(env, context->sourceID, &result); + napi_resolve_deferred(env, context->deferred, result); + } else { + AudioHapticCommonNapi::PromiseReject(env, context->deferred, + context->sourceID, "RegisterSourceFromFd Error: Operation is not supported or failed"); + } + } + napi_delete_async_work(env, context->work); + + delete context; + context = nullptr; +} + +int32_t AudioHapticManagerNapi::GetAudioHapticFileDescriptorValue(napi_env env, napi_value object, + AudioHapticFileDescriptor& audioHapticFd) +{ + napi_value property = nullptr; + napi_valuetype valueType = napi_undefined; + napi_typeof(env, object, &valueType); + CHECK_AND_RETURN_RET_LOG(valueType == napi_object, ERROR, "type mismatch"); + + auto status = napi_get_named_property(env, object, "fd", &property); + CHECK_AND_RETURN_RET_LOG(status == napi_ok, ERROR, "No property: fd"); + status = napi_get_value_int32(env, property, &(audioHapticFd.fd)); + CHECK_AND_RETURN_RET_LOG(status == napi_ok, ERROR, "Invalid value: fd"); + if (napi_get_named_property(env, object, "length", &property) == napi_ok) { + status = napi_get_value_int64(env, property, &(audioHapticFd.length)); + CHECK_AND_RETURN_RET_LOG(status == napi_ok, ERROR, "Invalid value: length"); + } + if (napi_get_named_property(env, object, "offset", &property) == napi_ok) { + status = napi_get_value_int64(env, property, &(audioHapticFd.offset)); + CHECK_AND_RETURN_RET_LOG(status == napi_ok, ERROR, "Invalid value: offset"); + } + return SUCCESS; +} + napi_value AudioHapticManagerNapi::RegisterSource(napi_env env, napi_callback_info info) { napi_value result = nullptr; diff --git a/frameworks/js/audio_haptic/src/audio_haptic_player/audio_haptic_player_napi.cpp b/frameworks/js/audio_haptic/src/audio_haptic_player/audio_haptic_player_napi.cpp index 7622892b57b62e49d9185a034c7fdec4c97d9238..df6f44bf3f550cb7d2aee97109dc72ef76e5b267 100644 --- a/frameworks/js/audio_haptic/src/audio_haptic_player/audio_haptic_player_napi.cpp +++ b/frameworks/js/audio_haptic/src/audio_haptic_player/audio_haptic_player_napi.cpp @@ -18,16 +18,10 @@ #include "audio_haptic_log.h" namespace { -/* Constants for array index */ -const int32_t PARAM0 = 0; -const int32_t PARAM1 = 1; - -/* Constants for array size */ -const int32_t ARGS_ONE = 1; -const int32_t ARGS_TWO = 2; const std::string AUDIO_INTERRUPT_CALLBACK_NAME = "audioInterrupt"; const std::string END_OF_STREAM_CALLBACK_NAME = "endOfStream"; +const double PRECISION = 100.00; constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_AUDIO_NAPI, "AudioHapticPlayerNapi"}; } @@ -54,6 +48,10 @@ napi_value AudioHapticPlayerNapi::Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("release", Release), DECLARE_NAPI_FUNCTION("on", On), DECLARE_NAPI_FUNCTION("off", Off), + DECLARE_NAPI_FUNCTION("setVolume", SetVolume), + DECLARE_NAPI_FUNCTION("setHapticsIntensity", SetHapticsIntensity), + DECLARE_NAPI_FUNCTION("enableHapticsInSilentMode", EnableHapticsInSilentMode), + DECLARE_NAPI_FUNCTION("isHapticsIntensityAdjustmentSupported", IsHapticsIntensityAdjustmentSupported), }; status = napi_define_class(env, AUDIO_HAPTIC_PLAYER_NAPI_CLASS_NAME.c_str(), NAPI_AUTO_LENGTH, Constructor, @@ -141,6 +139,72 @@ napi_value AudioHapticPlayerNapi::CreatePlayerInstance(napi_env env, return result; } +napi_value AudioHapticPlayerNapi::IsHapticsIntensityAdjustmentSupported(napi_env env, + napi_callback_info info) +{ + napi_value result = nullptr; + napi_get_undefined(env, &result); + + if (!AudioHapticCommonNapi::VerifySelfSystemPermission()) { + AudioHapticCommonNapi::ThrowError(env, NAPI_ERR_PERMISSION_DENIED, NAPI_ERR_PERMISSION_DENIED_INFO); + return result; + } + + void *native = nullptr; + napi_value argv[ARGS_ONE] = {0}; + if (!AudioHapticCommonNapi::InitNormalFunc(env, info, &native, argv, ARGS_ZERO)) { + return result; + } + + auto *audioHapticPlayerNapi = reinterpret_cast(native); + if (audioHapticPlayerNapi == nullptr || audioHapticPlayerNapi->audioHapticPlayer_ == nullptr) { + MEDIA_LOGE("IsHapticsIntensityAdjustmentSupported: unwrap failure!"); + AudioHapticCommonNapi::ThrowError(env, NAPI_ERR_SERVICE_DIED, "unwrap failure"); + return result; + } + bool isSupported = audioHapticPlayerNapi->audioHapticPlayer_->IsHapticsIntensityAdjustmentSupported(); + + napi_get_boolean(env, isSupported, &result); + return result; +} + +napi_value AudioHapticPlayerNapi::EnableHapticsInSilentMode(napi_env env, napi_callback_info info) +{ + napi_value result = nullptr; + napi_get_undefined(env, &result); + + if (!AudioHapticCommonNapi::VerifySelfSystemPermission()) { + AudioHapticCommonNapi::ThrowError(env, NAPI_ERR_PERMISSION_DENIED, NAPI_ERR_PERMISSION_DENIED_INFO); + return result; + } + + void *native = nullptr; + napi_value argv[ARGS_ONE] = {0}; + if (!AudioHapticCommonNapi::InitNormalFunc(env, info, &native, argv, ARGS_ONE)) { + return result; + } + + auto *audioHapticPlayerNapi = reinterpret_cast(native); + if (audioHapticPlayerNapi == nullptr || audioHapticPlayerNapi->audioHapticPlayer_ == nullptr) { + MEDIA_LOGE("EnableHapticsInSilentMode: unwrap failure!"); + AudioHapticCommonNapi::ThrowError(env, NAPI_ERR_SERVICE_DIED, "unwrap failure"); + return result; + } + + bool enable = false; + if (napi_get_value_bool(env, argv[PARAM0], &enable) != napi_ok) { + AudioHapticCommonNapi::ThrowError(env, NAPI_ERR_INPUT_INVALID, "input param is invalid"); + return result; + } + + int32_t ret = audioHapticPlayerNapi->audioHapticPlayer_->EnableHapticsInSilentMode(enable); + if (ret == NAPI_ERR_OPERATE_NOT_ALLOWED) { + AudioHapticCommonNapi::ThrowError(env, NAPI_ERR_OPERATE_NOT_ALLOWED, "operate not allowed"); + return result; + } + return result; +} + napi_value AudioHapticPlayerNapi::IsMuted(napi_env env, napi_callback_info info) { napi_value result = nullptr; @@ -199,6 +263,49 @@ bool AudioHapticPlayerNapi::IsLegalAudioHapticType(int32_t audioHapticType) return false; } +bool AudioHapticPlayerNapi::IsLegalVolumeOrIntensity(double number) +{ + return number >= 0.0 && number <= 1.0; +} + +bool AudioHapticPlayerNapi::JudgeVolume(napi_env env, std::unique_ptr& asyncContext) +{ + napi_valuetype valueType = napi_undefined; + napi_typeof(env, asyncContext->argv[PARAM0], &valueType); + double volume = -1.00; + if (valueType == napi_number) { + napi_get_value_double(env, asyncContext->argv[PARAM0], &volume); + } + if (!IsLegalVolumeOrIntensity(volume)) { + MEDIA_LOGE("SetVolume: the param is invalid"); + AudioHapticCommonNapi::PromiseReject(env, asyncContext->deferred, + NAPI_ERR_PARAM_OUT_OF_RANGE, "The value ranges from 0.00 to 1.00"); + return false; + } + + asyncContext->volume = static_cast(std::round(volume * PRECISION) / PRECISION); + return true; +} + +bool AudioHapticPlayerNapi::JudgeIntensity(napi_env env, std::unique_ptr& asyncContext) +{ + napi_valuetype valueType = napi_undefined; + napi_typeof(env, asyncContext->argv[PARAM0], &valueType); + double intensity = -1.00; + if (valueType == napi_number) { + napi_get_value_double(env, asyncContext->argv[PARAM0], &intensity); + } + if (!IsLegalVolumeOrIntensity(intensity)) { + MEDIA_LOGE("SetIntensity: the param is invalid"); + AudioHapticCommonNapi::PromiseReject(env, asyncContext->deferred, + NAPI_ERR_PARAM_OUT_OF_RANGE, "The value ranges from 0.00 to 1.00"); + return false; + } + + asyncContext->intensity = static_cast(std::round(intensity * PRECISION) / PRECISION); + return true; +} + void AudioHapticPlayerNapi::CommonAsyncCallbackComp(napi_env env, napi_status status, void *data) { auto context = static_cast(data); @@ -226,6 +333,114 @@ void AudioHapticPlayerNapi::CommonAsyncCallbackComp(napi_env env, napi_status st context = nullptr; } +napi_value AudioHapticPlayerNapi::SetHapticsIntensity(napi_env env, napi_callback_info info) +{ + std::unique_ptr asyncContext = std::make_unique(); + napi_value promise = nullptr; + if (!AudioHapticCommonNapi::InitPromiseFunc(env, info, asyncContext.get(), &promise, ARGS_ONE)) { + return promise; + } + if (!AudioHapticCommonNapi::VerifySelfSystemPermission()) { + AudioHapticCommonNapi::PromiseReject(env, asyncContext->deferred, + NAPI_ERR_PERMISSION_DENIED, NAPI_ERR_PERMISSION_DENIED_INFO); + return promise; + } + if (!JudgeIntensity(env, asyncContext)) { + return promise; + } + + napi_value funcName = nullptr; + napi_create_string_utf8(env, "SetVibrationIntensity", NAPI_AUTO_LENGTH, &funcName); + napi_status status = napi_create_async_work(env, nullptr, funcName, + [](napi_env env, void *data) { + auto context = static_cast(data); + AudioHapticPlayerNapi* object = reinterpret_cast(context->objectInfo); + if (object == nullptr || object->audioHapticPlayer_ == nullptr) { + context->result = NAPI_ERR_SERVICE_DIED; + } else { + context->result = object->audioHapticPlayer_->SetHapticIntensity(context->intensity * PRECISION); + } + }, + [](napi_env env, napi_status status, void *data) { + auto context = static_cast(data); + if (context->deferred) { + if (context->result == 0) { + napi_value result; + napi_get_undefined(env, &result); + napi_resolve_deferred(env, context->deferred, result); + } else { + AudioHapticCommonNapi::PromiseReject(env, context->deferred, + context->result, "Failed to set SetVibrationIntensity"); + } + } + napi_delete_async_work(env, context->work); + delete context; + context = nullptr; + }, static_cast(asyncContext.get()), &asyncContext->work); + if (status != napi_ok) { + AudioHapticCommonNapi::PromiseReject(env, asyncContext->deferred, status, "Failed to get create async work"); + } else { + napi_queue_async_work(env, asyncContext->work); + asyncContext.release(); + } + + return promise; +} + +napi_value AudioHapticPlayerNapi::SetVolume(napi_env env, napi_callback_info info) +{ + std::unique_ptr asyncContext = std::make_unique(); + napi_value promise = nullptr; + if (!AudioHapticCommonNapi::InitPromiseFunc(env, info, asyncContext.get(), &promise, ARGS_ONE)) { + return promise; + } + + if (!JudgeVolume(env, asyncContext)) { + return promise; + } + + napi_value funcName = nullptr; + napi_create_string_utf8(env, "SetVolume", NAPI_AUTO_LENGTH, &funcName); + napi_status status = napi_create_async_work( + env, + nullptr, + funcName, + [](napi_env env, void *data) { + auto context = static_cast(data); + AudioHapticPlayerNapi* object = reinterpret_cast(context->objectInfo); + + context->result = object->audioHapticPlayer_->SetVolume(context->volume); + }, + [](napi_env env, napi_status status, void *data) { + auto context = static_cast(data); + if (context->deferred) { + if (context->result == 0) { + napi_value result; + napi_get_undefined(env, &result); + napi_resolve_deferred(env, context->deferred, result); + } else { + AudioHapticCommonNapi::PromiseReject(env, context->deferred, + context->result, "Failed to set volume"); + } + } + napi_delete_async_work(env, context->work); + delete context; + context = nullptr; + }, + static_cast(asyncContext.get()), + &asyncContext->work); + if (status != napi_ok) { + MEDIA_LOGE("Start: Failed to get create async work"); + AudioHapticCommonNapi::PromiseReject(env, asyncContext->deferred, + status, "Failed to get create async work"); + } else { + napi_queue_async_work(env, asyncContext->work); + asyncContext.release(); + } + + return promise; +} + napi_value AudioHapticPlayerNapi::Start(napi_env env, napi_callback_info info) { napi_value result = nullptr; diff --git a/frameworks/js/avplayer/avplayer_callback.cpp b/frameworks/js/avplayer/avplayer_callback.cpp index ce086a36cc81613e6636ca3af474f8803f9e5f4b..f0bf540c99292cdcbf0ece7420c01f96a5ffdb05 100644 --- a/frameworks/js/avplayer/avplayer_callback.cpp +++ b/frameworks/js/avplayer/avplayer_callback.cpp @@ -956,7 +956,7 @@ void AVPlayerCallback::OnSpeedDoneCb(const int32_t extra, const Format &infoBody void AVPlayerCallback::OnPlaybackRateDoneCb(const int32_t extra, const Format &infoBody) { - (void)infoBody; + (void)extra; CHECK_AND_RETURN_LOG(isloaded_.load(), "current source is unready"); float speedRate = 0.0f; (void)infoBody.GetFloatValue(PlayerKeys::PLAYER_PLAYBACK_RATE, speedRate); diff --git a/frameworks/js/avplayer/avplayer_napi.cpp b/frameworks/js/avplayer/avplayer_napi.cpp index 7e53f3449795812a3a9428eb405c6f7cb99d046a..90571a89095a0182f06c272e9a0950a4d2d8e265 100644 --- a/frameworks/js/avplayer/avplayer_napi.cpp +++ b/frameworks/js/avplayer/avplayer_napi.cpp @@ -59,6 +59,7 @@ namespace { constexpr int32_t ARGS_TWO = 2; constexpr int32_t ARGS_THREE = 3; constexpr int32_t SEEK_CONTINUOUS_TS_ENUM_NUM = 3; + constexpr double RATE_DEFAULT_VALUE = 1.0; } namespace OHOS { @@ -988,7 +989,7 @@ napi_value AVPlayerNapi::JsSetPlaybackRate(napi_env env, napi_callback_info info return result; } - double rate = 1.0f; + double rate = RATE_DEFAULT_VALUE; napi_status status = napi_get_value_double(env, args[0], &rate); if (status != napi_ok || !jsPlayer->IsRateValid(rate)) { jsPlayer->OnErrorCb(MSERR_EXT_API20_PARAM_ERROR_OUT_OF_RANGE, @@ -1325,8 +1326,6 @@ napi_value AVPlayerNapi::JsSetUrl(napi_env env, napi_callback_info info) return result; } - - napi_value AVPlayerNapi::JsSetStartFrameRateOptEnabled(napi_env env, napi_callback_info info) { MediaTrace trace("AVPlayerNapi::SetStartFrameRateOptEnabled"); @@ -1352,6 +1351,12 @@ napi_value AVPlayerNapi::JsSetStartFrameRateOptEnabled(napi_env env, napi_callba return result; } + if (!IsSystemApp()) { + jsPlayer->OnErrorCb(MSERR_EXT_API9_INVALID_PARAMETER, + "invalid parameters, please dont't set"); + return result; + } + auto task = std::make_shared>([jsPlayer]() { MEDIA_LOGD("SetStartFrameRateOptEnabled Task"); if (jsPlayer->player_ != nullptr) { @@ -3215,42 +3220,20 @@ void AVPlayerNapi::DeviceChangeCallbackOff(AVPlayerNapi *jsPlayer, std::string c } } -void AVPlayerNapi::ReportMediaProgressCallbackOn(AVPlayerNapi *jsPlayer, std::string callbackName) +void AVPlayerNapi::HandleListenerStateChange(std::string callbackName, bool state) { - if (jsPlayer == nullptr) { - reportMediaProgressCallbackflag_ = false; - return; - } - if (callbackName == "timeUpdate") { - reportMediaProgressCallbackflag_ = true; - } - CHECK_AND_RETURN_LOG(jsPlayer->player_ != nullptr, "player_ is nullptr"); - if (reportMediaProgressCallbackflag_) { - (void)jsPlayer->player_->EnableReportMediaProgress(reportMediaProgressCallbackflag_); + CHECK_AND_RETURN_LOG(player_ != nullptr, "player is nullptr"); + + if (callbackName == "amplitudeUpdate") { + return (void)player_->SetMaxAmplitudeCbStatus(state); } -} -void AVPlayerNapi::ReportMediaProgressCallbackOff(AVPlayerNapi *jsPlayer, std::string callbackName) -{ - CHECK_AND_RETURN_LOG(jsPlayer != nullptr, "jsPlayer is nullptr"); - if (reportMediaProgressCallbackflag_ && callbackName == "timeUpdate") { - reportMediaProgressCallbackflag_ = false; - CHECK_AND_RETURN_LOG(jsPlayer->player_ != nullptr, "player_ is nullptr"); - (void)jsPlayer->player_->EnableReportMediaProgress(reportMediaProgressCallbackflag_); + if (callbackName == "timeUpdate") { + return (void)player_->EnableReportMediaProgress(state); } -} -void AVPlayerNapi::MaxAmplitudeCallbackOn(AVPlayerNapi *jsPlayer, std::string callbackName) -{ - if (jsPlayer == nullptr) { - calMaxAmplitude_ = false; - return; - } - if (callbackName == "amplitudeUpdate") { - calMaxAmplitude_ = true; - } - if (jsPlayer->player_ != nullptr && calMaxAmplitude_) { - (void)jsPlayer->player_->SetMaxAmplitudeCbStatus(calMaxAmplitude_); + if (callbackName == "audioInterrupt") { + return (void)player_->EnableReportAudioInterrupt(state); } } @@ -3306,8 +3289,7 @@ napi_value AVPlayerNapi::JsSetOnCallback(napi_env env, napi_callback_info info) } else if (argCount == ARGS_TWO) { CHECK_AND_RETURN_RET_NOLOG( VerifyExpectedType({env, args[1], napi_function}, jsPlayer, "param should be function."), result); - jsPlayer->MaxAmplitudeCallbackOn(jsPlayer, callbackName); - jsPlayer->ReportMediaProgressCallbackOn(jsPlayer, callbackName); + jsPlayer->HandleListenerStateChange(callbackName, true); napi_status status = napi_create_reference(env, args[1], 1, &ref); CHECK_AND_RETURN_RET_LOG(status == napi_ok && ref != nullptr, result, "failed to create reference!"); } @@ -3327,16 +3309,6 @@ bool AVPlayerNapi::VerifyExpectedType(const NapiTypeCheckUnit &unit, AVPlayerNap return false; } -void AVPlayerNapi::MaxAmplitudeCallbackOff(AVPlayerNapi *jsPlayer, std::string callbackName) -{ - if (jsPlayer != nullptr && calMaxAmplitude_ && callbackName == "amplitudeUpdate") { - calMaxAmplitude_ = false; - if (jsPlayer->player_ != nullptr) { - (void)jsPlayer->player_->SetMaxAmplitudeCbStatus(calMaxAmplitude_); - } - } -} - void AVPlayerNapi::SeiMessageCallbackOff(AVPlayerNapi *jsPlayer, std::string &callbackName, const std::vector &payloadTypes) { @@ -3380,8 +3352,7 @@ napi_value AVPlayerNapi::JsClearOnCallback(napi_env env, napi_callback_info info std::string callbackName = CommonNapi::GetStringArgument(env, args[0]); MEDIA_LOGI("0x%{public}06" PRIXPTR " set callbackName: %{public}s", FAKE_POINTER(jsPlayer), callbackName.c_str()); if (callbackName != "seiMessageReceived") { - jsPlayer->MaxAmplitudeCallbackOff(jsPlayer, callbackName); - jsPlayer->ReportMediaProgressCallbackOff(jsPlayer, callbackName); + jsPlayer->HandleListenerStateChange(callbackName, false); jsPlayer->ClearCallbackReference(callbackName); MEDIA_LOGI("0x%{public}06" PRIXPTR " JsClearOnCallback success", FAKE_POINTER(jsPlayer)); return result; diff --git a/frameworks/js/avplayer/avplayer_napi.h b/frameworks/js/avplayer/avplayer_napi.h index c36ac61443cb105fb0c375ae9221e05734f4ee40..953d0618fad791bfe5d40a22e4bca7ce830fd65b 100644 --- a/frameworks/js/avplayer/avplayer_napi.h +++ b/frameworks/js/avplayer/avplayer_napi.h @@ -362,12 +362,9 @@ private: void NotifyDrmInfoUpdated(const std::multimap> &infos) override; void StopTaskQue(); void WaitTaskQueStop(); - void MaxAmplitudeCallbackOn(AVPlayerNapi *jsPlayer, std::string callbackName); - void MaxAmplitudeCallbackOff(AVPlayerNapi *jsPlayer, std::string callbackName); + void HandleListenerStateChange(std::string callbackName, bool state); void DeviceChangeCallbackOn(AVPlayerNapi *jsPlayer, std::string callbackName); void DeviceChangeCallbackOff(AVPlayerNapi *jsPlayer, std::string callbackName); - void ReportMediaProgressCallbackOn(AVPlayerNapi *jsPlayer, std::string callbackName); - void ReportMediaProgressCallbackOff(AVPlayerNapi *jsPlayer, std::string callbackName); void SeiMessageCallbackOn( AVPlayerNapi *jsPlayer, std::string callbackName, const std::vector &payloadTypes); void SeiMessageCallbackOff( @@ -384,10 +381,8 @@ private: std::condition_variable stopTaskQueCond_; bool taskQueStoped_ = false; - bool calMaxAmplitude_ = false; bool deviceChangeCallbackflag_ = false; bool seiMessageCallbackflag_ = false; - bool reportMediaProgressCallbackflag_ = false; struct AVPlayerContext : public MediaAsyncContext { explicit AVPlayerContext(napi_env env) : MediaAsyncContext(env) {} diff --git a/frameworks/js/soundpool/BUILD.gn b/frameworks/js/soundpool/BUILD.gn index a496081151ddafd85c60b07e4df45b6cf0adebf2..216eab2c961945e0e456045f38e8de79c69c85de 100644 --- a/frameworks/js/soundpool/BUILD.gn +++ b/frameworks/js/soundpool/BUILD.gn @@ -90,6 +90,7 @@ ohos_shared_library("media_soundpool") { "eventhandler:libeventhandler", "hilog:libhilog", "hisysevent:libhisysevent", + "hitrace:hitrace_meter", "ipc:ipc_core", "napi:ace_napi", "qos_manager:qos", diff --git a/frameworks/js/soundpool/include/soundpool_callback_napi.h b/frameworks/js/soundpool/include/soundpool_callback_napi.h index 8dcf5f939101e310be9594e6477c3b950c5cbaa0..96365aff2ac6526725acefb203713a170cfa901d 100644 --- a/frameworks/js/soundpool/include/soundpool_callback_napi.h +++ b/frameworks/js/soundpool/include/soundpool_callback_napi.h @@ -53,10 +53,10 @@ protected: private: struct SoundPoolJsCallBack { - void RunJsErrorCallBackTask(int status, SoundPoolJsCallBack *event); - void RunJsErrorOccurredCallBackTask(int status, SoundPoolJsCallBack *event); - void RunJsloadCompletedCallBackTask(int status, SoundPoolJsCallBack *event); - void RunJsplayCompletedCallBackTask(int status, SoundPoolJsCallBack *event); + void RunJsErrorCallBackTask(SoundPoolJsCallBack *event); + void RunJsErrorOccurredCallBackTask(SoundPoolJsCallBack *event); + void RunJsloadCompletedCallBackTask(SoundPoolJsCallBack *event); + void RunJsplayCompletedCallBackTask(SoundPoolJsCallBack *event); std::weak_ptr autoRef; std::string callbackName = "unknown"; diff --git a/frameworks/js/soundpool/include/soundpool_napi.h b/frameworks/js/soundpool/include/soundpool_napi.h index 343f0b6aed643aaa08c6d425a191c037c2e3244b..f77e04c2df1a84f9a71514ecae5be33aef46fd2c 100644 --- a/frameworks/js/soundpool/include/soundpool_napi.h +++ b/frameworks/js/soundpool/include/soundpool_napi.h @@ -136,6 +136,7 @@ private: static SoundPoolNapi* GetJsInstanceAndArgs(napi_env env, napi_callback_info info, size_t &argCount, napi_value *args); static napi_status GetJsInstanceWithParameter(napi_env env, napi_value *argv, int32_t argvLength); + static void SendCompleteEvent(napi_env env, std::unique_ptr asyncCtx); static bool IsSystemApp(); int32_t ParserLoadOptionFromJs(std::unique_ptr &asyncCtx, napi_env env, napi_value *argv, size_t argCount); diff --git a/frameworks/js/soundpool/src/soundpool_callback_napi.cpp b/frameworks/js/soundpool/src/soundpool_callback_napi.cpp index 2d9c631b6cb12352653dbdaaa10ad3165faf864a..cf1ecd5961ccb2fef5845cf66bc28a4858021175 100644 --- a/frameworks/js/soundpool/src/soundpool_callback_napi.cpp +++ b/frameworks/js/soundpool/src/soundpool_callback_napi.cpp @@ -212,75 +212,36 @@ void SoundPoolCallBackNapi::SendPlayCompletedCallback(int32_t streamID) void SoundPoolCallBackNapi::OnJsErrorCallBack(SoundPoolJsCallBack *jsCb) const { - ON_SCOPE_EXIT(0) { - delete jsCb; - }; - uv_loop_s *loop = nullptr; - napi_get_uv_event_loop(env_, &loop); - CHECK_AND_RETURN_LOG(loop != nullptr, "Fail to get uv event loop"); - - uv_work_t *work = new(std::nothrow) uv_work_t; - CHECK_AND_RETURN_LOG(work != nullptr, "fail to new uv_work_t"); - ON_SCOPE_EXIT(1) { - delete work; - }; - work->data = reinterpret_cast(jsCb); - // async callback, jsWork and jsWork->data should be heap object. - int ret = uv_queue_work_with_qos(loop, work, [] (uv_work_t *work) { - MEDIA_LOGD("OnJsErrorCallBack uv_queue_work_with_qos"); - }, [] (uv_work_t *work, int status) { - // Js Thread - CHECK_AND_RETURN_LOG(work != nullptr, "work is nullptr"); - SoundPoolJsCallBack *event = reinterpret_cast(work->data); - event->RunJsErrorCallBackTask(status, event); + auto task = [event = jsCb]() { + event->RunJsErrorCallBackTask(event); delete event; - delete work; - }, uv_qos_user_initiated); - if (ret != 0) { - MEDIA_LOGI("fail to uv_queue_work_with_qos task"); + }; + + auto ret = napi_send_event(env_, task, napi_eprio_immediate); + if (ret != napi_status::napi_ok) { + MEDIA_LOGE("Failed to SendEvent CallBack, ret = %{public}d", ret); + delete jsCb; } - CANCEL_SCOPE_EXIT_GUARD(0); - CANCEL_SCOPE_EXIT_GUARD(1); } void SoundPoolCallBackNapi::OnJsErrorOccurredCallBack(SoundPoolJsCallBack *jsCb) const { - ON_SCOPE_EXIT(0) { - delete jsCb; - }; - uv_loop_s *loop = nullptr; - napi_get_uv_event_loop(env_, &loop); - CHECK_AND_RETURN_LOG(loop != nullptr, "Fail to get uv event loop"); - - uv_work_t *work = new(std::nothrow) uv_work_t; - CHECK_AND_RETURN_LOG(work != nullptr, "fail to new uv_work_t"); - ON_SCOPE_EXIT(1) { - delete work; - }; - work->data = reinterpret_cast(jsCb); - // async callback, jsWork and jsWork->data should be heap object. - int ret = uv_queue_work_with_qos(loop, work, [] (uv_work_t *work) { - MEDIA_LOGD("OnJsErrorOccurredCallBack uv_queue_work_with_qos"); - }, [] (uv_work_t *work, int status) { - // Js Thread - CHECK_AND_RETURN_LOG(work != nullptr, "work is nullptr"); - SoundPoolJsCallBack *event = reinterpret_cast(work->data); - event->RunJsErrorOccurredCallBackTask(status, event); + auto task = [event = jsCb]() { + event->RunJsErrorOccurredCallBackTask(event); delete event; - delete work; - }, uv_qos_user_initiated); - if (ret != 0) { - MEDIA_LOGI("fail to uv_queue_work_with_qos task"); + }; + + auto ret = napi_send_event(env_, task, napi_eprio_immediate); + if (ret != napi_status::napi_ok) { + MEDIA_LOGE("Failed to SendEvent CallBack, ret = %{public}d", ret); + delete jsCb; } - CANCEL_SCOPE_EXIT_GUARD(0); - CANCEL_SCOPE_EXIT_GUARD(1); } -void SoundPoolCallBackNapi::SoundPoolJsCallBack::RunJsErrorCallBackTask(int status, SoundPoolJsCallBack *event) +void SoundPoolCallBackNapi::SoundPoolJsCallBack::RunJsErrorCallBackTask(SoundPoolJsCallBack *event) { std::string request = event->callbackName; do { - CHECK_AND_BREAK_LOG(status != UV_ECANCELED, "%{public}s canceled", request.c_str()); std::shared_ptr ref = event->autoRef.lock(); CHECK_AND_BREAK_LOG(ref != nullptr, "%{public}s AutoRef is nullptr", request.c_str()); @@ -313,13 +274,12 @@ void SoundPoolCallBackNapi::SoundPoolJsCallBack::RunJsErrorCallBackTask(int stat } while (0); } -void SoundPoolCallBackNapi::SoundPoolJsCallBack::RunJsErrorOccurredCallBackTask(int status, SoundPoolJsCallBack *event) +void SoundPoolCallBackNapi::SoundPoolJsCallBack::RunJsErrorOccurredCallBackTask(SoundPoolJsCallBack *event) { std::string request = event->callbackName; MEDIA_LOGI("errorOccurredCallback event: errorMsg %{public}s, errorCode %{public}d, soundId %{public}d," "streamId %{public}d", event->errorMsg.c_str(), event->errorCode, event->loadSoundId, event->playFinishedStreamID); - CHECK_AND_RETURN_LOG(status != UV_ECANCELED, "%{public}s canceled", request.c_str()); std::shared_ptr ref = event->autoRef.lock(); CHECK_AND_RETURN_LOG(ref != nullptr, "%{public}s AutoRef is nullptr", request.c_str()); napi_handle_scope scope = nullptr; @@ -337,7 +297,7 @@ void SoundPoolCallBackNapi::SoundPoolJsCallBack::RunJsErrorOccurredCallBackTask( napi_create_object(ref->env_, &args[0]); napi_value errCode = nullptr; - status = CommonNapi::CreateError(ref->env_, event->errorCode, event->errorMsg, errCode); + int status = CommonNapi::CreateError(ref->env_, event->errorCode, event->errorMsg, errCode); CHECK_AND_RETURN_LOG(status == napi_ok && errCode != nullptr, " fail to convert to errorCode"); napi_set_named_property(ref->env_, args[0], "errorCode", errCode); @@ -357,45 +317,22 @@ void SoundPoolCallBackNapi::SoundPoolJsCallBack::RunJsErrorOccurredCallBackTask( void SoundPoolCallBackNapi::OnJsloadCompletedCallBack(SoundPoolJsCallBack *jsCb) const { - ON_SCOPE_EXIT(0) { - delete jsCb; - }; - uv_loop_s *loop = nullptr; - napi_get_uv_event_loop(env_, &loop); - CHECK_AND_RETURN_LOG(loop != nullptr, "Fail to get uv event loop"); - - uv_work_t *work = new(std::nothrow) uv_work_t; - CHECK_AND_RETURN_LOG(work != nullptr, "fail to new uv_work_t"); - ON_SCOPE_EXIT(1) { - delete work; + auto task = [event = jsCb]() { + event->RunJsloadCompletedCallBackTask(event); + delete event; }; - work->data = reinterpret_cast(jsCb); - // async callback, jsWork and jsWork->data should be heap object. - int ret = uv_queue_work_with_qos(loop, work, [] (uv_work_t *work) { - MEDIA_LOGD("OnJsloadCompletedCallBack uv_queue_work_with_qos"); - }, [] (uv_work_t *work, int status) { - CHECK_AND_RETURN_LOG(work != nullptr, "work is nullptr"); - if (work->data != nullptr) { - MEDIA_LOGD("work data not nullptr"); - SoundPoolJsCallBack *event = reinterpret_cast(work->data); - event->RunJsloadCompletedCallBackTask(status, event); - delete event; - } - delete work; - }, uv_qos_user_initiated); - if (ret != 0) { - MEDIA_LOGI("fail to uv_queue_work_with_qos task"); + + auto ret = napi_send_event(env_, task, napi_eprio_immediate); + if (ret != napi_status::napi_ok) { + MEDIA_LOGE("Failed to SendEvent CallBack, ret = %{public}d", ret); + delete jsCb; } - CANCEL_SCOPE_EXIT_GUARD(0); - CANCEL_SCOPE_EXIT_GUARD(1); } -void SoundPoolCallBackNapi::SoundPoolJsCallBack::RunJsloadCompletedCallBackTask(int status, - SoundPoolJsCallBack *event) +void SoundPoolCallBackNapi::SoundPoolJsCallBack::RunJsloadCompletedCallBackTask(SoundPoolJsCallBack *event) { std::string request = event->callbackName; do { - CHECK_AND_BREAK_LOG(status != UV_ECANCELED, "%{public}s canceled", request.c_str()); std::shared_ptr ref = event->autoRef.lock(); CHECK_AND_BREAK_LOG(ref != nullptr, "%{public}s AutoRef is nullptr", request.c_str()); napi_handle_scope scope = nullptr; @@ -421,47 +358,22 @@ void SoundPoolCallBackNapi::SoundPoolJsCallBack::RunJsloadCompletedCallBackTask( void SoundPoolCallBackNapi::OnJsplayCompletedCallBack(SoundPoolJsCallBack *jsCb) const { - ON_SCOPE_EXIT(0) { - delete jsCb; - }; - uv_loop_s *loop = nullptr; - napi_get_uv_event_loop(env_, &loop); - CHECK_AND_RETURN_LOG(loop != nullptr, "Fail to get uv event loop"); - - uv_work_t *work = new(std::nothrow) uv_work_t; - CHECK_AND_RETURN_LOG(work != nullptr, "fail to new uv_work_t"); - ON_SCOPE_EXIT(1) { - delete work; + auto task = [event = jsCb]() { + event->RunJsplayCompletedCallBackTask(event); + delete event; }; - work->data = reinterpret_cast(jsCb); - // async callback, jsWork and jsWork->data should be heap object. - int ret = uv_queue_work_with_qos(loop, work, [] (uv_work_t *work) { - MEDIA_LOGD("OnJsplayCompletedCallBack uv_queue_work_with_qos"); - }, [] (uv_work_t *work, int status) { - // Js Thread - CHECK_AND_RETURN_LOG(work != nullptr, "work is nullptr"); - if (work->data != nullptr) { - MEDIA_LOGI("work data not nullptr"); - SoundPoolJsCallBack *event = reinterpret_cast(work->data); - event->RunJsplayCompletedCallBackTask(status, event); - delete event; - } - delete work; - }, uv_qos_user_initiated); - if (ret != 0) { - MEDIA_LOGI("fail to uv_queue_work_with_qos task"); + + auto ret = napi_send_event(env_, task, napi_eprio_immediate); + if (ret != napi_status::napi_ok) { + MEDIA_LOGE("Failed to SendEvent CallBack, ret = %{public}d", ret); + delete jsCb; } - - CANCEL_SCOPE_EXIT_GUARD(0); - CANCEL_SCOPE_EXIT_GUARD(1); } -void SoundPoolCallBackNapi::SoundPoolJsCallBack::RunJsplayCompletedCallBackTask(int status, - SoundPoolJsCallBack *event) +void SoundPoolCallBackNapi::SoundPoolJsCallBack::RunJsplayCompletedCallBackTask(SoundPoolJsCallBack *event) { std::string request = event->callbackName; do { - CHECK_AND_BREAK_LOG(status != UV_ECANCELED, "%{public}s canceled", request.c_str()); std::shared_ptr ref = event->autoRef.lock(); CHECK_AND_BREAK_LOG(ref != nullptr, "%{public}s AutoRef is nullptr", request.c_str()); diff --git a/frameworks/js/soundpool/src/soundpool_napi.cpp b/frameworks/js/soundpool/src/soundpool_napi.cpp index ba50122354f8a6678c9bb93970b0096b1ae47d4c..5f9d8f4344d8a3e4ee090c0f26df6b8eb0c0f041 100644 --- a/frameworks/js/soundpool/src/soundpool_napi.cpp +++ b/frameworks/js/soundpool/src/soundpool_napi.cpp @@ -209,14 +209,7 @@ napi_value SoundPoolNapi::JsCreateSoundPool(napi_env env, napi_callback_info inf asyncCtx->JsResult = std::make_unique(constructor_); asyncCtx->ctorFlag = true; - napi_value resource = nullptr; - napi_create_string_utf8(env, "JsCreateSoundPool", NAPI_AUTO_LENGTH, &resource); - NAPI_CALL(env, napi_create_async_work(env, nullptr, resource, [](napi_env env, void* data) { - MEDIA_LOGD("JsCreateSoundPool napi_create_async_work"); - }, MediaAsyncContext::CompleteCallback, static_cast(asyncCtx.get()), &asyncCtx->work)); - NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncCtx->work, napi_qos_user_initiated)); - asyncCtx.release(); - + SoundPoolNapi::SendCompleteEvent(env, std::move(asyncCtx)); return result; } @@ -247,14 +240,7 @@ napi_value SoundPoolNapi::JsCreateParallelSoundPool(napi_env env, napi_callback_ asyncCtx->SignError(MSERR_EXT_API9_PERMISSION_DENIED, "failed to get without permission"); } - napi_value resource = nullptr; - napi_create_string_utf8(env, "JsCreateParallelSoundPool", NAPI_AUTO_LENGTH, &resource); - NAPI_CALL(env, napi_create_async_work(env, nullptr, resource, [](napi_env env, void* data) { - MEDIA_LOGD("JsCreateParallelSoundPool napi_create_async_work"); - }, MediaAsyncContext::CompleteCallback, static_cast(asyncCtx.get()), &asyncCtx->work)); - NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncCtx->work, napi_qos_user_initiated)); - asyncCtx.release(); - + SoundPoolNapi::SendCompleteEvent(env, std::move(asyncCtx)); return result; } @@ -299,13 +285,11 @@ napi_value SoundPoolNapi::JsLoad(napi_env env, napi_callback_info info) } MEDIA_LOGI("The js thread of load finishes execution and returns, soundId: %{public}d", soundId); }, MediaAsyncContext::CompleteCallback, static_cast(asyncCtx.get()), &asyncCtx->work)); + NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncCtx->work, napi_qos_user_initiated)); + asyncCtx.release(); } else { - NAPI_CALL(env, napi_create_async_work(env, nullptr, resource, [](napi_env env, void* data) { - MEDIA_LOGD("JsLoad napi_create_async_work"); - }, MediaAsyncContext::CompleteCallback, static_cast(asyncCtx.get()), &asyncCtx->work)); + SoundPoolNapi::SendCompleteEvent(env, std::move(asyncCtx)); } - NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncCtx->work, napi_qos_user_initiated)); - asyncCtx.release(); return result; } @@ -346,13 +330,11 @@ napi_value SoundPoolNapi::JsPlay(napi_env env, napi_callback_info info) } MEDIA_LOGI("The js thread of play finishes execution and returns, streamId: %{public}d", streamId); }, MediaAsyncContext::CompleteCallback, static_cast(asyncCtx.get()), &asyncCtx->work)); + NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncCtx->work, napi_qos_user_initiated)); + asyncCtx.release(); } else { - NAPI_CALL(env, napi_create_async_work(env, nullptr, resource, [](napi_env env, void* data) { - MEDIA_LOGD("JsPlay napi_create_async_work"); - }, MediaAsyncContext::CompleteCallback, static_cast(asyncCtx.get()), &asyncCtx->work)); + SoundPoolNapi::SendCompleteEvent(env, std::move(asyncCtx)); } - NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncCtx->work, napi_qos_user_initiated)); - asyncCtx.release(); return result; } @@ -392,13 +374,10 @@ napi_value SoundPoolNapi::JsStop(napi_env env, napi_callback_info info) MEDIA_LOGI("The js thread of stop finishes execution and returns"); }, MediaAsyncContext::CompleteCallback, static_cast(asyncCtx.get()), &asyncCtx->work)); NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncCtx->work, napi_qos_user_initiated)); + asyncCtx.release(); } else { - NAPI_CALL(env, napi_create_async_work(env, nullptr, resource, [](napi_env env, void* data) { - MEDIA_LOGD("JsStop napi_create_async_work"); - }, MediaAsyncContext::CompleteCallback, static_cast(asyncCtx.get()), &asyncCtx->work)); - NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncCtx->work, napi_qos_user_initiated)); + SoundPoolNapi::SendCompleteEvent(env, std::move(asyncCtx)); } - asyncCtx.release(); return result; } @@ -441,13 +420,10 @@ napi_value SoundPoolNapi::JsSetLoop(napi_env env, napi_callback_info info) MEDIA_LOGI("The js thread of SetLoop finishes execution and returns"); }, MediaAsyncContext::CompleteCallback, static_cast(asyncCtx.get()), &asyncCtx->work)); NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncCtx->work, napi_qos_user_initiated)); + asyncCtx.release(); } else { - NAPI_CALL(env, napi_create_async_work(env, nullptr, resource, [](napi_env env, void* data) { - MEDIA_LOGD("JsSetLoop napi_create_async_work"); - }, MediaAsyncContext::CompleteCallback, static_cast(asyncCtx.get()), &asyncCtx->work)); - NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncCtx->work, napi_qos_user_initiated)); + SoundPoolNapi::SendCompleteEvent(env, std::move(asyncCtx)); } - asyncCtx.release(); return result; } @@ -492,13 +468,10 @@ napi_value SoundPoolNapi::JsSetPriority(napi_env env, napi_callback_info info) MEDIA_LOGI("The js thread of SetPriority finishes execution and returns"); }, MediaAsyncContext::CompleteCallback, static_cast(asyncCtx.get()), &asyncCtx->work)); NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncCtx->work, napi_qos_user_initiated)); + asyncCtx.release(); } else { - NAPI_CALL(env, napi_create_async_work(env, nullptr, resource, [](napi_env env, void* data) { - MEDIA_LOGD("JsSetPriority napi_create_async_work"); - }, MediaAsyncContext::CompleteCallback, static_cast(asyncCtx.get()), &asyncCtx->work)); - NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncCtx->work, napi_qos_user_initiated)); + SoundPoolNapi::SendCompleteEvent(env, std::move(asyncCtx)); } - asyncCtx.release(); return result; } @@ -534,13 +507,10 @@ napi_value SoundPoolNapi::JsSetRate(napi_env env, napi_callback_info info) MEDIA_LOGI("The js thread of SetRate finishes execution and returns"); }, MediaAsyncContext::CompleteCallback, static_cast(asyncCtx.get()), &asyncCtx->work)); NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncCtx->work, napi_qos_user_initiated)); + asyncCtx.release(); } else { - NAPI_CALL(env, napi_create_async_work(env, nullptr, resource, [](napi_env env, void* data) { - MEDIA_LOGD("JsSetRate napi_create_async_work"); - }, MediaAsyncContext::CompleteCallback, static_cast(asyncCtx.get()), &asyncCtx->work)); - NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncCtx->work, napi_qos_user_initiated)); + SoundPoolNapi::SendCompleteEvent(env, std::move(asyncCtx)); } - asyncCtx.release(); return result; } @@ -577,13 +547,10 @@ napi_value SoundPoolNapi::JsSetVolume(napi_env env, napi_callback_info info) MEDIA_LOGI("The js thread of SetVolume finishes execution and returns"); }, MediaAsyncContext::CompleteCallback, static_cast(asyncCtx.get()), &asyncCtx->work)); NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncCtx->work, napi_qos_user_initiated)); + asyncCtx.release(); } else { - NAPI_CALL(env, napi_create_async_work(env, nullptr, resource, [](napi_env env, void* data) { - MEDIA_LOGD("JsSetVolume napi_create_async_work"); - }, MediaAsyncContext::CompleteCallback, static_cast(asyncCtx.get()), &asyncCtx->work)); - NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncCtx->work, napi_qos_user_initiated)); + SoundPoolNapi::SendCompleteEvent(env, std::move(asyncCtx)); } - asyncCtx.release(); return result; } @@ -625,13 +592,10 @@ napi_value SoundPoolNapi::JsUnload(napi_env env, napi_callback_info info) asyncCtx->soundId_); }, MediaAsyncContext::CompleteCallback, static_cast(asyncCtx.get()), &asyncCtx->work)); NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncCtx->work, napi_qos_user_initiated)); + asyncCtx.release(); } else { - NAPI_CALL(env, napi_create_async_work(env, nullptr, resource, [](napi_env env, void* data) { - MEDIA_LOGD("JsUnload napi_create_async_work"); - }, MediaAsyncContext::CompleteCallback, static_cast(asyncCtx.get()), &asyncCtx->work)); - NAPI_CALL(env, napi_queue_async_work_with_qos(env, asyncCtx->work, napi_qos_user_initiated)); + SoundPoolNapi::SendCompleteEvent(env, std::move(asyncCtx)); } - asyncCtx.release(); return result; } @@ -908,6 +872,16 @@ int32_t SoundPoolNapi::ParserVolumeOptionFromJs(std::unique_ptr asyncCtx) +{ + auto ret = MediaAsyncContext::SendCompleteEvent(env, asyncCtx.get(), napi_eprio_immediate); + if (ret != napi_status::napi_ok) { + MEDIA_LOGE("failed to SendEvent, ret = %{public}d", ret); + } else { + asyncCtx.release(); + } +} + void SoundPoolNapi::ErrorCallback(int32_t errCode, const std::string &operate, const std::string &add) { MEDIA_LOGE("failed to %{public}s, errCode = %{public}d", operate.c_str(), errCode); diff --git a/frameworks/native/audio_haptic/audio_haptic_manager_impl.cpp b/frameworks/native/audio_haptic/audio_haptic_manager_impl.cpp index 1c77d2049eaf2cffe771c0135ecfe677a7663965..745fa8b3f8512007d3c783b31d9c8a3a9e21657c 100644 --- a/frameworks/native/audio_haptic/audio_haptic_manager_impl.cpp +++ b/frameworks/native/audio_haptic/audio_haptic_manager_impl.cpp @@ -97,18 +97,7 @@ AudioHapticManagerImpl::~AudioHapticManagerImpl() { for (auto &[sourceId, info] : audioHapticPlayerMap_) { (void)sourceId; - if (!info->audioUri_.empty()) { - int32_t fd = ExtractFd(info->audioUri_); - if (fd != ERROR) { - close(fd); - } - } - if (!info->hapticSource_.hapticUri.empty()) { - int32_t fd = ExtractFd(info->hapticSource_.hapticUri); - if (fd != ERROR) { - close(fd); - } - } + ReleasePlayerInfo(info); } audioHapticPlayerMap_.clear(); curPlayerIndex_ = 0; @@ -120,19 +109,20 @@ int32_t AudioHapticManagerImpl::RegisterSourceWithEffectId(const std::string &au std::lock_guard lock(audioHapticManagerMutex_); if (effectId == "") { MEDIA_LOGE("RegisterSourceWithEffectId failed. The effectId is empty!"); - return -1; + return INVALID_SOURCE_ID; } if (curPlayerCount_ >= MAX_PLAYER_NUM) { MEDIA_LOGE("RegisterSourceWithEffectId failed. curPlayerCount_: %{public}d", curPlayerCount_); - return -1; + return INVALID_SOURCE_ID; } curPlayerIndex_ = (curPlayerIndex_ + 1) % MAX_PLAYER_NUM; while (audioHapticPlayerMap_[curPlayerIndex_] != nullptr) { curPlayerIndex_ = (curPlayerIndex_ + 1) % MAX_PLAYER_NUM; } int32_t sourceId = curPlayerIndex_; - HapticSource sourceUri = {"", effectId}; - audioHapticPlayerMap_[sourceId] = std::make_shared(audioUri, sourceUri, + AudioSource audioSrc = {.audioUri = audioUri}; + HapticSource hapticSrc = {.effectId = effectId}; + audioHapticPlayerMap_[sourceId] = std::make_shared(audioSrc, hapticSrc, AUDIO_LATENCY_MODE_FAST, AudioStandard::StreamUsage::STREAM_USAGE_MUSIC); curPlayerCount_ += 1; MEDIA_LOGI("Finish to RegisterSourceWithEffectId. effectId: %{public}s, sourceId: %{public}d", @@ -146,7 +136,7 @@ int32_t AudioHapticManagerImpl::RegisterSource(const std::string &audioUri, cons if (curPlayerCount_ >= MAX_PLAYER_NUM) { MEDIA_LOGE("RegisterSource failed curPlayerCount_: %{public}d", curPlayerCount_); - return -1; + return INVALID_SOURCE_ID; } curPlayerIndex_ = (curPlayerIndex_ + 1) % MAX_PLAYER_NUM; while (audioHapticPlayerMap_[curPlayerIndex_] != nullptr) { @@ -156,8 +146,9 @@ int32_t AudioHapticManagerImpl::RegisterSource(const std::string &audioUri, cons std::string hapticUriStr = DupFdFromUri(hapticUri); int32_t sourceId = curPlayerIndex_; - HapticSource sourceUri = {hapticUriStr, ""}; - audioHapticPlayerMap_[sourceId] = std::make_shared(audioUriStr, sourceUri, + AudioSource audioSrc = {.audioUri = audioUriStr}; + HapticSource hapticSrc = {.hapticUri = hapticUriStr}; + audioHapticPlayerMap_[sourceId] = std::make_shared(audioSrc, hapticSrc, AUDIO_LATENCY_MODE_NORMAL, AudioStandard::StreamUsage::STREAM_USAGE_MUSIC); curPlayerCount_ += 1; MEDIA_LOGI("Finish to RegisterSource. audioUri: %{public}s, hapticUri: %{public}s, sourceId: %{public}d", @@ -165,6 +156,40 @@ int32_t AudioHapticManagerImpl::RegisterSource(const std::string &audioUri, cons return sourceId; } +int32_t AudioHapticManagerImpl::RegisterSourceFromFd(const AudioHapticFileDescriptor& audioFd, + const AudioHapticFileDescriptor& hapticFd) +{ + std::lock_guard lock(audioHapticManagerMutex_); + if (curPlayerCount_ >= MAX_PLAYER_NUM) { + MEDIA_LOGE("RegisterSourceFromFd failed curPlayerCount_: %{public}d", curPlayerCount_); + return INVALID_SOURCE_ID; + } + int32_t newAudioFd = dup(audioFd.fd); + if (newAudioFd == FILE_DESCRIPTOR_INVALID) { + MEDIA_LOGE("RegisterSourceFromFd failed invalid audio fd"); + return INVALID_SOURCE_ID; + } + int32_t newHapticFd = dup(hapticFd.fd); + if (newHapticFd == FILE_DESCRIPTOR_INVALID) { + MEDIA_LOGE("RegisterSourceFromFd failed invalid haptic fd"); + return INVALID_SOURCE_ID; + } + + curPlayerIndex_ = (curPlayerIndex_ + 1) % MAX_PLAYER_NUM; + while (audioHapticPlayerMap_[curPlayerIndex_] != nullptr) { + curPlayerIndex_ = (curPlayerIndex_ + 1) % MAX_PLAYER_NUM; + } + int32_t sourceId = curPlayerIndex_; + AudioSource audioSrc = {.fd = newAudioFd, .length = audioFd.length, .offset = audioFd.offset}; + HapticSource hapticSrc = {.fd = newHapticFd, .length = hapticFd.length, .offset = hapticFd.offset}; + audioHapticPlayerMap_[sourceId] = std::make_shared(audioSrc, hapticSrc, + AUDIO_LATENCY_MODE_NORMAL, AudioStandard::StreamUsage::STREAM_USAGE_MUSIC); + curPlayerCount_ += 1; + MEDIA_LOGI("audioFd: %{public}d, hapticeFd: %{public}d, sourceId: %{public}d", + audioFd.fd, hapticFd.fd, sourceId); + return sourceId; +} + int32_t AudioHapticManagerImpl::UnregisterSource(const int32_t &sourceID) { std::lock_guard lock(audioHapticManagerMutex_); @@ -175,18 +200,7 @@ int32_t AudioHapticManagerImpl::UnregisterSource(const int32_t &sourceID) } std::shared_ptr info = audioHapticPlayerMap_[sourceID]; - if (!info->audioUri_.empty()) { - int32_t fd = ExtractFd(info->audioUri_); - if (fd != ERROR) { - close(fd); - } - } - if (!info->hapticSource_.hapticUri.empty()) { - int32_t fd = ExtractFd(info->hapticSource_.hapticUri); - if (fd != ERROR) { - close(fd); - } - } + ReleasePlayerInfo(info); audioHapticPlayerMap_[sourceID] = nullptr; audioHapticPlayerMap_.erase(sourceID); @@ -280,7 +294,7 @@ std::shared_ptr AudioHapticManagerImpl::CreatePlayer(const in std::shared_ptr audioHapticPlayerInfo = audioHapticPlayerMap_[sourceID]; AudioHapticPlayerParam param = AudioHapticPlayerParam(audioHapticPlayerOptions, - audioHapticPlayerInfo->audioUri_, audioHapticPlayerInfo->hapticSource_, + audioHapticPlayerInfo->audioSource_, audioHapticPlayerInfo->hapticSource_, audioHapticPlayerInfo->latencyMode_, audioHapticPlayerInfo->streamUsage_); std::shared_ptr audioHapticPlayer = AudioHapticPlayerFactory::CreateAudioHapticPlayer(param); @@ -290,5 +304,36 @@ std::shared_ptr AudioHapticManagerImpl::CreatePlayer(const in } return audioHapticPlayer; } + +void AudioHapticManagerImpl::ReleasePlayerInfo(const std::shared_ptr& info) +{ + if (info == nullptr) { + return; + } + + auto audioSrc = info->audioSource_; + if (!audioSrc.audioUri.empty()) { + int32_t fd = ExtractFd(audioSrc.audioUri); + if (fd > FILE_DESCRIPTOR_INVALID) { + close(fd); + } + } + int32_t audioFd = audioSrc.fd; + if (audioFd > FILE_DESCRIPTOR_INVALID) { + close(audioFd); + } + + auto hapticSrc = info->hapticSource_; + if (!hapticSrc.hapticUri.empty()) { + int32_t fd = ExtractFd(hapticSrc.hapticUri); + if (fd > FILE_DESCRIPTOR_INVALID) { + close(fd); + } + } + int32_t hapticFd = hapticSrc.fd; + if (hapticFd > FILE_DESCRIPTOR_INVALID) { + close(hapticFd); + } +} } // namesapce AudioStandard } // namespace OHOS diff --git a/frameworks/native/audio_haptic/audio_haptic_manager_impl.h b/frameworks/native/audio_haptic/audio_haptic_manager_impl.h index 9a667bec97034e4d12da2afa887593192db394bb..dc9c9d4315c58c2a2279ae990be48a30f20d4552 100644 --- a/frameworks/native/audio_haptic/audio_haptic_manager_impl.h +++ b/frameworks/native/audio_haptic/audio_haptic_manager_impl.h @@ -22,19 +22,20 @@ namespace OHOS { namespace Media { struct AudioHapticPlayerInfo { - std::string audioUri_; + AudioSource audioSource_; HapticSource hapticSource_; AudioLatencyMode latencyMode_; AudioStandard::StreamUsage streamUsage_; AudioHapticPlayerInfo() {}; - AudioHapticPlayerInfo(const std::string &audioUri, const HapticSource &hapticSource, + AudioHapticPlayerInfo(const AudioSource& audioSource, const HapticSource &hapticSource, const AudioLatencyMode &latencyMode, const AudioStandard::StreamUsage &streamUsage) - : audioUri_(audioUri), + : audioSource_(audioSource), hapticSource_(hapticSource), latencyMode_(latencyMode), streamUsage_(streamUsage) {}; }; +const int32_t INVALID_SOURCE_ID = -1; class AudioHapticManagerImpl : public AudioHapticManager { public: @@ -43,6 +44,9 @@ public: int32_t RegisterSource(const std::string &audioUri, const std::string &hapticUri) override; + int32_t RegisterSourceFromFd(const AudioHapticFileDescriptor& audioFd, + const AudioHapticFileDescriptor& hapticFd) override; + int32_t RegisterSourceWithEffectId(const std::string &audioUri, const std::string &effectId) override; int32_t UnregisterSource(const int32_t &sourceID) override; @@ -57,6 +61,7 @@ public: private: bool CheckAudioLatencyMode(const int32_t &sourceId, const AudioLatencyMode &latencyMode); bool CheckAudioStreamUsage(const AudioStandard::StreamUsage &streamUsage); + void ReleasePlayerInfo(const std::shared_ptr& info); std::unordered_map> audioHapticPlayerMap_; int32_t curPlayerIndex_; diff --git a/frameworks/native/audio_haptic/audio_haptic_player_impl.cpp b/frameworks/native/audio_haptic/audio_haptic_player_impl.cpp index c4ad5ed741a1122787373b016638969528febb2f..d4f73fbea8eaa0d48fabb48784d0d03f5a2d7984 100644 --- a/frameworks/native/audio_haptic/audio_haptic_player_impl.cpp +++ b/frameworks/native/audio_haptic/audio_haptic_player_impl.cpp @@ -29,6 +29,7 @@ namespace OHOS { namespace Media { const int32_t LOAD_WAIT_SECONDS = 2; const int32_t LOAD_WAIT_SECONDS_FOR_LOOP = 40; +const int32_t ERR_OPERATE_NOT_ALLOWED = 5400102; std::mutex AudioHapticPlayerFactory::createPlayerMutex_; @@ -46,7 +47,7 @@ std::shared_ptr AudioHapticPlayerFactory::CreateAudioHapticPl std::mutex AudioHapticSound::createAudioHapticSoundMutex_; std::shared_ptr AudioHapticSound::CreateAudioHapticSound( - const AudioLatencyMode &latencyMode, const std::string &audioUri, const bool &muteAudio, + const AudioLatencyMode &latencyMode, const AudioSource& audioSource, const bool &muteAudio, const AudioStandard::StreamUsage &streamUsage, const bool ¶llelPlayFlag) { if (latencyMode != AUDIO_LATENCY_MODE_NORMAL && latencyMode != AUDIO_LATENCY_MODE_FAST) { @@ -58,11 +59,11 @@ std::shared_ptr AudioHapticSound::CreateAudioHapticSound( std::shared_ptr audioHapticSound = nullptr; switch (latencyMode) { case AUDIO_LATENCY_MODE_NORMAL: - audioHapticSound = std::make_shared(audioUri, muteAudio, streamUsage); + audioHapticSound = std::make_shared(audioSource, muteAudio, streamUsage); break; case AUDIO_LATENCY_MODE_FAST: audioHapticSound = std::make_shared( - audioUri, muteAudio, streamUsage, parallelPlayFlag); + audioSource, muteAudio, streamUsage, parallelPlayFlag); break; default: MEDIA_LOGE("Invalid param: the latency mode %{public}d is unsupported.", latencyMode); @@ -74,8 +75,7 @@ std::shared_ptr AudioHapticSound::CreateAudioHapticSound( AudioHapticPlayerImpl::AudioHapticPlayerImpl() : latencyMode_(AUDIO_LATENCY_MODE_NORMAL), muteAudio_(false), - muteHaptic_(false), - audioUri_("") + muteHaptic_(false) { } @@ -92,7 +92,7 @@ void AudioHapticPlayerImpl::SetPlayerParam(const AudioHapticPlayerParam ¶m) muteAudio_ = param.options.muteAudio; muteHaptic_ = param.options.muteHaptics; parallelPlayFlag_ = param.options.parallelPlayFlag; - audioUri_ = param.audioUri; + audioSource_ = param.audioSource; hapticSource_ = param.hapticSource; latencyMode_ = param.latencyMode; streamUsage_ = param.streamUsage; @@ -102,7 +102,7 @@ void AudioHapticPlayerImpl::LoadPlayer() { // Load audio player audioHapticSound_ = AudioHapticSound::CreateAudioHapticSound( - latencyMode_, audioUri_, muteAudio_, streamUsage_, parallelPlayFlag_); + latencyMode_, audioSource_, muteAudio_, streamUsage_, parallelPlayFlag_); CHECK_AND_RETURN_LOG(audioHapticSound_ != nullptr, "Failed to create audio haptic sound instance"); soundCallback_ = std::make_shared(shared_from_this()); (void)audioHapticSound_->SetAudioHapticSoundCallback(soundCallback_); @@ -129,7 +129,8 @@ int32_t AudioHapticPlayerImpl::Prepare() std::lock_guard lock(audioHapticPlayerLock_); CHECK_AND_RETURN_RET_LOG(audioHapticSound_ != nullptr, MSERR_INVALID_OPERATION, "Audio haptic sound is nullptr"); - CHECK_AND_RETURN_RET_LOG(audioUri_ != "", MSERR_OPEN_FILE_FAILED, "Invalid val: audio uri is empty"); + CHECK_AND_RETURN_RET_LOG(audioSource_.audioUri != "" || audioSource_.fd > INVALID_FD, + MSERR_OPEN_FILE_FAILED, "Invalid val: audioSource"); result = audioHapticSound_->PrepareSound(); CHECK_AND_RETURN_RET_LOG(result == MSERR_OK, result, "Failed to load audio file"); @@ -266,6 +267,30 @@ int32_t AudioHapticPlayerImpl::SetVolume(float volume) return result; } +bool AudioHapticPlayerImpl::IsHapticsIntensityAdjustmentSupported() +{ + std::lock_guard lock(audioHapticPlayerLock_); + if (audioHapticVibrator_ != nullptr) { + return audioHapticVibrator_->IsHdHapticSupported(); + } + return false; +} + +int32_t AudioHapticPlayerImpl::EnableHapticsInSilentMode(bool enable) +{ + int32_t result = MSERR_OK; + MEDIA_LOGI("AudioHapticPlayerImpl::EnableHapticsInSilentMode %{public}d", enable); + std::lock_guard lock(audioHapticPlayerLock_); + + if (isVibrationRunning_.load()) { + return ERR_OPERATE_NOT_ALLOWED; + } + if (audioHapticVibrator_ != nullptr) { + audioHapticVibrator_->EnableHapticsInSilentMode(enable); + } + return result; +} + int32_t AudioHapticPlayerImpl::SetHapticIntensity(float intensity) { MEDIA_LOGI("AudioHapticPlayerImpl::SetHapticIntensity %{public}f", intensity); diff --git a/frameworks/native/audio_haptic/audio_haptic_player_impl.h b/frameworks/native/audio_haptic/audio_haptic_player_impl.h index c259ee97674249dad9575feb0bfef6246400d7a8..9c450ec625fb0debb9022d6a36e703d36d1e79d6 100644 --- a/frameworks/native/audio_haptic/audio_haptic_player_impl.h +++ b/frameworks/native/audio_haptic/audio_haptic_player_impl.h @@ -42,6 +42,8 @@ public: int32_t GetAudioCurrentTime() override; HapticsMode GetHapticsMode() const override; void SetHapticsMode(HapticsMode hapticsMode) override; + int32_t EnableHapticsInSilentMode(bool enable) override; + bool IsHapticsIntensityAdjustmentSupported() override; void SetPlayerParam(const AudioHapticPlayerParam ¶m); void LoadPlayer(); @@ -68,7 +70,7 @@ private: bool muteAudio_; bool muteHaptic_; bool parallelPlayFlag_ = false; - std::string audioUri_; + AudioSource audioSource_; HapticSource hapticSource_; float volume_ = 1.0f; bool loop_ = false; diff --git a/frameworks/native/audio_haptic/audio_haptic_sound_low_latency_impl.cpp b/frameworks/native/audio_haptic/audio_haptic_sound_low_latency_impl.cpp index 23e31edbf60441ba3469699a2179b9caef803e71..5ca0c03b1321eea22130c797e61f1c5858d91eff 100644 --- a/frameworks/native/audio_haptic/audio_haptic_sound_low_latency_impl.cpp +++ b/frameworks/native/audio_haptic/audio_haptic_sound_low_latency_impl.cpp @@ -19,6 +19,7 @@ #include "isoundpool.h" #include "audio_haptic_log.h" +#include "directory_ex.h" #include "media_errors.h" namespace { @@ -30,9 +31,9 @@ namespace Media { const int32_t MAX_SOUND_POOL_STREAMS = 1; // ensure that only one stream for sound pool is playing. const int32_t LOAD_WAIT_SECONDS = 2; -AudioHapticSoundLowLatencyImpl::AudioHapticSoundLowLatencyImpl(const std::string &audioUri, const bool &muteAudio, +AudioHapticSoundLowLatencyImpl::AudioHapticSoundLowLatencyImpl(const AudioSource& audioSource, const bool &muteAudio, const AudioStandard::StreamUsage &streamUsage, const bool ¶llelPlayFlag) - : audioUri_(audioUri), + : audioSource_(audioSource), muteAudio_(muteAudio), parallelPlayFlag_(parallelPlayFlag), streamUsage_(streamUsage) @@ -67,38 +68,49 @@ int32_t AudioHapticSoundLowLatencyImpl::LoadSoundPoolPlayer() CHECK_AND_RETURN_RET_LOG(firstFrameCallback_ != nullptr, MSERR_INVALID_VAL, "Failed to create callback object"); soundPoolPlayer_->SetSoundPoolFrameWriteCallback(firstFrameCallback_); - configuredAudioUri_ = ""; + configuredAudioSource_ = {}; playerState_ = AudioHapticPlayerState::STATE_NEW; return MSERR_OK; } -int32_t AudioHapticSoundLowLatencyImpl::OpenAudioUri(const std::string &audioUri) +int32_t AudioHapticSoundLowLatencyImpl::OpenAudioSource() { if (fileDes_ != -1) { (void)close(fileDes_); fileDes_ = -1; } - const std::string fdHead = "fd://"; - if (audioUri_.find(fdHead) != std::string::npos) { - int32_t fd = atoi(audioUri_.substr(fdHead.size()).c_str()); - CHECK_AND_RETURN_RET_LOG(fd > 0, MSERR_OPEN_FILE_FAILED, "GetAudioUriFd: Failed to extract fd for avplayer."); - fileDes_ = dup(fd); - MEDIA_LOGI("fileDes_ == %{public}d", fileDes_); - } else { - char realPathRes[PATH_MAX + 1] = {'\0'}; - if (audioUri.size() >= PATH_MAX || realpath(audioUri_.c_str(), realPathRes) == nullptr) { - MEDIA_LOGE("Invalid file path length"); - return MSERR_UNSUPPORT_FILE; - } - std::string realPathStr(realPathRes); - fileDes_ = open(realPathStr.c_str(), O_RDONLY); - if (fileDes_ == -1) { - MEDIA_LOGE("GetAudioUriFd: Failed to open the audio uri for sound pool."); - return MSERR_OPEN_FILE_FAILED; + auto audioUri = audioSource_.audioUri; + auto audioFd = audioSource_.fd; + MEDIA_LOGI("Set audio source to soundpool. audioUri [%{public}s], audioFd [%{public}d]", + audioUri.c_str(), audioFd); + CHECK_AND_RETURN_RET_LOG(!audioUri.empty() || audioFd > FILE_DESCRIPTOR_INVALID, MSERR_OPEN_FILE_FAILED, + "AudioUri is empty or invalid audioFd."); + + if (!audioUri.empty()) { + const std::string fdHead = "fd://"; + if (audioUri.find(fdHead) != std::string::npos) { + int32_t fd = atoi(audioUri.substr(fdHead.size()).c_str()); + CHECK_AND_RETURN_RET_LOG(fd > 0, MSERR_OPEN_FILE_FAILED, + "GetAudioUriFd: Failed to extract fd for avplayer."); + fileDes_ = dup(fd); + MEDIA_LOGI("fileDes_ == %{public}d", fileDes_); + } else { + std::string absFilePath; + CHECK_AND_RETURN_RET_LOG(PathToRealPath(audioUri, absFilePath), MSERR_OPEN_FILE_FAILED, + "file is not real path, file path: %{private}s", audioUri.c_str()); + CHECK_AND_RETURN_RET_LOG(!absFilePath.empty(), MSERR_OPEN_FILE_FAILED, + "Failed to obtain the canonical path for source path %{public}d %{private}s", + errno, audioUri.c_str()); + fileDes_ = open(absFilePath.c_str(), O_RDONLY | O_CLOEXEC); } + } else { + fileDes_ = dup(audioFd); } - return fileDes_ != -1 ? MSERR_OK : MSERR_OPEN_FILE_FAILED; + MEDIA_LOGI("AudioHapticSoundLowLatencyImpl::OpenAudioSource fileDes_: %{public}d", fileDes_); + CHECK_AND_RETURN_RET_LOG(fileDes_ > FILE_DESCRIPTOR_INVALID, MSERR_OPEN_FILE_FAILED, + "AudioHapticSoundLowLatencyImpl::OpenAudioSource: Failed to open the audio source for sound pool."); + return MSERR_OK; } int32_t AudioHapticSoundLowLatencyImpl::PrepareSound() @@ -109,17 +121,15 @@ int32_t AudioHapticSoundLowLatencyImpl::PrepareSound() CHECK_AND_RETURN_RET_LOG(result == MSERR_OK && soundPoolPlayer_ != nullptr, MSERR_INVALID_STATE, "Audio haptic player(soundpool) instance is null"); - if (!configuredAudioUri_.empty() && configuredAudioUri_ == audioUri_) { - MEDIA_LOGI("Prepare: The audioUri_ uri has been loaded. Return directly."); + if (!configuredAudioSource_.empty() && configuredAudioSource_ == audioSource_) { + MEDIA_LOGI("Prepare: The audioSource_ has been loaded. Return directly."); return MSERR_OK; } - MEDIA_LOGI("Set audio source to soundpool. audioUri [%{public}s]", audioUri_.c_str()); - result = OpenAudioUri(audioUri_); - CHECK_AND_RETURN_RET_LOG(result == MSERR_OK, result, "Failed to get audio uri fd."); - std::string uri = "fd://" + std::to_string(fileDes_); + result = OpenAudioSource(); + CHECK_AND_RETURN_RET_LOG(result == MSERR_OK, result, "Failed to open audio source."); - int32_t soundID = soundPoolPlayer_->Load(uri); + int32_t soundID = soundPoolPlayer_->Load(fileDes_, audioSource_.offset, audioSource_.length); if (soundID < 0) { MEDIA_LOGE("Prepare: Failed to load soundPool uri."); return MSERR_OPEN_FILE_FAILED; @@ -134,7 +144,7 @@ int32_t AudioHapticSoundLowLatencyImpl::PrepareSound() // The audio source has been loaded for sound pool soundID_ = soundID; - configuredAudioUri_ = audioUri_; + configuredAudioSource_ = audioSource_; playerState_ = AudioHapticPlayerState::STATE_PREPARED; return MSERR_OK; diff --git a/frameworks/native/audio_haptic/audio_haptic_sound_low_latency_impl.h b/frameworks/native/audio_haptic/audio_haptic_sound_low_latency_impl.h index 7665dae48d88f04955d1f05748c1378d1485c1c8..497a4a4ae31f5359e9163aaa10453b076d2a2db8 100644 --- a/frameworks/native/audio_haptic/audio_haptic_sound_low_latency_impl.h +++ b/frameworks/native/audio_haptic/audio_haptic_sound_low_latency_impl.h @@ -24,7 +24,7 @@ namespace Media { class AudioHapticSoundLowLatencyImpl : public AudioHapticSound, public std::enable_shared_from_this { public: - AudioHapticSoundLowLatencyImpl(const std::string &audioUri, const bool &muteAudio, + AudioHapticSoundLowLatencyImpl(const AudioSource& audioSource, const bool &muteAudio, const AudioStandard::StreamUsage &streamUsage, const bool ¶llelPlayFlag = false); ~AudioHapticSoundLowLatencyImpl(); @@ -46,15 +46,15 @@ public: private: int32_t LoadSoundPoolPlayer(); void ReleaseSoundPoolPlayer(); - int32_t OpenAudioUri(const std::string &audioUri); + int32_t OpenAudioSource(); - std::string audioUri_ = ""; + AudioSource audioSource_; bool muteAudio_ = false; bool parallelPlayFlag_ = false; AudioStandard::StreamUsage streamUsage_ = AudioStandard::STREAM_USAGE_UNKNOWN; float volume_ = 1.0f; bool loop_ = false; - std::string configuredAudioUri_ = ""; + AudioSource configuredAudioSource_; std::atomic playerState_ = AudioHapticPlayerState::STATE_NEW; std::weak_ptr audioHapticPlayerCallback_; diff --git a/frameworks/native/audio_haptic/audio_haptic_sound_normal_impl.cpp b/frameworks/native/audio_haptic/audio_haptic_sound_normal_impl.cpp index a7b05d8472fc3cbb69a6efab8dcacf1896b96f06..446dcd8431c16d075bcbf4fe1509f3668a0093ad 100644 --- a/frameworks/native/audio_haptic/audio_haptic_sound_normal_impl.cpp +++ b/frameworks/native/audio_haptic/audio_haptic_sound_normal_impl.cpp @@ -19,6 +19,7 @@ #include #include "audio_haptic_log.h" +#include "directory_ex.h" #include "media_errors.h" #include "player.h" @@ -30,9 +31,9 @@ namespace OHOS { namespace Media { const int32_t LOAD_WAIT_SECONDS = 2; -AudioHapticSoundNormalImpl::AudioHapticSoundNormalImpl(const std::string &audioUri, const bool &muteAudio, +AudioHapticSoundNormalImpl::AudioHapticSoundNormalImpl(const AudioSource& audioSource, const bool &muteAudio, const AudioStandard::StreamUsage &streamUsage) - : audioUri_(audioUri), + : audioSource_(audioSource), muteAudio_(muteAudio), streamUsage_(streamUsage) { @@ -54,7 +55,7 @@ int32_t AudioHapticSoundNormalImpl::LoadAVPlayer() CHECK_AND_RETURN_RET_LOG(avPlayerCallback_ != nullptr, MSERR_INVALID_VAL, "Failed to create callback object"); avPlayer_->SetPlayerCallback(avPlayerCallback_); - configuredAudioUri_ = ""; + configuredAudioSource_ = {}; playerState_ = AudioHapticPlayerState::STATE_NEW; return MSERR_OK; } @@ -66,39 +67,61 @@ int32_t AudioHapticSoundNormalImpl::PrepareSound() int32_t result = LoadAVPlayer(); CHECK_AND_RETURN_RET_LOG(result == MSERR_OK && avPlayer_ != nullptr, MSERR_INVALID_VAL, "Audio haptic player(avplayer) instance is null"); - CHECK_AND_RETURN_RET_LOG(!audioUri_.empty(), MSERR_OPEN_FILE_FAILED, "The audio uri is empty"); - if (audioUri_ != configuredAudioUri_) { + CHECK_AND_RETURN_RET_LOG(!audioSource_.empty(), MSERR_OPEN_FILE_FAILED, "The audio source is empty"); + if (audioSource_ != configuredAudioSource_) { return ResetAVPlayer(); } return MSERR_OK; } +int32_t AudioHapticSoundNormalImpl::OpenAudioSource() +{ + if (fileDes_ != -1) { + (void)close(fileDes_); + fileDes_ = -1; + } + + auto audioUri = audioSource_.audioUri; + auto audioFd = audioSource_.fd; + MEDIA_LOGI("Set audio source to avplayer. audioUri [%{public}s] audioFd: [%{public}d]", + audioUri.c_str(), audioFd); + CHECK_AND_RETURN_RET_LOG(!audioUri.empty() || audioFd > FILE_DESCRIPTOR_INVALID, MSERR_OPEN_FILE_FAILED, + "The audio uri is empty or the fd is invalid"); + + if (!audioUri.empty()) { + const std::string fdHead = "fd://"; + if (audioUri.find(fdHead) != std::string::npos) { + int32_t fd = atoi(audioUri.substr(fdHead.size()).c_str()); + CHECK_AND_RETURN_RET_LOG(fd > FILE_DESCRIPTOR_INVALID, MSERR_OPEN_FILE_FAILED, + "Prepare: Failed to extract fd for avplayer."); + fileDes_ = dup(fd); + } else { + std::string absFilePath; + CHECK_AND_RETURN_RET_LOG(PathToRealPath(audioUri, absFilePath), MSERR_OPEN_FILE_FAILED, + "file is not real path, file path: %{private}s", audioUri.c_str()); + CHECK_AND_RETURN_RET_LOG(!absFilePath.empty(), MSERR_OPEN_FILE_FAILED, + "Failed to obtain the canonical path for source path %{public}d %{private}s", + errno, audioUri.c_str()); + fileDes_ = open(absFilePath.c_str(), O_RDONLY | O_CLOEXEC); + } + } else { + fileDes_ = dup(audioFd); + } + MEDIA_LOGI("fileDes_ == %{public}d", fileDes_); + CHECK_AND_RETURN_RET_LOG(fileDes_ > FILE_DESCRIPTOR_INVALID, MSERR_OPEN_FILE_FAILED, + "Prepare: Invalid fileDes for avplayer."); + return MSERR_OK; +} + int32_t AudioHapticSoundNormalImpl::ResetAVPlayer() { // Reset the player and reload it. MEDIA_LOGI("ResetAVPlayer"); (void)avPlayer_->Reset(); - MEDIA_LOGI("Set audio source to avplayer. audioUri [%{public}s]", audioUri_.c_str()); - const std::string fdHead = "fd://"; - - if (audioUri_.find(fdHead) != std::string::npos) { - int32_t fd = atoi(audioUri_.substr(fdHead.size()).c_str()); - CHECK_AND_RETURN_RET_LOG(fd > 0, MSERR_OPEN_FILE_FAILED, "Prepare: Failed to extract fd for avplayer."); - fileDes_ = dup(fd); - MEDIA_LOGI("fileDes_ == %{public}d", fileDes_); - } else { - char realPathRes[PATH_MAX + 1] = {'\0'}; - CHECK_AND_RETURN_RET_LOG((strlen(audioUri_.c_str()) < PATH_MAX) && - (realpath(audioUri_.c_str(), realPathRes) != nullptr), MSERR_UNSUPPORT_FILE, "Invalid file path length"); - std::string realPathStr(realPathRes); - if (fileDes_ != -1) { - (void)close(fileDes_); - fileDes_ = -1; - } - fileDes_ = open(realPathStr.c_str(), O_RDONLY); - CHECK_AND_RETURN_RET_LOG(fileDes_ != -1, MSERR_OPEN_FILE_FAILED, "Prepare: Failed to open uri for avplayer."); - } - int32_t ret = avPlayer_->SetSource(fileDes_); + int32_t ret = OpenAudioSource(); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "Failed to open audio source."); + + ret = avPlayer_->SetSource(fileDes_, audioSource_.offset, audioSource_.length); CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, MSERR_OPEN_FILE_FAILED, "Set source failed %{public}d", ret); Format format; @@ -123,7 +146,7 @@ int32_t AudioHapticSoundNormalImpl::ResetAVPlayer() (void)avPlayer_->SetVolume(actualVolume, actualVolume); (void)avPlayer_->SetLooping(loop_); - configuredAudioUri_ = audioUri_; + configuredAudioSource_ = audioSource_; playerState_ = AudioHapticPlayerState::STATE_PREPARED; return MSERR_OK; } @@ -135,7 +158,7 @@ int32_t AudioHapticSoundNormalImpl::StartSound() std::lock_guard lock(audioHapticPlayerLock_); CHECK_AND_RETURN_RET_LOG(avPlayer_ != nullptr && playerState_ != AudioHapticPlayerState::STATE_INVALID, MSERR_INVALID_VAL, "StartAVPlayer: no available AVPlayer_"); - CHECK_AND_RETURN_RET_LOG(!audioUri_.empty(), MSERR_OPEN_FILE_FAILED, "The audio uri is empty"); + CHECK_AND_RETURN_RET_LOG(!audioSource_.empty(), MSERR_OPEN_FILE_FAILED, "The audio source is invalid"); if (playerState_ == AudioHapticPlayerState::STATE_RUNNING) { MEDIA_LOGE("The avplayer has been running. Cannot start again"); @@ -144,7 +167,7 @@ int32_t AudioHapticSoundNormalImpl::StartSound() } // Player doesn't support play in stopped state. Hence reinitialise player for making start<-->stop to work - if (playerState_ == AudioHapticPlayerState::STATE_STOPPED || audioUri_ != configuredAudioUri_) { + if (playerState_ == AudioHapticPlayerState::STATE_STOPPED || audioSource_ != configuredAudioSource_) { ResetAVPlayer(); } auto ret = avPlayer_->Play(); diff --git a/frameworks/native/audio_haptic/audio_haptic_sound_normal_impl.h b/frameworks/native/audio_haptic/audio_haptic_sound_normal_impl.h index 814ee8554d2098897c15d3866eff4b354afd4a65..9991b5a94b973aee09226590d2228152340558d5 100644 --- a/frameworks/native/audio_haptic/audio_haptic_sound_normal_impl.h +++ b/frameworks/native/audio_haptic/audio_haptic_sound_normal_impl.h @@ -24,7 +24,7 @@ namespace Media { class AudioHapticSoundNormalImpl : public AudioHapticSound, public std::enable_shared_from_this { public: - AudioHapticSoundNormalImpl(const std::string &audioUri, const bool &muteAudio, + AudioHapticSoundNormalImpl(const AudioSource& audioSource, const bool &muteAudio, const AudioStandard::StreamUsage &streamUsage); ~AudioHapticSoundNormalImpl(); @@ -49,13 +49,14 @@ private: int32_t LoadAVPlayer(); int32_t ResetAVPlayer(); void ReleaseAVPlayer(); + int32_t OpenAudioSource(); - std::string audioUri_ = ""; + AudioSource audioSource_; bool muteAudio_ = false; AudioStandard::StreamUsage streamUsage_ = AudioStandard::STREAM_USAGE_UNKNOWN; float volume_ = 1.0f; bool loop_ = false; - std::string configuredAudioUri_ = ""; + AudioSource configuredAudioSource_; AudioHapticPlayerState playerState_ = AudioHapticPlayerState::STATE_NEW; std::weak_ptr audioHapticPlayerCallback_; diff --git a/frameworks/native/audio_haptic/audio_haptic_vibrator_impl.cpp b/frameworks/native/audio_haptic/audio_haptic_vibrator_impl.cpp index 8749b84b1540fb5ad7fc4c46cb5e69883308ef32..c4e90a969e5ad3c642174e02bb16edf0ffc1151f 100644 --- a/frameworks/native/audio_haptic/audio_haptic_vibrator_impl.cpp +++ b/frameworks/native/audio_haptic/audio_haptic_vibrator_impl.cpp @@ -31,6 +31,15 @@ constexpr uint64_t MILLISECONDS_FOR_ONE_SECOND = 1000; // ms constexpr int32_t PLAYER_BUFFER_TIME = 50; // ms constexpr int32_t MAX_WAITING_LOOP_COUNT = 10; #endif + +int64_t GetCurrentTimeMillis() +{ + return static_cast( + std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch() + ).count() + ); +} } namespace OHOS { @@ -105,41 +114,55 @@ int32_t AudioHapticVibratorImpl::ExtractFd(const std::string& hapticsUri) } int32_t fd = atoi(numberPart.c_str()); - return fd > 0 ? fd : ERROR; + return fd > FILE_DESCRIPTOR_INVALID ? fd : ERROR; } -int32_t AudioHapticVibratorImpl::OpenHapticFile(const std::string &hapticUri) +int32_t AudioHapticVibratorImpl::OpenHapticSource(const HapticSource& hapticSource, int32_t& fd) { #ifdef SUPPORT_VIBRATOR - int32_t newFd = -1; - int32_t oldFd = ExtractFd(hapticUri); - if (oldFd != ERROR) { - newFd = dup(oldFd); - if (newFd == ERROR) { - MEDIA_LOGE("OpenHapticFile: dup failed, file path: %{public}s", hapticUri.c_str()); - return MSERR_OPEN_FILE_FAILED; + std::string hapticUri = hapticSource.hapticUri; + int32_t hapticFd = hapticSource.fd; + MEDIA_LOGI("OpenHapticSource. hapticUri [%{public}s], hapticFd [%{public}d]", + hapticUri.c_str(), hapticFd); + CHECK_AND_RETURN_RET_LOG(!hapticUri.empty() || hapticFd > FILE_DESCRIPTOR_INVALID, MSERR_OPEN_FILE_FAILED, + "hapticUri is empty or invalid hapticFd."); + + if (!hapticUri.empty()) { + int32_t oldFd = ExtractFd(hapticUri); + if (oldFd != ERROR) { + fd = dup(oldFd); + } else { + MEDIA_LOGW("OpenHapticFile: hapticUri is not new format."); + + std::string absFilePath; + if (!PathToRealPath(hapticUri, absFilePath)) { + MEDIA_LOGE("file is not real path, file path: %{private}s", hapticUri.c_str()); + return ERROR; + } + if (absFilePath.empty()) { + MEDIA_LOGE("Failed to obtain the canonical path for source path %{public}d %{private}s", + errno, hapticUri.c_str()); + return ERROR; + } + + fd = open(hapticUri.c_str(), O_RDONLY | O_CLOEXEC); } } else { - MEDIA_LOGW("OpenHapticFile: hapticUri is not new format."); + fd = dup(hapticFd); + } - std::string absFilePath; - if (!PathToRealPath(hapticUri, absFilePath)) { - MEDIA_LOGE("file is not real path, file path: %{private}s", hapticUri.c_str()); - return ERROR; - } - if (absFilePath.empty()) { - MEDIA_LOGE("Failed to obtain the canonical path for source path %{public}d %{private}s", - errno, hapticUri.c_str()); - return ERROR; - } + CHECK_AND_RETURN_RET_LOG(fd > FILE_DESCRIPTOR_INVALID, MSERR_OPEN_FILE_FAILED, + "OpenHapticSource: open source failed, file path: %{public}s, fd: %{public}d", hapticUri.c_str(), hapticFd); +#endif + return MSERR_OK; +} - newFd = open(hapticUri.c_str(), O_RDONLY); - if (newFd == ERROR) { - // open file failed, return. - MEDIA_LOGE("OpenHapticFile: open file failed, file path: %{public}s", hapticUri.c_str()); - return MSERR_OPEN_FILE_FAILED; - } - } +int32_t AudioHapticVibratorImpl::OpenHapticFile(const HapticSource& hapticSource) +{ +#ifdef SUPPORT_VIBRATOR + int32_t newFd = FILE_DESCRIPTOR_INVALID; + int32_t ret = OpenHapticSource(hapticSource, newFd); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "OpenHapticFile: open file failed"); vibratorFD_ = std::make_shared(); CHECK_AND_RETURN_RET_LOG(vibratorFD_ != nullptr, ERROR, "vibratorFD_ is null"); @@ -149,8 +172,8 @@ int32_t AudioHapticVibratorImpl::OpenHapticFile(const std::string &hapticUri) struct stat64 statbuf = { 0 }; if (fstat64(newFd, &statbuf) == 0) { vibratorFD_->fd = newFd; - vibratorFD_->offset = 0; - vibratorFD_->length = statbuf.st_size; + vibratorFD_->offset = hapticSource.offset; + vibratorFD_->length = hapticSource.length > 0 ? hapticSource.length : statbuf.st_size; return MSERR_OK; } else { close(newFd); @@ -179,7 +202,7 @@ int32_t AudioHapticVibratorImpl::PreLoad(const HapticSource &hapticSource, vibratorUsage_ = VibratorUsage::USAGE_MEDIA; } hapticSource_ = hapticSource; - if (hapticSource.hapticUri == "") { + if (hapticSource.hapticUri == "" && hapticSource.fd == FILE_DESCRIPTOR_INVALID) { bool isSupported = false; int32_t effectResult = Sensors::IsSupportEffect(hapticSource.effectId.c_str(), &isSupported); if (effectResult == 0 && isSupported) { @@ -192,7 +215,7 @@ int32_t AudioHapticVibratorImpl::PreLoad(const HapticSource &hapticSource, } } - if (OpenHapticFile(hapticSource.hapticUri) != MSERR_OK) { + if (OpenHapticFile(hapticSource) != MSERR_OK) { return MSERR_OPEN_FILE_FAILED; } @@ -208,10 +231,19 @@ int32_t AudioHapticVibratorImpl::SetHapticIntensity(float intensity) { MEDIA_LOGI("SetHapticIntensity for effectId source. intensity: %{public}f", intensity); std::lock_guard lock(vibrateMutex_); + int32_t result = MSERR_OK; #ifdef SUPPORT_VIBRATOR vibrateIntensity_ = intensity; + vibratorParameter_.intensity = intensity; + if (isRunning_) { + if (isIntensityChanged_) { + result = ERROR; + } else { + result = SeekAndRestart(); + } + } #endif - return MSERR_OK; + return result; } int32_t AudioHapticVibratorImpl::Release() @@ -229,6 +261,10 @@ int32_t AudioHapticVibratorImpl::Release() Sensors::FreeVibratorPackage(*vibratorPkg_); vibratorPkg_ = nullptr; } + if (seekVibratorPkg_ != nullptr) { + Sensors::FreeVibratorPackage(*seekVibratorPkg_); + seekVibratorPkg_ = nullptr; + } vibratorFD_ = nullptr; #endif @@ -273,7 +309,7 @@ int32_t AudioHapticVibratorImpl::StartVibrateWithEffect() int32_t result = MSERR_OK; #ifdef SUPPORT_VIBRATOR std::lock_guard lock(vibrateMutex_); - (void)Sensors::SetUsage(vibratorUsage_); + (void)Sensors::SetUsage(vibratorUsage_, enableInSilentMode_); MEDIA_LOGI("PlayPrimitiveEffect with effectId: %{public}s", hapticSource_.effectId.c_str()); result = Sensors::PlayPrimitiveEffect(hapticSource_.effectId.c_str(), vibrateIntensity_); if (result != 0) { @@ -284,6 +320,42 @@ int32_t AudioHapticVibratorImpl::StartVibrateWithEffect() return result; } +int32_t AudioHapticVibratorImpl::PlayVibrateForSoundPool( + const std::shared_ptr& vibratorPkg, + std::unique_lock& lock +) +{ + int32_t result = MSERR_OK; +#ifdef SUPPORT_VIBRATOR + vibrationTimeElapsed_ = 0; + patternStartTime_ = 0; + // record the pattern time which has been played + int32_t vibrateTime = audioHapticPlayer_.GetAudioCurrentTime(); + for (int32_t i = 0; i < vibratorPkg->patternNum; ++i) { + result = PlayVibrationPattern(vibratorPkg, i, vibrateTime, lock); + CHECK_AND_RETURN_RET_LOG(result == 0, result, "AudioHapticVibratorImpl::PlayVibrateForSoundPool failed."); + if (isStopped_) { + return result; + } + if (isNeedRestart_) { + break; + } + } + + if (isNeedRestart_ && seekVibratorPkg_ != nullptr) { + isNeedRestart_ = false; + MEDIA_LOGI("AudioHapticVibratorImpl::PlayVibrateForSoundPool change intensity and restart."); + result = PlayVibrateForSoundPool(seekVibratorPkg_, lock); + if (Sensors::FreeVibratorPackage(*seekVibratorPkg_) == MSERR_OK) { + seekVibratorPkg_ = nullptr; + } + } + vibrationTimeElapsed_ = 0; + patternStartTime_ = 0; +#endif + return result; +} + int32_t AudioHapticVibratorImpl::StartVibrateForSoundPool() { std::unique_lock lock(vibrateMutex_); @@ -300,53 +372,53 @@ int32_t AudioHapticVibratorImpl::StartVibrateForSoundPool() AudioHapticPlayerImpl::SendHapticPlayerEvent(MSERR_INVALID_OPERATION, "VIBRATOR_NOT_PREPARE"); return MSERR_INVALID_OPERATION; } - int32_t vibrateTime = 0; // record the pattern time which has been played - for (int32_t i = 0; i < vibratorPkg_->patternNum; ++i) { - int32_t patternTime = vibratorPkg_->patterns[i].time - vibrateTime; // calculate the time of single pattern - vibrateTime = vibratorPkg_->patterns[i].time; - (void)vibrateCV_.wait_for(lock, std::chrono::milliseconds(patternTime), - [this]() { return isStopped_; }); - CHECK_AND_RETURN_RET_LOG(!isStopped_, result, - "StartVibrateForSoundPool: Stop() is call when waiting"); - (void)Sensors::SetUsage(vibratorUsage_); - MEDIA_LOGI("PlayPattern for SoundPool."); - result = Sensors::PlayPattern(vibratorPkg_->patterns[i]); - if (result != 0) { - MEDIA_LOGE("Failed to PlayPattern for SoundPool. Error %{public}d", result); - return result; - } - } + isRunning_.store(true); + result = PlayVibrateForSoundPool(vibratorPkg_, lock); + isRunning_.store(false); + isIntensityChanged_.store(false); #endif return result; } -int32_t AudioHapticVibratorImpl::RunVibrationPatterns(std::unique_lock &lock) +int32_t AudioHapticVibratorImpl::RunVibrationPatterns(const std::shared_ptr& vibratorPkg, + std::unique_lock &lock) { int32_t result = MSERR_OK; #ifdef SUPPORT_VIBRATOR - int32_t vibrateTime = 0; // record the pattern time which has been played - for (int32_t i = 0; i < vibratorPkg_->patternNum; ++i) { - int32_t patternTime = vibratorPkg_->patterns[i].time - vibrateTime; // calculate the time of single pattern - vibrateTime = vibratorPkg_->patterns[i].time; - (void)vibrateCV_.wait_for(lock, std::chrono::milliseconds(patternTime), - [this]() { return isStopped_; }); - CHECK_AND_RETURN_RET_LOG(!isStopped_, result, - "RunVibrationPatterns: Stop() is call when waiting"); - (void)Sensors::SetUsage(vibratorUsage_); - MEDIA_LOGI("PlayPattern for NonSyncVibration"); - result = Sensors::PlayPattern(vibratorPkg_->patterns[i]); - if (result != 0) { - MEDIA_LOGE("Failed to PlayPattern for NonSyncVibration. Error %{public}d", result); + vibrationTimeElapsed_ = 0; + patternStartTime_ = 0; + // record the pattern time which has been played + int32_t vibrateTime = audioHapticPlayer_.GetAudioCurrentTime(); + for (int32_t i = 0; i < vibratorPkg->patternNum; ++i) { + result = PlayVibrationPattern(vibratorPkg, i, vibrateTime, lock); + CHECK_AND_RETURN_RET_LOG(result == 0, result, "AudioHapticVibratorImpl::PlayVibrateForSoundPool failed."); + if (isStopped_) { return result; } - if (i == vibratorPkg_->patternNum - 1) { - int32_t lastPatternDuration = vibratorPkg_->patterns[i].patternDuration; + if (isNeedRestart_) { + break; + } + if (i == vibratorPkg->patternNum - 1) { + int32_t lastPatternDuration = vibratorPkg->patterns[i].patternDuration; (void)vibrateCV_.wait_for(lock, std::chrono::milliseconds(lastPatternDuration), - [this]() { return isStopped_; }); + [this]() { return isStopped_ || isNeedRestart_; }); CHECK_AND_RETURN_RET_LOG(!isStopped_, result, "RunVibrationPatterns: Stop() is call when waiting"); + if (isNeedRestart_) { + break; + } + } + } + if (isNeedRestart_ && seekVibratorPkg_ != nullptr) { + isNeedRestart_ = false; + MEDIA_LOGI("AudioHapticVibratorImpl::RunVibrationPatterns change intensity and restart."); + result = RunVibrationPatterns(seekVibratorPkg_, lock); + if (Sensors::FreeVibratorPackage(*seekVibratorPkg_) == MSERR_OK) { + seekVibratorPkg_ = nullptr; } } + vibrationTimeElapsed_ = 0; + patternStartTime_ = 0; #endif return result; } @@ -366,7 +438,10 @@ int32_t AudioHapticVibratorImpl::StartNonSyncVibration() return MSERR_INVALID_OPERATION; } while (!isStopped_) { - result = RunVibrationPatterns(lock); + isRunning_ = true; + result = RunVibrationPatterns(vibratorPkg_, lock); + isRunning_ = false; + isIntensityChanged_ = false; if (result != MSERR_OK) { MEDIA_LOGI("StartNonSyncVibration: RunVibrationPatterns fail."); return result; @@ -390,7 +465,10 @@ int32_t AudioHapticVibratorImpl::StartNonSyncOnceVibration() MEDIA_LOGE("Vibration source file is not prepared. Can not start vibrating"); return MSERR_INVALID_OPERATION; } - result = RunVibrationPatterns(lock); + isRunning_ = true; + result = RunVibrationPatterns(vibratorPkg_, lock); + isRunning_ = false; + isIntensityChanged_ = false; if (result != MSERR_OK) { MEDIA_LOGI("StartNonSyncOnceVibration: RunVibrationPatterns fail."); return result; @@ -399,60 +477,131 @@ int32_t AudioHapticVibratorImpl::StartNonSyncOnceVibration() return result; } -int32_t AudioHapticVibratorImpl::StartVibrateForAVPlayer() +int32_t AudioHapticVibratorImpl::PlayVibrationPattern( + const std::shared_ptr& vibratorPkg, + int32_t patternIndex, + int32_t& vibrateTime, + std::unique_lock& lock +) { - std::unique_lock lock(vibrateMutex_); - if (isStopped_) { - MEDIA_LOGW("Vibrator has been stopped. Return ok immediately"); - return MSERR_OK; + int32_t result = MSERR_OK; +#ifdef SUPPORT_VIBRATOR + // the delay time of first frame has been handled in audio haptic player + // calculate the time of single pattern + MEDIA_LOGI("AudioHapticVibratorImpl::PlayVibrationPattern pattern time %{public}d", + vibratorPkg->patterns[patternIndex].time); + int32_t patternTime = vibratorPkg->patterns[patternIndex].time - vibrateTime; + (void)vibrateCV_.wait_for(lock, std::chrono::milliseconds(patternTime < 0 ? 0 : patternTime), + [this]() { return isStopped_ || isNeedRestart_; }); + CHECK_AND_RETURN_RET_LOG(!isStopped_ && !isNeedRestart_, result, + "AudioHapticVibratorImpl::PlayVibrationPattern: Stop() is call when waiting"); + (void)Sensors::SetUsage(vibratorUsage_, enableInSilentMode_); + (void)Sensors::SetParameters(vibratorParameter_); + MEDIA_LOGI("AudioHapticVibratorImpl::PlayVibrationPattern."); + patternStartTime_ = GetCurrentTimeMillis(); + if (patternIndex > 0) { + vibrationTimeElapsed_ += vibratorPkg->patterns[patternIndex - 1].patternDuration; } + result = Sensors::PlayPattern(vibratorPkg->patterns[patternIndex]); + CHECK_AND_RETURN_RET_LOG(result == 0, result, + "AudioHapticVibratorImpl::PlayVibrationPattern: Failed to PlayPattern. Error %{public}d", result); +#endif + return result; +} +int32_t AudioHapticVibratorImpl::PlayVibrateForAVPlayer(const std::shared_ptr& vibratorPkg, + std::unique_lock& lock) +{ int32_t result = MSERR_OK; #ifdef SUPPORT_VIBRATOR - if (vibratorPkg_ == nullptr || vibratorFD_ == nullptr) { - MEDIA_LOGE("Vibration source file is not prepared. Can not start vibrating"); - return MSERR_INVALID_OPERATION; - } - int32_t vibrateTime = 0; // record the pattern time which has been played - for (int32_t i = 0; i < vibratorPkg_->patternNum; ++i) { - // the delay time of first frame has been handled in audio haptic player - int32_t patternTime = vibratorPkg_->patterns[i].time - vibrateTime; // calculate the time of single pattern - (void)vibrateCV_.wait_for(lock, std::chrono::milliseconds(patternTime), - [this]() { return isStopped_; }); - CHECK_AND_RETURN_RET_LOG(!isStopped_, result, - "StartVibrateForAVPlayer: Stop() is call when waiting"); - (void)Sensors::SetUsage(vibratorUsage_); - MEDIA_LOGI("PlayPattern for AVPlayer successfully!"); - result = Sensors::PlayPattern(vibratorPkg_->patterns[i]); + vibrationTimeElapsed_ = 0; + patternStartTime_ = 0; + // record the pattern time which has been played + int32_t vibrateTime = audioHapticPlayer_.GetAudioCurrentTime(); + MEDIA_LOGI("AudioHapticVibratorImpl::PlayVibrateForAVPlayer: now: %{public}d", vibrateTime); + for (int32_t i = 0; i < vibratorPkg->patternNum; ++i) { + result = PlayVibrationPattern(vibratorPkg, i, vibrateTime, lock); AudioHapticPlayerImpl::SendHapticPlayerEvent(result, "PLAY_PATTERN_AVPLAYER"); - CHECK_AND_RETURN_RET_LOG(result == 0, result, - "Failed to PlayPattern for AVPlayer. Error %{public}d", result); - + CHECK_AND_RETURN_RET_LOG(result == 0, result, "AudioHapticVibratorImpl::PlayVibrateForAVPlayer failed."); + if (isStopped_) { + return result; + } // get the audio time every second and handle the delay time - if (i + 1 >= vibratorPkg_->patternNum) { - // the last pattern has been played, break. + if (isNeedRestart_ || i + 1 >= vibratorPkg->patternNum) { + // need restart or the last pattern has been played, break. break; } - int32_t nextVibratorTime = vibratorPkg_->patterns[i + 1].time; + int32_t nextVibratorTime = vibratorPkg->patterns[i + 1].time; vibrateTime = audioHapticPlayer_.GetAudioCurrentTime() - PLAYER_BUFFER_TIME + GetDelayTime(); int32_t count = 0; while (nextVibratorTime - vibrateTime > MIN_WAITING_TIME_FOR_VIBRATOR && count < MAX_WAITING_LOOP_COUNT) { (void)vibrateCV_.wait_for(lock, std::chrono::milliseconds(MILLISECONDS_FOR_ONE_SECOND), - [this]() { return isStopped_; }); + [this]() { return isStopped_ || isNeedRestart_; }); CHECK_AND_RETURN_RET_LOG(!isStopped_, result, - "StartVibrateForAVPlayer: Stop() is call when waiting"); + "PlayVibrateForAVPlayer: Stop() is call when waiting"); + if (isNeedRestart_) { + break; + } vibrateTime = audioHapticPlayer_.GetAudioCurrentTime() - PLAYER_BUFFER_TIME + GetDelayTime(); count++; } if (count == MAX_WAITING_LOOP_COUNT) { - MEDIA_LOGE("StartVibrateForAVPlayer: loop count has reached the max value."); + MEDIA_LOGE("PlayVibrateForAVPlayer: loop count has reached the max value."); return MSERR_INVALID_OPERATION; } } + if (isNeedRestart_ && seekVibratorPkg_ != nullptr) { + isNeedRestart_ = false; + MEDIA_LOGI("AudioHapticVibratorImpl::PlayVibrateForAVPlayer change intensity and restart."); + result = PlayVibrateForAVPlayer(seekVibratorPkg_, lock); + if (Sensors::FreeVibratorPackage(*seekVibratorPkg_) == MSERR_OK) { + seekVibratorPkg_ = nullptr; + } + } + vibrationTimeElapsed_ = 0; + patternStartTime_ = 0; #endif return result; } +int32_t AudioHapticVibratorImpl::StartVibrateForAVPlayer() +{ + std::unique_lock lock(vibrateMutex_); + if (isStopped_) { + MEDIA_LOGW("Vibrator has been stopped. Return ok immediately"); + return MSERR_OK; + } + + int32_t result = MSERR_OK; +#ifdef SUPPORT_VIBRATOR + if (vibratorPkg_ == nullptr || vibratorFD_ == nullptr) { + MEDIA_LOGE("Vibration source file is not prepared. Can not start vibrating"); + return MSERR_INVALID_OPERATION; + } + isRunning_.store(true); + result = PlayVibrateForAVPlayer(vibratorPkg_, lock); + isRunning_.store(false); + isIntensityChanged_.store(false); +#endif + return result; +} + +int32_t AudioHapticVibratorImpl::SeekAndRestart() +{ + seekVibratorPkg_ = std::make_shared(); + auto duration = GetCurrentTimeMillis() - patternStartTime_; + MEDIA_LOGI("AudioHapticVibratorImpl::SeekAndRestart vibrationTimeElapsed_: %{public}d duration: %{public}" PRId64, + vibrationTimeElapsed_.load(), duration); + int32_t result = Sensors::SeekTimeOnPackage(vibrationTimeElapsed_ + duration, *vibratorPkg_, *seekVibratorPkg_); + CHECK_AND_RETURN_RET_LOG(result == MSERR_OK, result, + "AudioHapticVibratorImpl::SeekAndRestart SeekTimeOnPackage error"); + isNeedRestart_ = true; + isIntensityChanged_ = true; + (void)Sensors::Cancel(); + vibrateCV_.notify_one(); + return MSERR_OK; +} + int32_t AudioHapticVibratorImpl::StopVibrate() { std::lock_guard lock(vibrateMutex_); @@ -474,5 +623,16 @@ int32_t AudioHapticVibratorImpl::GetDelayTime() #endif return delayTime; } + +bool AudioHapticVibratorImpl::IsHdHapticSupported() +{ + std::lock_guard lock(vibrateMutex_); + int32_t result = false; +#ifdef SUPPORT_VIBRATOR + result = Sensors::IsHdHapticSupported(); + MEDIA_LOGI("AudioHapticVibratorImpl::IsHdHapticSupported: %{public}d", result); +#endif + return result; +} } // namesapce Media } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/audio_haptic/audio_haptic_vibrator_impl.h b/frameworks/native/audio_haptic/audio_haptic_vibrator_impl.h index a07201c5907991d20a388416e825cee9adec4eda..5839cd0c51c72bed34630035de268b8ed62bc998 100644 --- a/frameworks/native/audio_haptic/audio_haptic_vibrator_impl.h +++ b/frameworks/native/audio_haptic/audio_haptic_vibrator_impl.h @@ -41,6 +41,11 @@ public: int32_t StopVibrate() override; int32_t GetDelayTime() override; void SetIsSupportEffectId(bool isSupport); + bool IsHdHapticSupported() override; + void EnableHapticsInSilentMode(bool enable) override + { + enableInSilentMode_ = enable; + } private: int32_t StartVibrateForSoundPool(); @@ -48,9 +53,20 @@ private: int32_t StartVibrateForAVPlayer(); int32_t StartNonSyncVibration(); int32_t StartNonSyncOnceVibration(); - int32_t RunVibrationPatterns(std::unique_lock &lock); - int32_t OpenHapticFile(const std::string &hapticUri); + int32_t RunVibrationPatterns(const std::shared_ptr& vibratorPkg, + std::unique_lock &lock); + int32_t OpenHapticSource(const HapticSource& hapticSource, int32_t& fd); + int32_t OpenHapticFile(const HapticSource& hapticSource); int32_t ExtractFd(const std::string& hapticsUri); + int32_t PlayVibrationPattern(const std::shared_ptr& vibratorPkg, + int32_t patternIndex, + int32_t& vibrateTime, + std::unique_lock& lock); + int32_t PlayVibrateForAVPlayer(const std::shared_ptr& vibratorPkg, + std::unique_lock& lock); + int32_t PlayVibrateForSoundPool(const std::shared_ptr& vibratorPkg, + std::unique_lock& lock); + int32_t SeekAndRestart(); AudioHapticPlayer &audioHapticPlayer_; @@ -58,14 +74,22 @@ private: VibratorUsage vibratorUsage_ = VibratorUsage::USAGE_UNKNOWN; std::shared_ptr vibratorFD_ = nullptr; std::shared_ptr vibratorPkg_ = nullptr; + std::shared_ptr seekVibratorPkg_ = nullptr; std::condition_variable vibrateCV_; float vibrateIntensity_ = 1.0f; bool isSupportEffectId_ = false; HapticSource hapticSource_; + bool enableInSilentMode_ = false; #endif std::mutex vibrateMutex_; AudioStandard::StreamUsage streamUsage_ = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool isStopped_ = false; + std::atomic vibrationTimeElapsed_ = 0; + std::atomic patternStartTime_ = 0; + VibratorParameter vibratorParameter_; + std::atomic isRunning_ = false; + std::atomic isIntensityChanged_ = false; + std::atomic isNeedRestart_ = false; }; } // namespace Media } // namespace OHOS diff --git a/frameworks/native/avmetadatahelper/test/unittest/src/avmetadata_unit_test.cpp b/frameworks/native/avmetadatahelper/test/unittest/src/avmetadata_unit_test.cpp index 9d21b29538ffdab9b740fd532d1322c8b86fc92f..5327d18d671f24eefe93b506449d049e138e0d5f 100644 --- a/frameworks/native/avmetadatahelper/test/unittest/src/avmetadata_unit_test.cpp +++ b/frameworks/native/avmetadatahelper/test/unittest/src/avmetadata_unit_test.cpp @@ -780,7 +780,7 @@ HWTEST_F(AVMetadataUnitTest, PtsAndFrameIndexConversion_API_0200, Level2) } /** - * @tc.number : PTSOutOfRange_1000 + * @tc.number : PTSOutOfRange_0100 * @tc.name : SetSource camera_info_parser.mp4 * @tc.desc : pts out of range */ @@ -795,7 +795,6 @@ HWTEST_F(AVMetadataUnitTest, PTSOutOfRange_API_0100, Level2) uint64_t time = 999999999; uint32_t index = 0; ASSERT_NE(MSERR_OK, helper->GetFrameIndexByTime(time, index)); - ASSERT_EQ(index, 0); } /** @@ -814,7 +813,6 @@ HWTEST_F(AVMetadataUnitTest, IndexOutOfRange_API_0100, Level2) uint64_t time = 0; uint32_t index = 9999999; ASSERT_NE(MSERR_OK, helper->GetTimeByFrameIndex(index, time)); - ASSERT_EQ(time, 0); } /** diff --git a/frameworks/native/capi/player/native_avplayer.cpp b/frameworks/native/capi/player/native_avplayer.cpp index 1ebacd26ad05d0eb625c86d7d546a17bd4b8d0fb..66fd6796d8efe97c873ade0d40c74743677fd60f 100644 --- a/frameworks/native/capi/player/native_avplayer.cpp +++ b/frameworks/native/capi/player/native_avplayer.cpp @@ -532,7 +532,7 @@ void NativeAVPlayerCallback::OnSpeedDoneCb(const int32_t extra, const Format &in void NativeAVPlayerCallback::OnPlaybackRateDoneCb(const int32_t extra, const Format &infoBody) { - (void)infoBody; + (void)extra; CHECK_AND_RETURN_LOG(isSourceLoaded_.load(), "OnPlaybackRateDoneCb current source is unready"); float rate = 0.0f; (void)infoBody.GetFloatValue(PlayerKeys::PLAYER_PLAYBACK_RATE, rate); diff --git a/frameworks/native/capi/screencapture/native_avscreen_capture.cpp b/frameworks/native/capi/screencapture/native_avscreen_capture.cpp index 50c3088263fc4120e07fe81265a00818f4ea6095..b3d2aef135481c6fd7f428763a67ee8018fad1ae 100644 --- a/frameworks/native/capi/screencapture/native_avscreen_capture.cpp +++ b/frameworks/native/capi/screencapture/native_avscreen_capture.cpp @@ -916,7 +916,7 @@ OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SetCaptureContentChangedCallback( if (screenCaptureObj->callback_ == nullptr || !screenCaptureObj->callback_->SetCaptureContentChangedCallback(callback, userData)) { MEDIA_LOGE("OH_AVScreenCapture_SetCaptureContentChangedCallback error"); - return AV_SCREEN_CAPTURE_ERR_NO_MEMORY; + return AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT; } MEDIA_LOGD("OH_AVScreenCapture_SetCaptureContentChangedCallback E"); return AV_SCREEN_CAPTURE_ERR_OK; @@ -1175,4 +1175,17 @@ OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SetCaptureArea(struct OH_AVScreen "SetCaptureArea failed!"); MEDIA_LOGD("OH_AVScreenCapture_SetCaptureArea E"); return AV_SCREEN_CAPTURE_ERR_OK; +} + +OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_StrategyForPrivacyMaskMode( + OH_AVScreenCapture_CaptureStrategy *strategy, int32_t value) +{ + MEDIA_LOGD("OH_AVScreenCapture_StrategyForPrivacyMaskMode S"); + CHECK_AND_RETURN_RET_LOG(strategy != nullptr, AV_SCREEN_CAPTURE_ERR_INVALID_VAL, "input strategy is nullptr!"); + struct ScreenCaptureStrategyObject *strategyObj = reinterpret_cast(strategy); + CHECK_AND_RETURN_RET_LOG(strategyObj != nullptr, AV_SCREEN_CAPTURE_ERR_INVALID_VAL, "strategyObj is nullptr"); + CHECK_AND_RETURN_RET_LOG(value == 0 || value == 1, AV_SCREEN_CAPTURE_ERR_INVALID_VAL, "input value is invalid"); + strategyObj->strategy.strategyForPrivacyMaskMode = value; + MEDIA_LOGD("OH_AVScreenCapture_StrategyForPrivacyMaskMode E"); + return AV_SCREEN_CAPTURE_ERR_OK; } \ No newline at end of file diff --git a/frameworks/native/media_service_helper/BUILD.gn b/frameworks/native/media_service_helper/BUILD.gn index ebda51ead0742357be46daccb3a34e7c66b262bd..a4124df862ed642975b5d111bfae27fa1609d0bb 100644 --- a/frameworks/native/media_service_helper/BUILD.gn +++ b/frameworks/native/media_service_helper/BUILD.gn @@ -16,13 +16,13 @@ import("//foundation/multimedia/player_framework/config.gni") MEDIA_ROOT_DIR = "//foundation/multimedia/player_framework" -config("media_public_config") { +config("media_helper_public_config") { include_dirs = [ "$MEDIA_ROOT_DIR/interfaces/inner_api/native/media_service_helper", ] } -config("media_client_ipc_config") { +config("media_helper_ipc_config") { include_dirs = [ "$MEDIA_ROOT_DIR/services/services/common", "$MEDIA_ROOT_DIR/services/services/monitor/client", @@ -30,7 +30,7 @@ config("media_client_ipc_config") { ] } -config("media_client_base_config") { +config("media_helper_base_config") { include_dirs = [ "$MEDIA_ROOT_DIR/services/include", "$MEDIA_ROOT_DIR/services/utils/include", @@ -84,11 +84,11 @@ ohos_shared_library("media_helper_client") { ] configs = [ - ":media_client_base_config", - ":media_client_ipc_config", + ":media_helper_base_config", + ":media_helper_ipc_config", ] - public_configs = [ ":media_public_config" ] + public_configs = [ ":media_helper_public_config" ] deps = [ "$MEDIA_ROOT_DIR/interfaces/inner_api/native:media_client", "$MEDIA_ROOT_DIR/services/utils:media_service_utils" ] @@ -103,6 +103,8 @@ ohos_shared_library("media_helper_client") { "media_foundation:media_foundation" ] + innerapi_tags = [ "platformsdk" ] subsystem_name = "multimedia" part_name = "player_framework" + version_script = "$MEDIA_ROOT_DIR/interfaces/inner_api/native/player_framework.versionscript" } diff --git a/frameworks/native/media_service_helper/media_service_helper.cpp b/frameworks/native/media_service_helper/media_service_helper.cpp index 4154b0b9f62a83b1c1aba6f8836ae257949b56fb..adf3662677e2cd6f7febee81c9361b7735f2658b 100644 --- a/frameworks/native/media_service_helper/media_service_helper.cpp +++ b/frameworks/native/media_service_helper/media_service_helper.cpp @@ -31,5 +31,14 @@ bool MediaServiceHelper::CanKillMediaService() return canKill; } +int32_t MediaServiceHelper::ProxyForFreeze(const std::set &pidList, bool isProxy) +{ + return MediaServiceFactory::GetInstance().ProxyForFreeze(pidList, isProxy); +} + +int32_t MediaServiceHelper::ResetAllProxy() +{ + return MediaServiceFactory::GetInstance().ResetAllProxy(); +} } // namespace Media } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/player/player_impl.cpp b/frameworks/native/player/player_impl.cpp index 11e9c8a7b30421651d9c3245fdd34441f45ce948..47f6504dd8346f3bdfe43133c2bfe3a3f2e4023f 100644 --- a/frameworks/native/player/player_impl.cpp +++ b/frameworks/native/player/player_impl.cpp @@ -64,6 +64,20 @@ std::shared_ptr PlayerFactory::CreatePlayer(const PlayerProducer produce return impl; } +std::vector PlayerFactory::GetPlayerPids() +{ + std::vector pids = MediaServiceFactory::GetInstance().GetPlayerPids(); + std::string pidLog = "GetPlayerPids size=" + std::to_string(pids.size()); + if (pids.size() > 0) { + pidLog += ", contents:"; + for (auto pid : pids) { + pidLog += std::to_string(pid) + ", "; + } + } + MEDIA_LOGI("%{public}s", pidLog.c_str()); + return pids; +} + int32_t PlayerImpl::Init(const PlayerProducer producer) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " Init in", FAKE_POINTER(this)); @@ -162,7 +176,14 @@ int32_t PlayerImpl::SetSource(int32_t fd, int64_t offset, int64_t size) int32_t PlayerImpl::SetSourceTask(int32_t fd, int64_t offset, int64_t size) { - auto ret = playerService_->SetSource(fd, offset, size); + int32_t ret = MSERR_OK; + FdsanFd reopenFd = FdUtils::ReOpenFd(fd); + if (reopenFd.Get() >= 0) { + MEDIA_LOGI("SetSourceTask: reopen success"); + ret = playerService_->SetSource(reopenFd.Get(), offset, size); + } else { + ret = playerService_->SetSource(fd, offset, size); + } CHECK_AND_RETURN_RET_NOLOG(ret == MSERR_OK, ret); int32_t dupFd = dup(fd); MEDIA_LOGI("PlayerImpl:0x%{public}06" PRIXPTR " SetSourceTask dupFd", FAKE_POINTER(this)); @@ -883,6 +904,7 @@ int32_t PlayerImpl::EnableCameraPostprocessing() int fd = fdsanFd_->Get(); MEDIA_LOGD("PlayerImpl EnableCameraPostprocessing reopen fd: %{public}d ", fd); FdsanFd reopenFd = FdUtils::ReOpenFd(fd); + CHECK_AND_RETURN_RET_LOG(reopenFd.Get() >= 0, MSERR_UNKNOWN, "EnableCameraPostprocessing: reopen failed"); auto ret = SetReopenFd(reopenFd.Get()); reopenFd.Reset(); CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, MSERR_OK, "SetReopenFd failed."); @@ -920,6 +942,21 @@ int32_t PlayerImpl::EnableReportMediaProgress(bool enable) return ret; } +int32_t PlayerImpl::EnableReportAudioInterrupt(bool enable) +{ + time_t startTime = time(nullptr); + ScopedTimer timer("EnableReportAudioInterrupt", OVERTIME_WARNING_MS); + MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " EnableReportAudioInterrupt in, enable is %{public}d", + FAKE_POINTER(this), enable); + CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist."); + int32_t ret = MSERR_OK; + LISTENER(ret = playerService_->EnableReportAudioInterrupt(enable), + "EnableReportAudioInterrupt", false, TIME_OUT_SECOND); + CHECK_AND_RETURN_RET_NOLOG(ret != MSERR_OK && hiAppEventAgent_ != nullptr, ret); + hiAppEventAgent_->TraceApiEvent(ret, "EnableReportAudioInterrupt", startTime, traceId_); + return ret; +} + void PlayerImpl::ReleaseClientListener() { ScopedTimer timer("ReleaseClientListener", OVERTIME_WARNING_MS); diff --git a/frameworks/native/player/player_impl.h b/frameworks/native/player/player_impl.h index 5870c0249dd8cea94f815b99d7d8a2943d612619..7400da0703b3dd41fe663a65c09a5494ea60bd58 100644 --- a/frameworks/native/player/player_impl.h +++ b/frameworks/native/player/player_impl.h @@ -90,6 +90,7 @@ public: bool IsSeekContinuousSupported() override; int32_t SetSeiMessageCbStatus(bool status, const std::vector &payloadTypes) override; int32_t EnableReportMediaProgress(bool enable) override; + int32_t EnableReportAudioInterrupt(bool enable) override; int32_t SetStartFrameRateOptEnabled(bool enabled) override; void ReleaseClientListener() override; HiviewDFX::HiTraceId GetTraceId(); diff --git a/frameworks/native/player/test/unittest/BUILD.gn b/frameworks/native/player/test/unittest/BUILD.gn index 4346a98bfc2e33c2a3838ce990b56da16140b94c..f010daf51e67198969f57cdef17b887d3090cb1a 100644 --- a/frameworks/native/player/test/unittest/BUILD.gn +++ b/frameworks/native/player/test/unittest/BUILD.gn @@ -55,6 +55,7 @@ ohos_unittest("player_unit_test") { external_deps = [ "audio_framework:audio_client", "c_utils:utils", + "graphic_2d:librender_service_base", "graphic_surface:surface", "hilog:libhilog", "ipc:ipc_single", diff --git a/frameworks/native/player/test/unittest/include/player_mock.h b/frameworks/native/player/test/unittest/include/player_mock.h index 787a9847b0fec97eea78705dfc39d937ad605e18..535376d5a375ee3c44d0b80560d4f9a628f9bf9c 100644 --- a/frameworks/native/player/test/unittest/include/player_mock.h +++ b/frameworks/native/player/test/unittest/include/player_mock.h @@ -178,6 +178,7 @@ public: int32_t SetVideoWindowSize(int32_t width, int32_t height); int32_t EnableReportMediaProgress(bool enable); void ReleaseClientListener(); + int32_t EnableReportAudioInterrupt(bool enable); private: void SeekPrepare(int32_t &mseconds, PlayerSeekMode &mode); std::shared_ptr player_ = nullptr; diff --git a/frameworks/native/player/test/unittest/src/player_mock.cpp b/frameworks/native/player/test/unittest/src/player_mock.cpp index 467011b5ffd6db752bc682b6cd62eef460f4a1ef..7e4706446160980c402d6891079b979935e69c31 100644 --- a/frameworks/native/player/test/unittest/src/player_mock.cpp +++ b/frameworks/native/player/test/unittest/src/player_mock.cpp @@ -844,6 +844,12 @@ int32_t PlayerMock::EnableReportMediaProgress(bool enable) return player_->EnableReportMediaProgress(enable); } +int32_t PlayerMock::EnableReportAudioInterrupt(bool enable) +{ + UNITTEST_CHECK_AND_RETURN_RET_LOG(player_ != nullptr, -1, "player_ == nullptr"); + return player_->EnableReportAudioInterrupt(enable); +} + void PlayerMock::ReleaseClientListener() { UNITTEST_CHECK_AND_RETURN_LOG(player_ != nullptr, "player_ == nullptr"); diff --git a/frameworks/native/player/test/unittest/src/player_unit_test.cpp b/frameworks/native/player/test/unittest/src/player_unit_test.cpp index aa171d9f12cabf92e2da73004e08b80dcda73014..b8c114f3bf27035f6e8e4c11901734f740a48ac0 100644 --- a/frameworks/native/player/test/unittest/src/player_unit_test.cpp +++ b/frameworks/native/player/test/unittest/src/player_unit_test.cpp @@ -1596,7 +1596,6 @@ HWTEST_F(PlayerUnitTest, Player_SelectTrack_002, TestSize.Level0) sleep(PLAYING_TIME_2_SEC); EXPECT_EQ(MSERR_OK, player_->GetCurrentTrack(MediaType::MEDIA_TYPE_AUD, currentAudioTrackIndex)); EXPECT_NE(MSERR_OK, player_->SelectTrack(currentAudioTrackIndex, trackChange)); - EXPECT_EQ(trackChange, false); sleep(PLAYING_TIME_2_SEC); EXPECT_EQ(MSERR_OK, player_->Stop()); } @@ -1622,7 +1621,6 @@ HWTEST_F(PlayerUnitTest, Player_DeselectTrack_001, TestSize.Level0) audioTrack[0].GetIntValue("track_index", defaultAudioTrackIndex); EXPECT_GT(defaultAudioTrackIndex, -1); EXPECT_NE(MSERR_OK, player_->DeselectTrack(defaultAudioTrackIndex, trackChange)); - EXPECT_EQ(trackChange, false); sleep(PLAYING_TIME_2_SEC); EXPECT_EQ(MSERR_OK, player_->Stop()); } diff --git a/frameworks/native/soundpool/BUILD.gn b/frameworks/native/soundpool/BUILD.gn index 32c9ce0d4261a2ee04a31611733146e281d53f00..97c265d6d564efabf203d43b83c254775b7321c0 100644 --- a/frameworks/native/soundpool/BUILD.gn +++ b/frameworks/native/soundpool/BUILD.gn @@ -66,6 +66,7 @@ ohos_shared_library("soundpool_client") { "hicollie:libhicollie", "hilog:libhilog", "hisysevent:libhisysevent", + "hitrace:hitrace_meter", "init:libbegetutil", "ipc:ipc_core", "qos_manager:qos", diff --git a/frameworks/native/soundpool/audio_renderer_manager.cpp b/frameworks/native/soundpool/audio_renderer_manager.cpp index 5483275c880ad70a57f871341d811e89e56ac8dc..88165b2d7cb5061adc26b723554c9ffc6255b17e 100644 --- a/frameworks/native/soundpool/audio_renderer_manager.cpp +++ b/frameworks/native/soundpool/audio_renderer_manager.cpp @@ -108,6 +108,27 @@ void AudioRendererManager::RemoveOldAudioRenderer() } } +void AudioRendererManager::DelAudioRenderer(int32_t globalId) +{ + std::lock_guard lock(renderMgrMutex_); + for (auto it = audioRendererVector_.begin(); it != audioRendererVector_.end();) { + if (it->first == globalId) { + SoundPoolXCollie soundPoolXCollie("AudioRenderer::DelAudioRenderer time out", + [](void *) { + MEDIA_LOGI("AudioRenderer::DelAudioRenderer time out"); + }); + (it->second)->Release(); + soundPoolXCollie.CancelXCollieTimer(); + it = audioRendererVector_.erase(it); + break; + } else { + ++it; + } + } + MEDIA_LOGI("AudioRendererManager::DelAudioRenderer audioRendererVector_ size:%{public}zu", + audioRendererVector_.size()); +} + void AudioRendererManager::SetParallelManager(std::weak_ptr parallelManager) { std::lock_guard lock(renderMgrMutex_); diff --git a/frameworks/native/soundpool/audio_renderer_manager.h b/frameworks/native/soundpool/audio_renderer_manager.h index d4a9bc7c72a8344949f9dd409a921e022a1ab521..facaac649de5afb16cf2c2e5410f532cc7279400 100644 --- a/frameworks/native/soundpool/audio_renderer_manager.h +++ b/frameworks/native/soundpool/audio_renderer_manager.h @@ -42,6 +42,7 @@ public: void RemoveOldAudioRenderer(); void SetParallelManager(std::weak_ptr parallelManager); void SetStreamIDManager(std::weak_ptr streamIDManager); + void DelAudioRenderer(int32_t globalId); private: AudioRendererManager() {} diff --git a/frameworks/native/soundpool/cache_buffer.cpp b/frameworks/native/soundpool/cache_buffer.cpp index a157cd3d905b57318017f329be7efeb37cd7186e..4b1ed18488614908d55366cc22c041bb1271a61c 100644 --- a/frameworks/native/soundpool/cache_buffer.cpp +++ b/frameworks/native/soundpool/cache_buffer.cpp @@ -105,7 +105,8 @@ void CacheBuffer::DealAudioRendererParams(AudioStandard::AudioRendererOptions &r rendererOptions.streamInfo.format = sampleFormat_; // Get channel count from trackFormat and set it to audiorender. trackFormat_.GetIntValue(MediaAVCodec::MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, channelCount); - rendererOptions.streamInfo.channels = static_cast(channelCount); + audioChannel_ = static_cast(channelCount); + rendererOptions.streamInfo.channels = audioChannel_; // contentType streamUsage rendererFlags come from user. if (IsAudioRendererCanMix(audioRendererInfo)) { rendererOptions.strategy.concurrencyMode = AudioStandard::AudioConcurrencyMode::MIX_WITH_OTHERS; @@ -201,6 +202,8 @@ void CacheBuffer::GetAvailableAudioRenderer(const AudioStandard::AudioRendererIn audioRenderer_ = CreateAudioRenderer(audioRendererInfo, playParams); } MEDIA_LOGI("CacheBuffer::GetAvailableAudioRenderer CreateAudioRenderer New end"); + CHECK_AND_RETURN_LOG(audioRenderer_ != nullptr, "Invalid CreateAudioRenderer"); + PrepareAudioRenderer(audioRenderer_); } MEDIA_LOGI("CacheBuffer::GetAvailableAudioRenderer end"); } @@ -215,7 +218,6 @@ int32_t CacheBuffer::PreparePlayInner(const AudioStandard::AudioRendererInfo &au } GetAvailableAudioRenderer(audioRendererInfo, playParams); CHECK_AND_RETURN_RET_LOG(audioRenderer_ != nullptr, MSERR_INVALID_VAL, "Invalid GetAvailableAudioRenderer"); - PrepareAudioRenderer(audioRenderer_); DealPlayParamsBeforePlay(playParams); return MSERR_OK; } @@ -275,6 +277,7 @@ int32_t CacheBuffer::HandleRendererNotStart(const int32_t streamID) "streamID:%{public}d", streamID); callback_->OnPlayFinished(streamID_); } + isNeedFadeIn_ = true; return MSERR_OK; } else { MEDIA_LOGE("CacheBuffer::HandleRendererNotStart audioRenderer start failed," @@ -380,6 +383,7 @@ void CacheBuffer::DealWriteData(size_t length) bufDesc.dataLength = length; cacheDataFrameIndex_ += copyLength; } + FadeInAudioBuffer(bufDesc); audioRenderer_->Enqueue(bufDesc); } else { MEDIA_LOGE("OnWriteData, cacheDataFrameIndex_: %{public}zu, length: %{public}zu," @@ -580,5 +584,16 @@ void CacheBuffer::SetSourceDuration(int64_t durationMs) sourceDurationMs_ = durationMs; } +void CacheBuffer::FadeInAudioBuffer(const AudioStandard::BufferDesc &bufDesc) +{ + if (isNeedFadeIn_) { + isNeedFadeIn_ = false; + MEDIA_LOGI("CacheBuffer::FadeInAudioBuffer, streamID:%{public}d", streamID_); + int32_t ret = AudioStandard::AudioRenderer::FadeInAudioBuffer(bufDesc, sampleFormat_, audioChannel_); + if (ret != AudioStandard::SUCCESS) { + MEDIA_LOGW("CacheBuffer::FadeInAudioBuffer failed ret: %{public}d, streamID:%{public}d", ret, streamID_); + } + } +} } // namespace Media } // namespace OHOS diff --git a/frameworks/native/soundpool/cache_buffer.h b/frameworks/native/soundpool/cache_buffer.h index 5ba97b0032fe2de2f7cea72054b8633c24a29845..14e9dfd891606901bbf79e8e58f61ba1322c2012 100644 --- a/frameworks/native/soundpool/cache_buffer.h +++ b/frameworks/native/soundpool/cache_buffer.h @@ -115,6 +115,7 @@ private: void DelGlobalId(int32_t globalId); void SetGlobalId(int32_t soundID, int32_t globalId); int32_t HandleRendererNotStart(const int32_t streamID); + void FadeInAudioBuffer(const AudioStandard::BufferDesc &bufDesc); Format trackFormat_; std::deque> cacheData_; @@ -123,6 +124,7 @@ private: int32_t soundID_ = 0; int32_t streamID_ = 0; AudioStandard::AudioSampleFormat sampleFormat_ = AudioStandard::AudioSampleFormat::INVALID_WIDTH; + AudioStandard:: AudioChannel audioChannel_ = AudioStandard:: AudioChannel::MONO; PlayParams playParameters_; AudioStandard::AudioRendererInfo audioRendererInfo_; @@ -140,6 +142,7 @@ private: int32_t loop_ = 0; int32_t priority_ = 0; int32_t rendererFlags_ = NORMAL_PLAY_RENDERER_FLAGS; + bool isNeedFadeIn_ = false; size_t cacheDataFrameIndex_ = 0; int32_t havePlayedCount_ = 0; diff --git a/frameworks/native/soundpool/parallel_stream_manager.cpp b/frameworks/native/soundpool/parallel_stream_manager.cpp index 2a291bbd3fdee2611910743cb3ccb1d4b04fb6ba..2513096a5b14b62a614d142efa968465fc643015 100644 --- a/frameworks/native/soundpool/parallel_stream_manager.cpp +++ b/frameworks/native/soundpool/parallel_stream_manager.cpp @@ -131,6 +131,7 @@ void ParallelStreamManager::DelSoundId(int32_t soundId) std::lock_guard lock(globalIdMutex_); for (auto it = globalIdVector_.begin(); it != globalIdVector_.end();) { if (it->first == soundId) { + OHOS::Media::AudioRendererManager::GetInstance().DelAudioRenderer(it->second); it = globalIdVector_.erase(it); } else { ++it; diff --git a/frameworks/native/soundpool/stream_id_manager.cpp b/frameworks/native/soundpool/stream_id_manager.cpp index 683f412050ad36c6c907a0401849b2511da0cf83..e62e79e9ee710bebb7a1586c06cc4238c9cc0273 100644 --- a/frameworks/native/soundpool/stream_id_manager.cpp +++ b/frameworks/native/soundpool/stream_id_manager.cpp @@ -140,6 +140,7 @@ void StreamIDManager::DelSoundId(int32_t soundId) std::lock_guard lock(globalIdMutex_); for (auto it = globalIdVector_.begin(); it != globalIdVector_.end();) { if (it->first == soundId) { + OHOS::Media::AudioRendererManager::GetInstance().DelAudioRenderer(it->second); it = globalIdVector_.erase(it); } else { ++it; diff --git a/frameworks/native/system_sound_manager/ringtone_player/ringtone_player_impl.cpp b/frameworks/native/system_sound_manager/ringtone_player/ringtone_player_impl.cpp index 57de4387c9a45e43cd1619955df0c0d0bd9f3b43..c02ad918d385cacf0cc085ba5a336114d2407073 100644 --- a/frameworks/native/system_sound_manager/ringtone_player/ringtone_player_impl.cpp +++ b/frameworks/native/system_sound_manager/ringtone_player/ringtone_player_impl.cpp @@ -272,7 +272,7 @@ int32_t RingtonePlayerImpl::RegisterSource(const std::string &audioUri, const st string newAudioUri = systemSoundMgr_.OpenAudioUri(databaseTool_, audioUri); string newHapticUri = systemSoundMgr_.OpenHapticsUri(databaseTool_, hapticUri); - if (newAudioUri.find(FDHEAD) == std::string::npos) { + if (newAudioUri.find(FDHEAD) == std::string::npos && newAudioUri != NO_RING_SOUND) { MEDIA_LOGI("Failed to open ringtone file, select to open default ringtone and play."); std::string uri = ""; std::shared_ptr ringtoneAttrs = systemSoundMgr_.GetDefaultRingtoneAttrs(context_, type_); @@ -305,10 +305,9 @@ void RingtonePlayerImpl::InitPlayer(std::string &audioUri, ToneHapticsSettings & { MEDIA_LOGI("InitPlayer: ToneUri:%{public}s, hapticsUri:%{public}s, mode:%{public}d.", audioUri.c_str(), settings.hapticsUri.c_str(), settings.mode); + CHECK_AND_RETURN_LOG(audioHapticManager_ != nullptr, "Failed to create audio haptic manager."); if (sourceId_ != -1) { - if (audioHapticManager_ != nullptr) { - (void)audioHapticManager_->UnregisterSource(sourceId_); - } + (void)audioHapticManager_->UnregisterSource(sourceId_); sourceId_ = -1; } @@ -428,22 +427,25 @@ int32_t RingtonePlayerImpl::StartForNoRing(const HapticStartupMode startupMode) (void)SystemSoundVibrator::StartVibratorForFastMode(); } InitPlayer(ringtoneUri, settings, options); - std::string hapticUri = systemSoundMgr_.OpenHapticsUri(databaseTool_, settings.hapticsUri); - int32_t result = MSERR_OK; // if no need to start vibrator, return MSERR_OK. - if (NeedToVibrate(settings)) { - result = SystemSoundVibrator::StartVibratorForRingtone(hapticUri); - } // Start an empty audio stream for NoRing. rendererParams_.sampleFormat = AudioStandard::SAMPLE_S24LE; rendererParams_.channelCount = AudioStandard::STEREO; - audioRenderer_ = AudioStandard::AudioRenderer::Create(AudioStandard::AudioStreamType::STREAM_VOICE_RING); + if (audioRenderer_ == nullptr) { + audioRenderer_ = AudioStandard::AudioRenderer::Create(AudioStandard::AudioStreamType::STREAM_VOICE_RING); + } CHECK_AND_RETURN_RET_LOG(audioRenderer_ != nullptr, MSERR_INVALID_VAL, "no audioRenderer"); int32_t audioRet = audioRenderer_->SetParams(rendererParams_); bool isStarted = audioRenderer_->Start(); - ringtoneState_ = isStarted ? STATE_RUNNING : ringtoneState_; - MEDIA_LOGI("isStarted : %{public}d, ret: %{public}d, ", isStarted, audioRet); + MEDIA_LOGI("isStarted : %{public}d, audioRet: %{public}d, ", isStarted, audioRet); + int32_t result = MSERR_OK; // if no need to start vibrator, return MSERR_OK. + if (NeedToVibrate(settings)) { + std::string hapticUri = systemSoundMgr_.OpenHapticsUri(databaseTool_, settings.hapticsUri); + result = SystemSoundVibrator::StartVibratorForRingtone(hapticUri); + } + ringtoneState_ = STATE_RUNNING; + ReleaseDatabaseTool(); return result; } diff --git a/frameworks/native/system_sound_manager/system_sound_manager_impl.cpp b/frameworks/native/system_sound_manager/system_sound_manager_impl.cpp index 33313c8173e5f0dd6d94d67b29a65f155bd39c39..490cb6fd744979937c328fcc54bc785eb771b7cc 100644 --- a/frameworks/native/system_sound_manager/system_sound_manager_impl.cpp +++ b/frameworks/native/system_sound_manager/system_sound_manager_impl.cpp @@ -1388,8 +1388,8 @@ int32_t SystemSoundManagerImpl::SetAlarmToneUri(const std::shared_ptr lock(uriMutex_); - MEDIA_LOGI("SetAlarmToneUri: alarm type %{public}s", - SystemSoundManagerUtils::GetTypeForSystemSoundUri(uri).c_str()); + MEDIA_LOGI("SetAlarmToneUri: alarm type %{public}d", + SystemSoundManagerUtils::GetTypeForSystemSoundUri(uri)); std::shared_ptr dataShareHelper = SystemSoundManagerUtils::CreateDataShareHelper(STORAGE_MANAGER_MANAGER_ID); CHECK_AND_RETURN_RET_LOG(dataShareHelper != nullptr, ERROR, "Create dataShare failed."); @@ -1485,8 +1485,8 @@ std::string SystemSoundManagerImpl::GetAlarmToneUri(const std::shared_ptrGetPath(); - MEDIA_LOGI("GetAlarmToneUri: alarm type %{public}s", - SystemSoundManagerUtils::GetTypeForSystemSoundUri(alarmToneUri).c_str()); + MEDIA_LOGI("GetAlarmToneUri: alarm type %{public}d", + SystemSoundManagerUtils::GetTypeForSystemSoundUri(alarmToneUri)); } else { MEDIA_LOGE("GetAlarmToneUri: no alarmtone in the ringtone library!"); } @@ -2153,7 +2153,7 @@ int32_t SystemSoundManagerImpl::GetToneHapticsSettings(const DatabaseTool &datab result = GetDefaultToneHapticsSettings(dataShareHelper, toneUri, toneHapticsType, settings); } if (result == SUCCESS) { - result = UpdateToneHapticsSettings(dataShareHelper, toneUri, toneHapticsType, settings); + MEDIA_LOGE("GetDefaultToneHapticsSettings: get defaultTone haptics settings success"); } else { MEDIA_LOGE("GetToneHapticsSettings: get defaultTone haptics settings fail"); } diff --git a/frameworks/native/system_sound_manager/system_sound_manager_utils.cpp b/frameworks/native/system_sound_manager/system_sound_manager_utils.cpp index 41e83d98ac0c081e86f4848a329be58f48397a6c..2cd15938c148810df4e884dc446cd433f3e86468 100644 --- a/frameworks/native/system_sound_manager/system_sound_manager_utils.cpp +++ b/frameworks/native/system_sound_manager/system_sound_manager_utils.cpp @@ -21,6 +21,7 @@ #include "system_sound_log.h" #include "media_errors.h" #include "os_account_manager.h" +#include "system_sound_manager.h" #include "system_tone_player_impl.h" #include "parameter.h" @@ -173,27 +174,34 @@ bool SystemSoundManagerUtils::GetScannerFirstParameter(const char* key, int32_t return false; } -std::string SystemSoundManagerUtils::GetTypeForSystemSoundUri(const std::string &uri) +int32_t SystemSoundManagerUtils::GetTypeForSystemSoundUri(const std::string &audioUri) { - if (uri == NO_SYSTEM_SOUND) { - return NO_SYSTEM_SOUND; - } - if (uri == NO_RING_SOUND) { - return NO_RING_SOUND; + if (audioUri == NO_SYSTEM_SOUND || audioUri == NO_SYSTEM_SOUND) { + return SystemToneUriType::NO_RINGTONES; } - size_t pos = uri.find_first_of("sys_prod"); + size_t pos = audioUri.find_first_of("sys_prod"); if (pos == 0 || pos == 1) { - // The uri of a preset ringtone starts with "sys_prod" or "/sys_prod". - return "pre_installed"; + // The audioUri of a preset ringtone starts with "sys prod” or "/sys prod". + return SystemToneUriType::PRESET_RINGTONES; } - pos = uri.find_first_of("data"); + pos = audioUri.find_first_of("data"); if (pos == 0 || pos == 1) { - // The uri of a custom ringtone starts with "data" or "/data". - return "customised"; + // The audioUri of a custom ringtone starts with "data" or "/data". + return SystemToneUriType::CUSTOM_RINGTONES; } + return UNKNOW_RINGTONES; +} - return "unknown"; +std::string SystemSoundManagerUtils::GetErrorReason(const int32_t &errorCode) +{ + std::string errorReason = ""; + if (errorCode == MSERR_OK) { + errorReason = "system tone playback successfully"; + } else { + errorReason = "system tone playback failed"; + } + return errorReason; } } // namesapce Media } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/system_sound_manager/system_sound_manager_utils.h b/frameworks/native/system_sound_manager/system_sound_manager_utils.h index cec47f887cbc5eaa288131bdb94ffe6b88158319..809ac59f930a679de3e3f829b21306774fd6960f 100644 --- a/frameworks/native/system_sound_manager/system_sound_manager_utils.h +++ b/frameworks/native/system_sound_manager/system_sound_manager_utils.h @@ -37,7 +37,8 @@ public: static bool IdExists(const std::string &ids, int32_t id); static bool CheckCurrentUser(); static bool GetScannerFirstParameter(const char* key, int32_t maxSize); - static std::string GetTypeForSystemSoundUri(const std::string &uri); + static int32_t GetTypeForSystemSoundUri(const std::string &audioUri); + static std::string GetErrorReason(const int32_t &errorCode); }; } // namespace Media } // namespace OHOS diff --git a/frameworks/native/system_sound_manager/system_tone_player/system_tone_player_impl.cpp b/frameworks/native/system_sound_manager/system_tone_player/system_tone_player_impl.cpp index 4b9efc31bc4c5ee6dff3e154c957bd293d521d65..d22101cec5a7ec855e9466a5b2c751c8187d9be2 100644 --- a/frameworks/native/system_sound_manager/system_tone_player/system_tone_player_impl.cpp +++ b/frameworks/native/system_sound_manager/system_tone_player/system_tone_player_impl.cpp @@ -157,8 +157,8 @@ bool SystemTonePlayerImpl::IsSameHapticMaps(const std::mapStart(); CHECK_AND_RETURN_RET_LOG(result == MSERR_OK, -1, "Failed to start audio haptic player: %{public}d", result); - SendMessageZoneEvent(AudioStandard::ERR_INVALID_PARAM, - systemToneOptions.muteAudio, systemToneOptions.muteHaptics); + SendSystemTonePlaybackEvent(result, systemToneOptions.muteAudio, systemToneOptions.muteHaptics); return streamId_; } @@ -835,8 +835,9 @@ bool SystemTonePlayerImpl::IsExitCallbackThreadId(int32_t streamId) return callbackThreadIdMap_.count(streamId) != 0 && callbackThreadIdMap_[streamId] == std::this_thread::get_id(); } -void SystemTonePlayerImpl::SendMessageZoneEvent(const int32_t &errorCode, bool muteAudio, bool muteHaptics) +void SystemTonePlayerImpl::SendSystemTonePlaybackEvent(const int32_t &errorCode, bool muteAudio, bool muteHaptics) { + MEDIA_LOGI("Send System Tone Playback Event ."); AudioStandard::AudioRendererInfo rendererInfo; rendererInfo.contentType = AudioStandard::ContentType::CONTENT_TYPE_UNKNOWN; rendererInfo.streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_NOTIFICATION; @@ -850,23 +851,25 @@ void SystemTonePlayerImpl::SendMessageZoneEvent(const int32_t &errorCode, bool m return; } + auto now = std::chrono::system_clock::now(); + time_t rawtime = std::chrono::system_clock::to_time_t(now); AudioStandard::AudioRingerMode ringerMode = systemSoundMgr_.GetRingerMode(); bool vibrateState = systemSoundMgr_.CheckVibrateSwitchStatus(); int32_t volumeLevel = AudioStandard::AudioSystemManager::GetInstance()-> GetVolume(AudioStandard::STREAM_NOTIFICATION); - + std::shared_ptr bean = std::make_shared( - Media::MediaMonitor::ModuleId::AUDIO, Media::MediaMonitor::EventId::MESSAGE_ZONE, - Media::MediaMonitor::EventType::MESSAGE_ZONE_EVENT); - bean->Add("IS_PLAYBACK", 0); - bean->Add("CONFIGURED_URI", configuredUri_); + Media::MediaMonitor::ModuleId::AUDIO, Media::MediaMonitor::EventId::SYSTEM_TONE_PLAYBACK, + Media::MediaMonitor::EventType::BEHAVIOR_EVENT); + bean->Add("TIME_STAMP", static_cast(rawtime)); + bean->Add("SYSTEM_TONE_TYPE", SystemSoundManagerUtils::GetTypeForSystemSoundUri(configuredUri_)); bean->Add("CLIENT_UID", static_cast(getuid())); bean->Add("DEVICE_TYPE", (desc.size() > 0 ? desc[0]->deviceType_ : AudioStandard::DEVICE_TYPE_NONE)); bean->Add("ERROR_CODE", errorCode); + bean->Add("ERROR_REASON", SystemSoundManagerUtils::GetErrorReason(errorCode)); bean->Add("MUTE_STATE", muteAudio); bean->Add("MUTE_HAPTICS", muteHaptics); bean->Add("RING_MODE", ringerMode); - bean->Add("STREAM_TYPE", AudioStandard::STREAM_NOTIFICATION); bean->Add("VIBRATION_STATE", vibrateState); bean->Add("VOLUME_LEVEL", volumeLevel); Media::MediaMonitor::MediaMonitorManager::GetInstance().WriteLogMsg(bean); diff --git a/frameworks/native/system_sound_manager/system_tone_player/system_tone_player_impl.h b/frameworks/native/system_sound_manager/system_tone_player/system_tone_player_impl.h index 367e83eaac474be8c3d8c7f5aa4982569faad655..f825f501ac5c70ebe20189c1f5943308e40cf564 100644 --- a/frameworks/native/system_sound_manager/system_tone_player/system_tone_player_impl.h +++ b/frameworks/native/system_sound_manager/system_tone_player/system_tone_player_impl.h @@ -17,6 +17,8 @@ #define SYSTEM_TONE_PLAYER_IMPL_H #include "audio_haptic_manager.h" +#include "media_errors.h" +#include "media_monitor_manager.h" #include "system_sound_manager_impl.h" namespace OHOS { @@ -76,7 +78,7 @@ private: void DeleteCallbackThreadId(int32_t streamId); void DeleteAllCallbackThreadId(); bool IsExitCallbackThreadId(int32_t streamId); - void SendMessageZoneEvent(const int32_t &errorCode, bool muteAudio, bool muteHaptics); + void SendSystemTonePlaybackEvent(const int32_t &errorCode, bool muteAudio, bool muteHaptics); std::shared_ptr audioHapticManager_ = nullptr; std::unordered_map> playerMap_; diff --git a/frameworks/native/transcoder/test/unittest/include/transcoder_mock.h b/frameworks/native/transcoder/test/unittest/include/transcoder_mock.h index 3f872ee467eee9a33fe672d083764032cb8c0c59..b36aa2765177da17fd2fe6ab2ffb6d6d78a315c2 100644 --- a/frameworks/native/transcoder/test/unittest/include/transcoder_mock.h +++ b/frameworks/native/transcoder/test/unittest/include/transcoder_mock.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2024-2025 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 @@ -50,6 +50,7 @@ public: int32_t SetVideoEncoder(VideoCodecFormat encoder); int32_t SetVideoEncodingBitRate(int32_t rate); int32_t SetVideoSize(int32_t videoFrameWidth, int32_t videoFrameHeight); + int32_t SetColorSpace(TranscoderColorSpace colorSpaceFormat); int32_t SetAudioEncoder(AudioCodecFormat encoder); int32_t SetAudioEncodingBitRate(int32_t bitRate); int32_t SetInputFile(int32_t fd, int64_t offset, int64_t size); diff --git a/frameworks/native/transcoder/test/unittest/src/transcoder_mock.cpp b/frameworks/native/transcoder/test/unittest/src/transcoder_mock.cpp index b651f963ebdd986b97a37a35a032d80bd570bd8e..08d53bfa093bfa2fa8c29390ed91211748c4b059 100644 --- a/frameworks/native/transcoder/test/unittest/src/transcoder_mock.cpp +++ b/frameworks/native/transcoder/test/unittest/src/transcoder_mock.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Huawei Device Co., Ltd. + * Copyright (C) 2024-2025 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 @@ -71,6 +71,12 @@ int32_t TranscoderMock::SetVideoSize(int32_t videoFrameWidth, int32_t videoFrame return transcoder_->SetVideoSize(videoFrameWidth, videoFrameHeight); } +int32_t TranscoderMock::SetColorSpace(TranscoderColorSpace colorSpaceFormat) +{ + UNITTEST_CHECK_AND_RETURN_RET_LOG(transcoder_ != nullptr, MSERR_INVALID_OPERATION, "transcoder_ == nullptr"); + return transcoder_->SetColorSpace(colorSpaceFormat); +} + int32_t TranscoderMock::SetAudioEncoder(AudioCodecFormat encoder) { UNITTEST_CHECK_AND_RETURN_RET_LOG(transcoder_ != nullptr, MSERR_INVALID_OPERATION, "transcoder_ == nullptr"); diff --git a/frameworks/native/transcoder/test/unittest/src/transcoder_unit_test.cpp b/frameworks/native/transcoder/test/unittest/src/transcoder_unit_test.cpp index 54999d0db389ba226b3e54bf1b956c772211acb8..61bdf1f585c80142d20ae455b2c91d3e8bc8e9eb 100644 --- a/frameworks/native/transcoder/test/unittest/src/transcoder_unit_test.cpp +++ b/frameworks/native/transcoder/test/unittest/src/transcoder_unit_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 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 @@ -192,6 +192,248 @@ HWTEST_F(TransCoderUnitTest, transcoder_PureVideo_004, TestSize.Level2) close(srcFd); } +/** + * @tc.name: transcoder_SetColorSpace_001 + * @tc.desc: transcode ChineseColor_H264_AAC_480p_15fps.mp4 with different color space settings + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(TransCoderUnitTest, transcoder_SetColorSpace_001, TestSize.Level2) +{ + int32_t srcFd = open((TRANSCODER_ROOT_SRC + "ChineseColor_H264_AAC_480p_15fps.mp4").c_str(), O_RDWR); + ASSERT_TRUE(srcFd >= 0); + int64_t offset = TRANSCODER_FILE_OFFSET; + int64_t size = TRANSCODER_FILE_SIZE; + EXPECT_EQ(MSERR_OK, transcoder_->SetInputFile(srcFd, offset, size)); + int32_t dstFd = open((TRANSCODER_ROOT_DST + "ChineseColor_H264_AAC_480p_15fps_dst.mp4").c_str(), O_RDWR); + ASSERT_TRUE(dstFd >= 0); + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFile(dstFd)); + std::shared_ptr cb = std::make_shared(); + EXPECT_EQ(MSERR_OK, transcoder_->SetTransCoderCallback(cb)); + OutputFormatType format = FORMAT_MPEG_4; + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFormat(format)); + TranscoderColorSpace colorSpaceFmt = TRANSCODER_COLORSPACE_BT709_LIMIT; + EXPECT_EQ(MSERR_OK, transcoder_->SetColorSpace(colorSpaceFmt)); + VideoCodecFormat encoder = H264; + EXPECT_EQ(MSERR_OK, transcoder_->SetVideoEncoder(encoder)); + int32_t videoWidth = -1; + int32_t videoHeight = -1; + if (access(VPE_LIB_PATH.c_str(), F_OK) == 0) { + videoWidth = TRANSCODER_BUFFER_WIDTH; + videoHeight = TRANSCODER_BUFFER_HEIGHT; + } else { + videoWidth = TRANSCODER_BUFFER_WIDTH_480p; + videoHeight = TRANSCODER_BUFFER_HEIGHT_480p; + } + EXPECT_EQ(MSERR_OK, transcoder_->SetVideoSize(videoWidth, videoHeight)); + + EXPECT_EQ(MSERR_OK, transcoder_->Prepare()); + EXPECT_EQ(MSERR_OK, transcoder_->Start()); + EXPECT_EQ(MSERR_OK, transcoder_->Cancel()); + EXPECT_EQ(MSERR_OK, transcoder_->Release()); + close(dstFd); + close(srcFd); +} + +/** + * @tc.name: transcoder_SetColorSpace_002 + * @tc.desc: transcode ChineseColor_H264_AAC_480p_15fps.mp4 with different color space settings + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(TransCoderUnitTest, transcoder_SetColorSpace_002, TestSize.Level2) +{ + int32_t srcFd = open((TRANSCODER_ROOT_SRC + "ChineseColor_H264_AAC_480p_15fps.mp4").c_str(), O_RDWR); + ASSERT_TRUE(srcFd >= 0); + int64_t offset = TRANSCODER_FILE_OFFSET; + int64_t size = TRANSCODER_FILE_SIZE; + EXPECT_EQ(MSERR_OK, transcoder_->SetInputFile(srcFd, offset, size)); + int32_t dstFd = open((TRANSCODER_ROOT_DST + "ChineseColor_H264_AAC_480p_15fps_dst.mp4").c_str(), O_RDWR); + ASSERT_TRUE(dstFd >= 0); + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFile(dstFd)); + std::shared_ptr cb = std::make_shared(); + EXPECT_EQ(MSERR_OK, transcoder_->SetTransCoderCallback(cb)); + OutputFormatType format = FORMAT_MPEG_4; + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFormat(format)); + TranscoderColorSpace colorSpaceFmt = TRANSCODER_COLORSPACE_P3_FULL; + EXPECT_EQ(MSERR_OK, transcoder_->SetColorSpace(colorSpaceFmt)); + VideoCodecFormat encoder = H264; + EXPECT_EQ(MSERR_OK, transcoder_->SetVideoEncoder(encoder)); + int32_t videoWidth = -1; + int32_t videoHeight = -1; + if (access(VPE_LIB_PATH.c_str(), F_OK) == 0) { + videoWidth = TRANSCODER_BUFFER_WIDTH; + videoHeight = TRANSCODER_BUFFER_HEIGHT; + } else { + videoWidth = TRANSCODER_BUFFER_WIDTH_480p; + videoHeight = TRANSCODER_BUFFER_HEIGHT_480p; + } + EXPECT_EQ(MSERR_OK, transcoder_->SetVideoSize(videoWidth, videoHeight)); + + EXPECT_EQ(MSERR_OK, transcoder_->Prepare()); + EXPECT_EQ(MSERR_OK, transcoder_->Start()); + EXPECT_EQ(MSERR_OK, transcoder_->Cancel()); + EXPECT_EQ(MSERR_OK, transcoder_->Release()); + close(dstFd); + close(srcFd); +} + +/** + * @tc.name: transcoder_SetColorSpace_003 + * @tc.desc: transcode ChineseColor_H264_AAC_480p_15fps.mp4 with different color space settings + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(TransCoderUnitTest, transcoder_SetColorSpace_003, TestSize.Level2) +{ + int32_t srcFd = open((TRANSCODER_ROOT_SRC + "ChineseColor_H264_AAC_480p_15fps.mp4").c_str(), O_RDWR); + ASSERT_TRUE(srcFd >= 0); + int64_t offset = TRANSCODER_FILE_OFFSET; + int64_t size = TRANSCODER_FILE_SIZE; + EXPECT_EQ(MSERR_OK, transcoder_->SetInputFile(srcFd, offset, size)); + int32_t dstFd = open((TRANSCODER_ROOT_DST + "ChineseColor_H264_AAC_480p_15fps_dst.mp4").c_str(), O_RDWR); + ASSERT_TRUE(dstFd >= 0); + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFile(dstFd)); + std::shared_ptr cb = std::make_shared(); + EXPECT_EQ(MSERR_OK, transcoder_->SetTransCoderCallback(cb)); + OutputFormatType format = FORMAT_MPEG_4; + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFormat(format)); + TranscoderColorSpace colorSpaceFmt = TRANSCODER_COLORSPACE_BT709_LIMIT; + EXPECT_EQ(MSERR_OK, transcoder_->SetColorSpace(colorSpaceFmt)); + VideoCodecFormat encoder = H264; + EXPECT_EQ(MSERR_OK, transcoder_->SetVideoEncoder(encoder)); + int32_t videoWidth = TRANSCODER_BUFFER_WIDTH_480p; + int32_t videoHeight = TRANSCODER_BUFFER_HEIGHT_480p; + EXPECT_EQ(MSERR_OK, transcoder_->SetVideoSize(videoWidth, videoHeight)); + + EXPECT_EQ(MSERR_OK, transcoder_->Prepare()); + EXPECT_EQ(MSERR_OK, transcoder_->Start()); + EXPECT_EQ(MSERR_OK, transcoder_->Cancel()); + EXPECT_EQ(MSERR_OK, transcoder_->Release()); + close(dstFd); + close(srcFd); +} + +/** + * @tc.name: transcoder_SetColorSpace_004 + * @tc.desc: transcode ChineseColor_H264_AAC_480p_15fps.mp4 with different color space settings + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(TransCoderUnitTest, transcoder_SetColorSpace_004, TestSize.Level2) +{ + int32_t srcFd = open((TRANSCODER_ROOT_SRC + "ChineseColor_H264_AAC_480p_15fps.mp4").c_str(), O_RDWR); + ASSERT_TRUE(srcFd >= 0); + int64_t offset = TRANSCODER_FILE_OFFSET; + int64_t size = TRANSCODER_FILE_SIZE; + EXPECT_EQ(MSERR_OK, transcoder_->SetInputFile(srcFd, offset, size)); + int32_t dstFd = open((TRANSCODER_ROOT_DST + "ChineseColor_H264_AAC_480p_15fps_dst.mp4").c_str(), O_RDWR); + ASSERT_TRUE(dstFd >= 0); + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFile(dstFd)); + std::shared_ptr cb = std::make_shared(); + EXPECT_EQ(MSERR_OK, transcoder_->SetTransCoderCallback(cb)); + OutputFormatType format = FORMAT_MPEG_4; + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFormat(format)); + TranscoderColorSpace colorSpaceFmt = TRANSCODER_COLORSPACE_P3_FULL; + EXPECT_EQ(MSERR_OK, transcoder_->SetColorSpace(colorSpaceFmt)); + VideoCodecFormat encoder = H264; + EXPECT_EQ(MSERR_OK, transcoder_->SetVideoEncoder(encoder)); + int32_t videoWidth = TRANSCODER_BUFFER_WIDTH_480p; + int32_t videoHeight = TRANSCODER_BUFFER_HEIGHT_480p; + EXPECT_EQ(MSERR_OK, transcoder_->SetVideoSize(videoWidth, videoHeight)); + + EXPECT_EQ(MSERR_OK, transcoder_->Prepare()); + EXPECT_EQ(MSERR_OK, transcoder_->Start()); + EXPECT_EQ(MSERR_OK, transcoder_->Cancel()); + EXPECT_EQ(MSERR_OK, transcoder_->Release()); + close(dstFd); + close(srcFd); +} + +/** + * @tc.name: transcoder_SetColorSpace_010 + * @tc.desc: transcode ChineseColor_H264_AAC_480p_15fps.mp4 with different color space settings + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(TransCoderUnitTest, transcoder_SetColorSpace_010, TestSize.Level2) +{ + int32_t srcFd = open((TRANSCODER_ROOT_SRC + "ChineseColor_H264_AAC_480p_15fps.mp4").c_str(), O_RDWR); + ASSERT_TRUE(srcFd >= 0); + int64_t offset = TRANSCODER_FILE_OFFSET; + int64_t size = TRANSCODER_FILE_SIZE; + EXPECT_EQ(MSERR_OK, transcoder_->SetInputFile(srcFd, offset, size)); + int32_t dstFd = open((TRANSCODER_ROOT_DST + "ChineseColor_H264_AAC_480p_15fps_dst.mp4").c_str(), O_RDWR); + ASSERT_TRUE(dstFd >= 0); + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFile(dstFd)); + OutputFormatType format = FORMAT_MPEG_4; + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFormat(format)); + TranscoderColorSpace colorSpaceFmt = TRANSCODER_COLORSPACE_NONE; + EXPECT_EQ(MSERR_INVALID_VAL, transcoder_->SetColorSpace(colorSpaceFmt)); + + EXPECT_EQ(MSERR_OK, transcoder_->Prepare()); + EXPECT_EQ(MSERR_OK, transcoder_->Start()); + EXPECT_EQ(MSERR_OK, transcoder_->Release()); + close(dstFd); + close(srcFd); +} + +/** + * @tc.name: transcoder_SetColorSpace_011 + * @tc.desc: transcode ChineseColor_H264_AAC_480p_15fps.mp4 with different color space settings + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(TransCoderUnitTest, transcoder_SetColorSpace_011, TestSize.Level2) +{ + int32_t srcFd = open((TRANSCODER_ROOT_SRC + "ChineseColor_H264_AAC_480p_15fps.mp4").c_str(), O_RDWR); + ASSERT_TRUE(srcFd >= 0); + int64_t offset = TRANSCODER_FILE_OFFSET; + int64_t size = TRANSCODER_FILE_SIZE; + EXPECT_EQ(MSERR_OK, transcoder_->SetInputFile(srcFd, offset, size)); + int32_t dstFd = open((TRANSCODER_ROOT_DST + "ChineseColor_H264_AAC_480p_15fps_dst.mp4").c_str(), O_RDWR); + ASSERT_TRUE(dstFd >= 0); + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFile(dstFd)); + OutputFormatType format = FORMAT_MPEG_4; + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFormat(format)); + TranscoderColorSpace colorSpaceFmt = TRANSCODER_COLORSPACE_BT601_EBU_FULL; + EXPECT_EQ(MSERR_OK, transcoder_->SetColorSpace(colorSpaceFmt)); + + EXPECT_EQ(MSERR_OK, transcoder_->Prepare()); + EXPECT_EQ(MSERR_OK, transcoder_->Start()); + EXPECT_EQ(MSERR_OK, transcoder_->Release()); + close(dstFd); + close(srcFd); +} + +/** + * @tc.name: transcoder_SetColorSpace_012 + * @tc.desc: transcode ChineseColor_H264_AAC_480p_15fps.mp4 with different color space settings + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(TransCoderUnitTest, transcoder_SetColorSpace_012, TestSize.Level2) +{ + int32_t srcFd = open((TRANSCODER_ROOT_SRC + "ChineseColor_H264_AAC_480p_15fps.mp4").c_str(), O_RDWR); + ASSERT_TRUE(srcFd >= 0); + int64_t offset = TRANSCODER_FILE_OFFSET; + int64_t size = TRANSCODER_FILE_SIZE; + EXPECT_EQ(MSERR_OK, transcoder_->SetInputFile(srcFd, offset, size)); + int32_t dstFd = open((TRANSCODER_ROOT_DST + "ChineseColor_H264_AAC_480p_15fps_dst.mp4").c_str(), O_RDWR); + ASSERT_TRUE(dstFd >= 0); + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFile(dstFd)); + OutputFormatType format = FORMAT_MPEG_4; + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFormat(format)); + TranscoderColorSpace colorSpaceFmt = TRANSCODER_COLORSPACE_BT601_SMPTE_C_FULL; + EXPECT_EQ(MSERR_OK, transcoder_->SetColorSpace(colorSpaceFmt)); + + EXPECT_EQ(MSERR_OK, transcoder_->Prepare()); + EXPECT_EQ(MSERR_OK, transcoder_->Start()); + EXPECT_EQ(MSERR_OK, transcoder_->Release()); + close(dstFd); + close(srcFd); +} + /** * @tc.name: transcoder_AudioVideo_001 * @tc.desc: transcoder audio and video ChineseColor_H264_AAC_480p_15fps.mp4 with codec format H264 diff --git a/frameworks/native/transcoder/transcoder_impl.cpp b/frameworks/native/transcoder/transcoder_impl.cpp index c51befd37485c98a81fa1f649627a46d2ba66130..79a77b10aa8405cf0bd002491528e23110819164 100644 --- a/frameworks/native/transcoder/transcoder_impl.cpp +++ b/frameworks/native/transcoder/transcoder_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Huawei Device Co., Ltd. + * Copyright (C) 2024-2025 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 @@ -85,6 +85,15 @@ int32_t TransCoderImpl::SetVideoEncodingBitRate(int32_t bitRate) return transCoderService_->SetVideoEncodingBitRate(bitRate); } +int32_t TransCoderImpl::SetColorSpace(TranscoderColorSpace colorSpaceFormat) +{ + MEDIA_LOGI("TransCoderImpl:0x%{public}06" PRIXPTR " SetColorSpace in, colorSpace is %{public}d", + FAKE_POINTER(this), static_cast(colorSpaceFormat)); + CHECK_AND_RETURN_RET_LOG(transCoderService_ != nullptr, MSERR_INVALID_OPERATION, + "transcoder service does not exist.."); + return transCoderService_->SetColorSpace(colorSpaceFormat); +} + int32_t TransCoderImpl::SetAudioEncoder(AudioCodecFormat encoder) { MEDIA_LOGI("TransCoderImpl:0x%{public}06" PRIXPTR " SetAudioEncoder in, encoder is %{public}d", diff --git a/frameworks/native/transcoder/transcoder_impl.h b/frameworks/native/transcoder/transcoder_impl.h index bcbea35ee8ec149edb8f5fb0fd68173d63928163..d96396b434b94217a08be62e65373db7738a51a3 100644 --- a/frameworks/native/transcoder/transcoder_impl.h +++ b/frameworks/native/transcoder/transcoder_impl.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Huawei Device Co., Ltd. + * Copyright (C) 2024-2025 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 @@ -31,6 +31,7 @@ public: int32_t SetVideoEncoder(VideoCodecFormat encoder) override; int32_t SetVideoEncodingBitRate(int32_t rate) override; int32_t SetVideoSize(int32_t width, int32_t height) override; + int32_t SetColorSpace(TranscoderColorSpace colorSpaceFormat) override; int32_t SetAudioEncoder(AudioCodecFormat encoder) override; int32_t SetAudioEncodingBitRate(int32_t bitRate) override; int32_t SetOutputFormat(OutputFormatType format) override; diff --git a/frameworks/native/video_editor/codec/video/decoder/video_decoder.cpp b/frameworks/native/video_editor/codec/video/decoder/video_decoder.cpp index aa009fce3d62ad63a1dd393c419bef7c46c831c9..084a8c310dc03e2385a9a815e8cc13392a600866 100644 --- a/frameworks/native/video_editor/codec/video/decoder/video_decoder.cpp +++ b/frameworks/native/video_editor/codec/video/decoder/video_decoder.cpp @@ -53,14 +53,14 @@ VEFError VideoDecoder::Init(OH_AVFormat* videoFormat) std::string dumpInfo = OH_AVFormat_DumpInfo(videoFormat); MEDIA_LOGI("[%{public}s] initializing decoder, format: %{public}s.", logTag_.c_str(), dumpInfo.c_str()); std::regex re("codec_profile = (\\d+)"); - std::smatch match; - if (std::regex_search(dumpInfo, match, re)) { - std::string bitType = match[1].str(); - if (bitType == "1") { - MEDIA_LOGE("[%{public}s] 10bit mode is 1, don't match.", logTag_.c_str()); - return VEFError::ERR_INTERNAL_ERROR; - } - } + std::smatch match; + if (std::regex_search(dumpInfo, match, re)) { + std::string bitType = match[1].str(); + if (bitType == "1") { + MEDIA_LOGE("[%{public}s] 10bit mode is 1, don't match.", logTag_.c_str()); + return VEFError::ERR_INTERNAL_ERROR; + } + } const char* mime = nullptr; if (!OH_AVFormat_GetStringValue(videoFormat, OH_MD_KEY_CODEC_MIME, &mime)) { MEDIA_LOGE("[%{public}s] get [%{public}s] from video format failed.", logTag_.c_str(), OH_MD_KEY_CODEC_MIME); diff --git a/frameworks/native/video_editor/render/graphics/base/gl_utils.cpp b/frameworks/native/video_editor/render/graphics/base/gl_utils.cpp index a44517a25c4e216344568753fa277350e745b013..ffead7bed8a4f0949bd2c290d301dadfe9312e9a 100644 --- a/frameworks/native/video_editor/render/graphics/base/gl_utils.cpp +++ b/frameworks/native/video_editor/render/graphics/base/gl_utils.cpp @@ -16,7 +16,11 @@ #include #include #include "gl_utils.h" +#ifdef USE_M133_SKIA +#include "third_party/skia/third_party/externals/oboe/samples/RhythmGame/third_party/glm/gtc/matrix_transform.hpp" +#else #include "third_party/externals/oboe/samples/RhythmGame/third_party/glm/gtc/matrix_transform.hpp" +#endif constexpr uint32_t MESSAGE_MAX_SIZE = 511; diff --git a/frameworks/native/video_editor/render/graphics/base/math/math_utils.h b/frameworks/native/video_editor/render/graphics/base/math/math_utils.h index eed11b974a3cfafd8ca38b81cde10f5da19cfc1a..f58c0ca47674a96c113a940491d045a08ee1d591 100644 --- a/frameworks/native/video_editor/render/graphics/base/math/math_utils.h +++ b/frameworks/native/video_editor/render/graphics/base/math/math_utils.h @@ -16,7 +16,11 @@ #ifndef OH_VEF_GRAPHICS_RENDER_MATH_UTIL_H #define OH_VEF_GRAPHICS_RENDER_MATH_UTIL_H +#ifdef USE_M133_SKIA +#include "third_party/skia/third_party/externals/oboe/samples/RhythmGame/third_party/glm/gtc/type_ptr.hpp" +#else #include "third_party/externals/oboe/samples/RhythmGame/third_party/glm/gtc/type_ptr.hpp" +#endif namespace OHOS { namespace Media { diff --git a/frameworks/native/video_editor/render/graphics/base/math/render_matrix.h b/frameworks/native/video_editor/render/graphics/base/math/render_matrix.h index 02c7558c9247e284112516aade04e97205b5a1fb..503405289317f673378a32d5ff7ebfcb945fa79a 100644 --- a/frameworks/native/video_editor/render/graphics/base/math/render_matrix.h +++ b/frameworks/native/video_editor/render/graphics/base/math/render_matrix.h @@ -16,9 +16,15 @@ #ifndef OH_VEF_GRAPHICS_RENDER_MATRIX_H #define OH_VEF_GRAPHICS_RENDER_MATRIX_H +#ifdef USE_M133_SKIA +#include "third_party/skia/third_party/externals/oboe/samples/RhythmGame/third_party/glm/mat2x2.hpp" +#include "third_party/skia/third_party/externals/oboe/samples/RhythmGame/third_party/glm/mat3x3.hpp" +#include "third_party/skia/third_party/externals/oboe/samples/RhythmGame/third_party/glm/mat4x4.hpp" +#else #include "third_party/externals/oboe/samples/RhythmGame/third_party/glm/mat2x2.hpp" #include "third_party/externals/oboe/samples/RhythmGame/third_party/glm/mat3x3.hpp" #include "third_party/externals/oboe/samples/RhythmGame/third_party/glm/mat4x4.hpp" +#endif namespace OHOS { namespace Media { diff --git a/frameworks/native/video_editor/render/graphics/base/math/render_vector.h b/frameworks/native/video_editor/render/graphics/base/math/render_vector.h index 7116fcb72ccf847dcff39401c7dfcf147fc403b2..282ff43858e9d1361b90bfb4653359ff62c7ffef 100644 --- a/frameworks/native/video_editor/render/graphics/base/math/render_vector.h +++ b/frameworks/native/video_editor/render/graphics/base/math/render_vector.h @@ -17,9 +17,15 @@ #define OH_VEF_GRAPHICS_RENDER_VECTOR_H #define GLM_FORCE_XYZW_ONLY +#ifdef USE_M133_SKIA +#include "third_party/skia/third_party/externals/oboe/samples/RhythmGame/third_party/glm/vec2.hpp" +#include "third_party/skia/third_party/externals/oboe/samples/RhythmGame/third_party/glm/vec3.hpp" +#include "third_party/skia/third_party/externals/oboe/samples/RhythmGame/third_party/glm/vec4.hpp" +#else #include "third_party/externals/oboe/samples/RhythmGame/third_party/glm/vec2.hpp" #include "third_party/externals/oboe/samples/RhythmGame/third_party/glm/vec3.hpp" #include "third_party/externals/oboe/samples/RhythmGame/third_party/glm/vec4.hpp" +#endif namespace OHOS { namespace Media { diff --git a/interfaces/inner_api/native/audio_haptic/include/audio_haptic_manager.h b/interfaces/inner_api/native/audio_haptic/include/audio_haptic_manager.h index 4842e0f339ca49fb2d595039803052222bcc1632..9d75ac03c94da94fad6159187cba82d99ad05b10 100644 --- a/interfaces/inner_api/native/audio_haptic/include/audio_haptic_manager.h +++ b/interfaces/inner_api/native/audio_haptic/include/audio_haptic_manager.h @@ -25,12 +25,21 @@ namespace OHOS { namespace Media { +struct AudioHapticFileDescriptor { + int32_t fd = -1; + int64_t length; + int64_t offset; +}; + class AudioHapticManager { public: virtual ~AudioHapticManager() = default; virtual int32_t RegisterSource(const std::string &audioUri, const std::string &hapticUri) = 0; + virtual int32_t RegisterSourceFromFd(const AudioHapticFileDescriptor& audioFd, + const AudioHapticFileDescriptor& hapticFd); + virtual int32_t RegisterSourceWithEffectId(const std::string &audioUri, const std::string &effectId) = 0; virtual int32_t UnregisterSource(const int32_t &sourceID) = 0; diff --git a/interfaces/inner_api/native/audio_haptic/include/audio_haptic_player.h b/interfaces/inner_api/native/audio_haptic/include/audio_haptic_player.h index 1f2276a0d0024fab742cb317f4d29fc575abd9c5..b13e500f9796882490352df50f08343fcfa5f4c2 100644 --- a/interfaces/inner_api/native/audio_haptic/include/audio_haptic_player.h +++ b/interfaces/inner_api/native/audio_haptic/include/audio_haptic_player.h @@ -22,6 +22,9 @@ namespace OHOS { namespace Media { +constexpr int32_t FILE_DESCRIPTOR_ZERO = 0; +constexpr int32_t FILE_DESCRIPTOR_INVALID = -1; + enum AudioHapticType { AUDIO_HAPTIC_TYPE_AUDIO = 0, AUDIO_HAPTIC_TYPE_HAPTIC = 1, @@ -63,24 +66,52 @@ enum HapticsMode { HAPTICS_MODE_NON_SYNC_ONCE = 3, }; +struct AudioSource { + std::string audioUri = ""; + int32_t fd = FILE_DESCRIPTOR_INVALID; + int64_t length = 0; + int64_t offset = 0; + + bool empty() const + { + return audioUri.empty() && fd == FILE_DESCRIPTOR_INVALID; + } + + bool operator==(const AudioSource& other) const + { + return this->audioUri == other.audioUri && + this->fd == other.fd && + this->length == other.length && + this->offset == other.offset; + } + + bool operator!=(const AudioSource& other) const + { + return !(*this == other); + } +}; + struct HapticSource { std::string hapticUri = ""; std::string effectId = ""; + int32_t fd = FILE_DESCRIPTOR_INVALID; + int64_t length = 0; + int64_t offset = 0; }; struct AudioHapticPlayerParam { AudioHapticPlayerOptions options; - std::string audioUri; + AudioSource audioSource; HapticSource hapticSource; AudioLatencyMode latencyMode; AudioStandard::StreamUsage streamUsage; AudioHapticPlayerParam() {}; AudioHapticPlayerParam(const AudioHapticPlayerOptions &options, - const std::string &audioUri, const HapticSource &hapticSource, + const AudioSource& audioSource, const HapticSource &hapticSource, const AudioLatencyMode &latencyMode, const AudioStandard::StreamUsage &streamUsage) : options(options), - audioUri(audioUri), + audioSource(audioSource), hapticSource(hapticSource), latencyMode(latencyMode), streamUsage(streamUsage) {}; @@ -116,6 +147,10 @@ public: virtual HapticsMode GetHapticsMode() const = 0; virtual void SetHapticsMode(HapticsMode hapticsMode) = 0; + + virtual int32_t EnableHapticsInSilentMode(bool enable) = 0; + + virtual bool IsHapticsIntensityAdjustmentSupported() = 0; }; class AudioHapticPlayerCallback { diff --git a/interfaces/inner_api/native/audio_haptic/include/audio_haptic_sound.h b/interfaces/inner_api/native/audio_haptic/include/audio_haptic_sound.h index c3a211add941aa274a6408a169a63b2b779fa4e7..5f01bcfbb58043fd94a373e5228bf2f94aa080de 100644 --- a/interfaces/inner_api/native/audio_haptic/include/audio_haptic_sound.h +++ b/interfaces/inner_api/native/audio_haptic/include/audio_haptic_sound.h @@ -38,7 +38,7 @@ public: virtual ~AudioHapticSound() = default; static std::shared_ptr CreateAudioHapticSound(const AudioLatencyMode &latencyMode, - const std::string &audioUri, const bool &muteAudio, const AudioStandard::StreamUsage &streamUsage, + const AudioSource& audioSource, const bool &muteAudio, const AudioStandard::StreamUsage &streamUsage, const bool ¶llelPlayFlag = false); virtual int32_t PrepareSound() = 0; diff --git a/interfaces/inner_api/native/audio_haptic/include/audio_haptic_vibrator.h b/interfaces/inner_api/native/audio_haptic/include/audio_haptic_vibrator.h index e26e6e4e9cff7a07debc054220a0135bc09dc926..76af6955b298afbb1f725d287ec8999f6000feb9 100644 --- a/interfaces/inner_api/native/audio_haptic/include/audio_haptic_vibrator.h +++ b/interfaces/inner_api/native/audio_haptic/include/audio_haptic_vibrator.h @@ -36,6 +36,8 @@ public: virtual int32_t SetHapticIntensity(float intensity) = 0; virtual int32_t StopVibrate() = 0; virtual int32_t GetDelayTime() = 0; + virtual void EnableHapticsInSilentMode(bool enable) = 0; + virtual bool IsHdHapticSupported() = 0; private: static std::mutex createVibratorMutex_; diff --git a/interfaces/inner_api/native/av_common.h b/interfaces/inner_api/native/av_common.h index b00df60f5e03f3d493f978332dc2c961b3ea10a4..55da53ee7c1ab3d5e71cd670a13c50c00ca00b18 100644 --- a/interfaces/inner_api/native/av_common.h +++ b/interfaces/inner_api/native/av_common.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (C) 2021-2025 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 @@ -76,6 +76,72 @@ enum VideoRotation : uint32_t { VIDEO_ROTATION_270 = 270, }; +/** + * @brief Enumerates output format types. + * + * @since 3.1 + * @version 3.1 + */ +enum OutputFormatType : int32_t { + /** Default format */ + FORMAT_DEFAULT = 0, + /** MPEG4 format */ + FORMAT_MPEG_4 = 2, + /** M4A format */ + FORMAT_M4A = 6, + /** AMR format */ + FORMAT_AMR = 8, + /** mp3 format */ + FORMAT_MP3 = 9, + /** WAV format */ + FORMAT_WAV = 10, + /** AAC format */ + FORMAT_AAC = 11, + /** BUTT */ + FORMAT_BUTT, +}; + +/** + * @brief Enumerates video codec formats. + * + * @since 3.1 + * @version 3.1 + */ +enum VideoCodecFormat : int32_t { + /** Default format */ + VIDEO_DEFAULT = 0, + /** H.264 */ + H264 = 2, + /** MPEG4 */ + MPEG4 = 6, + /** H.265 */ + H265 = 8, + VIDEO_CODEC_FORMAT_BUTT, +}; + +/** + * @brief Enumerates audio codec formats. + * + * @since 3.1 + * @version 3.1 + */ +enum AudioCodecFormat : int32_t { + /** Default format */ + AUDIO_DEFAULT = 0, + /** Advanced Audio Coding Low Complexity (AAC-LC) */ + AAC_LC = 3, + /** mp3 format */ + AUDIO_MPEG = 4, + /** G711-mulaw format */ + AUDIO_G711MU = 5, + /** AUDIO_AMR_NB format */ + AUDIO_AMR_NB = 9, + /** AUDIO_AMR_WB format */ + AUDIO_AMR_WB = 10, + /** Invalid value */ + AUDIO_CODEC_FORMAT_BUTT, +}; + class AVMimeType { public: static constexpr std::string_view APPLICATION_M3U8 = "application/m3u8"; diff --git a/interfaces/inner_api/native/media_service_helper/media_service_helper.h b/interfaces/inner_api/native/media_service_helper/media_service_helper.h index d8396f6714b212e2d3c0300fcf5f8ce12e3ec91b..c932630e6790ac998d631148fa282ee50fa9247b 100644 --- a/interfaces/inner_api/native/media_service_helper/media_service_helper.h +++ b/interfaces/inner_api/native/media_service_helper/media_service_helper.h @@ -16,11 +16,17 @@ #ifndef MEDIA_SERVICE_HELPER_H #define MEDIA_SERVICE_HELPER_H +#include + namespace OHOS { namespace Media { -class MediaServiceHelper { +class __attribute__((visibility("default"))) MediaServiceHelper { public: static bool CanKillMediaService(); + + static int32_t ProxyForFreeze(const std::set &pidList, bool isProxy); + + static int32_t ResetAllProxy(); }; } // namespace Media } // namespace OHOS diff --git a/interfaces/inner_api/native/player.h b/interfaces/inner_api/native/player.h index 1dc0209e37ee188918c65715501e75222840a745..14a249d4344da00f3defc00c007a49c106464f9f 100644 --- a/interfaces/inner_api/native/player.h +++ b/interfaces/inner_api/native/player.h @@ -307,6 +307,7 @@ enum PlayerStates : int32_t { PLAYER_PLAYBACK_COMPLETE = 8, /* released states */ PLAYER_RELEASED = 9, + PLAYER_FROZEN = 10, }; enum PlaybackRateMode : int32_t { @@ -361,6 +362,16 @@ public: * @param errorMsg Error message. */ virtual void OnError(int32_t errorCode, const std::string &errorMsg) = 0; + + virtual void SetFreezeFlag(bool isFrozen) + { + (void)isFrozen; + } + + virtual void SetInterruptListenerFlag(bool isRegistered) + { + (void)isRegistered; + } }; class Player { @@ -1014,6 +1025,21 @@ public: (void)enable; return 0; } + + /** + * @brief Enables or disables the report of audio interrupt during frozen state. + * + * @param enable Indicates whether to enable the report of audio interrupt during frozen state. + * @return Returns {@link MSERR_OK} if the report of audio interrupt is enabled or disabled; returns an error code + * defined in {@link media_errors.h} otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual int32_t EnableReportAudioInterrupt(bool enable) + { + (void)enable; + return 0; + } /** * @brief Set Start Frame Rate Opt Enabled. @@ -1074,6 +1100,7 @@ public: static std::shared_ptr CreatePlayer(const PlayerProducer producer); #endif + static std::vector GetPlayerPids(); private: PlayerFactory() = default; ~PlayerFactory() = default; diff --git a/interfaces/inner_api/native/player_framework.versionscript b/interfaces/inner_api/native/player_framework.versionscript index 345f481d3e5d97d4411f818ac4f2eb4928954b46..fc700a466f77725ead182cb29d4b393d9f1665b4 100644 --- a/interfaces/inner_api/native/player_framework.versionscript +++ b/interfaces/inner_api/native/player_framework.versionscript @@ -15,6 +15,7 @@ global: extern "C++" { *OHOS::Media::PlayerFactory::CreatePlayer*; + *OHOS::Media::PlayerFactory::GetPlayerPids*; *OHOS::Media::RecorderFactory::CreateRecorder*; *OHOS::Media::TransCoderFactory::CreateTransCoder*; *OHOS::Media::VideoEncoderFactory::CreateBy*; @@ -40,6 +41,8 @@ *OHOS::Media::ScreenCaptureMonitor::UnregisterScreenCaptureMonitorListener*; *OHOS::Media::MediaServiceFactory::GetInstance*; *OHOS::Media::MediaServiceHelper::CanKillMediaService*; + *OHOS::Media::MediaServiceHelper::ProxyForFreeze*; + *OHOS::Media::MediaServiceHelper::ResetAllProxy*; }; "*MSErrorToString*"; "*MSExtErrorToString*"; diff --git a/interfaces/inner_api/native/recorder.h b/interfaces/inner_api/native/recorder.h index 24f9c927fbe8c66808441dc9ded04049bdbe1648..a69dd4897ac7a587dc4a646b478beca37a3ece69 100644 --- a/interfaces/inner_api/native/recorder.h +++ b/interfaces/inner_api/native/recorder.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (C) 2021-2025 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 @@ -111,72 +111,6 @@ enum DataSourceType : int32_t { METADATA = 0 }; -/** - * @brief Enumerates output format types. - * - * @since 3.1 - * @version 3.1 - */ -enum OutputFormatType : int32_t { - /** Default format */ - FORMAT_DEFAULT = 0, - /** MPEG4 format */ - FORMAT_MPEG_4 = 2, - /** M4A format */ - FORMAT_M4A = 6, - /** AMR format */ - FORMAT_AMR = 8, - /** mp3 format */ - FORMAT_MP3 = 9, - /** WAV format */ - FORMAT_WAV = 10, - /** AAC format */ - FORMAT_AAC = 11, - /** BUTT */ - FORMAT_BUTT, -}; - -/** - * @brief Enumerates video codec formats. - * - * @since 3.1 - * @version 3.1 - */ -enum VideoCodecFormat : int32_t { - /** Default format */ - VIDEO_DEFAULT = 0, - /** H.264 */ - H264 = 2, - /** MPEG4 */ - MPEG4 = 6, - /** H.265 */ - H265 = 8, - VIDEO_CODEC_FORMAT_BUTT, -}; - -/** - * @brief Enumerates audio codec formats. - * - * @since 3.1 - * @version 3.1 - */ -enum AudioCodecFormat : int32_t { - /** Default format */ - AUDIO_DEFAULT = 0, - /** Advanced Audio Coding Low Complexity (AAC-LC) */ - AAC_LC = 3, - /** mp3 format */ - AUDIO_MPEG = 4, - /** G711-mulaw format */ - AUDIO_G711MU = 5, - /** AUDIO_AMR_NB format */ - AUDIO_AMR_NB = 9, - /** AUDIO_AMR_WB format */ - AUDIO_AMR_WB = 10, - /** Invalid value */ - AUDIO_CODEC_FORMAT_BUTT, -}; - /** * Unsupported App Usage. * @brief Enumerates file split types. diff --git a/interfaces/inner_api/native/screen_capture.h b/interfaces/inner_api/native/screen_capture.h index b5d8cd4a71189103425e1661eec3a15a66612ed0..7edc4e85ec6c21fa09bc9168ed545c4a57281975 100644 --- a/interfaces/inner_api/native/screen_capture.h +++ b/interfaces/inner_api/native/screen_capture.h @@ -181,6 +181,7 @@ struct AudioInfo { struct ScreenCaptureStrategy { bool enableDeviceLevelCapture = false; bool keepCaptureDuringCall = false; + int32_t strategyForPrivacyMaskMode = 0; bool setByUser = false; }; diff --git a/interfaces/inner_api/native/system_sound_manager/include/system_sound_manager.h b/interfaces/inner_api/native/system_sound_manager/include/system_sound_manager.h index bfbddff7a15e564ff6897f77eab125102c13c308..7518ffd27fcf212e977b7105c9c2b019231a97c1 100644 --- a/interfaces/inner_api/native/system_sound_manager/include/system_sound_manager.h +++ b/interfaces/inner_api/native/system_sound_manager/include/system_sound_manager.h @@ -49,6 +49,13 @@ enum ToneHapticsType { NOTIFICATION = 40, }; +enum SystemToneUriType { + UNKNOW_RINGTONES = -1, + NO_RINGTONES = 0, + PRESET_RINGTONES = 1, + CUSTOM_RINGTONES = 2, +}; + class SystemSoundManager { public: virtual ~SystemSoundManager() = default; diff --git a/interfaces/inner_api/native/transcoder.h b/interfaces/inner_api/native/transcoder.h index ac655638fd5db29cd568cd8bde09a77209092027..46ad07771ca399eb6c6d571a3f29fb19340410b9 100644 --- a/interfaces/inner_api/native/transcoder.h +++ b/interfaces/inner_api/native/transcoder.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Huawei Device Co., Ltd. + * Copyright (C) 2024-2025 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 @@ -23,7 +23,7 @@ #include #include "meta/format.h" #include "surface.h" -#include "recorder.h" +#include "surface/native_buffer.h" #include "av_common.h" #include "codec_capability.h" #include "media_core.h" @@ -49,6 +49,79 @@ enum TransCoderOnInfoType : int32_t { INFO_TYPE_PROGRESS_UPDATE = 1, }; +/** + * @brief Enumerates transcodering color space. + * + * @since 6.0 + * @version 6.0 + */ +enum TranscoderColorSpace : int32_t { + /** None color space */ + TRANSCODER_COLORSPACE_NONE = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_NONE, + /** COLORPRIMARIES_BT601_P */ + TRANSCODER_COLORSPACE_BT601_EBU_FULL = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT601_EBU_FULL, + /** COLORPRIMARIES_BT601_N */ + TRANSCODER_COLORSPACE_BT601_SMPTE_C_FULL = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT601_SMPTE_C_FULL, + /** COLORPRIMARIES_BT709 */ + TRANSCODER_COLORSPACE_BT709_FULL = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT709_FULL, + /** COLORPRIMARIES_BT2020 */ + TRANSCODER_COLORSPACE_BT2020_HLG_FULL = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_HLG_FULL, + /** COLORPRIMARIES_BT2020 */ + TRANSCODER_COLORSPACE_BT2020_PQ_FULL = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_PQ_FULL, + /** COLORPRIMARIES_BT601_P */ + TRANSCODER_COLORSPACE_BT601_EBU_LIMIT = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT601_EBU_LIMIT, + /** COLORPRIMARIES_BT601_N */ + TRANSCODER_COLORSPACE_BT601_SMPTE_C_LIMIT = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT601_SMPTE_C_LIMIT, + /** COLORPRIMARIES_BT709 */ + TRANSCODER_COLORSPACE_BT709_LIMIT = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT709_LIMIT, + /** COLORPRIMARIES_BT2020 */ + TRANSCODER_COLORSPACE_BT2020_HLG_LIMIT = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_HLG_LIMIT, + /** COLORPRIMARIES_BT2020 */ + TRANSCODER_COLORSPACE_BT2020_PQ_LIMIT = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_PQ_LIMIT, + /** COLORPRIMARIES_SRGB */ + TRANSCODER_COLORSPACE_SRGB_FULL = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_SRGB_FULL, + /** COLORPRIMARIES_P3_D65 */ + TRANSCODER_COLORSPACE_P3_FULL = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_FULL, + /** COLORPRIMARIES_P3_D65 */ + TRANSCODER_COLORSPACE_P3_HLG_FULL = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_HLG_FULL, + /** COLORPRIMARIES_P3_D65 */ + TRANSCODER_COLORSPACE_P3_PQ_FULL = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_PQ_FULL, + /** COLORPRIMARIES_ADOBERGB */ + TRANSCODER_COLORSPACE_ADOBERGB_FULL = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_ADOBERGB_FULL, + /** COLORPRIMARIES_SRGB */ + TRANSCODER_COLORSPACE_SRGB_LIMIT = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_SRGB_LIMIT, + /** COLORPRIMARIES_P3_D65 */ + TRANSCODER_COLORSPACE_P3_LIMIT = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_LIMIT, + /** COLORPRIMARIES_P3_D65 */ + TRANSCODER_COLORSPACE_P3_HLG_LIMIT = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_HLG_LIMIT, + /** COLORPRIMARIES_P3_D65 */ + TRANSCODER_COLORSPACE_P3_PQ_LIMIT = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_PQ_LIMIT, + /** COLORPRIMARIES_ADOBERGB */ + TRANSCODER_COLORSPACE_ADOBERGB_LIMIT = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_ADOBERGB_LIMIT, + /** COLORPRIMARIES_SRGB */ + TRANSCODER_COLORSPACE_LINEAR_SRGB = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_LINEAR_SRGB, + /** equal to OH_COLORSPACE_LINEAR_SRGB */ + TRANSCODER_COLORSPACE_LINEAR_BT709 = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_LINEAR_BT709, + /** COLORPRIMARIES_P3_D65 */ + TRANSCODER_COLORSPACE_LINEAR_P3 = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_LINEAR_P3, + /** COLORPRIMARIES_BT2020 */ + TRANSCODER_COLORSPACE_LINEAR_BT2020 = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_LINEAR_BT2020, + /** equal to OH_COLORSPACE_SRGB_FULL */ + TRANSCODER_COLORSPACE_DISPLAY_SRGB = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_DISPLAY_SRGB, + /** equal to OH_COLORSPACE_P3_FULL */ + TRANSCODER_COLORSPACE_DISPLAY_P3_SRGB = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_DISPLAY_P3_SRGB, + /** equal to OH_COLORSPACE_P3_HLG_FULL */ + TRANSCODER_COLORSPACE_DISPLAY_P3_HLG = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_DISPLAY_P3_HLG, + /** equal to OH_COLORSPACE_P3_PQ_FULL */ + TRANSCODER_COLORSPACE_DISPLAY_P3_PQ = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_DISPLAY_P3_PQ, + /** COLORPRIMARIES_BT2020 */ + TRANSCODER_COLORSPACE_DISPLAY_BT2020_SRGB = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_DISPLAY_BT2020_SRGB, + /** equal to OH_COLORSPACE_BT2020_HLG_FULL */ + TRANSCODER_COLORSPACE_DISPLAY_BT2020_HLG = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_DISPLAY_BT2020_HLG, + /** equal to OH_COLORSPACE_BT2020_PQ_FULL */ + TRANSCODER_COLORSPACE_DISPLAY_BT2020_PQ = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_DISPLAY_BT2020_PQ, +}; + /** * @brief Provides listeners for transcodering errors and information events. * @@ -142,6 +215,18 @@ public: */ virtual int32_t SetVideoSize(int32_t videoFrameWidth, int32_t videoFrameHeight) = 0; + /** + * @brief Sets the colorspace of the video to transcoder + * + * This function must be called after {@link SetOutputFormat} but before {@link Prepare}. + * + * @param colorSpaceFormat Indicates the colorSpace format of the video to set. + * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual int32_t SetColorSpace(TranscoderColorSpace colorSpaceFormat) = 0; + /** * @brief Sets the encoder of the audio to transcoder. * diff --git a/interfaces/kits/c/native_avscreen_capture.h b/interfaces/kits/c/native_avscreen_capture.h index 462839168952c3d19d7fb8b3897391e2a92f5a3a..7137ba9bdc6deefff4a2620a23c1d0e883b63f84 100644 --- a/interfaces/kits/c/native_avscreen_capture.h +++ b/interfaces/kits/c/native_avscreen_capture.h @@ -480,6 +480,22 @@ OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SetCaptureContentChangedCallback( */ OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SetCaptureArea(struct OH_AVScreenCapture *capture, uint64_t displayId, OH_Rect* area); + +/** + * @brief Set the fill mode for screen capture when a privacy window exists + * @syscap SystemCapability.Multimedia.Media.AVScreenCapture + * @param {OH_AVScreenCapture_CaptureStrategy*} strategy Pointer to an OH_AVScreenCapture_CaptureStrategy instance + * @param {int32_t} value + * If set to 0, it means that when there is a privacy window interface, the output screen image is completely black. + * If set to 1, it means that when there is a privacy window interface, + * only the privacy window area of the output screen becomes black, and other values returns an error. + * @return Function result code. + * {@link AV_SCREEN_CAPTURE_ERR_OK} if the execution is successful. + * {@link AV_SCREEN_CAPTURE_ERR_INVALID_VAL} strategy is nullptr or value is invalid. + * @since 20 + */ +OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_StrategyForPrivacyMaskMode( + OH_AVScreenCapture_CaptureStrategy *strategy, int32_t value); #ifdef __cplusplus } #endif diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index 5f3d3e5b40f1115ba76c6c14fe7a33294befcab2..95d9fc8d9d73c835a989296106fc05dfed680076 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -179,6 +179,7 @@ ohos_shared_library("media") { "eventhandler:libeventhandler", "hilog:libhilog", "hisysevent:libhisysevent", + "hitrace:hitrace_meter", "image_framework:image", "image_framework:image_native", "ipc:ipc_core", diff --git a/services/engine/common/recorder_profiles/recorder_profiles_xml_parser.cpp b/services/engine/common/recorder_profiles/recorder_profiles_xml_parser.cpp index 2d3f4c83d2f2e0fa89b07d31947a8a35dc27f2b5..e360de717904251ee9008243ebd8970b4a4934f7 100644 --- a/services/engine/common/recorder_profiles/recorder_profiles_xml_parser.cpp +++ b/services/engine/common/recorder_profiles/recorder_profiles_xml_parser.cpp @@ -392,8 +392,12 @@ bool RecorderProfilesXmlParser::ParseRecorderProfilesSourceData(const std::strin if (xmlStrcmp(node->name, reinterpret_cast(sourceType.c_str())) == 0) { std::string property = SOURCE_TYPE_ID_MAP.at(sourceType); if (xmlHasProp(node, reinterpret_cast(const_cast(property.c_str())))) { - std::string capabilityValue = std::string(reinterpret_cast(xmlGetProp(node, - reinterpret_cast(const_cast(property.c_str()))))); + std::unique_ptr propValue( + xmlGetProp(node, reinterpret_cast(const_cast(property.c_str()))), xmlFree); + std::string capabilityValue{""}; + if (propValue.get() != nullptr) { + capabilityValue = std::string(reinterpret_cast(propValue.get())); + } int32_t id = 0; if (!StrToInt(capabilityValue, id)) { MEDIA_LOGE("call StrToInt func false, input str is: %{public}s", capabilityValue.c_str()); diff --git a/services/engine/histreamer/player/BUILD.gn b/services/engine/histreamer/player/BUILD.gn index ef223df53c900eddde7856fbe2dddf04b252ed38..6e3e49b76423ff494ca509a1c7d91cfe5d0036bf 100644 --- a/services/engine/histreamer/player/BUILD.gn +++ b/services/engine/histreamer/player/BUILD.gn @@ -90,6 +90,7 @@ ohos_static_library("media_engine_histreamer_player") { "graphic_surface:sync_fence", "hilog:libhilog", "hisysevent:libhisysevent", + "hitrace:hitrace_meter", "hitrace:libhitracechain", "init:libbegetutil", "ipc:ipc_single", diff --git a/services/engine/histreamer/player/hiplayer_callback_looper.cpp b/services/engine/histreamer/player/hiplayer_callback_looper.cpp index 83a2f32e6be3248c57bd4a42c048d26d71b3c1af..cdfefcf2014d706ca8d20fe6caf82fa42bf48d2d 100755 --- a/services/engine/histreamer/player/hiplayer_callback_looper.cpp +++ b/services/engine/histreamer/player/hiplayer_callback_looper.cpp @@ -311,7 +311,7 @@ void HiPlayerCallbackLooper::DoReportDfxInfo(const Any& info) MEDIA_LOG_E_SHORT("DoReportDfxInfo error, ptr is nullptr"); return; } - MEDIA_LOG_D("Report Dfx, callerName: " PUBLIC_LOG_S " type: " PUBLIC_LOG_D32, + MEDIA_LOG_DD("Report Dfx, callerName: " PUBLIC_LOG_S " type: " PUBLIC_LOG_D32, ptr->callerName.c_str(), static_cast(ptr->type)); obs->OnDfxInfo(*ptr); } diff --git a/services/engine/histreamer/player/hiplayer_impl.cpp b/services/engine/histreamer/player/hiplayer_impl.cpp index d67d9b9a1e73687de91986da6b14ef7ace3fa164..843706811568dde496f58885153d0ff35fd24dd0 100644 --- a/services/engine/histreamer/player/hiplayer_impl.cpp +++ b/services/engine/histreamer/player/hiplayer_impl.cpp @@ -93,7 +93,7 @@ public: void OnEvent(const Event &event) override { - MEDIA_LOG_D("PlayerEventReceiver OnEvent."); + MEDIA_LOG_DD("PlayerEventReceiver OnEvent."); task_->SubmitJobOnce([this, event] { std::shared_lock lk(cbMutex_); FALSE_RETURN(hiPlayerImpl_ != nullptr); @@ -103,7 +103,7 @@ public: void OnDfxEvent(const DfxEvent &event) override { - MEDIA_LOG_D("PlayerEventReceiver OnDfxEvent."); + MEDIA_LOG_DD("PlayerEventReceiver OnDfxEvent."); std::shared_lock lk(cbMutex_); FALSE_RETURN(hiPlayerImpl_ != nullptr); hiPlayerImpl_->HandleDfxEvent(event); @@ -926,6 +926,86 @@ int32_t HiPlayerImpl::Pause(bool isSystemOperation) return TransStatus(ret); } +int32_t HiPlayerImpl::Freeze() +{ + MediaTrace trace("HiPlayerImpl::Freeze"); + MEDIA_LOG_I("Freeze in"); + std::unique_lock lock(freezeMutex_); + + if (pipelineStates_ != PlayerStates::PLAYER_STARTED) { + MEDIA_LOG_I("can not freeze, current state = %{public}d", static_cast(pipelineStates_)); + PauseSourceDownload(); + return TransStatus(Status::OK); + } + + PauseSourceDownload(); + callbackLooper_.StopReportMediaProgress(); + StopFlvCheckLiveDelayTime(); + callbackLooper_.StopCollectMaxAmplitude(); + Status ret = Status::OK; + ret = demuxer_->Freeze(); + syncManager_->Pause(); + if (audioSink_ != nullptr) { + audioSink_->FreezeAudioSink(); + } + + if (ret != Status::OK) { + UpdateStateNoLock(PlayerStates::PLAYER_STATE_ERROR); + return TransStatus(ret); + } + UpdateStateNoLock(PlayerStates::PLAYER_FROZEN, false, false); + return TransStatus(Status::OK); +} + +int32_t HiPlayerImpl::UnFreeze() +{ + MediaTrace trace("HiPlayerImpl::UnFreeze"); + MEDIA_LOG_I("UnFreeze in"); + std::unique_lock lock(freezeMutex_); + + if (pipelineStates_ != PlayerStates::PLAYER_FROZEN) { + MEDIA_LOG_I("can not unfreeze, current state = %{public}d", static_cast(pipelineStates_)); + ResumeSourceDownload(); + return TransStatus(Status::OK); + } + + if (audioSink_ != nullptr) { + audioSink_->UnFreezeAudioSink(); + } + + callbackLooper_.StartReportMediaProgress(REPORT_PROGRESS_INTERVAL); + callbackLooper_.StartCollectMaxAmplitude(SAMPLE_AMPLITUDE_INTERVAL); + Status ret = Status::OK; + syncManager_->Resume(); + ret = demuxer_->UnFreeze(); + ResumeSourceDownload(); + startTime_ = GetCurrentMillisecond(); + StartFlvCheckLiveDelayTime(); + if (ret != Status::OK) { + UpdateStateNoLock(PlayerStates::PLAYER_STATE_ERROR); + return TransStatus(ret); + } + UpdateStateNoLock(PlayerStates::PLAYER_STARTED, false, false); + return TransStatus(ret); +} + +int32_t HiPlayerImpl::PauseSourceDownload() +{ + Status ret = Status::OK; + if (ret == Status::OK) { + sourceDownloadPaused_ = true; + } + return MSERR_OK; +} + +int32_t HiPlayerImpl::ResumeSourceDownload() +{ + if (sourceDownloadPaused_) { + sourceDownloadPaused_ = false; + } + return MSERR_OK; +} + void HiPlayerImpl::ReportAudioInterruptEvent() { isHintPauseReceived_ = false; @@ -1187,6 +1267,9 @@ Status HiPlayerImpl::HandleSeek(int64_t seekPos, PlayerSeekMode mode) case PlayerStates::PLAYER_PREPARED: { return doPreparedSeek(seekPos, mode); } + case PlayerStates::PLAYER_FROZEN: { + return doFrozenSeek(seekPos, mode); + } default: MEDIA_LOG_I_SHORT("Seek in error pipelineStates: " PUBLIC_LOG_D32, static_cast(pipelineStates_)); @@ -1268,6 +1351,19 @@ Status HiPlayerImpl::doPausedSeek(int64_t seekPos, PlayerSeekMode mode) return rtv; } +Status HiPlayerImpl::doFrozenSeek(int64_t seekPos, PlayerSeekMode mode) +{ + MEDIA_LOG_I("doFrozenSeek."); + pipeline_ -> Pause(); + pipeline_ -> Flush(); + auto rtv = doSeek(seekPos, mode); + inEosSeek_ = false; + if ((rtv == Status::OK) && demuxer_->IsRenderNextVideoFrameSupported() && !demuxer_->IsVideoEos()) { + rtv = pipeline_->Preroll(true); + } + return rtv; +} + Status HiPlayerImpl::doCompletedSeek(int64_t seekPos, PlayerSeekMode mode) { MEDIA_LOG_D("doCompletedSeek"); @@ -2638,6 +2734,7 @@ void HiPlayerImpl::HandleCompleteEvent(const Event& event) AutoLock lock(handleCompleteMutex_); FALSE_RETURN_NOLOG(curState_ != PlayerStateId::STOPPED && HandleEosFlagState(event)); FALSE_RETURN_MSG(!inEosPlayingSeekContinuous_, "Skip complete event in seek continous!"); + std::unique_lock freezeLock(freezeMutex_); MEDIA_LOG_I("OnComplete looping: " PUBLIC_LOG_D32 ".", singleLoop_.load()); isStreaming_ = false; Format format; @@ -2856,6 +2953,7 @@ void HiPlayerImpl::NotifyAudioInterrupt(const Event& event) if (forceType == OHOS::AudioStandard::INTERRUPT_FORCE) { if (hintType == OHOS::AudioStandard::INTERRUPT_HINT_PAUSE || hintType == OHOS::AudioStandard::INTERRUPT_HINT_STOP) { + std::unique_lock freezeLock(freezeMutex_); isHintPauseReceived_ = true; Status ret = Status::OK; ret = pipeline_->Pause(); @@ -3662,7 +3760,7 @@ void HiPlayerImpl::SetFlvObs() // flv live with play water line max wait 30s. FALSE_RETURN_MSG(isSetBufferDurationForPlaying_ && bufferDurationForPlaying_ > 0, - "Flv live stream and no duration water line"); + "Flv live stream and no duration water line"); MEDIA_LOG_I("Wait flv live play water line for max 30s bufferDuration %{public}.2f", bufferDurationForPlaying_); std::unique_lock lock(flvLiveMutex_); flvLiveCond_.wait_for(lock, std::chrono::milliseconds(FLV_LIVE_PREPARE_WAIT_TIME), diff --git a/services/engine/histreamer/player/hiplayer_impl.h b/services/engine/histreamer/player/hiplayer_impl.h index 5830728c23e966837a21c2dc15cf7f5419e3558a..6c47004df79194b4af82f679a0abf8766c8be909 100755 --- a/services/engine/histreamer/player/hiplayer_impl.h +++ b/services/engine/histreamer/player/hiplayer_impl.h @@ -116,6 +116,10 @@ public: int32_t Pause(bool isSystemOperation) override; int32_t Stop() override; int32_t Reset() override; + int32_t Freeze() override; + int32_t UnFreeze() override; + int32_t PauseSourceDownload() override; + int32_t ResumeSourceDownload() override; int32_t Seek(int32_t mSeconds, PlayerSeekMode mode) override; int32_t SetVolume(float leftVolume, float rightVolume) override; int32_t SetVolumeMode(int32_t mode) override; @@ -263,6 +267,7 @@ private: Status doPreparedSeek(int64_t seekPos, PlayerSeekMode mode); Status doStartedSeek(int64_t seekPos, PlayerSeekMode mode); Status doPausedSeek(int64_t seekPos, PlayerSeekMode mode); + Status doFrozenSeek(int64_t seekPos, PlayerSeekMode mode); Status doCompletedSeek(int64_t seekPos, PlayerSeekMode mode); Status doSeek(int64_t seekPos, PlayerSeekMode mode); Status doSetPlaybackSpeed(float speed); @@ -469,6 +474,8 @@ private: std::mutex fdMutex_ {}; std::unique_ptr fdsanFd_ = nullptr; std::atomic enableCameraPostprocessing_ {false}; + bool sourceDownloadPaused_ {false}; + std::mutex freezeMutex_; }; } // namespace Media } // namespace OHOS diff --git a/services/engine/histreamer/recorder/BUILD.gn b/services/engine/histreamer/recorder/BUILD.gn index 650d86b59aa4dae7555853f4e79f0201ce6321e1..198d8ab14cdcfa300b659721aaa75608b8ffc82a 100644 --- a/services/engine/histreamer/recorder/BUILD.gn +++ b/services/engine/histreamer/recorder/BUILD.gn @@ -73,6 +73,7 @@ ohos_static_library("media_engine_histreamer_recorder") { "graphic_surface:sync_fence", "hilog:libhilog", "hisysevent:libhisysevent", + "hitrace:hitrace_meter", "ipc:ipc_single", "media_foundation:media_foundation", "safwk:system_ability_fwk", diff --git a/services/engine/histreamer/recorder/hirecorder_impl.cpp b/services/engine/histreamer/recorder/hirecorder_impl.cpp index 2f0974a833675b34aa24b333816749baf6588409..c7730f5903eb84a78d922296cb8424bb27bbf2f4 100644 --- a/services/engine/histreamer/recorder/hirecorder_impl.cpp +++ b/services/engine/histreamer/recorder/hirecorder_impl.cpp @@ -593,6 +593,18 @@ int32_t HiRecorderImpl::SetParameter(int32_t sourceId, const RecorderParam &recP return Configure(sourceId, recParam); } +void HiRecorderImpl::UpdateVideoFirstFramePts(const Event &event) +{ + if (audioCaptureFilter_) { + int64_t firstFramePts = AnyCast(event.param); + audioCaptureFilter_->SetVideoFirstFramePts(firstFramePts); + } + if (audioDataSourceFilter_) { + int64_t firstFramePts = AnyCast(event.param); + audioDataSourceFilter_->SetVideoFirstFramePts(firstFramePts); + } +} + void HiRecorderImpl::OnEvent(const Event &event) { switch (event.type) { @@ -633,10 +645,7 @@ void HiRecorderImpl::OnEvent(const Event &event) break; } case EventType::EVENT_VIDEO_FIRST_FRAME: { - if (audioCaptureFilter_) { - int64_t firstFramePts = AnyCast(event.param); - audioCaptureFilter_->SetVideoFirstFramePts(firstFramePts); - } + UpdateVideoFirstFramePts(event); break; } default: diff --git a/services/engine/histreamer/recorder/hirecorder_impl.h b/services/engine/histreamer/recorder/hirecorder_impl.h index 2b0220c0d3964f0e9132b054b919c5f058a8deca..7eca55b364b07a730705637c006d019e6df62f56 100644 --- a/services/engine/histreamer/recorder/hirecorder_impl.h +++ b/services/engine/histreamer/recorder/hirecorder_impl.h @@ -117,7 +117,7 @@ private: EncoderCapabilityData ConvertAudioEncoderInfo(MediaAVCodec::CapabilityData *capabilityData); EncoderCapabilityData ConvertVideoEncoderInfo(MediaAVCodec::CapabilityData *capabilityData); std::vector ConvertEncoderInfo(std::vector &capData); - + void UpdateVideoFirstFramePts(const Event &event); AudioRecorderChangeInfo ConvertCapturerChangeInfo(const AudioStandard::AudioCapturerChangeInfo &capturerChangeInfo); void CloseFd(); std::atomic audioCount_{0}; diff --git a/services/engine/histreamer/transcoder/BUILD.gn b/services/engine/histreamer/transcoder/BUILD.gn index b32edfad1eb2d39cd7508d5d4ec7a82fd26e9fad..da0b7f6a935fefb5a382ca3eaa9f139a7eed3fcd 100644 --- a/services/engine/histreamer/transcoder/BUILD.gn +++ b/services/engine/histreamer/transcoder/BUILD.gn @@ -76,6 +76,7 @@ ohos_static_library("media_engine_histreamer_transcoder") { "graphic_surface:sync_fence", "hilog:libhilog", "hisysevent:libhisysevent", + "hitrace:hitrace_meter", "ipc:ipc_single", "media_foundation:media_foundation", "safwk:system_ability_fwk", diff --git a/services/engine/histreamer/transcoder/hitranscoder_impl.cpp b/services/engine/histreamer/transcoder/hitranscoder_impl.cpp index 0ef8f19170425210f8aee00abb96c04b5d7b2187..a5c86735c9e0ffb549303fb391d3536741bb4eda 100644 --- a/services/engine/histreamer/transcoder/hitranscoder_impl.cpp +++ b/services/engine/histreamer/transcoder/hitranscoder_impl.cpp @@ -423,10 +423,21 @@ Status HiTransCoderImpl::ConfigureVideoWidthHeight(const TransCoderParam &transC VideoRectangle videoRectangle = static_cast(transCoderParam); if (videoRectangle.width != -1) { videoEncFormat_->Set(videoRectangle.width); - } + } if (videoRectangle.height != -1) { videoEncFormat_->Set(videoRectangle.height); - } + } + return Status::OK; +} + +Status HiTransCoderImpl::ConfigureColorSpace(const TransCoderParam &transCoderParam) +{ + VideoColorSpace colSpa = static_cast(transCoderParam); + MEDIA_LOG_I("HiTranscoderImpl::ConfigureColorSpace %{public}d", static_cast(colSpa.colorSpaceFmt)); + if (static_cast(colSpa.colorSpaceFmt) <= 0) { + return Status::ERROR_INVALID_PARAMETER; + } + videoEncFormat_->Set(static_cast(colSpa.colorSpaceFmt)); return Status::OK; } @@ -481,6 +492,10 @@ int32_t HiTransCoderImpl::Configure(const TransCoderParam &transCoderParam) videoEncFormat_->Set(videoBitrate.bitRate); break; } + case TransCoderPublicParamType::COLOR_SPACE_FMT: { + ret = ConfigureColorSpace(transCoderParam); + break; + } case TransCoderPublicParamType::AUDIO_ENC_FMT: { AudioEnc audioEnc = static_cast(transCoderParam); MEDIA_LOG_I("HiTransCoderImpl::Configure audioEnc %{public}d", audioEnc.encFmt); @@ -697,6 +712,9 @@ void HiTransCoderImpl::AppendDstMediaInfo(std::shared_ptr meta) videoEncFormat_->Get(dstVideoBitrate); meta->SetData(Tag::AV_TRANSCODER_DST_VIDEO_BITRATE, static_cast(dstVideoBitrate)); meta->SetData(Tag::AV_TRANSCODER_DST_HDR_TYPE, 0); + int32_t colorSpaceFormat = 0; + videoEncFormat_->Get(colorSpaceFormat); + meta->SetData(Tag::AV_TRANSCODER_DST_COLOR_SPACE, colorSpaceFormat); int32_t dstAudioSampleRate; audioEncFormat_->Get(dstAudioSampleRate); meta->SetData(Tag::AV_TRANSCODER_DST_AUDIO_SAMPLE_RATE, dstAudioSampleRate); @@ -808,9 +826,10 @@ Status HiTransCoderImpl::LinkVideoDecoderFilter(const std::shared_ptrSetCodecFormat(videoEncFormat_); videoDecoderFilter_->Init(transCoderEventReceiver_, transCoderFilterCallback_); Status ret = pipeline_->LinkFilters(preFilter, {videoDecoderFilter_}, type); - FALSE_RETURN_V_MSG_E(ret == Status::OK, ret, "Add videoDecoderFilter_ to pipeline fail"); + FALSE_RETURN_V_MSG_E(ret == Status::OK, ret, "Add videoDecoderFilter to pipeline failed"); return Status::OK; } diff --git a/services/engine/histreamer/transcoder/hitranscoder_impl.h b/services/engine/histreamer/transcoder/hitranscoder_impl.h index e8542d61c2c984e24a0d4ece9b9679ce7b75f76d..b2925dc3749e300d530ba7d89411ec0b26508b1c 100644 --- a/services/engine/histreamer/transcoder/hitranscoder_impl.h +++ b/services/engine/histreamer/transcoder/hitranscoder_impl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 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 @@ -65,6 +65,7 @@ private: void AppendDstMediaInfo(std::shared_ptr meta); int32_t GetRealPath(const std::string &url, std::string &realUrlPath) const; Status ConfigureVideoEncoderFormat(const TransCoderParam &transCoderParam); + Status ConfigureColorSpace(const TransCoderParam &transCoderParam); Status LinkAudioDecoderFilter(const std::shared_ptr& preFilter, Pipeline::StreamType type); Status LinkAudioEncoderFilter(const std::shared_ptr& preFilter, Pipeline::StreamType type); Status LinkVideoDecoderFilter(const std::shared_ptr& preFilter, Pipeline::StreamType type); diff --git a/services/include/i_media_service.h b/services/include/i_media_service.h index 699114c596563d57e9b7d9b3f835d2323b3343f4..227345b8831fbde8d13e14e4a26cbd2def2c884a 100644 --- a/services/include/i_media_service.h +++ b/services/include/i_media_service.h @@ -233,6 +233,12 @@ public: virtual void ReleaseClientListener() = 0; virtual bool CanKillMediaService() = 0; + + virtual std::vector GetPlayerPids() = 0; + + virtual int32_t ProxyForFreeze(const std::set& pidList, bool isProxy) = 0; + + virtual int32_t ResetAllProxy() = 0; }; class __attribute__((visibility("default"))) MediaServiceFactory { diff --git a/services/include/i_player_service.h b/services/include/i_player_service.h index 6497f45c65f24f552e44235cc1ae6fc9a8a7ffd1..27d400ee60c5e53d08b430ac9cf4884194a7b5d9 100644 --- a/services/include/i_player_service.h +++ b/services/include/i_player_service.h @@ -670,6 +670,31 @@ public: return 0; } + /** + * @brief Enables or disables the report of audio interrupt during frozen state. + * + * @param enable Indicates whether to enable the report of audio interrupt during frozen state. + * @return Returns {@link MSERR_OK} if the report of audio interrupt is enabled or disabled; returns an error code + * defined in {@link media_errors.h} otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual int32_t EnableReportAudioInterrupt(bool enable) + { + (void)enable; + return 0; + } + + virtual int32_t Freeze() + { + return 0; + } + + virtual int32_t UnFreeze() + { + return 0; + } + virtual int32_t SetStartFrameRateOptEnabled(bool enabled) { (void)enabled; diff --git a/services/include/i_transcoder_service.h b/services/include/i_transcoder_service.h index 09ddb37ea04531d87883103b9837bd9e87722dfe..f4e18d7249c6bac603f505bb699123869a25691e 100644 --- a/services/include/i_transcoder_service.h +++ b/services/include/i_transcoder_service.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Huawei Device Co., Ltd. + * Copyright (C) 2024-2025 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 @@ -67,6 +67,18 @@ public: */ virtual int32_t SetVideoEncodingBitRate(int32_t rate) = 0; + /** + * @brief Sets the colorspace of the video to transcoder. + * + * This function must be called after {@link SetAudioSource} but before {@link Prepare}. + * + * @param colorSpaceFormat Indicates the color space format of the video to set. + * @return Returns {@link MSERR_Ok} if the setting is successful; returns an error code otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual int32_t SetColorSpace(TranscoderColorSpace colorSpaceFormat) = 0; + /** * @brief Sets the encoder of the audio to transcoder. * diff --git a/services/services/engine_intf/i_player_engine.h b/services/services/engine_intf/i_player_engine.h index eaf9885537a50e53a45dace7ffd8e74ae77ac144..5138263cc17d4f7bb6a76dfda989b4196bf921f2 100644 --- a/services/services/engine_intf/i_player_engine.h +++ b/services/services/engine_intf/i_player_engine.h @@ -94,6 +94,16 @@ public: virtual int32_t Pause(bool isSystemOperation) = 0; virtual int32_t Stop() = 0; virtual int32_t Reset() = 0; + virtual int32_t Freeze() = 0; + virtual int32_t UnFreeze() = 0; + virtual int32_t PauseSourceDownload() + { + return 0; + } + virtual int32_t ResumeSourceDownload() + { + return 0; + } virtual int32_t SetVolume(float leftVolume, float rightVolume) = 0; virtual int32_t SetVolumeMode(int32_t mode) = 0; virtual int32_t Seek(int32_t mSeconds, PlayerSeekMode mode) = 0; diff --git a/services/services/engine_intf/transcoder_param.h b/services/services/engine_intf/transcoder_param.h index 61aa532109a977802c8fcd00c062af0fa0c24f59..f140032edea32423e8806a1d5976b01ee7a17534 100644 --- a/services/services/engine_intf/transcoder_param.h +++ b/services/services/engine_intf/transcoder_param.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Huawei Device Co., Ltd. + * Copyright (C) 2024-2025 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 @@ -29,6 +29,7 @@ enum TransCoderPublicParamType : uint32_t { VIDEO_ENC_FMT, VIDEO_RECTANGLE, VIDEO_BITRATE, + COLOR_SPACE_FMT, VIDEO_PUBLIC_PARAM_END, // audio begin AUDIO_PUBLIC_PARAM_BEGIN, @@ -71,6 +72,12 @@ struct VideoBitRate : public TransCoderParam { int32_t bitRate; }; +struct VideoColorSpace : public TransCoderParam { + explicit VideoColorSpace(TranscoderColorSpace fmt) : TransCoderParam(TransCoderPublicParamType::COLOR_SPACE_FMT), + colorSpaceFmt(fmt) {} + TranscoderColorSpace colorSpaceFmt; +}; + struct AudioEnc : public TransCoderParam { explicit AudioEnc(AudioCodecFormat fmt) : TransCoderParam(TransCoderPublicParamType::AUDIO_ENC_FMT), encFmt(fmt) {} AudioCodecFormat encFmt; diff --git a/services/services/monitor/server/monitor_server_object.cpp b/services/services/monitor/server/monitor_server_object.cpp index a663ab295dad023f0c435cc1e2d920dac0ac0ef3..8122231d2b1ffc90ee59cc45536e9812bfb7e40a 100644 --- a/services/services/monitor/server/monitor_server_object.cpp +++ b/services/services/monitor/server/monitor_server_object.cpp @@ -66,5 +66,15 @@ void MonitorServerObject::UnSetIpcAlarmedFlag() { alarmed_ = false; } + +int32_t MonitorServerObject::EnableMonitor(int32_t pid) +{ + return MonitorServer::GetInstance().EnableMonitor(pid); +} + +int32_t MonitorServerObject::DisableMonitor(int32_t pid) +{ + return MonitorServer::GetInstance().DisableMonitor(pid); +} } // namespace Media } // namespace OHOS diff --git a/services/services/monitor/server/monitor_server_object.h b/services/services/monitor/server/monitor_server_object.h index 85e2884d1eb42deb71fc170ce3dc9374371cde3e..6a6e06a4c56c7663ed73dc905171cb57445c9288 100644 --- a/services/services/monitor/server/monitor_server_object.h +++ b/services/services/monitor/server/monitor_server_object.h @@ -31,6 +31,8 @@ public: int32_t IpcRecovery(bool fromMonitor); void SetIpcAlarmedFlag(); void UnSetIpcAlarmedFlag(); + int32_t EnableMonitor(int32_t pid); + int32_t DisableMonitor(int32_t pid); protected: int32_t RegisterMonitor(int32_t pid); diff --git a/services/services/observer/incall_observer.cpp b/services/services/observer/incall_observer.cpp index edec2b73d7dbc82376728ffd83c549b99f507eb2..e2062e103a5fda771d9dc7b13563320ac3d4c8d8 100644 --- a/services/services/observer/incall_observer.cpp +++ b/services/services/observer/incall_observer.cpp @@ -157,7 +157,7 @@ bool InCallObserver::RegisterObserver() ret = true; mediaTelephonyListeners_.push_back(telephonyObserver_); } else { - MEDIA_LOGI("InCallObserver Register Listener observer ret:%{public}d", observerRes); + MEDIA_LOGI("InCallObserver Register Listener observer ret:%{public}d", observerRes); } return ret; } diff --git a/services/services/observer/media_telephony_listener.cpp b/services/services/observer/media_telephony_listener.cpp index 58a557ac15b800e9a1dc340bdbdd8e46c696a116..db8c0079d6f5e3ade012a4d37e0f3298bc1dc15d 100644 --- a/services/services/observer/media_telephony_listener.cpp +++ b/services/services/observer/media_telephony_listener.cpp @@ -21,6 +21,7 @@ #include "call_manager_base.h" #include #include +#include "system_ability_definition.h" namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_PLAYER, "MediaTelephonyListener"}; @@ -39,6 +40,16 @@ MediaTelephonyListener::~MediaTelephonyListener() MEDIA_LOGI("0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this)); } +bool MediaTelephonyListener::HasCallFromTel() +{ + std::shared_ptr callManagerClientPtr = + DelayedSingleton::GetInstance(); + callManagerClientPtr->Init(OHOS::TELEPHONY_CALL_MANAGER_SYS_ABILITY_ID); + bool hasCall = callManagerClientPtr->HasCall(false); // not include voip call + MEDIA_LOGI("SC MediaTelephonyListener hasCall: %{public}d", hasCall); + return hasCall; +} + void MediaTelephonyListener::OnCallStateUpdated(int32_t slotId, int32_t callState, const std::u16string &phoneNumber) { MEDIA_LOGI("SC OnCallStateUpdated slotId = %{public}d, callState = %{public}d", slotId, callState); @@ -53,7 +64,9 @@ void MediaTelephonyListener::OnCallStateUpdated(int32_t slotId, int32_t callStat callState == static_cast(TelCallState::CALL_STATUS_ACTIVE) || callState == static_cast(TelCallState::CALL_STATUS_WAITING)) { MEDIA_LOGD("SC OnCallStateUpdated IN Report in call"); - InCallObserver::GetInstance().OnCallStateUpdated(true); + if (HasCallFromTel()) { + InCallObserver::GetInstance().OnCallStateUpdated(true); + } } else if (callState == static_cast(TelCallState::CALL_STATUS_DISCONNECTED)) { // CALL_STATUS_DISCONNECTING 重复状态不需要 MEDIA_LOGD("SC OnCallStateUpdated IN Report stop call"); diff --git a/services/services/observer/media_telephony_listener.h b/services/services/observer/media_telephony_listener.h index 0b1e2018c337be26990e745ccdbccffbefafddd7..436e43273f3abcd41d1e16715c4199b2dd2f0efa 100644 --- a/services/services/observer/media_telephony_listener.h +++ b/services/services/observer/media_telephony_listener.h @@ -47,6 +47,9 @@ public: void OnVoiceMailMsgIndicatorUpdated(int32_t slotId, bool voiceMailMsgResult) override; void OnIccAccountUpdated() override; + +private: + bool HasCallFromTel(); }; } } diff --git a/services/services/player/client/player_client.cpp b/services/services/player/client/player_client.cpp index ca87ceb683b869d59f94260049b0ef0656763c83..d2abad267d2c2bf1d4874c85da21d8fb41b0440f 100644 --- a/services/services/player/client/player_client.cpp +++ b/services/services/player/client/player_client.cpp @@ -547,5 +547,13 @@ int32_t PlayerClient::EnableReportMediaProgress(bool enable) CHECK_AND_RETURN_RET_LOG(playerProxy_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerProxy_->EnableReportMediaProgress(enable); } + +int32_t PlayerClient::EnableReportAudioInterrupt(bool enable) +{ + MEDIA_LOGD("PlayerClient:0x%{public}06" PRIXPTR " EnableReportAudioInterrupt in", FAKE_POINTER(this)); + std::lock_guard lock(mutex_); + CHECK_AND_RETURN_RET_LOG(playerProxy_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); + return playerProxy_->EnableReportAudioInterrupt(enable); +} } // namespace Media } // namespace OHOS \ No newline at end of file diff --git a/services/services/player/client/player_client.h b/services/services/player/client/player_client.h index 259cc46348d29847b3a5457fb9196ff7c018dfd3..84b6f74177bf9d9f6d25d58f8b5b0b9f01018f6c 100644 --- a/services/services/player/client/player_client.h +++ b/services/services/player/client/player_client.h @@ -94,6 +94,7 @@ public: int32_t SetReopenFd(int32_t fd) override; int32_t EnableCameraPostprocessing() override; int32_t EnableReportMediaProgress(bool enable) override; + int32_t EnableReportAudioInterrupt(bool enable) override; private: int32_t CreateListenerObject(); diff --git a/services/services/player/ipc/i_standard_player_listener.h b/services/services/player/ipc/i_standard_player_listener.h index d11191ceebbac4e23426ebbc529fb52c46b78913..256d078f5411f07b3cd1e50702b652343bcf5809 100644 --- a/services/services/player/ipc/i_standard_player_listener.h +++ b/services/services/player/ipc/i_standard_player_listener.h @@ -38,6 +38,14 @@ public: (void)errorCode; (void)errorMsg; } + virtual void SetFreezeFlag(bool isFrozen) + { + (void)isFrozen; + } + virtual void SetInterruptListenerFlag(bool isRegistered) + { + (void)isRegistered; + } enum PlayerListenerMsg { ON_ERROR = 0, ON_INFO, diff --git a/services/services/player/ipc/i_standard_player_service.h b/services/services/player/ipc/i_standard_player_service.h index f5af7e41c13f262650be9be8e4e8b8384b0cb449..e412397789c817dac82f6aa0685e83986501871d 100644 --- a/services/services/player/ipc/i_standard_player_service.h +++ b/services/services/player/ipc/i_standard_player_service.h @@ -182,6 +182,12 @@ public: return 0; } + virtual int32_t EnableReportAudioInterrupt(bool enable) + { + (void)enable; + return 0; + } + /** * IPC code ID */ @@ -245,6 +251,7 @@ public: SET_REOPEN_FD, ENABLE_CAMERA_POSTPROCESSING, ENABLE_REPORT_MEDIA_PROGRESS, + ENABLE_REPORT_AUDIO_INTERRUPT, MAX_IPC_ID, // all IPC codes should be added before MAX_IPC_ID }; diff --git a/services/services/player/ipc/player_listener_proxy.cpp b/services/services/player/ipc/player_listener_proxy.cpp index d312f349c45758ef87747cc3588fc55b2d0dcb2f..b2a8bd75902d838ca1ccb32233e790e949d679f2 100644 --- a/services/services/player/ipc/player_listener_proxy.cpp +++ b/services/services/player/ipc/player_listener_proxy.cpp @@ -40,7 +40,10 @@ void PlayerListenerProxy::OnError(int32_t errorCode, const std::string &errorMsg { MessageParcel data; MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC); + + int32_t options = isFrozen_ ? (MessageOption::TF_ASYNC | MessageOption::TF_ASYNC_WAKEUP_LATER) + : MessageOption::TF_ASYNC; + MessageOption option(options); bool token = data.WriteInterfaceToken(PlayerListenerProxy::GetDescriptor()); CHECK_AND_RETURN_LOG(token, "Failed to write descriptor!"); @@ -63,7 +66,12 @@ void PlayerListenerProxy::OnInfo(PlayerOnInfoType type, int32_t extra, const For MessageParcel data; MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC); + + bool isReportLater = isFrozen_ && (type != INFO_TYPE_INTERRUPT_EVENT || + (type == INFO_TYPE_INTERRUPT_EVENT && !isRegistered_)); + int32_t options = isReportLater ? (MessageOption::TF_ASYNC | MessageOption::TF_ASYNC_WAKEUP_LATER) + : MessageOption::TF_ASYNC; + MessageOption option(options); bool token = data.WriteInterfaceToken(PlayerListenerProxy::GetDescriptor()); CHECK_AND_RETURN_LOG(token, "Failed to write descriptor!"); @@ -71,11 +79,24 @@ void PlayerListenerProxy::OnInfo(PlayerOnInfoType type, int32_t extra, const For data.WriteInt32(type); data.WriteInt32(extra); MediaParcel::Marshalling(data, infoBody); + std::string info = infoBody.Stringify(); + MEDIA_LOGD("0x%{public}06" PRIXPTR " send on info type: %{public}d extra %{public}d, format %{public}s", + FAKE_POINTER(this), type, extra, info.c_str()); int error = SendRequest(PlayerListenerMsg::ON_INFO, data, reply, option); CHECK_AND_RETURN_LOG(error == MSERR_OK, "0x%{public}06" PRIXPTR " on info failed, error: %{public}d", FAKE_POINTER(this), error); } +void PlayerListenerProxy::SetFreezeFlag(bool isFrozen) +{ + isFrozen_ = isFrozen; +} + +void PlayerListenerProxy::SetInterruptListenerFlag(bool isRegistered) +{ + isRegistered_ = isRegistered; +} + PlayerListenerCallback::PlayerListenerCallback(const sptr &listener) : listener_(listener) { MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this)); @@ -99,6 +120,18 @@ void PlayerListenerCallback::OnInfo(PlayerOnInfoType type, int32_t extra, const listener_->OnInfo(type, extra, infoBody); } +void PlayerListenerCallback::SetFreezeFlag(bool isFrozen) +{ + CHECK_AND_RETURN(listener_ != nullptr); + listener_->SetFreezeFlag(isFrozen); +} + +void PlayerListenerCallback::SetInterruptListenerFlag(bool isRegistered) +{ + CHECK_AND_RETURN(listener_ != nullptr); + listener_->SetInterruptListenerFlag(isRegistered); +} + int32_t PlayerListenerProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { diff --git a/services/services/player/ipc/player_listener_proxy.h b/services/services/player/ipc/player_listener_proxy.h index 8505cf9431c0a2c485208da81a242b249a1d8fcd..eed48cde9f4d21d8c5231751922ca600d09d03a4 100644 --- a/services/services/player/ipc/player_listener_proxy.h +++ b/services/services/player/ipc/player_listener_proxy.h @@ -30,6 +30,8 @@ public: void OnError(int32_t errorCode, const std::string &errorMsg) override; void OnInfo(PlayerOnInfoType type, int32_t extra, const Format &infoBody = {}) override; + void SetFreezeFlag(bool isFrozen) override; + void SetInterruptListenerFlag(bool isRegistered) override; private: sptr listener_ = nullptr; @@ -42,10 +44,14 @@ public: void OnError(int32_t errorCode, const std::string &errorMsg) override; void OnInfo(PlayerOnInfoType type, int32_t extra, const Format &infoBody = {}) override; + void SetFreezeFlag(bool isFrozen) override; + void SetInterruptListenerFlag(bool isRegistered) override; private: int32_t SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); static inline BrokerDelegator delegator_; + std::atomic isFrozen_ = false; + std::atomic isRegistered_ = false; }; } // namespace Media } // namespace OHOS diff --git a/services/services/player/ipc/player_service_proxy.cpp b/services/services/player/ipc/player_service_proxy.cpp index a34a1de93e6b70a0cee4d8b1971192bb2842b99b..0ac72a409b487bff1170e24329ab666b216249b8 100644 --- a/services/services/player/ipc/player_service_proxy.cpp +++ b/services/services/player/ipc/player_service_proxy.cpp @@ -115,6 +115,7 @@ void PlayerServiceProxy::InitPlayerFuncsPart2() playerFuncs_[SET_REOPEN_FD] = "Player::SetReopenFd"; playerFuncs_[ENABLE_CAMERA_POSTPROCESSING] = "Player::EnableCameraPostprocessing"; playerFuncs_[ENABLE_REPORT_MEDIA_PROGRESS] = "Player::EnableReportMediaProgress"; + playerFuncs_[ENABLE_REPORT_AUDIO_INTERRUPT] = "Player::EnableReportAudioInterrupt"; } int32_t PlayerServiceProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) @@ -1282,5 +1283,22 @@ int32_t PlayerServiceProxy::EnableReportMediaProgress(bool enable) "EnableReportMediaProgress failed, error: %{public}d", error); return reply.ReadInt32(); } + +int32_t PlayerServiceProxy::EnableReportAudioInterrupt(bool enable) +{ + MediaTrace trace("PlayerServiceProxy::EnableReportAudioInterrupt"); + MessageParcel data; + MessageParcel reply; + MessageOption option; + + bool token = data.WriteInterfaceToken(PlayerServiceProxy::GetDescriptor()); + CHECK_AND_RETURN_RET_LOG(token, MSERR_INVALID_OPERATION, "Failed to write descriptor!"); + + data.WriteBool(enable); + int32_t error = SendRequest(ENABLE_REPORT_AUDIO_INTERRUPT, data, reply, option); + CHECK_AND_RETURN_RET_LOG(error == MSERR_OK, MSERR_INVALID_OPERATION, + "EnableReportAudioInterrupt failed, error: %{public}d", error); + return reply.ReadInt32(); +} } // namespace Media } // namespace OHOS diff --git a/services/services/player/ipc/player_service_proxy.h b/services/services/player/ipc/player_service_proxy.h index eb34cac1ecfda8b69e06fc9e491da1ce75649f9e..1430091c4722dff86001127943092f965046c863 100644 --- a/services/services/player/ipc/player_service_proxy.h +++ b/services/services/player/ipc/player_service_proxy.h @@ -88,6 +88,7 @@ public: int32_t SetReopenFd(int32_t fd) override; int32_t EnableCameraPostprocessing() override; int32_t EnableReportMediaProgress(bool enable) override; + int32_t EnableReportAudioInterrupt(bool enable) override; private: int32_t SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); void InitPlayerFuncsPart1(); diff --git a/services/services/player/ipc/player_service_stub.cpp b/services/services/player/ipc/player_service_stub.cpp index 826cedee1048d8e2c41ab27e91094e8d8ae3ab32..46920955f9bd0e568c0e2a4bde8cd4a8b4799595 100644 --- a/services/services/player/ipc/player_service_stub.cpp +++ b/services/services/player/ipc/player_service_stub.cpp @@ -76,6 +76,46 @@ PlayerServiceStub::~PlayerServiceStub() MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this)); } +int32_t PlayerServiceStub::Freeze() +{ + MediaTrace trace("PlayerServiceStub::Freeze"); + MEDIA_LOGI("0x%{public}06" PRIXPTR " Stub received Freeze", FAKE_POINTER(this)); + CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr"); + auto task = std::make_shared>([this] { + MEDIA_LOGI("0x%{public}06" PRIXPTR " Stub freeze in", FAKE_POINTER(this)); + int32_t ret = MSERR_OK; + CHECK_AND_RETURN_RET_LOG(!isFrozen_, ret, "can not freeze"); + (void)DisableMonitor(appPid_); + ret = playerServer_->Freeze(); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "Freeze failed"); + isFrozen_ = true; + return ret; + }); + int32_t ret = taskQue_.EnqueueTask(task); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "EnqueueTask failed"); + return MSERR_OK; +} + +int32_t PlayerServiceStub::UnFreeze() +{ + MediaTrace trace("PlayerServiceStub::UnFreeze"); + MEDIA_LOGI("0x%{public}06" PRIXPTR " Stub received Unfreeze", FAKE_POINTER(this)); + CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr"); + auto task = std::make_shared>([this] { + MEDIA_LOGI("0x%{public}06" PRIXPTR " Stub Unfreeze in", FAKE_POINTER(this)); + int32_t ret = MSERR_OK; + CHECK_AND_RETURN_RET_LOG(isFrozen_, ret, "can not UnFreeze"); + ret = playerServer_->UnFreeze(); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "UnFreeze failed"); + (void)EnableMonitor(appPid_); + isFrozen_ = false; + return ret; + }); + int32_t ret = taskQue_.EnqueueTask(task); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "EnqueueTask failed"); + return MSERR_OK; +} + void PlayerServiceStub::SetPlayerFuncs() { FillPlayerFuncPart1(); @@ -212,6 +252,8 @@ void PlayerServiceStub::FillPlayerFuncPart3() [this](MessageParcel &data, MessageParcel &reply) { return SetPlaybackRate(data, reply); } }; playerFuncs_[ENABLE_REPORT_MEDIA_PROGRESS] = { "Player::EnableReportMediaProgress", [this](MessageParcel &data, MessageParcel &reply) { return EnableReportMediaProgress(data, reply); } }; + playerFuncs_[ENABLE_REPORT_AUDIO_INTERRUPT] = { "Player::EnableReportAudioInterrupt", + [this](MessageParcel &data, MessageParcel &reply) { return EnableReportAudioInterrupt(data, reply); } }; playerFuncs_[SET_PLAYER_PRODUCER] = { "Player::SetPlayerProducer", [this](MessageParcel &data, MessageParcel &reply) { return SetPlayerProducer(data, reply); } }; } @@ -265,6 +307,8 @@ int PlayerServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Messa if (memberFunc != nullptr) { auto task = std::make_shared>([&, this] { (void)IpcRecovery(false); + auto res = CheckandDoUnFreeze(); + CHECK_AND_RETURN_RET_LOG(res == MSERR_OK, res, "UnFreeze failed"); int32_t ret = -1; ret = memberFunc(data, reply); return ret; @@ -280,6 +324,17 @@ int PlayerServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Messa return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } +int32_t PlayerServiceStub::CheckandDoUnFreeze() +{ + CHECK_AND_RETURN_RET_NOLOG(isFrozen_, MSERR_OK); + MEDIA_LOGE("UnFreeze Later"); + auto ret = playerServer_->UnFreeze(); + CHECK_AND_RETURN_RET_NOLOG(ret == MSERR_OK, ret); + (void)EnableMonitor(appPid_); + isFrozen_ = false; + return ret; +} + int32_t PlayerServiceStub::SetListenerObject(const sptr &object) { MediaTrace trace("PlayerServiceStub::SetListenerObject"); @@ -1385,5 +1440,19 @@ int32_t PlayerServiceStub::EnableReportMediaProgress(MessageParcel &data, Messag reply.WriteInt32(EnableReportMediaProgress(enable)); return MSERR_OK; } + +int32_t PlayerServiceStub::EnableReportAudioInterrupt(bool enable) +{ + MediaTrace trace("PlayerServiceStub::EnableReportAudioInterrupt"); + CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr"); + return playerServer_->EnableReportAudioInterrupt(enable); +} + +int32_t PlayerServiceStub::EnableReportAudioInterrupt(MessageParcel &data, MessageParcel &reply) +{ + bool enable = data.ReadBool(); + reply.WriteInt32(EnableReportAudioInterrupt(enable)); + return MSERR_OK; +} } // namespace Media } // namespace OHOS diff --git a/services/services/player/ipc/player_service_stub.h b/services/services/player/ipc/player_service_stub.h index ea30d0755eb30ae28b6acbea69cc2803dd122131..0ac6b4fd69edda3b4baefb1c1fb2d81429adef66 100644 --- a/services/services/player/ipc/player_service_stub.h +++ b/services/services/player/ipc/player_service_stub.h @@ -74,6 +74,8 @@ public: int32_t SetMediaMuted(OHOS::Media::MediaType mediaType, bool isMuted) override; int32_t SetSuperResolution(bool enabled) override; int32_t SetVideoWindowSize(int32_t width, int32_t height) override; + int32_t Freeze(); + int32_t UnFreeze(); #ifdef SUPPORT_VIDEO int32_t SetVideoSurface(sptr surface) override; #endif @@ -105,6 +107,8 @@ public: int32_t SetReopenFd(int32_t fd) override; int32_t EnableCameraPostprocessing() override; int32_t EnableReportMediaProgress(bool enable) override; + int32_t EnableReportAudioInterrupt(bool enable) override; + bool isFrozen_ = false; protected: PlayerServiceStub(); virtual int32_t Init(); @@ -179,11 +183,13 @@ private: int32_t SetReopenFd(MessageParcel &data, MessageParcel &reply); int32_t EnableCameraPostprocessing(MessageParcel &data, MessageParcel &reply); int32_t EnableReportMediaProgress(MessageParcel &data, MessageParcel &reply); + int32_t EnableReportAudioInterrupt(MessageParcel &data, MessageParcel &reply); int32_t ReadMediaStreamListFromMessageParcel( MessageParcel &data, const std::shared_ptr &mediaSource); void ReadPlayStrategyFromMessageParcel(MessageParcel &data, AVPlayStrategy &strategy); + int32_t CheckandDoUnFreeze(); std::map> playerFuncs_; void FillPlayerFuncPart1(); void FillPlayerFuncPart2(); diff --git a/services/services/player/server/player_server.cpp b/services/services/player/server/player_server.cpp index b9ed568dc215c4677f7d3e5fea93c965f642b141..baf7e4555208a15df61d383546bed62db7b5371b 100644 --- a/services/services/player/server/player_server.cpp +++ b/services/services/player/server/player_server.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include "media_log.h" #include "media_errors.h" #include "engine_factory_repo.h" @@ -258,7 +259,8 @@ int32_t PlayerServer::InitPlayEngine(const std::string &url) std::shared_ptr obs = shared_from_this(); ret = playerEngine_->SetObs(obs); CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, MSERR_INVALID_OPERATION, "SetObs Failed!"); - ret = playerEngine_->SetMaxAmplitudeCbStatus(playerProducer_ == PlayerProducer::NAPI ? maxAmplitudeCbStatus_ : true); + ret = playerEngine_->SetMaxAmplitudeCbStatus( + playerProducer_ == PlayerProducer::NAPI ? maxAmplitudeCbStatus_ : true); ret = playerEngine_->SetSeiMessageCbStatus(seiMessageCbStatus_, payloadTypes_); CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, MSERR_INVALID_OPERATION, "SetMaxAmplitudeCbStatus Failed!"); @@ -266,6 +268,11 @@ int32_t PlayerServer::InitPlayEngine(const std::string &url) playerProducer_ == PlayerProducer::NAPI ? enableReportMediaProgress_ : true); TRUE_LOG(ret != MSERR_OK, MEDIA_LOGW, "PlayerEngine enable report media progress failed, ret %{public}d", ret); + if (playerCb_ != nullptr) { + playerCb_->SetInterruptListenerFlag( + playerProducer_ == PlayerProducer::NAPI ? enableReportAudioInterrupt_ : true); + } + lastOpStatus_ = PLAYER_INITIALIZED; ChangeState(initializedState_); @@ -628,6 +635,108 @@ int32_t PlayerServer::HandlePause(bool isSystemOperation) return MSERR_OK; } +int32_t PlayerServer::Freeze() +{ + std::lock_guard lock(mutex_); + if (lastOpStatus_ != PLAYER_STARTED) { + MEDIA_LOGE("Can not Freeze, currentState is %{public}s", GetStatusDescription(lastOpStatus_).c_str()); + return MSERR_OK; + } + if (playerCb_ != nullptr) { + playerCb_->SetFreezeFlag(true); + } + auto ret = OnFreeze(); + isFrozen_ = ret == MSERR_OK; + return ret; +} + +int32_t PlayerServer::OnFreeze() +{ + CHECK_AND_RETURN_RET_LOG(playerEngine_ != nullptr, MSERR_NO_MEMORY, "playerEngine_ is nullptr"); + MEDIA_LOGI("0x%{public}06" PRIXPTR " PlayerServer OnFreeze in", FAKE_POINTER(this)); + auto freezeTask = std::make_shared>([this]() { + MediaTrace Trace("PlayerServer::Freeze"); + MEDIA_LOGI("PlayerServer::OnFreeze start"); + auto currState = std::static_pointer_cast(GetCurrState()); + (void)currState->Freeze(); + MEDIA_LOGI("PlayerServer::OnFreeze end"); + }); + + auto cancelTask = std::make_shared>([this]() { + MEDIA_LOGI("cancel OnFreeze"); + taskMgr_.MarkTaskDone("interrupted OnFreeze done"); + }); + + int ret = taskMgr_.FreezeTask(freezeTask, cancelTask, "Freeze"); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "Freeze failed"); + + return MSERR_OK; +} + +int32_t PlayerServer::HandleFreeze() +{ + MEDIA_LOGI("PlayerServer HandleFreeze in"); + CHECK_AND_RETURN_RET_LOG(playerEngine_ != nullptr, MSERR_INVALID_OPERATION, "playerEngine_ is nullptr"); + ExitSeekContinous(true); + int32_t ret = playerEngine_->Freeze(); + UpdateFlvLivePauseTime(); + taskMgr_.MarkTaskDone("Freeze done"); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, MSERR_INVALID_OPERATION, "Engine Freeze Failed!"); + + return MSERR_OK; +} + +int32_t PlayerServer::UnFreeze() +{ + std::lock_guard lock(mutex_); + if (playerCb_ != nullptr) { + playerCb_->SetFreezeFlag(false); + } + if (!isFrozen_) { + MEDIA_LOGE("Can not UnFreeze, is not FrozenState"); + return MSERR_OK; + } + auto ret = OnUnFreeze(); + isFrozen_ = ret != MSERR_OK; + return ret; +} + +int32_t PlayerServer::OnUnFreeze() +{ + CHECK_AND_RETURN_RET_LOG(playerEngine_ != nullptr, MSERR_NO_MEMORY, "playerEngine_ is nullptr"); + MEDIA_LOGI("0x%{public}06" PRIXPTR " PlayerServer OnUnFreeze in", FAKE_POINTER(this)); + auto unFreezeTask = std::make_shared>([this]() { + MediaTrace Trace("PlayerServer::UnFreeze"); + MEDIA_LOGI("PlayerServer::OnUnFreeze start"); + auto currState = std::static_pointer_cast(GetCurrState()); + (void)currState->UnFreeze(); + MEDIA_LOGI("PlayerServer::OnUnFreeze end"); + }); + + auto cancelTask = std::make_shared>([this]() { + MEDIA_LOGI("cancel OnUnFreeze"); + taskMgr_.MarkTaskDone("cancel OnUnFreeze done"); + }); + + int ret = taskMgr_.UnFreezeTask(unFreezeTask, cancelTask, "UnFreeze"); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "UnFreeze failed"); + + return MSERR_OK; +} + +int32_t PlayerServer::HandleUnFreeze() +{ + MEDIA_LOGI("PlayerServer HandleUnFreeze in"); + CHECK_AND_RETURN_RET_LOG(playerEngine_ != nullptr, MSERR_INVALID_OPERATION, "playerEngine_ is nullptr"); + ExitSeekContinous(true); + TryFlvLiveRestartLink(); + int32_t ret = playerEngine_->UnFreeze(); + taskMgr_.MarkTaskDone("UnFreeze done"); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, MSERR_INVALID_OPERATION, "Engine UnFreeze Failed!"); + + return MSERR_OK; +} + int32_t PlayerServer::HandlePauseDemuxer() { MEDIA_LOGI("KPI-TRACE: PlayerServer HandlePauseDemuxer in"); @@ -1175,7 +1284,8 @@ int32_t PlayerServer::HandleSetPlaybackSpeed(PlaybackRateMode mode) int32_t PlayerServer::HandleSetPlaybackRate(float rate) { - if (config_.speedRate == rate) { + constexpr float EPSILON = 1e-6; + if (std::fabs(config_.speedRate - rate) < EPSILON) { MEDIA_LOGD("The speed rate is same, rate = %{public}f", rate); Format format; (void)format.PutFloatValue(PlayerKeys::PLAYER_PLAYBACK_RATE, rate); @@ -2231,7 +2341,7 @@ int32_t PlayerServer::SetSeiMessageCbStatus(bool status, const std::vector= MEMORY_USAGE_VERSION_ISOLATION, 0,"api version is low %{public}d", version); + CHECK_AND_RETURN_RET_LOG(version >= MEMORY_USAGE_VERSION_ISOLATION, 0, "api version is low %{public}d", version); return totalMemoryUage_.load(); } @@ -2260,5 +2370,15 @@ int32_t PlayerServer::EnableReportMediaProgress(bool enable) CHECK_AND_RETURN_RET_LOG(playerEngine_ != nullptr, MSERR_NO_MEMORY, "playerEngine_ is nullptr"); return playerEngine_->EnableReportMediaProgress(enableReportMediaProgress_); } + +int32_t PlayerServer::EnableReportAudioInterrupt(bool enable) +{ + std::lock_guard lock(mutex_); + enableReportAudioInterrupt_ = enable; + if (playerCb_ != nullptr) { + playerCb_->SetInterruptListenerFlag(enableReportAudioInterrupt_); + } + return MSERR_OK; +} } // namespace Media } // namespace OHOS diff --git a/services/services/player/server/player_server.h b/services/services/player/server/player_server.h index 2152bbcb0171c1737983c6e323d3b2b6e8f9b7c0..b6cd02bd1164e45b2548ee23ae13e6219a93d93d 100644 --- a/services/services/player/server/player_server.h +++ b/services/services/player/server/player_server.h @@ -77,6 +77,8 @@ public: PlayerServer(); virtual ~PlayerServer(); + int32_t Freeze() override; + int32_t UnFreeze() override; int32_t Play() override; int32_t Prepare() override; int32_t SetRenderFirstFrame(bool display) override; @@ -155,6 +157,7 @@ public: int32_t SetReopenFd(int32_t fd) override; int32_t EnableCameraPostprocessing() override; int32_t EnableReportMediaProgress(bool enable) override; + int32_t EnableReportAudioInterrupt(bool enable) override; protected: class BaseState; @@ -212,12 +215,18 @@ private: int32_t InitPlayEngine(const std::string &url); int32_t OnPrepare(bool sync); int32_t OnPlay(); + int32_t OnFreeze(); + int32_t OnUnFreeze(); int32_t OnPause(bool isSystemOperation); int32_t OnStop(bool sync); int32_t OnReset(); int32_t HandlePrepare(); int32_t HandlePlay(); int32_t HandlePause(bool isSystemOperation); + int32_t HandleFreeze(); + int32_t HandleLiteFreeze(); + int32_t HandleUnFreeze(); + int32_t HandleLiteUnFreeze(); int32_t HandlePauseDemuxer(); int32_t HandleResumeDemuxer(); int32_t HandleStop(); @@ -227,6 +236,7 @@ private: int32_t HandleSetPlaybackSpeed(PlaybackRateMode mode); int32_t HandleSetPlaybackRate(float rate); int32_t SetAudioEffectMode(const int32_t effectMode); + int32_t CheckandDoUnFreeze(); void HandleEos(); void PreparedHandleEos(); @@ -283,6 +293,7 @@ private: bool maxAmplitudeCbStatus_ = false; bool seiMessageCbStatus_ = false; bool enableReportMediaProgress_ = false; + bool enableReportAudioInterrupt_ = false; std::vector payloadTypes_ {}; bool isStreamUsagePauseRequired_ = true; std::mutex surfaceMutex_; @@ -292,6 +303,7 @@ private: bool isCalledBySystemApp_ = false; std::atomic totalMemoryUage_ {0}; PlayerProducer playerProducer_ = PlayerProducer::INNER; + std::atomic isFrozen_ = false; }; } // namespace Media } // namespace OHOS diff --git a/services/services/player/server/player_server_state.cpp b/services/services/player/server/player_server_state.cpp index da33049aec5d14225432580526001b2dc672a731..12910d0e1d46ab3cfafe529a726eece6d14d490b 100644 --- a/services/services/player/server/player_server_state.cpp +++ b/services/services/player/server/player_server_state.cpp @@ -53,6 +53,18 @@ int32_t PlayerServer::BaseState::Pause(bool isSystemOperation) return MSERR_INVALID_STATE; } +int32_t PlayerServer::BaseState::Freeze() +{ + ReportInvalidOperation(); + return MSERR_INVALID_STATE; +} + +int32_t PlayerServer::BaseState::UnFreeze() +{ + ReportInvalidOperation(); + return MSERR_INVALID_STATE; +} + int32_t PlayerServer::BaseState::PauseDemuxer() { ReportInvalidOperation(); @@ -345,6 +357,16 @@ int32_t PlayerServer::PlayingState::Pause(bool isSystemOperation) return server_.HandlePause(isSystemOperation); } +int32_t PlayerServer::PlayingState::Freeze() +{ + return server_.HandleFreeze(); +} + +int32_t PlayerServer::PlayingState::UnFreeze() +{ + return server_.HandleUnFreeze(); +} + int32_t PlayerServer::PlayingState::PauseDemuxer() { return server_.HandlePauseDemuxer(); @@ -466,6 +488,11 @@ int32_t PlayerServer::PausedState::Stop() return server_.HandleStop(); } +int32_t PlayerServer::PausedState::UnFreeze() +{ + return server_.HandleUnFreeze(); +} + int32_t PlayerServer::PausedState::SetPlaybackSpeed(PlaybackRateMode mode) { return server_.HandleSetPlaybackSpeed(mode); @@ -567,6 +594,11 @@ int32_t PlayerServer::PlaybackCompletedState::Stop() return server_.HandleStop(); } +int32_t PlayerServer::PlaybackCompletedState::UnFreeze() +{ + return server_.HandleUnFreeze(); +} + void PlayerServer::PlaybackCompletedState::HandleStateChange(int32_t newState) { if (newState == PLAYER_STARTED) { diff --git a/services/services/player/server/player_server_state.h b/services/services/player/server/player_server_state.h index f766cf6c9463bc5fc7341059cba2fa6e42d4593a..e18362c5be5c6934fa5046d8f1ff14bf121a3bb3 100644 --- a/services/services/player/server/player_server_state.h +++ b/services/services/player/server/player_server_state.h @@ -28,6 +28,8 @@ public: virtual int32_t Prepare(); virtual int32_t Play(); virtual int32_t Pause(bool isSystemOperation); + virtual int32_t Freeze(); + virtual int32_t UnFreeze(); virtual int32_t Seek(int32_t mSeconds, PlayerSeekMode mode); virtual int32_t SetPlaybackSpeed(PlaybackRateMode mode); virtual int32_t SetPlaybackRate(float rate); @@ -122,6 +124,8 @@ public: int32_t Play() override; int32_t Pause(bool isSystemOperation) override; + int32_t Freeze() override; + int32_t UnFreeze() override; int32_t Seek(int32_t mSeconds, PlayerSeekMode mode) override; int32_t Stop() override; int32_t SetPlaybackSpeed(PlaybackRateMode mode) override; @@ -147,6 +151,7 @@ public: int32_t Play() override; int32_t Pause(bool isSystemOperation) override; + int32_t UnFreeze() override; int32_t Seek(int32_t mSeconds, PlayerSeekMode mode) override; int32_t Stop() override; int32_t SetPlaybackSpeed(PlaybackRateMode mode) override; @@ -177,6 +182,7 @@ public: int32_t Play() override; int32_t Seek(int32_t mSeconds, PlayerSeekMode mode) override; + int32_t UnFreeze() override; int32_t Stop() override; int32_t SetPlaybackSpeed(PlaybackRateMode mode) override; int32_t SetPlaybackRate(float rate) override; diff --git a/services/services/player/server/player_server_task_mgr.cpp b/services/services/player/server/player_server_task_mgr.cpp index 38ee90cb05e27f0b820d6eb947ee76f17eb29d20..64e6011e95fe7b13161b50fab8bc899f8d5de377 100644 --- a/services/services/player/server/player_server_task_mgr.cpp +++ b/services/services/player/server/player_server_task_mgr.cpp @@ -175,6 +175,56 @@ int32_t PlayerServerTaskMgr::SeekTask(const std::shared_ptr &task, return MSERR_OK; } +int32_t PlayerServerTaskMgr::FreezeTask(const std::shared_ptr &task, + const std::shared_ptr &cancelTask, const std::string &taskName) +{ + std::unique_lock lock(mutex_); + CHECK_AND_RETURN_RET_LOG(isInited_, MSERR_INVALID_OPERATION, "not init"); + + if (currTwoPhaseTask_ == nullptr) { + return EnqueueTask(task, PlayerServerTaskType::FREEZE_TASK, taskName); + } + MEDIA_LOGI("current task[%{public}s] is in processing, new task[%{public}s] wait", + currTwoPhaseTaskName_.c_str(), taskName.c_str()); + for (auto &item : pendingTwoPhaseTasks_) { + if (item.type == PlayerServerTaskType::FREEZE_TASK || + item.type == PlayerServerTaskType::UNFREEZE_TASK) { + item.type = PlayerServerTaskType::CANCEL_TASK; + MEDIA_LOGI("replace old freeze and unfreeze task"); + } + } + + pendingTwoPhaseTasks_.push_back({ + PlayerServerTaskType::FREEZE_TASK, task, cancelTask, taskName + }); + return MSERR_OK; +} + +int32_t PlayerServerTaskMgr::UnFreezeTask(const std::shared_ptr &task, + const std::shared_ptr &cancelTask, const std::string &taskName) +{ + std::unique_lock lock(mutex_); + CHECK_AND_RETURN_RET_LOG(isInited_, MSERR_INVALID_OPERATION, "not init"); + + if (currTwoPhaseTask_ == nullptr) { + return EnqueueTask(task, PlayerServerTaskType::UNFREEZE_TASK, taskName); + } + MEDIA_LOGI("current task[%{public}s] is in processing, new task[%{public}s] wait", + currTwoPhaseTaskName_.c_str(), taskName.c_str()); + for (auto &item : pendingTwoPhaseTasks_) { + if (item.type == PlayerServerTaskType::FREEZE_TASK || + item.type == PlayerServerTaskType::UNFREEZE_TASK) { + item.type = PlayerServerTaskType::CANCEL_TASK; + MEDIA_LOGI("replace old freeze and unfreeze task"); + } + } + + pendingTwoPhaseTasks_.push_back({ + PlayerServerTaskType::UNFREEZE_TASK, task, cancelTask, taskName + }); + return MSERR_OK; +} + int32_t PlayerServerTaskMgr::SeekContinousTask(const std::shared_ptr &task, const std::string &taskName) { std::unique_lock lock(mutex_); diff --git a/services/services/player/server/player_server_task_mgr.h b/services/services/player/server/player_server_task_mgr.h index 25206cf043c0417cd544830e0d51016c89f4ec94..43a7b8f8f1d338e31025f68ea58ac76557cb326e 100644 --- a/services/services/player/server/player_server_task_mgr.h +++ b/services/services/player/server/player_server_task_mgr.h @@ -38,6 +38,8 @@ enum class PlayerServerTaskType : uint8_t { CANCEL_TASK, SEEK_CONTINOUS, LIGHT_TASK, + FREEZE_TASK, + UNFREEZE_TASK, SET_VIDEO_SURFACE, BUTT, }; @@ -56,6 +58,10 @@ public: const std::string &taskName, int32_t speedMode); int32_t SeekContinousTask(const std::shared_ptr &task, const std::string &taskName); int32_t SetVideoSurfaeTask(const std::shared_ptr &task, const std::string &taskName); + int32_t FreezeTask(const std::shared_ptr &task, + const std::shared_ptr &cancelTask, const std::string &taskName); + int32_t UnFreezeTask(const std::shared_ptr &task, + const std::shared_ptr &cancelTask, const std::string &taskName); // only take effect when it is called at the task thread. int32_t MarkTaskDone(const std::string &taskName); void ClearAllTask(); diff --git a/services/services/sa_media/client/media_client.cpp b/services/services/sa_media/client/media_client.cpp index 7bed7829f1dd065cab97d0871c67fb6dd4378577..0aa9ca2841268ce3749c76adfdde998fe521e55d 100644 --- a/services/services/sa_media/client/media_client.cpp +++ b/services/services/sa_media/client/media_client.cpp @@ -74,6 +74,23 @@ MediaClient::~MediaClient() MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this)); } +int32_t MediaClient::ProxyForFreeze(const std::set &pidList, bool isProxy) +{ + std::lock_guard lock(mutex_); + CHECK_AND_RETURN_RET_LOG(IsAlived(), MSERR_SERVICE_DIED, "media service does not exist."); + MEDIA_LOGD("received Freeze Notification, pidSize = %{public}d, isProxy = %{public}d", + static_cast(pidList.size()), isProxy); + return mediaProxy_->FreezeStubForPids(pidList, isProxy); +} + +int32_t MediaClient::ResetAllProxy() +{ + std::lock_guard lock(mutex_); + CHECK_AND_RETURN_RET_LOG(IsAlived(), MSERR_SERVICE_DIED, "media service does not exist."); + MEDIA_LOGI("received ResetAllProxy"); + return mediaProxy_->ResetAllProxy(); +} + bool MediaClient::IsAlived() { if (mediaProxy_ == nullptr) { @@ -346,6 +363,13 @@ int32_t MediaClient::DestroyScreenCaptureControllerClient(std::shared_ptr MediaClient::GetPlayerPids() +{ + std::vector res; + CHECK_AND_RETURN_RET_LOG(IsAlived(), res, "MediaServer Is Not Alived"); + return mediaProxy_->GetPlayerPids(); +} + sptr MediaClient::GetMonitorProxy() { std::unique_lock lock(mutex_); @@ -481,7 +505,10 @@ void MediaClient::DoMediaServerDied() std::lock_guard lock(mutex_); MEDIA_LOGI("DoMediaServerDied"); if (mediaProxy_ != nullptr) { - (void)mediaProxy_->AsObject()->RemoveDeathRecipient(deathRecipient_); + sptr object = mediaProxy_->AsObject(); + if (object != nullptr) { + object->RemoveDeathRecipient(deathRecipient_); + } mediaProxy_ = nullptr; } listenerStub_ = nullptr; diff --git a/services/services/sa_media/client/media_client.h b/services/services/sa_media/client/media_client.h index a30ea5fc5b64fdc1bbe3a1fce3481a380dfc6085..47ab7e395f4710d80d7ce7644aeece69aede585f 100644 --- a/services/services/sa_media/client/media_client.h +++ b/services/services/sa_media/client/media_client.h @@ -47,6 +47,8 @@ public: MediaClient() noexcept; ~MediaClient(); + int32_t ProxyForFreeze(const std::set &pidList, bool isProxy) override; + int32_t ResetAllProxy() override; sptr GetMonitorProxy() override; void ReleaseClientListener() override; bool CanKillMediaService() override; @@ -77,6 +79,7 @@ public: std::shared_ptr CreateScreenCaptureControllerClient() override; int32_t DestroyScreenCaptureControllerClient(std::shared_ptr controller) override; #endif + std::vector GetPlayerPids() override; private: sptr GetMediaProxy(); diff --git a/services/services/sa_media/ipc/i_standard_media_service.h b/services/services/sa_media/ipc/i_standard_media_service.h index 82acb20079801bb840b2ed6c76d11b30abb3bbb7..3f43de4027086340e6e7f722c695c8ec58277d2d 100644 --- a/services/services/sa_media/ipc/i_standard_media_service.h +++ b/services/services/sa_media/ipc/i_standard_media_service.h @@ -20,6 +20,7 @@ #include "iremote_broker.h" #include "iremote_proxy.h" #include "iremote_stub.h" +#include namespace OHOS { namespace Media { @@ -69,6 +70,15 @@ public: */ virtual bool CanKillMediaService() = 0; + /** + * Get pid vector of players. + */ + virtual std::vector GetPlayerPids() = 0; + + virtual int32_t FreezeStubForPids(const std::set &pidList, bool isProxy) = 0; + + virtual int32_t ResetAllProxy() = 0; + /** * IPC code ID */ @@ -77,6 +87,9 @@ public: GET_SUBSYSTEM_ASYNC = 1, RELEASE_CLIENT_LISTENER = 2, CAN_KILL_MEDIA_SERVICE = 3, + GET_PLAYER_PIDS = 4, + FREEZE = 5, + RESET_ALL_PROXY = 6, }; DECLARE_INTERFACE_DESCRIPTOR(u"IStandardMediaService"); diff --git a/services/services/sa_media/ipc/media_service_proxy.cpp b/services/services/sa_media/ipc/media_service_proxy.cpp index ebfcc9861c6a875ffd82ac051c9109317cb76b16..c91e6ab56a89eb4ab5516fbdd16ca40aa3be3889 100644 --- a/services/services/sa_media/ipc/media_service_proxy.cpp +++ b/services/services/sa_media/ipc/media_service_proxy.cpp @@ -52,6 +52,30 @@ void MediaServiceProxy::ReleaseClientListener() } } +std::vector MediaServiceProxy::GetPlayerPids() +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + std::vector res; + + bool token = data.WriteInterfaceToken(MediaServiceProxy::GetDescriptor()); + CHECK_AND_RETURN_RET_LOG(token, res, "Failed to write descriptor!"); + int32_t error = -1; + error = Remote()->SendRequest(MediaServiceMsg::GET_PLAYER_PIDS, data, reply, option); + if (error != MSERR_OK) { + MEDIA_LOGE("Send request failed, error: %{public}d", error); + return res; + } + int64_t vecSize = reply.ReadInt64(); + CHECK_AND_RETURN_RET_LOG(vecSize >= 0, res, "Fail to read vecSize"); + for (int64_t i = 0; i < vecSize; i++) { + res.emplace_back(static_cast(reply.ReadInt64())); + } + return res; +} + sptr MediaServiceProxy::GetSubSystemAbility(IStandardMediaService::MediaSystemAbility subSystemId, const sptr &listener) { @@ -117,5 +141,47 @@ bool MediaServiceProxy::CanKillMediaService() return reply.ReadBool(); } + +int32_t MediaServiceProxy::FreezeStubForPids(const std::set &pidList, bool isProxy) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + bool token = data.WriteInterfaceToken(MediaServiceProxy::GetDescriptor()); + CHECK_AND_RETURN_RET_LOG(token, MSERR_INVALID_OPERATION, "WriteInterfaceToken failed"); + + CHECK_AND_RETURN_RET_LOG(data.WriteBool(isProxy), MSERR_INVALID_OPERATION, "Failed to write bool"); + + int32_t size = static_cast(pidList.size()); + CHECK_AND_RETURN_RET_LOG(size > 0, MSERR_INVALID_VAL, "size is invalid"); + CHECK_AND_RETURN_RET_LOG(data.WriteInt32(size), MSERR_INVALID_OPERATION, "Failed to write int32"); + + for (auto pid : pidList) { + CHECK_AND_RETURN_RET_LOG(data.WriteInt32(pid), MSERR_INVALID_OPERATION, "Failed to write int32"); + } + + int32_t error = -1; + error = Remote()->SendRequest(MediaServiceMsg::FREEZE, data, reply, option); + CHECK_AND_RETURN_RET_LOG(error == MSERR_OK, MSERR_INVALID_OPERATION, + "SendRequest failed, error: %{public}d", error); + return reply.ReadInt32(); +} + +int32_t MediaServiceProxy::ResetAllProxy() +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + bool token = data.WriteInterfaceToken(MediaServiceProxy::GetDescriptor()); + CHECK_AND_RETURN_RET_LOG(token, MSERR_INVALID_OPERATION, "WriteInterfaceToken failed"); + + int32_t error = -1; + error = Remote()->SendRequest(MediaServiceMsg::RESET_ALL_PROXY, data, reply, option); + CHECK_AND_RETURN_RET_LOG(error == MSERR_OK, MSERR_INVALID_OPERATION, + "SendRequest failed, error: %{public}d", error); + return reply.ReadInt32(); +} } // namespace Media } // namespace OHOS diff --git a/services/services/sa_media/ipc/media_service_proxy.h b/services/services/sa_media/ipc/media_service_proxy.h index 33e741c52b71df41888fc8d5aaca71dd6618f3c4..44de1d94a28adbdcfca4b13eb910dc6b22647183 100644 --- a/services/services/sa_media/ipc/media_service_proxy.h +++ b/services/services/sa_media/ipc/media_service_proxy.h @@ -35,6 +35,11 @@ public: bool CanKillMediaService() override; + std::vector GetPlayerPids() override; + int32_t FreezeStubForPids(const std::set &pidList, bool isProxy) override; + + int32_t ResetAllProxy() override; + private: bool IsGetSubSystemAbilityASync() const; static inline BrokerDelegator delegator_; diff --git a/services/services/sa_media/ipc/media_service_stub.cpp b/services/services/sa_media/ipc/media_service_stub.cpp index eb4959dced1703109cd03a7b554ab89dcf7af874..069873e9b23e6ed2ca85002012bca8363b02ba2b 100644 --- a/services/services/sa_media/ipc/media_service_stub.cpp +++ b/services/services/sa_media/ipc/media_service_stub.cpp @@ -24,6 +24,7 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_PLAYER, "MediaServiceStub"}; const std::string TASK_NAME = "OHOS::Media::MediaServiceStub::GetSystemAbility"; const int32_t TIME_OUT_SECOND = 30; // time out is 30 senconds +const int32_t RSS_UID = 1096; } namespace OHOS { @@ -50,6 +51,44 @@ void MediaServiceStub::Init() [this] (MessageParcel &data, MessageParcel &reply) { return ReleaseClientListenerStub(data, reply); }; mediaFuncs_[CAN_KILL_MEDIA_SERVICE] = [this] (MessageParcel &data, MessageParcel &reply) { return HandleKillMediaService(data, reply); }; + mediaFuncs_[GET_PLAYER_PIDS] = + [this] (MessageParcel &data, MessageParcel &reply) { return GetPlayerPidsStub(data, reply); }; + mediaFuncs_[FREEZE] = + [this](MessageParcel &data, MessageParcel &reply) { return HandleFreezeStubForPids(data, reply); }; + mediaFuncs_[RESET_ALL_PROXY] = + [this](MessageParcel &data, MessageParcel &reply) { return HandleResetAllProxy(data, reply); }; +} + +int32_t MediaServiceStub::HandleFreezeStubForPids(MessageParcel &data, MessageParcel &reply) +{ + int32_t callingUid = IPCSkeleton::GetCallingUid(); + CHECK_AND_RETURN_RET_LOG(callingUid == RSS_UID, MSERR_INVALID_OPERATION, "No Permission"); + + bool isProxy = false; + CHECK_AND_RETURN_RET_LOG(data.ReadBool(isProxy), MSERR_INVALID_OPERATION, "Failed to Read Bool"); + + std::set pidList; + int32_t size = 0; + CHECK_AND_RETURN_RET_LOG(data.ReadInt32(size), MSERR_INVALID_OPERATION, "Failed to Read Int32"); + CHECK_AND_RETURN_RET_LOG(size > 0, MSERR_INVALID_VAL, "size is invalid"); + + for (int32_t i = 0; i < size; i++) { + int32_t pid = 0; + CHECK_AND_RETURN_RET_LOG(data.ReadInt32(pid), MSERR_INVALID_OPERATION, "Failed to Read Int32"); + pidList.insert(pid); + } + + reply.WriteInt32(FreezeStubForPids(pidList, isProxy)); + return MSERR_OK; +} + +int32_t MediaServiceStub::HandleResetAllProxy(MessageParcel &data, MessageParcel &reply) +{ + int32_t callingUid = IPCSkeleton::GetCallingUid(); + CHECK_AND_RETURN_RET_LOG(callingUid == RSS_UID, MSERR_INVALID_OPERATION, "No Permission"); + + reply.WriteInt32(ResetAllProxy()); + return MSERR_OK; } int32_t MediaServiceStub::DestroyStubForPid(pid_t pid) @@ -159,12 +198,29 @@ int32_t MediaServiceStub::ReleaseClientListenerStub(MessageParcel &data, Message return MSERR_OK; } +int32_t MediaServiceStub::GetPlayerPidsStub(MessageParcel &data, MessageParcel &reply) +{ + (void)data; + std::vector res = GetPlayerPids(); + int64_t vectorSize = static_cast(res.size()); + reply.WriteInt64(vectorSize); + for (auto &pid : res) { + reply.WriteInt64(static_cast(pid)); + } + return MSERR_OK; +} + void MediaServiceStub::ReleaseClientListener() { pid_t pid = IPCSkeleton::GetCallingPid(); (void)DestroyStubForPid(pid); } +std::vector MediaServiceStub::GetPlayerPids() +{ + return MediaServerManager::GetInstance().GetPlayerPids(); +} + int32_t MediaServiceStub::GetSystemAbility(MessageParcel &data, MessageParcel &reply) { int32_t mediaSystemAbility = data.ReadInt32(); diff --git a/services/services/sa_media/ipc/media_service_stub.h b/services/services/sa_media/ipc/media_service_stub.h index fd5fd69af5bbe82d720e5071910bf96e050fc816..7c4f836a229f317b8796b0ad8d65baf0f992bca0 100644 --- a/services/services/sa_media/ipc/media_service_stub.h +++ b/services/services/sa_media/ipc/media_service_stub.h @@ -41,7 +41,11 @@ private: int32_t GetSystemAbilityAync(MessageParcel &data, MessageParcel &reply); int32_t ReleaseClientListenerStub(MessageParcel &data, MessageParcel &reply); int32_t HandleKillMediaService(MessageParcel &data, MessageParcel &reply); + int32_t GetPlayerPidsStub(MessageParcel &data, MessageParcel &reply); void ReleaseClientListener() override; + std::vector GetPlayerPids() override; + int32_t HandleFreezeStubForPids(MessageParcel &data, MessageParcel &reply); + int32_t HandleResetAllProxy(MessageParcel &data, MessageParcel &reply); void ClientDied(pid_t pid); int32_t DestroyStubForPid(pid_t pid); std::map mediaFuncs_; diff --git a/services/services/sa_media/server/media_server.cpp b/services/services/sa_media/server/media_server.cpp index bcc6d463330d1905281f06f5351fd1afcce86776..99f32b9eb61d92164d3b77afc95b08ed83c157f0 100644 --- a/services/services/sa_media/server/media_server.cpp +++ b/services/services/sa_media/server/media_server.cpp @@ -75,7 +75,7 @@ void MediaServer::OnStart() AddSystemAbilityListener(MEMORY_MANAGER_SA_ID); AddSystemAbilityListener(AUDIO_POLICY_SERVICE_ID); #ifdef SUPPORT_CALL - MEDIA_LOGD("InCallObserver OnStart"); + MEDIA_LOGD("InCallObserver init OnStart"); InCallObserver::GetInstance(); #endif } @@ -87,6 +87,24 @@ void MediaServer::OnStop() SYSTEM_PROCESS_TYPE, SYSTEM_STATUS_STOP, OHOS::PLAYER_DISTRIBUTED_SERVICE_ID); } +int32_t MediaServer::FreezeStubForPids(const std::set &pidList, bool isProxy) +{ + int32_t size = static_cast(pidList.size()); + MEDIA_LOGI("received Freeze Notification, pidSize = %{public}d, isProxy = %{public}d", + size, isProxy); + + for (auto pid : pidList) { + MEDIA_LOGI("received Freeze Pid, pid = %{public}d, isProxy = %{public}d", + pid, isProxy); + } + return MediaServerManager::GetInstance().FreezeStubForPids(pidList, isProxy); +} + +int32_t MediaServer::ResetAllProxy() +{ + return MediaServerManager::GetInstance().ResetAllProxy(); +} + #ifdef SUPPORT_START_STOP_ON_DEMAND int32_t MediaServer::OnIdle(const SystemAbilityOnDemandReason &idleReason) { diff --git a/services/services/sa_media/server/media_server.h b/services/services/sa_media/server/media_server.h index 4b18b8227ac9e0b5243aa9981146b81972bb1538..5a04a2e7d8e776ad0a8a5fcbe56f5d80b5f733aa 100644 --- a/services/services/sa_media/server/media_server.h +++ b/services/services/sa_media/server/media_server.h @@ -34,6 +34,10 @@ public: explicit MediaServer(int32_t systemAbilityId, bool runOnCreate = true); ~MediaServer(); + int32_t FreezeStubForPids(const std::set &pidList, bool isProxy) override; + + int32_t ResetAllProxy() override; + // IStandardMediaService override sptr GetSubSystemAbility(IStandardMediaService::MediaSystemAbility subSystemId, const sptr &listener) override; diff --git a/services/services/sa_media/server_manager/media_server_manager.cpp b/services/services/sa_media/server_manager/media_server_manager.cpp index 77ef1cd3f49b042093026ba457f6158099a32f63..f8c140124b5e6301055b698f45a262fad84e4e05 100644 --- a/services/services/sa_media/server_manager/media_server_manager.cpp +++ b/services/services/sa_media/server_manager/media_server_manager.cpp @@ -43,6 +43,7 @@ #include "service_dump_manager.h" #include "player_xcollie.h" #include "client/memory_collector_client.h" +#include namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_PLAYER, "MediaServerManager"}; @@ -186,6 +187,50 @@ MediaServerManager::~MediaServerManager() MEDIA_LOGI("0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this)); } +int32_t MediaServerManager::FreezeStubForPids(const std::set &pidList, bool isProxy) +{ + std::lock_guard lock(mutex_); + for (const auto &pid : pidList) { + auto pidIt = pidToPlayerStubMap_.find(pid); + if (pidIt == pidToPlayerStubMap_.end()) { + MEDIA_LOGD("PID(%{public}d) has no player stubs, skip freeze", pid); + continue; + } + + const auto &stubSet = pidIt->second; + MEDIA_LOGI("Freezing %{public}zu player stubs for PID = %{public}d, isProxy: %{public}d", + stubSet.size(), pid, isProxy); + + for (const auto &stubObj : stubSet) { + auto playerStub = iface_cast(stubObj); + CHECK_AND_CONTINUE_LOG(playerStub != nullptr, + "failed to cast PlayerServiceStub, pid = %{public}d", pid); + + if (isProxy) { + playerStub->Freeze(); + } else { + playerStub->UnFreeze(); + } + } + } + return MSERR_OK; +} + +int32_t MediaServerManager::ResetAllProxy() +{ + std::lock_guard lock(mutex_); + MEDIA_LOGI("received ResetAllProxy"); + for (const auto &pidEntry : pidToPlayerStubMap_) { + for (const auto &remoteObj : pidEntry.second) { + auto playerStub = iface_cast(remoteObj); + CHECK_AND_CONTINUE_LOG(playerStub != nullptr, + "failed to cast PlayerServiceStub, pid = %{public}d", pidEntry.first); + playerStub->UnFreeze(); + } + } + return MSERR_OK; +} + sptr MediaServerManager::CreateStubObject(StubType type) { std::lock_guard lock(mutex_); @@ -256,6 +301,9 @@ sptr MediaServerManager::CreatePlayerStubObject() StartMemoryReportTask(); + auto &instanceSet = pidToPlayerStubMap_[pid]; + instanceSet.insert(object); + Dumper dumper; dumper.entry_ = [player = playerStub](int32_t fd) -> int32_t { return player->DumpInfo(fd); @@ -501,13 +549,13 @@ void MediaServerManager::DestroyAVPlayerStub(StubType type, sptr switch (type) { case PLAYER: { for (auto it = playerStubMap_.begin(); it != playerStubMap_.end(); it++) { - if (it->first == object) { - MEDIA_LOGD("destroy player stub services(%{public}zu) pid(%{public}d).", - playerStubMap_.size(), pid); - (void)playerStubMap_.erase(it); - MediaTrace::CounterTrace("The number of player", playerStubMap_.size()); - return; - } + CHECK_AND_CONTINUE(it->first == object); + RemovePlayerStubFromMap(object, it->second); + MEDIA_LOGD("destroy player stub services(%{public}zu) pid(%{public}d).", + playerStubMap_.size(), pid); + (void)playerStubMap_.erase(it); + MediaTrace::CounterTrace("The number of player", playerStubMap_.size()); + return; } MEDIA_LOGE("find player object failed, pid(%{public}d).", pid); break; @@ -529,6 +577,19 @@ void MediaServerManager::DestroyAVPlayerStub(StubType type, sptr } } +void MediaServerManager::RemovePlayerStubFromMap(sptr object, pid_t pid) +{ + auto pidIt = pidToPlayerStubMap_.find(pid); + if (pidIt == pidToPlayerStubMap_.end()) { + return; + } + + pidIt->second.erase(object); + if (pidIt->second.empty()) { + pidToPlayerStubMap_.erase(pidIt); + } +} + void MediaServerManager::DestroyAVRecorderStub(StubType type, sptr object, pid_t pid) { switch (type) { @@ -722,6 +783,10 @@ void MediaServerManager::DestroyAVCodecStubForPid(pid_t pid) void MediaServerManager::DestroyAVPlayerStubForPid(pid_t pid) { MEDIA_LOGD("player stub services(%{public}zu) pid(%{public}d).", playerStubMap_.size(), pid); + auto pidIt = pidToPlayerStubMap_.find(pid); + if (pidIt != pidToPlayerStubMap_.end()) { + pidToPlayerStubMap_.erase(pidIt); + } for (auto itPlayer = playerStubMap_.begin(); itPlayer != playerStubMap_.end();) { if (itPlayer->second == pid) { executor_.Commit(itPlayer->first); @@ -785,6 +850,21 @@ void MediaServerManager::DestroyStubObjectForPid(pid_t pid) #endif } +std::vector MediaServerManager::GetPlayerPids() +{ + std::lock_guard lock(mutex_); + std::vector res; + CHECK_AND_RETURN_RET_NOLOG(!playerStubMap_.empty(), res); + std::unordered_set tmpRes; + for (const auto& [object, pid] : playerStubMap_) { + (void)tmpRes.insert(pid); + } + for (auto &uniqPid : tmpRes) { + res.emplace_back(uniqPid); + } + return res; +} + void MediaServerManager::DestroyDumper(StubType type, sptr object) { for (auto it = dumperTbl_[type].begin(); it != dumperTbl_[type].end(); it++) { diff --git a/services/services/sa_media/server_manager/media_server_manager.h b/services/services/sa_media/server_manager/media_server_manager.h index 5bb1c31d6b6aefe9b9bf1893164be35aaffcf64b..92a3b9e03701c7fbfb2838c9f9337fb4642f3703 100644 --- a/services/services/sa_media/server_manager/media_server_manager.h +++ b/services/services/sa_media/server_manager/media_server_manager.h @@ -24,6 +24,7 @@ #include "ipc_skeleton.h" #include "nocopyable.h" #include "osal/task/task.h" +#include namespace OHOS { namespace Media { @@ -57,12 +58,15 @@ public: }; sptr CreateStubObject(StubType type); void DestroyStubObject(StubType type, sptr object); + void RemovePlayerStubFromMap(sptr object, pid_t pid); void DestroyStubObjectForPid(pid_t pid); int32_t Dump(int32_t fd, const std::vector &args); void DestroyDumper(StubType type, sptr object); void DestroyDumperForPid(pid_t pid); void NotifyMemMgrLoaded(); void DestoryMemoryReportTask(); + int32_t FreezeStubForPids(const std::set &pidList, bool isProxy); + int32_t ResetAllProxy(); #ifdef SUPPORT_START_STOP_ON_DEMAND int32_t GetInstanceCount(); int32_t GetInstanceCountLocked(); @@ -72,6 +76,7 @@ public: void UpdateAllInstancesReleasedTime(); #endif bool CanKillMediaService(); + std::vector GetPlayerPids(); private: MediaServerManager(); #ifdef SUPPORT_PLAYER @@ -126,6 +131,7 @@ private: std::map, pid_t> recorderStubMap_; std::map, pid_t> transCoderStubMap_; std::map, pid_t> playerStubMap_; + std::map>> pidToPlayerStubMap_; std::map, pid_t> avMetadataHelperStubMap_; std::map, pid_t> avCodecListStubMap_; std::map, pid_t> avCodecStubMap_; diff --git a/services/services/screen_capture/ipc/screen_capture_service_proxy.cpp b/services/services/screen_capture/ipc/screen_capture_service_proxy.cpp index a844c81edb74e27eb6c45155c8e7ea40d510dc71..33c7e0e8c5f533342673fdd0ec98cbbbe6400572 100644 --- a/services/services/screen_capture/ipc/screen_capture_service_proxy.cpp +++ b/services/services/screen_capture/ipc/screen_capture_service_proxy.cpp @@ -633,7 +633,8 @@ int32_t ScreenCaptureServiceProxy::SetScreenCaptureStrategy(ScreenCaptureStrateg bool token = data.WriteInterfaceToken(ScreenCaptureServiceProxy::GetDescriptor()); CHECK_AND_RETURN_RET_LOG(token, MSERR_INVALID_OPERATION, "Failed to write descriptor!"); - token = data.WriteBool(strategy.enableDeviceLevelCapture) && data.WriteBool(strategy.keepCaptureDuringCall); + token = data.WriteBool(strategy.enableDeviceLevelCapture) && data.WriteBool(strategy.keepCaptureDuringCall) + && data.WriteInt32(strategy.strategyForPrivacyMaskMode); CHECK_AND_RETURN_RET_LOG(token, MSERR_INVALID_OPERATION, "Failed to write strategy!"); int error = Remote()->SendRequest(SET_STRATEGY, data, reply, option); diff --git a/services/services/screen_capture/ipc/screen_capture_service_stub.cpp b/services/services/screen_capture/ipc/screen_capture_service_stub.cpp index 16522545f204fdc375dae80b74c6207c7c9dc730..192075a96433b69c88620655644f7efd57deadc5 100644 --- a/services/services/screen_capture/ipc/screen_capture_service_stub.cpp +++ b/services/services/screen_capture/ipc/screen_capture_service_stub.cpp @@ -716,6 +716,7 @@ int32_t ScreenCaptureServiceStub::SetScreenCaptureStrategy(MessageParcel &data, ScreenCaptureStrategy strategy; strategy.enableDeviceLevelCapture = data.ReadBool(); strategy.keepCaptureDuringCall = data.ReadBool(); + strategy.strategyForPrivacyMaskMode = data.ReadInt32(); int32_t ret = SetScreenCaptureStrategy(strategy); reply.WriteInt32(ret); return MSERR_OK; diff --git a/services/services/screen_capture/server/audio_capturer_wrapper.cpp b/services/services/screen_capture/server/audio_capturer_wrapper.cpp index c8a7763392194d3860612ae220e43bd6332ff2b8..53bc21a1a28d36b13a5fc06abb2bfc97cac7b1d0 100644 --- a/services/services/screen_capture/server/audio_capturer_wrapper.cpp +++ b/services/services/screen_capture/server/audio_capturer_wrapper.cpp @@ -97,60 +97,12 @@ int32_t AudioCapturerWrapper::Start(const OHOS::AudioStandard::AppInfo &appInfo) return MSERR_OK; } -int32_t AudioCapturerWrapper::Pause() -{ - std::lock_guard lock(mutex_); - MEDIA_LOGI("0x%{public}06" PRIXPTR " Pause S, threadName:%{public}s", FAKE_POINTER(this), threadName_.c_str()); - if (isRunning_.load()) { - isRunning_.store(false); - if (readAudioLoop_ != nullptr && readAudioLoop_->joinable()) { - readAudioLoop_->join(); - readAudioLoop_.reset(); - readAudioLoop_ = nullptr; - } - if (audioCapturer_ != nullptr) { - if (!audioCapturer_->Pause()) { - MEDIA_LOGE("AudioCapturer Pause failed, threadName:%{public}s", threadName_.c_str()); - } - } - } - captureState_.store(CAPTURER_PAUSED); - MEDIA_LOGI("0x%{public}06" PRIXPTR " Pause E, threadName:%{public}s", FAKE_POINTER(this), threadName_.c_str()); - return MSERR_OK; -} - -int32_t AudioCapturerWrapper::Resume() -{ - std::lock_guard lock(mutex_); - if (isRunning_.load()) { - MEDIA_LOGE("Resume failed, is running, threadName:%{public}s", threadName_.c_str()); - return MSERR_UNKNOWN; - } -#ifdef SUPPORT_CALL - if (isInTelCall_.load()) { - MEDIA_LOGE("Resume failed, is in telephony call, threadName:%{public}s", threadName_.c_str()); - return MSERR_UNKNOWN; - } -#endif - CHECK_AND_RETURN_RET_LOG(audioCapturer_ != nullptr, MSERR_UNKNOWN, "Resume failed, audioCapturer_ is nullptr"); - - if (!audioCapturer_->Start()) { - MEDIA_LOGE("AudioCapturer Start failed, threadName:%{public}s", threadName_.c_str()); - OnStartFailed(ScreenCaptureErrorType::SCREEN_CAPTURE_ERROR_INTERNAL, SCREEN_CAPTURE_ERR_UNKNOWN); - return MSERR_UNKNOWN; - } - MEDIA_LOGI("0x%{public}06" PRIXPTR "Resume success, threadName:%{public}s", FAKE_POINTER(this), - threadName_.c_str()); - - isRunning_.store(true); - readAudioLoop_ = std::make_unique([this] { this->CaptureAudio(); }); - captureState_.store(CAPTURER_RECORDING); - return MSERR_OK; -} - int32_t AudioCapturerWrapper::Stop() { std::lock_guard lock(mutex_); + if (captureState_.load() == AudioCapturerWrapperState::CAPTURER_STOPED) { + return MSERR_OK; + } MEDIA_LOGI("0x%{public}06" PRIXPTR " Stop S, threadName:%{public}s", FAKE_POINTER(this), threadName_.c_str()); isRunning_.store(false); if (readAudioLoop_ != nullptr && readAudioLoop_->joinable()) { @@ -170,10 +122,10 @@ int32_t AudioCapturerWrapper::Stop() free(availBuffers_.front()->buffer); availBuffers_.front()->buffer = nullptr; } - availBuffers_.pop(); + availBuffers_.pop_front(); } MEDIA_LOGI("0x%{public}06" PRIXPTR " Stop E, threadName:%{public}s", FAKE_POINTER(this), threadName_.c_str()); - captureState_.store(CAPTURER_STOPED); + captureState_.store(AudioCapturerWrapperState::CAPTURER_STOPED); return MSERR_OK; } @@ -308,6 +260,35 @@ int32_t AudioCapturerWrapper::RelativeSleep(int64_t nanoTime) return ret; } +int32_t AudioCapturerWrapper::GetCaptureAudioBuffer(std::shared_ptr audioBuffer, size_t bufferLen) +{ + Timestamp timestamp; + memset_s(audioBuffer->buffer, bufferLen, 0, bufferLen); + int32_t bufferRead = audioCapturer_->Read(*(audioBuffer->buffer), bufferLen, true); + if (bufferRead <= 0) { + RelativeSleep(OHOS::Media::AUDIO_CAPTURE_READ_FAILED_WAIT_TIME); + PartiallyPrintLog(__LINE__, "CaptureAudio read audio buffer failed " + threadName_ + + " ret: " + std::to_string(bufferRead)); + return MSERR_NO_MEMORY; + } + audioBuffer->length = bufferRead; + bool ret = audioCapturer_->GetTimeStampInfo(timestamp, Timestamp::Timestampbase::MONOTONIC); + int64_t audioTime = static_cast(timestamp.time.tv_sec) * AUDIO_NS_PER_SECOND + + static_cast(timestamp.time.tv_nsec); + if (!ret) { + MEDIA_LOGE("0x%{public}06" PRIXPTR " GetTimeStampInfo failed name:%{public}s", + FAKE_POINTER(this), threadName_.c_str()); + return MSERR_NO_MEMORY; + } + if (audioInfo_.audioSource == AudioCaptureSourceType::SOURCE_DEFAULT || + audioInfo_.audioSource == AudioCaptureSourceType::MIC) { + audioBuffer->timestamp = audioTime; + } else { + audioBuffer->timestamp = audioTime + INNER_AUDIO_READ_TO_HEAR_TIME; + } + return MSERR_OK; +} + int32_t AudioCapturerWrapper::CaptureAudio() { MEDIA_LOGI("0x%{public}06" PRIXPTR " CaptureAudio S, name:%{public}s", FAKE_POINTER(this), threadName_.c_str()); @@ -316,7 +297,6 @@ int32_t AudioCapturerWrapper::CaptureAudio() size_t bufferLen = 0; CHECK_AND_RETURN_RET_LOG(audioCapturer_ != nullptr && audioCapturer_->GetBufferSize(bufferLen) == MSERR_OK && bufferLen > 0, MSERR_NO_MEMORY, "CaptureAudio GetBufferSize failed"); - Timestamp timestamp; std::shared_ptr audioBuffer; while (true) { CHECK_AND_RETURN_RET_LOG(isRunning_.load(), MSERR_OK, "CaptureAudio is not running, stop capture %{public}s", @@ -327,17 +307,9 @@ int32_t AudioCapturerWrapper::CaptureAudio() audioBuffer = std::make_shared(buffer, 0, 0, audioInfo_.audioSource); CHECK_AND_RETURN_RET_LOG(audioBuffer != nullptr, MSERR_OK, "CaptureAudio make_shared AudioBuffer failed" " %{public}s", name.c_str()); - memset_s(audioBuffer->buffer, bufferLen, 0, bufferLen); - int32_t bufferRead = audioCapturer_->Read(*(audioBuffer->buffer), bufferLen, true); - if (bufferRead <= 0) { - RelativeSleep(OHOS::Media::AUDIO_CAPTURE_READ_FAILED_WAIT_TIME); - PartiallyPrintLog(__LINE__, "CaptureAudio read audio buffer failed " + name); + if (GetCaptureAudioBuffer(audioBuffer, bufferLen) != MSERR_OK) { continue; } - audioBuffer->length = bufferRead; - audioCapturer_->GetAudioTime(timestamp, Timestamp::Timestampbase::MONOTONIC); - int64_t audioTime = timestamp.time.tv_nsec + timestamp.time.tv_sec * SEC_TO_NANOSECOND; - audioBuffer->timestamp = audioTime; { std::unique_lock lock(bufferMutex_); CHECK_AND_RETURN_RET_LOG(isRunning_.load(), MSERR_OK, "CaptureAudio is not running, ignore and stop" @@ -346,7 +318,7 @@ int32_t AudioCapturerWrapper::CaptureAudio() PartiallyPrintLog(__LINE__, "consume slow, drop audio frame" + name); continue; } - availBuffers_.push(audioBuffer); + availBuffers_.push_back(audioBuffer); } bufferCond_.notify_all(); CHECK_AND_RETURN_RET_LOG(isRunning_.load(), MSERR_OK, "CaptureAudio is not running, ignore and stop" @@ -354,11 +326,95 @@ int32_t AudioCapturerWrapper::CaptureAudio() CHECK_AND_RETURN_RET_LOG(screenCaptureCb_ != nullptr, MSERR_OK, "no consumer, will drop audio frame %{public}s", name.c_str()); screenCaptureCb_->OnAudioBufferAvailable(true, audioInfo_.audioSource); + usleep(WRAPPER_PUSH_AUDIO_SAMPLE_INTERVAL_IN_US); } MEDIA_LOGI("0x%{public}06" PRIXPTR " CaptureAudio E, name:%{public}s", FAKE_POINTER(this), threadName_.c_str()); return MSERR_OK; } +int32_t AudioCapturerWrapper::UseUpAllLeftBufferUntil(int64_t audioTime) +{ + using namespace std::chrono_literals; + std::unique_lock lock(bufferMutex_); + CHECK_AND_RETURN_RET(isRunning_.load(), MSERR_OK); + MEDIA_LOGD("0x%{public}06" PRIXPTR " UseUpBufUntil S, name:%{public}s", FAKE_POINTER(this), threadName_.c_str()); + if (!bufferCond_.wait_for(lock, std::chrono::milliseconds(STOP_WAIT_TIMEOUT_IN_MS), + [this, audioTime]() { + return availBuffers_.empty() || (availBuffers_.front() != nullptr && + availBuffers_.front()->timestamp >= audioTime); + })) { + MEDIA_LOGE("UseUpBufUntil timeout, threadName:%{public}s", threadName_.c_str()); + return MSERR_UNKNOWN; + } + if (!availBuffers_.empty() && (availBuffers_.front() != nullptr && availBuffers_.front()->timestamp < audioTime)) { + MEDIA_LOGE("UseUpBufUntil not finish all buffer, threadName:%{public}s", threadName_.c_str()); + return MSERR_UNKNOWN; + } + MEDIA_LOGD("0x%{public}06" PRIXPTR " UseUpBufUntil E, name:%{public}s", FAKE_POINTER(this), threadName_.c_str()); + return MSERR_OK; +} + +int32_t AudioCapturerWrapper::AddBufferFrom(int64_t timeWindow, int64_t bufferSize, int64_t fromTime) +{ + using namespace std::chrono_literals; + std::unique_lock lock(bufferMutex_); + CHECK_AND_RETURN_RET(isRunning_.load(), MSERR_OK); + CHECK_AND_RETURN_RET_LOG(bufferSize > 0 && bufferSize < MAX_AUDIO_BUFFER_LEN, MSERR_UNKNOWN, + "bufferSize invalid %{public}" PRId64, bufferSize); + MEDIA_LOGD("0x%{public}06" PRIXPTR " AddBufferFrom S, name:%{public}s", FAKE_POINTER(this), threadName_.c_str()); + int32_t diffCount = timeWindow / AUDIO_CAPTURE_READ_FRAME_TIME; + MEDIA_LOGI("Audio late, add buffer diffCount: %{public}d", diffCount); + while (diffCount > 0) { + std::shared_ptr audioBuffer; + uint8_t *cacheAudioData = static_cast(malloc(bufferSize)); + CHECK_AND_RETURN_RET_LOG(cacheAudioData != nullptr, MSERR_OK, "AddBuffer cacheAudioData no memory"); + audioBuffer = std::make_shared(cacheAudioData, 0, 0, audioInfo_.audioSource); + CHECK_AND_RETURN_RET_LOG(audioBuffer != nullptr, MSERR_OK, "AddBuffer make AudioBuffer failed"); + memset_s(audioBuffer->buffer, bufferSize, 0, bufferSize); + audioBuffer->length = bufferSize; + int64_t startTime = fromTime + (diffCount - 1) * AUDIO_CAPTURE_READ_FRAME_TIME; + audioBuffer->timestamp = startTime; + availBuffers_.push_front(audioBuffer); + --diffCount; + MEDIA_LOGD("0x%{public}06" PRIXPTR " ABuffer add name:%{public}s time: %{public}" PRId64, + FAKE_POINTER(this), threadName_.c_str(), startTime); + } + MEDIA_LOGD("0x%{public}06" PRIXPTR " AddBufferFrom E, name:%{public}s", FAKE_POINTER(this), threadName_.c_str()); + return MSERR_OK; +} + +int32_t AudioCapturerWrapper::DropBufferUntil(int64_t audioTime) +{ + using namespace std::chrono_literals; + std::unique_lock lock(bufferMutex_); + CHECK_AND_RETURN_RET(isRunning_.load(), MSERR_OK); + MEDIA_LOGD("0x%{public}06" PRIXPTR " DropBufferUntil S, name:%{public}s", FAKE_POINTER(this), threadName_.c_str()); + while (!availBuffers_.empty()) { + if (availBuffers_.front() != nullptr && availBuffers_.front()->timestamp < audioTime) { + MEDIA_LOGD("0x%{public}06" PRIXPTR " ABuffer drop name:%{public}s time: %{public}" PRId64, + FAKE_POINTER(this), threadName_.c_str(), availBuffers_.front()->timestamp); + availBuffers_.pop_front(); + } else { + break; + } + } + MEDIA_LOGD("0x%{public}06" PRIXPTR " DropBufferUntil E, name:%{public}s", FAKE_POINTER(this), threadName_.c_str()); + return MSERR_OK; +} + +int32_t AudioCapturerWrapper::GetCurrentAudioTime(int64_t ¤tAudioTime) +{ + struct timespec timestamp = {0, 0}; + clock_gettime(CLOCK_MONOTONIC, ×tamp); + currentAudioTime = static_cast(timestamp.tv_sec) * AUDIO_NS_PER_SECOND + + static_cast(timestamp.tv_nsec); + MEDIA_LOGD("0x%{public}06" PRIXPTR " GetCurrentAudioTime currentAudioTime:%{public}" PRId64, + FAKE_POINTER(this), currentAudioTime); + CHECK_AND_RETURN_RET_LOG(audioCapturer_ != nullptr, MSERR_UNKNOWN, + "AudioCapturerWrapper::GetCurrentAudioTime audioCapturer is nullptr"); + return MSERR_OK; +} + int32_t AudioCapturerWrapper::AcquireAudioBuffer(std::shared_ptr &audioBuffer) { using namespace std::chrono_literals; @@ -367,8 +423,10 @@ int32_t AudioCapturerWrapper::AcquireAudioBuffer(std::shared_ptr &a MEDIA_LOGD("0x%{public}06" PRIXPTR " Acquire Buffer S, name:%{public}s", FAKE_POINTER(this), threadName_.c_str()); if (!bufferCond_.wait_for(lock, std::chrono::milliseconds(OPERATION_TIMEOUT_IN_MS), - [this] { return !availBuffers_.empty() || captureState_.load() == CAPTURER_RELEASED; })) { - MEDIA_LOGE("AcquireAudioBuffer timeout, threadName:%{public}s", threadName_.c_str()); + [this] { + return !availBuffers_.empty() || captureState_.load() == AudioCapturerWrapperState::CAPTURER_RELEASED; + })) { + MEDIA_LOGD("AcquireAudioBuffer timeout, threadName:%{public}s", threadName_.c_str()); return MSERR_UNKNOWN; } if (availBuffers_.empty()) { @@ -406,7 +464,9 @@ int32_t AudioCapturerWrapper::ReleaseAudioBuffer() MEDIA_LOGD("0x%{public}06" PRIXPTR " Release Buffer S, name:%{public}s", FAKE_POINTER(this), threadName_.c_str()); CHECK_AND_RETURN_RET_LOG(isRunning_.load(), MSERR_UNKNOWN, "ReleaseAudioBuffer failed, not running"); CHECK_AND_RETURN_RET_LOG(!availBuffers_.empty(), MSERR_UNKNOWN, "ReleaseAudioBuffer failed, no frame to release"); - availBuffers_.pop(); + MEDIA_LOGD("0x%{public}06" PRIXPTR " ABuffer release name:%{public}s time: %{public}" PRId64, + FAKE_POINTER(this), threadName_.c_str(), availBuffers_.front()->timestamp); + availBuffers_.pop_front(); MEDIA_LOGD("0x%{public}06" PRIXPTR " Release Buffer E, name:%{public}s", FAKE_POINTER(this), threadName_.c_str()); return MSERR_OK; } diff --git a/services/services/screen_capture/server/audio_capturer_wrapper.h b/services/services/screen_capture/server/audio_capturer_wrapper.h index 27ffa05f6747e6dd7b03606c64134ccaadbde777..569751c2f043fa9e3551eb0cb7cfad334a7d6d00 100644 --- a/services/services/screen_capture/server/audio_capturer_wrapper.h +++ b/services/services/screen_capture/server/audio_capturer_wrapper.h @@ -60,8 +60,6 @@ public: contentFilter_(filter) {} virtual ~AudioCapturerWrapper(); int32_t Start(const OHOS::AudioStandard::AppInfo &appInfo); - int32_t Pause(); - int32_t Resume(); int32_t Stop(); int32_t UpdateAudioCapturerConfig(ScreenCaptureContentFilter &filter); int32_t CaptureAudio(); @@ -73,6 +71,10 @@ public: void SetIsInTelCall(bool isInTelCall); #endif AudioCapturerWrapperState GetAudioCapturerState(); + int32_t UseUpAllLeftBufferUntil(int64_t audioTime); + int32_t GetCurrentAudioTime(int64_t ¤tAudioTime); + int32_t DropBufferUntil(int64_t audioTime); + int32_t AddBufferFrom(int64_t timeWindow, int64_t bufferSize, int64_t fromTime); protected: virtual void OnStartFailed(ScreenCaptureErrorType errorType, int32_t errorCode); @@ -83,6 +85,7 @@ private: void SetInnerStreamUsage(std::vector &usages); void PartiallyPrintLog(int32_t lineNumber, std::string str); int32_t RelativeSleep(int64_t nanoTime); + int32_t GetCaptureAudioBuffer(std::shared_ptr audioBuffer, size_t bufferLen); protected: std::shared_ptr screenCaptureCb_; @@ -100,7 +103,7 @@ private: std::mutex bufferMutex_; std::condition_variable bufferCond_; - std::queue> availBuffers_; + std::deque> availBuffers_; std::string bundleName_; std::atomic isInVoIPCall_ = false; #ifdef SUPPORT_CALL @@ -111,11 +114,16 @@ private: /* used for hilog output */ std::map captureAudioLogCountMap_; + static constexpr int64_t INNER_AUDIO_READ_TO_HEAR_TIME = 240000000; // 240ms + static constexpr uint32_t WRAPPER_PUSH_AUDIO_SAMPLE_INTERVAL_IN_US = 5000; // 5ms static constexpr uint32_t MAX_THREAD_NAME_LENGTH = 15; static constexpr uint32_t MAX_AUDIO_BUFFER_SIZE = 128; static constexpr uint32_t SEC_TO_NANOSECOND = 1000000000; // 10^9ns - static constexpr uint32_t OPERATION_TIMEOUT_IN_MS = 200; // 200ms + static constexpr uint32_t OPERATION_TIMEOUT_IN_MS = 5; // 5ms static constexpr int32_t AC_LOG_SKIP_NUM = 1000; + static constexpr uint32_t STOP_WAIT_TIMEOUT_IN_MS = 500; // 500ms + static constexpr int64_t AUDIO_CAPTURE_READ_FRAME_TIME = 21333333; // 21333333 ns 21ms + static constexpr int32_t MAX_AUDIO_BUFFER_LEN = 10 * 1024 * 1024; // 10M }; class MicAudioCapturerWrapper : public AudioCapturerWrapper { diff --git a/services/services/screen_capture/server/screen_capture_server.cpp b/services/services/screen_capture/server/screen_capture_server.cpp index 6ba8d14ed4c75000bde021a3676b3a9c7b951264..0d6f196fa549232253fe05c6ccac1bc15cea8b7f 100644 --- a/services/services/screen_capture/server/screen_capture_server.cpp +++ b/services/services/screen_capture/server/screen_capture_server.cpp @@ -87,7 +87,7 @@ static const int32_t WINDOW_INFO_LIST_SIZE = 1; #endif static const auto NOTIFICATION_SUBSCRIBER = NotificationSubscriber(); -static constexpr int32_t AUDIO_CHANGE_TIME = 200000; // 200 ms +static constexpr int32_t AUDIO_CHANGE_TIME = 80000; // 80 ms std::map> ScreenCaptureServer::serverMap_{}; std::map> ScreenCaptureServer::saUidAppUidMap_{}; @@ -500,6 +500,8 @@ int32_t ScreenCaptureServer::RegisterWindowInfoChangedListener() "create new windowInfoChangedListener failed."); windowInfoChangedListener_ = listener; windowInfoChangedListener_->AddInterestInfo(Rosen::WindowInfoKey::WINDOW_ID); + CHECK_AND_RETURN_RET_LOG(!windowIdList_.empty(), MSERR_INVALID_OPERATION, + "windowIdList is empty, AddInterestWindowId failed."); windowInfoChangedListener_->AddInterestWindowId(windowIdList_.front()); std::unordered_set observedInfo; @@ -926,6 +928,36 @@ DataType ScreenCaptureServer::GetSCServerDataType() return captureConfig_.dataType; } +bool ScreenCaptureServer::IsMicrophoneSwitchTurnOn() +{ + return isMicrophoneSwitchTurnOn_; +} + +bool ScreenCaptureServer::IsSCRecorderFileWithVideo() +{ + return recorderFileWithVideo_.load(); +} + +std::shared_ptr ScreenCaptureServer::GetInnerAudioCapture() +{ + return innerAudioCapture_; +} + +void ScreenCaptureServer::SetInnerAudioCapture(std::shared_ptr innerAudioCapture) +{ + innerAudioCapture_ = innerAudioCapture; +} + +std::shared_ptr ScreenCaptureServer::GetMicAudioCapture() +{ + return micAudioCapture_; +} + +bool ScreenCaptureServer::IsStopAcquireAudioBufferFlag() +{ + return stopAcquireAudioBufferFromAudio_; +} + void ScreenCaptureServer::SetDisplayId(uint64_t displayId) { captureConfig_.videoInfo.videoCapInfo.displayId = displayId; @@ -1360,6 +1392,9 @@ int32_t ScreenCaptureServer::CheckCaptureStreamParams() " videoCapInfo.state:%{public}d, innerCapInfo.state:%{public}d.", FAKE_POINTER(this), isSurfaceMode_ ? "true" : "false", captureConfig_.videoInfo.videoCapInfo.state, captureConfig_.audioInfo.innerCapInfo.state); + if (captureConfig_.audioInfo.micCapInfo.state != AVScreenCaptureParamValidationState::VALIDATION_VALID) { + isMicrophoneSwitchTurnOn_ = false; + } if (isSurfaceMode_) { // surface mode, surface must not nullptr and videoCapInfo must valid. if (surface_ == nullptr || @@ -1601,11 +1636,6 @@ int32_t ScreenCaptureServer::StartFileInnerAudioCapture() std::string(GenerateThreadNameByPrefix("OS_FInnAd")), contentFilter_); int32_t ret = innerCapture->Start(appInfo_); CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "StartFileInnerAudioCapture failed"); - if (audioSource_ && audioSource_->GetSpeakerAliveStatus() && !audioSource_->GetIsInVoIPCall() && - micAudioCapture_ && micAudioCapture_->GetAudioCapturerState() == CAPTURER_RECORDING) { - ret = innerCapture->Pause(); - CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "StartAudioCapture innerCapture Pause failed"); - } } innerAudioCapture_ = innerCapture; MEDIA_LOGI("ScreenCaptureServer: 0x%{public}06" PRIXPTR " StartFileInnerAudioCapture OK.", FAKE_POINTER(this)); @@ -1620,6 +1650,7 @@ int32_t ScreenCaptureServer::StartFileMicAudioCapture() #ifdef SUPPORT_CALL if (InCallObserver::GetInstance().IsInCall(true) && !IsTelInCallSkipList()) { MEDIA_LOGI("ScreenCaptureServer: 0x%{public}06" PRIXPTR " skip creating micAudioCapture", FAKE_POINTER(this)); + NotifyStateChange(AVScreenCaptureStateCode::SCREEN_CAPTURE_STATE_MIC_UNAVAILABLE); return MSERR_OK; } #endif @@ -1696,9 +1727,12 @@ int32_t ScreenCaptureServer::StartScreenCaptureFile() // not return, if start mic capture failed, inner capture will be started } } - int32_t retInner = StartFileInnerAudioCapture(); - CHECK_AND_RETURN_RET_LOG(retInner == MSERR_OK, retInner, "StartFileInnerAudioCapture failed, ret:%{public}d," - "dataType:%{public}d", retInner, captureConfig_.dataType); + if (audioSource_ && !(audioSource_->GetSpeakerAliveStatus() && !audioSource_->GetIsInVoIPCall() && + isMicrophoneSwitchTurnOn_)) { // skip only when speaker on, voip off, mic on + int32_t retInner = StartFileInnerAudioCapture(); + CHECK_AND_RETURN_RET_LOG(retInner == MSERR_OK, retInner, "StartFileInnerAudioCapture failed, ret:%{public}d," + "dataType:%{public}d", retInner, captureConfig_.dataType); + } MEDIA_LOGI("StartScreenCaptureFile RecorderServer S"); ret = recorder_->Start(); if (ret != MSERR_OK) { @@ -1972,6 +2006,33 @@ int32_t ScreenCaptureServer::InitRecorderInfo(std::shared_ptr return MSERR_OK; } +int32_t ScreenCaptureServer::InitRecorderMix() +{ + int32_t ret = MSERR_OK; + MEDIA_LOGI("InitRecorder prepare to SetAudioDataSource"); + audioSource_ = std::make_unique(AVScreenCaptureMixMode::MIX_MODE, this); + captureCallback_ = std::make_shared(); + audioSource_->SetAppPid(appInfo_.appPid); + audioSource_->SetAppName(appName_); + captureCallback_->SetAppName(appName_); + captureCallback_->SetAudioSource(audioSource_); + audioSource_->RegisterAudioRendererEventListener(appInfo_.appPid, captureCallback_); + ret = recorder_->SetAudioDataSource(audioSource_, audioSourceId_); + recorderFileAudioType_ = AVScreenCaptureMixMode::MIX_MODE; + return ret; +} + +int32_t ScreenCaptureServer::InitRecorderInner() +{ + int32_t ret = MSERR_OK; + isMicrophoneSwitchTurnOn_ = false; + MEDIA_LOGI("InitRecorder prepare to SetAudioSource inner"); + audioSource_ = std::make_unique(AVScreenCaptureMixMode::INNER_MODE, this); + ret = recorder_->SetAudioDataSource(audioSource_, audioSourceId_); + recorderFileAudioType_ = AVScreenCaptureMixMode::INNER_MODE; + return ret; +} + int32_t ScreenCaptureServer::InitRecorder() { CHECK_AND_RETURN_RET_LOG(outputFd_ > 0, MSERR_INVALID_OPERATION, "the outputFd is invalid"); @@ -1986,28 +2047,19 @@ int32_t ScreenCaptureServer::InitRecorder() AudioCaptureInfo audioInfo; if (captureConfig_.audioInfo.innerCapInfo.state == AVScreenCaptureParamValidationState::VALIDATION_VALID && captureConfig_.audioInfo.micCapInfo.state == AVScreenCaptureParamValidationState::VALIDATION_VALID) { - MEDIA_LOGI("InitRecorder prepare to SetAudioDataSource"); audioInfo = captureConfig_.audioInfo.innerCapInfo; - audioSource_ = std::make_unique(AVScreenCaptureMixMode::MIX_MODE, this); - captureCallback_ = std::make_shared(); - audioSource_->SetAppPid(appInfo_.appPid); - audioSource_->SetAppName(appName_); - captureCallback_->SetAppName(appName_); - captureCallback_->SetAudioSource(audioSource_); - audioSource_->RegisterAudioRendererEventListener(appInfo_.appPid, captureCallback_); - ret = recorder_->SetAudioDataSource(audioSource_, audioSourceId_); + ret = InitRecorderMix(); CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, MSERR_UNKNOWN, "SetAudioDataSource failed"); } else if (captureConfig_.audioInfo.innerCapInfo.state == AVScreenCaptureParamValidationState::VALIDATION_VALID) { audioInfo = captureConfig_.audioInfo.innerCapInfo; - MEDIA_LOGI("InitRecorder prepare to SetAudioSource inner"); - audioSource_ = std::make_unique(AVScreenCaptureMixMode::INNER_MODE, this); - ret = recorder_->SetAudioDataSource(audioSource_, audioSourceId_); + ret = InitRecorderInner(); CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, MSERR_UNKNOWN, "SetAudioDataSource failed"); } else if (captureConfig_.audioInfo.micCapInfo.state == AVScreenCaptureParamValidationState::VALIDATION_VALID) { audioInfo = captureConfig_.audioInfo.micCapInfo; MEDIA_LOGI("InitRecorder prepare to SetAudioSource mic"); audioSource_ = std::make_unique(AVScreenCaptureMixMode::MIC_MODE, this); ret = recorder_->SetAudioDataSource(audioSource_, audioSourceId_); + recorderFileAudioType_ = AVScreenCaptureMixMode::MIC_MODE; CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, MSERR_UNKNOWN, "SetAudioDataSource failed"); } else { MEDIA_LOGE("InitRecorder not VALIDATION_VALID"); @@ -2021,6 +2073,7 @@ int32_t ScreenCaptureServer::InitRecorder() ret = recorder_->Prepare(); CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, MSERR_UNKNOWN, "recorder Prepare failed"); if (captureConfig_.videoInfo.videoCapInfo.state != AVScreenCaptureParamValidationState::VALIDATION_IGNORE) { + recorderFileWithVideo_.store(true); consumer_ = recorder_->GetSurface(videoSourceId_); CHECK_AND_RETURN_RET_LOG(consumer_ != nullptr, MSERR_UNKNOWN, "recorder GetSurface failed"); } @@ -2857,7 +2910,7 @@ VirtualScreenOption ScreenCaptureServer::InitVirtualScreenOption(const std::stri .height_ = captureConfig_.videoInfo.videoCapInfo.videoFrameHeight, .density_ = 0, .surface_ = consumer, - .flags_ = 0, + .flags_ = captureConfig_.strategy.strategyForPrivacyMaskMode, .isForShot_ = true, .missionIds_ = {}, .virtualScreenType_ = VirtualScreenType::SCREEN_RECORDING, @@ -2882,7 +2935,7 @@ int32_t ScreenCaptureServer::GetMissionIds(std::vector &missionIds) int32_t ScreenCaptureServer::AcquireAudioBuffer(std::shared_ptr &audioBuffer, AudioCaptureSourceType type) { - MediaTrace trace("ScreenCaptureServer::AcquireAudioBuffer"); + MediaTrace trace("ScreenCaptureServer::AcquireAudioBuffer", HITRACE_LEVEL_DEBUG); std::unique_lock lock(mutex_); MEDIA_LOGD("ScreenCaptureServer: 0x%{public}06" PRIXPTR " AcquireAudioBuffer start, state:%{public}d, " "type:%{public}d.", FAKE_POINTER(this), captureState_, type); @@ -2903,42 +2956,9 @@ int32_t ScreenCaptureServer::AcquireAudioBuffer(std::shared_ptr &au return MSERR_UNKNOWN; } -int32_t ScreenCaptureServer::AcquireAudioBufferMix(std::shared_ptr &innerAudioBuffer, - std::shared_ptr &micAudioBuffer, AVScreenCaptureMixMode type) -{ - if (captureState_ != AVScreenCaptureState::STARTED) { - return MSERR_INVALID_STATE; - } - if (type == AVScreenCaptureMixMode::MIX_MODE && micAudioCapture_ != nullptr && - micAudioCapture_->GetAudioCapturerState() == CAPTURER_RECORDING) { - if (micAudioCapture_->AcquireAudioBuffer(micAudioBuffer) != MSERR_OK) { - MEDIA_LOGE("micAudioCapture AcquireAudioBuffer failed"); - } - } - if (type == AVScreenCaptureMixMode::MIX_MODE && innerAudioCapture_ != nullptr && - innerAudioCapture_->GetAudioCapturerState() == CAPTURER_RECORDING) { - if (innerAudioCapture_->AcquireAudioBuffer(innerAudioBuffer) != MSERR_OK) { - MEDIA_LOGE("innerAudioCapture AcquireAudioBuffer failed"); - } - } - if (type == AVScreenCaptureMixMode::MIC_MODE && micAudioCapture_ != nullptr && - micAudioCapture_->GetAudioCapturerState() == CAPTURER_RECORDING) { - if (micAudioCapture_->AcquireAudioBuffer(micAudioBuffer) != MSERR_OK) { - MEDIA_LOGE("micAudioCapture AcquireAudioBuffer failed"); - } - } - if (type == AVScreenCaptureMixMode::INNER_MODE && innerAudioCapture_ != nullptr && - innerAudioCapture_->GetAudioCapturerState() == CAPTURER_RECORDING) { - if (innerAudioCapture_->AcquireAudioBuffer(innerAudioBuffer) != MSERR_OK) { - MEDIA_LOGE("innerAudioCapture AcquireAudioBuffer failed"); - } - } - return MSERR_OK; -} - int32_t ScreenCaptureServer::ReleaseAudioBuffer(AudioCaptureSourceType type) { - MediaTrace trace("ScreenCaptureServer::ReleaseAudioBuffer"); + MediaTrace trace("ScreenCaptureServer::ReleaseAudioBuffer", HITRACE_LEVEL_DEBUG); std::unique_lock lock(mutex_); MEDIA_LOGD("ScreenCaptureServer: 0x%{public}06" PRIXPTR " ReleaseAudioBuffer start, state:%{public}d, " "type:%{public}d.", FAKE_POINTER(this), captureState_, type); @@ -2959,37 +2979,6 @@ int32_t ScreenCaptureServer::ReleaseAudioBuffer(AudioCaptureSourceType type) return MSERR_UNKNOWN; } -int32_t ScreenCaptureServer::ReleaseAudioBufferMix(AVScreenCaptureMixMode type) -{ - CHECK_AND_RETURN_RET_LOG(captureState_ == AVScreenCaptureState::STARTED, MSERR_INVALID_OPERATION, - "ReleaseAudioBuffer failed, capture is not STARTED, state:%{public}d, type:%{public}d", captureState_, type); - if (type == AVScreenCaptureMixMode::MIX_MODE && micAudioCapture_ != nullptr && - micAudioCapture_->GetAudioCapturerState() == CAPTURER_RECORDING) { - if (micAudioCapture_->ReleaseAudioBuffer() != MSERR_OK) { - MEDIA_LOGE("micAudioCapture ReleaseAudioBuffer failed"); - } - } - if (type == AVScreenCaptureMixMode::MIX_MODE && innerAudioCapture_ != nullptr && - innerAudioCapture_->GetAudioCapturerState() == CAPTURER_RECORDING) { - if (innerAudioCapture_->ReleaseAudioBuffer() != MSERR_OK) { - MEDIA_LOGE("innerAudioCapture ReleaseAudioBuffer failed"); - } - } - if (type == AVScreenCaptureMixMode::MIC_MODE && micAudioCapture_ != nullptr && - micAudioCapture_->GetAudioCapturerState() == CAPTURER_RECORDING) { - if (micAudioCapture_->ReleaseAudioBuffer() != MSERR_OK) { - MEDIA_LOGE("micAudioCapture ReleaseAudioBuffer failed"); - } - } - if (type == AVScreenCaptureMixMode::INNER_MODE && innerAudioCapture_ != nullptr && - innerAudioCapture_->GetAudioCapturerState() == CAPTURER_RECORDING) { - if (innerAudioCapture_->ReleaseAudioBuffer() != MSERR_OK) { - MEDIA_LOGE("innerAudioCapture ReleaseAudioBuffer failed"); - } - } - return MSERR_OK; -} - int32_t ScreenCaptureServer::ReleaseInnerAudioBuffer() { CHECK_AND_RETURN_RET_LOG(innerAudioCapture_, MSERR_UNKNOWN, "innerAudioCapture_ is nullptr"); @@ -3029,7 +3018,7 @@ int32_t ScreenCaptureServer::GetMicAudioCaptureBufferSize(size_t &size) int32_t ScreenCaptureServer::AcquireVideoBuffer(sptr &surfaceBuffer, int32_t &fence, int64_t ×tamp, OHOS::Rect &damage) { - MediaTrace trace("ScreenCaptureServer::AcquireVideoBuffer"); + MediaTrace trace("ScreenCaptureServer::AcquireVideoBuffer", HITRACE_LEVEL_DEBUG); std::unique_lock lock(mutex_); MEDIA_LOGD("ScreenCaptureServer: 0x%{public}06" PRIXPTR " AcquireVideoBuffer start, state:%{public}d, " "fence:%{public}d, timestamp:%{public}" PRId64, FAKE_POINTER(this), captureState_, fence, timestamp); @@ -3062,7 +3051,7 @@ int32_t ScreenCaptureServer::AcquireVideoBuffer(sptr &surfa int32_t ScreenCaptureServer::ReleaseVideoBuffer() { - MediaTrace trace("ScreenCaptureServer::ReleaseVideoBuffer"); + MediaTrace trace("ScreenCaptureServer::ReleaseVideoBuffer", HITRACE_LEVEL_DEBUG); std::unique_lock lock(mutex_); MEDIA_LOGD("ScreenCaptureServer: 0x%{public}06" PRIXPTR " ReleaseVideoBuffer start, state:%{public}d.", FAKE_POINTER(this), captureState_); @@ -3175,13 +3164,15 @@ int32_t ScreenCaptureServer::SetMicrophoneEnabled(bool isMicrophone) MEDIA_LOGI("ScreenCaptureServer: 0x%{public}06" PRIXPTR " SetMicrophoneEnabled isMicrophoneSwitchTurnOn_:" "%{public}d, new isMicrophone:%{public}d", FAKE_POINTER(this), isMicrophoneSwitchTurnOn_, isMicrophone); int32_t ret = MSERR_UNKNOWN; - isMicrophoneSwitchTurnOn_ = isMicrophone; if (isMicrophone) { statisticalEventInfo_.enableMic = true; } if (captureState_ != AVScreenCaptureState::STARTED) { + isMicrophoneSwitchTurnOn_ = isMicrophone; return MSERR_OK; } + CHECK_AND_RETURN_RET_LOG(captureConfig_.audioInfo.micCapInfo.state == + AVScreenCaptureParamValidationState::VALIDATION_VALID, MSERR_OK, "No Microphone Config"); if (isMicrophone) { ret = SetMicrophoneOn(); CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "SetMicrophoneOn failed"); @@ -3191,6 +3182,7 @@ int32_t ScreenCaptureServer::SetMicrophoneEnabled(bool isMicrophone) CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "SetMicrophoneOff failed"); NotifyStateChange(AVScreenCaptureStateCode::SCREEN_CAPTURE_STATE_MIC_MUTED_BY_USER); } + isMicrophoneSwitchTurnOn_ = isMicrophone; // For CAPTURE FILE, should call Recorder interface to make effect MEDIA_LOGI("SetMicrophoneEnabled OK."); return MSERR_OK; @@ -3214,8 +3206,8 @@ int32_t ScreenCaptureServer::SetMicrophoneOn() ret = StartFileMicAudioCapture(); CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "StartFileMicAudioCapture failed"); } - } else if (micAudioCapture_->GetAudioCapturerState() == CAPTURER_PAUSED) { - ret = micAudioCapture_->Resume(); + } else if (micAudioCapture_->GetAudioCapturerState() == AudioCapturerWrapperState::CAPTURER_STOPED) { + ret = micAudioCapture_->Start(appInfo_); // Resume if (ret != MSERR_OK) { MEDIA_LOGE("micAudioCapture Resume failed"); NotifyStateChange(AVScreenCaptureStateCode::SCREEN_CAPTURE_STATE_MIC_UNAVAILABLE); @@ -3224,29 +3216,20 @@ int32_t ScreenCaptureServer::SetMicrophoneOn() } else if (micAudioCapture_->GetAudioCapturerState() != CAPTURER_RECORDING) { MEDIA_LOGE("AudioCapturerState invalid"); } - if (captureConfig_.dataType == DataType::CAPTURE_FILE) { - CHECK_AND_RETURN_RET_LOG(micAudioCapture_ && micAudioCapture_->GetAudioCapturerState() == CAPTURER_RECORDING, - MSERR_OK, "micAudioCapture is not recording"); - if (innerAudioCapture_ && innerAudioCapture_->GetAudioCapturerState() == CAPTURER_RECORDING && - audioSource_ && audioSource_->GetSpeakerAliveStatus() && !audioSource_->GetIsInVoIPCall()) { - usleep(AUDIO_CHANGE_TIME); - ret = innerAudioCapture_->Pause(); - CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "innerAudioCapture Pause failed"); - } - } return MSERR_OK; } int32_t ScreenCaptureServer::SetMicrophoneOff() { int32_t ret = MSERR_UNKNOWN; - if (innerAudioCapture_ && innerAudioCapture_->GetAudioCapturerState() == CAPTURER_PAUSED) { - ret = innerAudioCapture_->Resume(); - CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "innerAudioCapture Resume failed"); + if (recorderFileAudioType_ == AVScreenCaptureMixMode::MIX_MODE && !innerAudioCapture_) { + ret = StartFileInnerAudioCapture(); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "innerAudioCapture Start failed"); } if (micAudioCapture_ && micAudioCapture_->GetAudioCapturerState() == CAPTURER_RECORDING) { usleep(AUDIO_CHANGE_TIME); - ret = micAudioCapture_->Pause(); + MEDIA_LOGI("Microphone Pause"); + ret = StopMicAudioCapture(); // Pause CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "micAudioCapture Pause failed"); } return MSERR_OK; @@ -3256,14 +3239,10 @@ int32_t ScreenCaptureServer::OnSpeakerAliveStatusChanged(bool speakerAliveStatus { int32_t ret = MSERR_UNKNOWN; CHECK_AND_RETURN_RET_LOG(innerAudioCapture_, MSERR_UNKNOWN, "innerAudioCapture_ is nullptr"); - if (!speakerAliveStatus && innerAudioCapture_->GetAudioCapturerState() == CAPTURER_PAUSED) { - ret = innerAudioCapture_->Resume(); + if (!speakerAliveStatus && recorderFileAudioType_ == AVScreenCaptureMixMode::MIX_MODE && + innerAudioCapture_->GetAudioCapturerState() == CAPTURER_STOPED) { // back to headset + ret = innerAudioCapture_->Start(appInfo_); // Resume CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "innerAudioCapture Resume failed"); - } else if (speakerAliveStatus && micAudioCapture_ && - micAudioCapture_->GetAudioCapturerState() == CAPTURER_RECORDING && audioSource_ && - !audioSource_->GetIsInVoIPCall() && innerAudioCapture_->GetAudioCapturerState() == CAPTURER_RECORDING) { - ret = innerAudioCapture_->Pause(); - CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "innerAudioCapture Pause failed"); } return MSERR_OK; } @@ -3271,6 +3250,7 @@ int32_t ScreenCaptureServer::OnSpeakerAliveStatusChanged(bool speakerAliveStatus int32_t ScreenCaptureServer::ReStartMicForVoIPStatusSwitch() { int32_t ret = MSERR_OK; + usleep(AUDIO_CHANGE_TIME); StopMicAudioCapture(); if (isMicrophoneSwitchTurnOn_) { #ifdef SUPPORT_CALL @@ -3291,27 +3271,15 @@ int32_t ScreenCaptureServer::ReStartMicForVoIPStatusSwitch() int32_t ScreenCaptureServer::OnVoIPStatusChanged(bool isInVoIPCall) { MEDIA_LOGI("OnVoIPStatusChanged, isInVoIPCall:%{public}d", isInVoIPCall); - int32_t ret = MSERR_UNKNOWN; if (isInVoIPCall) { CHECK_AND_RETURN_RET_LOG(innerAudioCapture_, MSERR_UNKNOWN, "innerAudioCapture is nullptr"); - if (innerAudioCapture_->GetAudioCapturerState() == CAPTURER_PAUSED) { - ret = innerAudioCapture_->Resume(); - CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "innerAudioCapture Resume failed"); - } - usleep(AUDIO_CHANGE_TIME); - ReStartMicForVoIPStatusSwitch(); - } else { - ReStartMicForVoIPStatusSwitch(); - CHECK_AND_RETURN_RET_LOG(innerAudioCapture_, MSERR_UNKNOWN, "innerAudioCapture is nullptr"); - if (innerAudioCapture_->GetAudioCapturerState() == CAPTURER_RECORDING && - micAudioCapture_ && micAudioCapture_->GetAudioCapturerState() == CAPTURER_RECORDING && - audioSource_ && audioSource_->GetSpeakerAliveStatus()) { - usleep(AUDIO_CHANGE_TIME); - ret = innerAudioCapture_->Pause(); - CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "innerAudioCapture Pause failed"); + if (recorderFileAudioType_ == AVScreenCaptureMixMode::MIX_MODE && + innerAudioCapture_->GetAudioCapturerState() == CAPTURER_STOPED) { + int32_t ret = innerAudioCapture_->Start(appInfo_); // Resume + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "OnVoIPStatusChanged innerAudioCapture Resume failed"); } } - return MSERR_OK; + return ReStartMicForVoIPStatusSwitch(); } #ifdef SUPPORT_CALL @@ -3351,16 +3319,17 @@ int32_t ScreenCaptureServer::OnTelCallStart() if (!isInTelCall_.load() && !isInTelCallAudio_.load()) { return ret; } - if (innerAudioCapture_ && innerAudioCapture_->GetAudioCapturerState() == CAPTURER_PAUSED) { - ret = innerAudioCapture_->Resume(); - CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "innerAudioCapture Resume failed"); + if (recorderFileAudioType_ == AVScreenCaptureMixMode::MIX_MODE && !innerAudioCapture_) { + ret = StartFileInnerAudioCapture(); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "tel innerAudioCapture Start failed"); } if (micAudioCapture_) { - usleep(AUDIO_CHANGE_TIME); micAudioCapture_->SetIsInTelCall(true); if (micAudioCapture_->GetAudioCapturerState() == CAPTURER_RECORDING) { - ret = micAudioCapture_->Pause(); + usleep(AUDIO_CHANGE_TIME); + ret = StopMicAudioCapture(); // Pause CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "micAudioCapture Pause failed"); + NotifyStateChange(AVScreenCaptureStateCode::SCREEN_CAPTURE_STATE_MIC_UNAVAILABLE); } } return MSERR_OK; @@ -3375,8 +3344,9 @@ int32_t ScreenCaptureServer::OnTelCallStop() } if (micAudioCapture_) { micAudioCapture_->SetIsInTelCall(false); - if (isMicrophoneSwitchTurnOn_ && micAudioCapture_->GetAudioCapturerState() == CAPTURER_PAUSED) { - ret = micAudioCapture_->Resume(); + if (isMicrophoneSwitchTurnOn_ && micAudioCapture_->GetAudioCapturerState() == + AudioCapturerWrapperState::CAPTURER_STOPED) { + ret = micAudioCapture_->Start(appInfo_); // Resume if (ret != MSERR_OK) { MEDIA_LOGE("micAudioCapture Resume failed"); NotifyStateChange(AVScreenCaptureStateCode::SCREEN_CAPTURE_STATE_MIC_UNAVAILABLE); @@ -3393,29 +3363,10 @@ int32_t ScreenCaptureServer::OnTelCallStop() CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "StartFileMicAudioCapture failed"); } } - if (captureConfig_.dataType == DataType::CAPTURE_FILE) { - CHECK_AND_RETURN_RET_LOG(micAudioCapture_ && micAudioCapture_->GetAudioCapturerState() == CAPTURER_RECORDING, - MSERR_OK, "micAudioCapture is not recording"); - usleep(AUDIO_CHANGE_TIME); - if (innerAudioCapture_ && innerAudioCapture_->GetAudioCapturerState() == CAPTURER_RECORDING && - audioSource_ && audioSource_->GetSpeakerAliveStatus() && !audioSource_->GetIsInVoIPCall()) { - ret = innerAudioCapture_->Pause(); - CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "innerAudioCapture Pause failed"); - } - } return MSERR_OK; } #endif -bool ScreenCaptureServer::GetMicWorkingState() -{ - MEDIA_LOGD("ScreenCaptureServer: 0x%{public}06" PRIXPTR " GetMicWorkingState", FAKE_POINTER(this)); - if (micAudioCapture_ != nullptr) { - return micAudioCapture_->GetAudioCapturerState() == CAPTURER_RECORDING; - } - return false; -} - int32_t ScreenCaptureServer::SetCanvasRotation(bool canvasRotation) { MediaTrace trace("ScreenCaptureServer::SetCanvasRotation"); @@ -3639,6 +3590,7 @@ int32_t ScreenCaptureServer::StartMicAudioCapture() #ifdef SUPPORT_CALL if (InCallObserver::GetInstance().IsInCall(true) && !IsTelInCallSkipList()) { MEDIA_LOGI("ScreenCaptureServer: 0x%{public}06" PRIXPTR " skip creating micAudioCapture", FAKE_POINTER(this)); + NotifyStateChange(AVScreenCaptureStateCode::SCREEN_CAPTURE_STATE_MIC_UNAVAILABLE); return MSERR_OK; } #endif @@ -3661,24 +3613,26 @@ int32_t ScreenCaptureServer::StartMicAudioCapture() int32_t ScreenCaptureServer::StopInnerAudioCapture() { + int32_t ret = MSERR_OK; MEDIA_LOGI("ScreenCaptureServer: 0x%{public}06" PRIXPTR " StopInnerAudioCapture start.", FAKE_POINTER(this)); if (innerAudioCapture_ != nullptr) { MediaTrace trace("ScreenCaptureServer::StopInnerAudioCapture"); - innerAudioCapture_->Stop(); + ret = innerAudioCapture_->Stop(); } MEDIA_LOGI("ScreenCaptureServer: 0x%{public}06" PRIXPTR " StopInnerAudioCapture end.", FAKE_POINTER(this)); - return MSERR_OK; + return ret; } int32_t ScreenCaptureServer::StopMicAudioCapture() { + int32_t ret = MSERR_OK; MEDIA_LOGI("ScreenCaptureServer: 0x%{public}06" PRIXPTR " StopMicAudioCapture start.", FAKE_POINTER(this)); if (micAudioCapture_ != nullptr) { MediaTrace trace("ScreenCaptureServer::StopAudioCaptureMic"); - micAudioCapture_->Stop(); + ret = micAudioCapture_->Stop(); } MEDIA_LOGI("ScreenCaptureServer: 0x%{public}06" PRIXPTR " StopMicAudioCapture end.", FAKE_POINTER(this)); - return MSERR_OK; + return ret; } int32_t ScreenCaptureServer::StopVideoCapture() @@ -3716,6 +3670,16 @@ int32_t ScreenCaptureServer::StopScreenCaptureRecorder() MediaTrace trace("ScreenCaptureServer::StopScreenCaptureRecorder"); int32_t ret = MSERR_OK; if (recorder_ != nullptr) { + stopAcquireAudioBufferFromAudio_ = true; + if (recorderFileAudioType_ == AVScreenCaptureMixMode::MIX_MODE && + audioSource_ && audioSource_->IsInWaitMicSyncState() && + innerAudioCapture_ && innerAudioCapture_->GetAudioCapturerState() == CAPTURER_RECORDING) { + int64_t currentAudioTime; + innerAudioCapture_->GetCurrentAudioTime(currentAudioTime); + MEDIA_LOGI("0x%{public}06" PRIXPTR " UseUpAllLeftBuffer currentAudioTime: %{public}" PRId64, + FAKE_POINTER(this), currentAudioTime); + innerAudioCapture_->UseUpAllLeftBufferUntil(currentAudioTime); + } ret = recorder_->Stop(false); if (ret != MSERR_OK) { MEDIA_LOGE("StopScreenCaptureRecorder recorder stop failed, ret:%{public}d", ret); @@ -3968,8 +3932,9 @@ int32_t ScreenCaptureServer::SetScreenCaptureStrategy(ScreenCaptureStrategy stra std::lock_guard lock(mutex_); CHECK_AND_RETURN_RET_LOG(captureState_ < AVScreenCaptureState::POPUP_WINDOW, MSERR_UNSUPPORT, "strategy can not be modified after screencapture started"); - MEDIA_LOGI("SetScreenCaptureStrategy enableDeviceLevelCapture: %{public}d, keepCaptureDuringCall: %{public}d", - strategy.enableDeviceLevelCapture, strategy.keepCaptureDuringCall); + MEDIA_LOGI("SetScreenCaptureStrategy enableDeviceLevelCapture: %{public}d, keepCaptureDuringCall: %{public}d," + "strategyForPrivacyMaskMode: %{public}d", + strategy.enableDeviceLevelCapture, strategy.keepCaptureDuringCall, strategy.strategyForPrivacyMaskMode); captureConfig_.strategy = strategy; return MSERR_OK; } @@ -4049,7 +4014,7 @@ ScreenCaptureObserverCallBack::~ScreenCaptureObserverCallBack() void ScreenCapBufferConsumerListener::OnBufferAvailable() { - MediaTrace trace("ScreenCapConsumer::OnBufferAvailable"); + MediaTrace trace("ScreenCapConsumer::OnBufferAvailable", HITRACE_LEVEL_DEBUG); MEDIA_LOGD("ScreenCapConsumer: 0x%{public}06" PRIXPTR " OnBufferAvailable start.", FAKE_POINTER(this)); { std::lock_guard lock(bufferAvailableWorkerMtx_); @@ -4062,7 +4027,7 @@ void ScreenCapBufferConsumerListener::OnBufferAvailable() void ScreenCapBufferConsumerListener::OnBufferAvailableAction() { - MediaTrace trace("ScreenCapConsumer::OnBufferAvailableAction"); + MediaTrace trace("ScreenCapConsumer::OnBufferAvailableAction", HITRACE_LEVEL_DEBUG); MEDIA_LOGD("OnBufferAvailableAction: 0x%{public}06" PRIXPTR " start.", FAKE_POINTER(this)); CHECK_AND_RETURN(consumer_ != nullptr); int64_t timestamp = 0; @@ -4167,7 +4132,7 @@ void ScreenCapBufferConsumerListener::ProcessVideoBufferCallBack() int32_t ScreenCapBufferConsumerListener::AcquireVideoBuffer(sptr &surfaceBuffer, int32_t &fence, int64_t ×tamp, OHOS::Rect &damage) { - MediaTrace trace("ScreenCaptureServer::AcquireVideoBuffer"); + MediaTrace trace("ScreenCaptureServer::AcquireVideoBuffer", HITRACE_LEVEL_DEBUG); using namespace std::chrono_literals; std::unique_lock lock(bufferMutex_); MEDIA_LOGD("ScreenCaptureServer: 0x%{public}06" PRIXPTR " AcquireVideoBuffer start, fence:%{public}d, " @@ -4222,7 +4187,7 @@ int32_t ScreenCapBufferConsumerListener::ReleaseBuffer() int32_t ScreenCapBufferConsumerListener::ReleaseVideoBuffer() { - MediaTrace trace("ScreenCaptureServer::ReleaseVideoBuffer"); + MediaTrace trace("ScreenCaptureServer::ReleaseVideoBuffer", HITRACE_LEVEL_DEBUG); std::unique_lock lock(bufferMutex_); MEDIA_LOGD("ScreenCapBufferConsumerListener: 0x%{public}06" PRIXPTR " ReleaseVideoBuffer start.", FAKE_POINTER(this)); @@ -4402,6 +4367,11 @@ bool AudioDataSource::GetIsInVoIPCall() return isInVoIPCall_.load(); } +bool AudioDataSource::IsInWaitMicSyncState() +{ + return isInWaitMicSyncState_; +} + bool AudioDataSource::GetSpeakerAliveStatus() { return speakerAliveStatus_; @@ -4433,40 +4403,393 @@ int32_t AudioDataSource::UnregisterAudioRendererEventListener(const int32_t clie return AudioStreamManager::GetInstance()->UnregisterAudioRendererEventListener(clientPid); } -int32_t AudioDataSource::ReadAt(std::shared_ptr buffer, uint32_t length) +void AudioDataSource::SetVideoFirstFramePts(int64_t firstFramePts) +{ + firstVideoFramePts_.store(firstFramePts); + struct timespec timestamp = {0, 0}; + clock_gettime(CLOCK_MONOTONIC, ×tamp); + int64_t curTime = timestamp.tv_sec * SEC_TO_NS + timestamp.tv_nsec; + MEDIA_LOGI("SetVideoFirstFramePts video to ScreenCapture timeWindow: %{public}" PRId64 + " firstVideoFramePts: %{public}" PRId64, curTime - firstFramePts, firstFramePts); +} + +void AudioDataSource::SetAudioFirstFramePts(int64_t firstFramePts) +{ + if (firstAudioFramePts_.load() == -1) { + firstAudioFramePts_.store(firstFramePts); + MEDIA_LOGI("firstAudioFramePts_: %{public}" PRId64, firstFramePts); + } +} + +AudioDataSourceReadAtActionState AudioDataSource::WriteInnerAudio(std::shared_ptr &buffer, + uint32_t length, std::shared_ptr &innerAudioBuffer) +{ + std::shared_ptr &bufferMem = buffer->memory_; + if (buffer->memory_ == nullptr || innerAudioBuffer == nullptr) { + MEDIA_LOGE("buffer->memory_ or innerAudioBuffer nullptr"); + return AudioDataSourceReadAtActionState::RETRY_SKIP; + } + std::shared_ptr tmp = nullptr; + SetAudioFirstFramePts(innerAudioBuffer->timestamp); // update firstAudioFramePts in case re-sync + return MixModeBufferWrite(innerAudioBuffer, tmp, bufferMem); +} + +AudioDataSourceReadAtActionState AudioDataSource::WriteMicAudio(std::shared_ptr &buffer, uint32_t length, + std::shared_ptr &micAudioBuffer) +{ + std::shared_ptr &bufferMem = buffer->memory_; + if (buffer->memory_ == nullptr || micAudioBuffer == nullptr) { + MEDIA_LOGE("buffer->memory_ or innerAudioBuffer nullptr"); + return AudioDataSourceReadAtActionState::RETRY_SKIP; + } + std::shared_ptr tmp = nullptr; + SetAudioFirstFramePts(micAudioBuffer->timestamp); + return MixModeBufferWrite(tmp, micAudioBuffer, bufferMem); +} + +AudioDataSourceReadAtActionState AudioDataSource::WriteMixAudio(std::shared_ptr &buffer, uint32_t length, + std::shared_ptr &innerAudioBuffer, std::shared_ptr &micAudioBuffer) +{ + std::shared_ptr &bufferMem = buffer->memory_; + if (buffer->memory_ == nullptr || innerAudioBuffer == nullptr || micAudioBuffer == nullptr) { + MEDIA_LOGE("buffer->memory_ or innerAudioBuffer nullptr"); + return AudioDataSourceReadAtActionState::RETRY_SKIP; + } + SetAudioFirstFramePts(std::min(micAudioBuffer->timestamp, innerAudioBuffer->timestamp)); + return MixModeBufferWrite(innerAudioBuffer, micAudioBuffer, bufferMem); +} + +AudioDataSourceReadAtActionState AudioDataSource::HandleMicBeforeInnerSync(std::shared_ptr &buffer, + uint32_t length, std::shared_ptr &innerAudioBuffer, std::shared_ptr &micAudioBuffer) +{ + if (innerAudioBuffer->timestamp - micAudioBuffer->timestamp > MAX_MIC_BEFORE_INNER_TIME_IN_NS) { + // Drop mic data Before 40ms + if (micAudioBuffer && screenCaptureServer_->GetMicAudioCapture()) { + screenCaptureServer_->GetMicAudioCapture()->DropBufferUntil(innerAudioBuffer->timestamp); + } + return AudioDataSourceReadAtActionState::RETRY_SKIP; + } + return WriteMicAudio(buffer, length, micAudioBuffer); +} + +AudioDataSourceReadAtActionState AudioDataSource::InnerMicAudioSync(std::shared_ptr &buffer, + uint32_t length, std::shared_ptr &innerAudioBuffer, std::shared_ptr &micAudioBuffer) +{ + int64_t timeWindow = micAudioBuffer->timestamp - innerAudioBuffer->timestamp; + if (timeWindow <= NEG_AUDIO_INTERVAL_IN_NS) { // mic before inner + return HandleMicBeforeInnerSync(buffer, length, innerAudioBuffer, micAudioBuffer); + } + if (timeWindow > NEG_AUDIO_INTERVAL_IN_NS && timeWindow < AUDIO_INTERVAL_IN_NS) { // Write mix + return WriteMixAudio(buffer, length, innerAudioBuffer, micAudioBuffer); + } else { // Write Inner data Before mic timeWindow >= AUDIO_INTERVAL_IN_NS + return WriteInnerAudio(buffer, length, innerAudioBuffer); + } +} + +AudioDataSourceReadAtActionState AudioDataSource::VideoAudioSyncMixMode(std::shared_ptr &buffer, + uint32_t length, int64_t timeWindow, std::shared_ptr &innerAudioBuffer, + std::shared_ptr &micAudioBuffer) +{ + if (timeWindow <= NEG_AUDIO_INTERVAL_IN_NS) { // video before audio add 0 + if (micAudioBuffer && screenCaptureServer_->GetMicAudioCapture() && mixModeAddAudioMicFrame_) { + MEDIA_LOGI("mic AddBufferFrom timeWindow: %{public}" PRId64, timeWindow); + screenCaptureServer_->GetMicAudioCapture()->AddBufferFrom(-1 * timeWindow, + length, firstVideoFramePts_.load()); + } + if (innerAudioBuffer && screenCaptureServer_->GetInnerAudioCapture() && !mixModeAddAudioMicFrame_) { + MEDIA_LOGI("inner AddBufferFrom timeWindow: %{public}" PRId64, timeWindow); + screenCaptureServer_->GetInnerAudioCapture()->AddBufferFrom(-1 * timeWindow, + length, firstVideoFramePts_.load()); + } + SetAudioFirstFramePts(firstVideoFramePts_.load()); + return AudioDataSourceReadAtActionState::SKIP_WITHOUT_LOG; + } + if (timeWindow >= AUDIO_INTERVAL_IN_NS) { // video after audio drop audio + if (micAudioBuffer && screenCaptureServer_->GetMicAudioCapture()) { + screenCaptureServer_->GetMicAudioCapture()->DropBufferUntil(firstVideoFramePts_.load()); + } + if (innerAudioBuffer && screenCaptureServer_->GetInnerAudioCapture()) { + screenCaptureServer_->GetInnerAudioCapture()->DropBufferUntil(firstVideoFramePts_.load()); + } + SetAudioFirstFramePts(firstVideoFramePts_.load()); + return AudioDataSourceReadAtActionState::SKIP_WITHOUT_LOG; + } else { // (timeWindow > NEG_AUDIO_INTERVAL_IN_NS && timeWindow < AUDIO_INTERVAL_IN_NS) + return ReadWriteAudioBufferMixCore(buffer, length, innerAudioBuffer, micAudioBuffer); + } +} + +int64_t AudioDataSource::GetFirstAudioTime(std::shared_ptr &innerAudioBuffer, + std::shared_ptr &micAudioBuffer) +{ + if (innerAudioBuffer && micAudioBuffer) { + if (innerAudioBuffer->timestamp > micAudioBuffer->timestamp) { + mixModeAddAudioMicFrame_ = true; + return micAudioBuffer->timestamp; + } + mixModeAddAudioMicFrame_ = false; + return innerAudioBuffer->timestamp; + } + if (innerAudioBuffer && !micAudioBuffer) { + mixModeAddAudioMicFrame_ = false; + return innerAudioBuffer->timestamp; + } + if (!innerAudioBuffer && micAudioBuffer) { + mixModeAddAudioMicFrame_ = true; + return micAudioBuffer->timestamp; + } + return -1; +} + +AudioDataSourceReadAtActionState AudioDataSource::ReadWriteAudioBufferMixCore(std::shared_ptr &buffer, + uint32_t length, std::shared_ptr &innerAudioBuffer, std::shared_ptr &micAudioBuffer) +{ + if (innerAudioBuffer == nullptr && micAudioBuffer) { + return WriteMicAudio(buffer, length, micAudioBuffer); + } + if (innerAudioBuffer && micAudioBuffer == nullptr) { + if (screenCaptureServer_->IsStopAcquireAudioBufferFlag() && isInWaitMicSyncState_) { + return WriteInnerAudio(buffer, length, innerAudioBuffer); + } + if (screenCaptureServer_->IsMicrophoneSwitchTurnOn()) { + int64_t currentAudioTime = 0; + screenCaptureServer_->GetInnerAudioCapture()->GetCurrentAudioTime(currentAudioTime); + if (currentAudioTime - innerAudioBuffer->timestamp < MAX_INNER_AUDIO_TIMEOUT_IN_NS) { // 2s + isInWaitMicSyncState_ = true; + return AudioDataSourceReadAtActionState::RETRY_IN_INTERVAL; + } else { + isInWaitMicSyncState_ = false; + } + } + return WriteInnerAudio(buffer, length, innerAudioBuffer); + } + if (innerAudioBuffer && micAudioBuffer) { + return InnerMicAudioSync(buffer, length, innerAudioBuffer, micAudioBuffer); + } + if (innerAudioBuffer == nullptr && micAudioBuffer == nullptr) { + return AudioDataSourceReadAtActionState::RETRY_SKIP; + } + return AudioDataSourceReadAtActionState::OK; +} + +AudioDataSourceReadAtActionState AudioDataSource::ReadWriteAudioBufferMix(std::shared_ptr &buffer, + uint32_t length, std::shared_ptr &innerAudioBuffer, std::shared_ptr &micAudioBuffer) +{ + if (screenCaptureServer_->GetMicAudioCapture() && + screenCaptureServer_->GetMicAudioCapture()->GetAudioCapturerState() == CAPTURER_RECORDING) { + if (screenCaptureServer_->GetMicAudioCapture()->AcquireAudioBuffer(micAudioBuffer) != MSERR_OK) { + MEDIA_LOGD("micAudioCapture AcquireAudioBuffer failed"); + } + } + if (screenCaptureServer_->GetInnerAudioCapture() && + screenCaptureServer_->GetInnerAudioCapture()->GetAudioCapturerState() == CAPTURER_RECORDING) { + if (screenCaptureServer_->GetInnerAudioCapture()->AcquireAudioBuffer(innerAudioBuffer) != MSERR_OK) { + MEDIA_LOGD("innerAudioCapture AcquireAudioBuffer failed"); + } + } + if (screenCaptureServer_->IsSCRecorderFileWithVideo() && firstAudioFramePts_ == -1) { // video audio sync + int64_t audioTime = GetFirstAudioTime(innerAudioBuffer, micAudioBuffer); + if (audioTime == -1) { + return AudioDataSourceReadAtActionState::RETRY_SKIP; + } + struct timespec timestamp = {0, 0}; + clock_gettime(CLOCK_MONOTONIC, ×tamp); + int64_t curTime = timestamp.tv_sec * SEC_TO_NS + timestamp.tv_nsec; + MEDIA_LOGI("ReadWriteAudioBufferMix audio to ScreenCapture timeWindow: %{public}" PRId64 + " firstAudioFramePts: %{public}" PRId64, curTime - audioTime, audioTime); + int64_t timeWindow = firstVideoFramePts_.load() - audioTime; + MEDIA_LOGI("ReadWriteAudioBufferMix video to audio timeWindow: %{public}" PRId64, timeWindow); + return VideoAudioSyncMixMode(buffer, length, timeWindow, innerAudioBuffer, micAudioBuffer); + } + return ReadWriteAudioBufferMixCore(buffer, length, innerAudioBuffer, micAudioBuffer); +} + +AudioDataSourceReadAtActionState AudioDataSource::ReadAtMixMode(std::shared_ptr buffer, uint32_t length) { - MEDIA_LOGD("AudioDataSource ReadAt start"); std::shared_ptr innerAudioBuffer = nullptr; std::shared_ptr micAudioBuffer = nullptr; - int32_t ret = MSERR_OK; + AudioDataSourceReadAtActionState ret = ReadWriteAudioBufferMix(buffer, length, innerAudioBuffer, micAudioBuffer); + MEDIA_LOGD("AudioDataSource ReadAtMixMode ret: %{public}d", static_cast(ret)); + return ret; +} + +AudioDataSourceReadAtActionState AudioDataSource::ReadAtMicMode(std::shared_ptr buffer, uint32_t length) +{ + if (screenCaptureServer_->GetMicAudioCapture() == nullptr) { + return AudioDataSourceReadAtActionState::INVALID; + } + if (screenCaptureServer_->GetMicAudioCapture()->GetAudioCapturerState() == CAPTURER_RECORDING) { + std::shared_ptr micAudioBuffer = nullptr; + if (screenCaptureServer_->GetMicAudioCapture()->AcquireAudioBuffer(micAudioBuffer) != MSERR_OK) { + MEDIA_LOGD("micAudioCapture AcquireAudioBuffer failed"); + return AudioDataSourceReadAtActionState::RETRY_SKIP; + } + MEDIA_LOGD("AcquireAudioBuffer mic success"); + std::shared_ptr &bufferMem = buffer->memory_; + if (buffer->memory_ == nullptr || micAudioBuffer == nullptr) { + MEDIA_LOGE("buffer->memory_ or micAudioBuffer nullptr"); + return AudioDataSourceReadAtActionState::RETRY_SKIP; + } + MEDIA_LOGD("ABuffer write mic cur:%{public}" PRId64 " last: %{public}" PRId64, + micAudioBuffer->timestamp, lastWriteAudioFramePts_.load()); + lastWriteAudioFramePts_.store(micAudioBuffer->timestamp); + lastWriteType_ = AVScreenCaptureMixBufferType::MIC; + bufferMem->Write(reinterpret_cast(micAudioBuffer->buffer), micAudioBuffer->length, 0); + CHECK_AND_RETURN_RET_LOG(screenCaptureServer_->ReleaseMicAudioBuffer() == MSERR_OK, + AudioDataSourceReadAtActionState::RETRY_SKIP, "micAudioCapture ReleaseAudioBuffer failed"); + micAudioBuffer = nullptr; + return AudioDataSourceReadAtActionState::OK; + } + return AudioDataSourceReadAtActionState::RETRY_SKIP; +} + +AudioDataSourceReadAtActionState AudioDataSource::VideoAudioSyncInnerMode(std::shared_ptr &buffer, + uint32_t length, int64_t timeWindow, std::shared_ptr &innerAudioBuffer) +{ + if (timeWindow <= NEG_AUDIO_INTERVAL_IN_NS) { // video before audio add 0 + if (innerAudioBuffer && screenCaptureServer_->GetInnerAudioCapture()) { + screenCaptureServer_->GetInnerAudioCapture()->AddBufferFrom(-1 * timeWindow, + length, firstVideoFramePts_.load()); + } + SetAudioFirstFramePts(firstVideoFramePts_.load()); + return AudioDataSourceReadAtActionState::SKIP_WITHOUT_LOG; + } + if (timeWindow >= AUDIO_INTERVAL_IN_NS) { // video after audio drop audio + if (screenCaptureServer_->GetInnerAudioCapture()) { + screenCaptureServer_->GetInnerAudioCapture()->DropBufferUntil(firstVideoFramePts_.load()); + } + SetAudioFirstFramePts(firstVideoFramePts_.load()); + return AudioDataSourceReadAtActionState::SKIP_WITHOUT_LOG; + } else { // (timeWindow > NEG_AUDIO_INTERVAL_IN_NS && timeWindow < AUDIO_INTERVAL_IN_NS) + std::shared_ptr &bufferMem = buffer->memory_; + if (buffer->memory_ == nullptr || innerAudioBuffer == nullptr) { + MEDIA_LOGE("buffer->memory_ or innerAudioBuffer nullptr"); + return AudioDataSourceReadAtActionState::SKIP_WITHOUT_LOG; + } + MEDIA_LOGD("ABuffer write inner cur:%{public}" PRId64 " last: %{public}" PRId64, + innerAudioBuffer->timestamp, lastWriteAudioFramePts_.load()); + lastWriteAudioFramePts_.store(innerAudioBuffer->timestamp); + bufferMem->Write(reinterpret_cast(innerAudioBuffer->buffer), innerAudioBuffer->length, 0); + SetAudioFirstFramePts(innerAudioBuffer->timestamp); + lastWriteType_ = AVScreenCaptureMixBufferType::INNER; + screenCaptureServer_->ReleaseInnerAudioBuffer(); + innerAudioBuffer = nullptr; + return AudioDataSourceReadAtActionState::OK; + } +} + +AudioDataSourceReadAtActionState AudioDataSource::ReadAtInnerMode(std::shared_ptr buffer, uint32_t length) +{ + if (screenCaptureServer_->GetInnerAudioCapture() == nullptr) { + return AudioDataSourceReadAtActionState::INVALID; + } + if (screenCaptureServer_->GetInnerAudioCapture()->GetAudioCapturerState() == CAPTURER_RECORDING) { + std::shared_ptr innerAudioBuffer = nullptr; + if (screenCaptureServer_->GetInnerAudioCapture()->AcquireAudioBuffer(innerAudioBuffer) != MSERR_OK) { + MEDIA_LOGD("innerAudioCapture AcquireAudioBuffer failed"); + return AudioDataSourceReadAtActionState::RETRY_SKIP; + } + MEDIA_LOGD("AcquireAudioBuffer inner success"); + if (screenCaptureServer_->IsSCRecorderFileWithVideo() && firstAudioFramePts_ == -1 && innerAudioBuffer) { + int64_t timeWindow = firstVideoFramePts_.load() - innerAudioBuffer->timestamp; + return VideoAudioSyncInnerMode(buffer, length, timeWindow, innerAudioBuffer); + } + std::shared_ptr &bufferMem = buffer->memory_; + if (buffer->memory_ == nullptr || innerAudioBuffer == nullptr) { + MEDIA_LOGE("buffer->memory_ or innerAudioBuffer nullptr"); + return AudioDataSourceReadAtActionState::RETRY_SKIP; + } + MEDIA_LOGD("ABuffer write inner cur:%{public}" PRId64 " last: %{public}" PRId64, + innerAudioBuffer->timestamp, lastWriteAudioFramePts_.load()); + lastWriteAudioFramePts_.store(innerAudioBuffer->timestamp); + lastWriteType_ = AVScreenCaptureMixBufferType::INNER; + bufferMem->Write(reinterpret_cast(innerAudioBuffer->buffer), innerAudioBuffer->length, 0); + CHECK_AND_RETURN_RET_LOG(screenCaptureServer_->ReleaseInnerAudioBuffer() == MSERR_OK, + AudioDataSourceReadAtActionState::RETRY_SKIP, "innerAudioCapture ReleaseAudioBuffer failed"); + innerAudioBuffer = nullptr; + return AudioDataSourceReadAtActionState::OK; + } + return AudioDataSourceReadAtActionState::RETRY_SKIP; +} + +AudioDataSourceReadAtActionState AudioDataSource::ReadAt(std::shared_ptr buffer, uint32_t length) +{ + MEDIA_LOGD("AudioDataSource ReadAt start"); if (screenCaptureServer_ == nullptr) { - return MSERR_UNKNOWN; + return AudioDataSourceReadAtActionState::RETRY_SKIP; } - ret = screenCaptureServer_->AcquireAudioBufferMix(innerAudioBuffer, micAudioBuffer, type_); - if (ret != MSERR_OK) { - return ret; + if (screenCaptureServer_->GetSCServerCaptureState() != AVScreenCaptureState::STARTED) { + return AudioDataSourceReadAtActionState::SKIP_WITHOUT_LOG; } - MEDIA_LOGD("AcquireAudioBufferMix sucess"); - std::shared_ptr &bufferMem = buffer->memory_; - if (buffer->memory_ == nullptr) { - MEDIA_LOGE("buffer->memory_ is nullptr"); - return MSERR_INVALID_VAL; + if (screenCaptureServer_->IsSCRecorderFileWithVideo() && firstVideoFramePts_.load() == -1) { // video frame not come + return AudioDataSourceReadAtActionState::SKIP_WITHOUT_LOG; } if (type_ == AVScreenCaptureMixMode::MIX_MODE) { - return MixModeBufferWrite(innerAudioBuffer, micAudioBuffer, bufferMem); - } else if (type_ == AVScreenCaptureMixMode::INNER_MODE && innerAudioBuffer != nullptr) { - bufferMem->Write(reinterpret_cast(innerAudioBuffer->buffer), innerAudioBuffer->length, 0); - return screenCaptureServer_->ReleaseAudioBufferMix(type_); - } else if (type_ == AVScreenCaptureMixMode::MIC_MODE && micAudioBuffer != nullptr) { - bufferMem->Write(reinterpret_cast(micAudioBuffer->buffer), micAudioBuffer->length, 0); - return screenCaptureServer_->ReleaseAudioBufferMix(type_); + return ReadAtMixMode(buffer, length); + } + if (type_ == AVScreenCaptureMixMode::INNER_MODE) { + return ReadAtInnerMode(buffer, length); + } + if (type_ == AVScreenCaptureMixMode::MIC_MODE) { + return ReadAtMicMode(buffer, length); + } + return AudioDataSourceReadAtActionState::RETRY_SKIP; +} + +void AudioDataSource::HandlePastMicBuffer(std::shared_ptr &micAudioBuffer) +{ + if (micAudioBuffer->timestamp < lastWriteAudioFramePts_.load() && + micAudioBuffer->timestamp < lastMicAudioFramePts_.load() + AUDIO_MIC_TOO_CLOSE_LIMIT_IN_NS && + lastWriteType_ == AVScreenCaptureMixBufferType::INNER) { // drop past mic data when switch,keep when mic stable + screenCaptureServer_->ReleaseMicAudioBuffer(); + MEDIA_LOGD("ABuffer drop mix mic error cur:%{public}" PRId64 " last: %{public}" PRId64, + micAudioBuffer->timestamp, lastWriteAudioFramePts_.load()); + micAudioBuffer = nullptr; } - return MSERR_UNKNOWN; } -int32_t AudioDataSource::MixModeBufferWrite(std::shared_ptr &innerAudioBuffer, +void AudioDataSource::HandleSwitchToSpeakerOptimise(std::shared_ptr &innerAudioBuffer, + std::shared_ptr &micAudioBuffer) +{ + if (speakerAliveStatus_ && screenCaptureServer_ && screenCaptureServer_->IsMicrophoneSwitchTurnOn() && + !isInVoIPCall_ && micAudioBuffer->buffer && + lastWriteType_ == AVScreenCaptureMixBufferType::MIX && screenCaptureServer_->GetInnerAudioCapture()) { + if (stableStopInnerSwitchCount_ > INNER_SWITCH_MIC_REQUIRE_COUNT) { // optimise inner while use speaker + MEDIA_LOGI("ABuffer stop mix inner optimise cur:%{public}" PRId64 " last: %{public}" PRId64, + innerAudioBuffer->timestamp, lastWriteAudioFramePts_.load()); + innerAudioBuffer = nullptr; + screenCaptureServer_->StopInnerAudioCapture(); + screenCaptureServer_->SetInnerAudioCapture(nullptr); + stableStopInnerSwitchCount_ = 0; + } else { + stableStopInnerSwitchCount_++; + } + } +} + +void AudioDataSource::HandleBufferTimeStamp(std::shared_ptr &innerAudioBuffer, + std::shared_ptr &micAudioBuffer) +{ + if (micAudioBuffer) { + HandlePastMicBuffer(micAudioBuffer); + } + if (innerAudioBuffer) { + if (innerAudioBuffer->timestamp < lastWriteAudioFramePts_.load() + && !GetIsInVoIPCall() && speakerAliveStatus_) { + screenCaptureServer_->ReleaseInnerAudioBuffer(); // drop past inner data while use speaker + MEDIA_LOGD("ABuffer drop mix inner error cur:%{public}" PRId64 " last: %{public}" PRId64, + innerAudioBuffer->timestamp, lastWriteAudioFramePts_.load()); + innerAudioBuffer = nullptr; + } + } + if (innerAudioBuffer && micAudioBuffer) { + HandleSwitchToSpeakerOptimise(innerAudioBuffer, micAudioBuffer); + } +} + +AudioDataSourceReadAtActionState AudioDataSource::MixModeBufferWrite(std::shared_ptr &innerAudioBuffer, std::shared_ptr &micAudioBuffer, std::shared_ptr &bufferMem) { + HandleBufferTimeStamp(innerAudioBuffer, micAudioBuffer); if (innerAudioBuffer && innerAudioBuffer->buffer && micAudioBuffer && micAudioBuffer->buffer) { char* mixData = new char[innerAudioBuffer->length]; char* srcData[2] = {nullptr}; @@ -4474,43 +4797,62 @@ int32_t AudioDataSource::MixModeBufferWrite(std::shared_ptr &innerA srcData[1] = reinterpret_cast(micAudioBuffer->buffer); int channels = 2; MixAudio(srcData, mixData, channels, innerAudioBuffer->length); + MEDIA_LOGD("ABuffer write mix mix cur:%{public}" PRId64 " mic:%{public}" PRId64 " last: %{public}" PRId64, + innerAudioBuffer->timestamp, micAudioBuffer->timestamp, lastWriteAudioFramePts_.load()); + lastWriteAudioFramePts_.store(innerAudioBuffer->timestamp); + lastMicAudioFramePts_.store(micAudioBuffer->timestamp); + lastWriteType_ = AVScreenCaptureMixBufferType::MIX; bufferMem->Write(reinterpret_cast(mixData), innerAudioBuffer->length, 0); delete[] mixData; } else if (innerAudioBuffer && innerAudioBuffer->buffer) { + MEDIA_LOGD("ABuffer write mix inner cur:%{public}" PRId64 " last: %{public}" PRId64, + innerAudioBuffer->timestamp, lastWriteAudioFramePts_.load()); + lastWriteAudioFramePts_.store(innerAudioBuffer->timestamp); + lastWriteType_ = AVScreenCaptureMixBufferType::INNER; + stableStopInnerSwitchCount_ = 0; bufferMem->Write(reinterpret_cast(innerAudioBuffer->buffer), innerAudioBuffer->length, 0); } else if (micAudioBuffer && micAudioBuffer->buffer) { + MEDIA_LOGD("ABuffer write mix mic cur:%{public}" PRId64 " last: %{public}" PRId64, + micAudioBuffer->timestamp, lastWriteAudioFramePts_.load()); + lastWriteAudioFramePts_.store(micAudioBuffer->timestamp); + lastMicAudioFramePts_.store(micAudioBuffer->timestamp); + lastWriteType_ = AVScreenCaptureMixBufferType::MIC; + stableStopInnerSwitchCount_ = 0; bufferMem->Write(reinterpret_cast(micAudioBuffer->buffer), micAudioBuffer->length, 0); } else { MEDIA_LOGE("without buffer write"); - return MSERR_UNKNOWN; + return AudioDataSourceReadAtActionState::RETRY_SKIP; } if (innerAudioBuffer) { - if (screenCaptureServer_->ReleaseInnerAudioBuffer() != MSERR_OK) { - MEDIA_LOGE("ReleaseInnerAudioBuffer failed"); - } + screenCaptureServer_->ReleaseInnerAudioBuffer(); + innerAudioBuffer = nullptr; } if (micAudioBuffer) { - if (screenCaptureServer_->ReleaseMicAudioBuffer() != MSERR_OK) { - MEDIA_LOGE("ReleaseMicAudioBuffer failed"); - } + screenCaptureServer_->ReleaseMicAudioBuffer(); + micAudioBuffer = nullptr; } - return MSERR_OK; + return AudioDataSourceReadAtActionState::OK; } int32_t AudioDataSource::GetSize(int64_t &size) { size_t bufferLen = 0; - int32_t ret = screenCaptureServer_->GetInnerAudioCaptureBufferSize(bufferLen); - MEDIA_LOGD("AudioDataSource::GetSize : %{public}zu", bufferLen); - if (ret == MSERR_OK) { - size = static_cast(bufferLen); - return ret; + int32_t ret = MSERR_UNKNOWN; + if (screenCaptureServer_->GetInnerAudioCapture()) { + ret = screenCaptureServer_->GetInnerAudioCaptureBufferSize(bufferLen); + MEDIA_LOGD("AudioDataSource::GetSize : %{public}zu", bufferLen); + if (ret == MSERR_OK) { + size = static_cast(bufferLen); + return ret; + } } - ret = screenCaptureServer_->GetMicAudioCaptureBufferSize(bufferLen); - MEDIA_LOGD("AudioDataSource::GetSize : %{public}zu", bufferLen); - if (ret == MSERR_OK) { - size = static_cast(bufferLen); - return ret; + if (screenCaptureServer_->GetMicAudioCapture()) { + ret = screenCaptureServer_->GetMicAudioCaptureBufferSize(bufferLen); + MEDIA_LOGD("AudioDataSource::GetSize : %{public}zu", bufferLen); + if (ret == MSERR_OK) { + size = static_cast(bufferLen); + return ret; + } } return ret; } diff --git a/services/services/screen_capture/server/screen_capture_server.h b/services/services/screen_capture/server/screen_capture_server.h index a9972c945fed4a243eb9d6d54ac52e37cc899f19..387bd2b98c204e625ec5b3d2d85b6c6dc5650056 100644 --- a/services/services/screen_capture/server/screen_capture_server.h +++ b/services/services/screen_capture/server/screen_capture_server.h @@ -109,10 +109,6 @@ public: int32_t TelCallAudioStateUpdated(bool isInTelCallAudio); #endif void UpdateMicrophoneEnabled(); - - int32_t AcquireAudioBufferMix(std::shared_ptr &innerAudioBuffer, - std::shared_ptr &micAudioBuffer, AVScreenCaptureMixMode type); - int32_t ReleaseAudioBufferMix(AVScreenCaptureMixMode type); int32_t ReleaseMicAudioBuffer(); int32_t ReleaseInnerAudioBuffer(); int32_t GetInnerAudioCaptureBufferSize(size_t &size); @@ -134,6 +130,13 @@ public: int32_t GetSCServerSaUid(); DataType GetSCServerDataType(); AVScreenCaptureState GetSCServerCaptureState(); + bool IsSCRecorderFileWithVideo(); + std::shared_ptr GetInnerAudioCapture(); + std::shared_ptr GetMicAudioCapture(); + bool IsStopAcquireAudioBufferFlag(); + bool IsMicrophoneSwitchTurnOn(); + void SetInnerAudioCapture(std::shared_ptr innerAudioCapture); + int32_t StopInnerAudioCapture(); void SetWindowIdList(uint64_t windowId); std::vector GetWindowIdList(); void OnSceneSessionManagerDied(const wptr& remote); @@ -141,7 +144,6 @@ public: uint64_t GetDefaultDisplayId(); void SetCurDisplayId(uint64_t displayId); uint64_t GetCurDisplayId(); - private: int32_t StartScreenCaptureInner(bool isPrivacyAuthorityEnabled); int32_t RegisterServerCallbacks(); @@ -151,6 +153,8 @@ private: void PostStartScreenCapture(bool isSuccess); void PostStartScreenCaptureSuccessAction(); int32_t InitRecorderInfo(std::shared_ptr &recorder, AudioCaptureInfo audioInfo); + int32_t InitRecorderMix(); + int32_t InitRecorderInner(); int32_t InitRecorder(); int32_t StartScreenCaptureFile(); int32_t StartScreenCaptureStream(); @@ -159,7 +163,6 @@ private: int32_t StartStreamInnerAudioCapture(); int32_t StartStreamMicAudioCapture(); int32_t StartFileInnerAudioCapture(); - int32_t StopInnerAudioCapture(); int32_t StartFileMicAudioCapture(); int32_t StartMicAudioCapture(); int32_t StopMicAudioCapture(); @@ -265,6 +268,8 @@ private: bool checkBoxSelected_ = false; std::vector surfaceIdList_ = {}; std::vector surfaceTypeList_ = {}; + bool stopAcquireAudioBufferFromAudio_ = false; + AVScreenCaptureMixMode recorderFileAudioType_ = AVScreenCaptureMixMode::INVALID_MODE; int32_t sessionId_ = 0; int32_t notificationId_ = 0; @@ -332,7 +337,7 @@ private: std::atomic isInTelCall_ = false; std::atomic isInTelCallAudio_ = false; #endif - + std::atomic recorderFileWithVideo_{false}; private: static int32_t CheckAudioCapParam(const AudioCaptureInfo &audioCapInfo); static int32_t CheckVideoCapParam(const VideoCaptureInfo &videoCapInfo); @@ -359,6 +364,9 @@ private: static constexpr int32_t AV_SCREEN_CAPTURE_SESSION_UID = 1013; static constexpr const char* NOTIFICATION_SCREEN_RECORDING_TITLE_ID = "notification_screen_recording_title"; static constexpr const char* QUOTATION_MARKS_STRING = "\""; + static constexpr int64_t MAX_INNER_AUDIO_TIMEOUT_IN_NS = 2000000000; // 2s + static constexpr int64_t AUDIO_INTERVAL_IN_NS = 20000000; // 20ms + static constexpr int64_t NEG_AUDIO_INTERVAL_IN_NS = -20000000; // 20ms }; } // namespace Media } // namespace OHOS diff --git a/services/services/screen_capture/server/screen_capture_server_base.h b/services/services/screen_capture/server/screen_capture_server_base.h index 7a0bf32866f51f6ef741c3da1d067bca9e5bb03b..81f5667221aa4fa4e9d36b6a594215146ed46638 100644 --- a/services/services/screen_capture/server/screen_capture_server_base.h +++ b/services/services/screen_capture/server/screen_capture_server_base.h @@ -101,7 +101,14 @@ enum AVScreenCaptureMixMode : int32_t { MIX_MODE = 0, MIC_MODE = 1, INNER_MODE = 2, - INVAILD_MODE = 3 + INVALID_MODE = 3 +}; + +enum class AVScreenCaptureMixBufferType : int32_t { + MIX = 0, + MIC = 1, + INNER = 2, + INVALID = 3 }; enum AVScreenCaptureAvType : int8_t { @@ -225,7 +232,31 @@ public: AudioDataSource(AVScreenCaptureMixMode type, ScreenCaptureServer* screenCaptureServer) : type_(type), screenCaptureServer_(screenCaptureServer) {} - int32_t ReadAt(std::shared_ptr buffer, uint32_t length) override; + int64_t GetFirstAudioTime(std::shared_ptr &innerAudioBuffer, + std::shared_ptr &micAudioBuffer); + AudioDataSourceReadAtActionState WriteInnerAudio(std::shared_ptr &buffer, uint32_t length, + std::shared_ptr &innerAudioBuffer); + AudioDataSourceReadAtActionState WriteMicAudio(std::shared_ptr &buffer, uint32_t length, + std::shared_ptr &micAudioBuffer); + AudioDataSourceReadAtActionState WriteMixAudio(std::shared_ptr &buffer, uint32_t length, + std::shared_ptr &innerAudioBuffer, std::shared_ptr &micAudioBuffer); + AudioDataSourceReadAtActionState ReadWriteAudioBufferMix(std::shared_ptr &buffer, uint32_t length, + std::shared_ptr &innerAudioBuffer, std::shared_ptr &micAudioBuffer); + AudioDataSourceReadAtActionState ReadWriteAudioBufferMixCore(std::shared_ptr &buffer, uint32_t length, + std::shared_ptr &innerAudioBuffer, std::shared_ptr &micAudioBuffer); + AudioDataSourceReadAtActionState HandleMicBeforeInnerSync(std::shared_ptr &buffer, uint32_t length, + std::shared_ptr &innerAudioBuffer, std::shared_ptr &micAudioBuffer); + AudioDataSourceReadAtActionState InnerMicAudioSync(std::shared_ptr &buffer, uint32_t length, + std::shared_ptr &innerAudioBuffer, std::shared_ptr &micAudioBuffer); + AudioDataSourceReadAtActionState VideoAudioSyncMixMode(std::shared_ptr &buffer, uint32_t length, + int64_t timeWindow, std::shared_ptr &innerAudioBuffer, + std::shared_ptr &micAudioBuffer); + AudioDataSourceReadAtActionState ReadAtMixMode(std::shared_ptr buffer, uint32_t length); + AudioDataSourceReadAtActionState ReadAtMicMode(std::shared_ptr buffer, uint32_t length); + AudioDataSourceReadAtActionState ReadAtInnerMode(std::shared_ptr buffer, uint32_t length); + AudioDataSourceReadAtActionState ReadAt(std::shared_ptr buffer, uint32_t length) override; + AudioDataSourceReadAtActionState VideoAudioSyncInnerMode(std::shared_ptr &buffer, + uint32_t length, int64_t timeWindow, std::shared_ptr &innerAudioBuffer); int32_t GetSize(int64_t &size) override; int32_t RegisterAudioRendererEventListener(const int32_t clientPid, const std::shared_ptr &callback); @@ -243,26 +274,47 @@ public: int32_t GetAppPid(); bool GetIsInVoIPCall(); bool GetSpeakerAliveStatus(); + bool IsInWaitMicSyncState(); #ifdef SUPPORT_CALL void TelCallAudioStateUpdate( const std::vector> &audioRendererChangeInfos); #endif - -private: - int32_t MixModeBufferWrite(std::shared_ptr &innerAudioBuffer, + void SetVideoFirstFramePts(int64_t firstFramePts) override; + void SetAudioFirstFramePts(int64_t firstFramePts); + AudioDataSourceReadAtActionState MixModeBufferWrite(std::shared_ptr &innerAudioBuffer, std::shared_ptr &micAudioBuffer, std::shared_ptr &bufferMem); + void HandlePastMicBuffer(std::shared_ptr &micAudioBuffer); + void HandleSwitchToSpeakerOptimise(std::shared_ptr &innerAudioBuffer, + std::shared_ptr &micAudioBuffer); + void HandleBufferTimeStamp(std::shared_ptr &innerAudioBuffer, + std::shared_ptr &micAudioBuffer); +private: + void MixAudio(char** srcData, char* mixData, int channels, int bufferSize); + int32_t appPid_ { 0 }; std::string appName_; bool speakerAliveStatus_ = true; std::atomic isInVoIPCall_ = false; std::mutex voipStatusChangeMutex_; - - void MixAudio(char** srcData, char* mixData, int channels, int bufferSize); - + std::atomic firstAudioFramePts_{-1}; + std::atomic firstVideoFramePts_{-1}; + std::atomic lastWriteAudioFramePts_{0}; + std::atomic lastMicAudioFramePts_{0}; + AVScreenCaptureMixBufferType lastWriteType_ = AVScreenCaptureMixBufferType::INVALID; + int32_t stableStopInnerSwitchCount_ = 0; + bool mixModeAddAudioMicFrame_ = false; + bool isInWaitMicSyncState_ = false; AVScreenCaptureMixMode type_; ScreenCaptureServer* screenCaptureServer_; + static constexpr int32_t INNER_SWITCH_MIC_REQUIRE_COUNT = 10; static constexpr int32_t ADS_LOG_SKIP_NUM = 1000; + static constexpr int64_t MAX_INNER_AUDIO_TIMEOUT_IN_NS = 2000000000; // 2s + static constexpr int64_t AUDIO_MIC_TOO_CLOSE_LIMIT_IN_NS = 10000000; // 10ms + static constexpr int64_t AUDIO_INTERVAL_IN_NS = 21333334; // 20ms + static constexpr int64_t NEG_AUDIO_INTERVAL_IN_NS = -21333334; // 20ms + static constexpr int64_t SEC_TO_NS = 1000000000; // 1s + static constexpr int64_t MAX_MIC_BEFORE_INNER_TIME_IN_NS = 40000000; // 40ms }; class PrivateWindowListenerInScreenCapture : public DisplayManager::IPrivateWindowListener { diff --git a/services/services/transcoder/client/transcoder_client.cpp b/services/services/transcoder/client/transcoder_client.cpp index 3fb8a1aa84159f313e321e90464926a3a6157584..09380c68826137ee85a0fc91c001efc4b6d34757 100644 --- a/services/services/transcoder/client/transcoder_client.cpp +++ b/services/services/transcoder/client/transcoder_client.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Huawei Device Co., Ltd. + * Copyright (C) 2024-2025 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 @@ -108,6 +108,15 @@ int32_t TransCoderClient::SetVideoEncodingBitRate(int32_t rate) return transCoderProxy_->SetVideoEncodingBitRate(rate); } +int32_t TransCoderClient::SetColorSpace(TranscoderColorSpace colorSpaceFormat) +{ + std::lock_guard lock(mutex_); + CHECK_AND_RETURN_RET_LOG(transCoderProxy_ != nullptr, MSERR_NO_MEMORY, "transcoder service does not exist."); + + MEDIA_LOGD("SetColorSpace, format(%{public}d)", static_cast(colorSpaceFormat)); + return transCoderProxy_->SetColorSpace(colorSpaceFormat); +} + int32_t TransCoderClient::SetAudioEncoder(AudioCodecFormat encoder) { std::lock_guard lock(mutex_); diff --git a/services/services/transcoder/client/transcoder_client.h b/services/services/transcoder/client/transcoder_client.h index f069184bfccea976992a5eeb3fb279066103086a..580bc022de96c7dca59ed57f48cb0098236e0cd9 100644 --- a/services/services/transcoder/client/transcoder_client.h +++ b/services/services/transcoder/client/transcoder_client.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Huawei Device Co., Ltd. + * Copyright (C) 2024-2025 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 @@ -33,6 +33,7 @@ public: int32_t SetVideoEncoder(VideoCodecFormat encoder) override; int32_t SetVideoSize(int32_t width, int32_t height) override; int32_t SetVideoEncodingBitRate(int32_t rate) override; + int32_t SetColorSpace(TranscoderColorSpace colorSpaceFormat) override; int32_t SetAudioEncoder(AudioCodecFormat encoder) override; int32_t SetAudioEncodingBitRate(int32_t bitRate) override; int32_t SetOutputFormat(OutputFormatType format) override; diff --git a/services/services/transcoder/ipc/i_standard_transcoder_service.h b/services/services/transcoder/ipc/i_standard_transcoder_service.h index 0fcae632dd4464307b75341b25fefd8a6ca6c8a6..77442a8a13feeda5142f5ef72bb2b264fe73e51c 100644 --- a/services/services/transcoder/ipc/i_standard_transcoder_service.h +++ b/services/services/transcoder/ipc/i_standard_transcoder_service.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Huawei Device Co., Ltd. + * Copyright (C) 2024-2025 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 @@ -31,6 +31,7 @@ public: virtual int32_t SetVideoEncoder(VideoCodecFormat encoder) = 0; virtual int32_t SetVideoSize(int32_t width, int32_t height) = 0; virtual int32_t SetVideoEncodingBitRate(int32_t rate) = 0; + virtual int32_t SetColorSpace(TranscoderColorSpace colorSpaceFormat) = 0; virtual int32_t SetAudioEncoder(AudioCodecFormat encoder) = 0; virtual int32_t SetAudioEncodingBitRate(int32_t bitRate) = 0; virtual int32_t SetOutputFormat(OutputFormatType format) = 0; @@ -52,6 +53,7 @@ public: SET_VIDEO_ENCODER, SET_VIDEO_SIZE, SET_VIDEO_ENCODING_BIT_RATE, + SET_COLOR_SPACE, SET_AUDIO_ENCODER, SET_AUDIO_ENCODING_BIT_RATE, SET_OUTPUT_FORMAT, diff --git a/services/services/transcoder/ipc/transcoder_service_proxy.cpp b/services/services/transcoder/ipc/transcoder_service_proxy.cpp index 0f70a8e2c3981642383f1fc2807f6de9641c63e4..2adde58153689e21cb2d0cb583659c04e5fcfde2 100644 --- a/services/services/transcoder/ipc/transcoder_service_proxy.cpp +++ b/services/services/transcoder/ipc/transcoder_service_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Huawei Device Co., Ltd. + * Copyright (C) 2024-2025 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 @@ -104,6 +104,23 @@ int32_t TransCoderServiceProxy::SetVideoEncodingBitRate(int32_t rate) return reply.ReadInt32(); } +int32_t TransCoderServiceProxy::SetColorSpace(TranscoderColorSpace colorSpaceFormat) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + bool token = data.WriteInterfaceToken(TransCoderServiceProxy::GetDescriptor()); + CHECK_AND_RETURN_RET_LOG(token, MSERR_INVALID_OPERATION, "Failed to write descriptor!"); + + data.WriteInt32(static_cast(colorSpaceFormat)); + int error = Remote()->SendRequest(SET_COLOR_SPACE, data, reply, option); + CHECK_AND_RETURN_RET_LOG(error == MSERR_OK, MSERR_INVALID_OPERATION, + "SetColorSpace failed, error: %{public}d", error); + + return reply.ReadInt32(); +} + int32_t TransCoderServiceProxy::SetAudioEncoder(AudioCodecFormat encoder) { MessageParcel data; diff --git a/services/services/transcoder/ipc/transcoder_service_proxy.h b/services/services/transcoder/ipc/transcoder_service_proxy.h index 17ed414d0dd2fd0e34c520a513b52fb0d1b5f498..8f623328cdb4398d3202830ec3ed3c93451dc414 100644 --- a/services/services/transcoder/ipc/transcoder_service_proxy.h +++ b/services/services/transcoder/ipc/transcoder_service_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Huawei Device Co., Ltd. + * Copyright (C) 2024-2025 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 @@ -30,6 +30,7 @@ public: int32_t SetVideoEncoder(VideoCodecFormat encoder) override; int32_t SetVideoSize(int32_t width, int32_t height) override; int32_t SetVideoEncodingBitRate(int32_t rate) override; + int32_t SetColorSpace(TranscoderColorSpace colorSpaceFormat) override; int32_t SetAudioEncoder(AudioCodecFormat encoder) override; int32_t SetAudioEncodingBitRate(int32_t bitRate) override; int32_t SetOutputFormat(OutputFormatType format) override; diff --git a/services/services/transcoder/ipc/transcoder_service_stub.cpp b/services/services/transcoder/ipc/transcoder_service_stub.cpp index c43963019a60919d54a83dc0b58801f33601fc32..f2045183f6698b0b5f9d733c64af9828de9907dd 100644 --- a/services/services/transcoder/ipc/transcoder_service_stub.cpp +++ b/services/services/transcoder/ipc/transcoder_service_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Huawei Device Co., Ltd. + * Copyright (C) 2024-2025 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 @@ -66,6 +66,7 @@ int32_t TransCoderServiceStub::Init() recFuncs_[SET_VIDEO_ENCODING_BIT_RATE] = &TransCoderServiceStub::SetVideoEncodingBitRate; recFuncs_[SET_AUDIO_ENCODER] = &TransCoderServiceStub::SetAudioEncoder; recFuncs_[SET_AUDIO_ENCODING_BIT_RATE] = &TransCoderServiceStub::SetAudioEncodingBitRate; + recFuncs_[SET_COLOR_SPACE] = &TransCoderServiceStub::SetColorSpace; recFuncs_[SET_OUTPUT_FORMAT] = &TransCoderServiceStub::SetOutputFormat; recFuncs_[SET_INPUT_FILE_FD] = &TransCoderServiceStub::SetInputFileFd; recFuncs_[SET_OUTPUT_FILE] = &TransCoderServiceStub::SetOutputFile; @@ -156,6 +157,12 @@ int32_t TransCoderServiceStub::SetVideoEncodingBitRate(int32_t rate) return transCoderServer_->SetVideoEncodingBitRate(rate); } +int32_t TransCoderServiceStub::SetColorSpace(TranscoderColorSpace colorSpaceFormat) +{ + CHECK_AND_RETURN_RET_LOG(transCoderServer_ != nullptr, MSERR_NO_MEMORY, "transcoder server is nullptr"); + return transCoderServer_->SetColorSpace(colorSpaceFormat); +} + int32_t TransCoderServiceStub::SetAudioEncoder(AudioCodecFormat encoder) { CHECK_AND_RETURN_RET_LOG(transCoderServer_ != nullptr, MSERR_NO_MEMORY, "transcoder server is nullptr"); @@ -266,6 +273,14 @@ int32_t TransCoderServiceStub::SetVideoEncodingBitRate(MessageParcel &data, Mess return MSERR_OK; } +int32_t TransCoderServiceStub::SetColorSpace(MessageParcel &data, MessageParcel &reply) +{ + int32_t format = data.ReadInt32(); + TranscoderColorSpace colorSpaceFormat = static_cast(format); + reply.WriteInt32(SetColorSpace(colorSpaceFormat)); + return MSERR_OK; +} + int32_t TransCoderServiceStub::SetAudioEncoder(MessageParcel &data, MessageParcel &reply) { int32_t format = data.ReadInt32(); diff --git a/services/services/transcoder/ipc/transcoder_service_stub.h b/services/services/transcoder/ipc/transcoder_service_stub.h index 5d1490cb2b0be1ed274005bd1861d7d9f45e7bc1..c5de31c2f98fda462799b1c51f81d86d28a987cb 100644 --- a/services/services/transcoder/ipc/transcoder_service_stub.h +++ b/services/services/transcoder/ipc/transcoder_service_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Huawei Device Co., Ltd. + * Copyright (C) 2024-2025 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 @@ -39,6 +39,7 @@ public: int32_t SetVideoEncoder(VideoCodecFormat encoder) override; int32_t SetVideoSize(int32_t width, int32_t height) override; int32_t SetVideoEncodingBitRate(int32_t rate) override; + int32_t SetColorSpace(TranscoderColorSpace colorSpaceFormat) override; int32_t SetAudioEncoder(AudioCodecFormat encoder) override; int32_t SetAudioEncodingBitRate(int32_t bitRate) override; int32_t SetOutputFormat(OutputFormatType format) override; @@ -64,6 +65,7 @@ private: int32_t SetVideoEncoder(MessageParcel &data, MessageParcel &reply); int32_t SetVideoSize(MessageParcel &data, MessageParcel &reply); int32_t SetVideoEncodingBitRate(MessageParcel &data, MessageParcel &reply); + int32_t SetColorSpace(MessageParcel &data, MessageParcel &reply); int32_t SetAudioEncoder(MessageParcel &data, MessageParcel &reply); int32_t SetAudioEncodingBitRate(MessageParcel &data, MessageParcel &reply); int32_t SetOutputFormat(MessageParcel &data, MessageParcel &reply); diff --git a/services/services/transcoder/server/transcoder_server.cpp b/services/services/transcoder/server/transcoder_server.cpp index 61f2d275dee8a863f8df9e3e4da67bd4022ca75b..22b96db952bf41719c413d2163b506a16e2a7c1e 100644 --- a/services/services/transcoder/server/transcoder_server.cpp +++ b/services/services/transcoder/server/transcoder_server.cpp @@ -175,6 +175,25 @@ int32_t TransCoderServer::SetVideoEncodingBitRate(int32_t rate) return result.Value(); } +int32_t TransCoderServer::SetColorSpace(TranscoderColorSpace colorSpaceFormat) +{ + std::lock_guard lock(mutex_); + CHECK_AND_RETURN_RET_LOG(status_ == REC_CONFIGURED, MSERR_INVALID_OPERATION, + "invalid status, current status is %{public}s", GetStatusDescription(status_).c_str()); + CHECK_AND_RETURN_RET_LOG(transCoderEngine_ != nullptr, MSERR_NO_MEMORY, "engine is nullptr"); + config_.colorSpaceFormat = colorSpaceFormat; + VideoColorSpace colorSpaceFmt(colorSpaceFormat); + MEDIA_LOGD("set color space, format: %{public}d", static_cast(colorSpaceFormat)); + auto task = std::make_shared>([&, this] { + return transCoderEngine_->Configure(colorSpaceFmt); + }); + int32_t ret = taskQue_.EnqueueTask(task); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "EnqueueTask failed"); + + auto result = task->GetResult(); + return result.Value(); +} + int32_t TransCoderServer::SetAudioEncoder(AudioCodecFormat encoder) { std::lock_guard lock(mutex_); diff --git a/services/services/transcoder/server/transcoder_server.h b/services/services/transcoder/server/transcoder_server.h index 4aef22a97a676ec9fde16eb756579d5b1480294a..cab5db7a29eaba70c5bf8b9a603e905fa2c2fce1 100644 --- a/services/services/transcoder/server/transcoder_server.h +++ b/services/services/transcoder/server/transcoder_server.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Huawei Device Co., Ltd. + * Copyright (C) 2024-2025 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 @@ -50,6 +50,7 @@ public: int32_t SetVideoEncoder(VideoCodecFormat encoder) override; int32_t SetVideoSize(int32_t width, int32_t height) override; int32_t SetVideoEncodingBitRate(int32_t rate) override; + int32_t SetColorSpace(TranscoderColorSpace colorSpaceFormat) override; int32_t SetAudioEncoder(AudioCodecFormat encoder) override; int32_t SetAudioEncodingBitRate(int32_t bitRate) override; int32_t SetOutputFormat(OutputFormatType format) override; @@ -83,6 +84,7 @@ private: struct ConfigInfo { VideoCodecFormat videoCodec = VIDEO_CODEC_FORMAT_BUTT; AudioCodecFormat audioCodec = AUDIO_CODEC_FORMAT_BUTT; + TranscoderColorSpace colorSpaceFormat = TRANSCODER_COLORSPACE_NONE; int32_t width = -1; int32_t height = -1; int32_t videoBitRate = -1; diff --git a/services/utils/include/fd_utils.h b/services/utils/include/fd_utils.h index f010135d078500e4e2af370860631418da4ebe1e..58b1353ad284b641dc1a6b68a8ff95ea846879c8 100644 --- a/services/utils/include/fd_utils.h +++ b/services/utils/include/fd_utils.h @@ -19,19 +19,29 @@ #include #include #include "common/fdsan_fd.h" - +#ifdef __linux__ +#include +#endif + namespace OHOS { namespace Media { +#ifdef __linux__ +namespace { +constexpr size_t MAX_ATTR_NAME = 64; +const std::string CLOUD_LOCATION_ATTR = "user.cloud.location"; +static const std::string LOCAL = "1"; +} +#endif + class FdUtils { public: // This method is prohibited from being used on the server side. static FdsanFd ReOpenFd(int32_t fd) { #ifdef __linux__ - int loc; - int ioResult = ioctl(fd, HMDFS_IOC_GET_LOCATION, &loc); - if (ioResult == 0 && loc != IOCTL_CLOUD) { + if (fd > 0 && LocalFd(fd)) { + MEDIA_LOGI("ReOpenFd In"); std::stringstream ss; ss << "/proc/self/fd/" << fd; std::string fdPathStr = ss.str(); @@ -49,10 +59,27 @@ public: return FdsanFd(newFd); } #endif + MEDIA_LOGW("=== fd is cloud"); return FdsanFd(); } private: +#if __linux__ + static bool LocalFd(int32_t fd) + { + char value[MAX_ATTR_NAME + 1] = {0}; + ssize_t size = fgetxattr(fd, CLOUD_LOCATION_ATTR.c_str(), value, MAX_ATTR_NAME); + if (size <= 0 || static_cast(size) > MAX_ATTR_NAME) { + MEDIA_LOGW("Getxattr value failed, errno is %{public}s", std::strerror(errno)); + return false; + } + std::string location(value, static_cast(size)); + MEDIA_LOGD("Getxattr value, location is %{public}s", location.c_str()); + + return location == LOCAL; + } +#endif + // The HMDFS I/O control code static constexpr unsigned int HMDFS_IOC = 0xf2; // The I/O control code for retrieving the HMDFS location @@ -63,6 +90,6 @@ private: static constexpr ssize_t RESULT_ERROR = -1; static constexpr int PATH_MAX_REAL = PATH_MAX + 1; }; -} // namespace media +} // namespace Media } // namespace OHOS #endif // FD_UTILS_H \ No newline at end of file diff --git a/services/utils/include/media_dfx.h b/services/utils/include/media_dfx.h index 75eecdcff9d706e21b345565b92e95ef6d032190..d84988bb07c57df2b3710d6b7d68300d20fab82a 100644 --- a/services/utils/include/media_dfx.h +++ b/services/utils/include/media_dfx.h @@ -24,6 +24,7 @@ #include #include "nocopyable.h" #include "hisysevent.h" +#include "hitrace_meter.h" #include "meta/meta.h" #ifndef CROSS_PLATFORM #include "nlohmann/json.hpp" @@ -97,13 +98,15 @@ __attribute__((visibility("default"))) uint64_t GetMediaInfoContainInstanceNum() class __attribute__((visibility("default"))) MediaTrace : public NoCopyable { public: - explicit MediaTrace(const std::string &funcName); - static void TraceBegin(const std::string &funcName, int32_t taskId); - static void TraceEnd(const std::string &funcName, int32_t taskId); - static void CounterTrace(const std::string &varName, int32_t val); + explicit MediaTrace(const std::string &funcName, HiTraceOutputLevel level = HITRACE_LEVEL_INFO, + const std::string &customArgs = ""); + static void TraceBegin(const std::string &funcName, int32_t taskId, HiTraceOutputLevel level = HITRACE_LEVEL_INFO, + const std::string &customCategory = "", const std::string &customArgs = ""); + static void TraceEnd(const std::string &funcName, int32_t taskId, HiTraceOutputLevel level = HITRACE_LEVEL_INFO); + static void CounterTrace(const std::string &varName, int32_t val, HiTraceOutputLevel level = HITRACE_LEVEL_INFO); ~MediaTrace(); private: - bool isSync_ = false; + HiTraceOutputLevel level_ = HITRACE_LEVEL_INFO; }; } // namespace Media } // namespace OHOS diff --git a/services/utils/media_dfx.cpp b/services/utils/media_dfx.cpp index eebb9efdd84186b6f624866ab5ea4af954ce14da..59c51e2149ea9fc0de12c2b0d94b0e97203fec43 100644 --- a/services/utils/media_dfx.cpp +++ b/services/utils/media_dfx.cpp @@ -20,7 +20,6 @@ #include #include "securec.h" -#include "hitrace_meter.h" #include "hitrace/tracechain.h" #include "ipc_skeleton.h" #include "media_utils.h" @@ -477,32 +476,31 @@ uint64_t GetMediaInfoContainInstanceNum() return mediaInsNum + reportInsNum; } -MediaTrace::MediaTrace(const std::string &funcName) +MediaTrace::MediaTrace(const std::string &funcName, HiTraceOutputLevel level, const std::string &customArgs) { - StartTrace(HITRACE_TAG_ZMEDIA, funcName); - isSync_ = true; + StartTraceEx(level, HITRACE_TAG_ZMEDIA, funcName.c_str(), customArgs.c_str()); + level_ = level; } -void MediaTrace::TraceBegin(const std::string &funcName, int32_t taskId) +void MediaTrace::TraceBegin(const std::string &funcName, int32_t taskId, HiTraceOutputLevel level, + const std::string &customCategory, const std::string &customArgs) { - StartAsyncTrace(HITRACE_TAG_ZMEDIA, funcName, taskId); + StartAsyncTraceEx(level, HITRACE_TAG_ZMEDIA, funcName.c_str(), taskId, customCategory.c_str(), customArgs.c_str()); } -void MediaTrace::TraceEnd(const std::string &funcName, int32_t taskId) +void MediaTrace::TraceEnd(const std::string &funcName, int32_t taskId, HiTraceOutputLevel level) { - FinishAsyncTrace(HITRACE_TAG_ZMEDIA, funcName, taskId); + FinishAsyncTraceEx(level, HITRACE_TAG_ZMEDIA, funcName.c_str(), taskId); } -void MediaTrace::CounterTrace(const std::string &varName, int32_t val) +void MediaTrace::CounterTrace(const std::string &varName, int32_t val, HiTraceOutputLevel level) { - CountTrace(HITRACE_TAG_ZMEDIA, varName, val); + CountTraceEx(level, HITRACE_TAG_ZMEDIA, varName.c_str(), val); } MediaTrace::~MediaTrace() { - if (isSync_) { - FinishTrace(HITRACE_TAG_ZMEDIA); - } + FinishTraceEx(level_, HITRACE_TAG_ZMEDIA); } } // namespace Media } // namespace OHOS diff --git a/test/BUILD.gn b/test/BUILD.gn index 66bc380723c47cdbb580d41b1a5250401eca4596..236c9e8adaa2e86478f0b99e350aff3f3d002170 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -35,6 +35,7 @@ group("media_unit_test") { "unittest/audio_haptic_test:audio_haptic_unit_test", "unittest/audio_haptic_test:audio_haptic_vibrator_impl_unit_test", "unittest/avmetadata_helper_test:avmetadata_helper_unit_test", + "unittest/avmetadata_helper_unittest:avmetadata_helper_unittest", "unittest/avmetadatahelper_test:avmetadatahelper_unit_test", "unittest/dfx_test:player_framework_dfx_test", "unittest/hiplayer_impl_test:hiplayer_impl_unit_test", @@ -56,8 +57,10 @@ group("media_unit_test") { "unittest/recorder_test:recorder_server_unit_test", "unittest/sa_media_client_unit_test:sa_media_client_unit_test", "unittest/services/utils:utils_unit_test", + "unittest/sound_parser_unittest:sound_parser_unittest", "unittest/soundpool_cachebuffer_test:soundpool_cachebuffer_unit_test", "unittest/soundpool_test:soundpool_unit_test", + "unittest/soundpool_unittest:soundpool_unittest", "unittest/task_queue_test:task_queue_unit_test", "unittest/timeout_test:player_timeout_unit_test", "unittest/transcoder_server:transcoder_server_unit_test", diff --git a/test/fuzztest/avmetadata_fuzztest/avmetadatahelper_fuzzer/BUILD.gn b/test/fuzztest/avmetadata_fuzztest/avmetadatahelper_fuzzer/BUILD.gn index 3372c80b2f250d0f152aeb08a66931e496dde3e3..cd4357fc312bb6872c2dfcbab0efc79eaaf372e7 100644 --- a/test/fuzztest/avmetadata_fuzztest/avmetadatahelper_fuzzer/BUILD.gn +++ b/test/fuzztest/avmetadata_fuzztest/avmetadatahelper_fuzzer/BUILD.gn @@ -44,6 +44,7 @@ ohos_fuzztest("AVmetadataHelperFuzzTest") { external_deps = [ "c_utils:utils", + "graphic_2d:librender_service_base", "hilog:libhilog", "image_framework:image_native", "ipc:ipc_single", diff --git a/test/fuzztest/common/stub_common.cpp b/test/fuzztest/common/stub_common.cpp index a3026c85da6f94a28f6f0ad7e381db02260c655c..dbe61db7907a77d1c59d1f6b789fda8edccc1afa 100644 --- a/test/fuzztest/common/stub_common.cpp +++ b/test/fuzztest/common/stub_common.cpp @@ -62,5 +62,27 @@ bool MediaServiceProxyFuzzer::CanKillMediaService() (void)Remote()->SendRequest(MediaServiceMsg::CAN_KILL_MEDIA_SERVICE, data, reply, option); return reply.ReadBool(); } + +std::vector MediaServiceProxyFuzzer::GetPlayerPids() +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + (void)Remote()->SendRequest(MediaServiceMsg::GET_PLAYER_PIDS, data, reply, option); + std::vector res; + return res; +} + +int32_t MediaServiceProxyFuzzer::FreezeStubForPids(const std::set &pidList, bool isProxy) +{ + (void) pidList; + (void) isProxy; + return 0; +} + +int32_t MediaServiceProxyFuzzer::ResetAllProxy() +{ + return 0; +} } } \ No newline at end of file diff --git a/test/fuzztest/common/stub_common.h b/test/fuzztest/common/stub_common.h index 9e9afd1d9106baac623b8e15e7a407b0fdb97939..d4d0d84653c5f64fbcb4329b8ee8283162c8f70f 100644 --- a/test/fuzztest/common/stub_common.h +++ b/test/fuzztest/common/stub_common.h @@ -39,6 +39,9 @@ public: const sptr &listener, uint32_t timeoutMs); void ReleaseClientListener(); bool CanKillMediaService(); + std::vector GetPlayerPids(); + int32_t FreezeStubForPids(const std::set &pidList, bool isProxy); + int32_t ResetAllProxy(); private: static inline BrokerDelegator delegator_; }; diff --git a/test/fuzztest/player_fuzztest/playerfile_fuzzer/BUILD.gn b/test/fuzztest/player_fuzztest/playerfile_fuzzer/BUILD.gn index 38f74b4b09680883e08eca6208ebd2e094407493..d6a410f41bb29e323fd31c09be0a5fffa6d5cf9f 100644 --- a/test/fuzztest/player_fuzztest/playerfile_fuzzer/BUILD.gn +++ b/test/fuzztest/player_fuzztest/playerfile_fuzzer/BUILD.gn @@ -48,6 +48,7 @@ ohos_fuzztest("PlayerFileFuzzTest") { ] external_deps = [ "c_utils:utils", + "graphic_2d:librender_service_base", "graphic_surface:surface", "hilog:libhilog", "player_framework:media_client", diff --git a/test/fuzztest/player_fuzztest/playerseek_fuzzer/BUILD.gn b/test/fuzztest/player_fuzztest/playerseek_fuzzer/BUILD.gn index bc85dab9cfbc2d0388f7961ed363dfb1a60b3024..c659df8731838ea6df457e9ee26b25c9bd797bd9 100644 --- a/test/fuzztest/player_fuzztest/playerseek_fuzzer/BUILD.gn +++ b/test/fuzztest/player_fuzztest/playerseek_fuzzer/BUILD.gn @@ -49,6 +49,7 @@ ohos_fuzztest("PlayerSeekFuzzTest") { ] external_deps = [ "c_utils:utils", + "graphic_2d:librender_service_base", "graphic_surface:surface", "hilog:libhilog", "player_framework:media_client", diff --git a/test/fuzztest/player_fuzztest/playerservicestub_fuzzer/playerservicestub_fuzzer.cpp b/test/fuzztest/player_fuzztest/playerservicestub_fuzzer/playerservicestub_fuzzer.cpp index edb8632b3351c7616b36070e730940bebe09cd28..5375ce0fc7459888c0539e6819a47685ab7bdbd3 100644 --- a/test/fuzztest/player_fuzztest/playerservicestub_fuzzer/playerservicestub_fuzzer.cpp +++ b/test/fuzztest/player_fuzztest/playerservicestub_fuzzer/playerservicestub_fuzzer.cpp @@ -78,6 +78,28 @@ public: return reply.ReadBool(); } + std::vector GetPlayerPids() + { + MessageParcel data; + MessageParcel reply; + MessageOption option; + (void)Remote()->SendRequest(MediaServiceMsg::GET_PLAYER_PIDS, data, reply, option); + std::vector res; + return res; + } + + int32_t FreezeStubForPids(const std::set &pidList, bool isProxy) + { + (void)pidList; + (void)isProxy; + return 0; + } + + int32_t ResetAllProxy() + { + return 0; + } + private: static inline BrokerDelegator delegator_; }; diff --git a/test/fuzztest/player_fuzztest/playersetvolume_fuzzer/BUILD.gn b/test/fuzztest/player_fuzztest/playersetvolume_fuzzer/BUILD.gn index 9f6ff38384193e22b2d5e81cd9b137e540e5570a..81e9a4bcc6723e8088ad14446c3f1c6b84ca0871 100644 --- a/test/fuzztest/player_fuzztest/playersetvolume_fuzzer/BUILD.gn +++ b/test/fuzztest/player_fuzztest/playersetvolume_fuzzer/BUILD.gn @@ -49,6 +49,7 @@ ohos_fuzztest("PlayerSetVolumeFuzzTest") { ] external_deps = [ "c_utils:utils", + "graphic_2d:librender_service_base", "graphic_surface:surface", "hilog:libhilog", "player_framework:media_client", diff --git a/test/fuzztest/screen_capture_fuzztest/screencaptureserverstartcase_fuzzer/BUILD.gn b/test/fuzztest/screen_capture_fuzztest/screencaptureserverstartcase_fuzzer/BUILD.gn index f627bd640a33c92c2b14a9e429b6c43ff229068d..70f49aa5244c90e160b6fab1de7ca79882926371 100644 --- a/test/fuzztest/screen_capture_fuzztest/screencaptureserverstartcase_fuzzer/BUILD.gn +++ b/test/fuzztest/screen_capture_fuzztest/screencaptureserverstartcase_fuzzer/BUILD.gn @@ -132,6 +132,7 @@ ohos_fuzztest("ScreenCaptureServerStartCaseFuzzTest") { "graphic_surface:sync_fence", "hilog:libhilog", "hisysevent:libhisysevent", + "hitrace:hitrace_meter", "ipc:ipc_single", "media_foundation:media_foundation", "os_account:os_account_innerkits", diff --git a/test/fuzztest/screen_capture_fuzztest/screencaptureserverstartcase_fuzzer/screencaptureserverstartcase_fuzzer.cpp b/test/fuzztest/screen_capture_fuzztest/screencaptureserverstartcase_fuzzer/screencaptureserverstartcase_fuzzer.cpp index 251cc8c7ae25468f530ea19eaa4f0903f0f326e7..acd75e1c161e5445d4eee0fec4d68978796d0e01 100644 --- a/test/fuzztest/screen_capture_fuzztest/screencaptureserverstartcase_fuzzer/screencaptureserverstartcase_fuzzer.cpp +++ b/test/fuzztest/screen_capture_fuzztest/screencaptureserverstartcase_fuzzer/screencaptureserverstartcase_fuzzer.cpp @@ -109,12 +109,6 @@ bool ScreenCaptureServerStartCaseFuzzer::FuzzScreenCaptureServerStartCase(uint8_ screenCaptureServer_->captureCallback_->SetAudioSource(screenCaptureServer_->audioSource_); screenCaptureServer_->StartStreamInnerAudioCapture(); screenCaptureServer_->StartStreamMicAudioCapture(); - if (screenCaptureServer_->innerAudioCapture_ != nullptr) { - screenCaptureServer_->innerAudioCapture_->Pause(); - } - if (screenCaptureServer_->innerAudioCapture_ != nullptr) { - screenCaptureServer_->innerAudioCapture_->Resume(); - } std::shared_ptr callbackObj = std::make_shared(); TestScreenCapture::SetScreenCaptureCallback(callbackObj); screenCaptureServer_->ResizeCanvas(*reinterpret_cast(data), diff --git a/test/unittest/audio_haptic_test/BUILD.gn b/test/unittest/audio_haptic_test/BUILD.gn index d20921e6357ea2d50ef4c5109445f928b0a7ad21..bf8a2e826c71f83d5e6045744029ee497c355ecc 100644 --- a/test/unittest/audio_haptic_test/BUILD.gn +++ b/test/unittest/audio_haptic_test/BUILD.gn @@ -28,6 +28,7 @@ ohos_unittest("audio_haptic_unit_test") { cflags = [ "-Wall", "-Werror", + "-fno-access-control", ] sources = [ diff --git a/test/unittest/audio_haptic_test/audio_haptic_manager_impl_unit_test.cpp b/test/unittest/audio_haptic_test/audio_haptic_manager_impl_unit_test.cpp index 4e813bf830f70357426c451528c55008019c7800..1998a94a3f7f711847ac48df4879e7a78b48ce0b 100644 --- a/test/unittest/audio_haptic_test/audio_haptic_manager_impl_unit_test.cpp +++ b/test/unittest/audio_haptic_test/audio_haptic_manager_impl_unit_test.cpp @@ -540,5 +540,138 @@ HWTEST_F(AudioHapticManagerImplUnitTest, AudioHapticManagerImpl_CreatePlayer_006 g_audioHapticManagerImpl->UnregisterSource(sourceId); } + +/** + * @tc.name : Test AudioHapticManagerImpl CreatePlayer API + * @tc.number: AudioHapticManagerImpl_CreatePlayer_007 + * @tc.desc : Test AudioHapticManagerImpl CreatePlayer interface + */ +HWTEST_F(AudioHapticManagerImplUnitTest, AudioHapticManagerImpl_CreatePlayer_007, TestSize.Level1) +{ + EXPECT_NE(g_audioHapticManagerImpl, nullptr); + + std::string audioUri = AUDIO_TEST_URI; + std::string hapticUri = HAPTIC_TEST_URI; + + int32_t audioFd = open(audioUri.c_str(), O_RDONLY); + EXPECT_NE(-1, audioFd); + struct stat64 audioBuff = { 0 }; + int ret = fstat64(audioFd, &audioBuff); + EXPECT_EQ(0, ret); + AudioHapticFileDescriptor audioFile; + audioFile.fd = audioFd; + audioFile.offset = 0; + audioFile.length = audioBuff.st_size; + + int32_t hapticDd = open(hapticUri.c_str(), O_RDONLY); + EXPECT_NE(-1, hapticDd); + struct stat64 hatpicBuff = { 0 }; + ret = fstat64(hapticDd, &hatpicBuff); + EXPECT_EQ(0, ret); + AudioHapticFileDescriptor hapticFile; + hapticFile.fd = hapticDd; + hapticFile.offset = 0; + hapticFile.length = hatpicBuff.st_size; + + int32_t sourceId = g_audioHapticManagerImpl->RegisterSourceFromFd(audioFile, hapticFile); + EXPECT_NE(-1, sourceId); + + AudioHapticPlayerOptions options = {false, false}; + auto player = g_audioHapticManagerImpl->CreatePlayer(sourceId, options); + EXPECT_NE(nullptr, player); + + player->Release(); + g_audioHapticManagerImpl->UnregisterSource(sourceId); +} + +/** + * @tc.name : Test AudioHapticManagerImpl RegisterSourceFromFd API + * @tc.number: AudioHapticManagerImpl_RegisterSourceFromFd_001 + * @tc.desc : Test AudioHapticManagerImpl RegisterSourceFromFd Success + */ +HWTEST_F(AudioHapticManagerImplUnitTest, AudioHapticManagerImpl_RegisterSourceFromFd_001, TestSize.Level0) +{ + EXPECT_NE(g_audioHapticManagerImpl, nullptr); + + std::string audioUri = AUDIO_TEST_URI; + std::string hapticUri = HAPTIC_TEST_URI; + + int32_t audioFd = open(audioUri.c_str(), O_RDONLY); + EXPECT_NE(-1, audioFd); + struct stat64 audioBuff = { 0 }; + int ret = fstat64(audioFd, &audioBuff); + EXPECT_EQ(0, ret); + AudioHapticFileDescriptor audioFile; + audioFile.fd = audioFd; + audioFile.offset = 0; + audioFile.length = audioBuff.st_size; + + int32_t hapticDd = open(hapticUri.c_str(), O_RDONLY); + EXPECT_NE(-1, hapticDd); + struct stat64 hatpicBuff = { 0 }; + ret = fstat64(hapticDd, &hatpicBuff); + EXPECT_EQ(0, ret); + AudioHapticFileDescriptor hapticFile; + hapticFile.fd = hapticDd; + hapticFile.offset = 0; + hapticFile.length = hatpicBuff.st_size; + + int32_t sourceId = g_audioHapticManagerImpl->RegisterSourceFromFd(audioFile, hapticFile); + EXPECT_NE(-1, sourceId); + + g_audioHapticManagerImpl->UnregisterSource(sourceId); + close(audioFd); + close(hapticDd); +} + +/** + * @tc.name : Test AudioHapticManagerImpl RegisterSourceFromFd API + * @tc.number: AudioHapticManagerImpl_RegisterSourceFromFd_002 + * @tc.desc : Test AudioHapticManagerImpl RegisterSourceFromFd Error Fd + */ +HWTEST_F(AudioHapticManagerImplUnitTest, AudioHapticManagerImpl_RegisterSourceFromFd_002, TestSize.Level0) +{ + EXPECT_NE(g_audioHapticManagerImpl, nullptr); + + std::string audioUri = AUDIO_TEST_URI; + std::string hapticUri = HAPTIC_TEST_URI; + + int32_t audioFd = open(audioUri.c_str(), O_RDONLY); + EXPECT_NE(-1, audioFd); + struct stat64 audioBuff = { 0 }; + int ret = fstat64(audioFd, &audioBuff); + EXPECT_EQ(0, ret); + AudioHapticFileDescriptor audioFile; + audioFile.fd = audioFd; + audioFile.offset = 0; + audioFile.length = audioBuff.st_size; + + int32_t hapticDd = open(hapticUri.c_str(), O_RDONLY); + EXPECT_NE(-1, hapticDd); + struct stat64 hatpicBuff = { 0 }; + ret = fstat64(hapticDd, &hatpicBuff); + EXPECT_EQ(0, ret); + AudioHapticFileDescriptor hapticFile; + hapticFile.fd = hapticDd; + hapticFile.offset = 0; + hapticFile.length = hatpicBuff.st_size; + + g_audioHapticManagerImpl->curPlayerCount_ = 128; + int32_t sourceId = g_audioHapticManagerImpl->RegisterSourceFromFd(audioFile, hapticFile); + EXPECT_EQ(-1, sourceId); + + g_audioHapticManagerImpl->curPlayerCount_ = 0; + audioFile.fd = -1; + sourceId = g_audioHapticManagerImpl->RegisterSourceFromFd(audioFile, hapticFile); + EXPECT_EQ(-1, sourceId); + + audioFile.fd = audioFd; + hapticFile.fd = -1; + sourceId = g_audioHapticManagerImpl->RegisterSourceFromFd(audioFile, hapticFile); + EXPECT_EQ(-1, sourceId); + + close(audioFd); + close(hapticDd); +} } // namespace Media } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/audio_haptic_test/audio_haptic_player_impl_unit_test.cpp b/test/unittest/audio_haptic_test/audio_haptic_player_impl_unit_test.cpp index 3829ee3dd72ba2f84579c39e432cae72a5432b38..87618153c18972cdc18176b9a15c36e3666cf1f9 100644 --- a/test/unittest/audio_haptic_test/audio_haptic_player_impl_unit_test.cpp +++ b/test/unittest/audio_haptic_test/audio_haptic_player_impl_unit_test.cpp @@ -37,17 +37,17 @@ void AudioHapticPlayerImplUnitTest::TearDown(void) {} */ HWTEST_F(AudioHapticPlayerImplUnitTest, AudioHapticPlayerImpl_001, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSound = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSound = std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSound, nullptr); AudioLatencyMode latencyMode = static_cast(NUM2); bool parallelPlayFlag = true; - auto ret = audioHapticSound->CreateAudioHapticSound(latencyMode, audioUri, muteAudio, + auto ret = audioHapticSound->CreateAudioHapticSound(latencyMode, audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_EQ(ret, nullptr); } @@ -59,17 +59,17 @@ HWTEST_F(AudioHapticPlayerImplUnitTest, AudioHapticPlayerImpl_001, TestSize.Leve */ HWTEST_F(AudioHapticPlayerImplUnitTest, AudioHapticPlayerImpl_002, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSound = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSound = std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSound, nullptr); AudioLatencyMode latencyMode = AudioLatencyMode::AUDIO_LATENCY_MODE_NORMAL; bool parallelPlayFlag = true; - auto ret = audioHapticSound->CreateAudioHapticSound(latencyMode, audioUri, muteAudio, + auto ret = audioHapticSound->CreateAudioHapticSound(latencyMode, audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(ret, nullptr); } @@ -81,17 +81,17 @@ HWTEST_F(AudioHapticPlayerImplUnitTest, AudioHapticPlayerImpl_002, TestSize.Leve */ HWTEST_F(AudioHapticPlayerImplUnitTest, AudioHapticPlayerImpl_003, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSound = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSound = std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSound, nullptr); AudioLatencyMode latencyMode = AudioLatencyMode::AUDIO_LATENCY_MODE_FAST; bool parallelPlayFlag = true; - auto ret = audioHapticSound->CreateAudioHapticSound(latencyMode, audioUri, muteAudio, + auto ret = audioHapticSound->CreateAudioHapticSound(latencyMode, audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(ret, nullptr); } @@ -260,10 +260,11 @@ HWTEST_F(AudioHapticPlayerImplUnitTest, AudioHapticPlayerImpl_013, TestSize.Leve EXPECT_NE(audioHapticPlayerImpl, nullptr); - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -349,10 +350,11 @@ HWTEST_F(AudioHapticPlayerImplUnitTest, AudioHapticPlayerImpl_018, TestSize.Leve float volume = 0.0f; - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -379,10 +381,11 @@ HWTEST_F(AudioHapticPlayerImplUnitTest, AudioHapticPlayerImpl_019, TestSize.Leve float volume = NUM_3; - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -409,10 +412,11 @@ HWTEST_F(AudioHapticPlayerImplUnitTest, AudioHapticPlayerImpl_020, TestSize.Leve float volume = NUM_3; - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -439,10 +443,11 @@ HWTEST_F(AudioHapticPlayerImplUnitTest, AudioHapticPlayerImpl_021, TestSize.Leve float volume = NUM_3; - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -469,10 +474,11 @@ HWTEST_F(AudioHapticPlayerImplUnitTest, AudioHapticPlayerImpl_022, TestSize.Leve float volume = NUM_3; - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -499,10 +505,11 @@ HWTEST_F(AudioHapticPlayerImplUnitTest, AudioHapticPlayerImpl_023, TestSize.Leve float volume = NUM_3; - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -584,10 +591,11 @@ HWTEST_F(AudioHapticPlayerImplUnitTest, AudioHapticPlayerImpl_027, TestSize.Leve bool loop = true; - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -1113,5 +1121,45 @@ HWTEST_F(AudioHapticPlayerImplUnitTest, AudioHapticPlayerImpl_056, TestSize.Leve audioHapticSoundCallbackImpl->OnFirstFrameWriting(latency); } + +/** + * @tc.name : Test EnableHapticsInSilentMode API + * @tc.number: AudioHapticPlayerImpl_057 + * @tc.desc : Test AudioHapticPlayerImpl::EnableHapticsInSilentMode() + */ +HWTEST_F(AudioHapticPlayerImplUnitTest, AudioHapticPlayerImpl_057, TestSize.Level1) +{ + auto audioHapticPlayerImpl = std::make_shared(); + EXPECT_NE(audioHapticPlayerImpl, nullptr); + + AudioHapticPlayerImpl audioHapticPlayerImpl2; + auto audioHapticVibrator_ = std::make_shared(audioHapticPlayerImpl2); + audioHapticPlayerImpl->audioHapticVibrator_ = audioHapticVibrator_; + EXPECT_NE(audioHapticPlayerImpl->audioHapticVibrator_, nullptr); + + audioHapticPlayerImpl->EnableHapticsInSilentMode(true); + EXPECT_EQ(true, audioHapticVibrator_->enableInSilentMode_); +} + +/** + * @tc.name : Test IsHapticsIntensityAdjustmentSupported API + * @tc.number: AudioHapticPlayerImpl_058 + * @tc.desc : Test AudioHapticPlayerImpl::IsHapticsIntensityAdjustmentSupported() + */ +HWTEST_F(AudioHapticPlayerImplUnitTest, AudioHapticPlayerImpl_058, TestSize.Level1) +{ + auto audioHapticPlayerImpl = std::make_shared(); + EXPECT_NE(audioHapticPlayerImpl, nullptr); + + EXPECT_EQ(false, audioHapticPlayerImpl->IsHapticsIntensityAdjustmentSupported()); + + AudioHapticPlayerImpl audioHapticPlayerImpl2; + auto audioHapticVibrator_ = std::make_shared(audioHapticPlayerImpl2); + audioHapticPlayerImpl->audioHapticVibrator_ = audioHapticVibrator_; + EXPECT_NE(audioHapticPlayerImpl->audioHapticVibrator_, nullptr); + + EXPECT_EQ(audioHapticPlayerImpl->IsHapticsIntensityAdjustmentSupported(), + audioHapticVibrator_->IsHdHapticSupported()); +} } // namespace Media } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/audio_haptic_test/audio_haptic_sound_low_latency_impl_unit_test.cpp b/test/unittest/audio_haptic_test/audio_haptic_sound_low_latency_impl_unit_test.cpp index 1cc2a7eff7c65c2baca2de86f235ff6669e4ab17..0d35da4d277ed87710efc3edcb96b8cded4ccf88 100644 --- a/test/unittest/audio_haptic_test/audio_haptic_sound_low_latency_impl_unit_test.cpp +++ b/test/unittest/audio_haptic_test/audio_haptic_sound_low_latency_impl_unit_test.cpp @@ -40,12 +40,12 @@ void AudioHapticSoundLowLatencyImplUnitTest::TearDown(void) {} */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_001, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -67,12 +67,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_002, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -84,46 +84,46 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ /** * @tc.name : Test AudioHapticSoundLowLatencyImpl API * @tc.number: AudioHapticSoundLowLatencyImpl_003 - * @tc.desc : Test AudioHapticSoundLowLatencyImpl::OpenAudioUri() + * @tc.desc : Test AudioHapticSoundLowLatencyImpl::OpenAudioSource() */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_003, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); audioHapticSoundLowLatencyImpl->fileDes_ = 0; - audioHapticSoundLowLatencyImpl->audioUri_ = "123"; + audioHapticSoundLowLatencyImpl->audioSource_ = {.audioUri = "123"}; - auto ret = audioHapticSoundLowLatencyImpl->OpenAudioUri(audioUri); + auto ret = audioHapticSoundLowLatencyImpl->OpenAudioSource(); EXPECT_NE(ret, MSERR_OK); } /** * @tc.name : Test AudioHapticSoundLowLatencyImpl API * @tc.number: AudioHapticSoundLowLatencyImpl_004 - * @tc.desc : Test AudioHapticSoundLowLatencyImpl::OpenAudioUri() + * @tc.desc : Test AudioHapticSoundLowLatencyImpl::OpenAudioSource() */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_004, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); audioHapticSoundLowLatencyImpl->fileDes_ = -1; - audioHapticSoundLowLatencyImpl->audioUri_ = "123"; + audioHapticSoundLowLatencyImpl->audioSource_ = {.audioUri = "123"}; - auto ret = audioHapticSoundLowLatencyImpl->OpenAudioUri(audioUri); + auto ret = audioHapticSoundLowLatencyImpl->OpenAudioSource(); EXPECT_NE(ret, MSERR_OK); } @@ -134,12 +134,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_005, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -156,12 +156,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_006, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -187,12 +187,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_007, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -218,12 +218,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_008, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -249,12 +249,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_009, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -280,12 +280,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_010, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -302,12 +302,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_011, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -324,12 +324,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_012, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -346,12 +346,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_013, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -369,12 +369,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_014, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -403,12 +403,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_015, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -427,12 +427,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_016, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -450,12 +450,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_017, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -484,12 +484,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_018, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -508,12 +508,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_019, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -531,12 +531,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_020, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -553,12 +553,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_021, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -574,12 +574,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_022, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -601,12 +601,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_023, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -623,12 +623,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_024, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -650,12 +650,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_025, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -670,12 +670,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_026, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -695,12 +695,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_027, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -720,12 +720,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_028, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -735,7 +735,7 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ int32_t soundId = 0; std::shared_ptr sharedcb = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); aHSoundLowLatencyCallback->soundLowLatencyImpl_ = sharedcb; EXPECT_NE(aHSoundLowLatencyCallback->soundLowLatencyImpl_.lock(), nullptr); @@ -751,12 +751,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_029, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -776,12 +776,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_030, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -790,7 +790,7 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ int32_t streamID = 0; std::shared_ptr sharedcb = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); aHSoundLowLatencyCallback->soundLowLatencyImpl_ = sharedcb; EXPECT_NE(aHSoundLowLatencyCallback->soundLowLatencyImpl_.lock(), nullptr); @@ -805,12 +805,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_031, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -830,12 +830,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_032, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -844,7 +844,7 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ int32_t errorCode = 0; std::shared_ptr sharedcb = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); aHSoundLowLatencyCallback->soundLowLatencyImpl_ = sharedcb; EXPECT_NE(aHSoundLowLatencyCallback->soundLowLatencyImpl_.lock(), nullptr); @@ -859,12 +859,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_033, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -884,12 +884,12 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ */ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_034, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; bool parallelPlayFlag = true; auto audioHapticSoundLowLatencyImpl = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); EXPECT_NE(audioHapticSoundLowLatencyImpl, nullptr); @@ -898,7 +898,7 @@ HWTEST_F(AudioHapticSoundLowLatencyImplUnitTest, AudioHapticSoundLowLatencyImpl_ uint64_t latency = 0; std::shared_ptr sharedcb = - std::make_shared(audioUri, muteAudio, streamUsage, parallelPlayFlag); + std::make_shared(audioSource, muteAudio, streamUsage, parallelPlayFlag); aHSoundFirstFrameCallback->soundLowLatencyImpl_ = sharedcb; EXPECT_NE(aHSoundFirstFrameCallback->soundLowLatencyImpl_.lock(), nullptr); diff --git a/test/unittest/audio_haptic_test/audio_haptic_sound_normal_impl_unit_test.cpp b/test/unittest/audio_haptic_test/audio_haptic_sound_normal_impl_unit_test.cpp index bdc12d1f0daa7eb8e0cab322ee63245f527431e5..fc26df20b147a6d2488f52e26611fc1d2c741404 100644 --- a/test/unittest/audio_haptic_test/audio_haptic_sound_normal_impl_unit_test.cpp +++ b/test/unittest/audio_haptic_test/audio_haptic_sound_normal_impl_unit_test.cpp @@ -38,10 +38,11 @@ void AudioHapticSoundNormalImplUnitTest::TearDown(void) {} */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_001, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -56,10 +57,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_001, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_002, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -74,18 +76,19 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_002, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_003, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); audioHapticSoundNormalImpl->avPlayer_ = PlayerFactory::CreatePlayer(); EXPECT_NE(audioHapticSoundNormalImpl->avPlayer_, nullptr); - audioHapticSoundNormalImpl->audioUri_ = "abc"; - audioHapticSoundNormalImpl->configuredAudioUri_ = "abc"; + audioHapticSoundNormalImpl->audioSource_ = {.audioUri = "abc"}; + audioHapticSoundNormalImpl->configuredAudioSource_ = {.audioUri = "abc"}; auto ret = audioHapticSoundNormalImpl->PrepareSound(); EXPECT_NE(ret, MSERR_OK); @@ -98,10 +101,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_003, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_004, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -109,7 +113,7 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_004, Tes EXPECT_NE(audioHapticSoundNormalImpl->avPlayer_, nullptr); audioHapticSoundNormalImpl->playerState_ = AudioHapticPlayerState::STATE_RUNNING; - audioHapticSoundNormalImpl->audioUri_ = "abc"; + audioHapticSoundNormalImpl->audioSource_ = {.audioUri = "abc"}; auto ret = audioHapticSoundNormalImpl->StartSound(); EXPECT_EQ(ret, MSERR_START_FAILED); @@ -122,10 +126,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_004, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_005, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -133,7 +138,7 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_005, Tes EXPECT_NE(audioHapticSoundNormalImpl->avPlayer_, nullptr); audioHapticSoundNormalImpl->playerState_ = AudioHapticPlayerState::STATE_STOPPED; - audioHapticSoundNormalImpl->audioUri_ = "abc"; + audioHapticSoundNormalImpl->audioSource_ = {.audioUri = "abc"}; auto ret = audioHapticSoundNormalImpl->StartSound(); EXPECT_EQ(ret, MSERR_START_FAILED); @@ -146,10 +151,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_005, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_006, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -157,8 +163,8 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_006, Tes EXPECT_NE(audioHapticSoundNormalImpl->avPlayer_, nullptr); audioHapticSoundNormalImpl->playerState_ = AudioHapticPlayerState::STATE_NEW; - audioHapticSoundNormalImpl->audioUri_ = "abc"; - audioHapticSoundNormalImpl->configuredAudioUri_ = "abcd"; + audioHapticSoundNormalImpl->audioSource_ = {.audioUri = "abc"}; + audioHapticSoundNormalImpl->configuredAudioSource_ = {.audioUri = "abcd"}; auto ret = audioHapticSoundNormalImpl->StartSound(); EXPECT_EQ(ret, MSERR_START_FAILED); @@ -171,10 +177,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_006, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_007, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -182,8 +189,8 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_007, Tes EXPECT_NE(audioHapticSoundNormalImpl->avPlayer_, nullptr); audioHapticSoundNormalImpl->playerState_ = AudioHapticPlayerState::STATE_NEW; - audioHapticSoundNormalImpl->audioUri_ = "abc"; - audioHapticSoundNormalImpl->configuredAudioUri_ = "abc"; + audioHapticSoundNormalImpl->audioSource_ = {.audioUri = "abc"}; + audioHapticSoundNormalImpl->configuredAudioSource_ = {.audioUri = "abc"}; auto ret = audioHapticSoundNormalImpl->StartSound(); EXPECT_EQ(ret, MSERR_START_FAILED); @@ -196,10 +203,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_007, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_008, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -219,10 +227,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_008, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_009, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -242,10 +251,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_009, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_010, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -263,10 +273,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_010, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_011, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -283,10 +294,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_011, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_012, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -303,10 +315,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_012, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_013, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -323,10 +336,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_013, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_014, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -346,10 +360,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_014, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_015, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -369,10 +384,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_015, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_016, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -392,10 +408,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_016, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_017, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -415,10 +432,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_017, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_018, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -438,10 +456,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_018, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_019, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -461,10 +480,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_019, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_020, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -482,10 +502,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_020, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_021, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -501,10 +522,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_021, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_022, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -522,10 +544,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_022, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_023, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -541,10 +564,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_023, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_024, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -560,10 +584,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_024, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_025, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -584,10 +609,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_025, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_026, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -608,10 +634,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_026, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_027, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -629,10 +656,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_027, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_028, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -653,10 +681,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_028, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_029, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -674,10 +703,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_029, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_030, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -696,10 +726,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_030, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_031, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -715,10 +746,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AudioHapticSoundNormalImpl_031, Tes */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_032, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -726,7 +758,7 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_032, TestSize EXPECT_NE(aHSoundNormalCallback, nullptr); std::shared_ptr sharedcb = - std::make_shared(audioUri, muteAudio, streamUsage); + std::make_shared(audioSource, muteAudio, streamUsage); aHSoundNormalCallback->soundNormalImpl_ = sharedcb; EXPECT_NE(aHSoundNormalCallback->soundNormalImpl_.lock(), nullptr); @@ -743,10 +775,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_032, TestSize */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_033, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -768,10 +801,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_033, TestSize */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_034, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -794,10 +828,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_034, TestSize */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_035, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -820,10 +855,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_035, TestSize */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_036, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -846,10 +882,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_036, TestSize */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_037, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -872,10 +909,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_037, TestSize */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_038, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -897,10 +935,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_038, TestSize */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_039, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -922,10 +961,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_039, TestSize */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_040, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -933,7 +973,7 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_040, TestSize EXPECT_NE(aHSoundNormalCallback, nullptr); std::shared_ptr sharedcb = - std::make_shared(audioUri, muteAudio, streamUsage); + std::make_shared(audioSource, muteAudio, streamUsage); aHSoundNormalCallback->soundNormalImpl_ = sharedcb; EXPECT_NE(aHSoundNormalCallback->soundNormalImpl_.lock(), nullptr); @@ -951,10 +991,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_040, TestSize */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_041, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -976,10 +1017,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_041, TestSize */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_042, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -1001,10 +1043,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_042, TestSize */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_043, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -1012,7 +1055,7 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_043, TestSize EXPECT_NE(aHSoundNormalCallback, nullptr); std::shared_ptr sharedcb = - std::make_shared(audioUri, muteAudio, streamUsage); + std::make_shared(audioSource, muteAudio, streamUsage); aHSoundNormalCallback->soundNormalImpl_ = sharedcb; EXPECT_NE(aHSoundNormalCallback->soundNormalImpl_.lock(), nullptr); @@ -1030,10 +1073,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_043, TestSize */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_044, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -1055,10 +1099,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_044, TestSize */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_045, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -1079,10 +1124,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_045, TestSize */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_046, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -1090,7 +1136,7 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_046, TestSize EXPECT_NE(aHSoundNormalCallback, nullptr); std::shared_ptr sharedcb = - std::make_shared(audioUri, muteAudio, streamUsage); + std::make_shared(audioSource, muteAudio, streamUsage); aHSoundNormalCallback->soundNormalImpl_ = sharedcb; EXPECT_NE(aHSoundNormalCallback->soundNormalImpl_.lock(), nullptr); @@ -1106,10 +1152,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_046, TestSize */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_047, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); @@ -1117,7 +1164,7 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_047, TestSize EXPECT_NE(aHSoundNormalCallback, nullptr); std::shared_ptr sharedcb = - std::make_shared(audioUri, muteAudio, streamUsage); + std::make_shared(audioSource, muteAudio, streamUsage); aHSoundNormalCallback->soundNormalImpl_ = sharedcb; EXPECT_NE(aHSoundNormalCallback->soundNormalImpl_.lock(), nullptr); @@ -1133,10 +1180,11 @@ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_047, TestSize */ HWTEST_F(AudioHapticSoundNormalImplUnitTest, AHSoundNormalCallback_048, TestSize.Level1) { - std::string audioUri = "123"; + AudioSource audioSource = {.audioUri = "123"}; bool muteAudio = true; AudioStandard::StreamUsage streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; - auto audioHapticSoundNormalImpl = std::make_shared(audioUri, muteAudio, streamUsage); + auto audioHapticSoundNormalImpl = + std::make_shared(audioSource, muteAudio, streamUsage); EXPECT_NE(audioHapticSoundNormalImpl, nullptr); diff --git a/test/unittest/audio_haptic_test/audio_haptic_vibrator_impl_unit_test.cpp b/test/unittest/audio_haptic_test/audio_haptic_vibrator_impl_unit_test.cpp index 3dd3d58a1f4a72c404bd840e51fa3356d9b46f29..21879468cc73b80731fd153f06ab0a8bda772038 100644 --- a/test/unittest/audio_haptic_test/audio_haptic_vibrator_impl_unit_test.cpp +++ b/test/unittest/audio_haptic_test/audio_haptic_vibrator_impl_unit_test.cpp @@ -157,9 +157,9 @@ HWTEST_F(AudioHapticVibratorImplUnitTest, AudioHapticVibratorImpl_008, TestSize. auto audioHapticVibratorImpl = std::make_shared(audioHapticPlayerImpl); EXPECT_NE(audioHapticVibratorImpl, nullptr); - std::string hapticsUri = "fd://123"; + HapticSource hapticSource = {.hapticUri = "fd://123"}; - auto ret = audioHapticVibratorImpl->OpenHapticFile(hapticsUri); + auto ret = audioHapticVibratorImpl->OpenHapticFile(hapticSource); EXPECT_NE(ret, MSERR_OK); } diff --git a/test/unittest/avmetadata_helper_unittest/BUILD.gn b/test/unittest/avmetadata_helper_unittest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f21468075cc6c6db7818155739cf3541de1ff3ed --- /dev/null +++ b/test/unittest/avmetadata_helper_unittest/BUILD.gn @@ -0,0 +1,148 @@ +# Copyright (C) 2025 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/test.gni") +import("//foundation/multimedia/player_framework/config.gni") + +ohos_unittest("avmetadata_helper_unittest") { + module_out_path = "player_framework/player_framework/avmetadatahelper" + + cflags = [ + "-O2", + "-fPIC", + "-Wall", + "-fexceptions", + "-fno-rtti", + "-Wno-unused-but-set-variable", + "-Wno-format", + "-Dprivate=public", + "-Dprotected=public", + ] + + include_dirs = [ + "./mock", + "sa_media/ipc", + "sa_media/server", + "sa_media/server_manager", + "common", + "player/audio_background_adapter", + "player/ipc", + "player/player_mem_manage", + "player/server", + "player/subscriber", + "media_data_source/ipc", + "media_data_source/server", + "monitor/client", + "monitor/ipc", + "monitor/server", + "recorder/ipc", + "recorder/server", + "avmetadatahelper/ipc", + "avmetadatahelper/server", + "avcodec/ipc", + "avcodec/server", + "avcodeclist/ipc", + "avcodeclist/server", + "recorder_profiles/ipc", + "recorder_profiles/server", + "screen_capture/server", + "screen_capture/ipc", + "screen_capture_monitor/server", + "screen_capture_monitor/ipc", + "transcoder/server", + "transcoder/ipc", + "observer", + "$MEDIA_PLAYER_ROOT_DIR/frameworks/native/avmetadatahelper", + "$MEDIA_PLAYER_ROOT_DIR/services/include", + "$MEDIA_PLAYER_ROOT_DIR/services/services/factory", + "$MEDIA_PLAYER_ROOT_DIR/services/services/engine_intf", + "$MEDIA_PLAYER_ROOT_DIR/services/utils/include", + "$MEDIA_PLAYER_ROOT_DIR/interfaces/inner_api/native", + "$MEDIA_PLAYER_ROOT_DIR/services/services/common", + "$MEDIA_PLAYER_ROOT_DIR/services/engine/common/recorder_profiles", + "./../../../../player_framework/frameworks/native/player", + "./../../../../player_framework/test/unittest/common/include", + "$MEDIA_PLAYER_ROOT_DIR/services/services/avmetadatahelper/server", + "$MEDIA_PLAYER_ROOT_DIR/services/engine/histreamer/avmetadatahelper", + "$MEDIA_PLAYER_ROOT_DIR/services/engine/histreamer/utils", + "$MEDIA_PLAYER_ROOT_DIR/services/include", + "$MEDIA_PLAYER_ROOT_DIR/services/utils/include", + "$MEDIA_PLAYER_ROOT_DIR/interfaces/inner_api/native", + "$MEDIA_PLAYER_ROOT_DIR/services/services/engine_intf", + ] + + if (player_framework_support_avsession_background) { + include_dirs += [ "player/avsession_background" ] + } + + defines = [] + defines += player_framework_defines + + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + + sources = [ + "$MEDIA_PLAYER_ROOT_DIR/services/engine/histreamer/avmetadatahelper/av_thumbnail_generator.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp", + "av_thumbnail_generator_unittest.cpp", + ] + + deps = [ + "$MEDIA_PLAYER_ROOT_DIR/services/dfx:media_service_dfx", + "$MEDIA_PLAYER_ROOT_DIR/services/dfx:media_service_log_dfx", + "$MEDIA_PLAYER_ROOT_DIR/services/utils:media_service_utils", + ] + + external_deps = [ + "ability_runtime:ability_connect_callback_stub", + "access_token:libaccesstoken_sdk", + "audio_framework:audio_client", + "av_codec:av_codec_client", + "c_utils:utils", + "call_manager:tel_call_manager_api", + "common_event_service:cesfwk_innerkits", + "core_service:tel_core_service_api", + "drivers_interface_camera:metadata", + "drivers_interface_display:display_commontype_idl_headers", + "googletest:gmock_main", + "graphic_2d:librender_service_base", + "graphic_surface:surface", + "graphic_surface:sync_fence", + "hdf_core:libhdi", + "hicollie:libhicollie", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "hitrace:libhitracechain", + "i18n:intl_util", + "image_framework:image_native", + "image_framework:image_native", + "init:libbegetutil", + "ipc:ipc_single", + "libxml2:libxml2", + "media_foundation:media_foundation", + "memmgr:memmgrclient", + "napi:ace_napi", + "os_account:os_account_innerkits", + "qos_manager:concurrent_task_client", + "qos_manager:qos", + "resource_schedule_service:ressched_client", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "state_registry:tel_state_registry_api", + ] + + subsystem_name = "multimedia" + part_name = "player_framework" +} diff --git a/test/unittest/avmetadata_helper_unittest/av_thumbnail_generator_unittest.cpp b/test/unittest/avmetadata_helper_unittest/av_thumbnail_generator_unittest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9a63f53ad7a78e62b1652ecc32fa283d792a5aee --- /dev/null +++ b/test/unittest/avmetadata_helper_unittest/av_thumbnail_generator_unittest.cpp @@ -0,0 +1,345 @@ +/* + * Copyright (C) 2025 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 "av_thumbnail_generator_unittest.h" + +#include "buffer/avbuffer_common.h" +#include "common/media_source.h" +#include "ibuffer_consumer_listener.h" +#include "graphic_common_c.h" +#include "media_errors.h" +#include "media_log.h" +#include "media_description.h" +#include "meta/meta.h" +#include "meta/meta_key.h" +#include "plugin/plugin_time.h" +#include "sync_fence.h" +#include "uri_helper.h" + +#include "v1_0/cm_color_space.h" +#include "v1_0/hdr_static_metadata.h" +#include "v1_0/buffer_handle_meta_key_type.h" + +using namespace OHOS; +using namespace OHOS::Media; +using namespace std; +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Media { +namespace Test { +static const int32_t NUM_TEST = 1000; +static const int64_t ERR_OK = 0; +void AVThumbnailGeneratorUnitTest::SetUpTestCase(void) {} + +void AVThumbnailGeneratorUnitTest::TearDownTestCase(void) {} + +void AVThumbnailGeneratorUnitTest::SetUp(void) +{ + avThumbnailGenerator_ = std::make_shared(mediaDemuxer_); + mockMediaDemuxer_ = std::make_shared(); + avThumbnailGenerator_->mediaDemuxer_ = mockMediaDemuxer_; +} + +void AVThumbnailGeneratorUnitTest::TearDown(void) +{ + mockMediaDemuxer_ = nullptr; + avThumbnailGenerator_ = nullptr; +} + +/** + * @tc.name: StopTask + * @tc.desc: Test readTask_ != nullptr + * @tc.type: FUNC + */ +HWTEST_F(AVThumbnailGeneratorUnitTest, StopTask, TestSize.Level1) +{ + avThumbnailGenerator_->readTask_ = nullptr; + auto ret = avThumbnailGenerator_->StopTask(); + EXPECT_EQ(ret, ERR_OK); +} + +/** + * @tc.name: OnError + * @tc.desc: Test all + * @tc.type: FUNC + */ +HWTEST_F(AVThumbnailGeneratorUnitTest, OnError, TestSize.Level1) +{ + ASSERT_NE(avThumbnailGenerator_, nullptr); + MediaAVCodec::AVCodecErrorType errorType = MediaAVCodec::AVCODEC_ERROR_EXTEND_START; + int32_t errorCode = -1; + avThumbnailGenerator_->OnError(errorType, errorCode); + EXPECT_EQ(avThumbnailGenerator_->stopProcessing_, true); +} + +/** + * @tc.name: OnOutputFormatChanged + * @tc.desc: Test all + * @tc.type: FUNC + */ +HWTEST_F(AVThumbnailGeneratorUnitTest, OnOutputFormatChanged, TestSize.Level1) +{ + ASSERT_NE(avThumbnailGenerator_, nullptr); + MediaAVCodec::Format format; + avThumbnailGenerator_->OnOutputFormatChanged(format); + EXPECT_EQ(avThumbnailGenerator_->width_, 0); +} + +/** + * @tc.name: OnInputBufferAvailable + * @tc.desc: Test if (stopProcessing_.load() || hasFetchedFrame_.load() || readErrorFlag_.load()) + * @tc.type: FUNC + */ +HWTEST_F(AVThumbnailGeneratorUnitTest, OnInputBufferAvailable_003, TestSize.Level1) +{ + ASSERT_NE(avThumbnailGenerator_, nullptr); + uint32_t index = 0; + auto mockBuffer = std::make_shared(); + EXPECT_CALL(*mockBuffer, GetUniqueId()).WillRepeatedly(Return(1)); + mockBuffer->meta_ = std::make_shared(); + std::shared_ptr buffer = mockBuffer; + mockInputBufferQueueConsumer_ = new MockAVBufferQueueConsumer(); + avThumbnailGenerator_->inputBufferQueueConsumer_ = mockInputBufferQueueConsumer_; + avThumbnailGenerator_->stopProcessing_ = true; + avThumbnailGenerator_->hasFetchedFrame_ = true; + avThumbnailGenerator_->readErrorFlag_ = true; + avThumbnailGenerator_->OnInputBufferAvailable(index, buffer); +} + +/** + * @tc.name: OnOutputBufferAvailable + * @tc.desc: Test if (!isValidBuffer || !isValidState) + * @tc.type: FUNC + */ +HWTEST_F(AVThumbnailGeneratorUnitTest, OnOutputBufferAvailable, TestSize.Level1) +{ + ASSERT_NE(avThumbnailGenerator_, nullptr); + uint32_t index = 0; + auto mockAVCodecVideoDecoder = std::make_shared(); + EXPECT_CALL(*(mockAVCodecVideoDecoder), ReleaseOutputBuffer(_,_)).WillRepeatedly(Return(0)); + EXPECT_CALL(*(mockAVCodecVideoDecoder), Stop()).WillRepeatedly(Return(0)); + EXPECT_CALL(*(mockAVCodecVideoDecoder), Release()).WillRepeatedly(Return(0)); + avThumbnailGenerator_->videoDecoder_ = mockAVCodecVideoDecoder; + auto mockBuffer = std::make_shared(); + EXPECT_CALL(*mockBuffer, GetUniqueId()).WillRepeatedly(Return(1)); + mockBuffer->flag_ = static_cast(AVBufferFlag::EOS); + auto mockMemory = std::make_shared(); + EXPECT_CALL(*mockMemory, GetSize()).WillRepeatedly(Return(1)); + EXPECT_CALL(*mockMemory, GetSurfaceBuffer()).WillRepeatedly(Return(nullptr)); + mockBuffer->memory_ = mockMemory; + std::shared_ptr buffer = mockBuffer; + avThumbnailGenerator_->stopProcessing_ = true; + avThumbnailGenerator_->hasFetchedFrame_ = true; + avThumbnailGenerator_->OnOutputBufferAvailable(index, buffer); +} + +/** + * @tc.name: OnOutputBufferAvailable + * @tc.desc: Test if (!isAvailableFrame) + * @tc.type: FUNC + */ +HWTEST_F(AVThumbnailGeneratorUnitTest, OnOutputBufferAvailable_003, TestSize.Level1) +{ + ASSERT_NE(avThumbnailGenerator_, nullptr); + uint32_t index = 0; + auto mockAVCodecVideoDecoder = std::make_shared(); + EXPECT_CALL(*(mockAVCodecVideoDecoder), ReleaseOutputBuffer(_,_)).WillRepeatedly(Return(0)); + EXPECT_CALL(*(mockAVCodecVideoDecoder), Stop()).WillRepeatedly(Return(0)); + EXPECT_CALL(*(mockAVCodecVideoDecoder), Release()).WillRepeatedly(Return(0)); + avThumbnailGenerator_->videoDecoder_ = mockAVCodecVideoDecoder; + auto mockBuffer = std::make_shared(); + EXPECT_CALL(*mockBuffer, GetUniqueId()).WillRepeatedly(Return(1)); + mockBuffer->flag_ = static_cast(AVBufferFlag::NONE); + auto mockMemory = std::make_shared(); + EXPECT_CALL(*mockMemory, GetSize()).WillRepeatedly(Return(1)); + EXPECT_CALL(*mockMemory, GetSurfaceBuffer()).WillRepeatedly(Return(nullptr)); + mockBuffer->memory_ = mockMemory; + std::shared_ptr buffer = mockBuffer; + avThumbnailGenerator_->stopProcessing_ = false; + avThumbnailGenerator_->hasFetchedFrame_ = false; + avThumbnailGenerator_->seekMode_ = Plugins::SeekMode::SEEK_CLOSEST; + buffer->pts_ = -1; + avThumbnailGenerator_->OnOutputBufferAvailable(index, buffer); +} + +/** + * @tc.name: OnOutputBufferAvailable + * @tc.desc: Test if (isClosest && avBuffer_ != nullptr) && buffer->flag_ & (uint32_t)(AVBufferFlag::EOS) + * @tc.type: FUNC + */ +HWTEST_F(AVThumbnailGeneratorUnitTest, OnOutputBufferAvailable_004, TestSize.Level1) +{ + ASSERT_NE(avThumbnailGenerator_, nullptr); + uint32_t index = 0; + auto mockAVCodecVideoDecoder = std::make_shared(); + EXPECT_CALL(*(mockAVCodecVideoDecoder), ReleaseOutputBuffer(_,_)).WillRepeatedly(Return(0)); + EXPECT_CALL(*(mockAVCodecVideoDecoder), Stop()).WillRepeatedly(Return(0)); + EXPECT_CALL(*(mockAVCodecVideoDecoder), Release()).WillRepeatedly(Return(0)); + avThumbnailGenerator_->videoDecoder_ = mockAVCodecVideoDecoder; + auto mockBuffer = std::make_shared(); + EXPECT_CALL(*mockBuffer, GetUniqueId()).WillRepeatedly(Return(1)); + mockBuffer->flag_ = static_cast(AVBufferFlag::EOS); + auto mockMemory = std::make_shared(); + EXPECT_CALL(*mockMemory, GetSize()).WillRepeatedly(Return(1)); + EXPECT_CALL(*mockMemory, GetSurfaceBuffer()).WillRepeatedly(Return(nullptr)); + mockBuffer->memory_ = mockMemory; + std::shared_ptr buffer = mockBuffer; + avThumbnailGenerator_->stopProcessing_ = false; + avThumbnailGenerator_->hasFetchedFrame_ = false; + + avThumbnailGenerator_->seekMode_ = Plugins::SeekMode::SEEK_CLOSEST; + auto mockBuffer2 = std::make_shared(); + avThumbnailGenerator_->avBuffer_ = mockBuffer2; + avThumbnailGenerator_->OnOutputBufferAvailable(index, buffer); +} + +/** + * @tc.name: OnOutputBufferAvailable + * @tc.desc: Test buffer->flag_ != (uint32_t)(AVBufferFlag::EOS) + * @tc.type: FUNC + */ +HWTEST_F(AVThumbnailGeneratorUnitTest, OnOutputBufferAvailable_005, TestSize.Level1) +{ + ASSERT_NE(avThumbnailGenerator_, nullptr); + uint32_t index = 0; + auto mockAVCodecVideoDecoder = std::make_shared(); + EXPECT_CALL(*(mockAVCodecVideoDecoder), ReleaseOutputBuffer(_,_)).WillRepeatedly(Return(0)); + EXPECT_CALL(*(mockAVCodecVideoDecoder), Stop()).WillRepeatedly(Return(0)); + EXPECT_CALL(*(mockAVCodecVideoDecoder), Release()).WillRepeatedly(Return(0)); + avThumbnailGenerator_->videoDecoder_ = mockAVCodecVideoDecoder; + auto mockBuffer = std::make_shared(); + EXPECT_CALL(*mockBuffer, GetUniqueId()).WillRepeatedly(Return(1)); + mockBuffer->flag_ = static_cast(AVBufferFlag::NONE); + auto mockMemory = std::make_shared(); + EXPECT_CALL(*mockMemory, GetSize()).WillRepeatedly(Return(1)); + EXPECT_CALL(*mockMemory, GetSurfaceBuffer()).WillRepeatedly(Return(nullptr)); + mockBuffer->memory_ = mockMemory; + std::shared_ptr buffer = mockBuffer; + avThumbnailGenerator_->stopProcessing_ = false; + avThumbnailGenerator_->hasFetchedFrame_ = false; + + avThumbnailGenerator_->seekMode_ = Plugins::SeekMode::SEEK_CLOSEST; + auto mockAVBuffer = std::make_shared(); + mockAVBuffer->pts_ = -1; + avThumbnailGenerator_->avBuffer_ = mockAVBuffer; + avThumbnailGenerator_->OnOutputBufferAvailable(index, buffer); +} + +/** + * @tc.name: HandleFetchFrameYuvFailed + * @tc.desc: Test all + * @tc.type: FUNC + */ +HWTEST_F(AVThumbnailGeneratorUnitTest, HandleFetchFrameYuvFailed, TestSize.Level1) +{ + ASSERT_NE(avThumbnailGenerator_, nullptr); + EXPECT_CALL(*(mockMediaDemuxer_), Pause()).WillRepeatedly(Return(Status::OK)); + EXPECT_CALL(*(mockMediaDemuxer_), Flush()).WillRepeatedly(Return(Status::OK)); + avThumbnailGenerator_->readErrorFlag_ = false; + avThumbnailGenerator_->stopProcessing_ = false; + auto mockAVCodecVideoDecoder = std::make_shared(); + EXPECT_CALL(*(mockAVCodecVideoDecoder), ReleaseOutputBuffer(_,_)).WillRepeatedly(Return(0)); + EXPECT_CALL(*(mockAVCodecVideoDecoder), Flush()).WillRepeatedly(Return(0)); + EXPECT_CALL(*(mockAVCodecVideoDecoder), Stop()).WillRepeatedly(Return(0)); + EXPECT_CALL(*(mockAVCodecVideoDecoder), Release()).WillRepeatedly(Return(0)); + EXPECT_CALL(*(mockAVCodecVideoDecoder), SetParameter(_)).WillRepeatedly(Return(0)); + avThumbnailGenerator_->videoDecoder_ = mockAVCodecVideoDecoder; + + avThumbnailGenerator_->HandleFetchFrameYuvFailed(); + EXPECT_EQ(avThumbnailGenerator_->hasFetchedFrame_, true); +} + +/** + * @tc.name: SeekToTime + * @tc.desc: Test option == Plugins::SeekMode::SEEK_CLOSEST + * @tc.type: FUNC + */ +HWTEST_F(AVThumbnailGeneratorUnitTest, SeekToTime, TestSize.Level1) +{ + ASSERT_NE(avThumbnailGenerator_, nullptr); + int64_t timeMs = 0; + Plugins::SeekMode option = Plugins::SeekMode::SEEK_CLOSEST; + int64_t realSeekTime = 0; + EXPECT_CALL(*(mockMediaDemuxer_), SeekTo(_,_,_)).WillRepeatedly(Return(Status::OK)); + auto ret = avThumbnailGenerator_->SeekToTime(timeMs, option, realSeekTime); + EXPECT_EQ(ret, Status::OK); +} + +/** + * @tc.name: GetYuvDataAlignStride + * @tc.desc: Test outputHeight < height && format = GRAPHIC_PIXEL_FMT_YCBCR_P010 + * @tc.type: FUNC + */ +HWTEST_F(AVThumbnailGeneratorUnitTest, GetYuvDataAlignStride, TestSize.Level1) +{ + ASSERT_NE(avThumbnailGenerator_, nullptr); + auto mockSurfaceBuffer = new MockSurfaceBuffer(); + EXPECT_CALL(*(mockSurfaceBuffer), GetHeight()).WillRepeatedly(Return(NUM_TEST)); + EXPECT_CALL(*(mockSurfaceBuffer), GetFormat()). + WillRepeatedly(Return(static_cast(GraphicPixelFormat::GRAPHIC_PIXEL_FMT_YCBCR_P010))); + EXPECT_CALL(*(mockSurfaceBuffer), GetWidth()).WillRepeatedly(Return(0)); + EXPECT_CALL(*(mockSurfaceBuffer), GetStride()).WillRepeatedly(Return(0)); + EXPECT_CALL(*(mockSurfaceBuffer), GetVirAddr()).WillRepeatedly(Return(nullptr)); + EXPECT_CALL(*(mockSurfaceBuffer), GetSize()).WillRepeatedly(Return(0)); + sptr surfaceBuffer(mockSurfaceBuffer); + auto ret = avThumbnailGenerator_->GetYuvDataAlignStride(surfaceBuffer); + EXPECT_EQ(ret, MSERR_OK); +} + +/** + * @tc.name: GenerateAlignmentAvBuffer + * @tc.desc: Test outputHeight < height + * @tc.type: FUNC + */ +HWTEST_F(AVThumbnailGeneratorUnitTest, GenerateAlignmentAvBuffer, TestSize.Level1) +{ + ASSERT_NE(avThumbnailGenerator_, nullptr); + auto mockSurfaceBuffer = new MockSurfaceBuffer(); + EXPECT_CALL(*(mockSurfaceBuffer), GetWidth()).WillRepeatedly(Return(NUM_TEST)); + EXPECT_CALL(*(mockSurfaceBuffer), Alloc(_)).WillRepeatedly(Return(GSError::GSERROR_OK)); + EXPECT_CALL(*(mockSurfaceBuffer), GetHeight()).WillRepeatedly(Return(NUM_TEST)); + EXPECT_CALL(*(mockSurfaceBuffer), GetFormat()). + WillRepeatedly(Return(static_cast(GraphicPixelFormat::GRAPHIC_PIXEL_FMT_YCBCR_P010))); + sptr surfaceBuffer(mockSurfaceBuffer); + auto mockBuffer = std::make_shared(); + auto mockMemory = std::make_shared(); + EXPECT_CALL(*mockMemory, GetSurfaceBuffer()).WillRepeatedly(Return(mockSurfaceBuffer)); + EXPECT_CALL(*mockMemory, GetSize()).WillRepeatedly(Return(NUM_TEST)); + mockBuffer->memory_ = mockMemory; + avThumbnailGenerator_->avBuffer_ = mockBuffer; + auto ret = avThumbnailGenerator_->GenerateAlignmentAvBuffer(); + EXPECT_EQ(ret, nullptr); +} + +/** + * @tc.name: SetSbStaticMetadata + * @tc.desc: Test SetMetadata return GSERROR_OK + * @tc.type: FUNC + */ +HWTEST_F(AVThumbnailGeneratorUnitTest, SetSbStaticMetadata, TestSize.Level1) +{ + ASSERT_NE(avThumbnailGenerator_, nullptr); + auto mockSurfaceBuffer = new MockSurfaceBuffer(); + EXPECT_CALL(*(mockSurfaceBuffer), SetMetadata(_,_,_)).WillRepeatedly(Return(GSERROR_OK)); + sptr surfaceBuffer(mockSurfaceBuffer); + std::vector dynamicMetadata; + auto ret = avThumbnailGenerator_->SetSbStaticMetadata(surfaceBuffer, dynamicMetadata); + EXPECT_EQ(ret, true); +} +} // namespace Test +} // namespace Media +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/avmetadata_helper_unittest/av_thumbnail_generator_unittest.h b/test/unittest/avmetadata_helper_unittest/av_thumbnail_generator_unittest.h new file mode 100644 index 0000000000000000000000000000000000000000..8eb96002eed91c436db96ee94b69d1919fbb6898 --- /dev/null +++ b/test/unittest/avmetadata_helper_unittest/av_thumbnail_generator_unittest.h @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2025 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 AV_THUMBNAIL_GENERATOR_UNIT_TEST_H +#define AV_THUMBNAIL_GENERATOR_UNIT_TEST_H + +#include +#include +#include +#include +#include + +#include "mock/avbuffer.h" +#include "mock/mock_avbuffer_queue.h" +#include "mock/mock_avbuffer_queue_consumer.h" +#include "mock/mock_avbuffer_queue_producer.h" +#include "mock/mock_avcodec_video_decoder.h" +#include "mock/avsharedmomorybase.h" +#include "mock/mock_media_demuxer.h" +#include "common/status.h" +#include "i_avmetadatahelper_service.h" +#include "pipeline/pipeline.h" +#include "video_decoder_adapter.h" +#include "av_thumbnail_generator.h" +#include "gtest/gtest.h" + +namespace OHOS { +namespace Media { +namespace Test { +class AVThumbnailGeneratorUnitTest : public testing::Test { +public: + // SetUpTestCase: Called before all test cases + static void SetUpTestCase(void); + // TearDownTestCase: Called after all test case + static void TearDownTestCase(void); + // SetUp: Called before each test cases + void SetUp(void); + // TearDown: Called after each test cases + void TearDown(void); + +protected: + std::shared_ptr avThumbnailGenerator_{ nullptr }; + std::shared_ptr mediaDemuxer_{ nullptr }; + std::shared_ptr mockMediaDemuxer_{ nullptr }; + std::shared_ptr mockInputBufferQueue_{ nullptr }; + sptr mockInputBufferQueueConsumer_{ nullptr }; + sptr mockInputBufferQueueProducer_{ nullptr }; +}; +class MockSurfaceBuffer : public SurfaceBuffer { +public: + MOCK_METHOD(int32_t, GetWidth, (), (const, override)); + MOCK_METHOD(int32_t, GetHeight, (), (const, override)); + MOCK_METHOD(int32_t, GetStride, (), (const, override)); + MOCK_METHOD(int32_t, GetFormat, (), (const, override)); + MOCK_METHOD(uint64_t, GetUsage, (), (const, override)); + MOCK_METHOD(uint64_t, GetPhyAddr, (), (const, override)); + MOCK_METHOD(int32_t, GetFileDescriptor, (), (const, override)); + MOCK_METHOD(uint32_t, GetSize, (), (const, override)); + MOCK_METHOD(GraphicColorGamut, GetSurfaceBufferColorGamut, (), (const, override)); + MOCK_METHOD(GraphicTransformType, GetSurfaceBufferTransform, (), (const, override)); + MOCK_METHOD(int32_t, GetSurfaceBufferWidth, (), (const, override)); + MOCK_METHOD(int32_t, GetSurfaceBufferHeight, (), (const, override)); + MOCK_METHOD(uint32_t, GetSeqNum, (), (const, override)); + MOCK_METHOD(sptr, GetExtraData, (), (const, override)); + MOCK_METHOD(GSError, WriteToMessageParcel, (MessageParcel &parcel), (override)); + MOCK_METHOD(GSError, ReadFromMessageParcel, (MessageParcel &parcel, std::functionreadFdDefaultFunc)>readSafeFdFunc),(override)); + MOCK_METHOD(void, SetSurfaceBufferColorGamut, (const GraphicColorGamut& colorGamut), (override)); + MOCK_METHOD(void, SetSurfaceBufferTransform, (const GraphicTransformType& transform), (override)); + MOCK_METHOD(void, SetSurfaceBufferWidth, (int32_t width), (override)); + MOCK_METHOD(void, SetSurfaceBufferHeight, (int32_t width), (override)); + MOCK_METHOD(void, SetExtraData, (sptr bedata), (override)); + MOCK_METHOD(void, SetBufferHandle, (BufferHandle *handle), (override)); + MOCK_METHOD(BufferHandle*, GetBufferHandle, (), (const, override)); + MOCK_METHOD(void*, GetVirAddr, (), (override)); + MOCK_METHOD(GSError, Alloc, (const BufferRequestConfig &config), (override)); + MOCK_METHOD(GSError, Map, (), (override)); + MOCK_METHOD(GSError, Unmap, (), (override)); + MOCK_METHOD(GSError, FlushCache, (), (override)); + MOCK_METHOD(GSError, InvalidateCache, (), (override)); + MOCK_METHOD(GSError, SetMetadata, (uint32_t key, const std::vector& value, bool enableCache), (override)); + MOCK_METHOD(GSError, GetMetadata, (uint32_t key, std::vector& value), (override)); + MOCK_METHOD(GSError, ListMetadataKeys, (std::vector& keys), (override)); + MOCK_METHOD(GSError, EraseMetadataKey, (uint32_t key), (override)); + MOCK_METHOD(void, SetCropMetadata, (const OHOS::Rect& crop), (override)); + MOCK_METHOD(bool, GetCropMetadata, (OHOS::Rect& crop), (override)); + MOCK_METHOD(OH_NativeBuffer*, SurfaceBufferToNativeBuffer, (), (override)); + MOCK_METHOD(BufferRequestConfig, GetBufferRequestConfig, (), (const, override)); +}; +} // namespace Test +} // namespace Media +} // namespace OHOS +#endif // AV_THUMBNAIL_GENERATOR_UNIT_TEST_H \ No newline at end of file diff --git a/test/unittest/avmetadata_helper_unittest/mock/avbuffer.h b/test/unittest/avmetadata_helper_unittest/mock/avbuffer.h new file mode 100644 index 0000000000000000000000000000000000000000..8fde07ec25b6a8f7d94f57451415116dcdac8bc6 --- /dev/null +++ b/test/unittest/avmetadata_helper_unittest/mock/avbuffer.h @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2025 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 AVBUFFER_H +#define AVBUFFER_H + +#include +#include +#include +#include +#include "buffer/avallocator.h" +#include "common/status.h" + +namespace OHOS { +namespace Media { +class AVMemory; +class AVBuffer { +public: + AVBuffer() = default; + virtual ~AVBuffer() = default; + MOCK_METHOD(const AVBufferConfig&, GetConfig, (), ()); + MOCK_METHOD(uint64_t, GetUniqueId, (), ()); + MOCK_METHOD(bool, WriteToMessageParcel, (MessageParcel& parcel), ()); + MOCK_METHOD(bool, ReadFromMessageParcel, (MessageParcel& parcel, bool isSurfaceBuffer), ()); + static std::shared_ptr CreateAVBuffer(const AVBufferConfig &config){ + return std::make_shared(); + } + static std::shared_ptr CreateAVBuffer(std::shared_ptr allocator, int32_t capacity = 0, + int32_t align = 0){ + return std::make_shared(); + } + static std::shared_ptr CreateAVBuffer(uint8_t *ptr, int32_t capacity, int32_t size = 0){ + return std::make_shared(); + } + static std::shared_ptr CreateAVBuffer(sptr surfaceBuffer){ + return std::make_shared(); + } +protected: + using MetaData = std::vector; + int64_t pts_; + int64_t dts_; + int64_t duration_; + uint32_t flag_; + std::shared_ptr meta_; + std::shared_ptr memory_; + AVBufferConfig config_; + MOCK_METHOD(Status, Init, (std::shared_ptr allocator, int32_t capacity, int32_t align), ()); + MOCK_METHOD(Status, Init, (uint8_t* ptr, int32_t capacity, int32_t size), ()); + MOCK_METHOD(Status, Init, (sptr surfaceBuffer), ()); +}; + +class AVMemory { +public: + AVMemory() = default; + virtual ~AVMemory() = default; + MOCK_METHOD(MemoryType, GetMemoryType, (), ()); + MOCK_METHOD(MemoryFlag, GetMemoryFlag, (), ()); + MOCK_METHOD(int32_t, GetCapacity, (), ()); + MOCK_METHOD(int32_t, GetSize, (), ()); + MOCK_METHOD(Status, SetSize, (int32_t size), ()); + MOCK_METHOD(int32_t, GetOffset, (), ()); + MOCK_METHOD(Status, SetOffset, (int32_t offset), ()); + MOCK_METHOD(int32_t, GetFileDescriptor, (), ()); + MOCK_METHOD(uint8_t*, GetAddr, (), ()); + MOCK_METHOD(int32_t, Write, (const uint8_t* in, int32_t writeSize, int32_t position), ()); + MOCK_METHOD(int32_t, Read, (uint8_t* out, int32_t readSize, int32_t position), ()); + MOCK_METHOD(void, Reset, (), ()); + MOCK_METHOD(sptr, GetSurfaceBuffer, (), ()); + +protected: + MOCK_METHOD(Status, Init, (), ()); + MOCK_METHOD(Status, Init, (MessageParcel& parcel), ()); + MOCK_METHOD(Status, InitSurfaceBuffer, (MessageParcel& parcel), ()); + MOCK_METHOD(Status, InitSurfaceBuffer, (sptr surfaceBuffer), ()); + MOCK_METHOD(bool, WriteToMessageParcel, (MessageParcel& parcel), ()); + MOCK_METHOD(bool, ReadFromMessageParcel, (MessageParcel& parcel), ()); + MOCK_METHOD(bool, ReadCommonFromMessageParcel, (MessageParcel& parcel), ()); + MOCK_METHOD(bool, SkipCommonFromMessageParcel, (MessageParcel& parcel), ()); + MOCK_METHOD(bool, WriteCommonToMessageParcel, (MessageParcel& parcel), ()); + int32_t capacity_ = 0; + int32_t align_; + int32_t offset_; + int32_t size_; + uint8_t *base_; + uint64_t uid_; + std::shared_ptr allocator_; + static std::shared_ptr CreateAVMemory(std::shared_ptr allocator, + int32_t capacity = 0, int32_t align = 0){ + return std::make_shared(); + } + static std::shared_ptr CreateAVMemory(uint8_t *ptr, int32_t capacity, int32_t size){ + return std::make_shared(); + } + static std::shared_ptr CreateAVMemory(MessageParcel &parcel, bool isSurfaceBuffer = false){ + return std::make_shared(); + } + static std::shared_ptr CreateAVMemory(sptr surfaceBuffer){ + return std::make_shared(); + } +}; +} +} +#endif // MOCK_AVBUFFER_H \ No newline at end of file diff --git a/test/unittest/avmetadata_helper_unittest/mock/avsharedmomorybase.h b/test/unittest/avmetadata_helper_unittest/mock/avsharedmomorybase.h new file mode 100644 index 0000000000000000000000000000000000000000..6c840c784a9f8294b55a0073ea9d41ccba8b5bce --- /dev/null +++ b/test/unittest/avmetadata_helper_unittest/mock/avsharedmomorybase.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2025 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_MEDIA_AV_SHARED_MEMORY_BASE_H +#define OHOS_MEDIA_AV_SHARED_MEMORY_BASE_H + +#include +#include "buffer/avsharedmemory.h" +#include "gmock/gmock.h" + +namespace OHOS { +namespace Media { +class AVSharedMemoryBase { +public: + MOCK_METHOD(std::shared_ptr, CreateFromLocal, + (int32_t size, uint32_t flags, const std::string &name), ()); + + MOCK_METHOD(std::shared_ptr, CreateFromRemote, + (int32_t fd, int32_t size, uint32_t flags, const std::string &name), ()); + + ~AVSharedMemoryBase() = default; + AVSharedMemoryBase() = default; + + AVSharedMemoryBase(int32_t size, uint32_t flags, const std::string &name) {}; + + MOCK_METHOD(int32_t, Init, (bool isMapVirAddr), ()); + + MOCK_METHOD(int32_t, GetFd, (), ()); + + MOCK_METHOD(std::string, GetName, (), ()); + + MOCK_METHOD(int32_t, Write, (const uint8_t *in, int32_t writeSize, int32_t position), ()); + + MOCK_METHOD(int32_t, Read, (uint8_t *out, int32_t readSize, int32_t position), ()); + + MOCK_METHOD(int32_t, GetUsedSize, (), ()); + + MOCK_METHOD(void, ClearUsedSize, (), ()); + + MOCK_METHOD(uint8_t*, GetBase, (), ()); + + MOCK_METHOD(int32_t, GetSize, (), ()); + + MOCK_METHOD(uint32_t, GetFlags, (), ()); +}; +} // namespace Media +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/test/unittest/avmetadata_helper_unittest/mock/media_demuxer.h b/test/unittest/avmetadata_helper_unittest/mock/media_demuxer.h new file mode 100644 index 0000000000000000000000000000000000000000..b977fe2b63a4750e8b47b106fb22243d28cda83a --- /dev/null +++ b/test/unittest/avmetadata_helper_unittest/mock/media_demuxer.h @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2025 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 MEDIA_DEMUXER_H +#define MEDIA_DEMUXER_H + +#include +#include +#include +#include +#include + +#include "avcodec_common.h" +#include "buffer/avbuffer.h" +#include "common/media_source.h" +#include "common/seek_callback.h" +#include "demuxer/type_finder.h" +#include "filter/filter.h" +#include "meta/media_types.h" +#include "osal/task/autolock.h" +#include "osal/task/task.h" +#include "plugin/plugin_base.h" +#include "plugin/plugin_info.h" +#include "plugin/plugin_time.h" +#include "plugin/demuxer_plugin.h" + +namespace OHOS { +namespace Media { +using MediaSource = OHOS::Media::Plugins::MediaSource; +class BaseStreamDemuxer; +class DemuxerPluginManager; +class Source; + +class AVBufferQueueProducer; + +class MediaDemuxer { +public: + virtual ~MediaDemuxer() = default; + virtual Status SetDataSource(const std::shared_ptr &source); + virtual Status SetSubtitleSource(const std::shared_ptr &source); + virtual void SetBundleName(const std::string& bundleName); + virtual Status SetOutputBufferQueue(int32_t trackId, const sptr& producer); + + virtual std::shared_ptr GetGlobalMetaInfo(); + virtual std::vector> GetStreamMetaInfo(); + virtual std::shared_ptr GetUserMeta(); + + virtual Status SeekTo(int64_t seekTime, Plugins::SeekMode mode, int64_t& realSeekTime); + virtual Status Reset(); + virtual Status Start(); + virtual Status Stop(); + virtual Status Pause(); + virtual Status PauseDragging(); + virtual Status PauseAudioAlign(); + virtual Status Resume(); + virtual Status ResumeDragging(); + virtual Status ResumeAudioAlign(); + virtual Status Flush(); + virtual Status Preroll(); + virtual Status PausePreroll(); + + virtual Status StartTask(int32_t trackId); + virtual Status SelectTrack(int32_t trackId); + virtual Status UnselectTrack(int32_t trackId); + virtual Status ReadSample(uint32_t trackId, std::shared_ptr sample); + virtual Status GetBitRates(std::vector &bitRates); + virtual Status SelectBitRate(uint32_t bitRate); + virtual Status GetMediaKeySystemInfo(std::multimap> &infos); + virtual void SetDrmCallback(const std::shared_ptr &callback); + virtual void OnEvent(const Plugins::PluginEvent &event); + + virtual std::map> GetBufferQueueProducerMap(); + virtual Status PauseTaskByTrackId(int32_t trackId); + virtual bool IsRenderNextVideoFrameSupported(); + + virtual void SetEventReceiver(const std::shared_ptr &receiver); + virtual bool GetDuration(int64_t& durationMs); + virtual void SetPlayerId(const std::string &playerId); + virtual void OnInterrupted(bool isInterruptNeeded); + virtual void SetDumpInfo(bool isDump, uint64_t instanceId); + + virtual Status OptimizeDecodeSlow(bool isDecodeOptimizationEnabled); + virtual Status SetDecoderFramerateUpperLimit(int32_t decoderFramerateUpperLimit, uint32_t trackId); + virtual Status SetSpeed(float speed); + virtual Status SetFrameRate(double frameRate, uint32_t trackId); + + virtual bool IsLocalDrmInfosExisted(); + virtual void OnBufferAvailable(uint32_t trackId); + virtual void SetSelectBitRateFlag(bool flag, uint32_t desBitRate); + virtual bool CanAutoSelectBitRate(); + virtual void OnDumpInfo(int32_t fd); + + virtual Status StartReferenceParser(int64_t startTimeMs, bool isForward = true); + virtual Status GetFrameLayerInfo(std::shared_ptr videoSample, FrameLayerInfo &frameLayerInfo); + virtual Status GetFrameLayerInfo(uint32_t frameId, FrameLayerInfo &frameLayerInfo); + virtual Status GetGopLayerInfo(uint32_t gopId, GopLayerInfo &gopLayerInfo); + virtual bool IsVideoEos(); + virtual bool HasEosTrack(); + virtual Status GetIFramePos(std::vector &IFramePos); + virtual Status Dts2FrameId(int64_t dts, uint32_t &frameId, bool offset = true); + virtual void RegisterVideoStreamReadyCallback(const std::shared_ptr &callback); + virtual void DeregisterVideoStreamReadyCallback(); + + virtual Status GetIndexByRelativePresentationTimeUs(const uint32_t trackIndex, + const uint64_t relativePresentationTimeUs, uint32_t &index); + virtual Status GetRelativePresentationTimeUsByIndex(const uint32_t trackIndex, + const uint32_t index, uint64_t &relativePresentationTimeUs); + + virtual Status ResumeDemuxerReadLoop(); + virtual Status PauseDemuxerReadLoop(); + virtual void SetCacheLimit(uint32_t limitSize); + virtual void SetEnableOnlineFdCache(bool isEnableFdCache); + virtual void WaitForBufferingEnd(); +}; +} // namespace Media +} // namespace OHOS +#endif // MEDIA_DEMUXER_H \ No newline at end of file diff --git a/test/unittest/avmetadata_helper_unittest/mock/mock_avbuffer_queue.h b/test/unittest/avmetadata_helper_unittest/mock/mock_avbuffer_queue.h new file mode 100644 index 0000000000000000000000000000000000000000..31a05f522592cae865cc8513015f72e08cc4fc99 --- /dev/null +++ b/test/unittest/avmetadata_helper_unittest/mock/mock_avbuffer_queue.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2025 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 MOCK_HISTREAMER_FOUNDATION_AVBUFFER_QUEUE_H +#define MOCK_HISTREAMER_FOUNDATION_AVBUFFER_QUEUE_H + +#include "avbuffer_queue.h" +#include "gmock/gmock.h" + +namespace OHOS { +namespace Media { + +class MockAVBufferQueue : public AVBufferQueue { +public: + MockAVBufferQueue() = default; + ~MockAVBufferQueue() override {}; + + MOCK_METHOD(std::shared_ptr, GetLocalProducer, (), (override)); + MOCK_METHOD(std::shared_ptr, GetLocalConsumer, (), (override)); + + // 跨进程对象智能指针 + MOCK_METHOD(sptr, GetProducer, (), (override)); + MOCK_METHOD(sptr, GetConsumer, (), (override)); + + MOCK_METHOD(sptr, GetSurfaceAsProducer, (), (override)); + MOCK_METHOD(sptr, GetSurfaceAsConsumer, (), (override)); + + MOCK_METHOD(uint32_t, GetQueueSize, (), (override)); + MOCK_METHOD(Status, SetQueueSize, (uint32_t size), (override)); + MOCK_METHOD(Status, SetLargerQueueSize, (uint32_t size), (override)); + MOCK_METHOD(bool, IsBufferInQueue, (const std::shared_ptr& buffer), (override)); + MOCK_METHOD(Status, Clear, (), (override)); + MOCK_METHOD(Status, ClearBufferIf, (std::function &)> pred), (override)); + MOCK_METHOD(Status, SetQueueSizeAndAttachBuffer, + (uint32_t size, std::shared_ptr& buffer, bool isFilled), (override)); +}; + +} // namespace Media +} // namespace OHOS + +#endif // MOCK_HISTREAMER_FOUNDATION_AVBUFFER_QUEUE_H diff --git a/test/unittest/avmetadata_helper_unittest/mock/mock_avbuffer_queue_consumer.h b/test/unittest/avmetadata_helper_unittest/mock/mock_avbuffer_queue_consumer.h new file mode 100644 index 0000000000000000000000000000000000000000..849dc66c94ea41dc2fe2c842c92926783f80e727 --- /dev/null +++ b/test/unittest/avmetadata_helper_unittest/mock/mock_avbuffer_queue_consumer.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 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 MOCK_HISTREAMER_FOUNDATION_AVBUFFER_QUEUE_CONSUMER_H +#define MOCK_HISTREAMER_FOUNDATION_AVBUFFER_QUEUE_CONSUMER_H + +#include "avbuffer_queue_consumer.h" +#include "gmock/gmock.h" + +namespace OHOS { +namespace Media { + +class MockAVBufferQueueConsumer : public AVBufferQueueConsumer { +public: + MockAVBufferQueueConsumer() = default; + ~MockAVBufferQueueConsumer() override {}; + + MOCK_METHOD(uint32_t, GetQueueSize, (), (override)); + MOCK_METHOD(Status, SetQueueSize, (uint32_t size), (override)); + MOCK_METHOD(bool, IsBufferInQueue, (const std::shared_ptr& buffer), (override)); + + MOCK_METHOD(Status, AcquireBuffer, (std::shared_ptr& outBuffer), (override)); + MOCK_METHOD(Status, ReleaseBuffer, (const std::shared_ptr& inBuffer), (override)); + + MOCK_METHOD(Status, AttachBuffer, (std::shared_ptr& inBuffer, bool isFilled), (override)); + MOCK_METHOD(Status, DetachBuffer, (const std::shared_ptr& outBuffer), (override)); + + MOCK_METHOD(Status, SetBufferAvailableListener, (sptr& listener), (override)); + + MOCK_METHOD(Status, SetQueueSizeAndAttachBuffer, (uint32_t size, std::shared_ptr& buffer, + bool isFilled), (override)); +}; + +} // namespace Media +} // namespace OHOS + +#endif // MOCK_HISTREAMER_FOUNDATION_AVBUFFER_QUEUE_CONSUMER_H \ No newline at end of file diff --git a/test/unittest/avmetadata_helper_unittest/mock/mock_avbuffer_queue_producer.h b/test/unittest/avmetadata_helper_unittest/mock/mock_avbuffer_queue_producer.h new file mode 100644 index 0000000000000000000000000000000000000000..47f25bbfa6634a0553a4b9c12f9dd9483c7a1f9c --- /dev/null +++ b/test/unittest/avmetadata_helper_unittest/mock/mock_avbuffer_queue_producer.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 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 MOCK_HISTREAMER_FOUNDATION_AVBUFFER_QUEUE_PRODUCER_H +#define MOCK_HISTREAMER_FOUNDATION_AVBUFFER_QUEUE_PRODUCER_H + +#include "avbuffer_queue_producer.h" +#include "gmock/gmock.h" + + +namespace OHOS { +namespace Media { + +class MockAVBufferQueueProducer : public AVBufferQueueProducer { +public: + MockAVBufferQueueProducer() = default; + ~MockAVBufferQueueProducer() override {}; + + MOCK_METHOD(uint32_t, GetQueueSize, (), (override)); + MOCK_METHOD(Status, SetQueueSize, (uint32_t size), (override)); + + MOCK_METHOD(Status, RequestBuffer, (std::shared_ptr& outBuffer, + const AVBufferConfig& config, int32_t timeoutMs), (override)); + + MOCK_METHOD(Status, PushBuffer, (const std::shared_ptr& inBuffer, bool available), (override)); + MOCK_METHOD(Status, ReturnBuffer, (const std::shared_ptr& inBuffer, bool available), (override)); + + MOCK_METHOD(Status, AttachBuffer, (std::shared_ptr& inBuffer, bool isFilled), (override)); + MOCK_METHOD(Status, DetachBuffer, (const std::shared_ptr& outBuffer), (override)); + + MOCK_METHOD(Status, SetBufferFilledListener, (sptr& listener), (override)); + MOCK_METHOD(Status, RemoveBufferFilledListener, (sptr& listener), (override)); + MOCK_METHOD(Status, SetBufferAvailableListener, (sptr& listener), (override)); + MOCK_METHOD(Status, Clear, (), (override)); + MOCK_METHOD(Status, ClearBufferIf, (std::function &)> pred), (override)); + MOCK_METHOD(sptr, AsObject, (), (override)); +}; + +} // namespace Media +} // namespace OHOS + +#endif // MOCK_HISTREAMER_FOUNDATION_AVBUFFER_QUEUE_PRODUCER_H diff --git a/test/unittest/avmetadata_helper_unittest/mock/mock_avcodec_video_decoder.h b/test/unittest/avmetadata_helper_unittest/mock/mock_avcodec_video_decoder.h new file mode 100644 index 0000000000000000000000000000000000000000..80754572b5ce7b8b0724dd8a28cb2aaf38699ca1 --- /dev/null +++ b/test/unittest/avmetadata_helper_unittest/mock/mock_avcodec_video_decoder.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2025 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 MOCK_MEDIA_AVCODEC_VIDEO_DECODER_H +#define MOCK_MEDIA_AVCODEC_VIDEO_DECODER_H + +#include "gmock/gmock.h" +#include "avcodec_video_decoder.h" + +namespace OHOS { +namespace MediaAVCodec { +class MockAVCodecVideoDecoder : public AVCodecVideoDecoder { +public: + MockAVCodecVideoDecoder() = default; + ~MockAVCodecVideoDecoder() override = default; + MOCK_METHOD(int32_t, Configure, (const Format &format), ()); + + MOCK_METHOD(int32_t, Prepare, (), ()); + + MOCK_METHOD(int32_t, Start, (), ()); + + MOCK_METHOD(int32_t, Stop, (), ()); + + MOCK_METHOD(int32_t, Flush, (), ()); + + MOCK_METHOD(int32_t, Reset, (), ()); + + MOCK_METHOD(int32_t, Release, (), ()); + + MOCK_METHOD(int32_t, SetOutputSurface, (sptr surfac), ()); + + MOCK_METHOD(int32_t, QueueInputBuffer, (uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag), ()); + + MOCK_METHOD(int32_t, QueueInputBuffer, (uint32_t index), ()); + + MOCK_METHOD(int32_t, GetOutputFormat, (Format &format), ()); + + MOCK_METHOD(int32_t, ReleaseOutputBuffer, (uint32_t index, bool render), ()); + + MOCK_METHOD(int32_t, RenderOutputBufferAtTime, (uint32_t index, int64_t renderTimestampNs), ()); + + MOCK_METHOD(int32_t, SetParameter, (const Format &format), ()); + + MOCK_METHOD(int32_t, SetCallback, (const std::shared_ptr &callback), ()); + + MOCK_METHOD(int32_t, SetCallback, (const std::shared_ptr &callback), ()); + + MOCK_METHOD(int32_t, SetDecryptConfig, (const sptr &keySession, + const bool svpFlag), ()); +}; +} // namespace MediaAVCodec +} // namespace OHOS +#endif // MEDIA_AVCODEC_VIDEO_DECODER_H \ No newline at end of file diff --git a/test/unittest/avmetadata_helper_unittest/mock/mock_media_demuxer.h b/test/unittest/avmetadata_helper_unittest/mock/mock_media_demuxer.h new file mode 100644 index 0000000000000000000000000000000000000000..ca07fd89acd2f35c0d119bd84d6ee2f6b2d179f0 --- /dev/null +++ b/test/unittest/avmetadata_helper_unittest/mock/mock_media_demuxer.h @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2025 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 MOCK_MEDIA_DEMUXER_H +#define MOCK_MEDIA_DEMUXER_H + +#include "media_demuxer.h" +#include "gmock/gmock.h" + +namespace OHOS { +namespace Media { +using MediaSource = OHOS::Media::Plugins::MediaSource; +class BaseStreamDemuxer; +class DemuxerPluginManager; +class Source; + +class AVBufferQueueProducer; + +class MockMediaDemuxer : public MediaDemuxer { +public: + MockMediaDemuxer() = default; + ~MockMediaDemuxer() override {}; + MOCK_METHOD(Status, SetDataSource, (const std::shared_ptr &source), (override)); + MOCK_METHOD(Status, SetSubtitleSource, (const std::shared_ptr &source), (override)); + MOCK_METHOD(void, SetBundleName, (const std::string& bundleName), (override)); + MOCK_METHOD(Status, SetOutputBufferQueue, (int32_t trackId, const sptr& producer), + (override)); + + MOCK_METHOD(std::shared_ptr, GetGlobalMetaInfo, (), (override)); + MOCK_METHOD(std::vector>, GetStreamMetaInfo, (), (override)); + MOCK_METHOD(std::shared_ptr, GetUserMeta, (), (override)); + + MOCK_METHOD(Status, SeekTo, (int64_t seekTime, Plugins::SeekMode mode, int64_t& realSeekTime), (override)); + MOCK_METHOD(Status, Reset, (), (override)); + MOCK_METHOD(Status, Start, (), (override)); + MOCK_METHOD(Status, Stop, (), (override)); + MOCK_METHOD(Status, Pause, (), (override)); + MOCK_METHOD(Status, PauseDragging, (), (override)); + MOCK_METHOD(Status, PauseAudioAlign, (), (override)); + MOCK_METHOD(Status, Resume, (), (override)); + MOCK_METHOD(Status, ResumeDragging, (), (override)); + MOCK_METHOD(Status, ResumeAudioAlign, (), (override)); + MOCK_METHOD(Status, Flush, (), (override)); + MOCK_METHOD(Status, Preroll, (), (override)); + MOCK_METHOD(Status, PausePreroll, (), (override)); + + MOCK_METHOD(Status, StartTask, (int32_t trackId), (override)); + MOCK_METHOD(Status, SelectTrack, (int32_t trackId), (override)); + MOCK_METHOD(Status, UnselectTrack, (int32_t trackId), (override)); + MOCK_METHOD(Status, ReadSample, (uint32_t trackId, std::shared_ptr sample), (override)); + MOCK_METHOD(Status, GetBitRates, (std::vector &bitRates), (override)); + MOCK_METHOD(Status, SelectBitRate, (uint32_t bitRate), (override)); + MOCK_METHOD(Status, GetMediaKeySystemInfo, ((std::multimap>) &infos), (override)); + MOCK_METHOD(void, SetDrmCallback, (const std::shared_ptr &callback), + (override)); + MOCK_METHOD(void, OnEvent, (const Plugins::PluginEvent &event), (override)); + + MOCK_METHOD((std::map>), GetBufferQueueProducerMap, (), (override)); + MOCK_METHOD(Status, PauseTaskByTrackId, (int32_t trackId), (override)); + MOCK_METHOD(bool, IsRenderNextVideoFrameSupported, (), (override)); + + MOCK_METHOD(void, SetEventReceiver, (const std::shared_ptr &receiver), (override)); + MOCK_METHOD(bool, GetDuration, (int64_t& durationMs), (override)); + MOCK_METHOD(void, SetPlayerId, (const std::string &playerId), (override)); + MOCK_METHOD(void, OnInterrupted, (bool isInterruptNeeded), (override)); + MOCK_METHOD(void, SetDumpInfo, (bool isDump, uint64_t instanceId), (override)); + + MOCK_METHOD(Status, OptimizeDecodeSlow, (bool isDecodeOptimizationEnabled), (override)); + MOCK_METHOD(Status, SetDecoderFramerateUpperLimit, (int32_t decoderFramerateUpperLimit, uint32_t trackId), + (override)); + MOCK_METHOD(Status, SetSpeed, (float speed), (override)); + MOCK_METHOD(Status, SetFrameRate, (double frameRate, uint32_t trackId), (override)); + + MOCK_METHOD(bool, IsLocalDrmInfosExisted, (), (override)); + MOCK_METHOD(void, OnBufferAvailable, (uint32_t trackId), (override)); + MOCK_METHOD(void, SetSelectBitRateFlag, (bool flag, uint32_t desBitRate), (override)); + MOCK_METHOD(bool, CanAutoSelectBitRate, (), (override)); + MOCK_METHOD(void, OnDumpInfo, (int32_t fd), (override)); + + MOCK_METHOD(Status, StartReferenceParser, (int64_t startTimeMs, bool isForward), (override)); + MOCK_METHOD(Status, GetFrameLayerInfo, (std::shared_ptr videoSample, + FrameLayerInfo &frameLayerInfo), (override)); + MOCK_METHOD(Status, GetFrameLayerInfo, (uint32_t frameId, FrameLayerInfo &frameLayerInfo), (override)); + MOCK_METHOD(Status, GetGopLayerInfo, (uint32_t gopId, GopLayerInfo &gopLayerInfo), (override)); + MOCK_METHOD(bool, IsVideoEos, (), (override)); + MOCK_METHOD(bool, HasEosTrack, (), (override)); + MOCK_METHOD(Status, GetIFramePos, (std::vector &IFramePos), (override)); + MOCK_METHOD(Status, Dts2FrameId, (int64_t dts, uint32_t &frameId, bool offset), (override)); + MOCK_METHOD(void, RegisterVideoStreamReadyCallback, + (const std::shared_ptr &callback), (override)); + MOCK_METHOD(void, DeregisterVideoStreamReadyCallback, (), (override)); + + MOCK_METHOD(Status, GetIndexByRelativePresentationTimeUs, (const uint32_t trackIndex, + const uint64_t relativePresentationTimeUs, uint32_t &index), (override)); + MOCK_METHOD(Status, GetRelativePresentationTimeUsByIndex, (const uint32_t trackIndex, + const uint32_t index, uint64_t &relativePresentationTimeUs), (override)); + + MOCK_METHOD(Status, ResumeDemuxerReadLoop, (), (override)); + MOCK_METHOD(Status, PauseDemuxerReadLoop, (), (override)); + MOCK_METHOD(void, SetCacheLimit, (uint32_t limitSize), (override)); + MOCK_METHOD(void, WaitForBufferingEnd, (), (override)); + MOCK_METHOD(void, SetEnableOnlineFdCache, (bool isEnableFdCache), (override)); +}; +} // namespace Media +} // namespace OHOS +#endif // MOCK_MEDIA_DEMUXER_H \ No newline at end of file diff --git a/test/unittest/avmetadatahelper_test/avmetadatahelper_impl_unit_test.cpp b/test/unittest/avmetadatahelper_test/avmetadatahelper_impl_unit_test.cpp index 12321b5476e1a69b9ffdcc9cf6b1e2534e614973..a021ff6dc66dc86cbfdf3866a184281bf00ef982 100644 --- a/test/unittest/avmetadatahelper_test/avmetadatahelper_impl_unit_test.cpp +++ b/test/unittest/avmetadatahelper_test/avmetadatahelper_impl_unit_test.cpp @@ -73,6 +73,24 @@ bool MediaClient::CanKillMediaService() void MediaClient::ReleaseClientListener() {} +std::vector MediaClient::GetPlayerPids() +{ + std::vector ret; + return ret; +} + +int32_t MediaClient::ProxyForFreeze(const std::set &pidList, bool isProxy) +{ + (void) pidList; + (void) isProxy; + return 0; +} + +int32_t MediaClient::ResetAllProxy() +{ + return 0; +} + namespace Test { void AVMetadtahelperImplUnitTest::SetUpTestCase(void) {} diff --git a/test/unittest/avmetadatahelper_test/avmetadatahelper_server_unit_test.cpp b/test/unittest/avmetadatahelper_test/avmetadatahelper_server_unit_test.cpp index c1a1a4af4da08bdde3114684607af1b122bbc52e..25bc49067e65e8ff805b6c937d6e11a3d4a7b866 100644 --- a/test/unittest/avmetadatahelper_test/avmetadatahelper_server_unit_test.cpp +++ b/test/unittest/avmetadatahelper_test/avmetadatahelper_server_unit_test.cpp @@ -121,6 +121,17 @@ HWTEST_F(AVMetadataHelperServerUnitTest, GetStatusDescription, TestSize.Level1) avmetadataHelperServer_->GetStatusDescription(status); EXPECT_EQ(avmetadataHelperServer_->isLiveStream_, false); } + +/** + * @tc.name: MediaTrace + * @tc.desc: MediaTrace + * @tc.type: FUNC + */ +HWTEST_F(AVMetadataHelperServerUnitTest, MediaTrace, TestSize.Level1) +{ + MediaTrace trace("AVMetadataHelperServer::Test", HITRACE_LEVEL_CRITICAL); + EXPECT_EQ(HITRACE_LEVEL_CRITICAL, trace.level_); +} } // namespace Test } // namespace Media } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/hiplayer_impl_test/hiplayer_impl_unit_test.cpp b/test/unittest/hiplayer_impl_test/hiplayer_impl_unit_test.cpp index 5663cef1fc6e4a6b90b0748fdf8e7e2730766c94..3d32fd012a01d7226a971f979b8a0efa6618c184 100644 --- a/test/unittest/hiplayer_impl_test/hiplayer_impl_unit_test.cpp +++ b/test/unittest/hiplayer_impl_test/hiplayer_impl_unit_test.cpp @@ -1427,7 +1427,6 @@ HWTEST_F(HiplayerImplUnitTest, IsNeedChangePlaySpeed_003, TestSize.Level0) hiplayer_->maxLivingDelayTime_ = -1; EXPECT_FALSE(hiplayer_->IsNeedChangePlaySpeed(mode, isXSpeedPlay)); EXPECT_EQ(mode, PlaybackRateMode::SPEED_FORWARD_1_20_X); - EXPECT_EQ(isXSpeedPlay, true); } /** diff --git a/test/unittest/hiplayer_impl_test/mock/mock_iplayer_engine.h b/test/unittest/hiplayer_impl_test/mock/mock_iplayer_engine.h index e93064c1daf70f20ea43e19200c1626e0b74a6dd..5385602e391c3d43984eb60e1f981c17c58b2294 100644 --- a/test/unittest/hiplayer_impl_test/mock/mock_iplayer_engine.h +++ b/test/unittest/hiplayer_impl_test/mock/mock_iplayer_engine.h @@ -58,6 +58,8 @@ public: MOCK_METHOD(int32_t, Pause, (bool isSystemOperation), ()); MOCK_METHOD(int32_t, Stop, (), ()); MOCK_METHOD(int32_t, Reset, (), ()); + MOCK_METHOD(int32_t, Freeze, (), ()); + MOCK_METHOD(int32_t, UnFreeze, (), ()); MOCK_METHOD(int32_t, SetVolume, (float leftVolume, float rightVolume), ()); MOCK_METHOD(int32_t, SetVolumeMode, (int32_t mode), ()); MOCK_METHOD(int32_t, Seek, (int32_t mSeconds, PlayerSeekMode mode), ()); diff --git a/test/unittest/hiplayer_impl_unittest/hiplayer_impl_unittest.cpp b/test/unittest/hiplayer_impl_unittest/hiplayer_impl_unittest.cpp index 7c288520db9c86083923221e186b8538693109f3..f8bda1772b1244517a0efa8c9a7020b9f4ea38f9 100644 --- a/test/unittest/hiplayer_impl_unittest/hiplayer_impl_unittest.cpp +++ b/test/unittest/hiplayer_impl_unittest/hiplayer_impl_unittest.cpp @@ -445,5 +445,269 @@ HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_SetSeiMessageListener_001, TestSize.Lev Status ret = hiplayer_->SetSeiMessageListener(); EXPECT_NE(ret, Status::OK); } + +// @tc.name Test IsInValidSeekTime API +// @tc.number PHIUT_IsInValidSeekTime_001 +// @tc.desc Test if (seekTime > endTimeWithMode_) +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_IsInValidSeekTime_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + hiplayer_->endTimeWithMode_ = 0; + hiplayer_->startTimeWithMode_ = -1; + int32_t seekPos = 1; + auto mockPipeline = std::make_shared(); + EXPECT_CALL(*mockPipeline, SetPlayRange(_,_)).WillRepeatedly(Return(Status::OK)); + hiplayer_->pipeline_ = mockPipeline; + auto ret = hiplayer_->IsInValidSeekTime(seekPos); + EXPECT_EQ(ret, false); +} + +// @tc.name Test AddSubSource API +// @tc.number PHIUT_AddSubSource_001 +// @tc.desc Test if (result != MSERR_OK) +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_AddSubSource_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + std::string uriTest = "file:///path/../testfile.txt"; + auto ret = hiplayer_->AddSubSource(uriTest); + EXPECT_NE(ret, 0); +} + +// @tc.name Test SetStartFrameRateOptEnabled API +// @tc.number PHIUT_SetStartFrameRateOptEnabled_001 +// @tc.desc Test all +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_SetStartFrameRateOptEnabled_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + bool enabled = true; + auto ret = hiplayer_->SetStartFrameRateOptEnabled(enabled); + EXPECT_EQ(ret, 0); + EXPECT_EQ(hiplayer_->isEnableStartFrameRateOpt_, true); +} + +// @tc.name Test SetInterruptState API +// @tc.number PHIUT_SetInterruptState_001 +// @tc.desc Test if (isFlvLive_ && bufferDurationForPlaying_ > 0) +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_SetInterruptState_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + bool isInterruptNeeded = false; + hiplayer_->interruptMonitor_ = nullptr; + hiplayer_->isDrmProtected_ = false; + hiplayer_->isFlvLive_ = true; + hiplayer_->bufferDurationForPlaying_ = 1; + hiplayer_->SetInterruptState(isInterruptNeeded); + EXPECT_EQ(hiplayer_->isInterruptNeeded_, false); +} + +// @tc.name Test SelectBitRate API +// @tc.number PHIUT_SelectBitRate_002 +// @tc.desc Test return MSERR_INVALID_OPERATION; +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_SelectBitRate_002, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + std::string name = "testname"; + FilterType type = FilterType::VIDEO_CAPTURE; + auto mockDemuxer = std::make_shared(name, type); + EXPECT_CALL(*mockDemuxer, SelectBitRate(_,_)).WillRepeatedly(Return(Status::ERROR_INVALID_OPERATION)); + hiplayer_->demuxer_ = mockDemuxer; + uint32_t bitRate = 0; + bool isAutoSelect = false; + auto ret = hiplayer_->SelectBitRate(bitRate, isAutoSelect); + EXPECT_NE(ret, 0); +} + +// @tc.name Test DoInitializeForHttp API +// @tc.number PHIUT_DoInitializeForHttp_002 +// @tc.desc Test if (ret == Status::OK && vBitRates.size() > 0) +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_DoInitializeForHttp_002, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + std::string name = "testname"; + FilterType type = FilterType::VIDEO_CAPTURE; + auto mockDemuxer = std::make_shared(name, type); + EXPECT_CALL(*mockDemuxer, GetBitRates(_)).WillRepeatedly(Invoke([](std::vector vBitRates) { + vBitRates.push_back(1); + return Status::OK; + })); + hiplayer_->demuxer_ = mockDemuxer; + hiplayer_->isNetWorkPlay_ = false; + hiplayer_->DoInitializeForHttp(); + EXPECT_EQ(hiplayer_->isInterruptNeeded_, false); +} + +// @tc.name Test SetVolumeMode API +// @tc.number PHIUT_SetVolumeMode_002 +// @tc.desc Test if (ret != Status::OK) +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_SetVolumeMode_002, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + int32_t mode = 10; + std::string name = "testname"; + auto mockAudioSink = std::make_shared(name, FilterType::VIDEO_CAPTURE); + EXPECT_CALL(*mockAudioSink, SetVolumeMode(_)).WillRepeatedly(Return(Status::ERROR_NULL_POINTER)); + hiplayer_->audioSink_ = mockAudioSink; + auto ret = hiplayer_->SetVolumeMode(mode); + EXPECT_EQ(ret, 0); +} + +// @tc.name Test InnerSelectTrack API +// @tc.number PHIUT_InnerSelectTrack_001 +// @tc.desc Test if (IsSubtitleMime(mime))else if (IsVideoMime(mime)) +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_InnerSelectTrack_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + std::string name = "testname"; + FilterType type = FilterType::VIDEO_CAPTURE; + auto mockDemuxer = std::make_shared(name, type); + EXPECT_CALL(*mockDemuxer, SelectTrack(_)).WillRepeatedly(Return(Status::OK)); + hiplayer_->demuxer_ = mockDemuxer; + std::string mime = "text/vtt"; + int32_t trackId = 1; + PlayerSwitchMode mode = PlayerSwitchMode::SWITCH_SEGMENT; + hiplayer_->InnerSelectTrack(mime, trackId, mode); +} + +// @tc.name Test InnerSelectTrack API +// @tc.number PHIUT_InnerSelectTrack_002 +// @tc.desc Test mode == PlayerSwitchMode::SWITCH_SEGMENT & mode == PlayerSwitchMode::SWITCH_CLOSEST +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_InnerSelectTrack_002, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + std::string name = "testname"; + FilterType type = FilterType::VIDEO_CAPTURE; + auto mockDemuxer = std::make_shared(name, type); + EXPECT_CALL(*mockDemuxer, SelectTrack(_)).WillRepeatedly(Return(Status::OK)); + hiplayer_->demuxer_ = mockDemuxer; + std::string mime = "video/test"; + int32_t trackId = 1; + PlayerSwitchMode mode = PlayerSwitchMode::SWITCH_SEGMENT; + hiplayer_->curState_ = PlayerStateId::EOS; + auto ret = hiplayer_->InnerSelectTrack(mime, trackId, mode); + EXPECT_NE(ret, MSERR_OK); + mode = PlayerSwitchMode::SWITCH_CLOSEST; + ret = hiplayer_->InnerSelectTrack(mime, trackId, mode); + EXPECT_NE(ret, MSERR_OK); +} + +// @tc.name Test SelectTrack API +// @tc.number PHIUT_SelectTrack_001 +// @tc.desc Test return MSERR_UNKNOWN; +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_SelectTrack_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + std::shared_ptr meta1 = std::make_shared(); + meta1->SetData(Tag::MIME_TYPE, "test/invailed"); + std::vector> metaInfo; + metaInfo.push_back(meta1); + std::string name = "testname"; + FilterType type = FilterType::VIDEO_CAPTURE; + auto mockDemuxer = std::make_shared(name, type); + EXPECT_CALL(*mockDemuxer, GetStreamMetaInfo()).WillRepeatedly(Return(metaInfo)); + hiplayer_->demuxer_ = mockDemuxer; + int32_t trackId = 0; + PlayerSwitchMode mode = PlayerSwitchMode::SWITCH_SEGMENT; + auto ret = hiplayer_->SelectTrack(trackId, mode); + EXPECT_NE(ret, MSERR_OK); +} + +// @tc.name Test GetSubtitleTrackInfo API +// @tc.number PHIUT_GetSubtitleTrackInfo_001 +// @tc.desc Test !(trackInfo->GetData(Tag::MIME_TYPE, mime))||mime.find("invalid") == 0)if(IsSubtitleMime(mime)) +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_GetSubtitleTrackInfo_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + std::shared_ptr meta1 = std::make_shared(); + meta1->SetData(Tag::MIME_TYPE, "test/invailed"); + std::shared_ptr meta2 = std::make_shared(); + meta2->SetData(Tag::MIME_TYPE, "text/vtt"); + std::vector> metaInfo; + metaInfo.push_back(meta2); + metaInfo.push_back(meta1); + std::string name = "testname"; + FilterType type = FilterType::VIDEO_CAPTURE; + auto mockDemuxer = std::make_shared(name, type); + EXPECT_CALL(*mockDemuxer, GetStreamMetaInfo()).WillRepeatedly(Return(metaInfo)); + hiplayer_->demuxer_ = mockDemuxer; + std::vector subtitleTrack; + auto ret = hiplayer_->GetSubtitleTrackInfo(subtitleTrack); + EXPECT_EQ(ret, MSERR_OK); +} + +// @tc.name Test HandleAudioTrackChangeEvent API +// @tc.number PHIUT_HandleAudioTrackChangeEvent_001 +// @tc.desc Test if (!(metaInfo[trackId]->GetData(Tag::MIME_TYPE, mime))) +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_HandleAudioTrackChangeEvent_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + std::shared_ptr meta1 = std::make_shared(); + std::vector> metaInfo; + metaInfo.push_back(meta1); + Event event; + event.param = 0; + std::string name = "testname"; + FilterType type = FilterType::VIDEO_CAPTURE; + auto mockDemuxer = std::make_shared(name, type); + EXPECT_CALL(*mockDemuxer, GetStreamMetaInfo()).WillRepeatedly(Return(metaInfo)); + hiplayer_->demuxer_ = mockDemuxer; + hiplayer_->HandleAudioTrackChangeEvent(event); + EXPECT_NE(metaInfo.size(), 0); +} + +// @tc.name Test HandleVideoTrackChangeEvent API +// @tc.number PHIUT_HandleAudioTrackChangeEvent_002 +// @tc.desc Test if (Status::OK != demuxer_->StartTask(trackId)) +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_HandleAudioTrackChangeEvent_002, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + std::shared_ptr meta1 = std::make_shared(); + meta1->SetData(Tag::MIME_TYPE, "video/test"); + std::vector> metaInfo; + metaInfo.push_back(meta1); + Event event; + event.param = 0; + std::string name = "testname"; + FilterType type = FilterType::VIDEO_CAPTURE; + auto mockDemuxer = std::make_shared(name, type); + EXPECT_CALL(*mockDemuxer, GetStreamMetaInfo()).WillRepeatedly(Return(metaInfo)); + EXPECT_CALL(*mockDemuxer, StartTask(_)).WillRepeatedly(Return(Status::ERROR_INVALID_OPERATION)); + hiplayer_->demuxer_ = mockDemuxer; + hiplayer_->HandleVideoTrackChangeEvent(event); +} + +// @tc.name Test HandleSubtitleTrackChangeEvent API +// @tc.number PHIUT_HandleSubtitleTrackChangeEvent_001 +// @tc.desc Test if (!(metaInfo[trackId]->GetData(Tag::MIME_TYPE, mime))) +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_HandleSubtitleTrackChangeEvent_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + std::shared_ptr meta1 = std::make_shared(); + std::vector> metaInfo; + metaInfo.push_back(meta1); + Event event; + event.param = 0; + std::string name = "testname"; + FilterType type = FilterType::VIDEO_CAPTURE; + auto mockDemuxer = std::make_shared(name, type); + EXPECT_CALL(*mockDemuxer, GetStreamMetaInfo()).WillRepeatedly(Return(metaInfo)); + EXPECT_CALL(*mockDemuxer, StartTask(_)).WillRepeatedly(Return(Status::ERROR_INVALID_OPERATION)); + hiplayer_->demuxer_ = mockDemuxer; + hiplayer_->HandleSubtitleTrackChangeEvent(event); +} + +// @tc.name Test OnCallback API +// @tc.number PHIUT_OnCallback_002 +// @tc.desc Test default +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_OnCallback_002, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + std::string name = "testname"; + auto mockFilter = std::make_shared(); + std::shared_ptr filter = mockFilter; + FilterCallBackCommand cmd = FilterCallBackCommand::NEXT_FILTER_NEEDED; + StreamType outType = StreamType::STREAMTYPE_MAX; + auto ret = hiplayer_->OnCallback(filter, cmd, outType); + EXPECT_EQ(ret, Status::OK); +} } // namespace Media } // namespace OHOS diff --git a/test/unittest/hiplayer_impl_unittest/hiplayer_impl_unittest.h b/test/unittest/hiplayer_impl_unittest/hiplayer_impl_unittest.h index 322b965f5894e5c26111dfe503bb5de7463abbff..e6353314a557d1072a297649c74a32e2e638e88d 100644 --- a/test/unittest/hiplayer_impl_unittest/hiplayer_impl_unittest.h +++ b/test/unittest/hiplayer_impl_unittest/hiplayer_impl_unittest.h @@ -186,6 +186,254 @@ private: MOCK_METHOD(int64_t, GetSystimeTimeNs, (), ()); MOCK_METHOD(bool, IsPostProcessorSupported, (), ()); }; +class MockPipeline : public OHOS::Media::Pipeline::Pipeline { +public: + MOCK_METHOD(void, Init, (const std::shared_ptr& receiver, + const std::shared_ptr& callback, const std::string& groupId), ()); + MOCK_METHOD(Status, Prepare, (), ()); + MOCK_METHOD(Status, Start, (), ()); + MOCK_METHOD(Status, Pause, (), ()); + MOCK_METHOD(Status, Resume, (), ()); + MOCK_METHOD(Status, Stop, (), ()); + MOCK_METHOD(Status, Flush, (), ()); + MOCK_METHOD(Status, Release, (), ()); + MOCK_METHOD(Status, Preroll, (bool render), ()); + MOCK_METHOD(Status, SetPlayRange, (int64_t start, int64_t end), ()); + MOCK_METHOD(Status, AddHeadFilters, (std::vector> filters), ()); + MOCK_METHOD(Status, RemoveHeadFilter, (const std::shared_ptr& filter), ()); + MOCK_METHOD(Status, LinkFilters, (const std::shared_ptr& preFilter, + const std::vector>& filters, StreamType type, bool needTurbo), ()); + MOCK_METHOD(Status, UpdateFilters, (const std::shared_ptr& preFilter, + const std::vector>& filters, StreamType type), ()); + MOCK_METHOD(Status, UnLinkFilters, (const std::shared_ptr& preFilter, + const std::vector>& filters, StreamType type), ()); + MOCK_METHOD(void, OnEvent, (const Event& event), ()); + ~MockPipeline() = default; +}; +class MockMediaSource : public Plugins::MediaSource { +public: + explicit MockMediaSource(std::string uri) : MediaSource(std::move(uri)) {} + MockMediaSource(std::string uri, std::map header) + : MediaSource(std::move(uri), std::move(header)) {} + explicit MockMediaSource(std::shared_ptr dataSrc) + : MediaSource(std::move(dataSrc)) {} + ~MockMediaSource() = default; + MOCK_CONST_METHOD0(GetSourceType, SourceType()); + MOCK_CONST_METHOD0(GetSourceUri, const std::string&()); + MOCK_CONST_METHOD0(GetSourceHeader, const std::map&()); + MOCK_CONST_METHOD0(GetMediaStreamList, MediaStreamList()); + MOCK_CONST_METHOD0(GetPlayStrategy, std::shared_ptr()); + MOCK_CONST_METHOD0(GetMimeType, std::string()); + MOCK_CONST_METHOD0(GetAppUid, int32_t()); + MOCK_CONST_METHOD0(GetSourceLoader, std::shared_ptr()); + MOCK_CONST_METHOD0(GetDataSrc, std::shared_ptr()); + MOCK_METHOD(void, AddMediaStream, (const std::shared_ptr& playMediaStream)); + MOCK_METHOD(void, SetPlayStrategy, (const std::shared_ptr& playStrategy)); + MOCK_METHOD(void, SetMimeType, (const std::string& mimeType)); + MOCK_METHOD(void, SetAppUid, (int32_t appUid)); + MOCK_METHOD(void, SetSourceLoader, (std::shared_ptr mediaSourceLoader)); +}; +class MockDemuxerFilter : public DemuxerFilter { +public: + explicit MockDemuxerFilter(std::string name, FilterType type):DemuxerFilter(name, type) {} + ~MockDemuxerFilter() = default; + + MOCK_METHOD(void, Init, (const std::shared_ptr &receiver, + const std::shared_ptr &callback), ()); + MOCK_METHOD(void, Init, (const std::shared_ptr &receiver, + const std::shared_ptr &callback, const std::shared_ptr& monitor), ()); + MOCK_METHOD(Status, DoPrepare, (), ()); + MOCK_METHOD(Status, DoStart, (), ()); + MOCK_METHOD(Status, DoStop, (), ()); + MOCK_METHOD(Status, DoPause, (), ()); + MOCK_METHOD(Status, DoPauseDragging, (), ()); + MOCK_METHOD(Status, DoPauseAudioAlign, (), ()); + MOCK_METHOD(Status, DoResume, (), ()); + MOCK_METHOD(Status, DoResumeDragging, (), ()); + MOCK_METHOD(Status, DoResumeAudioAlign, (), ()); + MOCK_METHOD(Status, DoFlush, (), ()); + MOCK_METHOD(Status, DoPreroll, (), ()); + MOCK_METHOD(Status, DoWaitPrerollDone, (bool render), ()); + MOCK_METHOD(Status, DoSetPerfRecEnabled, (bool isPerfRecEnabled), ()); + MOCK_METHOD(Status, Reset, (), ()); + MOCK_METHOD(Status, PauseForSeek, (), ()); + MOCK_METHOD(Status, ResumeForSeek, (), ()); + MOCK_METHOD(Status, PrepareBeforeStart, (), ()); + MOCK_METHOD(void, SetParameter, (const std::shared_ptr ¶meter), ()); + MOCK_METHOD(void, GetParameter, (std::shared_ptr ¶meter), ()); + MOCK_METHOD(Status, SetTranscoderMode, (), ()); + MOCK_METHOD(Status, SetDataSource, (const std::shared_ptr source), ()); + MOCK_METHOD(Status, SetSubtitleSource, (const std::shared_ptr source), ()); + MOCK_METHOD(void, SetBundleName, (const std::string& bundleName), ()); + MOCK_METHOD(Status, SeekTo, (int64_t seekTime, Plugins::SeekMode mode, int64_t& realSeekTime), ()); + MOCK_METHOD(bool, IsRefParserSupported, (), ()); + MOCK_METHOD(Status, StartReferenceParser, (int64_t startTimeMs, bool isForward), ()); + MOCK_METHOD(Status, GetFrameLayerInfo, + (std::shared_ptr videoSample, FrameLayerInfo &frameLayerInfo), ()); + MOCK_METHOD(Status, GetFrameLayerInfo, (uint32_t frameId, FrameLayerInfo &frameLayerInfo), ()); + MOCK_METHOD(Status, GetGopLayerInfo, (uint32_t gopId, GopLayerInfo &gopLayerInfo), ()); + MOCK_METHOD(Status, GetIFramePos, (std::vector &IFramePos), ()); + MOCK_METHOD(Status, Dts2FrameId, (int64_t dts, uint32_t &frameId), ()); + MOCK_METHOD(Status, SeekMs2FrameId, (int64_t seekMs, uint32_t &frameId), ()); + MOCK_METHOD(Status, FrameId2SeekMs, (uint32_t frameId, int64_t &seekMs), ()); + MOCK_METHOD(Status, StartTask, (int32_t trackId), ()); + MOCK_METHOD(Status, SelectTrack, (int32_t trackId), ()); + MOCK_METHOD(std::vector>, GetStreamMetaInfo, (), (const)); + MOCK_METHOD(std::shared_ptr, GetGlobalMetaInfo, (), (const)); + MOCK_METHOD(Status, LinkNext, (const std::shared_ptr &nextFilter, StreamType outType), ()); + MOCK_METHOD(Status, UpdateNext, (const std::shared_ptr &nextFilter, StreamType outType), ()); + MOCK_METHOD(Status, UnLinkNext, (const std::shared_ptr &nextFilter, StreamType outType), ()); + MOCK_METHOD(Status, GetBitRates, (std::vector& bitRates), ()); + MOCK_METHOD(Status, SelectBitRate, (uint32_t bitRate, bool isAutoSelect), ()); + MOCK_METHOD(Status, StopBufferring, (bool flag), ()); + MOCK_METHOD(Status, GetDownloadInfo, (DownloadInfo& downloadInfo), ()); + MOCK_METHOD(Status, GetPlaybackInfo, (PlaybackInfo& playbackInfo), ()); + MOCK_METHOD(FilterType, GetFilterType, (), ()); + MOCK_METHOD(void, OnLinkedResult, + (const sptr &outputBufferQueue, std::shared_ptr &meta), ()); + MOCK_METHOD(void, OnUpdatedResult, (std::shared_ptr &meta), ()); + MOCK_METHOD(void, OnUnlinkedResult, (std::shared_ptr &meta), ()); + MOCK_METHOD(Status, PauseTaskByTrackId, (int32_t trackId), ()); + MOCK_METHOD(bool, IsRenderNextVideoFrameSupported, (), ()); + MOCK_METHOD(bool, IsDrmProtected, (), ()); + MOCK_METHOD(void, OnDrmInfoUpdated, ((const std::multimap>) &drmInfo), ()); + MOCK_METHOD(bool, GetDuration, (int64_t& durationMs), ()); + MOCK_METHOD(Status, OptimizeDecodeSlow, (bool isDecodeOptimizationEnabled), ()); + MOCK_METHOD(Status, SetSpeed, (float speed), ()); + MOCK_METHOD(void, SetDumpFlag, (bool isdump), ()); + MOCK_METHOD(void, OnDumpInfo, (int32_t fd), ()); + MOCK_METHOD(void, SetCallerInfo, (uint64_t instanceId, const std::string& appName), ()); + MOCK_METHOD(bool, IsVideoEos, (), ()); + MOCK_METHOD(bool, HasEosTrack, (), ()); + MOCK_METHOD(Status, DisableMediaTrack, (Plugins::MediaType mediaType), ()); + MOCK_METHOD(void, RegisterVideoStreamReadyCallback, + (const std::shared_ptr &callback), ()); + MOCK_METHOD(void, DeregisterVideoStreamReadyCallback, (), ()); + MOCK_METHOD(Status, ResumeDemuxerReadLoop, (), ()); + MOCK_METHOD(Status, PauseDemuxerReadLoop, (), ()); + MOCK_METHOD(void, WaitForBufferingEnd, (), ()); + MOCK_METHOD(int32_t, GetCurrentVideoTrackId, (), ()); + MOCK_METHOD(void, SetSyncCenter, (std::shared_ptr syncCenter), ()); + MOCK_METHOD(void, SetIsNotPrepareBeforeStart, (bool isNotPrepareBeforeStart), ()); + MOCK_METHOD(void, SetIsEnableReselectVideoTrack, (bool isEnable), ()); + MOCK_METHOD(void, SetApiVersion, (int32_t apiVersion), ()); + MOCK_METHOD(bool, IsLocalFd, (), ()); + MOCK_METHOD(bool, IsFlvLiveStream, (), ()); + MOCK_METHOD(Status, RebootPlugin, (), ()); + MOCK_METHOD(uint64_t, GetCachedDuration, (), ()); + MOCK_METHOD(void, RestartAndClearBuffer, (), ()); + MOCK_METHOD(bool, IsFlvLive, (), ()); + MOCK_METHOD(Status, OnLinked, (StreamType inType, const std::shared_ptr &meta, + const std::shared_ptr &callback), ()); + MOCK_METHOD(Status, OnUpdated, (StreamType inType, const std::shared_ptr &meta, + const std::shared_ptr &callback), ()); + MOCK_METHOD(Status, OnUnLinked, + (StreamType inType, const std::shared_ptr& callback), ()); + MOCK_METHOD(bool, FindTrackId, (StreamType outType, int32_t &trackId), ()); + MOCK_METHOD(bool, FindStreamType, (StreamType &streamType, Plugins::MediaType mediaType, + std::string mime, size_t index, std::shared_ptr &meta), ()); + MOCK_METHOD(bool, ShouldTrackSkipped, (Plugins::MediaType mediaType, std::string mime, size_t index), ()); + MOCK_METHOD(void, UpdateTrackIdMap, (StreamType streamType, int32_t index), ()); + MOCK_METHOD(Status, FaultDemuxerEventInfoWrite, (StreamType& streamType), ()); + MOCK_METHOD(bool, IsVideoMime, (const std::string& mime), ()); + MOCK_METHOD(bool, IsAudioMime, (const std::string& mime), ()); + MOCK_METHOD(bool, CheckIsBigendian, (std::shared_ptr &meta), ()); + MOCK_METHOD(Status, HandleTrackInfos, + (const std::vector> &trackInfos, int32_t &successNodeCount), ()); + MOCK_METHOD(std::string, CollectVideoAndAudioMime, (), ()); +}; +class MockAudioSinkFilter : public AudioSinkFilter { +public: + explicit MockAudioSinkFilter(const std::string& name, + FilterType filterType = FilterType::FILTERTYPE_ASINK):AudioSinkFilter(name, filterType) {} + ~MockAudioSinkFilter() = default; + MOCK_METHOD(void, Init, (const std::shared_ptr &receiver, + const std::shared_ptr &callback), ()); + MOCK_METHOD(void, Init, (const std::shared_ptr &receiver, + const std::shared_ptr &callback, const std::shared_ptr &monitor), + ()); + MOCK_METHOD(Status, DoInitAfterLink, (), ()); + MOCK_METHOD(Status, DoPrepare, (), ()); + MOCK_METHOD(Status, DoStart, (), ()); + MOCK_METHOD(Status, DoPause, (), ()); + MOCK_METHOD(Status, DoResume, (), ()); + MOCK_METHOD(Status, DoFlush, (), ()); + MOCK_METHOD(Status, DoStop, (), ()); + MOCK_METHOD(Status, DoRelease, (), ()); + MOCK_METHOD(Status, DoSetPlayRange, (int64_t start, int64_t end), ()); + MOCK_METHOD(Status, DoProcessInputBuffer, (int recvArg, bool dropFrame), ()); + MOCK_METHOD(void, SetParameter, (const std::shared_ptr& meta), ()); + MOCK_METHOD(void, GetParameter, (std::shared_ptr& meta), ()); + MOCK_METHOD(Status, OnLinked, (StreamType inType, const std::shared_ptr& meta, + const std::shared_ptr& callback), ()); + MOCK_METHOD(Status, DoSetPerfRecEnabled, (bool isPerfRecEnabled), ()); + MOCK_METHOD(Status, SetVolume, (float volume), ()); + MOCK_METHOD(Status, SetVolumeMode, (int32_t mode), ()); + MOCK_METHOD(void, SetSyncCenter, (std::shared_ptr syncCenter), ()); + MOCK_METHOD(Status, SetSpeed, (float speed), ()); + MOCK_METHOD(int32_t, SetVolumeWithRamp, (float targetVolume, int32_t duration), ()); + MOCK_METHOD(Status, SetAudioEffectMode, (int32_t effectMode), ()); + MOCK_METHOD(Status, GetAudioEffectMode, (int32_t &effectMode), ()); + MOCK_METHOD(Status, SetIsTransitent, (bool isTransitent), ()); + MOCK_METHOD(Status, ChangeTrack, (std::shared_ptr& meta), ()); + MOCK_METHOD(Status, SetMuted, (bool isMuted), ()); + MOCK_METHOD(Status, SetSeekTime, (int64_t seekTime), ()); + MOCK_METHOD(float, GetMaxAmplitude, (), ()); + MOCK_METHOD(int32_t, SetMaxAmplitudeCbStatus, (bool status), ()); + MOCK_METHOD(void, SetIsCancelStart, (bool isCancelStart), ()); + MOCK_METHOD(bool, NeedImmediateRender, (), ()); + MOCK_METHOD(Status, SetIsCalledBySystemApp, (bool isCalledBySystemApp), ()); + MOCK_METHOD(Status, SetLooping, (bool loop), ()); + + protected: + MOCK_METHOD(Status, OnUpdated, (StreamType inType, const std::shared_ptr& meta, + const std::shared_ptr& callback), ()); + MOCK_METHOD(Status, OnUnLinked, (StreamType inType, + const std::shared_ptr& callback), ()); +}; +class MockAudioDecoderFilter : public AudioDecoderFilter { +public: + explicit MockAudioDecoderFilter(std::string name, FilterType type):AudioDecoderFilter(name, type) {} + ~MockAudioDecoderFilter() = default; + MOCK_METHOD(Status, DoPrepare, (), ()); + MOCK_METHOD(Status, DoStart, (), ()); + MOCK_METHOD(Status, DoPause, (), ()); + MOCK_METHOD(Status, DoPauseAudioAlign, (), ()); + MOCK_METHOD(Status, DoResume, (), ()); + MOCK_METHOD(Status, DoResumeAudioAlign, (), ()); + MOCK_METHOD(Status, DoStop, (), ()); + MOCK_METHOD(Status, DoFlush, (), ()); + MOCK_METHOD(Status, DoRelease, (), ()); + MOCK_METHOD(void, SetParameter, (const std::shared_ptr& parameter), ()); + MOCK_METHOD(void, SetDumpFlag, (bool isDump), ()); + MOCK_METHOD(void, GetParameter, (std::shared_ptr& parameter), ()); + MOCK_METHOD(Status, LinkNext, (const std::shared_ptr& nextFilter, StreamType outType), ()); + MOCK_METHOD(Status, UpdateNext, (const std::shared_ptr& nextFilter, StreamType outType), ()); + MOCK_METHOD(Status, UnLinkNext, (const std::shared_ptr& nextFilter, StreamType outType), ()); + MOCK_METHOD(void, OnInterrupted, (bool isInterruptNeeded), ()); + MOCK_METHOD(Status, DoProcessInputBuffer, (int recvArg, bool dropFrame), ()); + MOCK_METHOD(Status, HandleInputBuffer, (bool isTriggeredByOutPort), ()); + MOCK_METHOD(Status, ChangePlugin, (std::shared_ptr meta), ()); + MOCK_METHOD(FilterType, GetFilterType, (), ()); + MOCK_METHOD(void, OnLinkedResult, + (const sptr& outputBufferQueue, std::shared_ptr& meta), ()); + MOCK_METHOD(void, OnUpdatedResult, (std::shared_ptr& meta), ()); + MOCK_METHOD(void, OnUnlinkedResult, (std::shared_ptr& meta), ()); + MOCK_METHOD(Status, SetDecryptionConfig, + (const sptr& keySessionProxy, bool svp), ()); + MOCK_METHOD(void, OnDumpInfo, (int32_t fd), ()); + MOCK_METHOD(void, SetCallerInfo, (uint64_t instanceId, const std::string& appName), ()); + MOCK_METHOD(void, OnError, (CodecErrorType errorType, int32_t errorCode), ()); + MOCK_METHOD(Status, OnLinked, (StreamType inType, const std::shared_ptr& meta, + const std::shared_ptr& callback), ()); + MOCK_METHOD(Status, OnUpdated, (StreamType inType, const std::shared_ptr& meta, + const std::shared_ptr& callback), ()); + MOCK_METHOD(Status, OnUnLinked, (StreamType inType, + const std::shared_ptr& callback), ()); + MOCK_METHOD(Status, SetInputBufferQueueConsumerListener, (), ()); + MOCK_METHOD(Status, SetOutputBufferQueueProducerListener, (), ()); + MOCK_METHOD(void, UpdateTrackInfoSampleFormat, (const std::string& mime, const std::shared_ptr& meta), ()); +}; } // namespace Media } // namespace OHOS #endif // HIPLAYER_IMPL_UNIT_TEST_H diff --git a/test/unittest/hitranscode/hitranscode_unit_test.cpp b/test/unittest/hitranscode/hitranscode_unit_test.cpp index de8091527cb4122392d56abd5b7b0232c7e98072..d0afee7a8eb574aa561ec90381e4e1226d55a3f8 100644 --- a/test/unittest/hitranscode/hitranscode_unit_test.cpp +++ b/test/unittest/hitranscode/hitranscode_unit_test.cpp @@ -1001,6 +1001,71 @@ HWTEST_F(HitranscodeUnitTest, ConfigureVideoWidthHeight_004, TestSize.Level0) EXPECT_EQ(ret, Status::OK); } +/** +* @tc.name : Test ConfigureColorSpace API +* @tc.number : ConfigureColorSpace_001 +* @tc.desc : Test ConfigureColorSpace. +* @tc.require : +*/ +HWTEST_F(HitranscodeUnitTest, ConfigureColorSpace_001, TestSize.Level0) +{ + VideoColorSpace videoColSpaFmt(TRANSCODER_COLORSPACE_P3_FULL); + Status ret = transcoder_->ConfigureColorSpace(videoColSpaFmt); + EXPECT_EQ(ret, Status::OK); +} + +/** +* @tc.name : Test ConfigureColorSpace API +* @tc.number : ConfigureColorSpace_002 +* @tc.desc : Test ConfigureColorSpace. +* @tc.require : +*/ +HWTEST_F(HitranscodeUnitTest, ConfigureColorSpace_002, TestSize.Level0) +{ + VideoColorSpace videoColSpaFmt(TRANSCODER_COLORSPACE_BT709_LIMIT); + Status ret = transcoder_->ConfigureColorSpace(videoColSpaFmt); + EXPECT_EQ(ret, Status::OK); +} + +/** +* @tc.name : Test ConfigureColorSpace API +* @tc.number : ConfigureColorSpace_003 +* @tc.desc : Test ConfigureColorSpace. +* @tc.require : +*/ +HWTEST_F(HitranscodeUnitTest, ConfigureColorSpace_003, TestSize.Level0) +{ + VideoColorSpace videoColSpaFmt(TRANSCODER_COLORSPACE_NONE); + Status ret = transcoder_->ConfigureColorSpace(videoColSpaFmt); + EXPECT_EQ(ret, Status::ERROR_INVALID_PARAMETER); +} + +/** +* @tc.name : Test ConfigureColorSpace API +* @tc.number : ConfigureColorSpace_004 +* @tc.desc : Test ConfigureColorSpace. +* @tc.require : +*/ +HWTEST_F(HitranscodeUnitTest, ConfigureColorSpace_004, TestSize.Level0) +{ + VideoColorSpace videoColSpaFmt(TRANSCODER_COLORSPACE_BT601_EBU_FULL); + Status ret = transcoder_->ConfigureColorSpace(videoColSpaFmt); + EXPECT_EQ(ret, Status::OK); +} + +/** +* @tc.name : Test ConfigureColorSpace API +* @tc.number : ConfigureColorSpace_005 +* @tc.desc : Test ConfigureColorSpace. +* @tc.require : +*/ +HWTEST_F(HitranscodeUnitTest, ConfigureColorSpace_005, TestSize.Level0) +{ + VideoColorSpace videoColSpaFmt(TRANSCODER_COLORSPACE_DISPLAY_BT2020_HLG); + Status ret = transcoder_->ConfigureColorSpace(videoColSpaFmt); + EXPECT_EQ(ret, Status::OK); +} + /** * @tc.name : Test ConfigureMetaDataToTrackFormat * @tc.number : ConfigureMetaDataToTrackFormat_001 @@ -1053,5 +1118,124 @@ HWTEST_F(HitranscodeUnitTest, Configure_001, TestSize.Level0) ret = transcoder_->Configure(inputUrl); EXPECT_EQ(ret, MSERR_OK); } + +/** +* @tc.name : Test Configure +* @tc.number : Configure_002 +* @tc.desc : Test Configure +* @tc.require : +*/ +HWTEST_F(HitranscodeUnitTest, Configure_002, TestSize.Level0) +{ + VideoRectangle videoRectangle(1280, 720); + int32_t ret = transcoder_->Configure(videoRectangle); + EXPECT_EQ(ret, MSERR_OK); + + VideoColorSpace videoColSpaFmt(TRANSCODER_COLORSPACE_BT709_LIMIT); + ret = transcoder_->Configure(videoColSpaFmt); + EXPECT_EQ(ret, MSERR_OK); +} + +/** +* @tc.name : Test Configure +* @tc.number : Configure_003 +* @tc.desc : Test Configure +* @tc.require : +*/ +HWTEST_F(HitranscodeUnitTest, Configure_003, TestSize.Level0) +{ + VideoRectangle videoRectangle(-1, 720); + int32_t ret = transcoder_->Configure(videoRectangle); + EXPECT_EQ(ret, MSERR_OK); + + VideoColorSpace videoColSpaFmt(TRANSCODER_COLORSPACE_BT709_LIMIT); + ret = transcoder_->Configure(videoColSpaFmt); + EXPECT_EQ(ret, MSERR_OK); +} + +/** +* @tc.name : Test Configure +* @tc.number : Configure_004 +* @tc.desc : Test Configure +* @tc.require : +*/ +HWTEST_F(HitranscodeUnitTest, Configure_004, TestSize.Level0) +{ + VideoRectangle videoRectangle(1280, -1); + int32_t ret = transcoder_->Configure(videoRectangle); + EXPECT_EQ(ret, MSERR_OK); + + VideoColorSpace videoColSpaFmt(TRANSCODER_COLORSPACE_BT709_LIMIT); + ret = transcoder_->Configure(videoColSpaFmt); + EXPECT_EQ(ret, MSERR_OK); +} + +/** +* @tc.name : Test Configure +* @tc.number : Configure_005 +* @tc.desc : Test Configure +* @tc.require : +*/ +HWTEST_F(HitranscodeUnitTest, Configure_005, TestSize.Level0) +{ + VideoRectangle videoRectangle(1280, 720); + int32_t ret = transcoder_->Configure(videoRectangle); + EXPECT_EQ(ret, MSERR_OK); + + VideoColorSpace videoColSpaFmt(TRANSCODER_COLORSPACE_P3_FULL); + ret = transcoder_->Configure(videoColSpaFmt); + EXPECT_EQ(ret, MSERR_OK); +} + +/** +* @tc.name : Test Configure +* @tc.number : Configure_006 +* @tc.desc : Test Configure +* @tc.require : +*/ +HWTEST_F(HitranscodeUnitTest, Configure_006, TestSize.Level0) +{ + VideoRectangle videoRectangle(1280, -1); + int32_t ret = transcoder_->Configure(videoRectangle); + EXPECT_EQ(ret, MSERR_OK); + + VideoColorSpace videoColSpaFmt(TRANSCODER_COLORSPACE_P3_FULL); + ret = transcoder_->Configure(videoColSpaFmt); + EXPECT_EQ(ret, MSERR_OK); +} + +/** +* @tc.name : Test Configure +* @tc.number : Configure_007 +* @tc.desc : Test Configure +* @tc.require : +*/ +HWTEST_F(HitranscodeUnitTest, Configure_007, TestSize.Level0) +{ + VideoRectangle videoRectangle(-1, 720); + int32_t ret = transcoder_->Configure(videoRectangle); + EXPECT_EQ(ret, MSERR_OK); + + VideoColorSpace videoColSpaFmt(TRANSCODER_COLORSPACE_P3_FULL); + ret = transcoder_->Configure(videoColSpaFmt); + EXPECT_EQ(ret, MSERR_OK); +} + +/** +* @tc.name : Test Configure +* @tc.number : Configure_008 +* @tc.desc : Test Configure +* @tc.require : +*/ +HWTEST_F(HitranscodeUnitTest, Configure_008, TestSize.Level0) +{ + VideoRectangle videoRectangle(1280, 720); + int32_t ret = transcoder_->Configure(videoRectangle); + EXPECT_EQ(ret, MSERR_OK); + + VideoColorSpace videoColSpaFmt(TRANSCODER_COLORSPACE_NONE); + ret = transcoder_->Configure(videoColSpaFmt); + EXPECT_EQ(ret, MSERR_INVALID_VAL); +} } // namespace Media } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/media_server_manager_test/media_server_manager_test.cpp b/test/unittest/media_server_manager_test/media_server_manager_test.cpp index b7af3bc60eaf4664044f3bc9b295d0b14405b9a5..675e7fa15f88563d9b2e564a325ca576198dd57f 100644 --- a/test/unittest/media_server_manager_test/media_server_manager_test.cpp +++ b/test/unittest/media_server_manager_test/media_server_manager_test.cpp @@ -42,6 +42,77 @@ void MediaServerManagerTest::TearDown(void) { } +/** + * @tc.name : FreezeStubForPids_001 + * @tc.number: FreezeStubForPids_001 + * @tc.desc : Test FreezeStubForPids interface + */ +HWTEST_F(MediaServerManagerTest, FreezeStubForPids_001, TestSize.Level1) +{ + sptr player = + MediaServerManager::GetInstance().CreateStubObject(MediaServerManager::PLAYER); + ASSERT_NE(player, nullptr); + int32_t pid = IPCSkeleton::GetCallingPid(); + std::set pidList; + pidList.insert(pid); + auto isProxy = true; + auto ret = MediaServerManager::GetInstance().FreezeStubForPids(pidList, isProxy); + EXPECT_EQ(ret, 0); + MediaServerManager::GetInstance().DestroyStubObject(MediaServerManager::PLAYER, player); +} + +/** + * @tc.name : FreezeStubForPids_002 + * @tc.number: FreezeStubForPids_002 + * @tc.desc : Test FreezeStubForPids interface + */ +HWTEST_F(MediaServerManagerTest, FreezeStubForPids_002, TestSize.Level1) +{ + sptr player = + MediaServerManager::GetInstance().CreateStubObject(MediaServerManager::PLAYER); + ASSERT_NE(player, nullptr); + std::set pidList; + pidList.insert(PID_TEST); + auto isProxy = true; + auto ret = MediaServerManager::GetInstance().FreezeStubForPids(pidList, isProxy); + EXPECT_EQ(ret, 0); + MediaServerManager::GetInstance().DestroyStubObject(MediaServerManager::PLAYER, player); +} + +/** + * @tc.name : FreezeStubForPids_003 + * @tc.number: FreezeStubForPids_003 + * @tc.desc : Test FreezeStubForPids interface + */ +HWTEST_F(MediaServerManagerTest, FreezeStubForPids_003, TestSize.Level1) +{ + sptr player = + MediaServerManager::GetInstance().CreateStubObject(MediaServerManager::PLAYER); + ASSERT_NE(player, nullptr); + int32_t pid = IPCSkeleton::GetCallingPid(); + std::set pidList; + pidList.insert(pid); + auto isProxy = false; + auto ret = MediaServerManager::GetInstance().FreezeStubForPids(pidList, isProxy); + EXPECT_EQ(ret, 0); + MediaServerManager::GetInstance().DestroyStubObject(MediaServerManager::PLAYER, player); +} + +/** + * @tc.name : ResetAllProxy_001 + * @tc.number: ResetAllProxy_001 + * @tc.desc : Test ResetAllProxy interface + */ +HWTEST_F(MediaServerManagerTest, ResetAllProxy, TestSize.Level1) +{ + sptr player = + MediaServerManager::GetInstance().CreateStubObject(MediaServerManager::PLAYER); + ASSERT_NE(player, nullptr); + auto ret = MediaServerManager::GetInstance().ResetAllProxy(); + EXPECT_EQ(ret, 0); + MediaServerManager::GetInstance().DestroyStubObject(MediaServerManager::PLAYER, player); +} + /** * @tc.name : DestroyStubObject_001 * @tc.number: DestroyStubObject_001 diff --git a/test/unittest/media_server_manager_test/mock/mock_task.h b/test/unittest/media_server_manager_test/mock/mock_task.h index 4c31008744169bafd99ef89093b667f2b29eaac0..885586963cfae6693b6f27933405f45e985f4272 100644 --- a/test/unittest/media_server_manager_test/mock/mock_task.h +++ b/test/unittest/media_server_manager_test/mock/mock_task.h @@ -46,6 +46,19 @@ public: { return nullptr; } + + int32_t FreezeStubForPids(const std::set &pidList, bool isProxy) + { + (void)pidList; + (void)isProxy; + return 0; + } + + int32_t ResetAllProxy() + { + return 0; + } + MOCK_METHOD(void, ReleaseClientListener, (), (override)); MOCK_METHOD(bool, CanKillMediaService, (), (override)); MOCK_METHOD(int32_t, SetDeathListener, (const sptr &object), ()); diff --git a/test/unittest/media_service_helper_test/media_service_helper_unit_test.cpp b/test/unittest/media_service_helper_test/media_service_helper_unit_test.cpp index a3e5f967ed112aa3b47f1c0d64d3001a6659b45c..ba0c57c9b538e4c1a5ada51e08d94907242f741d 100644 --- a/test/unittest/media_service_helper_test/media_service_helper_unit_test.cpp +++ b/test/unittest/media_service_helper_test/media_service_helper_unit_test.cpp @@ -21,6 +21,7 @@ using namespace testing::ext; namespace OHOS { namespace Media { +constexpr int32_t CONSTRUCTED_PID = 999999; void MediaServiceHelperUnitTest::SetUpTestCase(void) { @@ -38,6 +39,21 @@ void MediaServiceHelperUnitTest::TearDown(void) { } +HWTEST_F(MediaServiceHelperUnitTest, ProxyForFreeze_001, TestSize.Level0) +{ + std::set pidList; + pidList.insert(CONSTRUCTED_PID); + bool isProxy = true; + auto ret = MediaServiceHelper::ProxyForFreeze(pidList, isProxy); + EXPECT_FALSE(ret); +} + +HWTEST_F(MediaServiceHelperUnitTest, ResetAllProxy_001, TestSize.Level0) +{ + auto ret = MediaServiceHelper::ResetAllProxy(); + EXPECT_FALSE(ret); +} + HWTEST_F(MediaServiceHelperUnitTest, CanKillMediaService_001, TestSize.Level0) { EXPECT_TRUE(MediaServiceHelper::CanKillMediaService()); diff --git a/test/unittest/observer_test/observer_unittest/incall_observer_func_unittest.cpp b/test/unittest/observer_test/observer_unittest/incall_observer_func_unittest.cpp index 221c70482e22d645cadb4e580f4b5045ac0e2425..d673b7de887ad50bfa93a0d7e45a7e2ea4f86e1e 100644 --- a/test/unittest/observer_test/observer_unittest/incall_observer_func_unittest.cpp +++ b/test/unittest/observer_test/observer_unittest/incall_observer_func_unittest.cpp @@ -231,8 +231,8 @@ HWTEST_F(InCallObserverInnerUnitTest, InCallCallBackReturn_05, TestSize.Level1) { auto telephonyObserver = std::make_unique().release(); std::u16string phoneNumber = u""; - telephonyObserver->OnCallStateUpdated(-1, 1, phoneNumber); // -1 invalid slot id - int32_t slotId = 1; // 1 normal slot id + telephonyObserver->OnCallStateUpdated(3, 1, phoneNumber); // 3 invalid slot id + int32_t slotId = -1; // -1 all slot id for (int i = -1; i <= 9; i++) { // -1 9 foreach all state telephonyObserver->OnCallStateUpdated(slotId, i, phoneNumber); } diff --git a/test/unittest/player_server_test/include/player_server_mock.h b/test/unittest/player_server_test/include/player_server_mock.h index 993c4d4d0afdc09c49b951761978298a4ec3d417..2ad8214cfd0063760a690b895c5554fd91e5ac59 100644 --- a/test/unittest/player_server_test/include/player_server_mock.h +++ b/test/unittest/player_server_test/include/player_server_mock.h @@ -120,6 +120,8 @@ public: explicit PlayerServerMock(std::shared_ptr &callback); virtual ~PlayerServerMock(); bool CreatePlayer(); + int32_t Freeze(); + int32_t UnFreeze(); int32_t SetSource(const std::string url); int32_t SetSource(const std::string &path, int64_t offset, int64_t size); int32_t SetSource(int32_t fd, int64_t offset, int64_t size); diff --git a/test/unittest/player_server_test/src/player_server_mock.cpp b/test/unittest/player_server_test/src/player_server_mock.cpp index 6c50990c01de3d2286d4c1743724dfc1d5601763..c15629235a3204f2ed83f861000af12f7e922dbc 100644 --- a/test/unittest/player_server_test/src/player_server_mock.cpp +++ b/test/unittest/player_server_test/src/player_server_mock.cpp @@ -378,6 +378,18 @@ int32_t PlayerServerMock::SetMediaSource(const std::shared_ptr &m return player_->SetMediaSource(mediaSource, strategy); } +int32_t PlayerServerMock::Freeze() +{ + std::unique_lock lock(mutex_); + return player_->Freeze(); +} + +int32_t PlayerServerMock::UnFreeze() +{ + std::unique_lock lock(mutex_); + return player_->UnFreeze(); +} + int32_t PlayerServerMock::SetSource(const std::string url) { UNITTEST_CHECK_AND_RETURN_RET_LOG(player_ != nullptr, -1, "player_ == nullptr"); diff --git a/test/unittest/player_server_test/src/player_server_unit_test.cpp b/test/unittest/player_server_test/src/player_server_unit_test.cpp index 5d8e1adb14b355b211b5eed197185207b13ea4f1..65256fa64dc60019e97cddad712e829ae1c37b7a 100644 --- a/test/unittest/player_server_test/src/player_server_unit_test.cpp +++ b/test/unittest/player_server_test/src/player_server_unit_test.cpp @@ -1874,7 +1874,6 @@ HWTEST_F(PlayerServerUnitTest, Player_SelectTrack_002, TestSize.Level1) sleep(PLAYING_TIME_2_SEC); EXPECT_EQ(MSERR_OK, player_->GetCurrentTrack(MediaType::MEDIA_TYPE_AUD, currentAudioTrackIndex)); EXPECT_NE(MSERR_OK, player_->SelectTrack(currentAudioTrackIndex, trackChange)); - EXPECT_EQ(trackChange, false); sleep(PLAYING_TIME_2_SEC); EXPECT_EQ(MSERR_OK, player_->Stop()); } @@ -1900,7 +1899,6 @@ HWTEST_F(PlayerServerUnitTest, Player_DeselectTrack_001, TestSize.Level1) audioTrack[0].GetIntValue("track_index", defaultAudioTrackIndex); EXPECT_GT(defaultAudioTrackIndex, -1); EXPECT_NE(MSERR_OK, player_->DeselectTrack(defaultAudioTrackIndex, trackChange)); - EXPECT_EQ(trackChange, false); sleep(PLAYING_TIME_2_SEC); EXPECT_EQ(MSERR_OK, player_->Stop()); } @@ -5461,5 +5459,63 @@ HWTEST_F(PlayerServerUnitTest, Player_EnableReportMediaProgress_004, TestSize.Le ASSERT_EQ(MSERR_OK, player_->EnableReportMediaProgress(true)); EXPECT_EQ(MSERR_OK, player_->Play()); } + +/** + * @tc.name : Test Freeze API + * @tc.number: Player_Freeze_001 + * @tc.desc : Test Player Freeze + */ +HWTEST_F(PlayerServerUnitTest, Player_Freeze_001, TestSize.Level1) +{ + ASSERT_EQ(MSERR_OK, player_->SetSource(VIDEO_FILE1)); + EXPECT_EQ(MSERR_OK, player_->Freeze()); +} + +/** + * @tc.name : Test Freeze API + * @tc.number: Player_Freeze_002 + * @tc.desc : Test Player Freeze + */ +HWTEST_F(PlayerServerUnitTest, Player_Freeze_002, TestSize.Level1) +{ + ASSERT_EQ(MSERR_OK, player_->SetSource(VIDEO_FILE1)); + sptr videoSurface = player_->GetVideoSurface(); + ASSERT_NE(nullptr, videoSurface); + EXPECT_EQ(MSERR_OK, player_->SetVideoSurface(videoSurface)); + EXPECT_EQ(MSERR_OK, player_->Prepare()); + EXPECT_EQ(MSERR_OK, player_->Play()); + EXPECT_EQ(MSERR_OK, player_->Freeze()); + sleep(1); +} + +/** + * @tc.name : Test UnFreeze API + * @tc.number: Player_UnFreeze_001 + * @tc.desc : Test Player UnFreeze + */ +HWTEST_F(PlayerServerUnitTest, Player_UnFreeze_001, TestSize.Level1) +{ + ASSERT_EQ(MSERR_OK, player_->SetSource(VIDEO_FILE1)); + EXPECT_EQ(MSERR_OK, player_->UnFreeze()); +} + +/** + * @tc.name : Test Freeze API + * @tc.number: Player_UnFreeze_002 + * @tc.desc : Test Player UnFreeze + */ +HWTEST_F(PlayerServerUnitTest, Player_UnFreeze_002, TestSize.Level1) +{ + ASSERT_EQ(MSERR_OK, player_->SetSource(VIDEO_FILE1)); + sptr videoSurface = player_->GetVideoSurface(); + ASSERT_NE(nullptr, videoSurface); + EXPECT_EQ(MSERR_OK, player_->SetVideoSurface(videoSurface)); + EXPECT_EQ(MSERR_OK, player_->Prepare()); + EXPECT_EQ(MSERR_OK, player_->Play()); + EXPECT_EQ(MSERR_OK, player_->Freeze()); + sleep(1); + EXPECT_EQ(MSERR_OK, player_->UnFreeze()); + sleep(1); +} } // namespace Media } // namespace OHOS diff --git a/test/unittest/player_service_stub_test/player_service_stub_test.cpp b/test/unittest/player_service_stub_test/player_service_stub_test.cpp index c740afd7e3decaebdbcd8ae2ffa5cf3cf813bca9..177e2f7bb00abd77bc73c8700c9abcb510aaab8d 100644 --- a/test/unittest/player_service_stub_test/player_service_stub_test.cpp +++ b/test/unittest/player_service_stub_test/player_service_stub_test.cpp @@ -180,5 +180,76 @@ HWTEST_F(PlayerServiceStubTest, SetMediaSource_004, TestSize.Level1) EXPECT_EQ(ret, 0); playerServiceStub = nullptr; } + +/** + * @tc.name : Freeze_001 + * @tc.number: Freeze_001 + * @tc.desc : FUNC + */ +HWTEST_F(PlayerServiceStubTest, Freeze_001, TestSize.Level1) +{ + sptr playerServiceStub = PlayerServiceStub::Create(); + ASSERT_NE(playerServiceStub, nullptr); + + int ret = playerServiceStub->Freeze(); + EXPECT_EQ(ret, 0); + playerServiceStub = nullptr; +} + +/** + * @tc.name : UnFreeze_001 + * @tc.number: UnFreeze_001 + * @tc.desc : FUNC + */ +HWTEST_F(PlayerServiceStubTest, UnFreeze_001, TestSize.Level1) +{ + sptr playerServiceStub = PlayerServiceStub::Create(); + ASSERT_NE(playerServiceStub, nullptr); + + playerServiceStub->isFrozen_ = true; + int ret = playerServiceStub->UnFreeze(); + EXPECT_EQ(ret, 0); + playerServiceStub = nullptr; +} + +/** + * @tc.name : EnableReportAudioInterrupt_001 + * @tc.number: EnableReportAudioInterrupt_001 + * @tc.desc : FUNC + */ +HWTEST_F(PlayerServiceStubTest, EnableReportAudioInterrupt_001, TestSize.Level1) +{ + sptr playerServiceStub = PlayerServiceStub::Create(); + ASSERT_NE(playerServiceStub, nullptr); + + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteBool(true); + + int ret = playerServiceStub->EnableReportAudioInterrupt(data, reply); + EXPECT_EQ(ret, 0); + playerServiceStub = nullptr; +} + +/** + * @tc.name : EnableReportAudioInterrupt_002 + * @tc.number: EnableReportAudioInterrupt_002 + * @tc.desc : FUNC + */ +HWTEST_F(PlayerServiceStubTest, EnableReportAudioInterrupt_002, TestSize.Level1) +{ + sptr playerServiceStub = PlayerServiceStub::Create(); + ASSERT_NE(playerServiceStub, nullptr); + + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteBool(false); + + int ret = playerServiceStub->EnableReportAudioInterrupt(data, reply); + EXPECT_EQ(ret, 0); + playerServiceStub = nullptr; +} } } \ No newline at end of file diff --git a/test/unittest/recorder_test/BUILD.gn b/test/unittest/recorder_test/BUILD.gn index 3e52d7091a80de14eff81930815fdef3dfd5ca92..ec58471225e6f8b6adc26154d6376af40419f196 100644 --- a/test/unittest/recorder_test/BUILD.gn +++ b/test/unittest/recorder_test/BUILD.gn @@ -244,6 +244,7 @@ ohos_unittest("recorder_server_unit_test") { "graphic_surface:surface", "hilog:libhilog", "hisysevent:libhisysevent", + "hitrace:hitrace_meter", "power_manager:powermgr_client", "qos_manager:qos", ] diff --git a/test/unittest/screen_capture_test/BUILD.gn b/test/unittest/screen_capture_test/BUILD.gn index f208ef2189280f72e0d4bae1129c94b40affcf85..32f72980511dbc68c0a8de08e630fa3ff58761c2 100644 --- a/test/unittest/screen_capture_test/BUILD.gn +++ b/test/unittest/screen_capture_test/BUILD.gn @@ -290,6 +290,7 @@ ohos_unittest("screen_capture_server_function_unit_test") { "graphic_surface:surface", "hilog:libhilog", "hisysevent:libhisysevent", + "hitrace:hitrace_meter", "i18n:intl_util", "ipc:ipc_single", "media_foundation:media_foundation", diff --git a/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/include/screen_capture_server_function_unittest.h b/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/include/screen_capture_server_function_unittest.h index de299f374d3a32bb7bf731ae73f5dbb308ad2aee..d22e49870e3b4ebae440c92b70e41b3caac5ee36 100644 --- a/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/include/screen_capture_server_function_unittest.h +++ b/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/include/screen_capture_server_function_unittest.h @@ -48,6 +48,8 @@ public: int32_t SetScreenCaptureObserver(); int32_t StartFileAudioCapture(AVScreenCaptureMixMode mixMode); int32_t StartStreamAudioCapture(); + void SetSCInnerAudioCaptureAndPushData(std::shared_ptr innerAudioBuffer); + void SetSCMicAudioCaptureAndPushData(std::shared_ptr micAudioBuffer); protected: std::shared_ptr screenCaptureServer_; diff --git a/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/audio_capturer_wrapper_function_unittest.cpp b/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/audio_capturer_wrapper_function_unittest.cpp index d421de830e90edd66bff2fcc1d26b7a6eb778c8b..9853f3c4c0087fbd8ceed68b30c09587b67f31ff 100644 --- a/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/audio_capturer_wrapper_function_unittest.cpp +++ b/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/audio_capturer_wrapper_function_unittest.cpp @@ -32,6 +32,11 @@ using namespace testing::ext; using namespace OHOS::Media::ScreenCaptureTestParam; using namespace OHOS::Media; +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_SCREENCAPTURE, "ScreenCaptureServerFunctionTest"}; +static constexpr int64_t AUDIO_CAPTURE_READ_FRAME_TIME = 21333333; // 21333333 ns 21ms +} + namespace OHOS { namespace Media { HWTEST_F(ScreenCaptureServerFunctionTest, AudioCapturerWrapperStart_001, TestSize.Level2) @@ -143,10 +148,6 @@ HWTEST_F(ScreenCaptureServerFunctionTest, AudioCapturerWrapperPause_001, TestSiz screenCaptureServer_->innerAudioCapture_->bundleName_ = ScreenRecorderBundleName; ASSERT_EQ(screenCaptureServer_->innerAudioCapture_->Start(screenCaptureServer_->appInfo_), MSERR_OK); sleep(RECORDER_TIME); - ASSERT_EQ(screenCaptureServer_->innerAudioCapture_->Pause(), MSERR_OK); - sleep(RECORDER_TIME); - ASSERT_EQ(screenCaptureServer_->innerAudioCapture_->Resume(), MSERR_OK); - sleep(RECORDER_TIME); ASSERT_EQ(screenCaptureServer_->innerAudioCapture_->Stop(), MSERR_OK); } @@ -164,14 +165,6 @@ HWTEST_F(ScreenCaptureServerFunctionTest, AudioCapturerWrapperPause_002, TestSiz screenCaptureServer_->innerAudioCapture_->bundleName_ = ScreenRecorderBundleName; ASSERT_EQ(screenCaptureServer_->innerAudioCapture_->Start(screenCaptureServer_->appInfo_), MSERR_OK); sleep(RECORDER_TIME); - ASSERT_EQ(screenCaptureServer_->innerAudioCapture_->Pause(), MSERR_OK); - sleep(RECORDER_TIME); - ASSERT_EQ(screenCaptureServer_->innerAudioCapture_->Pause(), MSERR_OK); - sleep(RECORDER_TIME); - ASSERT_EQ(screenCaptureServer_->innerAudioCapture_->Resume(), MSERR_OK); - sleep(RECORDER_TIME); - ASSERT_NE(screenCaptureServer_->innerAudioCapture_->Resume(), MSERR_OK); - sleep(RECORDER_TIME); ASSERT_EQ(screenCaptureServer_->innerAudioCapture_->Stop(), MSERR_OK); } @@ -188,14 +181,7 @@ HWTEST_F(ScreenCaptureServerFunctionTest, AudioCapturerWrapperPause_003, TestSiz std::string("OS_InnerAudioCapture"), screenCaptureServer_->contentFilter_); screenCaptureServer_->innerAudioCapture_->bundleName_ = ScreenRecorderBundleName; ASSERT_EQ(screenCaptureServer_->innerAudioCapture_->Start(screenCaptureServer_->appInfo_), MSERR_OK); - sleep(RECORDER_TIME); - ASSERT_EQ(screenCaptureServer_->innerAudioCapture_->Pause(), MSERR_OK); - sleep(RECORDER_TIME); - screenCaptureServer_->innerAudioCapture_->isRunning_.store(true); - ASSERT_EQ(screenCaptureServer_->innerAudioCapture_->Pause(), MSERR_OK); - sleep(RECORDER_TIME); screenCaptureServer_->innerAudioCapture_->isRunning_.store(true); - ASSERT_EQ(screenCaptureServer_->innerAudioCapture_->Pause(), MSERR_OK); sleep(RECORDER_TIME); ASSERT_EQ(screenCaptureServer_->innerAudioCapture_->Stop(), MSERR_OK); } @@ -270,6 +256,52 @@ HWTEST_F(ScreenCaptureServerFunctionTest, AudioCapturerWrapperUpdateAudioCapture ASSERT_EQ(screenCaptureServer_->innerAudioCapture_->Stop(), MSERR_OK); } +HWTEST_F(ScreenCaptureServerFunctionTest, AudioCapturerWrapperUseUpBuffer_001, TestSize.Level2) +{ + SetValidConfig(); + ASSERT_EQ(InitStreamScreenCaptureServer(), MSERR_OK); + screenCaptureServer_->audioSource_ = std::make_unique( + AVScreenCaptureMixMode::INNER_MODE, screenCaptureServer_.get()); + screenCaptureServer_->captureCallback_ = std::make_shared(); + screenCaptureServer_->captureCallback_->SetAudioSource(screenCaptureServer_->audioSource_); + screenCaptureServer_->innerAudioCapture_ = std::make_shared( + screenCaptureServer_->captureConfig_.audioInfo.innerCapInfo, screenCaptureServer_->screenCaptureCb_, + std::string("OS_InnerAudioCapture"), screenCaptureServer_->contentFilter_); + screenCaptureServer_->innerAudioCapture_->bundleName_ = ScreenRecorderBundleName; + ASSERT_EQ(screenCaptureServer_->innerAudioCapture_->Start(screenCaptureServer_->appInfo_), MSERR_OK); + sleep(RECORDER_TIME); + int64_t currentAudioTime = 0; + screenCaptureServer_->innerAudioCapture_->GetCurrentAudioTime(currentAudioTime); + size_t size = 0; + screenCaptureServer_->innerAudioCapture_->GetBufferSize(size); + ASSERT_EQ(screenCaptureServer_->innerAudioCapture_->AddBufferFrom(0, static_cast(size), currentAudioTime), + MSERR_OK); + MEDIA_LOGI("UseUpBuffer time: %{public}" PRId64, static_cast(currentAudioTime)); + MEDIA_LOGI("UseUpBuffer size: %{public}" PRId64, static_cast(size)); + if (screenCaptureServer_->innerAudioCapture_->availBuffers_.front()) { + MEDIA_LOGI("UseUpBuffer ftime: %{public}" PRId64, static_cast( + screenCaptureServer_->innerAudioCapture_->availBuffers_.front()->timestamp)); + } + int32_t ret = screenCaptureServer_->innerAudioCapture_->UseUpAllLeftBufferUntil(currentAudioTime); + MEDIA_LOGI("UseUpBuffer ret: %{public}d", ret); + int64_t currentAudioTime1 = 0; + screenCaptureServer_->innerAudioCapture_->GetCurrentAudioTime(currentAudioTime1); + int64_t currentAudioTime2 = currentAudioTime1 - AUDIO_CAPTURE_READ_FRAME_TIME * 3; + screenCaptureServer_->innerAudioCapture_->AddBufferFrom(AUDIO_CAPTURE_READ_FRAME_TIME * 3, + static_cast(size), currentAudioTime2); + screenCaptureServer_->innerAudioCapture_->DropBufferUntil(currentAudioTime1); + MEDIA_LOGI("UseUpBuffer time: %{public}" PRId64, static_cast(currentAudioTime1)); + MEDIA_LOGI("UseUpBuffer before time: %{public}" PRId64, static_cast(currentAudioTime2)); + if (screenCaptureServer_->innerAudioCapture_->availBuffers_.front()) { + MEDIA_LOGI("UseUpBuffer ftime: %{public}" PRId64, static_cast( + screenCaptureServer_->innerAudioCapture_->availBuffers_.front()->timestamp)); + } + ret = screenCaptureServer_->innerAudioCapture_->UseUpAllLeftBufferUntil(currentAudioTime); + MEDIA_LOGI("UseUpBuffer 2 ret: %{public}d", ret); + sleep(RECORDER_TIME); + ASSERT_EQ(screenCaptureServer_->innerAudioCapture_->Stop(), MSERR_OK); +} + #ifdef SUPPORT_CALL /** * @tc.name: AudioCapturerWrapperInTelCall_001 @@ -310,11 +342,7 @@ HWTEST_F(ScreenCaptureServerFunctionTest, AudioCapturerWrapperInTelCall_002, Tes std::string("OS_MicAudioCapture"), screenCaptureServer_->contentFilter_); ASSERT_EQ(screenCaptureServer_->micAudioCapture_->Start(screenCaptureServer_->appInfo_), MSERR_OK); sleep(RECORDER_TIME); - ASSERT_EQ(screenCaptureServer_->micAudioCapture_->Pause(), MSERR_OK); - sleep(RECORDER_TIME); screenCaptureServer_->micAudioCapture_->SetIsInTelCall(true); - sleep(RECORDER_TIME); - ASSERT_NE(screenCaptureServer_->micAudioCapture_->Resume(), MSERR_OK); } #endif diff --git a/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/screen_capture_server_function_unittest.cpp b/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/screen_capture_server_function_unittest.cpp index 2ce06a01192c11c8248a05995b4b168294e3cc69..ea8ce6182c5b4401d6e5b1d2429ab44b604feb45 100644 --- a/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/screen_capture_server_function_unittest.cpp +++ b/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/screen_capture_server_function_unittest.cpp @@ -364,6 +364,26 @@ int32_t ScreenCaptureServerFunctionTest::StartStreamAudioCapture() return ret; } +void ScreenCaptureServerFunctionTest::SetSCInnerAudioCaptureAndPushData(std::shared_ptr innerAudioBuffer) +{ + screenCaptureServer_->innerAudioCapture_ = std::make_shared( + screenCaptureServer_->captureConfig_.audioInfo.innerCapInfo, screenCaptureServer_->screenCaptureCb_, + std::string("OS_InnerAudioCapture"), screenCaptureServer_->contentFilter_); + screenCaptureServer_->innerAudioCapture_->captureState_ = AudioCapturerWrapperState::CAPTURER_RECORDING; + screenCaptureServer_->innerAudioCapture_->isRunning_.store(true); + screenCaptureServer_->innerAudioCapture_->availBuffers_.push_back(innerAudioBuffer); +} + +void ScreenCaptureServerFunctionTest::SetSCMicAudioCaptureAndPushData(std::shared_ptr micAudioBuffer) +{ + screenCaptureServer_->micAudioCapture_ = std::make_shared( + screenCaptureServer_->captureConfig_.audioInfo.micCapInfo, screenCaptureServer_->screenCaptureCb_, + std::string("OS_MicAudioCapture"), screenCaptureServer_->contentFilter_); + screenCaptureServer_->micAudioCapture_->captureState_ = AudioCapturerWrapperState::CAPTURER_RECORDING; + screenCaptureServer_->micAudioCapture_->isRunning_.store(true); + screenCaptureServer_->micAudioCapture_->availBuffers_.push_back(micAudioBuffer); +} + // videoCapInfo and innerCapInfo IGNORE HWTEST_F(ScreenCaptureServerFunctionTest, CaptureStreamParamsInvalid_001, TestSize.Level2) { @@ -839,7 +859,6 @@ HWTEST_F(ScreenCaptureServerFunctionTest, RepeatResumeAudioCapture_001, TestSize config_.audioInfo.innerCapInfo.audioSource = AudioCaptureSourceType::ALL_PLAYBACK; ASSERT_EQ(InitStreamScreenCaptureServer(), MSERR_OK); ASSERT_EQ(StartStreamAudioCapture(), MSERR_OK); - ASSERT_NE(screenCaptureServer_->innerAudioCapture_->Resume(), MSERR_OK); } HWTEST_F(ScreenCaptureServerFunctionTest, RepeatPauseAudioCapture_001, TestSize.Level2) @@ -853,8 +872,6 @@ HWTEST_F(ScreenCaptureServerFunctionTest, RepeatPauseAudioCapture_001, TestSize. config_.audioInfo.innerCapInfo.audioSource = AudioCaptureSourceType::ALL_PLAYBACK; ASSERT_EQ(InitStreamScreenCaptureServer(), MSERR_OK); ASSERT_EQ(StartStreamAudioCapture(), MSERR_OK); - ASSERT_EQ(screenCaptureServer_->innerAudioCapture_->Pause(), MSERR_OK); - ASSERT_EQ(screenCaptureServer_->innerAudioCapture_->Pause(), MSERR_OK); } HWTEST_F(ScreenCaptureServerFunctionTest, UpdatePrivacyUsingPermissionState_001, TestSize.Level2) @@ -1085,14 +1102,6 @@ HWTEST_F(ScreenCaptureServerFunctionTest, SetMissionId_001, TestSize.Level2) } HWTEST_F(ScreenCaptureServerFunctionTest, StartScreenCaptureInner_001, TestSize.Level2) -{ - SetValidConfig(); - ASSERT_EQ(InitStreamScreenCaptureServer(), MSERR_OK); - screenCaptureServer_->appInfo_.appUid = ScreenCaptureServer::ROOT_UID + 1; - ASSERT_EQ(screenCaptureServer_->StartScreenCaptureInner(false), MSERR_OK); -} - -HWTEST_F(ScreenCaptureServerFunctionTest, StartScreenCaptureInner_002, TestSize.Level2) { SetValidConfig(); ASSERT_EQ(InitStreamScreenCaptureServer(), MSERR_OK); @@ -1151,35 +1160,62 @@ HWTEST_F(ScreenCaptureServerFunctionTest, TryNotificationOnPostStartScreenCaptur } #endif -HWTEST_F(ScreenCaptureServerFunctionTest, ReleaseAudioBufferMix_001, TestSize.Level2) -{ - screenCaptureServer_->captureState_ = AVScreenCaptureState::STARTED; - int32_t ret = screenCaptureServer_->ReleaseAudioBufferMix(AVScreenCaptureMixMode::MIX_MODE); - ASSERT_EQ(ret, MSERR_OK); - ret = screenCaptureServer_->ReleaseAudioBufferMix(AVScreenCaptureMixMode::MIC_MODE); - ASSERT_EQ(ret, MSERR_OK); - ret = screenCaptureServer_->ReleaseAudioBufferMix(AVScreenCaptureMixMode::INNER_MODE); - ASSERT_EQ(ret, MSERR_OK); -} - -HWTEST_F(ScreenCaptureServerFunctionTest, ReleaseAudioBufferMix_002, TestSize.Level2) +HWTEST_F(ScreenCaptureServerFunctionTest, ReadAtMix_001, TestSize.Level2) { - SetValidConfig(); - ASSERT_EQ(InitStreamScreenCaptureServer(), MSERR_OK); - ASSERT_EQ(StartStreamAudioCapture(), MSERR_OK); + screenCaptureServer_->captureState_ = AVScreenCaptureState::CREATED; + screenCaptureServer_->recorderFileAudioType_ = AVScreenCaptureMixMode::MIX_MODE; + screenCaptureServer_->GetSCServerCaptureState(); + screenCaptureServer_->IsMicrophoneSwitchTurnOn(); + screenCaptureServer_->IsSCRecorderFileWithVideo(); + screenCaptureServer_->GetInnerAudioCapture(); + screenCaptureServer_->GetMicAudioCapture(); + screenCaptureServer_->IsStopAcquireAudioBufferFlag(); + screenCaptureServer_->audioSource_ = std::make_unique( + AVScreenCaptureMixMode::MIX_MODE, screenCaptureServer_.get()); + screenCaptureServer_->audioSource_->IsInWaitMicSyncState(); + screenCaptureServer_->audioSource_->SetVideoFirstFramePts(0); + screenCaptureServer_->audioSource_->SetAudioFirstFramePts(0); + const int bufferSize = 10; + uint8_t *innerBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + uint8_t *micBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + std::shared_ptr innerAudioBuffer = std::make_shared(innerBuffer, bufferSize, 0, + SOURCE_DEFAULT); + std::shared_ptr micAudioBuffer = std::make_shared(micBuffer, bufferSize, 0, + SOURCE_DEFAULT); + std::shared_ptr buffer; + AudioDataSourceReadAtActionState ret = screenCaptureServer_->audioSource_->ReadAt(buffer, bufferSize); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::SKIP_WITHOUT_LOG); screenCaptureServer_->captureState_ = AVScreenCaptureState::STARTED; - int32_t ret = screenCaptureServer_->ReleaseAudioBufferMix(AVScreenCaptureMixMode::MIX_MODE); - ASSERT_EQ(ret, MSERR_OK); - ret = screenCaptureServer_->ReleaseAudioBufferMix(AVScreenCaptureMixMode::MIC_MODE); - ASSERT_EQ(ret, MSERR_OK); - ret = screenCaptureServer_->ReleaseAudioBufferMix(AVScreenCaptureMixMode::INNER_MODE); - ASSERT_EQ(ret, MSERR_OK); + screenCaptureServer_->audioSource_->type_ = AVScreenCaptureMixMode::INVALID_MODE; + ret = screenCaptureServer_->audioSource_->ReadAt(buffer, bufferSize); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::RETRY_SKIP); + screenCaptureServer_->audioSource_->screenCaptureServer_ = nullptr; + ret = screenCaptureServer_->audioSource_->ReadAt(buffer, bufferSize); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::RETRY_SKIP); } -HWTEST_F(ScreenCaptureServerFunctionTest, MixModeBufferWrite_001, TestSize.Level2) +HWTEST_F(ScreenCaptureServerFunctionTest, ReadAtMix_002, TestSize.Level2) { + RecorderInfo recorderInfo; + SetRecorderInfo("start_file_inner_audio_capture_001.mp4", recorderInfo); + SetValidConfigFile(recorderInfo); + ASSERT_EQ(InitFileScreenCaptureServer(), MSERR_OK); + screenCaptureServer_->SetMicrophoneEnabled(true); screenCaptureServer_->audioSource_ = std::make_unique( AVScreenCaptureMixMode::MIX_MODE, screenCaptureServer_.get()); + screenCaptureServer_->captureCallback_ = std::make_shared(); + screenCaptureServer_->captureCallback_->SetAudioSource(screenCaptureServer_->audioSource_); + screenCaptureServer_->captureConfig_.audioInfo.innerCapInfo.state = + AVScreenCaptureParamValidationState::VALIDATION_VALID; + screenCaptureServer_->audioSource_->speakerAliveStatus_ = false; + screenCaptureServer_->StartFileInnerAudioCapture(); + screenCaptureServer_->StartFileMicAudioCapture(); + screenCaptureServer_->captureState_ = AVScreenCaptureState::STARTED; + screenCaptureServer_->recorderFileAudioType_ = AVScreenCaptureMixMode::MIX_MODE; + int64_t size = 0; + screenCaptureServer_->audioSource_->GetSize(size); + screenCaptureServer_->SetInnerAudioCapture(nullptr); + screenCaptureServer_->audioSource_->GetSize(size); const int bufferSize = 10; uint8_t *innerBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); uint8_t *micBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); @@ -1187,75 +1223,795 @@ HWTEST_F(ScreenCaptureServerFunctionTest, MixModeBufferWrite_001, TestSize.Level SOURCE_DEFAULT); std::shared_ptr micAudioBuffer = std::make_shared(micBuffer, bufferSize, 0, SOURCE_DEFAULT); + std::shared_ptr buffer = AVBuffer::CreateAVBuffer(); + screenCaptureServer_->audioSource_->ReadAt(buffer, bufferSize); + ASSERT_EQ(screenCaptureServer_->StopScreenCapture(), MSERR_OK); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, ReadAtMicMode_001, TestSize.Level2) +{ + RecorderInfo recorderInfo; + SetRecorderInfo("start_file_inner_audio_capture_001.mp4", recorderInfo); + SetValidConfigFile(recorderInfo); + ASSERT_EQ(InitFileScreenCaptureServer(), MSERR_OK); + screenCaptureServer_->SetMicrophoneEnabled(true); + screenCaptureServer_->audioSource_ = std::make_unique( + AVScreenCaptureMixMode::MIC_MODE, screenCaptureServer_.get()); + screenCaptureServer_->captureCallback_ = std::make_shared(); + screenCaptureServer_->captureCallback_->SetAudioSource(screenCaptureServer_->audioSource_); + screenCaptureServer_->captureConfig_.audioInfo.micCapInfo.state = + AVScreenCaptureParamValidationState::VALIDATION_VALID; + screenCaptureServer_->audioSource_->speakerAliveStatus_ = false; + screenCaptureServer_->captureState_ = AVScreenCaptureState::STARTED; + screenCaptureServer_->recorderFileAudioType_ = AVScreenCaptureMixMode::MIC_MODE; + const int bufferSize = 10; + std::shared_ptr buffer = AVBuffer::CreateAVBuffer(); + screenCaptureServer_->micAudioCapture_ = std::make_shared( + screenCaptureServer_->captureConfig_.audioInfo.micCapInfo, screenCaptureServer_->screenCaptureCb_, + std::string("OS_MicAudioCapture"), screenCaptureServer_->contentFilter_); + screenCaptureServer_->micAudioCapture_->captureState_ = AudioCapturerWrapperState::CAPTURER_RECORDING; + AudioDataSourceReadAtActionState ret = screenCaptureServer_->audioSource_->ReadAtMicMode(buffer, bufferSize); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::RETRY_SKIP); // AcquireAudioBuffer failed + MEDIA_LOGI("ReadAtMicMode ret: %{public}d", static_cast(ret)); + screenCaptureServer_->micAudioCapture_->captureState_ = AudioCapturerWrapperState::CAPTURER_UNKNOWN; + ret = screenCaptureServer_->audioSource_->ReadAtMicMode(buffer, bufferSize); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::RETRY_SKIP); + screenCaptureServer_->micAudioCapture_ = nullptr; + ret = screenCaptureServer_->audioSource_->ReadAtMicMode(buffer, bufferSize); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::INVALID); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, ReadAtMicMode_002, TestSize.Level2) +{ + RecorderInfo recorderInfo; + SetRecorderInfo("start_file_inner_audio_capture_001.mp4", recorderInfo); + SetValidConfigFile(recorderInfo); + ASSERT_EQ(InitFileScreenCaptureServer(), MSERR_OK); + screenCaptureServer_->SetMicrophoneEnabled(true); + screenCaptureServer_->audioSource_ = std::make_unique( + AVScreenCaptureMixMode::MIC_MODE, screenCaptureServer_.get()); + screenCaptureServer_->captureCallback_ = std::make_shared(); + screenCaptureServer_->captureCallback_->SetAudioSource(screenCaptureServer_->audioSource_); + screenCaptureServer_->captureConfig_.audioInfo.micCapInfo.state = + AVScreenCaptureParamValidationState::VALIDATION_VALID; + screenCaptureServer_->audioSource_->speakerAliveStatus_ = false; + screenCaptureServer_->captureState_ = AVScreenCaptureState::STARTED; + screenCaptureServer_->recorderFileAudioType_ = AVScreenCaptureMixMode::MIC_MODE; + const int bufferSize = 10; + uint8_t *micBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + std::shared_ptr micAudioBuffer = std::make_shared(micBuffer, bufferSize, 0, + SOURCE_DEFAULT); + std::shared_ptr buffer = AVBuffer::CreateAVBuffer(); + screenCaptureServer_->micAudioCapture_ = std::make_shared( + screenCaptureServer_->captureConfig_.audioInfo.micCapInfo, screenCaptureServer_->screenCaptureCb_, + std::string("OS_MicAudioCapture"), screenCaptureServer_->contentFilter_); + screenCaptureServer_->micAudioCapture_->captureState_ = AudioCapturerWrapperState::CAPTURER_RECORDING; + screenCaptureServer_->micAudioCapture_->isRunning_.store(true); + screenCaptureServer_->micAudioCapture_->availBuffers_.push_back(micAudioBuffer); + AudioDataSourceReadAtActionState ret = screenCaptureServer_->audioSource_->ReadAtMicMode(buffer, bufferSize); + MEDIA_LOGI("ReadAtMicMode ret: %{public}d", static_cast(ret)); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::RETRY_SKIP); uint8_t data[bufferSize]; std::shared_ptr bufferMem = AVMemory::CreateAVMemory(data, bufferSize, bufferSize); - int32_t ret = screenCaptureServer_->audioSource_->MixModeBufferWrite(innerAudioBuffer, micAudioBuffer, bufferMem); - ASSERT_EQ(ret, MSERR_OK); + buffer->memory_ = bufferMem; + ret = screenCaptureServer_->audioSource_->ReadAtMicMode(buffer, bufferSize); + MEDIA_LOGI("ReadAtMicMode 2 ret: %{public}d", static_cast(ret)); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::OK); } -HWTEST_F(ScreenCaptureServerFunctionTest, MixModeBufferWrite_002, TestSize.Level2) +HWTEST_F(ScreenCaptureServerFunctionTest, ReadAtInnerMode_001, TestSize.Level2) { + RecorderInfo recorderInfo; + SetRecorderInfo("start_file_inner_audio_capture_001.mp4", recorderInfo); + SetValidConfigFile(recorderInfo); + ASSERT_EQ(InitFileScreenCaptureServer(), MSERR_OK); + screenCaptureServer_->SetMicrophoneEnabled(false); screenCaptureServer_->audioSource_ = std::make_unique( - AVScreenCaptureMixMode::MIX_MODE, screenCaptureServer_.get()); + AVScreenCaptureMixMode::INNER_MODE, screenCaptureServer_.get()); + screenCaptureServer_->captureCallback_ = std::make_shared(); + screenCaptureServer_->captureCallback_->SetAudioSource(screenCaptureServer_->audioSource_); + screenCaptureServer_->captureConfig_.audioInfo.innerCapInfo.state = + AVScreenCaptureParamValidationState::VALIDATION_VALID; + screenCaptureServer_->audioSource_->speakerAliveStatus_ = false; + screenCaptureServer_->captureState_ = AVScreenCaptureState::STARTED; + screenCaptureServer_->recorderFileAudioType_ = AVScreenCaptureMixMode::INNER_MODE; + const int bufferSize = 10; + std::shared_ptr buffer = AVBuffer::CreateAVBuffer(); + screenCaptureServer_->innerAudioCapture_ = std::make_shared( + screenCaptureServer_->captureConfig_.audioInfo.innerCapInfo, screenCaptureServer_->screenCaptureCb_, + std::string("OS_innerAudioCapture"), screenCaptureServer_->contentFilter_); + screenCaptureServer_->innerAudioCapture_->captureState_ = AudioCapturerWrapperState::CAPTURER_RECORDING; + AudioDataSourceReadAtActionState ret = screenCaptureServer_->audioSource_->ReadAtInnerMode(buffer, bufferSize); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::RETRY_SKIP); + MEDIA_LOGI("ReadAtInnerMode ret: %{public}d", static_cast(ret)); + screenCaptureServer_->innerAudioCapture_->captureState_ = AudioCapturerWrapperState::CAPTURER_UNKNOWN; + ret = screenCaptureServer_->audioSource_->ReadAtInnerMode(buffer, bufferSize); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::RETRY_SKIP); + screenCaptureServer_->innerAudioCapture_ = nullptr; + ret = screenCaptureServer_->audioSource_->ReadAtInnerMode(buffer, bufferSize); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::INVALID); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, ReadAtInnerMode_002, TestSize.Level2) +{ + RecorderInfo recorderInfo; + SetRecorderInfo("start_file_inner_audio_capture_001.mp4", recorderInfo); + SetValidConfigFile(recorderInfo); + ASSERT_EQ(InitFileScreenCaptureServer(), MSERR_OK); + screenCaptureServer_->SetMicrophoneEnabled(false); + screenCaptureServer_->audioSource_ = std::make_unique( + AVScreenCaptureMixMode::INNER_MODE, screenCaptureServer_.get()); + screenCaptureServer_->captureCallback_ = std::make_shared(); + screenCaptureServer_->captureCallback_->SetAudioSource(screenCaptureServer_->audioSource_); + screenCaptureServer_->captureConfig_.audioInfo.innerCapInfo.state = + AVScreenCaptureParamValidationState::VALIDATION_VALID; + screenCaptureServer_->audioSource_->speakerAliveStatus_ = false; + screenCaptureServer_->captureState_ = AVScreenCaptureState::STARTED; + screenCaptureServer_->recorderFileAudioType_ = AVScreenCaptureMixMode::INNER_MODE; const int bufferSize = 10; uint8_t *innerBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); std::shared_ptr innerAudioBuffer = std::make_shared(innerBuffer, bufferSize, 0, SOURCE_DEFAULT); - std::shared_ptr micAudioBuffer; + std::shared_ptr buffer = AVBuffer::CreateAVBuffer(); + SetSCInnerAudioCaptureAndPushData(innerAudioBuffer); + AudioDataSourceReadAtActionState ret = screenCaptureServer_->audioSource_->ReadAtInnerMode(buffer, bufferSize); + MEDIA_LOGI("ReadAtInnerMode ret: %{public}d", static_cast(ret)); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::RETRY_SKIP); uint8_t data[bufferSize]; std::shared_ptr bufferMem = AVMemory::CreateAVMemory(data, bufferSize, bufferSize); - int32_t ret = screenCaptureServer_->audioSource_->MixModeBufferWrite(innerAudioBuffer, micAudioBuffer, bufferMem); - ASSERT_EQ(ret, MSERR_OK); + buffer->memory_ = bufferMem; + ret = screenCaptureServer_->audioSource_->ReadAtInnerMode(buffer, bufferSize); + MEDIA_LOGI("ReadAtInnerMode 2 ret: %{public}d", static_cast(ret)); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::OK); } -HWTEST_F(ScreenCaptureServerFunctionTest, MixModeBufferWrite_003, TestSize.Level2) +HWTEST_F(ScreenCaptureServerFunctionTest, ReadAtMixMode_001, TestSize.Level2) { + RecorderInfo recorderInfo; + SetRecorderInfo("start_file_inner_audio_capture_001.mp4", recorderInfo); + SetValidConfigFile(recorderInfo); + ASSERT_EQ(InitFileScreenCaptureServer(), MSERR_OK); + screenCaptureServer_->SetMicrophoneEnabled(true); screenCaptureServer_->audioSource_ = std::make_unique( AVScreenCaptureMixMode::MIX_MODE, screenCaptureServer_.get()); + screenCaptureServer_->captureCallback_ = std::make_shared(); + screenCaptureServer_->captureCallback_->SetAudioSource(screenCaptureServer_->audioSource_); + screenCaptureServer_->captureConfig_.audioInfo.innerCapInfo.state = + AVScreenCaptureParamValidationState::VALIDATION_VALID; + screenCaptureServer_->audioSource_->speakerAliveStatus_ = false; + screenCaptureServer_->StartFileInnerAudioCapture(); + screenCaptureServer_->StartFileMicAudioCapture(); + screenCaptureServer_->captureState_ = AVScreenCaptureState::STARTED; + screenCaptureServer_->recorderFileAudioType_ = AVScreenCaptureMixMode::MIX_MODE; const int bufferSize = 10; + uint8_t *innerBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); uint8_t *micBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); - std::shared_ptr innerAudioBuffer; + std::shared_ptr innerAudioBuffer = std::make_shared(innerBuffer, bufferSize, 0, + SOURCE_DEFAULT); std::shared_ptr micAudioBuffer = std::make_shared(micBuffer, bufferSize, 0, SOURCE_DEFAULT); - uint8_t data[bufferSize]; - std::shared_ptr bufferMem = AVMemory::CreateAVMemory(data, bufferSize, bufferSize); - int32_t ret = screenCaptureServer_->audioSource_->MixModeBufferWrite(innerAudioBuffer, micAudioBuffer, bufferMem); - ASSERT_EQ(ret, MSERR_OK); + std::shared_ptr buffer = AVBuffer::CreateAVBuffer(); + screenCaptureServer_->audioSource_->ReadAtMixMode(buffer, bufferSize); + ASSERT_EQ(screenCaptureServer_->StopScreenCapture(), MSERR_OK); } -HWTEST_F(ScreenCaptureServerFunctionTest, AcquireAudioBufferMix_001, TestSize.Level2) +HWTEST_F(ScreenCaptureServerFunctionTest, ReadWriteAudioBufferMix_001, TestSize.Level2) { + RecorderInfo recorderInfo; + SetRecorderInfo("start_file_inner_audio_capture_001.mp4", recorderInfo); + SetValidConfigFile(recorderInfo); + ASSERT_EQ(InitFileScreenCaptureServer(), MSERR_OK); + screenCaptureServer_->SetMicrophoneEnabled(true); + screenCaptureServer_->audioSource_ = std::make_unique( + AVScreenCaptureMixMode::MIX_MODE, screenCaptureServer_.get()); + screenCaptureServer_->captureCallback_ = std::make_shared(); + screenCaptureServer_->captureCallback_->SetAudioSource(screenCaptureServer_->audioSource_); + screenCaptureServer_->captureConfig_.audioInfo.innerCapInfo.state = + AVScreenCaptureParamValidationState::VALIDATION_VALID; + screenCaptureServer_->audioSource_->speakerAliveStatus_ = false; + screenCaptureServer_->StartFileInnerAudioCapture(); + screenCaptureServer_->StartFileMicAudioCapture(); screenCaptureServer_->captureState_ = AVScreenCaptureState::STARTED; - std::shared_ptr innerAudioBuffer; - std::shared_ptr micAudioBuffer; - int32_t ret = screenCaptureServer_->AcquireAudioBufferMix(innerAudioBuffer, micAudioBuffer, - AVScreenCaptureMixMode::MIX_MODE); - ASSERT_EQ(ret, MSERR_OK); - ret = screenCaptureServer_->AcquireAudioBufferMix(innerAudioBuffer, micAudioBuffer, - AVScreenCaptureMixMode::MIC_MODE); - ASSERT_EQ(ret, MSERR_OK); - ret = screenCaptureServer_->AcquireAudioBufferMix(innerAudioBuffer, micAudioBuffer, - AVScreenCaptureMixMode::INNER_MODE); - ASSERT_EQ(ret, MSERR_OK); + screenCaptureServer_->recorderFileAudioType_ = AVScreenCaptureMixMode::MIX_MODE; + const int bufferSize = 10; + uint8_t *innerBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + uint8_t *micBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + std::shared_ptr innerAudioBuffer = std::make_shared(innerBuffer, bufferSize, 0, + SOURCE_DEFAULT); + std::shared_ptr micAudioBuffer = std::make_shared(micBuffer, bufferSize, 0, + SOURCE_DEFAULT); + std::shared_ptr buffer = AVBuffer::CreateAVBuffer(); + screenCaptureServer_->audioSource_->ReadWriteAudioBufferMix(buffer, bufferSize, innerAudioBuffer, micAudioBuffer); + ASSERT_EQ(screenCaptureServer_->StopScreenCapture(), MSERR_OK); } -HWTEST_F(ScreenCaptureServerFunctionTest, AcquireAudioBufferMix_002, TestSize.Level2) +HWTEST_F(ScreenCaptureServerFunctionTest, ReadWriteAudioBufferMix_002, TestSize.Level2) { - SetValidConfig(); - ASSERT_EQ(InitStreamScreenCaptureServer(), MSERR_OK); - ASSERT_EQ(StartStreamAudioCapture(), MSERR_OK); + RecorderInfo recorderInfo; + SetRecorderInfo("start_file_inner_audio_capture_001.mp4", recorderInfo); + SetValidConfigFile(recorderInfo); + ASSERT_EQ(InitFileScreenCaptureServer(), MSERR_OK); + screenCaptureServer_->SetMicrophoneEnabled(true); + screenCaptureServer_->audioSource_ = std::make_unique( + AVScreenCaptureMixMode::MIX_MODE, screenCaptureServer_.get()); + screenCaptureServer_->captureCallback_ = std::make_shared(); + screenCaptureServer_->captureCallback_->SetAudioSource(screenCaptureServer_->audioSource_); + screenCaptureServer_->captureConfig_.audioInfo.innerCapInfo.state = + AVScreenCaptureParamValidationState::VALIDATION_VALID; + screenCaptureServer_->audioSource_->speakerAliveStatus_ = false; + screenCaptureServer_->StartFileInnerAudioCapture(); + screenCaptureServer_->StartFileMicAudioCapture(); screenCaptureServer_->captureState_ = AVScreenCaptureState::STARTED; - std::shared_ptr innerAudioBuffer; - std::shared_ptr micAudioBuffer; - int32_t ret = screenCaptureServer_->AcquireAudioBufferMix(innerAudioBuffer, micAudioBuffer, - AVScreenCaptureMixMode::MIX_MODE); - ASSERT_EQ(ret, MSERR_OK); - ret = screenCaptureServer_->AcquireAudioBufferMix(innerAudioBuffer, micAudioBuffer, - AVScreenCaptureMixMode::MIC_MODE); - ASSERT_EQ(ret, MSERR_OK); - ret = screenCaptureServer_->AcquireAudioBufferMix(innerAudioBuffer, micAudioBuffer, - AVScreenCaptureMixMode::INNER_MODE); - ASSERT_EQ(ret, MSERR_OK); + screenCaptureServer_->recorderFileAudioType_ = AVScreenCaptureMixMode::MIX_MODE; + screenCaptureServer_->recorderFileWithVideo_ = true; + const int bufferSize = 10; + uint8_t *innerBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + uint8_t *micBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + std::shared_ptr innerAudioBuffer = std::make_shared(innerBuffer, bufferSize, 0, + SOURCE_DEFAULT); + std::shared_ptr micAudioBuffer = std::make_shared(micBuffer, bufferSize, 0, + SOURCE_DEFAULT); + std::shared_ptr buffer = AVBuffer::CreateAVBuffer(); + screenCaptureServer_->audioSource_->ReadWriteAudioBufferMix(buffer, bufferSize, innerAudioBuffer, micAudioBuffer); + ASSERT_EQ(screenCaptureServer_->StopScreenCapture(), MSERR_OK); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, ReadWriteAudioBufferMixCore_001, TestSize.Level2) +{ + RecorderInfo recorderInfo; + SetRecorderInfo("start_file_inner_audio_capture_001.mp4", recorderInfo); + SetValidConfigFile(recorderInfo); + ASSERT_EQ(InitFileScreenCaptureServer(), MSERR_OK); + screenCaptureServer_->SetMicrophoneEnabled(true); + screenCaptureServer_->audioSource_ = std::make_unique( + AVScreenCaptureMixMode::MIX_MODE, screenCaptureServer_.get()); + screenCaptureServer_->captureCallback_ = std::make_shared(); + screenCaptureServer_->captureCallback_->SetAudioSource(screenCaptureServer_->audioSource_); + screenCaptureServer_->captureConfig_.audioInfo.innerCapInfo.state = + AVScreenCaptureParamValidationState::VALIDATION_VALID; + screenCaptureServer_->audioSource_->speakerAliveStatus_ = false; + screenCaptureServer_->StartFileInnerAudioCapture(); + screenCaptureServer_->StartFileMicAudioCapture(); + screenCaptureServer_->captureState_ = AVScreenCaptureState::STARTED; + screenCaptureServer_->recorderFileAudioType_ = AVScreenCaptureMixMode::MIX_MODE; + const int bufferSize = 10; + uint8_t *innerBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + uint8_t *micBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + std::shared_ptr innerAudioBuffer = std::make_shared(innerBuffer, bufferSize, 0, + SOURCE_DEFAULT); + std::shared_ptr micAudioBuffer = std::make_shared(micBuffer, bufferSize, 0, + SOURCE_DEFAULT); + std::shared_ptr buffer = AVBuffer::CreateAVBuffer(); + screenCaptureServer_->audioSource_->ReadWriteAudioBufferMixCore(buffer, bufferSize, innerAudioBuffer, + micAudioBuffer); + ASSERT_EQ(screenCaptureServer_->StopScreenCapture(), MSERR_OK); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, GetFirstAudioTime_001, TestSize.Level2) +{ + screenCaptureServer_->audioSource_ = std::make_unique( + AVScreenCaptureMixMode::MIC_MODE, screenCaptureServer_.get()); + screenCaptureServer_->captureCallback_ = std::make_shared(); + screenCaptureServer_->captureCallback_->SetAudioSource(screenCaptureServer_->audioSource_); + screenCaptureServer_->captureConfig_.audioInfo.innerCapInfo.state = + AVScreenCaptureParamValidationState::VALIDATION_VALID; + const int bufferSize = 10; + uint8_t *innerBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + uint8_t *micBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + std::shared_ptr innerAudioBuffer = std::make_shared(innerBuffer, bufferSize, 0, + SOURCE_DEFAULT); + std::shared_ptr micAudioBuffer = std::make_shared(micBuffer, bufferSize, 0, + SOURCE_DEFAULT); + innerAudioBuffer->timestamp = 2; + micAudioBuffer->timestamp = 1; + int64_t resTime = screenCaptureServer_->audioSource_->GetFirstAudioTime(innerAudioBuffer, micAudioBuffer); + ASSERT_EQ(resTime, micAudioBuffer->timestamp); + innerAudioBuffer->timestamp = 1; + micAudioBuffer->timestamp = 2; + resTime = screenCaptureServer_->audioSource_->GetFirstAudioTime(innerAudioBuffer, micAudioBuffer); + ASSERT_EQ(resTime, innerAudioBuffer->timestamp); + innerAudioBuffer = nullptr; + resTime = screenCaptureServer_->audioSource_->GetFirstAudioTime(innerAudioBuffer, micAudioBuffer); + ASSERT_EQ(resTime, micAudioBuffer->timestamp); + uint8_t *innerBufferNew = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + innerAudioBuffer = std::make_shared(innerBufferNew, bufferSize, 0, + SOURCE_DEFAULT); + innerAudioBuffer->timestamp = 1; + micAudioBuffer = nullptr; + resTime = screenCaptureServer_->audioSource_->GetFirstAudioTime(innerAudioBuffer, micAudioBuffer); + ASSERT_EQ(resTime, innerAudioBuffer->timestamp); + innerAudioBuffer = nullptr; + micAudioBuffer = nullptr; + resTime = screenCaptureServer_->audioSource_->GetFirstAudioTime(innerAudioBuffer, micAudioBuffer); + ASSERT_EQ(resTime, -1); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, WriteInnerAudio_001, TestSize.Level2) +{ + RecorderInfo recorderInfo; + SetRecorderInfo("start_file_inner_audio_capture_001.mp4", recorderInfo); + SetValidConfigFile(recorderInfo); + ASSERT_EQ(InitFileScreenCaptureServer(), MSERR_OK); + screenCaptureServer_->SetMicrophoneEnabled(true); + screenCaptureServer_->audioSource_ = std::make_unique( + AVScreenCaptureMixMode::INNER_MODE, screenCaptureServer_.get()); + screenCaptureServer_->captureCallback_ = std::make_shared(); + screenCaptureServer_->captureCallback_->SetAudioSource(screenCaptureServer_->audioSource_); + screenCaptureServer_->captureConfig_.audioInfo.innerCapInfo.state = + AVScreenCaptureParamValidationState::VALIDATION_VALID; + screenCaptureServer_->audioSource_->speakerAliveStatus_ = false; + screenCaptureServer_->recorderFileAudioType_ = AVScreenCaptureMixMode::INNER_MODE; + const int bufferSize = 10; + uint8_t *innerBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + std::shared_ptr innerAudioBuffer = std::make_shared(innerBuffer, bufferSize, 0, + SOURCE_DEFAULT); + std::shared_ptr buffer = AVBuffer::CreateAVBuffer(); + SetSCInnerAudioCaptureAndPushData(innerAudioBuffer); + AudioDataSourceReadAtActionState ret = screenCaptureServer_->audioSource_->WriteInnerAudio(buffer, bufferSize, + innerAudioBuffer); + MEDIA_LOGI("WriteInnerAudio_001 ret: %{public}d", static_cast(ret)); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::RETRY_SKIP); + uint8_t data[bufferSize]; + std::shared_ptr bufferMem = AVMemory::CreateAVMemory(data, bufferSize, bufferSize); + buffer->memory_ = bufferMem; + screenCaptureServer_->audioSource_->firstAudioFramePts_.store(-1); + ret = screenCaptureServer_->audioSource_->WriteInnerAudio(buffer, bufferSize, innerAudioBuffer); + MEDIA_LOGI("WriteInnerAudio_001 1 ret: %{public}d", static_cast(ret)); + screenCaptureServer_->audioSource_->firstAudioFramePts_.store(10); + ret = screenCaptureServer_->audioSource_->WriteInnerAudio(buffer, bufferSize, innerAudioBuffer); + MEDIA_LOGI("WriteInnerAudio_001 2 ret: %{public}d", static_cast(ret)); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, WriteMicAudio_001, TestSize.Level2) +{ + RecorderInfo recorderInfo; + SetRecorderInfo("start_file_inner_audio_capture_001.mp4", recorderInfo); + SetValidConfigFile(recorderInfo); + ASSERT_EQ(InitFileScreenCaptureServer(), MSERR_OK); + screenCaptureServer_->SetMicrophoneEnabled(true); + screenCaptureServer_->audioSource_ = std::make_unique( + AVScreenCaptureMixMode::MIC_MODE, screenCaptureServer_.get()); + screenCaptureServer_->captureCallback_ = std::make_shared(); + screenCaptureServer_->captureCallback_->SetAudioSource(screenCaptureServer_->audioSource_); + screenCaptureServer_->captureConfig_.audioInfo.micCapInfo.state = + AVScreenCaptureParamValidationState::VALIDATION_VALID; + screenCaptureServer_->audioSource_->speakerAliveStatus_ = false; + screenCaptureServer_->recorderFileAudioType_ = AVScreenCaptureMixMode::MIC_MODE; + const int bufferSize = 10; + uint8_t *micBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + std::shared_ptr micAudioBuffer = std::make_shared(micBuffer, bufferSize, 0, + SOURCE_DEFAULT); + std::shared_ptr buffer = AVBuffer::CreateAVBuffer(); + SetSCMicAudioCaptureAndPushData(micAudioBuffer); + AudioDataSourceReadAtActionState ret = screenCaptureServer_->audioSource_->WriteMicAudio(buffer, bufferSize, + micAudioBuffer); + MEDIA_LOGI("WriteMicAudio_001 ret: %{public}d", static_cast(ret)); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::RETRY_SKIP); + uint8_t data[bufferSize]; + std::shared_ptr bufferMem = AVMemory::CreateAVMemory(data, bufferSize, bufferSize); + buffer->memory_ = bufferMem; + screenCaptureServer_->audioSource_->firstAudioFramePts_.store(-1); + ret = screenCaptureServer_->audioSource_->WriteMicAudio(buffer, bufferSize, micAudioBuffer); + MEDIA_LOGI("WriteMicAudio_001 1 ret: %{public}d", static_cast(ret)); + screenCaptureServer_->audioSource_->firstAudioFramePts_.store(10); + ret = screenCaptureServer_->audioSource_->WriteMicAudio(buffer, bufferSize, micAudioBuffer); + MEDIA_LOGI("WriteMicAudio_001 2 ret: %{public}d", static_cast(ret)); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, WriteMixAudio_001, TestSize.Level2) +{ + RecorderInfo recorderInfo; + SetRecorderInfo("start_file_inner_audio_capture_001.mp4", recorderInfo); + SetValidConfigFile(recorderInfo); + ASSERT_EQ(InitFileScreenCaptureServer(), MSERR_OK); + screenCaptureServer_->SetMicrophoneEnabled(true); + screenCaptureServer_->audioSource_ = std::make_unique( + AVScreenCaptureMixMode::MIX_MODE, screenCaptureServer_.get()); + screenCaptureServer_->captureCallback_ = std::make_shared(); + screenCaptureServer_->captureCallback_->SetAudioSource(screenCaptureServer_->audioSource_); + screenCaptureServer_->captureConfig_.audioInfo.micCapInfo.state = + AVScreenCaptureParamValidationState::VALIDATION_VALID; + screenCaptureServer_->audioSource_->speakerAliveStatus_ = false; + screenCaptureServer_->recorderFileAudioType_ = AVScreenCaptureMixMode::MIX_MODE; + const int bufferSize = 10; + uint8_t *micBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + uint8_t *innerBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + std::shared_ptr innerAudioBuffer = std::make_shared(innerBuffer, bufferSize, 0, + SOURCE_DEFAULT); + std::shared_ptr micAudioBuffer = std::make_shared(micBuffer, bufferSize, 0, + SOURCE_DEFAULT); + SetSCMicAudioCaptureAndPushData(micAudioBuffer); + SetSCInnerAudioCaptureAndPushData(innerAudioBuffer); + std::shared_ptr buffer = AVBuffer::CreateAVBuffer(); + AudioDataSourceReadAtActionState ret = screenCaptureServer_->audioSource_->WriteMixAudio(buffer, bufferSize, + innerAudioBuffer, micAudioBuffer); + MEDIA_LOGI("WriteMixAudio_001 ret: %{public}d", static_cast(ret)); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::RETRY_SKIP); + uint8_t data[bufferSize]; + std::shared_ptr bufferMem = AVMemory::CreateAVMemory(data, bufferSize, bufferSize); + buffer->memory_ = bufferMem; + screenCaptureServer_->audioSource_->firstAudioFramePts_.store(-1); + ret = screenCaptureServer_->audioSource_->WriteMixAudio(buffer, bufferSize, innerAudioBuffer, micAudioBuffer); + MEDIA_LOGI("WriteMixAudio_001 1 ret: %{public}d", static_cast(ret)); + screenCaptureServer_->audioSource_->firstAudioFramePts_.store(10); + ret = screenCaptureServer_->audioSource_->WriteMixAudio(buffer, bufferSize, innerAudioBuffer, micAudioBuffer); + MEDIA_LOGI("WriteMixAudio_001 2 ret: %{public}d", static_cast(ret)); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, InnerMicAudioSync_001, TestSize.Level2) +{ + RecorderInfo recorderInfo; + SetRecorderInfo("start_file_inner_audio_capture_001.mp4", recorderInfo); + SetValidConfigFile(recorderInfo); + ASSERT_EQ(InitFileScreenCaptureServer(), MSERR_OK); + screenCaptureServer_->SetMicrophoneEnabled(true); + screenCaptureServer_->audioSource_ = std::make_unique( + AVScreenCaptureMixMode::MIX_MODE, screenCaptureServer_.get()); + screenCaptureServer_->captureCallback_ = std::make_shared(); + screenCaptureServer_->captureCallback_->SetAudioSource(screenCaptureServer_->audioSource_); + screenCaptureServer_->captureConfig_.audioInfo.micCapInfo.state = + AVScreenCaptureParamValidationState::VALIDATION_VALID; + screenCaptureServer_->audioSource_->speakerAliveStatus_ = false; + screenCaptureServer_->recorderFileAudioType_ = AVScreenCaptureMixMode::MIX_MODE; + screenCaptureServer_->StartFileInnerAudioCapture(); + screenCaptureServer_->StartFileMicAudioCapture(); + const int bufferSize = 10; + uint8_t *micBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + uint8_t *innerBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + std::shared_ptr innerAudioBuffer = std::make_shared(innerBuffer, bufferSize, 0, + SOURCE_DEFAULT); + std::shared_ptr micAudioBuffer = std::make_shared(micBuffer, bufferSize, 0, + SOURCE_DEFAULT); + micAudioBuffer->timestamp = 1; + innerAudioBuffer->timestamp = 31333334; + SetSCMicAudioCaptureAndPushData(micAudioBuffer); + SetSCInnerAudioCaptureAndPushData(innerAudioBuffer); + std::shared_ptr buffer = AVBuffer::CreateAVBuffer(); + AudioDataSourceReadAtActionState ret = screenCaptureServer_->audioSource_->InnerMicAudioSync(buffer, bufferSize, + innerAudioBuffer, micAudioBuffer); + MEDIA_LOGI("InnerMicAudioSync_001 ret: %{public}d", static_cast(ret)); + ASSERT_EQ(screenCaptureServer_->StopScreenCapture(), MSERR_OK); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, InnerMicAudioSync_002, TestSize.Level2) +{ + RecorderInfo recorderInfo; + SetRecorderInfo("start_file_inner_audio_capture_001.mp4", recorderInfo); + SetValidConfigFile(recorderInfo); + ASSERT_EQ(InitFileScreenCaptureServer(), MSERR_OK); + screenCaptureServer_->SetMicrophoneEnabled(true); + screenCaptureServer_->audioSource_ = std::make_unique( + AVScreenCaptureMixMode::MIX_MODE, screenCaptureServer_.get()); + screenCaptureServer_->captureCallback_ = std::make_shared(); + screenCaptureServer_->captureCallback_->SetAudioSource(screenCaptureServer_->audioSource_); + screenCaptureServer_->captureConfig_.audioInfo.micCapInfo.state = + AVScreenCaptureParamValidationState::VALIDATION_VALID; + screenCaptureServer_->audioSource_->speakerAliveStatus_ = false; + screenCaptureServer_->recorderFileAudioType_ = AVScreenCaptureMixMode::MIX_MODE; + screenCaptureServer_->StartFileInnerAudioCapture(); + screenCaptureServer_->StartFileMicAudioCapture(); + const int bufferSize = 10; + uint8_t *micBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + uint8_t *innerBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + std::shared_ptr innerAudioBuffer = std::make_shared(innerBuffer, bufferSize, 0, + SOURCE_DEFAULT); + std::shared_ptr micAudioBuffer = std::make_shared(micBuffer, bufferSize, 0, + SOURCE_DEFAULT); + micAudioBuffer->timestamp = 21333334; + innerAudioBuffer->timestamp = 31333334; + SetSCMicAudioCaptureAndPushData(micAudioBuffer); + SetSCInnerAudioCaptureAndPushData(innerAudioBuffer); + std::shared_ptr buffer = AVBuffer::CreateAVBuffer(); + AudioDataSourceReadAtActionState ret = screenCaptureServer_->audioSource_->InnerMicAudioSync(buffer, bufferSize, + innerAudioBuffer, micAudioBuffer); + MEDIA_LOGI("InnerMicAudioSync_001 ret: %{public}d", static_cast(ret)); + ASSERT_EQ(screenCaptureServer_->StopScreenCapture(), MSERR_OK); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, InnerMicAudioSync_003, TestSize.Level2) +{ + RecorderInfo recorderInfo; + SetRecorderInfo("start_file_inner_audio_capture_001.mp4", recorderInfo); + SetValidConfigFile(recorderInfo); + ASSERT_EQ(InitFileScreenCaptureServer(), MSERR_OK); + screenCaptureServer_->SetMicrophoneEnabled(true); + screenCaptureServer_->audioSource_ = std::make_unique( + AVScreenCaptureMixMode::MIX_MODE, screenCaptureServer_.get()); + screenCaptureServer_->captureCallback_ = std::make_shared(); + screenCaptureServer_->captureCallback_->SetAudioSource(screenCaptureServer_->audioSource_); + screenCaptureServer_->captureConfig_.audioInfo.micCapInfo.state = + AVScreenCaptureParamValidationState::VALIDATION_VALID; + screenCaptureServer_->audioSource_->speakerAliveStatus_ = false; + screenCaptureServer_->recorderFileAudioType_ = AVScreenCaptureMixMode::MIX_MODE; + screenCaptureServer_->StartFileInnerAudioCapture(); + screenCaptureServer_->StartFileMicAudioCapture(); + const int bufferSize = 10; + uint8_t *micBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + uint8_t *innerBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + std::shared_ptr innerAudioBuffer = std::make_shared(innerBuffer, bufferSize, 0, + SOURCE_DEFAULT); + std::shared_ptr micAudioBuffer = std::make_shared(micBuffer, bufferSize, 0, + SOURCE_DEFAULT); + micAudioBuffer->timestamp = 31333334; + innerAudioBuffer->timestamp = 1; + SetSCMicAudioCaptureAndPushData(micAudioBuffer); + SetSCInnerAudioCaptureAndPushData(innerAudioBuffer); + std::shared_ptr buffer = AVBuffer::CreateAVBuffer(); + AudioDataSourceReadAtActionState ret = screenCaptureServer_->audioSource_->InnerMicAudioSync(buffer, bufferSize, + innerAudioBuffer, micAudioBuffer); + MEDIA_LOGI("InnerMicAudioSync_001 ret: %{public}d", static_cast(ret)); + ASSERT_EQ(screenCaptureServer_->StopScreenCapture(), MSERR_OK); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, HandleMicBeforeInnerSync_001, TestSize.Level2) +{ + RecorderInfo recorderInfo; + SetRecorderInfo("start_file_inner_audio_capture_001.mp4", recorderInfo); + SetValidConfigFile(recorderInfo); + ASSERT_EQ(InitFileScreenCaptureServer(), MSERR_OK); + screenCaptureServer_->SetMicrophoneEnabled(true); + screenCaptureServer_->audioSource_ = std::make_unique( + AVScreenCaptureMixMode::MIX_MODE, screenCaptureServer_.get()); + screenCaptureServer_->captureCallback_ = std::make_shared(); + screenCaptureServer_->captureCallback_->SetAudioSource(screenCaptureServer_->audioSource_); + screenCaptureServer_->captureConfig_.audioInfo.micCapInfo.state = + AVScreenCaptureParamValidationState::VALIDATION_VALID; + screenCaptureServer_->audioSource_->speakerAliveStatus_ = false; + screenCaptureServer_->recorderFileAudioType_ = AVScreenCaptureMixMode::MIX_MODE; + screenCaptureServer_->StartFileInnerAudioCapture(); + screenCaptureServer_->StartFileMicAudioCapture(); + const int bufferSize = 10; + uint8_t *micBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + uint8_t *innerBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + std::shared_ptr innerAudioBuffer = std::make_shared(innerBuffer, bufferSize, 0, + SOURCE_DEFAULT); + std::shared_ptr micAudioBuffer = std::make_shared(micBuffer, bufferSize, 0, + SOURCE_DEFAULT); + micAudioBuffer->timestamp = 1; + innerAudioBuffer->timestamp = 3000000000; + SetSCMicAudioCaptureAndPushData(micAudioBuffer); + SetSCInnerAudioCaptureAndPushData(innerAudioBuffer); + std::shared_ptr buffer = AVBuffer::CreateAVBuffer(); + AudioDataSourceReadAtActionState ret = screenCaptureServer_->audioSource_->HandleMicBeforeInnerSync(buffer, + bufferSize, innerAudioBuffer, micAudioBuffer); + MEDIA_LOGI("HandleMicBeforeInnerSync_001 ret: %{public}d", static_cast(ret)); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::RETRY_SKIP); + ASSERT_EQ(screenCaptureServer_->StopScreenCapture(), MSERR_OK); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, HandleMicBeforeInnerSync_002, TestSize.Level2) +{ + RecorderInfo recorderInfo; + SetRecorderInfo("start_file_inner_audio_capture_001.mp4", recorderInfo); + SetValidConfigFile(recorderInfo); + ASSERT_EQ(InitFileScreenCaptureServer(), MSERR_OK); + screenCaptureServer_->SetMicrophoneEnabled(true); + screenCaptureServer_->audioSource_ = std::make_unique( + AVScreenCaptureMixMode::MIX_MODE, screenCaptureServer_.get()); + screenCaptureServer_->captureCallback_ = std::make_shared(); + screenCaptureServer_->captureCallback_->SetAudioSource(screenCaptureServer_->audioSource_); + screenCaptureServer_->captureConfig_.audioInfo.micCapInfo.state = + AVScreenCaptureParamValidationState::VALIDATION_VALID; + screenCaptureServer_->captureConfig_.audioInfo.innerCapInfo.state = + AVScreenCaptureParamValidationState::VALIDATION_VALID; + screenCaptureServer_->audioSource_->speakerAliveStatus_ = false; + screenCaptureServer_->recorderFileAudioType_ = AVScreenCaptureMixMode::MIX_MODE; + screenCaptureServer_->StartFileInnerAudioCapture(); + screenCaptureServer_->StartFileMicAudioCapture(); + const int bufferSize = 10; + uint8_t *micBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + uint8_t *innerBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + std::shared_ptr innerAudioBuffer = std::make_shared(innerBuffer, bufferSize, 0, + SOURCE_DEFAULT); + std::shared_ptr micAudioBuffer = std::make_shared(micBuffer, bufferSize, 0, + SOURCE_DEFAULT); + micAudioBuffer->timestamp = 1; + innerAudioBuffer->timestamp = 3000000000; + SetSCMicAudioCaptureAndPushData(micAudioBuffer); + SetSCInnerAudioCaptureAndPushData(innerAudioBuffer); + std::shared_ptr buffer = AVBuffer::CreateAVBuffer(); + screenCaptureServer_->micAudioCapture_ = nullptr; + AudioDataSourceReadAtActionState ret = screenCaptureServer_->audioSource_->HandleMicBeforeInnerSync(buffer, + bufferSize, innerAudioBuffer, micAudioBuffer); + MEDIA_LOGI("HandleMicBeforeInnerSync_002 ret: %{public}d", static_cast(ret)); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::RETRY_SKIP); + ASSERT_EQ(screenCaptureServer_->StopScreenCapture(), MSERR_OK); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, HandleMicBeforeInnerSync_003, TestSize.Level2) +{ + RecorderInfo recorderInfo; + SetRecorderInfo("start_file_inner_audio_capture_001.mp4", recorderInfo); + SetValidConfigFile(recorderInfo); + ASSERT_EQ(InitFileScreenCaptureServer(), MSERR_OK); + screenCaptureServer_->SetMicrophoneEnabled(true); + screenCaptureServer_->audioSource_ = std::make_unique( + AVScreenCaptureMixMode::MIX_MODE, screenCaptureServer_.get()); + screenCaptureServer_->captureCallback_ = std::make_shared(); + screenCaptureServer_->captureCallback_->SetAudioSource(screenCaptureServer_->audioSource_); + screenCaptureServer_->captureConfig_.audioInfo.micCapInfo.state = + AVScreenCaptureParamValidationState::VALIDATION_VALID; + screenCaptureServer_->captureConfig_.audioInfo.innerCapInfo.state = + AVScreenCaptureParamValidationState::VALIDATION_VALID; + screenCaptureServer_->audioSource_->speakerAliveStatus_ = false; + screenCaptureServer_->recorderFileAudioType_ = AVScreenCaptureMixMode::MIX_MODE; + screenCaptureServer_->StartFileInnerAudioCapture(); + screenCaptureServer_->StartFileMicAudioCapture(); + const int bufferSize = 10; + uint8_t *micBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + uint8_t *innerBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + std::shared_ptr innerAudioBuffer = std::make_shared(innerBuffer, bufferSize, 0, + SOURCE_DEFAULT); + std::shared_ptr micAudioBuffer = std::make_shared(micBuffer, bufferSize, 0, + SOURCE_DEFAULT); + micAudioBuffer->timestamp = 2; + innerAudioBuffer->timestamp = 3; + SetSCMicAudioCaptureAndPushData(micAudioBuffer); + SetSCInnerAudioCaptureAndPushData(innerAudioBuffer); + std::shared_ptr buffer = AVBuffer::CreateAVBuffer(); + uint8_t data[bufferSize]; + std::shared_ptr bufferMem = AVMemory::CreateAVMemory(data, bufferSize, bufferSize); + buffer->memory_ = bufferMem; + AudioDataSourceReadAtActionState ret = screenCaptureServer_->audioSource_->HandleMicBeforeInnerSync(buffer, + bufferSize, innerAudioBuffer, micAudioBuffer); + MEDIA_LOGI("HandleMicBeforeInnerSync_003 ret: %{public}d", static_cast(ret)); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::OK); + ASSERT_EQ(screenCaptureServer_->StopScreenCapture(), MSERR_OK); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, VideoAudioSyncMixMode_001, TestSize.Level2) +{ + RecorderInfo recorderInfo; + SetRecorderInfo("start_file_inner_audio_capture_001.mp4", recorderInfo); + SetValidConfigFile(recorderInfo); + ASSERT_EQ(InitFileScreenCaptureServer(), MSERR_OK); + screenCaptureServer_->SetMicrophoneEnabled(true); + screenCaptureServer_->audioSource_ = std::make_unique( + AVScreenCaptureMixMode::MIX_MODE, screenCaptureServer_.get()); + screenCaptureServer_->captureCallback_ = std::make_shared(); + screenCaptureServer_->captureCallback_->SetAudioSource(screenCaptureServer_->audioSource_); + screenCaptureServer_->captureConfig_.audioInfo.micCapInfo.state = + AVScreenCaptureParamValidationState::VALIDATION_VALID; + screenCaptureServer_->captureConfig_.audioInfo.innerCapInfo.state = + AVScreenCaptureParamValidationState::VALIDATION_VALID; + screenCaptureServer_->audioSource_->speakerAliveStatus_ = false; + screenCaptureServer_->recorderFileAudioType_ = AVScreenCaptureMixMode::MIX_MODE; + screenCaptureServer_->StartFileInnerAudioCapture(); + screenCaptureServer_->StartFileMicAudioCapture(); + const int bufferSize = 10; + uint8_t *micBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + uint8_t *innerBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + std::shared_ptr innerAudioBuffer = std::make_shared(innerBuffer, bufferSize, 0, + SOURCE_DEFAULT); + std::shared_ptr micAudioBuffer = std::make_shared(micBuffer, bufferSize, 0, + SOURCE_DEFAULT); + SetSCMicAudioCaptureAndPushData(micAudioBuffer); + SetSCInnerAudioCaptureAndPushData(innerAudioBuffer); + std::shared_ptr buffer = AVBuffer::CreateAVBuffer(); + uint8_t data[bufferSize]; + std::shared_ptr bufferMem = AVMemory::CreateAVMemory(data, bufferSize, bufferSize); + buffer->memory_ = bufferMem; + int64_t timeWindow = -31333334; + AudioDataSourceReadAtActionState ret = screenCaptureServer_->audioSource_->VideoAudioSyncMixMode(buffer, + bufferSize, timeWindow, innerAudioBuffer, micAudioBuffer); + MEDIA_LOGI("VideoAudioSyncMixMode_001 ret: %{public}d", static_cast(ret)); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::SKIP_WITHOUT_LOG); + timeWindow = 31333334; + ret = screenCaptureServer_->audioSource_->VideoAudioSyncMixMode(buffer, + bufferSize, timeWindow, innerAudioBuffer, micAudioBuffer); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::SKIP_WITHOUT_LOG); + timeWindow = 1; + ret = screenCaptureServer_->audioSource_->VideoAudioSyncMixMode(buffer, + bufferSize, timeWindow, innerAudioBuffer, micAudioBuffer); + MEDIA_LOGI("VideoAudioSyncMixMode_001 ret: %{public}d", static_cast(ret)); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::OK); + ASSERT_EQ(screenCaptureServer_->StopScreenCapture(), MSERR_OK); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, VideoAudioSyncInnerMode_001, TestSize.Level2) +{ + RecorderInfo recorderInfo; + SetRecorderInfo("start_file_inner_audio_capture_001.mp4", recorderInfo); + SetValidConfigFile(recorderInfo); + ASSERT_EQ(InitFileScreenCaptureServer(), MSERR_OK); + screenCaptureServer_->SetMicrophoneEnabled(false); + screenCaptureServer_->audioSource_ = std::make_unique( + AVScreenCaptureMixMode::INNER_MODE, screenCaptureServer_.get()); + screenCaptureServer_->captureCallback_ = std::make_shared(); + screenCaptureServer_->captureCallback_->SetAudioSource(screenCaptureServer_->audioSource_); + screenCaptureServer_->captureConfig_.audioInfo.innerCapInfo.state = + AVScreenCaptureParamValidationState::VALIDATION_VALID; + screenCaptureServer_->audioSource_->speakerAliveStatus_ = false; + screenCaptureServer_->recorderFileAudioType_ = AVScreenCaptureMixMode::INNER_MODE; + screenCaptureServer_->StartFileInnerAudioCapture(); + const int bufferSize = 10; + uint8_t *innerBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + std::shared_ptr innerAudioBuffer = std::make_shared(innerBuffer, bufferSize, 0, + SOURCE_DEFAULT); + SetSCInnerAudioCaptureAndPushData(innerAudioBuffer); + std::shared_ptr buffer = AVBuffer::CreateAVBuffer(); + uint8_t data[bufferSize]; + std::shared_ptr bufferMem = AVMemory::CreateAVMemory(data, bufferSize, bufferSize); + buffer->memory_ = bufferMem; + int64_t timeWindow = -31333334; + AudioDataSourceReadAtActionState ret = screenCaptureServer_->audioSource_->VideoAudioSyncInnerMode(buffer, + bufferSize, timeWindow, innerAudioBuffer); + MEDIA_LOGI("VideoAudioSyncInnerMode_001 ret: %{public}d", static_cast(ret)); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::SKIP_WITHOUT_LOG); + timeWindow = 31333334; + ret = screenCaptureServer_->audioSource_->VideoAudioSyncInnerMode(buffer, + bufferSize, timeWindow, innerAudioBuffer); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::SKIP_WITHOUT_LOG); + timeWindow = 1; + ret = screenCaptureServer_->audioSource_->VideoAudioSyncInnerMode(buffer, + bufferSize, timeWindow, innerAudioBuffer); + MEDIA_LOGI("VideoAudioSyncInnerMode_001 ret: %{public}d", static_cast(ret)); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::OK); + ASSERT_EQ(screenCaptureServer_->StopScreenCapture(), MSERR_OK); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, MixModeBufferWrite_001, TestSize.Level2) +{ + screenCaptureServer_->audioSource_ = std::make_unique( + AVScreenCaptureMixMode::MIX_MODE, screenCaptureServer_.get()); + const int bufferSize = 10; + uint8_t *innerBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + uint8_t *micBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + std::shared_ptr innerAudioBuffer = std::make_shared(innerBuffer, bufferSize, 0, + SOURCE_DEFAULT); + std::shared_ptr micAudioBuffer = std::make_shared(micBuffer, bufferSize, 0, + SOURCE_DEFAULT); + uint8_t data[bufferSize]; + std::shared_ptr bufferMem = AVMemory::CreateAVMemory(data, bufferSize, bufferSize); + AudioDataSourceReadAtActionState ret = screenCaptureServer_->audioSource_->MixModeBufferWrite( + innerAudioBuffer, micAudioBuffer, bufferMem); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::OK); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, MixModeBufferWrite_002, TestSize.Level2) +{ + screenCaptureServer_->audioSource_ = std::make_unique( + AVScreenCaptureMixMode::MIX_MODE, screenCaptureServer_.get()); + const int bufferSize = 10; + uint8_t *innerBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + std::shared_ptr innerAudioBuffer = std::make_shared(innerBuffer, bufferSize, 0, + SOURCE_DEFAULT); + std::shared_ptr micAudioBuffer; + uint8_t data[bufferSize]; + std::shared_ptr bufferMem = AVMemory::CreateAVMemory(data, bufferSize, bufferSize); + AudioDataSourceReadAtActionState ret = screenCaptureServer_->audioSource_->MixModeBufferWrite(innerAudioBuffer, + micAudioBuffer, bufferMem); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::OK); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, MixModeBufferWrite_003, TestSize.Level2) +{ + screenCaptureServer_->audioSource_ = std::make_unique( + AVScreenCaptureMixMode::MIX_MODE, screenCaptureServer_.get()); + const int bufferSize = 10; + uint8_t *micBuffer = (uint8_t *)malloc(sizeof(uint8_t) * bufferSize); + std::shared_ptr innerAudioBuffer; + std::shared_ptr micAudioBuffer = std::make_shared(micBuffer, bufferSize, 0, + SOURCE_DEFAULT); + uint8_t data[bufferSize]; + std::shared_ptr bufferMem = AVMemory::CreateAVMemory(data, bufferSize, bufferSize); + AudioDataSourceReadAtActionState ret = screenCaptureServer_->audioSource_->MixModeBufferWrite(innerAudioBuffer, + micAudioBuffer, bufferMem); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::OK); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, MixModeBufferWrite_004, TestSize.Level2) +{ + screenCaptureServer_->audioSource_ = std::make_unique( + AVScreenCaptureMixMode::MIX_MODE, screenCaptureServer_.get()); + const int bufferSize = 10; + std::shared_ptr innerAudioBuffer; + std::shared_ptr micAudioBuffer; + uint8_t data[bufferSize]; + std::shared_ptr bufferMem = AVMemory::CreateAVMemory(data, bufferSize, bufferSize); + AudioDataSourceReadAtActionState ret = screenCaptureServer_->audioSource_->MixModeBufferWrite(innerAudioBuffer, + micAudioBuffer, bufferMem); + ASSERT_EQ(ret, AudioDataSourceReadAtActionState::RETRY_SKIP); } HWTEST_F(ScreenCaptureServerFunctionTest, GetChoiceFromJson_001, TestSize.Level2) diff --git a/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/screen_capture_server_function_unittest_multiInstance.cpp b/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/screen_capture_server_function_unittest_multiInstance.cpp index ec3fb22eb467e84f270066cd3aba0792337fc992..958926a00f3671932e9cd53cbbca99ee4c5b644a 100644 --- a/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/screen_capture_server_function_unittest_multiInstance.cpp +++ b/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/screen_capture_server_function_unittest_multiInstance.cpp @@ -905,10 +905,12 @@ HWTEST_F(ScreenCaptureServerFunctionTest, ProcessCurDisplayId_001, TestSize.Leve HWTEST_F(ScreenCaptureServerFunctionTest, NotifyCaptureContentChanged_001, TestSize.Level2) { + ScreenCaptureRect* area = nullptr; + screenCaptureServer_->captureState_ = AVScreenCaptureState::STARTED; screenCaptureServer_->NotifyCaptureContentChanged(AVScreenCaptureContentChangedEvent::SCREEN_CAPTURE_CONTENT_HIDE, nullptr); screenCaptureServer_->NotifyCaptureContentChanged( - AVScreenCaptureContentChangedEvent::SCREEN_CAPTURE_CONTENT_VISIBLE, nullptr); + AVScreenCaptureContentChangedEvent::SCREEN_CAPTURE_CONTENT_VISIBLE, area); screenCaptureServer_->NotifyCaptureContentChanged( AVScreenCaptureContentChangedEvent::SCREEN_CAPTURE_CONTENT_UNAVAILABLE, nullptr); ASSERT_NE(screenCaptureServer_, nullptr); @@ -917,6 +919,7 @@ HWTEST_F(ScreenCaptureServerFunctionTest, NotifyCaptureContentChanged_001, TestS HWTEST_F(ScreenCaptureServerFunctionTest, NotifyCaptureContentChanged_002, TestSize.Level2) { ScreenCaptureRect* area = nullptr; + screenCaptureServer_->captureState_ = AVScreenCaptureState::STARTED; area->x = 0; area->y = 0; area->width = 1; @@ -990,6 +993,9 @@ HWTEST_F(ScreenCaptureServerFunctionTest, WindowLifecycleListener_003, TestSize. HWTEST_F(ScreenCaptureServerFunctionTest, WindowInfoChangedListener_001, TestSize.Level2) { + screenCaptureServer_->windowIdList_ = {}; + int32_t windowId = 70; + screenCaptureServer_->SetWindowIdList(windowId); screenCaptureServer_->windowInfoChangedListener_ = nullptr; screenCaptureServer_->RegisterWindowInfoChangedListener(); ASSERT_NE(screenCaptureServer_->windowInfoChangedListener_, nullptr); @@ -1040,6 +1046,7 @@ HWTEST_F(ScreenCaptureServerFunctionTest, OnLifecycleEvent_001, TestSize.Level2) screenCaptureServer_->displayScreenId_ = 0; screenCaptureServer_->curWindowInDisplayId_ = 0; screenCaptureServer_->SetWindowIdList(80); + screenCaptureServer_->captureState_ = AVScreenCaptureState::STARTED; SCWindowLifecycleListener::LifecycleEventPayload payload; screenCaptureServer_->windowLifecycleListener_->OnLifecycleEvent( SCWindowLifecycleListener::SessionLifecycleEvent::FOREGROUND, payload); @@ -1050,6 +1057,37 @@ HWTEST_F(ScreenCaptureServerFunctionTest, OnLifecycleEvent_001, TestSize.Level2) ASSERT_NE(screenCaptureServer_, nullptr); } +HWTEST_F(ScreenCaptureServerFunctionTest, OnLifecycleEvent_002, TestSize.Level2) +{ + std::weak_ptr screenCaptureServer(screenCaptureServer_); + sptr listener(new (std::nothrow) SCWindowLifecycleListener(screenCaptureServer)); + screenCaptureServer_->windowLifecycleListener_ = listener; + screenCaptureServer_->displayScreenId_ = 0; + screenCaptureServer_->curWindowInDisplayId_ = 1; + screenCaptureServer_->SetWindowIdList(80); + SCWindowLifecycleListener::LifecycleEventPayload payload; + screenCaptureServer_->windowLifecycleListener_->OnLifecycleEvent( + SCWindowLifecycleListener::SessionLifecycleEvent::FOREGROUND, payload); + screenCaptureServer_->windowLifecycleListener_->OnLifecycleEvent( + SCWindowLifecycleListener::SessionLifecycleEvent::BACKGROUND, payload); + ASSERT_NE(screenCaptureServer_, nullptr); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, OnLifecycleEvent_003, TestSize.Level2) +{ + std::weak_ptr screenCaptureServer(screenCaptureServer_); + sptr listener(new (std::nothrow) SCWindowLifecycleListener(screenCaptureServer)); + screenCaptureServer_->windowLifecycleListener_ = listener; + screenCaptureServer_->displayScreenId_ = 0; + screenCaptureServer_->curWindowInDisplayId_ = 0; + screenCaptureServer_->SetWindowIdList(80); + screenCaptureServer_->captureState_ = AVScreenCaptureState::STOPPED; + SCWindowLifecycleListener::LifecycleEventPayload payload; + screenCaptureServer_->windowLifecycleListener_->OnLifecycleEvent( + SCWindowLifecycleListener::SessionLifecycleEvent::FOREGROUND, payload); + ASSERT_NE(screenCaptureServer_, nullptr); +} + HWTEST_F(ScreenCaptureServerFunctionTest, OnWindowInfoChanged_001, TestSize.Level2) { std::weak_ptr screenCaptureServer(screenCaptureServer_); @@ -1061,6 +1099,57 @@ HWTEST_F(ScreenCaptureServerFunctionTest, OnWindowInfoChanged_001, TestSize.Leve ASSERT_NE(screenCaptureServer_, nullptr); } +HWTEST_F(ScreenCaptureServerFunctionTest, OnWindowInfoChanged_002, TestSize.Level2) +{ + std::weak_ptr screenCaptureServer(screenCaptureServer_); + sptr listener(new (std::nothrow) SCWindowInfoChangedListener(screenCaptureServer)); + screenCaptureServer_->windowInfoChangedListener_ = listener; + screenCaptureServer_->SetWindowIdList(80); + screenCaptureServer_->curWindowInDisplayId_ = 0; + screenCaptureServer_->displayScreenId_ = 1; + screenCaptureServer_->windowInfoChangedListener_->AddInterestInfo(Rosen::WindowInfoKey::DISPLAY_ID); + std::vector> myWindowInfoList; + std::unordered_map myWindowInfo; + myWindowInfo[WindowInfoKey::DISPLAY_ID] = static_cast(1); + myWindowInfoList.push_back(myWindowInfo); + screenCaptureServer_->windowInfoChangedListener_->OnWindowInfoChanged(myWindowInfoList); + ASSERT_EQ(screenCaptureServer_->curWindowInDisplayId_, 1); + ASSERT_NE(screenCaptureServer_, nullptr); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, OnWindowInfoChanged_003, TestSize.Level2) +{ + std::weak_ptr screenCaptureServer(screenCaptureServer_); + sptr listener(new (std::nothrow) SCWindowInfoChangedListener(screenCaptureServer)); + screenCaptureServer_->windowInfoChangedListener_ = listener; + screenCaptureServer_->SetWindowIdList(80); + screenCaptureServer_->curWindowInDisplayId_ = 0; + screenCaptureServer_->displayScreenId_ = 999; + screenCaptureServer_->windowInfoChangedListener_->AddInterestInfo(Rosen::WindowInfoKey::DISPLAY_ID); + std::vector> myWindowInfoList; + std::unordered_map myWindowInfo; + myWindowInfo[WindowInfoKey::DISPLAY_ID] = static_cast(1); + myWindowInfoList.push_back(myWindowInfo); + screenCaptureServer_->windowInfoChangedListener_->OnWindowInfoChanged(myWindowInfoList); + ASSERT_EQ(screenCaptureServer_->curWindowInDisplayId_, 1); + ASSERT_NE(screenCaptureServer_, nullptr); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, OnWindowInfoChanged_004, TestSize.Level2) +{ + std::weak_ptr screenCaptureServer(screenCaptureServer_); + sptr listener(new (std::nothrow) SCWindowInfoChangedListener(screenCaptureServer)); + screenCaptureServer_->windowInfoChangedListener_ = listener; + screenCaptureServer_->SetWindowIdList(80); + screenCaptureServer_->curWindowInDisplayId_ = 0; + std::vector> myWindowInfoList; + std::unordered_map myWindowInfo; + myWindowInfoList.push_back(myWindowInfo); + screenCaptureServer_->windowInfoChangedListener_->OnWindowInfoChanged(myWindowInfoList); + ASSERT_EQ(screenCaptureServer_->curWindowInDisplayId_, 0); + ASSERT_NE(screenCaptureServer_, nullptr); +} + HWTEST_F(ScreenCaptureServerFunctionTest, StartScreenCaptureRegisterListener_001, TestSize.Level2) { screenCaptureServer_->isPrivacyAuthorityEnabled_ = true; @@ -1120,6 +1209,30 @@ HWTEST_F(ScreenCaptureServerFunctionTest, StartScreenCaptureRegisterListener_003 ASSERT_EQ(screenCaptureServer_->windowLifecycleListener_, nullptr); ASSERT_EQ(screenCaptureServer_->windowInfoChangedListener_, nullptr); } + +HWTEST_F(ScreenCaptureServerFunctionTest, OnDisconnect_001, TestSize.Level2) +{ + Rosen::ScreenId screenId = 1; + screenCaptureServer_->displayScreenId_ = screenId; + std::weak_ptr screenCaptureServer(screenCaptureServer_); + screenCaptureServer_->screenConnectListener_ = sptr::MakeSptr( + screenCaptureServer_->displayScreenId_, screenCaptureServer); + screenCaptureServer_->captureState_ = AVScreenCaptureState::STARTED; + screenCaptureServer_->screenConnectListener_->OnDisconnect(screenId); + ASSERT_NE(screenCaptureServer_, nullptr); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, OnDisconnect_002, TestSize.Level2) +{ + Rosen::ScreenId screenId = 1; + screenCaptureServer_->displayScreenId_ = 2; + std::weak_ptr screenCaptureServer(screenCaptureServer_); + screenCaptureServer_->screenConnectListener_ = sptr::MakeSptr( + screenCaptureServer_->displayScreenId_, screenCaptureServer); + screenCaptureServer_->captureState_ = AVScreenCaptureState::STARTED; + screenCaptureServer_->screenConnectListener_->OnDisconnect(screenId); + ASSERT_NE(screenCaptureServer_, nullptr); +} #endif } // Media } // OHOS \ No newline at end of file diff --git a/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/screen_capture_server_function_unittest_voip.cpp b/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/screen_capture_server_function_unittest_voip.cpp index 4f449de84118a15cbf8f22fe82ceef76962674d9..d6e8eee364739db6451244cb3c7d0263a4076107 100644 --- a/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/screen_capture_server_function_unittest_voip.cpp +++ b/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/screen_capture_server_function_unittest_voip.cpp @@ -78,7 +78,6 @@ HWTEST_F(ScreenCaptureServerFunctionTest, OnVoIPStatusChanged_003, TestSize.Leve SetValidConfigFile(recorderInfo); ASSERT_EQ(InitFileScreenCaptureServer(), MSERR_OK); screenCaptureServer_->SetMicrophoneEnabled(false); - ASSERT_EQ(screenCaptureServer_->GetMicWorkingState(), false); ASSERT_EQ(StartFileAudioCapture(AVScreenCaptureMixMode::MIX_MODE), MSERR_OK); sleep(RECORDER_TIME / 2); screenCaptureServer_->audioSource_->isInVoIPCall_ = true; @@ -113,7 +112,6 @@ HWTEST_F(ScreenCaptureServerFunctionTest, OnVoIPStatusChanged_004, TestSize.Leve sleep(RECORDER_TIME / 2); ASSERT_EQ(screenCaptureServer_->OnSpeakerAliveStatusChanged(true), MSERR_OK); sleep(RECORDER_TIME / 2); - ASSERT_EQ(screenCaptureServer_->GetMicWorkingState(), true); ASSERT_EQ(screenCaptureServer_->StopScreenCapture(), MSERR_OK); } @@ -301,7 +299,6 @@ HWTEST_F(ScreenCaptureServerFunctionTest, OnTelCallStart_003, TestSize.Level2) screenCaptureServer_->SetMicrophoneOn(); ASSERT_EQ(StartStreamAudioCapture(), MSERR_OK); screenCaptureServer_->captureState_ = AVScreenCaptureState::STARTED; - screenCaptureServer_->innerAudioCapture_->Pause(); screenCaptureServer_->isInTelCall_.store(true); screenCaptureServer_->isInTelCallAudio_.store(true); ASSERT_EQ(screenCaptureServer_->OnTelCallStart(), MSERR_OK); @@ -373,7 +370,6 @@ HWTEST_F(ScreenCaptureServerFunctionTest, OnTelCallStop_007, TestSize.Level2) screenCaptureServer_->captureState_ = AVScreenCaptureState::STARTED; screenCaptureServer_->isInTelCall_.store(false); screenCaptureServer_->isInTelCallAudio_.store(false); - screenCaptureServer_->micAudioCapture_->Pause(); ASSERT_EQ(screenCaptureServer_->OnTelCallStop(), MSERR_OK); } diff --git a/test/unittest/services/utils/BUILD.gn b/test/unittest/services/utils/BUILD.gn index 6568d737d58366d7831fa8fc2a7056951e424fb1..7632519ccc576455d5326e407ae1a171f4f58ab7 100644 --- a/test/unittest/services/utils/BUILD.gn +++ b/test/unittest/services/utils/BUILD.gn @@ -66,6 +66,7 @@ ohos_unittest("utils_unit_test") { "graphic_surface:sync_fence", "hilog:libhilog", "hisysevent:libhisysevent", + "hitrace:hitrace_meter", "hitrace:libhitracechain", "init:libbegetutil", "ipc:ipc_single", diff --git a/test/unittest/sound_parser_unittest/BUILD.gn b/test/unittest/sound_parser_unittest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..920bbf4a68de8a8557762cfdc046be4d917aba05 --- /dev/null +++ b/test/unittest/sound_parser_unittest/BUILD.gn @@ -0,0 +1,77 @@ +# Copyright (c) 2025 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/test.gni") +import("//foundation/multimedia/player_framework/config.gni") +import("./../../../multimedia_player_framework_aafwk.gni") + +module_output_path = "player_framework/player_framework/soundpool" + +ohos_unittest("sound_parser_unittest") { + module_out_path = module_output_path + include_dirs = [ + "./include", + "../soundpool_test/include", + "${multimedia_player_framework_path}/frameworks/native/soundpool", + "${multimedia_player_framework_path}/services/services/engine_intf", + "${multimedia_player_framework_path}/test/unittest/common/include", + "${multimedia_player_framework_path}/interfaces/inner_api/native/soundpool/include", + ] + + cflags = [ + "-Wall", + "-Werror", + "-Dprivate=public", + "-Dprotected=public", + ] + + sources = [ + "./sound_parser_unittest.cpp", + "./mock/avdemuxer.cpp", + "./mock/avsource.cpp", + "${multimedia_player_framework_path}/test/unittest/soundpool_test/src/soundpool_mock.cpp", + ] + + + deps = [ + "${multimedia_player_framework_path}/frameworks/native/soundpool:soundpool_client", + "${multimedia_player_framework_path}/interfaces/inner_api/native:media_client", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_manager", + "ability_runtime:abilitykit_native", + "audio_framework:audio_client", + "audio_framework:audio_renderer", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "ffrt:libffrt", + "googletest:gmock", + "graphic_surface:surface", + "hicollie:libhicollie", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "init:libbegetutil", + "ipc:ipc_core", + "qos_manager:qos", + ] + + if (player_framework_support_drm) { + external_deps += [ "drm_framework:drm_framework" ] + } + + resource_config_file = "${multimedia_player_framework_path}/test/unittest/resources/ohos_test.xml" +} diff --git a/test/unittest/sound_parser_unittest/mock/avdemuxer.cpp b/test/unittest/sound_parser_unittest/mock/avdemuxer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a33722061210f8736a3242fd178c3db225f58e47 --- /dev/null +++ b/test/unittest/sound_parser_unittest/mock/avdemuxer.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2025 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 "avdemuxer.h" +#include "avdemuxer_impl.h" +namespace OHOS { +namespace MediaAVCodec { +using namespace Media; +std::shared_ptr AVDemuxerFactory::CreateWithSource(std::shared_ptr source) +{ + std::shared_ptr sourceImpl = std::make_shared(); + return sourceImpl; +} +} // namespace MediaAVCodec +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/sound_parser_unittest/mock/avdemuxer.h b/test/unittest/sound_parser_unittest/mock/avdemuxer.h new file mode 100644 index 0000000000000000000000000000000000000000..96ec4e57cb0154178473094fb252db819e4a5a00 --- /dev/null +++ b/test/unittest/sound_parser_unittest/mock/avdemuxer.h @@ -0,0 +1,150 @@ +/* + * Copyright (C) 2025 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 MEDIA_AVCODEC_AVDEMUXER_H +#define MEDIA_AVCODEC_AVDEMUXER_H + +#include +#include "avcodec_common.h" +#include "buffer/avbuffer.h" +#include "buffer/avsharedmemory.h" +#include "avsource.h" +#include "meta/media_types.h" + +namespace OHOS { +namespace MediaAVCodec { +using namespace Media; +class AVDemuxer { +public: + virtual ~AVDemuxer() = default; + + /** + * @brief Select the sourceTrack by track index. + * This function can only by called before {@link ReadSample}. + * @param trackIndex The track index for being selected. + * @return Returns {@link AVCS_ERR_OK} if success; returns an error code otherwise. + * @since 4.0 + */ + virtual int32_t SelectTrackByID(uint32_t trackIndex) = 0; + + /** + * @brief Unselect the sourceTrack by track index. + * This function can only by called before {@link ReadSample}. + * @param trackIndex The track index for being unselected. + * @return Returns {@link AVCS_ERR_OK} if success; returns an error code otherwise. + * @since 4.0 + */ + virtual int32_t UnselectTrackByID(uint32_t trackIndex) = 0; + + /** + * @brief Retrieve the sample in selected tracks and store it in buffer, and store buffer's info to attr. + * @param trackIndex Get the sampleBuffer from this track. + * @param sample The AVSharedMemory handle pointer to get buffer data. + * @param info The CodecBufferAttr handle pointer to get buffer info. + * @param flag The buffer flags. + * @return Returns {@link AVCS_ERR_OK} if success; returns an error code otherwise. + * @since 4.0 + */ + virtual int32_t ReadSample(uint32_t trackIndex, std::shared_ptr sample, + AVCodecBufferInfo &info, uint32_t &flag) = 0; + + /** + * @brief Retrieve the sample in selected tracks and store it in buffer, and store buffer's info to attr. + * @param trackIndex Get the sampleBuffer from this track. + * @param sample The AVSharedMemory handle pointer to get buffer data. + * @param info The CodecBufferAttr handle pointer to get buffer info. + * @param flag The buffer flags. + * @return Returns {@link AVCS_ERR_OK} if success; returns an error code otherwise. + * @since 4.0 + */ + virtual int32_t ReadSample(uint32_t trackIndex, std::shared_ptr sample, + AVCodecBufferInfo &info, AVCodecBufferFlag &flag) = 0; + + /** + * @brief Retrieve the sample in selected tracks and store it in buffer, and store buffer's info to attr. + * @param trackIndex Get the sampleBuffer from this track. + * @param sample The AVBuffer handle pointer to get buffer data. + * @return Returns {@link AVCS_ERR_OK} if success; returns an error code otherwise. + * @since 4.1 + */ + virtual int32_t ReadSampleBuffer(uint32_t trackIndex, std::shared_ptr sample) = 0; + + /** + * @brief All selected tracks seek near to the requested time according to the seek mode. + * @param millisecond The timestamp for seeking which is the position relative to the beginning of the file. + * @param mode The mode for seeking. Value. For details, see {@link SeekMode}. + * @return Returns {@link AVCS_ERR_OK} if success; returns an error code otherwise. + * @since 4.0 + */ + virtual int32_t SeekToTime(int64_t millisecond, SeekMode mode) = 0; + + /** + * @brief Registers a demuxer listener. + * + * @param callback Indicates the demuxer listener to register. For details, see {@link AVDemuxerCallback}. + * @return Returns {@link AVCS_ERR_OK} if success; returns an error code otherwise. + * @since 4.1 + * @version 4.1 + */ + virtual int32_t SetCallback(const std::shared_ptr &callback) = 0; + + virtual int32_t GetMediaKeySystemInfo(std::multimap> &infos) = 0; + virtual int32_t StartReferenceParser(int64_t startTimeMs) = 0; + virtual int32_t GetFrameLayerInfo(std::shared_ptr videoSample, FrameLayerInfo &frameLayerInfo) = 0; + virtual int32_t GetGopLayerInfo(uint32_t gopId, GopLayerInfo &gopLayerInfo) = 0; + + /** + * @brief Obtian index by relative pts. + * @param trackIndex Get the index from this track. + * @param relativePresentationTimeUs Relative pts which obtian index by. + * @param index Frame index of obtian result. + * @return Returns {@link AVCS_ERR_OK} if success; returns an error code otherwise. + * @since 5.0 + */ + virtual int32_t GetIndexByRelativePresentationTimeUs(const uint32_t trackIndex, + const uint64_t relativePresentationTimeUs, uint32_t &index) = 0; + + /** + * @brief Obtian relative pts by index. + * @param trackIndex Get the relative pts from this track. + * @param index Frame index which obtian relative pts by. + * @param relativePresentationTimeUs Pts of obtian reuslt. + * @return Returns {@link AVCS_ERR_OK} if success; returns an error code otherwise. + * @since 5.0 + */ + virtual int32_t GetRelativePresentationTimeUsByIndex(const uint32_t trackIndex, + const uint32_t index, uint64_t &relativePresentationTimeUs) = 0; + + /** + * @brief Get cache of track in plugin. + * @param trackIndex Get the cache from this track. + * @param size Cache size in bytes. + * @return Returns {@link AVCS_ERR_OK} if success; returns an error code otherwise. + * @since 6.0 + */ + virtual int32_t GetCurrentCacheSize(uint32_t trackIndex, uint32_t& size) = 0; +}; + +class __attribute__((visibility("default"))) AVDemuxerFactory { +public: + static std::shared_ptr CreateWithSource(std::shared_ptr source); +private: + AVDemuxerFactory() = default; + ~AVDemuxerFactory() = default; +}; +} // namespace MediaAVCodec +} // namespace OHOS +#endif // MEDIA_AVCODEC_AVDEMUXER_H diff --git a/test/unittest/sound_parser_unittest/mock/avdemuxer_impl.h b/test/unittest/sound_parser_unittest/mock/avdemuxer_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..5924ad4ba953a2e5cd5ae313056589f2996d26e9 --- /dev/null +++ b/test/unittest/sound_parser_unittest/mock/avdemuxer_impl.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2025 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 AVDEMUXER_IMPL_H +#define AVDEMUXER_IMPL_H + +#include +#include +#include "avsource.h" +#include "avdemuxer.h" +#include "nocopyable.h" +#include "media_demuxer.h" + +namespace OHOS { +namespace MediaAVCodec { +using namespace Media; +class AVDemuxerImpl : public AVDemuxer, public NoCopyable { +public: + AVDemuxerImpl() = default; + ~AVDemuxerImpl() override = default; + MOCK_METHOD(int32_t, SelectTrackByID, (uint32_t trackIndex), (override)); + MOCK_METHOD(int32_t, UnselectTrackByID, (uint32_t trackIndex), (override)); + MOCK_METHOD(int32_t, ReadSample, (uint32_t trackIndex, std::shared_ptr sample, + AVCodecBufferInfo &info, uint32_t &flag), (override)); + MOCK_METHOD(int32_t, ReadSample, (uint32_t trackIndex, std::shared_ptr sample, + AVCodecBufferInfo &info, AVCodecBufferFlag &flag), (override)); + MOCK_METHOD(int32_t, ReadSampleBuffer, (uint32_t trackIndex, std::shared_ptr sample), (override)); + MOCK_METHOD(int32_t, SeekToTime, (int64_t millisecond, const SeekMode mode), (override)); + MOCK_METHOD(int32_t, SetCallback, (const std::shared_ptr &callback), (override)); + MOCK_METHOD(int32_t, GetMediaKeySystemInfo, + ((std::multimap> &)infos), (override)); + MOCK_METHOD(int32_t, Init, (std::shared_ptr source), ()); + MOCK_METHOD(int32_t, StartReferenceParser, (int64_t startTimeMs), (override)); + MOCK_METHOD(int32_t, GetFrameLayerInfo, + (std::shared_ptr videoSample, FrameLayerInfo &frameLayerInfo), (override)); + MOCK_METHOD(int32_t, GetGopLayerInfo, + (uint32_t gopId, GopLayerInfo &gopLayerInfo), (override)); + MOCK_METHOD(int32_t, GetIndexByRelativePresentationTimeUs, + (const uint32_t trackIndex, const uint64_t relativePresentationTimeUs, uint32_t &index), (override)); + MOCK_METHOD(int32_t, GetRelativePresentationTimeUsByIndex, + (const uint32_t trackIndex, const uint32_t index, uint64_t &relativePresentationTimeUs), (override)); + MOCK_METHOD(int32_t, GetCurrentCacheSize, + (uint32_t trackIndex, uint32_t& size), (override)); +private: + std::shared_ptr mediaDemuxer_ = nullptr; + std::string sourceUri_; +}; +} // namespace MediaAVCodec +} // namespace OHOS +#endif // AVDEMUXER_IMPL_H \ No newline at end of file diff --git a/test/unittest/sound_parser_unittest/mock/avsource.cpp b/test/unittest/sound_parser_unittest/mock/avsource.cpp new file mode 100644 index 0000000000000000000000000000000000000000..13398e9a625db106e763dd0b9c90dbce5b8e1afe --- /dev/null +++ b/test/unittest/sound_parser_unittest/mock/avsource.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2025 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 "avsource.h" +#include "avsource_impl.h" + +namespace OHOS { +namespace MediaAVCodec { +using namespace Media; +std::shared_ptr AVSourceFactory::CreateWithURI(const std::string &uri) +{ + std::shared_ptr sourceImpl = std::make_shared(); + return sourceImpl; +} +} // namespace MediaAVCodec +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/sound_parser_unittest/mock/avsource.h b/test/unittest/sound_parser_unittest/mock/avsource.h new file mode 100644 index 0000000000000000000000000000000000000000..f44fd9e117d1504cabf2f5119f3747d19d634df9 --- /dev/null +++ b/test/unittest/sound_parser_unittest/mock/avsource.h @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2025 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 MEDIA_AVCODEC_AVSOURCE_H +#define MEDIA_AVCODEC_AVSOURCE_H + +#include +#include +#include +#include "meta/format.h" +#include "media_demuxer.h" + +namespace OHOS { +namespace MediaAVCodec { +class AVSource { +public: + virtual ~AVSource() = default; + + /** + * @brief Get the format info of source. + * @param format The Format handle pointer to get format info. + * @return Returns {@link AVCS_ERR_OK} if success; returns an error code otherwise. + * @since 4.0 + */ + virtual int32_t GetSourceFormat(OHOS::Media::Format &format) = 0; + + /** + * @brief Gets the parameters of the source. + * @param format The Format handle pointer to get format info. + * @param trackIndex The track index to get format. + * @return Returns {@link AVCS_ERR_OK} if success; returns an error code otherwise. + * @since 4.0 + */ + virtual int32_t GetTrackFormat(OHOS::Media::Format &format, uint32_t trackIndex) = 0; + + /** + * @brief Gets the user meta for media. + * @param format The Format handle pointer to get format info. + * @return Returns {@link AVCS_ERR_OK} if success; returns an error code otherwise. + * @since 5.0 + */ + virtual int32_t GetUserMeta(OHOS::Media::Format &format) = 0; + + std::string sourceUri; + std::shared_ptr mediaDemuxer = nullptr; +}; + +class __attribute__((visibility("default"))) AVSourceFactory { +public: + static std::shared_ptr CreateWithURI(const std::string &uri); + + static std::shared_ptr CreateWithFD(int32_t fd, int64_t offset, int64_t size) + { + return nullptr; + } + + static std::shared_ptr CreateWithDataSource(const std::shared_ptr &dataSource) + { + return nullptr; + } +private: + AVSourceFactory() = default; + ~AVSourceFactory() = default; +}; +} // namespace MediaAVCodec +} // namespace OHOS +#endif // MEDIA_AVCODEC_AVSOURCE_H + diff --git a/test/unittest/sound_parser_unittest/mock/avsource_impl.h b/test/unittest/sound_parser_unittest/mock/avsource_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..e957af6e7e496b999b599ce6e54eb8485d8f5cc6 --- /dev/null +++ b/test/unittest/sound_parser_unittest/mock/avsource_impl.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2025 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 AVSOURCE_IMPL_H +#define AVSOURCE_IMPL_H + +#include +#include "avsource.h" +#include "nocopyable.h" +#include "meta/meta.h" + +namespace OHOS { +namespace MediaAVCodec { +class AVSourceImpl : public AVSource, public NoCopyable { +public: + AVSourceImpl() = default; + ~AVSourceImpl() override = default; + MOCK_METHOD(int32_t, GetSourceFormat, (OHOS::Media::Format &format), (override)); + MOCK_METHOD(int32_t, GetTrackFormat, (OHOS::Media::Format &format, uint32_t trackIndex), (override)); + MOCK_METHOD(int32_t, GetUserMeta, (OHOS::Media::Format &format), (override)); + MOCK_METHOD(int32_t, InitWithURI, (const std::string &uri), ()); + MOCK_METHOD(int32_t, InitWithFD, (int32_t fd, int64_t offset, int64_t size), ()); + MOCK_METHOD(int32_t, InitWithDataSource, (const std::shared_ptr &dataSource), ()); +}; +} // namespace MediaAVCodec +} // namespace OHOS +#endif // AVSOURCE_IMPL_H + diff --git a/test/unittest/sound_parser_unittest/sound_parser_unittest.cpp b/test/unittest/sound_parser_unittest/sound_parser_unittest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..87cb53795a70560f47e0a2b6fb83bea14837ce38 --- /dev/null +++ b/test/unittest/sound_parser_unittest/sound_parser_unittest.cpp @@ -0,0 +1,337 @@ +/* + * Copyright (c) 2025 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 +#include "media_errors.h" +#include "sound_parser_unittest.h" +#include "avsource_impl.h" +#include "parallel_stream_manager.h" +#include "avsharedmemorybase.h" +#include "soundpool_mock.h" + +namespace OHOS { +namespace Media { +static const int32_t ID_TEST = 1; +static const int32_t ERR_OK = 0; +using namespace std; +using namespace testing; +using namespace testing::ext; + +void SoundParserUnitTest::SetUpTestCase(void) +{ +} + +void SoundParserUnitTest::TearDownTestCase(void) +{ +} + +void SoundParserUnitTest::SetUp(void) +{ + soundParser_ = std::make_shared(1, "testurl"); + soundParser_->demuxer_ = nullptr; + soundParser_->source_ = nullptr; +} + +void SoundParserUnitTest::TearDown(void) +{ + soundParser_ = nullptr; +} + +// @tc.name Test DoParser API +// @tc.number SoundParser_DoParser_001 +// @tc.desc Test return MSERR_INVALID_VAL +HWTEST_F(SoundParserUnitTest, SoundParser_DoParser_001, TestSize.Level0) +{ + ASSERT_NE(soundParser_, nullptr); + auto source = std::make_shared(); + EXPECT_CALL(*(source), GetTrackFormat(_, _)).WillRepeatedly(testing::Return(ID_TEST)); + EXPECT_CALL(*(source), GetSourceFormat(_)).WillRepeatedly(testing::Return(ID_TEST)); + soundParser_->source_ = source; + std::shared_ptr demuxer = std::make_shared(); + EXPECT_CALL(*(demuxer), SelectTrackByID(_)).WillRepeatedly(testing::Return(ID_TEST)); + soundParser_->demuxer_ = demuxer; + int32_t ret = soundParser_->DoParser(); + EXPECT_EQ(ret, MSERR_INVALID_VAL); +} + +// @tc.name Test DoParser API +// @tc.number SoundParser_DoParser_002 +// @tc.desc Test return MSERR_INVALID_VAL +HWTEST_F(SoundParserUnitTest, SoundParser_DoParser_002, TestSize.Level0) +{ + ASSERT_NE(soundParser_, nullptr); + auto source = std::make_shared(); + EXPECT_CALL(*(source), GetTrackFormat(_, _)).WillRepeatedly(testing::Return(ID_TEST)); + EXPECT_CALL(*(source), GetSourceFormat(_)).WillRepeatedly(testing::Return(ID_TEST)); + soundParser_->source_ = source; + std::shared_ptr demuxer = std::make_shared(); + EXPECT_CALL(*(demuxer), SelectTrackByID(_)).WillRepeatedly(testing::Return(ID_TEST)); + soundParser_->demuxer_ = demuxer; + std::weak_ptr parallelStreamManager; + soundParser_->callback_ = std::make_shared(parallelStreamManager); + int32_t ret = soundParser_->DoParser(); + EXPECT_EQ(ret, MSERR_INVALID_VAL); +} + +// @tc.name Test DoDemuxer API +// @tc.number SoundParser_DoDemuxer_001 +// @tc.desc Test return MSERR_OK +HWTEST_F(SoundParserUnitTest, SoundParser_DoDemuxer_001, TestSize.Level0) +{ + ASSERT_NE(soundParser_, nullptr); + MediaAVCodec::Format trackFormat; + auto source = std::make_shared(); + EXPECT_CALL(*(source), GetTrackFormat(_, _)).WillRepeatedly(testing::Return(ID_TEST)); + EXPECT_CALL(*(source), GetSourceFormat(_)).WillRepeatedly(testing::Return(AVCS_ERR_INVALID_OPERATION)); + soundParser_->source_ = source; + std::shared_ptr demuxer = std::make_shared(); + EXPECT_CALL(*(demuxer), SelectTrackByID(_)).WillRepeatedly(testing::Return(ID_TEST)); + soundParser_->demuxer_ = demuxer; + MediaAVCodec::Format sourceFormat; + int32_t ret = soundParser_->source_->GetSourceFormat(sourceFormat); + EXPECT_EQ(ret, AVCS_ERR_INVALID_OPERATION); + ret = soundParser_->DoDemuxer(&trackFormat); + EXPECT_EQ(ret, MSERR_OK); +} + +// @tc.name Test OnError OnInputBufferAvailable SetCallback API +// @tc.number SoundParser_OnError_001 +// @tc.desc Test OnError all && Test OnInputBufferAvailable demuxer_ = nullptr || audioDec_ = nullptr +HWTEST_F(SoundParserUnitTest, SoundParser_OnError_001, TestSize.Level0) +{ + ASSERT_NE(soundParser_, nullptr); + + // Test OnError all + int32_t soundID = ID_TEST; + std::shared_ptr audioDec; + std::shared_ptr demuxer; + bool isRawFile = true; + SoundDecoderCallback_ = std::make_shared(soundID, audioDec, demuxer, isRawFile); + ASSERT_NE(SoundDecoderCallback_, nullptr); + SoundDecoderCallback_->isRawFile_ = true; + AVCodecErrorType errorType = AVCodecErrorType::AVCODEC_ERROR_INTERNAL; + int32_t errorCode = -1; + SoundDecoderCallback_->OnError(errorType, errorCode); + + // Test OnInputBufferAvailable demuxer_ = nullptr, audioDec_ = nullptr + uint32_t index = ID_TEST; + std::shared_ptr buffer; + SoundDecoderCallback_->OnInputBufferAvailable(index, buffer); + std::shared_ptr callback; + int32_t ret = SoundDecoderCallback_->SetCallback(callback); + EXPECT_EQ(SoundDecoderCallback_->callback_, nullptr); + EXPECT_EQ(ret, MSERR_OK); +} + +// @tc.name Test OnInputBufferAvailable API +// @tc.number SoundParser_OnInputBufferAvailable_002 +// @tc.desc Test buffer != nullptr, isRawFile_ == true, !decodeShouldCompleted_ == true +HWTEST_F(SoundParserUnitTest, SoundParser_OnInputBufferAvailable_002, TestSize.Level0) +{ + ASSERT_NE(soundParser_, nullptr); + MediaAVCodec::AVCodecBufferFlag bufferFlag = MediaAVCodec::AVCodecBufferFlag::AVCODEC_BUFFER_FLAG_NONE; + int32_t soundID = ID_TEST; + std::shared_ptr audioDec = std::make_shared(); + std::shared_ptr demuxer_value = std::make_shared(); + EXPECT_CALL(*(demuxer_value), ReadSample(_, _, _, bufferFlag)).WillRepeatedly(testing::Return(ERR_OK)); + soundParser_->source_ = std::make_shared(); + std::shared_ptr demuxer = demuxer_value; + ASSERT_NE(demuxer, nullptr); + bool isRawFile = true; + SoundDecoderCallback_ = std::make_shared(soundID, audioDec, demuxer, isRawFile); + SoundDecoderCallback_->isRawFile_ = true; + SoundDecoderCallback_->decodeShouldCompleted_ = false; + ASSERT_NE(SoundDecoderCallback_, nullptr); + uint32_t index = ID_TEST; + std::shared_ptr buffer = std::make_shared(1, 1, "test"); + SoundDecoderCallback_->OnInputBufferAvailable(index, buffer); + bool ret = SoundDecoderCallback_->amutex_.try_lock(); + EXPECT_EQ(ret, true); + if (ret == true) { + SoundDecoderCallback_->amutex_.unlock(); + } +} + +// @tc.name Test OnInputBufferAvailable API +// @tc.number SoundParser_OnInputBufferAvailable_003 +// @tc.desc Test (buffer != nullptr && !eosFlag_ && !decodeShouldCompleted_) == true +HWTEST_F(SoundParserUnitTest, SoundParser_OnInputBufferAvailable_003, TestSize.Level0) +{ + ASSERT_NE(soundParser_, nullptr); + MediaAVCodec::AVCodecBufferFlag bufferFlag = MediaAVCodec::AVCodecBufferFlag::AVCODEC_BUFFER_FLAG_NONE; + int32_t soundID = ID_TEST; + std::shared_ptr audioDec = std::make_shared(); + std::shared_ptr demuxer_value = std::make_shared(); + EXPECT_CALL(*(demuxer_value), ReadSample(_, _, _, bufferFlag)).WillRepeatedly(testing::Return(ID_TEST)); + soundParser_->source_ = std::make_shared(); + std::shared_ptr demuxer = demuxer_value; + bool isRawFile = true; + SoundDecoderCallback_ = std::make_shared(soundID, audioDec, demuxer, isRawFile); + SoundDecoderCallback_->eosFlag_ = false; + SoundDecoderCallback_->decodeShouldCompleted_ = false; + ASSERT_NE(SoundDecoderCallback_, nullptr); + uint32_t index = ID_TEST; + std::shared_ptr buffer = std::make_shared(1, 1, "test"); + SoundDecoderCallback_->OnInputBufferAvailable(index, buffer); + bool ret = SoundDecoderCallback_->amutex_.try_lock(); + EXPECT_EQ(ret, true); + if (ret == true) { + SoundDecoderCallback_->amutex_.unlock(); + } +} + +// @tc.name Test DealBufferRawFile API +// @tc.number SoundParser_DealBufferRawFile_001 +// @tc.desc Test (demuxer_->ReadSample(0, buffer, sampleInfo, bufferFlag) != AVCS_ERR_OK +HWTEST_F(SoundParserUnitTest, SoundParser_DealBufferRawFile_001, TestSize.Level0) +{ + ASSERT_NE(soundParser_, nullptr); + MediaAVCodec::AVCodecBufferFlag bufferFlag = MediaAVCodec::AVCodecBufferFlag::AVCODEC_BUFFER_FLAG_NONE; + int32_t soundID = ID_TEST; + std::shared_ptr audioDec = std::make_shared(); + std::shared_ptr demuxer_value = std::make_shared(); + EXPECT_CALL(*(demuxer_value), ReadSample(_, _, _, bufferFlag)).WillRepeatedly(testing::Return(ID_TEST)); + soundParser_->source_ = std::make_shared(); + std::shared_ptr demuxer = demuxer_value; + bool isRawFile = true; + SoundDecoderCallback_ = std::make_shared(soundID, audioDec, demuxer, isRawFile); + SoundDecoderCallback_->eosFlag_ = false; + SoundDecoderCallback_->decodeShouldCompleted_ = false; + ASSERT_NE(SoundDecoderCallback_, nullptr); + uint32_t index = ID_TEST; + MediaAVCodec::AVCodecBufferInfo sampleInfo; + std::shared_ptr buffer = nullptr; + SoundDecoderCallback_->DealBufferRawFile(bufferFlag, sampleInfo, index, buffer); + bool ret = SoundDecoderCallback_->demuxer_->ReadSample(0, buffer, sampleInfo, bufferFlag) != AVCS_ERR_OK; + EXPECT_EQ(ret, true); +} + +// @tc.name Test DealBufferRawFile API +// @tc.number SoundParser_DealBufferRawFile_002 +// @tc.desc Test decodeShouldCompleted_ == false +// Test currentSoundBufferSize_ > MAX_SOUND_BUFFER_SIZE +// Test bufferFlag == AVCODEC_BUFFER_FLAG_EOS +HWTEST_F(SoundParserUnitTest, SoundParser_DealBufferRawFile_002, TestSize.Level0) +{ + ASSERT_NE(soundParser_, nullptr); + MediaAVCodec::AVCodecBufferFlag bufferFlag = AVCODEC_BUFFER_FLAG_EOS; + int32_t soundID = ID_TEST; + std::shared_ptr audioDec = std::make_shared(); + std::shared_ptr demuxer_value = std::make_shared(); + EXPECT_CALL(*(demuxer_value), ReadSample(_, _, _, bufferFlag)).WillRepeatedly(testing::Return(ERR_OK)); + soundParser_->source_ = std::make_shared(); + std::shared_ptr demuxer = demuxer_value; + bool isRawFile = true; + SoundDecoderCallback_ = std::make_shared(soundID, audioDec, demuxer, isRawFile); + SoundDecoderCallback_->decodeShouldCompleted_ = false; + ASSERT_NE(SoundDecoderCallback_, nullptr); + uint32_t index = ID_TEST; + MediaAVCodec::AVCodecBufferInfo sampleInfo; + uint8_t testNum = ID_TEST; + uint8_t *testPtr = &testNum; + auto mockBuffer = std::make_shared(); + EXPECT_CALL(*(mockBuffer), GetBase()).WillRepeatedly(testing::Return(testPtr)); + std::shared_ptr buffer = mockBuffer; + std::shared_ptr testvalue = std::make_shared(); + SoundDecoderCallback_->listener_ = testvalue; + std::shared_ptr soundPool = std::make_shared(); + SoundDecoderCallback_->callback_ = std::make_shared(soundPool); + SoundDecoderCallback_->DealBufferRawFile(bufferFlag, sampleInfo, index, buffer); + EXPECT_EQ(SoundDecoderCallback_->decodeShouldCompleted_, true); +} + +// @tc.name Test DealBufferRawFile API +// @tc.number SoundParser_DealBufferRawFile_003 +// @tc.desc Test buf != nullptr +// Test memcpy_s(buf, size, buffer->GetBase(), size) != EOK +HWTEST_F(SoundParserUnitTest, SoundParser_DealBufferRawFile_003, TestSize.Level0) +{ + ASSERT_NE(soundParser_, nullptr); + MediaAVCodec::AVCodecBufferFlag bufferFlag = AVCODEC_BUFFER_FLAG_EOS; + int32_t soundID = ID_TEST; + std::shared_ptr audioDec = std::make_shared(); + std::shared_ptr demuxer_value = std::make_shared(); + EXPECT_CALL(*(demuxer_value), ReadSample(_, _, _, bufferFlag)).WillRepeatedly(testing::Return(ERR_OK)); + soundParser_->source_ = std::make_shared(); + std::shared_ptr demuxer = demuxer_value; + bool isRawFile = true; + SoundDecoderCallback_ = std::make_shared(soundID, audioDec, demuxer, isRawFile); + SoundDecoderCallback_->decodeShouldCompleted_ = true; + ASSERT_NE(SoundDecoderCallback_, nullptr); + uint32_t index = ID_TEST; + MediaAVCodec::AVCodecBufferInfo sampleInfo; + sampleInfo.size = 1; + uint8_t testNum = ID_TEST; + uint8_t *testPtr = &testNum; + auto mockBuffer = std::make_shared(); + EXPECT_CALL(*(mockBuffer), GetBase()).WillRepeatedly(testing::Return(testPtr)); + std::shared_ptr buffer = mockBuffer; + SoundDecoderCallback_->DealBufferRawFile(bufferFlag, sampleInfo, index, buffer); + EXPECT_EQ(SoundDecoderCallback_->currentSoundBufferSize_, ID_TEST); +} + +// @tc.name Test OnOutputBufferAvailable API +// @tc.number SoundParser_OnOutputBufferAvailable_001 +// @tc.desc Test demuxer_ == nullptr, audioDec_ == nullptr +HWTEST_F(SoundParserUnitTest, SoundParser_OnOutputBufferAvailable_001, TestSize.Level0) +{ + ASSERT_NE(soundParser_, nullptr); + int32_t soundID = ID_TEST; + std::shared_ptr audioDec; + std::shared_ptr demuxer; + bool isRawFile = true; + SoundDecoderCallback_ = std::make_shared(soundID, audioDec, demuxer, isRawFile); + ASSERT_NE(SoundDecoderCallback_, nullptr); + MediaAVCodec::AVCodecBufferInfo info; + MediaAVCodec::AVCodecBufferFlag flag = AVCODEC_BUFFER_FLAG_EOS; + uint32_t index = ID_TEST; + std::shared_ptr buffer = std::make_shared(1, 1, "test"); + SoundDecoderCallback_->OnOutputBufferAvailable(index, info, flag, buffer); + bool ret = SoundDecoderCallback_->amutex_.try_lock(); + EXPECT_EQ(ret, true); + if (ret == true) { + SoundDecoderCallback_->amutex_.unlock(); + } +} + +// @tc.name Test OnOutputBufferAvailable API +// @tc.number SoundParser_OnOutputBufferAvailable_002 +// @tc.desc Test isRawFile_ = true +HWTEST_F(SoundParserUnitTest, SoundParser_OnOutputBufferAvailable_002, TestSize.Level0) +{ + ASSERT_NE(soundParser_, nullptr); + int32_t soundID = ID_TEST; + std::shared_ptr audioDec = std::make_shared(); + std::shared_ptr demuxer_value = std::make_shared(); + soundParser_->source_ = std::make_shared(); + std::shared_ptr demuxer = demuxer_value; + bool isRawFile = true; + SoundDecoderCallback_ = std::make_shared(soundID, audioDec, demuxer, isRawFile); + + SoundDecoderCallback_->isRawFile_ = true; + ASSERT_NE(SoundDecoderCallback_, nullptr); + MediaAVCodec::AVCodecBufferInfo info; + MediaAVCodec::AVCodecBufferFlag flag = AVCODEC_BUFFER_FLAG_EOS; + uint32_t index = ID_TEST; + std::shared_ptr buffer = std::make_shared(1, 1, "test"); + SoundDecoderCallback_->OnOutputBufferAvailable(index, info, flag, buffer); + bool ret = SoundDecoderCallback_->amutex_.try_lock(); + EXPECT_EQ(ret, true); + if (ret == true) { + SoundDecoderCallback_->amutex_.unlock(); + } +} +} // namespace Media +} // namespace OHOS diff --git a/test/unittest/sound_parser_unittest/sound_parser_unittest.h b/test/unittest/sound_parser_unittest/sound_parser_unittest.h new file mode 100644 index 0000000000000000000000000000000000000000..9b257cab8cea95208ccf56e2ae96d259befa777f --- /dev/null +++ b/test/unittest/sound_parser_unittest/sound_parser_unittest.h @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2025 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 SOUND_PARSER_UNITTEST_H +#define SOUND_PARSER_UNITTEST_H + +#include "gtest/gtest.h" +#include "mock/avdemuxer_impl.h" +#include "mock/avsource_impl.h" +#include "sound_parser.h" +#include +#include "avcodec_video_decoder.h" + +namespace OHOS { +namespace Media { +class SoundParserUnitTest : public testing::Test { +public: + // SetUpTestCase: Called before all test cases + static void SetUpTestCase(void); + // TearDownTestCase: Called after all test case + static void TearDownTestCase(void); + // SetUp: Called before each test cases + void SetUp(void); + // TearDown: Called after each test cases + void TearDown(void); + + std::shared_ptr soundParser_; + std::shared_ptr SoundDecoderCallback_; +}; +class MyAVCodecAudioDecoder : public MediaAVCodec::AVCodecAudioDecoder { +public: + ~MyAVCodecAudioDecoder() = default; + int32_t Configure(const Format &format) + { + return ret; + } + int32_t Prepare() + { + return 0; + } + int32_t Start() + { + return 0; + } + int32_t Stop() + { + return 0; + } + int32_t Flush() + { + return 0; + } + int32_t Reset() + { + return ret; + } + int32_t Release() + { + return 0; + } + int32_t QueueInputBuffer(uint32_t index, MediaAVCodec::AVCodecBufferInfo info, MediaAVCodec::AVCodecBufferFlag flag) + { + return ret; + } + int32_t GetOutputFormat(Format &format) + { + return ret; + } + int32_t ReleaseOutputBuffer(uint32_t index) + { + return ret; + } + int32_t SetParameter(const Format &format) + { + return 0; + } + int32_t SetCallback(const std::shared_ptr &callback) + { + return ret; + } + int32_t ret = 1; +}; +class MockSoundDecodeListener : public SoundDecoderCallback::SoundDecodeListener { +public: + MockSoundDecodeListener() = default; + ~MockSoundDecodeListener() = default; + + void OnSoundDecodeCompleted(const std::shared_ptr &fullCacheData) override + { + std::cout << "this is mock of OnSoundDecodeCompleted" << std::endl; + } + void SetSoundBufferTotalSize(const size_t soundBufferTotalSize) override + { + std::cout << "this is mock of SetSoundBufferTotalSize" << std::endl; + } +}; +class MockAVSharedMemory : public AVSharedMemory { +public: + MOCK_METHOD(uint8_t *, GetBase, (), (override, const)); + MOCK_METHOD(int32_t, GetSize, (), (override, const)); + MOCK_METHOD(uint32_t, GetFlags, (), (override, const)); +}; +} // namespace Media +} // namespace OHOS +#endif // HIPLAYER_IMPL_UNIT_TEST_H diff --git a/test/unittest/soundpool_cachebuffer_test/BUILD.gn b/test/unittest/soundpool_cachebuffer_test/BUILD.gn index 25e29f7ed64fff835e8199fda2877f64580906a1..75338d73d637820399329020b3885e930b4be409 100644 --- a/test/unittest/soundpool_cachebuffer_test/BUILD.gn +++ b/test/unittest/soundpool_cachebuffer_test/BUILD.gn @@ -60,6 +60,7 @@ ohos_unittest("soundpool_cachebuffer_unit_test") { "hicollie:libhicollie", "hilog:libhilog", "hisysevent:libhisysevent", + "hitrace:hitrace_meter", "init:libbegetutil", "ipc:ipc_core", "qos_manager:qos", diff --git a/test/unittest/soundpool_test/BUILD.gn b/test/unittest/soundpool_test/BUILD.gn index 54e4358a3e95f105f757e0750412fbf3f26edbdc..e77e4b15d0f0b37c4f8833f4b4623ca052c1eb23 100644 --- a/test/unittest/soundpool_test/BUILD.gn +++ b/test/unittest/soundpool_test/BUILD.gn @@ -66,6 +66,7 @@ ohos_unittest("soundpool_unit_test") { "hilog:libhilog", "hilog:libhilog", "hisysevent:libhisysevent", + "hitrace:hitrace_meter", "init:libbegetutil", "ipc:ipc_core", "qos_manager:qos", diff --git a/test/unittest/soundpool_test/src/soundpool_unit_test.cpp b/test/unittest/soundpool_test/src/soundpool_unit_test.cpp index f01b83e100e26ec9298e2de45fd0c21f2b3e0b93..81b91ea7c7bc9e9cf5d767d82bc6fc7663dd1731 100644 --- a/test/unittest/soundpool_test/src/soundpool_unit_test.cpp +++ b/test/unittest/soundpool_test/src/soundpool_unit_test.cpp @@ -160,10 +160,9 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_001, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPool_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrl(g_fileName[loadNum_], loadNum_); loadNum_++; loadUrl(g_fileName[loadNum_], loadNum_); @@ -172,10 +171,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_001, TestSize.Level2) loadNum_++; loadUrl(g_fileName[1], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(4)); cb->ResetHaveLoadedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_001 after"); @@ -193,10 +188,9 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_002, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPool_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); // test invalid path std::string fileName = "/data/test/test_05.mp3"; fds_[loadNum_] = open(fileName.c_str(), O_RDWR); @@ -207,10 +201,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_002, TestSize.Level2) cout << "Url open a invalid path: " << fileName.c_str() << endl; } EXPECT_EQ(soundIDs_[loadNum_], -1); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } MEDIA_LOGI("soundpool_unit_test soundpool_function_002 after"); } @@ -243,16 +233,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_004, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPool_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrl(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -265,10 +250,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_004, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_004 after"); } @@ -285,10 +266,9 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_005, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPool_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadFd(g_fileName[loadNum_], loadNum_); loadNum_++; loadFd(g_fileName[loadNum_], loadNum_); @@ -297,10 +277,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_005, TestSize.Level2) loadNum_++; loadFd(g_fileName[1], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(4)); cb->ResetHaveLoadedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_005 after"); @@ -318,10 +294,9 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_006, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPool_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); std::string fileName = "/data/test/test_05.mp3"; fds_[loadNum_] = open(fileName.c_str(), O_RDONLY); size_t filesize = soundPool_->GetFileSize(fileName); @@ -332,10 +307,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_006, TestSize.Level2) cout << "Fd open a invalid path: " << fileName.c_str() << endl; } EXPECT_EQ(soundIDs_[loadNum_], -1); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } MEDIA_LOGI("soundpool_unit_test soundpool_function_006 after"); } @@ -368,16 +339,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_008, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPool_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadFd(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -390,10 +356,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_008, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_008 after"); } @@ -410,10 +372,9 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_009, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPool_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrl(g_fileName[loadNum_], loadNum_); loadNum_++; loadUrl(g_fileName[loadNum_], loadNum_); @@ -422,10 +383,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_009, TestSize.Level2) loadNum_++; loadFd(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(4)); cb->ResetHaveLoadedSoundNum(); @@ -448,10 +405,9 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_010, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPool_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); std::string fileName = "/data/test/test_05.mp3"; fds_[loadNum_] = open(fileName.c_str(), O_RDWR); std::string url = "fd://" + std::to_string(fds_[loadNum_]); @@ -470,10 +426,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_010, TestSize.Level2) cout << "Fd open a invalid path: " << fileName.c_str() << endl; } EXPECT_EQ(soundIDs_[loadNum_], -1); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } // test UnLoad a invalid-path return soundId int32_t unload = soundPool_->Unload(soundIDs_[0]); EXPECT_EQ(MSERR_NO_MEMORY, unload); @@ -519,17 +471,12 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_012, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPool_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrl(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -544,10 +491,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_012, TestSize.Level2) EXPECT_GT(streamIDs_[playNum_], 0); sleep(waitTime3); } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_012 after"); } @@ -564,13 +507,10 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_013, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); soundPool_->SetSoundPoolCallback(cb); loadUrl(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -593,10 +533,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_013, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_013 after"); } @@ -613,19 +549,14 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_014, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPool_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); struct PlayParams playParameters; streamIDs_[playNum_] = soundPool_->Play(5, playParameters); cout << "soundId 5 play, result: " << streamIDs_[playNum_] << endl; EXPECT_EQ(streamIDs_[playNum_], -1); sleep(waitTime1); - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_014 after"); } @@ -642,19 +573,14 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_015, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPool_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); struct PlayParams playParameters; streamIDs_[playNum_] = soundPool_->Play(-1, playParameters); cout << "soundId -1 play, result: " << streamIDs_[playNum_] << endl; EXPECT_EQ(streamIDs_[playNum_], -1); sleep(waitTime1); - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_015 after"); } @@ -671,18 +597,13 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_016, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPool_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrl(g_fileName[loadNum_], loadNum_); loadNum_++; loadUrl(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(2)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -692,10 +613,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_016, TestSize.Level2) playNum_++; streamIDs_[playNum_] = soundPool_->Play(soundIDs_[1], playParameters); EXPECT_GT(streamIDs_[playNum_], 0); - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_016 after"); } @@ -712,16 +629,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_017, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPool_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrl(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -730,10 +642,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_017, TestSize.Level2) EXPECT_GT(streamIDs_[playNum_], 0); sleep(waitTime1); } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); if (streamIDs_[playNum_] > 0) { int32_t stopResult = soundPool_->Stop(streamIDs_[playNum_]); @@ -757,15 +665,12 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_018, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); soundPool_->SetSoundPoolCallback(cb); loadUrl(g_fileName[loadNum_], loadNum_); loadNum_++; loadFd(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(2)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -780,10 +685,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_018, TestSize.Level2) EXPECT_GT(streamIDs_[playNum_], 0); sleep(waitTime1); } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); if (streamIDs_[0] > 0) { EXPECT_EQ(MSERR_OK, soundPool_->Stop(streamIDs_[0])); @@ -806,6 +707,7 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_019, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); soundPool_->SetSoundPoolCallback(cb); loadUrl(g_fileName[loadNum_], loadNum_); loadNum_++; @@ -813,10 +715,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_019, TestSize.Level2) loadNum_++; loadUrl(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(3)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -836,10 +734,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_019, TestSize.Level2) EXPECT_GT(streamIDs_[playNum_], 0); sleep(waitTime1); } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); EXPECT_EQ(MSERR_OK, soundPool_->Stop(streamIDs_[0])); EXPECT_EQ(MSERR_OK, soundPool_->Stop(streamIDs_[2])); @@ -858,16 +752,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_020, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPool_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrl(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); int32_t stopResult = soundPool_->Stop(-1); @@ -887,16 +776,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_021, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPool_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrl(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -912,10 +796,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_021, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); EXPECT_EQ(MSERR_OK, soundPool_->Unload(soundIDs_[loadNum_])); MEDIA_LOGI("soundpool_unit_test soundpool_function_021 after"); @@ -933,16 +813,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_022, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPool_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrl(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -958,10 +833,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_022, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_022 after"); } @@ -978,16 +849,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_023, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPool_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrl(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -1003,10 +869,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_023, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_023 after"); } @@ -1023,16 +885,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_024, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPool_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrl(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -1048,10 +905,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_024, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_024 after"); } @@ -1068,15 +921,12 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_025, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); soundPool_->SetSoundPoolCallback(cb); loadUrl(g_fileName[loadNum_], loadNum_); loadNum_++; loadUrl(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(2)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -1098,10 +948,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_025, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_025 after"); } @@ -1118,15 +964,12 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_026, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); soundPool_->SetSoundPoolCallback(cb); loadUrl(g_fileName[loadNum_], loadNum_); loadNum_++; loadUrl(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(2)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -1148,10 +991,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_026, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_026 after"); } @@ -1168,16 +1007,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_027, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPool_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrl(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -1196,10 +1030,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_027, TestSize.Level2) cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_027 after"); } @@ -1216,15 +1046,12 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_028, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); soundPool_->SetSoundPoolCallback(cb); loadUrl(g_fileName[loadNum_], loadNum_); loadNum_++; loadUrl(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(2)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -1245,10 +1072,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_028, TestSize.Level2) EXPECT_EQ(MSERR_OK, setRateResult); sleep(waitTime3); } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_028 after"); } @@ -1265,15 +1088,12 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_029, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); soundPool_->SetSoundPoolCallback(cb); loadUrl(g_fileName[loadNum_], loadNum_); loadNum_++; loadUrl(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(2)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -1295,10 +1115,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_029, TestSize.Level2) EXPECT_EQ(MSERR_OK, setRateResult); sleep(waitTime3); } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_029 after"); } @@ -1315,16 +1131,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_030, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPool_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrl(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -1340,10 +1151,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_030, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_030 after"); } @@ -1360,16 +1167,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_031, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPool_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrl(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -1387,10 +1189,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_031, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_031 after"); } @@ -1407,16 +1205,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_032, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPool_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrl(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -1431,10 +1224,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_032, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_032 after"); } @@ -1451,16 +1240,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_033, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPool_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrl(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -1475,10 +1259,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_033, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_033 after"); } @@ -1495,18 +1275,13 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_034, TestSize.Level2) int maxStreams = 1; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPool_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrl(g_fileName[loadNum_], loadNum_); loadNum_++; loadUrl(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(2)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -1526,10 +1301,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_034, TestSize.Level2) EXPECT_EQ(MSERR_OK, setPriority); sleep(waitTime1); } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_034 after"); } @@ -1547,15 +1318,12 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_035, TestSize.Level2) int maxStreams = 1; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPool_); + ASSERT_TRUE(cb != nullptr); soundPool_->SetSoundPoolCallback(cb); loadUrl(g_fileName[loadNum_], loadNum_); loadNum_++; loadUrl(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(2)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -1576,10 +1344,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_035, TestSize.Level2) int32_t setPriority = soundPool_->SetPriority(streamIDs_[0], priority); sleep(waitTime1); EXPECT_EQ(MSERR_OK, setPriority); - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_035 after"); } diff --git a/test/unittest/soundpool_test/src/soundpool_unit_test_parallel.cpp b/test/unittest/soundpool_test/src/soundpool_unit_test_parallel.cpp index 14e8247ffd7fd50c05b7c2df6bd8562018f6f1f2..8f212a811f44f5c7cd37a48670085323990c03fa 100644 --- a/test/unittest/soundpool_test/src/soundpool_unit_test_parallel.cpp +++ b/test/unittest/soundpool_test/src/soundpool_unit_test_parallel.cpp @@ -45,10 +45,9 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_044, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrlParallel(g_fileName[loadNum_], loadNum_); loadNum_++; loadUrlParallel(g_fileName[loadNum_], loadNum_); @@ -57,10 +56,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_044, TestSize.Level2) loadNum_++; loadUrlParallel(g_fileName[1], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(4)); cb->ResetHaveLoadedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_044 after"); @@ -78,10 +73,9 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_045, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); // test invalid path std::string fileName = "/data/test/test_05.mp3"; fds_[loadNum_] = open(fileName.c_str(), O_RDWR); @@ -92,10 +86,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_045, TestSize.Level2) cout << "Url open a invalid path: " << fileName.c_str() << endl; } EXPECT_EQ(soundIDs_[loadNum_], -1); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } MEDIA_LOGI("soundpool_unit_test soundpool_function_045 after"); } @@ -128,16 +118,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_047, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -150,10 +135,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_047, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_047 after"); } @@ -170,10 +151,9 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_048, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadFdParallel(g_fileName[loadNum_], loadNum_); loadNum_++; loadFdParallel(g_fileName[loadNum_], loadNum_); @@ -182,10 +162,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_048, TestSize.Level2) loadNum_++; loadFdParallel(g_fileName[1], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(4)); cb->ResetHaveLoadedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_048 after"); @@ -203,10 +179,9 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_049, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); std::string fileName = "/data/test/test_05.mp3"; fds_[loadNum_] = open(fileName.c_str(), O_RDONLY); size_t filesize = soundPoolParallel_->GetFileSize(fileName); @@ -217,10 +192,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_049, TestSize.Level2) cout << "Fd open a invalid path: " << fileName.c_str() << endl; } EXPECT_EQ(soundIDs_[loadNum_], -1); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } MEDIA_LOGI("soundpool_unit_test soundpool_function_049 after"); } @@ -253,16 +224,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_051, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadFdParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -275,10 +241,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_051, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_051 after"); } @@ -295,10 +257,9 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_052, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrlParallel(g_fileName[loadNum_], loadNum_); loadNum_++; loadUrlParallel(g_fileName[loadNum_], loadNum_); @@ -307,10 +268,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_052, TestSize.Level2) loadNum_++; loadFdParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(4)); cb->ResetHaveLoadedSoundNum(); EXPECT_EQ(MSERR_OK, soundPoolParallel_->Unload(soundIDs_[0])); @@ -332,10 +289,9 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_053, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); std::string fileName = "/data/test/test_05.mp3"; fds_[loadNum_] = open(fileName.c_str(), O_RDWR); std::string url = "fd://" + std::to_string(fds_[loadNum_]); @@ -354,10 +310,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_053, TestSize.Level2) cout << "Fd open a invalid path: " << fileName.c_str() << endl; } EXPECT_EQ(soundIDs_[loadNum_], -1); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } // test UnLoad a invalid-path return soundId int32_t unload = soundPoolParallel_->Unload(soundIDs_[0]); EXPECT_EQ(MSERR_NO_MEMORY, unload); @@ -403,17 +355,12 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_055, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -428,10 +375,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_055, TestSize.Level2) EXPECT_GT(streamIDs_[playNum_], 0); sleep(waitTime3); } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_055 after"); } @@ -448,13 +391,10 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_056, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); soundPoolParallel_->SetSoundPoolCallback(cb); loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -477,10 +417,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_056, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_056 after"); } @@ -497,19 +433,14 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_057, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); struct PlayParams playParameters; streamIDs_[playNum_] = soundPoolParallel_->Play(5, playParameters); cout << "soundId 5 play, result: " << streamIDs_[playNum_] << endl; EXPECT_EQ(streamIDs_[playNum_], -1); sleep(waitTime1); - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_057 after"); } @@ -526,19 +457,14 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_058, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); struct PlayParams playParameters; streamIDs_[playNum_] = soundPoolParallel_->Play(-1, playParameters); cout << "soundId -1 play, result: " << streamIDs_[playNum_] << endl; EXPECT_EQ(streamIDs_[playNum_], -1); sleep(waitTime1); - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_058 after"); } @@ -555,18 +481,13 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_059, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrlParallel(g_fileName[loadNum_], loadNum_); loadNum_++; loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(2)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -576,10 +497,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_059, TestSize.Level2) playNum_++; streamIDs_[playNum_] = soundPoolParallel_->Play(soundIDs_[1], playParameters); EXPECT_GT(streamIDs_[playNum_], 0); - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_059 after"); } @@ -596,16 +513,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_060, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -614,10 +526,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_060, TestSize.Level2) EXPECT_GT(streamIDs_[playNum_], 0); sleep(waitTime1); } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); if (streamIDs_[playNum_] > 0) { int32_t stopResult = soundPoolParallel_->Stop(streamIDs_[playNum_]); @@ -641,15 +549,12 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_061, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); soundPoolParallel_->SetSoundPoolCallback(cb); loadUrlParallel(g_fileName[loadNum_], loadNum_); loadNum_++; loadFdParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(2)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -664,10 +569,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_061, TestSize.Level2) EXPECT_GT(streamIDs_[playNum_], 0); sleep(waitTime1); } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); if (streamIDs_[0] > 0) { EXPECT_EQ(MSERR_OK, soundPoolParallel_->Stop(streamIDs_[0])); @@ -690,6 +591,7 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_062, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); soundPoolParallel_->SetSoundPoolCallback(cb); loadUrlParallel(g_fileName[loadNum_], loadNum_); loadNum_++; @@ -697,10 +599,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_062, TestSize.Level2) loadNum_++; loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(3)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -720,10 +618,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_062, TestSize.Level2) EXPECT_GT(streamIDs_[playNum_], 0); sleep(waitTime1); } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); EXPECT_EQ(MSERR_OK, soundPoolParallel_->Stop(streamIDs_[0])); EXPECT_EQ(MSERR_OK, soundPoolParallel_->Stop(streamIDs_[2])); @@ -742,16 +636,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_063, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); int32_t stopResult = soundPoolParallel_->Stop(-1); @@ -771,16 +660,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_064, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -796,10 +680,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_064, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); EXPECT_EQ(MSERR_OK, soundPoolParallel_->Unload(soundIDs_[loadNum_])); MEDIA_LOGI("soundpool_unit_test soundpool_function_064 after"); @@ -817,16 +697,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_065, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -842,10 +717,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_065, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_065 after"); } @@ -862,16 +733,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_066, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -887,10 +753,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_066, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_066 after"); } @@ -907,16 +769,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_067, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -932,10 +789,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_067, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_067 after"); } @@ -952,15 +805,12 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_068, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); soundPoolParallel_->SetSoundPoolCallback(cb); loadUrlParallel(g_fileName[loadNum_], loadNum_); loadNum_++; loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(2)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -982,10 +832,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_068, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_068 after"); } @@ -1002,15 +848,12 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_069, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); soundPoolParallel_->SetSoundPoolCallback(cb); loadUrlParallel(g_fileName[loadNum_], loadNum_); loadNum_++; loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(2)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -1032,10 +875,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_069, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_069 after"); } @@ -1052,16 +891,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_070, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -1080,10 +914,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_070, TestSize.Level2) cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_070 after"); } @@ -1100,15 +930,12 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_071, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); soundPoolParallel_->SetSoundPoolCallback(cb); loadUrlParallel(g_fileName[loadNum_], loadNum_); loadNum_++; loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(2)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -1129,10 +956,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_071, TestSize.Level2) EXPECT_EQ(MSERR_OK, result); sleep(waitTime3); } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_071 after"); } @@ -1149,15 +972,12 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_072, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); soundPoolParallel_->SetSoundPoolCallback(cb); loadUrlParallel(g_fileName[loadNum_], loadNum_); loadNum_++; loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(2)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -1179,10 +999,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_072, TestSize.Level2) EXPECT_EQ(MSERR_OK, result); sleep(waitTime3); } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_072 after"); } @@ -1199,16 +1015,13 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_073, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); if (ret != 0) { cout << "set callback failed" << endl; } loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -1224,10 +1037,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_073, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_073 after"); } @@ -1244,16 +1053,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_074, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -1271,10 +1075,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_074, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_074 after"); } @@ -1291,16 +1091,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_075, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -1315,10 +1110,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_075, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_075 after"); } @@ -1335,16 +1126,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_076, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(1)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -1359,10 +1145,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_076, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_076 after"); } @@ -1379,18 +1161,13 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_077, TestSize.Level2) int maxStreams = 1; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrlParallel(g_fileName[loadNum_], loadNum_); loadNum_++; loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(2)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -1408,10 +1185,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_077, TestSize.Level2) EXPECT_EQ(MSERR_OK, setPriority); sleep(waitTime1); } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_077 after"); } @@ -1429,15 +1202,12 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_078, TestSize.Level2) int maxStreams = 1; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); soundPoolParallel_->SetSoundPoolCallback(cb); loadUrlParallel(g_fileName[loadNum_], loadNum_); loadNum_++; loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } ASSERT_TRUE(cb->WaitLoadedSoundNum(2)); cb->ResetHaveLoadedSoundNum(); struct PlayParams playParameters; @@ -1456,10 +1226,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_078, TestSize.Level2) streamIDs_[playNum_] = soundPoolParallel_->Play(soundIDs_[1], playParameters); EXPECT_GT(streamIDs_[1], 0); } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_078 after"); } @@ -1971,16 +1737,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_089, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } while (true) { if (cb->GetHaveLoadedSoundNum() == 1) { cout << "All sound loaded Url break. loaded sound num = " << cb->GetHaveLoadedSoundNum() << endl; @@ -1997,10 +1758,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_089, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_089 after"); } @@ -2017,16 +1774,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_090, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } while (true) { if (cb->GetHaveLoadedSoundNum() == 1) { cout << "All sound loaded Url break. loaded sound num = " << cb->GetHaveLoadedSoundNum() << endl; @@ -2046,10 +1798,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_090, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_090 after"); } @@ -2066,16 +1814,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_091, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } while (true) { if (cb->GetHaveLoadedSoundNum() == 1) { cout << "All sound loaded Url break. loaded sound num = " << cb->GetHaveLoadedSoundNum() << endl; @@ -2096,10 +1839,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_091, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_091 after"); } @@ -2116,16 +1855,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_092, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } while (true) { if (cb->GetHaveLoadedSoundNum() == 1) { cout << "All sound loaded Url break. loaded sound num = " << cb->GetHaveLoadedSoundNum() << endl; @@ -2146,10 +1880,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_092, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_092 after"); } @@ -2166,16 +1896,11 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_093, TestSize.Level2) int maxStreams = 3; create(maxStreams); std::shared_ptr cb = std::make_shared(soundPoolParallel_); + ASSERT_TRUE(cb != nullptr); int32_t ret = soundPoolParallel_->SetSoundPoolCallback(cb); - if (ret != 0) { - cout << "set callback failed" << endl; - } + ASSERT_TRUE(ret == 0); loadUrlParallel(g_fileName[loadNum_], loadNum_); sleep(waitTime3); - if (cb == nullptr) { - cout << "Invalid cb to get loaded sound num." << endl; - return; - } while (true) { if (cb->GetHaveLoadedSoundNum() == 1) { cout << "All sound loaded Url break. loaded sound num = " << cb->GetHaveLoadedSoundNum() << endl; @@ -2196,10 +1921,6 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_093, TestSize.Level2) } else { cout << "Get soundId failed, please try to get soundId: " << soundIDs_[loadNum_] << endl; } - if (cb == nullptr) { - cout << "Invalid cb to get played sound num." << endl; - return; - } cb->ResetHavePlayedSoundNum(); MEDIA_LOGI("soundpool_unit_test soundpool_function_093 after"); } diff --git a/test/unittest/soundpool_unittest/BUILD.gn b/test/unittest/soundpool_unittest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0f091d3db530ceb31ea77730db0bf9d8f09c29a3 --- /dev/null +++ b/test/unittest/soundpool_unittest/BUILD.gn @@ -0,0 +1,76 @@ +# Copyright (c) 2025 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/test.gni") +import("//foundation/multimedia/player_framework/config.gni") +import("./../../../multimedia_player_framework_aafwk.gni") + +module_output_path = "player_framework/player_framework/soundpool" + +ohos_unittest("soundpool_unittest") { + module_out_path = module_output_path + include_dirs = [ + "./", + "${multimedia_player_framework_path}/interfaces/inner_api/native/soundpool/include", + "${multimedia_player_framework_path}/frameworks/native/soundpool", + "${multimedia_player_framework_path}/services/services/engine_intf", + "${multimedia_player_framework_path}/test/unittest/common/include", + ] + + cflags = [ + "-Wall", + "-Werror", + "-Dprivate=public", + "-Dprotected=public", + ] + + sources = [ + "./audio_renderer_manager_unittest.cpp", + "./parallel_stream_manager_test.cpp", + "./sound_id_manager_unittest.cpp", + "./soundpool_unittest.cpp", + "./stream_unittest.cpp", + ] + + deps = [ + "${multimedia_player_framework_path}/frameworks/native/soundpool:soundpool_client", + "${multimedia_player_framework_path}/interfaces/inner_api/native:media_client", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_manager", + "ability_runtime:abilitykit_native", + "audio_framework:audio_client", + "audio_framework:audio_renderer", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "ffrt:libffrt", + "googletest:gmock", + "graphic_surface:surface", + "hicollie:libhicollie", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "init:libbegetutil", + "ipc:ipc_core", + "qos_manager:qos", + ] + + if (player_framework_support_drm) { + external_deps += [ "drm_framework:drm_framework" ] + } + + resource_config_file = "${multimedia_player_framework_path}/test/unittest/resources/ohos_test.xml" +} diff --git a/test/unittest/soundpool_unittest/audio_renderer_manager_unittest.cpp b/test/unittest/soundpool_unittest/audio_renderer_manager_unittest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f5bc808909aa107c766b0a2db675c78f43d3f5e1 --- /dev/null +++ b/test/unittest/soundpool_unittest/audio_renderer_manager_unittest.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 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 "media_errors.h" +#include "audio_renderer_manager_unittest.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Media { +void AudioRendererManagerUnittest::SetUpTestCase(void) {} +void AudioRendererManagerUnittest::TearDownTestCase(void) {} +void AudioRendererManagerUnittest::SetUp(void) {} +void AudioRendererManagerUnittest::TearDown(void) {} + +/** + * @tc.name : Test RemoveOldAudioRenderer + * @tc.number: AudioRendererManagerRemoveOldAudioRenderer_001 + * @tc.desc : Test audioRendererVector_.size() > 0 + * Test removeGlobeId > 0 + */ +HWTEST_F(AudioRendererManagerUnittest, AudioRendererManagerRemoveOldAudioRenderer_001, TestSize.Level0) +{ + AudioRendererManager& testPtr = AudioRendererManager::GetInstance(); + ASSERT_NE(&testPtr, nullptr); + auto mockAudioRenderer = std::make_unique(); + EXPECT_CALL(*(mockAudioRenderer), Release()).WillRepeatedly(Return(false)); + std::unique_ptr audioRenderer = std::move(mockAudioRenderer); + testPtr.audioRendererVector_.push_back( + std::make_pair(1, std::move(audioRenderer)) + ); + testPtr.RemoveOldAudioRenderer(); + EXPECT_EQ(testPtr.audioRendererVector_.size(), 0); +} +} // namespace Media +} // namespace OHOS diff --git a/test/unittest/soundpool_unittest/audio_renderer_manager_unittest.h b/test/unittest/soundpool_unittest/audio_renderer_manager_unittest.h new file mode 100644 index 0000000000000000000000000000000000000000..a0fc73652a8c9ef866fa7b6ce12c91330414aedb --- /dev/null +++ b/test/unittest/soundpool_unittest/audio_renderer_manager_unittest.h @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2025 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 AUDIO_RENDERER_MANAGER_UNIT_TEST_H +#define AUDIO_RENDERER_MANAGER_UNIT_TEST_H +#include +#include +#include "audio_renderer_manager.h" + +namespace OHOS { +namespace Media { +class AudioRendererManagerUnittest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +class MockAudioRenderer : public AudioStandard::AudioRenderer { +public: + MOCK_METHOD(void, SetAudioPrivacyType, (AudioStandard::AudioPrivacyType privacyType), (override)); + MOCK_METHOD(AudioStandard::AudioPrivacyType, GetAudioPrivacyType, (), (override)); + MOCK_METHOD(int32_t, SetParams, (const AudioStandard::AudioRendererParams params), (override)); + MOCK_METHOD(int32_t, SetRendererCallback, + (const std::shared_ptr &callback), (override)); + MOCK_METHOD(int32_t, GetParams, (AudioStandard::AudioRendererParams ¶ms), (const, override)); + MOCK_METHOD(int32_t, GetRendererInfo, (AudioStandard::AudioRendererInfo &rendererInfo), (const, override)); + MOCK_METHOD(int32_t, GetStreamInfo, (AudioStandard::AudioStreamInfo &streamInfo), (const, override)); + MOCK_METHOD(bool, Start, (AudioStandard::StateChangeCmdType cmdType), (override)); + MOCK_METHOD(int32_t, Write, (uint8_t *buffer, size_t bufferSize), (override)); + MOCK_METHOD(int32_t, Write, + (uint8_t *pcmBuffer, size_t pcmBufferSize, uint8_t *metaBuffer, size_t metaBufferSize), (override)); + MOCK_METHOD(AudioStandard::RendererState, GetStatus, (), (const, override)); + MOCK_METHOD(bool, GetAudioTime, + (AudioStandard::Timestamp ×tamp, AudioStandard::Timestamp::Timestampbase base), (const, override)); + MOCK_METHOD(bool, GetAudioPosition, + (AudioStandard::Timestamp ×tamp, AudioStandard::Timestamp::Timestampbase base), (override)); + MOCK_METHOD(int32_t, GetLatency, (uint64_t &latency), (const, override)); + MOCK_METHOD(bool, Drain, (), (const, override)); + MOCK_METHOD(bool, Flush, (), (const, override)); + MOCK_METHOD(bool, PauseTransitent, (AudioStandard::StateChangeCmdType cmdType), (override)); + MOCK_METHOD(bool, Pause, (AudioStandard::StateChangeCmdType cmdType), (override)); + MOCK_METHOD(bool, Stop, (), (override)); + MOCK_METHOD(int32_t, GetBufferSize, (size_t &bufferSize), (const, override)); + MOCK_METHOD(int32_t, GetAudioStreamId, (uint32_t &sessionID), (const, override)); + MOCK_METHOD(int32_t, GetFrameCount, (uint32_t &frameCount), (const, override)); + MOCK_METHOD(int32_t, SetAudioRendererDesc, (AudioStandard::AudioRendererDesc audioRendererDesc), (override)); + MOCK_METHOD(int32_t, SetStreamType, (AudioStandard::AudioStreamType audioStreamType), (override)); + MOCK_METHOD(int32_t, SetVolume, (float volume), (const, override)); + MOCK_METHOD(int32_t, SetVolumeMode, (int32_t mode), (override)); + MOCK_METHOD(float, GetVolume, (), (const, override)); + MOCK_METHOD(int32_t, SetRenderRate, (AudioStandard::AudioRendererRate renderRate), (const, override)); + MOCK_METHOD(AudioStandard::AudioRendererRate, GetRenderRate, (), (const, override)); + MOCK_METHOD(int32_t, SetRendererSamplingRate, (uint32_t sampleRate), (const, override)); + MOCK_METHOD(uint32_t, GetRendererSamplingRate, (), (const, override)); + MOCK_METHOD(int32_t, SetRendererPositionCallback, (int64_t markPosition, + const std::shared_ptr &callback), (override)); + MOCK_METHOD(void, UnsetRendererPositionCallback, (), (override)); + MOCK_METHOD(void, SetPreferredFrameSize, (int32_t frameSize), (override)); + MOCK_METHOD(int32_t, SetRendererPeriodPositionCallback, (int64_t frameNumber, + const std::shared_ptr &callback), (override)); + MOCK_METHOD(void, UnsetRendererPeriodPositionCallback, (), (override)); + MOCK_METHOD(int32_t, SetBufferDuration, (uint64_t bufferDuration), (const, override)); + MOCK_METHOD(int32_t, SetRenderMode, (AudioStandard::AudioRenderMode renderMode), (override)); + MOCK_METHOD(AudioStandard::AudioRenderMode, GetRenderMode, (), (const, override)); + MOCK_METHOD(int32_t, SetRendererWriteCallback, + (const std::shared_ptr &callback), (override)); + MOCK_METHOD(int32_t, SetRendererFirstFrameWritingCallback, + (const std::shared_ptr &callback), (override)); + MOCK_METHOD(int32_t, GetBufferDesc, (AudioStandard::BufferDesc &bufDesc), (override)); + MOCK_METHOD(int32_t, Enqueue, (const AudioStandard::BufferDesc &bufDesc), (override)); + MOCK_METHOD(int32_t, Clear, (), (const, override)); + MOCK_METHOD(int32_t, GetBufQueueState, (AudioStandard::BufferQueueState &bufState), (const, override)); + MOCK_METHOD(void, SetInterruptMode, (AudioStandard::InterruptMode mode), (override)); + MOCK_METHOD(int32_t, SetParallelPlayFlag, (bool parallelPlayFlag), (override)); + MOCK_METHOD(int32_t, SetLowPowerVolume, (float volume), (const, override)); + MOCK_METHOD(float, GetLowPowerVolume, (), (const, override)); + MOCK_METHOD(int32_t, SetOffloadAllowed, (bool isAllowed), (override)); + MOCK_METHOD(int32_t, SetOffloadMode, (int32_t state, bool isAppBack), (const, override)); + MOCK_METHOD(int32_t, UnsetOffloadMode, (), (const, override)); + MOCK_METHOD(float, GetSingleStreamVolume, (), (const, override)); + MOCK_METHOD(float, GetMinStreamVolume, (), (const, override)); + MOCK_METHOD(float, GetMaxStreamVolume, (), (const, override)); + MOCK_METHOD(uint32_t, GetUnderflowCount, (), (const, override)); + MOCK_METHOD(int32_t, GetCurrentOutputDevices, (AudioStandard::AudioDeviceDescriptor &deviceInfo), + (const, override)); + MOCK_METHOD(AudioStandard::AudioEffectMode, GetAudioEffectMode, (), (const, override)); + MOCK_METHOD(int64_t, GetFramesWritten, (), (const, override)); + MOCK_METHOD(int32_t, SetAudioEffectMode, (AudioStandard::AudioEffectMode effectMode), (const, override)); + MOCK_METHOD(void, SetAudioRendererErrorCallback, + (std::shared_ptr errorCallback), (override)); + MOCK_METHOD(int32_t, RegisterOutputDeviceChangeWithInfoCallback, + (const std::shared_ptr &callback), (override)); + MOCK_METHOD(int32_t, UnregisterOutputDeviceChangeWithInfoCallback, + (const std::shared_ptr &callback), (override)); + MOCK_METHOD(int32_t, UnregisterOutputDeviceChangeWithInfoCallback, (), (override)); + MOCK_METHOD(int32_t, RegisterAudioPolicyServerDiedCb, (const int32_t clientPid, + const std::shared_ptr &callback), (override)); + MOCK_METHOD(int32_t, UnregisterAudioPolicyServerDiedCb, (const int32_t clientPid), (override)); + MOCK_METHOD(int32_t, SetChannelBlendMode, (AudioStandard::ChannelBlendMode blendMode), (override)); + MOCK_METHOD(int32_t, SetVolumeWithRamp, (float volume, int32_t duration), (override)); + MOCK_METHOD(int32_t, SetSpeed, (float speed), (override)); + MOCK_METHOD(int32_t, SetPitch, (float pitch), ()); + MOCK_METHOD(float, GetSpeed, (), (override)); + MOCK_METHOD(bool, IsFastRenderer, (), (override)); + MOCK_METHOD(void, SetSilentModeAndMixWithOthers, (bool on), (override)); + MOCK_METHOD(bool, GetSilentModeAndMixWithOthers, (), (override)); + MOCK_METHOD(void, EnableVoiceModemCommunicationStartStream, (bool enable), (override)); + MOCK_METHOD(bool, IsNoStreamRenderer, (), (const, override)); + MOCK_METHOD(int32_t, GetAudioTimestampInfo, + (AudioStandard::Timestamp ×tamp, AudioStandard::Timestamp::Timestampbase base), (const, override)); + MOCK_METHOD(bool, Release, (), (override)); + MOCK_METHOD(void, SetFastStatusChangeCallback, + (const std::shared_ptr& callback), + (override)); +}; +} // namespace Media +} // namespace OHOS + +#endif // AUDIO_RENDERER_MANAGER_UNIT_TEST_H diff --git a/test/unittest/soundpool_unittest/parallel_stream_manager_test.cpp b/test/unittest/soundpool_unittest/parallel_stream_manager_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ba9715f468380a365cd3a2819c43f5100f109a7d --- /dev/null +++ b/test/unittest/soundpool_unittest/parallel_stream_manager_test.cpp @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2025 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 "media_errors.h" +#include "parallel_stream_manager_test.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Media { + +static const int32_t ID_TEST = 1; +static const int32_t NUM_TEST = 0; +static const int32_t DEFAULT_NUM = 10; +void ParallelStreamManagerTest::SetUpTestCase(void) {} +void ParallelStreamManagerTest::TearDownTestCase(void) {} +void ParallelStreamManagerTest::SetUp(void) +{ + int32_t maxStreams = 1; + AudioStandard::AudioRendererInfo audioRenderInfo; + testPtr_ = std::make_shared(maxStreams, audioRenderInfo); +} +void ParallelStreamManagerTest::TearDown(void) +{ + testPtr_ = nullptr; +} + +/** + * @tc.name : Test ~ParallelStreamManager + * @tc.number: ParallelStreamManagerTestDestruct_001 + * @tc.desc : Test frameWriteCallback_ != nullptr + */ +HWTEST_F(ParallelStreamManagerTest, ParallelStreamManagerTestDestruct_001, TestSize.Level0) +{ + ASSERT_NE(testPtr_, nullptr); + auto frameWriteCallback = std::make_shared(); + testPtr_->frameWriteCallback_ = frameWriteCallback; + EXPECT_NE(testPtr_->frameWriteCallback_, nullptr); +} + +/** + * @tc.name : Test InitThreadPool + * @tc.number: ParallelStreamManagerInitThreadPool_001 + * @tc.desc : Test maxStreams_ < MIN_PLAY_STREAMS_NUMBER + */ +HWTEST_F(ParallelStreamManagerTest, ParallelStreamManagerInitThreadPool_001, TestSize.Level0) +{ + ASSERT_NE(testPtr_, nullptr); + testPtr_->maxStreams_ = NUM_TEST; + testPtr_->frameWriteCallback_ = nullptr; + auto ret = testPtr_->InitThreadPool(); + EXPECT_EQ(ret, MSERR_OK); +} + +/** + * @tc.name : Test RemoveFromWaitingDeque + * @tc.number: ParallelStreamManagerRemoveFromWaitingDeque_001 + * @tc.desc : Test it->first != streamId + */ +HWTEST_F(ParallelStreamManagerTest, ParallelStreamManagerRemoveFromWaitingDeque_001, TestSize.Level0) +{ + ASSERT_NE(testPtr_, nullptr); + int32_t idTest = ID_TEST; + std::shared_ptr testPtr1 = nullptr; + Format trackFormat; + int32_t soundID = ID_TEST; + int32_t streamID = DEFAULT_NUM; + std::shared_ptr streamStopThreadPool; + std::shared_ptr testPtr2 = std::make_shared(trackFormat, soundID, streamID, streamStopThreadPool); + testPtr_->waitingStream_.push_back(std::make_pair(0, testPtr1)); + testPtr_->waitingStream_.push_back(std::make_pair(idTest, testPtr2)); + testPtr_->RemoveFromWaitingDeque(idTest); + EXPECT_EQ(testPtr_->waitingStream_.size(), 1); +} + +/** + * @tc.name : Test AddToPlayingDeque + * @tc.number: ParallelStreamManagerAddToPlayingDeque_001 + * @tc.desc : Test stream->GetPriority() >= playingStream->GetPriority() + */ +HWTEST_F(ParallelStreamManagerTest, ParallelStreamManagerAddToPlayingDeque_001, TestSize.Level0) +{ + ASSERT_NE(testPtr_, nullptr); + int32_t streamID1 = ID_TEST; + Format trackFormat; + int32_t soundID = ID_TEST; + int32_t streamID2 = DEFAULT_NUM; + std::shared_ptr streamStopThreadPool; + std::shared_ptr stream = std::make_shared(trackFormat, soundID, streamID1, streamStopThreadPool); + std::shared_ptr stream2 = std::make_shared(trackFormat, soundID, streamID2, streamStopThreadPool); + testPtr_->playingStream_.push_back(std::make_pair(1, stream2)); + testPtr_->AddToPlayingDeque(streamID1, stream); + EXPECT_EQ(testPtr_->playingStream_.size(), 2); +} + +/** + * @tc.name : Test DoPlay + * @tc.number: ParallelStreamManagerDoPlay_001 + * @tc.desc : Test it->first == streamID + * Test it->first != streamID + */ +HWTEST_F(ParallelStreamManagerTest, ParallelStreamManagerDoPlay_001, TestSize.Level0) +{ + ASSERT_NE(testPtr_, nullptr); + int32_t streamID1 = ID_TEST; + Format trackFormat; + int32_t soundID = ID_TEST; + int32_t streamID2 = DEFAULT_NUM; + std::shared_ptr streamStopThreadPool; + std::shared_ptr stream1 = std::make_shared(trackFormat, soundID, streamID2, streamStopThreadPool); + std::shared_ptr stream2 = std::make_shared(trackFormat, soundID, streamID2, streamStopThreadPool); + testPtr_->playingStream_.push_back(std::make_pair(0, stream1)); + testPtr_->playingStream_.push_back(std::make_pair(1, stream2)); + auto ret = testPtr_->DoPlay(streamID1); + EXPECT_EQ(ret, MSERR_INVALID_VAL); +} + +/** + * @tc.name : Test UnloadStream + * @tc.number: ParallelStreamManagerUnloadStream_001 + * @tc.desc : Test it->second->GetSoundID() == soundId + * Test it->second->GetSoundID() != soundId + * Test it = playingStream_.begin(), it->second->GetSoundID() != soundId + */ +HWTEST_F(ParallelStreamManagerTest, ParallelStreamManagerUnloadStream_001, TestSize.Level0) +{ + ASSERT_NE(testPtr_, nullptr); + int32_t streamID1 = ID_TEST; + Format trackFormat; + int32_t soundID = ID_TEST; + int32_t streamID2 = DEFAULT_NUM; + std::shared_ptr streamStopThreadPool; + std::shared_ptr stream1 = std::make_shared(trackFormat, soundID, streamID2, streamStopThreadPool); + std::shared_ptr stream2 = std::make_shared(trackFormat, soundID, streamID2, streamStopThreadPool); + testPtr_->waitingStream_.push_back(std::make_pair(0, stream1)); + testPtr_->waitingStream_.push_back(std::make_pair(1, stream2)); + + std::shared_ptr stream3 = std::make_shared(trackFormat, soundID, streamID2, streamStopThreadPool); + std::shared_ptr stream4 = std::make_shared(trackFormat, soundID, streamID2, streamStopThreadPool); + testPtr_->playingStream_.push_back(std::make_pair(0, stream3)); + testPtr_->playingStream_.push_back(std::make_pair(1, stream4)); + auto ret = testPtr_->UnloadStream(streamID1); + EXPECT_EQ(ret, MSERR_OK); +} + +/** + * @tc.name : Test ReorderStream + * @tc.number: ParallelStreamManagerReorderStream_001 + * @tc.desc : Test (left != nullptr && right != nullptr && left->GetPriority() < right->GetPriority()) == true + */ +HWTEST_F(ParallelStreamManagerTest, ParallelStreamManagerReorderStream_001, TestSize.Level0) +{ + ASSERT_NE(testPtr_, nullptr); + Format trackFormat; + int32_t soundID = ID_TEST; + int32_t streamID2 = DEFAULT_NUM; + std::shared_ptr streamStopThreadPool; + std::shared_ptr stream1 = std::make_shared(trackFormat, soundID, streamID2, streamStopThreadPool); + std::shared_ptr stream2 = std::make_shared(trackFormat, soundID, streamID2, streamStopThreadPool); + testPtr_->playingStream_.push_back(std::make_pair(0, stream1)); + testPtr_->playingStream_.push_back(std::make_pair(1, stream2)); + testPtr_->ReorderStream(); + EXPECT_EQ(testPtr_->playingStream_.size(), 2); +} + +/** + * @tc.name : Test SetFrameWriteCallback + * @tc.number: ParallelStreamManagerSetFrameWriteCallback_001 + * @tc.desc : Test all + */ +HWTEST_F(ParallelStreamManagerTest, ParallelStreamManagerSetFrameWriteCallback_001, TestSize.Level0) +{ + ASSERT_NE(testPtr_, nullptr); + auto frameWriteCallback = std::make_shared(); + std::shared_ptr callback = frameWriteCallback; + auto ret = testPtr_->SetFrameWriteCallback(callback); + EXPECT_EQ(ret, MSERR_OK); +} +} // namespace Media +} // namespace OHOS diff --git a/test/unittest/soundpool_unittest/parallel_stream_manager_test.h b/test/unittest/soundpool_unittest/parallel_stream_manager_test.h new file mode 100644 index 0000000000000000000000000000000000000000..bbfe9206c00597172211e9ef677244eed7080690 --- /dev/null +++ b/test/unittest/soundpool_unittest/parallel_stream_manager_test.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 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 PARALL_STREAM_MANAGER_TEST_H +#define PARALL_STREAM_MANAGER_TEST_H +#include +#include +#include "parallel_stream_manager.h" + +namespace OHOS { +namespace Media { +class ParallelStreamManagerTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + std::shared_ptr testPtr_; +}; +class MockISoundPoolFrameWriteCallback : public ISoundPoolFrameWriteCallback { + MOCK_METHOD(void, OnFirstAudioFrameWritingCallback, (uint64_t &latency), ()); +}; +} // namespace Media +} // namespace OHOS + +#endif // AUDIO_RENDERER_MANAGER_UNIT_TEST_H diff --git a/test/unittest/soundpool_unittest/sound_id_manager_unittest.cpp b/test/unittest/soundpool_unittest/sound_id_manager_unittest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..feac2e550be7155c46f19e5cc4a5c6eb69992a12 --- /dev/null +++ b/test/unittest/soundpool_unittest/sound_id_manager_unittest.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2025 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 "sound_id_manager_unittest.h" +#include "media_errors.h" +#include "sound_id_manager.h" + +using namespace OHOS; +using namespace OHOS::Media; +using namespace testing; +using namespace testing::ext; +using namespace std; + +namespace OHOS { +namespace Media { +static const int32_t ID_TEST = 10; +static const int32_t NUM_TEST = 1; +static const int32_t LENGTH_TEST = 10; +static const int32_t MAX_NUM = 33; +static const int32_t MSERR_INVALID = -1; +void SoundIDManagerUnittest::SetUpTestCase(void) +{} + +void SoundIDManagerUnittest::TearDownTestCase(void) +{} + +void SoundIDManagerUnittest::SetUp(void) +{ + AudioStandard::AudioRendererInfo audioRenderInfo; + audioRenderInfo.contentType = AudioStandard::CONTENT_TYPE_MUSIC; + audioRenderInfo.streamUsage = AudioStandard::STREAM_USAGE_MUSIC; + audioRenderInfo.rendererFlags = 0; + soundIDManager_ = std::make_shared(); +} + +void SoundIDManagerUnittest::TearDown(void) +{ + soundIDManager_ = nullptr; +} + +/** + * @tc.name : Test Load + * @tc.number: SoundIdLoad_001 + * @tc.desc : Test apiVersion > 0 && apiVersion < SOUNDPOOL_API_VERSION_ISOLATION + */ +HWTEST_F(SoundIDManagerUnittest, SoundIdLoad_001, TestSize.Level0) +{ + int32_t fd = ID_TEST; + int64_t offset = 0; + int64_t length = LENGTH_TEST; + int32_t apiVersion = NUM_TEST; + for (int32_t i = 0; i <= MAX_NUM; ++i) + { + soundIDManager_->soundParsers_[i] = nullptr; + } + EXPECT_EQ(MSERR_INVALID, soundIDManager_->Load(fd, offset, length, apiVersion)); +} + +/** + * @tc.name : Test Load + * @tc.number: SoundIdLoad_002 + * @tc.desc : Test apiVersion > 0 && apiVersion < SOUNDPOOL_API_VERSION_ISOLATION + */ +HWTEST_F(SoundIDManagerUnittest, SoundIdLoad_002, TestSize.Level0) +{ + std::string testUrl = "testUri"; + int32_t apiVersion = NUM_TEST; + soundIDManager_->soundParsers_[0] = nullptr; + EXPECT_EQ(MSERR_INVALID, soundIDManager_->Load(testUrl, apiVersion)); +} +} // namespace Media +} // namespace OHOS diff --git a/test/unittest/soundpool_unittest/sound_id_manager_unittest.h b/test/unittest/soundpool_unittest/sound_id_manager_unittest.h new file mode 100644 index 0000000000000000000000000000000000000000..4e82306b34dfa11297419187f3e3c7195cd5812e --- /dev/null +++ b/test/unittest/soundpool_unittest/sound_id_manager_unittest.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2025 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 SOUNDIDMANAGER_UNITTEST_H +#define SOUNDIDMANAGER_UNITTEST_H + +#include "gtest/gtest.h" +#include "sound_id_manager.h" + +namespace OHOS { +namespace Media { +class SoundIDManagerUnittest : public testing::Test { +public: + // SetUpTestCase: Called before all test cases + static void SetUpTestCase(void); + // TearDownTestCase: Called after all test case + static void TearDownTestCase(void); + // SetUp: Called before each test cases + void SetUp(void); + // TearDown: Called after each test cases + void TearDown(void); + +protected: + std::shared_ptr soundIDManager_ = nullptr; +}; +} // namespace Media +} // namespace OHOS +#endif diff --git a/test/unittest/soundpool_unittest/soundpool_unittest.cpp b/test/unittest/soundpool_unittest/soundpool_unittest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bb51faa342f5fd5697745f0c39374dec7530a834 --- /dev/null +++ b/test/unittest/soundpool_unittest/soundpool_unittest.cpp @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2025 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 "soundpool_unittest.h" +#include "media_errors.h" +#include "soundpool_manager_multi.h" + +using namespace OHOS; +using namespace OHOS::Media; +using namespace testing; +using namespace testing::ext; +using namespace std; + +namespace OHOS { +namespace Media { +static const int32_t ID_TEST = 0; +static const int32_t NUM_TEST = 1; +static const int32_t MSERR_INVALID = -1; +static const int32_t SOUNDPOOL_INSTANCE_MAX_NUM = 128; +void SoundPoolUnittest::SetUpTestCase(void) +{} + +void SoundPoolUnittest::TearDownTestCase(void) +{} + +void SoundPoolUnittest::SetUp(void) +{ + soundPool_ = std::make_shared(); +} + +void SoundPoolUnittest::TearDown(void) +{ + soundPool_ = nullptr; +} + +/** + * @tc.name : Test CheckInitParam + * @tc.number: CheckInitParam_001 + * @tc.desc : Test Return false + */ +HWTEST_F(SoundPoolUnittest, CheckInitParam_001, TestSize.Level0) +{ + ASSERT_NE(soundPool_, nullptr); + int maxStreams = NUM_TEST; + AudioStandard::AudioRendererInfo audioRenderInfo; + audioRenderInfo.rendererFlags = -1; + auto ret = SoundPool::CheckInitParam(maxStreams, audioRenderInfo); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name : Test Play + * @tc.number: Play_001 + * @tc.desc : Test return -1 + */ +HWTEST_F(SoundPoolUnittest, Play_001, TestSize.Level0) +{ + ASSERT_NE(soundPool_, nullptr); + std::shared_ptr testPtr = std::make_shared(1, "testurl"); + soundPool_->soundIDManager_ = std::make_shared(); + int32_t soundID = ID_TEST; + PlayParams playParameters; + auto ret = soundPool_->Play(soundID, playParameters); + EXPECT_EQ(ret, MSERR_INVALID); +} + +/** + * @tc.name : Test SetPriority + * @tc.number: SetPriority_001 + * @tc.desc : Test return MSERR_INVALID_OPERATION + */ +HWTEST_F(SoundPoolUnittest, SetPriority_001, TestSize.Level0) +{ + ASSERT_NE(soundPool_, nullptr); + int32_t streamID = ID_TEST; + int32_t priority = NUM_TEST; + soundPool_->parallelStreamFlag_ = true; + int32_t maxStreams = NUM_TEST; + AudioStandard::AudioRendererInfo audioRenderInfo; + soundPool_->parallelStreamManager_ = std::make_shared(maxStreams, audioRenderInfo); + auto ret = soundPool_->SetPriority(streamID, priority); + EXPECT_EQ(ret, MSERR_INVALID_OPERATION); +} + +/** + * @tc.name : Test SetRate + * @tc.number: SetRate_001 + * @tc.desc : Test return MSERR_INVALID_OPERATION + */ +HWTEST_F(SoundPoolUnittest, SetRate_001, TestSize.Level0) +{ + ASSERT_NE(soundPool_, nullptr); + int32_t streamID = ID_TEST; + soundPool_->parallelStreamFlag_ = true; + int32_t maxStreams = NUM_TEST; + AudioStandard::AudioRendererInfo audioRenderInfo; + AudioStandard::AudioRendererRate renderRate = AudioStandard::AudioRendererRate::RENDER_RATE_NORMAL; + soundPool_->parallelStreamManager_ = std::make_shared(maxStreams, audioRenderInfo); + auto ret = soundPool_->SetRate(streamID, renderRate); + EXPECT_EQ(ret, MSERR_INVALID_OPERATION); +} + +/** + * @tc.name : Test ReleaseInner + * @tc.number: ReleaseInner_001 + * @tc.desc : Test return MSERR_OK + */ +HWTEST_F(SoundPoolUnittest, ReleaseInner_001, TestSize.Level0) +{ + ASSERT_NE(soundPool_, nullptr); + soundPool_->apiVersion_ = NUM_TEST; + soundPool_->parallelStreamFlag_ = false; + auto ret = soundPool_->ReleaseInner(); + EXPECT_EQ(ret, MSERR_OK); +} + +/** + * @tc.name : Test SetSoundPoolFrameWriteCallback + * @tc.number: SetSoundPoolFrameWriteCallback_001 + * @tc.desc : Test return MSERR_OK + */ +HWTEST_F(SoundPoolUnittest, SetSoundPoolFrameWriteCallback_001, TestSize.Level0) +{ + ASSERT_NE(soundPool_, nullptr); + AudioStandard::AudioRendererInfo audioRenderInfo; + std::shared_ptr frameWriteCallback; + soundPool_->parallelStreamManager_ = std::make_shared(1, audioRenderInfo); + auto ret = soundPool_->SetSoundPoolFrameWriteCallback(frameWriteCallback); + EXPECT_EQ(ret, MSERR_OK); +} + +/** + * @tc.name : Test GetSoundPoolInstance + * @tc.number: GetSoundPoolInstance_001 + * @tc.desc : Test return MSERR_INVALID_OPERATION + */ +HWTEST_F(SoundPoolUnittest, GetSoundPoolInstance_001, TestSize.Level0) +{ + auto soundPoolManagerMulti = std::make_shared(); + ASSERT_NE(soundPoolManagerMulti, nullptr); + std::shared_ptr soundPool; + for (int i = 0; i < (SOUNDPOOL_INSTANCE_MAX_NUM + 1); ++i) + { + soundPoolManagerMulti->soundPools_.push_back(soundPool); + } + auto ret = soundPoolManagerMulti->GetSoundPoolInstance(soundPool); + EXPECT_EQ(ret, MSERR_INVALID_OPERATION); +} +} // namespace Media +} // namespace OHOS diff --git a/test/unittest/soundpool_unittest/soundpool_unittest.h b/test/unittest/soundpool_unittest/soundpool_unittest.h new file mode 100644 index 0000000000000000000000000000000000000000..8962cf03200f2980d2905fcfcb475693964c5401 --- /dev/null +++ b/test/unittest/soundpool_unittest/soundpool_unittest.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2025 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 SOUNDPOOL_UNITTEST_H +#define SOUNDPOOL_UNITTEST_H + +#include "gtest/gtest.h" +#include +#include "soundpool.h" + +namespace OHOS { +namespace Media { +class SoundPoolUnittest : public testing::Test { +public: + // SetUpTestCase: Called before all test cases + static void SetUpTestCase(void); + // TearDownTestCase: Called after all test case + static void TearDownTestCase(void); + // SetUp: Called before each test cases + void SetUp(void); + // TearDown: Called after each test cases + void TearDown(void); + +protected: + std::shared_ptr soundPool_ = nullptr; +}; +} // namespace Media +} // namespace OHOS +#endif diff --git a/test/unittest/soundpool_unittest/stream_unittest.cpp b/test/unittest/soundpool_unittest/stream_unittest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..13a6461015c5a933c347b822dddfd516c067b402 --- /dev/null +++ b/test/unittest/soundpool_unittest/stream_unittest.cpp @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2025 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 "media_errors.h" +#include "stream_unittest.h" + +namespace OHOS { +namespace Media { +using namespace std; +using namespace testing; +using namespace testing::ext; +static const int32_t DEFAULT_NUM = 10; +static const int32_t MSERR_INVALID = -1; + +void SoundPoolStreamUnitTest::SetUpTestCase(void) +{ +} + +void SoundPoolStreamUnitTest::TearDownTestCase(void) +{ +} + +void SoundPoolStreamUnitTest::SetUp(void) +{ + Format trackFormat; + int32_t soundID = 1; + int32_t streamID = DEFAULT_NUM; + std::shared_ptr streamStopThreadPool; + stream_ = std::make_shared(trackFormat, soundID, streamID, streamStopThreadPool); +} + +void SoundPoolStreamUnitTest::TearDown(void) +{ + stream_ = nullptr; +} + +// @tc.name Test GetGlobalId API +// @tc.number StreamGetGlobalIdUnittest_001 +// @tc.desc Test return ERROE_GLOBAL_ID +HWTEST_F(SoundPoolStreamUnitTest, StreamGetGlobalIdUnittest_001, TestSize.Level0) +{ + ASSERT_NE(stream_, nullptr); + int32_t soundID = DEFAULT_NUM; + int32_t ret = stream_->GetGlobalId(soundID); + EXPECT_EQ(ret, MSERR_INVALID); +} + +// @tc.name Test IsAudioRendererCanMix API +// @tc.number StreamIsAudioRendererCanMixUnittest_001 +// @tc.desc Test return true +// Test return false +HWTEST_F(SoundPoolStreamUnitTest, StreamIsAudioRendererCanMixUnittest_001, TestSize.Level0) +{ + ASSERT_NE(stream_, nullptr); + AudioStandard::AudioRendererInfo audioRendererInfo; + audioRendererInfo.contentType = AudioStandard::ContentType::CONTENT_TYPE_PROMPT; + bool ret = false; + ret = stream_->IsAudioRendererCanMix(audioRendererInfo); + EXPECT_EQ(ret, true); + audioRendererInfo.streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_SYSTEM; + ret = stream_->IsAudioRendererCanMix(audioRendererInfo); + EXPECT_EQ(ret, false); +} + +// @tc.name Test OnInterrupt API +// @tc.number StreamOnInterruptUnittest_001 +// @tc.desc Test all +HWTEST_F(SoundPoolStreamUnitTest, StreamOnInterruptUnittest_001, TestSize.Level0) +{ + ASSERT_NE(stream_, nullptr); + AudioStandard::InterruptEvent interruptEvent; + interruptEvent.hintType = AudioStandard::InterruptHint::INTERRUPT_HINT_PAUSE; + stream_->OnInterrupt(interruptEvent); + EXPECT_EQ(stream_->startStopFlag_.load(), true); +} + +// @tc.name Test CheckAndAlignRendererRate API +// @tc.number StreamCheckAndAlignRendererRateUnittest_001 +// @tc.desc Test default +HWTEST_F(SoundPoolStreamUnitTest, StreamCheckAndAlignRendererRateUnittest_001, TestSize.Level0) +{ + ASSERT_NE(stream_, nullptr); + int32_t rate = DEFAULT_NUM; + AudioStandard::AudioRendererRate ret = stream_->CheckAndAlignRendererRate(rate); + EXPECT_EQ(ret, AudioStandard::AudioRendererRate::RENDER_RATE_NORMAL); +} + +// @tc.name Test CreateAudioRenderer API +// @tc.number StreamCreateAudioRendererUnittest_001 +// @tc.desc Test playParams.cacheDir != "" +HWTEST_F(SoundPoolStreamUnitTest, StreamCreateAudioRendererUnittest_001, TestSize.Level0) +{ + ASSERT_NE(stream_, nullptr); + AudioStandard::AudioRendererInfo audioRendererInfo; + PlayParams playParams; + playParams.cacheDir = "/data/test/cache/dir"; + auto ret = stream_->CreateAudioRenderer(audioRendererInfo, playParams); + EXPECT_EQ(ret, nullptr); +} + +// @tc.name Test DoPlay API +// @tc.number StreamDoPlayUnittest_001 +// @tc.desc Test fullCacheData_ == nullptr +// Test callback_ != nullptr, streamCallback_ != nullptr +HWTEST_F(SoundPoolStreamUnitTest, StreamDoPlayUnittest_001, TestSize.Level0) +{ + ASSERT_NE(stream_, nullptr); + auto audioRenderer = std::make_unique(); + EXPECT_CALL(*(audioRenderer), GetBufferSize(_)).WillRepeatedly(testing::Return(0)); + EXPECT_CALL(*(audioRenderer), SetRenderMode(_)).WillRepeatedly(testing::Return(0)); + EXPECT_CALL(*(audioRenderer), SetRenderRate(_)).WillRepeatedly(testing::Return(0)); + EXPECT_CALL(*(audioRenderer), SetVolume(_)).WillRepeatedly(testing::Return(0)); + EXPECT_CALL(*(audioRenderer), SetOffloadAllowed(_)).WillRepeatedly(testing::Return(0)); + EXPECT_CALL(*(audioRenderer), SetRendererCallback(_)).WillRepeatedly(testing::Return(0)); + EXPECT_CALL(*(audioRenderer), SetRendererWriteCallback(_)).WillRepeatedly(testing::Return(0)); + EXPECT_CALL(*(audioRenderer), SetRendererFirstFrameWritingCallback(_)).WillRepeatedly(testing::Return(0)); + EXPECT_CALL(*(audioRenderer), SetParallelPlayFlag(_)).WillRepeatedly(testing::Return(0)); + stream_->audioRenderer_ = std::move(audioRenderer); + auto callback = std::make_shared(); + EXPECT_CALL(*callback, OnError(_)).WillRepeatedly(testing::Return()); + stream_->callback_ = callback; + auto streamCallback = std::make_shared(); + EXPECT_CALL(*streamCallback, OnError(_)).WillRepeatedly(testing::Return()); + stream_->streamCallback_ = streamCallback; + auto ret = stream_->DoPlay(); + stream_->audioRenderer_ = nullptr; + EXPECT_EQ(ret, MSERR_INVALID_VAL); +} + +// @tc.name Test DoPlay API +// @tc.number StreamDoPlayUnittest_002 +// @tc.desc Test audioRenderer_->Start() == false +// Test callback_ != nullptr, streamCallback_ != nullptr +HWTEST_F(SoundPoolStreamUnitTest, StreamDoPlayUnittest_002, TestSize.Level0) +{ + ASSERT_NE(stream_, nullptr); + auto audioRenderer = std::make_unique(); + EXPECT_CALL(*(audioRenderer), GetBufferSize(_)).WillRepeatedly(testing::Return(0)); + EXPECT_CALL(*(audioRenderer), SetRenderMode(_)).WillRepeatedly(testing::Return(0)); + EXPECT_CALL(*(audioRenderer), SetRenderRate(_)).WillRepeatedly(testing::Return(0)); + EXPECT_CALL(*(audioRenderer), SetVolume(_)).WillRepeatedly(testing::Return(0)); + EXPECT_CALL(*(audioRenderer), SetOffloadAllowed(_)).WillRepeatedly(testing::Return(0)); + EXPECT_CALL(*(audioRenderer), SetRendererCallback(_)).WillRepeatedly(testing::Return(0)); + EXPECT_CALL(*(audioRenderer), SetRendererWriteCallback(_)).WillRepeatedly(testing::Return(0)); + EXPECT_CALL(*(audioRenderer), SetRendererFirstFrameWritingCallback(_)).WillRepeatedly(testing::Return(0)); + EXPECT_CALL(*(audioRenderer), SetParallelPlayFlag(_)).WillRepeatedly(testing::Return(0)); + stream_->audioRenderer_ = std::move(audioRenderer); + auto callback = std::make_shared(); + EXPECT_CALL(*callback, OnError(_)).WillRepeatedly(testing::Return()); + stream_->callback_ = callback; + auto streamCallback = std::make_shared(); + EXPECT_CALL(*streamCallback, OnError(_)).WillRepeatedly(testing::Return()); + EXPECT_CALL(*streamCallback, OnPlayFinished(_)).WillRepeatedly(testing::Return()); + stream_->streamCallback_ = streamCallback; + auto ret = stream_->DoPlay(); + stream_->audioRenderer_ = nullptr; + EXPECT_EQ(ret, MSERR_INVALID_VAL); +} + +// @tc.name Test Stop API +// @tc.number StreamStopUnittest_001 +// @tc.desc Test (audioRenderer_->IsFastRenderer()) == true +HWTEST_F(SoundPoolStreamUnitTest, StreamStopUnittest_001, TestSize.Level0) +{ + ASSERT_NE(stream_, nullptr); + stream_->isRunning_.store(true); + stream_->audioRenderer_ = std::make_unique(); + auto callBack = std::make_shared(); + EXPECT_CALL(*callBack, OnPlayFinished(_)).WillRepeatedly(testing::Return()); + stream_->callback_ = callBack; + auto audioRenderer = std::make_unique(); + EXPECT_CALL(*audioRenderer, IsFastRenderer()).WillRepeatedly(testing::Return(true)); + EXPECT_CALL(*audioRenderer, Pause(_)).WillRepeatedly(testing::Return(false)); + EXPECT_CALL(*audioRenderer, Flush()).WillRepeatedly(testing::Return(false)); + stream_->audioRenderer_ = std::move(audioRenderer); + auto ret = stream_->Stop(); + EXPECT_EQ(ret, MSERR_OK); +} + +// @tc.name Test AddStopTask API +// @tc.number StreamAddStopTaskUnittest_001 +// @tc.desc Test streamStopThreadPool_ = nullptr +HWTEST_F(SoundPoolStreamUnitTest, StreamAddStopTaskUnittest_001, TestSize.Level0) +{ + ASSERT_NE(stream_, nullptr); + stream_->streamCallback_ = nullptr; + auto audioRenderer = std::make_unique(); + EXPECT_CALL(*audioRenderer, IsFastRenderer()).WillRepeatedly(testing::Return(true)); + stream_->audioRenderer_ = std::move(audioRenderer); + stream_->AddStopTask(); + EXPECT_EQ(stream_->startStopFlag_.load(), true); +} +} // namespace Media +} // namespace OHOS diff --git a/test/unittest/soundpool_unittest/stream_unittest.h b/test/unittest/soundpool_unittest/stream_unittest.h new file mode 100644 index 0000000000000000000000000000000000000000..d463a08394bc1748a16d81a09818e5be52ea2f40 --- /dev/null +++ b/test/unittest/soundpool_unittest/stream_unittest.h @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2025 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 SOUNDPOOL_STREAM_UNITTEST_H +#define SOUNDPOOL_STREAM_UNITTEST_H + +#include "gtest/gtest.h" +#include "stream.h" +#include + +namespace OHOS { +namespace Media { +class SoundPoolStreamUnitTest : public testing::Test { +public: + // SetUpTestCase: Called before all test cases + static void SetUpTestCase(void); + // TearDownTestCase: Called after all test case + static void TearDownTestCase(void); + // SetUp: Called before each test cases + void SetUp(void); + // TearDown: Called after each test cases + void TearDown(void); + + std::shared_ptr stream_; +}; +class MockISoundPoolCallback : public ISoundPoolCallback { +public: + MOCK_METHOD(void, OnLoadCompleted, (int32_t soundId), ()); + MOCK_METHOD(void, OnPlayFinished, (int32_t streamID), ()); + MOCK_METHOD(void, OnError, (int32_t errorCode), ()); +}; +class MockAudioRenderer : public AudioStandard::AudioRenderer { +public: + MOCK_METHOD(void, SetAudioPrivacyType, (AudioStandard::AudioPrivacyType privacyType), (override)); + MOCK_METHOD(AudioStandard::AudioPrivacyType, GetAudioPrivacyType, (), (override)); + MOCK_METHOD(int32_t, SetParams, (const AudioStandard::AudioRendererParams params), (override)); + MOCK_METHOD(int32_t, SetRendererCallback, + (const std::shared_ptr &callback), (override)); + MOCK_METHOD(int32_t, GetParams, (AudioStandard::AudioRendererParams ¶ms), (const, override)); + MOCK_METHOD(int32_t, GetRendererInfo, (AudioStandard::AudioRendererInfo &rendererInfo), (const, override)); + MOCK_METHOD(int32_t, GetStreamInfo, (AudioStandard::AudioStreamInfo &streamInfo), (const, override)); + MOCK_METHOD(bool, Start, (AudioStandard::StateChangeCmdType cmdType), (override)); + MOCK_METHOD(int32_t, Write, (uint8_t *buffer, size_t bufferSize), (override)); + MOCK_METHOD(int32_t, Write, + (uint8_t *pcmBuffer, size_t pcmBufferSize, uint8_t *metaBuffer, size_t metaBufferSize), (override)); + MOCK_METHOD(AudioStandard::RendererState, GetStatus, (), (const, override)); + MOCK_METHOD(bool, GetAudioTime, + (AudioStandard::Timestamp ×tamp, AudioStandard::Timestamp::Timestampbase base), (const, override)); + MOCK_METHOD(bool, GetAudioPosition, + (AudioStandard::Timestamp ×tamp, AudioStandard::Timestamp::Timestampbase base), (override)); + MOCK_METHOD(int32_t, GetLatency, (uint64_t &latency), (const, override)); + MOCK_METHOD(bool, Drain, (), (const, override)); + MOCK_METHOD(bool, Flush, (), (const, override)); + MOCK_METHOD(bool, PauseTransitent, (AudioStandard::StateChangeCmdType cmdType), (override)); + MOCK_METHOD(bool, Pause, (AudioStandard::StateChangeCmdType cmdType), (override)); + MOCK_METHOD(bool, Stop, (), (override)); + MOCK_METHOD(int32_t, GetBufferSize, (size_t &bufferSize), (const, override)); + MOCK_METHOD(int32_t, GetAudioStreamId, (uint32_t &sessionID), (const, override)); + MOCK_METHOD(int32_t, GetFrameCount, (uint32_t &frameCount), (const, override)); + MOCK_METHOD(int32_t, SetAudioRendererDesc, (AudioStandard::AudioRendererDesc audioRendererDesc), (override)); + MOCK_METHOD(int32_t, SetStreamType, (AudioStandard::AudioStreamType audioStreamType), (override)); + MOCK_METHOD(int32_t, SetVolume, (float volume), (const, override)); + MOCK_METHOD(int32_t, SetVolumeMode, (int32_t mode), (override)); + MOCK_METHOD(float, GetVolume, (), (const, override)); + MOCK_METHOD(int32_t, SetRenderRate, (AudioStandard::AudioRendererRate renderRate), (const, override)); + MOCK_METHOD(AudioStandard::AudioRendererRate, GetRenderRate, (), (const, override)); + MOCK_METHOD(int32_t, SetRendererSamplingRate, (uint32_t sampleRate), (const, override)); + MOCK_METHOD(uint32_t, GetRendererSamplingRate, (), (const, override)); + MOCK_METHOD(int32_t, SetRendererPositionCallback, (int64_t markPosition, + const std::shared_ptr &callback), (override)); + MOCK_METHOD(void, UnsetRendererPositionCallback, (), (override)); + MOCK_METHOD(void, SetPreferredFrameSize, (int32_t frameSize), (override)); + MOCK_METHOD(int32_t, SetRendererPeriodPositionCallback, (int64_t frameNumber, + const std::shared_ptr &callback), (override)); + MOCK_METHOD(void, UnsetRendererPeriodPositionCallback, (), (override)); + MOCK_METHOD(int32_t, SetBufferDuration, (uint64_t bufferDuration), (const, override)); + MOCK_METHOD(int32_t, SetRenderMode, (AudioStandard::AudioRenderMode renderMode), (override)); + MOCK_METHOD(AudioStandard::AudioRenderMode, GetRenderMode, (), (const, override)); + MOCK_METHOD(int32_t, SetRendererWriteCallback, + (const std::shared_ptr &callback), (override)); + MOCK_METHOD(int32_t, SetRendererFirstFrameWritingCallback, + (const std::shared_ptr &callback), (override)); + MOCK_METHOD(int32_t, GetBufferDesc, (AudioStandard::BufferDesc &bufDesc), (override)); + MOCK_METHOD(int32_t, Enqueue, (const AudioStandard::BufferDesc &bufDesc), (override)); + MOCK_METHOD(int32_t, Clear, (), (const, override)); + MOCK_METHOD(int32_t, GetBufQueueState, (AudioStandard::BufferQueueState &bufState), (const, override)); + MOCK_METHOD(void, SetInterruptMode, (AudioStandard::InterruptMode mode), (override)); + MOCK_METHOD(int32_t, SetParallelPlayFlag, (bool parallelPlayFlag), (override)); + MOCK_METHOD(int32_t, SetLowPowerVolume, (float volume), (const, override)); + MOCK_METHOD(float, GetLowPowerVolume, (), (const, override)); + MOCK_METHOD(int32_t, SetOffloadAllowed, (bool isAllowed), (override)); + MOCK_METHOD(int32_t, SetOffloadMode, (int32_t state, bool isAppBack), (const, override)); + MOCK_METHOD(int32_t, UnsetOffloadMode, (), (const, override)); + MOCK_METHOD(float, GetSingleStreamVolume, (), (const, override)); + MOCK_METHOD(float, GetMinStreamVolume, (), (const, override)); + MOCK_METHOD(float, GetMaxStreamVolume, (), (const, override)); + MOCK_METHOD(uint32_t, GetUnderflowCount, (), (const, override)); + MOCK_METHOD(int32_t, GetCurrentOutputDevices, (AudioStandard::AudioDeviceDescriptor &deviceInfo), + (const, override)); + MOCK_METHOD(AudioStandard::AudioEffectMode, GetAudioEffectMode, (), (const, override)); + MOCK_METHOD(int64_t, GetFramesWritten, (), (const, override)); + MOCK_METHOD(int32_t, SetAudioEffectMode, (AudioStandard::AudioEffectMode effectMode), (const, override)); + MOCK_METHOD(void, SetAudioRendererErrorCallback, + (std::shared_ptr errorCallback), (override)); + MOCK_METHOD(int32_t, RegisterOutputDeviceChangeWithInfoCallback, + (const std::shared_ptr &callback), (override)); + MOCK_METHOD(int32_t, UnregisterOutputDeviceChangeWithInfoCallback, + (const std::shared_ptr &callback), (override)); + MOCK_METHOD(int32_t, UnregisterOutputDeviceChangeWithInfoCallback, (), (override)); + MOCK_METHOD(int32_t, RegisterAudioPolicyServerDiedCb, (const int32_t clientPid, + const std::shared_ptr &callback), (override)); + MOCK_METHOD(int32_t, UnregisterAudioPolicyServerDiedCb, (const int32_t clientPid), (override)); + MOCK_METHOD(int32_t, SetChannelBlendMode, (AudioStandard::ChannelBlendMode blendMode), (override)); + MOCK_METHOD(int32_t, SetVolumeWithRamp, (float volume, int32_t duration), (override)); + MOCK_METHOD(int32_t, SetSpeed, (float speed), (override)); + MOCK_METHOD(int32_t, SetPitch, (float pitch), ()); + MOCK_METHOD(float, GetSpeed, (), (override)); + MOCK_METHOD(bool, IsFastRenderer, (), (override)); + MOCK_METHOD(void, SetSilentModeAndMixWithOthers, (bool on), (override)); + MOCK_METHOD(bool, GetSilentModeAndMixWithOthers, (), (override)); + MOCK_METHOD(void, EnableVoiceModemCommunicationStartStream, (bool enable), (override)); + MOCK_METHOD(bool, IsNoStreamRenderer, (), (const, override)); + MOCK_METHOD(int32_t, GetAudioTimestampInfo, + (AudioStandard::Timestamp ×tamp, AudioStandard::Timestamp::Timestampbase base), (const, override)); + MOCK_METHOD(bool, Release, (), (override)); + MOCK_METHOD(void, SetFastStatusChangeCallback, + (const std::shared_ptr& callback), + (override)); +}; +} // namespace Media +} // namespace OHOS +#endif // SOUNDPOOL_STREAM_UNITTEST_H diff --git a/test/unittest/timeout_test/mock/mock_i_media_service.h b/test/unittest/timeout_test/mock/mock_i_media_service.h index 1f9d2f2bb3971229d346ff3e891b8eec3a976958..ec35626fbcd0a1ea11ac0a300adf9f1eb25cfc5f 100644 --- a/test/unittest/timeout_test/mock/mock_i_media_service.h +++ b/test/unittest/timeout_test/mock/mock_i_media_service.h @@ -64,6 +64,9 @@ public: MOCK_METHOD(sptr, GetMonitorProxy, (), (override)); MOCK_METHOD(void, ReleaseClientListener, (), (override)); MOCK_METHOD(bool, CanKillMediaService, (), (override)); + MOCK_METHOD(std::vector, GetPlayerPids, (), (override)); + MOCK_METHOD(int32_t, ProxyForFreeze, (const std::set& pidList, bool isProxy), (override)); + MOCK_METHOD(int32_t, ResetAllProxy, (), (override)); }; } // namespace Media } // namespace OHOS diff --git a/test/unittest/timeout_test/mock/mock_i_player_service.h b/test/unittest/timeout_test/mock/mock_i_player_service.h index 14d11816acbca50a3f4785dbedc58796be5ef953..7c062018b483eac9a4154e809bb9411a5996bbf9 100644 --- a/test/unittest/timeout_test/mock/mock_i_player_service.h +++ b/test/unittest/timeout_test/mock/mock_i_player_service.h @@ -32,6 +32,9 @@ public: MOCK_METHOD(int32_t, AddSubSource, (const std::string &url), (override)); MOCK_METHOD(int32_t, AddSubSource, (int32_t fd, int64_t offset, int64_t size), (override)); MOCK_METHOD(int32_t, Play, (), (override)); + MOCK_METHOD(int32_t, Freeze, (), (override)); + MOCK_METHOD(int32_t, UnFreeze, (), (override)); + MOCK_METHOD(int32_t, EnableReportAudioInterrupt, (bool enable), (override)); MOCK_METHOD(int32_t, Prepare, (), (override)); MOCK_METHOD(int32_t, SetRenderFirstFrame, (bool display), (override)); MOCK_METHOD(int32_t, SetPlayRange, (int64_t start, int64_t end), (override)); diff --git a/test/unittest/transcoder_server/transcoder_server_unit_test.cpp b/test/unittest/transcoder_server/transcoder_server_unit_test.cpp index 6c5e35f765a4b8ebbb990598bf4c61c36889119c..cec80c6a5bf872a5d9bd8ee3c85199d9fcb4c207 100644 --- a/test/unittest/transcoder_server/transcoder_server_unit_test.cpp +++ b/test/unittest/transcoder_server/transcoder_server_unit_test.cpp @@ -273,6 +273,296 @@ HWTEST_F(TransCoderUnitTest, transcoder_AudioVideo_001, TestSize.Level2) close(srcFd); } +/** + * @tc.name: transcoder_SetColorSpace_001 + * @tc.desc: transcode ChineseColor_H264_AAC_480p_15fps.mp4 with different color space settings + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(TransCoderUnitTest, transcoder_SetColorSpace_001, TestSize.Level2) +{ + int32_t srcFd = open((TRANSCODER_ROOT_SRC + "ChineseColor_H264_AAC_480p_15fps.mp4").c_str(), O_RDWR); + ASSERT_TRUE(srcFd >= 0); + int64_t offset = TRANSCODER_FILE_OFFSET; + int64_t size = TRANSCODER_FILE_SIZE; + EXPECT_EQ(MSERR_OK, transcoder_->SetInputFile(srcFd, offset, size)); + int32_t dstFd = open((TRANSCODER_ROOT_DST + "ChineseColor_H264_AAC_480p_15fps_dst.mp4").c_str(), O_RDWR); + ASSERT_TRUE(dstFd >= 0); + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFile(dstFd)); + std::shared_ptr cb = std::make_shared(); + EXPECT_EQ(MSERR_OK, transcoder_->SetTransCoderCallback(cb)); + OutputFormatType format = FORMAT_MPEG_4; + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFormat(format)); + TranscoderColorSpace colorSpaceFmt = TRANSCODER_COLORSPACE_BT709_LIMIT; + EXPECT_EQ(MSERR_OK, transcoder_->SetColorSpace(colorSpaceFmt)); + int32_t videoWidth = -1; + int32_t videoHeight = -1; + if (access(VPE_LIB_PATH.c_str(), F_OK) == 0) { + videoWidth = TRANSCODER_BUFFER_WIDTH; + videoHeight = TRANSCODER_BUFFER_HEIGHT; + } else { + videoWidth = TRANSCODER_BUFFER_WIDTH_480P; + videoHeight = TRANSCODER_BUFFER_HEIGHT_480P; + } + EXPECT_EQ(MSERR_OK, transcoder_->SetVideoSize(videoWidth, videoHeight)); + + EXPECT_EQ(MSERR_OK, transcoder_->Prepare()); + EXPECT_EQ(MSERR_OK, transcoder_->Start()); + EXPECT_EQ(MSERR_OK, transcoder_->Cancel()); + EXPECT_EQ(MSERR_OK, transcoder_->Release()); + close(dstFd); + close(srcFd); +} + +/** + * @tc.name: transcoder_SetColorSpace_002 + * @tc.desc: transcode ChineseColor_H264_AAC_480p_15fps.mp4 with different color space settings + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(TransCoderUnitTest, transcoder_SetColorSpace_002, TestSize.Level2) +{ + int32_t srcFd = open((TRANSCODER_ROOT_SRC + "ChineseColor_H264_AAC_480p_15fps.mp4").c_str(), O_RDWR); + ASSERT_TRUE(srcFd >= 0); + int64_t offset = TRANSCODER_FILE_OFFSET; + int64_t size = TRANSCODER_FILE_SIZE; + EXPECT_EQ(MSERR_OK, transcoder_->SetInputFile(srcFd, offset, size)); + int32_t dstFd = open((TRANSCODER_ROOT_DST + "ChineseColor_H264_AAC_480p_15fps_dst.mp4").c_str(), O_RDWR); + ASSERT_TRUE(dstFd >= 0); + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFile(dstFd)); + std::shared_ptr cb = std::make_shared(); + EXPECT_EQ(MSERR_OK, transcoder_->SetTransCoderCallback(cb)); + OutputFormatType format = FORMAT_MPEG_4; + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFormat(format)); + TranscoderColorSpace colorSpaceFmt = TRANSCODER_COLORSPACE_P3_FULL; + EXPECT_EQ(MSERR_OK, transcoder_->SetColorSpace(colorSpaceFmt)); + int32_t videoWidth = -1; + int32_t videoHeight = -1; + if (access(VPE_LIB_PATH.c_str(), F_OK) == 0) { + videoWidth = TRANSCODER_BUFFER_WIDTH; + videoHeight = TRANSCODER_BUFFER_HEIGHT; + } else { + videoWidth = TRANSCODER_BUFFER_WIDTH_480P; + videoHeight = TRANSCODER_BUFFER_HEIGHT_480P; + } + EXPECT_EQ(MSERR_OK, transcoder_->SetVideoSize(videoWidth, videoHeight)); + + EXPECT_EQ(MSERR_OK, transcoder_->Prepare()); + EXPECT_EQ(MSERR_OK, transcoder_->Start()); + EXPECT_EQ(MSERR_OK, transcoder_->Cancel()); + EXPECT_EQ(MSERR_OK, transcoder_->Release()); + close(dstFd); + close(srcFd); +} + +/** + * @tc.name: transcoder_SetColorSpace_003 + * @tc.desc: transcode ChineseColor_H264_AAC_480p_15fps.mp4 with different color space settings + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(TransCoderUnitTest, transcoder_SetColorSpace_003, TestSize.Level2) +{ + int32_t srcFd = open((TRANSCODER_ROOT_SRC + "ChineseColor_H264_AAC_480p_15fps.mp4").c_str(), O_RDWR); + ASSERT_TRUE(srcFd >= 0); + int64_t offset = TRANSCODER_FILE_OFFSET; + int64_t size = TRANSCODER_FILE_SIZE; + EXPECT_EQ(MSERR_OK, transcoder_->SetInputFile(srcFd, offset, size)); + int32_t dstFd = open((TRANSCODER_ROOT_DST + "ChineseColor_H264_AAC_480p_15fps_dst.mp4").c_str(), O_RDWR); + ASSERT_TRUE(dstFd >= 0); + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFile(dstFd)); + std::shared_ptr cb = std::make_shared(); + EXPECT_EQ(MSERR_OK, transcoder_->SetTransCoderCallback(cb)); + OutputFormatType format = FORMAT_MPEG_4; + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFormat(format)); + TranscoderColorSpace colorSpaceFmt = TRANSCODER_COLORSPACE_BT709_LIMIT; + EXPECT_EQ(MSERR_OK, transcoder_->SetColorSpace(colorSpaceFmt)); + int32_t videoWidth = TRANSCODER_BUFFER_WIDTH_480P; + int32_t videoHeight = TRANSCODER_BUFFER_HEIGHT_480P; + EXPECT_EQ(MSERR_OK, transcoder_->SetVideoSize(videoWidth, videoHeight)); + + EXPECT_EQ(MSERR_OK, transcoder_->Prepare()); + EXPECT_EQ(MSERR_OK, transcoder_->Start()); + EXPECT_EQ(MSERR_OK, transcoder_->Cancel()); + EXPECT_EQ(MSERR_OK, transcoder_->Release()); + close(dstFd); + close(srcFd); +} + +/** + * @tc.name: transcoder_SetColorSpace_004 + * @tc.desc: transcode ChineseColor_H264_AAC_480p_15fps.mp4 with different color space settings + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(TransCoderUnitTest, transcoder_SetColorSpace_004, TestSize.Level2) +{ + int32_t srcFd = open((TRANSCODER_ROOT_SRC + "ChineseColor_H264_AAC_480p_15fps.mp4").c_str(), O_RDWR); + ASSERT_TRUE(srcFd >= 0); + int64_t offset = TRANSCODER_FILE_OFFSET; + int64_t size = TRANSCODER_FILE_SIZE; + EXPECT_EQ(MSERR_OK, transcoder_->SetInputFile(srcFd, offset, size)); + int32_t dstFd = open((TRANSCODER_ROOT_DST + "ChineseColor_H264_AAC_480p_15fps_dst.mp4").c_str(), O_RDWR); + ASSERT_TRUE(dstFd >= 0); + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFile(dstFd)); + std::shared_ptr cb = std::make_shared(); + EXPECT_EQ(MSERR_OK, transcoder_->SetTransCoderCallback(cb)); + OutputFormatType format = FORMAT_MPEG_4; + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFormat(format)); + TranscoderColorSpace colorSpaceFmt = TRANSCODER_COLORSPACE_P3_FULL; + EXPECT_EQ(MSERR_OK, transcoder_->SetColorSpace(colorSpaceFmt)); + int32_t videoWidth = TRANSCODER_BUFFER_WIDTH_480P; + int32_t videoHeight = TRANSCODER_BUFFER_HEIGHT_480P; + EXPECT_EQ(MSERR_OK, transcoder_->SetVideoSize(videoWidth, videoHeight)); + + EXPECT_EQ(MSERR_OK, transcoder_->Prepare()); + EXPECT_EQ(MSERR_OK, transcoder_->Start()); + EXPECT_EQ(MSERR_OK, transcoder_->Cancel()); + EXPECT_EQ(MSERR_OK, transcoder_->Release()); + close(dstFd); + close(srcFd); +} + +/** + * @tc.name: transcoder_SetColorSpace_010 + * @tc.desc: transcode ChineseColor_H264_AAC_480p_15fps.mp4 with different color space settings + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(TransCoderUnitTest, transcoder_SetColorSpace_010, TestSize.Level2) +{ + int32_t srcFd = open((TRANSCODER_ROOT_SRC + "ChineseColor_H264_AAC_480p_15fps.mp4").c_str(), O_RDWR); + ASSERT_TRUE(srcFd >= 0); + int64_t offset = TRANSCODER_FILE_OFFSET; + int64_t size = TRANSCODER_FILE_SIZE; + EXPECT_EQ(MSERR_OK, transcoder_->SetInputFile(srcFd, offset, size)); + int32_t dstFd = open((TRANSCODER_ROOT_DST + "ChineseColor_H264_AAC_480p_15fps_dst.mp4").c_str(), O_RDWR); + ASSERT_TRUE(dstFd >= 0); + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFile(dstFd)); + OutputFormatType format = FORMAT_MPEG_4; + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFormat(format)); + TranscoderColorSpace colorSpaceFmt = TRANSCODER_COLORSPACE_NONE; + EXPECT_EQ(MSERR_INVALID_VAL, transcoder_->SetColorSpace(colorSpaceFmt)); + + EXPECT_EQ(MSERR_OK, transcoder_->Prepare()); + EXPECT_EQ(MSERR_OK, transcoder_->Start()); + EXPECT_EQ(MSERR_OK, transcoder_->Release()); + close(dstFd); + close(srcFd); +} + +/** + * @tc.name: transcoder_SetColorSpace_011 + * @tc.desc: transcode ChineseColor_H264_AAC_480p_15fps.mp4 with different color space settings + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(TransCoderUnitTest, transcoder_SetColorSpace_011, TestSize.Level2) +{ + int32_t srcFd = open((TRANSCODER_ROOT_SRC + "ChineseColor_H264_AAC_480p_15fps.mp4").c_str(), O_RDWR); + ASSERT_TRUE(srcFd >= 0); + int64_t offset = TRANSCODER_FILE_OFFSET; + int64_t size = TRANSCODER_FILE_SIZE; + EXPECT_EQ(MSERR_OK, transcoder_->SetInputFile(srcFd, offset, size)); + int32_t dstFd = open((TRANSCODER_ROOT_DST + "ChineseColor_H264_AAC_480p_15fps_dst.mp4").c_str(), O_RDWR); + ASSERT_TRUE(dstFd >= 0); + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFile(dstFd)); + OutputFormatType format = FORMAT_MPEG_4; + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFormat(format)); + TranscoderColorSpace colorSpaceFmt = TRANSCODER_COLORSPACE_BT601_EBU_FULL; + EXPECT_EQ(MSERR_OK, transcoder_->SetColorSpace(colorSpaceFmt)); + + EXPECT_EQ(MSERR_OK, transcoder_->Prepare()); + EXPECT_EQ(MSERR_OK, transcoder_->Start()); + EXPECT_EQ(MSERR_OK, transcoder_->Release()); + close(dstFd); + close(srcFd); +} + +/** + * @tc.name: transcoder_SetColorSpace_012 + * @tc.desc: transcode ChineseColor_H264_AAC_480p_15fps.mp4 with different color space settings + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(TransCoderUnitTest, transcoder_SetColorSpace_012, TestSize.Level2) +{ + int32_t srcFd = open((TRANSCODER_ROOT_SRC + "ChineseColor_H264_AAC_480p_15fps.mp4").c_str(), O_RDWR); + ASSERT_TRUE(srcFd >= 0); + int64_t offset = TRANSCODER_FILE_OFFSET; + int64_t size = TRANSCODER_FILE_SIZE; + EXPECT_EQ(MSERR_OK, transcoder_->SetInputFile(srcFd, offset, size)); + int32_t dstFd = open((TRANSCODER_ROOT_DST + "ChineseColor_H264_AAC_480p_15fps_dst.mp4").c_str(), O_RDWR); + ASSERT_TRUE(dstFd >= 0); + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFile(dstFd)); + OutputFormatType format = FORMAT_MPEG_4; + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFormat(format)); + TranscoderColorSpace colorSpaceFmt = TRANSCODER_COLORSPACE_BT601_SMPTE_C_FULL; + EXPECT_EQ(MSERR_OK, transcoder_->SetColorSpace(colorSpaceFmt)); + + EXPECT_EQ(MSERR_OK, transcoder_->Prepare()); + EXPECT_EQ(MSERR_OK, transcoder_->Start()); + EXPECT_EQ(MSERR_OK, transcoder_->Release()); + close(dstFd); + close(srcFd); +} + +/** + * @tc.name: transcoder_SetColorSpace_013 + * @tc.desc: transcode ChineseColor_H264_AAC_480p_15fps.mp4 with different color space settings + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(TransCoderUnitTest, transcoder_SetColorSpace_013, TestSize.Level2) +{ + int32_t srcFd = open((TRANSCODER_ROOT_SRC + "ChineseColor_H264_AAC_480p_15fps.mp4").c_str(), O_RDWR); + ASSERT_TRUE(srcFd >= 0); + int64_t offset = TRANSCODER_FILE_OFFSET; + int64_t size = TRANSCODER_FILE_SIZE; + EXPECT_EQ(MSERR_OK, transcoder_->SetInputFile(srcFd, offset, size)); + int32_t dstFd = open((TRANSCODER_ROOT_DST + "ChineseColor_H264_AAC_480p_15fps_dst.mp4").c_str(), O_RDWR); + ASSERT_TRUE(dstFd >= 0); + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFile(dstFd)); + OutputFormatType format = FORMAT_MPEG_4; + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFormat(format)); + TranscoderColorSpace colorSpaceFmt = TRANSCODER_COLORSPACE_BT709_FULL; + EXPECT_EQ(MSERR_OK, transcoder_->SetColorSpace(colorSpaceFmt)); + + EXPECT_EQ(MSERR_OK, transcoder_->Prepare()); + EXPECT_EQ(MSERR_OK, transcoder_->Start()); + EXPECT_EQ(MSERR_OK, transcoder_->Release()); + close(dstFd); + close(srcFd); +} + +/** + * @tc.name: transcoder_SetColorSpace_014 + * @tc.desc: transcode ChineseColor_H264_AAC_480p_15fps.mp4 with different color space settings + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(TransCoderUnitTest, transcoder_SetColorSpace_014, TestSize.Level2) +{ + int32_t srcFd = open((TRANSCODER_ROOT_SRC + "ChineseColor_H264_AAC_480p_15fps.mp4").c_str(), O_RDWR); + ASSERT_TRUE(srcFd >= 0); + int64_t offset = TRANSCODER_FILE_OFFSET; + int64_t size = TRANSCODER_FILE_SIZE; + EXPECT_EQ(MSERR_OK, transcoder_->SetInputFile(srcFd, offset, size)); + int32_t dstFd = open((TRANSCODER_ROOT_DST + "ChineseColor_H264_AAC_480p_15fps_dst.mp4").c_str(), O_RDWR); + ASSERT_TRUE(dstFd >= 0); + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFile(dstFd)); + OutputFormatType format = FORMAT_MPEG_4; + EXPECT_EQ(MSERR_OK, transcoder_->SetOutputFormat(format)); + TranscoderColorSpace colorSpaceFmt = TRANSCODER_COLORSPACE_P3_LIMIT; + EXPECT_EQ(MSERR_OK, transcoder_->SetColorSpace(colorSpaceFmt)); + + EXPECT_EQ(MSERR_OK, transcoder_->Prepare()); + EXPECT_EQ(MSERR_OK, transcoder_->Start()); + EXPECT_EQ(MSERR_OK, transcoder_->Release()); + close(dstFd); + close(srcFd); +} + /** * @tc.name: transcoder_AudioVideo_002 * @tc.desc: transcoder audio and video AVC_Baseline@L1.2_81.0Kbps_320x240.mp4 with codec format h264 pause and resume