WebRTC 学习笔记(5)--线程模型
来源:互联网 发布:淘宝网商城汽车配件 编辑:程序博客网 时间:2024/05/17 23:54
WebRTC 学习笔记(5)--线程模型
1, 基本线程
webretc中主要有两个线程:
signaling_thread-->处理小工作量方法。要求此线程内的方法都必须快速返回。
worker_thread-->处理大工作量的方法。此线程内的方法可能会处理很长时间,如网络消息等。
2, 线程实现
webrtc中的线程包含了一个消息队列。当需要在此线程中运行逻辑时,仅需要向线程对象发送一个消息即可。其中消息包含消息的处理类。
thread主要方法:
virtual void Post(MessageHandler *phandler, uint32 id = 0, MessageData *pdata = NULL, bool time_sensitive = false);发送一个异步请求,调用会立即返回。
发送一个异步请求,调用会立即返回,但是此请求会在cmsDelay后被处理。相当于集成了个计时器。
发送一个同步请求,消息处理完成后调用才会返回。
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);
原文地址:http://blog.csdn.net/oupeng1991/article/details/28619835
- WebRTC 学习笔记(5)--线程模型
- WebRTC 学习笔记(5)--线程模型
- WebRTC 学习笔记(5)--线程模型
- WebRTC-线程模型(1)
- WebRTC-线程模型(2)
- WebRTC 学习笔记(1)--总述
- WebRTC 学习笔记(4)--PeerConnection
- WebRTC 学习笔记(1)--总述
- WebRTC 学习笔记(1)--总述
- WebRTC 学习笔记(4)--PeerConnection
- WebRTC学习笔记(1)-迈出第一步
- webrtc libjingle 学习笔记
- WebRTC学习笔记
- WebRTC学习笔记
- WebRTC学习笔记
- WebRTC学习笔记
- WebRTC学习笔记
- WebRTC 学习笔记
- 我能否用void** 指针作为参数, 使函数按引用接受一般指针?
- ognl.NoSuchPropertyException
- 章子怡汪峰深夜吃火锅
- json-lib使用篇:JSONObject和JSONArray
- 百度地图API简单应用
- WebRTC 学习笔记(5)--线程模型
- 常见比较实用的代码
- 网上素材
- android4 SystemUI 流程分析
- 全局变量使用技巧和注意点
- Path Sum II
- .net下跨数据分布式事务的处理办法TransactionScope
- Azure SQL 数据库引入了新的服务级别
- java向文件写数据的3种方式