webrtc c++ native 获取local sdp流程
一、初始化线程
rtc::WinsockInitializer winsock_init;
rtc::Win32SocketServer w32_ss;
rtc::Win32Thread w32_thread(&w32_ss);
rtc::ThreadManager::Instance()->SetCurrentThread(&w32_thread);
二、创建peer_connection_factory
peer_connection_factory_ = webrtc::CreatePeerConnectionFactory(
nullptr /* network_thread */, nullptr /* worker_thread */,
nullptr /* signaling_thread */, nullptr /* default_adm */,
webrtc::CreateBuiltinAudioEncoderFactory(),
webrtc::CreateBuiltinAudioDecoderFactory(),
webrtc::CreateBuiltinVideoEncoderFactory(),
webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
nullptr /* audio_processing */);
三、创建peer_connection
peer_connection_ = peer_connection_factory_->CreatePeerConnection(
config, nullptr, nullptr, this);
四、创建audio track并add进入peer_connection
rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
peer_connection_factory_->CreateAudioTrack(
kAudioLabel, peer_connection_factory_->CreateAudioSource(
cricket::AudioOptions())));
auto result_or_error = peer_connection_->AddTrack(audio_track, { kStreamId });
五、创建video track并add进入peer_connection
rtc::scoped_refptr<CapturerTrackSource> video_device = CapturerTrackSource::Create();
rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track_(
peer_connection_factory_->CreateVideoTrack(kVideoLabel, video_device));
result_or_error = peer_connection_->AddTrack(video_track_, { kStreamId });
六、创建offer
peer_connection_->CreateOffer(
conductor, webrtc::PeerConnectionInterface::RTCOfferAnswerOptions());
七、获取sdp
void OnSuccess(webrtc::SessionDescriptionInterface* desc) override {
printf("xxxxxxxxxxxxxxxxxxxxxxx\n");
std::string sdp;
desc->ToString(&sdp);
}
八、常见问题
- 初始化线程最好放到main函数(主线程中),否则OnSuccess回调无法调用