1 /***************************************************************************** 2 * Time.hpp: Adaptative streaming time definitions 3 ***************************************************************************** 4 * Copyright © 2015 - VideoLAN and VLC Authors 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU Lesser General Public License as published 8 * by the Free Software Foundation; either version 2.1 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public License 17 * along with this program; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 19 *****************************************************************************/ 20 #ifndef TIME_HPP 21 #define TIME_HPP 22 23 #include <vlc_common.h> 24 25 /* Scaled time */ 26 typedef int64_t stime_t; 27 28 class Timescale 29 { 30 public: Timescale(uint64_t v=0)31 Timescale(uint64_t v = 0) : scale(v) {} 32 ToTime(stime_t t) const33 mtime_t ToTime(stime_t t) const 34 { 35 if( !scale ) return 0; 36 stime_t v = t / scale; 37 stime_t r = t % scale; 38 return v * 1000000 + r * 1000000 / scale; 39 } 40 ToScaled(mtime_t t) const41 stime_t ToScaled(mtime_t t) const 42 { 43 mtime_t v = t / 1000000; 44 mtime_t r = t % 1000000; 45 return v * scale + r * scale / 1000000; 46 } 47 isValid() const48 bool isValid() const { return !!scale; } operator uint64_t() const49 operator uint64_t() const { return scale; } 50 51 private: 52 uint64_t scale; 53 }; 54 55 #endif // TIME_HPP 56 57