32 #define MAX_SYNC_SIZE 100000
36 int pes2= (p[3] & 0xC0) == 0x80
37 && (p[4] & 0xC0) != 0x40
38 &&((p[4] & 0xC0) == 0x00 || (p[4]&0xC0)>>2 == (p[6]&0xF0));
40 for(p+=3; p<end && *p == 0xFF; p++);
41 if((*p&0xC0) == 0x40) p+=2;
42 if((*p&0xF0) == 0x20){
43 pes1= p[0]&p[2]&p[4]&1;
44 }
else if((*p&0xF0) == 0x30){
45 pes1= p[0]&p[2]&p[4]&p[5]&p[7]&p[9]&1;
53 return (buf[1] & 0xC0) == 0x40 || (buf[1] & 0xF0) == 0x20;
59 int sys=0, pspack=0, priv1=0, vid=0, audio=0, invalid=0;
64 code = (code<<8) + p->
buf[i];
65 if ((code & 0xffffff00) == 0x100) {
72 else if((code & 0xf0) ==
VIDEO_ID && pes) vid++;
75 else if((code & 0xe0) ==
AUDIO_ID && pes) {audio++; i+=
len;}
78 else if((code & 0xf0) ==
VIDEO_ID && !pes) invalid++;
79 else if((code & 0xe0) ==
AUDIO_ID && !pes) invalid++;
84 if(vid+audio > invalid)
88 if(sys>invalid && sys*9 <= pspack*10)
90 if(pspack > invalid && (priv1+vid+audio)*10 >= pspack*9)
92 if((!!vid ^ !!audio) && (audio > 4 || vid > 1) && !sys && !pspack && p->
buf_size>2048 && vid + audio > invalid)
111 const char *sofdec =
"Sofdec";
122 }
while (v == sofdec[i] && i++ < 6);
134 buf[0] = c<0 ?
avio_r8(pb) : c;
141 int32_t *header_state)
146 state = *header_state;
153 if (state == 0x000001) {
154 state = ((state << 8) | v) & 0xffffff;
158 state = ((state << 8) | v) & 0xffffff;
162 *header_state =
state;
169 static int find_prev_start_code(
AVIOContext *pb,
int *size_ptr)
171 int64_t pos, pos_start;
172 int max_size, start_code;
174 max_size = *size_ptr;
178 pos = pos_start - 16386;
187 if (pos < 0 || (pos_start - pos) >= max_size) {
193 if ((start_code & 0xffffff00) == 0x100)
197 *size_ptr = pos_start - pos;
210 int psm_length, ps_info_length, es_map_length;
222 while (es_map_length >= 4){
223 unsigned char type =
avio_r8(pb);
224 unsigned char es_id =
avio_r8(pb);
230 es_map_length -= 4 + es_info_length;
233 return 2 + psm_length;
240 int64_t *ppos,
int *pstart_code,
241 int64_t *ppts, int64_t *pdts)
245 int pes_ext, ext2_len, id_ext, skip;
280 m->
sofdec = !memcmp(buf,
"ofdec", 5);
296 if (!((startcode >= 0x1c0 && startcode <= 0x1df) ||
297 (startcode >= 0x1e0 && startcode <= 0x1ef) ||
298 (startcode == 0x1bd) || (startcode == 0x1fd)))
316 if ((c & 0xc0) == 0x40) {
322 if ((c & 0xe0) == 0x20) {
329 }
else if ((c & 0xc0) == 0x80) {
332 if ((c & 0x30) != 0) {
340 if (header_len > len)
351 if (flags & 0x3f && header_len == 0){
359 skip = (pes_ext >> 4) & 0xb;
361 if (pes_ext & 0x40 || skip > header_len){
368 if (pes_ext & 0x01) {
371 if ((ext2_len & 0x7f) > 0) {
373 if ((id_ext & 0x80) == 0)
374 startcode = ((startcode & 0xff) << 8) | id_ext;
389 if (startcode >= 0x80 && startcode <= 0xcf) {
395 if (startcode >= 0xb0 && startcode <= 0xbf) {
415 *pstart_code = startcode;
426 int len, startcode, i, es_type, ret;
429 int64_t pts, dts, dummy_pos;
430 uint8_t
av_uninit(dvdaudio_substream_type);
437 if(startcode == 0x1bd) {
438 dvdaudio_substream_type =
avio_r8(s->
pb);
446 if (st->
id == startcode)
477 }
else if (startcode >= 0x1e0 && startcode <= 0x1ef) {
478 static const unsigned char avs_seqh[4] = { 0, 0, 1, 0xb0 };
479 unsigned char buf[8];
482 if(!memcmp(buf, avs_seqh, 4) && (buf[6] != 0 || buf[7] != 1))
487 }
else if (startcode >= 0x1c0 && startcode <= 0x1df) {
490 }
else if (startcode >= 0x80 && startcode <= 0x87) {
493 }
else if ( ( startcode >= 0x88 && startcode <= 0x8f)
494 ||( startcode >= 0x98 && startcode <= 0x9f)) {
498 }
else if (startcode >= 0xa0 && startcode <= 0xaf) {
502 }
else if (startcode >= 0xb0 && startcode <= 0xbf) {
505 }
else if (startcode >= 0xc0 && startcode <= 0xcf) {
509 }
else if (startcode >= 0x20 && startcode <= 0x3f) {
512 }
else if (startcode >= 0xfd55 && startcode <= 0xfd5f) {
515 }
else if (startcode == 0x1bd) {
518 switch(dvdaudio_substream_type & 0xe0) {
521 case 0x80:
if((dvdaudio_substream_type & 0xf8) == 0x88)
546 if ((startcode >= 0xa0 && startcode <= 0xaf) ||
547 (startcode == 0x1bd && ((dvdaudio_substream_type & 0xe0) == 0xa0))) {
558 freq = (b1 >> 4) & 3;
573 pkt->
pos = dummy_pos;
575 av_dlog(s,
"%d: pts=%0.3f dts=%0.3f size=%d\n",
579 return (ret < 0) ? ret : 0;
583 int64_t *ppos, int64_t pos_limit)
586 int64_t pos, pts, dts;
595 av_dlog(s,
"none (ret=%d)\n", len);
598 if (startcode == s->
streams[stream_index]->
id &&
604 av_dlog(s,
"pos=0x%"PRIx64
" dts=0x%"PRIx64
" %0.3f\n",
605 pos, dts, dts / 90000.0);