48 return (buf[3]<<24)|(buf[2]<<16)|(buf[1]<<8)|buf[0];
52 static uint32_t getbe32(uint8_t *buf)
54 return (buf[0]<<24)|(buf[1]<<16)|(buf[2]<<8)|buf[3];
57 static void printhead(uint8_t *buf)
59 LOG(VB_GENERAL, LOG_INFO, QString(
"%1%2%3%4 ")
60 .arg(buf[0]).arg(buf[1]).arg(buf[2]).arg(buf[3]));
68 int len=
read(fd, buf, 4);
84 if (len < 12)
return -1;
86 if (tag !=
TAG_IT(
'R',
'I',
'F',
'F'))
return -1;
93 if (tag !=
TAG_IT(
'A',
'V',
'I',
' ') &&
94 tag !=
TAG_IT(
'A',
'V',
'I',
'X') )
return -1;
101 uint32_t fl, uint32_t
id)
106 uint32_t newnum = num + 1024;
119 ac->
idx[num].
id = id;
131 cc = (
char *) &ac->
idx[num].
id;
132 LOG(VB_GENERAL, LOG_DEBUG,
133 QString(
"%1 chunkid: %2%3%4%5 chunkoff: 0x%6 chunksize: 0x%7 "
136 .arg(*cc).arg(*(
cc+1)).arg(*(
cc+2)).arg(*(
cc+3))
137 .arg(ac->
idx[num].
off, 4,16,QChar(
'0'))
138 .arg(ac->
idx[num].
len, 4,16,QChar(
'0'))
139 .arg(ac->
idx[num].
flags, 4,16,QChar(
'0')));
152 LOG(VB_GENERAL, LOG_INFO,
"READING INDEX");
153 if ((start =
lseek(fd, 0, SEEK_CUR)) < 0)
return -3;
159 if (tag !=
TAG_IT(
'i',
'd',
'x',
'1')){
161 LOG(VB_GENERAL, LOG_INFO, QString(
" tag: %1%2%3%4\n ")
162 .arg(*cc).arg(*(
cc+1)).arg(*(
cc+2)).arg(*(
cc+3)));
164 if (
lseek(fd, start, SEEK_SET) < 0 )
return -5;
184 case TAG_IT(
'0',
'1',
'w',
'b'):
189 case TAG_IT(
'0',
'0',
'd',
'c'):
203 LOG(VB_GENERAL, LOG_DEBUG,
204 QString(
"Found %1 video (%2 were empty) and %3 "
205 "audio (%4 were empty) chunks")
209 lseek(fd, start, SEEK_SET);
227 while ((c=
read(fd, buf, 4))==4) {
233 LOG(VB_GENERAL, LOG_DEBUG, QString(
"tag: %1%2%3%4")
234 .arg(*cc).arg(*(
cc+1)).arg(*(
cc+2)).arg(*(
cc+3)));
237 case TAG_IT(
'L',
'I',
'S',
'T'):
242 case TAG_IT(
'm',
'o',
'v',
'i'):
247 LOG(VB_GENERAL, LOG_DEBUG,
248 QString(
" size: %1 header done").arg(size));
253 case TAG_IT(
'h',
'd',
'r',
'l'):
257 case TAG_IT(
's',
't',
'r',
'l'):
260 case TAG_IT(
'J',
'U',
'N',
'K'):
261 case TAG_IT(
's',
't',
'r',
'f'):
262 case TAG_IT(
's',
't',
'r',
'd'):
263 case TAG_IT(
's',
't',
'r',
'n'):
267 case TAG_IT(
'a',
'v',
'i',
'h'):
288 LOG(VB_GENERAL, LOG_DEBUG,
289 QString(
" size: %1").arg(size));
290 LOG(VB_GENERAL, LOG_DEBUG,
291 QString(
" microsecs per frame %1")
294 LOG(VB_GENERAL, LOG_DEBUG,
" AVI has index");
296 LOG(VB_GENERAL, LOG_DEBUG,
297 " AVI must use index");
299 LOG(VB_GENERAL, LOG_DEBUG,
300 " AVI is interleaved");
302 LOG(VB_GENERAL, LOG_DEBUG,
303 QString(
" total frames: %1")
306 LOG(VB_GENERAL, LOG_DEBUG,
307 QString(
" number of streams: %1")
309 LOG(VB_GENERAL, LOG_DEBUG, QString(
" size: %1x%2")
314 case TAG_IT(
's',
't',
'r',
'h'):
317 LOG(VB_GENERAL, LOG_DEBUG,
318 QString(
" size: %1").arg(size));
327 LOG(VB_GENERAL, LOG_DEBUG, QString(
" tag: %1%2%3%4")
328 .arg(*cc).arg(*(
cc+1)).arg(*(
cc+2)).arg((
cc+3)));
331 case TAG_IT(
'v',
'i',
'd',
's'):
336 LOG(VB_GENERAL, LOG_DEBUG,
337 QString(
" video handler: %1%2%3%4")
338 .arg(*cc).arg(*(
cc+1)).arg(*(
cc+2)).arg(*(
cc+3)));
353 LOG(VB_GENERAL, LOG_INFO,
354 QString(
"AVI video info: dw_scale %1 dw_rate %2 "
355 "fps %3 ini_frames %4 dw_start %5")
357 .arg(ac->
vi.
fps/1000.0, 0,
'f',3,QChar(
'0'))
361 case TAG_IT(
'a',
'u',
'd',
's'):
366 LOG(VB_GENERAL, LOG_DEBUG,
367 QString(
" audio handler: %1%2%3%4")
368 .arg(*cc).arg(*(
cc+1)).arg(*(
cc+2)).arg((
cc+3)));
389 LOG(VB_GENERAL, LOG_INFO,
390 QString(
"AVI audio%1 info: dw_scale %2 dw_rate "
391 "%3 ini_frames %4 dw_start %5 fps %6 "
392 " sam_size %7").arg(n)
396 .arg(ac->
ai[n].
fps/1000.0, 0,
'f',3,QChar(
'0'))
404 case TAG_IT(
'I',
'N',
'F',
'O'):
408 LOG(VB_GENERAL, LOG_DEBUG, QString(
" size: %1").arg(size));
415 lseek(fd, size, SEEK_CUR);
425 #define MAX_BUF_SIZE 0xffff
427 void (*func)(
pes_in_t *
p), uint32_t insize)
441 switch(idx[cidx].
id){
442 case TAG_IT(
'0',
'1',
'w',
'b'):
447 case TAG_IT(
'0',
'0',
'd',
'c'):
453 LOG(VB_GENERAL, LOG_ERR,
"strange chunk :");
454 show_buf((uint8_t *) &idx[cidx].
id,4);
455 LOG(VB_GENERAL, LOG_ERR, QString(
"offset: 0x%1 length: 0x%2")
456 .arg(idx[cidx].off, 4,16,QChar(
'0'))
457 .arg(idx[cidx].len, 4,16,QChar(
'0')));
466 read(fd,buf,idx[cidx].len);
471 if (idx[cidx].len > insize)
return 0;
474 LOG(VB_GENERAL, LOG_ERR,
475 "Buffer too small in get_avi_from_index");
484 if (cid != idx[cidx].
id){
486 cc = (
char *)&idx[cidx].
id;
487 LOG(VB_GENERAL, LOG_ERR,
488 QString(
"wrong chunk id: %1%2%3%4 != %5%6%7%8")
489 .arg(buf[0]).arg(buf[1]).arg(buf[2]).arg(buf[3])
490 .arg(*cc).arg(*(
cc+1)).arg(*(
cc+2)).arg(*(
cc+3)));
495 if (
p->plength != idx[cidx].len){
496 LOG(VB_GENERAL, LOG_ERR, QString(
"wrong chunk size: %1 != %2")
497 .arg(
p->plength).arg(idx[cidx].len));
505 if (per % 10 == 0 && per>
lastper)
506 LOG(VB_GENERAL, LOG_INFO, QString(
"read %1%%").arg(per,3));
510 LOG(VB_GENERAL, LOG_ERR,
511 QString(
"ring buffer overflow %1 0x%2")
512 .arg(
p->rbuf->size).arg(
p->type, 2,16,QChar(
'0')));
533 while (c < count && p->found < 8
537 if (buf[c] ==
'0')
p->found++;
542 if (buf[c] ==
'0'|| buf[c] ==
'1'){
544 p->which = buf[c] -
'0';
545 }
else if (buf[c] ==
'0'){
628 LOG(VB_GENERAL, LOG_ERR, QString(
"audio 0x%1 0x%2")
629 .arg(
p->plength, 0,16)
630 .arg(
ALIGN(
p->plength), 0,16));
631 LOG(VB_GENERAL, LOG_ERR, QString(
"video 0x%1 0x%2")
632 .arg(
p->plength, 0,16)
633 .arg(
ALIGN(
p->plength), 0,16));
643 if (
p->done ||
p->found > 8){
644 while (c < count && p->found < p->plength+8){
646 if (l+
p->found >
p->plength+8)
647 l =
p->plength+8-
p->found;
649 LOG(VB_GENERAL, LOG_ERR,
650 QString(
"ring buffer overflow %1")
651 .arg(
p->rbuf->size));
657 if(
p->found ==
p->plength+8){
662 if (
p->plength &&
p->found ==
p->plength+8) {
666 get_avi(
p, buf+c+a, count-c-a, func);