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 int32_t OpenReadOnlyMetadata(const string& movingPhotoUri); 36 static napi_value NewMovingPhotoNapi(napi_env env, const string& photoUri, SourceMode sourceMode); 37 std::string GetUri(); 38 SourceMode GetSourceMode(); 39 void SetSourceMode(SourceMode sourceMode); 40 private: 41 EXPORT static napi_value Constructor(napi_env env, napi_callback_info info); 42 EXPORT static void Destructor(napi_env env, void* nativeObject, void* finalizeHint); 43 44 EXPORT static napi_value JSRequestContent(napi_env env, napi_callback_info info); 45 EXPORT static napi_value JSGetUri(napi_env env, napi_callback_info info); 46 47 static thread_local napi_ref constructor_; 48 std::string photoUri_; 49 SourceMode sourceMode_ = SourceMode::EDITED_MODE; 50 }; 51 52 struct MovingPhotoAsyncContext : public NapiError { 53 enum RequestContentMode { 54 WRITE_TO_SANDBOX, 55 WRITE_TO_ARRAY_BUFFER, 56 UNDEFINED, 57 }; 58 59 napi_async_work work; 60 napi_deferred deferred; 61 napi_ref callbackRef; 62 63 std::string movingPhotoUri; 64 SourceMode sourceMode; 65 ResourceType resourceType; 66 std::string destImageUri; 67 std::string destVideoUri; 68 std::string destLivePhotoUri; 69 RequestContentMode requestContentMode = UNDEFINED; 70 void* arrayBufferData = nullptr; 71 size_t arrayBufferLength = 0; 72 }; 73 74 } // Media 75 } // OHOS 76 #endif // INTERFACES_KITS_JS_MEDIALIBRARY_INCLUDE_MOVING_PHOTO_NAPI_H