cache: better implemented changing disk cache folders

Not complete yet, but getting there.
This commit is contained in:
itsmattkc
2020-08-07 02:31:46 +10:00
parent 00d84cfda0
commit df14c2aaa7
33 changed files with 701 additions and 431 deletions
+7
View File
@@ -29,7 +29,9 @@
#include "codec/oiio/oiiodecoder.h"
#include "codec/waveinput.h"
#include "codec/waveoutput.h"
#include "common/filefunctions.h"
#include "task/taskmanager.h"
#include "project/project.h"
OLIVE_NAMESPACE_ENTER
@@ -175,6 +177,11 @@ QString Decoder::GetConformedFilename(const AudioParams &params)
return index_fn;
}
QString Decoder::GetIndexFilename()
{
return QDir(stream_->footage()->project()->cache_path()).filePath(FileFunctions::GetUniqueFileIdentifier(stream()->footage()->filename()).append(QString::number(stream()->index())));
}
bool Decoder::ConformAudio(const QAtomicInt *, const AudioParams& )
{
return false;
+2 -8
View File
@@ -242,19 +242,13 @@ signals:
protected:
void SignalProcessingProgress(const int64_t& ts);
/**
* @brief Returns the filename for the index
*
* Retrieves the absolute filename of the index file for this stream. Decoder must be open for
* this to work correctly.
*/
virtual QString GetIndexFilename() const = 0;
/**
* @brief Get the destination filename of an audio stream conformed to a set of parameters
*/
QString GetConformedFilename(const AudioParams &params);
QString GetIndexFilename();
bool open_;
QMutex mutex_;
-54
View File
@@ -611,40 +611,6 @@ void FFmpegDecoder::Error(const QString &s)
ClearResources();
}
QMutex scaler_lock;
void SaveCacheFrame(FFmpegDecoder* decoder,
SwsContext* scaler,
AVFrame* frame,
VideoParams params,
QString dst_fn)
{
QByteArray converted_buffer(PixelFormat::GetBufferSize(params.format(),
params.width(),
params.height()),
Qt::Uninitialized);
uint8_t* converted_data = reinterpret_cast<uint8_t*>(converted_buffer.data());
int converted_linesize = PixelFormat::GetBufferSize(params.format(),
params.width(),
1);
scaler_lock.lock();
sws_scale(scaler,
frame->data,
frame->linesize,
0,
frame->height,
&converted_data,
&converted_linesize);
scaler_lock.unlock();
if (!FrameHashCache::SaveCacheFrame(dst_fn, converted_buffer.data(), params, converted_linesize)) {
qCritical() <<" Failed to save cache frame" << dst_fn;
}
av_frame_free(&frame);
}
bool FFmpegDecoder::ConformAudio(const QAtomicInt *cancelled, const AudioParams &p)
{
// Iterate through each audio frame and extract the PCM data
@@ -774,17 +740,6 @@ bool FFmpegDecoder::ConformAudio(const QAtomicInt *cancelled, const AudioParams
return success;
}
QString FFmpegDecoder::GetIndexFilename() const
{
return FileFunctions::GetMediaIndexFilename(FileFunctions::GetUniqueFileIdentifier(stream()->footage()->filename()))
.append(QString::number(stream()->index()));
}
QString FFmpegDecoder::GetProxyFilename(int divider) const
{
return GetIndexFilename().append('d').append(QString::number(divider));
}
int FFmpegDecoder::GetScaledDimension(int dim, int divider)
{
return dim / divider;
@@ -914,7 +869,6 @@ void FFmpegDecoderInstance::SetWorking(bool working)
void FFmpegDecoderInstance::Seek(int64_t timestamp)
{
qDebug() << "Seeking to" << timestamp;
avcodec_flush_buffers(codec_ctx_);
av_seek_frame(fmt_ctx_, avstream_->index, timestamp, AVSEEK_FLAG_BACKWARD);
}
@@ -1171,14 +1125,6 @@ void FFmpegDecoder::FreeScaler()
}
}
QString FFmpegDecoder::GetProxyFrameFilename(const int64_t &timestamp, const int& divider) const
{
QString dst_fn = GetProxyFilename(divider);
dst_fn.append(QString::number(timestamp));
dst_fn.append(FrameHashCache::GetFormatExtension());
return dst_fn;
}
int64_t FFmpegDecoderInstance::RangeStart() const
{
if (cached_frames_.isEmpty()) {
-6
View File
@@ -172,17 +172,11 @@ private:
*/
void FFmpegError(int error_code);
virtual QString GetIndexFilename() const override;
QString GetProxyFilename(int divider) const;
void ClearResources();
void InitScaler(int divider);
void FreeScaler();
QString GetProxyFrameFilename(const int64_t& timestamp, const int &divider) const;
static int GetScaledDimension(int dim, int divider);
static PixelFormat::Format GetNativePixelFormat(AVPixelFormat pix_fmt);
-5
View File
@@ -220,11 +220,6 @@ bool OIIODecoder::SupportsVideo()
return true;
}
QString OIIODecoder::GetIndexFilename() const
{
return QString();
}
void OIIODecoder::FrameToBuffer(FramePtr frame, OIIO::ImageBuf *buf)
{
#if OIIO_VERSION < 20112
-2
View File
@@ -51,8 +51,6 @@ public:
virtual bool SupportsVideo() override;
virtual QString GetIndexFilename() const override;
static void FrameToBuffer(FramePtr frame, OIIO::ImageBuf* buf);
static void BufferToFrame(OIIO::ImageBuf* buf, FramePtr frame);