WebRTC 学习笔记(5)--线程模型
2015-06-23 12:04
435 查看
1, 基本线程
webrtc中主要有两个线程:
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<bool>(Bind(&MediaEngineInterface::SetOutputVolume, media_engine_, level));
以上调用表示在worker_thread_内同步调用media_engine_类的MediaEngineInterface::SetOutputVolume方法,方法有一个参数是level
3.3 用proxy宏
如下用PROXY宏定义对应类的proxy类,此proxy类的所有方法都会在woker_thread_线程内调用
BEGIN_PROXY_MAP(PeerConnection)
PROXY_METHOD0(talk_base::scoped_refptr<StreamCollectionInterface>,
local_streams)
PROXY_METHOD0(talk_base::scoped_refptr<StreamCollectionInterface>,
remote_streams)
PROXY_METHOD2(bool, AddStream, MediaStreamInterface*,
const MediaConstraintsInterface*)
PROXY_METHOD1(void, RemoveStream, MediaStreamInterface*)
PROXY_METHOD1(talk_base::scoped_refptr<DtmfSenderInterface>,
CreateDtmfSender, AudioTrackInterface*)
PROXY_METHOD2(bool, GetStats, StatsObserver*, MediaStreamTrackInterface*)
PROXY_METHOD2(talk_base::scoped_refptr<DataChannelInterface>,
CreateDataChannel, const std::string&, const DataChannelInit*)
PROXY_CONSTMETHOD0(const SessionDescriptionInterface*, local_description)
PROXY_CONSTMETHOD0(const SessionDescriptionInterface*, remote_description)
PROXY_METHOD2(void, CreateOffer, CreateSessionDescriptionObserver*,
const MediaConstraintsInterface*)
PROXY_METHOD2(void, CreateAnswer, CreateSessionDescriptionObserver*,
const MediaConstraintsInterface*)
PROXY_METHOD2(void, SetLocalDescription, SetSessionDescriptionObserver*,
SessionDescriptionInterface*)
PROXY_METHOD2(void, SetRemoteDescription, SetSessionDescriptionObserver*,
SessionDescriptionInterface*)
PROXY_METHOD2(bool, UpdateIce, const IceServers&,
const MediaConstraintsInterface*)
PROXY_METHOD1(bool, AddIceCandidate, const IceCandidateInterface*)
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);
/article/9284681.html
webrtc中主要有两个线程:
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<bool>(Bind(&MediaEngineInterface::SetOutputVolume, media_engine_, level));
以上调用表示在worker_thread_内同步调用media_engine_类的MediaEngineInterface::SetOutputVolume方法,方法有一个参数是level
3.3 用proxy宏
如下用PROXY宏定义对应类的proxy类,此proxy类的所有方法都会在woker_thread_线程内调用
BEGIN_PROXY_MAP(PeerConnection)
PROXY_METHOD0(talk_base::scoped_refptr<StreamCollectionInterface>,
local_streams)
PROXY_METHOD0(talk_base::scoped_refptr<StreamCollectionInterface>,
remote_streams)
PROXY_METHOD2(bool, AddStream, MediaStreamInterface*,
const MediaConstraintsInterface*)
PROXY_METHOD1(void, RemoveStream, MediaStreamInterface*)
PROXY_METHOD1(talk_base::scoped_refptr<DtmfSenderInterface>,
CreateDtmfSender, AudioTrackInterface*)
PROXY_METHOD2(bool, GetStats, StatsObserver*, MediaStreamTrackInterface*)
PROXY_METHOD2(talk_base::scoped_refptr<DataChannelInterface>,
CreateDataChannel, const std::string&, const DataChannelInit*)
PROXY_CONSTMETHOD0(const SessionDescriptionInterface*, local_description)
PROXY_CONSTMETHOD0(const SessionDescriptionInterface*, remote_description)
PROXY_METHOD2(void, CreateOffer, CreateSessionDescriptionObserver*,
const MediaConstraintsInterface*)
PROXY_METHOD2(void, CreateAnswer, CreateSessionDescriptionObserver*,
const MediaConstraintsInterface*)
PROXY_METHOD2(void, SetLocalDescription, SetSessionDescriptionObserver*,
SessionDescriptionInterface*)
PROXY_METHOD2(void, SetRemoteDescription, SetSessionDescriptionObserver*,
SessionDescriptionInterface*)
PROXY_METHOD2(bool, UpdateIce, const IceServers&,
const MediaConstraintsInterface*)
PROXY_METHOD1(bool, AddIceCandidate, const IceCandidateInterface*)
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);
/article/9284681.html
相关文章推荐
- mysql-bin权限问题导致mysql无法启动
- Linux下编译安装Apache Http Server
- 日语学习之沪江N3基础 20150623 -1
- sp_addlinkedserver '(null)' is an invalid product name
- 使用Meteor配合Node.js编写实时聊天应用的范例
- iOS 终端命令行
- awk学习笔记
- HTTP-API-DESIGN 怎样设计一个合理的 HTTP API (二)
- osgi环境问题
- link流程 建立时需要注意的地方
- Handlebars 文档笔记
- linux下安装JDK
- Android的fragment
- 敏捷每天站将
- PHP实现在线阅读PDF文件的方法
- 简单的SSM搭建步骤,以备后用。
- JNI之——'cl' 不是内部或外部命令,也不是可运行的程序或批处理文件
- ZOJ 3471 Most Powerful
- linux学习资料
- sublime3安装python插件 -- SublimeCodeIntel