2021-02-26 01:11:56 +01:00
|
|
|
|
using Ryujinx.Audio.Common;
|
|
|
|
|
using Ryujinx.Cpu;
|
|
|
|
|
using Ryujinx.HLE.HOS.Ipc;
|
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Threading;
|
2023-01-04 23:15:45 +01:00
|
|
|
|
using Ryujinx.Horizon.Common;
|
2021-02-26 01:11:56 +01:00
|
|
|
|
using Ryujinx.Memory;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Audio.AudioOut
|
|
|
|
|
{
|
2021-06-29 19:37:13 +02:00
|
|
|
|
class AudioOutServer : DisposableIpcService
|
2021-02-26 01:11:56 +01:00
|
|
|
|
{
|
|
|
|
|
private IAudioOut _impl;
|
|
|
|
|
|
|
|
|
|
public AudioOutServer(IAudioOut impl)
|
|
|
|
|
{
|
|
|
|
|
_impl = impl;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(0)]
|
2021-02-26 01:11:56 +01:00
|
|
|
|
// GetAudioOutState() -> u32 state
|
|
|
|
|
public ResultCode GetAudioOutState(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
context.ResponseData.Write((uint)_impl.GetState());
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(1)]
|
2021-02-26 01:11:56 +01:00
|
|
|
|
// Start()
|
|
|
|
|
public ResultCode Start(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
return _impl.Start();
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(2)]
|
2021-02-26 01:11:56 +01:00
|
|
|
|
// Stop()
|
|
|
|
|
public ResultCode Stop(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
return _impl.Stop();
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(3)]
|
2021-02-26 01:11:56 +01:00
|
|
|
|
// AppendAudioOutBuffer(u64 bufferTag, buffer<nn::audio::AudioOutBuffer, 5> buffer)
|
|
|
|
|
public ResultCode AppendAudioOutBuffer(ServiceCtx context)
|
|
|
|
|
{
|
2021-04-24 12:16:01 +02:00
|
|
|
|
ulong position = context.Request.SendBuff[0].Position;
|
2021-02-26 01:11:56 +01:00
|
|
|
|
|
|
|
|
|
ulong bufferTag = context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
|
|
AudioUserBuffer data = MemoryHelper.Read<AudioUserBuffer>(context.Memory, position);
|
|
|
|
|
|
|
|
|
|
return _impl.AppendBuffer(bufferTag, ref data);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(4)]
|
2021-02-26 01:11:56 +01:00
|
|
|
|
// RegisterBufferEvent() -> handle<copy>
|
|
|
|
|
public ResultCode RegisterBufferEvent(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
KEvent bufferEvent = _impl.RegisterBufferEvent();
|
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
|
if (context.Process.HandleTable.GenerateHandle(bufferEvent.ReadableEvent, out int handle) != Result.Success)
|
2021-02-26 01:11:56 +01:00
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Out of handles!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(5)]
|
2021-02-26 01:11:56 +01:00
|
|
|
|
// GetReleasedAudioOutBuffers() -> (u32 count, buffer<u64, 6> tags)
|
|
|
|
|
public ResultCode GetReleasedAudioOutBuffers(ServiceCtx context)
|
|
|
|
|
{
|
2021-04-24 12:16:01 +02:00
|
|
|
|
ulong position = context.Request.ReceiveBuff[0].Position;
|
|
|
|
|
ulong size = context.Request.ReceiveBuff[0].Size;
|
2021-02-26 01:11:56 +01:00
|
|
|
|
|
2021-04-24 12:16:01 +02:00
|
|
|
|
using (WritableRegion outputRegion = context.Memory.GetWritableRegion(position, (int)size))
|
2021-02-26 01:11:56 +01:00
|
|
|
|
{
|
|
|
|
|
ResultCode result = _impl.GetReleasedBuffers(MemoryMarshal.Cast<byte, ulong>(outputRegion.Memory.Span), out uint releasedCount);
|
|
|
|
|
|
|
|
|
|
context.ResponseData.Write(releasedCount);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(6)]
|
2021-02-26 01:11:56 +01:00
|
|
|
|
// ContainsAudioOutBuffer(u64 tag) -> b8
|
|
|
|
|
public ResultCode ContainsAudioOutBuffer(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
ulong bufferTag = context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
|
|
context.ResponseData.Write(_impl.ContainsBuffer(bufferTag));
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(7)] // 3.0.0+
|
2021-02-26 01:11:56 +01:00
|
|
|
|
// AppendAudioOutBufferAuto(u64 tag, buffer<nn::audio::AudioOutBuffer, 0x21>)
|
|
|
|
|
public ResultCode AppendAudioOutBufferAuto(ServiceCtx context)
|
|
|
|
|
{
|
2021-04-24 12:16:01 +02:00
|
|
|
|
(ulong position, _) = context.Request.GetBufferType0x21();
|
2021-02-26 01:11:56 +01:00
|
|
|
|
|
|
|
|
|
ulong bufferTag = context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
|
|
AudioUserBuffer data = MemoryHelper.Read<AudioUserBuffer>(context.Memory, position);
|
|
|
|
|
|
|
|
|
|
return _impl.AppendBuffer(bufferTag, ref data);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(8)] // 3.0.0+
|
2021-02-26 01:11:56 +01:00
|
|
|
|
// GetReleasedAudioOutBuffersAuto() -> (u32 count, buffer<u64, 0x22> tags)
|
|
|
|
|
public ResultCode GetReleasedAudioOutBuffersAuto(ServiceCtx context)
|
|
|
|
|
{
|
2021-04-24 12:16:01 +02:00
|
|
|
|
(ulong position, ulong size) = context.Request.GetBufferType0x22();
|
2021-02-26 01:11:56 +01:00
|
|
|
|
|
2021-04-24 12:16:01 +02:00
|
|
|
|
using (WritableRegion outputRegion = context.Memory.GetWritableRegion(position, (int)size))
|
2021-02-26 01:11:56 +01:00
|
|
|
|
{
|
|
|
|
|
ResultCode result = _impl.GetReleasedBuffers(MemoryMarshal.Cast<byte, ulong>(outputRegion.Memory.Span), out uint releasedCount);
|
|
|
|
|
|
|
|
|
|
context.ResponseData.Write(releasedCount);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(9)] // 4.0.0+
|
2021-02-26 01:11:56 +01:00
|
|
|
|
// GetAudioOutBufferCount() -> u32
|
|
|
|
|
public ResultCode GetAudioOutBufferCount(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
context.ResponseData.Write(_impl.GetBufferCount());
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(10)] // 4.0.0+
|
2021-02-26 01:11:56 +01:00
|
|
|
|
// GetAudioOutPlayedSampleCount() -> u64
|
|
|
|
|
public ResultCode GetAudioOutPlayedSampleCount(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
context.ResponseData.Write(_impl.GetPlayedSampleCount());
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(11)] // 4.0.0+
|
2021-02-26 01:11:56 +01:00
|
|
|
|
// FlushAudioOutBuffers() -> b8
|
|
|
|
|
public ResultCode FlushAudioOutBuffers(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
context.ResponseData.Write(_impl.FlushBuffers());
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(12)] // 6.0.0+
|
2021-02-26 01:11:56 +01:00
|
|
|
|
// SetAudioOutVolume(s32)
|
|
|
|
|
public ResultCode SetAudioOutVolume(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
float volume = context.RequestData.ReadSingle();
|
|
|
|
|
|
|
|
|
|
_impl.SetVolume(volume);
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 00:01:24 +02:00
|
|
|
|
[CommandHipc(13)] // 6.0.0+
|
2021-02-26 01:11:56 +01:00
|
|
|
|
// GetAudioOutVolume() -> s32
|
|
|
|
|
public ResultCode GetAudioOutVolume(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
context.ResponseData.Write(_impl.GetVolume());
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-29 19:37:13 +02:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
2021-02-26 01:11:56 +01:00
|
|
|
|
{
|
2021-06-29 19:37:13 +02:00
|
|
|
|
if (isDisposing)
|
2021-02-26 01:11:56 +01:00
|
|
|
|
{
|
|
|
|
|
_impl.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|