openharmony 鸿蒙 capi-avmedia-source-h

2026-08-25 浏览 (1)

avmedia_source.h

Overview

Defines the struct and enum of AVMediaSource.

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

Library: libavmedia_source.so

System capability: SystemCapability.Multimedia.Media.Core

Since: 23

Related module: avmedia_source

Total

Structs

Nametypedef KeywordDescription
OH_AVHttpHeaderOH_AVHttpHeaderDefines the HTTP header.
OH_AVMediaSourceOH_AVMediaSourceDefines the media source type.
OH_AVMediaSourceLoadingRequestOH_AVMediaSourceLoadingRequestDefines the loading request object, which is used by the application to obtain the location of the requested resource.
OH_AVMediaSourceLoaderOH_AVMediaSourceLoaderDefines the media data loader type, which is implemented by the application.

Enums

Nametypedef KeywordDescription
AVLoadingRequestErrorAVLoadingRequestErrorEnumerates the error codes of network loading requests.

Functions

Nametypedef KeywordDescription
OH_AVHttpHeader *OH_AVHttpHeader_Create(void)-Creates an HTTP header instance.
OH_AVErrCode OH_AVHttpHeader_Destroy(OH_AVHttpHeader *header)-Releases an HTTP header instance.
OH_AVErrCode OH_AVHttpHeader_GetCount(OH_AVHttpHeader *header, uint32_t *count)-Obtains the number of records in an HTTP header instance.
OH_AVErrCode OH_AVHttpHeader_AddRecord(OH_AVHttpHeader *header, const char *key, const char *value)-Adds a key-value pair record to an HTTP header instance.
OH_AVErrCode OH_AVHttpHeader_GetRecord(OH_AVHttpHeader *header, uint32_t index, const char **key, const char **value)-Obtains a key-value pair record in an HTTP header instance by index.
OH_AVMediaSource *OH_AVMediaSource_CreateWithUrl(const char *url, OH_AVHttpHeader *header)-Creates a media source using a URL.
OH_AVMediaSource *OH_AVMediaSource_CreateWithDataSource(OH_AVDataSource *dataSource)-Creates a media source using OH_AVDataSource.
OH_AVMediaSource *OH_AVMediaSource_CreateWithFd(int32_t fd, int64_t offset, int64_t size)-Creates a media source using a file descriptor.
OH_AVErrCode OH_AVMediaSource_Destroy(OH_AVMediaSource *source)-Releases a media source instance.
OH_AVErrCode OH_AVMediaSource_SetMimeType(OH_AVMediaSource *source, const char *mimetype)-Sets the MIME type to process extended media sources.
OH_AVErrCode OH_AVMediaSourceLoadingRequest_GetUrl(OH_AVMediaSourceLoadingRequest *request, const char **url)-Obtains the URL of a request.
OH_AVErrCode OH_AVMediaSourceLoadingRequest_GetHttpHeader(OH_AVMediaSourceLoadingRequest *request, OH_AVHttpHeader **header)-Obtains the HTTP header of a request.
int32_t OH_AVMediaSourceLoadingRequest_RespondData(OH_AVMediaSourceLoadingRequest *request, int64_t uuid, int64_t offset, const uint8_t *data, uint64_t dataSize)-Sends request data to the AVPlayer.
void OH_AVMediaSourceLoadingRequest_RespondHeader(OH_AVMediaSourceLoadingRequest *request, int64_t uuid, OH_AVHttpHeader *header, const char *redirectUrl)-Sends the response header to the AVPlayer. This API must be called before OH_AVMediaSourceLoadingRequest_RespondData is called for the first time.
void OH_AVMediaSourceLoadingRequest_FinishLoading(OH_AVMediaSourceLoadingRequest *request, int64_t uuid, AVLoadingRequestError error)-Notifies the player of the current request status. After pushing all data of a single resource, the application should send the LOADING_ERROR_SUCCESS state to notify the player that the resource push is complete.
OH_AVMediaSourceLoader *OH_AVMediaSourceLoader_Create(void)-Creates an OH_AVMediaSourceLoader instance. If the operation is successful, the OH_AVMediaSourceLoader pointer is returned. If the operation fails, a null pointer is returned.
OH_AVErrCode OH_AVMediaSourceLoader_Destroy(OH_AVMediaSourceLoader *loader)-Releases an OH_AVMediaSourceLoader instance.
OH_AVErrCode OH_AVMediaSource_SetMediaSourceLoader(OH_AVMediaSource *source, OH_AVMediaSourceLoader *loader)-Sets a source loader for the media source instance.
typedef int64_t (*OH_AVMediaSourceLoaderOnSourceOpenedCallback)(OH_AVMediaSourceLoadingRequest *request, void *userData)OH_AVMediaSourceLoaderOnSourceOpenedCallbackDefines the SourceOpenCallback function called by the server. The client should handle the passed request and return the unique handle of the opened resource. The client must return the handle immediately after processing the request.
typedef void (*OH_AVMediaSourceLoaderOnSourceReadCallback)(int64_t uuid, int64_t requestedOffset, int64_t requestedLength, void *userData)OH_AVMediaSourceLoaderOnSourceReadCallbackDefines the SourceReadCallback function called by the server. The client should record the read request and push data using the OH_AVMediaSourceLoadingRequest_RespondData and OH_AVMediaSourceLoadingRequest_RespondHeader methods of the request object when there is sufficient data. The client must return immediately after the request is processed.
typedef void (*OH_AVMediaSourceLoaderOnSourceClosedCallback)(int64_t uuid, void *userData)OH_AVMediaSourceLoaderOnSourceClosedCallbackDefines the SourceCloseCallback function called by the server. The client should release related resources and return immediately after the request is processed.
OH_AVErrCode OH_AVMediaSourceLoader_SetSourceOpenCallback(OH_AVMediaSourceLoader *loader, OH_AVMediaSourceLoaderOnSourceOpenedCallback callback, void *userData)-Sets the open callback function for OH_AVMediaSourceLoader.
OH_AVErrCode OH_AVMediaSourceLoader_SetSourceReadCallback(OH_AVMediaSourceLoader *loader, OH_AVMediaSourceLoaderOnSourceReadCallback callback, void *userData)-Sets the read callback function for OH_AVMediaSourceLoader.
OH_AVErrCode OH_AVMediaSourceLoader_SetSourceCloseCallback(OH_AVMediaSourceLoader *loader, OH_AVMediaSourceLoaderOnSourceClosedCallback callback, void *userData)-Sets the close callback function for OH_AVMediaSourceLoader.

Enum Description

AVLoadingRequestError

enum AVLoadingRequestError

Description

Enumerates the error codes of network loading requests.

Since: 23

Enum ItemDescription
AV_LOADING_ERROR_SUCCESS = 0The resource is successfully downloaded.
AV_LOADING_ERROR_NOT_READY = 1The resource is not ready and cannot be accessed.
AV_LOADING_ERROR_NO_RESOURCE = 2The resource URL does not exist.
AV_LOADING_ERROR_INVALID_HANDLE = 3The UUID of the resource handle is invalid.
AV_LOADING_ERROR_ACCESS_DENIED = 4The client does not have the permission to request the resource.
AV_LOADING_ERROR_ACCESS_TIMEOUT = 5The access times out.
AV_LOADING_ERROR_AUTHORIZE_FAILED = 6The authorization failed.

Function Description

OH_AVHttpHeader_Create()

OH_AVHttpHeader *OH_AVHttpHeader_Create(void)

Description

Creates an HTTP header instance.

Since: 23

Returns

TypeDescription
OH_AVHttpHeader *Pointer to the OH_AVHttpHeader instance if the operation is successful; null pointer if the operation fails.

OH_AVHttpHeader_Destroy()

OH_AVErrCode OH_AVHttpHeader_Destroy(OH_AVHttpHeader *header)

Description

Releases an HTTP header instance.

Since: 23

Parameters

NameDescription
OH_AVHttpHeader *headerPointer to the OH_AVHttpHeader instance.

Returns

TypeDescription
OH_AVErrCodeExecution result of the function.
AV_ERR_OK: The execution is successful.
AV_ERR_INVALID_VAL: The header is a null pointer or the instance fails to be destroyed.

OH_AVHttpHeader_GetCount()

OH_AVErrCode OH_AVHttpHeader_GetCount(OH_AVHttpHeader *header, uint32_t *count)

Description

Obtains the number of records in an HTTP header instance.

Since: 23

Parameters

NameDescription
OH_AVHttpHeader *headerPointer to the OH_AVHttpHeader instance.
uint32_t *countPointer to the number of records in the header instance.

Returns

TypeDescription
OH_AVErrCodeExecution result of the function.
AV_ERR_OK: The execution is successful.
AV_ERR_INVALID_VAL: The header is a null pointer.

OH_AVHttpHeader_AddRecord()

OH_AVErrCode OH_AVHttpHeader_AddRecord(OH_AVHttpHeader *header, const char *key, const char *value)

Description

Adds a key-value pair record to an HTTP header instance.

Since: 23

Parameters

NameDescription
OH_AVHttpHeader *headerPointer to the OH_AVHttpHeader instance.
const char *keyPointer to the key name of the record.
const char *valuePointer to the value of the record.

Returns

TypeDescription
OH_AVErrCodeExecution result of the function.
AV_ERR_OK: The execution is successful.
AV_ERR_INVALID_VAL: Any parameter is a null pointer.

OH_AVHttpHeader_GetRecord()

OH_AVErrCode OH_AVHttpHeader_GetRecord(OH_AVHttpHeader *header, uint32_t index, const char **key, const char **value)

Description

Obtains a key-value pair record in an HTTP header instance by index.

Since: 23

Parameters

NameDescription
OH_AVHttpHeader *headerPointer to the OH_AVHttpHeader instance.
uint32_t indexPosition of the record in the header.
const char **keyDouble pointer to the key name of the record.
const char **valueDouble pointer to the value of the record.

Returns

TypeDescription
OH_AVErrCodeExecution result of the function.
AV_ERR_OK: The execution is successful.
AV_ERR_INVALID_VAL: The header is a null pointer or the index is out of range.

OH_AVMediaSource_CreateWithUrl()

OH_AVMediaSource *OH_AVMediaSource_CreateWithUrl(const char *url, OH_AVHttpHeader *header)

Description

Creates a media source using a URL.

Since: 23

Parameters

NameDescription
const char *urlPointer to the URL of the media source. The following streaming media formats are supported: HLS, HTTP-FLV, DASH, and HTTPS.
OH_AVHttpHeader *headerPointer to the HTTP header attached to the network request.

Returns

TypeDescription
OH_AVMediaSource *Pointer to the OH_AVMediaSource instance if the operation is successful; null pointer if the operation fails.

OH_AVMediaSource_CreateWithDataSource()

OH_AVMediaSource *OH_AVMediaSource_CreateWithDataSource(OH_AVDataSource *dataSource)

Description

Creates a media source using OH_AVDataSource.

Since: 23

Parameters

NameDescription
OH_AVDataSource *dataSourcePointer to OH_AVDataSource.

Returns

TypeDescription
OH_AVMediaSource *Pointer to the OH_AVMediaSource instance if the operation is successful; null pointer if the operation fails.

OH_AVMediaSource_CreateWithFd()

OH_AVMediaSource *OH_AVMediaSource_CreateWithFd(int32_t fd, int64_t offset, int64_t size)

Description

Creates a media source using a file descriptor.

Since: 23

Parameters

NameDescription
int32_t fdFD of a media source file.
int64_t offsetOffset of the file to be read.
int64_t sizeFile size, in bytes

Returns

TypeDescription
OH_AVMediaSource *Pointer to the OH_AVMediaSource instance if the operation is successful; null pointer if the operation fails.

OH_AVMediaSource_Destroy()

OH_AVErrCode OH_AVMediaSource_Destroy(OH_AVMediaSource *source)

Description

Releases a media source instance.

Since: 23

Parameters

NameDescription
OH_AVMediaSource *sourcePointer to the OH_AVMediaSource instance.

Returns

TypeDescription
OH_AVErrCodeExecution result of the function.
AV_ERR_OK: The execution is successful.
AV_ERR_INVALID_VAL: The source is a null pointer or fails to be released.

OH_AVMediaSource_SetMimeType()

OH_AVErrCode OH_AVMediaSource_SetMimeType(OH_AVMediaSource *source, const char *mimetype)

Description

Sets the MIME type to process extended media sources.

Since: 23

Parameters

NameDescription
OH_AVMediaSource *sourcePointer to the OH_AVMediaSource instance.
const char *mimetypePointer to the MIME type (AV_MimeTypes) of the media source.

Returns

TypeDescription
OH_AVErrCodeExecution result of the function.
AV_ERR_OK: The execution is successful.
AV_ERR_INVALID_VAL: The source or mimetype is a null pointer.
AV_ERR_UNSUPPORTED_FORMAT: The mimetype is not supported.

OH_AVMediaSourceLoadingRequest_GetUrl()

OH_AVErrCode OH_AVMediaSourceLoadingRequest_GetUrl(OH_AVMediaSourceLoadingRequest *request, const char **url)

Description

Obtains the URL of a request.

Since: 23

Parameters

NameDescription
OH_AVMediaSourceLoadingRequest *requestPointer to the OH_AVMediaSourceLoadingRequest instance.
const char **urlDouble pointer to the URL for output.

Returns

TypeDescription
OH_AVErrCodeExecution result of the function.
AV_ERR_OK: The execution is successful.
AV_ERR_INVALID_VAL: The request is a null pointer or the URL does not exist.

OH_AVMediaSourceLoadingRequest_GetHttpHeader()

OH_AVErrCode OH_AVMediaSourceLoadingRequest_GetHttpHeader(OH_AVMediaSourceLoadingRequest *request, OH_AVHttpHeader **header)

Description

Obtains the HTTP header of a request.

Since: 23

Parameters

NameDescription
OH_AVMediaSourceLoadingRequest *requestPointer to the OH_AVMediaSourceLoadingRequest instance.
OH_AVHttpHeader **headerDouble pointer to the HTTP header used for the HTTP request.

Returns

TypeDescription
OH_AVErrCodeExecution result of the function.
AV_ERR_OK: The execution is successful.
AV_ERR_INVALID_VAL: The request is a null pointer.

OH_AVMediaSourceLoadingRequest_RespondData()

int32_t OH_AVMediaSourceLoadingRequest_RespondData(OH_AVMediaSourceLoadingRequest *request, int64_t uuid, int64_t offset, const uint8_t *data, uint64_t dataSize)

Description

Sends request data to the AVPlayer.

Since: 23

Parameters

NameDescription
OH_AVMediaSourceLoadingRequest *requestPointer to the request for opening a resource.
int64_t uuidID of the resource handle.
int64_t offsetOffset of the current media data relative to the start of the resource.
const uint8_t *dataPointer to the media data sent to the player.
uint64_t dataSizeLength of the data sent to the player.

Returns

TypeDescription
int32_tNumber of bytes accepted by the current read operation. If the return value is less than 0, the operation fails.
The value -2 indicates that the player no longer needs the current data, and the client should stop the current read process.
The value -3 indicates that the player's buffer is full, and the client should wait for the next read.

OH_AVMediaSourceLoadingRequest_RespondHeader()

void OH_AVMediaSourceLoadingRequest_RespondHeader(OH_AVMediaSourceLoadingRequest *request, int64_t uuid, OH_AVHttpHeader *header, const char *redirectUrl)

Description

Sends the response header to the AVPlayer. This API must be called before OH_AVMediaSourceLoadingRequest_RespondData is called for the first time.

Since: 23

Parameters

NameDescription
OH_AVMediaSourceLoadingRequest *requestPointer to the request for opening a resource.
int64_t uuidID of the resource handle.
OH_AVHttpHeader *headerPointer to the header information in the HTTP response.
The application can intersect the header field with the supported fields at the bottom layer and then pass the intersection result to the AVPlayer, or directly pass all the corresponding header information.
const char *redirectUrlPointer to the redirection URL contained in the HTTP response (if any).

OH_AVMediaSourceLoadingRequest_FinishLoading()

void OH_AVMediaSourceLoadingRequest_FinishLoading(OH_AVMediaSourceLoadingRequest *request, int64_t uuid, AVLoadingRequestError error)

Description

Notifies the player of the current request status. After pushing all data of a single resource, the application should send the LOADING_ERROR_SUCCESS state to notify the player that the resource push is complete.

Since: 23

Parameters

NameDescription
OH_AVMediaSourceLoadingRequest *requestPointer to the request for opening a resource.
int64_t uuidID of the resource handle.
AVLoadingRequestError errorAudio playback is in the error state.

OH_AVMediaSourceLoader_Create()

OH_AVMediaSourceLoader *OH_AVMediaSourceLoader_Create(void)

Description

Creates an OH_AVMediaSourceLoader instance. If the operation is successful, the OH_AVMediaSourceLoader pointer is returned. If the operation fails, a null pointer is returned.

Since: 23

OH_AVMediaSourceLoader_Destroy()

OH_AVErrCode OH_AVMediaSourceLoader_Destroy(OH_AVMediaSourceLoader *loader)

Description

Releases an OH_AVMediaSourceLoader instance.

Since: 23

Parameters

NameDescription
OH_AVMediaSourceLoader *loaderPointer to the OH_AVMediaSourceLoader instance to be released.

Returns

TypeDescription
OH_AVErrCodeExecution result of the function.
AV_ERR_OK: The execution is successful.
AV_ERR_INVALID_VAL: The loader is a null pointer or fails to be released.

OH_AVMediaSource_SetMediaSourceLoader()

OH_AVErrCode OH_AVMediaSource_SetMediaSourceLoader(OH_AVMediaSource *source, OH_AVMediaSourceLoader *loader)

Description

Sets a source loader for the media source instance.

Since: 23

Parameters

NameDescription
OH_AVMediaSource *sourcePointer to the OH_AVMediaSource that requires a network proxy.
OH_AVMediaSourceLoader *loaderPointer to the OH_AVMediaSourceLoader instance.

Returns

TypeDescription
OH_AVErrCodeExecution result of the function.
AV_ERR_OK: The execution is successful.
AV_ERR_INVALID_VAL: The source or loader is a null pointer, or the operation fails.

OH_AVMediaSourceLoaderOnSourceOpenedCallback()

typedef int64_t (*OH_AVMediaSourceLoaderOnSourceOpenedCallback)(OH_AVMediaSourceLoadingRequest *request, void *userData)

Description

Defines the SourceOpenCallback function called by the server. The client should handle the passed request and return the unique handle of the opened resource. The client must return the handle immediately after processing the request.

Since: 23

Parameters

NameDescription
OH_AVMediaSourceLoadingRequest *requestPointer to the request for opening a resource, including the detailed information about the requested resource and the data push mode.
void *userDataPointer to the data set by the user in OH_AVMediaSourceLoader_SetSourceOpenCallback.

Returns

TypeDescription
int64_tHandle of the current resource opening request, which is unique to the request object.
If the value is greater than 0, the request is successful.
Otherwise, the request fails.

OH_AVMediaSourceLoaderOnSourceReadCallback()

typedef void (*OH_AVMediaSourceLoaderOnSourceReadCallback)(int64_t uuid, int64_t requestedOffset, int64_t requestedLength, void *userData)

Description

Defines the SourceReadCallback function called by the server. The client should record the read request and push data using the OH_AVMediaSourceLoadingRequest_RespondData and OH_AVMediaSourceLoadingRequest_RespondHeader methods of the request object when there is sufficient data. The client must return immediately after the request is processed.

Since: 23

Parameters

NameDescription
int64_t uuidID of the resource handle.
int64_t requestedOffsetOffset of the current media data relative to the start of the resource.
int64_t requestedLengthLength of the requested data. The value -1 indicates that the end of the resource has been reached. In this case, call the OH_AVMediaSourceLoadingRequest_FinishLoading method to notify the player that the push is complete.
void *userDataPointer to the data set by the user in OH_AVMediaSourceLoader_SetSourceReadCallback.

OH_AVMediaSourceLoaderOnSourceClosedCallback()

typedef void (*OH_AVMediaSourceLoaderOnSourceClosedCallback)(int64_t uuid, void *userData)

Description

Defines the SourceCloseCallback function called by the server. The client should release related resources and return immediately after the request is processed.

Since: 23

Parameters

NameDescription
int64_t uuidID of the resource handle.
void *userDataPointer to the data set by the user in OH_AVMediaSourceLoader_SetSourceCloseCallback.

OH_AVMediaSourceLoader_SetSourceOpenCallback()

OH_AVErrCode OH_AVMediaSourceLoader_SetSourceOpenCallback(OH_AVMediaSourceLoader *loader, OH_AVMediaSourceLoaderOnSourceOpenedCallback callback, void *userData)

Description

Sets the open callback function for OH_AVMediaSourceLoader.

Since: 23

Parameters

NameDescription
OH_AVMediaSourceLoader *loaderPointer to the OH_AVMediaSourceLoader instance for which the callback function is to be set.
OH_AVMediaSourceLoaderOnSourceOpenedCallback callbackOpen callback function to be set.
void *userDataPointer to the user-defined data used in the callback function.

Returns

TypeDescription
OH_AVErrCodeExecution result of the function.
AV_ERR_OK: The execution is successful.
AV_ERR_INVALID_VAL: The loader is a null pointer or the operation fails.

OH_AVMediaSourceLoader_SetSourceReadCallback()

OH_AVErrCode OH_AVMediaSourceLoader_SetSourceReadCallback(OH_AVMediaSourceLoader *loader, OH_AVMediaSourceLoaderOnSourceReadCallback callback, void *userData)

Description

Sets the read callback function for OH_AVMediaSourceLoader.

Since: 23

Parameters

NameDescription
OH_AVMediaSourceLoader *loaderPointer to the OH_AVMediaSourceLoader instance for which the callback function is to be set.
OH_AVMediaSourceLoaderOnSourceReadCallback callbackRead callback function to be set.
void *userDataPointer to the user-defined data used in the callback function.

Returns

TypeDescription
OH_AVErrCodeExecution result of the function.
AV_ERR_OK: The execution is successful.
AV_ERR_INVALID_VAL: The loader is a null pointer or the operation fails.

OH_AVMediaSourceLoader_SetSourceCloseCallback()

OH_AVErrCode OH_AVMediaSourceLoader_SetSourceCloseCallback(OH_AVMediaSourceLoader *loader, OH_AVMediaSourceLoaderOnSourceClosedCallback callback, void *userData)

Description

Sets the close callback function for OH_AVMediaSourceLoader.

Since: 23

Parameters

NameDescription
OH_AVMediaSourceLoader *loaderPointer to the OH_AVMediaSourceLoader instance for which the callback function is to be set.
OH_AVMediaSourceLoaderOnSourceClosedCallback callbackClose callback function to be set.
void *userDataPointer to the user-defined data used in the callback function.

Returns

TypeDescription
OH_AVErrCodeExecution result of the function.
AV_ERR_OK: The execution is successful.
AV_ERR_INVALID_VAL: The loader is a null pointer or the operation fails.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-avrecorder-oh-avrecorder-range

openharmony 鸿蒙 errorcode-media

openharmony 鸿蒙 capi-avplayer

openharmony 鸿蒙 capi-avplayer-base-h

openharmony 鸿蒙 capi-avimage-generator-h

openharmony 鸿蒙 capi-avscreencapture-oh-rect

openharmony 鸿蒙 capi-videoprocessing-videoprocessing-callback

openharmony 鸿蒙 capi-avsinkbase

openharmony 鸿蒙 capi-avmetadataextractor

openharmony 鸿蒙 capi-avscreencapture-oh-multidisplaycapability

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