[vlc-commits] [Git][videolan/vlc][master] demux: adaptive: fix fractional part in iso 8601

Jean-Baptiste Kempf gitlab at videolan.org
Tue Jun 22 14:27:30 UTC 2021



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


Commits:
254cc167 by Francois Cartegnie at 2021-06-22T13:55:28+00:00
demux: adaptive: fix fractional part in iso 8601

- - - - -


2 changed files:

- modules/demux/adaptive/test/tools/Conversions.cpp
- modules/demux/adaptive/tools/Conversions.cpp


Changes:

=====================================
modules/demux/adaptive/test/tools/Conversions.cpp
=====================================
@@ -47,6 +47,11 @@ int Conversions_test()
     Expect(utc.mtime() == vlc_tick_from_sec(1560271925) + VLC_TICK_FROM_MS(12));
     utc = UTCTime("T16:52:05.012Z");
 
+    /* Check non ms fractional */
+    utc = UTCTime("2021-05-28T12:51:32+00:00");
+    Expect(utc.mtime() == vlc_tick_from_sec(1622206292));
+    utc = UTCTime("2021-05-28T12:51:32.996000+00:00");
+    Expect(utc.mtime() == vlc_tick_from_sec(1622206292)+VLC_TICK_FROM_MS(996));
 
     IsoTime isotime("PT0H9M56.46S");
     Expect(isotime == (vlc_tick_from_sec(9*60+56)+VLC_TICK_FROM_MS(460)));


=====================================
modules/demux/adaptive/tools/Conversions.cpp
=====================================
@@ -98,8 +98,9 @@ IsoTime::operator vlc_tick_t () const
 
 UTCTime::UTCTime(const std::string &str)
 {
-    enum { UTCTIME_YEAR = 0, UTCTIME_MON, UTCTIME_DAY, UTCTIME_HOUR, UTCTIME_MIN, UTCTIME_SEC, UTCTIME_MSEC, UTCTIME_TZ };
-    int values[8] = {0};
+    enum { UTCTIME_YEAR = 0, UTCTIME_MON, UTCTIME_DAY, UTCTIME_HOUR, UTCTIME_MIN,
+           UTCTIME_SEC, UTCTIME_FRAC_NUM, UTCTIME_FRAC_DEN, UTCTIME_TZ };
+    int values[9] = {0};
     std::istringstream in(str);
     in.imbue(std::locale("C"));
 
@@ -124,7 +125,16 @@ UTCTime::UTCTime(const std::string &str)
         if(!in.eof() && in.peek() == '.')
         {
             in.ignore(1);
-            in >> values[UTCTIME_MSEC];
+            values[UTCTIME_FRAC_NUM] = 0;
+            values[UTCTIME_FRAC_DEN] = 1;
+            int c = in.peek();
+            while(c >= '0' && c <= '9')
+            {
+                values[UTCTIME_FRAC_NUM] = values[UTCTIME_FRAC_NUM] * 10 + (c - '0');
+                values[UTCTIME_FRAC_DEN] *= 10;
+                in.ignore(1);
+                c = in.peek();
+            }
         }
         /* Timezone */
         if(!in.eof() && in.peek() == 'Z')
@@ -172,8 +182,9 @@ UTCTime::UTCTime(const std::string &str)
             int64_t mst = timegm( &tm );
             mst += values[UTCTIME_TZ] * -60;
             mst *= 1000;
-            mst += values[UTCTIME_MSEC];
             t = VLC_TICK_FROM_MS(mst);
+            if(values[UTCTIME_FRAC_DEN] > 0)
+                t += vlc_tick_from_samples(values[UTCTIME_FRAC_NUM], values[UTCTIME_FRAC_DEN]);
         } else {
             // Failure parsing time string
             t = 0;



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/254cc167bcafeebd003d15c9c7787b7d7f8ab2b3

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/254cc167bcafeebd003d15c9c7787b7d7f8ab2b3
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list