• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_ASSET_MANAGER_H
17 #define INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_ASSET_MANAGER_H
18 
19 #include <mutex>
20 #include <vector>
21 #include <map>
22 
23 #include "datashare_helper.h"
24 #include "media_asset_data_handler_capi.h"
25 #include "media_asset_base_capi.h"
26 
27 namespace OHOS {
28 namespace Media {
29 using MediaAssetDataHandlerPtr = std::shared_ptr<CapiMediaAssetDataHandler>;
30 
31 enum class MultiStagesCapturePhotoStatus {
32     QUERY_INNER_FAIL = 0,
33     HIGH_QUALITY_STATUS,
34     LOW_QUALITY_STATUS,
35 };
36 
37 struct RequestSourceAsyncContext {
38     int fileId = -1; // default value of request file id
39     std::string requestUri;
40     std::string photoId;
41     std::string displayName;
42     std::string mediaPath;
43     std::string callingPkgName;
44     std::string requestId;
45     std::string destUri;
46     NativeOnDataPrepared onDataPreparedHandler;
47     NativeRequestOptions requestOptions;
48     ReturnDataType returnDataType;
49     OH_MediaLibrary_OnImageDataPrepared onRequestImageDataPreparedHandler;
50     OH_MediaLibrary_OnMovingPhotoDataPrepared onRequestMovingPhotoDataPreparedHandler;
51     MultiStagesCapturePhotoStatus photoQuality = MultiStagesCapturePhotoStatus::HIGH_QUALITY_STATUS;
52     bool needsExtraInfo;
53 };
54 
55 struct AssetHandler {
56     std::string photoId;
57     std::string requestId;
58     std::string requestUri;
59     std::string destUri;
60     MediaAssetDataHandlerPtr dataHandler;
61 
AssetHandlerAssetHandler62     AssetHandler(const std::string &photoId, const std::string &requestId, const std::string &uri,
63         const std::string &destUri, const MediaAssetDataHandlerPtr &handler)
64         : photoId(photoId), requestId(requestId), requestUri(uri), destUri(destUri), dataHandler(handler) {}
65 };
66 
67 class MultiStagesTaskObserver : public DataShare::DataShareObserver {
68 public:
MultiStagesTaskObserver(int fileId)69     MultiStagesTaskObserver(int fileId)
70         : fileId_(fileId) {};
71     void OnChange(const ChangeInfo &changelnfo) override;
72 
73 private:
74     std::map<std::string, AssetHandler *> GetAssetHandlers(const std::string uriString);
75 
76 private:
77     int fileId_;
78 };
79 
80 class MediaAssetManager {
81 public:
82     virtual ~MediaAssetManager() = default;
83 
84 public:
85     virtual bool NativeCancelRequest(const std::string &requestId) = 0;
86     virtual std::string NativeRequestImage(const char* photoUri, const NativeRequestOptions &requestOptions,
87         const char* destPath, const NativeOnDataPrepared &callback) = 0;
88     virtual std::string NativeRequestVideo(const char* videoUri, const NativeRequestOptions &requestOptions,
89         const char* destUri, const NativeOnDataPrepared &callback) = 0;
90 
91     virtual MediaLibrary_ErrorCode NativeRequestImageSource(OH_MediaAsset* mediaAsset,
92         NativeRequestOptions requestOptions, MediaLibrary_RequestId* requestId,
93         OH_MediaLibrary_OnImageDataPrepared callback) = 0;
94     virtual MediaLibrary_ErrorCode NativeRequestMovingPhoto(OH_MediaAsset* mediaAsset,
95         NativeRequestOptions requestOptions, MediaLibrary_RequestId* requestId,
96         OH_MediaLibrary_OnMovingPhotoDataPrepared callback) = 0;
97 };
98 
99 class __attribute__((visibility("default"))) MediaAssetManagerFactory {
100 public:
101     static std::shared_ptr<MediaAssetManager> CreateMediaAssetManager();
102 private:
103     MediaAssetManagerFactory() = default;
104     ~MediaAssetManagerFactory() = default;
105 };
106 } // Media
107 } // OHOS
108 #endif // INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_ASSET_MANAGER_H
109