render: queue audio alongside video

Previously, audio was all queued first and would therefore all have to
finish before any video frames could start caching. No longer! Now they're
queued side by side so users won't have to wait for audio to finish before
their cached frames come in.
This commit is contained in:
itsmattkc
2020-06-16 03:49:12 +10:00
parent 3a4e13a04f
commit f70f266ca0
3 changed files with 15 additions and 10 deletions
+5 -4
View File
@@ -175,18 +175,19 @@ void RenderBackend::SetVideoDownloadMatrix(const QMatrix4x4 &mat)
video_download_matrix_ = mat;
}
QList<TimeRange> RenderBackend::SplitRangeIntoChunks(const TimeRange &r)
std::list<TimeRange> RenderBackend::SplitRangeIntoChunks(const TimeRange &r)
{
// FIXME: Magic number
const int chunk_size = 2;
QList<TimeRange> split_ranges;
std::list<TimeRange> split_ranges;
int start_time = qFloor(r.in().toDouble() / static_cast<double>(chunk_size)) * chunk_size;
int end_time = qCeil(r.out().toDouble() / static_cast<double>(chunk_size)) * chunk_size;
for (int i=start_time; i<end_time; i+=chunk_size) {
split_ranges.append(TimeRange(qMax(r.in(), rational(i)),
qMin(r.out(), rational(i + chunk_size))));
split_ranges.push_back(TimeRange(qMax(r.in(), rational(i)),
qMin(r.out(), rational(i + chunk_size))));
}
return split_ranges;
+1 -1
View File
@@ -87,7 +87,7 @@ public:
void SetVideoDownloadMatrix(const QMatrix4x4& mat);
static QList<TimeRange> SplitRangeIntoChunks(const TimeRange& r);
static std::list<TimeRange> SplitRangeIntoChunks(const TimeRange& r);
public slots:
void NodeGraphChanged(NodeInput *source);
+9 -5
View File
@@ -74,16 +74,14 @@ void RenderTask::Render(const TimeRangeList& video_range,
double total_length = 0;
double video_frame_sz = video_params_.time_base().toDouble();
std::list<TimeRange> audio_queue;
std::list<RangeSampleFuturePair> audio_lookup_table;
if (!audio_range.isEmpty()) {
foreach (const TimeRange& r, audio_range) {
total_length += r.length().toDouble();
QList<TimeRange> ranges = RenderBackend::SplitRangeIntoChunks(r);
foreach (const TimeRange& split, ranges) {
audio_lookup_table.push_back({split, backend_.RenderAudio(split)});
}
std::list<TimeRange> ranges = RenderBackend::SplitRangeIntoChunks(r);
audio_queue.insert(audio_queue.end(), ranges.begin(), ranges.end());
}
}
@@ -123,6 +121,7 @@ void RenderTask::Render(const TimeRangeList& video_range,
while (!IsCancelled()
&& (!render_lookup_table.empty()
|| !frame_queue.empty()
|| !audio_queue.empty()
|| !download_futures.empty()
|| !audio_lookup_table.empty())) {
@@ -168,6 +167,11 @@ void RenderTask::Render(const TimeRangeList& video_range,
frame_queue.pop_front();
}
if (!audio_queue.empty()) {
audio_lookup_table.push_back({audio_queue.front(), backend_.RenderAudio(audio_queue.front())});
audio_queue.pop_front();
}
i = render_lookup_table.begin();
while (!IsCancelled() && i != render_lookup_table.end()) {