diff --git a/frameworks/native/hdiadapter_new/include/sink/i_audio_render_sink.h b/frameworks/native/hdiadapter_new/include/sink/i_audio_render_sink.h index 2cebc0396d3c5eae2131e28f4a6f6208c6ac5c94..1f4e31a40542cb21243bf813b8ddab22c0c03c2d 100644 --- a/frameworks/native/hdiadapter_new/include/sink/i_audio_render_sink.h +++ b/frameworks/native/hdiadapter_new/include/sink/i_audio_render_sink.h @@ -112,8 +112,8 @@ public: virtual int32_t UnLockOffloadRunningLock(void) NOT_SUPPORT_RET // remote extend function - virtual int32_t SplitRenderFrame(char &data, uint64_t len, uint64_t &writeLen, const char *streamType, - const char *audioStreamType = nullptr) NOT_SUPPORT_RET + virtual int32_t SplitRenderFrame(char &data, uint64_t len, uint64_t &writeLen, + const char *splitStreamType) NOT_SUPPORT_RET // primary extend function virtual int32_t SetDeviceConnectedFlag(bool flag) NOT_SUPPORT_RET diff --git a/frameworks/native/hdiadapter_new/include/sink/remote_audio_render_sink.h b/frameworks/native/hdiadapter_new/include/sink/remote_audio_render_sink.h index a157497beb37fe857c0ccdfcd959a333571fb530..b7a0a2d777c4fb6a970a27d58f2a966f6df4642b 100644 --- a/frameworks/native/hdiadapter_new/include/sink/remote_audio_render_sink.h +++ b/frameworks/native/hdiadapter_new/include/sink/remote_audio_render_sink.h @@ -89,8 +89,7 @@ public: int32_t UpdateAppsUid(const int32_t appsUid[MAX_MIX_CHANNELS], const size_t size) final; int32_t UpdateAppsUid(const std::vector &appsUid) final; - int32_t SplitRenderFrame(char &data, uint64_t len, uint64_t &writeLen, const char *streamType, - const char *audioStreamType) override; + int32_t SplitRenderFrame(char &data, uint64_t len, uint64_t &writeLen, const char *splitStreamType) override; void DumpInfo(std::string &dumpString) override; @@ -100,7 +99,6 @@ public: void SetDmDeviceType(uint16_t dmDeviceType, DeviceType deviceType) override; private: - int8_t ConvertStr2Int(const char *str); static RemoteAudioFormat ConvertToHdiFormat(AudioSampleFormat format); static RemoteAudioCategory GetAudioCategory(AudioScene audioScene); void InitSplitStream(const char *splitStreamStr, std::vector &splitStreamVector); @@ -109,8 +107,7 @@ private: int32_t CreateRender(RemoteAudioCategory type); int32_t DoSetOutputRoute(void); void CheckUpdateState(char *data, uint64_t len); - int32_t RenderFrame(char &data, uint64_t len, uint64_t &writeLen, RemoteAudioCategory type, - bool isSplitFrame = false, const char *audioStreamType = nullptr); + int32_t RenderFrame(char &data, uint64_t len, uint64_t &writeLen, RemoteAudioCategory type); void JoinStartThread(); diff --git a/frameworks/native/hdiadapter_new/sink/remote_audio_render_sink.cpp b/frameworks/native/hdiadapter_new/sink/remote_audio_render_sink.cpp index 821f93472a1eb6776fa106d289c3eb20db174bf6..b2f40f5362c73ffad115bb49e6e9d8d920167d4a 100644 --- a/frameworks/native/hdiadapter_new/sink/remote_audio_render_sink.cpp +++ b/frameworks/native/hdiadapter_new/sink/remote_audio_render_sink.cpp @@ -458,14 +458,14 @@ int32_t RemoteAudioRenderSink::UpdateAppsUid(const std::vector &appsUid return ERR_NOT_SUPPORTED; } -int32_t RemoteAudioRenderSink::SplitRenderFrame(char &data, uint64_t len, uint64_t &writeLen, const char *streamType, - const char *audioStreamType) +int32_t RemoteAudioRenderSink::SplitRenderFrame(char &data, uint64_t len, uint64_t &writeLen, + const char *splitStreamType) { Trace trace("RemoteAudioRenderSink::SplitRenderFrame"); - AUDIO_DEBUG_LOG("in, type: %{public}s", streamType); - auto it = SPLIT_STREAM_MAP.find(streamType); + AUDIO_DEBUG_LOG("in, type: %{public}s", splitStreamType); + auto it = SPLIT_STREAM_MAP.find(splitStreamType); CHECK_AND_RETURN_RET_LOG(it != SPLIT_STREAM_MAP.end(), ERR_INVALID_PARAM, "invalid stream type"); - return RenderFrame(data, len, writeLen, it->second, true, audioStreamType); + return RenderFrame(data, len, writeLen, it->second); } void RemoteAudioRenderSink::DumpInfo(std::string &dumpString) @@ -654,22 +654,7 @@ void RemoteAudioRenderSink::CheckUpdateState(char *data, uint64_t len) } } -int8_t RemoteAudioRenderSink::ConvertStr2Int(const char *str) -{ - if (str == nullptr) { - AUDIO_ERR_LOG("str is null"); - return 0; - } - int8_t streamType = std::stoi(str); - if (streamType < INT8_MIN || streamType > INT8_MAX) { - AUDIO_ERR_LOG("Invalid str: %{public}s", str); - return 0; - } - return streamType; -} - -int32_t RemoteAudioRenderSink::RenderFrame(char &data, uint64_t len, uint64_t &writeLen, AudioCategory type, - bool isSplitFrame, const char *audioStreamType) +int32_t RemoteAudioRenderSink::RenderFrame(char &data, uint64_t len, uint64_t &writeLen, AudioCategory type) { CHECK_AND_RETURN_RET_LOG(renderInited_.load(), ERR_ILLEGAL_STATE, "not create, invalid state"); AUDIO_DEBUG_LOG("type: %{public}d", type); @@ -682,15 +667,7 @@ int32_t RemoteAudioRenderSink::RenderFrame(char &data, uint64_t len, uint64_t &w } std::vector bufferVec(len); - int32_t ret = ERROR; - if (isSplitFrame) { - CHECK_AND_RETURN_RET_LOG(audioStreamType != nullptr, ERR_INVALID_HANDLE, "audioStreamType is nullptr"); - int8_t streamType = ConvertStr2Int(audioStreamType); - ret = memcpy_s(bufferVec.data(), len, &data, len); - bufferVec.push_back(streamType); - } else { - ret = memcpy_s(bufferVec.data(), len, &data, len); - } + int32_t ret = memcpy_s(bufferVec.data(), len, &data, len); CHECK_AND_RETURN_RET_LOG(ret == EOK, ERR_OPERATION_FAILED, "copy fail, error code: %{public}d", ret); BufferDesc buffer = { reinterpret_cast(&data), len, len }; diff --git a/services/audio_engine/manager/include/hpae_msg_channel.h b/services/audio_engine/manager/include/hpae_msg_channel.h index 7fa44d36d27cf39d3be3348f6c3d3b37349e2a78..c442863c50d5ad4a7609e4145e1891d0223310cb 100644 --- a/services/audio_engine/manager/include/hpae_msg_channel.h +++ b/services/audio_engine/manager/include/hpae_msg_channel.h @@ -128,7 +128,7 @@ struct HpaeDfxNodeInfo { AudioChannel channels; AudioChannelLayout channelLayout = AudioChannelLayout::CH_LAYOUT_UNKNOWN; FadeType fadeType = NONE_FADE; - AudioStreamType streamType; + AudioStreamType streamType = STREAM_DEFAULT; HpaeProcessorType sceneType; std::string deviceClass; std::string deviceNetId; diff --git a/services/audio_engine/node/include/hpae_remote_sink_output_node.h b/services/audio_engine/node/include/hpae_remote_sink_output_node.h index 62b3b72d15f357452099b1b0aacfc1ca6f208c94..9c299844f3f07594cc015df818ef14a62274c511 100644 --- a/services/audio_engine/node/include/hpae_remote_sink_output_node.h +++ b/services/audio_engine/node/include/hpae_remote_sink_output_node.h @@ -57,6 +57,7 @@ public: int32_t UpdateAppsUid(const std::vector &appsUid); private: + void NotifyStreamTypeChange(AudioStreamType type, HpaeSplitStreamType splitStreamType); void HandleRemoteTiming(); void HandlePcmDumping(HpaeSplitStreamType streamType, char* data, size_t size); InputPort inputStream_; diff --git a/services/audio_engine/node/src/hpae_remote_sink_output_node.cpp b/services/audio_engine/node/src/hpae_remote_sink_output_node.cpp index 50a4f00c39d25b0b5d417798df7ab5cde0a8d1ce..8c6f8be7cd199b7f2a749bae8d78156cbc6fc4c2 100644 --- a/services/audio_engine/node/src/hpae_remote_sink_output_node.cpp +++ b/services/audio_engine/node/src/hpae_remote_sink_output_node.cpp @@ -28,7 +28,7 @@ namespace OHOS { namespace AudioStandard { namespace HPAE { - +const std::string STREAM_TYPE_CHANGE = "stream_type_change"; HpaeRemoteSinkOutputNode::HpaeRemoteSinkOutputNode(HpaeNodeInfo &nodeInfo, HpaeSinkInfo &sinkInfo) : HpaeNode(nodeInfo), renderFrameData_(nodeInfo.frameLen * nodeInfo.channels * GetSizeFromFormat(nodeInfo.format)), @@ -98,6 +98,26 @@ void HpaeRemoteSinkOutputNode::HandlePcmDumping(HpaeSplitStreamType streamType, } } +void HpaeRemoteSinkOutputNode::NotifyStreamTypeChange(AudioStreamType type, HpaeSplitStreamType splitStreamType) +{ + if (splitStreamType != STREAM_TYPE_MEDIA) { + return; + } + HpaeNodeInfo nodeInfo = GetNodeInfo(); + if (type == nodeInfo.streamType) { + return; + } + HdiAdapterManager &manager = HdiAdapterManager::GetInstance(); + std::shared_ptr deviceManager = manager.GetDeviceManager(HDI_DEVICE_MANAGER_TYPE_REMOTE); + if (deviceManager == nullptr) { + return; + } + AudioParamKey key = AudioParamKey::PARAM_KEY_STATE; + deviceManager->SetAudioParameter(nodeInfo.deviceNetId, key, STREAM_TYPE_CHANGE, std::to_string(type)); + nodeInfo.streamType = type; + SetNodeInfo(nodeInfo); +} + void HpaeRemoteSinkOutputNode::DoProcess() { auto rate = "rate[" + std::to_string(GetSampleRate()) + "]_"; @@ -114,20 +134,20 @@ void HpaeRemoteSinkOutputNode::DoProcess() if (outputData == nullptr || (!outputData->IsValid() && !needEmptyChunk_)) { continue; } - HpaeSplitStreamType streamType = outputData->GetSplitStreamType(); + HpaeSplitStreamType splitStreamType = outputData->GetSplitStreamType(); AudioStreamType type = outputData->GetAudioStreamType(); + NotifyStreamTypeChange(type, splitStreamType); ConvertFromFloat( GetBitWidth(), GetChannelCount() * GetFrameLen(), outputData->GetPcmDataBuffer(), renderFrameData_.data()); uint64_t writeLen = 0; char *renderFrameData = (char *)renderFrameData_.data(); #ifdef ENABLE_HOOK_PCM - HandlePcmDumping(streamType, renderFrameData, renderFrameData_.size()); + HandlePcmDumping(splitStreamType, renderFrameData, renderFrameData_.size()); #endif auto ret = audioRendererSink_->SplitRenderFrame(*renderFrameData, renderFrameData_.size(), - writeLen, std::to_string(static_cast(streamType)).c_str(), - std::to_string(static_cast(type)).c_str()); + writeLen, std::to_string(static_cast(splitStreamType)).c_str()); if (ret != SUCCESS || writeLen != renderFrameData_.size()) { - AUDIO_ERR_LOG("HpaeRemoteSinkOutputNode: RenderFrame failed, SplitStreamType %{public}d", streamType); + AUDIO_ERR_LOG("HpaeRemoteSinkOutputNode: RenderFrame failed, SplitStreamType %{public}d", splitStreamType); } } HandleRemoteTiming(); // used to control remote RenderFrame tempo. diff --git a/services/audio_engine/test/unittest/common/hpae_mocks.h b/services/audio_engine/test/unittest/common/hpae_mocks.h index 63771b5c6d2675e1e92f16c3316db3cea5314d24..418f35ec429cf8df375eab2e84d3c8dd58bd331c 100644 --- a/services/audio_engine/test/unittest/common/hpae_mocks.h +++ b/services/audio_engine/test/unittest/common/hpae_mocks.h @@ -109,7 +109,7 @@ public: MOCK_METHOD(int32_t, UnLockOffloadRunningLock, (), (override)); MOCK_METHOD(int32_t, SplitRenderFrame, - (char &data, uint64_t len, uint64_t &writeLen, const char *streamType, const char *audioType), (override)); + (char &data, uint64_t len, uint64_t &writeLen, const char *splitStreamType), (override)); MOCK_METHOD(int32_t, UpdatePrimaryConnectionState, (uint32_t operation), (override)); MOCK_METHOD(void, SetDmDeviceType, (uint16_t dmDeviceType, DeviceType deviceType), (override));