How to disable SRTP in WebRTC library

Table of Contents

Take peerconnection_client as example

  webrtc::PeerConnectionFactoryInterface::Options options;
  options.disable_encryption = this->disable_srtp_;
  peer_connection_factory_->SetOptions(options);

step 1

change C:\webrtc-checkout\src\examples\peerconnection\client\flag_defs.h

ABSL_FLAG(bool, disable_srtp, false, "disable srtp or not: false-enable srtp, true-disable srtp");

step 2

change C:\webrtc-checkout\src\examples\peerconnection\client\conductor.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-checkout\src\examples\peerconnection\client\conductor.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-checkout\src\examples\peerconnection\client\main.cc

  bool disable_srtp = absl::GetFlag(FLAGS_disable_srtp);
  conductor->DisableSrtp(disable_srtp);

Comments |0|

Legend *) Required fields are marked
**) You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Category: Uncategorized