Try   HackMD

雲端遊戲串流技術

tags: RD1

雲端遊戲串流簡介

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

傳統遊戲我們需要將遊戲安裝到指定的平台裝置上才能夠遊玩,像是:XBOX、PS4、手機、桌機。如果有需要多人遊戲還需要將數據藉由網路傳遞到後端伺服器進行處理。由於不同遊戲可能對平台裝置有不同程度上的要求,玩家可能要花費額外的金錢購買指定的平台裝置才能玩到想玩的遊戲,而且許多遊戲無法進行跨平台多人連線。

雲端串流遊戲的想法是只要把操作指令藉由網路傳給遠端的串流伺服器,由遠端的伺服器進行遊戲程式的操作遊玩並且把遊戲畫面藉由網路傳回給玩家。這樣就可以大幅降低接觸遊戲的硬體門檻,更可以進行跨平台的遊戲遊玩。

雲端串流遊戲操作的過程如下:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  1. 使用者使用操作手把或其他輸入設備透過網路傳送操作指令到串流遊戲平台。
  2. 指令接收器收到指令後,再用此指令操作遊戲。
  3. 遊戲收到指令後會改變畫面渲染。
  4. 串流遊戲平台會捕捉渲染後的畫面,交由影音編碼器編碼。
  5. 編碼後的畫面交由影音串流器透過網路回送到客戶端。
  6. 透過解碼器解碼後顯示在玩家的裝置上。

傳統遊戲痛點

  1. 硬體設備的花費,常常由於硬體設備不足而放棄一款遊戲,而行動裝置上的遊戲由於效能不足,可以發揮的空間就小於主機跟PC了。
  2. 許多不同平台上的遊戲無法進行多人連線遊玩。
  3. 獨佔遊戲,可能某ㄧ款遊戲只在特定平台裝置上運行,就必須買這特定平台裝置。

獨佔遊戲就是指只有在特定平台才能玩的到遊戲

串流遊戲解決以上痛點:

  1. 不須在硬體裝置上花費額外金錢,只要網路速度夠快,有一個能夠解析1080p 60fps影片的裝置就能玩遊戲。
  2. 跨平台遠端連線,由於遊戲都放在同一個雲端串流伺服器,多人跨平台遊玩就不是很大的問題。
  3. 不須下載、安裝、更新遊戲,遊戲直接在雲端上,開了就能玩。
  4. 由於遊戲程式都放在雲端串流伺服器,從根本上解決外掛、駭客跟盜版。
  5. 串流遊戲平台玩家很多,遊戲廠商就可能會考慮在該串流遊戲平台開發遊戲,只要串流遊戲平台統一市場就不會有獨佔遊戲問題,甚至有可能終結遊戲主機。

串流遊戲的實際問題:

  1. 網路速度,串流遊戲雖然不吃硬體效能,但卻吃你的網路速度。玩一些卡牌遊戲或是不吃什麼操作的RPG遊戲可能不會有什麼影響,但賽車遊戲、射擊遊戲、音樂遊戲、動作遊戲這些很吃操作的類型的話,一點點的延遲就會造成遊戲體驗瞬間被摧毀。畫面、介面再好都沒用了。還有串流遊戲的網路串流品質不只牽扯到串流遊戲平台本身而已,還關係到你所處的地方網路基礎建設。

  2. 不同的串流遊戲平台廠商可能會開發出不同的開發標準,根本上無法解決獨佔遊戲的問題。

實踐案例

以下是雲端串流技術的實踐:

使用Parsec軟體與雲端虛擬機器

Parsec軟體類似於遠端桌面軟體,不過Parsec可以將控制器(滑鼠、鍵盤、手把)相關的操作命令傳到機器裡面,遠端操作的機器也必須安裝Parsec軟體,以及想要玩的遊戲或者是遊戲平台( 如Steam )。服務的系統架構圖如下:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

類似的遠端遊戲串流軟體有很多,像是steam link等。將跑遊戲的機器架在雲端的運算平台上的虛擬機器也可以達到雲端串流遊戲的效果。不過此類方法只能部屬少量虛擬機器對於大量的玩家就顯的無能為力。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

圖片引用自How to: Create a Remote Gaming Server using Parsec on AWS

GameAnywhere(2013)

此段文章圖片部分擷取自GamingAnyWhere官網與相關論文GamingAnywhere-The First Open Source Cloud Gaming System

GameAnyWhere是由交通大學黃俊穎教授與清華大學徐正炘教授與相關團隊開發的一個開源雲端遊戲串流系統專案。其專案主要都是用一些開源的函式庫或工具進行開發,算是很早期的雲端串流遊戲系統。

部署架構圖

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

上面的架構圖主要在解釋該專案部署的架構,右下角為client端一開始會先向Portal Servers選擇遊戲來玩,Portal Servers通知Game Servers運行相對指定的遊戲並將該Game Servers的IP傳給client端後,client端與Game Servers進行連線並開始遊玩。

Cient與Game Server溝通的系統架構圖

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

上面的架構圖說明了Server端將遊戲影音encode後透過RTSP/RTP/RTCP網路協議傳輸到Client端,Client端再進行decode並把畫面顯示出來;而玩家輸入方面則是透過自訂的Protocol利用網路傳輸到Server端然後進行操作回放。

Server端的架構圖

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Client端的架構圖

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

使用的套件與模組

  • Server端
    • Video Source( platform dependent )
    • Audio Source( platform dependent )
    • Encoders( various encoders via ffmpeg )
    • Replayer( platform dependent )
    • RTSP/RTP Server( using ffmpeg )
  • Client端
    • RTSP/RTP client( using live555 )
    • Decoders( via ffmpeg )
    • Controller( using SDL )
    • Renderer( using SDL )

Demo

youtube影片

Stadia

Stadia 是 Google 營運的雲端遊戲串流服務。Google 聲稱服務支援最高4K解析度、每秒60影格、高動態範圍影片,由世界各地的伺服器經高速網際網路串流至用戶裝置。

成為Stadia開發者

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

想要成為Stadia的開發者必須先做一些表單的填寫,表單內容會問你是哪一間公司,開發過什麼遊戲,以及開發過的遊戲使用者評價,提交表單後Google可能會先做一些評估再決定要不要給你開發工具與相關文件。

要成為Stadia開發者有以下要求:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

不過Google有在Youtube上釋出一些開發者指引影片可以讓開發者先看。
A Guide to Stadia game development - Unity at GDC 2019
GDC 2019 Developer Session: A Guide to Developing on Stadia
Stadia Streaming Tech: A Deep Dive (Google I/O'19)

通過評核之後應該是會給你一個Google Games Platform網頁,上面會有Google遊戲開發相關的文件與工具。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Stadia的系統架構

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Stadia開發

Stadia開發主要是以PaaS(平台即服務)的形式提供給開發者。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Stadia是將使用者開發的遊戲放在Google data center的Virtual Machine上進行運行,Virtual Machine使用的硬體配置:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Stadia在雲端所運行的Virtual Machine被稱為instance,Virtual Machine為了提供雲端串流遊戲有進行一些優化:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Stadia instance 可以在本地端或雲端運行,開發上你可以在自己的Server運行instance,但最終測試還是希望在雲端遊玩測試。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Stadia instance作業系統使用的是Linux為核心的作業系統,Stadia會提供一系列底層(網路、畫面、輸入)的API函式庫與套件,像是:Vulkan。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Stadia會提供一系列的開發與管理的工具,裡面提供比較多比較面向於遊戲開發的工具,像是Unity、CryEngine、Visual Studio、RenderDoc、VTune。

Stadia主要會以Web UI,Command Line,供開發者與Stadia平台做互動

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

WebUI的管理工具

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

將開發好的遊戲放上Stadia instance

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

開發好的二進制檔與相關檔案可以用類似掛載的方式掛載到遠端的Stadia instance,然後執行遊戲的二進制檔。

使用Package管理你的遊戲

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

關於技術導入

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Stadia所提供的方案,是如圖一這樣的規劃,其他雲端串流平台商應該也是如此規劃。客戶端會送出操作指令給串流雲端運算中心上的instance,instance接收到操作指令後對遊戲進行相對應的操作。遊戲接收到指令後會改變遊戲環境與狀態,遊戲引擎會進行運算將環境進行渲染,渲染後的場景影像會經由串流傳輸到客戶端。

要在Stadia開發遊戲必須使用Stadia提供的SDK進行遊戲的開發,這方面由於還沒獲得實際的開發工具,所以instance真正的開發環境與流程還不是很清楚。

Stadia與Parsec的差別

使用Stadia,Google會幫你處理好虛擬機器部署的問題,而Stadia Instance也會透過特殊的調整進行優化,就是一個專門跑遊戲的虛擬機器,基本上可以把它當作一個家用主機來看待。

使用Parsec就必須跑一台電腦,不管是架在本地或雲端,而這台電腦必須有安裝你要玩的遊戲,可以把它理解為是一款遠端控制軟體。

Project xCloud

project xcloud開發


project xCloud開發

Microsoft有提供開發的文件給開發者做閱讀,提供的部分主要是關於client端與server端之間介接的操作說明文件,有提供「Getting Start」以及「Project xCloud | Game Developers Conference 2019」影片。

開發的流程

介面配置對應實際操作

Getting Start

文件中也有提供能夠介接他們API的使用範例

透過這樣的設定能夠,將手機介面上所進行的的操作,
對應到實際上遊戲的操作。

{ id: 'standard', name: 'Standard', left: { inner: [ { type: 'joystick', expand: false, axis: { input: 'axisXY', output: 'leftJoystick', deadzone: { threshold: 0.05, radial: true, }, }, }, ], outer: [ null, null, [ { type: 'directionalPad', }, ], { type: 'button', action: 'leftThumb', }, null, { type: 'button', action: 'leftTrigger', }, { type: 'button', action: 'leftBumper', }, ], }, right: { inner: [ { type: 'button', action: 'gamepadY', }, { type: 'button', action: 'gamepadB', }, { type: 'button', action: 'gamepadA', }, { type: 'button', action: 'gamepadX', }, ], outer: [ { type: 'button', action: 'rightBumper', }, { type: 'button', action: 'rightTrigger', }, null, { type: 'button', action: 'rightThumb', }, [ { type: 'joystick', axis: { input: 'axisXY', output: 'rightJoystick', deadzone: { threshold: 0.05, radial: true, }, }, }, ], ], }, upper: { leftCenter: [ { type: 'button', action: 'view', }, ], rightCenter: [ { type: 'button', action: 'menu', }, ], }, }

將對手機螢幕的實際操作對應到App中按鍵的操作

void ViewProvider::OnPointerPress( _In_ CoreWindow^ sender, _In_ PointerEventArgs^ args) { HandlePointerUpdateEvent( args->CurrentPoint->Properties->PointerUpdateKind, args->CurrentPoint->Timestamp, args->CurrentPoint->PointerDevice->PointerDeviceType == Windows::Device::Input::PointerDeviceType::Touch, args->CurrentPoint->Position.X, args->CurrentPoint->Position.Y); }
if (Event.bTouch) { if (Cursor.IsValid()) { Cursor->SetPosition( static_cast<int32>(Event.TouchX), static_cast<int32>(Event.TouchY)); MessageHandler->onMouseMove; } }

以下是一些基礎的API

// 判斷使用xCloud遊玩遊戲,是利用串流的方式或是連接到xbox主機 XGameStreamingIsStreaming() // 判斷連接的狀況,通常會使用在連線以及斷線 XGameStreamingRegisterConnectionStateChanged()

結論

以上有介紹的雲端遊戲串流最簡單的架構圖以及原理,中間也有提到三個實踐的案例,

  1. 使用第三方的軟體-Parsec與雲端虛擬機的方案,這就是一種遠端桌面,透過他人寫好的軟體來達成原端遊玩遊戲的方法。
  2. 該如何將視訊串流、玩家控制在server與client端之間互相傳送進行比較深入的研究,自行開發出能夠遠端連線至桌面的方法。
  3. Google已經實作好所有的溝通方法,給開發者一個能夠將自己的遊戲部署上去的空間,使用的開發引擎通常為Unity、Unreal等等的遊戲引擎,目前比較沒有實作面的資料。

來分析一下優缺點

  1. 無法進行自動部署,第一種方法必須在虛擬機上面安裝Parsec並且還要進行登入才能將遊戲分享給其他人來做遊玩。
  2. 管理不便以及對於虛擬機的擴展並沒有做很好的規劃,講者在演講中也有提到說並沒有特別去測試多人去擴展部署的部分,他們所開發的軟體包是git開源出來,要部署是能夠方便的部署出去,但是程式碼已經沒有在做維護,並且如果有新的使用者連線就要開一台全新的虛擬機給他一個人做使用,這樣的擴展方式太耗費資源了。
  3. 使用Google的平台進行開發雖然很方便,但是要註冊成為他們的開發者,所在的國家必須要有可以運行Stadia instance的data center,台灣並沒有他們的data center。除了這個之外,他們所使用的開發引擎是屬於遊戲的開發引擎,所以如果不是使用那些開發引擎要部署上去也會遇上許多的問題。

所以 B > Z

參考資料

云游戏解决方案
遊戲解決方案
Getting Started with AWS Game Tech
Stadia develope
Microsoft project xcloud
為您隆重介紹 Facebook Gaming 雲端遊戲平台
2020 Microsoft Gaming Developer Conference
雲端遊戲開發者大會

已經進入SaaS / PaaS / IaaS 時代已久,還在用舊時代想法規劃網站嗎?
A Year in the life of a Stadia Game Developer
Building a Best-in-Class Game Streaming Experience on Project xCloud | Game Stack Live
Project xCloud | Game Developers Conference 2019
Bringing Destiny to Stadia: A postmortem (Google Games Dev Summit)
讓手機像Switch一樣玩3A級大作 使用雲端遊戲串流打造自己的Google Stadia
ELI5: Does Stadia basically work like Parsec with Google's server as the host?
webrtcH4cKS: ~ Open Source Cloud Gaming with WebRTC
What is Stadia Makers?
走向天際─Stadia (天梯)雲端遊戲平台介紹與接受度調查