MediaLibrary native api impl

Signed-off-by: caochuan <caochuan@huawei.com>
This commit is contained in:
caochuan 2024-03-22 16:06:06 +08:00
parent e14f5072aa
commit da1c7b815a
4 changed files with 279 additions and 0 deletions

View File

@ -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 MediaLibrary_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
* MediaLibrary_RequestId type: This type is returned when requesting a media library resource.
* The request ID is used to cancel the request. \n
* MediaLibrary_DeliveryMode enumeration: This enumeration defines the delivery mode of the requested resources. \n
* OH_MediaLibrary_OnDataPrepared function pointer: This function is called when the requested source is prepared. \n
* MediaLibrary_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 <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Define UUID max length
*
* This constant defines the maximum length of a UUID string.
*
* @since 12
*/
static 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 MediaLibrary_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 MediaLibrary_RequestId {
/*request id*/
char requestId[UUID_STR_MAX_LENGTH];
} MediaLibrary_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 MediaLibrary_DeliveryMode {
/*delivery fast mode*/
MEDIA_LIBRARY_FAST_MODE = 0,
/*delivery high quality mode*/
MEDIA_LIBRARY_HIGH_QUALITY_MODE = 1,
/*delivery balanced mode*/
MEDIA_LIBRARY_BALANCED_MODE = 2
} MediaLibrary_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_MediaLibrary_OnDataPrepared)(int32_t result, MediaLibrary_RequestId requestId);
/**
* @brief Request Options
*
* This structure provides options for requesting media library resources.
*
* @since 12
*/
typedef struct MediaLibrary_RequestOptions {
/*delivery mode*/
MediaLibrary_DeliveryMode deliveryMode;
} MediaLibrary_RequestOptions;
#ifdef __cplusplus
}
#endif
#endif // MULTIMEDIA_MEDIA_LIBRARY_NATIVE_MEDIA_ASSET_BASE_H

View File

@ -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",
]
}

View File

@ -0,0 +1,18 @@
[
{
"first_introduced": "12",
"name": "OH_MediaAssetManager_Create"
},
{
"first_introduced": "12",
"name": "OH_MediaAssetManager_RequestImageForPath"
},
{
"first_introduced": "12",
"name": "OH_MediaAssetManager_RequestVideoForPath"
},
{
"first_introduced": "12",
"name": "OH_MediaAssetManager_CancelRequest"
}
]

View File

@ -0,0 +1,96 @@
/*
* 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
*/
MediaLibrary_RequestId OH_MediaAssetManager_RequestImageForPath(OH_MediaAssetManager* manager, const char* uri,
MediaLibrary_RequestOptions requestOptions, const char* destPath, OH_MediaLibrary_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
*/
MediaLibrary_RequestId OH_MediaAssetManager_RequestVideoForPath(OH_MediaAssetManager* manager, const char* uri,
MediaLibrary_RequestOptions requestOptions, const char* destPath, OH_MediaLibrary_OnDataPrepared callback);
/**
* @brief Cancel request by request id.
*
* @param manager Pointer to an OH_MediaAssetManager instance.
* @param requestId The request id to be canceled.
* @return Returns true if the request is canceled successfully; returns false otherwise.
* @since 12
*/
bool OH_MediaAssetManager_CancelRequest(OH_MediaAssetManager* manager, const MediaLibrary_RequestId requestId);
#ifdef __cplusplus
}
#endif
#endif // MULTIMEDIA_MEDIA_LIBRARY_NATIVE_MEDIA_ASSET_MANAGER_H