1 /*
2    mkvmerge -- utility for splicing together matroska files
3    from component media subtypes
4 
5    Distributed under the GPL v2
6    see the file COPYING for details
7    or visit https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
8 
9    helper functions for HDMV TextST subtitles
10 
11    Written by Moritz Bunkus <moritz@bunkus.org>.
12 */
13 
14 #include "common/common_pch.h"
15 
16 #include "common/endian.h"
17 #include "common/hdmv_textst.h"
18 
19 namespace mtx::hdmv_textst {
20 
21 ::timestamp_c
get_timestamp(unsigned char const * buf)22 get_timestamp(unsigned char const *buf) {
23   auto value = (static_cast<uint64_t>(buf[0] & 0x01) << 32) | get_uint32_be(&buf[1]);
24   return timestamp_c::mpeg(value);
25 }
26 
27 void
put_timestamp(unsigned char * buf,::timestamp_c const & timestamp)28 put_timestamp(unsigned char *buf,
29              ::timestamp_c const &timestamp) {
30   auto pts = timestamp.to_mpeg();
31 
32   buf[0] = (buf[0] & 0xfe) | ((pts >> 32) & 0x01);
33   put_uint32_be(&buf[1], pts & ((1ull << 32) - 1));
34 }
35 
36 
37 }
38