[vlc-commits] modules: add more vlc_tick_from_samples()

Steve Lhomme git at videolan.org
Thu Sep 20 17:14:12 CEST 2018


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Thu Sep 20 16:52:17 2018 +0200| [08af3e16c06ccd99b0ca31c89879039eb38ee6ea] | committer: Steve Lhomme

modules: add more vlc_tick_from_samples()

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

 modules/access/linsys/linsys_hdsdi.c    | 4 ++--
 modules/audio_output/directsound.c      | 2 +-
 modules/audio_output/jack.c             | 6 +++---
 modules/audio_output/kai.c              | 4 ++--
 modules/audio_output/opensles_android.c | 2 +-
 modules/codec/g711.c                    | 4 ++--
 modules/codec/lpcm.c                    | 4 ++--
 modules/codec/shine.c                   | 6 +++---
 modules/demux/caf.c                     | 2 +-
 modules/demux/flac.c                    | 4 ++--
 modules/demux/nsv.c                     | 2 +-
 modules/demux/xiph_metadata.c           | 2 +-
 modules/hw/vdpau/deinterlace.c          | 4 ++--
 modules/mux/mp4/libmp4mux.c             | 2 +-
 modules/video_filter/fps.c              | 3 ++-
 src/os2/thread.c                        | 2 +-
 16 files changed, 27 insertions(+), 26 deletions(-)

diff --git a/modules/access/linsys/linsys_hdsdi.c b/modules/access/linsys/linsys_hdsdi.c
index a8a7b144bf..4952427ade 100644
--- a/modules/access/linsys/linsys_hdsdi.c
+++ b/modules/access/linsys/linsys_hdsdi.c
@@ -629,8 +629,8 @@ static int HandleAudio( demux_t *p_demux, const uint8_t *p_buffer )
                         p_audio->i_channel * 2, p_sys->i_max_channel + 1 );
 
             p_block->i_dts = p_block->i_pts
-                = p_sys->i_next_adate + (vlc_tick_t)p_audio->i_delay
-                   * CLOCK_FREQ / p_sys->i_sample_rate;
+                = p_sys->i_next_adate + vlc_tick_from_samples(p_audio->i_delay,
+                                                              p_sys->i_sample_rate);
             p_block->i_length = p_sys->i_aincr;
             es_out_Send( p_demux->out, p_audio->p_es, p_block );
         }
diff --git a/modules/audio_output/directsound.c b/modules/audio_output/directsound.c
index 262e070ffc..fd9d94591f 100644
--- a/modules/audio_output/directsound.c
+++ b/modules/audio_output/directsound.c
@@ -171,7 +171,7 @@ static HRESULT TimeGet( aout_stream_sys_t *sys, vlc_tick_t *delay )
         /* underrun */
         Flush(sys, false);
 
-    *delay = ( sys->i_data / sys->i_bytes_per_sample ) * CLOCK_FREQ / sys->i_rate;
+    *delay = vlc_tick_from_samples( sys->i_data / sys->i_bytes_per_sample, sys->i_rate );
 
     return DS_OK;
 }
diff --git a/modules/audio_output/jack.c b/modules/audio_output/jack.c
index 44618b6da8..c388e4304a 100644
--- a/modules/audio_output/jack.c
+++ b/modules/audio_output/jack.c
@@ -352,9 +352,9 @@ static int TimeGet(audio_output_t *p_aout, vlc_tick_t *delay)
     jack_ringbuffer_t *rb = p_sys->p_jack_ringbuffer;
     const size_t bytes_per_frame = p_sys->i_channels * sizeof(jack_sample_t);
 
-    *delay = (p_sys->latency +
-            (jack_ringbuffer_read_space(rb) / bytes_per_frame)) *
-        CLOCK_FREQ / p_sys->i_rate;
+    *delay = p_sys->latency +
+            vlc_tick_from_samples(jack_ringbuffer_read_space(rb) / bytes_per_frame,
+                                  p_sys->i_rate);
 
     return 0;
 }
diff --git a/modules/audio_output/kai.c b/modules/audio_output/kai.c
index 6f26b49173..98a2182394 100644
--- a/modules/audio_output/kai.c
+++ b/modules/audio_output/kai.c
@@ -339,8 +339,8 @@ static int TimeGet( audio_output_t *aout, vlc_tick_t *restrict delay )
 
     vlc_mutex_lock( &buffer->mutex );
 
-    *delay = ( buffer->length / format->i_bytes_per_frame ) * CLOCK_FREQ /
-             format->i_rate;
+    *delay = vlc_tick_from_samples( buffer->length / format->i_bytes_per_frame,
+                                    format->i_rate );
 
     vlc_mutex_unlock( &buffer->mutex );
 
diff --git a/modules/audio_output/opensles_android.c b/modules/audio_output/opensles_android.c
index d1112b76b2..4a5674c649 100644
--- a/modules/audio_output/opensles_android.c
+++ b/modules/audio_output/opensles_android.c
@@ -169,7 +169,7 @@ static int TimeGet(audio_output_t* aout, vlc_tick_t* restrict drift)
         return -1;
 
     *drift = (CLOCK_FREQ * OPENSLES_BUFLEN * st.count / 1000)
-        + sys->samples * CLOCK_FREQ / sys->rate;
+        + vlc_tick_from_samples(sys->samples, sys->rate);
 
     /* msg_Dbg(aout, "latency %"PRId64" ms, %d/%d buffers", *drift / 1000,
         (int)st.count, OPENSLES_BUFFERS); */
diff --git a/modules/codec/g711.c b/modules/codec/g711.c
index c191a63e49..c044cbaabe 100644
--- a/modules/codec/g711.c
+++ b/modules/codec/g711.c
@@ -1209,8 +1209,8 @@ static block_t *EncoderEncode( encoder_t *p_enc, block_t *p_aout_buf )
     }
 
     p_block->i_dts = p_block->i_pts = p_aout_buf->i_pts;
-    p_block->i_length = (int64_t)p_aout_buf->i_nb_samples *
-                        CLOCK_FREQ / p_enc->fmt_in.audio.i_rate;
+    p_block->i_length = vlc_tick_from_samples(p_aout_buf->i_nb_samples,
+                                              p_enc->fmt_in.audio.i_rate);
     return p_block;
 }
 #endif /* ENABLE_SOUT */
diff --git a/modules/codec/lpcm.c b/modules/codec/lpcm.c
index f22b3db8bd..bd52689b5b 100644
--- a/modules/codec/lpcm.c
+++ b/modules/codec/lpcm.c
@@ -662,9 +662,9 @@ static block_t *EncodeFrames( encoder_t *p_enc, block_t *p_aout_buf )
 
         /* We need to find i_length by means of next_pts due to possible roundoff errors. */
         vlc_tick_t this_pts = p_aout_buf->i_pts +
-            (i * p_sys->i_frame_samples + i_start_offset) * CLOCK_FREQ / p_sys->i_rate;
+            vlc_tick_from_samples(i * p_sys->i_frame_samples + i_start_offset, p_sys->i_rate);
         vlc_tick_t next_pts = p_aout_buf->i_pts +
-            ((i + 1) * p_sys->i_frame_samples + i_start_offset) * CLOCK_FREQ / p_sys->i_rate;
+            vlc_tick_from_samples((i + 1) * p_sys->i_frame_samples + i_start_offset, p_sys->i_rate);
 
         p_block->i_pts = p_block->i_dts = this_pts;
         p_block->i_length = next_pts - this_pts;
diff --git a/modules/codec/shine.c b/modules/codec/shine.c
index 581f01c62a..c07430368a 100644
--- a/modules/codec/shine.c
+++ b/modules/codec/shine.c
@@ -228,7 +228,7 @@ static block_t *EncodeFrame( encoder_t *p_enc, block_t *p_block )
     block_t *p_chain = NULL;
     unsigned int i_samples = p_block->i_buffer >> 2 /* s16l stereo */;
     vlc_tick_t start_date = p_block->i_pts;
-    start_date -= (vlc_tick_t)i_samples * CLOCK_FREQ / (vlc_tick_t)p_enc->fmt_out.audio.i_rate;
+    start_date -= vlc_tick_from_samples(i_samples, p_enc->fmt_out.audio.i_rate);
 
     VLC_UNUSED(p_enc);
 
@@ -260,8 +260,8 @@ static block_t *EncodeFrame( encoder_t *p_enc, block_t *p_block )
         memcpy( p_mp3_block->p_buffer, buf, written );
 
         /* date management */
-        p_mp3_block->i_length = p_sys->samples_per_frame * CLOCK_FREQ /
-            p_enc->fmt_out.audio.i_rate;
+        p_mp3_block->i_length = vlc_tick_from_samples(p_sys->samples_per_frame,
+            p_enc->fmt_out.audio.i_rate);
 
         start_date += p_mp3_block->i_length;
         p_mp3_block->i_dts = p_mp3_block->i_pts = start_date;
diff --git a/modules/demux/caf.c b/modules/demux/caf.c
index 363b74b653..cc312a5a30 100644
--- a/modules/demux/caf.c
+++ b/modules/demux/caf.c
@@ -335,7 +335,7 @@ static inline vlc_tick_t FrameSpanGetTime( frame_span_t *span, uint32_t i_sample
     if( !i_sample_rate )
         return VLC_TICK_INVALID;
 
-    return ( span->i_samples * CLOCK_FREQ ) / i_sample_rate + VLC_TICK_0;
+    return vlc_tick_from_samples( span->i_samples, i_sample_rate) + VLC_TICK_0;
 }
 
 /* SetSpanWithSample returns the span from the beginning of the file up to and
diff --git a/modules/demux/flac.c b/modules/demux/flac.c
index abc0998fa5..34ca87c56c 100644
--- a/modules/demux/flac.c
+++ b/modules/demux/flac.c
@@ -726,8 +726,8 @@ static int  ParseHeaders( demux_t *p_demux, es_format_t *p_fmt )
             p_fmt->audio.i_channels = p_sys->stream_info.channels;
             p_fmt->audio.i_bitspersample = p_sys->stream_info.bits_per_sample;
             if( p_sys->stream_info.sample_rate > 0 )
-                p_sys->i_length = p_sys->stream_info.total_samples * CLOCK_FREQ
-                                / p_sys->stream_info.sample_rate;
+                p_sys->i_length = vlc_tick_from_samples(p_sys->stream_info.total_samples,
+                                  p_sys->stream_info.sample_rate);
 
             continue;
         }
diff --git a/modules/demux/nsv.c b/modules/demux/nsv.c
index 1d889ca7d5..0c6441a9c7 100644
--- a/modules/demux/nsv.c
+++ b/modules/demux/nsv.c
@@ -613,7 +613,7 @@ static int ReadNSVs( demux_t *p_demux )
     else if( header[16] != 0 )
     {
         /* Integer frame rate */
-        p_sys->i_pcr_inc = CLOCK_FREQ / header[16];
+        p_sys->i_pcr_inc = vlc_tick_from_samples(1, header[16]);
     }
     else
     {
diff --git a/modules/demux/xiph_metadata.c b/modules/demux/xiph_metadata.c
index de3748418f..2b9985ca2f 100644
--- a/modules/demux/xiph_metadata.c
+++ b/modules/demux/xiph_metadata.c
@@ -296,7 +296,7 @@ static void xiph_ParseCueSheetMeta( unsigned *pi_flags, vlc_meta_t *p_meta,
         unsigned m, s, f;
         if( sscanf( &psz_line[13], "%u:%u:%u", &m, &s, &f ) == 3 )
         {
-            p_seekpoint->i_time_offset = vlc_tick_from_sec(m * 60 + s) + f * CLOCK_FREQ/75;
+            p_seekpoint->i_time_offset = vlc_tick_from_sec(m * 60 + s) + vlc_tick_from_samples(f, 75);
             *pb_valid = true;
         }
     }
diff --git a/modules/hw/vdpau/deinterlace.c b/modules/hw/vdpau/deinterlace.c
index adfc0b859c..c57dcd509d 100644
--- a/modules/hw/vdpau/deinterlace.c
+++ b/modules/hw/vdpau/deinterlace.c
@@ -71,8 +71,8 @@ static picture_t *Deinterlace(filter_t *filter, picture_t *src)
         dst->date = (3 * src->date - last_pts) / 2;
     else
     if (filter->fmt_in.video.i_frame_rate != 0)
-        dst->date = src->date + ((filter->fmt_in.video.i_frame_rate_base
-                            * CLOCK_FREQ) / filter->fmt_in.video.i_frame_rate);
+        dst->date = src->date + vlc_tick_from_samples(filter->fmt_in.video.i_frame_rate_base
+                            ,filter->fmt_in.video.i_frame_rate);
     dst->b_top_field_first = !src->b_top_field_first;
     dst->i_nb_fields = 1;
     src->i_nb_fields = 1;
diff --git a/modules/mux/mp4/libmp4mux.c b/modules/mux/mp4/libmp4mux.c
index 772bc1f10f..bf2220f68c 100644
--- a/modules/mux/mp4/libmp4mux.c
+++ b/modules/mux/mp4/libmp4mux.c
@@ -1162,7 +1162,7 @@ static bo_t *GetTextBox(vlc_object_t *p_obj, mp4mux_trackinfo_t *p_track, bool b
 static int64_t GetScaledEntryDuration( const mp4mux_entry_t *p_entry, uint32_t i_timescale,
                                        vlc_tick_t *pi_total_mtime, int64_t *pi_total_scaled )
 {
-    const vlc_tick_t i_totalscaledtototalmtime = *pi_total_scaled * CLOCK_FREQ / i_timescale;
+    const vlc_tick_t i_totalscaledtototalmtime = vlc_tick_from_samples(*pi_total_scaled, i_timescale);
     const vlc_tick_t i_diff = *pi_total_mtime - i_totalscaledtototalmtime;
 
     /* Ensure to compensate the drift due to loss from time, and from scale, conversions */
diff --git a/modules/video_filter/fps.c b/modules/video_filter/fps.c
index 681c79db8f..9aea2dd468 100644
--- a/modules/video_filter/fps.c
+++ b/modules/video_filter/fps.c
@@ -164,7 +164,8 @@ static int Open( vlc_object_t *p_this)
             p_filter->fmt_in.video.i_frame_rate, p_filter->fmt_in.video.i_frame_rate_base,
             p_filter->fmt_out.video.i_frame_rate, p_filter->fmt_out.video.i_frame_rate_base );
 
-    p_sys->i_output_frame_interval = p_filter->fmt_out.video.i_frame_rate_base * CLOCK_FREQ / p_filter->fmt_out.video.i_frame_rate;
+    p_sys->i_output_frame_interval = vlc_tick_from_samples(p_filter->fmt_out.video.i_frame_rate_base,
+                                                           p_filter->fmt_out.video.i_frame_rate);
 
     date_Init( &p_sys->next_output_pts,
                p_filter->fmt_out.video.i_frame_rate, p_filter->fmt_out.video.i_frame_rate_base );
diff --git a/src/os2/thread.c b/src/os2/thread.c
index 17d2e60aa2..1c93c70797 100644
--- a/src/os2/thread.c
+++ b/src/os2/thread.c
@@ -909,7 +909,7 @@ vlc_tick_t vlc_tick_now (void)
     /* We need to split the division to avoid 63-bits overflow */
     lldiv_t d = lldiv (Q2LL(counter), freq);
 
-    return vlc_tick_from_sec( d.quot ) + ((d.rem * CLOCK_FREQ) / freq);
+    return vlc_tick_from_sec( d.quot ) + vlc_tick_from_samples(d.rem, freq);
 }
 
 #undef vlc_tick_wait



More information about the vlc-commits mailing list