webrtc_m130/pc/connection_context.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

135 lines
5.0 KiB
C
Raw Normal View History

/*
* Copyright 2020 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef PC_CONNECTION_CONTEXT_H_
#define PC_CONNECTION_CONTEXT_H_
#include <memory>
#include <string>
#include "api/call/call_factory_interface.h"
#include "api/field_trials_view.h"
#include "api/media_stream_interface.h"
#include "api/peer_connection_interface.h"
#include "api/ref_counted_base.h"
#include "api/scoped_refptr.h"
#include "api/sequence_checker.h"
#include "api/transport/sctp_transport_factory_interface.h"
#include "media/base/media_engine.h"
#include "p2p/base/basic_packet_socket_factory.h"
#include "pc/channel_manager.h"
#include "rtc_base/checks.h"
#include "rtc_base/network.h"
#include "rtc_base/network_monitor_factory.h"
#include "rtc_base/rtc_certificate_generator.h"
#include "rtc_base/socket_factory.h"
#include "rtc_base/thread.h"
#include "rtc_base/thread_annotations.h"
namespace rtc {
class BasicNetworkManager;
class BasicPacketSocketFactory;
} // namespace rtc
namespace webrtc {
class RtcEventLog;
// This class contains resources needed by PeerConnection and associated
// objects. A reference to this object is passed to each PeerConnection. The
// methods on this object are assumed not to change the state in any way that
// interferes with the operation of other PeerConnections.
//
// This class must be created and destroyed on the signaling thread.
class ConnectionContext final
: public rtc::RefCountedNonVirtual<ConnectionContext> {
public:
// Creates a ConnectionContext. May return null if initialization fails.
// The Dependencies class allows simple management of all new dependencies
// being added to the ConnectionContext.
static rtc::scoped_refptr<ConnectionContext> Create(
PeerConnectionFactoryDependencies* dependencies);
// This class is not copyable or movable.
ConnectionContext(const ConnectionContext&) = delete;
ConnectionContext& operator=(const ConnectionContext&) = delete;
// Functions called from PeerConnection and friends
SctpTransportFactoryInterface* sctp_transport_factory() const {
return sctp_factory_.get();
}
cricket::ChannelManager* channel_manager() const;
rtc::Thread* signaling_thread() { return signaling_thread_; }
const rtc::Thread* signaling_thread() const { return signaling_thread_; }
rtc::Thread* worker_thread() { return worker_thread_.get(); }
const rtc::Thread* worker_thread() const { return worker_thread_.get(); }
rtc::Thread* network_thread() { return network_thread_; }
const rtc::Thread* network_thread() const { return network_thread_; }
// Field trials associated with the PeerConnectionFactory.
// Note: that there can be different field trials for different
// PeerConnections (but they are not supposed change after creating the
// PeerConnection).
const FieldTrialsView& field_trials() const { return *trials_.get(); }
// Accessors only used from the PeerConnectionFactory class
rtc::BasicNetworkManager* default_network_manager() {
RTC_DCHECK_RUN_ON(signaling_thread_);
return default_network_manager_.get();
}
rtc::BasicPacketSocketFactory* default_socket_factory() {
RTC_DCHECK_RUN_ON(signaling_thread_);
return default_socket_factory_.get();
}
CallFactoryInterface* call_factory() {
RTC_DCHECK_RUN_ON(worker_thread());
return call_factory_.get();
}
protected:
explicit ConnectionContext(PeerConnectionFactoryDependencies* dependencies);
friend class rtc::RefCountedNonVirtual<ConnectionContext>;
~ConnectionContext();
private:
// The following three variables are used to communicate between the
// constructor and the destructor, and are never exposed externally.
bool wraps_current_thread_;
std::unique_ptr<rtc::SocketFactory> owned_socket_factory_;
std::unique_ptr<rtc::Thread> owned_network_thread_
RTC_GUARDED_BY(signaling_thread_);
rtc::Thread* const network_thread_;
AlwaysValidPointer<rtc::Thread> const worker_thread_;
rtc::Thread* const signaling_thread_;
// Accessed both on signaling thread and worker thread.
std::unique_ptr<FieldTrialsView> const trials_;
// channel_manager is accessed both on signaling thread and worker thread.
std::unique_ptr<cricket::ChannelManager> channel_manager_;
std::unique_ptr<rtc::NetworkMonitorFactory> const network_monitor_factory_
RTC_GUARDED_BY(signaling_thread_);
std::unique_ptr<rtc::BasicNetworkManager> default_network_manager_
RTC_GUARDED_BY(signaling_thread_);
std::unique_ptr<webrtc::CallFactoryInterface> const call_factory_
RTC_GUARDED_BY(worker_thread());
std::unique_ptr<rtc::BasicPacketSocketFactory> default_socket_factory_
RTC_GUARDED_BY(signaling_thread_);
Reland "Remove thread hops from events provided by JsepTransportController." This reverts commit 6e4fcac31312f2dda5b60d33874ff0cd62f94321. Reason for revert: Parent CL issue has been resolved. Original change's description: > Revert "Remove thread hops from events provided by JsepTransportController." > > This reverts commit f554b3c577f69fa9ffad5c07155898c2d985ac76. > > Reason for revert: Parent CL breaks FYI bots. > See https://webrtc-review.googlesource.com/c/src/+/206466 > > Original change's description: > > Remove thread hops from events provided by JsepTransportController. > > > > Events associated with Subscribe* methods in JTC had trampolines that > > would use an async invoker to fire the events on the signaling thread. > > This was being done for the purposes of PeerConnection but the concept > > of a signaling thread is otherwise not applicable to JTC and use of > > JTC from PC is inconsistent across threads (as has been flagged in > > webrtc:9987). > > > > This change makes all CallbackList members only accessible from the > > network thread and moves the signaling thread related work over to > > PeerConnection, which makes hops there more visible as well as making > > that class easier to refactor for thread efficiency. > > > > This CL removes the AsyncInvoker from JTC (webrtc:12339) > > > > The signaling_thread_ variable is also removed from JTC and more thread > > checks added to catch errors. > > > > Bug: webrtc:12427, webrtc:11988, webrtc:12339 > > Change-Id: Id232aedd00dfd5403b2ba0ca147d3eca7c12c7c5 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/206062 > > Commit-Queue: Tommi <tommi@webrtc.org> > > Reviewed-by: Niels Moller <nisse@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#33195} > > TBR=nisse@webrtc.org,tommi@webrtc.org > > Change-Id: I6134b71b74a9408854b79d44506d513519e9cf4d > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:12427 > Bug: webrtc:11988 > Bug: webrtc:12339 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/206467 > Reviewed-by: Guido Urdaneta <guidou@webrtc.org> > Commit-Queue: Guido Urdaneta <guidou@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#33203} TBR=nisse@webrtc.org,tommi@webrtc.org,guidou@webrtc.org # Not skipping CQ checks because original CL landed > 1 day ago. Bug: webrtc:12427 Bug: webrtc:11988 Bug: webrtc:12339 Change-Id: I4e2e1490e1f9a87ed6ac4d722fd3c442e3059ae0 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/206809 Reviewed-by: Tommi <tommi@webrtc.org> Commit-Queue: Tommi <tommi@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33225}
2021-02-10 17:40:08 +00:00
std::unique_ptr<SctpTransportFactoryInterface> const sctp_factory_;
};
} // namespace webrtc
#endif // PC_CONNECTION_CONTEXT_H_