comparison libmpdemux/demux_ty.c @ 24463:f93cfdc6f4f5

Move timestamps to int64_t and use MP_NOPTS_VALUE
author reimar
date Fri, 14 Sep 2007 18:03:36 +0000
parents bc31f7bc07de
children 41c96af4be72
comparison
equal deleted inserted replaced
24462:bc31f7bc07de 24463:f93cfdc6f4f5
69 #define TIVO_PART_LENGTH 0x20000000 69 #define TIVO_PART_LENGTH 0x20000000
70 70
71 #define CHUNKSIZE ( 128 * 1024 ) 71 #define CHUNKSIZE ( 128 * 1024 )
72 #define MAX_AUDIO_BUFFER ( 16 * 1024 ) 72 #define MAX_AUDIO_BUFFER ( 16 * 1024 )
73 73
74 #define PTS_MHZ 90
75 #define PTS_KHZ ( PTS_MHZ * 1000 )
76
77 #define TY_V 1 74 #define TY_V 1
78 #define TY_A 2 75 #define TY_A 2
79 76
80 typedef struct stmf_fileParts 77 typedef struct stmf_fileParts
81 { 78 {
94 unsigned char lastAudio[ MAX_AUDIO_BUFFER ]; 91 unsigned char lastAudio[ MAX_AUDIO_BUFFER ];
95 int lastAudioEnd; 92 int lastAudioEnd;
96 93
97 int tivoType; // 1 = SA, 2 = DTiVo 94 int tivoType; // 1 = SA, 2 = DTiVo
98 95
99 float firstAudioPTS; 96 int64_t firstAudioPTS;
100 float firstVideoPTS; 97 int64_t firstVideoPTS;
101 98
102 float lastAudioPTS; 99 int64_t lastAudioPTS;
103 float lastVideoPTS; 100 int64_t lastVideoPTS;
104 101
105 int headerOk; 102 int headerOk;
106 unsigned int pesFileId; // Should be 0xf5467abd 103 unsigned int pesFileId; // Should be 0xf5467abd
107 int streamType; // Should be 0x02 104 int streamType; // Should be 0x02
108 int chunkSize; // Should always be 128k 105 int chunkSize; // Should always be 128k
351 else 348 else
352 return 1; 349 return 1;
353 } 350 }
354 351
355 352
356 static float get_ty_pts( unsigned char *buf ) 353 static int64_t get_ty_pts( unsigned char *buf )
357 { 354 {
358 int a = buf[0] & 0xe; 355 int a = buf[0] & 0xe;
359 int b = AV_RB16(buf + 1); 356 int b = AV_RB16(buf + 1);
360 int c = AV_RB16(buf + 3); 357 int c = AV_RB16(buf + 3);
361 uint64_t pts;
362 358
363 if (!(1 & a & b & c)) // invalid MPEG timestamp 359 if (!(1 & a & b & c)) // invalid MPEG timestamp
364 return 0; 360 return MP_NOPTS_VALUE;
365 a >>= 1; b >>= 1; c >>= 1; 361 a >>= 1; b >>= 1; c >>= 1;
366 pts = (((uint64_t)a) << 30) | (b << 15) | c; 362 return (((uint64_t)a) << 30) | (b << 15) | c;
367 return (float)pts / PTS_KHZ;
368 } 363 }
369 364
370 static void demux_ty_AddToAudioBuffer( TiVoInfo *tivo, unsigned char *buffer, 365 static void demux_ty_AddToAudioBuffer( TiVoInfo *tivo, unsigned char *buffer,
371 int size ) 366 int size )
372 { 367 {
390 // printf( "%x %x %x %x\n", 385 // printf( "%x %x %x %x\n",
391 // buffer[ 0 ], buffer[ 1 ], buffer[ 2 ], buffer[ 3 ] ); 386 // buffer[ 0 ], buffer[ 1 ], buffer[ 2 ], buffer[ 3 ] );
392 387
393 dp = new_demux_packet( size ); 388 dp = new_demux_packet( size );
394 memcpy( dp->buffer, buffer, size ); 389 memcpy( dp->buffer, buffer, size );
395 dp->pts = pts; 390 if (pts != MP_NOPTS_VALUE)
391 dp->pts = pts / 90000.0;
396 dp->pos = pos; 392 dp->pos = pos;
397 dp->flags = 0; 393 dp->flags = 0;
398 ds_add_packet( ds, dp ); 394 ds_add_packet( ds, dp );
399 if ( type == TY_V && tivo->firstVideoPTS == -1 ) 395 if ( type == TY_V && tivo->firstVideoPTS == MP_NOPTS_VALUE )
400 tivo->firstVideoPTS = pts; 396 tivo->firstVideoPTS = pts;
401 if ( type == TY_A && tivo->firstAudioPTS == -1 ) 397 if ( type == TY_A && tivo->firstAudioPTS == MP_NOPTS_VALUE )
402 tivo->firstAudioPTS = pts; 398 tivo->firstAudioPTS = pts;
403 } 399 }
404 400
405 static int demux_ty_FindESHeader( unsigned char *header, int headerSize, 401 static int demux_ty_FindESHeader( unsigned char *header, int headerSize,
406 unsigned char *buffer, int bufferSize, int *esOffset1 ) 402 unsigned char *buffer, int bufferSize, int *esOffset1 )
509 if ( demux->a_streams[ MAX_A_STREAMS - 1 ] == 0 ) 505 if ( demux->a_streams[ MAX_A_STREAMS - 1 ] == 0 )
510 { 506 {
511 demux->a_streams[ MAX_A_STREAMS - 1 ] = malloc( sizeof( TiVoInfo ) ); 507 demux->a_streams[ MAX_A_STREAMS - 1 ] = malloc( sizeof( TiVoInfo ) );
512 tivo = demux->a_streams[ MAX_A_STREAMS - 1 ]; 508 tivo = demux->a_streams[ MAX_A_STREAMS - 1 ];
513 memset( tivo, 0, sizeof( TiVoInfo ) ); 509 memset( tivo, 0, sizeof( TiVoInfo ) );
514 tivo->firstAudioPTS = -1; 510 tivo->firstAudioPTS = MP_NOPTS_VALUE;
515 tivo->firstVideoPTS = -1; 511 tivo->firstVideoPTS = MP_NOPTS_VALUE;
516 } 512 }
517 else 513 else
518 { 514 {
519 tivo = demux->a_streams[ MAX_A_STREAMS - 1 ]; 515 tivo = demux->a_streams[ MAX_A_STREAMS - 1 ];
520 } 516 }
748 printf( "\n" ); 744 printf( "\n" );
749 #endif 745 #endif
750 demux_ty_FindESHeader( ty_VideoPacket, 4, &chunk[ offset ], 746 demux_ty_FindESHeader( ty_VideoPacket, 4, &chunk[ offset ],
751 size, &esOffset1 ); 747 size, &esOffset1 );
752 if ( esOffset1 != -1 ) 748 if ( esOffset1 != -1 )
753 {
754 tivo->lastVideoPTS = get_ty_pts( 749 tivo->lastVideoPTS = get_ty_pts(
755 &chunk[ offset + esOffset1 + 9 ] ); 750 &chunk[ offset + esOffset1 + 9 ] );
756 mp_msg( MSGT_DEMUX, MSGL_DBG3, "Video PTS %7.1f\n",
757 tivo->lastVideoPTS );
758 }
759 751
760 // Do NOT Pass the PES Header onto the MPEG2 Decode 752 // Do NOT Pass the PES Header onto the MPEG2 Decode
761 if( nybbleType != 0x06 ) 753 if( nybbleType != 0x06 )
762 demux_ty_CopyToDemuxPacket( TY_V, tivo, demux->video, 754 demux_ty_CopyToDemuxPacket( TY_V, tivo, demux->video,
763 &chunk[ offset ], size, demux->filepos + offset, 755 &chunk[ offset ], size, demux->filepos + offset,
849 if ( esOffset1 == 0 && size == 16 ) 841 if ( esOffset1 == 0 && size == 16 )
850 { 842 {
851 tivo->tivoType = 1; 843 tivo->tivoType = 1;
852 tivo->lastAudioPTS = get_ty_pts( &chunk[ offset + 844 tivo->lastAudioPTS = get_ty_pts( &chunk[ offset +
853 SERIES2_PTS_OFFSET ] ); 845 SERIES2_PTS_OFFSET ] );
854 mp_msg( MSGT_DEMUX, MSGL_DBG3, "SA Audio PTS %7.1f\n",
855 tivo->lastAudioPTS );
856 } 846 }
857 else 847 else
858 // DTiVo Audio with PES Header 848 // DTiVo Audio with PES Header
859 // ================================================ 849 // ================================================
860 { 850 {
878 "ty:Adding DTiVo Audio Packet Size %d\n", 868 "ty:Adding DTiVo Audio Packet Size %d\n",
879 packetSize ); 869 packetSize );
880 870
881 tivo->lastAudioPTS = get_ty_pts( 871 tivo->lastAudioPTS = get_ty_pts(
882 &tivo->lastAudio[ esOffset1 + ptsOffset ] ); 872 &tivo->lastAudio[ esOffset1 + ptsOffset ] );
883 mp_msg( MSGT_DEMUX, MSGL_DBG3,
884 "MPEG Audio PTS %7.1f\n", tivo->lastAudioPTS );
885 873
886 demux_ty_CopyToDemuxPacket 874 demux_ty_CopyToDemuxPacket
887 ( 875 (
888 TY_A, 876 TY_A,
889 tivo, 877 tivo,
940 "ty:Adding DTiVo Audio Packet Size %d\n", 928 "ty:Adding DTiVo Audio Packet Size %d\n",
941 packetSize ); 929 packetSize );
942 930
943 tivo->lastAudioPTS = get_ty_pts( 931 tivo->lastAudioPTS = get_ty_pts(
944 &tivo->lastAudio[ esOffset1 + ptsOffset ] ); 932 &tivo->lastAudio[ esOffset1 + ptsOffset ] );
945 mp_msg( MSGT_DEMUX, MSGL_DBG3,
946 "AC3 Audio PTS %7.1f\n", tivo->lastAudioPTS );
947 933
948 // AC3 Decoder WANTS the PTS 934 // AC3 Decoder WANTS the PTS
949 demux_ty_CopyToDemuxPacket 935 demux_ty_CopyToDemuxPacket
950 ( 936 (
951 TY_A, 937 TY_A,
1103 1089
1104 if ( demuxer->a_streams[ MAX_A_STREAMS - 1 ] != 0 ) 1090 if ( demuxer->a_streams[ MAX_A_STREAMS - 1 ] != 0 )
1105 { 1091 {
1106 tivo = demuxer->a_streams[ MAX_A_STREAMS - 1 ]; 1092 tivo = demuxer->a_streams[ MAX_A_STREAMS - 1 ];
1107 tivo->lastAudioEnd = 0; 1093 tivo->lastAudioEnd = 0;
1108 tivo->lastAudioPTS = 0; 1094 tivo->lastAudioPTS = MP_NOPTS_VALUE;
1109 tivo->lastVideoPTS = 0; 1095 tivo->lastVideoPTS = MP_NOPTS_VALUE;
1110 } 1096 }
1111 // 1097 //
1112 //================= seek in MPEG ========================== 1098 //================= seek in MPEG ==========================
1113 demuxer->filepos = stream_tell( demuxer->stream ); 1099 demuxer->filepos = stream_tell( demuxer->stream );
1114 1100