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 typedef struct OH_AVSource OH_AVSource;
50 
51 /**
52  * @brief Creates an OH_AVSource instance that models the media with data source.
53  * @syscap SystemCapability.Multimedia.Media.Spliter
54  * @param dataSource User customized media resource.
55  * @return Returns a pointer to an OH_AVSource instance if the execution is successful, otherwise returns nullptr.
56  * Possible failure causes:
57  *  1. dataSource is nullptr.
58  *  2. dataSource->size == 0.
59  *  3. set data source failed.
60  *  4. out of memory.
61  *  5. demuxer engine is nullptr.
62  * @since 12
63 */
64 OH_AVSource *OH_AVSource_CreateWithDataSource(OH_AVDataSource *dataSource);
65 
66 /**
67  * @brief Creates an OH_AVSource instance that models the media at the URI.
68  * @syscap SystemCapability.Multimedia.Media.Spliter
69  * @param uri An URI for a remote media resource.
70  * @return Returns a pointer to an OH_AVSource instance if the execution is successful, otherwise returns nullptr.
71  * Possible failure causes:
72  *  1. network anomaly.
73  *  2. resource is invalid.
74  *  3. file format is not supported.
75  * @since 10
76 */
77 OH_AVSource *OH_AVSource_CreateWithURI(char *uri);
78 
79 /**
80  * @brief Creates an OH_AVSource instance that models the media at the FileDescriptor.
81  * @syscap SystemCapability.Multimedia.Media.Spliter
82  * @param fd The fileDescriptor of data source.
83  * @param offset The offset into the file to start reading.
84  * @param size The file size in bytes.
85  * @return Returns a pointer to an OH_AVSource instance if the execution is successful, otherwise returns nullptr.
86  * Possible failure causes:
87  *  1. fd is invalid.
88  *  2. offset is not start pos of resource.
89  *  3. size error.
90  *  4. resource is invalid.
91  *  5. file format is not supported.
92  * @since 10
93 */
94 OH_AVSource *OH_AVSource_CreateWithFD(int32_t fd, int64_t offset, int64_t size);
95 
96 /**
97  * @brief Destroy the OH_AVSource instance and free the internal resources.
98  * @syscap SystemCapability.Multimedia.Media.Spliter
99  * @param source Pointer to an OH_AVSource instance.
100  * @return Returns AV_ERR_OK if the execution is successful,
101  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}
102  *          {@link AV_ERR_INVALID_VAL} source is invalid.
103  * @since 10
104 */
105 OH_AVErrCode OH_AVSource_Destroy(OH_AVSource *source);
106 
107 /**
108  * @brief Get the format info of source.
109  * @syscap SystemCapability.Multimedia.Media.Spliter
110  * @param source Pointer to an OH_AVSource instance.
111  * @return Returns the source's format info if the execution is successful, otherwise returns nullptr.
112  * Possible failure causes:
113  *  1. source is invalid.
114  * @since 10
115 */
116 OH_AVFormat *OH_AVSource_GetSourceFormat(OH_AVSource *source);
117 
118 /**
119  * @brief Get the format info of track.
120  * @syscap SystemCapability.Multimedia.Media.Spliter
121  * @param source Pointer to an OH_AVSource instance.
122  * @param trackIndex The track index to get format.
123  * @return Returns the track's format info if the execution is successful, otherwise returns nullptr.
124  * Possible failure causes:
125  *  1. source is invalid.
126  *  2. trackIndex is out of range.
127  * @since 10
128 */
129 OH_AVFormat *OH_AVSource_GetTrackFormat(OH_AVSource *source, uint32_t trackIndex);
130 
131 #ifdef __cplusplus
132 }
133 #endif
134 
135 #endif // NATIVE_AVSOURCE_H
136 /** @} */