Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- class Header
- {
- public:
- uint8_t SB;
- bool E;
- bool S;
- bool T;
- uint16_t PID;
- uint8_t TSC;
- uint8_t AFC;
- uint8_t CC;
- };
- class Packet
- {
- public:
- Header header;
- void parse(uint8_t * buf)
- {
- header.SB = buf[0];
- header.E = buf[1] & 0b10000000;
- header.S = buf[1] & 0b01000000;
- header.T = buf[1] & 0b00100000;
- header.PID = (uint16_t(buf[1] & 0b00011111) << 8 ) | buf[2];
- header.TSC = buf[3] & 0b11000000 >> 6;
- header.AFC = buf[3] & 0b00110000 >> 4;
- header.CC = buf[3] & 0b00001111;
- };
- void clear()
- {
- header.SB = 0;
- header.E = 0;
- header.S = 0;
- header.T = 0;
- header.PID = 0;
- header.TSC = 0;
- header.AFC = 0;
- header.CC = 0;
- };
- };
- int main()
- {
- std::fstream file;
- uint8_t buf[188];
- uint8_t packet_P[4096];
- Packet packet;
- file.open("D:\\Wiedza\\Multimedia\\Lab\\example.ts", std::ios::in | std::ios::binary);
- if (file.good())
- {
- while (!file.eof())
- {
- packet.clear();
- file.read((char *)buf, 188);
- packet.parse(buf);
- for (int k=0; k<19; k++)
- {
- int j=0;
- if((packet.header.AFC & 0b10) == 0)
- {
- for (int i=5+buf[4]; i<188; i++, j++)
- {
- packet_P[j]=buf[i];
- }
- }
- else
- {
- for (int i=4; i<188; i++, j++)
- {
- packet_P[j]=buf[i];
- }
- }
- }
- if(packet_P[0] == 0 and packet_P[1]==0 and packet_P[2]==1)
- {
- printf("%1d, %1d \n", packet_P[3], packet_P[4]);
- }
- }
- file.close();
- }
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement