• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 file. |
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| [OH_AVFormat](_core.md#oh_avformat) \* [OH_AVSource_GetCustomMetadataFormat](#oh_avsource_getcustommetadataformat) ([OH_AVSource](#oh_avsource) \*source) | Obtains the basic information about custom metadata.|
41
42
43## Type Description
44
45
46### OH_AVSource
47
48```
49typedef struct OH_AVSource OH_AVSource
50```
51
52**Description**
53
54Defines a struct that describes a native object for the media resource interface.
55
56**Since**: 10
57
58
59## Function Description
60
61
62### OH_AVSource_CreateWithDataSource()
63
64```
65OH_AVSource* OH_AVSource_CreateWithDataSource (OH_AVDataSource * dataSource)
66```
67
68**Description**
69
70Creates an **OH_AVSource** instance with a user-defined data source. You can release the instance by calling **OH_AVSource_Destroy**.
71
72**System capability**: SystemCapability.Multimedia.Media.Spliter
73
74**Since**: 12
75
76**Parameters**
77
78| Name| Description|
79| -------- | -------- |
80| dataSource | User-defined data source. |
81
82**Returns**
83
84Returns the pointer to the **OH_AVSource** instance created if the operation is successful; returns NULL otherwise.
85
86The possible causes of an operation failure are as follows:
87
881. The value of **dataSource** is a null pointer.
89
902. The size of the data source is 0.
91
923. Setting the data source fails.
93
944. The memory is insufficient.
95
965. The decoder engine is a null pointer.
97
98
99### OH_AVSource_CreateWithFD()
100
101```
102OH_AVSource* OH_AVSource_CreateWithFD (int32_t fd, int64_t offset, int64_t size)
103```
104
105**Description**
106
107Creates an **OH_AVSource** instance based on an FD.
108
109You can release the instance by calling **OH_AVSource_Destroy**.
110
111If **offset** is not the start position of the file or **size** is not the file size, undefined errors such as creation failure and demultiplexing failure may occur due to incomplete data obtained.
112
113**System capability**: SystemCapability.Multimedia.Media.Spliter
114
115**Since**: 10
116
117**Parameters**
118
119| Name| Description|
120| -------- | -------- |
121| fd | FD of a media resource file. |
122| offset | Position from which data is to read. |
123| size | File size, in bytes. |
124
125**Returns**
126
127Returns the pointer to the **OH_AVSource** instance created if the operation is successful; returns NULL otherwise.
128
129The possible causes of an operation failure are as follows:
130
1311. The FD is invalid.
132
1332. The offset is not the start position of the file.
134
1353. The size is incorrect.
136
1374. The resource is invalid.
138
1395. The file format is not supported.
140
141
142### OH_AVSource_CreateWithURI()
143
144```
145OH_AVSource* OH_AVSource_CreateWithURI (char *uri)
146```
147
148**Description**
149
150Create an **OH_AVSource** instance based on a URI. You can release the instance by calling **OH_AVSource_Destroy**.
151
152**System capability**: SystemCapability.Multimedia.Media.Spliter
153
154**Since**: 10
155
156**Parameters**
157
158| Name| Description|
159| -------- | -------- |
160| uri | URI of the media resource. |
161
162**Returns**
163
164Returns the pointer to the **OH_AVSource** instance created if the operation is successful; returns NULL otherwise.
165
166The possible causes of an operation failure are as follows:
167
1681. The network is abnormal.
169
1702. The resource is invalid.
171
1723. The file format is not supported.
173
174
175### OH_AVSource_Destroy()
176
177```
178OH_AVErrCode OH_AVSource_Destroy (OH_AVSource *source)
179```
180
181**Description**
182
183Destroys an **OH_AVSource** instance and clears internal resources.
184
185An 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.
186
187**System capability**: SystemCapability.Multimedia.Media.Spliter
188
189**Since**: 10
190
191**Parameters**
192
193| Name| Description|
194| -------- | -------- |
195| source | Pointer to an **OH_AVSource** instance. |
196
197**Returns**
198
199Returns either of the following result codes:
200
201**AV_ERR_OK**: The operation is successful.
202
203**AV_ERR_INVALID_VAL**: The operation fails.
204
205    1. The source pointer is invalid.
206    2. The pointer is null or does not point to an **OH_AVSource** instance.
207
208
209### OH_AVSource_GetCustomMetadataFormat()
210
211```
212OH_AVFormat *OH_AVSource_GetCustomMetadataFormat(OH_AVSource *source)
213```
214
215**Description**
216
217Obtains the basic information about custom metadata.
218
219The caller must call [OH_AVFormat_Destroy](_core.md#oh_avformat_destroy) to release the **OH_AVFormat** instance when its lifecycle ends.
220
221**System capability**: SystemCapability.Multimedia.Media.Spliter
222
223**Since**: 18
224
225**Parameters**
226
227| Name| Description|
228| -------- | -------- |
229| source | Pointer to an **OH_AVSource** instance.|
230
231**Returns**
232
233Returns the basic information about the metadata if the operation is successful; returns NULL otherwise.
234
235The possible causes of an operation failure are as follows:
236
2371. The source pointer is invalid.
2382. The pointer is null or does not point to an **OH_AVSource** instance.
2393. The source is not initialized.
240
241
242### OH_AVSource_GetSourceFormat()
243
244```
245OH_AVFormat* OH_AVSource_GetSourceFormat (OH_AVSource *source)
246```
247
248**Description**
249
250Obtains the basic information about a media resource file.
251
252The caller must call [OH_AVFormat_Destroy](_core.md#oh_avformat_destroy) to release the **OH_AVFormat** instance when its lifecycle ends.
253
254**System capability**: SystemCapability.Multimedia.Media.Spliter
255
256**Since**: 10
257
258**Parameters**
259
260| Name| Description|
261| -------- | -------- |
262| source | Pointer to an **OH_AVSource** instance. |
263
264**Returns**
265
266Returns the basic information about the file if the operation is successful; returns NULL otherwise.
267
268The possible causes of an operation failure are as follows:
269
2701. The source pointer is invalid.
2712. The pointer is null or does not point to an **OH_AVSource** instance.
2723. The source is not initialized.
273
274
275### OH_AVSource_GetTrackFormat()
276
277```
278OH_AVFormat* OH_AVSource_GetTrackFormat (OH_AVSource *source, uint32_t trackIndex)
279```
280
281**Description**
282
283Obtains the basic information about a track.
284
285The caller must call [OH_AVFormat_Destroy](_core.md#oh_avformat_destroy) to release the **OH_AVFormat** instance when its lifecycle ends.
286
287**System capability**: SystemCapability.Multimedia.Media.Spliter
288
289**Since**: 10
290
291**Parameters**
292
293| Name| Description|
294| -------- | -------- |
295| source | Pointer to an **OH_AVSource** instance. |
296| trackIndex | Index of the track whose information is to be obtained. |
297
298**Returns**
299
300Returns the basic information about the track if the operation is successful; returns NULL otherwise.
301
302The possible causes of an operation failure are as follows:
303
3041. The value of **source** is invalid (either a null pointer or a pointer to a non-OH_AVSource instance).
3052. The track index is out of range.
3063. The source is not initialized.
307