Advertisement
Guest User

Untitled

a guest
May 24th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. class Header
  5. {
  6. public:
  7. uint8_t SB;
  8. bool E;
  9. bool S;
  10. bool T;
  11. uint16_t PID;
  12. uint8_t TSC;
  13. uint8_t AFC;
  14. uint8_t CC;
  15. };
  16. class Packet
  17. {
  18. public:
  19. Header header;
  20. void parse(uint8_t * buf)
  21. {
  22. header.SB = buf[0];
  23. header.E = buf[1] & 0b10000000;
  24. header.S = buf[1] & 0b01000000;
  25. header.T = buf[1] & 0b00100000;
  26. header.PID = (uint16_t(buf[1] & 0b00011111) << 8 ) | buf[2];
  27. header.TSC = buf[3] & 0b11000000 >> 6;
  28. header.AFC = buf[3] & 0b00110000 >> 4;
  29. header.CC = buf[3] & 0b00001111;
  30. };
  31.  
  32. void clear()
  33. {
  34. header.SB = 0;
  35. header.E = 0;
  36. header.S = 0;
  37. header.T = 0;
  38. header.PID = 0;
  39. header.TSC = 0;
  40. header.AFC = 0;
  41. header.CC = 0;
  42. };
  43.  
  44.  
  45. };
  46.  
  47. int main()
  48. {
  49. std::fstream file;
  50. uint8_t buf[188];
  51. uint8_t packet_P[4096];
  52. Packet packet;
  53.  
  54. file.open("D:\\Wiedza\\Multimedia\\Lab\\example.ts", std::ios::in | std::ios::binary);
  55. if (file.good())
  56. {
  57. while (!file.eof())
  58. {
  59. packet.clear();
  60. file.read((char *)buf, 188);
  61. packet.parse(buf);
  62. for (int k=0; k<19; k++)
  63. {
  64. int j=0;
  65. if((packet.header.AFC & 0b10) == 0)
  66. {
  67. for (int i=5+buf[4]; i<188; i++, j++)
  68. {
  69. packet_P[j]=buf[i];
  70. }
  71. }
  72. else
  73. {
  74. for (int i=4; i<188; i++, j++)
  75. {
  76. packet_P[j]=buf[i];
  77. }
  78. }
  79. }
  80. if(packet_P[0] == 0 and packet_P[1]==0 and packet_P[2]==1)
  81. {
  82. printf("%1d, %1d \n", packet_P[3], packet_P[4]);
  83. }
  84. }
  85. file.close();
  86. }
  87.  
  88. system("PAUSE");
  89. return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement