目录

native_avsource.h

Overview

Declares the interfaces for parsing audio and video media data.

File to include: <multimedia/player_framework/native_avsource.h>

Library: libnative_media_avsource.so

System capability: SystemCapability.Multimedia.Media.Spliter

Since: 10

Related module: AVSource

Sample: AVCodec

Summary

[h2]Structs

Name typedef Keyword Description
OH_AVSource OH_AVSource Defines a native layer object for the media resource interface.

[h2]Function

Name Description
OH_AVSource *OH_AVSource_CreateWithDataSource(OH_AVDataSource *dataSource)

Creates an OH_AVSource instance for a resource object with a user-defined data source. The instance can be released by calling OH_AVSource_Destroy.

The lifecycle of the dataSource parameter must be consistent with that of the returned pointer OH_AVSource *.

OH_AVSource *OH_AVSource_CreateWithDataSourceExt(OH_AVDataSourceExt *dataSource, void *userData)

Creates an OH_AVSource instance for a resource object with a user-defined data source. The instance can be released by calling OH_AVSource_Destroy.

The callback supports passing user-defined data through userData.

The lifecycle of the dataSource parameter must be consistent with that of the returned pointer OH_AVSource *.

OH_AVSource *OH_AVSource_CreateWithURI(char *uri) Creates an OH_AVSource instance for the resource object corresponding to a Uniform Resource Identifier. The instance can be released by calling OH_AVSource_Destroy. This API supports only HTTP progressive streaming, not HLS/DASH streaming. For HLS/DASH streaming playback, use the AVPlayer component.
OH_AVSource *OH_AVSource_CreateWithFD(int32_t fd, int64_t offset, int64_t size)

Creates an OH_AVSource instance for the resource object corresponding to a file descriptor. The instance can be released by calling OH_AVSource_Destroy.

If the offset passed is not the start position of the file, or size is not the file size, undefined errors such as OH_AVSource creation failure or subsequent demuxing failure may occur due to incomplete data retrieval.

OH_AVErrCode OH_AVSource_Destroy(OH_AVSource *source)

Destroys an OH_AVSource instance and cleans up internal resources.

An instance can be destroyed only once. A destroyed instance cannot be used again until it is re-created. It is recommended to set the pointer to NULL after the instance is successfully destroyed.

OH_AVFormat *OH_AVSource_GetSourceFormat(OH_AVSource *source)

Obtains the basic information of a media resource file.

Note that the OH_AVFormat instance pointed to must be released by the caller through OH_AVFormat_Destroy at the end of its lifecycle.

OH_AVFormat *OH_AVSource_GetTrackFormat(OH_AVSource *source, uint32_t trackIndex)

Obtains the basic information of a track.

Note that the OH_AVFormat instance pointed to must be released by the caller through OH_AVFormat_Destroy at the end of its lifecycle.

OH_AVFormat *OH_AVSource_GetCustomMetadataFormat(OH_AVSource *source)

Obtains the basic information of custom metadata.

Note that the OH_AVFormat instance pointed to must be released by the developer through OH_AVFormat_Destroy at the end of its lifecycle.

Function Description

[h2]OH_AVSource_CreateWithDataSource()

OH_AVSource *OH_AVSource_CreateWithDataSource(OH_AVDataSource *dataSource)

Description

Creates an OH_AVSource instance for a resource object with a user-defined data source. The instance can be released by calling OH_AVSource_Destroy.

The lifecycle of the dataSource parameter must be consistent with that of the returned OH_AVSource pointer.

System capability: SystemCapability.Multimedia.Media.Spliter

Since: 12

Parameters

Name Description
OH_AVDataSource *dataSource User-defined data source.

Returns

Type Description
OH_AVSource *

Pointer to the OH_AVSource instance if the operation is successful; NULL otherwise.

Possible causes of failure:

1. dataSource is nullptr.

2. dataSource->size == 0.

3. Failed to set the data source.

4. Insufficient memory.

5. The decoder engine is nullptr.

6. dataSource->readAt == nullptr.

[h2]OH_AVSource_CreateWithDataSourceExt()

OH_AVSource *OH_AVSource_CreateWithDataSourceExt(OH_AVDataSourceExt *dataSource, void *userData)

Description

Creates an OH_AVSource instance for a resource object with a user-defined data source. The instance can be released by calling OH_AVSource_Destroy.

The callback supports passing user-defined data through userData.

The lifecycle of the dataSource parameter must be consistent with that of the returned OH_AVSource pointer.

System capability: SystemCapability.Multimedia.Media.Spliter

Since: 20

Parameters

Name Description
OH_AVDataSourceExt *dataSource Pointer to the data source struct, which is used to obtain input data.
void *userData Pointer to the user-defined data.

Returns

Type Description
OH_AVSource *

Pointer to the OH_AVSource instance if the operation is successful; NULL otherwise.

Possible causes of failure:

1. dataSource is nullptr.

2. dataSource->size == 0.

3. Failed to set the data source.

4. Insufficient memory.

5. The decoder engine is nullptr.

6. dataSource->readAt is nullptr.

[h2]OH_AVSource_CreateWithURI()

OH_AVSource *OH_AVSource_CreateWithURI(char *uri)

Description

Creates an OH_AVSource instance for the resource object corresponding to a Uniform Resource Identifier (URI). The instance can be released by calling OH_AVSource_Destroy. This API supports only HTTP progressive streaming, not HLS/DASH streaming. For HLS/DASH streaming playback, the AVPlayer component is recommended.

System capability: SystemCapability.Multimedia.Media.Spliter

Since: 10

Parameters

Name Description
char *uri Uniform Resource Identifier (URI) of the remote media resource.

Returns

Type Description
OH_AVSource *

Pointer to an OH_AVSource instance if the operation is successful; NULL otherwise.

Possible causes of failure:

1. Network exception.

2. Invalid resource.

3. Unsupported file format.

4. Plaintext interception configured for the app.

[h2]OH_AVSource_CreateWithFD()

OH_AVSource *OH_AVSource_CreateWithFD(int32_t fd, int64_t offset, int64_t size)

Description

Creates an OH_AVSource instance for the resource object corresponding to a file descriptor. The instance can be released by calling OH_AVSource_Destroy.

When this API is called, if the offset passed in is not the start position of the file, or the size is not the file size, OH_AVSource creation or subsequent demuxing may fail due to incomplete data retrieval.

System capability: SystemCapability.Multimedia.Media.Spliter

Since: 10

Parameters

Name Description
int32_t fd File descriptor of the data resource.
int64_t offset Position to start reading data, in bytes.
int64_t size File size in bytes, indicating the length of data that can be read starting from the position specified by offset.

Returns

Type Description
OH_AVSource *

Pointer to an OH_AVSource instance if the operation is successful; NULL otherwise.

Possible failure causes:

1. fd is invalid.

2. offset passed in is not the start position of the file.

3. size is incorrect.

4. The resource is invalid.

5. The file format is not supported.

[h2]OH_AVSource_Destroy()

OH_AVErrCode OH_AVSource_Destroy(OH_AVSource *source)

Description

Destroys an OH_AVSource instance and clears internal resources. An instance can be destroyed only once. A destroyed instance cannot be used again until it is re-created. It is recommended that the pointer be set to NULL after the instance is successfully destroyed.

System capability: SystemCapability.Multimedia.Media.Spliter

Since: 10

Parameters

Name Description
OH_AVSource *source Pointer to the OH_AVSource instance.

Returns

Type Description
OH_AVErrCode

Result code.

AV_ERR_OK: operation successful.

AV_ERR_INVALID_VAL:

1. The source pointer is invalid (null pointer).

2. Not an OH_AVSource instance.

[h2]OH_AVSource_GetSourceFormat()

OH_AVFormat *OH_AVSource_GetSourceFormat(OH_AVSource *source)

Description

Obtains the basic information of a media source file.

Note that the OH_AVFormat instance pointed to must be released by the caller through OH_AVFormat_Destroy at the end of its lifecycle.

System capability: SystemCapability.Multimedia.Media.Spliter

Since: 10

Parameters

Name Description
OH_AVSource *source Pointer to the OH_AVSource instance.

Returns

Type Description
OH_AVFormat *

Pointer to the basic information of the file if the operation is successful; returns NULL otherwise.

Possible failure causes:

1. The source pointer is invalid.

2. Null pointer or non-OH_AVSource instance.

3. The source is not initialized.

[h2]OH_AVSource_GetTrackFormat()

OH_AVFormat *OH_AVSource_GetTrackFormat(OH_AVSource *source, uint32_t trackIndex)

Description

Obtains the basic information of a track.

Note that the caller must release the OH_AVFormat instance pointed to by calling OH_AVFormat_Destroy at the end of its lifecycle.

System capability: SystemCapability.Multimedia.Media.Spliter

Since: 10

Parameters

Name Description
OH_AVSource *source Pointer to the OH_AVSource instance.
uint32_t trackIndex Index of the track whose information is to be obtained.

Returns

Type Description
OH_AVFormat *

Basic information of the track if the operation is successful; NULL otherwise.

Possible causes of failure:

1. The source pointer is invalid, is a null pointer, or is not an OH_AVSource instance.

2. The track index is out of range.

3. The source is not initialized.

[h2]OH_AVSource_GetCustomMetadataFormat()

OH_AVFormat *OH_AVSource_GetCustomMetadataFormat(OH_AVSource *source)

Description

Obtains the basic information of custom metadata.

Note that the caller must release the OH_AVFormat instance pointed to by calling OH_AVFormat_Destroy when its lifecycle ends.

System capability: SystemCapability.Multimedia.Media.Spliter

Since: 18

Parameters

Name Description
OH_AVSource *source Pointer to the OH_AVSource instance.

Returns

Type Description
OH_AVFormat *

Basic information of the metadata if the operation is successful; NULL otherwise.

Possible fault causes:

1. The source pointer is invalid.

2. Null pointer or non-OH_AVSource instance.

3. The source is not initialized.