BaseSink.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using Ryujinx.Audio.Renderer.Common;
  2. using Ryujinx.Audio.Renderer.Parameter;
  3. using Ryujinx.Audio.Renderer.Server.MemoryPool;
  4. using System.Diagnostics;
  5. using static Ryujinx.Audio.Renderer.Common.BehaviourParameter;
  6. namespace Ryujinx.Audio.Renderer.Server.Sink
  7. {
  8. /// <summary>
  9. /// Base class used for server information of a sink.
  10. /// </summary>
  11. public class BaseSink
  12. {
  13. /// <summary>
  14. /// The type of this <see cref="BaseSink"/>.
  15. /// </summary>
  16. public SinkType Type;
  17. /// <summary>
  18. /// Set to true if the sink is used.
  19. /// </summary>
  20. public bool IsUsed;
  21. /// <summary>
  22. /// Set to true if the sink need to be skipped because of invalid state.
  23. /// </summary>
  24. public bool ShouldSkip;
  25. /// <summary>
  26. /// The node id of the sink.
  27. /// </summary>
  28. public int NodeId;
  29. /// <summary>
  30. /// Create a new <see cref="BaseSink"/>.
  31. /// </summary>
  32. public BaseSink()
  33. {
  34. CleanUp();
  35. }
  36. /// <summary>
  37. /// Clean up the internal state of the <see cref="BaseSink"/>.
  38. /// </summary>
  39. public virtual void CleanUp()
  40. {
  41. Type = TargetSinkType;
  42. IsUsed = false;
  43. ShouldSkip = false;
  44. }
  45. /// <summary>
  46. /// The target <see cref="SinkType"/> handled by this <see cref="BaseSink"/>.
  47. /// </summary>
  48. public virtual SinkType TargetSinkType => SinkType.Invalid;
  49. /// <summary>
  50. /// Check if the <see cref="SinkType"/> sent by the user match the internal <see cref="SinkType"/>.
  51. /// </summary>
  52. /// <param name="parameter">The user parameter.</param>
  53. /// <returns>Return true, if the <see cref="SinkType"/> sent by the user match the internal <see cref="SinkType"/>.</returns>
  54. public bool IsTypeValid(ref SinkInParameter parameter)
  55. {
  56. return parameter.Type == TargetSinkType;
  57. }
  58. /// <summary>
  59. /// Update the <see cref="BaseSink"/> state during command generation.
  60. /// </summary>
  61. public virtual void UpdateForCommandGeneration()
  62. {
  63. Debug.Assert(Type == TargetSinkType);
  64. }
  65. /// <summary>
  66. /// Update the internal common parameters from user parameter.
  67. /// </summary>
  68. /// <param name="parameter">The user parameter.</param>
  69. protected void UpdateStandardParameter(ref SinkInParameter parameter)
  70. {
  71. if (IsUsed != parameter.IsUsed)
  72. {
  73. IsUsed = parameter.IsUsed;
  74. NodeId = parameter.NodeId;
  75. }
  76. }
  77. /// <summary>
  78. /// Update the internal state from user parameter.
  79. /// </summary>
  80. /// <param name="errorInfo">The possible <see cref="ErrorInfo"/> that was generated.</param>
  81. /// <param name="parameter">The user parameter.</param>
  82. /// <param name="outStatus">The user output status.</param>
  83. /// <param name="mapper">The mapper to use.</param>
  84. public virtual void Update(out ErrorInfo errorInfo, ref SinkInParameter parameter, ref SinkOutStatus outStatus, PoolMapper mapper)
  85. {
  86. Debug.Assert(IsTypeValid(ref parameter));
  87. errorInfo = new ErrorInfo();
  88. }
  89. }
  90. }