TableStream.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Diagnostics;
  6. using MatrixIO.IO.MpegTs.Tables;
  7. namespace MatrixIO.IO.MpegTs.Streams
  8. {
  9. public class TableStream : TsStream<TsTable>
  10. {
  11. protected override TsTable ProcessUnit(TsUnit unit)
  12. {
  13. // TODO: We should think about passing the unit payload in as an IList for speed. It complicates copying chunks of data, however.
  14. var unitPayload = new byte[unit.Payload.Count];
  15. unit.Payload.CopyTo(unitPayload, 0);
  16. var pointer = (int)unitPayload[0] + 1;
  17. var tid = (TableIdentifier)unitPayload[pointer];
  18. Debug.WriteLine("Received " + tid + " Table");
  19. switch (tid)
  20. {
  21. case TableIdentifier.ProgramAssociation:
  22. return new ProgramAssociationTable(unitPayload, pointer, unitPayload.Length - pointer);
  23. case TableIdentifier.ProgramMap:
  24. return new ProgramMapTable(unitPayload, pointer, unitPayload.Length - pointer);
  25. case TableIdentifier.Description:
  26. return new DescriptionTable(unitPayload, pointer, unitPayload.Length - pointer);
  27. default:
  28. Debug.WriteLine("Unsupported Table: " + tid);
  29. return null;
  30. }
  31. }
  32. }
  33. }