FAQ
Abstract |
FAQ |
Authors |
Walter Fan |
Status |
WIP |
Updated |
2024-08-21 |
How to disable SRTP?
以 WebRTC 所带的 peerconnection_client 例程
webrtc::PeerConnectionFactoryInterface::Options options;
options.disable_encryption = this->disable_srtp_;
peer_connection_factory_->SetOptions(options);
step 1
change C:webrtc-checkoutsrcexamplespeerconnectionclientflag_defs.h
ABSL_FLAG(bool, disable_srtp, false, "disable srtp or not: false-enable srtp, true-disable srtp");
step 2
change C:webrtc-checkoutsrcexamplespeerconnectionclientconductor.h
class Conductor : public webrtc::PeerConnectionObserver,
public webrtc::CreateSessionDescriptionObserver,
public PeerConnectionClientObserver,
public MainWndCallback {
public:
void DisableSrtp(bool flag);
bool disable_srtp_;
};
void Conductor::DisableSrtp(bool flag) {
this->disable_srtp_ = flag;
}
step 3
change C:webrtc-checkoutsrcexamplespeerconnectionclientconductor.cc
bool Conductor::InitializePeerConnection() {
RTC_DCHECK(!peer_connection_factory_);
RTC_DCHECK(!peer_connection_);
if (!signaling_thread_.get()) {
signaling_thread_ = rtc::Thread::CreateWithSocketServer();
signaling_thread_->Start();
}
peer_connection_factory_ = webrtc::CreatePeerConnectionFactory(
nullptr /* network_thread */, nullptr /* worker_thread */,
signaling_thread_.get(), nullptr /* default_adm */,
webrtc::CreateBuiltinAudioEncoderFactory(),
webrtc::CreateBuiltinAudioDecoderFactory(),
webrtc::CreateBuiltinVideoEncoderFactory(),
webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
nullptr /* audio_processing */);
if (!peer_connection_factory_) {
main_wnd_->MessageBox("Error", "Failed to initialize PeerConnectionFactory",
true);
DeletePeerConnection();
return false;
}
webrtc::PeerConnectionFactoryInterface::Options options;
options.disable_encryption = this->disable_srtp_;
peer_connection_factory_->SetOptions(options);
if (!CreatePeerConnection()) {
main_wnd_->MessageBox("Error", "CreatePeerConnection failed", true);
DeletePeerConnection();
}
if (videoSourceType_ != VideoSourceType::NOSEND) {
AddTracks();
} else {
main_wnd_->SwitchToStreamingUI();
}
return peer_connection_ != nullptr;
}
Step 4
change C:webrtc-checkoutsrcexamplespeerconnectionclientmain.cc
bool disable_srtp = absl::GetFlag(FLAGS_disable_srtp);
conductor->DisableSrtp(disable_srtp);