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_DATA_HANDLER_CAPI_H 17 #define INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_ASSET_DATA_HANDLER_CAPI_H 18 19 #include "stdint.h" 20 #include <string> 21 22 #include "media_asset_base_capi.h" 23 24 namespace OHOS { 25 namespace Media { 26 27 static const int32_t UUID_STR_LENGTH = 37; 28 29 /** 30 * @brief Request Id 31 * 32 * This type is returned when requesting a media library resource. 33 * The request id is used to cancel the request. 34 * The value is all zero like "00000000-0000-0000-0000-000000000000" if the request fails. 35 * @since 12 36 */ 37 typedef struct Native_RequestId { 38 char requestId[UUID_STR_LENGTH]; 39 } Native_RequestId; 40 /** 41 * @brief Delivery Mode 42 * 43 * @since 12 44 */ 45 typedef enum NativeDeliveryMode { 46 /*delivery fast mode*/ 47 FAST_MODE = 0, 48 /*delivery high quality mode*/ 49 HIGH_QUALITY_MODE = 1, 50 /*delivery balanced mode*/ 51 BALANCED_MODE = 2 52 } DeliveryMode; 53 54 /** 55 * @brief Source Mode 56 * 57 * @since 12 58 */ 59 typedef enum NativeSourceMode { 60 /*media source original mode*/ 61 ORIGINAL_MODE = 0, 62 /*media source edited mode*/ 63 EDITED_MODE = 1 64 } NativeSourceMode; 65 66 /** 67 * @brief Compatible Mode 68 * 69 * @since 12 70 */ 71 typedef enum NativeCompatibleMode { 72 /*compatible media source mode*/ 73 ORIGINAL_FORMAT_MODE = 0, 74 /*original media source mode*/ 75 COMPATIBLE_FORMAT_MODE = 1 76 } NativeCompatibleMode; 77 78 /** 79 * @brief Notify Mode 80 * 81 * @since 12 82 */ 83 typedef enum NativeNotifyMode : int32_t { 84 FAST_NOTIFY = 0, 85 WAIT_FOR_HIGH_QUALITY = 1 86 } NativeNotifyMode; 87 88 /** 89 * @brief Called when a requested source is prepared. 90 * 91 * @param result Results of the processing of the requested resources. 92 * @param requestId Request ID. 93 * @since 12 94 */ 95 typedef void (*NativeOnDataPrepared)(int32_t result, Native_RequestId requestId); 96 97 /** 98 * @brief Callback when stage progress is reached. 99 * 100 * @param progress Rate of progress completion. 101 * @since 12 102 */ 103 typedef void (*NativeOnProgressHandler)(uint32_t progress); 104 105 /** 106 * @brief Request Options 107 * 108 * @since 12 109 */ 110 typedef struct NativeRequestOptions { 111 NativeDeliveryMode deliveryMode; 112 NativeSourceMode sourceMode; 113 NativeCompatibleMode compatibleMode; 114 NativeOnProgressHandler handler; 115 } NativeRequestOptions; 116 117 enum class ReturnDataType { 118 TYPE_IMAGE_SOURCE = 0, 119 TYPE_ARRAY_BUFFER, 120 TYPE_MOVING_PHOTO, 121 TYPE_TARGET_FILE, 122 TYPE_PICTURE, 123 }; 124 125 class CapiMediaAssetDataHandler { 126 public: 127 CapiMediaAssetDataHandler(NativeOnDataPrepared dataHandler, ReturnDataType dataType, const std::string &uri, 128 const std::string &destUri, NativeSourceMode sourceMode); 129 CapiMediaAssetDataHandler(OH_MediaLibrary_OnImageDataPrepared imageDataHandler, ReturnDataType dataType, 130 const std::string &uri, const std::string &destUri, NativeSourceMode sourceMode); 131 CapiMediaAssetDataHandler(OH_MediaLibrary_OnMovingPhotoDataPrepared photoDataHandler, ReturnDataType dataType, 132 const std::string &uri, const std::string &destUri, NativeSourceMode sourceMode); 133 ~CapiMediaAssetDataHandler() = default; 134 ReturnDataType GetReturnDataType(); 135 std::string GetRequestUri(); 136 std::string GetDestUri(); 137 NativeSourceMode GetSourceMode(); 138 void SetNotifyMode(NativeNotifyMode trigger); 139 NativeNotifyMode GetNotifyMode(); 140 NativeOnDataPrepared onDataPreparedHandler_ = nullptr; 141 OH_MediaLibrary_OnImageDataPrepared onRequestImageDataPreparedHandler_ = nullptr; 142 OH_MediaLibrary_OnMovingPhotoDataPrepared onRequestMovingPhotoDataPreparedHandler_ = nullptr; 143 int32_t GetPhotoQuality(); 144 void SetPhotoQuality(int32_t photoQuality); 145 146 private: 147 ReturnDataType dataType_; 148 std::string requestUri_; 149 std::string destUri_; 150 NativeSourceMode sourceMode_; 151 NativeNotifyMode notifyMode_ = NativeNotifyMode::FAST_NOTIFY; 152 int32_t photoQuality_ = 0; 153 }; 154 } // Media 155 } // OHOS 156 #endif // INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_ASSET_DATA_HANDLER_CAPI_H 157