26 #if CONFIG_VOBSUB_DEMUXER
36 #define MAX_SYNC_SIZE 100000
41 int pes2 = (p[3] & 0xC0) == 0x80 &&
42 (p[4] & 0xC0) != 0x40 &&
43 ((p[4] & 0xC0) == 0x00 ||
44 (p[4] & 0xC0) >> 2 == (p[6] & 0xF0));
46 for (p += 3; p < end && *p == 0xFF; p++) ;
47 if ((*p & 0xC0) == 0x40)
50 if ((*p & 0xF0) == 0x20)
51 pes1 = p[0] & p[2] & p[4] & 1;
52 else if ((*p & 0xF0) == 0x30)
53 pes1 = p[0] & p[2] & p[4] & p[5] & p[7] & p[9] & 1;
62 return (buf[1] & 0xC0) == 0x40 || (buf[1] & 0xF0) == 0x20;
69 int sys = 0, pspack = 0, priv1 = 0, vid = 0;
70 int audio = 0, invalid = 0, score = 0;
74 code = (code << 8) + p->
buf[i];
75 if ((code & 0xffffff00) == 0x100) {
76 int len = p->
buf[i + 1] << 8 | p->
buf[i + 2];
84 else if ((code & 0xf0) ==
VIDEO_ID && pes) {
90 else if ((code & 0xe0) ==
AUDIO_ID && pes) {audio++; i+=
len;}
92 else if (code == 0x1fd && pes) vid++;
94 else if ((code & 0xf0) ==
VIDEO_ID && !pes) invalid++;
95 else if ((code & 0xe0) ==
AUDIO_ID && !pes) invalid++;
100 if (vid + audio > invalid + 1)
106 if (sys > invalid && sys * 9 <= pspack * 10)
109 if (pspack > invalid && (priv1 + vid + audio) * 10 >= pspack * 9)
112 if ((!!vid ^ !!audio) && (audio > 4 || vid > 1) && !sys &&
113 !pspack && p->
buf_size > 2048 && vid + audio > invalid)
129 #if CONFIG_VOBSUB_DEMUXER
145 if (!memcmp(
"IMKH", buffer, 4)) {
147 }
else if (!memcmp(
"Sofdec", buffer, 6)) {
172 state = *header_state;
179 if (state == 0x000001) {
180 state = ((state << 8) | v) & 0xffffff;
184 state = ((state << 8) | v) & 0xffffff;
189 *header_state =
state;
202 int psm_length, ps_info_length, es_map_length;
213 es_map_length = psm_length - ps_info_length - 10;
216 while (es_map_length >= 4) {
218 unsigned char es_id =
avio_r8(pb);
225 es_map_length -= 4 + es_info_length;
228 return 2 + psm_length;
235 int64_t *ppos,
int *pstart_code,
236 int64_t *ppts, int64_t *pdts)
240 int pes_ext, ext2_len, id_ext, skip;
277 if (bytesread != len) {
282 p = memchr(ps2buf,
'S', len - 5);
285 m->
sofdec = !memcmp(p+1,
"ofdec", 5);
290 if (len == 980 && ps2buf[0] == 0) {
292 uint32_t startpts =
AV_RB32(ps2buf + 0x0d);
293 uint32_t endpts =
AV_RB32(ps2buf + 0x11);
294 uint8_t hours = ((ps2buf[0x19] >> 4) * 10) + (ps2buf[0x19] & 0x0f);
295 uint8_t mins = ((ps2buf[0x1a] >> 4) * 10) + (ps2buf[0x1a] & 0x0f);
296 uint8_t secs = ((ps2buf[0x1b] >> 4) * 10) + (ps2buf[0x1b] & 0x0f);
298 m->
dvd = (hours <= 23 &&
301 (ps2buf[0x19] & 0x0f) < 10 &&
302 (ps2buf[0x1a] & 0x0f) < 10 &&
303 (ps2buf[0x1b] & 0x0f) < 10 &&
305 }
else if (len == 1018 && ps2buf[0] == 1) {
307 uint8_t hours = ((ps2buf[0x1d] >> 4) * 10) + (ps2buf[0x1d] & 0x0f);
308 uint8_t mins = ((ps2buf[0x1e] >> 4) * 10) + (ps2buf[0x1e] & 0x0f);
309 uint8_t secs = ((ps2buf[0x1f] >> 4) * 10) + (ps2buf[0x1f] & 0x0f);
311 m->
dvd = (hours <= 23 &&
314 (ps2buf[0x1d] & 0x0f) < 10 &&
315 (ps2buf[0x1e] & 0x0f) < 10 &&
316 (ps2buf[0x1f] & 0x0f) < 10);
339 }
else if (!m->
dvd) {
351 if (!((startcode >= 0x1c0 && startcode <= 0x1df) ||
352 (startcode >= 0x1e0 && startcode <= 0x1ef) ||
353 (startcode == 0x1bd) ||
355 (startcode == 0x1fd)))
375 if ((c & 0xc0) == 0x40) {
381 if ((c & 0xe0) == 0x20) {
389 }
else if ((c & 0xc0) == 0x80) {
394 if (header_len > len)
405 if (flags & 0x3f && header_len == 0) {
414 skip = (pes_ext >> 4) & 0xb;
416 if (pes_ext & 0x40 || skip > header_len) {
423 if (pes_ext & 0x01) {
426 if ((ext2_len & 0x7f) > 0) {
428 if ((id_ext & 0x80) == 0)
429 startcode = ((startcode & 0xff) << 8) | id_ext;
459 *pstart_code = startcode;
470 int len, startcode, i, es_type,
ret;
471 int lpcm_header_len = -1;
472 int request_probe= 0;
475 int64_t
pts, dts, dummy_pos;
482 if (startcode >= 0x80 && startcode <= 0xcf) {
490 if (startcode >= 0xb0 && startcode <= 0xbf) {
500 if (st->
id == startcode)
527 }
else if (m->
imkh_cctv && es_type == 0x91) {
530 }
else if (startcode >= 0x1e0 && startcode <= 0x1ef) {
531 static const unsigned char avs_seqh[4] = { 0, 0, 1, 0xb0 };
532 unsigned char buf[8];
536 if (!memcmp(buf, avs_seqh, 4) && (buf[6] != 0 || buf[7] != 1))
544 }
else if (startcode >= 0x1c0 && startcode <= 0x1df) {
553 }
else if (startcode >= 0x80 && startcode <= 0x87) {
556 }
else if ((startcode >= 0x88 && startcode <= 0x8f) ||
557 (startcode >= 0x98 && startcode <= 0x9f)) {
561 }
else if (startcode >= 0xa0 && startcode <= 0xaf) {
563 if (lpcm_header_len == 6) {
568 }
else if (startcode >= 0xb0 && startcode <= 0xbf) {
571 }
else if (startcode >= 0xc0 && startcode <= 0xcf) {
575 }
else if (startcode >= 0x20 && startcode <= 0x3f) {
578 }
else if (startcode >= 0xfd55 && startcode <= 0xfd5f) {
605 if (startcode >= 0xa0 && startcode <= 0xaf) {
617 pkt->
pos = dummy_pos;
619 av_dlog(s,
"%d: pts=%0.3f dts=%0.3f size=%d\n",
623 return (ret < 0) ? ret : 0;
627 int64_t *ppos, int64_t pos_limit)
630 int64_t pos,
pts, dts;
639 av_dlog(s,
"none (ret=%d)\n", len);
642 if (startcode == s->
streams[stream_index]->
id &&
648 av_dlog(s,
"pos=0x%"PRIx64
" dts=0x%"PRIx64
" %0.3f\n",
649 pos, dts, dts / 90000.0);
665 #if CONFIG_VOBSUB_DEMUXER
667 #define REF_STRING "# VobSub index file,"
668 #define MAX_LINE_SIZE 2048
672 if (!strncmp(p->
buf, REF_STRING,
sizeof(REF_STRING) - 1))
679 int i,
ret = 0, header_parsed = 0, langidx = 0;
681 char *sub_name =
NULL;
683 char *ext, *header_str;
693 fname_len = strlen(sub_name);
694 ext = sub_name - 3 + fname_len;
695 if (fname_len < 4 || *(ext - 1) !=
'.') {
697 "to guess the associated .SUB file\n");
701 memcpy(ext, !strncmp(ext,
"IDX", 3) ?
"SUB" :
"sub", 3);
710 if (!vobsub->sub_ctx) {
732 line[strcspn(line,
"\r\n")] = 0;
734 if (!strncmp(line,
"id:", 3)) {
735 if (sscanf(line,
"id: %63[^,], index: %u",
id, &stream_id) != 2) {
737 "assuming 'id: und, index: 0'\n", line);
755 }
else if (!strncmp(line,
"timestamp:", 10)) {
758 int64_t pos, timestamp;
759 const char *p = line + 10;
761 if (stream_id == -1) {
767 if (!st || st->
id != stream_id) {
782 if (sscanf(p,
"%02d:%02d:%02d:%03d, filepos: %"SCNx64,
783 &hh, &mm, &ss, &ms, &pos) != 5) {
785 "abort parsing\n", line);
789 timestamp = (hh*3600LL + mm*60LL + ss) * 1000LL + ms + delay;
798 sub->
pts = timestamp;
801 }
else if (!strncmp(line,
"alt:", 4)) {
802 const char *p = line + 4;
810 }
else if (!strncmp(line,
"delay:", 6)) {
811 int sign = 1, hh = 0, mm = 0, ss = 0, ms = 0;
812 const char *p = line + 6;
816 if (*p ==
'-' || *p ==
'+') {
817 sign = *p ==
'-' ? -1 : 1;
820 sscanf(p,
"%d:%d:%d:%d", &hh, &mm, &ss, &ms);
821 delay = ((hh*3600LL + mm*60LL + ss) * 1000LL + ms) * sign;
823 }
else if (!strncmp(line,
"langidx:", 8)) {
824 const char *p = line + 8;
826 if (sscanf(p,
"%d", &langidx) != 1)
829 }
else if (!header_parsed) {
830 if (line[0] && line[0] !=
'#')
866 int ret, psize, total_read = 0, i;
869 int64_t min_ts = INT64_MAX;
892 psize = fsize < 0 ? 0xffff : fsize - idx_pkt.
pos;
902 int n, to_read, startcode;
904 int64_t old_pos =
avio_tell(pb), new_pos;
913 to_read = ret & 0xffff;
915 pkt_size = ret + (new_pos - old_pos);
918 if (total_read + pkt_size > psize)
920 total_read += pkt_size;
932 pkt->
size -= to_read -
n;
933 }
while (total_read < psize);
949 int64_t min_ts, int64_t ts, int64_t max_ts,
int flags)
956 if (stream_index == -1 && s->
nb_streams != 1) {
964 time_base.
num * (int64_t)AV_TIME_BASE,
968 min_ts, ts, max_ts, flags);
975 if (stream_index == -1)
978 min_ts, ts, max_ts, flags);
1000 .read_seek2 = vobsub_read_seek,
1003 .extensions =
"idx",