1 /* 2 * Copyright (C) 2023 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 /** 17 * @addtogroup AVSource 18 * @{ 19 * 20 * @brief The AVSource module provides functions for constructing media resource object functionality. 21 * 22 * @syscap SystemCapability.Multimedia.Media.Spliter 23 * @since 10 24 */ 25 26 /** 27 * @file native_avsource.h 28 * 29 * @brief Declare the interface for parsing audio and video media data. 30 * 31 * @kit AVCodecKit 32 * @library libnative_media_avsource.so 33 * @syscap SystemCapability.Multimedia.Media.Spliter 34 * @since 10 35 */ 36 37 #ifndef NATIVE_AVSOURCE_H 38 #define NATIVE_AVSOURCE_H 39 40 #include <stdint.h> 41 #include "native_avcodec_base.h" 42 #include "native_averrors.h" 43 #include "native_avformat.h" 44 45 #ifdef __cplusplus 46 extern "C" { 47 #endif 48 49 /** 50 * @brief Forward declaration of OH_AVSource. 51 * 52 * @since 10 53 */ 54 typedef struct OH_AVSource OH_AVSource; 55 56 /** 57 * @brief Creates an OH_AVSource instance that models the media with dataSource. 58 * @syscap SystemCapability.Multimedia.Media.Spliter 59 * @param dataSource An Struct for a remote media resource. 60 * @return Returns a pointer to an OH_AVSource instance if the execution is successful, otherwise returns nullptr. 61 * Possible failure causes: 62 * 1. dataSource is nullptr. 63 * 2. dataSource->size == 0. 64 * 3. set data source failed. 65 * 4. out of memory. 66 * 5. demuxer engine is nullptr. 67 * @since 12 68 */ 69 OH_AVSource *OH_AVSource_CreateWithDataSource(OH_AVDataSource *dataSource); 70 71 /** 72 * @brief Creates an OH_AVSource instance that models the media at the URI. 73 * @syscap SystemCapability.Multimedia.Media.Spliter 74 * @param uri An URI for a remote media resource. 75 * @return Returns a pointer to an OH_AVSource instance if the execution is successful, otherwise returns nullptr. 76 * Possible failure causes: 77 * 1. network anomaly. 78 * 2. resource is invalid. 79 * 3. file format is not supported. 80 * @since 10 81 */ 82 OH_AVSource *OH_AVSource_CreateWithURI(char *uri); 83 84 /** 85 * @brief Creates an OH_AVSource instance that models the media at the FileDescriptor. 86 * @syscap SystemCapability.Multimedia.Media.Spliter 87 * @param fd The fileDescriptor of data source. 88 * @param offset The offset into the file to start reading. 89 * @param size The file size in bytes. 90 * @return Returns a pointer to an OH_AVSource instance if the execution is successful, otherwise returns nullptr. 91 * Possible failure causes: 92 * 1. fd is invalid. 93 * 2. offset is not start pos of resource. 94 * 3. size error. 95 * 4. resource is invalid. 96 * 5. file format is not supported. 97 * @since 10 98 */ 99 OH_AVSource *OH_AVSource_CreateWithFD(int32_t fd, int64_t offset, int64_t size); 100 101 /** 102 * @brief Destroy the OH_AVSource instance and free the internal resources. 103 * @syscap SystemCapability.Multimedia.Media.Spliter 104 * @param source Pointer to an OH_AVSource instance. 105 * @return Returns AV_ERR_OK if the execution is successful, 106 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 107 * {@link AV_ERR_INVALID_VAL} source is invalid. 108 * @since 10 109 */ 110 OH_AVErrCode OH_AVSource_Destroy(OH_AVSource *source); 111 112 /** 113 * @brief Get the format info of source. 114 * It should be noted that the life cycle of the OH_AVFormat instance pointed to by the return value * needs 115 * to be manually released by the caller. 116 * @syscap SystemCapability.Multimedia.Media.Spliter 117 * @param source Pointer to an OH_AVSource instance. 118 * @return Returns the source's format info if the execution is successful, otherwise returns nullptr. 119 * Possible failure causes: 120 * 1. source is invalid. 121 * @since 10 122 */ 123 OH_AVFormat *OH_AVSource_GetSourceFormat(OH_AVSource *source); 124 125 /** 126 * @brief Get the format info of track. 127 * It should be noted that the life cycle of the OH_AVFormat instance pointed to by the return value * needs 128 * to be manually released by the caller. 129 * @syscap SystemCapability.Multimedia.Media.Spliter 130 * @param source Pointer to an OH_AVSource instance. 131 * @param trackIndex The track index to get format. 132 * @return Returns the track's format info if the execution is successful, otherwise returns nullptr. 133 * Possible failure causes: 134 * 1. source is invalid. 135 * 2. trackIndex is out of range. 136 * @since 10 137 */ 138 OH_AVFormat *OH_AVSource_GetTrackFormat(OH_AVSource *source, uint32_t trackIndex); 139 140 /** 141 * @brief Get the format info of custom metadata. 142 * 143 * It should be noted that the life cycle of the OH_AVFormat instance pointed to by the return value * needs 144 * to be manually released by the caller. 145 * 146 * @syscap SystemCapability.Multimedia.Media.Spliter 147 * @param source Pointer to an OH_AVSource instance. 148 * @return Returns the metadata's format info if the execution is successful, otherwise returns nullptr. 149 * Possible failure causes: 150 * 1. source is invalid. 151 * @since 18 152 */ 153 OH_AVFormat *OH_AVSource_GetCustomMetadataFormat(OH_AVSource *source); 154 155 #ifdef __cplusplus 156 } 157 #endif 158 159 #endif // NATIVE_AVSOURCE_H 160 /** @} */