DSP

WebRtc libjingle_PeerConnection层(二) CreateOffer

2019-07-13 15:44发布

发起视频通话流程图如下
Set up a call 创建dsp描述符,CreateOffer在流程中位于 OnSignalingMessage(offer) void CConductor::ConnectToPeer(int peer_id) { if (peer_connection_.get()) { LOG(LS_ERROR) << "We only support connecting to one peer at a time"; return; } if (InitializePeerConnection()) { peer_connection_->CreateOffer(this, NULL); } else { LOG(LS_ERROR) << "Failed to initialize PeerConnection"; } } void CConductor::OnSuccess(webrtc::SessionDescriptionInterface* desc) { peer_connection_->SetLocalDescription( DummySetSessionDescriptionObserver::Create(), desc); std::string sdp; desc->ToString(&sdp); // For loopback test. To save some connecting delay. if (loopback_) { // Replace message type from "offer" to "answer" webrtc::SessionDescriptionInterface* session_description( webrtc::CreateSessionDescription("answer", sdp)); peer_connection_->SetRemoteDescription( DummySetSessionDescriptionObserver::Create(), session_description); return; } Json::StyledWriter writer; Json::Value jmessage; jmessage[kSessionDescriptionTypeName] = desc->type(); jmessage[kSessionDescriptionSdpName] = sdp; SendMessage(writer.write(jmessage)); } void CConductor::OnFailure(const std::string& error) { LOG(LERROR) << error; } CreateOffer的第一个参数是webrtc:CreateSessionDescriptionObserver,故CConductor继承自webrtc:CreateSessionDescriptionObserver,重写OnSuccess和OnFailure,当调用CreateOffer成功后,OnSuccess会被函数会被触发,就可以获得sdp信息。
再将sdp传递到外部,有通讯现成发送至RemotPeer。 int main(){ ... rtc::Win32Thread w32_thread; rtc::ThreadManager::Instance()->SetCurrentThread(&w32_thread); ... rtc::scoped_refptr conductor( new rtc::RefCountedObject(&client, &viceo_show)); ... while ((gm = ::GetMessage(&msg, NULL, 0, 0)) != 0 && gm != -1) { ::TranslateMessage(&msg); ::DispatchMessage(&msg); } ... } 从调试来看webrtc似乎是用了类似Windows的消息机制,很多命令都是通过DispatchMessage来派发消息。
注意如果没有调用rtc::ThreadManager::Instance()->SetCurrentThread()函数和DispatchMessage,会导致CreateOffer调用后,无法回调OnSuccess。(掉坑了) 调试的时候。仅需在OnSuccess中打断点即可。 仅含工程代码,无webrtc项目源码
http://download.csdn.net/detail/q339659207/9104747