use lossless compression on indexed frames
We use Qt's built in zlib compression on the fastest setting (it was found that higher compression took 5x as long with a negligible decrease in size). This helps keep disk cache sizes low.
This commit is contained in:
@@ -232,7 +232,8 @@ FramePtr FFmpegDecoder::RetrieveVideo(const rational &timecode)
|
||||
DiskManager::instance()->Accessed(compressed_frame.fileName());
|
||||
|
||||
// Read data
|
||||
frame_loader = compressed_frame.readAll();
|
||||
frame_loader = qUncompress(compressed_frame.readAll());
|
||||
//frame_loader = compressed_frame.readAll();
|
||||
|
||||
av_image_fill_arrays(input_data,
|
||||
input_linesize,
|
||||
@@ -283,9 +284,10 @@ FramePtr FFmpegDecoder::RetrieveVideo(const rational &timecode)
|
||||
input_linesize[i] = frame_->linesize[i];
|
||||
}
|
||||
|
||||
// Save frame to media index
|
||||
QFile save_frame(GetIndexFilename().append(QString::number(frame_->pts)));
|
||||
if (save_frame.open(QFile::WriteOnly)) {
|
||||
|
||||
// Save frame to media index
|
||||
int cached_buffer_sz = av_image_get_buffer_size(static_cast<AVPixelFormat>(frame_->format),
|
||||
frame_->width,
|
||||
frame_->height,
|
||||
@@ -302,13 +304,11 @@ FramePtr FFmpegDecoder::RetrieveVideo(const rational &timecode)
|
||||
frame_->height,
|
||||
1);
|
||||
|
||||
// FIXME: No compression
|
||||
save_frame.write(cached_frame);
|
||||
save_frame.write(qCompress(cached_frame, 1));
|
||||
save_frame.close();
|
||||
|
||||
DiskManager::instance()->CreatedFile(save_frame.fileName(), QByteArray());
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,8 @@ DiskManager *DiskManager::instance()
|
||||
|
||||
void DiskManager::Accessed(const QByteArray &hash)
|
||||
{
|
||||
lock_.lock();
|
||||
|
||||
for (int i=disk_data_.size()-1;i>=0;i--) {
|
||||
const HashTime& h = disk_data_.at(i);
|
||||
|
||||
@@ -91,10 +93,14 @@ void DiskManager::Accessed(const QByteArray &hash)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
lock_.unlock();
|
||||
}
|
||||
|
||||
void DiskManager::Accessed(const QString &filename)
|
||||
{
|
||||
lock_.lock();
|
||||
|
||||
for (int i=disk_data_.size()-1;i>=0;i--) {
|
||||
const HashTime& h = disk_data_.at(i);
|
||||
|
||||
@@ -108,29 +114,47 @@ void DiskManager::Accessed(const QString &filename)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
lock_.unlock();
|
||||
}
|
||||
|
||||
void DiskManager::CreatedFile(const QString &file_name, const QByteArray &hash)
|
||||
{
|
||||
lock_.lock();
|
||||
|
||||
qint64 file_size = QFile(file_name).size();
|
||||
|
||||
disk_data_.append({file_name, hash, QDateTime::currentMSecsSinceEpoch(), file_size});
|
||||
|
||||
consumption_ += file_size;
|
||||
|
||||
QList<QByteArray> deleted_hashes;
|
||||
|
||||
while (consumption_ > DiskLimit()) {
|
||||
DeleteLeastRecent();
|
||||
deleted_hashes.append(DeleteLeastRecent());
|
||||
}
|
||||
|
||||
lock_.unlock();
|
||||
|
||||
foreach (const QByteArray& hash, deleted_hashes) {
|
||||
emit DeletedFrame(hash);
|
||||
}
|
||||
}
|
||||
|
||||
bool DiskManager::ClearDiskCache()
|
||||
{
|
||||
lock_.lock();
|
||||
|
||||
bool deleted_files = QDir(GetMediaCacheLocation()).removeRecursively();
|
||||
|
||||
disk_data_.clear();
|
||||
|
||||
return QDir(GetMediaCacheLocation()).removeRecursively();
|
||||
lock_.unlock();
|
||||
|
||||
return deleted_files;
|
||||
}
|
||||
|
||||
void DiskManager::DeleteLeastRecent()
|
||||
QByteArray DiskManager::DeleteLeastRecent()
|
||||
{
|
||||
HashTime h = disk_data_.takeFirst();
|
||||
|
||||
@@ -138,7 +162,7 @@ void DiskManager::DeleteLeastRecent()
|
||||
|
||||
consumption_ -= h.file_size;
|
||||
|
||||
emit DeletedFrame(h.hash);
|
||||
return h.hash;
|
||||
}
|
||||
|
||||
qint64 DiskManager::DiskLimit()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef DISKMANAGER_H
|
||||
#define DISKMANAGER_H
|
||||
|
||||
#include <QMutex>
|
||||
#include <QObject>
|
||||
|
||||
class DiskManager : public QObject
|
||||
@@ -31,7 +32,7 @@ private:
|
||||
|
||||
static DiskManager* instance_;
|
||||
|
||||
void DeleteLeastRecent();
|
||||
QByteArray DeleteLeastRecent();
|
||||
|
||||
qint64 DiskLimit();
|
||||
|
||||
@@ -46,6 +47,8 @@ private:
|
||||
|
||||
qint64 consumption_;
|
||||
|
||||
QMutex lock_;
|
||||
|
||||
};
|
||||
|
||||
#endif // DISKMANAGER_H
|
||||
|
||||
Reference in New Issue
Block a user