AudioRendererManagerServer.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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(context, out IAudioRenderer renderer, ref parameter, workBufferSize, appletResourceUserId, workBufferTransferMemory, processHandle);
  31. if (result == ResultCode.Success)
  32. {
  33. MakeObject(context, new AudioRendererServer(renderer));
  34. }
  35. context.Device.System.KernelContext.Syscall.CloseHandle(transferMemoryHandle);
  36. context.Device.System.KernelContext.Syscall.CloseHandle((int)processHandle);
  37. return result;
  38. }
  39. [CommandHipc(1)]
  40. // GetWorkBufferSize(nn::audio::detail::AudioRendererParameterInternal parameter) -> u64 workBufferSize
  41. public ResultCode GetAudioRendererWorkBufferSize(ServiceCtx context)
  42. {
  43. AudioRendererConfiguration parameter = context.RequestData.ReadStruct<AudioRendererConfiguration>();
  44. if (BehaviourContext.CheckValidRevision(parameter.Revision))
  45. {
  46. ulong size = _impl.GetWorkBufferSize(ref parameter);
  47. context.ResponseData.Write(size);
  48. Logger.Debug?.Print(LogClass.ServiceAudio, $"WorkBufferSize is 0x{size:x16}.");
  49. return ResultCode.Success;
  50. }
  51. else
  52. {
  53. context.ResponseData.Write(0L);
  54. Logger.Warning?.Print(LogClass.ServiceAudio, $"Library Revision REV{BehaviourContext.GetRevisionNumber(parameter.Revision)} is not supported!");
  55. return ResultCode.UnsupportedRevision;
  56. }
  57. }
  58. [CommandHipc(2)]
  59. // GetAudioDeviceService(nn::applet::AppletResourceUserId) -> object<nn::audio::detail::IAudioDevice>
  60. public ResultCode GetAudioDeviceService(ServiceCtx context)
  61. {
  62. ulong appletResourceUserId = context.RequestData.ReadUInt64();
  63. ResultCode result = _impl.GetAudioDeviceServiceWithRevisionInfo(context, out IAudioDevice device, InitialRevision, appletResourceUserId);
  64. if (result == ResultCode.Success)
  65. {
  66. MakeObject(context, new AudioDeviceServer(device));
  67. }
  68. return result;
  69. }
  70. [CommandHipc(4)] // 4.0.0+
  71. // GetAudioDeviceServiceWithRevisionInfo(s32 revision, nn::applet::AppletResourceUserId appletResourceId) -> object<nn::audio::detail::IAudioDevice>
  72. public ResultCode GetAudioDeviceServiceWithRevisionInfo(ServiceCtx context)
  73. {
  74. int revision = context.RequestData.ReadInt32();
  75. ulong appletResourceUserId = context.RequestData.ReadUInt64();
  76. ResultCode result = _impl.GetAudioDeviceServiceWithRevisionInfo(context, out IAudioDevice device, revision, appletResourceUserId);
  77. if (result == ResultCode.Success)
  78. {
  79. MakeObject(context, new AudioDeviceServer(device));
  80. }
  81. return result;
  82. }
  83. }
  84. }