diff --git a/services/audio_policy/server/include/audio_stream_collector.h b/services/audio_policy/server/include/audio_stream_collector.h index 98a1a99fbb032402abc9683eb0a3da0a6db12f17..e08279943c3376b59d8a943a78ab228cd3806fec 100644 --- a/services/audio_policy/server/include/audio_stream_collector.h +++ b/services/audio_policy/server/include/audio_stream_collector.h @@ -71,6 +71,8 @@ public: int32_t SetAudioConcurrencyCallback(const uint32_t sessionID, const sptr &object); int32_t UnsetAudioConcurrencyCallback(const uint32_t sessionID); int32_t ActivateAudioConcurrency(const AudioPipeType &pipeType); + void ResetRendererStreamDeviceInfo(const AudioDeviceDescriptor& updatedDesc); + void ResetCapturerStreamDeviceInfo(const AudioDeviceDescriptor& updatedDesc); private: std::mutex streamsInfoMutex_; std::map, int32_t> rendererStatequeue_; diff --git a/services/audio_policy/server/src/audio_stream_collector.cpp b/services/audio_policy/server/src/audio_stream_collector.cpp index 8c65b75ebb1fa8352f68476130e88450a5fa59cc..15adf2743af1c0173b97913937a1ccaeca397de5 100644 --- a/services/audio_policy/server/src/audio_stream_collector.cpp +++ b/services/audio_policy/server/src/audio_stream_collector.cpp @@ -277,6 +277,34 @@ void AudioStreamCollector::SetCapturerStreamParam(AudioStreamChangeInfo &streamC capturerChangeInfo->inputDeviceInfo = streamChangeInfo.audioCapturerChangeInfo.inputDeviceInfo; } +void AudioStreamCollector::ResetRendererStreamDeviceInfo(const AudioDeviceDescriptor& updatedDesc) +{ + AUDIO_INFO_LOG("ResetRendererStreamDeviceInfo, deviceType:[%{public}d]", updatedDesc.deviceType_); + for (auto it = audioRendererChangeInfos_.begin(); it != audioRendererChangeInfos_.end(); it++) { + if ((*it)->outputDeviceInfo.deviceType == updatedDesc.deviceType_ && + (*it)->outputDeviceInfo.macAddress == updatedDesc.macAddress_ && + (*it)->outputDeviceInfo.networkId == updatedDesc.networkId_) { + (*it)->outputDeviceInfo.deviceType = DEVICE_TYPE_NONE; + (*it)->outputDeviceInfo.macAddress = ""; + (*it)->outputDeviceInfo.networkId = LOCAL_NETWORK_ID; + } + } +} + +void AudioStreamCollector::ResetCapturerStreamDeviceInfo(const AudioDeviceDescriptor& updatedDesc) +{ + AUDIO_INFO_LOG("ResetCapturerStreamDeviceInfo, deviceType:[%{public}d]", updatedDesc.deviceType_); + for (auto it = audioCapturerChangeInfos_.begin(); it != audioCapturerChangeInfos_.end(); it++) { + if ((*it)->inputDeviceInfo.deviceType == updatedDesc.deviceType_ && + (*it)->inputDeviceInfo.macAddress == updatedDesc.macAddress_ && + (*it)->inputDeviceInfo.networkId == updatedDesc.networkId_) { + (*it)->inputDeviceInfo.deviceType = DEVICE_TYPE_NONE; + (*it)->inputDeviceInfo.macAddress = ""; + (*it)->inputDeviceInfo.networkId = LOCAL_NETWORK_ID; + } + } +} + bool AudioStreamCollector::CheckRendererStateInfoChanged(AudioStreamChangeInfo &streamChangeInfo) { if (rendererStatequeue_.find(make_pair(streamChangeInfo.audioRendererChangeInfo.clientUID, diff --git a/services/audio_policy/server/src/service/audio_policy_service.cpp b/services/audio_policy/server/src/service/audio_policy_service.cpp index 50f08c5b9456593cb00569d17d4340938ba857d5..01c5796fcfd1476a5c567639c648ee6df6af1bad 100644 --- a/services/audio_policy/server/src/service/audio_policy_service.cpp +++ b/services/audio_policy/server/src/service/audio_policy_service.cpp @@ -3401,6 +3401,14 @@ void AudioPolicyService::UpdateConnectedDevicesWhenDisconnecting(const AudioDevi } } + // reset disconnected device info in stream + if (IsOutputDevice(updatedDesc.deviceType_)) { + streamCollector_.ResetRendererStreamDeviceInfo(updatedDesc); + } + if (IsInputDevice(updatedDesc.deviceType_)) { + streamCollector_.ResetCapturerStreamDeviceInfo(updatedDesc); + } + sptr devDesc = new (std::nothrow) AudioDeviceDescriptor(updatedDesc); CHECK_AND_RETURN_LOG(devDesc != nullptr, "Create device descriptor failed"); audioDeviceManager_.RemoveNewDevice(devDesc);