?? mediafield.cs
字號:
using SDP;
using System.Collections.Generic;
/// <summary>
/// A Media represents an m= field contained within a MediaDescription. The Media identifies
/// information about the format(s) of the media associated with the MediaDescription.
///
/// The Media field includes:
/// a mediaType (e.g. audio, video, etc.)
/// a port number (or set of ports)
/// a protocol to be used (e.g. RTP/AVP)
/// a set of media formats which correspond to Attributes associated with the media description.
/// Here is an example:
///
/// m=audio 60000 RTP/AVP 0
/// a=rtpmap:0 PCMU/8000
///
/// This example identifies that the client can receive audio on port 60000 in format 0 which
/// corresponds to PCMU/8000.
/// </summary>
public class MediaField : Field
{
private string mediaType;
/// <summary>
/// Gets the primary MIME type. See <see cref="MediaTypes"/>
/// </summary>
public string MediaType
{
get { return this.mediaType; }
}
private PortRange mediaPort;
/// <summary>
/// Gets the port range this media uses.
/// </summary>
public PortRange MediaPort
{
get { return this.mediaPort; }
}
private string protocol;
/// <summary>
/// Gets the network transport protocol for this media. Preliminarily defined
/// protocols are "RTP/AVP" and "udp".
/// </summary>
public string Protocol
{
get { return this.protocol; }
}
private List<string> mediaFormats;
/// <summary>
/// Gets a list of media formats. From RFC 2327:
///
/// The fourth and subsequent sub-fields are media formats. For audio
/// and video, these will normally be a media payload type as defined
/// in the RTP Audio/Video Profile.
///
/// When a list of payload formats is given, this implies that all of
/// these formats may be used in the session, but the first of these
/// formats is the default format for the session.
///
/// For media whose transport protocol is not RTP or UDP the format
/// field is protocol specific. Such formats should be defined in an
/// additional specification document.
/// </summary>
public List<string> MediaFormats
{
get { return this.mediaFormats; }
}
/// <summary>
/// Creates a new MediaField.
/// </summary>
/// <param name="value">The value portion of the field.</param>
public MediaField(string value)
: base("m=" + value)
{
string val = base.value;
string[] parts = val.Split(' ');
this.mediaType = parts[0];
string[] port = parts[1].Split('/');
if (port.Length > 1)
this.mediaPort = new PortRange(ushort.Parse(port[0]), ushort.Parse(port[1]));
else this.mediaPort = new PortRange(ushort.Parse(port[0]));
this.protocol = parts[2];
parts.CopyTo(parts, 3);
this.mediaFormats = new List<string>(parts);
}
/// <summary>
/// Creates a new MediaField.
/// </summary>
/// <param name="mediaType">The type of media.</param>
/// <param name="protocol">The transport protocol.</param>
/// <param name="ports">The port range this media operates on.</param>
/// <param name="formats">The formats this media will use.</param>
public MediaField(string mediaType, string protocol, PortRange ports, params string[] formats)
: this(helpConsolidate(mediaType, protocol, ports, formats)) { }
private static string helpConsolidate(string mediaType, string protocol, PortRange ports, string[] formats)
{
string s = mediaType + " " + ports.ToString() + " " + protocol;
foreach (string ss in formats)
s = s + " " + ss;
return s;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -