Ryujinx/src/Ryujinx.HLE/HOS/Services/Audio/AudioIn/AudioInServer.cs
TSRBerry 326749498b
[Ryujinx.HLE] Address dotnet-format issues (#5380)
* dotnet format style --severity info

Some changes were manually reverted.

* dotnet format analyzers --serverity info

Some changes have been minimally adapted.

* Restore a few unused methods and variables

* Silence dotnet format IDE0060 warnings

* Silence dotnet format IDE0052 warnings

* Address or silence dotnet format IDE1006 warnings

* Address dotnet format CA1816 warnings

* Address or silence dotnet format CA2208 warnings

* Address or silence dotnet format CA1806 and a few CA1854 warnings

* Address dotnet format CA2211 warnings

* Address dotnet format CA1822 warnings

* Address or silence dotnet format CA1069 warnings

* Make dotnet format succeed in style mode

* Address or silence dotnet format CA2211 warnings

* Address review comments

* Address dotnet format CA2208 warnings properly

* Make ProcessResult readonly

* Address most dotnet format whitespace warnings

* Apply dotnet format whitespace formatting

A few of them have been manually reverted and the corresponding warning was silenced

* Add previously silenced warnings back

I have no clue how these disappeared

* Revert formatting changes for while and for-loops

* Format if-blocks correctly

* Run dotnet format style after rebase

* Run dotnet format whitespace after rebase

* Run dotnet format style after rebase

* Run dotnet format analyzers after rebase

* Run dotnet format after rebase and remove unused usings

- analyzers
- style
- whitespace

* Disable 'prefer switch expression' rule

* Add comments to disabled warnings

* Fix a few disabled warnings

* Fix naming rule violation, Convert shader properties to auto-property and convert values to const

* Simplify properties and array initialization, Use const when possible, Remove trailing commas

* Start working on disabled warnings

* Fix and silence a few dotnet-format warnings again

* Run dotnet format after rebase

* Use using declaration instead of block syntax

* Address IDE0251 warnings

* Address a few disabled IDE0060 warnings

* Silence IDE0060 in .editorconfig

* Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas"

This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e.

* dotnet format whitespace after rebase

* First dotnet format pass

* Fix naming rule violations

* Fix typo

* Add trailing commas, use targeted new and use array initializer

* Fix build issues

* Fix remaining build issues

* Remove SuppressMessage for CA1069 where possible

* Address dotnet format issues

* Address formatting issues

Co-authored-by: Ac_K <acoustik666@gmail.com>

* Add GetHashCode implementation for RenderingSurfaceInfo

* Explicitly silence CA1822 for every affected method in Syscall

* Address formatting issues in Demangler.cs

* Address review feedback

Co-authored-by: Ac_K <acoustik666@gmail.com>

* Revert marking service methods as static

* Next dotnet format pass

* Address review feedback

---------

Co-authored-by: Ac_K <acoustik666@gmail.com>
2023-07-16 19:31:14 +02:00

201 lines
6.5 KiB
C#

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