Archived
1
0
Fork 0
forked from Mirror/Ryujinx
This repository has been archived on 2024-10-11. You can view files and clone it, but cannot push or open issues or pull requests.
jinx/Ryujinx.HLE/HOS/Services/Audio/AudioRendererManagerServer.cs
gdkchan cf6cd71488
IPC refactor part 2: Use ReplyAndReceive on HLE services and remove special handling from kernel (#1458)
* IPC refactor part 2: Use ReplyAndReceive on HLE services and remove special handling from kernel

* Fix for applet transfer memory + some nits

* Keep handles if possible to avoid server handle table exhaustion

* Fix IPC ZeroFill bug

* am: Correctly implement CreateManagedDisplayLayer and implement CreateManagedDisplaySeparableLayer

CreateManagedDisplaySeparableLayer is requires since 10.x+ when appletResourceUserId != 0

* Make it exit properly

* Make ServiceNotImplementedException show the full message again

* Allow yielding execution to avoid starving other threads

* Only wait if active

* Merge IVirtualMemoryManager and IAddressSpaceManager

* Fix Ro loading data from the wrong process

Co-authored-by: Thog <me@thog.eu>
2020-12-02 00:23:43 +01:00

107 lines
4.5 KiB
C#

using Ryujinx.Audio.Renderer.Parameter;
using Ryujinx.Audio.Renderer.Server;
using Ryujinx.Common;
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Kernel.Memory;
using Ryujinx.HLE.HOS.Services.Audio.AudioRenderer;
namespace Ryujinx.HLE.HOS.Services.Audio
{
[Service("audren:u")]
class AudioRendererManagerServer : IpcService
{
private const int InitialRevision = ('R' << 0) | ('E' << 8) | ('V' << 16) | ('1' << 24);
private IAudioRendererManager _impl;
public AudioRendererManagerServer(ServiceCtx context) : this(context, new AudioRendererManager(context.Device.System.AudioRendererManager, context.Device.System.AudioDeviceSessionRegistry)) { }
public AudioRendererManagerServer(ServiceCtx context, IAudioRendererManager impl) : base(new ServerBase(context.Device.System.KernelContext, "AudioRendererServer"))
{
_impl = impl;
}
[Command(0)]
// OpenAudioRenderer(nn::audio::detail::AudioRendererParameterInternal parameter, u64 workBufferSize, nn::applet::AppletResourceUserId appletResourceId, pid, handle<copy> workBuffer, handle<copy> processHandle)
// -> object<nn::audio::detail::IAudioRenderer>
public ResultCode OpenAudioRenderer(ServiceCtx context)
{
AudioRendererConfiguration parameter = context.RequestData.ReadStruct<AudioRendererConfiguration>();
ulong workBufferSize = context.RequestData.ReadUInt64();
ulong appletResourceUserId = context.RequestData.ReadUInt64();
KTransferMemory workBufferTransferMemory = context.Process.HandleTable.GetObject<KTransferMemory>(context.Request.HandleDesc.ToCopy[0]);
uint processHandle = (uint)context.Request.HandleDesc.ToCopy[1];
ResultCode result = _impl.OpenAudioRenderer(context, out IAudioRenderer renderer, ref parameter, workBufferSize, appletResourceUserId, workBufferTransferMemory, processHandle);
if (result == ResultCode.Success)
{
MakeObject(context, new AudioRendererServer(renderer));
}
context.Device.System.KernelContext.Syscall.CloseHandle((int)processHandle);
return result;
}
[Command(1)]
// GetWorkBufferSize(nn::audio::detail::AudioRendererParameterInternal parameter) -> u64 workBufferSize
public ResultCode GetAudioRendererWorkBufferSize(ServiceCtx context)
{
AudioRendererConfiguration parameter = context.RequestData.ReadStruct<AudioRendererConfiguration>();
if (BehaviourContext.CheckValidRevision(parameter.Revision))
{
ulong size = _impl.GetWorkBufferSize(ref parameter);
context.ResponseData.Write(size);
Logger.Debug?.Print(LogClass.ServiceAudio, $"WorkBufferSize is 0x{size:x16}.");
return ResultCode.Success;
}
else
{
context.ResponseData.Write(0L);
Logger.Warning?.Print(LogClass.ServiceAudio, $"Library Revision REV{BehaviourContext.GetRevisionNumber(parameter.Revision)} is not supported!");
return ResultCode.UnsupportedRevision;
}
}
[Command(2)]
// GetAudioDeviceService(nn::applet::AppletResourceUserId) -> object<nn::audio::detail::IAudioDevice>
public ResultCode GetAudioDeviceService(ServiceCtx context)
{
ulong appletResourceUserId = context.RequestData.ReadUInt64();
ResultCode result = _impl.GetAudioDeviceServiceWithRevisionInfo(context, out IAudioDevice device, InitialRevision, appletResourceUserId);
if (result == ResultCode.Success)
{
MakeObject(context, new AudioDeviceServer(device));
}
return result;
}
[Command(4)] // 4.0.0+
// GetAudioDeviceServiceWithRevisionInfo(s32 revision, nn::applet::AppletResourceUserId appletResourceId) -> object<nn::audio::detail::IAudioDevice>
public ResultCode GetAudioDeviceServiceWithRevisionInfo(ServiceCtx context)
{
int revision = context.RequestData.ReadInt32();
ulong appletResourceUserId = context.RequestData.ReadUInt64();
ResultCode result = _impl.GetAudioDeviceServiceWithRevisionInfo(context, out IAudioDevice device, revision, appletResourceUserId);
if (result == ResultCode.Success)
{
MakeObject(context, new AudioDeviceServer(device));
}
return result;
}
}
}