ffmpeg: allow decoders immediate access to frames even while indexing

Previously, FFmpeg decoders needed to wait for the initial index to finish
before they could retrieve frames. Now they can retrieve frames while the
index is occurring, provided the appropriate frame has already been indexed (if
not, the retrieve will need to wait still).
This commit is contained in:
itsmattkc
2020-02-15 13:57:29 +11:00
parent 97dadace1f
commit f5de19dd6b
6 changed files with 199 additions and 114 deletions
+8 -21
View File
@@ -32,12 +32,14 @@ extern "C" {
#include "audio/sampleformat.h"
#include "codec/decoder.h"
#include "codec/waveoutput.h"
#include "project/item/footage/videostream.h"
/**
* @brief A Decoder derivative that wraps FFmpeg functions as on Olive decoder
*/
class FFmpegDecoder : public Decoder
{
Q_OBJECT
public:
// Constructor
FFmpegDecoder();
@@ -63,6 +65,8 @@ public:
void SetMultithreading(bool e);
virtual void Index() override;
private:
void ConformInternal(SwrContext *resampler, WaveOutput *output, const char *in_data, int in_sample_count);
@@ -94,8 +98,6 @@ private:
*/
int GetFrame(AVPacket* pkt, AVFrame* frame);
virtual void Index() override;
/**
* @brief Returns the filename for the index
*
@@ -108,26 +110,13 @@ private:
*/
QString GetConformedFilename(const AudioRenderingParams &params);
/**
* @brief Used internally to load a frame index into frame_index_
*
* @return
*
* TRUE if a frame index was successfully loaded. FALSE usually means the file didn't exist and Index() should be
* run to create it.
*/
bool LoadIndex();
/**
* @brief Used in Index() to save the just created frame index to a file that can be loaded later
*/
void SaveIndex();
void IndexAudio(AVPacket* pkt, AVFrame* frame);
void IndexVideo(AVPacket* pkt, AVFrame* frame);
void UnconditionalAudioIndex(AVPacket* pkt, AVFrame* frame);
void UnconditionalVideoIndex(AVPacket* pkt, AVFrame* frame);
int64_t GetClosestTimestampInIndex(const int64_t& ts);
void ValidateVideoIndex();
void Seek(int64_t timestamp);
AVFormatContext* fmt_ctx_;
@@ -145,8 +134,6 @@ private:
AVDictionary* opts_;
QVector<int64_t> frame_index_;
bool multithreading_;
};