openharmony 鸿蒙 opensles

2025-06-12 浏览 (1)

OpenSL ES

NOTE

OpenHarmony provides the OpenSL ES APIs for audio development at the native layer since SDK 8. As the version evolves, these APIs fail to meet the capability expansion requirements of the audio system and therefore are no longer recommended. Switch from OpenSL ES to OHAudio.

Introduction

Open Sound Library for Embedded Systems (OpenSL ES) is a set of audio acceleration standards for embedded systems. It provides objects and APIs for developers to implement high-performance, low-latency audio features. OpenHarmony implements some native APIs based on OpenSL ES 1.0.1 API specifications. The table Supported APIs list these APIs.

Introducing OpenSL ES

To use OpenSL ES capabilities, include the following header files:

#include <SLES/OpenSLES.h>
#include <SLES/OpenSLES_OpenHarmony.h>
#include <SLES/OpenSLES_Platform.h>

Add the following dynamic link library to CMakeLists.txt:

libOpenSLES.so

Supported APIs

ObjectExternal InterfaceInterface InvocationSupportedDescription
SLEngineItfCreateAudioPlayerCreateAudioPlayer(SLEngineItf self, SLObjectItf *pPlayer, SLDataSource *pAudioSrc, SLDataSink *pAudioSnk, SLuint32 numInterfaces, const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired)YesCreates an audio player.
SLEngineItfCreateAudioRecorderreateAudioRecorder(SLEngineItf self, SLObjectItf *pRecorder, SLDataSource *pAudioSrc, SLDataSink *pAudioSnk, SLuint32 numInterfaces, const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired)YesCreates an audio recorder.
SLEngineItfCreateAudioOutputMixCreateOutputMix(SLEngineItf self, SLObjectItf *pMix, SLuint32 numInterfaces, const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired)YesCreates an audio output mixer.
SLObjectItfRealizeRealize(SLObjectItf self, SLboolean async)YesRealizes an audio player.
SLObjectItfgetStateGetState(SLObjectItf self, SLuint32 *pState)YesObtains the state.
SLObjectItfgetInterfaceGetInterface(SLObjectItf self, const SLInterfaceID iid, void *pInterface)YesObtains the interface.
SLObjectItfDestroyDestroy(SLObjectItf self)YesDestroys an object.
SLOHBufferQueueItfEnqueueEnqueue(SLOHBufferQueueItf self, const void *pBuffer, SLuint32 size)YesAdds a buffer to the queue.
SLOHBufferQueueItfclearClear(SLOHBufferQueueItf self)YesReleases the buffer queue.
SLOHBufferQueueItfgetStateGetState(SLOHBufferQueueItf self, SLOHBufferQueueState *pState)YesObtains the BufferQueue status.
SLOHBufferQueueItfgetBufferGetBuffer(SLOHBufferQueueItf self, SLuint8 **buffer, SLuint32 *size)YesObtains a buffer.
SLOHBufferQueueItfRegisterCallbackRegisterCallback(SLOHBufferQueueItf self, SlOHBufferQueueCallback callback, void *pContext)YesRegisters a callback.
SLPlayItfSetPlayStateSetPlayState(SLPlayItf self, SLuint32 state)YesSets the playback state.
SLPlayItfGetPlayStateGetPlayState(SLPlayItf self, SLuint32 *pState)YesObtains the playback state.
SLRecordItfSetRecordStateSetRecordState(SLRecordItf self, SLuint32 state)YesSets the recording state.
SLRecordItfGetRecordStateGetRecordState(SLRecordItf self, SLuint32 *pState)YesObtains the recording state.
SLVolumeItfSetVolumeLevelSetVolumeLevel(SLVolumeItf self, SLmillibel level)YesSets the volume.
SLVolumeItfGetVolumeLevelGetVolumeLevel(SLVolumeItf self, SLmillibel *pLevel)YesObtains the volume.
SLVolumeItfGetMaxVolumeLevelGetMaxVolumeLevel(SLVolumeItf self, SLmillibel *pMaxLevel)YesObtains the maximum volume.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Native API Standard Libraries

harmony 鸿蒙VkExternalFormatOHOS

harmony 鸿蒙VkImportNativeBufferInfoOHOS

harmony 鸿蒙VkMemoryGetNativeBufferInfoOHOS

harmony 鸿蒙VkNativeBufferFormatPropertiesOHOS

harmony 鸿蒙VkNativeBufferPropertiesOHOS

harmony 鸿蒙VkNativeBufferUsageOHOS

harmony 鸿蒙VkSurfaceCreateInfoOHOS

harmony 鸿蒙Vulkan Module

harmony 鸿蒙libc++

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