2018-07-17 20:00:16 -07:00
|
|
|
#pragma once
|
|
|
|
|
2019-04-18 20:02:14 -07:00
|
|
|
#include <functional>
|
2022-01-17 15:06:12 -06:00
|
|
|
#include <QQueue>
|
2019-04-18 20:02:14 -07:00
|
|
|
|
2018-07-17 20:00:16 -07:00
|
|
|
#include "decoder.h"
|
|
|
|
#include "ffmpeg-renderers/renderer.h"
|
2018-08-15 23:57:03 -07:00
|
|
|
#include "ffmpeg-renderers/pacer/pacer.h"
|
2018-07-17 20:00:16 -07:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include <libavcodec/avcodec.h>
|
|
|
|
}
|
|
|
|
|
|
|
|
class FFmpegVideoDecoder : public IVideoDecoder {
|
|
|
|
public:
|
2019-02-12 18:42:53 -08:00
|
|
|
FFmpegVideoDecoder(bool testOnly);
|
|
|
|
virtual ~FFmpegVideoDecoder() override;
|
2019-04-11 22:27:20 -07:00
|
|
|
virtual bool initialize(PDECODER_PARAMETERS params) override;
|
2018-07-17 20:00:16 -07:00
|
|
|
virtual bool isHardwareAccelerated() override;
|
2020-02-09 11:35:05 -08:00
|
|
|
virtual bool isAlwaysFullScreen() override;
|
2018-08-25 12:38:04 -07:00
|
|
|
virtual int getDecoderCapabilities() override;
|
2019-12-14 15:25:56 -08:00
|
|
|
virtual int getDecoderColorspace() override;
|
2020-02-23 00:43:43 -08:00
|
|
|
virtual QSize getDecoderMaxResolution() override;
|
2018-07-17 20:00:16 -07:00
|
|
|
virtual int submitDecodeUnit(PDECODE_UNIT du) override;
|
2019-04-09 21:46:14 -07:00
|
|
|
virtual void renderFrameOnMainThread() override;
|
2018-07-17 20:00:16 -07:00
|
|
|
|
2019-04-11 22:27:20 -07:00
|
|
|
virtual IFFmpegRenderer* getBackendRenderer();
|
2018-08-02 22:28:59 -07:00
|
|
|
|
2018-07-17 20:00:16 -07:00
|
|
|
private:
|
2021-05-24 23:26:38 -05:00
|
|
|
bool completeInitialization(const AVCodec* decoder, PDECODER_PARAMETERS params, bool testFrame, bool eglOnly);
|
2018-08-02 21:37:46 -07:00
|
|
|
|
2019-01-19 23:05:56 -08:00
|
|
|
void stringifyVideoStats(VIDEO_STATS& stats, char* output);
|
|
|
|
|
2018-09-25 00:47:59 -07:00
|
|
|
void logVideoStats(VIDEO_STATS& stats, const char* title);
|
|
|
|
|
|
|
|
void addVideoStats(VIDEO_STATS& src, VIDEO_STATS& dst);
|
|
|
|
|
2021-03-22 22:51:29 -05:00
|
|
|
bool createFrontendRenderer(PDECODER_PARAMETERS params, bool eglOnly);
|
2019-04-11 22:27:20 -07:00
|
|
|
|
2021-02-02 19:05:27 -06:00
|
|
|
bool tryInitializeRendererForDecoderByName(const char* decoderName,
|
|
|
|
PDECODER_PARAMETERS params);
|
|
|
|
|
2021-05-24 23:26:38 -05:00
|
|
|
bool tryInitializeRenderer(const AVCodec* decoder,
|
2019-04-18 20:02:14 -07:00
|
|
|
PDECODER_PARAMETERS params,
|
|
|
|
const AVCodecHWConfig* hwConfig,
|
|
|
|
std::function<IFFmpegRenderer*()> createRendererFunc);
|
|
|
|
|
2019-06-26 21:54:29 -07:00
|
|
|
static IFFmpegRenderer* createHwAccelRenderer(const AVCodecHWConfig* hwDecodeCfg, int pass);
|
2018-08-02 21:57:16 -07:00
|
|
|
|
2018-08-02 21:37:46 -07:00
|
|
|
void reset();
|
|
|
|
|
2018-10-12 17:59:53 -07:00
|
|
|
void writeBuffer(PLENTRY entry, int& offset);
|
|
|
|
|
2018-08-02 21:37:46 -07:00
|
|
|
static
|
|
|
|
enum AVPixelFormat ffGetFormat(AVCodecContext* context,
|
|
|
|
const enum AVPixelFormat* pixFmts);
|
2018-07-17 20:00:16 -07:00
|
|
|
|
2022-01-17 15:06:12 -06:00
|
|
|
void decoderThreadProc();
|
|
|
|
|
|
|
|
static int decoderThreadProcThunk(void* context);
|
|
|
|
|
2021-03-05 17:47:04 -06:00
|
|
|
AVPacket* m_Pkt;
|
2018-07-17 20:00:16 -07:00
|
|
|
AVCodecContext* m_VideoDecoderCtx;
|
|
|
|
QByteArray m_DecodeBuffer;
|
|
|
|
const AVCodecHWConfig* m_HwDecodeCfg;
|
2019-04-11 22:27:20 -07:00
|
|
|
IFFmpegRenderer* m_BackendRenderer;
|
|
|
|
IFFmpegRenderer* m_FrontendRenderer;
|
2018-08-09 18:39:38 -07:00
|
|
|
int m_ConsecutiveFailedDecodes;
|
2018-08-15 23:57:03 -07:00
|
|
|
Pacer* m_Pacer;
|
2018-09-25 00:47:59 -07:00
|
|
|
VIDEO_STATS m_ActiveWndVideoStats;
|
|
|
|
VIDEO_STATS m_LastWndVideoStats;
|
|
|
|
VIDEO_STATS m_GlobalVideoStats;
|
2019-01-19 23:05:56 -08:00
|
|
|
|
2020-01-26 20:15:11 -08:00
|
|
|
int m_FramesIn;
|
|
|
|
int m_FramesOut;
|
|
|
|
|
2018-09-25 00:47:59 -07:00
|
|
|
int m_LastFrameNumber;
|
|
|
|
int m_StreamFps;
|
2020-01-26 15:02:29 -08:00
|
|
|
int m_VideoFormat;
|
2018-10-12 17:59:53 -07:00
|
|
|
bool m_NeedsSpsFixup;
|
2019-02-12 18:42:53 -08:00
|
|
|
bool m_TestOnly;
|
2022-01-17 15:06:12 -06:00
|
|
|
SDL_Thread* m_DecoderThread;
|
|
|
|
SDL_atomic_t m_DecoderThreadShouldQuit;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint64_t enqueueTimeMs;
|
|
|
|
uint32_t presentationTimeMs;
|
|
|
|
} FrameInfoTuple;
|
|
|
|
QQueue<FrameInfoTuple> m_FrameInfoQueue;
|
2018-08-02 21:37:46 -07:00
|
|
|
|
|
|
|
static const uint8_t k_H264TestFrame[];
|
2019-11-05 17:08:25 -08:00
|
|
|
static const uint8_t k_HEVCMainTestFrame[];
|
|
|
|
static const uint8_t k_HEVCMain10TestFrame[];
|
2018-07-17 20:00:16 -07:00
|
|
|
};
|