AudioRendererManagerServer.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using Ryujinx.Audio.Renderer.Parameter;
  2. using Ryujinx.Audio.Renderer.Server;
  3. using Ryujinx.Common;
  4. using Ryujinx.Common.Logging;
  5. using Ryujinx.HLE.HOS.Kernel.Memory;
  6. using Ryujinx.HLE.HOS.Services.Audio.AudioRenderer;
  7. namespace Ryujinx.HLE.HOS.Services.Audio
  8. {
  9. [Service("audren:u")]
  10. class AudioRendererManagerServer : IpcService
  11. {
  12. private const int InitialRevision = ('R' << 0) | ('E' << 8) | ('V' << 16) | ('1' << 24);
  13. private IAudioRendererManager _impl;
  14. public AudioRendererManagerServer(ServiceCtx context) : this(context, new AudioRendererManager(context.Device.System.AudioRendererManager, context.Device.System.AudioDeviceSessionRegistry)) { }
  15. public AudioRendererManagerServer(ServiceCtx context, IAudioRendererManager impl) : base(context.Device.System.AudRenServer)
  16. {
  17. _impl = impl;
  18. }
  19. [CommandHipc(0)]
  20. // OpenAudioRenderer(nn::audio::detail::AudioRendererParameterInternal parameter, u64 workBufferSize, nn::applet::AppletResourceUserId appletResourceId, pid, handle<copy> workBuffer, handle<copy> processHandle)
  21. // -> object<nn::audio::detail::IAudioRenderer>
  22. public ResultCode OpenAudioRenderer(ServiceCtx context)
  23. {
  24. AudioRendererConfiguration parameter = context.RequestData.ReadStruct<AudioRendererConfiguration>();
  25. ulong workBufferSize = context.RequestData.ReadUInt64();
  26. ulong appletResourceUserId = context.RequestData.ReadUInt64();
  27. int transferMemoryHandle = context.Request.HandleDesc.ToCopy[0];
  28. KTransferMemory workBufferTransferMemory = context.Process.HandleTable.GetObject<KTransferMemory>(transferMemoryHandle);
  29. uint processHandle = (uint)context.Request.HandleDesc.ToCopy[1];
  30. ResultCode result = _impl.OpenAudioRenderer(
  31. context,
  32. out IAudioRenderer renderer,
  33. ref parameter,
  34. workBufferSize,
  35. appletResourceUserId,
  36. workBufferTransferMemory,
  37. processHandle);
  38. if (result == ResultCode.Success)
  39. {
  40. MakeObject(context, new AudioRendererServer(renderer));
  41. }
  42. context.Device.System.KernelContext.Syscall.CloseHandle(transferMemoryHandle);
  43. context.Device.System.KernelContext.Syscall.CloseHandle((int)processHandle);
  44. return result;
  45. }
  46. [CommandHipc(1)]
  47. // GetWorkBufferSize(nn::audio::detail::AudioRendererParameterInternal parameter) -> u64 workBufferSize
  48. public ResultCode GetAudioRendererWorkBufferSize(ServiceCtx context)
  49. {
  50. AudioRendererConfiguration parameter = context.RequestData.ReadStruct<AudioRendererConfiguration>();
  51. if (BehaviourContext.CheckValidRevision(parameter.Revision))
  52. {
  53. ulong size = _impl.GetWorkBufferSize(ref parameter);
  54. context.ResponseData.Write(size);
  55. Logger.Debug?.Print(LogClass.ServiceAudio, $"WorkBufferSize is 0x{size:x16}.");
  56. return ResultCode.Success;
  57. }
  58. else
  59. {
  60. context.ResponseData.Write(0L);
  61. Logger.Warning?.Print(LogClass.ServiceAudio, $"Library Revision REV{BehaviourContext.GetRevisionNumber(parameter.Revision)} is not supported!");
  62. return ResultCode.UnsupportedRevision;
  63. }
  64. }
  65. [CommandHipc(2)]
  66. // GetAudioDeviceService(nn::applet::AppletResourceUserId) -> object<nn::audio::detail::IAudioDevice>
  67. public ResultCode GetAudioDeviceService(ServiceCtx context)
  68. {
  69. ulong appletResourceUserId = context.RequestData.ReadUInt64();
  70. ResultCode result = _impl.GetAudioDeviceServiceWithRevisionInfo(context, out IAudioDevice device, InitialRevision, appletResourceUserId);
  71. if (result == ResultCode.Success)
  72. {
  73. MakeObject(context, new AudioDeviceServer(device));
  74. }
  75. return result;
  76. }
  77. [CommandHipc(4)] // 4.0.0+
  78. // GetAudioDeviceServiceWithRevisionInfo(s32 revision, nn::applet::AppletResourceUserId appletResourceId) -> object<nn::audio::detail::IAudioDevice>
  79. public ResultCode GetAudioDeviceServiceWithRevisionInfo(ServiceCtx context)
  80. {
  81. int revision = context.RequestData.ReadInt32();
  82. ulong appletResourceUserId = context.RequestData.ReadUInt64();
  83. ResultCode result = _impl.GetAudioDeviceServiceWithRevisionInfo(context, out IAudioDevice device, revision, appletResourceUserId);
  84. if (result == ResultCode.Success)
  85. {
  86. MakeObject(context, new AudioDeviceServer(device));
  87. }
  88. return result;
  89. }
  90. }
  91. }