Skip to content

Commit

Permalink
Fix Depacketizer: 1st capt_ts in middle of frame
Browse files Browse the repository at this point in the history
  • Loading branch information
baranovmv authored and gavv committed Nov 19, 2023
1 parent 85509ca commit 55821da
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/internal_modules/roc_audio/depacketizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,17 @@ Depacketizer::read_samples_(sample_t* buff_ptr, sample_t* buff_end, FrameInfo& i

buff_ptr = read_missing_samples_(buff_ptr, buff_ptr + n_samples);

// next_capture_ts_
// next_timestamp
//
// Packet |-----------------|
// timestamp_
//
// Frame |----------------|
info.n_filled_samples += n_samples;
if (!info.capture_ts && valid_capture_ts_) {
info.capture_ts =
next_capture_ts_ - sample_spec_.samples_overall_2_ns(mis_samples);
info.capture_ts = next_capture_ts_
- sample_spec_.samples_overall_2_ns(info.n_filled_samples);
}
}

Expand All @@ -129,12 +137,14 @@ Depacketizer::read_samples_(sample_t* buff_ptr, sample_t* buff_end, FrameInfo& i

info.n_decoded_samples += n_samples;
if (n_samples && !info.capture_ts && valid_capture_ts_) {
info.capture_ts = next_capture_ts_;
info.capture_ts = next_capture_ts_
- sample_spec_.samples_overall_2_ns(info.n_filled_samples);
}
if (valid_capture_ts_) {
next_capture_ts_ += sample_spec_.samples_overall_2_ns(n_samples);
}

info.n_filled_samples += n_samples;
buff_ptr = new_buff_ptr;
}

Expand All @@ -143,12 +153,14 @@ Depacketizer::read_samples_(sample_t* buff_ptr, sample_t* buff_end, FrameInfo& i
const size_t n_samples = size_t(buff_end - buff_ptr);

if (!info.capture_ts && valid_capture_ts_) {
info.capture_ts = next_capture_ts_;
info.capture_ts = next_capture_ts_
- sample_spec_.samples_overall_2_ns(info.n_filled_samples);
}
if (valid_capture_ts_) {
next_capture_ts_ += sample_spec_.samples_overall_2_ns(n_samples);
}

info.n_filled_samples += n_samples;
return read_missing_samples_(buff_ptr, buff_end);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/internal_modules/roc_audio/depacketizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class Depacketizer : public IFrameReader, public core::NonCopyable<> {
// Number of samples decoded from packets into the frame.
size_t n_decoded_samples;

// Number of samples filled out in the frame.
size_t n_filled_samples;

// Number of packets dropped during frame construction.
size_t n_dropped_packets;

Expand All @@ -68,6 +71,7 @@ class Depacketizer : public IFrameReader, public core::NonCopyable<> {

FrameInfo()
: n_decoded_samples(0)
, n_filled_samples(0)
, n_dropped_packets(0)
, capture_ts(0) {
}
Expand Down

0 comments on commit 55821da

Please sign in to comment.