AdaptationFieldExtension.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Text;
  6. namespace MatrixIO.IO.MpegTs
  7. {
  8. public class AdaptationFieldExtension
  9. {
  10. public byte Length { get; private set; }
  11. private byte _flags;
  12. public bool HasLegalTimeWindow
  13. {
  14. get { return (_flags & 0x80) > 0; }
  15. set { if (value) _flags |= 0x80; else _flags &= 0x7F; }
  16. }
  17. public bool HasPiecewiseRate
  18. {
  19. get { return (_flags & 0x40) > 0; }
  20. set { if (value) _flags |= 0x40; else _flags &= 0xBF; }
  21. }
  22. public bool HasSeamlessSplice
  23. {
  24. get { return (_flags & 0x20) > 0; }
  25. set { if (value) _flags |= 0x20; else _flags &= 0xDF; }
  26. }
  27. public byte[] Stuffing { get; set; }
  28. public AdaptationFieldExtension() { }
  29. public AdaptationFieldExtension(byte[] buffer, int offset = 0)
  30. {
  31. int position = offset;
  32. int length = Length = buffer[position++];
  33. if (length > 0)
  34. {
  35. _flags = buffer[position++];
  36. if(HasLegalTimeWindow)
  37. {
  38. Debug.WriteLine("Has Legal Time Window");
  39. // TODO: Support Legal Time Window
  40. offset += 2;
  41. }
  42. if(HasPiecewiseRate)
  43. {
  44. Debug.WriteLine("Has Piecewise Rate");
  45. // TODO: Support Piecewise Rate
  46. offset += 3;
  47. }
  48. if(HasSeamlessSplice)
  49. {
  50. Debug.WriteLine("Has Seamless Splice");
  51. // TODO: Support Piecewise Splice
  52. offset += 5;
  53. }
  54. int stuffingLength = length + 1 - (position - offset);
  55. if (stuffingLength > 0)
  56. {
  57. Debug.WriteLine("Has " + stuffingLength + " bytes of Adaptation Field Extension Stuffing.");
  58. Stuffing = new byte[stuffingLength];
  59. Buffer.BlockCopy(buffer, position, Stuffing, 0, stuffingLength);
  60. }
  61. }
  62. }
  63. }
  64. }