[vlc-devel] [PATCH 1/2] cdda: use time<->position helpers

Thomas Guillem thomas at gllm.fr
Thu Apr 1 15:01:50 UTC 2021


---
 modules/access/cdda.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/modules/access/cdda.c b/modules/access/cdda.c
index 9260b833eda..541e043a574 100644
--- a/modules/access/cdda.c
+++ b/modules/access/cdda.c
@@ -178,6 +178,16 @@ static int Demux(demux_t *demux)
     return VLC_DEMUXER_SUCCESS;
 }
 
+static inline vlc_tick_t PositionToTime(unsigned position)
+{
+    return (INT64_C(40000) * position) / 3;
+}
+
+static inline unsigned TimeToPosition(vlc_tick_t time)
+{
+    return time * 3 / INT64_C(40000);
+}
+
 static int DemuxControl(demux_t *demux, int query, va_list args)
 {
     demux_sys_t *sys = demux->p_sys;
@@ -211,14 +221,17 @@ static int DemuxControl(demux_t *demux, int query, va_list args)
             break;
 
         case DEMUX_GET_LENGTH:
-            *va_arg(args, vlc_tick_t *) = (INT64_C(40000) * sys->length) / 3;
+            *va_arg(args, vlc_tick_t *) = PositionToTime(sys->length);
             break;
         case DEMUX_GET_TIME:
-            *va_arg(args, vlc_tick_t *) = (INT64_C(40000) * sys->position) / 3;
+            *va_arg(args, vlc_tick_t *) = PositionToTime(sys->position);
             break;
         case DEMUX_SET_TIME:
-            sys->position = (va_arg(args, vlc_tick_t) * 3) / INT64_C(40000);
+        {
+            vlc_tick_t time = va_arg(args, vlc_tick_t);
+            sys->position = TimeToPosition(time);
             break;
+        }
 
         default:
             return VLC_EGENERIC;
-- 
2.30.0



More information about the vlc-devel mailing list