[vlc-commits] modules: use vlc_tick_from_samples()

Steve Lhomme git at videolan.org
Thu Sep 20 16:16:09 CEST 2018


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Thu Sep 20 14:35:36 2018 +0200| [cc79f1f98f89465385c595f572eee9be1ce80c03] | committer: Steve Lhomme

modules: use vlc_tick_from_samples()

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=cc79f1f98f89465385c595f572eee9be1ce80c03
---

 modules/access/alsa.c                               |  4 ++--
 modules/access/dcp/dcp.cpp                          |  8 ++++----
 modules/access/linsys/linsys_hdsdi.c                |  4 ++--
 modules/access/linsys/linsys_sdi.c                  |  4 ++--
 modules/access/oss.c                                |  4 ++--
 modules/access/rtp/session.c                        |  4 ++--
 modules/audio_filter/channel_mixer/spatialaudio.cpp |  2 +-
 modules/audio_filter/resampler/soxr.c               |  2 +-
 modules/audio_filter/resampler/speex.c              |  2 +-
 modules/audio_filter/resampler/src.c                |  3 +--
 modules/audio_filter/resampler/ugly.c               |  3 +--
 modules/audio_output/alsa.c                         |  2 +-
 modules/audio_output/audiotrack.c                   |  2 +-
 modules/audio_output/auhal.c                        |  2 +-
 modules/audio_output/coreaudio_common.c             |  2 +-
 modules/audio_output/oss.c                          |  4 ++--
 modules/audio_output/sndio.c                        |  2 +-
 modules/audio_output/waveout.c                      |  2 +-
 modules/codec/cc.c                                  |  2 +-
 modules/codec/cea708.c                              |  4 ++--
 modules/codec/daala.c                               |  2 +-
 modules/codec/fdkaac.c                              | 18 ++++++++----------
 modules/codec/flac.c                                |  7 +++----
 modules/codec/kate.c                                |  3 +--
 modules/codec/opus.c                                | 10 +++++-----
 modules/codec/qsv.c                                 |  5 ++---
 modules/codec/speex.c                               | 10 +++++-----
 modules/codec/synchro.c                             |  4 ++--
 modules/codec/theora.c                              |  2 +-
 modules/codec/ttml/ttml.c                           |  2 +-
 modules/codec/ttml/ttml.h                           |  4 ++--
 modules/codec/twolame.c                             | 12 ++++++------
 modules/codec/vorbis.c                              |  8 ++++----
 modules/codec/x264.c                                |  6 +++---
 modules/codec/x265.c                                |  6 +++---
 modules/demux/aiff.c                                |  9 ++++-----
 modules/demux/au.c                                  |  5 ++---
 modules/demux/avformat/demux.c                      | 12 ++++++------
 modules/demux/caf.c                                 |  4 ++--
 modules/demux/dash/mp4/IndexReader.cpp              |  4 ++--
 modules/demux/flac.c                                |  2 +-
 modules/demux/mpc.c                                 |  6 +++---
 modules/demux/mpeg/mpeg4_iod.c                      |  3 ++-
 modules/demux/mpeg/ps.c                             |  8 ++++----
 modules/demux/mpeg/ts.c                             |  2 +-
 modules/demux/nsv.c                                 |  2 +-
 modules/demux/pva.c                                 |  2 +-
 modules/demux/vc1.c                                 |  6 +++---
 modules/hw/mmal/deinterlace.c                       |  4 ++--
 modules/hw/vaapi/filters.c                          |  2 +-
 modules/mux/mp4/mp4.c                               | 20 ++++++++++----------
 modules/mux/mpeg/ts.c                               |  6 +++---
 modules/mux/ogg.c                                   | 10 +++++-----
 modules/packetizer/flac.h                           |  4 ++--
 modules/packetizer/h264.c                           |  4 ++--
 modules/packetizer/mpeg4video.c                     |  8 ++++----
 modules/packetizer/vc1.c                            |  6 +++---
 modules/stream_filter/hds/hds.c                     |  4 +++-
 modules/stream_out/sdi/AES3Audio.cpp                |  2 +-
 modules/video_filter/deinterlace/common.c           |  2 +-
 modules/video_output/decklink.cpp                   |  2 +-
 61 files changed, 147 insertions(+), 153 deletions(-)

diff --git a/modules/access/alsa.c b/modules/access/alsa.c
index d6b8b98f9a..978d0475ad 100644
--- a/modules/access/alsa.c
+++ b/modules/access/alsa.c
@@ -222,12 +222,12 @@ static void *Thread (void *data)
         if (snd_pcm_delay (pcm, &delay))
             delay = 0;
         delay += frames;
-        pts -= (CLOCK_FREQ * delay) / sys->rate;
+        pts -= vlc_tick_from_samples(delay,  sys->rate);
 
         block->i_buffer = snd_pcm_frames_to_bytes (pcm, frames);
         block->i_nb_samples = frames;
         block->i_pts = pts;
-        block->i_length = (CLOCK_FREQ * frames) / sys->rate;
+        block->i_length = vlc_tick_from_samples(frames, sys->rate);
 
         es_out_SetPCR(demux->out, block->i_pts);
         es_out_Send (demux->out, sys->es, block);
diff --git a/modules/access/dcp/dcp.cpp b/modules/access/dcp/dcp.cpp
index b8f615237e..ae8b08b34a 100644
--- a/modules/access/dcp/dcp.cpp
+++ b/modules/access/dcp/dcp.cpp
@@ -703,8 +703,8 @@ static int Demux( demux_t *p_demux )
             goto error;
     }
 
-    p_video_frame->i_length = CLOCK_FREQ * p_sys->frame_rate_denom / p_sys->frame_rate_num;
-    p_video_frame->i_pts = CLOCK_FREQ * p_sys->frame_no * p_sys->frame_rate_denom / p_sys->frame_rate_num;
+    p_video_frame->i_length = vlc_tick_from_samples(p_sys->frame_rate_denom, p_sys->frame_rate_num);
+    p_video_frame->i_pts = vlc_tick_from_samples(p_sys->frame_no * p_sys->frame_rate_denom, p_sys->frame_rate_num);
 
     if( !p_sys->p_dcp->audio_reels.empty() )
     {
@@ -741,8 +741,8 @@ static int Demux( demux_t *p_demux )
                     p_sys->pi_chan_table, VLC_CODEC_S24L );
 
         p_audio_frame->i_buffer = AudioFrameBuff.Size();
-        p_audio_frame->i_length = CLOCK_FREQ * p_sys->frame_rate_denom / p_sys->frame_rate_num;
-        p_audio_frame->i_pts = CLOCK_FREQ * p_sys->frame_no * p_sys->frame_rate_denom / p_sys->frame_rate_num;
+        p_audio_frame->i_length = vlc_tick_from_samples(p_sys->frame_rate_denom, p_sys->frame_rate_num);
+        p_audio_frame->i_pts = vlc_tick_from_samples(p_sys->frame_no * p_sys->frame_rate_denom, p_sys->frame_rate_num);
         /* Video is the main pts */
         if ( p_audio_frame->i_pts != p_video_frame->i_pts ) {
             msg_Err( p_demux, "Audio and video frame pts are not in sync" );
diff --git a/modules/access/linsys/linsys_hdsdi.c b/modules/access/linsys/linsys_hdsdi.c
index 77536c32cf..a8a7b144bf 100644
--- a/modules/access/linsys/linsys_hdsdi.c
+++ b/modules/access/linsys/linsys_hdsdi.c
@@ -494,7 +494,7 @@ static int InitVideo( demux_t *p_demux )
     }
 
     p_sys->i_next_vdate = START_DATE;
-    p_sys->i_incr = CLOCK_FREQ * p_sys->i_frame_rate_base / p_sys->i_frame_rate;
+    p_sys->i_incr = vlc_tick_from_samples(p_sys->i_frame_rate_base, p_sys->i_frame_rate);
     p_sys->i_vblock_size = p_sys->i_width * p_sys->i_height * 3 / 2
                             + sizeof(struct block_extension_t);
 
@@ -543,7 +543,7 @@ static int InitAudio( demux_t *p_demux )
 
     p_sys->i_next_adate = START_DATE;
     p_sys->i_ablock_size = p_sys->i_sample_rate * 4 * p_sys->i_frame_rate_base / p_sys->i_frame_rate;
-    p_sys->i_aincr = CLOCK_FREQ * p_sys->i_ablock_size / (p_sys->i_sample_rate * 4);
+    p_sys->i_aincr = vlc_tick_from_samples(p_sys->i_ablock_size, p_sys->i_sample_rate * 4);
 
     return VLC_SUCCESS;
 }
diff --git a/modules/access/linsys/linsys_sdi.c b/modules/access/linsys/linsys_sdi.c
index 6e2b4a3fb8..632680eb29 100644
--- a/modules/access/linsys/linsys_sdi.c
+++ b/modules/access/linsys/linsys_sdi.c
@@ -426,7 +426,7 @@ static int StartDecode( demux_t *p_demux )
     char *psz_parser;
 
     p_sys->i_next_date = START_DATE;
-    p_sys->i_incr = CLOCK_FREQ * p_sys->i_frame_rate_base / p_sys->i_frame_rate;
+    p_sys->i_incr = vlc_tick_from_samples(p_sys->i_frame_rate_base, p_sys->i_frame_rate);
     p_sys->i_block_size = p_sys->i_width * p_sys->i_height * 3 / 2
                            + sizeof(struct block_extension_t);
     if( NewFrame( p_demux ) != VLC_SUCCESS )
@@ -929,7 +929,7 @@ static int DecodeAudio( demux_t *p_demux, sdi_audio_t *p_audio )
     if( unlikely( !p_block ) )
         return VLC_ENOMEM;
     p_block->i_dts = p_block->i_pts = p_sys->i_next_date
-        + (vlc_tick_t)p_audio->i_delay * CLOCK_FREQ / p_audio->i_rate;
+        + vlc_tick_from_samples(p_audio->i_delay, p_audio->i_rate);
     p_output = (int16_t *)p_block->p_buffer;
 
     if ( p_audio->i_left_samples == p_audio->i_nb_samples &&
diff --git a/modules/access/oss.c b/modules/access/oss.c
index c54ceb9eda..0f1211e8d9 100644
--- a/modules/access/oss.c
+++ b/modules/access/oss.c
@@ -317,8 +317,8 @@ static block_t* GrabAudio( demux_t *p_demux )
 
     /* Timestamp */
     p_block->i_pts = p_block->i_dts =
-        vlc_tick_now() - CLOCK_FREQ * (vlc_tick_t)i_correct /
-        2 / ( p_sys->b_stereo ? 2 : 1) / p_sys->i_sample_rate;
+        vlc_tick_now() - vlc_tick_from_samples(i_correct,
+                        2 * ( p_sys->b_stereo ? 2 : 1) * p_sys->i_sample_rate);
 
     return p_block;
 }
diff --git a/modules/access/rtp/session.c b/modules/access/rtp/session.c
index 49ba9efbe3..708ea61edf 100644
--- a/modules/access/rtp/session.c
+++ b/modules/access/rtp/session.c
@@ -433,7 +433,7 @@ bool rtp_dequeue (demux_t *demux, const rtp_session_t *session,
             vlc_tick_t deadline;
             const rtp_pt_t *pt = rtp_find_ptype (session, src, block, NULL);
             if (pt)
-                deadline = CLOCK_FREQ * 3 * src->jitter / pt->frequency;
+                deadline = vlc_tick_from_samples(3 * src->jitter, pt->frequency);
             else
                 deadline = 0; /* no jitter estimate with no frequency :( */
 
@@ -523,7 +523,7 @@ rtp_decode (demux_t *demux, const rtp_session_t *session, rtp_source_t *src)
      * Otherwise it would be impossible to compute consistent timestamps. */
     const uint32_t timestamp = rtp_timestamp (block);
     block->i_pts = src->ref_ntp
-       + CLOCK_FREQ * (int32_t)(timestamp - src->ref_rtp) / pt->frequency;
+       + vlc_tick_from_samples(timestamp - src->ref_rtp, pt->frequency);
     /* TODO: proper inter-medias/sessions sync (using RTCP-SR) */
     src->ref_ntp = block->i_pts;
     src->ref_rtp = timestamp;
diff --git a/modules/audio_filter/channel_mixer/spatialaudio.cpp b/modules/audio_filter/channel_mixer/spatialaudio.cpp
index 2ba5fe0383..755f1422d5 100644
--- a/modules/audio_filter/channel_mixer/spatialaudio.cpp
+++ b/modules/audio_filter/channel_mixer/spatialaudio.cpp
@@ -196,7 +196,7 @@ static block_t *Mix( filter_t *p_filter, block_t *p_buf )
     else
         p_out_buf->i_pts = p_sys->i_inputPTS;
     p_out_buf->i_dts = p_out_buf->i_pts;
-    p_out_buf->i_length = p_out_buf->i_nb_samples * CLOCK_FREQ / p_filter->fmt_in.audio.i_rate;
+    p_out_buf->i_length = vlc_tick_from_samples(p_out_buf->i_nb_samples, p_filter->fmt_in.audio.i_rate);
 
     float *p_dest = (float *)p_out_buf->p_buffer;
     const float *p_src = (float *)p_sys->inputSamples.data();
diff --git a/modules/audio_filter/resampler/soxr.c b/modules/audio_filter/resampler/soxr.c
index 06b5ab6096..7babe2aaee 100644
--- a/modules/audio_filter/resampler/soxr.c
+++ b/modules/audio_filter/resampler/soxr.c
@@ -257,7 +257,7 @@ SoXR_Resample( filter_t *p_filter, soxr_t soxr, block_t *p_in, size_t i_olen )
 
     p_out->i_buffer = i_odone * i_oframesize;
     p_out->i_nb_samples = i_odone;
-    p_out->i_length = i_odone * CLOCK_FREQ / p_filter->fmt_out.audio.i_rate;
+    p_out->i_length = vlc_tick_from_samples(i_odone, p_filter->fmt_out.audio.i_rate);
 
     if( p_in )
     {
diff --git a/modules/audio_filter/resampler/speex.c b/modules/audio_filter/resampler/speex.c
index 992d084719..eeefc4f4c4 100644
--- a/modules/audio_filter/resampler/speex.c
+++ b/modules/audio_filter/resampler/speex.c
@@ -156,7 +156,7 @@ static block_t *Resample (filter_t *filter, block_t *in)
     out->i_buffer = olen * framesize;
     out->i_nb_samples = olen;
     out->i_pts = in->i_pts;
-    out->i_length = olen * CLOCK_FREQ / filter->fmt_out.audio.i_rate;
+    out->i_length = vlc_tick_from_samples(olen, filter->fmt_out.audio.i_rate);
 error:
     block_Release (in);
     return out;
diff --git a/modules/audio_filter/resampler/src.c b/modules/audio_filter/resampler/src.c
index fda4e94b23..1254314b13 100644
--- a/modules/audio_filter/resampler/src.c
+++ b/modules/audio_filter/resampler/src.c
@@ -162,8 +162,7 @@ static block_t *Resample (filter_t *filter, block_t *in)
     out->i_buffer = src.output_frames_gen * framesize;
     out->i_nb_samples = src.output_frames_gen;
     out->i_pts = in->i_pts;
-    out->i_length = src.output_frames_gen * CLOCK_FREQ
-                  / filter->fmt_out.audio.i_rate;
+    out->i_length = vlc_tick_from_samples(src.output_frames_gen, filter->fmt_out.audio.i_rate);
 error:
     block_Release (in);
     return out;
diff --git a/modules/audio_filter/resampler/ugly.c b/modules/audio_filter/resampler/ugly.c
index 765284bb84..bd7d92aabb 100644
--- a/modules/audio_filter/resampler/ugly.c
+++ b/modules/audio_filter/resampler/ugly.c
@@ -111,8 +111,7 @@ static block_t *DoWork( filter_t * p_filter, block_t * p_in_buf )
     p_out_buf->i_nb_samples = i_out_nb;
     p_out_buf->i_buffer = i_out_nb * framesize;
     p_out_buf->i_pts = p_in_buf->i_pts;
-    p_out_buf->i_length = p_out_buf->i_nb_samples *
-        CLOCK_FREQ / p_filter->fmt_out.audio.i_rate;
+    p_out_buf->i_length = vlc_tick_from_samples(p_out_buf->i_nb_samples, p_filter->fmt_out.audio.i_rate);
 
     while( i_out_nb )
     {
diff --git a/modules/audio_output/alsa.c b/modules/audio_output/alsa.c
index cac211c18e..08067c1338 100644
--- a/modules/audio_output/alsa.c
+++ b/modules/audio_output/alsa.c
@@ -640,7 +640,7 @@ static int TimeGet (audio_output_t *aout, vlc_tick_t *restrict delay)
         msg_Err (aout, "cannot estimate delay: %s", snd_strerror (val));
         return -1;
     }
-    *delay = frames * CLOCK_FREQ / sys->rate;
+    *delay = vlc_tick_from_samples(frames, sys->rate);
     return 0;
 }
 
diff --git a/modules/audio_output/audiotrack.c b/modules/audio_output/audiotrack.c
index e2f83026c8..7ec6a3642c 100644
--- a/modules/audio_output/audiotrack.c
+++ b/modules/audio_output/audiotrack.c
@@ -502,7 +502,7 @@ check_exception( JNIEnv *env, audio_output_t *p_aout,
 static inline vlc_tick_t
 frames_to_us( aout_sys_t *p_sys, uint64_t i_nb_frames )
 {
-    return  i_nb_frames * CLOCK_FREQ / p_sys->fmt.i_rate;
+    return  vlc_tick_from_samples(i_nb_frames, p_sys->fmt.i_rate);
 }
 #define FRAMES_TO_US(x) frames_to_us( p_sys, (x) )
 
diff --git a/modules/audio_output/auhal.c b/modules/audio_output/auhal.c
index a9bf3af2f0..377c0f1b02 100644
--- a/modules/audio_output/auhal.c
+++ b/modules/audio_output/auhal.c
@@ -1609,7 +1609,7 @@ Start(audio_output_t *p_aout, audio_sample_format_t *restrict fmt)
     UInt32 i_latency_samples;
     AO_GET1PROP(p_sys->i_selected_dev, UInt32, &i_latency_samples,
                 kAudioDevicePropertyLatency, kAudioObjectPropertyScopeOutput);
-    vlc_tick_t i_latency_us = i_latency_samples * CLOCK_FREQ / fmt->i_rate;
+    vlc_tick_t i_latency_us = vlc_tick_from_samples(i_latency_samples, fmt->i_rate);
 
     /* Check for Digital mode or Analog output mode */
     if (do_spdif)
diff --git a/modules/audio_output/coreaudio_common.c b/modules/audio_output/coreaudio_common.c
index a5598c62a7..d790daf1cb 100644
--- a/modules/audio_output/coreaudio_common.c
+++ b/modules/audio_output/coreaudio_common.c
@@ -45,7 +45,7 @@ BytesToFrames(struct aout_sys_common *p_sys, size_t i_bytes)
 static inline vlc_tick_t
 FramesToUs(struct aout_sys_common *p_sys, uint64_t i_nb_frames)
 {
-    return i_nb_frames * CLOCK_FREQ / p_sys->i_rate;
+    return vlc_tick_from_samples(i_nb_frames, p_sys->i_rate);
 }
 
 static void
diff --git a/modules/audio_output/oss.c b/modules/audio_output/oss.c
index f46a74aad7..5e16255798 100644
--- a/modules/audio_output/oss.c
+++ b/modules/audio_output/oss.c
@@ -261,8 +261,8 @@ static int TimeGet (audio_output_t *aout, vlc_tick_t *restrict pts)
         return -1;
     }
 
-    *pts = (delay * CLOCK_FREQ * sys->format.i_frame_length)
-                        / (sys->format.i_rate * sys->format.i_bytes_per_frame);
+    *pts = vlc_tick_from_samples(delay * sys->format.i_frame_length,
+                        sys->format.i_rate * sys->format.i_bytes_per_frame);
     return 0;
 }
 
diff --git a/modules/audio_output/sndio.c b/modules/audio_output/sndio.c
index 0063a7feae..6b28772817 100644
--- a/modules/audio_output/sndio.c
+++ b/modules/audio_output/sndio.c
@@ -226,7 +226,7 @@ static int TimeGet (audio_output_t *aout, vlc_tick_t *restrict delay)
 
     if (!sys->started)
         return -1;
-    *delay = (vlc_tick_t)sys->delay * CLOCK_FREQ / sys->rate;
+    *delay = vlc_tick_from_samples(sys->delay, sys->rate);
     return 0;
 }
 
diff --git a/modules/audio_output/waveout.c b/modules/audio_output/waveout.c
index 62bf37ac3f..cc233153cb 100644
--- a/modules/audio_output/waveout.c
+++ b/modules/audio_output/waveout.c
@@ -865,7 +865,7 @@ static int WaveOutTimeGet(audio_output_t * p_aout, vlc_tick_t *delay)
         return -1;
     }
 
-    vlc_tick_t i_pos = (vlc_tick_t) mmtime.u.sample * CLOCK_FREQ / sys->i_rate;
+    vlc_tick_t i_pos = vlc_tick_from_samples(mmtime.u.sample, sys->i_rate);
     *delay = sys->i_played_length - i_pos;
     return 0;
 }
diff --git a/modules/codec/cc.c b/modules/codec/cc.c
index b84cce2786..1a0c8e568a 100644
--- a/modules/codec/cc.c
+++ b/modules/codec/cc.c
@@ -547,7 +547,7 @@ static void Convert( decoder_t *p_dec, vlc_tick_t i_pts,
     {
         if( (p_buffer[0] & 0x04) /* Valid bit */ )
         {
-            const vlc_tick_t i_spupts = i_pts + i_ticks * CLOCK_FREQ / (1200/3);
+            const vlc_tick_t i_spupts = i_pts + vlc_tick_from_samples(i_ticks, 1200/3);
             /* Mask off the specific i_field bit, else some sequences can be lost. */
             if ( p_sys->p_eia608 &&
                 (p_buffer[0] & 0x03) == p_sys->i_field )
diff --git a/modules/codec/cea708.c b/modules/codec/cea708.c
index d9b4dc2b37..bf7220359b 100644
--- a/modules/codec/cea708.c
+++ b/modules/codec/cea708.c
@@ -1660,7 +1660,7 @@ static void CEA708_Decode_ServiceBuffer( cea708_t *h )
         /* Update internal clock */
         const uint8_t i_consumed = i_in - cea708_input_buffer_size( &h->input_buffer );
         if( i_consumed )
-            h->i_clock += CLOCK_FREQ / 9600 * i_consumed;
+            h->i_clock += vlc_tick_from_samples(1, 9600) * i_consumed;
     }
 }
 
@@ -1692,7 +1692,7 @@ void CEA708_Decoder_Push( cea708_t *h, vlc_tick_t i_time,
             {
                 /* Increase internal clock */
                 if( i_push )
-                    h->i_clock += CLOCK_FREQ / 1200 * i_push;
+                    h->i_clock += vlc_tick_from_samples(1, 1200) * i_push;
                 continue;
             }
             h->suspended_deadline = VLC_TICK_INVALID;
diff --git a/modules/codec/daala.c b/modules/codec/daala.c
index 1938d98559..df28ac21ec 100644
--- a/modules/codec/daala.c
+++ b/modules/codec/daala.c
@@ -451,7 +451,7 @@ static void *ProcessPacket( decoder_t *p_dec, daala_packet *p_dpacket,
     }
 
     /* Date management */
-    p_sys->i_pts += ( CLOCK_FREQ * p_sys->di.timebase_denominator /
+    p_sys->i_pts += vlc_tick_from_samples( p_sys->di.timebase_denominator,
                       p_sys->di.timebase_numerator ); /* 1 frame per packet */
 
     return p_buf;
diff --git a/modules/codec/fdkaac.c b/modules/codec/fdkaac.c
index 0394225c7b..6bdc9ebeb0 100644
--- a/modules/codec/fdkaac.c
+++ b/modules/codec/fdkaac.c
@@ -328,13 +328,11 @@ static block_t *EncodeAudio(encoder_t *p_enc, block_t *p_aout_buf)
     if (likely(p_aout_buf)) {
         p_buffer = (int16_t *)p_aout_buf->p_buffer;
         i_samples = p_aout_buf->i_nb_samples;
-        i_pts_out = p_aout_buf->i_pts - (vlc_tick_t)((double)CLOCK_FREQ *
-               (double)p_sys->i_encoderdelay /
-               (double)p_enc->fmt_out.audio.i_rate);
+        i_pts_out = p_aout_buf->i_pts - vlc_tick_from_samples(p_sys->i_encoderdelay,
+                                                   p_enc->fmt_out.audio.i_rate);
         if (p_sys->i_pts_last == 0)
-            p_sys->i_pts_last = i_pts_out - (vlc_tick_t)((double)CLOCK_FREQ *
-               (double)(p_sys->i_frame_size) /
-               (double)p_enc->fmt_out.audio.i_rate);
+            p_sys->i_pts_last = i_pts_out - vlc_tick_from_samples(p_sys->i_frame_size,
+                                                   p_enc->fmt_out.audio.i_rate);
     } else {
         i_samples = 0;
         i_pts_out = p_sys->i_pts_last;
@@ -407,10 +405,10 @@ static block_t *EncodeAudio(encoder_t *p_enc, block_t *p_aout_buf)
                     // in the library buffer from the prior block
                     double d_samples_delay = (double)p_sys->i_frame_size - (double)out_args.numInSamples /
                                              (double)p_enc->fmt_in.audio.i_channels;
-                    i_pts_out -= (vlc_tick_t)((double)CLOCK_FREQ * d_samples_delay /
-                                           (double)p_enc->fmt_out.audio.i_rate);
-                    p_block->i_length = (vlc_tick_t)((double)CLOCK_FREQ * (double)p_sys->i_frame_size /
-                        (double)p_enc->fmt_out.audio.i_rate);
+                    i_pts_out -= vlc_tick_from_samples( d_samples_delay,
+                                                   p_enc->fmt_out.audio.i_rate);
+                    p_block->i_length = vlc_tick_from_samples(p_sys->i_frame_size,
+                                p_enc->fmt_out.audio.i_rate);
                     p_block->i_nb_samples = d_samples_delay;
                     //p_block->i_length = i_pts_out - p_sys->i_pts_last;
                 } else {
diff --git a/modules/codec/flac.c b/modules/codec/flac.c
index 055bce751c..6755f78d8e 100644
--- a/modules/codec/flac.c
+++ b/modules/codec/flac.c
@@ -770,8 +770,7 @@ EncoderWriteCallback( const FLAC__StreamEncoder *encoder,
 
     p_sys->i_samples_delay -= samples;
 
-    p_block->i_length = CLOCK_FREQ *
-        (vlc_tick_t)samples / (vlc_tick_t)p_enc->fmt_in.audio.i_rate;
+    p_block->i_length = vlc_tick_from_samples(samples, p_enc->fmt_in.audio.i_rate);
 
     /* Update pts */
     p_sys->i_pts += p_block->i_length;
@@ -880,8 +879,8 @@ static block_t *Encode( encoder_t *p_enc, block_t *p_aout_buf )
     if( unlikely( !p_aout_buf ) ) return NULL;
 
     p_sys->i_pts = p_aout_buf->i_pts -
-                CLOCK_FREQ * (vlc_tick_t)p_sys->i_samples_delay /
-                (vlc_tick_t)p_enc->fmt_in.audio.i_rate;
+                vlc_tick_from_samples( p_sys->i_samples_delay,
+                            p_enc->fmt_in.audio.i_rate );
 
     p_sys->i_samples_delay += p_aout_buf->i_nb_samples;
 
diff --git a/modules/codec/kate.c b/modules/codec/kate.c
index 44523fec4d..c9bf09931c 100644
--- a/modules/codec/kate.c
+++ b/modules/codec/kate.c
@@ -1080,8 +1080,7 @@ static subpicture_t *DecodePacket( decoder_t *p_dec, kate_packet *p_kp, block_t
     }
 
     p_spu->i_start = p_block->i_pts;
-    p_spu->i_stop = p_block->i_pts + CLOCK_FREQ *
-        ev->duration * p_sys->ki.gps_denominator / p_sys->ki.gps_numerator;
+    p_spu->i_stop = p_block->i_pts + vlc_tick_from_samples(ev->duration * p_sys->ki.gps_denominator, p_sys->ki.gps_numerator);
     p_spu->b_ephemer = false;
     p_spu->b_absolute = false;
 
diff --git a/modules/codec/opus.c b/modules/codec/opus.c
index 3d25ecfc66..62855d1cc4 100644
--- a/modules/codec/opus.c
+++ b/modules/codec/opus.c
@@ -482,7 +482,7 @@ static block_t *DecodePacket( decoder_t *p_dec, ogg_packet *p_oggpacket,
 
     int i_end_trim = 0;
     if( i_duration > 0 && spp > 0 &&
-        i_duration < i_nb_samples * CLOCK_FREQ / 48000 )
+        i_duration < vlc_tick_from_samples(i_nb_samples, 48000) )
     {
         i_end_trim = spp - VLC_CLIP(samples_from_vlc_tick(i_duration, 48000), 0, spp);
     }
@@ -580,8 +580,8 @@ static block_t *Encode(encoder_t *enc, block_t *buf)
         return NULL;
 
     vlc_tick_t i_pts = buf->i_pts -
-                (vlc_tick_t) CLOCK_FREQ * (vlc_tick_t) sys->i_samples_delay /
-                (vlc_tick_t) enc->fmt_in.audio.i_rate;
+                vlc_tick_from_samples( sys->i_samples_delay,
+                             enc->fmt_in.audio.i_rate );
 
     sys->i_samples_delay += buf->i_nb_samples;
 
@@ -626,8 +626,8 @@ static block_t *Encode(encoder_t *enc, block_t *buf)
         }
         else
         {
-            out_block->i_length = (vlc_tick_t) CLOCK_FREQ *
-                (vlc_tick_t) OPUS_FRAME_SIZE / (vlc_tick_t) enc->fmt_in.audio.i_rate;
+            out_block->i_length = vlc_tick_from_samples( OPUS_FRAME_SIZE,
+                                                         enc->fmt_in.audio.i_rate );
 
             out_block->i_dts = out_block->i_pts = i_pts;
 
diff --git a/modules/codec/qsv.c b/modules/codec/qsv.c
index bfdd57f44e..a9b23330f7 100644
--- a/modules/codec/qsv.c
+++ b/modules/codec/qsv.c
@@ -720,9 +720,8 @@ static block_t *qsv_synchronize_block(encoder_t *enc, async_task_t *task)
     /*         task->bs.FrameType, task->bs.TimeStamp, block->i_pts, task->bs.DecodeTimeStamp, *task->syncp); */
 
     /* Copied from x264.c: This isn't really valid for streams with B-frames */
-    block->i_length = CLOCK_FREQ *
-        enc->fmt_in.video.i_frame_rate_base /
-        enc->fmt_in.video.i_frame_rate;
+    block->i_length = vlc_tick_from_samples( enc->fmt_in.video.i_frame_rate_base,
+                                             enc->fmt_in.video.i_frame_rate );
 
     // Buggy DTS (value comes from experiments)
     if (task->bs.DecodeTimeStamp < -10000)
diff --git a/modules/codec/speex.c b/modules/codec/speex.c
index b863b416f7..e7310e777f 100644
--- a/modules/codec/speex.c
+++ b/modules/codec/speex.c
@@ -1095,8 +1095,8 @@ static block_t *Encode( encoder_t *p_enc, block_t *p_aout_buf )
     int i_samples_delay = p_sys->i_samples_delay;
 
     vlc_tick_t i_pts = p_aout_buf->i_pts -
-                CLOCK_FREQ * (vlc_tick_t)p_sys->i_samples_delay /
-                (vlc_tick_t)p_enc->fmt_in.audio.i_rate;
+                vlc_tick_from_samples( p_sys->i_samples_delay,
+                            p_enc->fmt_in.audio.i_rate );
 
     p_sys->i_samples_delay += i_samples;
 
@@ -1154,9 +1154,9 @@ static block_t *Encode( encoder_t *p_enc, block_t *p_aout_buf )
         p_block = block_Alloc( i_out );
         memcpy( p_block->p_buffer, p_sys->p_buffer_out, i_out );
 
-        p_block->i_length = CLOCK_FREQ *
-            (vlc_tick_t)p_sys->i_frame_length * p_sys->header.frames_per_packet /
-            (vlc_tick_t)p_enc->fmt_in.audio.i_rate;
+        p_block->i_length = vlc_tick_from_samples(
+            p_sys->i_frame_length * p_sys->header.frames_per_packet,
+            p_enc->fmt_in.audio.i_rate );
 
         p_block->i_dts = p_block->i_pts = i_pts;
 
diff --git a/modules/codec/synchro.c b/modules/codec/synchro.c
index f27b0b0986..ce16a81fba 100644
--- a/modules/codec/synchro.c
+++ b/modules/codec/synchro.c
@@ -225,7 +225,7 @@ bool decoder_SynchroChoose( decoder_synchro_t * p_synchro, int i_coding_type,
     i_current_rate = decoder_GetDisplayRate( p_synchro->p_dec );
 
     now = vlc_tick_now();
-    period = CLOCK_FREQ * 1001 / p_synchro->i_frame_rate * i_current_rate;
+    period = vlc_tick_from_samples(1001, p_synchro->i_frame_rate) * i_current_rate;
 
     p_synchro->i_render_time = i_render_time;
 
@@ -406,7 +406,7 @@ void decoder_SynchroNewPicture( decoder_synchro_t * p_synchro, int i_coding_type
                                 int i_repeat_field, vlc_tick_t next_pts,
                                 vlc_tick_t next_dts, bool b_low_delay )
 {
-    vlc_tick_t      period = CLOCK_FREQ * 1001 / p_synchro->i_frame_rate;
+    vlc_tick_t    period = vlc_tick_from_samples(1001, p_synchro->i_frame_rate);
 #if 0
     vlc_tick_t      now = vlc_tick_now();
 #endif
diff --git a/modules/codec/theora.c b/modules/codec/theora.c
index da2d38fe3e..cc7aaa1b96 100644
--- a/modules/codec/theora.c
+++ b/modules/codec/theora.c
@@ -487,7 +487,7 @@ static void *ProcessPacket( decoder_t *p_dec, ogg_packet *p_oggpacket,
     }
 
     /* Date management */
-    p_sys->i_pts += ( CLOCK_FREQ * p_sys->ti.fps_denominator /
+    p_sys->i_pts += vlc_tick_from_samples( p_sys->ti.fps_denominator,
                       p_sys->ti.fps_numerator ); /* 1 frame per packet */
 
     return p_buf;
diff --git a/modules/codec/ttml/ttml.c b/modules/codec/ttml/ttml.c
index 91a2b486b7..312c2e1076 100644
--- a/modules/codec/ttml/ttml.c
+++ b/modules/codec/ttml/ttml.c
@@ -98,7 +98,7 @@ static tt_time_t tt_ParseTime( const char *s )
             unsigned i_den = 1;
             for( const char *p = strchr( s, '.' ) + 1; *p && (i_den < UINT_MAX / 10); p++ )
                 i_den *= 10;
-            t.base += vlc_tick_from_sec(d1) / i_den;
+            t.base += vlc_tick_from_samples(d1, i_den);
         }
         else if( c == ':' )
         {
diff --git a/modules/codec/ttml/ttml.h b/modules/codec/ttml/ttml.h
index 36fa70271c..d375597632 100644
--- a/modules/codec/ttml/ttml.h
+++ b/modules/codec/ttml/ttml.h
@@ -124,7 +124,7 @@ static inline vlc_tick_t tt_time_Convert( const tt_time_t *t )
     if( !tt_time_Valid( t ) )
         return VLC_TICK_INVALID;
     else
-        return t->base + CLOCK_FREQ * t->frames / TT_FRAME_RATE;
+        return t->base + vlc_tick_from_samples( t->frames, TT_FRAME_RATE);
 }
 
 static inline int tt_time_Compare( const tt_time_t *t1, const tt_time_t *t2 )
@@ -140,7 +140,7 @@ static inline tt_time_t tt_time_Add( tt_time_t t1, tt_time_t t2 )
 {
     t1.base += t2.base;
     t1.frames += t2.frames;
-    t1.base += CLOCK_FREQ * ( t1.frames / TT_FRAME_RATE );
+    t1.base += vlc_tick_from_samples( t1.frames, TT_FRAME_RATE );
     t1.frames = t1.frames % TT_FRAME_RATE;
     return t1;
 }
diff --git a/modules/codec/twolame.c b/modules/codec/twolame.c
index eed7e30262..a4dbfd1e01 100644
--- a/modules/codec/twolame.c
+++ b/modules/codec/twolame.c
@@ -289,8 +289,8 @@ static block_t *Encode( encoder_t *p_enc, block_t *p_aout_buf )
         if( !p_block )
             return NULL;
         memcpy( p_block->p_buffer, p_sys->p_out_buffer, i_used );
-        p_block->i_length = CLOCK_FREQ *
-                (vlc_tick_t)MPEG_FRAME_SIZE / (vlc_tick_t)p_enc->fmt_out.audio.i_rate;
+        p_block->i_length = vlc_tick_from_samples( MPEG_FRAME_SIZE,
+                                                   p_enc->fmt_out.audio.i_rate );
         p_block->i_dts = p_block->i_pts = p_sys->i_pts;
         p_sys->i_pts += p_block->i_length;
 
@@ -301,8 +301,8 @@ static block_t *Encode( encoder_t *p_enc, block_t *p_aout_buf )
     int i_nb_samples = p_aout_buf->i_nb_samples;
 
     p_sys->i_pts = p_aout_buf->i_pts -
-                CLOCK_FREQ * (vlc_tick_t)p_sys->i_nb_samples /
-                (vlc_tick_t)p_enc->fmt_out.audio.i_rate;
+                vlc_tick_from_samples( p_sys->i_nb_samples,
+                                       p_enc->fmt_out.audio.i_rate );
 
     while ( p_sys->i_nb_samples + i_nb_samples >= MPEG_FRAME_SIZE )
     {
@@ -332,8 +332,8 @@ static block_t *Encode( encoder_t *p_enc, block_t *p_aout_buf )
             return NULL;
         }
         memcpy( p_block->p_buffer, p_sys->p_out_buffer, i_used );
-        p_block->i_length = CLOCK_FREQ *
-                (vlc_tick_t)MPEG_FRAME_SIZE / (vlc_tick_t)p_enc->fmt_out.audio.i_rate;
+        p_block->i_length = vlc_tick_from_samples( MPEG_FRAME_SIZE,
+                                                   p_enc->fmt_out.audio.i_rate );
         p_block->i_dts = p_block->i_pts = p_sys->i_pts;
         p_sys->i_pts += p_block->i_length;
         block_ChainAppend( &p_chain, p_block );
diff --git a/modules/codec/vorbis.c b/modules/codec/vorbis.c
index 6a2740086f..42a6271ecc 100644
--- a/modules/codec/vorbis.c
+++ b/modules/codec/vorbis.c
@@ -902,8 +902,8 @@ static block_t *Encode( encoder_t *p_enc, block_t *p_aout_buf )
     if( unlikely( !p_aout_buf ) ) return NULL;
 
     vlc_tick_t i_pts = p_aout_buf->i_pts -
-                CLOCK_FREQ * (vlc_tick_t)p_sys->i_samples_delay /
-                (vlc_tick_t)p_enc->fmt_in.audio.i_rate;
+                vlc_tick_from_samples( p_sys->i_samples_delay,
+                                       p_enc->fmt_in.audio.i_rate );
 
     p_sys->i_samples_delay += p_aout_buf->i_nb_samples;
 
@@ -941,8 +941,8 @@ static block_t *Encode( encoder_t *p_enc, block_t *p_aout_buf )
             i_samples = ( p_sys->i_last_block_size + i_block_size ) >> 2;
             p_sys->i_last_block_size = i_block_size;
 
-            p_block->i_length = CLOCK_FREQ *
-                (vlc_tick_t)i_samples / (vlc_tick_t)p_enc->fmt_in.audio.i_rate;
+            p_block->i_length = vlc_tick_from_samples(i_samples,
+                                                      p_enc->fmt_in.audio.i_rate);
 
             p_block->i_dts = p_block->i_pts = i_pts;
 
diff --git a/modules/codec/x264.c b/modules/codec/x264.c
index c5954cb904..3802b24f4f 100644
--- a/modules/codec/x264.c
+++ b/modules/codec/x264.c
@@ -1542,9 +1542,9 @@ static block_t *Encode( encoder_t *p_enc, picture_t *p_pict )
     if( !p_sys->param.b_vfr_input )
     {
         /* This isn't really valid for streams with B-frames */
-        p_block->i_length = CLOCK_FREQ *
-            p_enc->fmt_in.video.i_frame_rate_base /
-                p_enc->fmt_in.video.i_frame_rate;
+        p_block->i_length = vlc_tick_from_samples(
+                    p_enc->fmt_in.video.i_frame_rate_base,
+                    p_enc->fmt_in.video.i_frame_rate );
     }
 
     /* scale pts-values back*/
diff --git a/modules/codec/x265.c b/modules/codec/x265.c
index e988f563db..0fb8c0be8b 100644
--- a/modules/codec/x265.c
+++ b/modules/codec/x265.c
@@ -104,9 +104,9 @@ static block_t *Encode(encoder_t *p_enc, picture_t *p_pict)
     memcpy(p_block->p_buffer, nal[0].payload, i_out);
 
     /* This isn't really valid for streams with B-frames */
-    p_block->i_length = CLOCK_FREQ *
-        p_enc->fmt_in.video.i_frame_rate_base /
-            p_enc->fmt_in.video.i_frame_rate;
+    p_block->i_length = vlc_tick_from_samples(
+                p_enc->fmt_in.video.i_frame_rate_base,
+                p_enc->fmt_in.video.i_frame_rate );
 
     p_block->i_pts = p_sys->initial_date + pic.poc * p_block->i_length;
     p_block->i_dts = p_sys->initial_date + p_sys->frame_count++ * p_block->i_length;
diff --git a/modules/demux/aiff.c b/modules/demux/aiff.c
index 193c3434ec..2aeb99c0a9 100644
--- a/modules/demux/aiff.c
+++ b/modules/demux/aiff.c
@@ -251,9 +251,8 @@ static int Demux( demux_t *p_demux )
     p_block->i_dts =
     p_block->i_pts = VLC_TICK_0 + p_sys->i_time;
 
-    p_sys->i_time += CLOCK_FREQ *
-                     p_block->i_buffer /
-                     p_sys->i_ssnd_fsize /
+    p_sys->i_time += vlc_tick_from_samples(p_block->i_buffer,
+                                           p_sys->i_ssnd_fsize) /
                      p_sys->fmt.audio.i_rate;
 
     /* */
@@ -306,7 +305,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
                 {
                     return VLC_EGENERIC;
                 }
-                p_sys->i_time = CLOCK_FREQ * i_frame / p_sys->fmt.audio.i_rate;
+                p_sys->i_time = vlc_tick_from_samples( i_frame, p_sys->fmt.audio.i_rate );
                 return VLC_SUCCESS;
             }
             return VLC_EGENERIC;
@@ -323,7 +322,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
             if( p_sys->i_ssnd_start < i_end )
             {
                 *va_arg( args, vlc_tick_t * ) =
-                    CLOCK_FREQ * ( i_end - p_sys->i_ssnd_start ) / p_sys->i_ssnd_fsize / p_sys->fmt.audio.i_rate;
+                    vlc_tick_from_samples( i_end - p_sys->i_ssnd_start, p_sys->i_ssnd_fsize) / p_sys->fmt.audio.i_rate;
                 return VLC_SUCCESS;
             }
             return VLC_EGENERIC;
diff --git a/modules/demux/au.c b/modules/demux/au.c
index 7a5af13679..72e16f437a 100644
--- a/modules/demux/au.c
+++ b/modules/demux/au.c
@@ -288,9 +288,8 @@ static int Open( vlc_object_t *p_this )
             p_sys->i_frame_size += p_sys->fmt.audio.i_blockalign - mod;
         }
     }
-    p_sys->i_frame_length = CLOCK_FREQ *
-                            (vlc_tick_t)i_samples /
-                            (vlc_tick_t)p_sys->fmt.audio.i_rate;
+    p_sys->i_frame_length = vlc_tick_from_samples( i_samples,
+                                                   p_sys->fmt.audio.i_rate );
 
     p_demux->p_sys = p_sys;
     p_demux->pf_demux = Demux;
diff --git a/modules/demux/avformat/demux.c b/modules/demux/avformat/demux.c
index b93c3f6f71..f7d9355526 100644
--- a/modules/demux/avformat/demux.c
+++ b/modules/demux/avformat/demux.c
@@ -702,9 +702,9 @@ int avformat_OpenDemux( vlc_object_t *p_this )
             EnsureUTF8( s->psz_name );
             msg_Dbg( p_demux, "    - chapter %d: %s", i, s->psz_name );
         }
-        s->i_time_offset = p_sys->ic->chapters[i]->start * CLOCK_FREQ *
-            p_sys->ic->chapters[i]->time_base.num /
-            p_sys->ic->chapters[i]->time_base.den -
+        s->i_time_offset = vlc_tick_from_samples( p_sys->ic->chapters[i]->start *
+            p_sys->ic->chapters[i]->time_base.num,
+            p_sys->ic->chapters[i]->time_base.den ) -
             (i_start_time != VLC_TICK_INVALID ? i_start_time : 0 );
         TAB_APPEND( p_sys->p_title->i_seekpoint, p_sys->p_title->seekpoint, s );
     }
@@ -842,9 +842,9 @@ static int Demux( demux_t *p_demux )
             p_stream->time_base.den - i_start_time + VLC_TICK_0;
     }
     if( pkt.duration > 0 && p_frame->i_length <= 0 )
-        p_frame->i_length = pkt.duration * CLOCK_FREQ *
-            p_stream->time_base.num /
-            p_stream->time_base.den;
+        p_frame->i_length = vlc_tick_from_samples(pkt.duration *
+            p_stream->time_base.num,
+            p_stream->time_base.den );
 
     /* Add here notoriously bugged file formats/samples */
     if( !strcmp( p_sys->fmt->name, "flv" ) )
diff --git a/modules/demux/caf.c b/modules/demux/caf.c
index 87ac2a2dd0..363b74b653 100644
--- a/modules/demux/caf.c
+++ b/modules/demux/caf.c
@@ -1017,12 +1017,12 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
 
         case DEMUX_GET_LENGTH:
             *va_arg( args, vlc_tick_t * ) =
-                CLOCK_FREQ * ( i_num_samples / p_sys->fmt.audio.i_rate );
+                vlc_tick_from_samples( i_num_samples, p_sys->fmt.audio.i_rate );
             return VLC_SUCCESS;
 
         case DEMUX_GET_TIME:
             *va_arg( args, vlc_tick_t * ) =
-                CLOCK_FREQ * ( p_sys->position.i_samples / p_sys->fmt.audio.i_rate );
+                vlc_tick_from_samples( p_sys->position.i_samples, p_sys->fmt.audio.i_rate );
             return VLC_SUCCESS;
 
         case DEMUX_GET_POSITION:
diff --git a/modules/demux/dash/mp4/IndexReader.cpp b/modules/demux/dash/mp4/IndexReader.cpp
index d539d22d8e..83ef5cab66 100644
--- a/modules/demux/dash/mp4/IndexReader.cpp
+++ b/modules/demux/dash/mp4/IndexReader.cpp
@@ -52,8 +52,8 @@ bool IndexReader::parseIndex(block_t *p_block, BaseRepresentation *rep, uint64_t
         {
             splitlist.push_back(point);
             point.offset += sidx->p_items[i].i_referenced_size;
-            point.duration = CLOCK_FREQ * sidx->p_items[i].i_subsegment_duration /
-                    sidx->i_timescale;
+            point.duration = vlc_tick_from_samples( sidx->p_items[i].i_subsegment_duration,
+                    sidx->i_timescale );
             point.time += point.duration;
         }
         rep->SplitUsingIndex(splitlist);
diff --git a/modules/demux/flac.c b/modules/demux/flac.c
index 3790131841..abc0998fa5 100644
--- a/modules/demux/flac.c
+++ b/modules/demux/flac.c
@@ -784,7 +784,7 @@ static void ParseSeekTable( demux_t *p_demux, const uint8_t *p_data, size_t i_da
             break;
 
         s = xmalloc( sizeof (*s) );
-        s->i_time_offset = i_sample * CLOCK_FREQ / i_sample_rate;
+        s->i_time_offset = vlc_tick_from_samples(i_sample, i_sample_rate);
         s->i_byte_offset = GetQWBE( &p_data[4+18*i+8] );
 
         /* Check for duplicate entry */
diff --git a/modules/demux/mpc.c b/modules/demux/mpc.c
index d422e870f4..faa65f03a5 100644
--- a/modules/demux/mpc.c
+++ b/modules/demux/mpc.c
@@ -241,7 +241,7 @@ static int Demux( demux_t *p_demux )
     /* */
     p_data->i_buffer = i_ret * sizeof(MPC_SAMPLE_FORMAT) * p_sys->info.channels;
     p_data->i_dts = p_data->i_pts =
-            VLC_TICK_0 + CLOCK_FREQ * p_sys->i_position / p_sys->info.sample_freq;
+            VLC_TICK_0 + vlc_tick_from_samples(p_sys->i_position, p_sys->info.sample_freq);
 
     es_out_SetPCR( p_demux->out, p_data->i_dts );
 
@@ -276,7 +276,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
 
         case DEMUX_GET_LENGTH:
             *va_arg( args, vlc_tick_t * ) =
-                CLOCK_FREQ * p_sys->info.pcm_samples / p_sys->info.sample_freq;
+                vlc_tick_from_samples(p_sys->info.pcm_samples, p_sys->info.sample_freq);
             return VLC_SUCCESS;
 
         case DEMUX_GET_POSITION:
@@ -290,7 +290,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
 
         case DEMUX_GET_TIME:
             *va_arg( args, vlc_tick_t * ) =
-                CLOCK_FREQ * p_sys->i_position / p_sys->info.sample_freq;
+                vlc_tick_from_samples(p_sys->i_position, p_sys->info.sample_freq);
             return VLC_SUCCESS;
 
         case DEMUX_SET_POSITION:
diff --git a/modules/demux/mpeg/mpeg4_iod.c b/modules/demux/mpeg/mpeg4_iod.c
index 1b209b4918..adb8b0697b 100644
--- a/modules/demux/mpeg/mpeg4_iod.c
+++ b/modules/demux/mpeg/mpeg4_iod.c
@@ -602,7 +602,8 @@ sl_header_data DecodeSLHeader( unsigned i_data, const uint8_t *p_data,
                     i_read |= bs_read( &s, i_bits );
                 }
                 if( sl->i_timestamp_resolution )
-                    *(timestamps[i].p_t) = VLC_TICK_0 + CLOCK_FREQ * i_read / sl->i_timestamp_resolution;
+                    *(timestamps[i].p_t) = VLC_TICK_0 +
+                        vlc_tick_from_samples(i_read, sl->i_timestamp_resolution);
             }
 
             bs_read( &s, sl->i_AU_length );
diff --git a/modules/demux/mpeg/ps.c b/modules/demux/mpeg/ps.c
index 724a9dfe1d..6d76fe02b0 100644
--- a/modules/demux/mpeg/ps.c
+++ b/modules/demux/mpeg/ps.c
@@ -157,7 +157,7 @@ static int OpenCommon( vlc_object_t *p_this, bool b_force )
         msg_Info( p_demux, "Detected PSMF-PS header");
         i_mux_rate = GetDWBE( &p_peek[96] );
         if( GetDWBE( &p_peek[86] ) > 0 )
-            i_length = CLOCK_FREQ * GetDWBE( &p_peek[92] ) / GetDWBE( &p_peek[86] );
+            i_length = vlc_tick_from_samples( GetDWBE( &p_peek[92] ), GetDWBE( &p_peek[86] ));
     }
     else if( !memcmp( p_peek, "RIFF", 4 ) && !memcmp( &p_peek[8], "CDXA", 4 ) )
     {
@@ -741,7 +741,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
                 if( p_sys->i_mux_rate > 0 && p_sys->b_have_pack )
                 {
                     uint64_t i_offset = vlc_stream_Tell( p_demux->s ) - p_sys->i_lastpack_byte;
-                    i_time += CLOCK_FREQ * i_offset / (p_sys->i_mux_rate * 50);
+                    i_time += vlc_tick_from_samples(i_offset, p_sys->i_mux_rate * 50);
                 }
                 *va_arg( args, vlc_tick_t * ) = i_time;
                 return VLC_SUCCESS;
@@ -757,8 +757,8 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
             }
             else if( p_sys->i_mux_rate > 0 )
             {
-                *va_arg( args, vlc_tick_t * ) = CLOCK_FREQ * ( stream_Size( p_demux->s ) - p_sys->i_start_byte / 50 ) /
-                    p_sys->i_mux_rate;
+                *va_arg( args, vlc_tick_t * ) = vlc_tick_from_samples( stream_Size( p_demux->s ) - p_sys->i_start_byte / 50,
+                    p_sys->i_mux_rate );
                 return VLC_SUCCESS;
             }
             *va_arg( args, vlc_tick_t * ) = 0;
diff --git a/modules/demux/mpeg/ts.c b/modules/demux/mpeg/ts.c
index 4fe4978d4b..8efaa85209 100644
--- a/modules/demux/mpeg/ts.c
+++ b/modules/demux/mpeg/ts.c
@@ -1310,7 +1310,7 @@ static block_t *J2K_Parse( demux_t *p_demux, block_t *p_block, bool b_interlaced
     uint16_t i_num = GetWBE( &p_buf[10] );
     if( i_den == 0 )
         goto invalid;
-    p_block->i_length = CLOCK_FREQ * i_den / i_num;
+    p_block->i_length = vlc_tick_from_samples( i_den, i_num );
 
     p_block->p_buffer += (b_interlaced) ? 48 : 38;
     p_block->i_buffer -= (b_interlaced) ? 48 : 38;
diff --git a/modules/demux/nsv.c b/modules/demux/nsv.c
index e08f82256d..1d889ca7d5 100644
--- a/modules/demux/nsv.c
+++ b/modules/demux/nsv.c
@@ -392,7 +392,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
         case DEMUX_GET_LENGTH:
             if( p_sys->i_mux_rate > 0 )
             {
-                *va_arg( args, vlc_tick_t * ) = CLOCK_FREQ * ( stream_Size( p_demux->s ) / 50 ) / p_sys->i_mux_rate;
+                *va_arg( args, vlc_tick_t * ) = vlc_tick_from_samples( stream_Size( p_demux->s ) / 50, p_sys->i_mux_rate);
                 return VLC_SUCCESS;
             }
             *va_arg( args, vlc_tick_t * ) = 0;
diff --git a/modules/demux/pva.c b/modules/demux/pva.c
index 56be650d58..daf0b42ad6 100644
--- a/modules/demux/pva.c
+++ b/modules/demux/pva.c
@@ -335,7 +335,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
             pi64 = va_arg( args, vlc_tick_t * );
             if( p_sys->i_mux_rate > 0 )
             {
-                *pi64 = CLOCK_FREQ * ( stream_Size( p_demux->s ) / 50 ) / p_sys->i_mux_rate;
+                *pi64 = vlc_tick_from_samples( stream_Size( p_demux->s ) / 50, p_sys->i_mux_rate);
                 return VLC_SUCCESS;
             }
             *pi64 = 0;
diff --git a/modules/demux/vc1.c b/modules/demux/vc1.c
index 069cc39a39..cf4fcb14d4 100644
--- a/modules/demux/vc1.c
+++ b/modules/demux/vc1.c
@@ -180,9 +180,9 @@ static int Demux( demux_t *p_demux)
 
             if( p_sys->p_packetizer->fmt_out.video.i_frame_rate > 0 &&
                 p_sys->p_packetizer->fmt_out.video.i_frame_rate_base > 0 )
-                p_sys->i_dts += CLOCK_FREQ *
-                    p_sys->p_packetizer->fmt_out.video.i_frame_rate_base /
-                    p_sys->p_packetizer->fmt_out.video.i_frame_rate;
+                p_sys->i_dts += vlc_tick_from_samples(
+                    p_sys->p_packetizer->fmt_out.video.i_frame_rate_base,
+                    p_sys->p_packetizer->fmt_out.video.i_frame_rate );
             else if( p_sys->f_fps > 0.001f )
                 p_sys->i_dts += (int64_t)((float) CLOCK_FREQ / p_sys->f_fps);
             else
diff --git a/modules/hw/mmal/deinterlace.c b/modules/hw/mmal/deinterlace.c
index 9e6a9bf31c..a127313899 100644
--- a/modules/hw/mmal/deinterlace.c
+++ b/modules/hw/mmal/deinterlace.c
@@ -88,8 +88,8 @@ static void flush(filter_t *filter);
 static int Open(filter_t *filter)
 {
     int32_t frame_duration = filter->fmt_in.video.i_frame_rate != 0 ?
-            CLOCK_FREQ * filter->fmt_in.video.i_frame_rate_base /
-            filter->fmt_in.video.i_frame_rate : 0;
+            vlc_tick_from_samples( filter->fmt_in.video.i_frame_rate_base,
+            filter->fmt_in.video.i_frame_rate ) : 0;
     bool use_qpu = var_InheritBool(filter, MMAL_DEINTERLACE_QPU);
 
     MMAL_PARAMETER_IMAGEFX_PARAMETERS_T imfx_param = {
diff --git a/modules/hw/vaapi/filters.c b/modules/hw/vaapi/filters.c
index 364519bc7c..d3f8610fcc 100644
--- a/modules/hw/vaapi/filters.c
+++ b/modules/hw/vaapi/filters.c
@@ -924,7 +924,7 @@ DeinterlaceX2(filter_t * filter, picture_t * src)
         i_field_dur = (src->date - p_deint_data->meta[i].date) / i_fields_total;
     }
     else if (fmt->i_frame_rate_base)
-        i_field_dur = CLOCK_FREQ * fmt->i_frame_rate_base / fmt->i_frame_rate;
+        i_field_dur = vlc_tick_from_samples(fmt->i_frame_rate_base, fmt->i_frame_rate);
 
     picture_t *dest[2] = {NULL, NULL};
     for (i = 0; i < 2; ++i)
diff --git a/modules/mux/mp4/mp4.c b/modules/mux/mp4/mp4.c
index a5eb85c835..c2828b39f6 100644
--- a/modules/mux/mp4/mp4.c
+++ b/modules/mux/mp4/mp4.c
@@ -652,9 +652,9 @@ static int MuxStream(sout_mux_t *p_mux, sout_input_t *p_input, mp4_stream_t *p_s
             { /* we have no way to know real length except by decoding */
                 if ( p_stream->mux.fmt.i_cat == VIDEO_ES )
                 {
-                    p_data->i_length = CLOCK_FREQ *
-                            p_stream->mux.fmt.video.i_frame_rate_base /
-                            p_stream->mux.fmt.video.i_frame_rate;
+                    p_data->i_length = vlc_tick_from_samples(
+                            p_stream->mux.fmt.video.i_frame_rate_base,
+                            p_stream->mux.fmt.video.i_frame_rate );
                     if( p_data->i_flags & BLOCK_FLAG_SINGLE_FIELD )
                         p_data->i_length >>= 1;
                     msg_Dbg( p_mux, "video track %u fixup to %"PRId64" for sample %u",
@@ -664,8 +664,8 @@ static int MuxStream(sout_mux_t *p_mux, sout_input_t *p_input, mp4_stream_t *p_s
                           p_stream->mux.fmt.audio.i_rate &&
                           p_data->i_nb_samples )
                 {
-                    p_data->i_length = CLOCK_FREQ * p_data->i_nb_samples /
-                            p_stream->mux.fmt.audio.i_rate;
+                    p_data->i_length = vlc_tick_from_samples(p_data->i_nb_samples,
+                            p_stream->mux.fmt.audio.i_rate);
                     msg_Dbg( p_mux, "audio track %u fixup to %"PRId64" for sample %u",
                              p_stream->mux.i_track_id, p_data->i_length, p_stream->mux.i_entry_count );
                 }
@@ -1315,9 +1315,9 @@ static void LengthLocalFixup(sout_mux_t *p_mux, const mp4_stream_t *p_stream, bl
 {
     if ( p_stream->mux.fmt.i_cat == VIDEO_ES && p_stream->mux.fmt.video.i_frame_rate )
     {
-        p_entrydata->i_length = CLOCK_FREQ *
-                p_stream->mux.fmt.video.i_frame_rate_base /
-                p_stream->mux.fmt.video.i_frame_rate;
+        p_entrydata->i_length = vlc_tick_from_samples(
+                p_stream->mux.fmt.video.i_frame_rate_base,
+                p_stream->mux.fmt.video.i_frame_rate);
         msg_Dbg(p_mux, "video track %d fixup to %"PRId64" for sample %u",
                 p_stream->mux.i_track_id, p_entrydata->i_length, p_stream->mux.i_entry_count - 1);
     }
@@ -1325,8 +1325,8 @@ static void LengthLocalFixup(sout_mux_t *p_mux, const mp4_stream_t *p_stream, bl
              p_stream->mux.fmt.audio.i_rate &&
              p_entrydata->i_nb_samples && p_stream->mux.fmt.audio.i_rate)
     {
-        p_entrydata->i_length = CLOCK_FREQ * p_entrydata->i_nb_samples /
-                p_stream->mux.fmt.audio.i_rate;
+        p_entrydata->i_length = vlc_tick_from_samples(p_entrydata->i_nb_samples,
+                p_stream->mux.fmt.audio.i_rate);
         msg_Dbg(p_mux, "audio track %d fixup to %"PRId64" for sample %u",
                 p_stream->mux.i_track_id, p_entrydata->i_length, p_stream->mux.i_entry_count - 1);
     }
diff --git a/modules/mux/mpeg/ts.c b/modules/mux/mpeg/ts.c
index d7a6a59334..722a8a8708 100644
--- a/modules/mux/mpeg/ts.c
+++ b/modules/mux/mpeg/ts.c
@@ -1090,9 +1090,9 @@ static void SetBlockDuration( sout_input_t *p_input, block_t *p_data )
                 p_input->p_fmt->video.i_frame_rate &&
                 p_input->p_fmt->video.i_frame_rate_base )
             {
-                p_data->i_length = CLOCK_FREQ *
-                                   p_input->p_fmt->video.i_frame_rate /
-                                   p_input->p_fmt->video.i_frame_rate_base;
+                p_data->i_length = vlc_tick_from_samples(
+                                   p_input->p_fmt->video.i_frame_rate,
+                                   p_input->p_fmt->video.i_frame_rate_base);
             }
             else if( p_input->p_fmt->i_cat == AUDIO_ES &&
                      p_input->p_fmt->audio.i_bytes_per_frame &&
diff --git a/modules/mux/ogg.c b/modules/mux/ogg.c
index 8c328fd572..b43a696a5d 100644
--- a/modules/mux/ogg.c
+++ b/modules/mux/ogg.c
@@ -1643,9 +1643,9 @@ static int MuxBlock( sout_mux_t *p_mux, sout_input_t *p_input )
                 p_stream->i_last_keyframe = p_stream->i_num_frames;
 
                 /* presentation time */
-                i_time = CLOCK_FREQ * ( p_stream->i_num_frames - 1 ) *
-                        p_stream->fmt.video.i_frame_rate_base /
-                        p_stream->fmt.video.i_frame_rate;
+                i_time = vlc_tick_from_samples( (p_stream->i_num_frames - 1 ) *
+                        p_stream->fmt.video.i_frame_rate_base,
+                        p_stream->fmt.video.i_frame_rate );
                 AddIndexEntry( p_mux, i_time, p_input );
             }
 
@@ -1713,8 +1713,8 @@ static int MuxBlock( sout_mux_t *p_mux, sout_input_t *p_input )
                 p_stream->i_last_keyframe = p_stream->i_num_frames;
 
                 /* presentation time */
-                i_time = CLOCK_FREQ * ( p_stream->i_num_frames - 1 ) *
-                         p_stream->fmt.video.i_frame_rate_base / p_stream->fmt.video.i_frame_rate;
+                i_time = vlc_tick_from_samples( ( p_stream->i_num_frames - 1 ) *
+                         p_stream->fmt.video.i_frame_rate_base, p_stream->fmt.video.i_frame_rate );
                 AddIndexEntry( p_mux, i_time, p_input );
             }
             op.granulepos = ( ((int64_t)p_stream->i_num_frames) << 32 ) |
diff --git a/modules/packetizer/flac.h b/modules/packetizer/flac.h
index 71a637d648..870a30cdf6 100644
--- a/modules/packetizer/flac.h
+++ b/modules/packetizer/flac.h
@@ -260,9 +260,9 @@ static inline int FLAC_ParseSyncInfo(const uint8_t *p_buf,
 
     /* Compute from frame absolute time */
     if ( (p_buf[1] & 0x01) == 0  ) /* Fixed blocksize stream / Frames */
-        h->i_pts = VLC_TICK_0 + CLOCK_FREQ * blocksize * i_fsnumber / samplerate;
+        h->i_pts = VLC_TICK_0 + vlc_tick_from_samples(blocksize * i_fsnumber, samplerate);
     else /* Variable blocksize stream / Samples */
-        h->i_pts = VLC_TICK_0 + CLOCK_FREQ * i_fsnumber / samplerate;
+        h->i_pts = VLC_TICK_0 + vlc_tick_from_samples(i_fsnumber, samplerate);
 
     h->i_bits_per_sample = bits_per_sample;
     h->i_rate = samplerate;
diff --git a/modules/packetizer/h264.c b/modules/packetizer/h264.c
index 686659f03a..f239b8531b 100644
--- a/modules/packetizer/h264.c
+++ b/modules/packetizer/h264.c
@@ -971,8 +971,8 @@ static block_t *OutputPicture( decoder_t *p_dec )
     {
         if( p_sps->vui.i_time_scale )
         {
-            p_pic->i_length = CLOCK_FREQ * i_num_clock_ts *
-                              p_sps->vui.i_num_units_in_tick / p_sps->vui.i_time_scale;
+            p_pic->i_length = vlc_tick_from_samples(i_num_clock_ts *
+                              p_sps->vui.i_num_units_in_tick, p_sps->vui.i_time_scale);
         }
         else
         {
diff --git a/modules/packetizer/mpeg4video.c b/modules/packetizer/mpeg4video.c
index 4877071381..e457d0c9cf 100644
--- a/modules/packetizer/mpeg4video.c
+++ b/modules/packetizer/mpeg4video.c
@@ -544,14 +544,14 @@ static int ParseVOP( decoder_t *p_dec, block_t *p_vop )
         p_dec->fmt_in.video.i_frame_rate > 0 &&
         p_dec->fmt_in.video.i_frame_rate_base > 0 )
     {
-        p_sys->i_interpolated_pts += CLOCK_FREQ *
-        p_dec->fmt_in.video.i_frame_rate_base /
-        p_dec->fmt_in.video.i_frame_rate;
+        p_sys->i_interpolated_pts += vlc_tick_from_samples(
+        p_dec->fmt_in.video.i_frame_rate_base,
+        p_dec->fmt_in.video.i_frame_rate);
     }
     else if( p_sys->i_fps_num )
     {
         i_time_diff = (i_time_ref + i_time_increment) - (p_sys->i_last_time + p_sys->i_last_timeincr);
-        p_sys->i_interpolated_pts += ( CLOCK_FREQ * i_time_diff / p_sys->i_fps_num );
+        p_sys->i_interpolated_pts += vlc_tick_from_samples( i_time_diff, p_sys->i_fps_num );
     }
 
 #if 0
diff --git a/modules/packetizer/vc1.c b/modules/packetizer/vc1.c
index f8d070c3a4..d9f56e76a6 100644
--- a/modules/packetizer/vc1.c
+++ b/modules/packetizer/vc1.c
@@ -389,9 +389,9 @@ static block_t *ParseIDU( decoder_t *p_dec, bool *pb_ts_used, block_t *p_frag )
         if( p_dec->fmt_out.video.i_frame_rate != 0 && p_dec->fmt_out.video.i_frame_rate_base != 0 )
         {
             if( p_sys->i_interpolated_dts != VLC_TICK_INVALID )
-                p_sys->i_interpolated_dts += CLOCK_FREQ *
-                                             p_dec->fmt_out.video.i_frame_rate_base /
-                                             p_dec->fmt_out.video.i_frame_rate;
+                p_sys->i_interpolated_dts += vlc_tick_from_samples(
+                                             p_dec->fmt_out.video.i_frame_rate_base,
+                                             p_dec->fmt_out.video.i_frame_rate);
 
             //msg_Dbg( p_dec, "-------------- XXX0 dts=%"PRId64" pts=%"PRId64" interpolated=%"PRId64,
             //         p_pic->i_dts, p_pic->i_pts, p_sys->i_interpolated_dts );
diff --git a/modules/stream_filter/hds/hds.c b/modules/stream_filter/hds/hds.c
index 280927b2e5..1b2290ee03 100644
--- a/modules/stream_filter/hds/hds.c
+++ b/modules/stream_filter/hds/hds.c
@@ -1167,7 +1167,9 @@ static void* live_thread( void* p )
             vlc_stream_Delete( download_stream );
         }
 
-        vlc_tick_wait( last_dl_start_time + (CLOCK_FREQ * hds_stream->fragment_runs[hds_stream->fragment_run_count-1].fragment_duration) / hds_stream->afrt_timescale);
+        vlc_tick_wait( last_dl_start_time +
+                       vlc_tick_from_samples(hds_stream->fragment_runs[hds_stream->fragment_run_count-1].fragment_duration,
+                                             hds_stream->afrt_timescale) );
 
 
     }
diff --git a/modules/stream_out/sdi/AES3Audio.cpp b/modules/stream_out/sdi/AES3Audio.cpp
index 0381f51ae5..5352880aa9 100644
--- a/modules/stream_out/sdi/AES3Audio.cpp
+++ b/modules/stream_out/sdi/AES3Audio.cpp
@@ -79,7 +79,7 @@ size_t AES3AudioBuffer::FramesToBytes(unsigned f) const
 
 vlc_tick_t AES3AudioBuffer::FramesToDuration(unsigned f) const
 {
-    return CLOCK_FREQ * f / 48000;
+    return vlc_tick_from_samples(f, 48000);
 }
 
 unsigned AES3AudioBuffer::BytesToFrames(size_t s) const
diff --git a/modules/video_filter/deinterlace/common.c b/modules/video_filter/deinterlace/common.c
index 95d144339f..04a4593716 100644
--- a/modules/video_filter/deinterlace/common.c
+++ b/modules/video_filter/deinterlace/common.c
@@ -94,7 +94,7 @@ vlc_tick_t GetFieldDuration(const struct deinterlace_ctx *p_context,
         i_field_dur = (p_pic->date - p_context->meta[i].pi_date) / i_fields_total;
     }
     else if (fmt->i_frame_rate_base)
-        i_field_dur = CLOCK_FREQ * fmt->i_frame_rate_base / fmt->i_frame_rate;
+        i_field_dur = vlc_tick_from_samples( fmt->i_frame_rate_base, fmt->i_frame_rate);
 
     /* Note that we default to field duration 0 if it could not be
        determined. This behaves the same as the old code - leaving the
diff --git a/modules/video_output/decklink.cpp b/modules/video_output/decklink.cpp
index 4dcccddb56..1e20c78d30 100644
--- a/modules/video_output/decklink.cpp
+++ b/modules/video_output/decklink.cpp
@@ -1097,7 +1097,7 @@ static void Flush (audio_output_t *aout, bool drain)
     if (drain) {
         uint32_t samples;
         sys->p_output->GetBufferedAudioSampleFrameCount(&samples);
-        vlc_tick_sleep(CLOCK_FREQ * samples / sys->i_rate);
+        vlc_tick_sleep(vlc_tick_from_samples(samples, sys->i_rate));
     } else if (sys->p_output->FlushBufferedAudioSamples() == E_FAIL)
         msg_Err(aout, "Flush failed");
 }



More information about the vlc-commits mailing list