当前位置:网站首页>Application of hard coding and streaming integration scheme based on spice protocol in cloud games
Application of hard coding and streaming integration scheme based on spice protocol in cloud games
2022-07-25 05:22:00 【InfoQ】
background
Linux Graphic stack

- X agreement: Earlier agreements ,X server Direct management GPU Internal framebuffer and X Client Submission of orders , adopt XClient(Xlib or XCB) towards Xserver(Xorg) Submit relevant commands to realize , And there are many extension protocols , But the drawback requires an extra Windows Manager To handle multiple applications . It has been Wayland This extended protocol replaces ,composer Process input , window , Composite display and other functions .
- GLX: Because it is used for indirect rendering , Did two jobs :1) take OpenGL and X window API binding 2) adopt X server forward GL Call to . In essence X The protocol .
- FB driver: Historical legacy display subsystem , Provides Framebuffer obtain , Image manipulation primitive , Power management and other functions .
- OpenGL: A unified 3D Graphic rendering API Interface , Major manufacturers (Intel、 Nvidia、AMD、Qualcomm etc. ) All supported interfaces , The mainstream implementation is open source mesa.Mesa 3D Is its most popular open source implementation , It is worth noting that Mesa Not only support OpenGL, And support Vulkan, Direct 3D Wait for the rendering API.
- DRM:Direct Rendering Manager, At present, the mainstream GPU Display subsystem , User mode use libDRM Of DRM API To operate DRM equipment , Yes GPU adopt ioctl And other standard file operations , Realization : framebuffer management . User mode Abstract rendering capability : Such as Buffer Object management ,GPU Operation order submission, etc , General and specific driver relevant . Virtual Driver Support : contain vmwgfx(VMware Bridging equipment ) and virgl(Virto Bridging equipment ) Prime Zero-copy memory,buffer Through user mode fd The file descriptor represents the... In the actual video memory DMA buffer, adopt Prime API export FD, Can be in IPC Passed between .


Android Graphic stack

- OpenGL ES:2D/3D Rendering path , Use drm All functions for painting and rendering .
- Gralloc FB: Use drm by app Provide functions such as video memory management .
- HWComposer: call openGL Window Composition RGB perhaps YUV, Realize screen drawing .
- virto-gpu Technology will OpenGLES Command export (virgl) Then call the host side in turn virglrenderer, Translate it back to OpenGL and GLSL, Then call the host's OpenGL, This part of the technical representative is Qemu programme . Use fake abstractions GPU. In the abstraction layer GPU Layer to intercept , And call the host side GPU.

Multimedia codec related
- stay Linux in ffmepg perhaps gstreamer And other standard multimedia frameworks have encapsulated the application interface , The hardware is connected to provide encoding and decoding, such as CUDA NVEnc Interface or VAAPI Interface .
- stay Android Use in OMX As its multimedia framework ,MediaCodec Drive docking vendor Driver to realize hard coding and decoding capability .
programme
spice agreement
- Open source : Easy to expand and customize ;
- Cross platform :Windows/Linux/Mac OS Full platform compatibility ;
- Support external devices : Except common USB Out of equipment , Devices such as printers and scanners can also be used remotely ;
- Rich media support : Including video 、 Audio 、 Images ;
- Smaller bandwidth footprint :Spice Built in image compression algorithm , Effectively reduce the bandwidth occupation during data transmission ;
- More secure data transmission :Spice have access to OpenSSL Encrypted transmission of data .
- agreement : It is the client side 、 The rules to be followed when the server side and the virtual machine side interact ;
- client : Responsible for receiving and converting virtual machine data , And sending user input data to the virtual machine , So that users can interact with virtual machines ;
- Server side : Integrated into the Hypervisor An internal user layer component , bring Hypervisor( Such as QEMU) Support Spice agreement ;
- Virtual machine side : Refers to all required components deployed inside the virtual machine , Such as QXL drive 、Spice Agent etc. .


- QEMU: Virtual machine environment , Currently in use
- Guest OS: The operating system running in the virtual machine
- Client OS: Running on the host Side application
- GDI/X:Graphics Device Interface, Image engine , Display interface provided by image stack ( Such as mesa)
- QXL: Device drivers , Provides a set of dynamic The device needs the client's QXL Drive to play its full role . however , When there is no drive , The standard VGA It can also support the device . This mode also shows the boot phase of virtual machine startup .QXL The device passes through the command and pointer ring , Display interrupt , Pointer event ,I/O Port to interact with the driver .
- Initialize and map devices ROM,RAM and VRAM To physical memory
- mapping I/O port , Deal with reading and writing to manage : Area update , command , Pointer notification ,IRQ to update , Mode setting , Device reset , Keep a log, etc .
- Ring - Initializing and maintaining command and pointer rings , Get commands and pointer commands from the ring , Wait for a notice . Maintain the resource ring .
- Use QXLWorker Interface with the corresponding red worker signal communication , This is red dispatcher Implemented in , It translates device calls into messages written to red worker passageway , Or from red worker Read messages from the channel .
- register QXL Interface enable worker Be able to communicate with equipment . This interface includes PCI Information and functions ( Such as attaching to one worker, Get the display and pointer commands from the ring , Display and pointer notifications , Mode change notification, etc ).
- Define support QXL Mode and change the current mode ( Such as VGA: All listeners reflect a single device )
- Deal with in VGA Initialization shown in mode , to update , Change size and refresh .


- Show channels in the default display On the call GTK widget Related components draw images on the screen .
- obtain playback Audio data , adopt gstreamer Of pipeline, call alsa Play the audio .
- Other mouse and keyboard processing , Do nothing about .

- Display Channel passageway , This part is getting FD after , Originally painted on GTK The process of HwFrame Adapter module , convert to RTC The data source required for encoding (YUV perhaps RGBA).
- Main Channel Channel increase VDAgent Type add custom type transfer RTC Remote call instruction , Reverse encapsulation will RTC The events and DataChannel Pass to GameService( Game management service process ).

- Main Channel Of VDAgent passageway , stay CLIPBOARD and FILE_XFER Add VD_AGENT_VENDOR_DATA, For remote gRPC call , receive android Side package data .

- GL_SCANOUT_UNIX, Screen initialization / Message after resolution change , Generally used during initialization .

- GL_DRAW_DONE, This message is delivered when the screen content changes , It can be thought of as every Android screen .


QEMU programme

AiC Containers

Scheme parameters
- Simulator or container environment . If you export fd The simulator and container solutions are consistent , No need to distinguish , Otherwise, you need to distinguish by environment variables or by passing in startup parameters .
- DRM device Appoint . In carrying GTK You need to specify in the version of Display Of device, remove Xorg After dependency, specify Render node.
- Encoding video card hardware designation , Because different hardware codes are different , In the coding module, the current hardware information is required to determine the coding mode .
Graphics export
eglCreateStreamKHReglGetStreamFileDescriptorKHReglStreamConsumerAcquireKHRCuGraphicsSubResourceGetMappedArray
eglExportDMABUFImageQueryMESAeglExportDMABUFImageMESA
Optimization and evolution
Code refactoring
remove Xorg
- By default, the exported fd, adopt GTK widget Draw in default Display On , But this step is not required in the actual streaming process .
- Deploy Xorg It also adds complexity .
- Display channel dependent GTK widget Dependency removal ,.
- Replace the original Display, Yes Nvidia,
getPlatformDisplayEXT(EGL_PLATFORM_DEVICE_EXT, (EGLNativeDisplayType)dev[num], NULL)export .
- Replace the original Display, Yes VAAPI Of AMD perhaps Intel The graphics card , Because of the mesa Graphic stack ,
getPlatformDisplayEXT(EGL_PLATFORM_GBM_MESAexport , One thing to note is that VAAPI Interface , Will be used for initialization Display Switch to DRM export .
#if ENABLE_GTK
int vaapi_init() {
x11_display = XOpenDisplay(g_getenv("DISPLAY"));
va_display = vaGetDisplay(x11_display);
#else
int vaapi_init(int drm_fd) {
va_display = (uint64_t)vaGetDisplayDRM(drm_fd);
g_message("drm_fd:%d va_dpy:%p", drm_fd, va_display);
#endif
int major_ver, minor_ver;
va_status = vaInitialize(va_display, &major_ver, &minor_ver);
return 0;
}
remove gstreamer
Graphic conversion optimization
The encoding card supports
Mixed hardware encoding support
Self upgrade
Monitoring and control SRE
other
About us
Reference resources
- https://en.wikipedia.org/wiki/Direct_Rendering_Manager
- https://en.wikipedia.org/wiki/Direct_Rendering_Infrastructure
- https://en.wikipedia.org/wiki/Mesa_(computer_graphics)
- https://source.android.com/devices/graphics
- https://www.opengl.org/
- https://www.mesa3d.org/
- https://www.spice-space.org/
- https://www.qemu.org/
- https://docs.nvidia.com/cuda/cuda-driver-api/index.html
边栏推荐
- Small case of data analysis: visualize recruitment data and view the most needed technologies in the field~
- When image component in wechat applet is used as background picture
- 深圳随到随考,科目四随到随考,科三理论第二理论随到随考说明
- 单点登录(一处登录,处处可用)
- Win11 how to view the file explorer tab
- OpenFegin远程调用丢失请求头问题
- panda3d 键盘移动场景
- Implementation principle of epoll
- Event cycle mechanism browser nodejs async await execution sequence promise execution sequence interview questions
- STL notes (VIII): container - List
猜你喜欢

rhcsa暑假第二天

Special analysis of data security construction in banking industry

1310_一个printf的实现分析

Performance Optimization: how to solve the slow loading speed of the first screen of spa single page application?

Game 302 of leetcode

Three schemes for finclip to realize wechat authorized login

Delivery practice of private PAAS platform based on cloud native

Thesis reading | which is the best multilingual pre training technology for machine translation? See the latest progress!

Project management tools - project developer tools

Introduction to base ring tree
随机推荐
Preliminary understanding of Panda3D particle system
Solution of win11 blue screen code 0x0000001a
基于云原生的私有化 PaaS 平台交付实践
Redis集群搭建(Windows)
服务器防护的七个建议
What about reinstalling win11 system?
Wechat applet related operation examples
Teach you three ways to optimize the performance from 20s to 500ms
Leetcode 15: sum of three numbers
LCP插件创建对等802.1ad接口
epoll的实现原理
typora+PicGo+阿里云OSS 搭建以及报错解决【转载】
Solve the problem that uni app applet obtains routes and route parameters
ThreadLocal
JWT(json web token)
Openfegin remote call lost request header problem
Event cycle mechanism browser nodejs async await execution sequence promise execution sequence interview questions
微服务 - 网关Gateway组件
批量下载视频小技巧
Sword finger offer special shock edition day 9