native_avformat.h

Overview

The file declares the functions and enums related to OH_AVFormat.

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

Library: libnative_media_core.so

System capability: SystemCapability.Multimedia.Media.Core

Since: 9

Related module: Core

Sample: AVCodec

Summary

Structs

Name typedef Keyword Description
OH_AVFormat OH_AVFormat Describes a native object for the OH_AVFormat interface.

Enums

Name typedef Keyword Description
OH_AVPixelFormat OH_AVPixelFormat Enumerates the video pixel formats.

Functions

Name Description
struct OH_AVFormat *OH_AVFormat_Create(void) Create an OH_AVFormat instance for reading data.
struct OH_AVFormat *OH_AVFormat_CreateAudioFormat(const char *mimeType, int32_t sampleRate, int32_t channelCount) Creates an audio OH_AVFormat instance with specified parameters for reading and writing data.
struct OH_AVFormat *OH_AVFormat_CreateVideoFormat(const char *mimeType, int32_t width, int32_t height) Creates a video OH_AVFormat instance with specified parameters for reading and writing data.
void OH_AVFormat_Destroy(struct OH_AVFormat *format) Destroys an OH_AVFormat instance. The instance cannot be destroyed repeatedly.
bool OH_AVFormat_Copy(struct OH_AVFormat *to, struct OH_AVFormat *from) Copies an OH_AVFormat instance.
bool OH_AVFormat_SetIntValue(struct OH_AVFormat *format, const char *key, int32_t value) Assigns a value of the int type to a key in an OH_AVFormat instance. This function can be used to set only parameters of the int type. For details, see native_avcodec_base.h.
bool OH_AVFormat_SetUintValue(struct OH_AVFormat *format, const char *key, uint32_t value) Assigns an unsigned int value to the key of OH_AVFormat. This API can be used to set only parameters of the unsigned int type. For details, see native_avcodec_base.h.
bool OH_AVFormat_SetLongValue(struct OH_AVFormat *format, const char *key, int64_t value) Assigns a value of the long type to a key in an OH_AVFormat instance. This function can be used to set only parameters of the long type. For details, see native_avcodec_base.h.
bool OH_AVFormat_SetFloatValue(struct OH_AVFormat *format, const char *key, float value) Assigns a value of the float type to a key in an OH_AVFormat instance. This function can be used to set only parameters of the float type. For details, see native_avcodec_base.h.
bool OH_AVFormat_SetDoubleValue(struct OH_AVFormat *format, const char *key, double value) Assigns a value of the double type to a key in an OH_AVFormat instance. This function can be used to set only parameters of the double type. For details, see native_avcodec_base.h.
bool OH_AVFormat_SetStringValue(struct OH_AVFormat *format, const char *key, const char *value) Assigns a value of the string type to a key in an OH_AVFormat instance. This function can be used to set only parameters of the string type. For details, see native_avcodec_base.h.
bool OH_AVFormat_SetBuffer(struct OH_AVFormat *format, const char *key, const uint8_t *addr, size_t size) Writes data blocks of a specified length to an OH_AVFormat instance. This function can be used to set only parameters of the buffer type. For details, see native_avcodec_base.h.
bool OH_AVFormat_GetIntValue(struct OH_AVFormat *format, const char *key, int32_t *out) Obtains the value of the int type of a key in an OH_AVFormat instance.
bool OH_AVFormat_GetUintValue(struct OH_AVFormat *format, const char *key, uint32_t *out) Obtains the value of the unsigned int type from an OH_AVFormat instance using a key
bool OH_AVFormat_GetLongValue(struct OH_AVFormat *format, const char *key, int64_t *out) Obtains the value of the long type of a key in an OH_AVFormat instance.
bool OH_AVFormat_GetFloatValue(struct OH_AVFormat *format, const char *key, float *out) Obtains the value of the float type of a key in an OH_AVFormat instance.
bool OH_AVFormat_GetDoubleValue(struct OH_AVFormat *format, const char *key, double *out) Obtains the value of the double type of a key in an OH_AVFormat instance.
bool OH_AVFormat_GetStringValue(struct OH_AVFormat *format, const char *key, const char **out) Obtains the value of the string type of a key in an OH_AVFormat instance.
bool OH_AVFormat_GetBuffer(struct OH_AVFormat *format, const char *key, uint8_t **addr, size_t *size) Reads data blocks of a specified length from an OH_AVFormat instance.
bool OH_AVFormat_GetIntBuffer(struct OH_AVFormat *format, const char *key, int32_t **addr, size_t *size) Reads an array of int32_t data from an OH_AVFormat instance.
Note that the buffer lifecycle is bound to the OH_AVFormat instance. The buffer becomes invalid automatically when the OH_AVFormat instance is destroyed.
To keep the data for an extended period, explicitly copy the data to newly allocated memory.
const char *OH_AVFormat_DumpInfo(struct OH_AVFormat *format) Returns a string consisting of key-value pairs in an OH_AVFormat instance. A string of up to 1024 bytes can be returned. The string pointer is released when the OH_AVFormat instance is destroyed.
bool OH_AVFormat_SetIntBuffer(struct OH_AVFormat *format, const char *key, const int32_t *addr, size_t size) Writes data blocks of the int32_t type with a specified length to an OH_AVFormat instance.
uint32_t OH_AVFormat_GetKeyCount(OH_AVFormat *format) Obtains the total number of keys in an OH_AVFormat instance.
bool OH_AVFormat_GetKey(OH_AVFormat *format, uint32_t index, const char **key) Obtains the key name string from an OH_AVFormat instance by index.

Enum Description

OH_AVPixelFormat

enum OH_AVPixelFormat

Description

Enumerates the video pixel formats.

System capability: SystemCapability.Multimedia.Media.Core

Since: 9

Value Description
AV_PIXEL_FORMAT_YUVI420 = 1 YUV 420 Planar.
AV_PIXEL_FORMAT_NV12 = 2 NV12. YUV 420 semi-planar.
AV_PIXEL_FORMAT_NV21 = 3 NV21. YVU 420 semi-planar.
AV_PIXEL_FORMAT_SURFACE_FORMAT = 4 Pixel format obtained from the surface. This value takes effect only in surface mode.
AV_PIXEL_FORMAT_RGBA = 5 RGBA8888.
AV_PIXEL_FORMAT_RGBA1010102 = 6 RGBA1010102.
Since: 20

Function Description

OH_AVFormat_Create()

struct OH_AVFormat *OH_AVFormat_Create(void)

Description

Create an OH_AVFormat instance for reading data.

System capability: SystemCapability.Multimedia.Media.Core

Since: 9

Returns

Type Description
struct OH_AVFormat * Pointer to an OH_AVFormat instance. If system resources are insufficient, NULL is returned.

OH_AVFormat_CreateAudioFormat()

struct OH_AVFormat *OH_AVFormat_CreateAudioFormat(const char *mimeType, int32_t sampleRate, int32_t channelCount)

Description

Creates an audio OH_AVFormat instance with specified parameters for reading and writing data.

System capability: SystemCapability.Multimedia.Media.Core

Since: 10

Parameters

Name Description
const char *mimeType Pointer to a string that describes the MIME type. For details, see AVCODEC_MIMETYPE.
int32_t sampleRate Sampling rate, in Hz.
int32_t channelCount Number of audio channels. For example, 1 indicates mono and 2 indicates stereo.

Returns

Type Description
struct OH_AVFormat * Pointer to the OH_AVFormat instance created. If the operation fails, NULL is returned.
The possible causes of an operation failure are as follows:
1. The value of mimeType is NULL.
2. System resources are insufficient.

OH_AVFormat_CreateVideoFormat()

struct OH_AVFormat *OH_AVFormat_CreateVideoFormat(const char *mimeType, int32_t width, int32_t height)

Description

Creates a video OH_AVFormat instance with specified parameters for reading and writing data.

System capability: SystemCapability.Multimedia.Media.Core

Since: 10

Parameters

Name Description
const char *mimeType Pointer to a string that describes the MIME type. For details, see AVCODEC_MIMETYPE.
int32_t width Image width, in pixels.
int32_t height Image height, in pixels.

Returns

Type Description
struct OH_AVFormat * Pointer to the OH_AVFormat instance created. If the operation fails, NULL is returned.
The possible causes of an operation failure are as follows:
1. The value of mimeType is NULL.
2. System resources are insufficient.

OH_AVFormat_Destroy()

void OH_AVFormat_Destroy(struct OH_AVFormat *format)

Description

Destroys an OH_AVFormat instance. The instance cannot be destroyed repeatedly.

System capability: SystemCapability.Multimedia.Media.Core

Since: 9

Parameters

Name Description
struct OH_AVFormat *format Pointer to an OH_AVFormat instance.

OH_AVFormat_Copy()

bool OH_AVFormat_Copy(struct OH_AVFormat *to, struct OH_AVFormat *from)

Description

Copies an OH_AVFormat instance.

System capability: SystemCapability.Multimedia.Media.Core

Since: 9

Parameters

Name Description
struct OH_AVFormat *to Pointer to the OH_AVFormat instance to which the data will be copied.
struct OH_AVFormat *from Pointer to the OH_AVFormat instance from which the data will be copied.

Returns

Type Description
bool true if the operation is successful; false otherwise.
The possible causes of an operation failure are as follows:
1. The input parameter is nullptr.
2. The value of OH_AVFormat fails parameter structure verification.

OH_AVFormat_SetIntValue()

bool OH_AVFormat_SetIntValue(struct OH_AVFormat *format, const char *key, int32_t value)

Description

Assigns a value of the int type to a key in an OH_AVFormat instance. This function can be used to set only parameters of the int type. For details, see native_avcodec_base.h.

System capability: SystemCapability.Multimedia.Media.Core

Since: 9

Parameters

Name Description
struct OH_AVFormat *format Pointer to an OH_AVFormat instance.
const char *key Pointer to the key of the data to write.
int32_t value Value of the data to write.

Returns

Type Description
bool true if the operation is successful; false otherwise.
The possible causes of an operation failure are as follows:
1. The value of format is nullptr.
2. The value of format fails parameter structure verification.
3. The value of key is nullptr.
4. The value type corresponding to the key is incorrect.

OH_AVFormat_SetUintValue()

bool OH_AVFormat_SetUintValue(struct OH_AVFormat *format, const char *key, uint32_t value)

Description

Assigns an unsigned int value to the key of an OH_AVFormat instance. This API can be used to set only parameters of the unsigned int type. For details, see native_avcodec_base.h.

Since: 23

Parameters

Name Description
struct OH_AVFormat *format Pointer to an OH_AVFormat instance.
const char *key Pointer to the key of the data to write.
uint32_t value Value of the data to write.

Returns

Type Description
bool true if the operation is successful; false otherwise.
The possible causes of an operation failure are as follows:
1. The value of format is nullptr.
2. The value of format fails parameter structure verification.
3. The value of key is nullptr.

OH_AVFormat_SetLongValue()

bool OH_AVFormat_SetLongValue(struct OH_AVFormat *format, const char *key, int64_t value)

Description

Assigns a value of the long type to a key in an OH_AVFormat instance. This function can be used to set only parameters of the long type. For details, see native_avcodec_base.h.

System capability: SystemCapability.Multimedia.Media.Core

Since: 9

Parameters

Name Description
struct OH_AVFormat *format Pointer to an OH_AVFormat instance.
const char *key Pointer to the key of the data to write.
int64_t value Value of the data to write.

Returns

Type Description
bool true if the operation is successful; false otherwise.
The possible causes of an operation failure are as follows:
1. The value of format is nullptr.
2. The value of format fails parameter structure verification.
3. The value of key is nullptr.
4. The value type corresponding to the key is incorrect.

OH_AVFormat_SetFloatValue()

bool OH_AVFormat_SetFloatValue(struct OH_AVFormat *format, const char *key, float value)

Description

Assigns a value of the float type to a key in an OH_AVFormat instance. This function can be used to set only parameters of the float type. For details, see native_avcodec_base.h.

System capability: SystemCapability.Multimedia.Media.Core

Since: 9

Parameters

Name Description
struct OH_AVFormat *format Pointer to an OH_AVFormat instance.
const char *key Pointer to the key of the data to write.
float value Value of the data to write.

Returns

Type Description
bool true if the operation is successful; false otherwise.
The possible causes of an operation failure are as follows:
1. The value of format is nullptr.
2. The value of format fails parameter structure verification.
3. The value of key is nullptr.
4. The value type corresponding to the key is incorrect.

OH_AVFormat_SetDoubleValue()

bool OH_AVFormat_SetDoubleValue(struct OH_AVFormat *format, const char *key, double value)

Description

Assigns a value of the double type to a key in an OH_AVFormat instance. This function can be used to set only parameters of the double type. For details, see native_avcodec_base.h.

System capability: SystemCapability.Multimedia.Media.Core

Since: 9

Parameters

Name Description
struct OH_AVFormat *format Pointer to an OH_AVFormat instance.
const char *key Pointer to the key of the data to write.
double value Value of the data to write.

Returns

Type Description
bool true if the operation is successful; false otherwise.
The possible causes of an operation failure are as follows:
1. The value of format is nullptr.
2. The value of format fails parameter structure verification.
3. The value of key is nullptr.
4. The value type corresponding to the key is incorrect.

OH_AVFormat_SetStringValue()

bool OH_AVFormat_SetStringValue(struct OH_AVFormat *format, const char *key, const char *value)

Description

Assigns a value of the string type to a key in an OH_AVFormat instance. This function can be used to set only parameters of the string type. For details, see native_avcodec_base.h.

System capability: SystemCapability.Multimedia.Media.Core

Since: 9

Parameters

Name Description
struct OH_AVFormat *format Pointer to an OH_AVFormat instance.
const char *key Pointer to the key of the data to write.
const char *value Pointer to the data to be written to the string. The length should not exceed 256 bytes.

Returns

Type Description
bool true if the operation is successful; false otherwise.
The possible causes of an operation failure are as follows:
1. The value of format is nullptr.
2. The value of format fails parameter structure verification.
3. The value of key is nullptr.
4. The passed-in value of value is a null pointer.
5. The value type corresponding to the key is incorrect.

OH_AVFormat_SetBuffer()

bool OH_AVFormat_SetBuffer(struct OH_AVFormat *format, const char *key, const uint8_t *addr, size_t size)

Description

Writes data blocks of a specified length to an OH_AVFormat instance. This function can be used to set only parameters of the buffer type. For details, see native_avcodec_base.h.

System capability: SystemCapability.Multimedia.Media.Core

Since: 9

Parameters

Name Description
struct OH_AVFormat *format Pointer to an OH_AVFormat instance.
const char *key Pointer to the key of the data to write.
const uint8_t *addr Pointer to the address to which data is written. The lifecycle is managed by the developer.
size_t size Length of the data written, in MB. The value range is (0, 1].

Returns

Type Description
bool true if the operation is successful; false otherwise.
The possible causes of an operation failure are as follows:
1. The value of format is nullptr.
2. The value of format fails parameter structure verification.
3. The value of key is nullptr.
4. The value of addr is nullptr.
5. The size is 0 or exceeds the upper limit 1 MB.
6. The value type corresponding to the key is incorrect.

OH_AVFormat_GetIntValue()

bool OH_AVFormat_GetIntValue(struct OH_AVFormat *format, const char *key, int32_t *out)

Description

Obtains the value of the int type of a key in an OH_AVFormat instance.

System capability: SystemCapability.Multimedia.Media.Core

Since: 9

Parameters

Name Description
struct OH_AVFormat *format Pointer to an OH_AVFormat instance.
const char *key Pointer to the key of the data to read.
int32_t *out Pointer to the value of the data read.

Returns

Type Description
bool true if the operation is successful; false otherwise.
The possible causes of an operation failure are as follows:
1. The value of format is nullptr.
2. The value of format fails parameter structure verification.
3. The value of key is nullptr.
4. The value of out is nullptr.
5. The obtained key does not exist or is not set.

OH_AVFormat_GetUintValue()

bool OH_AVFormat_GetUintValue(struct OH_AVFormat *format, const char *key, uint32_t *out)

Description

Obtains the value of the unsigned int type from an OH_AVFormat instance using a key.

Since: 23

Parameters

Name Description
struct OH_AVFormat *format Pointer to an OH_AVFormat instance.
const char *key Pointer to the key of the data to read.
uint32_t *out Pointer to the value of the data read.

Returns

Type Description
bool true if the operation is successful; false otherwise.
The possible causes of an operation failure are as follows:
1. The value of format is nullptr.
2. The value of format fails parameter structure verification.
3. The value of key is nullptr.
4. The value of out is nullptr.

OH_AVFormat_GetLongValue()

bool OH_AVFormat_GetLongValue(struct OH_AVFormat *format, const char *key, int64_t *out)

Description

Obtains the value of the long type of a key in an OH_AVFormat instance.

System capability: SystemCapability.Multimedia.Media.Core

Since: 9

Parameters

Name Description
struct OH_AVFormat *format Pointer to an OH_AVFormat instance.
const char *key Pointer to the key of the data to read.
int64_t *out Pointer to the value of the data read.

Returns

Type Description
bool true if the operation is successful; false otherwise.
The possible causes of an operation failure are as follows:
1. The value of format is nullptr.
2. The value of format fails parameter structure verification.
3. The value of key is nullptr.
4. The value of out is nullptr.
5. The obtained key does not exist or is not set.

OH_AVFormat_GetFloatValue()

bool OH_AVFormat_GetFloatValue(struct OH_AVFormat *format, const char *key, float *out)

Description

Obtains the value of the float type of a key in an OH_AVFormat instance.

System capability: SystemCapability.Multimedia.Media.Core

Since: 9

Parameters

Name Description
struct OH_AVFormat *format Pointer to an OH_AVFormat instance.
const char *key Pointer to the key of the data to read.
float *out Pointer to the value of the data read.

Returns

Type Description
bool true if the operation is successful; false otherwise.
The possible causes of an operation failure are as follows:
1. The value of format is nullptr.
2. The value of format fails parameter structure verification.
3. The value of key is nullptr.
4. The value of out is nullptr.
5. The obtained key does not exist or is not set.

OH_AVFormat_GetDoubleValue()

bool OH_AVFormat_GetDoubleValue(struct OH_AVFormat *format, const char *key, double *out)

Description

Obtains the value of the double type of a key in an OH_AVFormat instance.

System capability: SystemCapability.Multimedia.Media.Core

Since: 9

Parameters

Name Description
struct OH_AVFormat *format Pointer to an OH_AVFormat instance.
const char *key Pointer to the key of the data to read.
double *out Pointer to the value of the data read.

Returns

Type Description
bool true if the operation is successful; false otherwise.
The possible causes of an operation failure are as follows:
1. The value of format is nullptr.
2. The value of format fails parameter structure verification.
3. The value of key is nullptr.
4. The value of out is nullptr.
5. The obtained key does not exist or is not set.

OH_AVFormat_GetStringValue()

bool OH_AVFormat_GetStringValue(struct OH_AVFormat *format, const char *key, const char **out)

Description

Obtains the value of the string type of a key in an OH_AVFormat instance.

System capability: SystemCapability.Multimedia.Media.Core

Since: 9

Parameters

Name Description
struct OH_AVFormat *format Pointer to an OH_AVFormat instance.
const char *key Pointer to the key of the data to read.
const char **out Double pointer to the string read. The lifecycle of the out data matches the string in format. To keep the out data for an extended period of time, you must copy it to the memory. The maximum length of the output string is 256 bytes. If the length exceeds 256 bytes, false is returned.

Returns

Type Description
bool true if the operation is successful; false otherwise.
The possible causes of an operation failure are as follows:
1. The value of format is nullptr.
2. The value of format fails parameter structure verification.
3. The value of key is nullptr.
4. The value of out is nullptr.
5. The system resources are insufficient.
6. The obtained key does not exist or is not set.
7. The length of the out data exceeds 256 bytes.

OH_AVFormat_GetBuffer()

bool OH_AVFormat_GetBuffer(struct OH_AVFormat *format, const char *key, uint8_t **addr, size_t *size)

Description

Reads data blocks of a specified length from an OH_AVFormat instance.

System capability: SystemCapability.Multimedia.Media.Core

Since: 9

Parameters

Name Description
struct OH_AVFormat *format Pointer to an OH_AVFormat instance.
const char *key Pointer to the key of the data to read.
uint8_t **addr Double pointer to the address where the data read is stored. The data read is destroyed when the OH_AVFormat instance is destroyed. To hold the data for an extended period of time, copy it to the memory.
size_t *size Pointer to the size of the data read.

Returns

Type Description
bool true if the operation is successful; false otherwise.
The possible causes of an operation failure are as follows:
1. The value of format is nullptr.
2. The value of format fails parameter structure verification.
3. The value of key is nullptr.
4. The value of addr is nullptr.
5. The value of size is nullptr.
6. The obtained key does not exist or is not set.

OH_AVFormat_GetIntBuffer()

bool OH_AVFormat_GetIntBuffer(struct OH_AVFormat *format, const char *key, int32_t **addr, size_t *size)

Description

Reads an array of int32_t data from an OH_AVFormat instance.
Note that the buffer lifecycle is bound to the OH_AVFormat instance. The buffer becomes invalid automatically when the OH_AVFormat instance is destroyed.
To keep the data for an extended period, explicitly copy the data to newly allocated memory.

System capability: SystemCapability.Multimedia.Media.Core

Since: 20

Parameters

Name Description
struct OH_AVFormat *format Pointer to an OH_AVFormat instance.
const char *key Pointer to the key of the data to read.
int32_t **addr Double pointer to the memory where the data is stored.
size_t *size Pointer to the number of elements read.

Returns

Type Description
bool true if the operation is successful; false otherwise.
The possible causes of an operation failure are as follows:
1. The value of format is nullptr.
2. The value of format fails parameter structure verification.
3. The value of key is nullptr.
4. The value of addr is nullptr.
5. The value of size is nullptr.

OH_AVFormat_DumpInfo()

const char *OH_AVFormat_DumpInfo(struct OH_AVFormat *format)

Description

Returns a string consisting of key-value pairs in an OH_AVFormat instance. A string of up to 1024 bytes can be returned. The string pointer is released when the OH_AVFormat instance is destroyed.

System capability: SystemCapability.Multimedia.Media.Core

Since: 9

Parameters

Name Description
struct OH_AVFormat *format Pointer to an OH_AVFormat instance.

Returns

Type Description
const char * A string consisting of key-value pairs. If the operation fails, NULL is returned.
The possible causes of an operation failure are as follows:
1. The value of format is NULL.
2. System resources are insufficient.

OH_AVFormat_SetIntBuffer()

bool OH_AVFormat_SetIntBuffer(struct OH_AVFormat *format, const char *key, const int32_t *addr, size_t size)

Description

Writes data blocks of the int32_t type with a specified length to an OH_AVFormat instance.

System capability: SystemCapability.Multimedia.Media.Core

Since: 20

Parameters

Name Description
struct OH_AVFormat *format Pointer to an OH_AVFormat instance.
const char *key Pointer to the key of the data to write.
const int32_t *addr Pointer to the address to which data is written. The lifecycle is managed by the developer.
size_t size Length of the data to write, in units of elements, not bytes.

Returns

Type Description
bool true if the operation is successful; false otherwise.
The possible causes of an operation failure are as follows:
1. The value of format is nullptr.
2. The value of format fails parameter structure verification.
3. The value of key is nullptr.
4. The value of addr is nullptr.
5. The value of size is 0.

OH_AVFormat_GetKeyCount()

uint32_t OH_AVFormat_GetKeyCount(OH_AVFormat *format)

Description

Obtains the total number of keys in an OH_AVFormat instance.

Since: 23

Parameters

Name Description
OH_AVFormat *format Pointer to an OH_AVFormat instance.

Returns

Type Description
uint32_t Returns the number of keys on success; returns 0 otherwise.

OH_AVFormat_GetKey()

bool OH_AVFormat_GetKey(OH_AVFormat *format, uint32_t index, const char **key)

Description

Obtains the key name string from an OH_AVFormat instance by index.

Since: 23

Parameters

Name Description
OH_AVFormat *format Pointer to an OH_AVFormat instance.
uint32_t index Index of the key to be queried. The value range is [0, OH_AVFormat_GetKeyCount(format)).
const char **key Output pointer for receiving the key name string. The lifecycle of the string is bound to the format object.

Returns

Type Description
bool Returns true on success; returns false otherwise.