2020-08-18 03:49:37 +02:00
|
|
|
|
using Ryujinx.Common.Logging;
|
|
|
|
|
using Ryujinx.HLE.HOS.Ipc;
|
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Threading;
|
2023-01-04 23:15:45 +01:00
|
|
|
|
using Ryujinx.Horizon.Common;
|
2020-08-18 03:49:37 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Buffers;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Audio.AudioRenderer
|
|
|
|
|
{
|
2021-06-29 19:37:13 +02:00
|
|
|
|
class AudioRendererServer : DisposableIpcService
|
2020-08-18 03:49:37 +02:00
|
|
|
|
{
|
|
|
|
|
private IAudioRenderer _impl;
|
|
|
|
|
|
|
|
|
|
public AudioRendererServer(IAudioRenderer impl)
|
|
|
|
|
{
|
|
|
|
|
_impl = impl;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
|
[CommandCmif(0)]
|
2020-08-18 03:49:37 +02:00
|
|
|
|
// GetSampleRate() -> u32
|
|
|
|
|
public ResultCode GetSampleRate(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
context.ResponseData.Write(_impl.GetSampleRate());
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
|
[CommandCmif(1)]
|
2020-08-18 03:49:37 +02:00
|
|
|
|
// GetSampleCount() -> u32
|
|
|
|
|
public ResultCode GetSampleCount(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
context.ResponseData.Write(_impl.GetSampleCount());
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
|
[CommandCmif(2)]
|
2020-08-18 03:49:37 +02:00
|
|
|
|
// GetMixBufferCount() -> u32
|
|
|
|
|
public ResultCode GetMixBufferCount(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
context.ResponseData.Write(_impl.GetMixBufferCount());
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
|
[CommandCmif(3)]
|
2020-08-18 03:49:37 +02:00
|
|
|
|
// GetState() -> u32
|
|
|
|
|
public ResultCode GetState(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
context.ResponseData.Write(_impl.GetState());
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
|
[CommandCmif(4)]
|
2020-08-18 03:49:37 +02:00
|
|
|
|
// RequestUpdate(buffer<nn::audio::detail::AudioRendererUpdateDataHeader, 5> input)
|
|
|
|
|
// -> (buffer<nn::audio::detail::AudioRendererUpdateDataHeader, 6> output, buffer<nn::audio::detail::AudioRendererUpdateDataHeader, 6> performanceOutput)
|
|
|
|
|
public ResultCode RequestUpdate(ServiceCtx context)
|
|
|
|
|
{
|
2021-04-24 12:16:01 +02:00
|
|
|
|
ulong inputPosition = context.Request.SendBuff[0].Position;
|
|
|
|
|
ulong inputSize = context.Request.SendBuff[0].Size;
|
2020-08-18 03:49:37 +02:00
|
|
|
|
|
2021-04-24 12:16:01 +02:00
|
|
|
|
ulong outputPosition = context.Request.ReceiveBuff[0].Position;
|
|
|
|
|
ulong outputSize = context.Request.ReceiveBuff[0].Size;
|
2020-08-18 03:49:37 +02:00
|
|
|
|
|
2021-04-24 12:16:01 +02:00
|
|
|
|
ulong performanceOutputPosition = context.Request.ReceiveBuff[1].Position;
|
|
|
|
|
ulong performanceOutputSize = context.Request.ReceiveBuff[1].Size;
|
2020-08-18 03:49:37 +02:00
|
|
|
|
|
2021-04-24 12:16:01 +02:00
|
|
|
|
ReadOnlyMemory<byte> input = context.Memory.GetSpan(inputPosition, (int)inputSize).ToArray();
|
2020-08-18 03:49:37 +02:00
|
|
|
|
|
|
|
|
|
Memory<byte> output = new byte[outputSize];
|
|
|
|
|
Memory<byte> performanceOutput = new byte[performanceOutputSize];
|
|
|
|
|
|
|
|
|
|
using MemoryHandle outputHandle = output.Pin();
|
|
|
|
|
using MemoryHandle performanceOutputHandle = performanceOutput.Pin();
|
|
|
|
|
|
|
|
|
|
ResultCode result = _impl.RequestUpdate(output, performanceOutput, input);
|
|
|
|
|
|
|
|
|
|
if (result == ResultCode.Success)
|
|
|
|
|
{
|
2021-04-24 12:16:01 +02:00
|
|
|
|
context.Memory.Write(outputPosition, output.Span);
|
|
|
|
|
context.Memory.Write(performanceOutputPosition, performanceOutput.Span);
|
2020-08-18 03:49:37 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-05-19 00:59:27 +02:00
|
|
|
|
Logger.Error?.Print(LogClass.ServiceAudio, $"Error while processing renderer update: 0x{(int)result:X}");
|
2020-08-18 03:49:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
|
[CommandCmif(5)]
|
2020-08-18 03:49:37 +02:00
|
|
|
|
// Start()
|
|
|
|
|
public ResultCode Start(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
return _impl.Start();
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
|
[CommandCmif(6)]
|
2020-08-18 03:49:37 +02:00
|
|
|
|
// Stop()
|
|
|
|
|
public ResultCode Stop(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
return _impl.Stop();
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
|
[CommandCmif(7)]
|
2020-08-18 03:49:37 +02:00
|
|
|
|
// QuerySystemEvent() -> handle<copy, event>
|
|
|
|
|
public ResultCode QuerySystemEvent(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
ResultCode result = _impl.QuerySystemEvent(out KEvent systemEvent);
|
|
|
|
|
|
|
|
|
|
if (result == ResultCode.Success)
|
|
|
|
|
{
|
2023-01-04 23:15:45 +01:00
|
|
|
|
if (context.Process.HandleTable.GenerateHandle(systemEvent.ReadableEvent, out int handle) != Result.Success)
|
2020-08-18 03:49:37 +02:00
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Out of handles!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
|
[CommandCmif(8)]
|
2020-08-18 03:49:37 +02:00
|
|
|
|
// SetAudioRendererRenderingTimeLimit(u32 limit)
|
|
|
|
|
public ResultCode SetAudioRendererRenderingTimeLimit(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
uint limit = context.RequestData.ReadUInt32();
|
|
|
|
|
|
|
|
|
|
_impl.SetRenderingTimeLimit(limit);
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
|
[CommandCmif(9)]
|
2020-08-18 03:49:37 +02:00
|
|
|
|
// GetAudioRendererRenderingTimeLimit() -> u32 limit
|
|
|
|
|
public ResultCode GetAudioRendererRenderingTimeLimit(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
uint limit = _impl.GetRenderingTimeLimit();
|
|
|
|
|
|
|
|
|
|
context.ResponseData.Write(limit);
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
|
[CommandCmif(10)] // 3.0.0+
|
2020-08-18 03:49:37 +02:00
|
|
|
|
// RequestUpdateAuto(buffer<nn::audio::detail::AudioRendererUpdateDataHeader, 0x21> input)
|
|
|
|
|
// -> (buffer<nn::audio::detail::AudioRendererUpdateDataHeader, 0x22> output, buffer<nn::audio::detail::AudioRendererUpdateDataHeader, 0x22> performanceOutput)
|
|
|
|
|
public ResultCode RequestUpdateAuto(ServiceCtx context)
|
|
|
|
|
{
|
2021-04-24 12:16:01 +02:00
|
|
|
|
(ulong inputPosition, ulong inputSize) = context.Request.GetBufferType0x21();
|
|
|
|
|
(ulong outputPosition, ulong outputSize) = context.Request.GetBufferType0x22(0);
|
|
|
|
|
(ulong performanceOutputPosition, ulong performanceOutputSize) = context.Request.GetBufferType0x22(1);
|
2020-08-18 03:49:37 +02:00
|
|
|
|
|
2021-04-24 12:16:01 +02:00
|
|
|
|
ReadOnlyMemory<byte> input = context.Memory.GetSpan(inputPosition, (int)inputSize).ToArray();
|
2020-08-18 03:49:37 +02:00
|
|
|
|
|
|
|
|
|
Memory<byte> output = new byte[outputSize];
|
|
|
|
|
Memory<byte> performanceOutput = new byte[performanceOutputSize];
|
|
|
|
|
|
|
|
|
|
using MemoryHandle outputHandle = output.Pin();
|
|
|
|
|
using MemoryHandle performanceOutputHandle = performanceOutput.Pin();
|
|
|
|
|
|
|
|
|
|
ResultCode result = _impl.RequestUpdate(output, performanceOutput, input);
|
|
|
|
|
|
|
|
|
|
if (result == ResultCode.Success)
|
|
|
|
|
{
|
2021-04-24 12:16:01 +02:00
|
|
|
|
context.Memory.Write(outputPosition, output.Span);
|
|
|
|
|
context.Memory.Write(performanceOutputPosition, performanceOutput.Span);
|
2020-08-18 03:49:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
|
[CommandCmif(11)] // 3.0.0+
|
2022-11-28 08:28:45 +01:00
|
|
|
|
// ExecuteAudioRendererRendering()
|
|
|
|
|
public ResultCode ExecuteAudioRendererRendering(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
return _impl.ExecuteAudioRendererRendering();
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
|
[CommandCmif(12)] // 15.0.0+
|
2022-11-28 08:28:45 +01:00
|
|
|
|
// SetVoiceDropParameter(f32 voiceDropParameter)
|
|
|
|
|
public ResultCode SetVoiceDropParameter(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
float voiceDropParameter = context.RequestData.ReadSingle();
|
|
|
|
|
|
|
|
|
|
_impl.SetVoiceDropParameter(voiceDropParameter);
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
|
[CommandCmif(13)] // 15.0.0+
|
2022-11-28 08:28:45 +01:00
|
|
|
|
// GetVoiceDropParameter() -> f32 voiceDropParameter
|
|
|
|
|
public ResultCode GetVoiceDropParameter(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
float voiceDropParameter = _impl.GetVoiceDropParameter();
|
|
|
|
|
|
|
|
|
|
context.ResponseData.Write(voiceDropParameter);
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-29 19:37:13 +02:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
2020-08-18 03:49:37 +02:00
|
|
|
|
{
|
2021-06-29 19:37:13 +02:00
|
|
|
|
if (isDisposing)
|
2020-08-18 03:49:37 +02:00
|
|
|
|
{
|
|
|
|
|
_impl.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-15 01:00:34 +02:00
|
|
|
|
}
|