WebRTC代理类作用--切到原本的线程执行

博客内容涉及WebRTC中PeerConnectionFactory的实现,包括创建PeerConnection的方法,并强调了线程安全的重要性。创建PeerConnection时需在信令线程上进行,而其他如VideoReceiveStream和BaseChannel的工作则在不同的线程上处理。代码示例展示了如何确保任务在正确线程上执行以及如何调用SetRemoteDescription等方法。
//src/api/peer_connection_factory_proxy.h
BEGIN_PRIMARY_PROXY_MAP(PeerConnectionFactory) //primary
PROXY_PRIMARY_THREAD_DESTRUCTOR()
  
PROXY_METHOD4(rtc::scoped_refptr<PeerConnectionInterface>,
              CreatePeerConnection,
              const PeerConnectionInterface::RTCConfiguration&,
              std::unique_ptr<cricket::PortAllocator>,
              std::unique_ptr<rtc::RTCCertificateGeneratorInterface>,
              PeerConnectionObserver*)
  ...
END_PROXY_MAP()


//实现在proxy.h
#define BEGIN_PRIMARY_PROXY_MAP(c)                                             \
  PROXY_MAP_BOILERPLATE(c)                                                     \
  PRIMARY_PROXY_MAP_BOILERPLATE(c)                                             \
  REFCOUNTED_PROXY_MAP_BOILERPLATE(c)                                          \
 public:                                                                       \
  static rtc::scoped_refptr<c##ProxyWithInternal> Create(                      \
      rtc::Thread* primary_thread, INTERNAL_CLASS* c) {                        \
    return new rtc::RefCountedObject<c##ProxyWithInternal>(primary_thread, c); \
  }

class MethodCall : public QueuedTask {
  R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
    if (t->IsCurrent()) {
      Invoke(std::index_sequence_for<Args...>());
    } else {
      t->PostTask(std::unique_ptr<QueuedTask>(this));
      event_.Wait(rtc::Event::kForever);
    }
    return r_.moved_result();
  }
}

//Synchronous同步, Asynchronous异步,
//没判断是否在信令线程 ?
peer_connection_->SetRemoteDescription(...)
//检查是否在信令线程
rtc::scoped_refptr<PeerConnectionInterface>
PeerConnectionFactory::CreatePeerConnection(...) {
  RTC_DCHECK(signaling_thread_->IsCurrent());
}


peer_connection_factory_->CreateVideoTrack(
          kVideoLabel,
          peer_connection_factory_->CreateVideoSource(OpenVideoCaptureDevice(), 			                                         
                                                      NULL)));

peer_connection_factory_->CreateLocalMediaStream(kStreamLabel);

信令线程用在:发送信令。

工作线程:VideoReceiveStream、BaseChannel等有判断。

网络线程:WebRtcSession等有判断。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值