mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-07-29 09:18:43 -04:00
64 lines
1.8 KiB
C++
64 lines
1.8 KiB
C++
// 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 <algorithm>
|
|
|
|
#include "IdleOperation.hpp"
|
|
#include "PlaybackOperation.hpp"
|
|
#include "RecorderOperation.hpp"
|
|
#include "RouterOperation.hpp"
|
|
|
|
#include "bsp/audio/bsp_audio.hpp"
|
|
#include "Audio/decoder/decoder.hpp"
|
|
|
|
namespace audio
|
|
{
|
|
std::optional<std::unique_ptr<Operation>> Operation::Create(
|
|
Operation::Type t,
|
|
const char *fileName,
|
|
const audio::PlaybackType &playbackType,
|
|
std::function<uint32_t(const std::string &path, const uint32_t &defaultValue)> dbCallback)
|
|
{
|
|
std::unique_ptr<Operation> inst;
|
|
|
|
switch (t) {
|
|
case Type::Idle:
|
|
inst = std::make_unique<IdleOperation>(fileName);
|
|
break;
|
|
case Type::Playback:
|
|
inst = std::make_unique<PlaybackOperation>(fileName, playbackType, dbCallback);
|
|
break;
|
|
case Type::Router:
|
|
inst = std::make_unique<RouterOperation>(fileName, dbCallback);
|
|
break;
|
|
case Type::Recorder:
|
|
inst = std::make_unique<RecorderOperation>(fileName, dbCallback);
|
|
break;
|
|
}
|
|
|
|
if (inst->isInitialized) {
|
|
inst->opType = t;
|
|
inst->filePath = fileName;
|
|
return inst;
|
|
}
|
|
else {
|
|
return {};
|
|
}
|
|
}
|
|
|
|
std::optional<std::shared_ptr<Profile>> Operation::GetProfile(const Profile::Type type)
|
|
{
|
|
auto ret = std::find_if(
|
|
availableProfiles.begin(), availableProfiles.end(), [type](const auto &w) { return w->GetType() == type; });
|
|
if (ret == availableProfiles.end()) {
|
|
return std::nullopt;
|
|
}
|
|
else {
|
|
return *ret;
|
|
}
|
|
}
|
|
|
|
} // namespace audio
|