diff --git a/src/internal_modules/roc_audio/depacketizer.cpp b/src/internal_modules/roc_audio/depacketizer.cpp index 31d708f65..dabbe0ef3 100644 --- a/src/internal_modules/roc_audio/depacketizer.cpp +++ b/src/internal_modules/roc_audio/depacketizer.cpp @@ -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); } } @@ -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; } @@ -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); } } diff --git a/src/internal_modules/roc_audio/depacketizer.h b/src/internal_modules/roc_audio/depacketizer.h index cfee356e5..87a82b01f 100644 --- a/src/internal_modules/roc_audio/depacketizer.h +++ b/src/internal_modules/roc_audio/depacketizer.h @@ -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; @@ -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) { }