home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
MediaPortal 1
Development
General Development (no feature request here!)
MERGING MediaPortal Url Source Splitter & IPTV Filter
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="KayDiefenthal" data-source="post: 1067331" data-attributes="member: 22825"><p>mm1352000 i use this for receiving of RtpData</p><p>Initialize the RtpSession(localaddress, localPort) in RtspSetup Response</p><p>and Invoke Connect in RtspPlay</p><p></p><p>[CODE]public class RtpSession</p><p> {</p><p> </p><p> </p><p> private Thread _listenerThread;</p><p> </p><p> private EndPoint _endPoint;</p><p> private MemoryStream _stream;</p><p></p><p> public MemoryStream Stream</p><p> {</p><p> get { return _stream; }</p><p> set { _stream = value; }</p><p> }</p><p></p><p> private bool _listening;</p><p> private Socket _socket;</p><p> private int _rcvd;</p><p></p><p> /// <summary></p><p> /// Initialize a new Instance of<see cref="RtpSession"/> Class.</p><p> /// </summary></p><p> public RtpSession(string address,int port )</p><p> {</p><p> _stream = new MemoryStream();</p><p> Connect(address, port);</p><p> }</p><p></p><p> private void Connect(string address,int port )</p><p> {</p><p> var rtpEndPoint = new IPEndPoint(IPAddress.Parse(address), port);</p><p> var endPoint = (EndPoint)rtpEndPoint;</p><p> _socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);</p><p> _socket.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.ReuseAddress, 1);</p><p> _socket.Bind(endPoint);</p><p></p><p> var sender = new IPEndPoint(IPAddress.Parse(address), port);</p><p> _endPoint = (EndPoint)sender;</p><p></p><p></p><p> _listenerThread = new Thread(ReceiveCallback);</p><p> _listenerThread.Start();</p><p></p><p> }</p><p></p><p> private void ReceiveCallback()</p><p> {</p><p> _listening = true;</p><p></p><p> while (_listening)</p><p> {</p><p> // Receive RTP packet</p><p> byte[] packet = new byte[1370];</p><p></p><p></p><p> _rcvd = _socket.ReceiveFrom( packet ,ref _endPoint);</p><p></p><p> // Decode the header of the packet.</p><p> // Each piece of information has a start bit and an end bit.</p><p> // The GetRTPHeaderValue takes the packet, the start bit index and the</p><p> // end bit index and determines what the header value is. The header values</p><p> // are all in Big Endian, which makes things more complicated.</p><p> int version = GetRTPHeaderValue(packet, 0, 1);</p><p> int padding = GetRTPHeaderValue(packet, 2, 2);</p><p> int extension = GetRTPHeaderValue(packet, 3, 3);</p><p> int csrcCount = GetRTPHeaderValue(packet, 4, 7);</p><p> int marker = GetRTPHeaderValue(packet, 8, 8);</p><p> int payloadType = GetRTPHeaderValue(packet, 9, 15);</p><p> int sequenceNum = GetRTPHeaderValue(packet, 16, 31);</p><p> int timestamp = GetRTPHeaderValue(packet, 32, 63);</p><p> int ssrcId = GetRTPHeaderValue(packet, 64, 95);</p><p> int csrcid = GetRTPHeaderValue(packet, 96,96);</p><p> StringBuilder sb = new StringBuilder();</p><p> sb.Append(string.Format(" RtpPacket V:{0}, P:{1}, EX:{2}, CSRC:{3}, M:{4}, PT:{5}, SQ:{6}, TS:{7}, SSRC:{8}, CSRC:{9} \r\n", version, padding, extension, csrcCount, marker, payloadType, sequenceNum, timestamp, ssrcId,csrcid));</p><p> Debug.Write(sb.ToString());</p><p></p><p>//the packet payload starts at Offset 12 and the Payload lenght is packet.lenght without headersize</p><p> _stream.Write(packet, 12, packet.Length - 12);</p><p> </p><p> }</p><p> }</p><p> private int GetRTPHeaderValue(byte[] packet, int startBit, int endBit)</p><p> {</p><p> int result = 0;</p><p></p><p> // Number of bits in value</p><p> int length = endBit - startBit + 1;</p><p></p><p> // Values in RTP header are big endian, so need to do these conversions</p><p> for (int i = startBit; i <= endBit; i++)</p><p> {</p><p> int byteIndex = i / 8;</p><p> int bitShift = 7 - (i % 8);</p><p> result += ((packet[byteIndex] >> bitShift) & 1) * (int)Math.Pow(2, length - i + startBit - 1);</p><p> }</p><p> return result;</p><p> }</p><p></p><p> public void StopClient()</p><p> {</p><p> // Tell listener thread that we are done listening.</p><p> _listening = false;</p><p> }</p><p></p><p> }[/CODE]</p></blockquote><p></p>
[QUOTE="KayDiefenthal, post: 1067331, member: 22825"] mm1352000 i use this for receiving of RtpData Initialize the RtpSession(localaddress, localPort) in RtspSetup Response and Invoke Connect in RtspPlay [CODE]public class RtpSession { private Thread _listenerThread; private EndPoint _endPoint; private MemoryStream _stream; public MemoryStream Stream { get { return _stream; } set { _stream = value; } } private bool _listening; private Socket _socket; private int _rcvd; /// <summary> /// Initialize a new Instance of<see cref="RtpSession"/> Class. /// </summary> public RtpSession(string address,int port ) { _stream = new MemoryStream(); Connect(address, port); } private void Connect(string address,int port ) { var rtpEndPoint = new IPEndPoint(IPAddress.Parse(address), port); var endPoint = (EndPoint)rtpEndPoint; _socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); _socket.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.ReuseAddress, 1); _socket.Bind(endPoint); var sender = new IPEndPoint(IPAddress.Parse(address), port); _endPoint = (EndPoint)sender; _listenerThread = new Thread(ReceiveCallback); _listenerThread.Start(); } private void ReceiveCallback() { _listening = true; while (_listening) { // Receive RTP packet byte[] packet = new byte[1370]; _rcvd = _socket.ReceiveFrom( packet ,ref _endPoint); // Decode the header of the packet. // Each piece of information has a start bit and an end bit. // The GetRTPHeaderValue takes the packet, the start bit index and the // end bit index and determines what the header value is. The header values // are all in Big Endian, which makes things more complicated. int version = GetRTPHeaderValue(packet, 0, 1); int padding = GetRTPHeaderValue(packet, 2, 2); int extension = GetRTPHeaderValue(packet, 3, 3); int csrcCount = GetRTPHeaderValue(packet, 4, 7); int marker = GetRTPHeaderValue(packet, 8, 8); int payloadType = GetRTPHeaderValue(packet, 9, 15); int sequenceNum = GetRTPHeaderValue(packet, 16, 31); int timestamp = GetRTPHeaderValue(packet, 32, 63); int ssrcId = GetRTPHeaderValue(packet, 64, 95); int csrcid = GetRTPHeaderValue(packet, 96,96); StringBuilder sb = new StringBuilder(); sb.Append(string.Format(" RtpPacket V:{0}, P:{1}, EX:{2}, CSRC:{3}, M:{4}, PT:{5}, SQ:{6}, TS:{7}, SSRC:{8}, CSRC:{9} \r\n", version, padding, extension, csrcCount, marker, payloadType, sequenceNum, timestamp, ssrcId,csrcid)); Debug.Write(sb.ToString()); //the packet payload starts at Offset 12 and the Payload lenght is packet.lenght without headersize _stream.Write(packet, 12, packet.Length - 12); } } private int GetRTPHeaderValue(byte[] packet, int startBit, int endBit) { int result = 0; // Number of bits in value int length = endBit - startBit + 1; // Values in RTP header are big endian, so need to do these conversions for (int i = startBit; i <= endBit; i++) { int byteIndex = i / 8; int bitShift = 7 - (i % 8); result += ((packet[byteIndex] >> bitShift) & 1) * (int)Math.Pow(2, length - i + startBit - 1); } return result; } public void StopClient() { // Tell listener thread that we are done listening. _listening = false; } }[/CODE] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
MediaPortal 1
Development
General Development (no feature request here!)
MERGING MediaPortal Url Source Splitter & IPTV Filter
Contact us
RSS
Top
Bottom