AudioCodecInfo.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using System;
  2. using UnityEngine;
  3. using Unity.WebRTC;
  4. namespace Unity.RenderStreaming
  5. {
  6. /// <summary>
  7. ///
  8. /// </summary>
  9. [Serializable]
  10. public class AudioCodecInfo : IEquatable<AudioCodecInfo>
  11. {
  12. [SerializeField]
  13. private string m_MimeType;
  14. [SerializeField]
  15. private string m_SdpFmtpLine;
  16. [SerializeField]
  17. private int m_ChannelCount;
  18. [SerializeField]
  19. private int m_SampleRate;
  20. /// <summary>
  21. ///
  22. /// </summary>
  23. public string name { get { return m_MimeType.GetCodecName(); } }
  24. /// <summary>
  25. ///
  26. /// </summary>
  27. public string mimeType { get { return m_MimeType; } }
  28. /// <summary>
  29. ///
  30. /// </summary>
  31. public int channelCount { get { return m_ChannelCount; } }
  32. /// <summary>
  33. ///
  34. /// </summary>
  35. public int sampleRate { get { return m_SampleRate; } }
  36. /// <summary>
  37. ///
  38. /// </summary>
  39. public string sdpFmtpLine { get { return m_SdpFmtpLine; } }
  40. static internal AudioCodecInfo Create(RTCRtpCodecCapability caps)
  41. {
  42. return new AudioCodecInfo(caps);
  43. }
  44. /// <summary>
  45. ///
  46. /// </summary>
  47. /// <param name="other"></param>
  48. /// <returns></returns>
  49. public bool Equals(AudioCodecInfo other)
  50. {
  51. if (other == null)
  52. return false;
  53. return this.mimeType == other.mimeType
  54. && this.sdpFmtpLine == other.sdpFmtpLine
  55. && this.channelCount == other.channelCount
  56. && this.sampleRate == other.sampleRate;
  57. }
  58. /// <summary>
  59. ///
  60. /// </summary>
  61. /// <param name="obj"></param>
  62. /// <returns></returns>
  63. public override bool Equals(object obj)
  64. {
  65. return obj is AudioCodecInfo ? Equals((AudioCodecInfo)obj) : base.Equals(obj);
  66. }
  67. /// <summary>
  68. ///
  69. /// </summary>
  70. /// <returns></returns>
  71. public override int GetHashCode()
  72. {
  73. return new { mimeType, sdpFmtpLine, channelCount, sampleRate }.GetHashCode();
  74. }
  75. /// <summary>
  76. ///
  77. /// </summary>
  78. /// <param name="left"></param>
  79. /// <param name="right"></param>
  80. /// <returns></returns>
  81. public static bool operator ==(AudioCodecInfo left, AudioCodecInfo right)
  82. {
  83. if (ReferenceEquals(left, null))
  84. {
  85. return ReferenceEquals(left, null);
  86. }
  87. else
  88. {
  89. return left.Equals(right);
  90. }
  91. }
  92. /// <summary>
  93. ///
  94. /// </summary>
  95. /// <param name="left"></param>
  96. /// <param name="right"></param>
  97. /// <returns></returns>
  98. public static bool operator !=(AudioCodecInfo left, AudioCodecInfo right)
  99. {
  100. return !(left == right);
  101. }
  102. internal AudioCodecInfo(RTCRtpCodecCapability cap)
  103. {
  104. m_MimeType = cap.mimeType;
  105. m_SdpFmtpLine = cap.sdpFmtpLine;
  106. m_ChannelCount = cap.channels.GetValueOrDefault();
  107. m_SampleRate = cap.clockRate.GetValueOrDefault();
  108. }
  109. internal bool Equals(RTCRtpCodecCapability other)
  110. {
  111. if (other == null)
  112. return false;
  113. return this.mimeType == other.mimeType
  114. && this.sdpFmtpLine == other.sdpFmtpLine
  115. && this.channelCount == other.channels
  116. && this.sampleRate == other.clockRate;
  117. }
  118. }
  119. }