1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
/***
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 "decoder.h"
#include <QCoreApplication>
#include <QDebug>
#include <QFileInfo>
#include "codec/ffmpeg/ffmpegcommon.h"
#include "codec/ffmpeg/ffmpegdecoder.h"
#include "codec/oiio/oiiodecoder.h"
#include "codec/waveinput.h"
#include "codec/waveoutput.h"
#include "task/taskmanager.h"
OLIVE_NAMESPACE_ENTER
Decoder::Decoder() :
open_(false),
stream_(nullptr)
{
}
Decoder::Decoder(Stream *fs) :
open_(false),
stream_(fs)
{
}
StreamPtr Decoder::stream() const
{
return stream_;
}
void Decoder::set_stream(StreamPtr fs)
{
Close();
stream_ = fs;
}
FramePtr Decoder::RetrieveVideo(const rational &/*timecode*/, const int &/*divider*/)
{
return nullptr;
}
SampleBufferPtr Decoder::RetrieveAudio(const rational &/*timecode*/, const rational &/*length*/, const AudioParams &/*params*/)
{
return nullptr;
}
bool Decoder::SupportsVideo()
{
return false;
}
bool Decoder::SupportsAudio()
{
return false;
}
/*
* DECODER STATIC PUBLIC MEMBERS
*/
QVector<DecoderPtr> ReceiveListOfAllDecoders() {
QVector<DecoderPtr> decoders;
// The order in which these decoders are added is their priority when probing. Hence FFmpeg should usually be last,
// since it supports so many formats and we presumably want to override those formats with a more specific decoder.
decoders.append(std::make_shared<OIIODecoder>());
decoders.append(std::make_shared<FFmpegDecoder>());
return decoders;
}
bool Decoder::ProbeMedia(Footage *f, const QAtomicInt* cancelled)
{
// Check for a valid filename
if (f->filename().isEmpty()) {
qWarning() << "Tried to probe media with an empty filename";
return false;
}
// Check file exists
if (!QFileInfo::exists(f->filename())) {
qWarning() << "Tried to probe file that doesn't exist:" << f->filename();
return false;
}
// Reset Footage state for probing
f->Clear();
// Create list to iterate through
QVector<DecoderPtr> decoder_list = ReceiveListOfAllDecoders();
// Pass Footage through each Decoder's probe function
for (int i=0;i<decoder_list.size();i++) {
if (cancelled && *cancelled) {
return false;
}
DecoderPtr decoder = decoder_list.at(i);
if (decoder->Probe(f, cancelled)) {
// 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(decoder->id());
// FIXME: Cache the results so we don't have to probe if this media is added a second time
return true;
}
}
// We aren't able to use this Footage
f->set_status(Footage::kInvalid);
f->set_decoder(QString());
return false;
}
DecoderPtr Decoder::CreateFromID(const QString &id)
{
if (id.isEmpty()) {
return nullptr;
}
// Create list to iterate through
QVector<DecoderPtr> decoder_list = ReceiveListOfAllDecoders();
foreach (DecoderPtr d, decoder_list) {
if (d->id() == id) {
return d;
}
}
return nullptr;
}
QString Decoder::GetConformedFilename(const AudioParams ¶ms)
{
QString index_fn = GetIndexFilename();
index_fn.append('.');
index_fn.append(QString::number(params.sample_rate()));
index_fn.append('.');
index_fn.append(QString::number(params.format()));
index_fn.append('.');
index_fn.append(QString::number(params.channel_layout()));
return index_fn;
}
bool Decoder::ConformAudio(const QAtomicInt *, const AudioParams& )
{
return false;
}
bool Decoder::HasConformedVersion(const AudioParams ¶ms)
{
if (stream()->type() != Stream::kAudio) {
return false;
}
AudioStreamPtr audio_stream = std::static_pointer_cast<AudioStream>(stream());
if (audio_stream->has_conformed_version(params)) {
return true;
}
// Get indexed WAV file
WaveInput input(GetIndexFilename());
bool index_already_matches = false;
if (input.open()) {
index_already_matches = (input.params() == params);
input.close();
}
return index_already_matches;
}
void Decoder::SignalProcessingProgress(const int64_t &ts)
{
if (stream()->duration() != AV_NOPTS_VALUE && stream()->duration() != 0) {
emit IndexProgress(static_cast<double>(ts) / static_cast<double>(stream()->duration()));
}
}
OLIVE_NAMESPACE_EXIT
|