BaseSink.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // Copyright (c) 2019-2021 Ryujinx
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. //
  17. using Ryujinx.Audio.Renderer.Common;
  18. using Ryujinx.Audio.Renderer.Parameter;
  19. using Ryujinx.Audio.Renderer.Server.MemoryPool;
  20. using System.Diagnostics;
  21. using static Ryujinx.Audio.Renderer.Common.BehaviourParameter;
  22. namespace Ryujinx.Audio.Renderer.Server.Sink
  23. {
  24. /// <summary>
  25. /// Base class used for server information of a sink.
  26. /// </summary>
  27. public class BaseSink
  28. {
  29. /// <summary>
  30. /// The type of this <see cref="BaseSink"/>.
  31. /// </summary>
  32. public SinkType Type;
  33. /// <summary>
  34. /// Set to true if the sink is used.
  35. /// </summary>
  36. public bool IsUsed;
  37. /// <summary>
  38. /// Set to true if the sink need to be skipped because of invalid state.
  39. /// </summary>
  40. public bool ShouldSkip;
  41. /// <summary>
  42. /// The node id of the sink.
  43. /// </summary>
  44. public int NodeId;
  45. /// <summary>
  46. /// Create a new <see cref="BaseSink"/>.
  47. /// </summary>
  48. public BaseSink()
  49. {
  50. CleanUp();
  51. }
  52. /// <summary>
  53. /// Clean up the internal state of the <see cref="BaseSink"/>.
  54. /// </summary>
  55. public virtual void CleanUp()
  56. {
  57. Type = TargetSinkType;
  58. IsUsed = false;
  59. ShouldSkip = false;
  60. }
  61. /// <summary>
  62. /// The target <see cref="SinkType"/> handled by this <see cref="BaseSink"/>.
  63. /// </summary>
  64. public virtual SinkType TargetSinkType => SinkType.Invalid;
  65. /// <summary>
  66. /// Check if the <see cref="SinkType"/> sent by the user match the internal <see cref="SinkType"/>.
  67. /// </summary>
  68. /// <param name="parameter">The user parameter.</param>
  69. /// <returns>Return true, if the <see cref="SinkType"/> sent by the user match the internal <see cref="SinkType"/>.</returns>
  70. public bool IsTypeValid(ref SinkInParameter parameter)
  71. {
  72. return parameter.Type == TargetSinkType;
  73. }
  74. /// <summary>
  75. /// Update the <see cref="BaseSink"/> state during command generation.
  76. /// </summary>
  77. public virtual void UpdateForCommandGeneration()
  78. {
  79. Debug.Assert(Type == TargetSinkType);
  80. }
  81. /// <summary>
  82. /// Update the internal common parameters from user parameter.
  83. /// </summary>
  84. /// <param name="parameter">The user parameter.</param>
  85. protected void UpdateStandardParameter(ref SinkInParameter parameter)
  86. {
  87. if (IsUsed != parameter.IsUsed)
  88. {
  89. IsUsed = parameter.IsUsed;
  90. NodeId = parameter.NodeId;
  91. }
  92. }
  93. /// <summary>
  94. /// Update the internal state from user parameter.
  95. /// </summary>
  96. /// <param name="errorInfo">The possible <see cref="ErrorInfo"/> that was generated.</param>
  97. /// <param name="parameter">The user parameter.</param>
  98. /// <param name="outStatus">The user output status.</param>
  99. /// <param name="mapper">The mapper to use.</param>
  100. public virtual void Update(out ErrorInfo errorInfo, ref SinkInParameter parameter, ref SinkOutStatus outStatus, PoolMapper mapper)
  101. {
  102. Debug.Assert(IsTypeValid(ref parameter));
  103. errorInfo = new ErrorInfo();
  104. }
  105. }
  106. }