Bound the render-ahead so a demuxer cannot pace rendering
This commit is contained in:
1 parent
80543e6bd3
commit
30182ac670
4 files changed
+56
-10
No files matched your search
+15
-3
@@ -221,7 +221,7 @@ Status Stream::push_eac3(const std::uint8_t* data, std::size_t size, std::size_t
|
||||
}
|
||||
metadata_.push_back(entry);
|
||||
}
|
||||
return process_ready_frames();
|
||||
return process_ready_frames(false);
|
||||
}
|
||||
|
||||
Status Stream::push_bed(const float* interleaved6, std::size_t samples, std::size_t* consumed) {
|
||||
@@ -235,7 +235,7 @@ Status Stream::push_bed(const float* interleaved6, std::size_t samples, std::siz
|
||||
bed_pending_.insert(bed_pending_.end(), interleaved6,
|
||||
interleaved6 + samples * kBedChannels);
|
||||
}
|
||||
return process_ready_frames();
|
||||
return process_ready_frames(false);
|
||||
}
|
||||
|
||||
Status Stream::push_objects16(const float* planar16, std::size_t samples, std::size_t* consumed) {
|
||||
@@ -267,8 +267,13 @@ Status Stream::push_objects16(const float* planar16, std::size_t samples, std::s
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
Status Stream::process_ready_frames() {
|
||||
Status Stream::process_ready_frames(bool drain_all) {
|
||||
while (bed_pending_.size() / kBedChannels >= kFrameSamples && !metadata_.empty()) {
|
||||
// Stop before rendering what the caller is not about to take: the frames
|
||||
// stay queued, in order, and are rendered by a later push or by flush().
|
||||
if (!drain_all && buffered_samples() >= kMaxRenderAheadSamples) {
|
||||
break;
|
||||
}
|
||||
const FrameMetadata entry = metadata_.front();
|
||||
metadata_.pop_front();
|
||||
|
||||
@@ -429,6 +434,13 @@ Status Stream::pull(float* destination, std::size_t capacity_samples, std::size_
|
||||
}
|
||||
|
||||
Status Stream::flush() {
|
||||
// Input has ended, so the render-ahead bound has nothing left to wait for:
|
||||
// every frame still queued has to reach the renderer before its tail is
|
||||
// drained, or the end of the file would be dropped.
|
||||
const Status remaining = process_ready_frames(true);
|
||||
if (!remaining.ok()) {
|
||||
return remaining;
|
||||
}
|
||||
if (binaural_ready_) {
|
||||
std::vector<double> tail;
|
||||
const Status drained =
|
||||
|
||||
+11
-1
@@ -85,8 +85,18 @@ public:
|
||||
: 0u;
|
||||
}
|
||||
|
||||
// A push renders every frame it makes ready, and the caller decides how far
|
||||
// its demuxer runs ahead of playback. Without a bound, a demuxer that runs
|
||||
// far ahead turns its whole read-ahead burst into latency on whichever pull()
|
||||
// happens to follow it: the samples are not wasted, but they are rendered at
|
||||
// the worst possible moment. Rendering therefore stops once this many
|
||||
// samples are rendered and unpulled; flush() lifts the bound so the frames
|
||||
// still waiting when the input ends are drained rather than dropped.
|
||||
static constexpr std::size_t kMaxRenderAheadSamples = 16384;
|
||||
|
||||
private:
|
||||
Status process_ready_frames();
|
||||
// `drain_all` ignores kMaxRenderAheadSamples and renders every ready frame.
|
||||
Status process_ready_frames(bool drain_all);
|
||||
Status render_objects16(const std::vector<float>& objects16);
|
||||
Status render_rosella_objects16(const std::vector<float>& objects16);
|
||||
// Moves at most `limit` rendered stereo samples per channel out of the FIFO
|
||||
|
||||
Reference in new issue
Block a user