2018-07-18 03:00:16 +00:00
|
|
|
#include "renderer.h"
|
2018-07-13 09:28:10 +00:00
|
|
|
|
2018-07-27 02:26:22 +00:00
|
|
|
#include <Limelight.h>
|
|
|
|
|
2018-07-13 09:28:10 +00:00
|
|
|
SdlRenderer::SdlRenderer()
|
|
|
|
: m_Renderer(nullptr),
|
|
|
|
m_Texture(nullptr)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SdlRenderer::~SdlRenderer()
|
|
|
|
{
|
|
|
|
if (m_Texture != nullptr) {
|
|
|
|
SDL_DestroyTexture(m_Texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_Renderer != nullptr) {
|
|
|
|
SDL_DestroyRenderer(m_Renderer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SdlRenderer::prepareDecoderContext(AVCodecContext*)
|
|
|
|
{
|
|
|
|
/* Nothing to do */
|
2018-07-28 23:06:26 +00:00
|
|
|
|
|
|
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
|
|
|
"Using SDL software renderer");
|
|
|
|
|
2018-07-13 09:28:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-19 07:59:04 +00:00
|
|
|
bool SdlRenderer::needsTestFrame()
|
|
|
|
{
|
|
|
|
// This renderer should always work
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-08-25 19:38:04 +00:00
|
|
|
int SdlRenderer::getDecoderCapabilities()
|
|
|
|
{
|
2018-08-25 20:36:54 +00:00
|
|
|
// The FFmpeg CPU decoder can handle reference frame invalidation,
|
|
|
|
// but only for H.264.
|
|
|
|
return CAPABILITY_REFERENCE_FRAME_INVALIDATION_AVC;
|
2018-08-25 19:38:04 +00:00
|
|
|
}
|
|
|
|
|
2018-09-04 00:57:09 +00:00
|
|
|
IFFmpegRenderer::VSyncConstraint SdlRenderer::getVsyncConstraint()
|
|
|
|
{
|
|
|
|
return VSYNC_ANY;
|
|
|
|
}
|
|
|
|
|
2018-07-13 09:28:10 +00:00
|
|
|
bool SdlRenderer::initialize(SDL_Window* window,
|
2018-08-04 23:45:31 +00:00
|
|
|
int,
|
2018-07-13 09:28:10 +00:00
|
|
|
int width,
|
2018-08-16 03:41:19 +00:00
|
|
|
int height,
|
2018-08-21 01:19:42 +00:00
|
|
|
int,
|
|
|
|
bool enableVsync)
|
2018-07-13 09:28:10 +00:00
|
|
|
{
|
2018-08-21 01:19:42 +00:00
|
|
|
Uint32 rendererFlags = SDL_RENDERER_ACCELERATED;
|
|
|
|
|
|
|
|
if ((SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN) {
|
|
|
|
// In full-screen exclusive mode, we enable V-sync if requested. For other modes, Windows and Mac
|
|
|
|
// have compositors that make rendering tear-free. Linux compositor varies by distro and user
|
|
|
|
// configuration but doesn't seem feasible to detect here.
|
|
|
|
if (enableVsync) {
|
|
|
|
rendererFlags |= SDL_RENDERER_PRESENTVSYNC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Renderer = SDL_CreateRenderer(window, -1, rendererFlags);
|
2018-07-13 09:28:10 +00:00
|
|
|
if (!m_Renderer) {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
|
|
|
"SDL_CreateRenderer() failed: %s",
|
|
|
|
SDL_GetError());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-16 09:07:32 +00:00
|
|
|
// The window may be smaller than the stream size, so ensure our
|
|
|
|
// logical rendering surface size is equal to the stream size
|
|
|
|
SDL_RenderSetLogicalSize(m_Renderer, width, height);
|
|
|
|
|
2018-07-19 05:07:43 +00:00
|
|
|
// Draw a black frame until the video stream starts rendering
|
|
|
|
SDL_SetRenderDrawColor(m_Renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
|
|
|
|
SDL_RenderClear(m_Renderer);
|
|
|
|
SDL_RenderPresent(m_Renderer);
|
|
|
|
|
2018-07-13 09:28:10 +00:00
|
|
|
m_Texture = SDL_CreateTexture(m_Renderer,
|
|
|
|
SDL_PIXELFORMAT_YV12,
|
|
|
|
SDL_TEXTUREACCESS_STREAMING,
|
|
|
|
width,
|
|
|
|
height);
|
|
|
|
if (!m_Texture) {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
|
|
|
"SDL_CreateRenderer() failed: %s",
|
|
|
|
SDL_GetError());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-16 06:57:03 +00:00
|
|
|
void SdlRenderer::renderFrameAtVsync(AVFrame* frame)
|
2018-07-13 09:28:10 +00:00
|
|
|
{
|
|
|
|
SDL_UpdateYUVTexture(m_Texture, nullptr,
|
|
|
|
frame->data[0],
|
|
|
|
frame->linesize[0],
|
|
|
|
frame->data[1],
|
|
|
|
frame->linesize[1],
|
|
|
|
frame->data[2],
|
|
|
|
frame->linesize[2]);
|
2018-07-18 07:10:22 +00:00
|
|
|
|
2018-07-13 09:28:10 +00:00
|
|
|
SDL_RenderClear(m_Renderer);
|
|
|
|
SDL_RenderCopy(m_Renderer, m_Texture, nullptr, nullptr);
|
|
|
|
SDL_RenderPresent(m_Renderer);
|
|
|
|
}
|