123 lines
3.1 KiB
C#
123 lines
3.1 KiB
C#
using skyscraper8.Ietf.Rfc3550_RTP;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace skyscraper8.SatIp
|
|
{
|
|
internal class SessionDescriptionProtocol
|
|
{
|
|
public SessionDescriptionProtocol(StreamReader sr)
|
|
{
|
|
while (!sr.EndOfStream)
|
|
{
|
|
string line = sr.ReadLine();
|
|
int indexOf = line.IndexOf('=');
|
|
string key = line.Substring(0, indexOf);
|
|
string value = line.Substring(indexOf + 1);
|
|
switch (key)
|
|
{
|
|
case "v":
|
|
SdpVersion = int.Parse(value);
|
|
break;
|
|
case "o":
|
|
string[] oArgs = value.Split(' ');
|
|
Username = oArgs[0];
|
|
SessionId = ulong.Parse(oArgs[1]);
|
|
SessionVersion = uint.Parse(oArgs[2]);
|
|
OwnerNetworkType = Enum.Parse<OwnerNetworkTypeEnum>(oArgs[3]);
|
|
OwnerAddressType = Enum.Parse<OwnerAddressTypeEnum>(oArgs[4]);
|
|
OwnerAddress = IPAddress.Parse(oArgs[5]);
|
|
break;
|
|
case "s":
|
|
SessionName = value;
|
|
break;
|
|
case "t":
|
|
string[] tArgs = value.Split(' ');
|
|
SessionStartTime = uint.Parse(tArgs[0]);
|
|
SessionStopType = uint.Parse(tArgs[1]);
|
|
break;
|
|
case "m":
|
|
string[] mArgs = value.Split(' ');
|
|
MediaType = Enum.Parse<MediaTypeEnum>(mArgs[0], true);
|
|
MediaPort = uint.Parse(mArgs[1]);
|
|
MediaProtocol = mArgs[2];
|
|
MediaFormat = (MediaFormatEnum)int.Parse(mArgs[3]);
|
|
break;
|
|
case "c":
|
|
string[] cArgs = value.Split(' ');
|
|
ConnectionNetworkType = Enum.Parse<OwnerNetworkTypeEnum>(cArgs[0]);
|
|
ConnectionAddressType = Enum.Parse<OwnerAddressTypeEnum>(cArgs[1]);
|
|
ConnectionAddress = IPAddress.Parse(cArgs[2]);
|
|
break;
|
|
case "a":
|
|
int aIndex = value.IndexOf(':');
|
|
string aKey = value.Substring(0, aIndex);
|
|
string aValue = value.Substring(aIndex + 1);
|
|
if (MediaAttribute == null)
|
|
MediaAttribute = new Dictionary<string, string>();
|
|
MediaAttribute[aKey] = aValue;
|
|
break;
|
|
default:
|
|
throw new NotImplementedException(key);
|
|
}
|
|
}
|
|
}
|
|
|
|
public Dictionary<string, string> MediaAttribute { get; set; }
|
|
|
|
public IPAddress ConnectionAddress { get; set; }
|
|
|
|
public OwnerAddressTypeEnum ConnectionAddressType { get; set; }
|
|
|
|
public OwnerNetworkTypeEnum ConnectionNetworkType { get; set; }
|
|
|
|
public MediaFormatEnum MediaFormat { get; set; }
|
|
|
|
public string MediaProtocol { get; set; }
|
|
|
|
public uint MediaPort { get; set; }
|
|
|
|
public MediaTypeEnum MediaType { get; set; }
|
|
|
|
public uint SessionStopType { get; set; }
|
|
|
|
public uint SessionStartTime { get; set; }
|
|
|
|
public string SessionName { get; set; }
|
|
|
|
public IPAddress OwnerAddress { get; set; }
|
|
|
|
public OwnerAddressTypeEnum OwnerAddressType { get; set; }
|
|
|
|
public OwnerNetworkTypeEnum OwnerNetworkType { get; set; }
|
|
|
|
public uint SessionVersion { get; set; }
|
|
|
|
public ulong SessionId { get; set; }
|
|
|
|
public string Username { get; set; }
|
|
|
|
public int SdpVersion { get; private set; }
|
|
}
|
|
|
|
public enum OwnerNetworkTypeEnum
|
|
{
|
|
IN
|
|
}
|
|
|
|
public enum OwnerAddressTypeEnum
|
|
{
|
|
IP4
|
|
}
|
|
|
|
public enum MediaTypeEnum
|
|
{
|
|
Video,
|
|
}
|
|
|
|
}
|