mirror of
https://github.com/moonlight-stream/moonlight-qt
synced 2024-12-14 21:32:27 +00:00
67 lines
1.8 KiB
C++
67 lines
1.8 KiB
C++
#include "streaming/session.hpp"
|
|
|
|
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 */
|
|
return true;
|
|
}
|
|
|
|
bool SdlRenderer::initialize(SDL_Window* window,
|
|
int,
|
|
int width,
|
|
int height)
|
|
{
|
|
m_Renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
|
if (!m_Renderer) {
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
|
"SDL_CreateRenderer() failed: %s",
|
|
SDL_GetError());
|
|
return false;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
void SdlRenderer::renderFrame(AVFrame* frame)
|
|
{
|
|
SDL_UpdateYUVTexture(m_Texture, nullptr,
|
|
frame->data[0],
|
|
frame->linesize[0],
|
|
frame->data[1],
|
|
frame->linesize[1],
|
|
frame->data[2],
|
|
frame->linesize[2]);
|
|
SDL_RenderClear(m_Renderer);
|
|
SDL_RenderCopy(m_Renderer, m_Texture, nullptr, nullptr);
|
|
SDL_RenderPresent(m_Renderer);
|
|
}
|