merged probe functions into decoder class

This commit is contained in:
itsmattkc
2019-08-08 17:22:26 +10:00
parent c6dfab4caf
commit 6833b18829
8 changed files with 141 additions and 187 deletions
+102
View File
@@ -20,6 +20,12 @@
#include "decoder.h"
#include <QCoreApplication>
#include <QDebug>
#include <QFileInfo>
#include "decoder/ffmpeg/ffmpegdecoder.h"
Decoder::Decoder() :
open_(false),
stream_(nullptr)
@@ -47,3 +53,99 @@ void Decoder::set_stream(const Stream *fs)
stream_ = fs;
}
/*
* DECODER STATIC PUBLIC MEMBERS
*/
QVector<Decoder*> ReceiveListOfAllDecoders() {
QVector<Decoder*> decoders;
decoders.append(new FFmpegDecoder());
return decoders;
}
void FreeListOfDecoders(const QVector<Decoder*>& decoders, Decoder* except = nullptr) {
foreach (Decoder* d, decoders) {
if (except == nullptr || except != d) {
delete d;
}
}
}
bool Decoder::ProbeMedia(Footage *f)
{
// Check for a valid filename
if (f->filename().isEmpty()) {
qWarning() << QCoreApplication::translate("ProbeMedia", "Tried to probe media with an empty filename");
return false;
}
// Check file exists
if (!QFileInfo::exists(f->filename())) {
qWarning() << QCoreApplication::translate("ProbeMedia", "Tried to probe file that doesn't exist");
return false;
}
// Reset Footage state for probing
f->Clear();
// Create list to iterate through
QVector<Decoder*> decoder_list = ReceiveListOfAllDecoders();
Decoder* found_decoder = nullptr;
// Pass Footage through each Decoder's probe function
for (int i=0;i<decoder_list.size();i++) {
Decoder* decoder = decoder_list.at(i);
if (decoder->Probe(f)) {
// FIXME: Cache the results so we don't have to probe if this media is added a second time
found_decoder = decoder;
break;
}
}
if (found_decoder == nullptr) {
// We aren't able to use this Footage
f->set_status(Footage::kInvalid);
f->set_decoder(QString());
} else {
// We found a Decoder, so we can set this media as valid
f->set_status(Footage::kReady);
// Attach the successful Decoder to this Footage object
f->set_decoder(found_decoder->id());
}
FreeListOfDecoders(decoder_list);
return (found_decoder != nullptr);
}
Decoder *Decoder::CreateFromID(const QString &id)
{
if (id.isEmpty()) {
return nullptr;
}
// Create list to iterate through
QVector<Decoder*> decoder_list = ReceiveListOfAllDecoders();
Decoder* found_decoder = nullptr;
foreach (Decoder* d, decoder_list) {
if (d->id() == id) {
found_decoder = d;
break;
}
}
FreeListOfDecoders(decoder_list, found_decoder);
return found_decoder;
}