From 137454beff5004a8d10033c74b8b3618a49aca0a Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 8 Jan 2021 18:05:27 -0600 Subject: [PATCH] Use SDL_UpdateNVTexture on SDL 2.0.15+ --- .../video/ffmpeg-renderers/sdlvid.cpp | 47 ++++++++++++------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/app/streaming/video/ffmpeg-renderers/sdlvid.cpp b/app/streaming/video/ffmpeg-renderers/sdlvid.cpp index 294dcca5..d83a7c8c 100644 --- a/app/streaming/video/ffmpeg-renderers/sdlvid.cpp +++ b/app/streaming/video/ffmpeg-renderers/sdlvid.cpp @@ -291,25 +291,38 @@ void SdlRenderer::renderFrame(AVFrame* frame) frame->linesize[2]); } else { - char* pixels; - int pitch; +#if SDL_VERSION_ATLEAST(2, 0, 15) + // SDL_UpdateNVTexture is not supported on all renderer backends, + // (notably not DX9), so we must have a fallback in case it's not + // supported and for earlier versions of SDL. + if (SDL_UpdateNVTexture(m_Texture, + nullptr, + frame->data[0], + frame->linesize[0], + frame->data[1], + frame->linesize[1]) != 0) +#endif + { + char* pixels; + int pitch; - err = SDL_LockTexture(m_Texture, nullptr, (void**)&pixels, &pitch); - if (err < 0) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, - "SDL_LockTexture() failed: %s", - SDL_GetError()); - goto Exit; + err = SDL_LockTexture(m_Texture, nullptr, (void**)&pixels, &pitch); + if (err < 0) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, + "SDL_LockTexture() failed: %s", + SDL_GetError()); + goto Exit; + } + + memcpy(pixels, + frame->data[0], + frame->linesize[0] * frame->height); + memcpy(pixels + (frame->linesize[0] * frame->height), + frame->data[1], + frame->linesize[1] * frame->height / 2); + + SDL_UnlockTexture(m_Texture); } - - memcpy(pixels, - frame->data[0], - frame->linesize[0] * frame->height); - memcpy(pixels + (frame->linesize[0] * frame->height), - frame->data[1], - frame->linesize[1] * frame->height / 2); - - SDL_UnlockTexture(m_Texture); } SDL_RenderClear(m_Renderer);