• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# AVDemuxer
2
3
4## Overview
5
6The AVDemuxer module provides the APIs for extracting [samples](../../media/avcodec/audio-video-demuxer.md) from media streams.
7
8For details about the development guide and sample, see [Media Data Demultiplexing](../../media/avcodec/audio-video-demuxer.md).
9
10**System capability**: SystemCapability.Multimedia.Media.Spliter
11
12**Since**: 10
13
14
15## Summary
16
17
18### Files
19
20| Name| Description|
21| -------- | -------- |
22| [native_avdemuxer.h](native__avdemuxer_8h.md) | Declares the APIs for parsing audio and video media data.|
23
24### Types
25
26| Name| Description|
27| -------- | -------- |
28| typedef void(* [DRM_MediaKeySystemInfoCallback](#drm_mediakeysysteminfocallback)) (DRM_MediaKeySystemInfo *mediaKeySystemInfo) | Defines a pointer to the callback function for [DRM_MediaKeySystemInfo](../apis-drm-kit/capi-drm-drm-mediakeysysteminfo.md). No demuxer instance is returned. This callback function applies to the scenario where a single demuxer instance is used. You need to call [OH_AVDemuxer_SetMediaKeySystemInfoCallback](#oh_avdemuxer_setmediakeysysteminfocallback) to set the callback function as a callback. (It is deprecated from API version 14.) |
29| typedef void(* [Demuxer_MediaKeySystemInfoCallback](#demuxer_mediakeysysteminfocallback)) (OH_AVDemuxer *demuxer, DRM_MediaKeySystemInfo *mediaKeySystemInfo)| Defines a pointer to the callback function for [DRM_MediaKeySystemInfo](../apis-drm-kit/capi-drm-drm-mediakeysysteminfo.md). A demuxer instance is returned. This callback function applies to the scenario where multiple demuxer instances are used. You need to call [OH_AVDemuxer_SetDemuxerMediaKeySystemInfoCallback](#oh_avdemuxer_setdemuxermediakeysysteminfocallback) to set the callback function as a callback. This callback function is recommended. |
30
31
32### Functions
33
34| Name| Description|
35| -------- | -------- |
36| OH_AVDemuxer \* [OH_AVDemuxer_CreateWithSource](#oh_avdemuxer_createwithsource) ([OH_AVSource](_a_v_source.md#oh_avsource) \*source) | Creates an OH_AVDemuxer instance based on a source instance.|
37| [OH_AVErrCode](_core.md#oh_averrcode) [OH_AVDemuxer_Destroy](#oh_avdemuxer_destroy) (OH_AVDemuxer \*demuxer) | Destroys an OH_AVDemuxer instance and clears internal resources.|
38| [OH_AVErrCode](_core.md#oh_averrcode) [OH_AVDemuxer_SelectTrackByID](#oh_avdemuxer_selecttrackbyid) (OH_AVDemuxer \*demuxer, uint32_t trackIndex) | Selects a track from which the demuxer reads sample data.|
39| [OH_AVErrCode](_core.md#oh_averrcode) [OH_AVDemuxer_UnselectTrackByID](#oh_avdemuxer_unselecttrackbyid) (OH_AVDemuxer \*demuxer, uint32_t trackIndex) | Deselects a track. The demuxer no longer reads sample data from a track after it is deselected.|
40| [OH_AVErrCode](_core.md#oh_averrcode) [OH_AVDemuxer_ReadSample](#oh_avdemuxer_readsample) (OH_AVDemuxer \*demuxer, uint32_t trackIndex, [OH_AVMemory](_core.md#oh_avmemory) \*sample, [OH_AVCodecBufferAttr](_o_h___a_v_codec_buffer_attr.md) \*info) | Reads the sample and related information from the specified track. (It is deprecated from API version 11.) |
41| [OH_AVErrCode](_core.md#oh_averrcode) [OH_AVDemuxer_ReadSampleBuffer](#oh_avdemuxer_readsamplebuffer) (OH_AVDemuxer \*demuxer, uint32_t trackIndex, [OH_AVBuffer](_core.md#oh_avbuffer) \*sample) | Reads the sample and related information from the specified track.|
42| [OH_AVErrCode](_core.md#oh_averrcode) [OH_AVDemuxer_SeekToTime](#oh_avdemuxer_seektotime) (OH_AVDemuxer \*demuxer, int64_t millisecond, [OH_AVSeekMode](_codec_base.md#oh_avseekmode) mode) | Seeks to the specified time for all the selected tracks based on a [seek mode](_codec_base.md#oh_avseekmode-1). |
43| [OH_AVErrCode](_core.md#oh_averrcode) [OH_AVDemuxer_SetMediaKeySystemInfoCallback](#oh_avdemuxer_setmediakeysysteminfocallback) (OH_AVDemuxer \*demuxer, DRM_MediaKeySystemInfoCallback callback) | Sets an asynchronous callback for obtaining the media key system information. (It is deprecated from API version 14.) |
44| [OH_AVErrCode](_core.md#oh_averrcode) [OH_AVDemuxer_SetDemuxerMediaKeySystemInfoCallback](#oh_avdemuxer_setdemuxermediakeysysteminfocallback) (OH_AVDemuxer \*demuxer, Demuxer_MediaKeySystemInfoCallback callback) | Sets an asynchronous callback for obtaining the media key system information. |
45| [OH_AVErrCode](_core.md#oh_averrcode) [OH_AVDemuxer_GetMediaKeySystemInfo](#oh_avdemuxer_getmediakeysysteminfo) (OH_AVDemuxer \*demuxer, DRM_MediaKeySystemInfo \*mediaKeySystemInfo) | Obtains the media key system information. |
46
47
48## Type Description
49
50### Demuxer_MediaKeySystemInfoCallback
51
52```
53typedef void(* Demuxer_MediaKeySystemInfoCallback) (OH_AVDemuxer *demuxer, DRM_MediaKeySystemInfo *mediaKeySystemInfo)
54```
55
56**Description**
57Defines a pointer to the callback function for the media key system information.
58
59**System capability**: SystemCapability.Multimedia.Media.Spliter
60
61**Since**: 12
62
63
64### DRM_MediaKeySystemInfoCallback
65
66```
67typedef void(* DRM_MediaKeySystemInfoCallback) (DRM_MediaKeySystemInfo *mediaKeySystemInfo)
68```
69
70**Description**
71Defines a pointer to the callback function for the media key system information.
72
73**System capability**: SystemCapability.Multimedia.Media.Spliter
74
75**Since**: 11
76
77**Deprecated from**: 14
78
79**Substitute**: [Demuxer_MediaKeySystemInfoCallback](#demuxer_mediakeysysteminfocallback)
80
81
82## Function Description
83
84
85### OH_AVDemuxer_CreateWithSource()
86
87```
88OH_AVDemuxer* OH_AVDemuxer_CreateWithSource (OH_AVSource *source)
89```
90**Description**
91Creates an OH_AVDemuxer instance based on a source instance.
92
93For details about how to create, destroy, and use a source instance, see [OH_AVSource](_a_v_source.md).
94
95**System capability**: SystemCapability.Multimedia.Media.Spliter
96
97**Since**: 10
98
99**Parameters**
100
101| Name| Description|
102| -------- | -------- |
103| source | Pointer to an OH_AVSource instance. |
104
105**Returns**
106
107Pointer to an OH_AVDemuxer instance.
108
109If the operation fails, NULL is returned.
110
111The possible causes of an operation failure are as follows:
1121. The value of **source** is invalid, that is, nullptr.
1132. The value of **source** does not point to an OH_AVSource instance.
114
115
116### OH_AVDemuxer_Destroy()
117
118```
119OH_AVErrCode OH_AVDemuxer_Destroy (OH_AVDemuxer *demuxer)
120```
121**Description**
122Destroys an OH_AVDemuxer instance and clears internal resources. An 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.
123
124**System capability**: SystemCapability.Multimedia.Media.Spliter
125
126**Since**: 10
127
128**Parameters**
129
130| Name| Description|
131| -------- | -------- |
132| demuxer | Pointer to an OH_AVDemuxer instance. |
133
134**Returns**
135
136One of the following result codes:
137
138**AV_ERR_OK**: The operation is successful.
139
140**AV_ERR_INVALID_VAL**: The value of **demuxer** is nullptr or does not point to a demuxer instance.
141
142
143### OH_AVDemuxer_GetMediaKeySystemInfo()
144
145```
146OH_AVErrCode OH_AVDemuxer_GetMediaKeySystemInfo (OH_AVDemuxer *demuxer, DRM_MediaKeySystemInfo *mediaKeySystemInfo)
147```
148**Description**
149Obtains the media key system information. The media key system information can be obtained only after [Demuxer_MediaKeySystemInfoCallback](#demuxer_mediakeysysteminfocallback) or [DRM_MediaKeySystemInfoCallback](#drm_mediakeysysteminfocallback) is successfully invoked.
150
151**System capability**: SystemCapability.Multimedia.Media.Spliter
152
153**Since**: 11
154
155**Parameters**
156
157| Name| Description|
158| -------- | -------- |
159| demuxer | Pointer to an OH_AVDemuxer instance. |
160| mediaKeySystemInfo | Pointer to the media key system information. For details, see [DRM_MediaKeySystemInfo](../apis-drm-kit/capi-drm-drm-mediakeysysteminfo.md). |
161
162**Returns**
163
164One of the following result codes:
165
166**AV_ERR_OK**: The operation is successful.
167
168**AV_ERR_INVALID_VAL**:
169
170    1. The value of **demuxer** is nullptr or does not point to a demuxer instance.
171    2. The value of **mediaKeySystemInfo** is nullptr.
172
173
174### OH_AVDemuxer_ReadSample()
175
176```
177OH_AVErrCode OH_AVDemuxer_ReadSample (OH_AVDemuxer *demuxer, uint32_t trackIndex, OH_AVMemory *sample, OH_AVCodecBufferAttr *info)
178```
179**Description**
180Reads the sample and related information from the specified track.
181
182You must select a track before reading the sample. After this API is called, the demuxer automatically proceeds to the next frame.
183
184**System capability**: SystemCapability.Multimedia.Media.Spliter
185
186**Since**: 10
187
188**Deprecated from**: 11
189
190**Substitute API**: [OH_AVDemuxer_ReadSampleBuffer](#oh_avdemuxer_readsamplebuffer)
191
192**Parameters**
193
194| Name| Description|
195| -------- | -------- |
196| demuxer | Pointer to an OH_AVDemuxer instance. |
197| trackIndex | Index of the track from which the compressed frame is to be read. |
198| sample | Pointer to the OH_AVMemory instance for storing the compressed frame data. |
199| info | Pointer to the OH_AVCodecBufferAttr instance for storing the compressed frame information. |
200
201**Returns**
202
203One of the following result codes:
204
205**AV_ERR_OK**: The operation is successful.
206
207**AV_ERR_INVALID_VAL**:
208
209    1. The value of **demuxer** is nullptr or does not point to a demuxer instance.
210    2. The track index is out of range.
211    3. Track reading is not supported.
212    4. The value of **sample** is null.
213    5. The value of **info** is null.
214
215**AV_ERR_OPERATE_NOT_PERMIT**:
216
217    1. The track with the specified index is not selected.
218    2. The demuxer is not correctly initialized.
219
220**AV_ERR_NO_MEMORY**: The sample capacity is insufficient to store all frame data.
221
222**AV_ERR_UNKNOWN**: Failed to read or parse the frame from the file.
223
224
225### OH_AVDemuxer_ReadSampleBuffer()
226
227```
228OH_AVErrCode OH_AVDemuxer_ReadSampleBuffer (OH_AVDemuxer *demuxer, uint32_t trackIndex, OH_AVBuffer *sample)
229```
230**Description**
231Reads the sample and related information from the specified track.
232
233You can use [OH_AVDemuxer_SelectTrackByID](#oh_avdemuxer_selecttrackbyid) to select a track before reading the sample. After this API is called, the demuxer automatically proceeds to the next frame.
234
235**System capability**: SystemCapability.Multimedia.Media.Spliter
236
237**Since**: 11
238
239**Parameters**
240
241| Name| Description|
242| -------- | -------- |
243| demuxer | Pointer to an OH_AVDemuxer instance. |
244| trackIndex | Index of the track from which the compressed frame is to be read. |
245| sample | Pointer to the OH_AVBuffer instance for storing the compressed frame data and related information. |
246
247**Returns**
248
249One of the following result codes:
250
251**AV_ERR_OK**: The operation is successful.
252
253**AV_ERR_INVALID_VAL**:
254
255    1. The value of **demuxer** is nullptr or does not point to a demuxer instance.
256    2. The value of **sample** is nullptr.
257    3. The track index is out of range.
258    4. The value of **sample** is null.
259
260**AV_ERR_OPERATE_NOT_PERMIT**:
261
262    1. The track with the specified index is not selected.
263    2. The demuxer is not correctly initialized.
264
265**AV_ERR_NO_MEMORY**: The sample capacity is insufficient to store all frame data.
266
267**AV_ERR_UNKNOWN**: Failed to read or parse the frame from the file.
268
269
270### OH_AVDemuxer_SeekToTime()
271
272```
273OH_AVErrCode OH_AVDemuxer_SeekToTime (OH_AVDemuxer *demuxer, int64_t millisecond, OH_AVSeekMode mode)
274```
275**Description**
276Seeks to the specified time for all the selected tracks based on a [seek mode](_codec_base.md#oh_avseekmode-1).
277
278**System capability**: SystemCapability.Multimedia.Media.Spliter
279
280**Since**: 10
281
282**Parameters**
283
284| Name| Description|
285| -------- | -------- |
286| demuxer | Pointer to an OH_AVDemuxer instance. |
287| millisecond | Time to seek to, in milliseconds. The timestamp is relative to the start position of the file. |
288| mode | Seek mode. For details, see [OH_AVSeekMode](_codec_base.md#oh_avseekmode). |
289
290**Returns**
291
292One of the following result codes:
293
294**AV_ERR_OK**: The operation is successful.
295
296**AV_ERR_INVALID_VAL**:
297
298    1. The value of **demuxer** is nullptr or does not point to a demuxer instance.
299    2. The value of **millisecond** is out of range.
300
301**AV_ERR_OPERATE_NOT_PERMIT**:
302
303    1. The track with the specified index is not selected.
304    2. The demuxer is not correctly initialized.
305    3. The seek operation cannot be performed on the resource.
306
307**AV_ERR_UNKNOWN**:
308
309    1. The seek operation fails.
310    2. **OH_AVSeekMode** is set to **SEEK_MODE_NEXT_SYNC** and there is no I-frame following the specified position.
311
312
313### OH_AVDemuxer_SelectTrackByID()
314
315```
316OH_AVErrCode OH_AVDemuxer_SelectTrackByID (OH_AVDemuxer *demuxer, uint32_t trackIndex)
317```
318**Description**
319Selects a track from which the demuxer reads sample data. You can select multiple tracks by calling this API multiple times, with a different track index passed in each time. When **OH_AVDemuxer_ReadSample** is called, only the data in the selected track is read. If the same track is selected multiple times, **AV_ERR_OK** is returned and the API call takes effect only once.
320
321**System capability**: SystemCapability.Multimedia.Media.Spliter
322
323**Since**: 10
324
325**Parameters**
326
327| Name| Description|
328| -------- | -------- |
329| demuxer | Pointer to an OH_AVDemuxer instance. |
330| trackIndex | Index of the track. |
331
332**Returns**
333
334One of the following result codes:
335
336**AV_ERR_OK**: The operation is successful.
337
338**AV_ERR_OPERATE_NOT_PERMIT**: The demuxer is not correctly initialized.
339
340**AV_ERR_INVALID_VAL**:
341
342    1. The value of **demuxer** is nullptr or does not point to a demuxer instance.
343    2. The track index is out of range.
344    3. Track reading is not supported.
345
346
347### OH_AVDemuxer_SetDemuxerMediaKeySystemInfoCallback()
348
349```
350OH_AVErrCode OH_AVDemuxer_SetDemuxerMediaKeySystemInfoCallback (OH_AVDemuxer *demuxer, Demuxer_MediaKeySystemInfoCallback callback)
351```
352**Description**
353Sets a callback for obtaining the media key system information.
354
355**System capability**: SystemCapability.Multimedia.Media.Spliter
356
357**Since**: 12
358
359**Parameters**
360
361| Name| Description|
362| -------- | -------- |
363| demuxer | Pointer to an OH_AVDemuxer instance. |
364| callback | Callback function. For details, see [Demuxer_MediaKeySystemInfoCallback](#demuxer_mediakeysysteminfocallback). |
365
366**Returns**
367
368One of the following result codes:
369
370**AV_ERR_OK**: The operation is successful.
371
372**AV_ERR_OPERATE_NOT_PERMIT**: The demuxer is not correctly initialized.
373
374**AV_ERR_INVALID_VAL**: The value of **demuxer** is nullptr or does not point to a demuxer instance.
375
376
377### OH_AVDemuxer_SetMediaKeySystemInfoCallback()
378
379```
380OH_AVErrCode OH_AVDemuxer_SetMediaKeySystemInfoCallback (OH_AVDemuxer *demuxer, DRM_MediaKeySystemInfoCallback callback)
381```
382**Description**
383Sets a callback for obtaining the media key system information.
384
385**System capability**: SystemCapability.Multimedia.Media.Spliter
386
387**Since**: 11
388
389**Deprecated from**: 14
390
391**Substitute**: [OH_AVDemuxer_SetDemuxerMediaKeySystemInfoCallback](#oh_avdemuxer_setdemuxermediakeysysteminfocallback)
392
393**Parameters**
394
395| Name| Description|
396| -------- | -------- |
397| demuxer | Pointer to an OH_AVDemuxer instance. |
398| callback | Callback function. For details, see [DRM_MediaKeySystemInfoCallback](#drm_mediakeysysteminfocallback). |
399
400**Returns**
401
402One of the following result codes:
403
404**AV_ERR_OK**: The operation is successful.
405
406**AV_ERR_OPERATE_NOT_PERMIT**: The demuxer is not correctly initialized.
407
408**AV_ERR_INVALID_VAL**: The value of **demuxer** is nullptr or does not point to a demuxer instance.
409
410
411### OH_AVDemuxer_UnselectTrackByID()
412
413```
414OH_AVErrCode OH_AVDemuxer_UnselectTrackByID (OH_AVDemuxer *demuxer, uint32_t trackIndex)
415```
416**Description**
417Deselects a track. The demuxer no longer reads sample data from a track after it is deselected. You can deselect multiple tracks by calling this API multiple times, with a different track index passed in each time. If the same track is deselected multiple times, **AV_ERR_OK** is returned and the API call takes effect only once.
418
419**System capability**: SystemCapability.Multimedia.Media.Spliter
420
421**Since**: 10
422
423**Parameters**
424
425| Name| Description|
426| -------- | -------- |
427| demuxer | Pointer to an OH_AVDemuxer instance. |
428| trackIndex | Index of the track. |
429
430**Returns**
431
432One of the following result codes:
433
434**AV_ERR_OK**: The operation is successful.
435
436**AV_ERR_OPERATE_NOT_PERMIT**: The demuxer is not correctly initialized.
437
438**AV_ERR_INVALID_VAL**: The value of **demuxer** is nullptr or does not point to a demuxer instance.
439