2021-02-25 16:11:56 -08:00
|
|
|
|
using Ryujinx.Audio.Common;
|
|
|
|
|
using Ryujinx.Cpu;
|
|
|
|
|
using Ryujinx.HLE.HOS.Ipc;
|
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Threading;
|
2023-01-04 14:15:45 -08:00
|
|
|
|
using Ryujinx.Horizon.Common;
|
2021-02-25 16:11:56 -08:00
|
|
|
|
using Ryujinx.Memory;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Audio.AudioIn
|
|
|
|
|
{
|
2021-06-29 10:37:13 -07:00
|
|
|
|
class AudioInServer : DisposableIpcService
|
2021-02-25 16:11:56 -08:00
|
|
|
|
{
|
|
|
|
|
private IAudioIn _impl;
|
|
|
|
|
|
|
|
|
|
public AudioInServer(IAudioIn impl)
|
|
|
|
|
{
|
|
|
|
|
_impl = impl;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
|
[CommandHipc(0)]
|
2021-02-25 16:11:56 -08:00
|
|
|
|
// GetAudioInState() -> u32 state
|
|
|
|
|
public ResultCode GetAudioInState(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
context.ResponseData.Write((uint)_impl.GetState());
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
|
[CommandHipc(1)]
|
2021-02-25 16:11:56 -08:00
|
|
|
|
// Start()
|
|
|
|
|
public ResultCode Start(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
return _impl.Start();
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
|
[CommandHipc(2)]
|
2021-02-25 16:11:56 -08:00
|
|
|
|
// Stop()
|
|
|
|
|
public ResultCode StopAudioIn(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
return _impl.Stop();
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
|
[CommandHipc(3)]
|
2021-02-25 16:11:56 -08:00
|
|
|
|
// AppendAudioInBuffer(u64 tag, buffer<nn::audio::AudioInBuffer, 5>)
|
|
|
|
|
public ResultCode AppendAudioInBuffer(ServiceCtx context)
|
|
|
|
|
{
|
2021-04-24 03:16:01 -07:00
|
|
|
|
ulong position = context.Request.SendBuff[0].Position;
|
2021-02-25 16:11:56 -08:00
|
|
|
|
|
|
|
|
|
ulong bufferTag = context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
|
|
AudioUserBuffer data = MemoryHelper.Read<AudioUserBuffer>(context.Memory, position);
|
|
|
|
|
|
|
|
|
|
return _impl.AppendBuffer(bufferTag, ref data);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
|
[CommandHipc(4)]
|
2021-02-25 16:11:56 -08:00
|
|
|
|
// RegisterBufferEvent() -> handle<copy>
|
|
|
|
|
public ResultCode RegisterBufferEvent(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
KEvent bufferEvent = _impl.RegisterBufferEvent();
|
|
|
|
|
|
2023-01-04 14:15:45 -08:00
|
|
|
|
if (context.Process.HandleTable.GenerateHandle(bufferEvent.ReadableEvent, out int handle) != Result.Success)
|
2021-02-25 16:11:56 -08:00
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Out of handles!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
|
[CommandHipc(5)]
|
2021-02-25 16:11:56 -08:00
|
|
|
|
// GetReleasedAudioInBuffers() -> (u32 count, buffer<u64, 6> tags)
|
|
|
|
|
public ResultCode GetReleasedAudioInBuffers(ServiceCtx context)
|
|
|
|
|
{
|
2021-04-24 03:16:01 -07:00
|
|
|
|
ulong position = context.Request.ReceiveBuff[0].Position;
|
|
|
|
|
ulong size = context.Request.ReceiveBuff[0].Size;
|
2021-02-25 16:11:56 -08:00
|
|
|
|
|
|
|
|
|
using (WritableRegion outputRegion = context.Memory.GetWritableRegion((ulong)position, (int)size))
|
|
|
|
|
{
|
|
|
|
|
ResultCode result = _impl.GetReleasedBuffers(MemoryMarshal.Cast<byte, ulong>(outputRegion.Memory.Span), out uint releasedCount);
|
|
|
|
|
|
|
|
|
|
context.ResponseData.Write(releasedCount);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
|
[CommandHipc(6)]
|
2021-02-25 16:11:56 -08:00
|
|
|
|
// ContainsAudioInBuffer(u64 tag) -> b8
|
|
|
|
|
public ResultCode ContainsAudioInBuffer(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
ulong bufferTag = context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
|
|
context.ResponseData.Write(_impl.ContainsBuffer(bufferTag));
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
|
[CommandHipc(7)] // 3.0.0+
|
2021-02-25 16:11:56 -08:00
|
|
|
|
// AppendUacInBuffer(u64 tag, handle<copy, unknown>, buffer<nn::audio::AudioInBuffer, 5>)
|
|
|
|
|
public ResultCode AppendUacInBuffer(ServiceCtx context)
|
|
|
|
|
{
|
2021-04-24 03:16:01 -07:00
|
|
|
|
ulong position = context.Request.SendBuff[0].Position;
|
2021-02-25 16:11:56 -08:00
|
|
|
|
|
|
|
|
|
ulong bufferTag = context.RequestData.ReadUInt64();
|
|
|
|
|
uint handle = (uint)context.Request.HandleDesc.ToCopy[0];
|
|
|
|
|
|
|
|
|
|
AudioUserBuffer data = MemoryHelper.Read<AudioUserBuffer>(context.Memory, position);
|
|
|
|
|
|
|
|
|
|
return _impl.AppendUacBuffer(bufferTag, ref data, handle);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
|
[CommandHipc(8)] // 3.0.0+
|
2021-02-25 16:11:56 -08:00
|
|
|
|
// AppendAudioInBufferAuto(u64 tag, buffer<nn::audio::AudioInBuffer, 0x21>)
|
|
|
|
|
public ResultCode AppendAudioInBufferAuto(ServiceCtx context)
|
|
|
|
|
{
|
2021-04-24 03:16:01 -07:00
|
|
|
|
(ulong position, _) = context.Request.GetBufferType0x21();
|
2021-02-25 16:11:56 -08:00
|
|
|
|
|
|
|
|
|
ulong bufferTag = context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
|
|
AudioUserBuffer data = MemoryHelper.Read<AudioUserBuffer>(context.Memory, position);
|
|
|
|
|
|
|
|
|
|
return _impl.AppendBuffer(bufferTag, ref data);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
|
[CommandHipc(9)] // 3.0.0+
|
2021-02-25 16:11:56 -08:00
|
|
|
|
// GetReleasedAudioInBuffersAuto() -> (u32 count, buffer<u64, 0x22> tags)
|
|
|
|
|
public ResultCode GetReleasedAudioInBuffersAuto(ServiceCtx context)
|
|
|
|
|
{
|
2021-04-24 03:16:01 -07:00
|
|
|
|
(ulong position, ulong size) = context.Request.GetBufferType0x22();
|
2021-02-25 16:11:56 -08:00
|
|
|
|
|
2021-04-24 03:16:01 -07:00
|
|
|
|
using (WritableRegion outputRegion = context.Memory.GetWritableRegion(position, (int)size))
|
2021-02-25 16:11:56 -08:00
|
|
|
|
{
|
|
|
|
|
ResultCode result = _impl.GetReleasedBuffers(MemoryMarshal.Cast<byte, ulong>(outputRegion.Memory.Span), out uint releasedCount);
|
|
|
|
|
|
|
|
|
|
context.ResponseData.Write(releasedCount);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
|
[CommandHipc(10)] // 3.0.0+
|
2021-02-25 16:11:56 -08:00
|
|
|
|
// AppendUacInBufferAuto(u64 tag, handle<copy, event>, buffer<nn::audio::AudioInBuffer, 0x21>)
|
|
|
|
|
public ResultCode AppendUacInBufferAuto(ServiceCtx context)
|
|
|
|
|
{
|
2021-04-24 03:16:01 -07:00
|
|
|
|
(ulong position, _) = context.Request.GetBufferType0x21();
|
2021-02-25 16:11:56 -08:00
|
|
|
|
|
|
|
|
|
ulong bufferTag = context.RequestData.ReadUInt64();
|
|
|
|
|
uint handle = (uint)context.Request.HandleDesc.ToCopy[0];
|
|
|
|
|
|
|
|
|
|
AudioUserBuffer data = MemoryHelper.Read<AudioUserBuffer>(context.Memory, position);
|
|
|
|
|
|
|
|
|
|
return _impl.AppendUacBuffer(bufferTag, ref data, handle);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
|
[CommandHipc(11)] // 4.0.0+
|
2021-02-25 16:11:56 -08:00
|
|
|
|
// GetAudioInBufferCount() -> u32
|
|
|
|
|
public ResultCode GetAudioInBufferCount(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
context.ResponseData.Write(_impl.GetBufferCount());
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
|
[CommandHipc(12)] // 4.0.0+
|
2021-02-25 16:11:56 -08:00
|
|
|
|
// SetAudioInVolume(s32)
|
|
|
|
|
public ResultCode SetAudioInVolume(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
float volume = context.RequestData.ReadSingle();
|
|
|
|
|
|
|
|
|
|
_impl.SetVolume(volume);
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
|
[CommandHipc(13)] // 4.0.0+
|
2021-02-25 16:11:56 -08:00
|
|
|
|
// GetAudioInVolume() -> s32
|
|
|
|
|
public ResultCode GetAudioInVolume(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
context.ResponseData.Write(_impl.GetVolume());
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
|
[CommandHipc(14)] // 6.0.0+
|
2021-02-25 16:11:56 -08:00
|
|
|
|
// FlushAudioInBuffers() -> b8
|
|
|
|
|
public ResultCode FlushAudioInBuffers(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
context.ResponseData.Write(_impl.FlushBuffers());
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-29 10:37:13 -07:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
2021-02-25 16:11:56 -08:00
|
|
|
|
{
|
2021-06-29 10:37:13 -07:00
|
|
|
|
if (isDisposing)
|
2021-02-25 16:11:56 -08:00
|
|
|
|
{
|
|
|
|
|
_impl.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|