一、窗口尺寸改变大小时,视频卡住不动
网上介绍的方法有:
1:修改源码中的代码!
SDL_OnWindowResized中的SDL_WINDOWEVENT_SIZE_CHANGED更改为SDL_WINDOWEVENT_RESIZED
2:SDL_EventState(SDL_WINDOWEVENT, SDL_IGNORE);
我都试过了,确实可以实现,但是牺牲了分辨率,视频边的模糊
我总结了方法,既然不信那就重新创建SDL_Window、SDL_Renderer、SDL_Texture呗,再利用事件即可解决
cpp
void SDLRender::_HandleEventProc()
{
std::string str = "1";
while (true)
{
SDL_Event event;
if (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_WINDOWEVENT:
switch (event.window.event)
{
case SDL_WINDOWEVENT_RESIZED:
case SDL_WINDOWEVENT_SIZE_CHANGED:
m_nScaleWidth = event.window.data1;
m_nScaleHeight = event.window.data2;
if (m_SdlWindow)
{
SDL_DestroyWindow(m_SdlWindow);
m_SdlWindow = nullptr;
}
if (m_SdlTexture)
{
SDL_DestroyTexture(m_SdlTexture);
m_SdlTexture = nullptr;
}
if (m_SdlRender)
{
SDL_DestroyRenderer(m_SdlRender);
m_SdlRender = nullptr;
}
if (!m_SdlWindow)
m_SdlWindow = SDL_CreateWindowFrom(m_hwnd);
if (!m_SdlRender)
m_SdlRender = SDL_CreateRenderer(m_SdlWindow, -1, SDL_RendererFlags::SDL_RENDERER_ACCELERATED);
break;
default:
break;
}
break;
default:
break;
}
}
}
}
只要检测到窗口尺寸变化就重新创建。
二、播放不同分辨率视频会崩溃
解决办法:检测到不用分辨率的帧重新创建SDL_CreateTexture
cpp
if (m_SdlTexture)
{
SDL_DestroyTexture(m_SdlTexture);
m_SdlTexture = nullptr;
}
m_SdlTexture = SDL_CreateTexture(m_SdlRender, GetSDLFormat((AVPixelFormat)frame->format), SDL_TEXTUREACCESS_STREAMING, frame->width, frame->height);
有不足指出还请指教。。。。