implemented separate waveform cache
This commit is contained in:
@@ -24,6 +24,8 @@ set(OLIVE_SOURCES
|
||||
render/audioparams.h
|
||||
render/audioplaybackcache.cpp
|
||||
render/audioplaybackcache.h
|
||||
render/audiowaveformcache.cpp
|
||||
render/audiowaveformcache.h
|
||||
render/color.cpp
|
||||
render/color.h
|
||||
render/colorprocessor.cpp
|
||||
|
||||
@@ -48,9 +48,6 @@ void AudioPlaybackCache::SetParameters(const AudioParams ¶ms)
|
||||
}
|
||||
|
||||
params_ = params;
|
||||
visual_.set_channel_count(params_.channel_count());
|
||||
|
||||
emit ParametersChanged();
|
||||
}
|
||||
|
||||
void AudioPlaybackCache::WritePCM(const TimeRange &range, const TimeRangeList &valid_ranges, const SampleBuffer &samples)
|
||||
@@ -62,23 +59,6 @@ void AudioPlaybackCache::WritePCM(const TimeRange &range, const TimeRangeList &v
|
||||
}
|
||||
}
|
||||
|
||||
void AudioPlaybackCache::WriteWaveform(const TimeRange &range, const TimeRangeList &valid_ranges, const AudioVisualWaveform *waveform)
|
||||
{
|
||||
// Write each valid range to the segments
|
||||
foreach (const TimeRange& r, valid_ranges) {
|
||||
// Write visual
|
||||
if (waveform) {
|
||||
visual_.OverwriteSums(*waveform, r.in(), r.in() - range.in(), r.length());
|
||||
} else {
|
||||
visual_.OverwriteSilence(r.in(), r.length());
|
||||
}
|
||||
}
|
||||
|
||||
if (!valid_ranges.isEmpty()) {
|
||||
emit WaveformUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
void AudioPlaybackCache::WriteSilence(const TimeRange &range)
|
||||
{
|
||||
// WritePCM will automatically fill non-existent bytes with silence, so we just have to send
|
||||
|
||||
@@ -68,18 +68,8 @@ public:
|
||||
|
||||
void WritePCM(const TimeRange &range, const TimeRangeList &valid_ranges, const SampleBuffer &samples);
|
||||
|
||||
void WriteWaveform(const TimeRange &range, const TimeRangeList &valid_ranges, const AudioVisualWaveform *waveform);
|
||||
|
||||
void WriteSilence(const TimeRange &range);
|
||||
|
||||
const AudioVisualWaveform &visual() const { return visual_; }
|
||||
void set_visual(const AudioVisualWaveform &v) { visual_ = v; }
|
||||
|
||||
signals:
|
||||
void ParametersChanged();
|
||||
|
||||
void WaveformUpdated();
|
||||
|
||||
private:
|
||||
bool WritePartOfSampleBuffer(const SampleBuffer &samples, const rational &write_start, const rational &buffer_start, const rational &length);
|
||||
|
||||
@@ -89,8 +79,6 @@ private:
|
||||
|
||||
AudioParams params_;
|
||||
|
||||
AudioVisualWaveform visual_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2022 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#include "audiowaveformcache.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
AudioWaveformCache::AudioWaveformCache(QObject *parent) :
|
||||
PlaybackCache{parent}
|
||||
{
|
||||
}
|
||||
|
||||
void AudioWaveformCache::WriteWaveform(const TimeRange &range, const TimeRangeList &valid_ranges, const AudioVisualWaveform *waveform)
|
||||
{
|
||||
// Write each valid range to the segments
|
||||
foreach (const TimeRange& r, valid_ranges) {
|
||||
// Write visual
|
||||
TimeRangeList::util_remove(&waveforms_, r);
|
||||
|
||||
if (waveform) {
|
||||
TimeRangeWithWaveform wv = r;
|
||||
rational local_start = r.in() - range.in();
|
||||
wv.waveform = waveform->Mid(local_start, r.length());
|
||||
waveforms_.append(wv);
|
||||
}
|
||||
|
||||
Validate(r);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioWaveformCache::Draw(QPainter *painter, const QRect &rect, const double &scale, const rational &start_time) const
|
||||
{
|
||||
rational end = start_time + rational::fromDouble(rect.width() / scale);
|
||||
TimeRange draw_range(start_time, end);
|
||||
|
||||
foreach (const TimeRangeWithWaveform &wv, waveforms_) {
|
||||
if (wv.OverlapsWith(draw_range)) {
|
||||
rational substart = std::max(wv.in(), draw_range.in());
|
||||
rational subend = std::min(wv.out(), draw_range.out());
|
||||
|
||||
QRect subrect = rect;
|
||||
subrect.setLeft(subrect.left() + (substart - draw_range.in()).toDouble()*scale);
|
||||
subrect.setWidth((subend - substart).toDouble()*scale);
|
||||
|
||||
rational local_start = substart - wv.in();
|
||||
AudioVisualWaveform::DrawWaveform(painter, subrect, scale, wv.waveform, local_start);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AudioVisualWaveform::Sample AudioWaveformCache::GetSummaryFromTime(const rational &start, const rational &length) const
|
||||
{
|
||||
QMap<rational, AudioVisualWaveform::Sample> sample;
|
||||
|
||||
TimeRange acquire(start, start+length);
|
||||
foreach (const TimeRangeWithWaveform &wv, waveforms_) {
|
||||
if (wv.OverlapsWith(acquire)) {
|
||||
TimeRange this_range = wv.Intersected(acquire);
|
||||
auto sum = wv.waveform.GetSummaryFromTime(this_range.in() - wv.in(), this_range.length());
|
||||
sample.insert(this_range.in(), sum);
|
||||
}
|
||||
}
|
||||
|
||||
AudioVisualWaveform::Sample result;
|
||||
|
||||
for (auto it=sample.cbegin(); it!=sample.cend(); it++) {
|
||||
result.append(it.value());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
rational AudioWaveformCache::length() const
|
||||
{
|
||||
rational len = 0;
|
||||
|
||||
foreach (const TimeRangeWithWaveform &wv, waveforms_) {
|
||||
len = std::max(len, wv.out());
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2022 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef AUDIOWAVEFORMCACHE_H
|
||||
#define AUDIOWAVEFORMCACHE_H
|
||||
|
||||
#include "audio/audiovisualwaveform.h"
|
||||
#include "playbackcache.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class AudioWaveformCache : public PlaybackCache
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
AudioWaveformCache(QObject *parent = nullptr);
|
||||
|
||||
void WriteWaveform(const TimeRange &range, const TimeRangeList &valid_ranges, const AudioVisualWaveform *waveform);
|
||||
|
||||
const AudioParams &GetParameters() const { return params_; }
|
||||
void SetParameters(const AudioParams &p) { params_ = p; }
|
||||
|
||||
void Draw(QPainter* painter, const QRect &rect, const double &scale, const rational &start_time) const;
|
||||
|
||||
AudioVisualWaveform::Sample GetSummaryFromTime(const rational &start, const rational &length) const;
|
||||
|
||||
rational length() const;
|
||||
|
||||
private:
|
||||
class TimeRangeWithWaveform : public TimeRange
|
||||
{
|
||||
public:
|
||||
TimeRangeWithWaveform() = default;
|
||||
TimeRangeWithWaveform(const TimeRange &r) :
|
||||
TimeRange(r)
|
||||
{
|
||||
}
|
||||
|
||||
void set_in(const rational& in)
|
||||
{
|
||||
waveform.TrimIn(in - this->in());
|
||||
TimeRange::set_in(in);
|
||||
}
|
||||
|
||||
void set_out(const rational& out)
|
||||
{
|
||||
waveform.Resize(out - this->in());
|
||||
TimeRange::set_out(out);
|
||||
}
|
||||
|
||||
void set_range(const rational& in, const rational& out)
|
||||
{
|
||||
waveform.TrimRange(in, out-in);
|
||||
TimeRange::set_range(in, out);
|
||||
}
|
||||
|
||||
AudioVisualWaveform waveform;
|
||||
};
|
||||
|
||||
QVector<TimeRangeWithWaveform> waveforms_;
|
||||
|
||||
AudioParams params_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // AUDIOWAVEFORMCACHE_H
|
||||
@@ -80,7 +80,7 @@ RenderTicketPtr PreviewAutoCacher::GetSingleFrame(const rational &t, RenderTicke
|
||||
|
||||
RenderTicketPtr PreviewAutoCacher::GetRangeOfAudio(TimeRange range, RenderTicketPriority priority)
|
||||
{
|
||||
return RenderAudio(copied_viewer_node_->GetConnectedSampleOutput(), range, PlaybackCache::kCacheOnly, priority);
|
||||
return RenderAudio(copied_viewer_node_->GetConnectedSampleOutput(), range, PlaybackCache::kCacheOnly, priority, nullptr);
|
||||
}
|
||||
|
||||
void PreviewAutoCacher::VideoInvalidatedFromCache(const TimeRange &range)
|
||||
@@ -127,14 +127,17 @@ void PreviewAutoCacher::AudioRendered()
|
||||
|
||||
SampleBuffer buf = watcher->Get().value<SampleBuffer>();
|
||||
node->audio_playback_cache()->SetParameters(buf.audio_params());
|
||||
node->waveform_cache()->SetParameters(buf.audio_params());
|
||||
|
||||
PlaybackCache::RequestType type = PlaybackCache::RequestType(watcher->property("type").toInt());
|
||||
|
||||
if (type == PlaybackCache::kCacheOnly) {
|
||||
// WritePCM is tolerant to its buffer being null, it will just write silence instead
|
||||
node->audio_playback_cache()->WritePCM(range,
|
||||
valid_ranges,
|
||||
watcher->Get().value<SampleBuffer>());
|
||||
if (AudioPlaybackCache *cache = Node::ValueToPtr<AudioPlaybackCache>(watcher->property("cache"))) {
|
||||
cache->WritePCM(range,
|
||||
valid_ranges,
|
||||
watcher->Get().value<SampleBuffer>());
|
||||
}
|
||||
} else {
|
||||
// Detect if this audio was incomplete because it was waiting on a conform to finish
|
||||
if (watcher->GetTicket()->property("incomplete").toBool()) {
|
||||
@@ -146,7 +149,9 @@ void PreviewAutoCacher::AudioRendered()
|
||||
d.needing_conform.insert(range);
|
||||
}
|
||||
} else {
|
||||
node->audio_playback_cache()->WriteWaveform(range, valid_ranges, &waveform);
|
||||
if (AudioWaveformCache *cache = Node::ValueToPtr<AudioWaveformCache>(watcher->property("cache"))) {
|
||||
cache->WriteWaveform(range, valid_ranges, &waveform);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -320,16 +325,6 @@ void PreviewAutoCacher::InsertIntoCopyMap(Node *node, Node *copy)
|
||||
|
||||
void PreviewAutoCacher::ConnectToNodeCache(Node *node)
|
||||
{
|
||||
connect(node->video_frame_cache(),
|
||||
&PlaybackCache::AutomaticChanged,
|
||||
this,
|
||||
&PreviewAutoCacher::VideoAutoCacheEnableChanged);
|
||||
|
||||
connect(node->audio_playback_cache(),
|
||||
&PlaybackCache::AutomaticChanged,
|
||||
this,
|
||||
&PreviewAutoCacher::AudioAutoCacheEnableChanged);
|
||||
|
||||
connect(node->video_frame_cache(),
|
||||
&PlaybackCache::Request,
|
||||
this,
|
||||
@@ -345,32 +340,18 @@ void PreviewAutoCacher::ConnectToNodeCache(Node *node)
|
||||
this,
|
||||
&PreviewAutoCacher::AudioInvalidatedFromCache);
|
||||
|
||||
connect(node->waveform_cache(),
|
||||
&PlaybackCache::Request,
|
||||
this,
|
||||
&PreviewAutoCacher::AudioInvalidatedFromCache);
|
||||
|
||||
node->video_frame_cache()->LoadState();
|
||||
node->audio_playback_cache()->LoadState();
|
||||
node->thumbnail_cache()->LoadState();
|
||||
|
||||
// Copy invalidated ranges and start rendering if necessary
|
||||
if (node->video_frame_cache()->IsAutomatic()) {
|
||||
VideoAutoCacheEnableChangedFromNode(node, true);
|
||||
}
|
||||
|
||||
if (node->audio_playback_cache()->IsAutomatic()) {
|
||||
AudioAutoCacheEnableChangedFromNode(node, true);
|
||||
}
|
||||
}
|
||||
|
||||
void PreviewAutoCacher::DisconnectFromNodeCache(Node *node)
|
||||
{
|
||||
disconnect(node->video_frame_cache(),
|
||||
&PlaybackCache::AutomaticChanged,
|
||||
this,
|
||||
&PreviewAutoCacher::VideoAutoCacheEnableChanged);
|
||||
|
||||
disconnect(node->audio_playback_cache(),
|
||||
&PlaybackCache::AutomaticChanged,
|
||||
this,
|
||||
&PreviewAutoCacher::AudioAutoCacheEnableChanged);
|
||||
|
||||
disconnect(node->video_frame_cache(),
|
||||
&PlaybackCache::Request,
|
||||
this,
|
||||
@@ -386,17 +367,14 @@ void PreviewAutoCacher::DisconnectFromNodeCache(Node *node)
|
||||
this,
|
||||
&PreviewAutoCacher::AudioInvalidatedFromCache);
|
||||
|
||||
disconnect(node->waveform_cache(),
|
||||
&PlaybackCache::Request,
|
||||
this,
|
||||
&PreviewAutoCacher::AudioInvalidatedFromCache);
|
||||
|
||||
node->video_frame_cache()->SaveState();
|
||||
node->audio_playback_cache()->SaveState();
|
||||
node->thumbnail_cache()->SaveState();
|
||||
|
||||
if (node->video_frame_cache()->IsAutomatic()) {
|
||||
VideoAutoCacheEnableChangedFromNode(node, false);
|
||||
}
|
||||
|
||||
if (node->audio_playback_cache()->IsAutomatic()) {
|
||||
AudioAutoCacheEnableChangedFromNode(node, false);
|
||||
}
|
||||
}
|
||||
|
||||
void PreviewAutoCacher::UpdateGraphChangeValue()
|
||||
@@ -474,24 +452,6 @@ void PreviewAutoCacher::AudioInvalidatedFromNode(Node *node, const TimeRange &ra
|
||||
StartCachingAudioRange(node, range, type);
|
||||
}
|
||||
|
||||
void PreviewAutoCacher::VideoAutoCacheEnableChangedFromNode(Node *node, bool e)
|
||||
{
|
||||
if (e) {
|
||||
VideoInvalidatedList(node, node->video_frame_cache()->GetInvalidatedRanges(node->GetVideoCacheRange()));
|
||||
} else {
|
||||
CancelVideoTasks(node);
|
||||
}
|
||||
}
|
||||
|
||||
void PreviewAutoCacher::AudioAutoCacheEnableChangedFromNode(Node *node, bool e)
|
||||
{
|
||||
if (e) {
|
||||
AudioInvalidatedList(node, node->audio_playback_cache()->GetInvalidatedRanges(node->GetAudioCacheRange()));
|
||||
} else {
|
||||
CancelAudioTasks(node);
|
||||
}
|
||||
}
|
||||
|
||||
void PreviewAutoCacher::SetPlayhead(const rational &playhead)
|
||||
{
|
||||
cache_range_ = TimeRange(playhead - OLIVE_CONFIG("DiskCacheBehind").value<rational>(),
|
||||
@@ -657,7 +617,13 @@ void PreviewAutoCacher::TryRender()
|
||||
|
||||
// Start job
|
||||
if (Node *copy = copy_map_.value(d.node)) {
|
||||
RenderAudio(copy, d.range, d.type, RenderTicketPriority::kNormal);
|
||||
PlaybackCache *cache;
|
||||
if (d.type == PlaybackCache::kPreviewsOnly) {
|
||||
cache = d.node->waveform_cache();
|
||||
} else {
|
||||
cache = d.node->audio_playback_cache();
|
||||
}
|
||||
RenderAudio(copy, d.range, d.type, RenderTicketPriority::kNormal, cache);
|
||||
} else {
|
||||
qCritical() << "Failed to find node copy for audio job";
|
||||
}
|
||||
@@ -705,12 +671,13 @@ RenderTicketWatcher* PreviewAutoCacher::RenderFrame(Node *node, const rational&
|
||||
return watcher;
|
||||
}
|
||||
|
||||
RenderTicketPtr PreviewAutoCacher::RenderAudio(Node *node, const TimeRange &r, PlaybackCache::RequestType type, RenderTicketPriority priority)
|
||||
RenderTicketPtr PreviewAutoCacher::RenderAudio(Node *node, const TimeRange &r, PlaybackCache::RequestType type, RenderTicketPriority priority, PlaybackCache *cache)
|
||||
{
|
||||
RenderTicketWatcher* watcher = new RenderTicketWatcher();
|
||||
watcher->setProperty("job", QVariant::fromValue(last_update_time_));
|
||||
watcher->setProperty("node", Node::PtrToValue(node));
|
||||
watcher->setProperty("type", type);
|
||||
watcher->setProperty("cache", Node::PtrToValue(cache));
|
||||
connect(watcher, &RenderTicketWatcher::Finished, this, &PreviewAutoCacher::AudioRendered);
|
||||
audio_tasks_.insert(watcher, r);
|
||||
|
||||
@@ -720,6 +687,7 @@ RenderTicketPtr PreviewAutoCacher::RenderAudio(Node *node, const TimeRange &r, P
|
||||
|
||||
rap.generate_waveforms = (type == PlaybackCache::kPreviewsOnly);
|
||||
rap.priority = priority;
|
||||
rap.clamp = false;
|
||||
|
||||
RenderTicketPtr ticket = RenderManager::instance()->RenderAudio(rap);
|
||||
watcher->SetTicket(ticket);
|
||||
@@ -744,20 +712,6 @@ void PreviewAutoCacher::ConformFinished()
|
||||
}
|
||||
}
|
||||
|
||||
void PreviewAutoCacher::VideoAutoCacheEnableChanged(bool e)
|
||||
{
|
||||
FrameHashCache *cache = static_cast<FrameHashCache*>(sender());
|
||||
|
||||
VideoAutoCacheEnableChangedFromNode(cache->parent(), e);
|
||||
}
|
||||
|
||||
void PreviewAutoCacher::AudioAutoCacheEnableChanged(bool e)
|
||||
{
|
||||
AudioPlaybackCache *cache = static_cast<AudioPlaybackCache*>(sender());
|
||||
|
||||
AudioAutoCacheEnableChangedFromNode(cache->parent(), e);
|
||||
}
|
||||
|
||||
void PreviewAutoCacher::CacheProxyTaskCancelled()
|
||||
{
|
||||
pending_video_jobs_.clear();
|
||||
|
||||
@@ -105,7 +105,7 @@ private:
|
||||
|
||||
RenderTicketWatcher *RenderFrame(Node *node, const rational &time, PlaybackCache::RequestType type, RenderTicketPriority priority, FrameHashCache *cache);
|
||||
|
||||
RenderTicketPtr RenderAudio(Node *node, const TimeRange &range, PlaybackCache::RequestType type, RenderTicketPriority priority);
|
||||
RenderTicketPtr RenderAudio(Node *node, const TimeRange &range, PlaybackCache::RequestType type, RenderTicketPriority priority, PlaybackCache *cache);
|
||||
|
||||
/**
|
||||
* @brief Process all changes to internal NodeGraph copy
|
||||
@@ -142,9 +142,6 @@ private:
|
||||
void VideoInvalidatedFromNode(Node *node, const olive::TimeRange &range, PlaybackCache::RequestType type);
|
||||
void AudioInvalidatedFromNode(Node *node, const olive::TimeRange &range, PlaybackCache::RequestType type);
|
||||
|
||||
void VideoAutoCacheEnableChangedFromNode(Node *node, bool e);
|
||||
void AudioAutoCacheEnableChangedFromNode(Node *node, bool e);
|
||||
|
||||
class QueuedJob {
|
||||
public:
|
||||
enum Type {
|
||||
@@ -264,10 +261,6 @@ private slots:
|
||||
|
||||
void ConformFinished();
|
||||
|
||||
void VideoAutoCacheEnableChanged(bool e);
|
||||
|
||||
void AudioAutoCacheEnableChanged(bool e);
|
||||
|
||||
void CacheProxyTaskCancelled();
|
||||
|
||||
};
|
||||
|
||||
@@ -112,6 +112,7 @@ RenderTicketPtr RenderManager::RenderAudio(const RenderAudioParams ¶ms)
|
||||
ticket->setProperty("time", QVariant::fromValue(params.range));
|
||||
ticket->setProperty("type", kTypeAudio);
|
||||
ticket->setProperty("enablewaveforms", params.generate_waveforms);
|
||||
ticket->setProperty("clamp", params.clamp);
|
||||
ticket->setProperty("aparam", QVariant::fromValue(params.audio_params));
|
||||
|
||||
AddTicket(ticket, params.priority);
|
||||
|
||||
@@ -129,6 +129,7 @@ public:
|
||||
audio_params = aparam;
|
||||
generate_waveforms = false;
|
||||
priority = RenderTicketPriority::kNormal;
|
||||
clamp = true;
|
||||
}
|
||||
|
||||
Node *node;
|
||||
@@ -136,6 +137,7 @@ public:
|
||||
AudioParams audio_params;
|
||||
bool generate_waveforms;
|
||||
RenderTicketPriority priority;
|
||||
bool clamp;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -216,7 +216,9 @@ void RenderProcessor::Run()
|
||||
|
||||
SampleBuffer samples = sample_val.toSamples();
|
||||
if (samples.is_allocated()) {
|
||||
samples.clamp();
|
||||
if (ticket_->property("clamp").toBool()) {
|
||||
samples.clamp();
|
||||
}
|
||||
|
||||
if (ticket_->property("enablewaveforms").toBool()) {
|
||||
AudioVisualWaveform vis;
|
||||
|
||||
Reference in New Issue
Block a user