From 9a7bfe1571881ef0dfbabd9f1edfbb33e6deefd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B6=E6=98=A5=E9=BE=99?= Date: Sat, 6 Sep 2025 17:39:56 +0800 Subject: [PATCH 1/2] =?UTF-8?q?audio=20server=20=E5=A4=9A=E6=AC=A1crash=20?= =?UTF-8?q?=E6=81=A2=E5=A4=8D=E5=90=8Eposition=E4=B8=8D=E5=87=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陶春龙 --- .../client/src/renderer_in_client_public.cpp | 31 +++---------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/services/audio_service/client/src/renderer_in_client_public.cpp b/services/audio_service/client/src/renderer_in_client_public.cpp index ce4d0631f6..dd871490a8 100644 --- a/services/audio_service/client/src/renderer_in_client_public.cpp +++ b/services/audio_service/client/src/renderer_in_client_public.cpp @@ -359,36 +359,13 @@ void RendererInClientInner::SetSwitchInfoTimestamp( std::vector> lastFramePosAndTimePair, std::vector> lastFramePosAndTimePairWithSpeed) { - std::vector timestampCurrent = {0}; - ClockTime::GetAllTimeStamp(timestampCurrent); + AUDIO_INFO_LOG("RendererInClientInner::SetSwitchInfoTimestamp"); lastFramePosAndTimePair_ = lastFramePosAndTimePair; lastFramePosAndTimePairWithSpeed_ = lastFramePosAndTimePairWithSpeed; for (int32_t base = 0; base < Timestamp::Timestampbase::BASESIZE; base++) { - uint64_t timestampNS = timestampCurrent[base]; - - // Calculate the number of samples at the switching point based on the current time - // before scaling to one times speed, for RendererInClientInner::GetAudioPosition - uint64_t lastTimeNS = lastFramePosAndTimePair[base].second; - uint64_t durationNS = timestampNS > lastTimeNS && lastTimeNS > 0 ? timestampNS - lastTimeNS : 0; - uint64_t durationUS = durationNS / AUDIO_US_PER_MS; - uint64_t newPositionUS = - lastFramePosAndTimePair[base].first + durationUS * curStreamParams_.samplingRate / AUDIO_US_PER_S; - lastSwitchPosition_[base] = newPositionUS; - lastFramePosAndTimePair_[base].first = newPositionUS; - lastFramePosAndTimePair_[base].second = timestampNS; - - // after scaling to one times speed, for RendererInClientInner::GetAudioTimestampInfo - uint64_t lastTimeWithSpeedNS = lastFramePosAndTimePairWithSpeed[base].second; - uint64_t durationWithSpeedNS = - timestampNS > lastTimeWithSpeedNS && lastTimeWithSpeedNS > 0 ? timestampNS - lastTimeWithSpeedNS : 0; - uint64_t durationWithSpeedUS = durationWithSpeedNS / AUDIO_US_PER_MS; - float speed = GetSpeed(); - uint64_t newPositionWithSpeedUS = lastFramePosAndTimePairWithSpeed[base].first + - durationWithSpeedUS * curStreamParams_.samplingRate * speed / AUDIO_US_PER_S; - lastSwitchPositionWithSpeed_[base] = newPositionWithSpeedUS; - lastFramePosAndTimePairWithSpeed_[base].first = newPositionWithSpeedUS; - lastFramePosAndTimePairWithSpeed_[base].second = timestampNS; + lastSwitchPosition_[base] = lastFramePosAndTimePair[base].first; + lastSwitchPositionWithSpeed_[base] = lastFramePosAndTimePairWithSpeed[base].first; } } @@ -1522,7 +1499,7 @@ void RendererInClientInner::GetStreamSwitchInfo(IAudioStream::SwitchInfo& info) info.renderPeriodPositionCb = rendererPeriodPositionCallback_; info.rendererWriteCallback = writeCb_; - info.unprocessSamples = unprocessedFramesBytes_.load(); + info.unprocessSamples = unprocessedFramesBytes_.load() + lastSwitchPosition_[Timestampbase::MONOTONIC]; } IAudioStream::StreamClass RendererInClientInner::GetStreamClass() -- Gitee From 28cf52b165f188ff6f061cd0d9045761915cc2be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B6=E6=98=A5=E9=BE=99?= Date: Sat, 6 Sep 2025 18:35:04 +0800 Subject: [PATCH 2/2] fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陶春龙 --- services/audio_service/client/src/renderer_in_client_public.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/audio_service/client/src/renderer_in_client_public.cpp b/services/audio_service/client/src/renderer_in_client_public.cpp index dd871490a8..a25ba3773f 100644 --- a/services/audio_service/client/src/renderer_in_client_public.cpp +++ b/services/audio_service/client/src/renderer_in_client_public.cpp @@ -1499,7 +1499,7 @@ void RendererInClientInner::GetStreamSwitchInfo(IAudioStream::SwitchInfo& info) info.renderPeriodPositionCb = rendererPeriodPositionCallback_; info.rendererWriteCallback = writeCb_; - info.unprocessSamples = unprocessedFramesBytes_.load() + lastSwitchPosition_[Timestampbase::MONOTONIC]; + info.unprocessSamples = unprocessedFramesBytes_.load() + lastSwitchPosition_[Timestamp::Timestampbase::MONOTONIC]; } IAudioStream::StreamClass RendererInClientInner::GetStreamClass() -- Gitee