[libdvdnav-devel] [Git][videolan/libdvdread][master] dvd_reader: use time() instead of gettimeofday() for CSS crack timing

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Wed Jul 29 06:47:55 UTC 2026



Jean-Baptiste Kempf pushed to branch master at VideoLAN / libdvdread


Commits:
1335d694 by Kacper Michajłow at 2026-07-29T08:47:09+02:00
dvd_reader: use time() instead of gettimeofday() for CSS crack timing

Simplifies the code and all the checks, time() is more than enough for
this simple log.

- - - - -


3 changed files:

- meson.build
- − msvc/include/sys/time.h
- src/dvd_reader.c


Changes:

=====================================
meson.build
=====================================
@@ -70,12 +70,7 @@ if host_machine.endian() == 'big'
   cdata.set('WORDS_BIGENDIAN', 1)
 endif
 
-if host_machine.system() == 'windows'
-# dvdread_headers += files('msvc/contrib/win32_cs.h')
-    if cc.has_function('gettimeofday', prefix: '#include <sys/time.h>', args: test_args)
-        cdata.set('HAVE_GETTIMEOFDAY', 1)
-    endif
-elif host_machine.system() == 'linux'
+if host_machine.system() == 'linux'
     if cc.has_function('getmntent_r', prefix: '#include <mntent.h>', args: test_args)
         cdata.set('HAVE_GETMNTENT_R', 1)
     endif


=====================================
msvc/include/sys/time.h deleted
=====================================
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2000-2001 the xine project
- *
- * This file is part of xine, a unix video player.
- *
- * xine is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * xine is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * WIN32 PORT,
- * by Matthew Grooms <elon at altavista.com>
- *
- * sys/time.h - There is no separate sys/time.h for win32 so we simply
- *              include the standard time header as well as our xine
- *                              timer functions.
- */
-
-#include <time.h>


=====================================
src/dvd_reader.c
=====================================
@@ -21,12 +21,12 @@
  */
 
 #include "config.h"
-#include <sys/time.h>       /* For the timing of dvdcss_title crack. */
+#include <time.h>           /* For the timing of dvdcss_title crack. */
 #include <stdlib.h>         /* free */
 #include <stdio.h>          /* fprintf */
 #include <errno.h>          /* errno, EIN* */
 #include <string.h>         /* memcpy, strlen */
-#include <unistd.h>         /* pclose */
+#include <unistd.h>         /* close */
 #include <limits.h>         /* PATH_MAX */
 #include <ctype.h>          /* isalpha */
 
@@ -67,24 +67,6 @@
 #define PATH_MAX _MAX_PATH
 #endif
 
-/* misc win32 helpers */
-
-#ifdef _WIN32
-# ifndef HAVE_GETTIMEOFDAY
-   /* replacement gettimeofday implementation */
-#  include <sys/timeb.h>
-static inline int _private_gettimeofday( struct timeval *tv, void *tz )
-{
-  struct timeb t;
-  ftime( &t );
-  tv->tv_sec = t.time;
-  tv->tv_usec = t.millitm * 1000;
-  return 0;
-}
-#  define gettimeofday(TV, TZ) _private_gettimeofday((TV), (TZ))
-# endif
-#endif /* _WIN32 */
-
 #define DEFAULT_UDF_CACHE_LEVEL 1
 
 struct dvd_reader_device_s {
@@ -172,8 +154,8 @@ void SetUDFCacheHandle(dvd_reader_t *reader, void *cache)
 static int initAllCSSKeys( dvd_reader_t *ctx )
 {
   dvd_reader_device_t *dvd = ctx->rd;
-  struct timeval all_s, all_e;
-  struct timeval t_s, t_e;
+  time_t all_s, all_e;
+  time_t t_s, t_e;
   char filename[ MAX_UDF_FILE_NAME_LEN ];
   uint32_t start, len;
   int title;
@@ -184,10 +166,10 @@ static int initAllCSSKeys( dvd_reader_t *ctx )
 
   Log2(ctx,"Attempting to retrieve all CSS keys" );
   Log2(ctx,"This can take a _long_ time, please be patient" );
-  gettimeofday(&all_s, NULL);
+  all_s = time(NULL);
 
   for( title = 0; title < 100; title++ ) {
-    gettimeofday( &t_s, NULL );
+    t_s = time(NULL);
     if( title == 0 ) {
       strcpy( filename, "/VIDEO_TS/VIDEO_TS.VOB" );
     } else {
@@ -200,13 +182,13 @@ static int initAllCSSKeys( dvd_reader_t *ctx )
       if( dvdinput_title( dvd->dev, (int)start ) < 0 ) {
         Log1(ctx,"Error cracking CSS key for %s (0x%08x)", filename, start);
       }
-      gettimeofday( &t_e, NULL );
-      Log3(ctx,"Elapsed time %ld", (long int) t_e.tv_sec - t_s.tv_sec );
+      t_e = time(NULL);
+      Log3(ctx,"Elapsed time %.0f", difftime(t_e, t_s) );
     }
 
     if( title == 0 ) continue;
 
-    gettimeofday( &t_s, NULL );
+    t_s = time(NULL);
     sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, 1 );
     start = UDFFindFile( ctx, filename, &len );
     if( start == 0 || len == 0 ) break;
@@ -216,14 +198,14 @@ static int initAllCSSKeys( dvd_reader_t *ctx )
     if( dvdinput_title( dvd->dev, (int)start ) < 0 ) {
       Log1(ctx,"Error cracking CSS key for %s (0x%08x)", filename, start);
     }
-    gettimeofday( &t_e, NULL );
-    Log3(ctx,"Elapsed time %ld", (long int) t_e.tv_sec - t_s.tv_sec );
+    t_e = time(NULL);
+    Log3(ctx,"Elapsed time %.0f", difftime(t_e, t_s) );
   }
   title--;
 
   Log3(ctx,"Found %d VTS's", title );
-  gettimeofday(&all_e, NULL);
-  Log3(ctx,"Elapsed time %ld", (long int) all_e.tv_sec - all_s.tv_sec );
+  all_e = time(NULL);
+  Log3(ctx,"Elapsed time %.0f", difftime(all_e, all_s) );
 
   return 0;
 }



View it on GitLab: https://code.videolan.org/videolan/libdvdread/-/commit/1335d694cf8f56ca7127f2362d4c37c4274c5a56

-- 
View it on GitLab: https://code.videolan.org/videolan/libdvdread/-/commit/1335d694cf8f56ca7127f2362d4c37c4274c5a56
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the libdvdnav-devel mailing list