From 5d90e19661767e00d2ee27e46551b6d9a2a88503 Mon Sep 17 00:00:00 2001 From: magekkkk Date: Mon, 24 Mar 2025 08:56:21 +0000 Subject: [PATCH 1/3] add fast status apis Signed-off-by: magekkkk --- .../audio_capturer/native_audiocapturer.h | 24 +++ .../native_audio_stream_manager.h | 137 ++++++++++++++++++ .../audio_renderer/native_audiorenderer.h | 24 +++ .../common/native_audiostream_base.h | 50 +++++++ .../common/native_audiostreambuilder.h | 25 ++++ 5 files changed, 260 insertions(+) create mode 100644 multimedia/audio_framework/audio_manager/native_audio_stream_manager.h diff --git a/multimedia/audio_framework/audio_capturer/native_audiocapturer.h b/multimedia/audio_framework/audio_capturer/native_audiocapturer.h index bbe32247e..532d63fc8 100644 --- a/multimedia/audio_framework/audio_capturer/native_audiocapturer.h +++ b/multimedia/audio_framework/audio_capturer/native_audiocapturer.h @@ -344,6 +344,30 @@ typedef void (*OH_AudioCapturer_OnInterruptCallback)(OH_AudioCapturer* capturer, typedef void (*OH_AudioCapturer_OnErrorCallback)(OH_AudioCapturer* renderer, void* userData, OH_AudioStream_Result error); +/** + * @brief xxx + * + * @param capturer xxx + * @param status xxx + * @since 20 + */ +OH_AudioStream_Result OH_AudioCapturer_GetFastStatus(OH_AudioCapturer* capturer, + OH_AudioStream_FastStatus* status); + +/** + * @brief xxx + * + * @param capturer xxx + * @param userData xxx + * @param status xxx + * @since 20 + */ +typedef void (*OH_AudioCapturer_OnFastStatusChange)( + OH_AudioCapturer* capturer, + void* userData, + OH_AudioStream_FastStatus status +); + #ifdef __cplusplus } #endif 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..b030a4d4d --- /dev/null +++ b/multimedia/audio_framework/audio_manager/native_audio_stream_manager.h @@ -0,0 +1,137 @@ +/* + * 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 20 + */ + +/** + * @file native_audio_strea,_manager.h + * + * @brief Declare audio stream manager related interfaces. + * + * This file interfaces are used for the creation of AudioStreamManager. + * + * @library libohaudio.so + * @syscap SystemCapability.Multimedia.Audio.Core + * @kit AudioKit + * @since 20 + */ + +#ifndef NATIVE_AUDIO_STREAM_MANAGER_H +#define NATIVE_AUDIO_STREAM_MANAGER_H + +#include "native_audio_common.h" +#include "native_audiostream_base.h" +#include "native_audio_device_base.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Declare the audio stream manager. + * Audio stream manager provides many functions about audio streams, like monitoring audio streams status, + * getting different stream types supported information and so on. + * + * @since 20 + */ +typedef struct OH_AudioStreamManager OH_AudioStreamManager; + +/** + * @brief Fetch the audio stream manager handle, which is a singleton. + * + * @param streamManager output parameter to get the {@link #OH_AudioStreamManager}. + * @return + * {@link #AUDIOCOMMON_RESULT_SUCCESS} if execution succeeds + * {@link #AUDIOCOMMON_RESULT_ERROR_SYSTEM} if system state error + * @since 20 + */ +OH_AudioCommon_Result OH_AudioManager_GetAudioStreamManager( + OH_AudioStreamManager **streamManager); + +/** + * @brief Return if fast playback is supported for the specific audio stream info and usage type + * in current device situation. + * + * @param streamManager {@link OH_AudioStreamManager} handle + * provided by {@link OH_AudioManager_GetAudioStreamManager}. + * @param streamInfo reference of stream info structure to describe basic audio format. + * @param usage stream usage type used to decide the audio device and pipe type selection result. + * @return {@code true} if fast playback is supported in this situation. + * @since 20 + */ +bool OH_AudioStreamManager_IsFastPlaybackSupported( + OH_AudioStreamManager *streamManager, OH_AudioStreamInfo *streamInfo, OH_AudioStream_Usage usage); + +/** + * @brief Return if fast playback is supported for the specific audio stream info, usage type + * and audio output device. + * + * @param streamManager {@link OH_AudioStreamManager} handle + * provided by {@link OH_AudioManager_GetAudioStreamManager}. + * @param streamInfo reference of stream info structure to describe basic audio format. + * @param usage stream usage type used to decide the audio device and pipe type selection result. + * @param deviceDescriptor target audio output device provided by {@link OH_AudioRoutingManager_GetDevices}. + * @return {@code true} if fast playback is supported in this situation. + * @since 20 + */ +bool OH_AudioStreamManager_IsFastPlaybackSupportedForDevice( + OH_AudioStreamManager *streamManager, OH_AudioStreamInfo *streamInfo, OH_AudioStream_Usage usage, + OH_AudioDeviceDescriptor *deviceDescriptor); + +/** + * @brief Return if fast recording is supported for the specific audio stream info and source type + * in current device situation. + * + * @param streamManager {@link OH_AudioStreamManager} handle + * provided by {@link OH_AudioManager_GetAudioStreamManager}. + * @param streamInfo reference of stream info structure to describe basic audio format. + * @param source stream source type used to decide the audio device and pipe type selection result. + * @return {@code true} if fast recording is supported in this situation. + * @since 20 + */ +bool OH_AudioStreamManager_IsFastRecordingSupported( + OH_AudioStreamManager *streamManager, OH_AudioStreamInfo *streamInfo, OH_AudioStream_SourceType source); + +/** + * @brief Return if fast recording is supported for the specific audio stream info, source type + * and audio input device. + * + * @param streamManager {@link OH_AudioStreamManager} handle + * provided by {@link OH_AudioManager_GetAudioStreamManager}. + * @param streamInfo reference of stream info structure to describe basic audio format. + * @param source stream source type used to decide the audio device and pipe type selection result. + * @param deviceDescriptor target audio input device provided by {@link OH_AudioRoutingManager_GetDevices}. + * @return {@code true} if fast recording is supported in this situation. + * @since 20 + */ +bool OH_AudioStreamManager_IsFastRecordingSupportedForDevice( + OH_AudioStreamManager *streamManager, OH_AudioStreamInfo *streamInfo, OH_AudioStream_SourceType source, + OH_AudioDeviceDescriptor *deviceDescriptor); + +#ifdef __cplusplus +} +#endif + +#endif // NATIVE_AUDIO_ROUTING_MANAGER_H +/** @} */ \ No newline at end of file diff --git a/multimedia/audio_framework/audio_renderer/native_audiorenderer.h b/multimedia/audio_framework/audio_renderer/native_audiorenderer.h index be7722f07..e314500d0 100644 --- a/multimedia/audio_framework/audio_renderer/native_audiorenderer.h +++ b/multimedia/audio_framework/audio_renderer/native_audiorenderer.h @@ -564,6 +564,30 @@ typedef void (*OH_AudioRenderer_OnInterruptCallback)(OH_AudioRenderer* renderer, typedef void (*OH_AudioRenderer_OnErrorCallback)(OH_AudioRenderer* renderer, void* userData, OH_AudioStream_Result error); +/** + * @brief xxx + * + * @param renderer xxx + * @param status xxx + * @since 20 + */ +OH_AudioStream_Result OH_AudioRenderer_GetFastStatus(OH_AudioRenderer* renderer, + OH_AudioStream_FastStatus* status); + +/** + * @brief xxx + * + * @param renderer xxx + * @param userData xxx + * @param status xxx + * @since 20 + */ +typedef void (*OH_AudioRenderer_OnFastStatusChange)( + OH_AudioRenderer* renderer, + void* userData, + OH_AudioStream_FastStatus status +); + #ifdef __cplusplus } #endif diff --git a/multimedia/audio_framework/common/native_audiostream_base.h b/multimedia/audio_framework/common/native_audiostream_base.h index 6b1fb6cb6..112f71037 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" { @@ -161,6 +162,39 @@ typedef enum { AUDIOSTREAM_ENCODING_TYPE_AUDIOVIVID = 1, } OH_AudioStream_EncodingType; +/** + * @brief Define the audio stream info structure, used to describe basic audio format. + * + * @since 20 + */ +typedef struct OH_AudioStreamInfo { + /** + * @brief Audio sampling rate. + * + * @since 20 + */ + int32_t samplingRate; + /** + * @brief Audio channel layout. + * + * @since 20 + */ + OH_AudioChannelLayout channelLayout; + /** + * @brief Audio encoding format type. + * + * @since 20 + */ + OH_AudioStream_EncodingType encodingType; + /** + * @brief Audio sample format. + * + * @since 20 + */ + OH_AudioStream_SampleFormat sampleFormat; +} OH_AudioStreamInfo; + + /** * @brief Define the audio stream usage. * Audio stream usage is used to describe what work scenario @@ -501,6 +535,22 @@ typedef enum { EFFECT_DEFAULT = 1, } OH_AudioStream_AudioEffectMode; +/** + * @brief Defines the fast status. + * + * @since 20 + */ +typedef enum { + /** + * normal status + */ + AUDIOSTREAM_FASTSTATUS_NORMAL = 0, + /** + * fast status + */ + AUDIOSTREAM_FASTSTATUS_FAST = 1 +} OH_AudioStream_FastStatus; + /** * @brief Declaring the audio stream builder. * The instance of builder is used for creating audio stream. diff --git a/multimedia/audio_framework/common/native_audiostreambuilder.h b/multimedia/audio_framework/common/native_audiostreambuilder.h index 5fb946d81..13b71cd65 100644 --- a/multimedia/audio_framework/common/native_audiostreambuilder.h +++ b/multimedia/audio_framework/common/native_audiostreambuilder.h @@ -488,6 +488,31 @@ OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerInterruptCallback(OH_Audi */ OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerErrorCallback(OH_AudioStreamBuilder* builder, OH_AudioCapturer_OnErrorCallback callback, void* userData); + +/** + * @brief xxx + * + * @param builder Builder provided by OH_AudioStreamBuilder_Create() + * @param callback Callback function that will recevie the fast status change event. + * @param userData Pointer to an application data structure that will be passed to the callback functions. + * @return xxx + * @since 20 + */ +OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererFastStatusChangeCallback(OH_AudioStreamBuilder* builder, + OH_AudioRenderer_OnFastStatusChange callback, void* userData); + +/** + * @brief xxx + * + * @param builder Builder provided by OH_AudioStreamBuilder_Create() + * @param callback Callback function that will recevie the fast status change event. + * @param userData Pointer to an application data structure that will be passed to the callback functions. + * @return xxx + * @since 20 + */ +OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerFastStatusChangeCallback(OH_AudioStreamBuilder* builder, + OH_AudioCapturer_OnFastStatusChange callback, void* userData); + #ifdef __cplusplus } #endif -- Gitee From 781a78f7147712d542cba0b043db16cbc4545ea6 Mon Sep 17 00:00:00 2001 From: magekkkk Date: Tue, 15 Apr 2025 06:36:33 +0000 Subject: [PATCH 2/3] remove api for device Signed-off-by: magekkkk --- .../native_audio_stream_manager.h | 32 ------------------- 1 file changed, 32 deletions(-) diff --git a/multimedia/audio_framework/audio_manager/native_audio_stream_manager.h b/multimedia/audio_framework/audio_manager/native_audio_stream_manager.h index b030a4d4d..eb9c3c3a6 100644 --- a/multimedia/audio_framework/audio_manager/native_audio_stream_manager.h +++ b/multimedia/audio_framework/audio_manager/native_audio_stream_manager.h @@ -83,22 +83,6 @@ OH_AudioCommon_Result OH_AudioManager_GetAudioStreamManager( bool OH_AudioStreamManager_IsFastPlaybackSupported( OH_AudioStreamManager *streamManager, OH_AudioStreamInfo *streamInfo, OH_AudioStream_Usage usage); -/** - * @brief Return if fast playback is supported for the specific audio stream info, usage type - * and audio output device. - * - * @param streamManager {@link OH_AudioStreamManager} handle - * provided by {@link OH_AudioManager_GetAudioStreamManager}. - * @param streamInfo reference of stream info structure to describe basic audio format. - * @param usage stream usage type used to decide the audio device and pipe type selection result. - * @param deviceDescriptor target audio output device provided by {@link OH_AudioRoutingManager_GetDevices}. - * @return {@code true} if fast playback is supported in this situation. - * @since 20 - */ -bool OH_AudioStreamManager_IsFastPlaybackSupportedForDevice( - OH_AudioStreamManager *streamManager, OH_AudioStreamInfo *streamInfo, OH_AudioStream_Usage usage, - OH_AudioDeviceDescriptor *deviceDescriptor); - /** * @brief Return if fast recording is supported for the specific audio stream info and source type * in current device situation. @@ -113,22 +97,6 @@ bool OH_AudioStreamManager_IsFastPlaybackSupportedForDevice( bool OH_AudioStreamManager_IsFastRecordingSupported( OH_AudioStreamManager *streamManager, OH_AudioStreamInfo *streamInfo, OH_AudioStream_SourceType source); -/** - * @brief Return if fast recording is supported for the specific audio stream info, source type - * and audio input device. - * - * @param streamManager {@link OH_AudioStreamManager} handle - * provided by {@link OH_AudioManager_GetAudioStreamManager}. - * @param streamInfo reference of stream info structure to describe basic audio format. - * @param source stream source type used to decide the audio device and pipe type selection result. - * @param deviceDescriptor target audio input device provided by {@link OH_AudioRoutingManager_GetDevices}. - * @return {@code true} if fast recording is supported in this situation. - * @since 20 - */ -bool OH_AudioStreamManager_IsFastRecordingSupportedForDevice( - OH_AudioStreamManager *streamManager, OH_AudioStreamInfo *streamInfo, OH_AudioStream_SourceType source, - OH_AudioDeviceDescriptor *deviceDescriptor); - #ifdef __cplusplus } #endif -- Gitee From d794c6f7aee07699dbbab135e34ded4b1f73070f Mon Sep 17 00:00:00 2001 From: magekkkk Date: Tue, 15 Apr 2025 13:31:45 +0000 Subject: [PATCH 3/3] add api comment Signed-off-by: magekkkk --- .../audio_capturer/native_audiocapturer.h | 20 +++++++++++-------- .../native_audio_stream_manager.h | 2 +- .../audio_renderer/native_audiorenderer.h | 20 +++++++++++-------- .../common/native_audiostreambuilder.h | 12 +++++++---- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/multimedia/audio_framework/audio_capturer/native_audiocapturer.h b/multimedia/audio_framework/audio_capturer/native_audiocapturer.h index 532d63fc8..788002d60 100644 --- a/multimedia/audio_framework/audio_capturer/native_audiocapturer.h +++ b/multimedia/audio_framework/audio_capturer/native_audiocapturer.h @@ -345,21 +345,25 @@ typedef void (*OH_AudioCapturer_OnErrorCallback)(OH_AudioCapturer* renderer, voi OH_AudioStream_Result error); /** - * @brief xxx - * - * @param capturer xxx - * @param status xxx + * @brief Gets audio capturer running status, check if it works in fast status. + * + * @param capturer Reference created by OH_AudioStreamBuilder_GenerateCapturer. + * @param status Pointer to a variable to receive the status. + * @return + * {@link AUDIOSTREAM_SUCCESS} if the execution is successful. + * {@link AUDIOSTREAM_ERROR_INVALID_PARAM} the param of capturer is nullptr. + * {@link AUDIOSTREAM_ERROR_ILLEGAL_STATE} function called in invalid state, only available before release state. * @since 20 */ OH_AudioStream_Result OH_AudioCapturer_GetFastStatus(OH_AudioCapturer* capturer, OH_AudioStream_FastStatus* status); /** - * @brief xxx + * @brief Callback function of fast status change event for audio capturer. * - * @param capturer xxx - * @param userData xxx - * @param status xxx + * @param capturer Pointer to an audio capturer instance for which this callback occurs. + * @param userData Userdata which is passed by register. + * @param status Current fast status. * @since 20 */ typedef void (*OH_AudioCapturer_OnFastStatusChange)( diff --git a/multimedia/audio_framework/audio_manager/native_audio_stream_manager.h b/multimedia/audio_framework/audio_manager/native_audio_stream_manager.h index eb9c3c3a6..a628b06c7 100644 --- a/multimedia/audio_framework/audio_manager/native_audio_stream_manager.h +++ b/multimedia/audio_framework/audio_manager/native_audio_stream_manager.h @@ -25,7 +25,7 @@ */ /** - * @file native_audio_strea,_manager.h + * @file native_audio_stream_manager.h * * @brief Declare audio stream manager related interfaces. * diff --git a/multimedia/audio_framework/audio_renderer/native_audiorenderer.h b/multimedia/audio_framework/audio_renderer/native_audiorenderer.h index e314500d0..c50deff85 100644 --- a/multimedia/audio_framework/audio_renderer/native_audiorenderer.h +++ b/multimedia/audio_framework/audio_renderer/native_audiorenderer.h @@ -565,21 +565,25 @@ typedef void (*OH_AudioRenderer_OnErrorCallback)(OH_AudioRenderer* renderer, voi OH_AudioStream_Result error); /** - * @brief xxx - * - * @param renderer xxx - * @param status xxx + * @brief Gets audio renderer running status, check if it works in fast status. + * + * @param renderer Reference created by OH_AudioStreamBuilder_GenerateRenderer. + * @param status Pointer to a variable to receive the status. + * @return + * {@link AUDIOSTREAM_SUCCESS} if the execution is successful. + * {@link AUDIOSTREAM_ERROR_INVALID_PARAM} the param of renderer is nullptr. + * {@link AUDIOSTREAM_ERROR_ILLEGAL_STATE} function called in invalid state, only available before release state. * @since 20 */ OH_AudioStream_Result OH_AudioRenderer_GetFastStatus(OH_AudioRenderer* renderer, OH_AudioStream_FastStatus* status); /** - * @brief xxx + * @brief Callback function of fast status change event for audio renderer. * - * @param renderer xxx - * @param userData xxx - * @param status xxx + * @param renderer Pointer to an audio renderer instance for which this callback occurs. + * @param userData Userdata which is passed by register. + * @param status Current fast status. * @since 20 */ typedef void (*OH_AudioRenderer_OnFastStatusChange)( diff --git a/multimedia/audio_framework/common/native_audiostreambuilder.h b/multimedia/audio_framework/common/native_audiostreambuilder.h index 13b71cd65..95e804518 100644 --- a/multimedia/audio_framework/common/native_audiostreambuilder.h +++ b/multimedia/audio_framework/common/native_audiostreambuilder.h @@ -490,24 +490,28 @@ OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerErrorCallback(OH_AudioStr OH_AudioCapturer_OnErrorCallback callback, void* userData); /** - * @brief xxx + * @brief Set the callback of fast status change event for audio renderer. * * @param builder Builder provided by OH_AudioStreamBuilder_Create() * @param callback Callback function that will recevie the fast status change event. * @param userData Pointer to an application data structure that will be passed to the callback functions. - * @return xxx + * @return + * {@link AUDIOSTREAM_SUCCESS} if the execution is successful. + * {@link AUDIOSTREAM_ERROR_INVALID_PARAM} the param of builder or callback is nullptr. * @since 20 */ OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererFastStatusChangeCallback(OH_AudioStreamBuilder* builder, OH_AudioRenderer_OnFastStatusChange callback, void* userData); /** - * @brief xxx + * @brief Set the callback of fast status change event for audio capturer. * * @param builder Builder provided by OH_AudioStreamBuilder_Create() * @param callback Callback function that will recevie the fast status change event. * @param userData Pointer to an application data structure that will be passed to the callback functions. - * @return xxx + * @return + * {@link AUDIOSTREAM_SUCCESS} if the execution is successful. + * {@link AUDIOSTREAM_ERROR_INVALID_PARAM} the param of builder or callback is nullptr. * @since 20 */ OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerFastStatusChangeCallback(OH_AudioStreamBuilder* builder, -- Gitee