Skip to content

Commit

Permalink
capture ts comparison helper takes SampleSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
baranovmv committed Nov 16, 2023
1 parent 141323e commit fc6a280
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/tests/roc_pipeline/test_helpers/frame_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ class FrameReader : public core::NonCopyable<> {
const core::nanoseconds_t capture_ts =
base_ts + sample_spec.samples_per_chan_2_ns(abs_offset_);

expect_capture_timestamp(capture_ts, frame.capture_timestamp(),
TimestampEpsilon);
expect_capture_timestamp(capture_ts, frame.capture_timestamp(), sample_spec,
TimestampEpsilonSmpls);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/tests/roc_pipeline/test_helpers/packet_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class PacketReader : public core::NonCopyable<> {
base_ts + sample_spec.samples_per_chan_2_ns(abs_offset_);

expect_capture_timestamp(capture_ts, pkt.rtp()->capture_timestamp,
TimestampEpsilon);
sample_spec, TimestampEpsilonSmpls);
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/tests/roc_pipeline/test_helpers/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ namespace {

const double SampleEpsilon = 0.00001;

const core::nanoseconds_t TimestampEpsilon =
(core::nanoseconds_t)(1. / DefaultSampleRate * core::Second);
const size_t TimestampEpsilonSmpls = 1;

inline audio::sample_t nth_sample(uint8_t n) {
return audio::sample_t(n) / 1024;
Expand All @@ -40,7 +39,10 @@ inline address::SocketAddr new_address(int port) {

inline void expect_capture_timestamp(core::nanoseconds_t expected,
core::nanoseconds_t actual,
core::nanoseconds_t epsilon) {
const audio::SampleSpec& sample_spec,
const size_t epsilon_smpls) {
const core::nanoseconds_t epsilon = sample_spec.samples_per_chan_2_ns(epsilon_smpls);

if (!core::ns_equal_delta(expected, actual, epsilon)) {
char sbuff[256];
snprintf(sbuff, sizeof(sbuff),
Expand Down
6 changes: 3 additions & 3 deletions src/tests/roc_pipeline/test_receiver_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1744,9 +1744,9 @@ TEST(receiver_source, recv_timestamp_mapping_remixing) {
const core::nanoseconds_t expected_capture_ts = first_ts
+ output_sample_spec.samples_overall_2_ns(frame_num * frame_size);

test::expect_capture_timestamp(expected_capture_ts,
frame.capture_timestamp(),
test::TimestampEpsilon);
test::expect_capture_timestamp(
expected_capture_ts, frame.capture_timestamp(), output_sample_spec,
test::TimestampEpsilonSmpls);

frame_num++;
}
Expand Down
5 changes: 2 additions & 3 deletions src/tests/roc_pipeline/test_sender_sink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,6 @@ TEST(sender_sink, timestamp_mapping_remixing_packet_reader) {
InputChans = Chans_Stereo,
PacketChans = Chans_Mono
};
const core::nanoseconds_t eps_resampled =
core::nanoseconds_t(1.f / PacketRate * core::Second);

init(InputRate, InputChans, PacketRate, PacketChans);

Expand Down Expand Up @@ -428,7 +426,8 @@ TEST(sender_sink, timestamp_mapping_remixing_packet_reader) {
CHECK(cts >= unix_base);
} else {
test::expect_capture_timestamp(cts, pp->rtp()->capture_timestamp,
eps_resampled);
packet_sample_spec,
test::TimestampEpsilonSmpls);
}
cts += packet_sample_spec.samples_per_chan_2_ns(pp->rtp()->duration);
}
Expand Down

0 comments on commit fc6a280

Please sign in to comment.