2020-04-19 23:04:05 +02:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
2020-03-27 20:36:02 +01:00
|
|
|
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
|
|
|
|
2020-02-17 20:11:59 +01:00
|
|
|
#include <kernel/types/KProcess.h>
|
|
|
|
#include "IAudioOutManager.h"
|
|
|
|
#include "IAudioOut.h"
|
|
|
|
|
|
|
|
namespace skyline::service::audio {
|
2020-09-21 12:04:26 +02:00
|
|
|
IAudioOutManager::IAudioOutManager(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager) {}
|
2020-02-17 20:11:59 +01:00
|
|
|
|
2020-09-03 20:43:52 +02:00
|
|
|
Result IAudioOutManager::ListAudioOuts(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
2022-04-30 16:33:44 +02:00
|
|
|
std::memset(request.outputBuf.at(0).data(), 0, request.outputBuf.at(0).size());
|
2020-09-25 02:05:12 +02:00
|
|
|
request.outputBuf.at(0).copy_from(constant::DefaultAudioOutName);
|
2022-06-04 20:12:37 +02:00
|
|
|
response.Push<u32>(1); // One audio out
|
2020-09-03 20:43:52 +02:00
|
|
|
return {};
|
2020-02-17 20:11:59 +01:00
|
|
|
}
|
|
|
|
|
2020-09-03 20:43:52 +02:00
|
|
|
Result IAudioOutManager::OpenAudioOut(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
2022-01-22 22:42:38 +01:00
|
|
|
struct AudioInputParams {
|
|
|
|
u32 sampleRate;
|
|
|
|
u16 channelCount;
|
|
|
|
u16 _pad_;
|
|
|
|
};
|
|
|
|
auto &inputParams{request.Pop<AudioInputParams>()};
|
|
|
|
|
|
|
|
inputParams.sampleRate = inputParams.sampleRate ? inputParams.sampleRate : constant::SampleRate;
|
|
|
|
inputParams.channelCount = inputParams.channelCount <= constant::StereoChannelCount ? constant::StereoChannelCount : constant::SurroundChannelCount;
|
|
|
|
inputParams._pad_ = 0;
|
|
|
|
Logger::Debug("Opening an IAudioOut with sample rate: {}, channel count: {}", inputParams.sampleRate, inputParams.channelCount);
|
|
|
|
manager.RegisterService(std::make_shared<IAudioOut>(state, manager, inputParams.channelCount, inputParams.sampleRate), session, response);
|
|
|
|
response.Push<AudioInputParams>(inputParams);
|
2020-04-17 23:23:38 +02:00
|
|
|
response.Push(static_cast<u32>(skyline::audio::AudioFormat::Int16));
|
2020-02-17 20:11:59 +01:00
|
|
|
response.Push(static_cast<u32>(skyline::audio::AudioOutState::Stopped));
|
2020-09-03 20:43:52 +02:00
|
|
|
|
2022-04-30 16:33:44 +02:00
|
|
|
std::memset(request.outputBuf.at(0).data(), 0, request.outputBuf.at(0).size());
|
|
|
|
|
2022-01-22 22:42:38 +01:00
|
|
|
if (request.inputBuf.at(0).empty() || !request.inputBuf.at(0)[0])
|
|
|
|
request.outputBuf.at(0).copy_from(constant::DefaultAudioOutName);
|
|
|
|
else
|
|
|
|
request.outputBuf.at(0).copy_from(request.inputBuf.at(0));
|
|
|
|
|
2020-09-03 20:43:52 +02:00
|
|
|
return {};
|
2020-02-17 20:11:59 +01:00
|
|
|
}
|
|
|
|
}
|