From ddcd15e7142af817eb9c75a68cd4b3be6bd02dff Mon Sep 17 00:00:00 2001 From: caochuan Date: Fri, 22 Mar 2024 16:06:06 +0800 Subject: [PATCH] MediaLibrary native api impl Signed-off-by: caochuan --- .../media_library/media_asset_base_capi.h | 130 ++++++++++++++++++ .../media_asset_manager/BUILD.gn | 35 +++++ .../lib_media_asset_namager_capi.ndk.json | 14 ++ .../media_library/media_asset_manager_capi.h | 86 ++++++++++++ 4 files changed, 265 insertions(+) create mode 100644 multimedia/media_library/media_asset_base_capi.h create mode 100644 multimedia/media_library/media_asset_manager/BUILD.gn create mode 100644 multimedia/media_library/media_asset_manager/lib_media_asset_namager_capi.ndk.json create mode 100644 multimedia/media_library/media_asset_manager_capi.h diff --git a/multimedia/media_library/media_asset_base_capi.h b/multimedia/media_library/media_asset_base_capi.h new file mode 100644 index 000000000..522ea1287 --- /dev/null +++ b/multimedia/media_library/media_asset_base_capi.h @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup MediaAssetManager + * @{ + * + * @brief Provides APIs of request capability for Media Source. + * + * The OH_MediaAssetManager structure and OH_RequestId type are used to request media library resources. + * The request can be cancelled using the request ID. + * + * @since 12 + */ + +/** + * @file media_asset_manager.h + * + * @brief Defines the structure and enumeration for Media Asset Manager. + * + * OH_MediaAssetManager structure: This structure provides the ability to request resources from a media library. \n + * OH_RequestId type: This type is returned when requesting a media library resource. + * The request ID is used to cancel the request. \n + * OH_ML_DeliveryMode enumeration: This enumeration defines the delivery mode of the requested resources. \n + * OH_ML_OnDataPrepared function pointer: This function is called when the requested source is prepared. \n + * OH_ML_RequestOptions structure: This structure provides options for requesting media library resources. \n + * + * @Syscap SystemCapability.FileManagement.PhotoAccessHelper.Core + * @library libmedia_asset_manager.so + * @since 12 + */ + +#ifndef MULTIMEDIA_MEDIA_LIBRARY_NATIVE_MEDIA_ASSET_BASE_H +#define MULTIMEDIA_MEDIA_LIBRARY_NATIVE_MEDIA_ASSET_BASE_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Define UUID max length + * + * This macro defines the maximum length of a UUID string. + * + * @since 12 + */ + +const int32_t UUID_STR_MAX_LENGTH = 37; + +/** + * @brief Define Media Asset Manager + * + * This structure provides the ability to request media library resources. + * Null pointer is returned if the creation fails. + * + * @since 12 + */ +typedef struct OH_MediaAssetManager OH_MediaAssetManager; + +/** + * @brief Define OH_RequestId + * + * This type is returned when requesting a media library resource. + * The request id is used to cancel the request. + * The value is all zero like "00000000-0000-0000-0000-000000000000" if the request fails. + * + * @since 12 + */ +typedef struct OH_RequestId { + char requestId[UUID_STR_MAX_LENGTH]; +} OH_RequestId; + +/** + * @brief Delivery Mode + * + * This enumeration defines the delivery mode of the requested resources. + * The delivery mode can be set to fast mode, high quality mode, or balanced mode. + * + * @since 12 + */ +typedef enum OH_ML_DeliveryMode { + /*delivery fast mode*/ + ML_FAST_MODE = 0, + /*delivery high quality mode*/ + ML_HIGH_QUALITY_MODE = 1, + /*delivery balanced mode*/ + ML_BALANCED_MODE = 2 +} OH_ML_DeliveryMode; + +/** + * @brief Called when a requested source is prepared. + * + * This function is called when the requested source is prepared. + * + * @param result Results of the processing of the requested resources. + * @param requestId Request ID. + * @since 12 + */ +typedef void (*OH_ML_OnDataPrepared)(int32_t result, OH_RequestId requestId); + +/** + * @brief Request Options + * + * This structure provides options for requesting media library resources. + * + * @since 12 + */ +typedef struct OH_ML_RequestOptions { + /*delivery mode*/ + OH_ML_DeliveryMode deliveryMode; +} OH_ML_RequestOptions; + +#ifdef __cplusplus +} +#endif +#endif // MULTIMEDIA_MEDIA_LIBRARY_NATIVE_MEDIA_ASSET_BASE_H \ No newline at end of file diff --git a/multimedia/media_library/media_asset_manager/BUILD.gn b/multimedia/media_library/media_asset_manager/BUILD.gn new file mode 100644 index 000000000..57c7fb44c --- /dev/null +++ b/multimedia/media_library/media_asset_manager/BUILD.gn @@ -0,0 +1,35 @@ +# Copyright (C) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/ohos/ndk/ndk.gni") +import("//foundation/multimedia/media_library/media_library.gni") + +ohos_ndk_headers("media_asset_manager_header") { + dest_dir = "$ndk_headers_out_dir/multimedia/media_library" + sources = [ + "../media_asset_base_capi.h", + "../media_asset_manager_capi.h", + ] +} + +ohos_ndk_library("libmedia_asset_manager") { + ndk_description_file = "./lib_media_asset_namager_capi.ndk.json" + output_name = "media_asset_manager" + output_extension = "so" + system_capability = "SystemCapability.FileManagement.PhotoAccessHelper.Core" + system_capability_headers = [ + "multimedia/media_library/media_asset_manager_capi.h", + "multimedia/media_library/media_asset_base_capi.h", + ] +} diff --git a/multimedia/media_library/media_asset_manager/lib_media_asset_namager_capi.ndk.json b/multimedia/media_library/media_asset_manager/lib_media_asset_namager_capi.ndk.json new file mode 100644 index 000000000..7c9dc1ea9 --- /dev/null +++ b/multimedia/media_library/media_asset_manager/lib_media_asset_namager_capi.ndk.json @@ -0,0 +1,14 @@ +[ + { + "first_introduced": "12", + "name": "OH_MediaAssetManager_Create" + }, + { + "first_introduced": "12", + "name": "OH_MediaAssetManager_RequestImageToPath" + }, + { + "first_introduced": "12", + "name": "OH_MediaAssetManager_RequestVideoToPath" + } +] \ No newline at end of file diff --git a/multimedia/media_library/media_asset_manager_capi.h b/multimedia/media_library/media_asset_manager_capi.h new file mode 100644 index 000000000..0abfce894 --- /dev/null +++ b/multimedia/media_library/media_asset_manager_capi.h @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup MediaAssetManager + * @{ + * + * @brief Provides APIs of request capability for Media Source. + * + * @since 12 + */ + +/** + * @file media_asset_manager.h + * + * @brief Defines the media asset manager APIs. + * + * Uses the Native APIs provided by Media Asset Manager + * to reqeust media source. + * + * @Syscap SystemCapability.FileManagement.PhotoAccessHelper.Core + * @library libmedia_asset_manager.so + * @since 12 + */ + +#ifndef MULTIMEDIA_MEDIA_LIBRARY_NATIVE_MEDIA_ASSET_MANAGER_H +#define MULTIMEDIA_MEDIA_LIBRARY_NATIVE_MEDIA_ASSET_MANAGER_H + +#include "media_asset_base_capi.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Create a media asset manager. + * + * @return Returns a pointer to an OH_MediaAssetManager instance. + * @since 12 +*/ +OH_MediaAssetManager *OH_MediaAssetManager_Create(void); + +/** + * @brief Request image source with dest path. + * + * @param manager Pointer to an OH_MediaAssetManager instance. + * @param uri The uri of the requested image resource. + * @param requestOptions Options model for requesting resource. + * @param destPath Destination address of the requested resource. + * @param callBack Called when a requested source is prepared. + * @return Return Request id. + * @since 12 +*/ +OH_RequestId OH_MediaAssetManager_RequestImageToPath(OH_MediaAssetManager* manager, const char* uri, + OH_ML_RequestOptions requestOptions, const char* destPath, OH_ML_OnDataPrepared callBack); + +/** + * @brief Request video source with dest path. + * + * @param manager Pointer to an OH_MediaAssetManager instance. + * @param uri The uri of the requested video resource. + * @param requestOptions Options model for requesting resource. + * @param destPath Destination address of the requested resource. + * @param callBack Called when a requested source is prepared. + * @return Return Request id. + * @since 12 +*/ +OH_RequestId OH_MediaAssetManager_RequestVideoToPath(OH_MediaAssetManager* manager, const char* uri, + OH_ML_RequestOptions requestOptions, const char* destPath, OH_ML_OnDataPrepared callBack); + +#ifdef __cplusplus +} +#endif +#endif // MULTIMEDIA_MEDIA_LIBRARY_NATIVE_MEDIA_ASSET_MANAGER_H \ No newline at end of file -- Gitee