try to index media immediately on import

Since indexing is supplemental, it can be made a background task that can occur
at more or less any time. So we run it as soon as possible.
This commit is contained in:
itsmattkc
2020-01-17 03:58:29 +11:00
parent 63b3c60017
commit 653709dc84
28 changed files with 410 additions and 735 deletions
+25 -23
View File
@@ -62,6 +62,11 @@ bool FFmpegDecoder::Open()
return true;
}
if (!stream()) {
Error(QStringLiteral("Tried to open a decoder with no footage stream set"));
return false;
}
int error_code;
// Convert QString to a C string
@@ -344,7 +349,7 @@ FramePtr FFmpegDecoder::RetrieveAudio(const rational &timecode, const rational &
return nullptr;
}
ValidateIndex();
Index();
Conform(params);
@@ -437,7 +442,7 @@ void FFmpegDecoder::Conform(const AudioRenderingParams &params)
return;
}
ValidateIndex();
Index();
// Get indexed WAV file
WaveInput input(GetIndexFilename());
@@ -659,7 +664,7 @@ bool FFmpegDecoder::Probe(Footage *f)
Open();
// Use index to find duration
ValidateIndex();
Index();
// Use last frame index as the duration
// FIXME: Does this skip the last frame?
@@ -706,17 +711,25 @@ void FFmpegDecoder::Index()
return;
}
// Reset state
Seek(0);
stream()->index_lock_.lock();
if (!LoadIndex()) {
// Reset state
Seek(0);
if (avstream_->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
IndexVideo(pkt_, frame_);
} else if (avstream_->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
IndexAudio(pkt_, frame_);
}
// Reset state
Seek(0);
if (avstream_->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
IndexVideo(pkt_, frame_);
} else if (avstream_->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
IndexAudio(pkt_, frame_);
}
// Reset state
Seek(0);
stream()->index_lock_.unlock();
}
QString FFmpegDecoder::GetIndexFilename()
@@ -756,17 +769,6 @@ QString FFmpegDecoder::GetConformedFilename(const AudioRenderingParams &params)
return index_fn;
}
void FFmpegDecoder::ValidateIndex()
{
stream()->index_lock_.lock();
if (!LoadIndex()) {
Index();
}
stream()->index_lock_.unlock();
}
bool FFmpegDecoder::LoadIndex()
{
switch (avstream_->codecpar->codec_type) {
@@ -991,7 +993,7 @@ int64_t FFmpegDecoder::GetClosestTimestampInIndex(const int64_t &ts)
{
// Index now if we haven't already
if (frame_index_.isEmpty()) {
ValidateIndex();
Index();
}
if (frame_index_.isEmpty()) {