Skip to content

Commit

Permalink
removed platform_time.c + references
Browse files Browse the repository at this point in the history
get_time_in_ns() should be used instead time_since_epoch_in_ms(). Having
both may be misleading and may lead to errors when interchanged.
  • Loading branch information
MartinPulec committed Aug 8, 2023
1 parent 1a8164a commit abffc7c
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 152 deletions.
1 change: 0 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ COMMON_OBJS = \
src/compat/dlfunc.o \
src/compat/platform_pipe.o \
src/compat/platform_semaphore.o \
src/compat/platform_time.o \
src/compat/usleep.o \
src/crypto/crc_32.o \
src/crypto/crypt_aes.o \
Expand Down
81 changes: 0 additions & 81 deletions src/compat/platform_time.c

This file was deleted.

42 changes: 0 additions & 42 deletions src/compat/platform_time.h

This file was deleted.

1 change: 0 additions & 1 deletion src/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
#include <string_view>
#include <unordered_map>

#include "compat/platform_time.h"
#include "debug.h"
#include "host.h"
#include "utils/color_out.h"
Expand Down
8 changes: 4 additions & 4 deletions src/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ bool parse_log_cfg(const char *conf_str,
#include <string>
#include <string_view>
#include <mutex>
#include "compat/platform_time.h"
#include "tv.h"
#include "utils/color_out.h"

class Log_output{
Expand Down Expand Up @@ -222,9 +222,9 @@ inline void Log_output::submit(){
if (show_timestamps == LOG_TIMESTAMP_ENABLED
|| (show_timestamps == LOG_TIMESTAMP_AUTO && log_level >= LOG_LEVEL_VERBOSE))
{
auto time_ms = time_since_epoch_in_ms();
snprintf(ts_str, ts_bufsize - 1, "[%.3f] ", time_ms / 1000.0);
ts_str[ts_bufsize - 1] = '\0';
const time_ns_t time_ns = get_time_in_ns();
snprintf(ts_str, ts_bufsize, "[%.3f] ",
(double) time_ns / NS_IN_SEC_DBL);
}

const char *start_newline = "";
Expand Down
1 change: 0 additions & 1 deletion src/hd-rum-translator/hd-rum-translator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
#include <string.h>
#include <pthread.h>

#include "compat/platform_time.h"
#include "control_socket.h"
#include "crypto/random.h"
#include "host.h"
Expand Down
1 change: 0 additions & 1 deletion src/rtp/video_decoders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
#include "config_win32.h"
#endif // HAVE_CONFIG_H

#include "compat/platform_time.h"
#include "control_socket.h"
#include "crypto/openssl_decrypt.h"
#include "debug.h"
Expand Down
19 changes: 10 additions & 9 deletions src/transmit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
#include "utils/random.h"
#include "video.h"
#include "video_codec.h"
#include "compat/platform_time.h"

#include <algorithm>
#include <array>
Expand All @@ -94,7 +93,7 @@

#define FEC_MAX_MULT 10

#define CONTROL_PORT_BANDWIDTH_REPORT_INTERVAL_MS 1000
#define CONTROL_PORT_BANDWIDTH_REPORT_INTERVAL_NS NS_IN_SEC

#ifdef HAVE_MACOSX
#define GET_STARTTIME gettimeofday(&start, NULL)
Expand Down Expand Up @@ -705,12 +704,14 @@ tx_send_base(struct tx *tx, struct video_frame *frame, struct rtp *rtp_session,
}

if (control_stats_enabled(tx->control)) {
auto current_time_ms = time_since_epoch_in_ms();
if(current_time_ms - tx->last_stat_report >= CONTROL_PORT_BANDWIDTH_REPORT_INTERVAL_MS){
const time_ns_t current_time_ns =
get_time_in_ns();
if (current_time_ns - tx->last_stat_report >=
CONTROL_PORT_BANDWIDTH_REPORT_INTERVAL_NS) {
std::ostringstream oss;
oss << "tx_send " << std::hex << rtp_my_ssrc(rtp_session) << std::dec << " video " << tx->sent_since_report;
control_report_stats(tx->control, oss.str());
tx->last_stat_report = current_time_ms;
tx->last_stat_report = current_time_ns;
tx->sent_since_report = 0;
}
tx->sent_since_report += data_len + rtp_hdr_len;
Expand Down Expand Up @@ -879,15 +880,15 @@ audio_tx_send_pkt(struct tx *tx, struct rtp *rtp_session, uint32_t timestamp,
}

if (control_stats_enabled(tx->control)) {
auto current_time_ms = time_since_epoch_in_ms();
if (current_time_ms - tx->last_stat_report >=
CONTROL_PORT_BANDWIDTH_REPORT_INTERVAL_MS) {
const time_ns_t current_time_ns = get_time_in_ns();
if (current_time_ns - tx->last_stat_report >=
CONTROL_PORT_BANDWIDTH_REPORT_INTERVAL_NS) {
std::ostringstream oss;
oss << "tx_send " << std::hex
<< rtp_my_ssrc(rtp_session) << std::dec
<< " audio " << tx->sent_since_report;
control_report_stats(tx->control, oss.str());
tx->last_stat_report = current_time_ms;
tx->last_stat_report = current_time_ns;
tx->sent_since_report = 0;
}
tx->sent_since_report += data_len + rtp_hdr_len;
Expand Down
20 changes: 12 additions & 8 deletions src/video_capture/screen_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
#include <spa/param/props.h>
#include <spa/debug/format.h>

#include "utils/synchronized_queue.h"
#include "tv.h"
#include "debug.h"
#include "lib_common.h"
#include "utils/color_out.h"
#include "utils/synchronized_queue.h"
#include "video.h"
#include "video_capture.h"

Expand Down Expand Up @@ -363,7 +364,7 @@ struct screen_cast_session {
}

int frame_count = 0;
uint64_t frame_counter_begin_time = time_since_epoch_in_ms();
time_ns_t frame_counter_begin_time = get_time_in_ns();
int expecting_fps = DEFAULT_EXPECTING_FPS;

~pw_() {
Expand Down Expand Up @@ -564,17 +565,20 @@ static void on_process(void *session_ptr) {
pw_stream_queue_buffer(session.pw.stream, buffer);

++session.pw.frame_count;
uint64_t time_now = time_since_epoch_in_ms();

uint64_t delta = time_now - session.pw.frame_counter_begin_time;
if(delta >= 5000) {
double average_fps = session.pw.frame_count / (static_cast<int>(delta) / 1000.0);
const time_ns_t time_now = get_time_in_ns();

const time_ns_t delta =
time_now - session.pw.frame_counter_begin_time;
if (delta >= 5 * NS_IN_SEC) {
const double average_fps = session.pw.frame_count /
static_cast<double>(delta) /
NS_IN_SEC_DBL;
LOG(LOG_LEVEL_VERBOSE) << "[screen_pw]: on process: average fps in last 5 seconds: " << average_fps << "\n";
session.pw.expecting_fps = static_cast<int>(average_fps);
if(session.pw.expecting_fps == 0)
session.pw.expecting_fps = 1;
session.pw.frame_count = 0;
session.pw.frame_counter_begin_time = time_since_epoch_in_ms();
session.pw.frame_counter_begin_time = get_time_in_ns();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/video_compress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ void compress_state_real::async_tile_consumer(struct compress_state *s)
}
}

ret->compress_end = time_since_epoch_in_ms();
ret->compress_end = get_time_in_ns();
compressed_tiles.resize(state.size(), nullptr);
compressed_tiles[i] = std::move(ret);
}
Expand Down
8 changes: 6 additions & 2 deletions src/video_display/decklink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@

#include "audio/types.h"
#include "blackmagic_common.hpp"
#include "compat/platform_time.h"
#include "debug.h"
#include "host.h"
#include "lib_common.h"
Expand Down Expand Up @@ -203,7 +202,12 @@ class PlaybackDelegate : public IDeckLinkVideoOutputCallback // , public IDeckLi
BMD_STR timecode_str;
if (timecode && timecode->GetString(&timecode_str) == S_OK) {
char *timecode_cstr = get_cstr_from_bmd_api_str(timecode_str);
LOG(LOG_LEVEL_DEBUG) << "Frame " << timecode_cstr << " output at " << time_since_epoch_in_ms() / (double) 1e3 << '\n';
LOG(LOG_LEVEL_DEBUG)
<< "Frame " << timecode_cstr
<< " output at "
<< (double) get_time_in_ns() /
NS_IN_SEC_DBL
<< '\n';
release_bmd_api_str(timecode_str);
free(timecode_cstr);
}
Expand Down
1 change: 0 additions & 1 deletion src/video_rxtx/ultragrid_rtp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#include <string>
#include <stdexcept>

#include "compat/platform_time.h"
#include "control_socket.h"
#include "export.h"
#include "host.h"
Expand Down

0 comments on commit abffc7c

Please sign in to comment.