WebRTC 學習筆記(5) 執行緒模型

2021-07-10 01:30:05 字數 2930 閱讀 8351

1, 基本執行緒

webretc中主要有兩個執行緒:

signaling_thread-->處理小工作量方法。要求此執行緒內的方法都必須快速返回。

worker_thread-->處理大工作量的方法。此執行緒內的方法可能會處理很長時間,如網路訊息等。

​2, 執行緒實現

webrtc中的執行緒包含了乙個訊息佇列。當需要在此執行緒中執行邏輯時,僅需要向執行緒物件傳送乙個訊息即可。其中訊息包含訊息的處理類。

thread主要方法:

virtual void post(messagehandler *phandler, uint32 id = 0,  messagedata *pdata = null, bool time_sensitive = false);

傳送乙個非同步請求,呼叫會立即返回。

virtual void postdelayed(int cmsdelay, messagehandler *phandler, uint32 id = 0, messagedata *pdata = null);

傳送乙個非同步請求,呼叫會立即返回,但是此請求會在cmsdelay後被處理。相當於整合了個計時器。

virtual void send(messagehandler *phandler, uint32 id = 0,  messagedata *pdata = null);

傳送乙個同步請求,訊息處理完成後呼叫才會返回。

3, 執行緒呼叫實現

3.1 傳送乙個訊息。

thread->send() 

thread->post()

3.2 呼叫invoke

worker_thread_->invoke(bind(&mediaengineinte***ce::setoutputvolume, media_engine_, level));

以上呼叫表示在worker_thread_內同步呼叫media_engine_類的mediaengineinte***ce::setoutputvolume方法,方法有乙個引數是level

3.3 用proxy巨集

如下用proxy巨集定義對應類的proxy類,此proxy類的所有方法都會在woker_thread_執行緒內呼叫

begin_proxy_map(peerconnection)

proxy_method0(talk_base::scoped_refptr,

local_streams)

proxy_method0(talk_base::scoped_refptr,

remote_streams)

proxy_method2(bool, addstream, mediastreaminte***ce*,

const mediaconstraintsinte***ce*)

proxy_method1(void, removestream, mediastreaminte***ce*)

proxy_method1(talk_base::scoped_refptr,

createdtmfsender, audiotrackinte***ce*)

proxy_method2(bool, getstats, statsobserver*, mediastreamtrackinte***ce*)

proxy_method2(talk_base::scoped_refptr,

createdatachannel, const std::string&, const datachannelinit*)

proxy_constmethod0(const sessiondescriptioninte***ce*, local_description)

proxy_constmethod0(const sessiondescriptioninte***ce*, remote_description)

proxy_method2(void, createoffer, createsessiondescriptionobserver*,

const mediaconstraintsinte***ce*)

proxy_method2(void, createanswer, createsessiondescriptionobserver*,

const mediaconstraintsinte***ce*)

proxy_method2(void, setlocaldescription, setsessiondescriptionobserver*,

sessiondescriptioninte***ce*)

proxy_method2(void, setremotedescription, setsessiondescriptionobserver*,

sessiondescriptioninte***ce*)

proxy_method2(bool, updateice, const iceservers&,

const mediaconstraintsinte***ce*)

proxy_method1(bool, addicecandidate, const icecandidateinte***ce*)

proxy_method0(signalingstate, signaling_state)

proxy_method0(icestate, ice_state)

proxy_method0(iceconnectionstate, ice_connection_state)

proxy_method0(icegatheringstate, ice_gathering_state)

proxy_method0(void, close)

end_proxy()

peerconnectionproxy(woker_thread_, peer_connection);

webrtc學習筆記四 Webrtc原始碼目錄結構

webrtc的 量非常巨大,所以目錄也特別多 但是webrtc是分層的,必須掌握一些重要的目錄,在後續開發中會遇到需要修改webrtc 的需求情況,所以必須掌握主要的目錄的功能,這樣在修改 的時候,就能夠快速的定位到相應的目錄下,找到相應的檔案進行修改 如果不清楚目錄結構,就只能乙個個的去查詢,這就...

WebRTC 學習筆記(1) 總述

1,主頁 2,專案由來。當前的webrtc專案是由google收購的gips專案和libjingle專案融合而成。其中gips部分主要提供 的處理的功能。libjingle專案部分主要提供p2p傳輸部分的功能。3,專案實現的功能。4,code source 5,code基本結構 libjingle ...

WebRTC 學習筆記(1) 總述

1,主頁 2,專案由來。當前的webrtc專案是由google收購的gips專案和libjingle專案融合而成。其中 gips 部分主要提供 的處理的功能 libjingle 專案部分主要提供p2p傳輸部分的功能。3,專案實現的功能。4,code source 5,code基本結構 libjing...