[vlc-commits] date_t: always init to TS_INVALID
Francois Cartegnie
git at videolan.org
Fri May 25 11:10:43 CEST 2018
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri May 25 09:54:21 2018 +0200| [10318107ac248f2d9b1be038265f3d29a6734c97] | committer: Francois Cartegnie
date_t: always init to TS_INVALID
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=10318107ac248f2d9b1be038265f3d29a6734c97
---
modules/access/cdda.c | 5 +++--
modules/access/jack.c | 3 ++-
modules/access/qtsound.m | 3 ++-
modules/access/timecode.c | 2 +-
modules/codec/adpcm.c | 1 -
modules/codec/aes3.c | 1 -
modules/codec/araw.c | 1 -
modules/codec/audiotoolbox_midi.c | 1 -
modules/codec/avcodec/audio.c | 1 -
modules/codec/avcodec/encoder.c | 28 ++++++++++++++++++----------
modules/codec/avcodec/video.c | 1 -
modules/codec/dmo/dmo.c | 1 +
modules/codec/faad.c | 5 ++---
modules/codec/flac.c | 3 +--
modules/codec/fluidsynth.c | 1 -
modules/codec/g711.c | 1 -
modules/codec/lpcm.c | 4 ++--
modules/codec/mpg123.c | 1 -
modules/codec/omxil/omxil.c | 2 +-
modules/codec/opus.c | 4 ++--
modules/codec/schroedinger.c | 21 +++++++++++----------
modules/codec/speex.c | 4 ++--
modules/codec/uleaddvaudio.c | 3 +--
modules/codec/vorbis.c | 4 ++--
modules/demux/cdg.c | 5 +++--
modules/demux/gme.c | 3 ++-
modules/demux/image.c | 18 +++++++++---------
modules/demux/mod.c | 10 +++++-----
modules/demux/rawaud.c | 3 ++-
modules/demux/rawvid.c | 5 +++--
modules/demux/sid.cpp | 3 ++-
modules/demux/voc.c | 1 +
modules/demux/wav.c | 3 ++-
modules/misc/stats.c | 4 ++--
modules/packetizer/dts.c | 4 ++--
modules/packetizer/flac.c | 1 -
modules/packetizer/h264.c | 1 -
modules/packetizer/hevc.c | 1 -
modules/packetizer/mlp.c | 1 -
modules/packetizer/mpeg4audio.c | 1 -
modules/packetizer/mpegaudio.c | 1 -
modules/packetizer/mpegvideo.c | 2 --
modules/video_filter/fps.c | 1 -
src/misc/mtime.c | 6 +++++-
44 files changed, 89 insertions(+), 86 deletions(-)
diff --git a/modules/access/cdda.c b/modules/access/cdda.c
index f6f6770fef..7ce0924fad 100644
--- a/modules/access/cdda.c
+++ b/modules/access/cdda.c
@@ -156,11 +156,11 @@ static int Demux(demux_t *demux)
sys->position += count;
block->i_nb_samples = block->i_buffer / 4;
- block->i_dts = block->i_pts = VLC_TS_0 + date_Get(&sys->pts);
+ block->i_dts = block->i_pts = date_Get(&sys->pts);
date_Increment(&sys->pts, block->i_nb_samples);
es_out_Send(demux->out, sys->es, block);
- es_out_SetPCR(demux->out, VLC_TS_0 + date_Get(&sys->pts));
+ es_out_SetPCR(demux->out, date_Get(&sys->pts));
return VLC_DEMUXER_SUCCESS;
}
@@ -254,6 +254,7 @@ static int DemuxOpen(vlc_object_t *obj, vcddev_t *dev, unsigned track)
sys->es = es_out_Add(demux->out, &fmt);
date_Init(&sys->pts, 44100, 1);
+ date_Set(&sys->pts, VLC_TS_0);
sys->position = 0;
demux->pf_demux = Demux;
diff --git a/modules/access/jack.c b/modules/access/jack.c
index 94d4c4e451..86dfc2f77c 100644
--- a/modules/access/jack.c
+++ b/modules/access/jack.c
@@ -290,6 +290,7 @@ static int Open( vlc_object_t *p_this )
p_sys->p_es_audio = es_out_Add( p_demux->out, &fmt );
date_Init( &p_sys->pts, fmt.audio.i_rate, 1 );
+ date_Set( &p_sys->pts, 0 );
return VLC_SUCCESS;
}
@@ -463,7 +464,7 @@ static block_t *GrabJack( demux_t *p_demux )
i_read = jack_ringbuffer_read( p_sys->p_jack_ringbuffer, ( char * ) p_block->p_buffer, i_read );
- p_block->i_dts = p_block->i_pts = VLC_TS_0 + date_Increment( &p_sys->pts,
+ p_block->i_dts = p_block->i_pts = date_Increment( &p_sys->pts,
i_read/(p_sys->i_channels * p_sys->jack_sample_size) );
p_sys->p_block_audio = p_block;
diff --git a/modules/access/qtsound.m b/modules/access/qtsound.m
index 9a16bb0a9e..2caa244056 100644
--- a/modules/access/qtsound.m
+++ b/modules/access/qtsound.m
@@ -97,6 +97,7 @@ vlc_module_end ()
p_qtsound = p_demux;
currentAudioBuffer = nil;
date_Init(&date, 44100, 1);
+ date_Set(&date, 0);
currentPts = 0;
previousPts = 0;
}
@@ -116,7 +117,7 @@ vlc_module_end ()
@synchronized (self) {
numberOfSamples = [sampleBuffer numberOfSamples];
date_Increment(&date,numberOfSamples);
- currentPts = VLC_TS_0 + date_Get(&date);
+ currentPts = date_Get(&date);
tempAudioBufferList = [sampleBuffer audioBufferListWithOptions:0];
if (tempAudioBufferList->mNumberBuffers == 2) {
diff --git a/modules/access/timecode.c b/modules/access/timecode.c
index adbd0f50e9..551a2e010c 100644
--- a/modules/access/timecode.c
+++ b/modules/access/timecode.c
@@ -65,7 +65,7 @@ static int DemuxOnce (demux_t *demux, bool master)
lldiv_t d;
unsigned h, m, s, f;
- d = lldiv (pts, CLOCK_FREQ);
+ d = lldiv (pts - VLC_TS_0, CLOCK_FREQ);
f = d.rem * sys->date.i_divider_num / sys->date.i_divider_den / CLOCK_FREQ;
d = lldiv (d.quot, 60);
s = d.rem;
diff --git a/modules/codec/adpcm.c b/modules/codec/adpcm.c
index f478d235c5..fea140bd4b 100644
--- a/modules/codec/adpcm.c
+++ b/modules/codec/adpcm.c
@@ -270,7 +270,6 @@ static int OpenDecoder( vlc_object_t *p_this )
p_dec->fmt_out.audio.i_physical_channels = vlc_chan_maps[i_channels];
date_Init( &p_sys->end_date, p_dec->fmt_out.audio.i_rate, 1 );
- date_Set( &p_sys->end_date, VLC_TS_INVALID );
p_dec->pf_decode = DecodeAudio;
p_dec->pf_flush = Flush;
diff --git a/modules/codec/aes3.c b/modules/codec/aes3.c
index 6acff6511e..d4873870df 100644
--- a/modules/codec/aes3.c
+++ b/modules/codec/aes3.c
@@ -279,7 +279,6 @@ static int Open( decoder_t *p_dec, bool b_packetizer )
/* Misc init */
date_Init( &p_sys->end_date, 48000, 1 );
- date_Set( &p_sys->end_date, VLC_TS_INVALID );
/* Set output properties */
p_dec->fmt_out.audio.i_rate = 48000;
diff --git a/modules/codec/araw.c b/modules/codec/araw.c
index 53a361e8e0..2a8f35abee 100644
--- a/modules/codec/araw.c
+++ b/modules/codec/araw.c
@@ -289,7 +289,6 @@ static int DecoderOpen( vlc_object_t *p_this )
assert( p_sys->framebits );
date_Init( &p_sys->end_date, p_dec->fmt_out.audio.i_rate, 1 );
- date_Set( &p_sys->end_date, VLC_TS_INVALID );
p_dec->pf_decode = DecodeBlock;
p_dec->pf_flush = Flush;
diff --git a/modules/codec/audiotoolbox_midi.c b/modules/codec/audiotoolbox_midi.c
index 7d96e12716..a1edee031a 100644
--- a/modules/codec/audiotoolbox_midi.c
+++ b/modules/codec/audiotoolbox_midi.c
@@ -278,7 +278,6 @@ static int Open(vlc_object_t *p_this)
// Initialize date (for PTS)
date_Init(&p_sys->end_date, p_dec->fmt_out.audio.i_rate, 1);
- date_Set(&p_sys->end_date, VLC_TS_INVALID);
p_dec->p_sys = p_sys;
p_dec->pf_decode = DecodeBlock;
diff --git a/modules/codec/avcodec/audio.c b/modules/codec/avcodec/audio.c
index 880a329b26..e05911a28e 100644
--- a/modules/codec/avcodec/audio.c
+++ b/modules/codec/avcodec/audio.c
@@ -251,7 +251,6 @@ int InitAudioDec( vlc_object_t *obj )
/* Try to set as much information as possible but do not trust it */
SetupOutputFormat( p_dec, false );
- date_Set( &p_sys->end_date, VLC_TS_INVALID );
if( !p_dec->fmt_out.audio.i_rate )
p_dec->fmt_out.audio.i_rate = p_dec->fmt_in.audio.i_rate;
if( p_dec->fmt_out.audio.i_rate )
diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c
index 87fff6d3c7..8f9408a221 100644
--- a/modules/codec/avcodec/encoder.c
+++ b/modules/codec/avcodec/encoder.c
@@ -727,7 +727,6 @@ int InitVideoEnc( vlc_object_t *p_this )
p_context->sample_rate = p_enc->fmt_out.audio.i_rate;
date_Init( &p_sys->buffer_date, p_enc->fmt_out.audio.i_rate, 1 );
- date_Set( &p_sys->buffer_date, AV_NOPTS_VALUE );
p_context->time_base.num = 1;
p_context->time_base.den = p_context->sample_rate;
p_context->channels = p_enc->fmt_out.audio.i_channels;
@@ -1266,11 +1265,15 @@ static block_t *handle_delay_buffer( encoder_t *p_enc, encoder_sys_t *p_sys, uns
p_sys->frame->format = p_sys->p_context->sample_fmt;
p_sys->frame->nb_samples = leftover_samples + p_sys->i_samples_delay;
- p_sys->frame->pts = date_Get( &p_sys->buffer_date ) * p_sys->p_context->time_base.den /
- CLOCK_FREQ / p_sys->p_context->time_base.num;
-
- if( likely( p_sys->frame->pts != AV_NOPTS_VALUE) )
+ if( likely( date_Get( &p_sys->buffer_date ) != VLC_TS_INVALID) )
+ {
+ /* Convert to AV timing */
+ p_sys->frame->pts = date_Get( &p_sys->buffer_date ) - VLC_TS_0;
+ p_sys->frame->pts = p_sys->frame->pts * p_sys->p_context->time_base.den /
+ CLOCK_FREQ / p_sys->p_context->time_base.num;
date_Increment( &p_sys->buffer_date, p_sys->frame->nb_samples );
+ }
+ else p_sys->frame->pts = AV_NOPTS_VALUE;
if( likely( p_aout_buf ) )
{
@@ -1287,8 +1290,7 @@ static block_t *handle_delay_buffer( encoder_t *p_enc, encoder_sys_t *p_sys, uns
p_aout_buf->p_buffer += leftover;
p_aout_buf->i_buffer -= leftover;
- if( likely( p_sys->frame->pts != AV_NOPTS_VALUE) )
- p_aout_buf->i_pts = date_Get( &p_sys->buffer_date );
+ p_aout_buf->i_pts = date_Get( &p_sys->buffer_date );
}
if(unlikely( ( (leftover + buffer_delay) < p_sys->i_buffer_out ) &&
@@ -1391,8 +1393,14 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_aout_buf )
else
p_sys->frame->nb_samples = p_sys->i_frame_size;
p_sys->frame->format = p_sys->p_context->sample_fmt;
- p_sys->frame->pts = date_Get( &p_sys->buffer_date ) * p_sys->p_context->time_base.den /
- CLOCK_FREQ / p_sys->p_context->time_base.num;
+ if( likely(date_Get( &p_sys->buffer_date ) != VLC_TS_INVALID) )
+ {
+ /* Convert to AV timing */
+ p_sys->frame->pts = date_Get( &p_sys->buffer_date ) - VLC_TS_0;
+ p_sys->frame->pts = p_sys->frame->pts * p_sys->p_context->time_base.den /
+ CLOCK_FREQ / p_sys->p_context->time_base.num;
+ }
+ else p_sys->frame->pts = AV_NOPTS_VALUE;
const int in_bytes = p_sys->frame->nb_samples *
p_sys->p_context->channels * p_sys->i_sample_bytes;
@@ -1421,7 +1429,7 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_aout_buf )
p_aout_buf->p_buffer += in_bytes;
p_aout_buf->i_buffer -= in_bytes;
p_aout_buf->i_nb_samples -= p_sys->frame->nb_samples;
- if( likely( p_sys->frame->pts != AV_NOPTS_VALUE) )
+ if( likely(date_Get( &p_sys->buffer_date ) != VLC_TS_INVALID) )
date_Increment( &p_sys->buffer_date, p_sys->frame->nb_samples );
p_block = encode_avframe( p_enc, p_sys, p_sys->frame );
diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index d171b4f5f3..f58af6545e 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -614,7 +614,6 @@ int InitVideoDec( vlc_object_t *obj )
/* ***** misc init ***** */
date_Init(&p_sys->pts, 1, 30001);
- date_Set(&p_sys->pts, VLC_TS_INVALID);
p_sys->b_first_frame = true;
p_sys->i_late_frames = 0;
p_sys->b_from_preroll = false;
diff --git a/modules/codec/dmo/dmo.c b/modules/codec/dmo/dmo.c
index fbb00bfa8b..baa9f3afca 100644
--- a/modules/codec/dmo/dmo.c
+++ b/modules/codec/dmo/dmo.c
@@ -597,6 +597,7 @@ static int DecOpen( decoder_t *p_dec )
date_Init( &p_sys->end_date, p_dec->fmt_in.audio.i_rate, 1 );
else
date_Init( &p_sys->end_date, 25 /* FIXME */, 1 );
+ date_Set( &p_sys->end_date, VLC_TS_0 );
free( p_vih );
free( p_wf );
diff --git a/modules/codec/faad.c b/modules/codec/faad.c
index e3c9e0405f..5b9afc4dfb 100644
--- a/modules/codec/faad.c
+++ b/modules/codec/faad.c
@@ -128,8 +128,6 @@ static int Open( vlc_object_t *p_this )
}
/* Misc init */
- date_Set( &p_sys->date, 0 );
-
p_dec->fmt_out.audio.channel_type = p_dec->fmt_in.audio.channel_type;
if( p_dec->fmt_in.i_extra > 0 )
@@ -160,6 +158,7 @@ static int Open( vlc_object_t *p_this )
/* Will be initalised from first frame */
p_dec->fmt_out.audio.i_rate = 0;
p_dec->fmt_out.audio.i_channels = 0;
+ date_Set( &p_sys->date, VLC_TS_INVALID );
}
p_dec->fmt_out.i_codec = HAVE_FPU ? VLC_CODEC_FL32 : VLC_CODEC_S16N;
@@ -321,7 +320,7 @@ static int DecodeBlock( decoder_t *p_dec, block_t *p_block )
{
date_Set( &p_sys->date, i_pts );
}
- else if( !date_Get( &p_sys->date ) )
+ else if( date_Get( &p_sys->date ) == VLC_TS_INVALID )
{
/* We've just started the stream, wait for the first PTS. */
FlushBuffer( p_sys, SIZE_MAX );
diff --git a/modules/codec/flac.c b/modules/codec/flac.c
index 9142bf51c8..aca1cae9bf 100644
--- a/modules/codec/flac.c
+++ b/modules/codec/flac.c
@@ -326,7 +326,6 @@ static void DecoderMetadataCallback( const FLAC__StreamDecoder *decoder,
p_sys->stream_info = metadata->data.stream_info;
date_Init( &p_sys->end_date, p_dec->fmt_out.audio.i_rate, 1 );
- date_Set( &p_sys->end_date, VLC_TS_INVALID );
break;
case FLAC__METADATA_TYPE_VORBIS_COMMENT:
@@ -628,7 +627,7 @@ static void Flush( decoder_t *p_dec )
if( p_sys->b_stream_info )
FLAC__stream_decoder_flush( p_sys->p_flac );
- date_Set( &p_sys->end_date, 0 );
+ date_Set( &p_sys->end_date, VLC_TS_INVALID );
}
/****************************************************************************
diff --git a/modules/codec/fluidsynth.c b/modules/codec/fluidsynth.c
index 41f597946f..61726c5343 100644
--- a/modules/codec/fluidsynth.c
+++ b/modules/codec/fluidsynth.c
@@ -174,7 +174,6 @@ static int Open (vlc_object_t *p_this)
p_dec->fmt_out.i_codec = VLC_CODEC_FL32;
p_dec->fmt_out.audio.i_bitspersample = 32;
date_Init (&p_sys->end_date, p_dec->fmt_out.audio.i_rate, 1);
- date_Set(&p_sys->end_date, VLC_TS_INVALID);
p_dec->p_sys = p_sys;
p_dec->pf_decode = DecodeBlock;
diff --git a/modules/codec/g711.c b/modules/codec/g711.c
index 0b4c2e85c2..904f24d420 100644
--- a/modules/codec/g711.c
+++ b/modules/codec/g711.c
@@ -202,7 +202,6 @@ static int DecoderOpen( vlc_object_t *p_this )
p_sys->table = table;
date_Init( &p_sys->end_date, p_dec->fmt_out.audio.i_rate, 1 );
- date_Set( &p_sys->end_date, VLC_TS_INVALID );
return VLC_SUCCESS;
}
diff --git a/modules/codec/lpcm.c b/modules/codec/lpcm.c
index f6b394a157..bb92b13365 100644
--- a/modules/codec/lpcm.c
+++ b/modules/codec/lpcm.c
@@ -252,7 +252,7 @@ static int OpenCommon( decoder_t *p_dec, bool b_packetizer )
/* Misc init */
p_sys->b_packetizer = b_packetizer;
- date_Set( &p_sys->end_date, 0 );
+ date_Set( &p_sys->end_date, VLC_TS_INVALID );
p_sys->i_type = i_type;
p_sys->i_header_size = i_header_size;
p_sys->i_chans_to_reorder = 0;
@@ -317,7 +317,7 @@ static void Flush( decoder_t *p_dec )
{
decoder_sys_t *p_sys = p_dec->p_sys;
- date_Set( &p_sys->end_date, 0 );
+ date_Set( &p_sys->end_date, VLC_TS_INVALID );
}
/*****************************************************************************
diff --git a/modules/codec/mpg123.c b/modules/codec/mpg123.c
index fdfcb8f2ba..9011626d9e 100644
--- a/modules/codec/mpg123.c
+++ b/modules/codec/mpg123.c
@@ -190,7 +190,6 @@ static int UpdateAudioFormat( decoder_t *p_dec )
{
p_dec->fmt_out.audio.i_rate = (unsigned int)frame_info.rate;
date_Init( &p_sys->end_date, p_dec->fmt_out.audio.i_rate, 1 );
- date_Set( &p_sys->end_date, VLC_TS_INVALID );
}
return decoder_UpdateAudioFormat( p_dec );
diff --git a/modules/codec/omxil/omxil.c b/modules/codec/omxil/omxil.c
index 92f7c1d258..2673d5feee 100644
--- a/modules/codec/omxil/omxil.c
+++ b/modules/codec/omxil/omxil.c
@@ -1471,7 +1471,7 @@ int DecodeAudio ( decoder_t *p_dec, block_t *p_block )
if( p_block->i_flags & BLOCK_FLAG_CORRUPTED )
{
block_Release( p_block );
- date_Set( &p_sys->end_date, 0 );
+ date_Set( &p_sys->end_date, VLC_TS_INVALID );
if(!p_sys->in.b_flushed)
{
msg_Dbg(p_dec, "flushing");
diff --git a/modules/codec/opus.c b/modules/codec/opus.c
index ae55db5c73..9597e215cc 100644
--- a/modules/codec/opus.c
+++ b/modules/codec/opus.c
@@ -179,7 +179,7 @@ static int OpenDecoder( vlc_object_t *p_this )
return VLC_ENOMEM;
p_sys->b_has_headers = false;
- date_Set( &p_sys->end_date, 0 );
+ date_Set( &p_sys->end_date, VLC_TS_INVALID );
/* Set output properties */
p_dec->fmt_out.i_codec = VLC_CODEC_FL32;
@@ -386,7 +386,7 @@ static void Flush( decoder_t *p_dec )
{
decoder_sys_t *p_sys = p_dec->p_sys;
- date_Set( &p_sys->end_date, 0 );
+ date_Set( &p_sys->end_date, VLC_TS_INVALID );
}
/*****************************************************************************
diff --git a/modules/codec/schroedinger.c b/modules/codec/schroedinger.c
index cd64dd8331..bba878421d 100644
--- a/modules/codec/schroedinger.c
+++ b/modules/codec/schroedinger.c
@@ -907,8 +907,8 @@ typedef struct
block_t *p_chain;
struct picture_pts_t pts_tlb[SCHRO_PTS_TLB_SIZE];
- mtime_t i_pts_offset;
- mtime_t i_field_time;
+ unsigned i_pts_offset;
+ unsigned i_field_duration;
bool b_eos_signalled;
bool b_eos_pulled;
@@ -1455,16 +1455,17 @@ static block_t *Encode( encoder_t *p_enc, picture_t *p_pic )
}
}
- date_Init( &date, p_enc->fmt_in.video.i_frame_rate, p_enc->fmt_in.video.i_frame_rate_base );
+ date_Init( &date, p_enc->fmt_in.video.i_frame_rate * 2, p_enc->fmt_in.video.i_frame_rate_base );
+ date_Set( &date, VLC_TS_0 );
/* FIXME - Unlike dirac-research codec Schro doesn't have a function that returns the delay in pics yet.
* Use a default of 1
*/
- date_Increment( &date, 1 );
- p_sys->i_pts_offset = date_Get( &date );
+ date_Increment( &date, 2 /* 2 fields, 1 frame */ );
+ p_sys->i_pts_offset = date_Get( &date ) - VLC_TS_0;
if( schro_encoder_setting_get_double( p_sys->p_schro, "interlaced_coding" ) > 0.0 ) {
- date_Set( &date, 0 );
- date_Increment( &date, 1);
- p_sys->i_field_time = date_Get( &date ) / 2;
+ date_Set( &date, VLC_TS_0 );
+ date_Increment( &date, 1 /* field */ );
+ p_sys->i_field_duration = date_Get( &date ) - VLC_TS_0;
}
schro_video_format_set_std_signal_range( p_sys->p_format, SCHRO_SIGNAL_RANGE_8BIT_VIDEO );
@@ -1503,13 +1504,13 @@ static block_t *Encode( encoder_t *p_enc, picture_t *p_pic )
* pts lookaside buffer and dts queue, offset to correspond
* to a one field delay. */
if( schro_encoder_setting_get_double( p_sys->p_schro, "interlaced_coding" ) > 0.0 ) {
- StorePicturePTS( p_enc, p_sys->i_input_picnum, p_pic->date + p_sys->i_field_time );
+ StorePicturePTS( p_enc, p_sys->i_input_picnum, p_pic->date + p_sys->i_field_duration );
p_sys->i_input_picnum++;
p_block = block_Alloc( 1 );
if( !p_block )
return NULL;
- p_block->i_dts = p_pic->date - p_sys->i_pts_offset + p_sys->i_field_time;
+ p_block->i_dts = p_pic->date - p_sys->i_pts_offset + p_sys->i_field_duration;
block_FifoPut( p_sys->p_dts_fifo, p_block );
p_block = NULL;
}
diff --git a/modules/codec/speex.c b/modules/codec/speex.c
index bcb692260c..bf3f0d5620 100644
--- a/modules/codec/speex.c
+++ b/modules/codec/speex.c
@@ -210,7 +210,7 @@ static int OpenDecoder( vlc_object_t *p_this )
p_sys->rtp_rate = p_dec->fmt_in.audio.i_rate;
p_sys->b_has_headers = false;
- date_Set( &p_sys->end_date, 0 );
+ date_Set( &p_sys->end_date, VLC_TS_INVALID );
/* Set output properties */
p_dec->fmt_out.i_codec = VLC_CODEC_S16N;
@@ -554,7 +554,7 @@ static void Flush( decoder_t *p_dec )
{
decoder_sys_t *p_sys = p_dec->p_sys;
- date_Set( &p_sys->end_date, 0 );
+ date_Set( &p_sys->end_date, VLC_TS_INVALID );
}
/*****************************************************************************
diff --git a/modules/codec/uleaddvaudio.c b/modules/codec/uleaddvaudio.c
index ac73ce3e31..7e3917d669 100644
--- a/modules/codec/uleaddvaudio.c
+++ b/modules/codec/uleaddvaudio.c
@@ -58,7 +58,7 @@ static void Flush(decoder_t *dec)
{
decoder_sys_t *sys = dec->p_sys;
- date_Set(&sys->end_date, 0);
+ date_Set(&sys->end_date, VLC_TS_INVALID);
}
static block_t *DecodeBlock(decoder_t *dec, block_t **block_ptr)
@@ -155,7 +155,6 @@ static int Open(vlc_object_t *object)
sys->is_12bit = dec->fmt_in.audio.i_bitspersample == 12;
date_Init(&sys->end_date, dec->fmt_in.audio.i_rate, 1);
- date_Set(&sys->end_date, 0);
for (unsigned i = 0; i < sizeof(sys->shuffle) / sizeof(*sys->shuffle); i++) {
const unsigned a = sys->is_pal ? 18 : 15;
diff --git a/modules/codec/vorbis.c b/modules/codec/vorbis.c
index 2689bca54f..a1577d652c 100644
--- a/modules/codec/vorbis.c
+++ b/modules/codec/vorbis.c
@@ -244,7 +244,7 @@ static int OpenDecoder( vlc_object_t *p_this )
return VLC_ENOMEM;
/* Misc init */
- date_Set( &p_sys->end_date, 0 );
+ date_Set( &p_sys->end_date, VLC_TS_INVALID );
p_sys->i_last_block_size = 0;
p_sys->b_packetizer = false;
p_sys->b_has_headers = false;
@@ -455,7 +455,7 @@ static void Flush( decoder_t *p_dec )
{
decoder_sys_t *p_sys = p_dec->p_sys;
- date_Set( &p_sys->end_date, 0 );
+ date_Set( &p_sys->end_date, VLC_TS_INVALID );
}
/*****************************************************************************
diff --git a/modules/demux/cdg.c b/modules/demux/cdg.c
index d682d6f4b8..cc6af125fc 100644
--- a/modules/demux/cdg.c
+++ b/modules/demux/cdg.c
@@ -100,6 +100,7 @@ static int Open( vlc_object_t * p_this )
/* There is CDG_FRAME_RATE frames per second */
date_Init( &p_sys->pts, CDG_FRAME_RATE, 1 );
+ date_Set( &p_sys->pts, VLC_TS_0 );
p_demux->pf_demux = Demux;
p_demux->pf_control = Control;
@@ -132,12 +133,12 @@ static int Demux( demux_t *p_demux )
if( i_date >= date_Get( &p_sys->pts ) + i_delta )
{
p_block->i_dts = p_block->i_pts = VLC_TS_0 + i_date;
- date_Set( &p_sys->pts, i_date );
+ date_Set( &p_sys->pts, VLC_TS_0 + i_date );
}
else
{
p_block->i_dts = VLC_TS_0 + i_date;
- p_block->i_pts = VLC_TS_0 + date_Get( &p_sys->pts );
+ p_block->i_pts = date_Get( &p_sys->pts );
}
es_out_SetPCR( p_demux->out, p_block->i_pts );
diff --git a/modules/demux/gme.c b/modules/demux/gme.c
index 07a38048f4..52adad0196 100644
--- a/modules/demux/gme.c
+++ b/modules/demux/gme.c
@@ -130,6 +130,7 @@ static int Open (vlc_object_t *obj)
sys->es = es_out_Add (demux->out, &fmt);
date_Init (&sys->pts, RATE, 1);
+ date_Set(&sys->pts, VLC_TS_0);
/* Titles */
unsigned n = gme_track_count (sys->emu);
@@ -228,7 +229,7 @@ static int Demux (demux_t *demux)
return VLC_DEMUXER_EOF;
}
- block->i_pts = block->i_dts = VLC_TS_0 + date_Get (&sys->pts);
+ block->i_pts = block->i_dts = date_Get (&sys->pts);
es_out_SetPCR (demux->out, block->i_pts);
es_out_Send (demux->out, sys->es, block);
date_Increment (&sys->pts, SAMPLES);
diff --git a/modules/demux/image.c b/modules/demux/image.c
index b2befd1a31..0e8586e74f 100644
--- a/modules/demux/image.c
+++ b/modules/demux/image.c
@@ -104,7 +104,7 @@ typedef struct
es_out_id_t *es;
mtime_t duration;
bool is_realtime;
- mtime_t pts_origin;
+ int64_t pts_offset;
mtime_t pts_next;
date_t pts;
} demux_sys_t;
@@ -191,7 +191,7 @@ static int Demux(demux_t *demux)
return VLC_DEMUXER_EOF;
mtime_t deadline;
- const mtime_t pts_first = sys->pts_origin + date_Get(&sys->pts);
+ const mtime_t pts_first = sys->pts_offset + date_Get(&sys->pts);
if (sys->pts_next != VLC_TS_INVALID) {
deadline = sys->pts_next;
} else if (sys->is_realtime) {
@@ -208,8 +208,8 @@ static int Demux(demux_t *demux)
}
for (;;) {
- const mtime_t pts = sys->pts_origin + date_Get(&sys->pts);
- if (sys->duration >= 0 && pts >= sys->pts_origin + sys->duration)
+ const mtime_t pts = sys->pts_offset + date_Get(&sys->pts);
+ if (sys->duration >= 0 && pts >= VLC_TS_0 + sys->pts_offset + sys->duration)
return VLC_DEMUXER_EOF;
if (pts >= deadline)
@@ -256,20 +256,20 @@ static int Control(demux_t *demux, int query, va_list args)
}
case DEMUX_GET_TIME: {
int64_t *time = va_arg(args, int64_t *);
- *time = sys->pts_origin + date_Get(&sys->pts);
+ *time = sys->pts_offset + date_Get(&sys->pts);
return VLC_SUCCESS;
}
case DEMUX_SET_TIME: {
if (sys->duration < 0 || sys->is_realtime)
return VLC_EGENERIC;
int64_t time = va_arg(args, int64_t);
- date_Set(&sys->pts, VLC_CLIP(time - sys->pts_origin, 0, sys->duration));
+ date_Set(&sys->pts, VLC_CLIP(time - sys->pts_offset, VLC_TS_0, sys->duration));
return VLC_SUCCESS;
}
case DEMUX_SET_NEXT_DEMUX_TIME: {
mtime_t pts_next = VLC_TS_0 + va_arg(args, mtime_t);
if (sys->pts_next == VLC_TS_INVALID)
- sys->pts_origin = pts_next;
+ sys->pts_offset = pts_next - VLC_TS_0;
sys->pts_next = pts_next;
return VLC_SUCCESS;
}
@@ -733,10 +733,10 @@ static int Open(vlc_object_t *object)
sys->es = es_out_Add(demux->out, &fmt);
sys->duration = CLOCK_FREQ * var_InheritFloat(demux, "image-duration");
sys->is_realtime = var_InheritBool(demux, "image-realtime");
- sys->pts_origin = sys->is_realtime ? mdate() : 0;
+ sys->pts_offset = sys->is_realtime ? mdate() : 0;
sys->pts_next = VLC_TS_INVALID;
date_Init(&sys->pts, fmt.video.i_frame_rate, fmt.video.i_frame_rate_base);
- date_Set(&sys->pts, 0);
+ date_Set(&sys->pts, VLC_TS_0);
es_format_Clean(&fmt);
diff --git a/modules/demux/mod.c b/modules/demux/mod.c
index 644506037b..5f685094ad 100644
--- a/modules/demux/mod.c
+++ b/modules/demux/mod.c
@@ -217,7 +217,7 @@ static int Open( vlc_object_t *p_this )
/* init time */
date_Init( &p_sys->pts, settings.mFrequency, 1 );
- date_Set( &p_sys->pts, 0 );
+ date_Set( &p_sys->pts, VLC_TS_0 );
p_sys->i_length = ModPlug_GetLength( p_sys->f ) * INT64_C(1000);
msg_Dbg( p_demux, "MOD loaded name=%s length=%"PRId64"ms",
@@ -277,7 +277,7 @@ static int Demux( demux_t *p_demux )
}
p_frame->i_buffer = i_read;
p_frame->i_dts =
- p_frame->i_pts = VLC_TS_0 + date_Get( &p_sys->pts );
+ p_frame->i_pts = date_Get( &p_sys->pts );
es_out_SetPCR( p_demux->out, p_frame->i_pts );
es_out_Send( p_demux->out, p_sys->es, p_frame );
@@ -304,7 +304,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
pf = va_arg( args, double* );
if( p_sys->i_length > 0 )
{
- double current = date_Get( &p_sys->pts );
+ double current = date_Get( &p_sys->pts ) - VLC_TS_0;
double length = p_sys->i_length;
*pf = current / length;
return VLC_SUCCESS;
@@ -318,7 +318,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
if( i64 >= 0 && i64 <= p_sys->i_length )
{
ModPlug_Seek( p_sys->f, i64 / 1000 );
- date_Set( &p_sys->pts, i64 );
+ date_Set( &p_sys->pts, VLC_TS_0 + i64 );
return VLC_SUCCESS;
}
@@ -340,7 +340,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
if( i64 >= 0 && i64 <= p_sys->i_length )
{
ModPlug_Seek( p_sys->f, i64 / 1000 );
- date_Set( &p_sys->pts, i64 );
+ date_Set( &p_sys->pts, VLC_TS_0 + i64 );
return VLC_SUCCESS;
}
diff --git a/modules/demux/rawaud.c b/modules/demux/rawaud.c
index 3fbe034f1b..6a2b2fbe69 100644
--- a/modules/demux/rawaud.c
+++ b/modules/demux/rawaud.c
@@ -208,6 +208,7 @@ static int Open( vlc_object_t * p_this )
/* initialize timing */
date_Init( &p_sys->pts, p_sys->fmt.audio.i_rate, 1 );
+ date_Set( &p_sys->pts, VLC_TS_0 );
/* calculate 50ms frame size/time */
p_sys->i_frame_samples = __MAX( p_sys->fmt.audio.i_rate / 20, 1 );
@@ -247,7 +248,7 @@ static int Demux( demux_t *p_demux )
if( p_block == NULL )
return VLC_DEMUXER_EOF;
- p_block->i_dts = p_block->i_pts = VLC_TS_0 + date_Get( &p_sys->pts );
+ p_block->i_dts = p_block->i_pts = date_Get( &p_sys->pts );
es_out_SetPCR( p_demux->out, p_block->i_pts );
es_out_Send( p_demux->out, p_sys->p_es, p_block );
diff --git a/modules/demux/rawvid.c b/modules/demux/rawvid.c
index bce8b2cf2f..be49f680de 100644
--- a/modules/demux/rawvid.c
+++ b/modules/demux/rawvid.c
@@ -341,6 +341,7 @@ valid:
u_fps_num, u_fps_den, 0);
date_Init( &p_sys->pcr, p_sys->fmt_video.video.i_frame_rate,
p_sys->fmt_video.video.i_frame_rate_base );
+ date_Set( &p_sys->pcr, VLC_TS_0 );
if( !p_sys->fmt_video.video.i_bits_per_pixel )
{
@@ -394,7 +395,7 @@ static int Demux( demux_t *p_demux )
mtime_t i_pcr = date_Get( &p_sys->pcr );
/* Call the pace control */
- es_out_SetPCR( p_demux->out, VLC_TS_0 + i_pcr );
+ es_out_SetPCR( p_demux->out, i_pcr );
if( p_sys->b_y4m )
{
@@ -417,7 +418,7 @@ static int Demux( demux_t *p_demux )
if( p_block == NULL )
return VLC_DEMUXER_EOF;
- p_block->i_dts = p_block->i_pts = VLC_TS_0 + i_pcr;
+ p_block->i_dts = p_block->i_pts = i_pcr;
es_out_Send( p_demux->out, p_sys->p_es_video, p_block );
date_Increment( &p_sys->pcr, 1 );
diff --git a/modules/demux/sid.cpp b/modules/demux/sid.cpp
index da0abc3b01..aa87462e94 100644
--- a/modules/demux/sid.cpp
+++ b/modules/demux/sid.cpp
@@ -166,6 +166,7 @@ static int Open (vlc_object_t *obj)
sys->es = es_out_Add (demux->out, &fmt);
date_Init (&sys->pts, fmt.audio.i_rate, 1);
+ date_Set(&sys->pts, VLC_TS_0);
sys->tune->selectSong (0);
result = (sys->player->load (sys->tune) >=0 );
@@ -220,7 +221,7 @@ static int Demux (demux_t *demux)
return VLC_DEMUXER_EOF;
}
block->i_buffer = i_read;
- block->i_pts = block->i_dts = VLC_TS_0 + date_Get (&sys->pts);
+ block->i_pts = block->i_dts = date_Get (&sys->pts);
es_out_SetPCR (demux->out, block->i_pts);
diff --git a/modules/demux/voc.c b/modules/demux/voc.c
index bf376e7c0f..9bb9e12927 100644
--- a/modules/demux/voc.c
+++ b/modules/demux/voc.c
@@ -117,6 +117,7 @@ static int Open( vlc_object_t * p_this )
p_sys->p_es = NULL;
date_Init( &p_sys->pts, 1, 1 );
+ date_Set( &p_sys->pts, VLC_TS_0 );
es_format_Init( &p_sys->fmt, AUDIO_ES, 0 );
p_demux->pf_demux = Demux;
diff --git a/modules/demux/wav.c b/modules/demux/wav.c
index 1a45525723..789bac08b5 100644
--- a/modules/demux/wav.c
+++ b/modules/demux/wav.c
@@ -428,6 +428,7 @@ static int Open( vlc_object_t * p_this )
goto error;
date_Init( &p_sys->pts, p_sys->fmt.audio.i_rate, 1 );
+ date_Set( &p_sys->pts, VLC_TS_0 );
return VLC_SUCCESS;
@@ -469,7 +470,7 @@ static int Demux( demux_t *p_demux )
}
p_block->i_dts =
- p_block->i_pts = VLC_TS_0 + date_Get( &p_sys->pts );
+ p_block->i_pts = date_Get( &p_sys->pts );
/* set PCR */
es_out_SetPCR( p_demux->out, p_block->i_pts );
diff --git a/modules/misc/stats.c b/modules/misc/stats.c
index 3b0b6593f2..f60a153ca0 100644
--- a/modules/misc/stats.c
+++ b/modules/misc/stats.c
@@ -149,8 +149,7 @@ static int Demux( demux_t *p_demux )
if( !p_block ) return 1;
- p_block->i_dts = p_block->i_pts =
- VLC_TS_0 + date_Increment( &p_sys->pts, kBufferSize );
+ p_block->i_dts = p_block->i_pts = date_Increment( &p_sys->pts, kBufferSize );
msg_Dbg( p_demux, "demux got %"PRId64" ms offset",
(mdate() - *(mtime_t *)p_block->p_buffer) / 1000 );
@@ -190,6 +189,7 @@ static int OpenDemux ( vlc_object_t *p_this )
return VLC_ENOMEM;
date_Init( &p_sys->pts, 1, 1 );
+ date_Set( &p_sys->pts, VLC_TS_0 );
es_format_Init( &p_sys->fmt, VIDEO_ES, VLC_FOURCC('s','t','a','t') );
p_sys->fmt.video.i_width = 720;
diff --git a/modules/packetizer/dts.c b/modules/packetizer/dts.c
index ddb0a0e919..12245c2bcb 100644
--- a/modules/packetizer/dts.c
+++ b/modules/packetizer/dts.c
@@ -77,7 +77,7 @@ static void PacketizeFlush( decoder_t *p_dec )
decoder_sys_t *p_sys = p_dec->p_sys;
p_sys->b_discontinuity = true;
- date_Set( &p_sys->end_date, 0 );
+ date_Set( &p_sys->end_date, VLC_TS_INVALID );
p_sys->i_state = STATE_NOSYNC;
block_BytestreamEmpty( &p_sys->bytestream );
}
@@ -352,7 +352,7 @@ static int Open( vlc_object_t *p_this )
/* Misc init */
p_sys->i_state = STATE_NOSYNC;
- date_Set( &p_sys->end_date, 0 );
+ date_Set( &p_sys->end_date, VLC_TS_INVALID );
p_sys->i_pts = VLC_TS_INVALID;
p_sys->b_date_set = false;
p_sys->b_discontinuity = false;
diff --git a/modules/packetizer/flac.c b/modules/packetizer/flac.c
index 09171193cb..6044042511 100644
--- a/modules/packetizer/flac.c
+++ b/modules/packetizer/flac.c
@@ -554,7 +554,6 @@ static int Open(vlc_object_t *p_this)
p_sys->i_next_block_flags = 0;
block_BytestreamInit(&p_sys->bytestream);
date_Init( &p_sys->pts, 1, 1 );
- date_Set( &p_sys->pts, VLC_TS_INVALID );
/* */
es_format_Copy(&p_dec->fmt_out, &p_dec->fmt_in);
diff --git a/modules/packetizer/h264.c b/modules/packetizer/h264.c
index 7a567b7a6a..4f8a97d0f6 100644
--- a/modules/packetizer/h264.c
+++ b/modules/packetizer/h264.c
@@ -372,7 +372,6 @@ static int Open( vlc_object_t *p_this )
p_sys->prevdatedpoc.pts = VLC_TS_INVALID;
date_Init( &p_sys->dts, 30000 * 2, 1001 );
- date_Set( &p_sys->dts, VLC_TS_INVALID );
/* Setup properties */
es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
diff --git a/modules/packetizer/hevc.c b/modules/packetizer/hevc.c
index 80ec727b81..d71a0bfe75 100644
--- a/modules/packetizer/hevc.c
+++ b/modules/packetizer/hevc.c
@@ -204,7 +204,6 @@ static int Open(vlc_object_t *p_this)
p_dec->fmt_in.video.i_frame_rate_base );
else
date_Init( &p_sys->dts, 2 * 30000, 1001 );
- date_Set( &p_sys->dts, VLC_TS_INVALID );
p_sys->pts = VLC_TS_INVALID;
p_sys->b_need_ts = true;
diff --git a/modules/packetizer/mlp.c b/modules/packetizer/mlp.c
index 365d483ed9..6f16e6c8c3 100644
--- a/modules/packetizer/mlp.c
+++ b/modules/packetizer/mlp.c
@@ -482,7 +482,6 @@ static int Open( vlc_object_t *p_this )
/* */
p_sys->i_state = STATE_NOSYNC;
date_Init( &p_sys->end_date, 1, 1 );
- date_Set( &p_sys->end_date, VLC_TS_INVALID );
block_BytestreamInit( &p_sys->bytestream );
p_sys->b_mlp = false;
diff --git a/modules/packetizer/mpeg4audio.c b/modules/packetizer/mpeg4audio.c
index 3814dda031..9237853a3e 100644
--- a/modules/packetizer/mpeg4audio.c
+++ b/modules/packetizer/mpeg4audio.c
@@ -293,7 +293,6 @@ static int OpenPacketizer(vlc_object_t *p_this)
date_Init(&p_sys->end_date, p_dec->fmt_out.audio.i_rate ?
p_dec->fmt_out.audio.i_rate : 48000, 1);
- date_Set(&p_sys->end_date, VLC_TS_INVALID);
/* Set callbacks */
p_dec->pf_packetize = Packetize;
diff --git a/modules/packetizer/mpegaudio.c b/modules/packetizer/mpegaudio.c
index acbf674676..ab01b5b5c4 100644
--- a/modules/packetizer/mpegaudio.c
+++ b/modules/packetizer/mpegaudio.c
@@ -630,7 +630,6 @@ static int Open( vlc_object_t *p_this )
/* Misc init */
p_sys->i_state = STATE_NOSYNC;
date_Init( &p_sys->end_date, 1, 1 );
- date_Set( &p_sys->end_date, VLC_TS_INVALID );
block_BytestreamInit( &p_sys->bytestream );
p_sys->i_pts = VLC_TS_INVALID;
p_sys->b_discontinuity = false;
diff --git a/modules/packetizer/mpegvideo.c b/modules/packetizer/mpegvideo.c
index 95d89e1853..318b3f7181 100644
--- a/modules/packetizer/mpegvideo.c
+++ b/modules/packetizer/mpegvideo.c
@@ -222,9 +222,7 @@ static int Open( vlc_object_t *p_this )
p_sys->i_dts =
p_sys->i_pts = VLC_TS_INVALID;
date_Init( &p_sys->dts, 30000, 1001 );
- date_Set( &p_sys->dts, VLC_TS_INVALID );
date_Init( &p_sys->prev_iframe_dts, 30000, 1001 );
- date_Set( &p_sys->prev_iframe_dts, VLC_TS_INVALID );
p_sys->i_frame_rate = 2 * 30000;
p_sys->i_frame_rate_base = 1001;
diff --git a/modules/video_filter/fps.c b/modules/video_filter/fps.c
index 689efc9632..43c967662d 100644
--- a/modules/video_filter/fps.c
+++ b/modules/video_filter/fps.c
@@ -169,7 +169,6 @@ static int Open( vlc_object_t *p_this)
date_Init( &p_sys->next_output_pts,
p_filter->fmt_out.video.i_frame_rate, p_filter->fmt_out.video.i_frame_rate_base );
- date_Set( &p_sys->next_output_pts, VLC_TS_INVALID );
p_sys->p_previous_pic = NULL;
p_filter->pf_video_filter = Filter;
diff --git a/src/misc/mtime.c b/src/misc/mtime.c
index 2087516957..8f835e91eb 100644
--- a/src/misc/mtime.c
+++ b/src/misc/mtime.c
@@ -78,7 +78,7 @@ char *secstotimestr( char *psz_buffer, int32_t i_seconds )
void date_Init( date_t *p_date, uint32_t i_divider_n, uint32_t i_divider_d )
{
- p_date->date = 0;
+ p_date->date = VLC_TS_INVALID;
p_date->i_divider_num = i_divider_n;
p_date->i_divider_den = i_divider_d;
p_date->i_remainder = 0;
@@ -94,6 +94,8 @@ void date_Change( date_t *p_date, uint32_t i_divider_n, uint32_t i_divider_d )
mtime_t date_Increment( date_t *p_date, uint32_t i_nb_samples )
{
+ if(unlikely(p_date->date == VLC_TS_INVALID))
+ return VLC_TS_INVALID;
assert( p_date->i_divider_num != 0 );
mtime_t i_dividend = i_nb_samples * CLOCK_FREQ * p_date->i_divider_den;
lldiv_t d = lldiv( i_dividend, p_date->i_divider_num );
@@ -114,6 +116,8 @@ mtime_t date_Increment( date_t *p_date, uint32_t i_nb_samples )
mtime_t date_Decrement( date_t *p_date, uint32_t i_nb_samples )
{
+ if(unlikely(p_date->date == VLC_TS_INVALID))
+ return VLC_TS_INVALID;
mtime_t i_dividend = (mtime_t)i_nb_samples * CLOCK_FREQ * p_date->i_divider_den;
p_date->date -= i_dividend / p_date->i_divider_num;
unsigned i_rem_adjust = i_dividend % p_date->i_divider_num;
More information about the vlc-commits
mailing list