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/)
|
2023-03-15 18:49:17 +01:00
|
|
|
// Copyright © 2022 yuzu Emulator Project (https://github.com/yuzu-emu/)
|
2020-03-27 20:36:02 +01:00
|
|
|
|
2023-03-15 18:49:17 +01:00
|
|
|
#include <audio_core/audio_out_manager.h>
|
|
|
|
#include <audio.h>
|
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) {
|
2023-03-15 18:49:17 +01:00
|
|
|
auto &inputParams{request.Pop<AudioCore::AudioOut::AudioOutParameter>()};
|
|
|
|
auto appletResourceUserId{request.Pop<u64>()};
|
|
|
|
std::string_view deviceName{request.inputBuf.at(0).as_string(true)};
|
|
|
|
auto handle{request.copyHandles.at(0)};
|
|
|
|
|
|
|
|
auto &audioOutManager{*state.audio->audioOutManager};
|
|
|
|
if (auto result{audioOutManager.LinkToManager()}; result.IsError()) {
|
|
|
|
Logger::Warn("Failed to link Audio Out to manager");
|
|
|
|
return Result{result};
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t sessionId{};
|
|
|
|
if (auto result{audioOutManager.AcquireSessionId(sessionId)}; result.IsError()) {
|
|
|
|
Logger::Warn("Failed to acquire audio session");
|
|
|
|
return Result{result};
|
|
|
|
}
|
|
|
|
|
|
|
|
auto audioOut{std::make_shared<IAudioOut>(state, manager, sessionId, deviceName, inputParams, handle, appletResourceUserId)};
|
|
|
|
manager.RegisterService(audioOut, session, response);
|
|
|
|
|
|
|
|
audioOutManager.sessions[sessionId] = audioOut->impl;
|
|
|
|
audioOutManager.applet_resource_user_ids[sessionId] = appletResourceUserId;
|
|
|
|
|
|
|
|
auto &outSystem{audioOut->impl->GetSystem()};
|
|
|
|
response.Push<AudioCore::AudioOut::AudioOutParameterInternal>({
|
|
|
|
.sample_rate = outSystem.GetSampleRate(),
|
|
|
|
.channel_count = outSystem.GetChannelCount(),
|
|
|
|
.sample_format = static_cast<u32>(outSystem.GetSampleFormat()),
|
|
|
|
.state = static_cast<u32>(outSystem.GetState())
|
|
|
|
});
|
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());
|
|
|
|
|
2023-03-15 18:49:17 +01:00
|
|
|
request.outputBuf.at(0).copy_from(outSystem.GetName());
|
2022-01-22 22:42:38 +01:00
|
|
|
|
2020-09-03 20:43:52 +02:00
|
|
|
return {};
|
2020-02-17 20:11:59 +01:00
|
|
|
}
|
|
|
|
}
|