26 #if CONFIG_VOBSUB_DEMUXER
38 #define MAX_SYNC_SIZE 100000
43 int pes2 = (p[3] & 0xC0) == 0x80 &&
44 (p[4] & 0xC0) != 0x40 &&
45 ((p[4] & 0xC0) == 0x00 ||
46 (p[4] & 0xC0) >> 2 == (p[6] & 0xF0));
48 for (p += 3; p < end && *p == 0xFF; p++) ;
49 if ((*p & 0xC0) == 0x40)
52 if ((*p & 0xF0) == 0x20)
53 pes1 = p[0] & p[2] & p[4] & 1;
54 else if ((*p & 0xF0) == 0x30)
55 pes1 = p[0] & p[2] & p[4] & p[5] & p[7] & p[9] & 1;
64 return (buf[1] & 0xC0) == 0x40 || (buf[1] & 0xF0) == 0x20;
71 int sys = 0, pspack = 0, priv1 = 0, vid = 0;
72 int audio = 0, invalid = 0, score = 0;
75 code = (code << 8) + p->
buf[i];
76 if ((code & 0xffffff00) == 0x100) {
77 int len = p->
buf[i + 1] << 8 | p->
buf[i + 2];
85 else if ((code & 0xf0) ==
VIDEO_ID && pes)
89 else if ((code & 0xe0) ==
AUDIO_ID && pes) {audio++; i+=
len;}
91 else if (code == 0x1fd && pes) vid++;
93 else if ((code & 0xf0) ==
VIDEO_ID && !pes) invalid++;
94 else if ((code & 0xe0) ==
AUDIO_ID && !pes) invalid++;
99 if (vid + audio > invalid + 1)
102 if (sys > invalid && sys * 9 <= pspack * 10)
105 if (pspack > invalid && (priv1 + vid + audio) * 10 >= pspack * 9)
108 if ((!!vid ^ !!audio) && (audio > 4 || vid > 1) && !sys &&
109 !pspack && p->
buf_size > 2048 && vid + audio > invalid)
125 #if CONFIG_VOBSUB_DEMUXER
141 if (!memcmp(
"IMKH", buffer, 4)) {
143 }
else if (!memcmp(
"Sofdec", buffer, 6)) {
168 state = *header_state;
175 if (state == 0x000001) {
176 state = ((state << 8) | v) & 0xffffff;
180 state = ((state << 8) | v) & 0xffffff;
185 *header_state =
state;
198 int psm_length, ps_info_length, es_map_length;
209 es_map_length = psm_length - ps_info_length - 10;
212 while (es_map_length >= 4) {
214 unsigned char es_id =
avio_r8(pb);
221 es_map_length -= 4 + es_info_length;
224 return 2 + psm_length;
231 int64_t *ppos,
int *pstart_code,
232 int64_t *ppts, int64_t *pdts)
236 int pes_ext, ext2_len, id_ext, skip;
273 if (bytesread != len) {
278 p = memchr(ps2buf,
'S', len - 5);
281 m->
sofdec = !memcmp(p+1,
"ofdec", 5);
286 if (len == 980 && ps2buf[0] == 0) {
288 uint32_t startpts =
AV_RB32(ps2buf + 0x0d);
289 uint32_t endpts =
AV_RB32(ps2buf + 0x11);
290 uint8_t hours = ((ps2buf[0x19] >> 4) * 10) + (ps2buf[0x19] & 0x0f);
291 uint8_t mins = ((ps2buf[0x1a] >> 4) * 10) + (ps2buf[0x1a] & 0x0f);
292 uint8_t secs = ((ps2buf[0x1b] >> 4) * 10) + (ps2buf[0x1b] & 0x0f);
294 m->
dvd = (hours <= 23 &&
297 (ps2buf[0x19] & 0x0f) < 10 &&
298 (ps2buf[0x1a] & 0x0f) < 10 &&
299 (ps2buf[0x1b] & 0x0f) < 10 &&
301 }
else if (len == 1018 && ps2buf[0] == 1) {
303 uint8_t hours = ((ps2buf[0x1d] >> 4) * 10) + (ps2buf[0x1d] & 0x0f);
304 uint8_t mins = ((ps2buf[0x1e] >> 4) * 10) + (ps2buf[0x1e] & 0x0f);
305 uint8_t secs = ((ps2buf[0x1f] >> 4) * 10) + (ps2buf[0x1f] & 0x0f);
307 m->
dvd = (hours <= 23 &&
310 (ps2buf[0x1d] & 0x0f) < 10 &&
311 (ps2buf[0x1e] & 0x0f) < 10 &&
312 (ps2buf[0x1f] & 0x0f) < 10);
335 }
else if (!m->
dvd) {
347 if (!((startcode >= 0x1c0 && startcode <= 0x1df) ||
348 (startcode >= 0x1e0 && startcode <= 0x1ef) ||
349 (startcode == 0x1bd) ||
351 (startcode == 0x1fd)))
371 if ((c & 0xc0) == 0x40) {
377 if ((c & 0xe0) == 0x20) {
385 }
else if ((c & 0xc0) == 0x80) {
390 if (header_len > len)
401 if (flags & 0x3f && header_len == 0) {
410 skip = (pes_ext >> 4) & 0xb;
412 if (pes_ext & 0x40 || skip > header_len) {
419 if (pes_ext & 0x01) {
422 if ((ext2_len & 0x7f) > 0) {
424 if ((id_ext & 0x80) == 0)
425 startcode = ((startcode & 0xff) << 8) | id_ext;
455 *pstart_code = startcode;
466 int len, startcode, i, es_type,
ret;
467 int lpcm_header_len = -1;
468 int request_probe= 0;
471 int64_t pts, dts, dummy_pos;
478 if (startcode >= 0x80 && startcode <= 0xcf) {
486 if (startcode >= 0xb0 && startcode <= 0xbf) {
496 if (st->
id == startcode)
523 }
else if (m->
imkh_cctv && es_type == 0x91) {
526 }
else if (startcode >= 0x1e0 && startcode <= 0x1ef) {
527 static const unsigned char avs_seqh[4] = { 0, 0, 1, 0xb0 };
528 unsigned char buf[8];
532 if (!memcmp(buf, avs_seqh, 4) && (buf[6] != 0 || buf[7] != 1))
540 }
else if (startcode >= 0x1c0 && startcode <= 0x1df) {
549 }
else if (startcode >= 0x80 && startcode <= 0x87) {
552 }
else if ((startcode >= 0x88 && startcode <= 0x8f) ||
553 (startcode >= 0x98 && startcode <= 0x9f)) {
557 }
else if (startcode >= 0xa0 && startcode <= 0xaf) {
559 if (lpcm_header_len == 6) {
564 }
else if (startcode >= 0xb0 && startcode <= 0xbf) {
567 }
else if (startcode >= 0xc0 && startcode <= 0xcf) {
571 }
else if (startcode >= 0x20 && startcode <= 0x3f) {
574 }
else if (startcode >= 0xfd55 && startcode <= 0xfd5f) {
601 if (startcode >= 0xa0 && startcode <= 0xaf) {
613 pkt->
pos = dummy_pos;
615 av_dlog(s,
"%d: pts=%0.3f dts=%0.3f size=%d\n",
619 return (ret < 0) ? ret : 0;
623 int64_t *ppos, int64_t pos_limit)
626 int64_t pos, pts, dts;
635 av_dlog(s,
"none (ret=%d)\n", len);
638 if (startcode == s->
streams[stream_index]->
id &&
644 av_dlog(s,
"pos=0x%"PRIx64
" dts=0x%"PRIx64
" %0.3f\n",
645 pos, dts, dts / 90000.0);
661 #if CONFIG_VOBSUB_DEMUXER
663 #define REF_STRING "# VobSub index file,"
664 #define MAX_LINE_SIZE 2048
668 if (!strncmp(p->
buf, REF_STRING,
sizeof(REF_STRING) - 1))
675 int i,
ret = 0, header_parsed = 0, langidx = 0;
677 char *sub_name = NULL;
679 char *ext, *header_str;
689 fname_len = strlen(sub_name);
690 ext = sub_name - 3 + fname_len;
691 if (fname_len < 4 || *(ext - 1) !=
'.') {
693 "to guess the associated .SUB file\n");
697 memcpy(ext, !strncmp(ext,
"IDX", 3) ?
"SUB" :
"sub", 3);
706 if (!vobsub->sub_ctx) {
728 line[strcspn(line,
"\r\n")] = 0;
730 if (!strncmp(line,
"id:", 3)) {
731 if (sscanf(line,
"id: %63[^,], index: %u",
id, &stream_id) != 2) {
733 "assuming 'id: und, index: 0'\n", line);
751 }
else if (!strncmp(line,
"timestamp:", 10)) {
754 int64_t pos, timestamp;
755 const char *p = line + 10;
757 if (stream_id == -1) {
763 if (!st || st->
id != stream_id) {
778 if (sscanf(p,
"%02d:%02d:%02d:%03d, filepos: %"SCNx64,
779 &hh, &mm, &ss, &ms, &pos) != 5) {
781 "abort parsing\n", line);
785 timestamp = (hh*3600LL + mm*60LL + ss) * 1000LL + ms + delay;
794 sub->
pts = timestamp;
797 }
else if (!strncmp(line,
"alt:", 4)) {
798 const char *p = line + 4;
806 }
else if (!strncmp(line,
"delay:", 6)) {
807 int sign = 1, hh = 0, mm = 0, ss = 0, ms = 0;
808 const char *p = line + 6;
812 if (*p ==
'-' || *p ==
'+') {
813 sign = *p ==
'-' ? -1 : 1;
816 sscanf(p,
"%d:%d:%d:%d", &hh, &mm, &ss, &ms);
817 delay = ((hh*3600LL + mm*60LL + ss) * 1000LL + ms) * sign;
819 }
else if (!strncmp(line,
"langidx:", 8)) {
820 const char *p = line + 8;
822 if (sscanf(p,
"%d", &langidx) != 1)
825 }
else if (!header_parsed) {
826 if (line[0] && line[0] !=
'#')
862 int ret, psize, total_read = 0, i;
865 int64_t min_ts = INT64_MAX;
888 psize = fsize < 0 ? 0xffff : fsize - idx_pkt.
pos;
898 int n, to_read, startcode;
900 int64_t old_pos =
avio_tell(pb), new_pos;
909 to_read = ret & 0xffff;
911 pkt_size = ret + (new_pos - old_pos);
914 if (total_read + pkt_size > psize)
916 total_read += pkt_size;
928 pkt->
size -= to_read -
n;
929 }
while (total_read < psize);
945 int64_t min_ts, int64_t ts, int64_t max_ts,
int flags)
952 if (stream_index == -1 && s->
nb_streams != 1) {
960 time_base.
num * (int64_t)AV_TIME_BASE,
964 min_ts, ts, max_ts, flags);
971 if (stream_index == -1)
974 min_ts, ts, max_ts, flags);
996 .read_seek2 = vobsub_read_seek,