M module-audio/Audio/Operation/PlaybackOperation.cpp => module-audio/Audio/Operation/PlaybackOperation.cpp +9 -3
@@ 57,7 57,7 @@ namespace audio
}
operationToken = token;
- assert(dataStreamOut);
+ assert(dataStreamOut != nullptr);
dec->startDecodingWorker(*dataStreamOut, endOfFileCallback);
@@ 89,17 89,19 @@ namespace audio
if (!audioDevice) {
return audio::RetCode::DeviceFailure;
}
+
+ dec->stopDecodingWorker();
return GetDeviceError(audioDevice->Stop());
}
audio::RetCode PlaybackOperation::Pause()
{
-
if (state == State::Paused || state == State::Idle) {
return RetCode::InvokedInIncorrectState;
}
-
state = State::Paused;
+
+ dec->stopDecodingWorker();
return GetDeviceError(audioDevice->Stop());
}
@@ 110,6 112,9 @@ namespace audio
return RetCode::InvokedInIncorrectState;
}
state = State::Active;
+
+ assert(dataStreamOut != nullptr);
+ dec->startDecodingWorker(*dataStreamOut, endOfFileCallback);
auto ret = audioDevice->Start(currentProfile->GetAudioFormat());
return GetDeviceError(ret);
}
@@ 196,6 201,7 @@ namespace audio
PlaybackOperation::~PlaybackOperation()
{
+ dec->stopDecodingWorker();
Stop();
dataStreamOut->reset();
dataStreamIn->reset();
M module-audio/Audio/Operation/RouterOperation.cpp => module-audio/Audio/Operation/RouterOperation.cpp +4 -11
@@ 25,17 25,6 @@ namespace audio
AddProfile(Profile::Type::RoutingHeadphones, PlaybackType::None, false);
AddProfile(Profile::Type::RoutingEarspeaker, PlaybackType::None, true);
AddProfile(Profile::Type::RoutingLoudspeaker, PlaybackType::None, true);
-
- auto defaultProfile = GetProfile(Profile::Type::RoutingEarspeaker);
- if (!defaultProfile) {
- throw AudioInitException("Error during initializing profile", RetCode::ProfileNotSet);
- }
- currentProfile = defaultProfile;
-
- auto retCode = SwitchToPriorityProfile();
- if (retCode != RetCode::Success) {
- throw AudioInitException("Failed to switch audio profile", retCode);
- }
}
audio::RetCode RouterOperation::SetOutputVolume(float vol)
@@ 153,7 142,11 @@ namespace audio
audio::RetCode RouterOperation::SwitchProfile(const audio::Profile::Type type)
{
auto ret = GetProfile(type);
+
if (ret) {
+ if (currentProfile && currentProfile->GetType() == ret->GetType()) {
+ return RetCode::Success;
+ }
currentProfile = ret;
}
else {
M module-audio/Audio/decoder/Decoder.cpp => module-audio/Audio/decoder/Decoder.cpp +8 -0
@@ 133,4 133,12 @@ namespace audio
}
}
+ void Decoder::stopDecodingWorker()
+ {
+ if (audioWorker) {
+ audioWorker->close();
+ }
+ audioWorker = nullptr;
+ }
+
} // namespace audio
M module-audio/Audio/decoder/Decoder.hpp => module-audio/Audio/decoder/Decoder.hpp +1 -0
@@ 81,6 81,7 @@ namespace audio
virtual uint32_t decode(uint32_t samplesToRead, int16_t *pcmData) = 0;
void startDecodingWorker(Stream &audioStream, DecoderWorker::EndOfFileCallback endOfFileCallback);
+ void stopDecodingWorker();
std::unique_ptr<Tags> fetchTags();
M module-bsp/board/rt1051/bsp/audio/RT1051Audiocodec.cpp => module-bsp/board/rt1051/bsp/audio/RT1051Audiocodec.cpp +2 -2
@@ 99,11 99,11 @@ namespace bsp
return AudioDevice::RetCode::Failure;
}
- codec.Stop();
-
InStop();
OutStop();
+ codec.Stop();
+
state = State::Stopped;
vTaskDelay(codecSettleTime);