chromium/remoting/protocol/webrtc_transport.cc

// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "remoting/protocol/webrtc_transport.h"

#include <algorithm>
#include <memory>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

#include "base/base64.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ref.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/threading/thread_restrictions.h"
#include "base/time/time.h"
#include "components/webrtc/net_address_utils.h"
#include "components/webrtc/thread_wrapper.h"
#include "remoting/base/constants.h"
#include "remoting/base/logging.h"
#include "remoting/protocol/authenticator.h"
#include "remoting/protocol/errors.h"
#include "remoting/protocol/port_allocator_factory.h"
#include "remoting/protocol/sdp_message.h"
#include "remoting/protocol/transport.h"
#include "remoting/protocol/transport_context.h"
#include "remoting/protocol/webrtc_audio_module.h"
#include "third_party/libjingle_xmpp/xmllite/xmlelement.h"
#include "third_party/webrtc/api/audio_codecs/audio_decoder_factory_template.h"
#include "third_party/webrtc/api/audio_codecs/audio_encoder_factory_template.h"
#include "third_party/webrtc/api/audio_codecs/opus/audio_decoder_opus.h"
#include "third_party/webrtc/api/audio_codecs/opus/audio_encoder_opus.h"
#include "third_party/webrtc/api/enable_media.h"
#include "third_party/webrtc/api/peer_connection_interface.h"
#include "third_party/webrtc/api/rtc_event_log/rtc_event_log_factory.h"
#include "third_party/webrtc/api/video_codecs/builtin_video_decoder_factory.h"
#include "third_party/webrtc/modules/audio_processing/include/audio_processing.h"
#include "third_party/webrtc_overrides/task_queue_factory.h"

#if !defined(NDEBUG)
#include "base/command_line.h"
#endif

QName;
XmlElement;

namespace remoting::protocol {

class ScopedAllowThreadJoinForWebRtcTransport
    : public base::ScopedAllowBaseSyncPrimitivesOutsideBlockingScope {};

class ScopedAllowSyncPrimitivesForWebRtcTransport
    : public base::ScopedAllowBaseSyncPrimitivesOutsideBlockingScope {};

namespace {

DataChannelState;

// Delay after candidate creation before sending transport-info message to
// accumulate multiple candidates. This is an optimization to reduce number of
// transport-info messages.
const int kTransportInfoSendDelayMs =;

// XML namespace for the transport elements.
const char kTransportNamespace[] =;

// Global maximum bitrate set for the PeerConnection.
const int kMaxBitrateBps =;  // 100 Mbps.

// Frequency of polling the event and control data channels for their current
// state while waiting for them to close.
constexpr base::TimeDelta kDefaultDataChannelStatePollingInterval =;

// The maximum amount of time we will wait for the data channels to close before
// closing the PeerConnection.
constexpr base::TimeDelta kWaitForDataChannelsClosedTimeout =;

// The time to wait after receiving a disconnected state change before assuming
// that the connection is failed.
constexpr base::TimeDelta kCloseAfterDisconnectTimeout =;

base::TimeDelta data_channel_state_polling_interval =;

#if !defined(NDEBUG)
// Command line switch used to disable signature verification.
// TODO(sergeyu): Remove this flag.
const char kDisableAuthenticationSwitchName[] =;
#endif

bool IsValidSessionDescriptionType(webrtc::SdpType type) {}

void UpdateCodecParameters(SdpMessage* sdp_message, bool incoming) {}

std::string GetTransportProtocol(const cricket::CandidatePair& candidate_pair) {}

// Returns true if the selected candidate-pair indicates a relay connection.
std::optional<bool> IsConnectionRelayed(
    const cricket::CandidatePair& selected_candidate_pair) {}

// Utility function to map a cricket::Candidate string type to a
// TransportRoute::RouteType enum value.
TransportRoute::RouteType CandidateTypeToTransportRouteType(
    const cricket::Candidate& candidate) {}

void SetSenderParameters(webrtc::RtpSenderInterface& sender,
                         const webrtc::RtpParameters& parameters) {}

// Initializes default parameters for a sender that may be different from
// WebRTC's defaults.
void SetDefaultSenderParameters(
    rtc::scoped_refptr<webrtc::RtpSenderInterface> sender) {}

// A webrtc::CreateSessionDescriptionObserver implementation used to receive the
// results of creating descriptions for this end of the PeerConnection.
class CreateSessionDescriptionObserver
    : public webrtc::CreateSessionDescriptionObserver {};

// A webrtc::SetSessionDescriptionObserver implementation used to receive the
// results of setting local and remote descriptions of the PeerConnection.
class SetSessionDescriptionObserver
    : public webrtc::SetSessionDescriptionObserver {};

class RtcEventLogOutput : public webrtc::RtcEventLogOutput {};

}  // namespace

class WebrtcTransport::PeerConnectionWrapper
    : public webrtc::PeerConnectionObserver {};

WebrtcTransport::WebrtcTransport(
    rtc::Thread* worker_thread,
    scoped_refptr<TransportContext> transport_context,
    std::unique_ptr<webrtc::VideoEncoderFactory> video_encoder_factory,
    EventHandler* event_handler)
    :{}

WebrtcTransport::~WebrtcTransport() {}

webrtc::PeerConnectionInterface* WebrtcTransport::peer_connection() {}

webrtc::PeerConnectionFactoryInterface*
WebrtcTransport::peer_connection_factory() {}

WebrtcAudioModule* WebrtcTransport::audio_module() {}

std::unique_ptr<MessagePipe> WebrtcTransport::CreateOutgoingChannel(
    const std::string& name) {}

void WebrtcTransport::ApplyNetworkSettings(
    const NetworkSettings& network_settings) {}

void WebrtcTransport::Start(
    Authenticator* authenticator,
    SendTransportInfoCallback send_transport_info_callback) {}

bool WebrtcTransport::ProcessTransportInfo(XmlElement* transport_info) {}

const SessionOptions& WebrtcTransport::session_options() const {}

void WebrtcTransport::SetPreferredBitrates(std::optional<int> min_bitrate_bps,
                                           std::optional<int> max_bitrate_bps) {}

void WebrtcTransport::RequestIceRestart() {}

void WebrtcTransport::RequestSdpRestart() {}

// static
void WebrtcTransport::SetDataChannelPollingIntervalForTests(
    base::TimeDelta new_polling_interval) {}

// static
void WebrtcTransport::ClosePeerConnection(
    rtc::scoped_refptr<webrtc::DataChannelInterface> control_data_channel,
    rtc::scoped_refptr<webrtc::DataChannelInterface> event_data_channel,
    std::unique_ptr<PeerConnectionWrapper> peer_connection_wrapper,
    base::Time start_time = base::Time::Now()) {}

void WebrtcTransport::Close(ErrorCode error) {}

void WebrtcTransport::ApplySessionOptions(const SessionOptions& options) {}

void WebrtcTransport::OnAudioTransceiverCreated(
    rtc::scoped_refptr<webrtc::RtpTransceiverInterface> transceiver) {}

void WebrtcTransport::OnVideoTransceiverCreated(
    rtc::scoped_refptr<webrtc::RtpTransceiverInterface> transceiver) {}

void WebrtcTransport::OnLocalSessionDescriptionCreated(
    std::unique_ptr<webrtc::SessionDescriptionInterface> description,
    const std::string& error) {}

void WebrtcTransport::OnLocalDescriptionSet(bool success,
                                            const std::string& error) {}

void WebrtcTransport::OnRemoteDescriptionSet(bool send_answer,
                                             bool success,
                                             const std::string& error) {}

void WebrtcTransport::SendAnswer() {}

void WebrtcTransport::OnCloseAfterDisconnectTimeout() {}

void WebrtcTransport::OnSignalingChange(
    webrtc::PeerConnectionInterface::SignalingState new_state) {}

void WebrtcTransport::OnAddStream(
    rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) {}

void WebrtcTransport::OnRemoveStream(
    rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) {}

void WebrtcTransport::OnDataChannel(
    rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) {}

void WebrtcTransport::OnRenegotiationNeeded() {}

void WebrtcTransport::OnIceConnectionChange(
    webrtc::PeerConnectionInterface::IceConnectionState new_state) {}

void WebrtcTransport::OnIceGatheringChange(
    webrtc::PeerConnectionInterface::IceGatheringState new_state) {}

void WebrtcTransport::OnIceCandidate(
    const webrtc::IceCandidateInterface* candidate) {}

void WebrtcTransport::OnIceSelectedCandidatePairChanged(
    const cricket::CandidatePairChangeEvent& event) {}

std::tuple<int, int> WebrtcTransport::BitratesForConnection() {}

void WebrtcTransport::UpdateBitrates() {}

void WebrtcTransport::SetPeerConnectionBitrates(int min_bitrate_bps,
                                                int max_bitrate_bps) {}

void WebrtcTransport::SetSenderBitrates(
    rtc::scoped_refptr<webrtc::RtpSenderInterface> sender,
    int min_bitrate_bps,
    int max_bitrate_bps) {}

void WebrtcTransport::RequestNegotiation() {}

void WebrtcTransport::SendOffer() {}

void WebrtcTransport::EnsurePendingTransportInfoMessage() {}

void WebrtcTransport::SendTransportInfo() {}

void WebrtcTransport::AddPendingCandidatesIfPossible() {}

void WebrtcTransport::StartRtcEventLogging() {}

void WebrtcTransport::StopRtcEventLogging() {}

}  // namespace remoting::protocol