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 INNER_API_MEDIA_LIBRARY_HELPER_INCLUDE_MEDIA_PHOTO_ASSET_PROXY_H
17 #define INNER_API_MEDIA_LIBRARY_HELPER_INCLUDE_MEDIA_PHOTO_ASSET_PROXY_H
18 
19 #include <string>
20 #include <memory>
21 
22 #include "datashare_helper.h"
23 #include "file_asset.h"
24 #include "photo_proxy.h"
25 #include "userfile_manager_types.h"
26 
27 namespace OHOS {
28 namespace Media {
29 #define EXPORT __attribute__ ((visibility ("default")))
30 // 相机拍摄类型,由相机框架传入
31 enum class CameraShotType : int32_t {
32     IMAGE  = 0, // 图片
33     VIDEO, // 视频
34     MOVING_PHOTO, // 动态照片
35     BURST, // 连拍照片
36 };
37 
38 class VideoAttrs : public RefBase {
39 public:
VideoAttrs()40     VideoAttrs() {}
41     virtual ~VideoAttrs() = default;
42 
43     virtual int32_t GetVideoSize() = 0;
44 };
45 
46 class PhotoAssetProxy {
47 public:
48     PhotoAssetProxy();
49     PhotoAssetProxy(std::shared_ptr<DataShare::DataShareHelper> dataShareHelper, CameraShotType cameraShotType,
50         uint32_t callingUid, int32_t userId);
51     ~PhotoAssetProxy();
52 
53     EXPORT std::unique_ptr<FileAsset> GetFileAsset();
54     EXPORT std::string GetPhotoAssetUri();
55     EXPORT void AddPhotoProxy(const sptr<PhotoProxy> &photoProxy);
56     EXPORT int32_t GetVideoFd();
57     EXPORT void NotifyVideoSaveFinished();
58 
59 private:
60     void CreatePhotoAsset(const sptr<PhotoProxy> &photoProxy);
61     static int SaveImage(int fd, const std::string &uri, const std::string &photoId, void *output, size_t writeSize);
62     static int PackAndSaveImage(int fd, const std::string &uri, const sptr<PhotoProxy> &photoProxy);
63     static int32_t UpdatePhotoQuality(std::shared_ptr<DataShare::DataShareHelper> &dataShareHelper,
64         const sptr<PhotoProxy> &photoProxy, int32_t fileId, int32_t subType);
65     static int SaveLowQualityPhoto(std::shared_ptr<DataShare::DataShareHelper> &dataShareHelper,
66     const sptr<PhotoProxy> &photoProxy, int32_t fileId, int32_t subType);
67     static void DealWithLowQualityPhoto(std::shared_ptr<DataShare::DataShareHelper> &dataShareHelper, int fd,
68         const std::string &uri, const sptr<PhotoProxy> &photoProxy);
69     static void SetShootingModeAndGpsInfo(const uint8_t *data, uint32_t size,
70         const sptr<PhotoProxy> &photoProxy, int fd);
71     static std::string LocationValueToString(double value);
72 
73     static void SetPhotoIdForAsset(const sptr<PhotoProxy> &photoProxy, DataShare::DataShareValuesBucket &values);
74 
75     sptr<PhotoProxy> photoProxy_;
76     int32_t fileId_ {0};
77     std::string uri_;
78     CameraShotType cameraShotType_ = CameraShotType::IMAGE;
79     uint32_t callingUid_ {0};
80     int32_t userId_ {0};
81     PhotoSubType subType_ = PhotoSubType::DEFAULT;
82     bool isMovingPhotoVideoSaved_ = false;
83     std::shared_ptr<DataShare::DataShareHelper> dataShareHelper_;
84 };
85 } // Media
86 } // OHOS
87 #endif // INNER_API_MEDIA_LIBRARY_HELPER_INCLUDE_MEDIA_PHOTO_ASSET_PROXY_H