Add thread safety annotations for some more PeerConnection members (part 12)

Plus all the annotations that were necessary to make things compile
again. I also had to send copies of some values owned by the signal
thread to the network thread, instead of letting the latter read them
itself.

Bug: webrtc:9987
Change-Id: Ic4b38696245584bab44956e60ac63753146e3ff4
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/131020
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Steve Anton <steveanton@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27437}
This commit is contained in:
Karl Wiberg 2019-04-03 11:37:28 +02:00 committed by Commit Bot
parent c680c4a807
commit 739506e45e
2 changed files with 47 additions and 24 deletions

View File

@ -3463,7 +3463,8 @@ bool PeerConnection::SetConfiguration(const RTCConfiguration& configuration,
modified_config.ice_candidate_pool_size,
modified_config.prune_turn_ports,
modified_config.turn_customizer,
modified_config.stun_candidate_keepalive_interval))) {
modified_config.stun_candidate_keepalive_interval,
static_cast<bool>(local_description())))) {
RTC_LOG(LS_ERROR) << "Failed to apply configuration to PortAllocator.";
return SafeSetError(RTCErrorType::INTERNAL_ERROR, error);
}
@ -3758,32 +3759,38 @@ rtc::scoped_refptr<SctpTransportInterface> PeerConnection::GetSctpTransport()
}
const SessionDescriptionInterface* PeerConnection::local_description() const {
RTC_DCHECK_RUN_ON(signaling_thread());
return pending_local_description_ ? pending_local_description_.get()
: current_local_description_.get();
}
const SessionDescriptionInterface* PeerConnection::remote_description() const {
RTC_DCHECK_RUN_ON(signaling_thread());
return pending_remote_description_ ? pending_remote_description_.get()
: current_remote_description_.get();
}
const SessionDescriptionInterface* PeerConnection::current_local_description()
const {
RTC_DCHECK_RUN_ON(signaling_thread());
return current_local_description_.get();
}
const SessionDescriptionInterface* PeerConnection::current_remote_description()
const {
RTC_DCHECK_RUN_ON(signaling_thread());
return current_remote_description_.get();
}
const SessionDescriptionInterface* PeerConnection::pending_local_description()
const {
RTC_DCHECK_RUN_ON(signaling_thread());
return pending_local_description_.get();
}
const SessionDescriptionInterface* PeerConnection::pending_remote_description()
const {
RTC_DCHECK_RUN_ON(signaling_thread());
return pending_remote_description_.get();
}
@ -5392,13 +5399,14 @@ bool PeerConnection::ReconfigurePortAllocator_n(
int candidate_pool_size,
bool prune_turn_ports,
webrtc::TurnCustomizer* turn_customizer,
absl::optional<int> stun_candidate_keepalive_interval) {
absl::optional<int> stun_candidate_keepalive_interval,
bool have_local_description) {
port_allocator_->set_candidate_filter(
ConvertIceTransportTypeToCandidateFilter(type));
// According to JSEP, after setLocalDescription, changing the candidate pool
// size is not allowed, and changing the set of ICE servers will not result
// in new candidates being gathered.
if (local_description()) {
if (have_local_description) {
port_allocator_->FreezeCandidatePool();
}
// Add the custom tls turn servers if they exist.
@ -5600,7 +5608,9 @@ RTCError PeerConnection::PushdownMediaDescription(
cricket::GetFirstDataContent(remote_description()->description())) {
bool success = network_thread()->Invoke<bool>(
RTC_FROM_HERE,
rtc::Bind(&PeerConnection::PushdownSctpParameters_n, this, source));
rtc::Bind(&PeerConnection::PushdownSctpParameters_n, this, source,
GetSctpPort(local_description()->description()),
GetSctpPort(remote_description()->description())));
if (!success) {
LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
"Failed to push down SCTP parameters.");
@ -5610,15 +5620,13 @@ RTCError PeerConnection::PushdownMediaDescription(
return RTCError::OK();
}
bool PeerConnection::PushdownSctpParameters_n(cricket::ContentSource source) {
RTC_DCHECK(network_thread()->IsCurrent());
RTC_DCHECK(local_description());
RTC_DCHECK(remote_description());
bool PeerConnection::PushdownSctpParameters_n(cricket::ContentSource source,
int local_sctp_port,
int remote_sctp_port) {
RTC_DCHECK_RUN_ON(network_thread());
// Apply the SCTP port (which is hidden inside a DataCodec structure...)
// When we support "max-message-size", that would also be pushed down here.
return cricket_sctp_transport()->Start(
GetSctpPort(local_description()->description()),
GetSctpPort(remote_description()->description()));
return cricket_sctp_transport()->Start(local_sctp_port, remote_sctp_port);
}
RTCError PeerConnection::PushdownTransportDescription(
@ -5823,6 +5831,7 @@ bool PeerConnection::ReadyToSendData() const {
void PeerConnection::OnDataReceived(int channel_id,
DataMessageType type,
const rtc::CopyOnWriteBuffer& buffer) {
RTC_DCHECK_RUN_ON(network_thread());
cricket::ReceiveDataParams params;
params.sid = channel_id;
params.type = ToCricketDataMessageType(type);
@ -5836,6 +5845,7 @@ void PeerConnection::OnDataReceived(int channel_id,
}
void PeerConnection::OnChannelClosing(int channel_id) {
RTC_DCHECK_RUN_ON(network_thread());
media_transport_invoker_->AsyncInvoke<void>(
RTC_FROM_HERE, signaling_thread(), [this, channel_id] {
RTC_DCHECK_RUN_ON(signaling_thread());
@ -5844,6 +5854,7 @@ void PeerConnection::OnChannelClosing(int channel_id) {
}
void PeerConnection::OnChannelClosed(int channel_id) {
RTC_DCHECK_RUN_ON(network_thread());
media_transport_invoker_->AsyncInvoke<void>(
RTC_FROM_HERE, signaling_thread(), [this, channel_id] {
RTC_DCHECK_RUN_ON(signaling_thread());

View File

@ -784,7 +784,8 @@ class PeerConnection : public PeerConnectionInternal,
int candidate_pool_size,
bool prune_turn_ports,
webrtc::TurnCustomizer* turn_customizer,
absl::optional<int> stun_candidate_keepalive_interval);
absl::optional<int> stun_candidate_keepalive_interval,
bool have_local_description);
// Starts output of an RTC event log to the given output object.
// This function should only be called from the worker thread.
@ -850,11 +851,13 @@ class PeerConnection : public PeerConnectionInternal,
// Non-const versions of local_description()/remote_description(), for use
// internally.
SessionDescriptionInterface* mutable_local_description() {
SessionDescriptionInterface* mutable_local_description()
RTC_RUN_ON(signaling_thread()) {
return pending_local_description_ ? pending_local_description_.get()
: current_local_description_.get();
}
SessionDescriptionInterface* mutable_remote_description() {
SessionDescriptionInterface* mutable_remote_description()
RTC_RUN_ON(signaling_thread()) {
return pending_remote_description_ ? pending_remote_description_.get()
: current_remote_description_.get();
}
@ -869,7 +872,9 @@ class PeerConnection : public PeerConnectionInternal,
// down to all of the channels.
RTCError PushdownMediaDescription(SdpType type, cricket::ContentSource source)
RTC_RUN_ON(signaling_thread());
bool PushdownSctpParameters_n(cricket::ContentSource source);
bool PushdownSctpParameters_n(cricket::ContentSource source,
int local_sctp_port,
int remote_sctp_port);
RTCError PushdownTransportDescription(cricket::ContentSource source,
SdpType type);
@ -893,7 +898,8 @@ class PeerConnection : public PeerConnectionInternal,
// Returns false if the local session description does not have a media
// content called |content_name|.
bool GetLocalCandidateMediaIndex(const std::string& content_name,
int* sdp_mline_index);
int* sdp_mline_index)
RTC_RUN_ON(signaling_thread());
// Uses all remote candidates in |remote_desc| in this session.
bool UseCandidatesInSessionDescription(
const SessionDescriptionInterface* remote_desc)
@ -978,7 +984,7 @@ class PeerConnection : public PeerConnectionInternal,
// Returns true if SRTP (either using DTLS-SRTP or SDES) is required by
// this session.
bool SrtpRequired() const;
bool SrtpRequired() const RTC_RUN_ON(signaling_thread());
// JsepTransportController signal handlers.
void OnTransportControllerConnectionState(cricket::IceConnectionState state)
@ -1012,7 +1018,8 @@ class PeerConnection : public PeerConnectionInternal,
void ReportBestConnectionState(const cricket::TransportStats& stats);
void ReportNegotiatedCiphers(const cricket::TransportStats& stats,
const std::set<cricket::MediaType>& media_types);
const std::set<cricket::MediaType>& media_types)
RTC_RUN_ON(signaling_thread());
void NoteUsageEvent(UsageEvent event);
void ReportUsagePattern() const RTC_RUN_ON(signaling_thread());
@ -1266,7 +1273,8 @@ class PeerConnection : public PeerConnectionInternal,
false;
// Used to invoke media transport signals on the signaling thread.
std::unique_ptr<rtc::AsyncInvoker> media_transport_invoker_;
std::unique_ptr<rtc::AsyncInvoker> media_transport_invoker_
RTC_GUARDED_BY(network_thread());
// Identical to the signals for SCTP, but from media transport:
sigslot::signal1<bool> SignalMediaTransportWritable_s
@ -1279,11 +1287,15 @@ class PeerConnection : public PeerConnectionInternal,
sigslot::signal1<int> SignalMediaTransportChannelClosed_s
RTC_GUARDED_BY(signaling_thread());
std::unique_ptr<SessionDescriptionInterface> current_local_description_;
std::unique_ptr<SessionDescriptionInterface> pending_local_description_;
std::unique_ptr<SessionDescriptionInterface> current_remote_description_;
std::unique_ptr<SessionDescriptionInterface> pending_remote_description_;
bool dtls_enabled_ = false;
std::unique_ptr<SessionDescriptionInterface> current_local_description_
RTC_GUARDED_BY(signaling_thread());
std::unique_ptr<SessionDescriptionInterface> pending_local_description_
RTC_GUARDED_BY(signaling_thread());
std::unique_ptr<SessionDescriptionInterface> current_remote_description_
RTC_GUARDED_BY(signaling_thread());
std::unique_ptr<SessionDescriptionInterface> pending_remote_description_
RTC_GUARDED_BY(signaling_thread());
bool dtls_enabled_ RTC_GUARDED_BY(signaling_thread()) = false;
// Specifies which kind of data channel is allowed. This is controlled
// by the chrome command-line flag and constraints:
// 1. If chrome command-line switch 'enable-sctp-data-channels' is enabled,