1# AVSource
2
3
4## Overview
5
6The AVSource module provides the functions for constructing media resource objects.
7
8**System capability**: SystemCapability.Multimedia.Media.Spliter
9
10**Since**: 10
11
12
13## Summary
14
15
16### File
17
18| Name| Description|
19| -------- | -------- |
20| [native_avsource.h](native__avsource_8h.md) | Declares the APIs for parsing audio and video media data. |
21
22
23### Types
24
25| Name| Description|
26| -------- | -------- |
27| typedef struct [OH_AVSource](#oh_avsource) [OH_AVSource](#oh_avsource) | Defines a struct that describes a native object for the media resource interface. |
28
29
30### Functions
31
32| Name| Description|
33| -------- | -------- |
34| [OH_AVSource](#oh_avsource) \* [OH_AVSource_CreateWithDataSource](#oh_avsource_createwithdatasource) ([OH_AVDataSource](_o_h___a_v_data_source.md) \*dataSource) | Creates an **OH_AVSource** instance with a user-defined data source. You can release the instance by calling **OH_AVSource_Destroy**. |
35| [OH_AVSource](#oh_avsource) \* [OH_AVSource_CreateWithURI](#oh_avsource_createwithuri) (char \*uri) | Creates an **OH_AVSource** instance based on a URI. |
36| [OH_AVSource](#oh_avsource) \* [OH_AVSource_CreateWithFD](#oh_avsource_createwithfd) (int32_t fd, int64_t offset, int64_t size) | Creates an **OH_AVSource** instance based on a file descriptor (FD). |
37| [OH_AVErrCode](_core.md#oh_averrcode) [OH_AVSource_Destroy](#oh_avsource_destroy) ([OH_AVSource](#oh_avsource) \*source) | Destroys an **OH_AVSource** instance and clears internal resources. |
38| [OH_AVFormat](_core.md#oh_avformat) \* [OH_AVSource_GetSourceFormat](#oh_avsource_getsourceformat) ([OH_AVSource](#oh_avsource) \*source) | Obtains the basic information about a media resource. |
39| [OH_AVFormat](_core.md#oh_avformat) \* [OH_AVSource_GetTrackFormat](#oh_avsource_gettrackformat) ([OH_AVSource](#oh_avsource) \*source, uint32_t trackIndex) | Obtains the basic information about a track. |
40
41
42## Type Description
43
44
45### OH_AVSource
46
47```
48typedef struct OH_AVSource OH_AVSource
49```
50
51**Description**
52
53Defines a struct that describes a native object for the media resource interface.
54
55**Since**: 10
56
57
58## Function Description
59
60
61### OH_AVSource_CreateWithDataSource()
62
63```
64OH_AVSource* OH_AVSource_CreateWithDataSource (OH_AVDataSource * dataSource)
65```
66
67**Description**
68
69Creates an **OH_AVSource** instance with a user-defined data source. You can release the instance by calling **OH_AVSource_Destroy**.
70
71**System capability**: SystemCapability.Multimedia.Media.Spliter
72
73**Since**: 12
74
75**Parameters**
76
77| Name| Description|
78| -------- | -------- |
79| dataSource | User-defined data source. |
80
81**Returns**
82
83Returns the pointer to the **OH_AVSource** instance created if the operation is successful; returns NULL otherwise.
84
85The possible causes of an operation failure are as follows:
86
871. The value of **dataSource** is a null pointer.
88
892. The size of the data source is 0.
90
913. Setting the data source fails.
92
934. The memory is insufficient.
94
955. The decoder engine is a null pointer.
96
97
98### OH_AVSource_CreateWithFD()
99
100```
101OH_AVSource* OH_AVSource_CreateWithFD (int32_t fd, int64_t offset, int64_t size)
102```
103
104**Description**
105
106Creates an **OH_AVSource** instance based on an FD.
107
108You can release the instance by calling **OH_AVSource_Destroy**.
109
110If **offset** is not the start position of the file or **size** is not the file size, undefined errors such as creation failure and demuxing failure may occur due to incomplete data obtained.
111
112**System capability**: SystemCapability.Multimedia.Media.Spliter
113
114**Since**: 10
115
116**Parameters**
117
118| Name| Description|
119| -------- | -------- |
120| fd | FD of a media resource file. |
121| offset | Position from which data is to read. |
122| size | File size, in bytes. |
123
124**Returns**
125
126Returns the pointer to the **OH_AVSource** instance created if the operation is successful; returns NULL otherwise.
127
128The possible causes of an operation failure are as follows:
129
1301. The FD is invalid.
131
1322. The offset is not the start position of the file.
133
1343. The size is incorrect.
135
1364. The resource is invalid.
137
1385. The file format is not supported.
139
140
141### OH_AVSource_CreateWithURI()
142
143```
144OH_AVSource* OH_AVSource_CreateWithURI (char *uri)
145```
146
147**Description**
148
149Create an **OH_AVSource** instance based on a URI. You can release the instance by calling **OH_AVSource_Destroy**.
150
151**System capability**: SystemCapability.Multimedia.Media.Spliter
152
153**Since**: 10
154
155**Parameters**
156
157| Name| Description|
158| -------- | -------- |
159| uri | URI of the media resource. |
160
161**Returns**
162
163Returns the pointer to the **OH_AVSource** instance created if the operation is successful; returns NULL otherwise.
164
165The possible causes of an operation failure are as follows:
166
1671. The network is abnormal.
168
1692. The resource is invalid.
170
1713. The file format is not supported.
172
173
174### OH_AVSource_Destroy()
175
176```
177OH_AVErrCode OH_AVSource_Destroy (OH_AVSource *source)
178```
179
180**Description**
181
182Destroys an **OH_AVSource** instance and clears internal resources.
183
184An instance can be destroyed only once. The destroyed instance cannot be used until it is re-created. You are advised to set the pointer to **NULL** after the instance is destroyed.
185
186**System capability**: SystemCapability.Multimedia.Media.Spliter
187
188**Since**: 10
189
190**Parameters**
191
192| Name| Description|
193| -------- | -------- |
194| source | Pointer to an **OH_AVSource** instance. |
195
196**Returns**
197
198Returns either of the following result codes:
199
200**AV_ERR_OK**: The operation is successful.
201
202**AV_ERR_INVALID_VAL**: The operation fails.
203
204    1. The source pointer is invalid.
205    2. The pointer is null or does not point to an **OH_AVSource** instance.
206
207
208### OH_AVSource_GetSourceFormat()
209
210```
211OH_AVFormat* OH_AVSource_GetSourceFormat (OH_AVSource *source)
212```
213
214**Description**
215
216Obtains the basic information about a media resource.
217
218**System capability**: SystemCapability.Multimedia.Media.Spliter
219
220**Since**: 10
221
222**Parameters**
223
224| Name| Description|
225| -------- | -------- |
226| source | Pointer to an **OH_AVSource** instance. |
227
228**Returns**
229
230Returns the pointer to the **OH_AVSource** instance created if the operation is successful; returns NULL otherwise.
231
232The possible causes of an operation failure are as follows:
233
2341. The source pointer is invalid.
2352. The pointer is null or does not point to an **OH_AVSource** instance.
2363. The source is not initialized.
237
238
239### OH_AVSource_GetTrackFormat()
240
241```
242OH_AVFormat* OH_AVSource_GetTrackFormat (OH_AVSource *source, uint32_t trackIndex)
243```
244
245**Description**
246
247Obtains the basic information about a track.
248
249**System capability**: SystemCapability.Multimedia.Media.Spliter
250
251**Since**: 10
252
253**Parameters**
254
255| Name| Description|
256| -------- | -------- |
257| source | Pointer to an **OH_AVSource** instance. |
258| trackIndex | Index of the track whose information is to be obtained. |
259
260**Returns**
261
262Returns the basic information about the track if the operation is successful; returns NULL otherwise.
263
264The possible causes of an operation failure are as follows:
265
2661. The value of **source** is invalid (either a null pointer or a pointer to a non-OH_AVSource instance).
2672. The track index is out of range.
2683. The source is not initialized.
269