1 /* 2 * Copyright (C) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef CLONE_RESTORE_CV_ANALYSIS_H 17 #define CLONE_RESTORE_CV_ANALYSIS_H 18 19 #include <string> 20 21 #include "clone_restore_highlight.h" 22 #include "nlohmann/json.hpp" 23 #include "rdb_store.h" 24 25 namespace OHOS::Media { 26 class CloneRestoreCVAnalysis { 27 public: 28 void Init(int32_t sceneCode, const std::string &taskId, std::shared_ptr<NativeRdb::RdbStore> mediaLibraryRdb, 29 std::shared_ptr<NativeRdb::RdbStore> mediaRdb, const std::string &backupRestoreDir); 30 void RestoreAlbums(CloneRestoreHighlight &cloneHighlight); 31 32 private: 33 void RestoreAssetSdMap(CloneRestoreHighlight &cloneHighlight); 34 void RestoreAlbumAssetMap(CloneRestoreHighlight &cloneHighlight); 35 void InsertIntoAssetSdMap(std::vector<NativeRdb::ValuesBucket> &values); 36 void InsertIntoAlbumAssetMap(std::vector<NativeRdb::ValuesBucket> &values); 37 void MoveAnalysisAssets(const std::string &srcPath, const std::string &dstPath); 38 int32_t BatchInsertWithRetry(const std::string &tableName, 39 const std::vector<NativeRdb::ValuesBucket> &values, int64_t &rowNum); 40 std::string ParsePlayInfo(const std::string &oldPlayInfo, CloneRestoreHighlight &cloneHighlight); 41 void ParseEffectline(nlohmann::json &newPlayInfo, size_t effectlineIndex, CloneRestoreHighlight &cloneHighlight); 42 void ParseEffectlineFileData(nlohmann::json &newPlayInfo, size_t effectlineIndex, 43 CloneRestoreHighlight &cloneHighlight); 44 void ParseTimeline(nlohmann::json &newPlayInfo, size_t TimelineIndex, CloneRestoreHighlight &cloneHighlight); 45 void UpdateHighlightPlayInfos(CloneRestoreHighlight &cloneHighlight, std::vector<int32_t> &updateHighlightIds); 46 void ReportCloneRestoreCVAnalysisTask(); 47 std::string GetNewEffectVideoUri(const std::string &oldVideoUri, CloneRestoreHighlight &cloneHighlight); 48 std::string GetNewTransitionVideoUri(const std::string &oldVideoUri, CloneRestoreHighlight &cloneHighlight); 49 std::string GetNewPhotoUriByUri(const std::string &oldUri, CloneRestoreHighlight &cloneHighlight); 50 51 int32_t sceneCode_{-1}; 52 std::string taskId_; 53 // old media_liabrary.db 54 std::shared_ptr<NativeRdb::RdbStore> mediaRdb_; 55 // new media_liabrary.db 56 std::shared_ptr<NativeRdb::RdbStore> mediaLibraryRdb_; 57 std::string assetPath_; 58 std::string garblePath_; 59 std::unordered_map<std::string, std::string> assetUriMap_; 60 bool isHighlightVideoDirExist_{false}; 61 int64_t assetSdSuccessCnt_{0}; 62 int64_t assetSdFailedCnt_{0}; 63 int64_t albumAssetSuccessCnt_{0}; 64 int64_t albumAssetFailedCnt_{0}; 65 int64_t restoreTimeCost_{0}; 66 }; 67 } // namespace OHOS::Media 68 #endif // CLONE_RESTORE_CV_ANALYSIS_H