using System;
using Unity.WebRTC;
using UnityEngine;
namespace Unity.RenderStreaming
{
///
/// Represents information about an audio codec, including its MIME type, SDP format parameters, channel count, and sample rate.
///
[Serializable]
public class AudioCodecInfo : IEquatable
{
[SerializeField]
private string m_MimeType;
[SerializeField]
private string m_SdpFmtpLine;
[SerializeField]
private int m_ChannelCount;
[SerializeField]
private int m_SampleRate;
///
/// Gets the name of the audio codec.
///
public string name { get { return m_MimeType.GetCodecName(); } }
///
/// Gets the MIME type of the audio codec.
///
public string mimeType { get { return m_MimeType; } }
///
/// Gets the number of audio channels.
///
public int channelCount { get { return m_ChannelCount; } }
///
/// Gets the sample rate of the audio.
///
public int sampleRate { get { return m_SampleRate; } }
///
/// Gets the SDP format parameters line.
///
public string sdpFmtpLine { get { return m_SdpFmtpLine; } }
static internal AudioCodecInfo Create(RTCRtpCodecCapability caps)
{
return new AudioCodecInfo(caps);
}
///
/// Determines whether the specified is equal to the current .
///
///
///
///
///
///
/// The to compare with the current .
/// true if the specified is equal to the current ; otherwise, false.
public bool Equals(AudioCodecInfo other)
{
if (other == null)
return false;
return this.mimeType == other.mimeType
&& this.sdpFmtpLine == other.sdpFmtpLine
&& this.channelCount == other.channelCount
&& this.sampleRate == other.sampleRate;
}
///
/// Determines whether the specified object is equal to the current .
///
/// The object to compare with the current .
/// true if the specified object is equal to the current ; otherwise, false.
public override bool Equals(object obj)
{
return obj is AudioCodecInfo ? Equals((AudioCodecInfo)obj) : base.Equals(obj);
}
///
/// Returns a hash code for the .
///
/// A hash code for the current .
public override int GetHashCode()
{
return new { mimeType, sdpFmtpLine, channelCount, sampleRate }.GetHashCode();
}
///
/// Determines whether two specified instances of are equal.
///
/// The first to compare.
/// The second to compare.
/// true if the two instances are equal; otherwise, false.
public static bool operator ==(AudioCodecInfo left, AudioCodecInfo right)
{
if (ReferenceEquals(left, null))
{
return ReferenceEquals(left, null);
}
else
{
return left.Equals(right);
}
}
///
/// Determines whether two specified instances of are not equal.
///
/// The first to compare.
/// The second to compare.
/// true if the two instances are not equal; otherwise, false.
public static bool operator !=(AudioCodecInfo left, AudioCodecInfo right)
{
return !(left == right);
}
internal AudioCodecInfo(RTCRtpCodecCapability cap)
{
m_MimeType = cap.mimeType;
m_SdpFmtpLine = cap.sdpFmtpLine;
m_ChannelCount = cap.channels.GetValueOrDefault();
m_SampleRate = cap.clockRate.GetValueOrDefault();
}
internal bool Equals(RTCRtpCodecCapability other)
{
if (other == null)
return false;
return this.mimeType == other.mimeType
&& this.sdpFmtpLine == other.sdpFmtpLine
&& this.channelCount == other.channels
&& this.sampleRate == other.clockRate;
}
}
}