mirror of
https://github.com/moonlight-stream/moonlight-qt
synced 2024-12-15 13:52:28 +00:00
d6cfbdb273
This allows us to keep asynchronous decoders like MMAL and V4L2M2M fed while we're waiting for output frames. Behavior for synchronous decoders should be identical. Continuing to feed new data while waiting for output frames is crucial for acceptable performance on 1080p video on the Raspberry Pi using V4L2M2M, since it allows the decode and copy operations to be pipelined.
94 lines
2.9 KiB
C++
94 lines
2.9 KiB
C++
#pragma once
|
|
|
|
#include <functional>
|
|
#include <QQueue>
|
|
|
|
#include "decoder.h"
|
|
#include "ffmpeg-renderers/renderer.h"
|
|
#include "ffmpeg-renderers/pacer/pacer.h"
|
|
|
|
extern "C" {
|
|
#include <libavcodec/avcodec.h>
|
|
}
|
|
|
|
class FFmpegVideoDecoder : public IVideoDecoder {
|
|
public:
|
|
FFmpegVideoDecoder(bool testOnly);
|
|
virtual ~FFmpegVideoDecoder() override;
|
|
virtual bool initialize(PDECODER_PARAMETERS params) override;
|
|
virtual bool isHardwareAccelerated() override;
|
|
virtual bool isAlwaysFullScreen() override;
|
|
virtual int getDecoderCapabilities() override;
|
|
virtual int getDecoderColorspace() override;
|
|
virtual QSize getDecoderMaxResolution() override;
|
|
virtual int submitDecodeUnit(PDECODE_UNIT du) override;
|
|
virtual void renderFrameOnMainThread() override;
|
|
|
|
virtual IFFmpegRenderer* getBackendRenderer();
|
|
|
|
private:
|
|
bool completeInitialization(const AVCodec* decoder, PDECODER_PARAMETERS params, bool testFrame, bool eglOnly);
|
|
|
|
void stringifyVideoStats(VIDEO_STATS& stats, char* output);
|
|
|
|
void logVideoStats(VIDEO_STATS& stats, const char* title);
|
|
|
|
void addVideoStats(VIDEO_STATS& src, VIDEO_STATS& dst);
|
|
|
|
bool createFrontendRenderer(PDECODER_PARAMETERS params, bool eglOnly);
|
|
|
|
bool tryInitializeRendererForDecoderByName(const char* decoderName,
|
|
PDECODER_PARAMETERS params);
|
|
|
|
bool tryInitializeRenderer(const AVCodec* decoder,
|
|
PDECODER_PARAMETERS params,
|
|
const AVCodecHWConfig* hwConfig,
|
|
std::function<IFFmpegRenderer*()> createRendererFunc);
|
|
|
|
static IFFmpegRenderer* createHwAccelRenderer(const AVCodecHWConfig* hwDecodeCfg, int pass);
|
|
|
|
void reset();
|
|
|
|
void writeBuffer(PLENTRY entry, int& offset);
|
|
|
|
static
|
|
enum AVPixelFormat ffGetFormat(AVCodecContext* context,
|
|
const enum AVPixelFormat* pixFmts);
|
|
|
|
void decoderThreadProc();
|
|
|
|
static int decoderThreadProcThunk(void* context);
|
|
|
|
AVPacket* m_Pkt;
|
|
AVCodecContext* m_VideoDecoderCtx;
|
|
QByteArray m_DecodeBuffer;
|
|
const AVCodecHWConfig* m_HwDecodeCfg;
|
|
IFFmpegRenderer* m_BackendRenderer;
|
|
IFFmpegRenderer* m_FrontendRenderer;
|
|
int m_ConsecutiveFailedDecodes;
|
|
Pacer* m_Pacer;
|
|
VIDEO_STATS m_ActiveWndVideoStats;
|
|
VIDEO_STATS m_LastWndVideoStats;
|
|
VIDEO_STATS m_GlobalVideoStats;
|
|
|
|
int m_FramesIn;
|
|
int m_FramesOut;
|
|
|
|
int m_LastFrameNumber;
|
|
int m_StreamFps;
|
|
int m_VideoFormat;
|
|
bool m_NeedsSpsFixup;
|
|
bool m_TestOnly;
|
|
SDL_Thread* m_DecoderThread;
|
|
SDL_atomic_t m_DecoderThreadShouldQuit;
|
|
|
|
typedef struct {
|
|
uint64_t enqueueTimeMs;
|
|
uint32_t presentationTimeMs;
|
|
} FrameInfoTuple;
|
|
QQueue<FrameInfoTuple> m_FrameInfoQueue;
|
|
|
|
static const uint8_t k_H264TestFrame[];
|
|
static const uint8_t k_HEVCMainTestFrame[];
|
|
static const uint8_t k_HEVCMain10TestFrame[];
|
|
};
|