diff --git a/adapter/ohos/osal/resource_adapter_impl.cpp b/adapter/ohos/osal/resource_adapter_impl.cpp index b640a9bb4fafc629787b37e21af672d99c00015a..932a6bbab9e935c243e5c4685cd654e3f4afd040 100644 --- a/adapter/ohos/osal/resource_adapter_impl.cpp +++ b/adapter/ohos/osal/resource_adapter_impl.cpp @@ -671,6 +671,18 @@ bool ResourceAdapterImpl::GetRawFileDescription( return true; } +bool ResourceAdapterImpl::CloseRawFileDescription(const std::string &rawfileName) const +{ + auto manager = GetResourceManager(); + CHECK_NULL_RETURN(manager, false); + auto state = manager->CloseRawFileDescriptor(rawfileName); + if (state != Global::Resource::SUCCESS) { + LOGE("Close RawFile Description error, rawfileName=%{public}s, error:%{public}u", rawfileName.c_str(), state); + return false; + } + return true; +} + bool ResourceAdapterImpl::GetMediaById(const int32_t& resId, std::string& mediaPath) const { auto manager = GetResourceManager(); diff --git a/adapter/ohos/osal/resource_adapter_impl.h b/adapter/ohos/osal/resource_adapter_impl.h index d00c1b93fc5bea936efa110f301196efbe80299f..899e68c5f26d8a943809a11bf779ee536458e0b8 100644 --- a/adapter/ohos/osal/resource_adapter_impl.h +++ b/adapter/ohos/osal/resource_adapter_impl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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,7 @@ public: const std::string& bundleName, const std::string& moduleName) override; void UpdateResourceManager(const std::string& bundleName, const std::string& moduleName) override; bool GetRawFileDescription(const std::string& rawfileName, RawfileDescription& rawfileDescription) const override; + bool CloseRawFileDescription(const std::string &rawfileName) const override; bool GetMediaById(const int32_t& resId, std::string& mediaPath) const override; uint32_t GetResourceLimitKeys() const override; uint32_t GetSymbolById(uint32_t resId) const override; diff --git a/frameworks/bridge/cj_frontend/interfaces/cj_ffi/cj_video_ffi.cpp b/frameworks/bridge/cj_frontend/interfaces/cj_ffi/cj_video_ffi.cpp index e7da0edfef1a7f87ca4932a3608a5cbe06be87ee..07d92acfdcff4ba9202c3610232e394a1fe0e0bb 100644 --- a/frameworks/bridge/cj_frontend/interfaces/cj_ffi/cj_video_ffi.cpp +++ b/frameworks/bridge/cj_frontend/interfaces/cj_ffi/cj_video_ffi.cpp @@ -81,7 +81,7 @@ void FfiOHOSAceFrameworkVideoCreate(const char* src, double progressRate, const auto controller = FFIData::GetData(controllerId); if (controller) { VideoModel::GetInstance()->Create(controller->GetController()); - VideoModel::GetInstance()->SetSrc(src); + VideoModel::GetInstance()->SetSrc(src, "", ""); VideoModel::GetInstance()->SetProgressRate(progressRate); VideoModel::GetInstance()->SetPosterSourceInfo(preview, "", ""); } else { diff --git a/frameworks/bridge/declarative_frontend/jsview/js_video.cpp b/frameworks/bridge/declarative_frontend/jsview/js_video.cpp index 02b69dfc4045512d37efb4215efcf5d8bb3745ad..0b74da296f6e023b93d60b8cbc13bc99f7f4e41b 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_video.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_video.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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,9 +76,12 @@ void JSVideo::Create(const JSCallbackInfo& info) VideoModel::GetInstance()->Create(videoController); // Parse the src, if it is invalid, use the empty string. - std::string videoSrc; - ParseJsMedia(srcValue, videoSrc); - VideoModel::GetInstance()->SetSrc(videoSrc); + std::string bundleNameSrc; + std::string moduleNameSrc; + std::string src; + int32_t resId = 0; + ParseJsMediaWithBundleName(srcValue, src, bundleNameSrc, moduleNameSrc, resId); + VideoModel::GetInstance()->SetSrc(src, bundleNameSrc, moduleNameSrc); // Parse the rate, if it is invalid, set it as 1.0. double currentProgressRate = 1.0; diff --git a/frameworks/bridge/declarative_frontend/jsview/models/video_model_impl.cpp b/frameworks/bridge/declarative_frontend/jsview/models/video_model_impl.cpp index fd17ad4a79b06603be310c4a7067d21f15a123c2..0a4517afdc21425d8d40360a2c1904cfd092ee1d 100644 --- a/frameworks/bridge/declarative_frontend/jsview/models/video_model_impl.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/models/video_model_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -40,7 +40,8 @@ void VideoModelImpl::Create(const RefPtr& videoController) stack->GetFlexItemComponent(); } -void VideoModelImpl::SetSrc(const std::string& src) +void VideoModelImpl::SetSrc(const std::string& src, const std::string& /* bundleName */, + const std::string& /*moduleName */) { auto videoComponent = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); CHECK_NULL_VOID(videoComponent); diff --git a/frameworks/bridge/declarative_frontend/jsview/models/video_model_impl.h b/frameworks/bridge/declarative_frontend/jsview/models/video_model_impl.h index 00a2e059acfbc094560020fcde4f1b504a020107..5ae86fdc476d26d94047606e5bf295033b2e7685 100644 --- a/frameworks/bridge/declarative_frontend/jsview/models/video_model_impl.h +++ b/frameworks/bridge/declarative_frontend/jsview/models/video_model_impl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ namespace OHOS::Ace::Framework { class VideoModelImpl : public OHOS::Ace::VideoModel { public: void Create(const RefPtr& videoController) override; - void SetSrc(const std::string& src) override; + void SetSrc(const std::string& src, const std::string& bundleName, const std::string& moduleName) override; void SetProgressRate(double progressRate) override; void SetPosterSourceInfo(const std::string& posterUrl, const std::string &bundleName, const std::string &moduleName) override; diff --git a/frameworks/core/common/resource/resource_wrapper.h b/frameworks/core/common/resource/resource_wrapper.h index 25ea76173d7f7d8e92fe0870f72637e71be7f08a..30d2689eeab27e6a416c5f4bf449ad91cde12cef 100644 --- a/frameworks/core/common/resource/resource_wrapper.h +++ b/frameworks/core/common/resource/resource_wrapper.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 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 @@ -225,6 +225,14 @@ public: return themeConstants_->GetRawFileDescription(rawfileName, rawfileDescription); } + bool CloseRawFileDescription(const std::string& rawfileName) const + { + if (SystemProperties::GetResourceDecoupling()) { + return resourceAdapter_->CloseRawFileDescription(rawfileName); + } + return themeConstants_->CloseRawFileDescription(rawfileName); + } + bool GetMediaById(const int32_t& resId, std::string& mediaPath) const { if (SystemProperties::GetResourceDecoupling()) { diff --git a/frameworks/core/components/theme/resource_adapter.h b/frameworks/core/components/theme/resource_adapter.h index b8eb87520d6e7fdb978abc7abc20c5c3a68feea1..a850194e3b38af7a6436367f071dd6533817f13f 100644 --- a/frameworks/core/components/theme/resource_adapter.h +++ b/frameworks/core/components/theme/resource_adapter.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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,11 @@ public: virtual void UpdateResourceManager(const std::string& bundleName, const std::string& moduleName) {} + virtual bool CloseRawFileDescription(const std::string& rawfileName) const + { + return false; + } + virtual bool GetRawFileDescription(const std::string& rawfileName, RawfileDescription& rawfileDescription) const { return false; diff --git a/frameworks/core/components/theme/theme_constants.cpp b/frameworks/core/components/theme/theme_constants.cpp index 3321b30b2ed1462c4ab9000648127fedd7d6b529..a3056c369dd1ee60d41250e21d7b459fb546f779 100644 --- a/frameworks/core/components/theme/theme_constants.cpp +++ b/frameworks/core/components/theme/theme_constants.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -308,6 +308,14 @@ bool ThemeConstants::GetRawFileDescription(const std::string& rawfileName, Rawfi return resAdapter_->GetRawFileDescription(rawfileName, rawfileDescription); } +bool ThemeConstants::CloseRawFileDescription(const std::string& rawfileName) const +{ + if (!resAdapter_) { + return false; + } + return resAdapter_->CloseRawFileDescription(rawfileName); +} + bool ThemeConstants::GetMediaById(const int32_t& resId, std::string& mediaPath) const { if (!resAdapter_) { diff --git a/frameworks/core/components/theme/theme_constants.h b/frameworks/core/components/theme/theme_constants.h index 6d2e0a0f33b08d0d413958621e090b8c3eedb078..0e6611eabf5f1fde2dc2e82018fb787403939234 100644 --- a/frameworks/core/components/theme/theme_constants.h +++ b/frameworks/core/components/theme/theme_constants.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -257,6 +257,14 @@ public: */ bool GetRawFileDescription(const std::string& rawfileName, RawfileDescription& rawfileDescription) const; + /* + * Close rawfile file description. + * NOTE: false value will be returned if not found. + * @param[in] rawfileName Target rawfile. + * @return success or not to close file info. + */ + bool CloseRawFileDescription(const std::string& rawfileName) const; + /* * Get resource media file path. * NOTE: false value will be returned if not found. diff --git a/frameworks/core/components_ng/pattern/video/video_accessibility_property.cpp b/frameworks/core/components_ng/pattern/video/video_accessibility_property.cpp index 0e204e0c666be8c667bc9b9212a554b871ffb9a9..8a5d05a8640945146fefbdd6edbfec44ec888a73 100644 --- a/frameworks/core/components_ng/pattern/video/video_accessibility_property.cpp +++ b/frameworks/core/components_ng/pattern/video/video_accessibility_property.cpp @@ -25,7 +25,7 @@ std::string VideoAccessibilityProperty::GetText() const CHECK_NULL_RETURN(frameNode, ""); auto videoLayoutProperty = frameNode->GetLayoutProperty(); CHECK_NULL_RETURN(videoLayoutProperty, ""); - return videoLayoutProperty->GetVideoSource().value_or(""); + return videoLayoutProperty->GetVideoSourceValue(VideoSourceInfo()).GetSrc(); } AccessibilityValue VideoAccessibilityProperty::GetAccessibilityValue() const diff --git a/frameworks/core/components_ng/pattern/video/video_layout_property.h b/frameworks/core/components_ng/pattern/video/video_layout_property.h index 8b728b490f17b2ed2c7ee3ed086729097e51fd20..4443c286d17103c3a0cf96d2b513c7edcfb86468 100644 --- a/frameworks/core/components_ng/pattern/video/video_layout_property.h +++ b/frameworks/core/components_ng/pattern/video/video_layout_property.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -49,13 +49,13 @@ public: void fullScreenReset() { - auto src_ = GetVideoSourceValue(""); + auto videoSrcInfo_ = GetVideoSourceValue(VideoSourceInfo()); auto objectFit_ = GetObjectFitValue(ImageFit::COVER); auto ImageSourceInfo_ = GetPosterImageInfoValue(ImageSourceInfo()); auto control_ = GetControlsValue(true); auto videoSize_ = GetVideoSizeValue(SizeF()); Reset(); - UpdateVideoSource(src_); + UpdateVideoSource(videoSrcInfo_); UpdateObjectFit(objectFit_); UpdateControls(control_); UpdatePosterImageInfo(ImageSourceInfo_); @@ -64,7 +64,7 @@ public: ACE_DEFINE_PROPERTY_GROUP(VideoStyle, VideoStyle); ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(VideoStyle, ObjectFit, ImageFit, PROPERTY_UPDATE_MEASURE); - ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(VideoStyle, VideoSource, std::string, PROPERTY_UPDATE_MEASURE); + ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(VideoStyle, VideoSource, VideoSourceInfo, PROPERTY_UPDATE_MEASURE); ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(VideoStyle, PosterImageInfo, ImageSourceInfo, PROPERTY_UPDATE_LAYOUT); ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(VideoStyle, Controls, bool, PROPERTY_UPDATE_MEASURE); ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(VideoStyle, VideoSize, SizeF, PROPERTY_UPDATE_MEASURE); diff --git a/frameworks/core/components_ng/pattern/video/video_model.h b/frameworks/core/components_ng/pattern/video/video_model.h index 6e39ce22983595c5e55a8ab6be99b8c8fd4ad508..e2ff1d6bbf930eda6d67e57fdd970a6c38ef0b99 100644 --- a/frameworks/core/components_ng/pattern/video/video_model.h +++ b/frameworks/core/components_ng/pattern/video/video_model.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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,7 +30,7 @@ public: virtual ~VideoModel() = default; virtual void Create(const RefPtr& videoController) = 0; - virtual void SetSrc(const std::string& src) = 0; + virtual void SetSrc(const std::string& src, const std::string& bundleName, const std::string& moduleName) = 0; virtual void SetProgressRate(double progressRate) = 0; virtual void SetPosterSourceInfo(const std::string& posterUrl, const std::string &bundleName, const std::string &moduleName) = 0; diff --git a/frameworks/core/components_ng/pattern/video/video_model_ng.cpp b/frameworks/core/components_ng/pattern/video/video_model_ng.cpp index 602452647f67bff2dad5501cf4fdfefd82ad3216..008e476043fd856100052b59eb4721258d9401a0 100644 --- a/frameworks/core/components_ng/pattern/video/video_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/video/video_model_ng.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -64,9 +64,13 @@ void VideoModelNG::Create(const RefPtr& videoController) AddDragFrameNodeToManager(); } -void VideoModelNG::SetSrc(const std::string& src) +void VideoModelNG::SetSrc(const std::string& src, const std::string& bundleName, const std::string& moduleName) { - ACE_UPDATE_LAYOUT_PROPERTY(VideoLayoutProperty, VideoSource, src); + VideoSourceInfo videoSrcInfo; + videoSrcInfo.src = src; + videoSrcInfo.bundleName = bundleName; + videoSrcInfo.moduleName = moduleName; + ACE_UPDATE_LAYOUT_PROPERTY(VideoLayoutProperty, VideoSource, videoSrcInfo); } void VideoModelNG::SetProgressRate(double progressRate) diff --git a/frameworks/core/components_ng/pattern/video/video_model_ng.h b/frameworks/core/components_ng/pattern/video/video_model_ng.h index 10b22a6c62302c661208c0c706353108bff34888..118eaa6a10f9106e9352805e746be84ec94a5d50 100644 --- a/frameworks/core/components_ng/pattern/video/video_model_ng.h +++ b/frameworks/core/components_ng/pattern/video/video_model_ng.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -24,7 +24,7 @@ namespace OHOS::Ace::NG { class ACE_EXPORT VideoModelNG : public OHOS::Ace::VideoModel { public: void Create(const RefPtr& videoController) override; - void SetSrc(const std::string& src) override; + void SetSrc(const std::string& src, const std::string& bundleName, const std::string& moduleName) override; void SetProgressRate(double progressRate) override; void SetPosterSourceInfo(const std::string& posterUrl, const std::string &bundleName, const std::string &moduleName) override; diff --git a/frameworks/core/components_ng/pattern/video/video_pattern.cpp b/frameworks/core/components_ng/pattern/video/video_pattern.cpp index 1957e950129e3f77ea490ea1651ebf7949470fd0..4bd8ffeffa4e704cd1c99552a6d41f0ecd830758 100755 --- a/frameworks/core/components_ng/pattern/video/video_pattern.cpp +++ b/frameworks/core/components_ng/pattern/video/video_pattern.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -297,11 +297,14 @@ void VideoPattern::PrepareMediaPlayer() auto videoLayoutProperty = GetLayoutProperty(); CHECK_NULL_VOID(videoLayoutProperty); // src has not set/changed - if (!videoLayoutProperty->HasVideoSource() || videoLayoutProperty->GetVideoSource().value() == src_) { + if (!videoLayoutProperty->HasVideoSource() || videoLayoutProperty->GetVideoSource() == videoSrcInfo_) { TAG_LOGI(AceLogTag::ACE_VIDEO, "Video source is null or the source has not changed."); return; } - src_ = videoLayoutProperty->GetVideoSource().value(); + auto videoSrcInfo = videoLayoutProperty->GetVideoSource(); + videoSrcInfo_.src = videoSrcInfo->GetSrc(); + videoSrcInfo_.bundleName = videoSrcInfo->GetBundleName(); + videoSrcInfo_.moduleName = videoSrcInfo->GetModuleName(); if (mediaPlayer_ && !mediaPlayer_->IsMediaPlayerValid()) { mediaPlayer_->CreateMediaPlayer(); } @@ -328,14 +331,15 @@ void VideoPattern::PrepareMediaPlayer() bool VideoPattern::SetSourceForMediaPlayer() { - TAG_LOGI(AceLogTag::ACE_VIDEO, "Video Set src for media, it is : %{private}s", src_.c_str()); + TAG_LOGI(AceLogTag::ACE_VIDEO, "Video Set src for media, it is : %{private}s", videoSrcInfo_.GetSrc().c_str()); CHECK_NULL_RETURN(mediaPlayer_, false); - return mediaPlayer_->SetSource(src_); + return mediaPlayer_->SetSource(videoSrcInfo_.GetSrc(), videoSrcInfo_.GetBundleName(), + videoSrcInfo_.GetModuleName()); } void VideoPattern::RegisterMediaPlayerEvent() { - if (src_.empty() || !mediaPlayer_) { + if (videoSrcInfo_.GetSrc().empty() || !mediaPlayer_) { TAG_LOGW(AceLogTag::ACE_VIDEO, "Video src is empty or mediaPlayer is null, register mediaPlayerEvent fail"); return; } @@ -929,10 +933,10 @@ void VideoPattern::OnModifyDone() // src has changed auto layoutProperty = GetLayoutProperty(); #ifdef RENDER_EXTRACT_SUPPORTED - if ((layoutProperty && layoutProperty->HasVideoSource() && layoutProperty->GetVideoSource().value() != src_)) { + if ((layoutProperty && layoutProperty->HasVideoSource() && layoutProperty->GetVideoSource() != videoSrcInfo_)) { #else if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE) && - (layoutProperty && layoutProperty->HasVideoSource() && layoutProperty->GetVideoSource().value() != src_)) { + (layoutProperty && layoutProperty->HasVideoSource() && layoutProperty->GetVideoSource() != videoSrcInfo_)) { #endif ResetStatus(); } @@ -1762,7 +1766,8 @@ void VideoPattern::EnableDrag() } videoPattern->SetIsDragEndAutoPlay(true); - videoLayoutProperty->UpdateVideoSource(videoSrc); + VideoSourceInfo videoSrcInfo = {videoSrc, "", ""}; + videoLayoutProperty->UpdateVideoSource(videoSrcInfo); auto frameNode = videoPattern->GetHost(); CHECK_NULL_VOID(frameNode); frameNode->MarkModifyDone(); @@ -1801,7 +1806,10 @@ void VideoPattern::RecoverState(const RefPtr& videoPattern) } isInitialState_ = videoPattern->GetInitialState(); auto layoutProperty = videoPattern->GetLayoutProperty(); - src_ = layoutProperty->GetVideoSourceValue(""); + auto videoSrcInfo = layoutProperty->GetVideoSource(); + videoSrcInfo_.src = videoSrcInfo->GetSrc(); + videoSrcInfo_.bundleName = videoSrcInfo->GetBundleName(); + videoSrcInfo_.moduleName = videoSrcInfo->GetModuleName(); isStop_ = videoPattern->GetIsStop(); muted_ = videoPattern->GetMuted(); autoPlay_ = videoPattern->GetAutoPlay(); diff --git a/frameworks/core/components_ng/pattern/video/video_pattern.h b/frameworks/core/components_ng/pattern/video/video_pattern.h index 9c266ae0da2af00cc25e4043bbf86109dd29e4ba..f6a17ab9c722523d73b68feb3090bcacd97bb07d 100644 --- a/frameworks/core/components_ng/pattern/video/video_pattern.h +++ b/frameworks/core/components_ng/pattern/video/video_pattern.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -188,7 +188,7 @@ public: const std::string& GetSrc() const { - return src_; + return videoSrcInfo_.src; } void UpdateMediaParam(const RefPtr& mediaPlayer, const RefPtr& renderSurface, @@ -358,7 +358,7 @@ private: HiddenChangeEvent hiddenChangeEvent_; // Video src. - std::string src_; + VideoSourceInfo videoSrcInfo_; bool isInitialState_ = true; // Initial state is true. Play or seek will set it to false. bool isPlaying_ = false; diff --git a/frameworks/core/components_ng/pattern/video/video_styles.h b/frameworks/core/components_ng/pattern/video/video_styles.h index a85d071ccd13e3897522870860f4fe12d785adbf..13e56e73a9b521f5acc3dc9d57e609fbb22a4376 100644 --- a/frameworks/core/components_ng/pattern/video/video_styles.h +++ b/frameworks/core/components_ng/pattern/video/video_styles.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -22,9 +22,35 @@ #include "core/image/image_source_info.h" namespace OHOS::Ace::NG { +struct VideoSourceInfo { + std::string src; + std::string bundleName = ""; + std::string moduleName = ""; + bool operator==(const VideoSourceInfo& videoSrcInfo) const + { + return src == videoSrcInfo.src && bundleName == videoSrcInfo.bundleName && + moduleName == videoSrcInfo.moduleName; + } + bool operator!=(const VideoSourceInfo& videoSrcInfo) const + { + return !operator==(videoSrcInfo); + } + const std::string& GetSrc() + { + return src; + } + const std::string& GetBundleName() + { + return bundleName; + } + const std::string& GetModuleName() + { + return moduleName; + } +}; struct VideoStyle { - ACE_DEFINE_PROPERTY_GROUP_ITEM(VideoSource, std::string); + ACE_DEFINE_PROPERTY_GROUP_ITEM(VideoSource, VideoSourceInfo); ACE_DEFINE_PROPERTY_GROUP_ITEM(PosterImageInfo, ImageSourceInfo); ACE_DEFINE_PROPERTY_GROUP_ITEM(Controls, bool); ACE_DEFINE_PROPERTY_GROUP_ITEM(ObjectFit, ImageFit); diff --git a/frameworks/core/components_ng/render/adapter/media_player_impl.cpp b/frameworks/core/components_ng/render/adapter/media_player_impl.cpp index 246f4150103579bd4f6ea5b2c1185e02a1d09cb9..d01156c28eb1e24cd03a8b82af50ac4ca467399c 100755 --- a/frameworks/core/components_ng/render/adapter/media_player_impl.cpp +++ b/frameworks/core/components_ng/render/adapter/media_player_impl.cpp @@ -135,7 +135,8 @@ void MediaPlayerImpl::SetVolume(float leftVolume, float rightVolume) player_->SetVolume(leftVolume); } -bool MediaPlayerImpl::SetSource(const std::string& src) +bool MediaPlayerImpl::SetSource(const std::string& src, const std::string& /* bundleName */, + const std::string& /* moduleName */) { CHECK_NULL_RETURN(player_, false); player_->SetSource(src); diff --git a/frameworks/core/components_ng/render/adapter/media_player_impl.h b/frameworks/core/components_ng/render/adapter/media_player_impl.h index 02ae55e4eb8f3c6e60f8bbf1d813e6b4398a4831..9961529c54914b2dfacb1c313c83355079c421c6 100644 --- a/frameworks/core/components_ng/render/adapter/media_player_impl.h +++ b/frameworks/core/components_ng/render/adapter/media_player_impl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 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,7 +33,7 @@ public: void ResetMediaPlayer() override; bool IsMediaPlayerValid() override; void SetVolume(float leftVolume, float rightVolume) override; - bool SetSource(const std::string& src) override; + bool SetSource(const std::string& src, const std::string& bundleName, const std::string& moduleName) override; void SetRenderSurface(const RefPtr& renderSurface) override; void RegisterMediaPlayerEvent(PositionUpdatedEvent&& positionUpdatedEvent, StateChangedEvent&& stateChangedEvent, CommonEvent&& errorEvent, CommonEvent&& resolutionChangeEvent, CommonEvent&& startRenderFrameEvent) override; diff --git a/frameworks/core/components_ng/render/adapter/rosen_media_player.cpp b/frameworks/core/components_ng/render/adapter/rosen_media_player.cpp index d96c823c768d69e847be21bdf31984ffb5da0ee0..64d2385eddded1707cc3558ef6235177cb712ebb 100644 --- a/frameworks/core/components_ng/render/adapter/rosen_media_player.cpp +++ b/frameworks/core/components_ng/render/adapter/rosen_media_player.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -17,6 +17,9 @@ #include #include #include "base/image/file_uri_helper.h" +#include "core/common/resource/resource_manager.h" +#include "core/common/resource/resource_object.h" +#include "core/common/resource/resource_wrapper.h" #include "core/pipeline_ng/pipeline_context.h" namespace OHOS::Ace::NG { @@ -31,6 +34,7 @@ const int32_t RAWFILE_PREFIX_LENGTH = strlen("resource://RAWFILE/"); const std::regex MEDIA_RES_ID_REGEX(R"(^resource://\w+/([0-9]+)\.\w+$)", std::regex::icase); const std::regex MEDIA_APP_RES_ID_REGEX(R"(^resource://.*/([0-9]+)\.\w+$)", std::regex::icase); const std::string FA_RESOURCE_PREFIX = "assets/entry/"; +const std::regex MEDIA_APP_RES_PATH_REGEX(R"(^resource://RAWFILE/(.*)$)"); OHOS::Media::PlayerSeekMode ConvertToMediaSeekMode(SeekMode seekMode) { @@ -103,12 +107,12 @@ void RosenMediaPlayer::SetMediaMuted(int32_t type, bool isMuted) mediaPlayer_->SetMediaMuted(static_cast(type), isMuted); } -bool RosenMediaPlayer::SetSource(const std::string& src) +bool RosenMediaPlayer::SetSource(const std::string& src, const std::string& bundleName, const std::string& moduleName) { auto videoSrc = src; int32_t fd = -1; bool useFd = false; - if (!SetMediaSource(videoSrc, fd, useFd)) { + if (!SetMediaSource(videoSrc, fd, useFd, bundleName, moduleName)) { LOGE("Video media player set media source failed."); return false; } @@ -213,6 +217,44 @@ bool RosenMediaPlayer::MediaPlay(const std::string& filePath) return true; } +bool RosenMediaPlayer::RawFileWithModuleInfoPlay(const std::string& src, const std::string& bundleName, + const std::string& moduleName) +{ + auto resourceObject = AceType::MakeRefPtr(bundleName, moduleName); + RefPtr resourceAdapter = nullptr; + RefPtr themeConstants = nullptr; + if (SystemProperties::GetResourceDecoupling()) { + resourceAdapter = ResourceManager::GetInstance().GetOrCreateResourceAdapter(resourceObject); + CHECK_NULL_RETURN(resourceAdapter, false); + resourceAdapter->UpdateResourceManager(bundleName, moduleName); + } else { + auto themeManager = PipelineBase::CurrentThemeManager(); + CHECK_NULL_RETURN(themeManager, false); + themeConstants = themeManager->GetThemeConstants(); + CHECK_NULL_RETURN(themeConstants, false); + } + + auto resourceWrapper = AceType::MakeRefPtr(themeConstants, resourceAdapter); + std::string rawFile; + RawfileDescription rawfileDescription; + if (GetResourceId(src, rawFile)) { + if (!resourceWrapper->GetRawFileDescription(rawFile, rawfileDescription)) { + TAG_LOGW(AceLogTag::ACE_VIDEO, "get video data by name failed, src:%{private}s, rawFile:%{private}s", + src.c_str(), rawFile.c_str()); + return false; + } + } + + if (mediaPlayer_ && + mediaPlayer_->SetSource(rawfileDescription.fd, rawfileDescription.offset, rawfileDescription.length) != 0) { + LOGE("Player SetSource failed"); + resourceWrapper->CloseRawFileDescription(rawFile); + return false; + } + resourceWrapper->CloseRawFileDescription(rawFile); + return true; +} + bool RosenMediaPlayer::RawFilePlay(const std::string& filePath) { auto pipelineContext = PipelineBase::GetCurrentContext(); @@ -301,7 +343,19 @@ bool RosenMediaPlayer::GetResourceId(const std::string& path, uint32_t& resId) return false; } -bool RosenMediaPlayer::SetMediaSource(std::string& filePath, int32_t& fd, bool& useFd) +bool RosenMediaPlayer::GetResourceId(const std::string& uri, std::string& path) const +{ + std::smatch matches; + if (std::regex_match(uri, matches, MEDIA_APP_RES_PATH_REGEX) && matches.size() == MEDIA_RESOURCE_MATCH_SIZE) { + path = matches[1].str(); + return true; + } + + return false; +} + +bool RosenMediaPlayer::SetMediaSource(std::string& filePath, int32_t& fd, bool& useFd, + const std::string& bundleName, const std::string& moduleName) { if (StringUtils::StartWith(filePath, "dataability://") || StringUtils::StartWith(filePath, "datashare://") || StringUtils::StartWith(filePath, "file://media")) { @@ -320,8 +374,13 @@ bool RosenMediaPlayer::SetMediaSource(std::string& filePath, int32_t& fd, bool& // file path: resources/base/media/xxx.xx --> resource:///xxx.xx return MediaPlay(filePath); } else if (StringUtils::StartWith(filePath, "resource://RAWFILE")) { - // file path: resource/rawfile/xxx.xx --> resource://rawfile/xxx.xx - return RawFilePlay(filePath); + //Multi module, eg: HSP + if (!RawFileWithModuleInfoPlay(filePath, bundleName, moduleName)) { + LOGW("Player SetSource failed, try again"); + // file path: resource/rawfile/xxx.xx --> resource://rawfile/xxx.xx + return RawFilePlay(filePath); + } + return true; } else if (StringUtils::StartWith(filePath, "http")) { // http or https if (mediaPlayer_ && mediaPlayer_->SetSource(filePath) != 0) { diff --git a/frameworks/core/components_ng/render/adapter/rosen_media_player.h b/frameworks/core/components_ng/render/adapter/rosen_media_player.h index 97a4225c84219099836ee31c1f9574a81fae96f9..95906142f74ba56754483e87f013ddeee3e49693 100644 --- a/frameworks/core/components_ng/render/adapter/rosen_media_player.h +++ b/frameworks/core/components_ng/render/adapter/rosen_media_player.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -38,7 +38,7 @@ public: bool IsMediaPlayerValid() override; void SetVolume(float leftVolume, float rightVolume) override; void SetMediaMuted(int32_t type, bool isMuted) override; - bool SetSource(const std::string& src) override; + bool SetSource(const std::string& src, const std::string& bundleName, const std::string& moduleName) override; bool SetSourceByFd(int32_t fd) override; void SetRenderSurface(const RefPtr& renderSurface) override; void RegisterMediaPlayerEvent(PositionUpdatedEvent&& positionUpdatedEvent, StateChangedEvent&& stateChangedEvent, @@ -60,11 +60,15 @@ public: private: // Interim programme - bool SetMediaSource(std::string& filePath, int32_t& fd, bool& useFd); + bool SetMediaSource(std::string& filePath, int32_t& fd, bool& useFd, const std::string& bundleName = "", + const std::string& moduleName = ""); bool MediaPlay(const std::string& filePath); bool RawFilePlay(const std::string& filePath); bool RelativePathPlay(const std::string& filePath); + bool RawFileWithModuleInfoPlay(const std::string& src, const std::string& bundleName, + const std::string& moduleName); bool GetResourceId(const std::string& path, uint32_t& resId); + bool GetResourceId(const std::string& uri, std::string& path) const; std::shared_ptr mediaPlayer_ = nullptr; std::shared_ptr mediaPlayerCallback_ = nullptr; diff --git a/frameworks/core/components_ng/render/media_player.h b/frameworks/core/components_ng/render/media_player.h index 9eab974b5e120d100815fba7414412cddaba545a..4f0fc9e12ba67f22ae789e5d06bc2292acacb664 100644 --- a/frameworks/core/components_ng/render/media_player.h +++ b/frameworks/core/components_ng/render/media_player.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -52,7 +52,8 @@ public: virtual void SetMediaMuted(int32_t type, bool isMuted) {} - virtual bool SetSource(const std::string& /*src*/) + virtual bool SetSource(const std::string& /*src*/, const std::string& bundleName = "", + const std::string& moduleName = "") { return false; } diff --git a/test/mock/core/render/mock_media_player.h b/test/mock/core/render/mock_media_player.h index bc375c48c0dbc30e881977e0542627c15d975570..5d9b1c629827593c6416335d78d88f6b5ceb7839 100644 --- a/test/mock/core/render/mock_media_player.h +++ b/test/mock/core/render/mock_media_player.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -44,7 +44,7 @@ public: } MOCK_METHOD0(IsMediaPlayerValid, bool()); - MOCK_METHOD1(SetSource, bool(const std::string&)); + MOCK_METHOD3(SetSource, bool(const std::string&, const std::string&, const std::string&)); MOCK_METHOD0(SetSurface, int32_t()); MOCK_METHOD0(PrepareAsync, int32_t()); MOCK_METHOD0(Pause, int32_t()); diff --git a/test/unittest/core/pattern/movingphoto/movingphoto_test_ng.cpp b/test/unittest/core/pattern/movingphoto/movingphoto_test_ng.cpp index 297abffab87b9b7813a461ad26ff8b04ce9e459d..a4909a073bcd1d020591ef3180c2505fae66e942 100644 --- a/test/unittest/core/pattern/movingphoto/movingphoto_test_ng.cpp +++ b/test/unittest/core/pattern/movingphoto/movingphoto_test_ng.cpp @@ -784,7 +784,7 @@ HWTEST_F(MovingphotoTestNg, MovingPhotoPatternTest017, TestSize.Level1) * @tc.expected: mediaPlayer_'s functions is called. and PlaybackStatus is PREPARED */ movingphoto.SetImageSrc(MOVINGPHOTO_IMAGE_SRC); - EXPECT_CALL(*(AceType::DynamicCast(movingphotoPattern->mediaPlayer_)), SetSource(_)) + EXPECT_CALL(*(AceType::DynamicCast(movingphotoPattern->mediaPlayer_)), SetSource(_, _, _)) .WillRepeatedly(Return(true)); EXPECT_CALL(*(AceType::DynamicCast(movingphotoPattern->mediaPlayer_)), PrepareAsync()) .WillRepeatedly(Return(0)); diff --git a/test/unittest/core/pattern/video/video_property_test_ng.cpp b/test/unittest/core/pattern/video/video_property_test_ng.cpp index 702ecb0ce949863243a1683193ca3817bdf45231..f3ba74c8df1fc39e4a3a3799208458b9be82ec03 100644 --- a/test/unittest/core/pattern/video/video_property_test_ng.cpp +++ b/test/unittest/core/pattern/video/video_property_test_ng.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -171,7 +171,7 @@ RefPtr VideoPropertyTestNg::CreateVideoNode(TestProperty& testPropert .WillRepeatedly(Return(true)); if (testProperty.src.has_value()) { - VideoModelNG().SetSrc(testProperty.src.value()); + VideoModelNG().SetSrc(testProperty.src.value(), "", ""); } if (testProperty.progressRate.has_value()) { VideoModelNG().SetProgressRate(testProperty.progressRate.value()); @@ -217,7 +217,7 @@ HWTEST_F(VideoPropertyTestNg, VideoPropertyTest002, TestSize.Level1) EXPECT_CALL(*(AceType::DynamicCast(videoPatternTemp->mediaPlayer_)), IsMediaPlayerValid()) .WillRepeatedly(Return(false)); - video.SetSrc(VIDEO_SRC); + video.SetSrc(VIDEO_SRC, "", ""); video.SetProgressRate(VIDEO_PROGRESS_RATE); video.SetPosterSourceInfo(VIDEO_POSTER_URL, "", ""); video.SetMuted(MUTED_VALUE); @@ -233,7 +233,7 @@ HWTEST_F(VideoPropertyTestNg, VideoPropertyTest002, TestSize.Level1) auto videoPattern = frameNode->GetPattern(); ASSERT_NE(videoPattern, nullptr); - EXPECT_EQ(videoLayoutProperty->GetVideoSource().value_or(""), VIDEO_SRC); + EXPECT_EQ(videoLayoutProperty->GetVideoSourceValue(VideoSourceInfo()).GetSrc(), VIDEO_SRC); EXPECT_EQ(videoPattern->GetProgressRate(), VIDEO_PROGRESS_RATE); EXPECT_EQ(videoLayoutProperty->GetPosterImageInfoValue(ImageSourceInfo("")), ImageSourceInfo(VIDEO_POSTER_URL)); EXPECT_EQ(videoPattern->GetMuted(), MUTED_VALUE); @@ -564,7 +564,7 @@ HWTEST_F(VideoPropertyTestNg, VideoPropertyTest016, TestSize.Level1) ImageSourceInfo secondPixelMapImage = ImageSourceInfo(secondPixelMap); ImageSourceInfo urlImage = ImageSourceInfo(VIDEO_POSTER_URL); - video.SetSrc(VIDEO_SRC); + video.SetSrc(VIDEO_SRC, "", ""); video.SetProgressRate(VIDEO_PROGRESS_RATE); video.SetPosterSourceByPixelMap(pixelMap); @@ -573,7 +573,7 @@ HWTEST_F(VideoPropertyTestNg, VideoPropertyTest016, TestSize.Level1) auto videoLayoutProperty = frameNode->GetLayoutProperty(); EXPECT_FALSE(videoLayoutProperty == nullptr); - EXPECT_EQ(videoLayoutProperty->GetVideoSource().value_or(""), VIDEO_SRC); + EXPECT_EQ(videoLayoutProperty->GetVideoSourceValue(VideoSourceInfo()).GetSrc(), VIDEO_SRC); EXPECT_EQ(videoLayoutProperty->GetPosterImageInfoValue(defaultImage), pixelMapImage); /** @@ -828,7 +828,7 @@ HWTEST_F(VideoPropertyTestNg, VideoPatternTest020, TestSize.Level1) auto videoPattern = AceType::DynamicCast(frameNode->GetPattern()); ASSERT_NE(videoPattern, nullptr); - videoPattern->src_ = "test"; + videoPattern->videoSrcInfo_.src = "test"; videoPattern->EnableDrag(); auto eventHub = frameNode->GetEventHub(); ASSERT_NE(eventHub, nullptr); @@ -914,15 +914,18 @@ HWTEST_F(VideoPropertyTestNg, VideoFullScreenTest001, TestSize.Level1) EXPECT_FALSE(videoLayout->HasControls()); videoLayout->UpdateObjectFit(ImageFit::COVER); fullScreenLayout->UpdateObjectFit(ImageFit::CONTAIN); - videoLayout->UpdateVideoSource(VIDEO_SRC); - fullScreenLayout->UpdateVideoSource(""); + auto videoSrcInfo = videoLayout->GetVideoSourceValue(VideoSourceInfo()); + videoSrcInfo.src = VIDEO_SRC; + videoLayout->UpdateVideoSource(videoSrcInfo); + videoSrcInfo.src = ""; + fullScreenLayout->UpdateVideoSource(videoSrcInfo); videoLayout->UpdatePosterImageInfo(ImageSourceInfo(VIDEO_POSTER_URL)); fullScreenLayout->UpdatePosterImageInfo(ImageSourceInfo("")); videoLayout->UpdateControls(true); fullScreenLayout->UpdateControls(false); fullScreenPattern->UpdateState(); EXPECT_EQ(fullScreenLayout->GetObjectFit().value(), ImageFit::COVER); - EXPECT_EQ(fullScreenLayout->GetVideoSource().value(), VIDEO_SRC); + EXPECT_EQ(fullScreenLayout->GetVideoSource().value().GetSrc(), VIDEO_SRC); EXPECT_EQ(fullScreenLayout->GetPosterImageInfo().value(), ImageSourceInfo(VIDEO_POSTER_URL)); EXPECT_TRUE(fullScreenLayout->GetControls().value()); fullScreenPattern->UpdateState(); @@ -949,8 +952,8 @@ HWTEST_F(VideoPropertyTestNg, VideoPatternTest021, TestSize.Level1) * @tc.steps: step2. Call ResetMediaPlayer when mediaPlayer_ in different status. * @tc.expected: mediaPlayer_'s functions is called. */ - videoPattern->src_ = VIDEO_SRC; - EXPECT_CALL(*(AceType::DynamicCast(videoPattern->mediaPlayer_)), SetSource(_)) + videoPattern->videoSrcInfo_.src = VIDEO_SRC; + EXPECT_CALL(*(AceType::DynamicCast(videoPattern->mediaPlayer_)), SetSource(_, _, _)) .WillOnce(Return(true)) .WillOnce(Return(false)) .WillOnce(Return(true)); diff --git a/test/unittest/core/pattern/video/video_test_ng.cpp b/test/unittest/core/pattern/video/video_test_ng.cpp index ed9ba65fad1a6b87b11c23963840ca65d4e960c0..870a9cc8ef6bc6767fe57c4b9a9b22598f5ae836 100755 --- a/test/unittest/core/pattern/video/video_test_ng.cpp +++ b/test/unittest/core/pattern/video/video_test_ng.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -176,7 +176,7 @@ RefPtr VideoTestNg::CreateVideoNode(TestProperty& testProperty) .WillRepeatedly(Return(true)); if (testProperty.src.has_value()) { - VideoModelNG().SetSrc(testProperty.src.value()); + VideoModelNG().SetSrc(testProperty.src.value(), "", ""); } if (testProperty.progressRate.has_value()) { VideoModelNG().SetProgressRate(testProperty.progressRate.value()); @@ -321,7 +321,9 @@ HWTEST_F(VideoTestNg, VideoPatternTest008, TestSize.Level1) * @tc.expected: step4. IsMediaPlayerValid will be called 5 times */ auto videoLayoutProperty = pattern->GetLayoutProperty(); - videoLayoutProperty->UpdateVideoSource(VIDEO_SRC); + auto videoSrcInfo = videoLayoutProperty->GetVideoSourceValue(VideoSourceInfo()); + videoSrcInfo.src = VIDEO_SRC; + videoLayoutProperty->UpdateVideoSource(videoSrcInfo); EXPECT_CALL(*(AceType::DynamicCast(pattern->mediaPlayer_)), IsMediaPlayerValid()) .Times(5) .WillRepeatedly(Return(true)); @@ -330,7 +332,7 @@ HWTEST_F(VideoTestNg, VideoPatternTest008, TestSize.Level1) /** * @tc.steps: step5. Call UpdateMediaPlayerOnBg - * case: IsMediaPlayerValid is always true & has set VideoSource & has set src_ + * case: IsMediaPlayerValid is always true & has set VideoSource & has set videoSrcInfo_.src * @tc.expected: step5. IsMediaPlayerValid will be called 3 times. */ EXPECT_CALL(*(AceType::DynamicCast(pattern->mediaPlayer_)), IsMediaPlayerValid()) @@ -345,7 +347,7 @@ HWTEST_F(VideoTestNg, VideoPatternTest008, TestSize.Level1) * other function will be called once and return right value when preparing MediaPlayer * firstly */ - pattern->src_.clear(); + pattern->videoSrcInfo_.src.clear(); EXPECT_CALL(*(AceType::DynamicCast(pattern->mediaPlayer_)), IsMediaPlayerValid()) .Times(5) .WillOnce(Return(false)) @@ -383,11 +385,11 @@ HWTEST_F(VideoTestNg, VideoPatternTest008, TestSize.Level1) .WillOnce(Return(true)) .WillOnce(Return(true)) .WillOnce(Return(true)); - pattern->src_.clear(); + pattern->videoSrcInfo_.src.clear(); pattern->UpdateMediaPlayerOnBg(); - pattern->src_.clear(); + pattern->videoSrcInfo_.src.clear(); pattern->UpdateMediaPlayerOnBg(); - pattern->src_.clear(); + pattern->videoSrcInfo_.src.clear(); pattern->UpdateMediaPlayerOnBg(); // CreateMediaPlayer success but PrepareMediaPlayer fail for mediaPlayer is invalid @@ -398,7 +400,7 @@ HWTEST_F(VideoTestNg, VideoPatternTest008, TestSize.Level1) .WillOnce(Return(false)) .WillOnce(Return(false)) .WillOnce(Return(false)); - pattern->src_.clear(); + pattern->videoSrcInfo_.src.clear(); pattern->UpdateMediaPlayerOnBg(); } @@ -917,7 +919,7 @@ HWTEST_F(VideoTestNg, VideoAccessibilityPropertyTest001, TestSize.Level1) ASSERT_NE(videoAccessibilitProperty, nullptr); EXPECT_EQ(videoAccessibilitProperty->GetText(), ""); - video.SetSrc(VIDEO_SRC); + video.SetSrc(VIDEO_SRC, "", ""); EXPECT_EQ(videoAccessibilitProperty->GetText(), VIDEO_SRC); } diff --git a/test/unittest/core/pattern/video/video_test_ng_add.cpp b/test/unittest/core/pattern/video/video_test_ng_add.cpp index 04f38cf3512612972f2eb8d0e81de0f4fbd86e18..754f70669990568cd120c278112e390d69041393 100644 --- a/test/unittest/core/pattern/video/video_test_ng_add.cpp +++ b/test/unittest/core/pattern/video/video_test_ng_add.cpp @@ -169,7 +169,7 @@ RefPtr VideoTestAddNg::CreateVideoNode(TestProperty& g_testProperty) .WillRepeatedly(Return(true)); if (g_testProperty.src.has_value()) { - VideoModelNG().SetSrc(g_testProperty.src.value()); + VideoModelNG().SetSrc(g_testProperty.src.value(), "", ""); } if (g_testProperty.progressRate.has_value()) { VideoModelNG().SetProgressRate(g_testProperty.progressRate.value()); diff --git a/test/unittest/core/pattern/video/video_test_ng_extra_add.cpp b/test/unittest/core/pattern/video/video_test_ng_extra_add.cpp index 41f9f71dbc6160abc39b7c1e45b9006e246d7ec1..2ad25e73acebdb95369837d0a957a098671b98a5 100644 --- a/test/unittest/core/pattern/video/video_test_ng_extra_add.cpp +++ b/test/unittest/core/pattern/video/video_test_ng_extra_add.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -173,7 +173,7 @@ RefPtr VideoTestExtraAddNg::CreateVideoNode(TestProperty& g_testPrope .WillRepeatedly(Return(true)); if (g_testProperty.src.has_value()) { - VideoModelNG().SetSrc(g_testProperty.src.value()); + VideoModelNG().SetSrc(g_testProperty.src.value(), "", ""); } if (g_testProperty.progressRate.has_value()) { VideoModelNG().SetProgressRate(g_testProperty.progressRate.value()); @@ -867,11 +867,13 @@ HWTEST_F(VideoTestExtraAddNg, OnModifyDone001, TestSize.Level1) videoPattern->OnModifyDone(); EXPECT_TRUE(videoPattern->isInitialState_); - layoutProperty->UpdateVideoSource(VIDEO_SRC); + auto videoSrcInfo = layoutProperty->GetVideoSourceValue(VideoSourceInfo()); + videoSrcInfo.src = VIDEO_SRC; + layoutProperty->UpdateVideoSource(videoSrcInfo); videoPattern->OnModifyDone(); EXPECT_TRUE(videoPattern->isInitialState_); - videoPattern->src_ = VIDEO_SRC; + videoPattern->videoSrcInfo_.src = VIDEO_SRC; videoPattern->OnModifyDone(); EXPECT_TRUE(videoPattern->isInitialState_);