// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "Operation.hpp" #include #include "IdleOperation.hpp" #include "PlaybackOperation.hpp" #include "RecorderOperation.hpp" #include "RouterOperation.hpp" #include "Audio/BluetoothProxyAudio.hpp" #include namespace audio { std::unique_ptr Operation::Create(Operation::Type t, const char *fileName, const audio::PlaybackType &playbackType, AudioServiceMessage::Callback callback) { std::unique_ptr inst; switch (t) { case Type::Idle: inst = std::make_unique(fileName); break; case Type::Playback: inst = std::make_unique(fileName, playbackType, callback); break; case Type::Router: inst = std::make_unique(fileName, callback); break; case Type::Recorder: inst = std::make_unique(fileName, callback); break; } inst->opType = t; inst->filePath = fileName; return inst; } std::shared_ptr Operation::GetProfile(const Profile::Type type) { auto ret = std::find_if(supportedProfiles.begin(), supportedProfiles.end(), [type](const auto &w) { return w.isAvailable == true && w.profile->GetType() == type; }); if (ret == supportedProfiles.end()) { return nullptr; } else { return ret->profile; } } audio::RetCode Operation::SwitchToPriorityProfile() { for (auto &p : supportedProfiles) { if (p.isAvailable == true) { return SwitchProfile(p.profile->GetType()); } } return audio::RetCode::ProfileNotSet; } void Operation::SetProfileAvailability(std::vector profiles, bool available) { for (auto &p : supportedProfiles) { if (auto shouldSet = (std::find(profiles.begin(), profiles.end(), p.profile->GetType()) != profiles.end()); shouldSet) { p.isAvailable = available; } } } void Operation::AddProfile(const Profile::Type &profile, const PlaybackType &playback, bool isAvailable) { const auto reqVol = AudioServiceMessage::DbRequest(audio::dbPath(Setting::Volume, playback, profile)); const auto reqGain = AudioServiceMessage::DbRequest(audio::dbPath(Setting::Gain, playback, profile)); std::optional volume; std::optional gain; if (auto val = serviceCallback(&reqVol); val) { volume = utils::getNumericValue(val.value()); } if (auto val = serviceCallback(&reqGain); val) { gain = utils::getNumericValue(val.value()); } supportedProfiles.emplace_back(Profile::Create(profile, nullptr, volume, gain), isAvailable); } std::optional> Operation::CreateDevice(bsp::AudioDevice::Type type, bsp::AudioDevice::audioCallback_t callback) { if (type == bsp::AudioDevice::Type::Bluetooth) { auto audioFormat = currentProfile->GetAudioFormat(); return std::make_unique( serviceCallback, *dataStreamOut, *dataStreamIn, audioFormat); } return bsp::AudioDevice::Create(type, callback).value_or(nullptr); } } // namespace audio