SDL2源代码分析:视频显示总结

转载:http://blog.csdn.net/leixiaohua1020/article/details/41207787

本文简单总结一下SDL显示视频的源代码。

SDL显示视频的结构体

SDL显示视频涉及到下列结构体:

SDL_Window:代表了窗口
SDL_Renderer
:代表了渲染器
SDL_Texture
:代表了纹理
SDL_Rect
:一个矩形框,用于确定纹理显示的位置。

上述几个结构体之间的关系如下图所示。

PS:该图源自于文章《最简单的基于FFMPEG+SDL的视频播放器 ver2 (采用SDL2.0

由图可见,YUV/RGB像素数据首先加载至SDL_Texture,然后通过SDL_Render渲染至SDL_Window。其中SDL_Rect可以指定显示的位置。

SDL显示视频的流程

SDL显示视频的流程如下图所示。

 更清晰的图片链接(右键保存):http://my.csdn.net/leixiaohua1020/album/detail/1795751

从图中可以看出,整体的流程可以概括为如下步骤:
1.    
初始化:SDL_Init()
2.    
创建SDL_WindowSDL_CreateWindow()
3.    
创建SDL_RenderSDL_CreateRenderer()
4.    
创建SDL_TextureSDL_CreateTexture()
5.    
更新SDL_TextureSDL_UpdateTexture()
6.    
渲染SDL_TextureSDL_RenderCopy()
7.    
显示:SDL_RenderPresent()
8.    
返回步骤4继续执行
上图中显示了SDL播放视频的时候API的调用流程。下文总结一下在不同的系统以及渲染技术下,这些SDLAPI和系统底层API之间的调用关系。

SDL-Windows-Direct3D

SDLWindows系统下,使用Direct3D渲染视频的时候的函数调用关系如下图所示。

PS:白色背景函数为SDLAPI;蓝色背景的函数为Win32API;紫色背景的函数Direct3DAPI

更清晰的图片链接(右键保存):http://my.csdn.net/leixiaohua1020/album/detail/1795753

从图中可以看出,SDLWindows下使用Direct3D渲染视频的时候。函数之间的调用关系如下所列:
SDL_CreateWindow()
调用了如下Win32API

CreateWindow()
SetWindowText()
ShowWindow()
SetWindowPos()


SDL_CreateRenderer()
调用了如下Direc3DAPI

Direct3DCreate9()
IDirect3D9_GetDeviceCaps()
IDirect3D9_CreateDevice()
IDirect3DDevice9_SetFVF()
IDirect3DDevice9_SetRenderState()
IDirect3DDevice9_SetTextureStageState()
IDirect3DDevice9_SetTransform()
IDirect3DDevice9_CreatePixelShader()


SDL_CreateTexture()
调用了如下Direc3DAPI

IDirect3DDevice9_CreateTexture()


SDL_UpdateTexture()
调用了如下Direc3DAPI

IDirect3DTexture9_LockRect()
memcpy()
:这个不算D3D的,用于拷贝像素数据。
IDirect3DTexture9_UnlockRect()


SDL_RenderCopy()
调用了如下Direc3DAPI

IDirect3DDevice9_BeginScene()
IDirect3DDevice9_SetRenderState()
IDirect3DDevice9_SetSamplerState()
IDirect3DDevice9_SetTexture()
IDirect3DDevice9_SetPixelShader()
IDirect3DDevice9_DrawPrimitiveUP()


SDL_RenderPresent()
调用了如下Direc3DAPI

IDirect3DDevice9_EndScene()
IDirect3DDevice9_Present()

SDL-Windows-OpenGL

SDLWindows系统下,使用OpenGL渲染视频的时候的函数调用关系如下图所示。
PS:白色背景函数为SDLAPI;蓝色背景的函数为Win32API;紫色背景的函数OpenGLAPI

更清晰的图片链接(右键保存):http://my.csdn.net/leixiaohua1020/album/detail/1795755

 

从图中可以看出,SDLWindows下使用OpenGL渲染视频的时候。函数之间的调用关系如下所列:
SDL_CreateWindow()
调用了如下Win32API

CreateWindow()
SetWindowText()
ShowWindow()
SetWindowPos()


SDL_CreateRenderer()
调用了如下OpenGLAPI

glCreateProgramObject()
glCreateShaderObject()
glShaderSource()
glCompileShader()
GetObjectParameteriv()
AttachObject()
LinkProgram()
UseProgramObject()


SDL_CreateTexture()
调用了如下OpenGLAPI

glGenTextures()
glBindTexture()
glTexParameteri()
glTexImage2D()


SDL_UpdateTexture()
调用了如下OpenGLAPI

glBindTexture()
glTexSubImage2D()


SDL_RenderCopy()
调用了如下OpenGLAPI

glActiveTexture()
glBindTexture()


SDL_RenderPresent()
调用了如下OpenGLAPI

SwapBuffers()

SDL-Windows-Software

SDLWindows系统下,使用Software渲染视频的时候的函数调用关系如下图所示。
PS1:白色背景函数为SDLAPI;蓝色背景的函数为Win32API
PS2
Software渲染目前还没有透彻分析。

 

更清晰的图片链接(右键保存):http://my.csdn.net/leixiaohua1020/album/detail/1795757

 

从图中可以看出,SDLWindows下使用Software渲染视频的时候。函数之间的调用关系如下所列:
SDL_CreateWindow()
调用了如下Win32API

CreateWindow()
SetWindowText()
ShowWindow()
SetWindowPos()


SDL_CreateRenderer()
调用了如下Win32API

CreateCompatibleBitmap()
GetDIBits()
CreateCompatibleDC()
CreateDIBSection()
SelectObject()


SDL_UpdateTexture()
调用了memcpy()填充像素数据。

SDL_RenderPresent()
调用了如下Win32API

BitBlt()

猜你喜欢

转载自blog.csdn.net/flyztek/article/details/74113289
今日推荐