1 /*
2  * Copyright (C) 2024 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 FRAMEWORKS_INNERKITSIMPL_MEDIA_LIBRARY_INCLUDE_MOVING_PHOTO_FILE_UTILS_H
17 #define FRAMEWORKS_INNERKITSIMPL_MEDIA_LIBRARY_INCLUDE_MOVING_PHOTO_FILE_UTILS_H
18 
19 #include <string>
20 
21 #include "photo_file_utils.h"
22 
23 namespace OHOS::Media {
24 #define EXPORT __attribute__ ((visibility ("default")))
25 EXPORT const std::string LIVE_TAG = "LIVE_";
26 
27 EXPORT constexpr int32_t LIVE_TAG_LEN = 20;
28 EXPORT constexpr int32_t PLAY_INFO_LEN = 20;
29 EXPORT constexpr int32_t VERSION_TAG_LEN = 20;
30 EXPORT constexpr int32_t CINEMAGRAPH_INFO_SIZE_LEN = 4;
31 EXPORT constexpr int32_t MIN_STANDARD_SIZE = LIVE_TAG_LEN + PLAY_INFO_LEN + VERSION_TAG_LEN;
32 
33 class MovingPhotoFileUtils : public PhotoFileUtils {
34 public:
35     EXPORT static int32_t ConvertToMovingPhoto(const std::string &livePhotoPath,
36         const std::string &movingPhotoImagePath, const std::string &movingPhotoVideoPath,
37         const std::string &extraDataPath);
38     EXPORT static int32_t ConvertToLivePhoto(const std::string &movingPhotoImagepath, int64_t coverPosition,
39         std::string &livePhotoPath, int32_t userId = -1);
40     EXPORT static int32_t ConvertToSourceLivePhoto(const std::string &movingPhotoImagepath,
41         std::string &sourceLivePhotoPath, int32_t userId = -1);
42     EXPORT static int32_t GetCoverPosition(const std::string &videoPath, const uint32_t frameIndex,
43         uint64_t &coverPosition, int32_t scene = 0);
44     EXPORT static int32_t GetVersionAndFrameNum(const std::string &tag,
45         uint32_t &version, uint32_t &frameIndex, bool &hasCinemagraphInfo);
46     EXPORT static int32_t GetVersionAndFrameNum(int32_t fd, uint32_t &version, uint32_t &frameIndex,
47         bool &hasCinemagraphInfo);
48     EXPORT static std::string GetMovingPhotoVideoPath(const std::string &imagePath, int32_t userId = -1);
49     EXPORT static std::string GetMovingPhotoExtraDataDir(const std::string &imagePath, int32_t userId = -1);
50     EXPORT static std::string GetMovingPhotoExtraDataPath(const std::string &imagePath, int32_t userId = -1);
51     EXPORT static std::string GetSourceMovingPhotoImagePath(const std::string &imagePath, int32_t userId = -1);
52     EXPORT static std::string GetSourceMovingPhotoVideoPath(const std::string &imagePath, int32_t userId = -1);
53     EXPORT static std::string GetLivePhotoCacheDir(const std::string &imagePath, int32_t userId = -1);
54     EXPORT static std::string GetLivePhotoCachePath(const std::string &imagePath, int32_t userId = -1);
55     EXPORT static std::string GetSourceLivePhotoCachePath(const std::string &imagePath, int32_t userId = -1);
56     EXPORT static bool IsMovingPhoto(int32_t subtype, int32_t effectMode, int32_t originalSubtype);
57     EXPORT static bool IsGraffiti(int32_t subtype, int32_t originalSubtype);
58     EXPORT static bool IsLivePhoto(const std::string &path);
59     EXPORT static int32_t GetExtraDataLen(const std::string &imagePath, const std::string &videoPath,
60         uint32_t frameIndex, off_t &fileSize);
61     EXPORT static uint32_t GetFrameIndex(int64_t time, const int32_t fd);
62 };
63 } // namespace OHOS::Media
64 
65 #endif // FRAMEWORKS_INNERKITSIMPL_MEDIA_LIBRARY_INCLUDE_MOVING_PHOTO_FILE_UTILS_H
66