SDL2原始碼分析8:視頻顯示總結,sdl2原始碼
本文簡單總結一下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_Window:SDL_CreateWindow()
3.建立SDL_Render:SDL_CreateRenderer()
4.建立SDL_Texture:SDL_CreateTexture()
5.更新SDL_Texture:SDL_UpdateTexture()
6.渲染SDL_Texture:SDL_RenderCopy()
7.顯示:SDL_RenderPresent()
8.返回步驟4繼續執行
中顯示了SDL播放視頻的時候API的調用流程。下文總結一下在不同的系統以及渲染技術下,這些SDL的API和系統底層API之間的調用關係。
SDL-Windows-Direct3DSDL在Windows系統下,使用Direct3D渲染視頻的時候的函數調用關係如所示。
PS:白色背景函數為SDL的API;藍色背景的函數為Win32的API;紫色背景的函數Direct3D的API。
更清晰的圖片連結(右鍵儲存):http://my.csdn.net/leixiaohua1020/album/detail/1795753
可以看出,SDL在Windows下使用Direct3D渲染視頻的時候。函數之間的調用關係如下所列:
SDL_CreateWindow()調用了如下Win32的API:
CreateWindow()
SetWindowText()
ShowWindow()
SetWindowPos()
SDL_CreateRenderer()調用了如下Direc3D的API:
Direct3DCreate9()
IDirect3D9_GetDeviceCaps()
IDirect3D9_CreateDevice()
IDirect3DDevice9_SetFVF()
IDirect3DDevice9_SetRenderState()
IDirect3DDevice9_SetTextureStageState()
IDirect3DDevice9_SetTransform()
IDirect3DDevice9_CreatePixelShader()
SDL_CreateTexture()調用了如下Direc3D的API:
IDirect3DDevice9_CreateTexture()
SDL_UpdateTexture()調用了如下Direc3D的API:
IDirect3DTexture9_LockRect()
memcpy():這個不算D3D的,用於拷貝像素資料。
IDirect3DTexture9_UnlockRect()
SDL_RenderCopy()調用了如下Direc3D的API:
IDirect3DDevice9_BeginScene()
IDirect3DDevice9_SetRenderState()
IDirect3DDevice9_SetSamplerState()
IDirect3DDevice9_SetTexture()
IDirect3DDevice9_SetPixelShader()
IDirect3DDevice9_DrawPrimitiveUP()
SDL_RenderPresent()調用了如下Direc3D的API:
IDirect3DDevice9_EndScene()
IDirect3DDevice9_Present()
SDL-Windows-OpenGLSDL在Windows系統下,使用OpenGL渲染視頻的時候的函數調用關係如所示。
PS:白色背景函數為SDL的API;藍色背景的函數為Win32的API;紫色背景的函數OpenGL的API。
更清晰的圖片連結(右鍵儲存):http://my.csdn.net/leixiaohua1020/album/detail/1795755
可以看出,SDL在Windows下使用OpenGL渲染視頻的時候。函數之間的調用關係如下所列:
SDL_CreateWindow()調用了如下Win32的API:
CreateWindow()
SetWindowText()
ShowWindow()
SetWindowPos()
SDL_CreateRenderer()調用了如下OpenGL的API:
glCreateProgramObject()
glCreateShaderObject()
glShaderSource()
glCompileShader()
GetObjectParameteriv()
AttachObject()
LinkProgram()
UseProgramObject()
SDL_CreateTexture()調用了如下OpenGL的API:
glGenTextures()
glBindTexture()
glTexParameteri()
glTexImage2D()
SDL_UpdateTexture()調用了如下OpenGL的API:
glBindTexture()
glTexSubImage2D()
SDL_RenderCopy()調用了如下OpenGL的API:
glActiveTexture()
glBindTexture()
SDL_RenderPresent()調用了如下OpenGL的API:
SwapBuffers()
SDL-Windows-SoftwareSDL在Windows系統下,使用Software渲染視頻的時候的函數調用關係如所示。
PS1:白色背景函數為SDL的API;藍色背景的函數為Win32的API。
PS2:Software渲染目前還沒有透徹分析。
更清晰的圖片連結(右鍵儲存):http://my.csdn.net/leixiaohua1020/album/detail/1795757
可以看出,SDL在Windows下使用Software渲染視頻的時候。函數之間的調用關係如下所列:
SDL_CreateWindow()調用了如下Win32的API:
CreateWindow()
SetWindowText()
ShowWindow()
SetWindowPos()
SDL_CreateRenderer()調用了如下Win32的API:
CreateCompatibleBitmap()
GetDIBits()
CreateCompatibleDC()
CreateDIBSection()
SelectObject()
SDL_UpdateTexture()調用了memcpy()填充像素資料。
SDL_RenderPresent()調用了如下Win32的API:
BitBlt()