From d86f6c31dfc15dede164ed9c1f4b413e706bc551 Mon Sep 17 00:00:00 2001 From: y30052185 Date: Fri, 29 Aug 2025 14:31:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=89=E9=9C=80=E7=94=9F=E6=88=90=E5=B9=B4?= =?UTF-8?q?=E6=9C=88=E9=80=BB=E8=BE=91=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: y30052185 --- .../include/thumbnail_source_loading.h | 5 ++++ .../src/thumbnail_generate_helper.cpp | 2 +- .../src/thumbnail_source_loading.cpp | 30 +++++++++++++++---- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/frameworks/services/media_thumbnail/include/thumbnail_source_loading.h b/frameworks/services/media_thumbnail/include/thumbnail_source_loading.h index ac848a5cf0..7b1a92fdca 100644 --- a/frameworks/services/media_thumbnail/include/thumbnail_source_loading.h +++ b/frameworks/services/media_thumbnail/include/thumbnail_source_loading.h @@ -175,6 +175,11 @@ public: */ static const std::unordered_map UPGRADE_VIDEO_SOURCE_LOADING_STATES; + /* + * Define source loading states sequence for creating year&month thumbnails from local and cloud thumbnails. + */ + static const std::unordered_map LOCAL_AND_CLOUD_THUMB_SOURCE_LOADING_STATES; + SourceLoader(Size &desiredSize, ThumbnailData &data) : data_(data), desiredSize_(desiredSize) { GetSourcePath = nullptr; diff --git a/frameworks/services/media_thumbnail/src/thumbnail_generate_helper.cpp b/frameworks/services/media_thumbnail/src/thumbnail_generate_helper.cpp index 3d6007c0bf..9de88745be 100644 --- a/frameworks/services/media_thumbnail/src/thumbnail_generate_helper.cpp +++ b/frameworks/services/media_thumbnail/src/thumbnail_generate_helper.cpp @@ -287,7 +287,7 @@ int32_t ThumbnailGenerateHelper::CreateAstcMthAndYear(ThumbRdbOpt &opts) SourceLoader::LOCAL_SOURCE_LOADING_STATES : SourceLoader::LOCAL_THUMB_SOURCE_LOADING_STATES; } else { ThumbnailUtils::HandleImageExifRotate(data); - data.loaderOpts.loadingStates = SourceLoader::CLOUD_SOURCE_LOADING_STATES; + data.loaderOpts.loadingStates = SourceLoader::LOCAL_AND_CLOUD_THUMB_SOURCE_LOADING_STATES; } data.needGenerateExThumbnail = false; if (!IThumbnailHelper::DoCreateAstcMthAndYear(opts, data)) { diff --git a/frameworks/services/media_thumbnail/src/thumbnail_source_loading.cpp b/frameworks/services/media_thumbnail/src/thumbnail_source_loading.cpp index c506d32f22..fc6e64cc29 100644 --- a/frameworks/services/media_thumbnail/src/thumbnail_source_loading.cpp +++ b/frameworks/services/media_thumbnail/src/thumbnail_source_loading.cpp @@ -104,6 +104,14 @@ const std::unordered_map SourceLoader::UPGRADE_VIDEO_S { SourceState::CLOUD_LCD, SourceState::FINISH }, }; +const std::unordered_map SourceLoader::LOCAL_AND_CLOUD_THUMB_SOURCE_LOADING_STATES = { + { SourceState::BEGIN, SourceState::LOCAL_THUMB }, + { SourceState::LOCAL_THUMB, SourceState::LOCAL_LCD }, + { SourceState::LOCAL_LCD, SourceState::CLOUD_THUMB }, + { SourceState::CLOUD_THUMB, SourceState::CLOUD_LCD }, + { SourceState::CLOUD_LCD, SourceState::FINISH }, +}; + std::string GetLocalThumbnailPath(const std::string &path, const std::string &key) { if (path.length() < ROOT_MEDIA_DIR.length()) { @@ -156,7 +164,7 @@ bool IsLocalSourceAvailable(const std::string& path) return true; } -bool IsCloudSourceAvailable(const std::string& path) +bool IsCloudSourceAvailable(const std::string& path, int32_t &error) { string absFilePath; if (!PathToRealPath(path, absFilePath)) { @@ -166,6 +174,7 @@ bool IsCloudSourceAvailable(const std::string& path) int fd = open(absFilePath.c_str(), O_RDONLY); if (fd < 0) { + error = errno; MEDIA_ERR_LOG("open cloud file fail: errno: %{public}d, %{public}s", errno, DfxUtils::GetSafePath(path).c_str()); return false; @@ -588,6 +597,7 @@ bool SourceLoader::RunLoading() if (IsFinal()) { break; } + error_ = E_OK; SetCurrentStateFunction(); do { if (state_ < SourceState::CLOUD_THUMB) { @@ -645,7 +655,14 @@ bool SourceLoader::IsSizeAcceptable(std::unique_ptr& imageSource, I bool SourceLoader::IsFinal() { - if (error_ != E_OK) { + if (error_ == ENETUNREACH) { + if (data_.loaderOpts.desiredType == ThumbnailType::MTH_ASTC) { + MEDIA_WARN_LOG("The network is poor, stop generating thumbnails"); + state_ = SourceState::ERROR; + data_.stats.errorCode = error_; + return true; + } + } else if (error_ != E_OK) { state_ = SourceState::ERROR; data_.stats.errorCode = error_; return true; @@ -715,7 +732,7 @@ std::string CloudThumbSource::GetSourcePath(ThumbnailData &data, int32_t &error) std::string tmpPath = ThumbnailUtils::IsExCloudThumbnail(data) ? GetThumbnailPath(data.path, THUMBNAIL_THUMB_EX_SUFFIX) : GetThumbnailPath(data.path, THUMBNAIL_THUMB_SUFFIX); int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds(); - if (!IsCloudSourceAvailable(tmpPath)) { + if (!IsCloudSourceAvailable(tmpPath, error)) { return ""; } int32_t totalCost = static_cast(MediaFileUtils::UTCTimeMilliSeconds() - startTime); @@ -741,7 +758,7 @@ std::string CloudLcdSource::GetSourcePath(ThumbnailData &data, int32_t &error) tmpPath = GetThumbnailPath(data.path, THUMBNAIL_LCD_SUFFIX); } int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds(); - if (!IsCloudSourceAvailable(tmpPath)) { + if (!IsCloudSourceAvailable(tmpPath, error)) { return ""; } int32_t totalCost = static_cast(MediaFileUtils::UTCTimeMilliSeconds() - startTime); @@ -754,6 +771,9 @@ bool CloudLcdSource::IsSizeLargeEnough(ThumbnailData &data, int32_t &minSize) if (data.mediaType == MEDIA_TYPE_VIDEO) { return true; } + if (data.loaderOpts.desiredType == ThumbnailType::MTH_ASTC) { + return true; + } int photoShorterSide = data.photoWidth < data.photoHeight ? data.photoWidth : data.photoHeight; if (photoShorterSide != 0 && photoShorterSide < SHORT_SIDE_THRESHOLD) { return true; @@ -772,7 +792,7 @@ std::string CloudOriginSource::GetSourcePath(ThumbnailData &data, int32_t &error return data.path; } int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds(); - if (!IsCloudSourceAvailable(data.path)) { + if (!IsCloudSourceAvailable(data.path, error)) { return ""; } int32_t totalCost = static_cast(MediaFileUtils::UTCTimeMilliSeconds() - startTime); -- Gitee