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_KITS_JS_MEDIALIBRARY_INCLUDE_MOVING_PHOTO_NAPI_H 17 #define INTERFACES_KITS_JS_MEDIALIBRARY_INCLUDE_MOVING_PHOTO_NAPI_H 18 19 #include <memory> 20 21 #include "media_asset_data_handler.h" 22 #include "media_asset_manager_napi.h" 23 #include "media_library_napi.h" 24 25 namespace OHOS { 26 namespace Media { 27 28 class MovingPhotoNapi { 29 public: MovingPhotoNapi(const std::string & photoUri)30 MovingPhotoNapi(const std::string& photoUri) : photoUri_(photoUri) {}; 31 ~MovingPhotoNapi() = default; 32 EXPORT static napi_value Init(napi_env env, napi_value exports); 33 static int32_t OpenReadOnlyFile(const string& uri, bool isReadImage); 34 static int32_t OpenReadOnlyLivePhoto(const string& destLivePhotoUri); 35 static napi_value NewMovingPhotoNapi(napi_env env, const string& photoUri, SourceMode sourceMode); 36 std::string GetUri(); 37 SourceMode GetSourceMode(); 38 void SetSourceMode(SourceMode sourceMode); 39 private: 40 EXPORT static napi_value Constructor(napi_env env, napi_callback_info info); 41 EXPORT static void Destructor(napi_env env, void* nativeObject, void* finalizeHint); 42 43 EXPORT static napi_value JSRequestContent(napi_env env, napi_callback_info info); 44 EXPORT static napi_value JSGetUri(napi_env env, napi_callback_info info); 45 46 static thread_local napi_ref constructor_; 47 std::string photoUri_; 48 SourceMode sourceMode_ = SourceMode::EDITED_MODE; 49 }; 50 51 struct MovingPhotoAsyncContext : public NapiError { 52 enum RequestContentMode { 53 WRITE_TO_SANDBOX, 54 WRITE_TO_ARRAY_BUFFER, 55 UNDEFINED, 56 }; 57 58 napi_async_work work; 59 napi_deferred deferred; 60 napi_ref callbackRef; 61 62 std::string movingPhotoUri; 63 SourceMode sourceMode; 64 ResourceType resourceType; 65 std::string destImageUri; 66 std::string destVideoUri; 67 std::string destLivePhotoUri; 68 RequestContentMode requestContentMode = UNDEFINED; 69 void* arrayBufferData = nullptr; 70 size_t arrayBufferLength = 0; 71 }; 72 73 } // Media 74 } // OHOS 75 #endif // INTERFACES_KITS_JS_MEDIALIBRARY_INCLUDE_MOVING_PHOTO_NAPI_H