1
0
mirror of https://github.com/mpv-player/mpv synced 2025-02-07 23:51:49 +00:00

Move timestamps to int64_t and use MP_NOPTS_VALUE

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@24483 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
reimar 2007-09-14 18:03:36 +00:00
parent 0c71c038df
commit a6a96ab944

View File

@ -71,9 +71,6 @@ extern int sub_justify;
#define CHUNKSIZE ( 128 * 1024 ) #define CHUNKSIZE ( 128 * 1024 )
#define MAX_AUDIO_BUFFER ( 16 * 1024 ) #define MAX_AUDIO_BUFFER ( 16 * 1024 )
#define PTS_MHZ 90
#define PTS_KHZ ( PTS_MHZ * 1000 )
#define TY_V 1 #define TY_V 1
#define TY_A 2 #define TY_A 2
@ -96,11 +93,11 @@ typedef struct sTivoInfo
int tivoType; // 1 = SA, 2 = DTiVo int tivoType; // 1 = SA, 2 = DTiVo
float firstAudioPTS; int64_t firstAudioPTS;
float firstVideoPTS; int64_t firstVideoPTS;
float lastAudioPTS; int64_t lastAudioPTS;
float lastVideoPTS; int64_t lastVideoPTS;
int headerOk; int headerOk;
unsigned int pesFileId; // Should be 0xf5467abd unsigned int pesFileId; // Should be 0xf5467abd
@ -353,18 +350,16 @@ static int IsValidAudioPacket( int size, int *ptsOffset, int *ptsLen )
} }
static float get_ty_pts( unsigned char *buf ) static int64_t get_ty_pts( unsigned char *buf )
{ {
int a = buf[0] & 0xe; int a = buf[0] & 0xe;
int b = AV_RB16(buf + 1); int b = AV_RB16(buf + 1);
int c = AV_RB16(buf + 3); int c = AV_RB16(buf + 3);
uint64_t pts;
if (!(1 & a & b & c)) // invalid MPEG timestamp if (!(1 & a & b & c)) // invalid MPEG timestamp
return 0; return MP_NOPTS_VALUE;
a >>= 1; b >>= 1; c >>= 1; a >>= 1; b >>= 1; c >>= 1;
pts = (((uint64_t)a) << 30) | (b << 15) | c; return (((uint64_t)a) << 30) | (b << 15) | c;
return (float)pts / PTS_KHZ;
} }
static void demux_ty_AddToAudioBuffer( TiVoInfo *tivo, unsigned char *buffer, static void demux_ty_AddToAudioBuffer( TiVoInfo *tivo, unsigned char *buffer,
@ -392,13 +387,14 @@ static void demux_ty_CopyToDemuxPacket( int type, TiVoInfo *tivo, demux_stream_t
dp = new_demux_packet( size ); dp = new_demux_packet( size );
memcpy( dp->buffer, buffer, size ); memcpy( dp->buffer, buffer, size );
dp->pts = pts; if (pts != MP_NOPTS_VALUE)
dp->pts = pts / 90000.0;
dp->pos = pos; dp->pos = pos;
dp->flags = 0; dp->flags = 0;
ds_add_packet( ds, dp ); ds_add_packet( ds, dp );
if ( type == TY_V && tivo->firstVideoPTS == -1 ) if ( type == TY_V && tivo->firstVideoPTS == MP_NOPTS_VALUE )
tivo->firstVideoPTS = pts; tivo->firstVideoPTS = pts;
if ( type == TY_A && tivo->firstAudioPTS == -1 ) if ( type == TY_A && tivo->firstAudioPTS == MP_NOPTS_VALUE )
tivo->firstAudioPTS = pts; tivo->firstAudioPTS = pts;
} }
@ -511,8 +507,8 @@ static int demux_ty_fill_buffer( demuxer_t *demux, demux_stream_t *dsds )
demux->a_streams[ MAX_A_STREAMS - 1 ] = malloc( sizeof( TiVoInfo ) ); demux->a_streams[ MAX_A_STREAMS - 1 ] = malloc( sizeof( TiVoInfo ) );
tivo = demux->a_streams[ MAX_A_STREAMS - 1 ]; tivo = demux->a_streams[ MAX_A_STREAMS - 1 ];
memset( tivo, 0, sizeof( TiVoInfo ) ); memset( tivo, 0, sizeof( TiVoInfo ) );
tivo->firstAudioPTS = -1; tivo->firstAudioPTS = MP_NOPTS_VALUE;
tivo->firstVideoPTS = -1; tivo->firstVideoPTS = MP_NOPTS_VALUE;
} }
else else
{ {
@ -750,12 +746,8 @@ static int demux_ty_fill_buffer( demuxer_t *demux, demux_stream_t *dsds )
demux_ty_FindESHeader( ty_VideoPacket, 4, &chunk[ offset ], demux_ty_FindESHeader( ty_VideoPacket, 4, &chunk[ offset ],
size, &esOffset1 ); size, &esOffset1 );
if ( esOffset1 != -1 ) if ( esOffset1 != -1 )
{
tivo->lastVideoPTS = get_ty_pts( tivo->lastVideoPTS = get_ty_pts(
&chunk[ offset + esOffset1 + 9 ] ); &chunk[ offset + esOffset1 + 9 ] );
mp_msg( MSGT_DEMUX, MSGL_DBG3, "Video PTS %7.1f\n",
tivo->lastVideoPTS );
}
// Do NOT Pass the PES Header onto the MPEG2 Decode // Do NOT Pass the PES Header onto the MPEG2 Decode
if( nybbleType != 0x06 ) if( nybbleType != 0x06 )
@ -851,8 +843,6 @@ static int demux_ty_fill_buffer( demuxer_t *demux, demux_stream_t *dsds )
tivo->tivoType = 1; tivo->tivoType = 1;
tivo->lastAudioPTS = get_ty_pts( &chunk[ offset + tivo->lastAudioPTS = get_ty_pts( &chunk[ offset +
SERIES2_PTS_OFFSET ] ); SERIES2_PTS_OFFSET ] );
mp_msg( MSGT_DEMUX, MSGL_DBG3, "SA Audio PTS %7.1f\n",
tivo->lastAudioPTS );
} }
else else
// DTiVo Audio with PES Header // DTiVo Audio with PES Header
@ -880,8 +870,6 @@ static int demux_ty_fill_buffer( demuxer_t *demux, demux_stream_t *dsds )
tivo->lastAudioPTS = get_ty_pts( tivo->lastAudioPTS = get_ty_pts(
&tivo->lastAudio[ esOffset1 + ptsOffset ] ); &tivo->lastAudio[ esOffset1 + ptsOffset ] );
mp_msg( MSGT_DEMUX, MSGL_DBG3,
"MPEG Audio PTS %7.1f\n", tivo->lastAudioPTS );
demux_ty_CopyToDemuxPacket demux_ty_CopyToDemuxPacket
( (
@ -942,8 +930,6 @@ static int demux_ty_fill_buffer( demuxer_t *demux, demux_stream_t *dsds )
tivo->lastAudioPTS = get_ty_pts( tivo->lastAudioPTS = get_ty_pts(
&tivo->lastAudio[ esOffset1 + ptsOffset ] ); &tivo->lastAudio[ esOffset1 + ptsOffset ] );
mp_msg( MSGT_DEMUX, MSGL_DBG3,
"AC3 Audio PTS %7.1f\n", tivo->lastAudioPTS );
// AC3 Decoder WANTS the PTS // AC3 Decoder WANTS the PTS
demux_ty_CopyToDemuxPacket demux_ty_CopyToDemuxPacket
@ -1105,8 +1091,8 @@ static void demux_seek_ty( demuxer_t *demuxer, float rel_seek_secs, float audio_
{ {
tivo = demuxer->a_streams[ MAX_A_STREAMS - 1 ]; tivo = demuxer->a_streams[ MAX_A_STREAMS - 1 ];
tivo->lastAudioEnd = 0; tivo->lastAudioEnd = 0;
tivo->lastAudioPTS = 0; tivo->lastAudioPTS = MP_NOPTS_VALUE;
tivo->lastVideoPTS = 0; tivo->lastVideoPTS = MP_NOPTS_VALUE;
} }
// //
//================= seek in MPEG ========================== //================= seek in MPEG ==========================