From bda18b5b5430523a879df2bb243c9d6dbc9dc34b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Smoczy=C5=84ski?= Date: Tue, 9 Feb 2021 23:12:49 +0100 Subject: [PATCH] [EGD-5706] Refactor creating audio device MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Audio devices are created in the audio subsystem and it is not possible to send a device to bt service upon creation. Introduce hookable audio device factory to allow sharing bluetooth audio device. Move audio devices from bsp to audio allowing removal of unwanted bsp -> audio dependency. Remove Bluetooth proxy device which turned out to be a dead end. Signed-off-by: Marcin Smoczyński --- CMakeLists.txt | 4 + module-apps/CMakeLists.txt | 6 +- module-audio/Audio/AudioCommon.cpp | 6 +- module-audio/Audio/AudioCommon.hpp | 15 +- .../Audio/AudioDevice.hpp | 32 ++-- module-audio/Audio/AudioDeviceFactory.cpp | 25 +++ module-audio/Audio/AudioDeviceFactory.hpp | 34 ++++ module-audio/Audio/AudioPlatform.hpp | 18 ++ module-audio/Audio/BluetoothProxyAudio.cpp | 93 ---------- module-audio/Audio/BluetoothProxyAudio.hpp | 45 ----- module-audio/Audio/Operation/Operation.cpp | 14 +- module-audio/Audio/Operation/Operation.hpp | 5 +- .../Audio/Operation/PlaybackOperation.cpp | 9 +- .../Audio/Operation/RecorderOperation.cpp | 5 +- .../Audio/Operation/RecorderOperation.hpp | 4 +- .../Audio/Operation/RouterOperation.cpp | 11 +- .../Audio/Operation/RouterOperation.hpp | 5 +- module-audio/Audio/Profiles/Profile.cpp | 14 +- module-audio/Audio/Profiles/Profile.hpp | 31 ++-- module-audio/Audio/Profiles/ProfileIdle.hpp | 4 +- .../Profiles/ProfilePlaybackBluetoothA2DP.hpp | 18 +- .../Profiles/ProfilePlaybackHeadphones.hpp | 19 +- .../Profiles/ProfilePlaybackLoudspeaker.hpp | 18 +- .../Profiles/ProfileRecordingBluetoothHSP.hpp | 25 ++- .../Profiles/ProfileRecordingHeadphones.hpp | 25 ++- .../Profiles/ProfileRecordingOnBoardMic.hpp | 25 ++- .../Profiles/ProfileRoutingBluetoothHSP.hpp | 28 +-- .../Profiles/ProfileRoutingEarspeaker.hpp | 29 ++- .../Profiles/ProfileRoutingHeadphones.hpp | 28 +-- .../Profiles/ProfileRoutingLoudspeaker.hpp | 28 +-- module-audio/CMakeLists.txt | 48 ++--- module-audio/board/linux/CMakeLists.txt | 12 ++ .../board/linux/LinuxAudioPlatform.cpp | 25 +++ module-audio/board/rt1051/CMakeLists.txt | 17 ++ .../board/rt1051/RT1051AudioCodec.cpp | 165 ++++++++---------- .../board/rt1051/RT1051AudioCodec.hpp | 28 +-- .../board/rt1051}/RT1051CellularAudio.cpp | 12 +- .../board/rt1051}/RT1051CellularAudio.hpp | 4 +- .../board/rt1051/RT1051DeviceFactory.cpp | 35 ++++ .../board/rt1051/RT1051DeviceFactory.hpp | 17 ++ module-audio/board/rt1051/RT1051Platform.cpp | 16 ++ .../board/rt1051}/SAIAudioDevice.cpp | 2 +- .../board/rt1051}/SAIAudioDevice.hpp | 8 +- module-audio/targets/Target_Cross.cmake | 9 - module-audio/targets/Target_Linux.cmake | 3 - .../Bluetooth/interface/profiles/Profile.hpp | 8 +- module-bsp/CMakeLists.txt | 6 +- .../board/rt1051/bsp/audio/CodecMAX98090.cpp | 60 +++---- .../board/rt1051/bsp/audio/CodecMAX98090.hpp | 26 ++- module-bsp/board/rt1051/common/audio.cpp | 74 ++++++++ module-bsp/board/rt1051/common/audio.hpp | 32 ++++ module-bsp/board/rt1051/common/board.cpp | 4 +- module-bsp/bsp/audio/bsp_audio.cpp | 52 ------ module-bsp/targets/Target_RT1051.cmake | 7 +- .../service-audio/ServiceAudio.cpp | 25 +-- .../service-bluetooth/BluetoothMessage.hpp | 69 -------- 56 files changed, 679 insertions(+), 708 deletions(-) rename module-bsp/bsp/audio/bsp_audio.hpp => module-audio/Audio/AudioDevice.hpp (91%) mode change 100755 => 100644 create mode 100644 module-audio/Audio/AudioDeviceFactory.cpp create mode 100644 module-audio/Audio/AudioDeviceFactory.hpp create mode 100644 module-audio/Audio/AudioPlatform.hpp delete mode 100644 module-audio/Audio/BluetoothProxyAudio.cpp delete mode 100644 module-audio/Audio/BluetoothProxyAudio.hpp create mode 100644 module-audio/board/linux/CMakeLists.txt create mode 100644 module-audio/board/linux/LinuxAudioPlatform.cpp create mode 100644 module-audio/board/rt1051/CMakeLists.txt rename module-bsp/board/rt1051/bsp/audio/RT1051Audiocodec.cpp => module-audio/board/rt1051/RT1051AudioCodec.cpp (60%) rename module-bsp/board/rt1051/bsp/audio/RT1051Audiocodec.hpp => module-audio/board/rt1051/RT1051AudioCodec.hpp (76%) mode change 100755 => 100644 rename {module-bsp/board/rt1051/bsp/audio => module-audio/board/rt1051}/RT1051CellularAudio.cpp (96%) rename {module-bsp/board/rt1051/bsp/audio => module-audio/board/rt1051}/RT1051CellularAudio.hpp (98%) mode change 100755 => 100644 create mode 100644 module-audio/board/rt1051/RT1051DeviceFactory.cpp create mode 100644 module-audio/board/rt1051/RT1051DeviceFactory.hpp create mode 100644 module-audio/board/rt1051/RT1051Platform.cpp rename {module-bsp/board/rt1051/bsp/audio => module-audio/board/rt1051}/SAIAudioDevice.cpp (98%) rename {module-bsp/board/rt1051/bsp/audio => module-audio/board/rt1051}/SAIAudioDevice.hpp (88%) delete mode 100644 module-audio/targets/Target_Cross.cmake delete mode 100644 module-audio/targets/Target_Linux.cmake create mode 100644 module-bsp/board/rt1051/common/audio.cpp create mode 100644 module-bsp/board/rt1051/common/audio.hpp delete mode 100644 module-bsp/bsp/audio/bsp_audio.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e54f6884b3a5404a46897eafec091aea888e9b4..771b902d65b12ff73e280be1abb656123669ffb8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,10 @@ message("TARGET_COMPILE_DEFINITIONS: ${TARGET_COMPILE_OPTIONS}") message("TARGET_LIBRARIES: ${TARGET_LIBRARIES}") message("TARGET_LINKER_FLAGS: ${TARGET_LINKER_FLAGS}") +string(REPLACE "TARGET_" "" PROJECT_TARGET_NAME ${PROJECT_TARGET}) +string(TOLOWER "${PROJECT_TARGET_NAME}" PROJECT_TARGET_NAME) +message("Project target name: ${PROJECT_TARGET_NAME}") + add_executable(${PROJECT_NAME} "" ) if (NOT ${PROJECT_TARGET} STREQUAL "TARGET_RT1051") diff --git a/module-apps/CMakeLists.txt b/module-apps/CMakeLists.txt index c3fec373bd1afd7136b18da862bdd5ca485eac3c..d3c53632a26cf18407bbb2d17f2b75ec9c818862 100644 --- a/module-apps/CMakeLists.txt +++ b/module-apps/CMakeLists.txt @@ -1,4 +1,7 @@ -cmake_minimum_required(VERSION 3.14) +# Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +cmake_minimum_required(VERSION 3.14) project(module-apps VERSION 1.0 DESCRIPTION "Library with all applications.") @@ -112,6 +115,7 @@ target_link_libraries(${PROJECT_NAME} service-db service-evtmgr PUBLIC + module-audio module-bsp module-os module-sys diff --git a/module-audio/Audio/AudioCommon.cpp b/module-audio/Audio/AudioCommon.cpp index b3c6bcb955d3bad8952a1ed40cf9f9bc1cfe9f9f..f7f762a931e91d58f57827221add538f10bb370d 100644 --- a/module-audio/Audio/AudioCommon.cpp +++ b/module-audio/Audio/AudioCommon.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "AudioCommon.hpp" @@ -8,9 +8,9 @@ namespace audio { - audio::RetCode GetDeviceError(bsp::AudioDevice::RetCode retCode) + audio::RetCode GetDeviceError(AudioDevice::RetCode retCode) { - if (retCode == bsp::AudioDevice::RetCode::Success) { + if (retCode == AudioDevice::RetCode::Success) { return RetCode::Success; } diff --git a/module-audio/Audio/AudioCommon.hpp b/module-audio/Audio/AudioCommon.hpp index 92f9fc8bd75ccbebc80a9d2b9a1114e1de010479..203caf4bc7f14b039a335a7da6a761bbafd8cf40 100644 --- a/module-audio/Audio/AudioCommon.hpp +++ b/module-audio/Audio/AudioCommon.hpp @@ -1,16 +1,17 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once +#include "AudioDevice.hpp" +#include "Profiles/Profile.hpp" + +#include +#include + #include #include -#include -#include #include -#include - -#include "Profiles/Profile.hpp" namespace audio { @@ -243,7 +244,7 @@ namespace audio friend class ::audio::AudioMux; }; - RetCode GetDeviceError(bsp::AudioDevice::RetCode retCode); + RetCode GetDeviceError(AudioDevice::RetCode retCode); const std::string str(RetCode retcode); [[nodiscard]] auto GetVolumeText(const audio::Volume &volume) -> std::string; } // namespace audio diff --git a/module-bsp/bsp/audio/bsp_audio.hpp b/module-audio/Audio/AudioDevice.hpp old mode 100755 new mode 100644 similarity index 91% rename from module-bsp/bsp/audio/bsp_audio.hpp rename to module-audio/Audio/AudioDevice.hpp index 29a8704791911ad085e6c9823a3e9519cd8f31c2..dc9cfac92906533f59b189e7921df4d1bee72621 --- a/module-bsp/bsp/audio/bsp_audio.hpp +++ b/module-audio/Audio/AudioDevice.hpp @@ -1,3 +1,6 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + #pragma once #include