mocked up a prototype of decoding data into the node graph

This commit is contained in:
itsmattkc
2019-08-04 14:45:17 +10:00
parent fb8d5df24b
commit 298ae2f36c
15 changed files with 178 additions and 32 deletions
+4 -3
View File
@@ -21,7 +21,8 @@
#include "decoder.h"
Decoder::Decoder() :
open_(false)
open_(false),
stream_(nullptr)
{
}
@@ -35,12 +36,12 @@ Decoder::~Decoder()
{
}
Stream *Decoder::stream()
const Stream *Decoder::stream()
{
return stream_;
}
void Decoder::set_stream(Stream *fs)
void Decoder::set_stream(const Stream *fs)
{
Close();
+3 -3
View File
@@ -54,8 +54,8 @@ public:
virtual ~Decoder();
Stream* stream();
void set_stream(Stream* fs);
const Stream* stream();
void set_stream(const Stream *fs);
/**
* @brief Probe a footage file and dump metadata about it
@@ -148,7 +148,7 @@ protected:
bool open_;
private:
Stream* stream_;
const Stream* stream_;
};
using DecoderPtr = std::shared_ptr<Decoder>;
+48 -2
View File
@@ -122,12 +122,58 @@ bool FFmpegDecoder::Open()
FramePtr FFmpegDecoder::Retrieve(const rational &timecode, const rational &length)
{
// FIXME: Fill this out
if (!open_ && !Open()) {
return nullptr;
}
// avcodec_flush_buffers(codec_ctx_);
// av_seek_frame(fmt_ctx_, avstream_->index, 0, AVSEEK_FLAG_BACKWARD);
AVFrame* frame = av_frame_alloc();
AVPacket pkt;
av_init_packet(&pkt);
int ret = 69;
bool eof = false;
while ((ret = avcodec_receive_frame(codec_ctx_, frame)) == AVERROR(EAGAIN) && !eof) {
ret = av_read_frame(fmt_ctx_, &pkt);
if (ret == AVERROR_EOF) {
// Don't break so that receive gets called again, but don't try to read again
eof = true;
// Send a null packet to signal end of
avcodec_send_packet(codec_ctx_, nullptr);
} else if (ret < 0) {
// Handle other error
break;
} else {
// Successful read, send the packet
ret = avcodec_send_packet(codec_ctx_, &pkt);
av_packet_unref(&pkt);
if (ret < 0) {
break;
}
}
}
if (ret < 0) {
qWarning() << tr("Failed to retrieve frame from FFmpeg decoder: %1").arg(ret);
av_frame_free(&frame);
return nullptr;
}
FramePtr frame_container = std::make_shared<Frame>();
frame_container->SetAVFrame(frame, avstream_->time_base);
Q_UNUSED(timecode)
Q_UNUSED(length)
return nullptr;
// Close();
return frame_container;
}
void FFmpegDecoder::Close()
+2 -1
View File
@@ -20,6 +20,7 @@
#include "frame.h"
#include <QDebug>
#include <QtGlobal>
Frame::Frame() :
@@ -71,7 +72,7 @@ void Frame::SetAVFrame(AVFrame *f, AVRational timebase)
{
FreeChild();
f = frame_;
frame_ = f;
timestamp_ = rational(timebase.num*f->pts, timebase.den);
}