comparison libmpdemux/demux_real.c @ 6995:8f92313a0cd5

RV20 A-V desync fixed - use timestamp hack only for RV30
author arpi
date Wed, 14 Aug 2002 09:15:31 +0000
parents 9037a1a34c94
children 66c2e2d0504f
comparison
equal deleted inserted replaced
6994:c7d6b72b6fc0 6995:8f92313a0cd5
6 Based on FFmpeg's libav/rm.c. 6 Based on FFmpeg's libav/rm.c.
7 7
8 TODO: fix the whole syncing mechanism 8 TODO: fix the whole syncing mechanism
9 9
10 $Log$ 10 $Log$
11 Revision 1.21 2002/08/14 09:15:31 arpi
12 RV20 A-V desync fixed - use timestamp hack only for RV30
13
11 Revision 1.20 2002/08/12 00:04:37 arpi 14 Revision 1.20 2002/08/12 00:04:37 arpi
12 RV40 support 15 RV40 support
13 16
14 Revision 1.19 2002/08/05 03:13:45 arpi 17 Revision 1.19 2002/08/05 03:13:45 arpi
15 fixed 'eof at 66s' bug 18 fixed 'eof at 66s' bug
369 return 1; 372 return 1;
370 } 373 }
371 374
372 void hexdump(char *, unsigned long); 375 void hexdump(char *, unsigned long);
373 376
374 static float real_fix_timestamp(real_priv_t* priv, unsigned char* s, int timestamp, float frametime){ 377 static float real_fix_timestamp(real_priv_t* priv, unsigned char* s, int timestamp, float frametime, unsigned int format){
375 int kf=2*(((s[1]&15)<<8)+s[2]); // 12-bit timestamp from frame header 378 float v_pts;
376 float v_pts; 379 int kf=timestamp;
380 if(format==0x30335652){ // RV30 timestamps:
381 kf=2*(((s[1]&15)<<8)+s[2]); // 12-bit timestamp from frame header
382 //kf=((s[1]<<8)+s[2])>>3; // 12-bit timestamp from frame header
383 printf("\nTS: %08X (%04X) %02X %02X %02X %02X\n",timestamp,kf,s[0],s[1],s[2],s[3]);
377 kf|=timestamp&(~0x1fff); // combine with packet timestamp 384 kf|=timestamp&(~0x1fff); // combine with packet timestamp
378 if(kf<timestamp-4096) kf+=8192; else // workaround wrap-around problems 385 if(kf<timestamp-4096) kf+=8192; else // workaround wrap-around problems
379 if(kf>timestamp+4096) kf-=8192; 386 if(kf>timestamp+4096) kf-=8192;
380 if(!(s[0]&0x8) || !(s[0]&0x10)){ // P || I frame -> swap timestamps 387 if(!(s[0]&0x8) || !(s[0]&0x10)){ // P || I frame -> swap timestamps
381 int tmp=kf; 388 int tmp=kf;
382 kf=priv->kf_pts; 389 kf=priv->kf_pts;
383 priv->kf_pts=tmp; 390 priv->kf_pts=tmp;
384 // if(kf<=tmp) kf=0; 391 // if(kf<=tmp) kf=0;
385 } 392 }
393 }
386 v_pts=kf*0.001f; 394 v_pts=kf*0.001f;
387 if(v_pts<priv->v_pts || !kf) v_pts=priv->v_pts+frametime; 395 if(v_pts<priv->v_pts || !kf) v_pts=priv->v_pts+frametime;
388 priv->v_pts=v_pts; 396 priv->v_pts=v_pts;
389 // printf("\n#T# %5d/%5d (%5.3f) %5.3f \n",kf,timestamp,frametime,v_pts); 397 // printf("\n#T# %5d/%5d (%5.3f) %5.3f \n",kf,timestamp,frametime,v_pts);
390 return v_pts; 398 return v_pts;
601 // we have an incomplete packet: 609 // we have an incomplete packet:
602 if(ds->asf_seq!=vpkg_seqnum){ 610 if(ds->asf_seq!=vpkg_seqnum){
603 // this fragment is for new packet, close the old one 611 // this fragment is for new packet, close the old one
604 mp_msg(MSGT_DEMUX,MSGL_DBG2, "closing probably incomplete packet, len: %d \n",dp->len); 612 mp_msg(MSGT_DEMUX,MSGL_DBG2, "closing probably incomplete packet, len: %d \n",dp->len);
605 dp->pts=(dp->len<3)?0: 613 dp->pts=(dp->len<3)?0:
606 real_fix_timestamp(priv,dp->buffer,timestamp,sh_video->frametime); 614 real_fix_timestamp(priv,dp->buffer,timestamp,sh_video->frametime,sh_video->format);
607 ds_add_packet(ds,dp); 615 ds_add_packet(ds,dp);
608 ds->asf_packet=NULL; 616 ds->asf_packet=NULL;
609 } else { 617 } else {
610 // append data to it! 618 // append data to it!
611 extra=(unsigned int*)(dp->buffer+vpkg_length); 619 extra=(unsigned int*)(dp->buffer+vpkg_length);
625 dp->len+=vpkg_offset; 633 dp->len+=vpkg_offset;
626 len-=vpkg_offset; 634 len-=vpkg_offset;
627 mp_dbg(MSGT_DEMUX,MSGL_DBG2, "fragment (%d bytes) appended, %d bytes left\n",vpkg_offset,len); 635 mp_dbg(MSGT_DEMUX,MSGL_DBG2, "fragment (%d bytes) appended, %d bytes left\n",vpkg_offset,len);
628 // we know that this is the last fragment -> we can close the packet! 636 // we know that this is the last fragment -> we can close the packet!
629 dp->pts=(dp->len<3)?0: 637 dp->pts=(dp->len<3)?0:
630 real_fix_timestamp(priv,dp->buffer,extra[1],sh_video->frametime); 638 real_fix_timestamp(priv,dp->buffer,extra[1],sh_video->frametime,sh_video->format);
631 ds_add_packet(ds,dp); 639 ds_add_packet(ds,dp);
632 ds->asf_packet=NULL; 640 ds->asf_packet=NULL;
633 // continue parsing 641 // continue parsing
634 continue; 642 continue;
635 } 643 }
664 } 672 }
665 // whole packet (not fragmented): 673 // whole packet (not fragmented):
666 dp->len=vpkg_length; len-=vpkg_length; 674 dp->len=vpkg_length; len-=vpkg_length;
667 stream_read(demuxer->stream, dp->buffer, dp->len); 675 stream_read(demuxer->stream, dp->buffer, dp->len);
668 dp->pts=(dp->len<3)?0: 676 dp->pts=(dp->len<3)?0:
669 real_fix_timestamp(priv,dp->buffer,extra[1],sh_video->frametime); 677 real_fix_timestamp(priv,dp->buffer,extra[1],sh_video->frametime,sh_video->format);
670 ds_add_packet(ds,dp); 678 ds_add_packet(ds,dp);
671 679
672 } // while(len>0) 680 } // while(len>0)
673 681
674 if(len){ 682 if(len){