native_audiostream_base.h
Overview
The file declares the basic data structure of OHAudio.
File to include: <ohaudio/native_audiostream_base.h>
Library: libohaudio.so
System capability: SystemCapability.Multimedia.Audio.Core
Since: 10
Related module: OHAudio
Summary
Structs
| Name | typedef Keyword | Description |
|---|---|---|
| OH_AudioStreamInfo | OH_AudioStreamInfo | Describes the audio stream information, which is used to describe the basic audio format. |
| OH_AudioRenderer_Callbacks_Struct | OH_AudioRenderer_Callbacks | Describes a pointer to the callbacks related to an audio renderer. (It is deprecated in API version 20.) |
| OH_AudioCapturer_Callbacks_Struct | OH_AudioCapturer_Callbacks | Describes a pointer to the callbacks related to an audio capturer. To avoid unexpected behavior, ensure that every member variable of the struct is initialized by a custom callback method or a null pointer when setting the audio callback functions. (It is deprecated in API version 20.) |
| OH_AudioStreamBuilderStruct | OH_AudioStreamBuilder | Defines a struct for an audio stream builder. An audio stream builder instance is often used to create an audio stream and set its attributes. |
| OH_AudioRendererStruct | OH_AudioRenderer | Describes an audio renderer, which is used to render audio data. |
| OH_AudioCapturerStruct | OH_AudioCapturer | Describes an audio capturer, which is used to capture audio data. |
Enums
| Name | typedef Keyword | Description |
|---|---|---|
| OH_AudioStream_Result | OH_AudioStream_Result | Enumerates the audio operation results. |
| OH_AudioStream_Type | OH_AudioStream_Type | Enumerates the audio stream types. |
| OH_AudioStream_SampleFormat | OH_AudioStream_SampleFormat | Enumerates the sampling formats of audio streams. |
| OH_AudioStream_EncodingType | OH_AudioStream_EncodingType | Enumerates the encoding types of audio streams. |
| OH_AudioStream_Usage | OH_AudioStream_Usage | Enumerates the usage scenarios of audio streams. Generally, it is used to describe usage scenarios of audio output streams. |
| OH_AudioStream_LatencyMode | OH_AudioStream_LatencyMode | Enumerates the latency modes of audio streams. |
| OH_AudioStream_DirectPlaybackMode | OH_AudioStream_DirectPlaybackMode | Enumerates the direct playback modes of audio streams. |
| OH_AudioStream_VolumeMode | OH_AudioStream_VolumeMode | Enumerates the volume modes of audio streams. |
| OH_AudioStream_State | OH_AudioStream_State | Enumerates the audio stream states. |
| OH_AudioStream_SourceType | OH_AudioStream_SourceType | Enumerates the usage scenarios of audio streams. Generally, it is used to describe usage scenarios of audio input streams. |
| OH_AudioStream_Event | OH_AudioStream_Event | Enumerates the audio stream events. (It is deprecated in API version 20.) |
| OH_AudioInterrupt_ForceType | OH_AudioInterrupt_ForceType | Enumerates the types of force that causes audio interruption. The force type is obtained when an audio interruption event is received. This type indicates whether the audio interruption operation is forcibly performed by the system. For details about the operation (such as audio pause and stop), see OH_AudioInterrupt_Hint. |
| OH_AudioInterrupt_Hint | OH_AudioInterrupt_Hint | Enumerates the hints provided along with audio interruption. The force type is obtained when an audio interruption event is received. The hint specifies the operation (such as audio pause or volume adjustment) to be performed on audio streams based on the focus strategy. You can combine the OH_AudioInterrupt_ForceType information to determine whether the operation has been forcibly performed by the system. |
| OH_AudioInterrupt_Mode | OH_AudioInterrupt_Mode | Enumerates the audio interruption modes. |
| OH_AudioStream_AudioEffectMode | OH_AudioStream_AudioEffectMode | Enumerates the audio effect modes. |
| OH_AudioStream_FastStatus | OH_AudioStream_FastStatus | Enumerates the low-latency statuses. |
| OH_AudioStream_DeviceChangeReason | OH_AudioStream_DeviceChangeReason | Enumerates the reasons for audio stream device changes. |
| OH_AudioStream_PrivacyType | OH_AudioStream_PrivacyType | Enumerates the privacy types of an audio stream. The privacy type specifies whether the audio stream can be recorded by other applications. |
| OH_AudioData_Callback_Result | OH_AudioData_Callback_Result | Enumerates the audio data callback results. |
| OH_AudioStream_LatencyType | OH_AudioStream_LatencyType | Enumerates the audio latency types. |
| OH_AudioStream_PlaybackCaptureMode | OH_AudioStream_PlaybackCaptureMode | Enumerates the filter types for internal audio recording (capturing sound from the applications on the device). Each filter type corresponds to a type of playback stream. This API is currently not available for public use. |
| OH_AudioStream_PlaybackCaptureStartState | OH_AudioStream_PlaybackCaptureStartState | Enumerates the internal audio recording start statuses, which will be returned asynchronously after the OH_AudioCapturer_RequestPlaybackCaptureStart function is called. This API is currently not available for public use. |
Functions
| Name | typedef Keyword | Description |
|---|---|---|
| typedef void (*OH_AudioRenderer_OutputDeviceChangeCallback)(OH_AudioRenderer* renderer, void* userData, OH_AudioStream_DeviceChangeReason reason) | OH_AudioRenderer_OutputDeviceChangeCallback | Defines a pointer to the callback invoked when the audio capturer device changes. |
| typedef void (*OH_AudioRenderer_OnMarkReachedCallback)(OH_AudioRenderer* renderer, uint32_t samplePos, void* userData) | OH_AudioRenderer_OnMarkReachedCallback | Defines a pointer to the callback invoked when the mark position is reached. |
| typedef int32_t (*OH_AudioRenderer_WriteDataWithMetadataCallback)(OH_AudioRenderer* renderer, void* userData, void* audioData, int32_t audioDataSize, void* metadata, int32_t metadataSize) | OH_AudioRenderer_WriteDataWithMetadataCallback | Defines a function pointer to the callback used to write audio data and metadata. |
| typedef OH_AudioData_Callback_Result (*OH_AudioRenderer_OnWriteDataCallback)(OH_AudioRenderer* renderer, void* userData, void* audioData, int32_t audioDataSize) | OH_AudioRenderer_OnWriteDataCallback | Defines a function pointer to the callback used to write audio data. The callback is used only to write audio data. Do not call AudioRenderer APIs in it. The return result indicates whether the data filled in the buffer is valid. If the data is invalid, the data entered by the user will not be played. Once the callback finishes its execution, the audio service queues the data pointed to by audioData for playback. Therefore, do not change the data outside the callback. It is crucial to fill audioData with the exact length (specified by audioDataSize) of data designated for playback; otherwise, noises may occur during playback. The audioDataSize parameter can be set by calling OH_AudioStreamBuilder_SetFrameSizeInCallback. |
Enum Description
OH_AudioStream_Result
enum OH_AudioStream_Result
Description
Enumerates the audio operation results.
Since: 10
| Enum Item | Description |
|---|---|
| AUDIOSTREAM_SUCCESS = 0 | Operation successful. |
| AUDIOSTREAM_ERROR_INVALID_PARAM = 1 | Invalid input parameter. |
| AUDIOSTREAM_ERROR_ILLEGAL_STATE = 2 | Invalid state. |
| AUDIOSTREAM_ERROR_SYSTEM = 3 | System error. |
| AUDIOSTREAM_ERROR_UNSUPPORTED_FORMAT = 4 | Unsupported audio format, such as unsupported encoding type or sampling format. Since: 19 |
OH_AudioStream_Type
enum OH_AudioStream_Type
Description
Enumerates the audio stream types.
Since: 10
| Enum Item | Description |
|---|---|
| AUDIOSTREAM_TYPE_RENDERER = 1 | The audio stream is an output stream. |
| AUDIOSTREAM_TYPE_CAPTURER = 2 | The audio stream is an input stream. |
OH_AudioStream_SampleFormat
enum OH_AudioStream_SampleFormat
Description
Enumerates the sampling formats of audio streams.
Since: 10
| Enum Item | Description |
|---|---|
| AUDIOSTREAM_SAMPLE_U8 = 0 | Unsigned 8-bit. |
| AUDIOSTREAM_SAMPLE_S16LE = 1 | Short 16-bit little-endian. |
| AUDIOSTREAM_SAMPLE_S24LE = 2 | Short 24-bit little-endian. |
| AUDIOSTREAM_SAMPLE_S32LE = 3 | Short 32-bit little-endian. |
| AUDIOSTREAM_SAMPLE_F32LE = 4 | Float 32-bit little-endian. Since: 17 |
OH_AudioStream_EncodingType
enum OH_AudioStream_EncodingType
Description
Enumerates the encoding types of audio streams.
Since: 10
| Enum Item | Description |
|---|---|
| AUDIOSTREAM_ENCODING_TYPE_RAW = 0 | PCM encoding. |
| AUDIOSTREAM_ENCODING_TYPE_AUDIOVIVID = 1 | Audio Vivid encoding. Since: 12 |
| AUDIOSTREAM_ENCODING_TYPE_E_AC3 = 2 | E_AC3 encoding. Since: 19 |
OH_AudioStream_Usage
enum OH_AudioStream_Usage
Description
Enumerates the usage scenarios of audio streams.
that is, usage scenarios of audio output streams.
Since: 10
| Enum Item | Description |
|---|---|
| AUDIOSTREAM_USAGE_UNKNOWN = 0 | Unknown content. |
| AUDIOSTREAM_USAGE_MUSIC = 1 | Music. |
| AUDIOSTREAM_USAGE_VOICE_COMMUNICATION = 2 | VoIP voice call. |
| AUDIOSTREAM_USAGE_VOICE_ASSISTANT = 3 | Voice assistant. |
| AUDIOSTREAM_USAGE_ALARM = 4 | Alarming. |
| AUDIOSTREAM_USAGE_VOICE_MESSAGE = 5 | Voice message. |
| AUDIOSTREAM_USAGE_RINGTONE = 6 | Ringtone. |
| AUDIOSTREAM_USAGE_NOTIFICATION = 7 | Notification. |
| AUDIOSTREAM_USAGE_ACCESSIBILITY = 8 | Accessibility. |
| AUDIOSTREAM_USAGE_MOVIE = 10 | Movie or video. |
| AUDIOSTREAM_USAGE_GAME = 11 | Gaming. |
| AUDIOSTREAM_USAGE_AUDIOBOOK = 12 | Audiobooks (including crosstalks and storytelling), news radio, and podcasts. |
| AUDIOSTREAM_USAGE_NAVIGATION = 13 | Navigation. |
| AUDIOSTREAM_USAGE_VIDEO_COMMUNICATION = 17 | VoIP video call. Since: 12 |
OH_AudioStream_LatencyMode
enum OH_AudioStream_LatencyMode
Description
Enumerates the latency modes of audio streams.
Since: 10
| Enum Item | Description |
|---|---|
| AUDIOSTREAM_LATENCY_MODE_NORMAL = 0 | Normal latency mode. |
| AUDIOSTREAM_LATENCY_MODE_FAST = 1 | Low latency mode. |
OH_AudioStream_DirectPlaybackMode
enum OH_AudioStream_DirectPlaybackMode
Description
Enumerates the direct playback modes of audio streams.
Since: 19
| Enum Item | Description |
|---|---|
| AUDIOSTREAM_DIRECT_PLAYBACK_NOT_SUPPORTED = 0 | Direct playback is not supported. |
| AUDIOSTREAM_DIRECT_PLAYBACK_BITSTREAM_SUPPORTED = 1 | Direct playback of bit streams (without decoding) is supported. |
| AUDIOSTREAM_DIRECT_PLAYBACK_PCM_SUPPORTED = 2 | Direct playback of PCM-encoded audio is supported. |
OH_AudioStream_VolumeMode
enum OH_AudioStream_VolumeMode
Description
Enumerates the volume modes of audio streams.
Since: 19
| Enum Item | Description |
|---|---|
| AUDIOSTREAM_VOLUMEMODE_SYSTEM_GLOBAL = 0 | System-level volume (default mode). |
| AUDIOSTREAM_VOLUMEMODE_APP_INDIVIDUAL = 1 | Application-level volume. In this mode, you can set and query the application volume through the provided functions. |
OH_AudioStream_State
enum OH_AudioStream_State
Description
Enumerates the audio stream states.
Since: 10
| Enum Item | Description |
|---|---|
| AUDIOSTREAM_STATE_INVALID = -1 | Invalid state. |
| AUDIOSTREAM_STATE_NEW = 0 | Newly created. |
| AUDIOSTREAM_STATE_PREPARED = 1 | Prepared. |
| AUDIOSTREAM_STATE_RUNNING = 2 | Running. |
| AUDIOSTREAM_STATE_STOPPED = 3 | Stopped. |
| AUDIOSTREAM_STATE_RELEASED = 4 | Released. |
| AUDIOSTREAM_STATE_PAUSED = 5 | Paused. |
OH_AudioStream_SourceType
enum OH_AudioStream_SourceType
Description
Enumerates the usage scenarios of audio streams,
that is, usage scenarios of audio input streams.
Since: 10
| Enum Item | Description |
|---|---|
| AUDIOSTREAM_SOURCE_TYPE_INVALID = -1 | Invalid state. |
| AUDIOSTREAM_SOURCE_TYPE_MIC = 0 | Audio recording. |
| AUDIOSTREAM_SOURCE_TYPE_VOICE_RECOGNITION = 1 | Voice recognition. |
| AUDIOSTREAM_SOURCE_TYPE_PLAYBACK_CAPTURE = 2 | Audio playback. Deprecated from: 12 Substitute: OH_AVScreenCapture |
| AUDIOSTREAM_SOURCE_TYPE_VOICE_COMMUNICATION = 7 | Voice communication. |
| AUDIOSTREAM_SOURCE_TYPE_VOICE_MESSAGE = 10 | Voice message. Since: 12 |
| AUDIOSTREAM_SOURCE_TYPE_CAMCORDER = 13 | Video recording. Since: 13 |
| AUDIOSTREAM_SOURCE_TYPE_UNPROCESSED = 14 | Raw microphone recording, where the system does not perform any algorithm processing. Since: 14 |
| AUDIOSTREAM_SOURCE_TYPE_LIVE = 17 | Live. Since: 20 |
OH_AudioStream_Event
enum OH_AudioStream_Event
Description
Enumerates the audio stream events.
Since: 10
Deprecated from: 20
Substitute: OH_AudioRenderer_OutputDeviceChangeCallback
| Enum Item | Description |
|---|---|
| AUDIOSTREAM_EVENT_ROUTING_CHANGED = 0 | The audio route has been changed. |
OH_AudioInterrupt_ForceType
enum OH_AudioInterrupt_ForceType
Description
Enumerates the types of force that causes audio interruption.
The force type is obtained when an audio interruption event is received.
This type indicates whether the audio interruption operation is forcibly performed by the system. For details about the operation (such as audio pause and stop), see OH_AudioInterrupt_Hint.
Since: 10
| Enum Item | Description |
|---|---|
| AUDIOSTREAM_INTERRUPT_FORCE = 0 | The operation is forcibly performed by the system. |
| AUDIOSTREAM_INTERRUPT_SHARE = 1 | The system does not perform the specific operation. Instead, it notifies the application of the interruption through OH_AudioInterrupt_Hint and provides suggestions for the application to decide the next step. |
OH_AudioInterrupt_Hint
enum OH_AudioInterrupt_Hint
Description
Enumerates the hints provided along with audio interruption.
The force type is obtained when an audio interruption event is received.
The hint specifies the operation (such as audio pause or volume adjustment) to be performed on audio streams based on the focus strategy.
You can combine the OH_AudioInterrupt_ForceType information to determine whether the operation has been forcibly performed by the system.
Since: 10
| Enum Item | Description |
|---|---|
| AUDIOSTREAM_INTERRUPT_HINT_NONE = 0 | None. |
| AUDIOSTREAM_INTERRUPT_HINT_RESUME = 1 | A hint is displayed, indicating that the audio stream is restored. The application can proactively trigger operations related to rendering or recording. This operation cannot be forcibly performed by the system. The corresponding OH_AudioInterrupt_ForceType must be AUDIOSTREAM_INTERRUPT_SHARE. |
| AUDIOSTREAM_INTERRUPT_HINT_PAUSE = 2 | A hint is displayed, indicating that the audio stream is paused and the audio focus is lost temporarily. The AUDIOSTREAM_INTERRUPT_HINT_RESUME event will be triggered when the focus is gained. |
| AUDIOSTREAM_INTERRUPT_HINT_STOP = 3 | A hint is displayed, indicating that the audio stream stops and the audio focus is lost. |
| AUDIOSTREAM_INTERRUPT_HINT_DUCK = 4 | A hint is displayed, indicating that audio ducking starts and the audio is played at a lower volume. |
| AUDIOSTREAM_INTERRUPT_HINT_UNDUCK = 5 | A hint is displayed, indicating that audio ducking ends and the audio is played at the normal volume. |
| AUDIOSTREAM_INTERRUPT_HINT_MUTE = 6 | A hint is displayed, indicating that the audio is muted. Since: 20 |
| AUDIOSTREAM_INTERRUPT_HINT_UNMUTE = 7 | A hint is displayed, indicating that the audio is unmuted. Since: 20 |
OH_AudioInterrupt_Mode
enum OH_AudioInterrupt_Mode
Description
Enumerates the audio interruption modes.
Since: 12
| Enum Item | Description |
|---|---|
| AUDIOSTREAM_INTERRUPT_MODE_SHARE = 0 | Shared mode. |
| AUDIOSTREAM_INTERRUPT_MODE_INDEPENDENT = 1 | Independent mode. |
OH_AudioStream_AudioEffectMode
enum OH_AudioStream_AudioEffectMode
Description
Enumerates the audio effect modes.
Since: 12
| Enum Item | Description |
|---|---|
| EFFECT_NONE = 0 | No audio effect used. |
| EFFECT_DEFAULT = 1 | Default audio effect mode. |
OH_AudioStream_FastStatus
enum OH_AudioStream_FastStatus
Description
Enumerates the low-latency statuses.
Since: 20
| Enum Item | Description |
|---|---|
| AUDIOSTREAM_FASTSTATUS_NORMAL = 0 | Normal audio stream status. |
| AUDIOSTREAM_FASTSTATUS_FAST = 1 | Low-latency audio stream status. |
OH_AudioStream_DeviceChangeReason
enum OH_AudioStream_DeviceChangeReason
Description
Enumerates the reasons for audio stream device changes.
Since: 11
| Enum Item | Description |
|---|---|
| REASON_UNKNOWN = 0 | Unknown reason. |
| REASON_NEW_DEVICE_AVAILABLE = 1 | A new device is available. |
| REASON_OLD_DEVICE_UNAVAILABLE = 2 | The old device is unavailable. When this reason is reported, the application should consider pausing audio playback. |
| REASON_OVERRODE = 3 | The user or system forcibly changes the device. |
| REASON_SESSION_ACTIVATED = 4 | The audio session has been activated. Since: 20 |
| REASON_STREAM_PRIORITY_CHANGED = 5 | An audio stream with higher priority appears. Since: 20 |
OH_AudioStream_PrivacyType
enum OH_AudioStream_PrivacyType
Description
Enumerates the privacy types of an audio stream. The privacy type specifies whether the audio stream can be recorded by other applications.
Since: 12
| Enum Item | Description |
|---|---|
| AUDIO_STREAM_PRIVACY_TYPE_PUBLIC = 0 | The audio stream can be recorded or screen-projected by other applications and is not privacy-related. |
| AUDIO_STREAM_PRIVACY_TYPE_PRIVATE = 1 | The audio stream cannot be recorded or screen-projected by other applications. |
| AUDIO_STREAM_PRIVACY_TYPE_SHARED = 2 | The audio stream can be recorded or screen-projected by other applications and is privacy-related. For example, if the privacy policy is PRIVACY_TYPE_PUBLIC, the AUDIOSTREAM_USAGE_VOICE_COMMUNICATION audio stream cannot be recorded or screen-projected by other applications. However, if the privacy policy is PRIVACY_TYPE_SHARED, these audio streams can be recorded or screen-projected by other applications. Since: 21 |
OH_AudioData_Callback_Result
enum OH_AudioData_Callback_Result
Description
Enumerates the audio data callback results.
Since: 12
| Enum Item | Description |
|---|---|
| AUDIO_DATA_CALLBACK_RESULT_INVALID = -1 | The audio data callback result is invalid, and the audio data will not be played. |
| AUDIO_DATA_CALLBACK_RESULT_VALID = 0 | The audio data callback result is valid, and the audio data will be played. |
OH_AudioStream_LatencyType
enum OH_AudioStream_LatencyType
Description
Enumerates the audio latency types.
Since: 23
| Enum Item | Description |
|---|---|
| AUDIOSTREAM_LATENCY_TYPE_ALL = 0 | Obtains the overall audio processing latency for both software and hardware components. |
| AUDIOSTREAM_LATENCY_TYPE_SOFTWARE = 1 | Obtains the software latency, including latency for sound effect processing on the software side. |
| AUDIOSTREAM_LATENCY_TYPE_HARDWARE = 2 | Obtains the hardware latency, including latency for sound effect processing on the hardware abstraction layer (HAL), driver, and hardware side. |
OH_AudioStream_PlaybackCaptureMode
enum OH_AudioStream_PlaybackCaptureMode
Description
Enumerates the filter types for internal audio recording (capturing sound from the applications on the device). Each filter type corresponds to a type of playback stream. This API is currently not available for public use.
Since: 23
| Enum Item | Description |
|---|---|
| AUDIOSTREAM_PLAYBACKCAPTURE_MODE_DEFAULT = 0x0 | Default mode. Most audio streams are recorded, excluding the prompt streams and privacy streams. Since: 23 |
| AUDIOSTREAM_PLAYBACKCAPTURE_MODE_MEDIA = 0x1 | Media mode. Media, voice messages, and unknown streams are retrieved. Since: 23 |
| AUDIOSTREAM_PLAYBACKCAPTURE_MODE_EXCLUDING_SELF = 0x8000 | Self-exclusion mode. All audio streams except for those played by the application itself are retrieved. Since: 23 |
OH_AudioStream_PlaybackCaptureStartState
enum OH_AudioStream_PlaybackCaptureStartState
Description
Enumerates the internal audio recording start statuses, which will be returned asynchronously after the OH_AudioCapturer_RequestPlaybackCaptureStart function is called. This API is currently not available for public use.
Since: 23
| Enum Item | Description |
|---|---|
| AUDIOSTREAM_PLAYBACKCAPTURE_START_STATE_SUCCESS = 0 | Internal audio recording is started successfully. Since: 23 |
| AUDIOSTREAM_PLAYBACKCAPTURE_START_STATE_FAILED = 1 | Internal audio recording fails to be started. The focus request (prioritized by stream type) is interrupted or an internal system error occurs. Since: 23 |
| AUDIOSTREAM_PLAYBACKCAPTURE_START_STATE_NOT_AUTHORIZED = 2 | Internal audio recording fails to be started due to lack of user authorization. Since: 23 |
Function Description
OH_AudioRenderer_OutputDeviceChangeCallback()
typedef void (*OH_AudioRenderer_OutputDeviceChangeCallback)(OH_AudioRenderer* renderer, void* userData, OH_AudioStream_DeviceChangeReason reason)
Description
Defines a pointer to the callback invoked when the audio capturer device changes.
Since: 11
Parameters
| Name | Description |
|---|---|
| OH_AudioRenderer* renderer | Pointer to an audio renderer instance, which is created by calling OH_AudioStreamBuilder_GenerateRenderer. |
| void* userData | Pointer to the application data passed through the callback. |
| OH_AudioStream_DeviceChangeReason reason | Enumerates the reasons for audio stream device changes. |
OH_AudioRenderer_OnMarkReachedCallback()
typedef void (*OH_AudioRenderer_OnMarkReachedCallback)(OH_AudioRenderer* renderer, uint32_t samplePos, void* userData)
Description
Defines a pointer to the callback invoked when the mark position is reached.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_AudioRenderer* renderer | Pointer to an audio renderer instance, which is created by calling OH_AudioStreamBuilder_GenerateRenderer. |
| uint32_t samplePos | Mark position. |
| void* userData | Pointer to the application data passed through the callback. |
OH_AudioRenderer_WriteDataWithMetadataCallback()
typedef int32_t (*OH_AudioRenderer_WriteDataWithMetadataCallback)(OH_AudioRenderer* renderer, void* userData, void* audioData, int32_t audioDataSize, void* metadata, int32_t metadataSize)
Description
Defines a function pointer to the callback used to write audio data and metadata.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_AudioRenderer* renderer | Pointer to an audio renderer instance, which is created by calling OH_AudioStreamBuilder_GenerateRenderer. |
| void* userData | Pointer to the application data passed through the callback. |
| void* audioData | Pointer to the audio data written by the user. |
| int32_t audioDataSize | Length of the audio data, in bytes. |
| void* metadata | Pointer to the metadata written by the user. |
| int32_t metadataSize | Length of the metadata, in bytes. |
Returns
| Type | Description |
|---|---|
| int32_t | Error code of the callback. |
OH_AudioRenderer_OnWriteDataCallback()
typedef OH_AudioData_Callback_Result (*OH_AudioRenderer_OnWriteDataCallback)(OH_AudioRenderer* renderer, void* userData, void* audioData, int32_t audioDataSize)
Description
Defines a function pointer to the callback used to write audio data.
The callback is used only to write audio data. Do not call AudioRenderer APIs in it.
The return result indicates whether the data filled in the buffer is valid. If the data is invalid, the data entered by the user will not be played.
Once the callback finishes its execution, the audio service queues the data pointed to by audioData for playback. Therefore, do not change the data outside the callback. It is crucial to fill audioData with the exact length (specified by audioDataSize) of data designated for playback; otherwise, noises may occur during playback.
The audioDataSize parameter can be set by calling OH_AudioStreamBuilder_SetFrameSizeInCallback.
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_AudioRenderer* renderer | Pointer to an audio renderer instance, which is created by calling OH_AudioStreamBuilder_GenerateRenderer. |
| void* userData | Pointer to the application data passed through the callback. |
| void* audioData | Pointer to the audio data written by the user. |
| int32_t audioDataSize | Length of the audio data, in bytes. |
Returns
| Type | Description |
|---|---|
| OH_AudioData_Callback_Result | AUDIO_DATA_CALLBACK_RESULT_INVALID: The audio data callback result is invalid, and the audio data will not be played. AUDIO_DATA_CALLBACK_RESULT_VALID: The audio data callback result is valid, and the audio data will be played. |
你可能感兴趣的鸿蒙文章
openharmony 鸿蒙 capi-native-audiostreambuilder-h
openharmony 鸿蒙 capi-ohaudiosuite
openharmony 鸿蒙 js-apis-inner-multimedia-systemSoundPlayer
openharmony 鸿蒙 arkts-apis-audio-i
openharmony 鸿蒙 arkts-apis-audio-AudioManager
openharmony 鸿蒙 capi-ohaudiosuite-oh-audiosuite-spacerenderpositionparams