diff --git a/api/BUILD.gn b/api/BUILD.gn index 00542f3076..aee9787f3f 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -157,7 +157,9 @@ rtc_library("libjingle_peerconnection_api") { "stats_types.h", "turn_customizer.h", "uma_metrics.h", + "video_track_source_proxy.cc", "video_track_source_proxy.h", + "video_track_source_proxy_factory.h", ] deps = [ ":array_view", diff --git a/api/rtp_receiver_interface.h b/api/rtp_receiver_interface.h index d2645eda8c..327c9f2fee 100644 --- a/api/rtp_receiver_interface.h +++ b/api/rtp_receiver_interface.h @@ -22,7 +22,6 @@ #include "api/frame_transformer_interface.h" #include "api/media_stream_interface.h" #include "api/media_types.h" -#include "api/proxy.h" #include "api/rtp_parameters.h" #include "api/scoped_refptr.h" #include "api/transport/rtp/rtp_source.h" @@ -119,36 +118,6 @@ class RTC_EXPORT RtpReceiverInterface : public rtc::RefCountInterface { ~RtpReceiverInterface() override = default; }; -// Define proxy for RtpReceiverInterface. -// TODO(deadbeef): Move this to .cc file and out of api/. What threads methods -// are called on is an implementation detail. -BEGIN_PROXY_MAP(RtpReceiver) -PROXY_PRIMARY_THREAD_DESTRUCTOR() -BYPASS_PROXY_CONSTMETHOD0(rtc::scoped_refptr, track) -PROXY_CONSTMETHOD0(rtc::scoped_refptr, dtls_transport) -PROXY_CONSTMETHOD0(std::vector, stream_ids) -PROXY_CONSTMETHOD0(std::vector>, - streams) -BYPASS_PROXY_CONSTMETHOD0(cricket::MediaType, media_type) -BYPASS_PROXY_CONSTMETHOD0(std::string, id) -PROXY_SECONDARY_CONSTMETHOD0(RtpParameters, GetParameters) -PROXY_METHOD1(void, SetObserver, RtpReceiverObserverInterface*) -PROXY_SECONDARY_METHOD1(void, - SetJitterBufferMinimumDelay, - absl::optional) -PROXY_SECONDARY_CONSTMETHOD0(std::vector, GetSources) -// TODO(bugs.webrtc.org/12772): Remove. -PROXY_SECONDARY_METHOD1(void, - SetFrameDecryptor, - rtc::scoped_refptr) -// TODO(bugs.webrtc.org/12772): Remove. -PROXY_SECONDARY_CONSTMETHOD0(rtc::scoped_refptr, - GetFrameDecryptor) -PROXY_SECONDARY_METHOD1(void, - SetDepacketizerToDecoderFrameTransformer, - rtc::scoped_refptr) -END_PROXY_MAP() - } // namespace webrtc #endif // API_RTP_RECEIVER_INTERFACE_H_ diff --git a/api/rtp_sender_interface.h b/api/rtp_sender_interface.h index dd93792a07..9ffad68644 100644 --- a/api/rtp_sender_interface.h +++ b/api/rtp_sender_interface.h @@ -23,7 +23,6 @@ #include "api/frame_transformer_interface.h" #include "api/media_stream_interface.h" #include "api/media_types.h" -#include "api/proxy.h" #include "api/rtc_error.h" #include "api/rtp_parameters.h" #include "api/scoped_refptr.h" @@ -101,33 +100,6 @@ class RTC_EXPORT RtpSenderInterface : public rtc::RefCountInterface { ~RtpSenderInterface() override = default; }; -// Define proxy for RtpSenderInterface. -// TODO(deadbeef): Move this to .cc file and out of api/. What threads methods -// are called on is an implementation detail. -BEGIN_PRIMARY_PROXY_MAP(RtpSender) -PROXY_PRIMARY_THREAD_DESTRUCTOR() -PROXY_METHOD1(bool, SetTrack, MediaStreamTrackInterface*) -PROXY_CONSTMETHOD0(rtc::scoped_refptr, track) -PROXY_CONSTMETHOD0(rtc::scoped_refptr, dtls_transport) -PROXY_CONSTMETHOD0(uint32_t, ssrc) -BYPASS_PROXY_CONSTMETHOD0(cricket::MediaType, media_type) -BYPASS_PROXY_CONSTMETHOD0(std::string, id) -PROXY_CONSTMETHOD0(std::vector, stream_ids) -PROXY_CONSTMETHOD0(std::vector, init_send_encodings) -PROXY_CONSTMETHOD0(RtpParameters, GetParameters) -PROXY_METHOD1(RTCError, SetParameters, const RtpParameters&) -PROXY_CONSTMETHOD0(rtc::scoped_refptr, GetDtmfSender) -PROXY_METHOD1(void, - SetFrameEncryptor, - rtc::scoped_refptr) -PROXY_CONSTMETHOD0(rtc::scoped_refptr, - GetFrameEncryptor) -PROXY_METHOD1(void, SetStreams, const std::vector&) -PROXY_METHOD1(void, - SetEncoderToPacketizerFrameTransformer, - rtc::scoped_refptr) -END_PROXY_MAP() - } // namespace webrtc #endif // API_RTP_SENDER_INTERFACE_H_ diff --git a/api/video_track_source_proxy.cc b/api/video_track_source_proxy.cc new file mode 100644 index 0000000000..a24faf82a5 --- /dev/null +++ b/api/video_track_source_proxy.cc @@ -0,0 +1,25 @@ +/* + * Copyright 2021 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. + */ + +#include "api/video_track_source_proxy.h" + +#include "api/media_stream_interface.h" +#include "api/video_track_source_proxy_factory.h" + +namespace webrtc { + +rtc::scoped_refptr CreateVideoTrackSourceProxy( + rtc::Thread* signaling_thread, + rtc::Thread* worker_thread, + VideoTrackSourceInterface* source) { + return VideoTrackSourceProxy::Create(signaling_thread, worker_thread, source); +} + +} // namespace webrtc diff --git a/api/video_track_source_proxy_factory.h b/api/video_track_source_proxy_factory.h new file mode 100644 index 0000000000..974720d50b --- /dev/null +++ b/api/video_track_source_proxy_factory.h @@ -0,0 +1,28 @@ +/* + * Copyright 2021 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 API_VIDEO_TRACK_SOURCE_PROXY_FACTORY_H_ +#define API_VIDEO_TRACK_SOURCE_PROXY_FACTORY_H_ + +#include "api/media_stream_interface.h" + +namespace webrtc { + +// Creates a proxy source for |source| which makes sure the real +// VideoTrackSourceInterface implementation is destroyed on the signaling thread +// and marshals calls to |worker_thread| and |signaling_thread|. +rtc::scoped_refptr RTC_EXPORT +CreateVideoTrackSourceProxy(rtc::Thread* signaling_thread, + rtc::Thread* worker_thread, + VideoTrackSourceInterface* source); + +} // namespace webrtc + +#endif // API_VIDEO_TRACK_SOURCE_PROXY_FACTORY_H_ diff --git a/pc/BUILD.gn b/pc/BUILD.gn index 82f90df581..98c30be3e4 100644 --- a/pc/BUILD.gn +++ b/pc/BUILD.gn @@ -50,6 +50,8 @@ rtc_library("rtc_pc_base") { "rtcp_mux_filter.h", "rtp_media_utils.cc", "rtp_media_utils.h", + "rtp_receiver_proxy.h", + "rtp_sender_proxy.h", "rtp_transport.cc", "rtp_transport.h", "rtp_transport_internal.h", diff --git a/pc/rtp_receiver_proxy.h b/pc/rtp_receiver_proxy.h new file mode 100644 index 0000000000..5b9b443332 --- /dev/null +++ b/pc/rtp_receiver_proxy.h @@ -0,0 +1,54 @@ +/* + * Copyright 2021 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_RTP_RECEIVER_PROXY_H_ +#define PC_RTP_RECEIVER_PROXY_H_ + +#include +#include + +#include "api/proxy.h" +#include "api/rtp_receiver_interface.h" + +namespace webrtc { + +// Define proxy for RtpReceiverInterface. +// TODO(deadbeef): Move this to .cc file. What threads methods are called on is +// an implementation detail. +BEGIN_PROXY_MAP(RtpReceiver) +PROXY_PRIMARY_THREAD_DESTRUCTOR() +BYPASS_PROXY_CONSTMETHOD0(rtc::scoped_refptr, track) +PROXY_CONSTMETHOD0(rtc::scoped_refptr, dtls_transport) +PROXY_CONSTMETHOD0(std::vector, stream_ids) +PROXY_CONSTMETHOD0(std::vector>, + streams) +BYPASS_PROXY_CONSTMETHOD0(cricket::MediaType, media_type) +BYPASS_PROXY_CONSTMETHOD0(std::string, id) +PROXY_SECONDARY_CONSTMETHOD0(RtpParameters, GetParameters) +PROXY_METHOD1(void, SetObserver, RtpReceiverObserverInterface*) +PROXY_SECONDARY_METHOD1(void, + SetJitterBufferMinimumDelay, + absl::optional) +PROXY_SECONDARY_CONSTMETHOD0(std::vector, GetSources) +// TODO(bugs.webrtc.org/12772): Remove. +PROXY_SECONDARY_METHOD1(void, + SetFrameDecryptor, + rtc::scoped_refptr) +// TODO(bugs.webrtc.org/12772): Remove. +PROXY_SECONDARY_CONSTMETHOD0(rtc::scoped_refptr, + GetFrameDecryptor) +PROXY_SECONDARY_METHOD1(void, + SetDepacketizerToDecoderFrameTransformer, + rtc::scoped_refptr) +END_PROXY_MAP() + +} // namespace webrtc + +#endif // PC_RTP_RECEIVER_PROXY_H_ diff --git a/pc/rtp_sender_proxy.h b/pc/rtp_sender_proxy.h new file mode 100644 index 0000000000..1c5040eab3 --- /dev/null +++ b/pc/rtp_sender_proxy.h @@ -0,0 +1,51 @@ +/* + * Copyright 2021 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_RTP_SENDER_PROXY_H_ +#define PC_RTP_SENDER_PROXY_H_ + +#include +#include + +#include "api/proxy.h" +#include "api/rtp_sender_interface.h" + +namespace webrtc { + +// Define proxy for RtpSenderInterface. +// TODO(deadbeef): Move this to .cc file. What threads methods are called on is +// an implementation detail. +BEGIN_PRIMARY_PROXY_MAP(RtpSender) +PROXY_PRIMARY_THREAD_DESTRUCTOR() +PROXY_METHOD1(bool, SetTrack, MediaStreamTrackInterface*) +PROXY_CONSTMETHOD0(rtc::scoped_refptr, track) +PROXY_CONSTMETHOD0(rtc::scoped_refptr, dtls_transport) +PROXY_CONSTMETHOD0(uint32_t, ssrc) +BYPASS_PROXY_CONSTMETHOD0(cricket::MediaType, media_type) +BYPASS_PROXY_CONSTMETHOD0(std::string, id) +PROXY_CONSTMETHOD0(std::vector, stream_ids) +PROXY_CONSTMETHOD0(std::vector, init_send_encodings) +PROXY_CONSTMETHOD0(RtpParameters, GetParameters) +PROXY_METHOD1(RTCError, SetParameters, const RtpParameters&) +PROXY_CONSTMETHOD0(rtc::scoped_refptr, GetDtmfSender) +PROXY_METHOD1(void, + SetFrameEncryptor, + rtc::scoped_refptr) +PROXY_CONSTMETHOD0(rtc::scoped_refptr, + GetFrameEncryptor) +PROXY_METHOD1(void, SetStreams, const std::vector&) +PROXY_METHOD1(void, + SetEncoderToPacketizerFrameTransformer, + rtc::scoped_refptr) +END_PROXY_MAP() + +} // namespace webrtc + +#endif // PC_RTP_SENDER_PROXY_H_ diff --git a/pc/rtp_transceiver.h b/pc/rtp_transceiver.h index 35dea25a7b..66a0bea32e 100644 --- a/pc/rtp_transceiver.h +++ b/pc/rtp_transceiver.h @@ -24,8 +24,6 @@ #include "api/proxy.h" #include "api/rtc_error.h" #include "api/rtp_parameters.h" -#include "api/rtp_receiver_interface.h" -#include "api/rtp_sender_interface.h" #include "api/rtp_transceiver_direction.h" #include "api/rtp_transceiver_interface.h" #include "api/scoped_refptr.h" @@ -33,7 +31,9 @@ #include "pc/channel_interface.h" #include "pc/channel_manager.h" #include "pc/rtp_receiver.h" +#include "pc/rtp_receiver_proxy.h" #include "pc/rtp_sender.h" +#include "pc/rtp_sender_proxy.h" #include "rtc_base/ref_counted_object.h" #include "rtc_base/task_utils/pending_task_safety_flag.h" #include "rtc_base/third_party/sigslot/sigslot.h" diff --git a/pc/video_rtp_receiver.cc b/pc/video_rtp_receiver.cc index 34cfe96f28..99a200db31 100644 --- a/pc/video_rtp_receiver.cc +++ b/pc/video_rtp_receiver.cc @@ -16,7 +16,7 @@ #include #include "api/video/recordable_encoded_frame.h" -#include "api/video_track_source_proxy.h" +#include "api/video_track_source_proxy_factory.h" #include "pc/video_track.h" #include "rtc_base/checks.h" #include "rtc_base/location.h" @@ -41,12 +41,11 @@ VideoRtpReceiver::VideoRtpReceiver( track_(VideoTrackProxyWithInternal::Create( rtc::Thread::Current(), worker_thread, - VideoTrack::Create( - receiver_id, - VideoTrackSourceProxy::Create(rtc::Thread::Current(), - worker_thread, - source_), - worker_thread))), + VideoTrack::Create(receiver_id, + CreateVideoTrackSourceProxy(rtc::Thread::Current(), + worker_thread, + source_), + worker_thread))), attachment_id_(GenerateUniqueId()) { RTC_DCHECK(worker_thread_); SetStreams(streams);