[vlc-commits] modules: use samples_from_vlc_tick()

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


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Thu Sep 20 13:50:04 2018 +0200| [5e95c92802e195d7c6386fe3318d45f4c49a427b] | committer: Steve Lhomme

modules: use samples_from_vlc_tick()

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

 modules/access/rtp/session.c            |  2 +-
 modules/audio_output/audiotrack.c       |  5 ++---
 modules/audio_output/jack.c             |  4 ++--
 modules/codec/opus.c                    |  2 +-
 modules/demux/caf.c                     |  3 ++-
 modules/demux/mkv/mkv.cpp               |  3 +--
 modules/mux/mp4/libmp4mux.c             | 16 ++++++++--------
 modules/mux/mp4/mp4.c                   |  8 ++++----
 modules/mux/ogg.c                       | 10 +++++-----
 modules/stream_out/sdi/AES3Audio.cpp    |  2 +-
 modules/stream_out/sdi/DBMSDIOutput.cpp |  2 +-
 modules/video_output/decklink.cpp       |  2 +-
 12 files changed, 29 insertions(+), 30 deletions(-)

diff --git a/modules/access/rtp/session.c b/modules/access/rtp/session.c
index a4a8268efd..49ba9efbe3 100644
--- a/modules/access/rtp/session.c
+++ b/modules/access/rtp/session.c
@@ -313,7 +313,7 @@ rtp_queue (demux_t *demux, rtp_session_t *session, block_t *block)
              * It is independent of RTP sequence. */
             uint32_t freq = pt->frequency;
             int64_t ts = rtp_timestamp (block);
-            int64_t d = SEC_FROM_VLC_TICK((now - src->last_rx) * freq);
+            int64_t d = samples_from_vlc_tick(now - src->last_rx, freq);
             d        -=    ts - src->last_ts;
             if (d < 0) d = -d;
             src->jitter += ((d - src->jitter) + 8) >> 4;
diff --git a/modules/audio_output/audiotrack.c b/modules/audio_output/audiotrack.c
index 5cce12af49..e2f83026c8 100644
--- a/modules/audio_output/audiotrack.c
+++ b/modules/audio_output/audiotrack.c
@@ -705,7 +705,7 @@ AudioTrack_GetTimestampPositionUs( JNIEnv *env, audio_output_t *p_aout )
      && ( i_now - p_sys->timestamp.i_frame_us ) <= VLC_TICK_FROM_SEC(10) )
     {
         vlc_tick_t i_time_diff = i_now - p_sys->timestamp.i_frame_us;
-        jlong i_frames_diff = i_time_diff * p_sys->fmt.i_rate / CLOCK_FREQ;
+        jlong i_frames_diff = samples_from_vlc_tick(i_time_diff, p_sys->fmt.i_rate);
         return FRAMES_TO_US( p_sys->timestamp.i_frame_pos + i_frames_diff );
     } else
         return 0;
@@ -1247,8 +1247,7 @@ Start( audio_output_t *p_aout, audio_sample_format_t *restrict p_fmt )
     else
     {
         /* 2 seconds of buffering */
-        p_sys->circular.i_size = p_sys->circular.i_size * AOUT_MAX_PREPARE_TIME
-                               / CLOCK_FREQ;
+        p_sys->circular.i_size = samples_from_vlc_tick(AOUT_MAX_PREPARE_TIME, p_sys->circular.i_size);
     }
 
     /* Allocate circular buffer */
diff --git a/modules/audio_output/jack.c b/modules/audio_output/jack.c
index eabb847cab..44618b6da8 100644
--- a/modules/audio_output/jack.c
+++ b/modules/audio_output/jack.c
@@ -180,8 +180,8 @@ static int Start( audio_output_t *p_aout, audio_sample_format_t *restrict fmt )
         goto error_out;
     }
 
-    const size_t buf_sz = AOUT_MAX_ADVANCE_TIME * fmt->i_rate *
-        fmt->i_bytes_per_frame / CLOCK_FREQ;
+    const size_t buf_sz =
+        samples_from_vlc_tick(AOUT_MAX_ADVANCE_TIME, fmt->i_rate * fmt->i_bytes_per_frame);
     p_sys->p_jack_ringbuffer = jack_ringbuffer_create( buf_sz );
 
     if( p_sys->p_jack_ringbuffer == NULL )
diff --git a/modules/codec/opus.c b/modules/codec/opus.c
index 48b36d1c40..3d25ecfc66 100644
--- a/modules/codec/opus.c
+++ b/modules/codec/opus.c
@@ -484,7 +484,7 @@ static block_t *DecodePacket( decoder_t *p_dec, ogg_packet *p_oggpacket,
     if( i_duration > 0 && spp > 0 &&
         i_duration < i_nb_samples * CLOCK_FREQ / 48000 )
     {
-        i_end_trim = spp - VLC_CLIP(i_duration * 48000 / CLOCK_FREQ, 0, spp);
+        i_end_trim = spp - VLC_CLIP(samples_from_vlc_tick(i_duration, 48000), 0, spp);
     }
 
     if( spp < 0 || i_nb_samples <= 0 || i_end_trim >= i_nb_samples)
diff --git a/modules/demux/caf.c b/modules/demux/caf.c
index c48114aa19..87ac2a2dd0 100644
--- a/modules/demux/caf.c
+++ b/modules/demux/caf.c
@@ -1039,7 +1039,8 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
             return VLC_SUCCESS;
 
         case DEMUX_SET_TIME:
-            i_sample = va_arg( args, vlc_tick_t ) * p_sys->fmt.audio.i_rate / CLOCK_FREQ;
+            i_sample =
+                samples_from_vlc_tick( va_arg( args, vlc_tick_t ), p_sys->fmt.audio.i_rate );
             if( SetSpanWithSample( p_demux, &position, i_sample ))
                 return VLC_EGENERIC;
             p_sys->position = position;
diff --git a/modules/demux/mkv/mkv.cpp b/modules/demux/mkv/mkv.cpp
index 352e84139e..615160f063 100644
--- a/modules/demux/mkv/mkv.cpp
+++ b/modules/demux/mkv/mkv.cpp
@@ -632,8 +632,7 @@ void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simpleblock
                 vlc_tick_t i_length = VLC_TICK_FROM_NS(i_duration * track.f_timecodescale *
                                                        p_segment->i_timescale);
                 if ( i_length < 0 ) i_length = 0;
-                p_block->i_nb_samples = i_length * track.fmt.audio.i_rate
-                        / CLOCK_FREQ;
+                p_block->i_nb_samples = samples_from_vlc_tick(i_length, track.fmt.audio.i_rate);
             }
             break;
 
diff --git a/modules/mux/mp4/libmp4mux.c b/modules/mux/mp4/libmp4mux.c
index 217a338e0a..772bc1f10f 100644
--- a/modules/mux/mp4/libmp4mux.c
+++ b/modules/mux/mp4/libmp4mux.c
@@ -203,15 +203,15 @@ static bo_t *GetEDTS( mp4mux_trackinfo_t *p_track, uint32_t i_movietimescale, bo
         if(p_track->p_edits[i].i_start_offset != 0)
         {
             AddEdit(elst,
-                    p_track->p_edits[i].i_start_offset * i_movietimescale / CLOCK_FREQ,
+                    samples_from_vlc_tick(p_track->p_edits[i].i_start_offset, i_movietimescale),
                     -1,
                     b_64_ext);
         }
 
         /* !WARN AGAIN! Uses different Timescales ! */
         AddEdit(elst,
-                p_track->p_edits[i].i_duration * i_movietimescale / CLOCK_FREQ,
-                p_track->p_edits[i].i_start_time * p_track->i_timescale / CLOCK_FREQ,
+                samples_from_vlc_tick(p_track->p_edits[i].i_duration, i_movietimescale),
+                samples_from_vlc_tick(p_track->p_edits[i].i_start_time, p_track->i_timescale),
                 b_64_ext);
     }
 
@@ -1166,7 +1166,7 @@ static int64_t GetScaledEntryDuration( const mp4mux_entry_t *p_entry, uint32_t i
     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 */
-    int64_t i_scaled = (p_entry->i_length + i_diff) * i_timescale / CLOCK_FREQ;
+    int64_t i_scaled = samples_from_vlc_tick(p_entry->i_length + i_diff, i_timescale);
     *pi_total_mtime += p_entry->i_length;
     *pi_total_scaled += i_scaled;
 
@@ -1307,7 +1307,7 @@ static bo_t *GetStblBox(vlc_object_t *p_obj, mp4mux_trackinfo_t *p_track, bool b
                     break;
 
             bo_add_32be(ctts, i - i_first); // sample-count
-            bo_add_32be(ctts, i_offset * p_track->i_timescale / CLOCK_FREQ ); // sample-offset
+            bo_add_32be(ctts, samples_from_vlc_tick(i_offset, p_track->i_timescale) ); // sample-offset
         }
         bo_swap_32be(ctts, 12, i_index);
     }
@@ -1424,7 +1424,7 @@ bo_t * mp4mux_GetMoovBox(vlc_object_t *p_obj, mp4mux_trackinfo_t **pp_tracks, un
         if(p_obj)
             msg_Dbg(p_obj, "movie duration %"PRId64"s", SEC_FROM_VLC_TICK(i_duration));
     }
-    int64_t i_movie_duration = i_duration * i_movie_timescale / CLOCK_FREQ;
+    int64_t i_movie_duration = samples_from_vlc_tick(i_duration, i_movie_timescale);
 
     /* *** add /moov/mvhd *** */
     if (!b_64_ext) {
@@ -1473,7 +1473,7 @@ bo_t * mp4mux_GetMoovBox(vlc_object_t *p_obj, mp4mux_trackinfo_t **pp_tracks, un
 
         int64_t i_stream_duration;
         if ( !b_fragmented )
-            i_stream_duration = p_stream->i_read_duration * i_movie_timescale / CLOCK_FREQ;
+            i_stream_duration = samples_from_vlc_tick(p_stream->i_read_duration, i_movie_timescale);
         else
             i_stream_duration = 0;
 
@@ -1817,7 +1817,7 @@ bo_t * mp4mux_GetMoovBox(vlc_object_t *p_obj, mp4mux_trackinfo_t **pp_tracks, un
                 bo_t *trex = box_full_new("trex", 0, 0);
                 bo_add_32be(trex, p_stream->i_track_id);
                 bo_add_32be(trex, 1); // sample desc index
-                bo_add_32be(trex, (uint64_t)p_stream->i_trex_default_length * p_stream->i_timescale / CLOCK_FREQ); // sample duration
+                bo_add_32be(trex, samples_from_vlc_tick(p_stream->i_trex_default_length, p_stream->i_timescale)); // sample duration
                 bo_add_32be(trex, p_stream->i_trex_default_size); // sample size
                 bo_add_32be(trex, 0); // sample flags
                 box_gather(mvex, trex);
diff --git a/modules/mux/mp4/mp4.c b/modules/mux/mp4/mp4.c
index 7cb6012be8..a5eb85c835 100644
--- a/modules/mux/mp4/mp4.c
+++ b/modules/mux/mp4/mp4.c
@@ -992,7 +992,7 @@ static bo_t *GetMoofBox(sout_mux_t *p_mux, size_t *pi_mdat_total_size,
 
         /* set the local sample duration default */
         if (i_tfhd_flags & MP4_TFHD_DFLT_SAMPLE_DURATION)
-            bo_add_32be(tfhd, p_stream->read.p_first->p_block->i_length * p_stream->mux.i_timescale / CLOCK_FREQ);
+            bo_add_32be(tfhd, samples_from_vlc_tick(p_stream->read.p_first->p_block->i_length, p_stream->mux.i_timescale));
 
         /* set the local sample size default */
         if (i_tfhd_flags & MP4_TFHD_DFLT_SAMPLE_SIZE)
@@ -1007,7 +1007,7 @@ static bo_t *GetMoofBox(sout_mux_t *p_mux, size_t *pi_mdat_total_size,
             bo_free(traf);
             continue;
         }
-        bo_add_64be(tfdt, p_stream->i_written_duration * p_stream->mux.i_timescale / CLOCK_FREQ );
+        bo_add_64be(tfdt, samples_from_vlc_tick(p_stream->i_written_duration, p_stream->mux.i_timescale) );
         box_gather(traf, tfdt);
 
         /* *** add /moof/traf/trun *** */
@@ -1067,7 +1067,7 @@ static bo_t *GetMoofBox(sout_mux_t *p_mux, size_t *pi_mdat_total_size,
                 DEQUEUE_ENTRY(p_stream->read, p_entry);
 
                 if (i_trun_flags & MP4_TRUN_SAMPLE_DURATION)
-                    bo_add_32be(trun, p_entry->p_block->i_length * p_stream->mux.i_timescale / CLOCK_FREQ); // sample duration
+                    bo_add_32be(trun, samples_from_vlc_tick(p_entry->p_block->i_length, p_stream->mux.i_timescale)); // sample duration
 
                 if (i_trun_flags & MP4_TRUN_SAMPLE_SIZE)
                     bo_add_32be(trun, p_entry->p_block->i_buffer); // sample size
@@ -1080,7 +1080,7 @@ static bo_t *GetMoofBox(sout_mux_t *p_mux, size_t *pi_mdat_total_size,
                     {
                         i_diff = p_entry->p_block->i_pts - p_entry->p_block->i_dts;
                     }
-                    bo_add_32be(trun, i_diff * p_stream->mux.i_timescale / CLOCK_FREQ); // ctts
+                    bo_add_32be(trun, samples_from_vlc_tick(i_diff, p_stream->mux.i_timescale)); // ctts
                 }
 
                 *pi_mdat_total_size += p_entry->p_block->i_buffer;
diff --git a/modules/mux/ogg.c b/modules/mux/ogg.c
index 0452694c4c..8c328fd572 100644
--- a/modules/mux/ogg.c
+++ b/modules/mux/ogg.c
@@ -1446,7 +1446,7 @@ static bool AllocateIndex( sout_mux_t *p_mux, sout_input_t *p_input )
         /* estimate length of pos value */
         if ( p_input->p_fmt->i_bitrate )
         {
-            i = i_interval * p_input->p_fmt->i_bitrate / CLOCK_FREQ;
+            i = samples_from_vlc_tick(i_interval, p_input->p_fmt->i_bitrate);
             while ( i <<= 1 ) i_tuple_size++;
         }
         else
@@ -1618,8 +1618,8 @@ static int MuxBlock( sout_mux_t *p_mux, sout_input_t *p_input )
         {
             /* number of sample from begining + current packet */
             op.granulepos =
-                ( p_data->i_dts - p_sys->i_start_dts + p_data->i_length ) *
-                (vlc_tick_t)p_input->p_fmt->audio.i_rate / CLOCK_FREQ;
+                samples_from_vlc_tick( p_data->i_dts - p_sys->i_start_dts + p_data->i_length,
+                                       p_input->p_fmt->audio.i_rate );
 
             i_time = p_data->i_dts - p_sys->i_start_dts;
             AddIndexEntry( p_mux, i_time, p_input );
@@ -1627,8 +1627,8 @@ static int MuxBlock( sout_mux_t *p_mux, sout_input_t *p_input )
         else if( p_stream->p_oggds_header )
         {
             /* number of sample from begining */
-            op.granulepos = ( p_data->i_dts - p_sys->i_start_dts ) *
-                p_stream->p_oggds_header->i_samples_per_unit / CLOCK_FREQ;
+            op.granulepos = samples_from_vlc_tick( p_data->i_dts - p_sys->i_start_dts,
+                                  p_stream->p_oggds_header->i_samples_per_unit );
         }
     }
     else if( p_stream->fmt.i_cat == VIDEO_ES )
diff --git a/modules/stream_out/sdi/AES3Audio.cpp b/modules/stream_out/sdi/AES3Audio.cpp
index 81fcda079d..0381f51ae5 100644
--- a/modules/stream_out/sdi/AES3Audio.cpp
+++ b/modules/stream_out/sdi/AES3Audio.cpp
@@ -89,7 +89,7 @@ unsigned AES3AudioBuffer::BytesToFrames(size_t s) const
 
 unsigned AES3AudioBuffer::TicksDurationToFrames(vlc_tick_t t) const
 {
-    return t * 48000 / CLOCK_FREQ;
+    return samples_from_vlc_tick(t, 48000);
 }
 
 void AES3AudioBuffer::flushConsumed()
diff --git a/modules/stream_out/sdi/DBMSDIOutput.cpp b/modules/stream_out/sdi/DBMSDIOutput.cpp
index 0818e4fc03..a5a947b13e 100644
--- a/modules/stream_out/sdi/DBMSDIOutput.cpp
+++ b/modules/stream_out/sdi/DBMSDIOutput.cpp
@@ -487,7 +487,7 @@ int DBMSDIOutput::Start()
     if(b_running)
         return VLC_EGENERIC;
     result = p_output->StartScheduledPlayback(
-                     SEC_FROM_VLC_TICK(vlc_tick_now() * timescale), timescale, 1.0);
+                     samples_from_vlc_tick(vlc_tick_now(), timescale), timescale, 1.0);
     CHECK("Could not start playback");
     b_running = true;
     return VLC_SUCCESS;
diff --git a/modules/video_output/decklink.cpp b/modules/video_output/decklink.cpp
index 3e6a291b7a..4dcccddb56 100644
--- a/modules/video_output/decklink.cpp
+++ b/modules/video_output/decklink.cpp
@@ -727,7 +727,7 @@ static int OpenDecklink(vout_display_t *vd, decklink_sys_t *sys)
 
     /* start */
     result = sys->p_output->StartScheduledPlayback(
-        SEC_FROM_VLC_TICK(vlc_tick_now() * sys->timescale), sys->timescale, 1.0);
+        samples_from_vlc_tick(vlc_tick_now(), sys->timescale), sys->timescale, 1.0);
     CHECK("Could not start playback");
 
     p_config->Release();



More information about the vlc-commits mailing list