diff --git a/app/decoder/CMakeLists.txt b/app/decoder/CMakeLists.txt index 00c3f9a67..22ab4ae4b 100644 --- a/app/decoder/CMakeLists.txt +++ b/app/decoder/CMakeLists.txt @@ -22,7 +22,5 @@ set(OLIVE_SOURCES decoder/decoder.cpp decoder/frame.h decoder/frame.cpp - decoder/probeserver.h - decoder/probeserver.cpp PARENT_SCOPE ) diff --git a/app/decoder/decoder.cpp b/app/decoder/decoder.cpp index 8f8e316ef..db8197bde 100644 --- a/app/decoder/decoder.cpp +++ b/app/decoder/decoder.cpp @@ -20,6 +20,12 @@ #include "decoder.h" +#include +#include +#include + +#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 ReceiveListOfAllDecoders() { + QVector decoders; + + decoders.append(new FFmpegDecoder()); + + return decoders; +} + +void FreeListOfDecoders(const QVector& 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_list = ReceiveListOfAllDecoders(); + + Decoder* found_decoder = nullptr; + + // Pass Footage through each Decoder's probe function + for (int i=0;iProbe(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_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; +} diff --git a/app/decoder/decoder.h b/app/decoder/decoder.h index aebb2950d..de160fbf1 100644 --- a/app/decoder/decoder.h +++ b/app/decoder/decoder.h @@ -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_; diff --git a/app/decoder/probeserver.cpp b/app/decoder/probeserver.cpp deleted file mode 100644 index 25eb4a64e..000000000 --- a/app/decoder/probeserver.cpp +++ /dev/null @@ -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 . - -***/ - -#include "probeserver.h" - -#include -#include -#include - -#include "decoder/ffmpeg/ffmpegdecoder.h" - -QVector ReceiveListOfAllDecoders() { - QVector decoders; - - decoders.append(new FFmpegDecoder()); - - return decoders; -} - -void FreeListOfDecoders(const QVector& 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_list = ReceiveListOfAllDecoders(); - - Decoder* found_decoder = nullptr; - - // Pass Footage through each Decoder's probe function - for (int i=0;iProbe(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_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; -} diff --git a/app/decoder/probeserver.h b/app/decoder/probeserver.h deleted file mode 100644 index bc16eec16..000000000 --- a/app/decoder/probeserver.h +++ /dev/null @@ -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 . - -***/ - -#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 diff --git a/app/node/input/media/media.cpp b/app/node/input/media/media.cpp index 8c015867a..3d64382ac 100644 --- a/app/node/input/media/media.cpp +++ b/app/node/input/media/media.cpp @@ -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) { diff --git a/app/render/texturebuffer.cpp b/app/render/texturebuffer.cpp index dc5418ddc..98f7fd735 100644 --- a/app/render/texturebuffer.cpp +++ b/app/render/texturebuffer.cpp @@ -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); diff --git a/app/task/probe/probe.cpp b/app/task/probe/probe.cpp index 9d6e82a55..60948af63 100644 --- a/app/task/probe/probe.cpp +++ b/app/task/probe/probe.cpp @@ -22,7 +22,7 @@ #include -#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();