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_IMPL_H 17 #define INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_ASSET_MANAGER_IMPL_H 18 19 #include "nocopyable.h" 20 #include "media_asset_manager.h" 21 #include "media_library_manager.h" 22 23 namespace OHOS { 24 namespace Media { 25 26 class MediaAssetManagerImpl : public MediaAssetManager, public NoCopyable { 27 public: 28 MediaAssetManagerImpl(); 29 ~MediaAssetManagerImpl(); 30 31 static MultiStagesCapturePhotoStatus QueryPhotoStatus(int32_t fileId, std::string &photoId); 32 static bool NotifyImageDataPrepared(AssetHandler *assetHandler); 33 std::string NativeRequestImage(const char* photoUri, const NativeRequestOptions &requestOptions, 34 const char* destPath, const NativeOnDataPrepared &callback) override; 35 std::string NativeRequestVideo(const char* videoUri, const NativeRequestOptions &requestOptions, 36 const char* destPath, const NativeOnDataPrepared &callback) override; 37 bool NativeCancelRequest(const std::string &requestId) override; 38 39 MediaLibrary_ErrorCode NativeRequestImageSource(OH_MediaAsset* mediaAsset, 40 NativeRequestOptions requestOptions, MediaLibrary_RequestId* requestId, 41 OH_MediaLibrary_OnImageDataPrepared callback) override; 42 MediaLibrary_ErrorCode NativeRequestMovingPhoto(OH_MediaAsset* mediaAsset, 43 NativeRequestOptions requestOptions, MediaLibrary_RequestId* requestId, 44 OH_MediaLibrary_OnMovingPhotoDataPrepared callback) override; 45 static std::mutex mutex_; 46 47 private: 48 void CreateDataHelper(int32_t systemAbilityId); 49 bool OnHandleRequestImage(const std::unique_ptr<RequestSourceAsyncContext> &asyncContext); 50 bool OnHandleRequestVideo(const std::unique_ptr<RequestSourceAsyncContext> &asyncContext); 51 bool NotifyDataPreparedWithoutRegister(const std::unique_ptr<RequestSourceAsyncContext> &asyncContext); 52 void RegisterTaskObserver(const unique_ptr<RequestSourceAsyncContext> &asyncContext); 53 void ProcessImage(const int fileId, const int deliveryMode); 54 static int32_t WriteFileToPath(const std::string &srcUri, const std::string &destPath, bool isSource); 55 static int32_t GetFdFromSandBoxUri(const std::string &sandBoxUri); 56 57 static OH_ImageSourceNative* CreateImageSource(const std::string requestId, const std::string requestUri); 58 59 private: 60 static MediaLibraryManager* mediaLibraryManager_; 61 }; 62 } // Media 63 } // OHOS 64 #endif // INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_ASSET_MANAGER_IMPL_H 65