diff --git a/multimedia/audio_framework/audio_manager/native_audio_session_manager.h b/multimedia/audio_framework/audio_manager/native_audio_session_manager.h index 01df4fea37df3433bd65c1e7a305d23998e3dcab..c3b40731777332b5da0450e97416cdc03773aacb 100644 --- a/multimedia/audio_framework/audio_manager/native_audio_session_manager.h +++ b/multimedia/audio_framework/audio_manager/native_audio_session_manager.h @@ -45,6 +45,8 @@ #define NATIVE_AUDIO_SESSION_MANAGER_H #include "native_audio_common.h" +#include "native_audiostream_base.h" +#include "native_audio_device_base.h" #ifdef __cplusplus extern "C" { #endif @@ -84,6 +86,82 @@ typedef enum { CONCURRENCY_PAUSE_OTHERS = 3, } OH_AudioSession_ConcurrencyMode; +/** + * @brief Declare the audio session scene. + * + * @since 20 + */ +typedef enum { + /** + * @brief scene for media + */ + AUDIO_SESSION_SCENE_MEDIA = 0, + + /** + * @brief scene for game + */ + AUDIO_SESSION_SCENE_GAME = 1, + + /** + * @brief scene for voice communication + */ + AUDIO_SESSION_SCENE_VOICE_COMMUNICATION = 2, +} OH_AudioSession_Scene; + +/** + * @brief Declare the audio session state change hints. + * + * @since 20 + */ +typedef enum { + /** + * @brief Resume the playback + */ + AUDIO_SESSION_STATE_CHANGE_HINT_RESUME = 0, + + /** + * @brief paused/pause the playback + */ + AUDIO_SESSION_STATE_CHANGE_HINT_PAUSE = 1, + + /** + * @brief stopped/stop the playback. + */ + AUDIO_SESSION_STATE_CHANGE_HINT_STOP = 2, + + /** + * @brief stopped/stop the playback due to no audio stream for a long time. + */ + AUDIO_SESSION_STATE_CHANGE_HINT_TIME_OUT_STOP = 3, + + /** + * @brief Ducked the playback. (In ducking, the audio volume is reduced, but not silenced.) + */ + AUDIO_SESSION_STATE_CHANGE_HINT_DUCK = 4, + + /** + * @brief Unducked the playback. + */ + AUDIO_SESSION_STATE_CHANGE_HINT_UNDUCK = 5, +} OH_AudioSession_StateChangeHint; + +/** + * @brief Declare the recommend action when device change. + * + * @since 20 + */ +typedef enum { + /** + * @brief Recommend to continue the playback. + */ + DEVICE_CHANGE_RECOMMEND_TO_CONTINUE = 0, + + /** + * @brief recommend to stop the playback. + */ + DEVICE_CHANGE_RECOMMEND_TO_STOP = 1, +} OH_AudioSession_OutputDeviceChangeRecommendedAction; + /** * @brief Declare the audio deactivated reasons. * @@ -125,6 +203,47 @@ typedef struct OH_AudioSession_DeactivatedEvent { OH_AudioSession_DeactivatedReason reason; } OH_AudioSession_DeactivatedEvent; +/** + * @brief declare the audio session state change event + * + * @since 20 + */ +typedef struct OH_AudioSession_StateChangedEvent { + /** + * @brief audio session state change hints. + */ + OH_AudioSession_StateChangeHint stateChangeHint; +} OH_AudioSession_StateChangedEvent; + +/** + * @brief This function pointer will point to the callback function that + * is used to return the audio session state change event. + * + * @param event the {@link #OH_AudioSession_StateChangedEvent} state change triggering event. + * @since 20 + */ +typedef void (*OH_AudioSession_StateChangedCallback) ( + OH_AudioSession_StateChangedEvent event); + +/** + * @brief This function pointer will point to the callback function that + * is used to return the audio session device change event. + * + * @param audioDeviceDescriptorArray the {@link OH_AudioDeviceDescriptorArray} + * pointer variable which will be set the audio device descriptors value. + * Do not release the audioDeviceDescriptorArray pointer separately + * instead call {@link OH_AudioSessionManager_ReleaseDevices} + * to release the DeviceDescriptor array when it is no use anymore. + * @param changeReason the {@link #OH_AudioStream_DeviceChangeReason} indicates that why does the device changes. + * @param recommendedAction the {@link #OH_AudioSession_OutputDeviceChangeRecommendedAction} + * recommend action when device change. + * @since 20 + */ +typedef void (*OH_AudioSession_CurrentOutputDeviceChangedCallback) ( + OH_AudioDeviceDescriptorArray *devices, + OH_AudioStream_DeviceChangeReason changeReason, + OH_AudioSession_OutputDeviceChangeRecommendedAction recommendedAction); + /** * @brief This function pointer will point to the callback function that * is used to return the audio session deactivated event. @@ -150,6 +269,7 @@ OH_AudioCommon_Result OH_AudioManager_GetAudioSessionManager( /** * @brief Activate the audio session for the current pid application. + * If {@link #OH_AudioSessionManager_SetScene} is called, it will take focus when calling this method. * * @param audioSessionManager the {@link #OH_AudioSessionManager} * returned by the {@link #OH_AudioManager_GetAudioSessionManager} @@ -215,6 +335,138 @@ OH_AudioCommon_Result OH_AudioSessionManager_RegisterSessionDeactivatedCallback( */ OH_AudioCommon_Result OH_AudioSessionManager_UnregisterSessionDeactivatedCallback( OH_AudioSessionManager *audioSessionManager, OH_AudioSession_DeactivatedCallback callback); + +/** + * @brief Set scene for audio session. + * + * @param audioSessionManager the {@link #OH_AudioSessionManager} + * returned by the {@link #OH_AudioManager_GetAudioSessionManager} + * @param scene the {@link #OH_AudioSession_Scene} + * @return {@link #AUDIOCOMMON_RESULT_SUCCESS} if execution succeeds + * or {@link #AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM} if parameter validation fails + * or {@link #AUDIOCOMMON_RESULT_ERROR_ILLEGAL_STATE} if system illegal state + * or {@link #AUDIOCOMMON_RESULT_ERROR_SYSTEM} if system state error + * @since 20 + */ +OH_AudioCommon_Result OH_AudioSessionManager_SetScene( + OH_AudioSessionManager *audioSessionManager, OH_AudioSession_Scene scene); + +/** + * @brief Register the audio session state change event callback. + * + * @param audioSessionManager the {@link #OH_AudioSessionManager} + * returned by the {@link #OH_AudioManager_GetAudioSessionManager} + * @param callback the {@link #OH_AudioSession_StateChangedCallback} which is used + * to receive the state change event + * @return {@link #AUDIOCOMMON_RESULT_SUCCESS} if execution succeeds + * or {@link #AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM} if parameter validation fails + * or {@link AUDIOCOMMON_RESULT_ERROR_NO_MEMORY} No memory error + * or {@link #AUDIOCOMMON_RESULT_ERROR_SYSTEM} if system state error + * @since 20 + */ +OH_AudioCommon_Result OH_AudioSessionManager_RegisterStateChangeCallback( + OH_AudioSessionManager *audioSessionManager, OH_AudioSession_StateChangedCallback callback); + +/** + * @brief Unregister the audio session state change event callback. + * + * @param audioSessionManager the {@link #OH_AudioSessionManager} + * returned by the {@link #OH_AudioManager_GetAudioSessionManager} + * @param callback the {@link #OH_AudioSession_StateChangedCallback} which is used + * to receive the state change event + * @return {@link #AUDIOCOMMON_RESULT_SUCCESS} if execution succeeds + * or {@link #AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM} if parameter validation fails + * or {@link #AUDIOCOMMON_RESULT_ERROR_SYSTEM} if system state error + * @since 20 + */ +OH_AudioCommon_Result OH_AudioSessionManager_UnregisterStateChangeCallback( + OH_AudioSessionManager *audioSessionManager, OH_AudioSession_StateChangedCallback callback); + +/** + * @brief Sets the default output device. + * This function applys on audiorenderers whose StreamUsage are + * STREAM_USAGE_VOICE_COMMUNICATION/STREAM_USAGE_VIDEO_COMMUNICATION/STREAM_USAGE_VOICE_MESSAGE. + * Setting the device will only takes effect if no other accessory such as headphones are in use + * @param audioSessionManager the {@link #OH_AudioSessionManager} + * returned by the {@link #OH_AudioManager_GetAudioSessionManager} + * @param deviceType The target device. The available deviceTypes are: + * EARPIECE: Built-in earpiece + * SPEAKER: Built-in speaker + * DEFAULT: System default output device + * @return {@link #AUDIOCOMMON_RESULT_SUCCESS} if execution succeeds + * or {@link #AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM} if parameter validation fails + * or {@link #AUDIOCOMMON_RESULT_ERROR_SYSTEM} if system state error + * @since 20 + */ +OH_AudioCommon_Result OH_AudioSessionManager_SetDefaultOutputDevice( + OH_AudioSessionManager *audioSessionManager, OH_AudioDevice_Type deviceType); + +/** + * @brief Gets the default output device. + * + * @param audioSessionManager the {@link #OH_AudioSessionManager} + * returned by the {@link #OH_AudioManager_GetAudioSessionManager} + * @param deviceType The target device.The available deviceTypes are: + * EARPIECE: Built-in earpiece + * SPEAKER: Built-in speaker + * DEFAULT: System default output device + * @return {@link #AUDIOCOMMON_RESULT_SUCCESS} if execution succeeds + * or {@link #AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM} if parameter validation fails + * or {@link #AUDIOCOMMON_RESULT_ERROR_ILLEGAL_STATE} if system illegal state + * @since 20 + */ +OH_AudioCommon_Result OH_AudioSessionManager_GetDefaultOutputDevice( + OH_AudioSessionManager *audioSessionManager, OH_AudioDevice_Type *deviceType); + +/** + * @brief Release the audio device descriptor array object. + * + * @param audioSessionManager the {@link OH_AudioSessionManager} + * returned by the {@link #OH_AudioManager_GetAudioSessionManager} + * @param audioDeviceDescriptorArray Audio device descriptors should be released. + * @return {@link AUDIOCOMMON_RESULT_SUCCESS} If the execution is successful. + * or {@link AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM} if parameter validation fails + * 1.The param of audioSessionManager is nullptr; + * 2.The param of audioDeviceDescriptorArray is nullptr. + * @since 20 + */ +OH_AudioCommon_Result OH_AudioSessionManager_ReleaseDevices( + OH_AudioSessionManager *audioSessionManager, + OH_AudioDeviceDescriptorArray *audioDeviceDescriptorArray); + +/** + * @brief Register the audio session device change event callback. + * + * @param audioSessionManager the {@link #OH_AudioSessionManager} + * returned by the {@link #OH_AudioManager_GetAudioSessionManager} + * @param callback the {@link #OH_AudioSession_CurrentOutputDeviceChangedCallback} which is used + * to receive the device change event + * @return {@link #AUDIOCOMMON_RESULT_SUCCESS} if execution succeeds + * or {@link #AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM} if parameter validation fails + * or {@link AUDIOCOMMON_RESULT_ERROR_NO_MEMORY} No memory error + * or {@link #AUDIOCOMMON_RESULT_ERROR_SYSTEM} if system state error + * @since 20 + */ +OH_AudioCommon_Result OH_AudioSessionManager_RegisterCurrentOutputDeviceChangeCallback( + OH_AudioSessionManager *audioSessionManager, + OH_AudioSession_CurrentOutputDeviceChangedCallback callback); + +/** + * @brief Unregister the audio session device change event callback. + * + * @param audioSessionManager the {@link #OH_AudioSessionManager} + * returned by the {@link #OH_AudioManager_GetAudioSessionManager} + * @param callback the {@link #OH_AudioSession_CurrentOutputDeviceChangedCallback} which is used + * to receive the device change event + * @return {@link #AUDIOCOMMON_RESULT_SUCCESS} if execution succeeds + * or {@link #AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM} if parameter validation fails + * or {@link #AUDIOCOMMON_RESULT_ERROR_SYSTEM} if system state error + * @since 20 + */ +OH_AudioCommon_Result OH_AudioSessionManager_UnregisterCurrentOutputDeviceChangeCallback( + OH_AudioSessionManager *audioSessionManager, + OH_AudioSession_CurrentOutputDeviceChangedCallback callback); + #ifdef __cplusplus } #endif diff --git a/multimedia/audio_framework/common/native_audiostream_base.h b/multimedia/audio_framework/common/native_audiostream_base.h index 9b763054bc9bff2e1bf5b9b4490f33b99a52fbce..2d2a6dc040d52358adc6be4c69dfc0c057b9613d 100644 --- a/multimedia/audio_framework/common/native_audiostream_base.h +++ b/multimedia/audio_framework/common/native_audiostream_base.h @@ -774,6 +774,18 @@ typedef enum { REASON_OLD_DEVICE_UNAVAILABLE = 2, /* Device is overrode by user or system. */ REASON_OVERRODE = 3, + /** + * @brief Device information when the audio session is activated. + * + * @since 20 + */ + REASON_SESSION_ACTIVATED = 4, + /** + * @brief There is a higher-priority stream, causing the system device to change. + * + * @since 20 + */ + REASON_STREAM_PRIORITY_CHANGED = 5, } OH_AudioStream_DeviceChangeReason; /** diff --git a/multimedia/audio_framework/ohaudio.ndk.json b/multimedia/audio_framework/ohaudio.ndk.json index 5ff756f754df6bf4290459f5e02e231ed24d113f..858a405ccc3ce5403e73550e770a5889ef7e7db3 100644 --- a/multimedia/audio_framework/ohaudio.ndk.json +++ b/multimedia/audio_framework/ohaudio.ndk.json @@ -347,6 +347,38 @@ "first_introduced": "12", "name":"OH_AudioSessionManager_UnregisterSessionDeactivatedCallback" }, + { + "first_introduced": "12", + "name":"OH_AudioSessionManager_SetScene" + }, + { + "first_introduced": "12", + "name":"OH_AudioSessionManager_RegisterStateChangeCallback" + }, + { + "first_introduced": "12", + "name":"OH_AudioSessionManager_UnregisterStateChangeCallback" + }, + { + "first_introduced": "12", + "name":"OH_AudioSessionManager_SetDefaultOutputDevice" + }, + { + "first_introduced": "12", + "name":"OH_AudioSessionManager_GetDefaultOutputDevice" + }, + { + "first_introduced": "12", + "name":"OH_AudioSessionManager_ReleaseDevices" + }, + { + "first_introduced": "12", + "name":"OH_AudioSessionManager_RegisterCurrentOutputDeviceChangeCallback" + }, + { + "first_introduced": "12", + "name":"OH_AudioSessionManager_UnregisterCurrentOutputDeviceChangeCallback" + }, { "first_introduced": "12", "name": "OH_GetAudioManager"