int main(int argc, char *argv[])
{
	int fd, bytes_read;
	uint8_t packet_buffer[TS_PACKET_SIZE];
	int n_packets = 0;
	
	TSParser tsParser;
	memset(&tsParser, 0, sizeof(TSParser));
	
	fd = openStream(argv[1]);
	if(fd<0)
	{
		printf("Error opening the stream\nSyntax: tsunpacket FileToParse.ts\n");
		return -1;
	}
	
	while(1)
	{
		bytes_read = readData(fd, packet_buffer, TS_PACKET_SIZE);
			
		if(packet_buffer[0] == TS_DISCONTINUITY)
		{
			printf("Discontinuity detected!\n");
			signalDiscontinuity(&tsParser, 0);
		}
		else if(bytes_read < TS_PACKET_SIZE)
		{
			printf("End of file!\n");
			break;
		}
		else if(packet_buffer[0] == TS_SYNC)
		{
			ABitReader bitReader;
			initABitReader(&bitReader, packet_buffer, bytes_read);
			
			parseTSPacket(&tsParser, &bitReader);			
			
			n_packets++;
		}
		
		
	}
	
	printf("Number of packets: %d\n", n_packets);
	printf("Finishing application\n");
	close(fd);
	
	freeParserResources(&tsParser);
	
	return 0;
}
示例#2
0
ESExtractor::ESExtractor(const sp<DataSource> &source)
    : mDataSource(source),
      mOffset(0),
      mFinalResult(OK),
      mBuffer(new ABuffer(0)),
      mScanning(true),
      mSeeking(false),
      mFileSize(0),
      mhasVTrack(false),
      mhasATrack(false),
      mNeedDequeuePES(true),
	  bisPlayable(true) {
      init();
      signalDiscontinuity(true);
      //Init Offset
      mOffset = 0;
      mScanning = false;
}