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
-2
View File
@@ -22,7 +22,5 @@ set(OLIVE_SOURCES
decoder/decoder.cpp
decoder/frame.h
decoder/frame.cpp
decoder/probeserver.h
decoder/probeserver.cpp
PARENT_SCOPE
)
+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;
}
+30
View File
@@ -157,6 +157,36 @@ public:
*/
virtual void Close() = 0;
/**
* @brief Try to probe a Footage file by passing it through all available Decoders
*
* This is a helper function designed to abstract the process of communicating with several Decoders from the rest of
* the application. This function will take a Footage file and manually pass it through the available Decoders' Probe()
* functions until one indicates that it can decode this file. That Decoder will then dump information about the file
* into the Footage object for use throughout the program.
*
* Probing may be a lengthy process and it's recommended to run this in a separate thread.
*
* @param f
*
* A Footage object with a valid filename. If the Footage does not have a valid filename (e.g. is empty or file doesn't
* exist), this function will return FALSE.
*
* @return
*
* TRUE if a Decoder was successfully able to parse and probe this file. FALSE if not.
*/
static bool ProbeMedia(Footage* f);
/**
* @brief Create a Decoder instance using a Decoder ID
*
* @return
*
* A Decoder instance or nullptr if a Decoder with this ID does not exist
*/
static Decoder* CreateFromID(const QString& id);
protected:
bool open_;
-119
View File
@@ -1,119 +0,0 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 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 "probeserver.h"
#include <QApplication>
#include <QDebug>
#include <QFileInfo>
#include "decoder/ffmpeg/ffmpegdecoder.h"
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 olive::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* olive::CreateDecoderFromID(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;
}
-54
View File
@@ -1,54 +0,0 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 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 PROBESERVER_H
#define PROBESERVER_H
#include "decoder/decoder.h"
#include "project/item/footage/footage.h"
namespace olive {
/**
* @brief Try to probe a Footage file by passing it through all available Decoders
*
* This is a helper function designed to abstract the process of communicating with several Decoders from the rest of
* the application. This function will take a Footage file and manually pass it through the available Decoders' Probe()
* functions until one indicates that it can decode this file. That Decoder will then dump information about the file
* into the Footage object for use throughout the program.
*
* Probing may be a lengthy process and it's recommended to run this in a separate thread.
*
* @param f
*
* A Footage object with a valid filename. If the Footage does not have a valid filename (e.g. is empty or file doesn't
* exist), this function will return FALSE.
*
* @return
*
* TRUE if a Decoder was successfully able to parse and probe this file. FALSE if not.
*/
bool ProbeMedia(Footage* f);
Decoder* CreateDecoderFromID(const QString& id);
}
#endif // PROBESERVER_H
+2 -7
View File
@@ -27,7 +27,6 @@
// FIXME: Test code only
#include "decoder/ffmpeg/ffmpegdecoder.h"
#include "decoder/probeserver.h"
#include "render/pixelservice.h"
// End test code
@@ -92,12 +91,8 @@ void MediaInput::Process(const rational &time)
// Otherwise try to get frame of footage from decoder
// Determine which decoder to use
if (decoder_ == nullptr) {
decoder_ = olive::CreateDecoderFromID(footage->decoder());
if (decoder_ == nullptr) {
return;
}
if (decoder_ == nullptr
&& (decoder_ = Decoder::CreateFromID(footage->decoder())) == nullptr) {
}
if (decoder_->stream() == nullptr) {
+5 -3
View File
@@ -92,9 +92,11 @@ void TextureBuffer::Create(QOpenGLContext *ctx, const olive::PixelFormat &format
GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture_, 0
);
// clear new texture
ctx->functions()->glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
ctx->functions()->glClear(GL_COLOR_BUFFER_BIT);
// clear new texture (doesn't seem to be necessary)
/*if (data == nullptr) {
ctx->functions()->glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
ctx->functions()->glClear(GL_COLOR_BUFFER_BIT);
}*/
// release texture
f->glBindTexture(GL_TEXTURE_2D, 0);
+2 -2
View File
@@ -22,7 +22,7 @@
#include <QFileInfo>
#include "decoder/probeserver.h"
#include "decoder/decoder.h"
ProbeTask::ProbeTask(FootagePtr footage) :
footage_(footage)
@@ -36,7 +36,7 @@ bool ProbeTask::Action()
{
footage_->Lock();
olive::ProbeMedia(footage_.get());
Decoder::ProbeMedia(footage_.get());
footage_->Unlock();