diff --git a/app/streaming/video/ffmpeg-renderers/dxva2.cpp b/app/streaming/video/ffmpeg-renderers/dxva2.cpp index af0603f0..2ed5a2e1 100644 --- a/app/streaming/video/ffmpeg-renderers/dxva2.cpp +++ b/app/streaming/video/ffmpeg-renderers/dxva2.cpp @@ -1,5 +1,6 @@ #include #include "dxva2.h" +#include "../ffmpeg.h" #include @@ -77,8 +78,6 @@ bool DXVA2Renderer::prepareDecoderContext(AVCodecContext* context) context->get_buffer2 = ffGetBuffer2; - context->opaque = this; - m_Pool = av_buffer_pool_init2(ARRAYSIZE(m_DecSurfaces), this, ffPoolAlloc, nullptr); if (!m_Pool) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, @@ -94,7 +93,7 @@ bool DXVA2Renderer::prepareDecoderContext(AVCodecContext* context) int DXVA2Renderer::ffGetBuffer2(AVCodecContext* context, AVFrame* frame, int) { - DXVA2Renderer* me = reinterpret_cast(context->opaque); + DXVA2Renderer* me = (DXVA2Renderer*)((FFmpegVideoDecoder*)context->opaque)->getRenderer(); frame->buf[0] = av_buffer_pool_get(me->m_Pool); if (!frame->buf[0]) { diff --git a/app/streaming/video/ffmpeg.cpp b/app/streaming/video/ffmpeg.cpp index 7c0aef06..1e3ed032 100644 --- a/app/streaming/video/ffmpeg.cpp +++ b/app/streaming/video/ffmpeg.cpp @@ -60,6 +60,11 @@ FFmpegVideoDecoder::~FFmpegVideoDecoder() reset(); } +IFFmpegRenderer* FFmpegVideoDecoder::getRenderer() +{ + return m_Renderer; +} + void FFmpegVideoDecoder::reset() { // Drop any frames still queued to ensure @@ -99,9 +104,6 @@ bool FFmpegVideoDecoder::completeInitialization(AVCodec* decoder, int videoForma return false; } - // Stash a pointer to this object in the context - m_VideoDecoderCtx->opaque = this; - // Always request low delay decoding m_VideoDecoderCtx->flags |= AV_CODEC_FLAG_LOW_DELAY; @@ -126,6 +128,10 @@ bool FFmpegVideoDecoder::completeInitialization(AVCodec* decoder, int videoForma return false; } + // Stash a pointer to this object in the context + SDL_assert(m_VideoDecoderCtx->opaque == nullptr); + m_VideoDecoderCtx->opaque = this; + int err = avcodec_open2(m_VideoDecoderCtx, decoder, nullptr); if (err < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, diff --git a/app/streaming/video/ffmpeg.h b/app/streaming/video/ffmpeg.h index fcfeead2..5eadb3db 100644 --- a/app/streaming/video/ffmpeg.h +++ b/app/streaming/video/ffmpeg.h @@ -22,8 +22,11 @@ public: virtual void renderFrame(SDL_UserEvent* event) override; virtual void dropFrame(SDL_UserEvent* event) override; + virtual IFFmpegRenderer* getRenderer(); + private: - bool completeInitialization(AVCodec* decoder, int videoFormat, int width, int height, bool testOnly); + bool completeInitialization(AVCodec* decoder, int videoFormat, + int width, int height, bool testOnly); IFFmpegRenderer* createAcceleratedRenderer(const AVCodecHWConfig* hwDecodeCfg);