IAudioOut.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using ChocolArm64.Memory;
  2. using Ryujinx.Audio;
  3. using Ryujinx.Core.Logging;
  4. using Ryujinx.Core.OsHle.Handles;
  5. using Ryujinx.Core.OsHle.Ipc;
  6. using System;
  7. using System.Collections.Generic;
  8. namespace Ryujinx.Core.OsHle.Services.Aud
  9. {
  10. class IAudioOut : IpcService, IDisposable
  11. {
  12. private Dictionary<int, ServiceProcessRequest> m_Commands;
  13. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
  14. private IAalOutput AudioOut;
  15. private KEvent ReleaseEvent;
  16. private int Track;
  17. public IAudioOut(IAalOutput AudioOut, KEvent ReleaseEvent, int Track)
  18. {
  19. m_Commands = new Dictionary<int, ServiceProcessRequest>()
  20. {
  21. { 0, GetAudioOutState },
  22. { 1, StartAudioOut },
  23. { 2, StopAudioOut },
  24. { 3, AppendAudioOutBuffer },
  25. { 4, RegisterBufferEvent },
  26. { 5, GetReleasedAudioOutBuffer },
  27. { 6, ContainsAudioOutBuffer },
  28. { 7, AppendAudioOutBufferEx },
  29. { 8, GetReleasedAudioOutBufferEx }
  30. };
  31. this.AudioOut = AudioOut;
  32. this.ReleaseEvent = ReleaseEvent;
  33. this.Track = Track;
  34. }
  35. public long GetAudioOutState(ServiceCtx Context)
  36. {
  37. Context.ResponseData.Write((int)AudioOut.GetState(Track));
  38. return 0;
  39. }
  40. public long StartAudioOut(ServiceCtx Context)
  41. {
  42. AudioOut.Start(Track);
  43. return 0;
  44. }
  45. public long StopAudioOut(ServiceCtx Context)
  46. {
  47. AudioOut.Stop(Track);
  48. return 0;
  49. }
  50. public long AppendAudioOutBuffer(ServiceCtx Context)
  51. {
  52. long Tag = Context.RequestData.ReadInt64();
  53. AudioOutData Data = AMemoryHelper.Read<AudioOutData>(
  54. Context.Memory,
  55. Context.Request.SendBuff[0].Position);
  56. byte[] Buffer = AMemoryHelper.ReadBytes(
  57. Context.Memory,
  58. Data.SampleBufferPtr,
  59. Data.SampleBufferSize);
  60. AudioOut.AppendBuffer(Track, Tag, Buffer);
  61. return 0;
  62. }
  63. public long RegisterBufferEvent(ServiceCtx Context)
  64. {
  65. int Handle = Context.Process.HandleTable.OpenHandle(ReleaseEvent);
  66. Context.Response.HandleDesc = IpcHandleDesc.MakeCopy(Handle);
  67. return 0;
  68. }
  69. public long GetReleasedAudioOutBuffer(ServiceCtx Context)
  70. {
  71. long Position = Context.Request.ReceiveBuff[0].Position;
  72. long Size = Context.Request.ReceiveBuff[0].Size;
  73. uint Count = (uint)((ulong)Size >> 3);
  74. long[] ReleasedBuffers = AudioOut.GetReleasedBuffers(Track, (int)Count);
  75. for (uint Index = 0; Index < Count; Index++)
  76. {
  77. long Tag = 0;
  78. if (Index < ReleasedBuffers.Length)
  79. {
  80. Tag = ReleasedBuffers[Index];
  81. }
  82. Context.Memory.WriteInt64(Position + Index * 8, Tag);
  83. }
  84. Context.ResponseData.Write(ReleasedBuffers.Length);
  85. return 0;
  86. }
  87. public long ContainsAudioOutBuffer(ServiceCtx Context)
  88. {
  89. long Tag = Context.RequestData.ReadInt64();
  90. Context.ResponseData.Write(AudioOut.ContainsBuffer(Track, Tag) ? 1 : 0);
  91. return 0;
  92. }
  93. public long AppendAudioOutBufferEx(ServiceCtx Context)
  94. {
  95. Context.Ns.Log.PrintStub(LogClass.ServiceAudio, "Stubbed.");
  96. return 0;
  97. }
  98. public long GetReleasedAudioOutBufferEx(ServiceCtx Context)
  99. {
  100. Context.Ns.Log.PrintStub(LogClass.ServiceAudio, "Stubbed.");
  101. return 0;
  102. }
  103. public void Dispose()
  104. {
  105. Dispose(true);
  106. }
  107. protected virtual void Dispose(bool Disposing)
  108. {
  109. if (Disposing)
  110. {
  111. AudioOut.CloseTrack(Track);
  112. ReleaseEvent.Dispose();
  113. }
  114. }
  115. }
  116. }