diff --git a/frameworks/native/audiocapturer/include/audio_capturer_proxy_obj.h b/frameworks/native/audiocapturer/include/audio_capturer_proxy_obj.h index ecb2c9deac932c32a74ce02b6ab964105cadc568..40f217ec2d6c6a36b1927acbb0b93b99b68f3142 100644 --- a/frameworks/native/audiocapturer/include/audio_capturer_proxy_obj.h +++ b/frameworks/native/audiocapturer/include/audio_capturer_proxy_obj.h @@ -31,6 +31,7 @@ public: void SetLowPowerVolumeImpl(float volume); void GetLowPowerVolumeImpl(float &volume); + void GetSingleStreamVolumeImpl(float &volume); private: const AudioCapturer *capturer; diff --git a/frameworks/native/audiocapturer/src/audio_capturer_proxy_obj.cpp b/frameworks/native/audiocapturer/src/audio_capturer_proxy_obj.cpp index eb2ee57e6d9881b9f4e9b01373635e65dbbdbe11..7b9e2cc89a5e30b54a0574e77e60e89293ebe2de 100644 --- a/frameworks/native/audiocapturer/src/audio_capturer_proxy_obj.cpp +++ b/frameworks/native/audiocapturer/src/audio_capturer_proxy_obj.cpp @@ -45,5 +45,10 @@ void AudioCapturerProxyObj::GetLowPowerVolumeImpl(float &volume) { volume = 1.0; } + +void AudioCapturerProxyObj::GetSingleStreamVolumeImpl(float &volume) +{ + volume = 0; +} } // namespace AudioStandard } // namespace OHOS diff --git a/frameworks/native/audiopolicy/include/audio_policy_manager.h b/frameworks/native/audiopolicy/include/audio_policy_manager.h index 3fb067d5e18cd55466e89be19341164775c22047..91e464a2b8e16f1287a9816ab1ee967348e31c34 100644 --- a/frameworks/native/audiopolicy/include/audio_policy_manager.h +++ b/frameworks/native/audiopolicy/include/audio_policy_manager.h @@ -56,6 +56,8 @@ public: float GetLowPowerVolume(int32_t streamId); + float GetSingleStreamVolume(int32_t streamId); + int32_t SetStreamMute(AudioStreamType streamType, bool mute); bool GetStreamMute(AudioStreamType streamType); diff --git a/frameworks/native/audiorenderer/include/audio_renderer_private.h b/frameworks/native/audiorenderer/include/audio_renderer_private.h index be5f047ec0c6c495db478566e05da2f9969a35fd..8da12141e50e4d1a17037fd34bea8a0af2b6c114 100644 --- a/frameworks/native/audiorenderer/include/audio_renderer_private.h +++ b/frameworks/native/audiorenderer/include/audio_renderer_private.h @@ -68,6 +68,7 @@ public: void SetInterruptMode(InterruptMode mode) override; int32_t SetLowPowerVolume(float volume) const override; float GetLowPowerVolume() const override; + float GetSingleStreamVolume() const override; AudioRendererInfo rendererInfo_ = {}; diff --git a/frameworks/native/audiorenderer/include/audio_renderer_proxy_obj.h b/frameworks/native/audiorenderer/include/audio_renderer_proxy_obj.h index 9d0d429750c367286563dc29595a26d2170def63..4633cf8cde9ab608901b5c21b09611afe35cef67 100644 --- a/frameworks/native/audiorenderer/include/audio_renderer_proxy_obj.h +++ b/frameworks/native/audiorenderer/include/audio_renderer_proxy_obj.h @@ -30,6 +30,7 @@ public: void ResumeStreamImpl(const StreamSetStateEventInternal &streamSetStateEventInternal); void SetLowPowerVolumeImpl(float volume); void GetLowPowerVolumeImpl(float &volume); + void GetSingleStreamVolumeImpl(float &volume); private: const AudioRenderer *renderer; }; diff --git a/frameworks/native/audiorenderer/src/audio_renderer.cpp b/frameworks/native/audiorenderer/src/audio_renderer.cpp index e79e22021ea3f05d767a9c2512e269727322a009..cfcc9b39517e12082403ca8dce89596de33de550 100644 --- a/frameworks/native/audiorenderer/src/audio_renderer.cpp +++ b/frameworks/native/audiorenderer/src/audio_renderer.cpp @@ -716,5 +716,10 @@ float AudioRendererPrivate::GetLowPowerVolume() const { return audioStream_->GetLowPowerVolume(); } + +float AudioRendererPrivate::GetSingleStreamVolume() const +{ + return audioStream_->GetSingleStreamVolume(); +} } // namespace AudioStandard } // namespace OHOS diff --git a/frameworks/native/audiorenderer/src/audio_renderer_proxy_obj.cpp b/frameworks/native/audiorenderer/src/audio_renderer_proxy_obj.cpp index d13602750f15299a13cfe934543d923c87238190..afd42c376f9a6b6660b5cfa6c32c4254c3d13015 100644 --- a/frameworks/native/audiorenderer/src/audio_renderer_proxy_obj.cpp +++ b/frameworks/native/audiorenderer/src/audio_renderer_proxy_obj.cpp @@ -45,5 +45,10 @@ void AudioRendererProxyObj::GetLowPowerVolumeImpl(float &volume) { volume = renderer->GetLowPowerVolume(); } + +void AudioRendererProxyObj::GetSingleStreamVolumeImpl(float &volume) +{ + volume = renderer->GetSingleStreamVolume(); +} } // namespace AudioStandard } // namespace OHOS diff --git a/frameworks/native/audiostream/include/audio_stream.h b/frameworks/native/audiostream/include/audio_stream.h index fef8ed041edc21bc4608691c66a3297378fd1810..de028acc18026327d2b45a0198a40d588dff43db 100644 --- a/frameworks/native/audiostream/include/audio_stream.h +++ b/frameworks/native/audiostream/include/audio_stream.h @@ -62,6 +62,7 @@ public: int32_t Clear(); int32_t SetLowPowerVolume(float volume); float GetLowPowerVolume(); + float GetSingleStreamVolume(); std::vector GetSupportedFormats() const; std::vector GetSupportedEncodingTypes() const; diff --git a/interfaces/inner_api/native/audiomanager/include/audio_stream_manager.h b/interfaces/inner_api/native/audiomanager/include/audio_stream_manager.h index 2c06e7e78311bb72fb1d8c670cfce5523768e096..59cb3110923634fc519fc082abe8175e4eea1a1a 100644 --- a/interfaces/inner_api/native/audiomanager/include/audio_stream_manager.h +++ b/interfaces/inner_api/native/audiomanager/include/audio_stream_manager.h @@ -63,6 +63,7 @@ public: virtual void ResumeStreamImpl(const StreamSetStateEventInternal &streamSetStateEventInternal) = 0; virtual void SetLowPowerVolumeImpl(float volume) = 0; virtual void GetLowPowerVolumeImpl(float &volume) = 0; + virtual void GetSingleStreamVolumeImpl(float &volume) = 0; }; class AudioStreamManager { diff --git a/interfaces/inner_api/native/audiomanager/include/audio_system_manager.h b/interfaces/inner_api/native/audiomanager/include/audio_system_manager.h index 9e7dc71f563363e9449e7b33708ef285f9da7c77..d248f7448bd3ee5df0350b3aed7b70a0d932397a 100644 --- a/interfaces/inner_api/native/audiomanager/include/audio_system_manager.h +++ b/interfaces/inner_api/native/audiomanager/include/audio_system_manager.h @@ -212,6 +212,7 @@ public: int32_t GetVolume(AudioVolumeType volumeType) const; int32_t SetLowPowerVolume(int32_t streamId, float volume) const; float GetLowPowerVolume(int32_t streamId) const; + float GetSingleStreamVolume(int32_t streamId) const; int32_t GetMaxVolume(AudioVolumeType volumeType); int32_t GetMinVolume(AudioVolumeType volumeType); int32_t SetMute(AudioVolumeType volumeType, bool mute) const; diff --git a/interfaces/inner_api/native/audiorenderer/include/audio_renderer.h b/interfaces/inner_api/native/audiorenderer/include/audio_renderer.h index 56a86b3a8193ecfd897b0720b75104710ffc1d1a..d6fc209830e524210b6b52a7a3c1ec54d1c9f011 100644 --- a/interfaces/inner_api/native/audiorenderer/include/audio_renderer.h +++ b/interfaces/inner_api/native/audiorenderer/include/audio_renderer.h @@ -538,6 +538,14 @@ public: * @return volume adjustment percentage. */ virtual float GetLowPowerVolume() const = 0; + + /** + * @brief Get single stream volume. + * + * @param none. + * @return single stream volume. + */ + virtual float GetSingleStreamVolume() const = 0; virtual ~AudioRenderer(); }; diff --git a/services/include/audio_policy/client/audio_client_tracker_callback_stub.h b/services/include/audio_policy/client/audio_client_tracker_callback_stub.h index 9e97a5cfb61512bec993a34860d5c37cc3cb7a41..b9fef89615a73886204c9a3ed2bcac988eb3cbaf 100644 --- a/services/include/audio_policy/client/audio_client_tracker_callback_stub.h +++ b/services/include/audio_policy/client/audio_client_tracker_callback_stub.h @@ -34,6 +34,7 @@ public: void SetLowPowerVolumeImpl(float volume) override; void GetLowPowerVolumeImpl(float &volume) override; + void GetSingleStreamVolumeImpl(float &volume) override; private: std::weak_ptr callback_; diff --git a/services/include/audio_policy/client/audio_policy_base.h b/services/include/audio_policy/client/audio_policy_base.h index 34e5fe3df2804c79ef7f3bf6f2775b5ee01a85e4..7534b95eb891846c75d85ac133008a34279c856d 100644 --- a/services/include/audio_policy/client/audio_policy_base.h +++ b/services/include/audio_policy/client/audio_policy_base.h @@ -38,6 +38,8 @@ public: virtual float GetLowPowerVolume(int32_t streamId) = 0; + virtual float GetSingleStreamVolume(int32_t streamId) = 0; + virtual int32_t SetStreamMute(AudioStreamType streamType, bool mute) = 0; virtual bool GetStreamMute(AudioStreamType streamType) = 0; diff --git a/services/include/audio_policy/client/audio_policy_manager_stub.h b/services/include/audio_policy/client/audio_policy_manager_stub.h index 8b6189140696ef86a99352571eff0ce32671148e..0f0896c9db3d8310c11f87811bebac9c4aeb6bff 100644 --- a/services/include/audio_policy/client/audio_policy_manager_stub.h +++ b/services/include/audio_policy/client/audio_policy_manager_stub.h @@ -34,6 +34,7 @@ private: void GetStreamVolumeInternal(MessageParcel &data, MessageParcel &reply); void SetLowPowerVolumeInternal(MessageParcel &data, MessageParcel &reply); void GetLowPowerVolumeInternal(MessageParcel &data, MessageParcel &reply); + void GetSingleStreamVolumeInternal(MessageParcel &data, MessageParcel &reply); void SetStreamMuteInternal(MessageParcel &data, MessageParcel &reply); void GetStreamMuteInternal(MessageParcel &data, MessageParcel &reply); void IsStreamActiveInternal(MessageParcel &data, MessageParcel &reply); diff --git a/services/include/audio_policy/client/audio_policy_proxy.h b/services/include/audio_policy/client/audio_policy_proxy.h index 875825836a2f2a27f54b1e53d05c369d0109c285..e4458d25c54daffc55c8784e17a6b6344fb5abf5 100644 --- a/services/include/audio_policy/client/audio_policy_proxy.h +++ b/services/include/audio_policy/client/audio_policy_proxy.h @@ -36,6 +36,8 @@ public: float GetLowPowerVolume(int32_t streamId) override; + float GetSingleStreamVolume(int32_t streamId) override; + int32_t SetStreamMute(AudioStreamType streamType, bool mute) override; bool GetStreamMute(AudioStreamType streamType) override; diff --git a/services/include/audio_policy/common/audio_policy_types.h b/services/include/audio_policy/common/audio_policy_types.h index f7c15027258b2feef45acc6c8d6ddc35fddcbf25..cb2396914c5af339546443de076b5074a40f3ee3 100644 --- a/services/include/audio_policy/common/audio_policy_types.h +++ b/services/include/audio_policy/common/audio_policy_types.h @@ -69,6 +69,7 @@ enum AudioPolicyCommand { SET_LOW_POWER_STREM_VOLUME, GET_LOW_POWRR_STREM_VOLUME, UPDATE_STREAM_STATE, + GET_SINGLE_STREAM_VOLUME, }; } // namespace AudioStandard } // namespace OHOS diff --git a/services/include/audio_policy/common/i_standard_client_tracker.h b/services/include/audio_policy/common/i_standard_client_tracker.h index 50f5777ef63c16169d69a5d5eeab71e02b919fc9..182bbd79d5f709080d513eaa7fb181f5ebf10196 100644 --- a/services/include/audio_policy/common/i_standard_client_tracker.h +++ b/services/include/audio_policy/common/i_standard_client_tracker.h @@ -31,6 +31,7 @@ public: virtual void ResumeStreamImpl(const StreamSetStateEventInternal &streamSetStateEventInternal) = 0; virtual void SetLowPowerVolumeImpl(float volume) = 0; virtual void GetLowPowerVolumeImpl(float& volume) = 0; + virtual void GetSingleStreamVolumeImpl(float& volume) = 0; enum AudioClientTrackerMsg { ON_ERROR = 0, @@ -39,6 +40,7 @@ public: GETLOWPOWERVOL, PAUSEDSTREAM, RESUMESTREAM, + GETSINGLESTREAMVOL, }; DECLARE_INTERFACE_DESCRIPTOR(u"IStandardClientTracker"); diff --git a/services/include/audio_policy/server/audio_client_tracker_callback_proxy.h b/services/include/audio_policy/server/audio_client_tracker_callback_proxy.h index e4d0c0ba3457063143e8fdec5300ad106260d90d..bcf7f4f3040e5f2ecfa9819fc18787d2d5ec2d34 100644 --- a/services/include/audio_policy/server/audio_client_tracker_callback_proxy.h +++ b/services/include/audio_policy/server/audio_client_tracker_callback_proxy.h @@ -33,6 +33,7 @@ public: virtual void SetLowPowerVolumeImpl(float volume) override; virtual void GetLowPowerVolumeImpl(float &volume) override; + virtual void GetSingleStreamVolumeImpl(float &volume) override; private: sptr listener_ = nullptr; @@ -47,6 +48,7 @@ public: virtual void SetLowPowerVolumeImpl(float volume) override; virtual void GetLowPowerVolumeImpl(float &volume) override; + virtual void GetSingleStreamVolumeImpl(float &volume) override; private: static inline BrokerDelegator delegator_; diff --git a/services/include/audio_policy/server/audio_policy_server.h b/services/include/audio_policy/server/audio_policy_server.h index b5f64394ce47057a4a9f806e2213790ede553f52..a4889e06a931498357fdf22dd9a61aa2f50b8ea9 100644 --- a/services/include/audio_policy/server/audio_policy_server.h +++ b/services/include/audio_policy/server/audio_policy_server.h @@ -58,6 +58,8 @@ public: float GetLowPowerVolume(int32_t streamId) override; + float GetSingleStreamVolume(int32_t streamId) override; + int32_t SetStreamMute(AudioStreamType streamType, bool mute) override; bool GetStreamMute(AudioStreamType streamType) override; diff --git a/services/include/audio_policy/server/audio_stream_collector.h b/services/include/audio_policy/server/audio_stream_collector.h index 7b5bb3475199f6465de0c5f819e9e4b85ccbc427..cf7a6feda90c94f6d090292329ed7b2cf8940230 100644 --- a/services/include/audio_policy/server/audio_stream_collector.h +++ b/services/include/audio_policy/server/audio_stream_collector.h @@ -48,6 +48,7 @@ public: int32_t UpdateStreamState(int32_t clientUid, StreamSetStateEventInternal &streamSetStateEventInternal); int32_t SetLowPowerVolume(int32_t streamId, float volume); float GetLowPowerVolume(int32_t streamId); + float GetSingleStreamVolume(int32_t streamId); private: AudioStreamEventDispatcher &mDispatcherService; std::mutex streamsInfoMutex_; diff --git a/services/include/audio_policy/server/service/audio_policy_service.h b/services/include/audio_policy/server/service/audio_policy_service.h index eb2998ff62826667c0a8f5968c42ea7877d0c05b..7e9945f803a1ab06b915f3a530c95ef6e9113652 100644 --- a/services/include/audio_policy/server/service/audio_policy_service.h +++ b/services/include/audio_policy/server/service/audio_policy_service.h @@ -53,6 +53,8 @@ public: float GetLowPowerVolume(int32_t streamId) const; + float GetSingleStreamVolume(int32_t streamId) const; + int32_t SetStreamMute(AudioStreamType streamType, bool mute) const; bool GetStreamMute(AudioStreamType streamType) const; diff --git a/services/include/audio_service/client/audio_service_client.h b/services/include/audio_service/client/audio_service_client.h index 439bc0b2f0fce896a9c40ea4a569d89094b66e14..9fe5f7288214996ac1479af23db8eb19fd48bf58 100644 --- a/services/include/audio_service/client/audio_service_client.h +++ b/services/include/audio_service/client/audio_service_client.h @@ -498,6 +498,7 @@ public: bool VerifyClientPermission(const std::string &permissionName, uint32_t appTokenId, int32_t appUid); int32_t SetStreamLowPowerVolume(float powerVolumeFactor); float GetStreamLowPowerVolume(); + float GetSingleStreamVol(); // Audio timer callback virtual void OnTimeOut(); diff --git a/services/src/audio_policy/client/audio_client_tracker_callback_stub.cpp b/services/src/audio_policy/client/audio_client_tracker_callback_stub.cpp index ce8acad532722e64ff5e204cb3ad0666fec1e6ab..7f5e05c24ca7e45878058ba1f8156aeb60f3883b 100644 --- a/services/src/audio_policy/client/audio_client_tracker_callback_stub.cpp +++ b/services/src/audio_policy/client/audio_client_tracker_callback_stub.cpp @@ -59,7 +59,12 @@ int AudioClientTrackerCallbackStub::OnRemoteRequest( float volume; GetLowPowerVolumeImpl(volume); reply.WriteFloat(volume); - data.WriteFloat(static_cast(volume)); + return AUDIO_OK; + } + case GETSINGLESTREAMVOL: { + float volume; + GetSingleStreamVolumeImpl(volume); + reply.WriteFloat(volume); return AUDIO_OK; } default: { @@ -97,7 +102,7 @@ void AudioClientTrackerCallbackStub::SetLowPowerVolumeImpl(float volume) if (cb != nullptr) { cb->SetLowPowerVolumeImpl(volume); } else { - AUDIO_ERR_LOG("AudioClientTrackerCallbackStub: callback_ is nullptr"); + AUDIO_ERR_LOG("AudioClientTrackerCallbackStub: SetLowPowerVolumeImpl callback_ is nullptr"); } } @@ -120,7 +125,18 @@ void AudioClientTrackerCallbackStub::GetLowPowerVolumeImpl(float &volume) if (cb != nullptr) { cb->GetLowPowerVolumeImpl(volume); } else { - AUDIO_ERR_LOG("AudioClientTrackerCallbackStub: callback_ is nullptr"); + AUDIO_ERR_LOG("AudioClientTrackerCallbackStub: GetLowPowerVolumeImpl callback_ is nullptr"); + } +} + +void AudioClientTrackerCallbackStub::GetSingleStreamVolumeImpl(float &volume) +{ + AUDIO_DEBUG_LOG("AudioClientTrackerCallbackStub GetSingleStreamVolumeImpl start"); + std::shared_ptr cb = callback_.lock(); + if (cb != nullptr) { + cb->GetSingleStreamVolumeImpl(volume); + } else { + AUDIO_ERR_LOG("AudioClientTrackerCallbackStub: GetSingleStreamVolumeImpl callback_ is nullptr"); } } } // namespace AudioStandard diff --git a/services/src/audio_policy/client/audio_policy_manager.cpp b/services/src/audio_policy/client/audio_policy_manager.cpp index 821b0e035f4ae70b7366a7afdb9f4dba5f5ec9d1..510e4018e652caceac524de99c2d2e589ab84401 100644 --- a/services/src/audio_policy/client/audio_policy_manager.cpp +++ b/services/src/audio_policy/client/audio_policy_manager.cpp @@ -122,6 +122,11 @@ float AudioPolicyManager::GetLowPowerVolume(int32_t streamId) return g_sProxy->GetLowPowerVolume(streamId); } +float AudioPolicyManager::GetSingleStreamVolume(int32_t streamId) +{ + return g_sProxy->GetSingleStreamVolume(streamId); +} + bool AudioPolicyManager::IsStreamActive(AudioStreamType streamType) { return g_sProxy->IsStreamActive(streamType); diff --git a/services/src/audio_policy/client/audio_policy_proxy.cpp b/services/src/audio_policy/client/audio_policy_proxy.cpp index 5d61c6c2b4c0da91b61a65e35f1b90e0d0d3ea91..9cfe004520e79c45690bbb8adebb2dcfc61135bf 100644 --- a/services/src/audio_policy/client/audio_policy_proxy.cpp +++ b/services/src/audio_policy/client/audio_policy_proxy.cpp @@ -221,6 +221,25 @@ float AudioPolicyProxy::GetLowPowerVolume(int32_t streamId) return reply.ReadFloat(); } +float AudioPolicyProxy::GetSingleStreamVolume(int32_t streamId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!data.WriteInterfaceToken(GetDescriptor())) { + AUDIO_ERR_LOG("AudioPolicyProxy: WriteInterfaceToken failed"); + return -1; + } + data.WriteInt32(streamId); + int32_t error = Remote()->SendRequest(GET_SINGLE_STREAM_VOLUME, data, reply, option); + if (error != ERR_NONE) { + AUDIO_ERR_LOG("get single stream volume failed, error: %d", error); + return error; + } + return reply.ReadFloat(); +} + int32_t AudioPolicyProxy::SetStreamMute(AudioStreamType streamType, bool mute) { MessageParcel data; diff --git a/services/src/audio_policy/server/audio_client_tracker_callback_proxy.cpp b/services/src/audio_policy/server/audio_client_tracker_callback_proxy.cpp index ea23ef8ccf5dcf05f3e72a6ce8267af9b145fd02..9c1a859dc270e61886f47868bc8905e38907c655 100644 --- a/services/src/audio_policy/server/audio_client_tracker_callback_proxy.cpp +++ b/services/src/audio_policy/server/audio_client_tracker_callback_proxy.cpp @@ -93,6 +93,24 @@ void AudioClientTrackerCallbackProxy::GetLowPowerVolumeImpl(float &volume) volume = reply.ReadFloat(); } +void AudioClientTrackerCallbackProxy::GetSingleStreamVolumeImpl(float &volume) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + AUDIO_ERR_LOG("AudioClientTrackerCallbackProxy: WriteInterfaceToken failed"); + return; + } + + int error = Remote()->SendRequest(GETSINGLESTREAMVOL, data, reply, option); + if (error != ERR_NONE) { + AUDIO_ERR_LOG("GETSINGLESTREAMVOL failed, error: %{public}d", error); + } + + volume = reply.ReadFloat(); +} + ClientTrackerCallbackListener::ClientTrackerCallbackListener(const sptr &listener) : listener_(listener) { @@ -134,5 +152,12 @@ void ClientTrackerCallbackListener::GetLowPowerVolumeImpl(float &volume) listener_->GetLowPowerVolumeImpl(volume); } } + +void ClientTrackerCallbackListener::GetSingleStreamVolumeImpl(float &volume) +{ + if (listener_ != nullptr) { + listener_->GetSingleStreamVolumeImpl(volume); + } +} } // namespace AudioStandard } // namespace OHOS diff --git a/services/src/audio_policy/server/audio_policy_manager_stub.cpp b/services/src/audio_policy/server/audio_policy_manager_stub.cpp index 2d27c962904e9b62dbd33050a80947dce9df931c..1235b86b951196c4d3bd4edd86d1e75fa46b5759 100644 --- a/services/src/audio_policy/server/audio_policy_manager_stub.cpp +++ b/services/src/audio_policy/server/audio_policy_manager_stub.cpp @@ -130,6 +130,13 @@ void AudioPolicyManagerStub::GetLowPowerVolumeInternal(MessageParcel &data, Mess reply.WriteFloat(volume); } +void AudioPolicyManagerStub::GetSingleStreamVolumeInternal(MessageParcel &data, MessageParcel &reply) +{ + int32_t streamId = data.ReadInt32(); + float volume = GetSingleStreamVolume(streamId); + reply.WriteFloat(volume); +} + void AudioPolicyManagerStub::SetStreamMuteInternal(MessageParcel &data, MessageParcel &reply) { AudioStreamType streamType = static_cast(data.ReadInt32()); @@ -807,6 +814,10 @@ int AudioPolicyManagerStub::OnRemoteRequest( GetLowPowerVolumeInternal(data, reply); break; + case GET_SINGLE_STREAM_VOLUME: + GetSingleStreamVolumeInternal(data, reply); + break; + default: AUDIO_ERR_LOG("default case, need check AudioPolicyManagerStub"); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); diff --git a/services/src/audio_policy/server/audio_policy_server.cpp b/services/src/audio_policy/server/audio_policy_server.cpp index 4b841aa881d800fb4e6ee41ca7beebbded90fca2..2f2b97d63cd1cb2c4af30f0e979ba2e3287a6927 100644 --- a/services/src/audio_policy/server/audio_policy_server.cpp +++ b/services/src/audio_policy/server/audio_policy_server.cpp @@ -251,6 +251,11 @@ float AudioPolicyServer::GetLowPowerVolume(int32_t streamId) return mPolicyService.GetLowPowerVolume(streamId); } +float AudioPolicyServer::GetSingleStreamVolume(int32_t streamId) +{ + return mPolicyService.GetSingleStreamVolume(streamId); +} + int32_t AudioPolicyServer::SetStreamMute(AudioStreamType streamType, bool mute) { if (streamType == AudioStreamType::STREAM_RING) { diff --git a/services/src/audio_policy/server/audio_stream_collector.cpp b/services/src/audio_policy/server/audio_stream_collector.cpp index d11b677e7d22398d923e08d47cf3d07e95adbdc6..29c92baaab1bccc0ff4aa34b102990f26bf366cf 100644 --- a/services/src/audio_policy/server/audio_stream_collector.cpp +++ b/services/src/audio_policy/server/audio_stream_collector.cpp @@ -490,5 +490,17 @@ float AudioStreamCollector::GetLowPowerVolume(int32_t streamId) callback->GetLowPowerVolumeImpl(volume); return volume; } + +float AudioStreamCollector::GetSingleStreamVolume(int32_t streamId) +{ + CHECK_AND_RETURN_RET_LOG(!(clientTracker_.count(streamId) == 0), + ERR_INVALID_PARAM, "AudioStreamCollector:GetSingleStreamVolume streamId invalid."); + float volume; + std::shared_ptr callback = clientTracker_[streamId]; + CHECK_AND_RETURN_RET_LOG(callback != nullptr, + ERR_INVALID_PARAM, "AudioStreamCollector:GetSingleStreamVolume callback failed"); + callback->GetSingleStreamVolumeImpl(volume); + return volume; +} } // namespace AudioStandard } // namespace OHOS diff --git a/services/src/audio_policy/server/service/audio_policy_service.cpp b/services/src/audio_policy/server/service/audio_policy_service.cpp index 288a6abe72633404341bf9fdcd958b582b2be617..a5d24ab790b7ac3cc9a896d4ed49e47b643b9598 100644 --- a/services/src/audio_policy/server/service/audio_policy_service.cpp +++ b/services/src/audio_policy/server/service/audio_policy_service.cpp @@ -145,6 +145,11 @@ float AudioPolicyService::GetLowPowerVolume(int32_t streamId) const return mStreamCollector.GetLowPowerVolume(streamId); } +float AudioPolicyService::GetSingleStreamVolume(int32_t streamId) const +{ + return mStreamCollector.GetSingleStreamVolume(streamId); +} + int32_t AudioPolicyService::SetStreamMute(AudioStreamType streamType, bool mute) const { return mAudioPolicyManager.SetStreamMute(streamType, mute); diff --git a/services/src/audio_service/client/audio_service_client.cpp b/services/src/audio_service/client/audio_service_client.cpp index 677239bde05b11bd19efa91c59dcc976019ac45b..09d4eed7b2d30cb989c09b6a23a95b4665078fc6 100644 --- a/services/src/audio_service/client/audio_service_client.cpp +++ b/services/src/audio_service/client/audio_service_client.cpp @@ -2298,5 +2298,27 @@ float AudioServiceClient::GetStreamLowPowerVolume() { return mPowerVolumeFactor; } + +float AudioServiceClient::GetSingleStreamVol() +{ + int32_t systemVolumeInt = mAudioSystemMgr->GetVolume(static_cast(mStreamType)); + float systemVolume = AudioSystemManager::MapVolumeToHDI(systemVolumeInt); + float vol = systemVolume * mVolumeFactor * mPowerVolumeFactor; + + AudioRingerMode ringerMode = mAudioSystemMgr->GetRingerMode(); + if ((mStreamType == STREAM_RING) && (ringerMode != RINGER_MODE_NORMAL)) { + vol = MIN_STREAM_VOLUME_LEVEL; + } + + if (mAudioSystemMgr->IsStreamMute(static_cast(mStreamType))) { + if (mUnMute_) { + mAudioSystemMgr->SetMute(static_cast(mStreamType), false); + } else { + vol = MIN_STREAM_VOLUME_LEVEL; + } + } + + return vol; +} } // namespace AudioStandard } // namespace OHOS diff --git a/services/src/audio_service/client/audio_stream.cpp b/services/src/audio_service/client/audio_stream.cpp index 4bd131cf3b27a89123b507b15a7579c5af6bd5f5..ff73d8b9ec0ad485042663bd210144ab7b8a6547 100644 --- a/services/src/audio_service/client/audio_stream.cpp +++ b/services/src/audio_service/client/audio_stream.cpp @@ -945,5 +945,10 @@ float AudioStream::GetLowPowerVolume() { return GetStreamLowPowerVolume(); } + +float AudioStream::GetSingleStreamVolume() +{ + return GetSingleStreamVol(); +} } // namespace AudioStandard } // namespace OHOS diff --git a/services/src/audio_service/client/audio_system_manager.cpp b/services/src/audio_service/client/audio_system_manager.cpp index 02eac4d6e7eb481a412792d304a2c7fe623dfa9a..aa165a5d32bb10da0b5ffd62144ece04bf59259b 100644 --- a/services/src/audio_service/client/audio_system_manager.cpp +++ b/services/src/audio_service/client/audio_system_manager.cpp @@ -343,6 +343,11 @@ float AudioSystemManager::GetLowPowerVolume(int32_t streamId) const return AudioPolicyManager::GetInstance().GetLowPowerVolume(streamId); } +float AudioSystemManager::GetSingleStreamVolume(int32_t streamId) const +{ + return AudioPolicyManager::GetInstance().GetSingleStreamVolume(streamId); +} + float AudioSystemManager::MapVolumeToHDI(int32_t volume) { float value = (float)volume / MAX_VOLUME_LEVEL; diff --git a/services/test/audio_policy_test.cpp b/services/test/audio_policy_test.cpp index c29273e53c4ed29d008f9ba6f5fe62be3cf85bc6..6327c93000c5538508e55f9f91f917b53a073bc8 100644 --- a/services/test/audio_policy_test.cpp +++ b/services/test/audio_policy_test.cpp @@ -43,6 +43,8 @@ namespace AudioPolicyTest { const int TWELFTH_ARG = 12; const int OPT_ARG_BASE = 10; const int OPT_SHORT_LEN = 3; + const int OPT_GET_VOL_FACTOR = 1; + const int OPT_GET_SS_VOL = 2; } static void PrintUsage(void) @@ -73,10 +75,8 @@ static void PrintUsage(void) cout << "-r\n\tGets RingerMode status" << endl << endl; cout << "-C\n\tSets AudioScene" << endl << endl; cout << "-c\n\tGets AudioScene status" << endl << endl; - cout << "-N\n\tSet the discount volume factor to 0" << endl << endl; - cout << "-O\n\tSet the discount volume factor to 0.5f" << endl << endl; - cout << "-P\n\tSet the discount volume factor to 1.0f" << endl << endl; - cout << "-G\n\tGet the discount volume factor" << endl << endl; + cout << "-N\n\tSet the discount volume factor" << endl << endl; + cout << "-n\n\tGet the discount volume factor or Get single stream volume" << endl << endl; cout << "-s\n\tGet Stream Status" << endl << endl; cout << "AUTHOR" << endl << endl; cout << "\tWritten by Sajeesh Sidharthan and Anurup M" << endl << endl; @@ -384,31 +384,34 @@ static void HandleUpdateStreamState(int type, char *seg1) cout << "result : " << result << endl; } -static void HandleLowPowerVolumeOption(char option) +static void HandleSingleStreamVolumeOption(int argc, char* argv[], char opt) { + if (argc != AudioPolicyTest::FOURTH_ARG) { + cout << "Incorrect number of test commands." << endl; + return; + } + AudioSystemManager *audioSystemMgr = AudioSystemManager::GetInstance(); - int32_t streamId = stoi(optarg); - switch (option) { - case 'N': - audioSystemMgr->SetLowPowerVolume(streamId, 0); - cout << "Set low power volume 0" << endl; - break; - case 'O': - audioSystemMgr->SetLowPowerVolume(streamId, 0.5f); - cout << "Set low power volume 0.5" << endl; - break; - case 'P': - audioSystemMgr->SetLowPowerVolume(streamId, 1.0f); - cout << "Set low power volume 1.0" << endl; - break; - case 'G': { + int32_t streamId = atoi(argv[AudioPolicyTest::SECOND_ARG]); + if (opt == 'N') { + float volume = atof(argv[AudioPolicyTest::THIRD_ARG]); + if (volume < 0 || volume > 1.0f) { + cout << "volume out of range." << endl; + return; + } + audioSystemMgr->SetLowPowerVolume(streamId, volume); + cout << "Set low power volume :" << volume << endl; + } else { + int32_t opt_flag = atoi(argv[AudioPolicyTest::THIRD_ARG]); + if (opt_flag == AudioPolicyTest::OPT_GET_VOL_FACTOR) { float volume = audioSystemMgr->GetLowPowerVolume(streamId); - cout << "Get low power volume is: " << volume << endl; - break; + cout << "Get discounted volume factor: " << volume << endl; + } else if (opt_flag == AudioPolicyTest::OPT_GET_SS_VOL) { + float volume = audioSystemMgr->GetSingleStreamVolume(streamId); + cout << "Get single stream volume: " << volume << endl; + } else { + cout << "invalid operation." << endl; } - default : - cout << "This operation is not supported" << endl; - break; } } @@ -422,7 +425,7 @@ int main(int argc, char* argv[]) } int streamType = static_cast(AudioVolumeType::STREAM_MUSIC); - while ((opt = getopt(argc, argv, ":V:U:S:D:M:R:C:X:Z:d:L:l:s:vmrucOoIiGg")) != -1) { + while ((opt = getopt(argc, argv, ":V:U:S:D:M:R:C:X:Z:d:s:vmrucOoIiGgNn")) != -1) { switch (opt) { case 'G': case 'g': @@ -468,7 +471,6 @@ int main(int argc, char* argv[]) case 'c': HandleAudioScene(opt); break; - case 'X': HandleUpdateStreamState(0, optarg); break; @@ -476,8 +478,8 @@ int main(int argc, char* argv[]) HandleUpdateStreamState(1, optarg); break; case 'N': - case 'P': - HandleLowPowerVolumeOption(opt); + case 'n': + HandleSingleStreamVolumeOption(argc, argv, opt); break; case ':': NoValueError(); diff --git a/test/unittest/manager_test/src/audio_manager_unit_test.cpp b/test/unittest/manager_test/src/audio_manager_unit_test.cpp index e972a160af098635a95fc3d0c276a2fd144a4e8d..c087c47da8a59523f3c8d6d217cb85968797b178 100644 --- a/test/unittest/manager_test/src/audio_manager_unit_test.cpp +++ b/test/unittest/manager_test/src/audio_manager_unit_test.cpp @@ -39,8 +39,8 @@ namespace { constexpr int32_t INV_CHANNEL = -1; constexpr int32_t CHANNEL_10 = 10; constexpr float DISCOUNT_VOLUME = 0.5; - constexpr float DISCOUNT_VOLUME_MIN = 0; - constexpr float DISCOUNT_VOLUME_MAX = 1.0; + constexpr float VOLUME_MIN = 0; + constexpr float VOLUME_MAX = 1.0; } void AudioManagerUnitTest::SetUpTestCase(void) {} @@ -814,7 +814,50 @@ HWTEST(AudioManagerUnitTest, GetLowPowerVolume_001, TestSize.Level1) ASSERT_NE(0, streamId); float vol = AudioSystemManager::GetInstance()->GetLowPowerVolume(streamId); - if (vol < DISCOUNT_VOLUME_MIN || vol > DISCOUNT_VOLUME_MAX) { + if (vol < VOLUME_MIN || vol > VOLUME_MAX) { + ret = ERROR; + } else { + ret = SUCCESS; + } + EXPECT_EQ(SUCCESS, ret); + audioRenderer->Release(); +} + +/** +* @tc.name : Test GetSingleStreamVolume API +* @tc.number: GetSingleStreamVolume_001 +* @tc.desc : Test get single stream volume. +*/ +HWTEST(AudioManagerUnitTest, GetSingleStreamVolume_001, TestSize.Level1) +{ + int32_t streamId = 0; + vector> audioRendererChangeInfos; + AudioRendererOptions rendererOptions = {}; + AppInfo appInfo = {}; + appInfo.appUid = static_cast(getuid()); + rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_44100; + rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM; + rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_S16LE; + rendererOptions.streamInfo.channels = AudioChannel::STEREO; + rendererOptions.rendererInfo.contentType = ContentType::CONTENT_TYPE_MUSIC; + rendererOptions.rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_MEDIA; + rendererOptions.rendererInfo.rendererFlags = 0; + + unique_ptr audioRenderer = AudioRenderer::Create(rendererOptions, appInfo); + ASSERT_NE(nullptr, audioRenderer); + int32_t ret = AudioStreamManager::GetInstance()->GetCurrentRendererChangeInfos(audioRendererChangeInfos); + EXPECT_EQ(SUCCESS, ret); + + for (auto it = audioRendererChangeInfos.begin(); it != audioRendererChangeInfos.end(); it++) { + AudioRendererChangeInfo audioRendererChangeInfos_ = **it; + if (audioRendererChangeInfos_.clientUID == appInfo.appUid) { + streamId = audioRendererChangeInfos_.sessionId; + } + } + ASSERT_NE(0, streamId); + + float vol = AudioSystemManager::GetInstance()->GetSingleStreamVolume(streamId); + if (vol < VOLUME_MIN || vol > VOLUME_MAX) { ret = ERROR; } else { ret = SUCCESS;