TsRtpSource.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace TsViewer
  6. {
  7. public class TsRtpSource : TsUdpSource
  8. {
  9. internal override void ProcessPacket(UdpPacket packet)
  10. {
  11. base.ProcessPacket(packet);
  12. }
  13. private class RtpPacket
  14. {
  15. private byte header1; // TODO: Set default version here.
  16. // 2 bit version
  17. // 1 bit Padding Indicator -- indicated here by null padding
  18. // 1 bit Extension Indicator -- indicated here by null extension
  19. // 4 bit CSRC identifier Count -- indicated here by ContributingSources array length
  20. private byte header2 = 0x80; // Marker should always be 1
  21. // 1 bit Marker
  22. // 7 bit Payload Type
  23. private byte PayloadType { get; set; }
  24. // 16 bit Sequence Number
  25. public ushort SequenceNumber { get; set; }
  26. // 32 bit Timestamp
  27. public uint TimeStamp { get; set; }
  28. // 32 bit Synchronization Source RC Identifier
  29. public uint SynchronizationSource { get; set; }
  30. // 32 bit Contributing Source RC identifier -- 0 or more per identifier count above
  31. public IList<uint> ContributingSources { get; private set; }
  32. // Optional Extension with 16 bit profile-specific identifier and 16 bit length.
  33. public RtpExtension Extension { get; set; }
  34. public byte[] Payload { get; set; }
  35. public byte[] Padding { get; set; }
  36. public RtpPacket()
  37. {
  38. ContributingSources = new List<uint>();
  39. }
  40. public RtpPacket(byte[] buffer, int offset) : this()
  41. {
  42. int position = offset;
  43. header1 = buffer[offset++];
  44. header2 = buffer[offset++];
  45. SequenceNumber = (ushort)(buffer[offset++] << 8 & buffer[offset++]);
  46. SynchronizationSource = (uint)(buffer[offset++] << 24 & buffer[offset++] << 16 & buffer[offset++] << 8 & buffer[offset++]);
  47. // TODO: Load Optional Contributing Sources
  48. // TODO: Load Optional Extension
  49. // TODO: Load Payload
  50. // TODO: Load Optional Padding
  51. }
  52. }
  53. private class RtpExtension
  54. {
  55. public uint Identifier { get; set; }
  56. public byte[] Data;
  57. }
  58. }
  59. }