AudioRendererManagerServer.cs 4.4 KB

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