1 /* 2 * Copyright (C) 2023 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_KITS_JS_MEDIALIBRARY_INCLUDE_MEDIA_ASSET_DATA_HANDLER_NAPI_H 17 #define INTERFACES_KITS_JS_MEDIALIBRARY_INCLUDE_MEDIA_ASSET_DATA_HANDLER_NAPI_H 18 19 #include "medialibrary_napi_utils.h" 20 21 namespace OHOS { 22 namespace Media { 23 enum class ReturnDataType { 24 TYPE_IMAGE_SOURCE = 0, 25 TYPE_ARRAY_BUFFER, 26 TYPE_MOVING_PHOTO, 27 TYPE_TARGET_PATH, 28 TYPE_PICTURE, 29 }; 30 31 enum class DeliveryMode { 32 FAST = 0, 33 HIGH_QUALITY, 34 BALANCED_MODE, 35 }; 36 37 enum class SourceMode { 38 ORIGINAL_MODE = 0, 39 EDITED_MODE, 40 }; 41 42 enum class NotifyMode : int32_t { 43 FAST_NOTIFY = 0, 44 WAIT_FOR_HIGH_QUALITY, 45 }; 46 47 enum class CompatibleMode { 48 ORIGINAL_FORMAT_MODE = 0, 49 COMPATIBLE_FORMAT_MODE = 1, 50 }; 51 52 constexpr const char* ON_DATA_PREPARED_FUNC = "onDataPrepared"; 53 constexpr const char* ON_PROGRESS_FUNC = "onProgress"; 54 55 class NapiMediaAssetDataHandler { 56 public: 57 NapiMediaAssetDataHandler(napi_env env, napi_ref dataHandler, ReturnDataType dataType, const std::string &uri, 58 const std::string &destUri, SourceMode sourceMode); 59 void DeleteNapiReference(napi_env env); 60 ReturnDataType GetReturnDataType(); 61 std::string GetRequestUri(); 62 std::string GetDestUri(); 63 SourceMode GetSourceMode(); 64 void SetNotifyMode(NotifyMode trigger); 65 NotifyMode GetNotifyMode(); 66 void JsOnDataPrepared(napi_env env, napi_value exports, napi_value extraInfo); 67 void JsOnDataPrepared(napi_env env, napi_value pictures, napi_value exports, napi_value extraInfo); 68 69 CompatibleMode GetCompatibleMode(); 70 void SetCompatibleMode(const CompatibleMode &compatibleMode); 71 std::string GetRequestId(); 72 void SetRequestId(std::string requestId); 73 private: 74 napi_env env_ = nullptr; 75 napi_ref dataHandlerRef_ = nullptr; 76 ReturnDataType dataType_; 77 std::string requestUri_; 78 std::string destUri_; 79 SourceMode sourceMode_; 80 NotifyMode notifyMode_ = NotifyMode::FAST_NOTIFY; 81 CompatibleMode compatibleMode_; 82 std::string requestId_; 83 static std::mutex dataHandlerRefMutex_; 84 }; 85 } // Media 86 } // OHOS 87 #endif // INTERFACES_KITS_JS_MEDIALIBRARY_INCLUDE_MEDIA_ASSET_DATA_HANDLER_NAPI_H 88