Valkka  1.6.1
OpenSource Video Management
tools.h
Go to the documentation of this file.
1 #ifndef TOOLS_HEADER_GUARD
2 #define TOOLS_HEADER_GUARD
3 
4 /*
5  * tools.h : Auxiliary routines
6  *
7  * (c) Copyright 2017-2024 Sampsa Riikonen
8  *
9  * Authors: Sampsa Riikonen <sampsa.riikonen@iki.fi>
10  *
11  * This file is part of the Valkka library.
12  *
13  * Valkka is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU Lesser General Public License as
15  * published by the Free Software Foundation, either version 3 of the
16  * License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public License
24  * along with this program. If not, see <https://www.gnu.org/licenses/>
25  *
26  */
27 
39 #include "common.h"
40 #include "constant.h"
41 #include "logging.h"
42 #include <sys/socket.h>
43 #include <netinet/in.h>
44 #include <arpa/inet.h>
45 
56 static const int64_t NANOSEC_PER_SEC = 1000000000;
57 
58 long int getCurrentMsTimestamp();
59 
60 long int getMsDiff(timeval tv1, timeval tv2);
61 
62 struct timeval msToTimeval(long int mstimestamp);
63 
64 long int timevalToMs(struct timeval time);
65 
66 bool slotOk(SlotNumber n_slot);
67 
68 void normalize_timespec(struct timespec *ts, time_t sec, int64_t nanosec);
69 
70 static char oneval[4] = {1,0,0,0};
71 static uint32_t* isLittleEndian = (uint32_t*)(oneval);
72 
73 inline uint32_t deserialize_uint32_big_endian(unsigned char *buffer) {
74  uint32_t value = 0;
75  if (*isLittleEndian==1) {
76  value |= buffer[0] << 24;
77  value |= buffer[1] << 16;
78  value |= buffer[2] << 8;
79  value |= buffer[3];
80  }
81  else {
82  value |= buffer[3] << 24;
83  value |= buffer[2] << 16;
84  value |= buffer[1] << 8;
85  value |= buffer[0];
86  }
87  return value;
88 }
89 
90 /*
91 // this was removed from live555 at some point
92 unsigned our_inet_addr(const char* cp)
93 {
94  return inet_addr(cp);
95 }
96 */
97 
98 #endif
List of common header files.
Constant/default values, version numbers.
Logging utilities.
long int getCurrentMsTimestamp()
Utility function: returns current unix epoch timestamp in milliseconds. Uses timeval.
Definition: tools.cpp:40
struct timeval msToTimeval(long int mstimestamp)
Milliseconds to timeval.
Definition: tools.cpp:52
bool slotOk(SlotNumber n_slot)
Timeval to milliseconds.
Definition: tools.cpp:64
long int getMsDiff(timeval tv1, timeval tv2)
Utility function: return timedif of two timeval structs in milliseconds.
Definition: tools.cpp:47