--- demux_ts_old.c 2003-04-13 01:01:14.000000000 +0200 +++ demux_ts.c 2003-04-13 01:04:30.000000000 +0200 @@ -54,7 +54,7 @@ #define MAX_HEADER_SIZE 6 /* enough for PES header + length */ #define MAX_PROBE_SIZE 1000000 -#define NUM_CONSECUTIVE_TS_PACKETS 5 +#define NUM_CONSECUTIVE_TS_PACKETS 32 int ts_fastparse = 0; @@ -123,29 +123,29 @@ } - int ts_check_file(demuxer_t * demuxer) { const int buf_size = (TS_FEC_PACKET_SIZE * NUM_CONSECUTIVE_TS_PACKETS); - char buf[buf_size], c, done = 0; - uint32_t _read, i=1; + unsigned char buf[buf_size], c, done = 0, *ptr; + uint32_t _read, i=1, count = 0; + int cc[NB_PID_MAX], last_cc[NB_PID_MAX], pid, cc_ok; uint8_t size = 0; off_t pos = 0; - + mp_msg(MSGT_DEMUX, MSGL_V, "************Checking for TS************\n"); while(! done) { while(((c=stream_read_char(demuxer->stream)) != 0x47) - && (i < MAX_PROBE_SIZE) - && ! demuxer->stream->eof + && (i < MAX_PROBE_SIZE) + && ! demuxer->stream->eof ) i++; if(c != 0x47) { - mp_msg(MSGT_DEMUX, MSGL_V, "NOT A TS FILE1\n"); - done = 1; - continue; + mp_msg(MSGT_DEMUX, MSGL_V, "NOT A TS FILE1\n"); + done = 1; + continue; } pos = stream_tell(demuxer->stream) - 1; @@ -154,19 +154,48 @@ if(_read < buf_size-1) { - mp_msg(MSGT_DEMUX, MSGL_V, "COULDN'T READ ENOUGH DATA, EXITING TS_CHECK\n"); - stream_reset(demuxer->stream); - return 0; + mp_msg(MSGT_DEMUX, MSGL_V, "COULDN'T READ ENOUGH DATA, EXITING TS_CHECK\n"); + stream_reset(demuxer->stream); + return 0; } size = get_packet_size(buf, buf_size); if(size) - done = 1; + done = 1; } - mp_msg(MSGT_DEMUX, MSGL_V, "TRIED UP TO POSITION %u, FUOND %x, packet_size= %d\n", i, c, size); + mp_msg(MSGT_DEMUX, MSGL_V, "TRIED UP TO POSITION %u, FOUND %x, packet_size= %d\n", i, c, size); stream_seek(demuxer->stream, pos); - return size; + + //return size; + + for(count = 0; count < NB_PID_MAX; count++) + { + cc[count] = last_cc[count] = -1; + } + + done = 0; + for(count = 0; count < NUM_CONSECUTIVE_TS_PACKETS; count++) + { + ptr = &(buf[size * count]); + pid = ((ptr[1] & 0x1f) << 8) | ptr[2]; + mp_msg(MSGT_DEMUX, MSGL_V, "BUF: %02x %02x %02x %02x, PID %d, SIZE: %d \n", + ptr[0], ptr[1], ptr[2], ptr[3], pid, size); + + if(pid == 8191) + continue; + + cc[pid] = (ptr[3] & 0xf); + cc_ok = (last_cc[pid] < 0) || ((((last_cc[pid] + 1) & 0x0f) == cc[pid])); + mp_msg(MSGT_DEMUX, MSGL_V, "PID %d, COMPARE CC %d AND LAST_CC %d\n", pid, cc[pid], last_cc[pid]); + if(! cc_ok) + return 0; + + last_cc[pid] = cc[pid]; + done++; + } + + return size; }