Skip to content

Commit

Permalink
Fec Writer/Reader: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
baranovmv committed May 29, 2024
1 parent d333cb8 commit 0693040
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
19 changes: 10 additions & 9 deletions src/internal_modules/roc_fec/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,18 +803,19 @@ void Reader::drop_repair_packets_from_prev_blocks_() {
}

void Reader::update_block_duration_(const packet::PacketPtr& ptr) {
if (!ptr->rtp()) {
return;
}
packet::stream_timestamp_diff_t block_dur = 0;
if (prev_block_timestamp_valid_) {
block_dur = packet::stream_timestamp_diff(ptr->rtp()->stream_timestamp,
prev_block_timestamp_);
block_dur =
packet::stream_timestamp_diff(ptr->stream_timestamp(), prev_block_timestamp_);
}
if (block_dur < 0) {
roc_log(LogTrace, "fec reader: negative block duration");
prev_block_timestamp_valid_ = false;
} else {
block_max_duration_ = std::max(block_max_duration_, block_dur);
prev_block_timestamp_ = ptr->stream_timestamp();
prev_block_timestamp_valid_ = true;
}
roc_panic_if_msg(block_dur < 0, "fec reader: negative block duration");
block_max_duration_ = std::max(block_max_duration_, block_dur);
prev_block_timestamp_ = ptr->rtp()->stream_timestamp;
prev_block_timestamp_valid_ = true;
}

packet::stream_timestamp_t Reader::max_block_duration() const {
Expand Down
12 changes: 5 additions & 7 deletions src/internal_modules/roc_fec/writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ status::StatusCode Writer::write(const packet::PacketPtr& pp) {
}

if (cur_packet_ == 0) {
update_block_duration_(pp);
if (!begin_block_(pp)) {
// TODO(gh-183): return status
return status::StatusOK;
Expand All @@ -139,6 +138,8 @@ status::StatusCode Writer::write(const packet::PacketPtr& pp) {
}

bool Writer::begin_block_(const packet::PacketPtr& pp) {
update_block_duration_(pp);

if (!apply_sizes_(next_sblen_, next_rblen_, pp->fec()->payload.size())) {
return false;
}
Expand Down Expand Up @@ -347,19 +348,16 @@ bool Writer::validate_source_packet_(const packet::PacketPtr& pp) {
}

void Writer::update_block_duration_(const packet::PacketPtr& ptr) {
if (!ptr->rtp()) {
return;
}
packet::stream_timestamp_diff_t block_dur = 0;
if (prev_block_timestamp_valid_) {
block_dur = packet::stream_timestamp_diff(ptr->rtp()->stream_timestamp,
prev_block_timestamp_);
block_dur =
packet::stream_timestamp_diff(ptr->stream_timestamp(), prev_block_timestamp_);
}
if (block_dur < 0) {
prev_block_timestamp_valid_ = false;
} else {
block_max_duration_ = std::max(block_max_duration_, block_dur);
prev_block_timestamp_ = ptr->rtp()->stream_timestamp;
prev_block_timestamp_ = ptr->stream_timestamp();
prev_block_timestamp_valid_ = true;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/tests/roc_fec/test_writer_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ TEST(writer_reader, no_losses) {
} else {
CHECK(reader.is_started());
if (i_block > 1) {
// CHECK(reader.max_block_duration() == NumSourcePackets * 10);
// CHECK(reader.max_block_duration() ==
// NumSourcePackets * 10);
}
}
CHECK(p);
Expand Down

0 comments on commit 0693040

Please sign in to comment.