Skip to content

Commit

Permalink
Normalize the return value of janus_get_monotonic_time()
Browse files Browse the repository at this point in the history
  • Loading branch information
lminiero committed Jul 9, 2024
1 parent 195bac0 commit c161ca0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/janus.c
Original file line number Diff line number Diff line change
Expand Up @@ -4408,6 +4408,7 @@ gint main(int argc, char *argv[]) {
g_print("Janus version: %d (%s)\n", janus_version, janus_version_string);
g_print("Janus commit: %s\n", janus_build_git_sha);
g_print("Compiled on: %s\n\n", janus_build_git_time);
janus_mark_started();

/* Initialize some command line options defaults */
options.debug_level = -1;
Expand Down
12 changes: 11 additions & 1 deletion src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,22 @@
#include "mach_gettime.h"
#endif

gint64 janus_get_monotonic_time(void) {
static gint64 janus_get_monotonic_time_internal(void) {
struct timespec ts;
clock_gettime (CLOCK_MONOTONIC, &ts);
return (ts.tv_sec*G_GINT64_CONSTANT(1000000)) + (ts.tv_nsec/G_GINT64_CONSTANT(1000));
}

static gint64 janus_started = 0;
void janus_mark_started(void) {
if(janus_started == 0)
janus_started = janus_get_monotonic_time_internal();
}

gint64 janus_get_monotonic_time(void) {
return janus_get_monotonic_time_internal() - janus_started;
}

gint64 janus_get_real_time(void) {
struct timespec ts;
clock_gettime (CLOCK_REALTIME, &ts);
Expand Down
4 changes: 4 additions & 0 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ struct janus_json_parameter {
#endif


/*! Helper method used by the core to mark when Janus started */
void janus_mark_started(void);

/*! \brief Helper to retrieve the system monotonic time, as Glib's
* g_get_monotonic_time may not be available (only since 2.28)
* @note The monotonic time will be normalized from the Janus start time
* @returns The system monotonic time */
gint64 janus_get_monotonic_time(void);

Expand Down

0 comments on commit c161ca0

Please sign in to comment.