openharmony 鸿蒙 capi-native-avsource-h

2026-08-25 浏览 (1)

native_avsource.h

Overview

The file declares the APIs 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

Structs

Nametypedef KeywordDescription
OH_AVSourceOH_AVSourceDescribes a native object for the media source interface.

Functions

NameDescription
OH_AVSource *OH_AVSource_CreateWithDataSource(OH_AVDataSource *dataSource)Creates an OH_AVSource instance with a user-defined data source. You can release the instance by calling OH_AVSource_Destroy.
The lifecycle of dataSource must be the same as that of the returned OH_AVSource * pointer.
OH_AVSource *OH_AVSource_CreateWithDataSourceExt(OH_AVDataSourceExt *dataSource, void *userData)Creates an OH_AVSource instance with a user-defined data source. You can release the instance by calling OH_AVSource_Destroy.
User-defined data can be passed to its callback functions through the userData parameter.
The lifecycle of dataSource must be the same as that of the returned OH_AVSource * pointer.
OH_AVSource *OH_AVSource_CreateWithURI(char *uri)Creates an OH_AVSource instance based on a URI. You can release the instance by calling OH_AVSource_Destroy. This function supports only HTTP progressive streaming media, but not HLS/DASH streaming media. For HLS/DASH streaming media playback, use the AVPlayer for development.
OH_AVSource *OH_AVSource_CreateWithFD(int32_t fd, int64_t offset, int64_t size)Creates an OH_AVSource instance based on an FD. You can release the instance by calling OH_AVSource_Destroy.
If 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.
OH_AVErrCode OH_AVSource_Destroy(OH_AVSource *source)Destroys an OH_AVSource 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.
OH_AVFormat *OH_AVSource_GetSourceFormat(OH_AVSource *source)Obtains the basic information about a media resource file.
You must call OH_AVFormat_Destroy to release the OH_AVFormat instance when its lifecycle ends.
OH_AVFormat *OH_AVSource_GetTrackFormat(OH_AVSource *source, uint32_t trackIndex)Obtains the basic information about a track.
You must call OH_AVFormat_Destroy to release the OH_AVFormat instance when its lifecycle ends.
OH_AVFormat *OH_AVSource_GetCustomMetadataFormat(OH_AVSource *source)Obtains the basic information about custom metadata.
You must call OH_AVFormat_Destroy to release the OH_AVFormat instance when its lifecycle ends.

Function Description

OH_AVSource_CreateWithDataSource()

OH_AVSource *OH_AVSource_CreateWithDataSource(OH_AVDataSource *dataSource)

Description

Creates an OH_AVSource instance with a user-defined data source. You can release the instance by calling OH_AVSource_Destroy.
The lifecycle of dataSource must be the same as that of the returned OH_AVSource * pointer.

System capability: SystemCapability.Multimedia.Media.Spliter

Since: 12

Parameters

NameDescription
OH_AVDataSource *dataSourcePointer to user-defined data source.

Returns

TypeDescription
OH_AVSource *Pointer to the OH_AVSource instance created. If the operation fails, NULL is returned.
The possible causes of an operation failure are as follows:
1. The value of dataSource is nullptr.
2. The size of the data source is 0.
3. Setting the data source fails.
4. The memory is insufficient.
5. The decoder engine is nullptr.
6. dataSource->readAt == nullptr.

OH_AVSource_CreateWithDataSourceExt()

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

Description

Creates an OH_AVSource instance with a user-defined data source. You can release the instance by calling OH_AVSource_Destroy.
User-defined data can be passed to its callback functions through the userData parameter.
The lifecycle of dataSource must be the same as that of the returned OH_AVSource * pointer.

System capability: SystemCapability.Multimedia.Media.Spliter

Since: 20

Parameters

NameDescription
OH_AVDataSourceExt *dataSourcePointer to the data source struct, which is used to obtain the input data.
void *userDataPointer to user-defined data.

Returns

TypeDescription
OH_AVSource *Pointer to the OH_AVSource instance created. If the operation fails, NULL is returned.
The possible causes of an operation failure are as follows:
1. The value of dataSource is nullptr.
2. The size of the data source is 0.
3. Setting the data source fails.
4. The memory is insufficient.
5. The decoder engine is nullptr.
6. dataSource->readAt == nullptr.

OH_AVSource_CreateWithURI()

OH_AVSource *OH_AVSource_CreateWithURI(char *uri)

Description

Creates an OH_AVSource instance based on a URI. You can release the instance by calling OH_AVSource_Destroy. This function supports only HTTP progressive streaming media, but not HLS/DASH streaming media. For HLS/DASH streaming media playback, use the AVPlayer for development.

System capability: SystemCapability.Multimedia.Media.Spliter

Since: 10

Parameters

NameDescription
char *uriURI of the media resource.

Returns

TypeDescription
OH_AVSource *Pointer to the OH_AVSource instance created. If the operation fails, NULL is returned.
The possible causes of an operation failure are as follows:
1. The network is abnormal.
2. The resource is invalid.
3. The file format is not supported.
4. The application configuration is intercepted because it contains plaintext data.

OH_AVSource_CreateWithFD()

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

Description

Creates an OH_AVSource instance based on an FD. You can release the instance by calling OH_AVSource_Destroy.
If 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.

System capability: SystemCapability.Multimedia.Media.Spliter

Since: 10

Parameters

NameDescription
int32_t fdFD of a media resource file.
int64_t offsetPosition from which data is to read.
int64_t sizeFile size, in bytes.

Returns

TypeDescription
OH_AVSource *Pointer to the OH_AVSource instance created. If the operation fails, NULL is returned.
The possible causes of an operation failure are as follows:
1. The FD is invalid.
2. The offset is not the start position of the file.
3. The size is incorrect.
4. The resource is invalid.
5. The file format is not supported.

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. 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.

System capability: SystemCapability.Multimedia.Media.Spliter

Since: 10

Parameters

NameDescription
OH_AVSource *sourcePointer to an OH_AVSource instance.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_INVALID_VAL:
1. The value of source is nullptr.
2. The value of source does not point to an OH_AVSource instance.

OH_AVSource_GetSourceFormat()

OH_AVFormat *OH_AVSource_GetSourceFormat(OH_AVSource *source)

Description

Obtains the basic information about a media resource file.
You must call OH_AVFormat_Destroy to release the OH_AVFormat instance when its lifecycle ends.

System capability: SystemCapability.Multimedia.Media.Spliter

Since: 10

Parameters

NameDescription
OH_AVSource *sourcePointer to an OH_AVSource instance.

Returns

TypeDescription
OH_AVFormat *Basic information about the file. If the operation fails, NULL is returned.
The possible causes of an operation failure are as follows:
1. The value of source is nullptr.
2. The pointer is null or does not point to an OH_AVSource instance.
3. The source is not initialized.

OH_AVSource_GetTrackFormat()

OH_AVFormat *OH_AVSource_GetTrackFormat(OH_AVSource *source, uint32_t trackIndex)

Description

Obtains the basic information about a track.
You must call OH_AVFormat_Destroy to release the OH_AVFormat instance when its lifecycle ends.

System capability: SystemCapability.Multimedia.Media.Spliter

Since: 10

Parameters

NameDescription
OH_AVSource *sourcePointer to an OH_AVSource instance.
uint32_t trackIndexIndex of the track whose information is to be obtained.

Returns

TypeDescription
OH_AVFormat *Basic information about the track. If the operation fails, NULL is returned.
The possible causes of an operation failure are as follows:
1. The value of source is invalid (either nullptr or a pointer to a non-OH_AVSource instance).
2. The track index is out of range.
3. The source is not initialized.

OH_AVSource_GetCustomMetadataFormat()

OH_AVFormat *OH_AVSource_GetCustomMetadataFormat(OH_AVSource *source)

Description

Obtains the basic information about custom metadata.
You must call OH_AVFormat_Destroy to release the OH_AVFormat instance when its lifecycle ends.

System capability: SystemCapability.Multimedia.Media.Spliter

Since: 18

Parameters

NameDescription
OH_AVSource *sourcePointer to an OH_AVSource instance.

Returns

TypeDescription
OH_AVFormat *Basic information about the metadata. If the operation fails, NULL is returned.
The possible causes of an operation failure are as follows:
1. The value of source is nullptr.
2. The pointer is null or does not point to an OH_AVSource instance.
3. The source is not initialized.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-native-avcodec-audiocodec-h

openharmony 鸿蒙 capi-avsource-oh-avsource

openharmony 鸿蒙 capi-native-cencinfo-h

openharmony 鸿蒙 capi-avmuxer

openharmony 鸿蒙 capi-multimedia-drm-oh-avcencinfo

openharmony 鸿蒙 capi-native-avdemuxer-h

openharmony 鸿蒙 capi-media-types-h

openharmony 鸿蒙 capi-native-audio-channel-layout-h

openharmony 鸿蒙 capi-native-avbuffer-info-h

openharmony 鸿蒙 capi-codecbase-oh-avcodecasynccallback

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/JuHcgERE