AudioRendererManagerServer.cs 4.5 KB

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