From 7037aa804c246af8eae649e7bdbfdd847e3c6944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E4=B8=B4=E9=A3=8E?= Date: Wed, 16 Apr 2025 22:40:20 +0800 Subject: [PATCH] add new audio format related apis MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 杨临风 --- .../native_audio_stream_manager.h | 99 +++++++++++++++++++ .../common/native_audiostream_base.h | 74 +++++++++++++- 2 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 multimedia/audio_framework/audio_manager/native_audio_stream_manager.h diff --git a/multimedia/audio_framework/audio_manager/native_audio_stream_manager.h b/multimedia/audio_framework/audio_manager/native_audio_stream_manager.h new file mode 100644 index 000000000..9232626b7 --- /dev/null +++ b/multimedia/audio_framework/audio_manager/native_audio_stream_manager.h @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup OHAudio + * @{ + * + * @brief Provide the definition of the C interface for the audio module. + * + * @syscap SystemCapability.Multimedia.Audio.Core + * + * @since 19 + */ + +/** + * @file native_audio_stream_manager.h + * + * @brief Declare audio stream manager related interfaces. + * + * This file interface is used for the creation of audioStreamManager + * as well as the audio stream settings and management. + * + * @library libohaudio.so + * @syscap SystemCapability.Multimedia.Audio.Core + * @kit AudioKit + * @since 19 + */ + +#ifndef NATIVE_AUDIO_STREAM_MANAGER_H +#define NATIVE_AUDIO_STREAM_MANAGER_H + +#include "native_audio_common.h" +#include "native_audiostream_base.h" +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Declaring the audio stream manager. + * The handle of audio stream manager used for audio stream settings and management. + * + * @since 19 + */ +typedef struct OH_AudioStreamManager OH_AudioStreamManager; + +/** + * @brief Query the audio stream manager handle, which should be set as the first parameter in stream management + * releated functions. + * + * @param audioStreamManager the {@link OH_AudioStreamManager} handle returned by + * {@link OH_AudioManager_GetAudioStreamManager}. + * @return Function result code: + * {@link AUDIOCOMMON_RESULT_SUCCESS} If the execution is successful. + * {@link AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM}: + * 1.The param of audioStreamManager is nullptr. + * @since 19 + */ +OH_AudioCommon_Result OH_AudioManager_GetAudioStreamManager(OH_AudioStreamManager **audioStreamManager); + +/** + * @brief Gets the mode of direct playback available for a given audio format with current active device. + * + * @param audioStreamManager the {@link OH_AudioStreamManager} handle returned by + * {@link OH_AudioManager_GetAudioStreamManager}. + * @param streamInfo the {@link OH_AudioStreamInfo}. + * @param usage the {@link OH_AudioStream_Usage}. + * @param directPlaybackMode the {@link OH_AudioStream_DirectPlaybackMode} pointer to a variable which receives the + * result. + * @return Function result code: + * {@link AUDIOCOMMON_RESULT_SUCCESS} If the execution is successful. + * {@link AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM}: + * 1.The param of audioStreamManager is nullptr; + * 2.The param of streamInfo is nullptr; + * 3.The param of usage invalid; + * 4.The param of directPlaybackMode is nullptr. + * @since 19 + */ +OH_AudioCommon_Result OH_AudioStreamManager_GetDirectPlaybackSupport( + OH_AudioStreamManager *audioStreamManager, OH_AudioStreamInfo *streamInfo, + OH_AudioStream_Usage usage, OH_AudioStream_DirectPlaybackMode *directPlaybackMode); + +#ifdef __cplusplus +} +#endif + +#endif // NATIVE_AUDIO_STREAM_MANAGER_H +/** @} */ diff --git a/multimedia/audio_framework/common/native_audiostream_base.h b/multimedia/audio_framework/common/native_audiostream_base.h index 6b1fb6cb6..15af99de7 100644 --- a/multimedia/audio_framework/common/native_audiostream_base.h +++ b/multimedia/audio_framework/common/native_audiostream_base.h @@ -41,6 +41,7 @@ #define NATIVE_AUDIOSTREAM_BASE_H #include +#include "multimedia/native_audio_channel_layout.h" #ifdef __cplusplus extern "C" { @@ -78,7 +79,14 @@ typedef enum { * * @since 10 */ - AUDIOSTREAM_ERROR_SYSTEM = 3 + AUDIOSTREAM_ERROR_SYSTEM = 3, + + /** + * @error Unsupported audio format, such as unsupported encoding type, sample format etc. + * + * @since 19 + */ + AUDIOSTREAM_ERROR_UNSUPPORTED_FORMAT = 4 } OH_AudioStream_Result; /** @@ -159,8 +167,46 @@ typedef enum { * @since 12 */ AUDIOSTREAM_ENCODING_TYPE_AUDIOVIVID = 1, + /** + * E_AC3 encoding type. + * + * @since 19 + */ + AUDIOSTREAM_ENCODING_TYPE_E_AC3 = 2, } OH_AudioStream_EncodingType; +/** + * @brief Define the audio stream info structure, used to describe basic audio format. + * + * @since 19 + */ +typedef struct OH_AudioStreamInfo { + /** + * @brief Audio sampling rate. + * + * @since 19 + */ + int32_t samplingRate; + /** + * @brief Audio channel layout. + * + * @since 19 + */ + OH_AudioChannelLayout channelLayout; + /** + * @brief Audio encoding format type. + * + * @since 19 + */ + OH_AudioStream_EncodingType encodingType; + /** + * @brief Audio sample format. + * + * @since 19 + */ + OH_AudioStream_SampleFormat sampleFormat; +} OH_AudioStreamInfo; + /** * @brief Define the audio stream usage. * Audio stream usage is used to describe what work scenario @@ -275,6 +321,32 @@ typedef enum { AUDIOSTREAM_LATENCY_MODE_FAST = 1 } OH_AudioStream_LatencyMode; +/** + * @brief Enumerates audio direct playback modes. + * + * @since 19 + */ +typedef enum { + /** + * Direct playback is not supported. + * + * @since 19 + */ + AUDIOSTREAM_DIRECT_PLAYBACK_NOT_SUPPORTED = 0, + /** + * Direct playback mode which is bitstream pass-through such as compressed pass-through. + * + * @since 19 + */ + AUDIOSTREAM_DIRECT_PLAYBACK_BITSTREAM_SUPPORTED = 1, + /** + * Direct playback mode of pcm. + * + * @since 19 + */ + AUDIOSTREAM_DIRECT_PLAYBACK_PCM_SUPPORTED = 2 +} OH_AudioStream_DirectPlaybackMode; + /** * @brief Define the audio event. * -- Gitee