2018-08-16 05:02:15 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-09-25 07:47:59 +00:00
|
|
|
#include "../../decoder.h"
|
2018-08-16 05:02:15 +00:00
|
|
|
#include "../renderer.h"
|
|
|
|
|
|
|
|
#include <QQueue>
|
2019-01-23 04:31:31 +00:00
|
|
|
#include <QMutex>
|
|
|
|
#include <QWaitCondition>
|
2018-08-16 05:02:15 +00:00
|
|
|
|
|
|
|
class IVsyncSource {
|
|
|
|
public:
|
|
|
|
virtual ~IVsyncSource() {}
|
2018-08-21 00:53:35 +00:00
|
|
|
virtual bool initialize(SDL_Window* window, int displayFps) = 0;
|
2018-08-16 05:02:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Pacer
|
|
|
|
{
|
|
|
|
public:
|
2018-09-25 07:47:59 +00:00
|
|
|
Pacer(IFFmpegRenderer* renderer, PVIDEO_STATS videoStats);
|
2018-08-16 05:02:15 +00:00
|
|
|
|
|
|
|
~Pacer();
|
|
|
|
|
|
|
|
void submitFrame(AVFrame* frame);
|
|
|
|
|
2018-12-25 20:57:00 +00:00
|
|
|
bool initialize(SDL_Window* window, int maxVideoFps, bool enablePacing);
|
2018-08-16 05:02:15 +00:00
|
|
|
|
2018-08-21 00:53:35 +00:00
|
|
|
void vsyncCallback(int timeUntilNextVsyncMillis);
|
2018-08-16 05:02:15 +00:00
|
|
|
|
|
|
|
private:
|
2019-01-23 04:31:31 +00:00
|
|
|
static int renderThread(void* context);
|
|
|
|
|
2019-01-22 01:58:42 +00:00
|
|
|
void addRenderTimeToHistory(int renderTime);
|
|
|
|
|
2019-01-21 03:59:29 +00:00
|
|
|
void renderFrame(AVFrame* frame);
|
|
|
|
|
2019-02-16 06:09:50 +00:00
|
|
|
QQueue<AVFrame*> m_RenderQueue;
|
|
|
|
QQueue<AVFrame*> m_PacingQueue;
|
|
|
|
QQueue<int> m_PacingQueueHistory;
|
2019-01-22 01:58:42 +00:00
|
|
|
QQueue<int> m_RenderTimeHistory;
|
2019-01-23 04:31:31 +00:00
|
|
|
QMutex m_FrameQueueLock;
|
2019-02-16 06:09:50 +00:00
|
|
|
QWaitCondition m_RenderQueueNotEmpty;
|
|
|
|
QWaitCondition m_PacingQueueNotEmpty;
|
2019-01-23 04:31:31 +00:00
|
|
|
SDL_Thread* m_RenderThread;
|
|
|
|
bool m_Stopping;
|
2018-08-16 05:02:15 +00:00
|
|
|
|
|
|
|
IVsyncSource* m_VsyncSource;
|
2018-08-16 06:57:03 +00:00
|
|
|
IFFmpegRenderer* m_VsyncRenderer;
|
2018-08-16 05:02:15 +00:00
|
|
|
int m_MaxVideoFps;
|
|
|
|
int m_DisplayFps;
|
2018-09-25 07:47:59 +00:00
|
|
|
PVIDEO_STATS m_VideoStats;
|
2018-08-16 05:02:15 +00:00
|
|
|
};
|