From d28fdb6594f1de047e94990f7c552d1bb55eb336 Mon Sep 17 00:00:00 2001 From: Lefucjusz Date: Thu, 19 Jan 2023 18:52:27 +0100 Subject: [PATCH] [MOS-882] Fix FLAC file playback with USB cable connected Fix of the issue that caused system crash when trying to play 96kHz FLAC file with USB cable connected. The reason of the issue was the lack of FreeRTOS heap space left, what caused pvPortMalloc() to fail when allocating memory for stream buffer. Additionally minor code cleanup. --- module-audio/Audio/StreamFactory.cpp | 5 +---- module-audio/Audio/decoder/Decoder.cpp | 19 ++----------------- module-audio/Audio/decoder/Decoder.hpp | 7 +------ module-audio/Audio/decoder/DecoderWorker.cpp | 6 +++--- .../board/rt1051/puretx/PureTxAudioCodec.cpp | 4 +--- .../board/rt1051/os/include/FreeRTOSConfig.h | 4 ++-- .../service-audio/ServiceAudio.cpp | 4 ++-- module-sys/Service/Worker.cpp | 6 +++--- pure_changelog.md | 1 + 9 files changed, 16 insertions(+), 40 deletions(-) diff --git a/module-audio/Audio/StreamFactory.cpp b/module-audio/Audio/StreamFactory.cpp index 55d8f93a21a172f305547d123e7d4d5aa6ef74fd..9c1862d40bd62dec68d65bcd63d6ba2f23ee0cf1 100644 --- a/module-audio/Audio/StreamFactory.cpp +++ b/module-audio/Audio/StreamFactory.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "StreamFactory.hpp" @@ -18,9 +18,6 @@ #include #include -using audio::AudioFormat; -using audio::Sink; -using audio::Source; using audio::Stream; using audio::StreamFactory; using audio::transcode::InputTranscodeProxy; diff --git a/module-audio/Audio/decoder/Decoder.cpp b/module-audio/Audio/decoder/Decoder.cpp index 3d9388c8dcedd834501dbde47a92ac59d8c54da4..4f9af1d6f574ba2754fe38938834c668c3fbac39 100644 --- a/module-audio/Audio/decoder/Decoder.cpp +++ b/module-audio/Audio/decoder/Decoder.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include @@ -13,8 +13,7 @@ namespace audio { - Decoder::Decoder(const std::string &path) - : filePath(path), workerBuffer(std::make_unique(workerBufferSize)) + Decoder::Decoder(const std::string &path) : filePath(path) { fd = std::fopen(path.c_str(), "r"); if (fd == nullptr) { @@ -75,20 +74,6 @@ namespace audio return dec; } - void Decoder::convertmono2stereo(int16_t *pcm, uint32_t samplecount) - { - uint32_t i = 0, j = 0; - - memset(workerBuffer.get(), 0, workerBufferSize * sizeof(int16_t)); - - for (; j < samplecount; j++) { - workerBuffer[i++] = pcm[j]; - workerBuffer[i++] = pcm[j]; - } - - memcpy(pcm, &workerBuffer[0], samplecount * 2 * sizeof(int16_t)); - } - void Decoder::startDecodingWorker(const DecoderWorker::EndOfFileCallback &endOfFileCallback) { assert(_stream != nullptr); diff --git a/module-audio/Audio/decoder/Decoder.hpp b/module-audio/Audio/decoder/Decoder.hpp index e2f90e47838c53f1456e262a02e2f408f4352911..bf1d4b22c606639d0e71d5d491bc55f8d9184f34 100644 --- a/module-audio/Audio/decoder/Decoder.hpp +++ b/module-audio/Audio/decoder/Decoder.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -70,9 +70,6 @@ namespace audio } virtual std::unique_ptr fetchTags(); - void convertmono2stereo(std::int16_t *pcm, std::uint32_t samplecount); - - static constexpr auto workerBufferSize = 1024 * 8; static constexpr Endpoint::Traits decoderCaps = {.usesDMA = false}; std::uint32_t sampleRate = 0; @@ -84,8 +81,6 @@ namespace audio std::uint32_t fileSize = 0; std::string filePath; - // Worker buffer used for converting mono stream to stereo - std::unique_ptr workerBuffer; std::unique_ptr tags; bool isInitialized = false; diff --git a/module-audio/Audio/decoder/DecoderWorker.cpp b/module-audio/Audio/decoder/DecoderWorker.cpp index bf8bd8b943b318e6f5c1c908c897b2b0b52fd191..0325e9872e7fad371037ecfc9fce0222dcf2590e 100644 --- a/module-audio/Audio/decoder/DecoderWorker.cpp +++ b/module-audio/Audio/decoder/DecoderWorker.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "DecoderWorker.hpp" @@ -21,10 +21,10 @@ audio::DecoderWorker::~DecoderWorker() auto audio::DecoderWorker::init(std::list queues) -> bool { - std::list list{ + const std::list list{ {listenerQueueName, StreamQueuedEventsListener::listenerElementSize, listenerQueueCapacity}}; - auto isSuccessful = Worker::init(list); + const auto isSuccessful = Worker::init(list); queueListener = std::make_unique(getQueueByName(listenerQueueName)); if (!queueListener) { diff --git a/module-audio/board/rt1051/puretx/PureTxAudioCodec.cpp b/module-audio/board/rt1051/puretx/PureTxAudioCodec.cpp index 214c320ddfc31efe24e446acbd88ad60896425e6..a0ce6d14658fc173cf81f322b89520fa2a817c87 100644 --- a/module-audio/board/rt1051/puretx/PureTxAudioCodec.cpp +++ b/module-audio/board/rt1051/puretx/PureTxAudioCodec.cpp @@ -1,12 +1,10 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "PureTxAudioCodec.hpp" #include "board.h" -#include "dma_config.h" #include -#include "board/BoardDefinitions.hpp" #include "board/rt1051/common/audio.hpp" using audio::codec::Configuration; diff --git a/module-bsp/board/rt1051/os/include/FreeRTOSConfig.h b/module-bsp/board/rt1051/os/include/FreeRTOSConfig.h index a27a2fdaf58581c5a5cd909922a5b445648547aa..a32b3f7e0fb1fccc5a3e8d9723a857af83810174 100644 --- a/module-bsp/board/rt1051/os/include/FreeRTOSConfig.h +++ b/module-bsp/board/rt1051/os/include/FreeRTOSConfig.h @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md /* @@ -78,7 +78,7 @@ extern "C" /* Memory allocation related definitions. */ #define configSUPPORT_STATIC_ALLOCATION 1 #define configSUPPORT_DYNAMIC_ALLOCATION 1 -#define configTOTAL_HEAP_SIZE ((size_t)(1024 * 386)) +#define configTOTAL_HEAP_SIZE ((size_t)(1024 * 424)) #define configAPPLICATION_ALLOCATED_HEAP 0 diff --git a/module-services/service-audio/ServiceAudio.cpp b/module-services/service-audio/ServiceAudio.cpp index 8e87f5bb5958dd4d27ff157d372dfef7cb5f072b..a7e7548be104a0fdb5acf4cab2c8e1327b8b0ffd 100644 --- a/module-services/service-audio/ServiceAudio.cpp +++ b/module-services/service-audio/ServiceAudio.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include @@ -22,7 +22,7 @@ using namespace audio; -inline constexpr auto audioServiceStackSize = 1024 * 8; +static constexpr auto audioServiceStackSize = 1024 * 8; static constexpr auto defaultVolumeHigh = "10"; static constexpr auto defaultVolumeMid = "7"; diff --git a/module-sys/Service/Worker.cpp b/module-sys/Service/Worker.cpp index cf7e8fe3353b1db6bb0b25d8c1c2296a5fec1109..482c57b8b44d4ceb037e09b7aee7641bf0f2d6fd 100644 --- a/module-sys/Service/Worker.cpp +++ b/module-sys/Service/Worker.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include @@ -136,7 +136,7 @@ namespace sys auto setSize = SERVICE_QUEUE_LENGTH + CONTROL_QUEUE_LENGTH; // iterate over all entries in the list of queues and summarize queue sizes - for (auto wqi : queuesList) { + for (const auto &wqi : queuesList) { setSize += wqi.length; } @@ -154,7 +154,7 @@ namespace sys controlQueueIndex = addQueue(getControlQueueName(), CONTROL_QUEUE_LENGTH, sizeof(std::uint8_t)); // create and add all queues provided from service - for (auto wqi : queuesList) { + for (const auto &wqi : queuesList) { addQueue(wqi.name, wqi.length, wqi.elementSize); }; diff --git a/pure_changelog.md b/pure_changelog.md index 462894bfe0ebacc90c4ed54d695560e85c33f7ab..68cbf2708a4bf7647861fe762be991a87c381e23 100644 --- a/pure_changelog.md +++ b/pure_changelog.md @@ -33,6 +33,7 @@ * Fixed full filesystem path displayed in music player for invalid files instead of just filename * Fixed problem with track info not being displayed correctly * Fixed alarm rings on the low battery screen +* Fixed crash when trying to play 96kHz FLAC with USB cable connected ### Added