Apply PIMPL pattern to MediaSender and Receiver objects
This detaches the implementation (which is still merged)
from the objects used to interface to it.
Bug: webrtc:13931
Change-Id: I872ee10e4ed9fa432bfa231f723af1d3989d79d4
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/288080
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38906}
diff --git a/media/BUILD.gn b/media/BUILD.gn
index b884b0d..07a5f2d 100644
--- a/media/BUILD.gn
+++ b/media/BUILD.gn
@@ -52,6 +52,7 @@
":rtc_media_config",
"../api:array_view",
"../api:audio_options_api",
+ "../api:call_api",
"../api:field_trials_view",
"../api:frame_transformer_interface",
"../api:media_stream_interface",
@@ -72,6 +73,7 @@
"../api/transport:stun_types",
"../api/transport/rtp:rtp_source",
"../api/units:time_delta",
+ "../api/video:recordable_encoded_frame",
"../api/video:video_bitrate_allocation",
"../api/video:video_bitrate_allocator_factory",
"../api/video:video_frame",
diff --git a/media/base/media_channel.h b/media/base/media_channel.h
index 77a5ba6..ee9a472 100644
--- a/media/base/media_channel.h
+++ b/media/base/media_channel.h
@@ -20,6 +20,7 @@
#include "absl/types/optional.h"
#include "api/audio_codecs/audio_encoder.h"
#include "api/audio_options.h"
+#include "api/call/audio_sink.h"
#include "api/crypto/frame_decryptor_interface.h"
#include "api/crypto/frame_encryptor_interface.h"
#include "api/frame_transformer_interface.h"
@@ -61,7 +62,6 @@
}
namespace webrtc {
-class AudioSinkInterface;
class VideoFrame;
webrtc::RTCError InvokeSetParametersCallback(SetParametersCallback& callback,
@@ -219,14 +219,9 @@
public:
virtual ~MediaSendChannelInterface() = default;
- virtual VideoMediaSendChannelInterface* AsVideoSendChannel() {
- RTC_CHECK_NOTREACHED();
- return nullptr;
- }
- virtual VoiceMediaSendChannelInterface* AsVoiceSendChannel() {
- RTC_CHECK_NOTREACHED();
- return nullptr;
- }
+ virtual VideoMediaSendChannelInterface* AsVideoSendChannel() = 0;
+
+ virtual VoiceMediaSendChannelInterface* AsVoiceSendChannel() = 0;
// Creates a new outgoing media stream with SSRCs and CNAME as described
// by sp.
diff --git a/media/base/media_channel_impl.cc b/media/base/media_channel_impl.cc
index 626de34..eeefea0 100644
--- a/media/base/media_channel_impl.cc
+++ b/media/base/media_channel_impl.cc
@@ -12,6 +12,7 @@
#include <map>
#include <string>
+#include <type_traits>
#include <utility>
#include "absl/functional/any_invocable.h"
@@ -21,6 +22,7 @@
#include "api/rtp_sender_interface.h"
#include "api/units/time_delta.h"
#include "api/video/video_timing.h"
+#include "api/video_codecs/scalability_mode.h"
#include "common_video/include/quality_limitation_reason.h"
#include "media/base/codec.h"
#include "media/base/media_channel.h"
diff --git a/media/base/media_channel_impl.h b/media/base/media_channel_impl.h
index 41bead7..45a250e 100644
--- a/media/base/media_channel_impl.h
+++ b/media/base/media_channel_impl.h
@@ -14,20 +14,42 @@
#include <stddef.h>
#include <stdint.h>
+#include <functional>
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
#include "absl/strings/string_view.h"
+#include "absl/types/optional.h"
+#include "api/audio_options.h"
+#include "api/call/audio_sink.h"
#include "api/call/transport.h"
#include "api/crypto/frame_decryptor_interface.h"
#include "api/crypto/frame_encryptor_interface.h"
#include "api/frame_transformer_interface.h"
#include "api/media_types.h"
+#include "api/rtc_error.h"
+#include "api/rtp_parameters.h"
+#include "api/rtp_sender_interface.h"
#include "api/scoped_refptr.h"
#include "api/sequence_checker.h"
#include "api/task_queue/pending_task_safety_flag.h"
#include "api/task_queue/task_queue_base.h"
+#include "api/transport/rtp/rtp_source.h"
+#include "api/video/recordable_encoded_frame.h"
+#include "api/video/video_frame.h"
+#include "api/video/video_sink_interface.h"
+#include "api/video/video_source_interface.h"
+#include "api/video_codecs/video_encoder_factory.h"
+#include "media/base/codec.h"
#include "media/base/media_channel.h"
+#include "media/base/stream_params.h"
#include "rtc_base/async_packet_socket.h"
+#include "rtc_base/checks.h"
#include "rtc_base/copy_on_write_buffer.h"
#include "rtc_base/dscp.h"
+#include "rtc_base/logging.h"
#include "rtc_base/network/sent_packet.h"
#include "rtc_base/network_route.h"
#include "rtc_base/socket.h"
@@ -38,6 +60,8 @@
// but this is in the process of being changed.
// TODO(bugs.webrtc.org/13931): Consider removing these classes.
+// The target
+
namespace cricket {
class VoiceMediaChannel;
@@ -175,6 +199,10 @@
// Downcasting to the implemented interfaces.
VideoMediaSendChannelInterface* AsVideoSendChannel() override { return this; }
+ VoiceMediaSendChannelInterface* AsVoiceSendChannel() override {
+ RTC_CHECK_NOTREACHED();
+ return nullptr;
+ }
VideoMediaReceiveChannelInterface* AsVideoReceiveChannel() override {
return this;
@@ -225,6 +253,11 @@
VoiceMediaChannel* AsVoiceChannel() override { return this; }
+ VideoMediaSendChannelInterface* AsVideoSendChannel() override {
+ RTC_CHECK_NOTREACHED();
+ return nullptr;
+ }
+
void SetExtmapAllowMixed(bool mixed) override {
MediaChannel::SetExtmapAllowMixed(mixed);
}
@@ -237,6 +270,374 @@
bool get_and_clear_legacy_stats) = 0;
};
+// The externally exposed objects that support the Send and Receive interfaces.
+// These dispatch their functions to the underlying MediaChannel objects.
+
+class VoiceMediaSendChannel : public VoiceMediaSendChannelInterface {
+ public:
+ explicit VoiceMediaSendChannel(VoiceMediaChannel* impl) : impl_(impl) {}
+ virtual ~VoiceMediaSendChannel() {}
+ VoiceMediaSendChannelInterface* AsVoiceSendChannel() override { return this; }
+ VideoMediaSendChannelInterface* AsVideoSendChannel() override {
+ RTC_CHECK_NOTREACHED();
+ return nullptr;
+ }
+
+ // Implementation of MediaBaseChannelInterface
+ cricket::MediaType media_type() const override { return MEDIA_TYPE_AUDIO; }
+ void OnPacketReceived(rtc::CopyOnWriteBuffer packet,
+ int64_t packet_time_us) override {
+ impl()->OnPacketReceived(packet, packet_time_us);
+ }
+ void OnPacketSent(const rtc::SentPacket& sent_packet) override {
+ impl()->OnPacketSent(sent_packet);
+ }
+ void OnReadyToSend(bool ready) override { impl()->OnReadyToSend(ready); }
+ void OnNetworkRouteChanged(absl::string_view transport_name,
+ const rtc::NetworkRoute& network_route) override {
+ impl()->OnNetworkRouteChanged(transport_name, network_route);
+ }
+ void SetExtmapAllowMixed(bool extmap_allow_mixed) override {
+ impl()->SetExtmapAllowMixed(extmap_allow_mixed);
+ }
+ bool ExtmapAllowMixed() const override { return impl()->ExtmapAllowMixed(); }
+ // Implementation of MediaSendChannelInterface
+ bool AddSendStream(const StreamParams& sp) override {
+ return impl()->AddSendStream(sp);
+ }
+ bool RemoveSendStream(uint32_t ssrc) override {
+ return impl()->RemoveSendStream(ssrc);
+ }
+ void SetFrameEncryptor(uint32_t ssrc,
+ rtc::scoped_refptr<webrtc::FrameEncryptorInterface>
+ frame_encryptor) override {
+ impl()->SetFrameEncryptor(ssrc, frame_encryptor);
+ }
+ webrtc::RTCError SetRtpSendParameters(
+ uint32_t ssrc,
+ const webrtc::RtpParameters& parameters,
+ webrtc::SetParametersCallback callback = nullptr) override {
+ return impl()->SetRtpSendParameters(ssrc, parameters, std::move(callback));
+ }
+
+ void SetEncoderToPacketizerFrameTransformer(
+ uint32_t ssrc,
+ rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer)
+ override {
+ return impl()->SetEncoderToPacketizerFrameTransformer(ssrc,
+ frame_transformer);
+ }
+ void SetEncoderSelector(uint32_t ssrc,
+ webrtc::VideoEncoderFactory::EncoderSelectorInterface*
+ encoder_selector) override {
+ impl()->SetEncoderSelector(ssrc, encoder_selector);
+ }
+ webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const override {
+ return impl()->GetRtpSendParameters(ssrc);
+ }
+ // Implementation of VoiceMediaSendChannel
+ bool SetSendParameters(const AudioSendParameters& params) override {
+ return impl()->SetSendParameters(params);
+ }
+ void SetSend(bool send) override { return impl()->SetSend(send); }
+ bool SetAudioSend(uint32_t ssrc,
+ bool enable,
+ const AudioOptions* options,
+ AudioSource* source) override {
+ return impl()->SetAudioSend(ssrc, enable, options, source);
+ }
+ bool CanInsertDtmf() override { return impl()->CanInsertDtmf(); }
+ bool InsertDtmf(uint32_t ssrc, int event, int duration) override {
+ return impl()->InsertDtmf(ssrc, event, duration);
+ }
+
+ private:
+ VoiceMediaSendChannelInterface* impl() { return impl_; }
+ const VoiceMediaSendChannelInterface* impl() const { return impl_; }
+ VoiceMediaChannel* impl_;
+};
+
+class VoiceMediaReceiveChannel : public VoiceMediaReceiveChannelInterface {
+ public:
+ explicit VoiceMediaReceiveChannel(VoiceMediaChannel* impl) : impl_(impl) {}
+ virtual ~VoiceMediaReceiveChannel() {}
+ // Implementation of MediaBaseChannelInterface
+ cricket::MediaType media_type() const override { return MEDIA_TYPE_AUDIO; }
+ void OnPacketReceived(rtc::CopyOnWriteBuffer packet,
+ int64_t packet_time_us) override {
+ impl()->OnPacketReceived(packet, packet_time_us);
+ }
+ void OnPacketSent(const rtc::SentPacket& sent_packet) override {
+ impl()->OnPacketSent(sent_packet);
+ }
+ void OnReadyToSend(bool ready) override { impl()->OnReadyToSend(ready); }
+ void OnNetworkRouteChanged(absl::string_view transport_name,
+ const rtc::NetworkRoute& network_route) override {
+ impl()->OnNetworkRouteChanged(transport_name, network_route);
+ }
+ void SetExtmapAllowMixed(bool extmap_allow_mixed) override {
+ impl()->SetExtmapAllowMixed(extmap_allow_mixed);
+ }
+ bool ExtmapAllowMixed() const override { return impl()->ExtmapAllowMixed(); }
+ // Implementation of Delayable
+ bool SetBaseMinimumPlayoutDelayMs(uint32_t ssrc, int delay_ms) override {
+ return impl()->SetBaseMinimumPlayoutDelayMs(ssrc, delay_ms);
+ }
+ absl::optional<int> GetBaseMinimumPlayoutDelayMs(
+ uint32_t ssrc) const override {
+ return impl()->GetBaseMinimumPlayoutDelayMs(ssrc);
+ }
+ // Implementation of MediaReceiveChannelInterface
+ bool AddRecvStream(const StreamParams& sp) override {
+ return impl()->AddRecvStream(sp);
+ }
+ bool RemoveRecvStream(uint32_t ssrc) override {
+ return impl()->RemoveRecvStream(ssrc);
+ }
+ void ResetUnsignaledRecvStream() override {
+ return impl()->ResetUnsignaledRecvStream();
+ }
+ void OnDemuxerCriteriaUpdatePending() override {
+ impl()->OnDemuxerCriteriaUpdatePending();
+ }
+ void OnDemuxerCriteriaUpdateComplete() override {
+ impl()->OnDemuxerCriteriaUpdateComplete();
+ }
+ void SetFrameDecryptor(uint32_t ssrc,
+ rtc::scoped_refptr<webrtc::FrameDecryptorInterface>
+ frame_decryptor) override {
+ impl()->SetFrameDecryptor(ssrc, frame_decryptor);
+ }
+ void SetDepacketizerToDecoderFrameTransformer(
+ uint32_t ssrc,
+ rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer)
+ override {
+ impl()->SetDepacketizerToDecoderFrameTransformer(ssrc, frame_transformer);
+ }
+ // Implementation of VoiceMediaReceiveChannelInterface
+ bool SetRecvParameters(const AudioRecvParameters& params) override {
+ return impl()->SetRecvParameters(params);
+ }
+ webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const override {
+ return impl()->GetRtpReceiveParameters(ssrc);
+ }
+ std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const override {
+ return impl()->GetSources(ssrc);
+ }
+ webrtc::RtpParameters GetDefaultRtpReceiveParameters() const override {
+ return impl()->GetDefaultRtpReceiveParameters();
+ }
+ void SetPlayout(bool playout) override { return impl()->SetPlayout(playout); }
+ bool SetOutputVolume(uint32_t ssrc, double volume) override {
+ return impl()->SetOutputVolume(ssrc, volume);
+ }
+ bool SetDefaultOutputVolume(double volume) override {
+ return impl()->SetDefaultOutputVolume(volume);
+ }
+ void SetRawAudioSink(
+ uint32_t ssrc,
+ std::unique_ptr<webrtc::AudioSinkInterface> sink) override {
+ return impl()->SetRawAudioSink(ssrc, std::move(sink));
+ }
+ void SetDefaultRawAudioSink(
+ std::unique_ptr<webrtc::AudioSinkInterface> sink) override {
+ return impl()->SetDefaultRawAudioSink(std::move(sink));
+ }
+
+ private:
+ VoiceMediaReceiveChannelInterface* impl() { return impl_; }
+ const VoiceMediaReceiveChannelInterface* impl() const { return impl_; }
+ VoiceMediaChannel* impl_;
+};
+
+class VideoMediaSendChannel : public VideoMediaSendChannelInterface {
+ public:
+ explicit VideoMediaSendChannel(VideoMediaChannel* impl) : impl_(impl) {}
+
+ VideoMediaSendChannelInterface* AsVideoSendChannel() override { return this; }
+ VoiceMediaSendChannelInterface* AsVoiceSendChannel() override {
+ RTC_CHECK_NOTREACHED();
+ return nullptr;
+ }
+
+ // Implementation of MediaBaseChannelInterface
+ cricket::MediaType media_type() const override { return MEDIA_TYPE_AUDIO; }
+ void OnPacketReceived(rtc::CopyOnWriteBuffer packet,
+ int64_t packet_time_us) override {
+ impl()->OnPacketReceived(packet, packet_time_us);
+ }
+ void OnPacketSent(const rtc::SentPacket& sent_packet) override {
+ impl()->OnPacketSent(sent_packet);
+ }
+ void OnReadyToSend(bool ready) override { impl()->OnReadyToSend(ready); }
+ void OnNetworkRouteChanged(absl::string_view transport_name,
+ const rtc::NetworkRoute& network_route) override {
+ impl()->OnNetworkRouteChanged(transport_name, network_route);
+ }
+ void SetExtmapAllowMixed(bool extmap_allow_mixed) override {
+ impl()->SetExtmapAllowMixed(extmap_allow_mixed);
+ }
+ bool ExtmapAllowMixed() const override { return impl()->ExtmapAllowMixed(); }
+ // Implementation of MediaSendChannelInterface
+ bool AddSendStream(const StreamParams& sp) override {
+ return impl()->AddSendStream(sp);
+ }
+ bool RemoveSendStream(uint32_t ssrc) override {
+ return impl()->RemoveSendStream(ssrc);
+ }
+ void SetFrameEncryptor(uint32_t ssrc,
+ rtc::scoped_refptr<webrtc::FrameEncryptorInterface>
+ frame_encryptor) override {
+ impl()->SetFrameEncryptor(ssrc, frame_encryptor);
+ }
+ webrtc::RTCError SetRtpSendParameters(
+ uint32_t ssrc,
+ const webrtc::RtpParameters& parameters,
+ webrtc::SetParametersCallback callback = nullptr) override {
+ return impl()->SetRtpSendParameters(ssrc, parameters, std::move(callback));
+ }
+
+ void SetEncoderToPacketizerFrameTransformer(
+ uint32_t ssrc,
+ rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer)
+ override {
+ return impl()->SetEncoderToPacketizerFrameTransformer(ssrc,
+ frame_transformer);
+ }
+ void SetEncoderSelector(uint32_t ssrc,
+ webrtc::VideoEncoderFactory::EncoderSelectorInterface*
+ encoder_selector) override {
+ impl()->SetEncoderSelector(ssrc, encoder_selector);
+ }
+ webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const override {
+ return impl()->GetRtpSendParameters(ssrc);
+ }
+ // Implementation of VideoMediaSendChannelInterface
+ bool SetSendParameters(const VideoSendParameters& params) override {
+ return impl()->SetSendParameters(params);
+ }
+ bool GetSendCodec(VideoCodec* send_codec) override {
+ return impl()->GetSendCodec(send_codec);
+ }
+ bool SetSend(bool send) override { return impl()->SetSend(send); }
+ bool SetVideoSend(
+ uint32_t ssrc,
+ const VideoOptions* options,
+ rtc::VideoSourceInterface<webrtc::VideoFrame>* source) override {
+ return impl()->SetVideoSend(ssrc, options, source);
+ }
+ void GenerateSendKeyFrame(uint32_t ssrc,
+ const std::vector<std::string>& rids) override {
+ return impl()->GenerateSendKeyFrame(ssrc, rids);
+ }
+ void SetVideoCodecSwitchingEnabled(bool enabled) override {
+ return impl()->SetVideoCodecSwitchingEnabled(enabled);
+ }
+
+ private:
+ VideoMediaSendChannelInterface* impl() { return impl_; }
+ const VideoMediaSendChannelInterface* impl() const { return impl_; }
+ VideoMediaChannel* const impl_;
+};
+
+class VideoMediaReceiveChannel : public VideoMediaReceiveChannelInterface {
+ public:
+ explicit VideoMediaReceiveChannel(VideoMediaChannel* impl) : impl_(impl) {}
+ // Implementation of MediaBaseChannelInterface
+ cricket::MediaType media_type() const override { return MEDIA_TYPE_AUDIO; }
+ void OnPacketReceived(rtc::CopyOnWriteBuffer packet,
+ int64_t packet_time_us) override {
+ impl()->OnPacketReceived(packet, packet_time_us);
+ }
+ void OnPacketSent(const rtc::SentPacket& sent_packet) override {
+ impl()->OnPacketSent(sent_packet);
+ }
+ void OnReadyToSend(bool ready) override { impl()->OnReadyToSend(ready); }
+ void OnNetworkRouteChanged(absl::string_view transport_name,
+ const rtc::NetworkRoute& network_route) override {
+ impl()->OnNetworkRouteChanged(transport_name, network_route);
+ }
+ void SetExtmapAllowMixed(bool extmap_allow_mixed) override {
+ impl()->SetExtmapAllowMixed(extmap_allow_mixed);
+ }
+ bool ExtmapAllowMixed() const override { return impl()->ExtmapAllowMixed(); }
+ // Implementation of Delayable
+ bool SetBaseMinimumPlayoutDelayMs(uint32_t ssrc, int delay_ms) override {
+ return impl()->SetBaseMinimumPlayoutDelayMs(ssrc, delay_ms);
+ }
+ absl::optional<int> GetBaseMinimumPlayoutDelayMs(
+ uint32_t ssrc) const override {
+ return impl()->GetBaseMinimumPlayoutDelayMs(ssrc);
+ }
+ // Implementation of MediaReceiveChannelInterface
+ bool AddRecvStream(const StreamParams& sp) override {
+ return impl()->AddRecvStream(sp);
+ }
+ bool RemoveRecvStream(uint32_t ssrc) override {
+ return impl()->RemoveRecvStream(ssrc);
+ }
+ void ResetUnsignaledRecvStream() override {
+ return impl()->ResetUnsignaledRecvStream();
+ }
+ void OnDemuxerCriteriaUpdatePending() override {
+ impl()->OnDemuxerCriteriaUpdatePending();
+ }
+ void OnDemuxerCriteriaUpdateComplete() override {
+ impl()->OnDemuxerCriteriaUpdateComplete();
+ }
+ void SetFrameDecryptor(uint32_t ssrc,
+ rtc::scoped_refptr<webrtc::FrameDecryptorInterface>
+ frame_decryptor) override {
+ impl()->SetFrameDecryptor(ssrc, frame_decryptor);
+ }
+ void SetDepacketizerToDecoderFrameTransformer(
+ uint32_t ssrc,
+ rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer)
+ override {
+ impl()->SetDepacketizerToDecoderFrameTransformer(ssrc, frame_transformer);
+ }
+ // Implementation on videoMediaReceiveChannelInterface
+ bool SetRecvParameters(const VideoRecvParameters& params) override {
+ return impl()->SetRecvParameters(params);
+ }
+ webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const override {
+ return impl()->GetRtpReceiveParameters(ssrc);
+ }
+ webrtc::RtpParameters GetDefaultRtpReceiveParameters() const override {
+ return impl()->GetDefaultRtpReceiveParameters();
+ }
+ bool SetSink(uint32_t ssrc,
+ rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override {
+ return impl()->SetSink(ssrc, sink);
+ }
+ void SetDefaultSink(
+ rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override {
+ return impl()->SetDefaultSink(sink);
+ }
+ void RequestRecvKeyFrame(uint32_t ssrc) override {
+ return impl()->RequestRecvKeyFrame(ssrc);
+ }
+ std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const override {
+ return impl()->GetSources(ssrc);
+ }
+ // Set recordable encoded frame callback for `ssrc`
+ void SetRecordableEncodedFrameCallback(
+ uint32_t ssrc,
+ std::function<void(const webrtc::RecordableEncodedFrame&)> callback)
+ override {
+ return impl()->SetRecordableEncodedFrameCallback(ssrc, std::move(callback));
+ }
+ // Clear recordable encoded frame callback for `ssrc`
+ void ClearRecordableEncodedFrameCallback(uint32_t ssrc) override {
+ impl()->ClearRecordableEncodedFrameCallback(ssrc);
+ }
+
+ private:
+ VideoMediaReceiveChannelInterface* impl() { return impl_; }
+ const VideoMediaReceiveChannelInterface* impl() const { return impl_; }
+ VideoMediaChannel* const impl_;
+};
+
} // namespace cricket
#endif // MEDIA_BASE_MEDIA_CHANNEL_IMPL_H_
diff --git a/pc/channel.cc b/pc/channel.cc
index 4c078de..09ed037 100644
--- a/pc/channel.cc
+++ b/pc/channel.cc
@@ -826,7 +826,9 @@
mid,
srtp_required,
crypto_options,
- ssrc_generator) {}
+ ssrc_generator),
+ send_channel_(this->media_channel()->AsVoiceChannel()),
+ receive_channel_(this->media_channel()->AsVoiceChannel()) {}
VoiceChannel::~VoiceChannel() {
TRACE_EVENT0("webrtc", "VoiceChannel::~VoiceChannel");
@@ -950,7 +952,9 @@
mid,
srtp_required,
crypto_options,
- ssrc_generator) {}
+ ssrc_generator),
+ send_channel_(this->media_channel()->AsVideoChannel()),
+ receive_channel_(this->media_channel()->AsVideoChannel()) {}
VideoChannel::~VideoChannel() {
TRACE_EVENT0("webrtc", "VideoChannel::~VideoChannel");
diff --git a/pc/channel.h b/pc/channel.h
index 08a6679..f25866d 100644
--- a/pc/channel.h
+++ b/pc/channel.h
@@ -156,29 +156,21 @@
// RtpPacketSinkInterface overrides.
void OnRtpPacket(const webrtc::RtpPacketReceived& packet) override;
- MediaChannel* media_channel() const override { return media_channel_.get(); }
+ MediaChannel* media_channel() override { return media_channel_.get(); }
- MediaSendChannelInterface* media_send_channel() const override {
- return media_channel_->AsSendChannel();
- }
- VideoMediaSendChannelInterface* video_media_send_channel() const override {
+ VideoMediaSendChannelInterface* video_media_send_channel() override {
RTC_CHECK(false) << "Attempt to fetch video channel from non-video";
return nullptr;
}
- VoiceMediaSendChannelInterface* voice_media_send_channel() const override {
+ VoiceMediaSendChannelInterface* voice_media_send_channel() override {
RTC_CHECK(false) << "Attempt to fetch voice channel from non-voice";
return nullptr;
}
- MediaReceiveChannelInterface* media_receive_channel() const override {
- return media_channel_->AsReceiveChannel();
- }
- VideoMediaReceiveChannelInterface* video_media_receive_channel()
- const override {
+ VideoMediaReceiveChannelInterface* video_media_receive_channel() override {
RTC_CHECK(false) << "Attempt to fetch video channel from non-video";
return nullptr;
}
- VoiceMediaReceiveChannelInterface* voice_media_receive_channel()
- const override {
+ VoiceMediaReceiveChannelInterface* voice_media_receive_channel() override {
RTC_CHECK(false) << "Attempt to fetch voice channel from non-voice";
return nullptr;
}
@@ -383,23 +375,20 @@
rtc::UniqueRandomIdGenerator* ssrc_generator);
~VoiceChannel();
- // downcasts a MediaChannel
- VoiceMediaSendChannelInterface* media_send_channel() const override {
- return media_channel()->AsVoiceChannel()->AsVoiceSendChannel();
+ VoiceMediaSendChannelInterface* media_send_channel() override {
+ return &send_channel_;
}
- VoiceMediaSendChannelInterface* voice_media_send_channel() const override {
- return media_send_channel();
+ VoiceMediaSendChannelInterface* voice_media_send_channel() override {
+ return &send_channel_;
}
- // downcasts a MediaChannel
- VoiceMediaReceiveChannelInterface* media_receive_channel() const override {
- return media_channel()->AsVoiceChannel()->AsVoiceReceiveChannel();
+ VoiceMediaReceiveChannelInterface* media_receive_channel() override {
+ return &receive_channel_;
}
- VoiceMediaReceiveChannelInterface* voice_media_receive_channel()
- const override {
- return media_receive_channel();
+ VoiceMediaReceiveChannelInterface* voice_media_receive_channel() override {
+ return &receive_channel_;
}
cricket::MediaType media_type() const override {
@@ -418,6 +407,8 @@
std::string& error_desc)
RTC_RUN_ON(worker_thread()) override;
+ VoiceMediaSendChannel send_channel_ RTC_GUARDED_BY(worker_thread());
+ VoiceMediaReceiveChannel receive_channel_ RTC_GUARDED_BY(worker_thread());
// Last AudioSendParameters sent down to the media_channel() via
// SetSendParameters.
AudioSendParameters last_send_params_ RTC_GUARDED_BY(worker_thread());
@@ -440,21 +431,20 @@
~VideoChannel();
// downcasts a MediaChannel
- VideoMediaSendChannelInterface* media_send_channel() const override {
+ VideoMediaSendChannelInterface* media_send_channel() override {
return media_channel()->AsVideoChannel()->AsVideoSendChannel();
}
- VideoMediaSendChannelInterface* video_media_send_channel() const override {
+ VideoMediaSendChannelInterface* video_media_send_channel() override {
return media_send_channel();
}
// downcasts a MediaChannel
- VideoMediaReceiveChannelInterface* media_receive_channel() const override {
+ VideoMediaReceiveChannelInterface* media_receive_channel() override {
return media_channel()->AsVideoChannel()->AsVideoReceiveChannel();
}
- VideoMediaReceiveChannelInterface* video_media_receive_channel()
- const override {
+ VideoMediaReceiveChannelInterface* video_media_receive_channel() override {
return media_receive_channel();
}
@@ -474,6 +464,8 @@
std::string& error_desc)
RTC_RUN_ON(worker_thread()) override;
+ VideoMediaSendChannel send_channel_ RTC_GUARDED_BY(worker_thread());
+ VideoMediaReceiveChannel receive_channel_ RTC_GUARDED_BY(worker_thread());
// Last VideoSendParameters sent down to the media_channel() via
// SetSendParameters.
VideoSendParameters last_send_params_ RTC_GUARDED_BY(worker_thread());
diff --git a/pc/channel_interface.h b/pc/channel_interface.h
index 445712b..c647483 100644
--- a/pc/channel_interface.h
+++ b/pc/channel_interface.h
@@ -49,19 +49,17 @@
virtual cricket::MediaType media_type() const = 0;
// Temporary fix while MediaChannel is being reconstructed
- virtual MediaChannel* media_channel() const = 0;
- virtual MediaSendChannelInterface* media_send_channel() const = 0;
+ virtual MediaChannel* media_channel() = 0;
+ virtual MediaSendChannelInterface* media_send_channel() = 0;
// Typecasts of media_channel(). Will cause an exception if the
// channel is of the wrong type.
- virtual VideoMediaSendChannelInterface* video_media_send_channel() const = 0;
- virtual VoiceMediaSendChannelInterface* voice_media_send_channel() const = 0;
- virtual MediaReceiveChannelInterface* media_receive_channel() const = 0;
+ virtual VideoMediaSendChannelInterface* video_media_send_channel() = 0;
+ virtual VoiceMediaSendChannelInterface* voice_media_send_channel() = 0;
+ virtual MediaReceiveChannelInterface* media_receive_channel() = 0;
// Typecasts of media_channel(). Will cause an exception if the
// channel is of the wrong type.
- virtual VideoMediaReceiveChannelInterface* video_media_receive_channel()
- const = 0;
- virtual VoiceMediaReceiveChannelInterface* voice_media_receive_channel()
- const = 0;
+ virtual VideoMediaReceiveChannelInterface* video_media_receive_channel() = 0;
+ virtual VoiceMediaReceiveChannelInterface* voice_media_receive_channel() = 0;
// Returns a string view for the transport name. Fetching the transport name
// must be done on the network thread only and note that the lifetime of
diff --git a/pc/channel_unittest.cc b/pc/channel_unittest.cc
index 583c292..27ad96a 100644
--- a/pc/channel_unittest.cc
+++ b/pc/channel_unittest.cc
@@ -74,6 +74,8 @@
template <class ChannelT,
class MediaChannelT,
+ class MediaSendChannelT,
+ class MediaReceiveChannelT,
class ContentT,
class CodecT,
class MediaInfoT,
@@ -82,6 +84,8 @@
public:
typedef ChannelT Channel;
typedef MediaChannelT MediaChannel;
+ typedef MediaSendChannelT MediaSendChannel;
+ typedef MediaReceiveChannelT MediaReceiveChannel;
typedef ContentT Content;
typedef CodecT Codec;
typedef MediaInfoT MediaInfo;
@@ -90,6 +94,8 @@
class VoiceTraits : public Traits<cricket::VoiceChannel,
cricket::FakeVoiceMediaChannel,
+ cricket::VoiceMediaSendChannelInterface,
+ cricket::VoiceMediaReceiveChannelInterface,
cricket::AudioContentDescription,
cricket::AudioCodec,
cricket::VoiceMediaInfo,
@@ -97,6 +103,8 @@
class VideoTraits : public Traits<cricket::VideoChannel,
cricket::FakeVideoMediaChannel,
+ cricket::VideoMediaSendChannelInterface,
+ cricket::VideoMediaReceiveChannelInterface,
cricket::VideoContentDescription,
cricket::VideoCodec,
cricket::VideoMediaInfo,
@@ -429,7 +437,7 @@
}
void SendRtp1(rtc::Buffer data) {
- SendRtp(media_send_channel1(), std::move(data));
+ SendRtp(media_channel1(), std::move(data));
}
void SendRtp2() {
@@ -449,8 +457,7 @@
}
bool CheckRtp1() {
- return media_send_channel1()->CheckRtp(rtp_packet_.data(),
- rtp_packet_.size());
+ return media_channel1()->CheckRtp(rtp_packet_.data(), rtp_packet_.size());
}
bool CheckRtp2() {
return media_channel2()->CheckRtp(rtp_packet_.data(), rtp_packet_.size());
@@ -458,7 +465,7 @@
// Methods to check custom data.
bool CheckCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
- return media_send_channel1()->CheckRtp(data.data(), data.size());
+ return media_channel1()->CheckRtp(data.data(), data.size());
}
bool CheckCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
@@ -475,7 +482,7 @@
return data;
}
- bool CheckNoRtp1() { return media_send_channel1()->CheckNoRtp(); }
+ bool CheckNoRtp1() { return media_channel1()->CheckNoRtp(); }
bool CheckNoRtp2() { return media_channel2()->CheckNoRtp(); }
void CreateContent(int flags,
@@ -558,13 +565,18 @@
void TestInit() {
CreateChannels(0, 0);
EXPECT_FALSE(IsSrtpActive(channel1_));
- EXPECT_FALSE(media_send_channel1()->sending());
+ EXPECT_FALSE(media_channel1()->sending());
if (verify_playout_) {
- EXPECT_FALSE(media_send_channel1()->playout());
+ EXPECT_FALSE(media_channel1()->playout());
}
- EXPECT_TRUE(media_send_channel1()->codecs().empty());
- EXPECT_TRUE(media_send_channel1()->recv_streams().empty());
- EXPECT_TRUE(media_send_channel1()->rtp_packets().empty());
+ EXPECT_TRUE(media_channel1()->codecs().empty());
+ EXPECT_TRUE(media_channel1()->recv_streams().empty());
+ EXPECT_TRUE(media_channel1()->rtp_packets().empty());
+ // Basic sanity test for send and receive channel objects
+ EXPECT_EQ(channel1_->media_send_channel()->media_type(),
+ media_channel1()->media_type());
+ EXPECT_EQ(channel1_->media_receive_channel()->media_type(),
+ media_channel1()->media_type());
}
// Test that SetLocalContent and SetRemoteContent properly configure
@@ -575,11 +587,11 @@
CreateContent(0, kPcmuCodec, kH264Codec, &content);
std::string err;
EXPECT_TRUE(channel1_->SetLocalContent(&content, SdpType::kOffer, err));
- EXPECT_EQ(0U, media_send_channel1()->codecs().size());
+ EXPECT_EQ(0U, media_channel1()->codecs().size());
EXPECT_TRUE(channel1_->SetRemoteContent(&content, SdpType::kAnswer, err));
- ASSERT_EQ(1U, media_send_channel1()->codecs().size());
+ ASSERT_EQ(1U, media_channel1()->codecs().size());
EXPECT_TRUE(
- CodecMatches(content.codecs()[0], media_send_channel1()->codecs()[0]));
+ CodecMatches(content.codecs()[0], media_channel1()->codecs()[0]));
}
// Test that SetLocalContent and SetRemoteContent properly configure
@@ -623,11 +635,11 @@
std::string err;
EXPECT_TRUE(channel1_->SetLocalContent(&content, SdpType::kOffer, err));
CreateContent(0, kPcmuCodec, kH264Codec, &content);
- EXPECT_EQ(0U, media_send_channel1()->codecs().size());
+ EXPECT_EQ(0U, media_channel1()->codecs().size());
EXPECT_TRUE(channel1_->SetRemoteContent(&content, SdpType::kAnswer, err));
- ASSERT_EQ(1U, media_send_channel1()->codecs().size());
+ ASSERT_EQ(1U, media_channel1()->codecs().size());
EXPECT_TRUE(
- CodecMatches(content.codecs()[0], media_send_channel1()->codecs()[0]));
+ CodecMatches(content.codecs()[0], media_channel1()->codecs()[0]));
}
// Test that SetLocalContent and SetRemoteContent properly set RTCP
@@ -669,7 +681,7 @@
std::string err;
EXPECT_TRUE(channel1_->SetLocalContent(&content1, SdpType::kOffer, err));
channel1_->Enable(true);
- EXPECT_EQ(1u, media_send_channel1()->send_streams().size());
+ EXPECT_EQ(1u, media_channel1()->send_streams().size());
EXPECT_TRUE(channel2_->SetRemoteContent(&content1, SdpType::kOffer, err));
EXPECT_EQ(1u, media_channel2()->recv_streams().size());
@@ -679,7 +691,7 @@
typename T::Content content2;
CreateContent(0, kPcmuCodec, kH264Codec, &content2);
EXPECT_TRUE(channel1_->SetRemoteContent(&content2, SdpType::kAnswer, err));
- EXPECT_EQ(0u, media_send_channel1()->recv_streams().size());
+ EXPECT_EQ(0u, media_channel1()->recv_streams().size());
EXPECT_TRUE(channel2_->SetLocalContent(&content2, SdpType::kAnswer, err));
channel2_->Enable(true);
EXPECT_EQ(0u, media_channel2()->send_streams().size());
@@ -697,14 +709,14 @@
EXPECT_EQ(stream2, media_channel2()->send_streams()[0]);
EXPECT_TRUE(channel1_->SetRemoteContent(&content3, SdpType::kOffer, err));
- ASSERT_EQ(1u, media_send_channel1()->recv_streams().size());
- EXPECT_EQ(stream2, media_send_channel1()->recv_streams()[0]);
+ ASSERT_EQ(1u, media_channel1()->recv_streams().size());
+ EXPECT_EQ(stream2, media_channel1()->recv_streams()[0]);
// Channel 1 replies but stop sending stream1.
typename T::Content content4;
CreateContent(0, kPcmuCodec, kH264Codec, &content4);
EXPECT_TRUE(channel1_->SetLocalContent(&content4, SdpType::kAnswer, err));
- EXPECT_EQ(0u, media_send_channel1()->send_streams().size());
+ EXPECT_EQ(0u, media_channel1()->send_streams().size());
EXPECT_TRUE(channel2_->SetRemoteContent(&content4, SdpType::kAnswer, err));
EXPECT_EQ(0u, media_channel2()->recv_streams().size());
@@ -718,9 +730,9 @@
void TestPlayoutAndSendingStates() {
CreateChannels(0, 0);
if (verify_playout_) {
- EXPECT_FALSE(media_send_channel1()->playout());
+ EXPECT_FALSE(media_channel1()->playout());
}
- EXPECT_FALSE(media_send_channel1()->sending());
+ EXPECT_FALSE(media_channel1()->sending());
if (verify_playout_) {
EXPECT_FALSE(media_channel2()->playout());
}
@@ -728,16 +740,16 @@
channel1_->Enable(true);
FlushCurrentThread();
if (verify_playout_) {
- EXPECT_FALSE(media_send_channel1()->playout());
+ EXPECT_FALSE(media_channel1()->playout());
}
- EXPECT_FALSE(media_send_channel1()->sending());
+ EXPECT_FALSE(media_channel1()->sending());
std::string err;
EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
SdpType::kOffer, err));
if (verify_playout_) {
- EXPECT_TRUE(media_send_channel1()->playout());
+ EXPECT_TRUE(media_channel1()->playout());
}
- EXPECT_FALSE(media_send_channel1()->sending());
+ EXPECT_FALSE(media_channel1()->sending());
EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
SdpType::kOffer, err));
if (verify_playout_) {
@@ -752,9 +764,9 @@
EXPECT_FALSE(media_channel2()->sending());
ConnectFakeTransports();
if (verify_playout_) {
- EXPECT_TRUE(media_send_channel1()->playout());
+ EXPECT_TRUE(media_channel1()->playout());
}
- EXPECT_FALSE(media_send_channel1()->sending());
+ EXPECT_FALSE(media_channel1()->sending());
if (verify_playout_) {
EXPECT_FALSE(media_channel2()->playout());
}
@@ -768,9 +780,9 @@
EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
SdpType::kAnswer, err));
if (verify_playout_) {
- EXPECT_TRUE(media_send_channel1()->playout());
+ EXPECT_TRUE(media_channel1()->playout());
}
- EXPECT_TRUE(media_send_channel1()->sending());
+ EXPECT_TRUE(media_channel1()->sending());
}
// Test that changing the MediaContentDirection in the local and remote
@@ -788,9 +800,9 @@
channel2_->Enable(true);
FlushCurrentThread();
if (verify_playout_) {
- EXPECT_FALSE(media_send_channel1()->playout());
+ EXPECT_FALSE(media_channel1()->playout());
}
- EXPECT_FALSE(media_send_channel1()->sending());
+ EXPECT_FALSE(media_channel1()->sending());
if (verify_playout_) {
EXPECT_FALSE(media_channel2()->playout());
}
@@ -805,9 +817,9 @@
ConnectFakeTransports();
if (verify_playout_) {
- EXPECT_TRUE(media_send_channel1()->playout());
+ EXPECT_TRUE(media_channel1()->playout());
}
- EXPECT_FALSE(media_send_channel1()->sending()); // remote InActive
+ EXPECT_FALSE(media_channel1()->sending()); // remote InActive
if (verify_playout_) {
EXPECT_FALSE(media_channel2()->playout()); // local InActive
}
@@ -820,9 +832,9 @@
channel1_->SetRemoteContent(&content2, SdpType::kPrAnswer, err));
if (verify_playout_) {
- EXPECT_TRUE(media_send_channel1()->playout());
+ EXPECT_TRUE(media_channel1()->playout());
}
- EXPECT_TRUE(media_send_channel1()->sending());
+ EXPECT_TRUE(media_channel1()->sending());
if (verify_playout_) {
EXPECT_TRUE(media_channel2()->playout()); // local RecvOnly
}
@@ -834,9 +846,9 @@
EXPECT_TRUE(channel1_->SetRemoteContent(&content2, SdpType::kAnswer, err));
if (verify_playout_) {
- EXPECT_TRUE(media_send_channel1()->playout());
+ EXPECT_TRUE(media_channel1()->playout());
}
- EXPECT_TRUE(media_send_channel1()->sending());
+ EXPECT_TRUE(media_channel1()->sending());
if (verify_playout_) {
EXPECT_TRUE(media_channel2()->playout());
}
@@ -856,15 +868,14 @@
CreateChannels(DTLS, DTLS);
SendInitiate();
- typename T::MediaChannel* media_send_channel1 =
- static_cast<typename T::MediaChannel*>(channel1_->media_send_channel());
- ASSERT_TRUE(media_send_channel1);
+ typename T::MediaChannel* media_channel1 = this->media_channel1();
+ ASSERT_TRUE(media_channel1);
// Need to wait for the threads before calling
// `set_num_network_route_changes` because the network route would be set
// when creating the channel.
WaitForThreads();
- media_send_channel1->set_num_network_route_changes(0);
+ media_channel1->set_num_network_route_changes(0);
SendTask(network_thread_, [this] {
rtc::NetworkRoute network_route;
// The transport channel becomes disconnected.
@@ -872,9 +883,9 @@
absl::optional<rtc::NetworkRoute>(network_route));
});
WaitForThreads();
- EXPECT_EQ(1, media_send_channel1->num_network_route_changes());
- EXPECT_FALSE(media_send_channel1->last_network_route().connected);
- media_send_channel1->set_num_network_route_changes(0);
+ EXPECT_EQ(1, media_channel1->num_network_route_changes());
+ EXPECT_FALSE(media_channel1->last_network_route().connected);
+ media_channel1->set_num_network_route_changes(0);
SendTask(network_thread_, [this] {
rtc::NetworkRoute network_route;
@@ -891,16 +902,16 @@
absl::optional<rtc::NetworkRoute>(network_route));
});
WaitForThreads();
- EXPECT_EQ(1, media_send_channel1->num_network_route_changes());
- EXPECT_TRUE(media_send_channel1->last_network_route().connected);
+ EXPECT_EQ(1, media_channel1->num_network_route_changes());
+ EXPECT_TRUE(media_channel1->last_network_route().connected);
EXPECT_EQ(kLocalNetId,
- media_send_channel1->last_network_route().local.network_id());
+ media_channel1->last_network_route().local.network_id());
EXPECT_EQ(kRemoteNetId,
- media_send_channel1->last_network_route().remote.network_id());
+ media_channel1->last_network_route().remote.network_id());
EXPECT_EQ(kLastPacketId,
- media_send_channel1->last_network_route().last_sent_packet_id);
+ media_channel1->last_network_route().last_sent_packet_id);
EXPECT_EQ(kTransportOverheadPerPacket + kSrtpOverheadPerPacket,
- media_send_channel1->transport_overhead_per_packet());
+ media_channel1->transport_overhead_per_packet());
}
// Test setting up a call.
@@ -909,13 +920,13 @@
EXPECT_FALSE(IsSrtpActive(channel1_));
EXPECT_TRUE(SendInitiate());
if (verify_playout_) {
- EXPECT_TRUE(media_send_channel1()->playout());
+ EXPECT_TRUE(media_channel1()->playout());
}
- EXPECT_FALSE(media_send_channel1()->sending());
+ EXPECT_FALSE(media_channel1()->sending());
EXPECT_TRUE(SendAccept());
EXPECT_FALSE(IsSrtpActive(channel1_));
- EXPECT_TRUE(media_send_channel1()->sending());
- EXPECT_EQ(1U, media_send_channel1()->codecs().size());
+ EXPECT_TRUE(media_channel1()->sending());
+ EXPECT_EQ(1U, media_channel1()->codecs().size());
if (verify_playout_) {
EXPECT_TRUE(media_channel2()->playout());
}
@@ -1047,7 +1058,7 @@
// Regain writability
SendTask(network_thread_,
[this] { fake_rtp_dtls_transport1_->SetWritable(true); });
- EXPECT_TRUE(media_send_channel1()->sending());
+ EXPECT_TRUE(media_channel1()->sending());
SendRtp1();
SendRtp2();
WaitForThreads();
@@ -1061,7 +1072,7 @@
bool asymmetric = true;
fake_rtp_dtls_transport1_->SetDestination(nullptr, asymmetric);
});
- EXPECT_TRUE(media_send_channel1()->sending());
+ EXPECT_TRUE(media_channel1()->sending());
// Should fail also.
SendRtp1();
@@ -1077,7 +1088,7 @@
fake_rtp_dtls_transport1_->SetDestination(fake_rtp_dtls_transport2_.get(),
asymmetric);
});
- EXPECT_TRUE(media_send_channel1()->sending());
+ EXPECT_TRUE(media_channel1()->sending());
SendRtp1();
SendRtp2();
WaitForThreads();
@@ -1130,17 +1141,17 @@
std::unique_ptr<typename T::Content> content(
CreateMediaContentWithStream(1));
- media_send_channel1()->set_fail_set_recv_codecs(true);
+ media_channel1()->set_fail_set_recv_codecs(true);
EXPECT_FALSE(
channel1_->SetLocalContent(content.get(), SdpType::kOffer, err));
EXPECT_FALSE(
channel1_->SetLocalContent(content.get(), SdpType::kAnswer, err));
- media_send_channel1()->set_fail_set_send_codecs(true);
+ media_channel1()->set_fail_set_send_codecs(true);
EXPECT_FALSE(
channel1_->SetRemoteContent(content.get(), SdpType::kOffer, err));
- media_send_channel1()->set_fail_set_send_codecs(true);
+ media_channel1()->set_fail_set_send_codecs(true);
EXPECT_FALSE(
channel1_->SetRemoteContent(content.get(), SdpType::kAnswer, err));
}
@@ -1153,14 +1164,14 @@
CreateMediaContentWithStream(1));
EXPECT_TRUE(
channel1_->SetLocalContent(content1.get(), SdpType::kOffer, err));
- EXPECT_TRUE(media_send_channel1()->HasSendStream(1));
+ EXPECT_TRUE(media_channel1()->HasSendStream(1));
std::unique_ptr<typename T::Content> content2(
CreateMediaContentWithStream(2));
EXPECT_TRUE(
channel1_->SetLocalContent(content2.get(), SdpType::kOffer, err));
- EXPECT_FALSE(media_send_channel1()->HasSendStream(1));
- EXPECT_TRUE(media_send_channel1()->HasSendStream(2));
+ EXPECT_FALSE(media_channel1()->HasSendStream(1));
+ EXPECT_TRUE(media_channel1()->HasSendStream(2));
}
void TestReceiveTwoOffers() {
@@ -1171,14 +1182,14 @@
CreateMediaContentWithStream(1));
EXPECT_TRUE(
channel1_->SetRemoteContent(content1.get(), SdpType::kOffer, err));
- EXPECT_TRUE(media_send_channel1()->HasRecvStream(1));
+ EXPECT_TRUE(media_channel1()->HasRecvStream(1));
std::unique_ptr<typename T::Content> content2(
CreateMediaContentWithStream(2));
EXPECT_TRUE(
channel1_->SetRemoteContent(content2.get(), SdpType::kOffer, err));
- EXPECT_FALSE(media_send_channel1()->HasRecvStream(1));
- EXPECT_TRUE(media_send_channel1()->HasRecvStream(2));
+ EXPECT_FALSE(media_channel1()->HasRecvStream(1));
+ EXPECT_TRUE(media_channel1()->HasRecvStream(2));
}
void TestSendPrAnswer() {
@@ -1190,24 +1201,24 @@
CreateMediaContentWithStream(1));
EXPECT_TRUE(
channel1_->SetRemoteContent(content1.get(), SdpType::kOffer, err));
- EXPECT_TRUE(media_send_channel1()->HasRecvStream(1));
+ EXPECT_TRUE(media_channel1()->HasRecvStream(1));
// Send PR answer
std::unique_ptr<typename T::Content> content2(
CreateMediaContentWithStream(2));
EXPECT_TRUE(
channel1_->SetLocalContent(content2.get(), SdpType::kPrAnswer, err));
- EXPECT_TRUE(media_send_channel1()->HasRecvStream(1));
- EXPECT_TRUE(media_send_channel1()->HasSendStream(2));
+ EXPECT_TRUE(media_channel1()->HasRecvStream(1));
+ EXPECT_TRUE(media_channel1()->HasSendStream(2));
// Send answer
std::unique_ptr<typename T::Content> content3(
CreateMediaContentWithStream(3));
EXPECT_TRUE(
channel1_->SetLocalContent(content3.get(), SdpType::kAnswer, err));
- EXPECT_TRUE(media_send_channel1()->HasRecvStream(1));
- EXPECT_FALSE(media_send_channel1()->HasSendStream(2));
- EXPECT_TRUE(media_send_channel1()->HasSendStream(3));
+ EXPECT_TRUE(media_channel1()->HasRecvStream(1));
+ EXPECT_FALSE(media_channel1()->HasSendStream(2));
+ EXPECT_TRUE(media_channel1()->HasSendStream(3));
}
void TestReceivePrAnswer() {
@@ -1219,39 +1230,39 @@
CreateMediaContentWithStream(1));
EXPECT_TRUE(
channel1_->SetLocalContent(content1.get(), SdpType::kOffer, err));
- EXPECT_TRUE(media_send_channel1()->HasSendStream(1));
+ EXPECT_TRUE(media_channel1()->HasSendStream(1));
// Receive PR answer
std::unique_ptr<typename T::Content> content2(
CreateMediaContentWithStream(2));
EXPECT_TRUE(
channel1_->SetRemoteContent(content2.get(), SdpType::kPrAnswer, err));
- EXPECT_TRUE(media_send_channel1()->HasSendStream(1));
- EXPECT_TRUE(media_send_channel1()->HasRecvStream(2));
+ EXPECT_TRUE(media_channel1()->HasSendStream(1));
+ EXPECT_TRUE(media_channel1()->HasRecvStream(2));
// Receive answer
std::unique_ptr<typename T::Content> content3(
CreateMediaContentWithStream(3));
EXPECT_TRUE(
channel1_->SetRemoteContent(content3.get(), SdpType::kAnswer, err));
- EXPECT_TRUE(media_send_channel1()->HasSendStream(1));
- EXPECT_FALSE(media_send_channel1()->HasRecvStream(2));
- EXPECT_TRUE(media_send_channel1()->HasRecvStream(3));
+ EXPECT_TRUE(media_channel1()->HasSendStream(1));
+ EXPECT_FALSE(media_channel1()->HasRecvStream(2));
+ EXPECT_TRUE(media_channel1()->HasRecvStream(3));
}
void TestOnTransportReadyToSend() {
CreateChannels(0, 0);
- EXPECT_FALSE(media_send_channel1()->ready_to_send());
+ EXPECT_FALSE(media_channel1()->ready_to_send());
network_thread_->PostTask(
[this] { channel1_->OnTransportReadyToSend(true); });
WaitForThreads();
- EXPECT_TRUE(media_send_channel1()->ready_to_send());
+ EXPECT_TRUE(media_channel1()->ready_to_send());
network_thread_->PostTask(
[this] { channel1_->OnTransportReadyToSend(false); });
WaitForThreads();
- EXPECT_FALSE(media_send_channel1()->ready_to_send());
+ EXPECT_FALSE(media_channel1()->ready_to_send());
}
bool SetRemoteContentWithBitrateLimit(int remote_limit) {
@@ -1280,7 +1291,7 @@
std::string err;
EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
SdpType::kOffer, err));
- EXPECT_EQ(media_send_channel1()->max_bps(), -1);
+ EXPECT_EQ(media_channel1()->max_bps(), -1);
VerifyMaxBitrate(media_send_channel1()->GetRtpSendParameters(kSsrc1),
absl::nullopt);
}
@@ -1398,18 +1409,31 @@
ProcessThreadQueue(rtc::Thread::Current());
}
- typename T::MediaChannel* media_send_channel1() {
+ // Accessors that return the FakeMedia<type>Channel object.
+ // Note that these depend on getting the object back that was
+ // passed to the channel constructor.
+ typename T::MediaChannel* media_channel1() {
RTC_DCHECK(channel1_);
- RTC_DCHECK(channel1_->media_send_channel());
- return static_cast<typename T::MediaChannel*>(
- channel1_->media_send_channel());
+ RTC_DCHECK(channel1_->media_channel());
+ return static_cast<typename T::MediaChannel*>(channel1_->media_channel());
}
typename T::MediaChannel* media_channel2() {
RTC_DCHECK(channel2_);
+ RTC_DCHECK(channel2_->media_channel());
+ return static_cast<typename T::MediaChannel*>(channel2_->media_channel());
+ }
+
+ typename T::MediaSendChannel* media_send_channel1() {
+ RTC_DCHECK(channel1_);
+ RTC_DCHECK(channel1_->media_send_channel());
+ return channel1_->media_send_channel();
+ }
+
+ typename T::MediaSendChannel* media_send_channel2() {
+ RTC_DCHECK(channel2_);
RTC_DCHECK(channel2_->media_send_channel());
- return static_cast<typename T::MediaChannel*>(
- channel2_->media_send_channel());
+ return channel2_->media_send_channel();
}
rtc::AutoThread main_thread_;
@@ -1598,8 +1622,8 @@
TEST_F(VoiceChannelSingleThreadTest, TestInit) {
Base::TestInit();
- EXPECT_FALSE(media_send_channel1()->IsStreamMuted(0));
- EXPECT_TRUE(media_send_channel1()->dtmf_info_queue().empty());
+ EXPECT_FALSE(media_channel1()->IsStreamMuted(0));
+ EXPECT_TRUE(media_channel1()->dtmf_info_queue().empty());
}
TEST_F(VoiceChannelSingleThreadTest, TestDeinit) {
@@ -1735,8 +1759,8 @@
// VoiceChannelDoubleThreadTest
TEST_F(VoiceChannelDoubleThreadTest, TestInit) {
Base::TestInit();
- EXPECT_FALSE(media_send_channel1()->IsStreamMuted(0));
- EXPECT_TRUE(media_send_channel1()->dtmf_info_queue().empty());
+ EXPECT_FALSE(media_channel1()->IsStreamMuted(0));
+ EXPECT_TRUE(media_channel1()->dtmf_info_queue().empty());
}
TEST_F(VoiceChannelDoubleThreadTest, TestDeinit) {
@@ -2019,15 +2043,14 @@
std::string err;
EXPECT_TRUE(channel1_->SetLocalContent(&video, SdpType::kOffer, err));
- EXPECT_THAT(media_send_channel1()->send_codecs(), testing::IsEmpty());
- ASSERT_THAT(media_send_channel1()->recv_codecs(), testing::SizeIs(2));
- EXPECT_TRUE(media_send_channel1()->recv_codecs()[0].Matches(kVp8Codec,
- &field_trials_));
- EXPECT_EQ(media_send_channel1()->recv_codecs()[0].packetization,
- absl::nullopt);
- EXPECT_TRUE(media_send_channel1()->recv_codecs()[1].Matches(vp9_codec,
- &field_trials_));
- EXPECT_EQ(media_send_channel1()->recv_codecs()[1].packetization,
+ EXPECT_THAT(media_channel1()->send_codecs(), testing::IsEmpty());
+ ASSERT_THAT(media_channel1()->recv_codecs(), testing::SizeIs(2));
+ EXPECT_TRUE(
+ media_channel1()->recv_codecs()[0].Matches(kVp8Codec, &field_trials_));
+ EXPECT_EQ(media_channel1()->recv_codecs()[0].packetization, absl::nullopt);
+ EXPECT_TRUE(
+ media_channel1()->recv_codecs()[1].Matches(vp9_codec, &field_trials_));
+ EXPECT_EQ(media_channel1()->recv_codecs()[1].packetization,
cricket::kPacketizationParamRaw);
}
@@ -2043,15 +2066,14 @@
std::string err;
EXPECT_TRUE(channel1_->SetRemoteContent(&video, SdpType::kOffer, err));
EXPECT_TRUE(err.empty());
- EXPECT_THAT(media_send_channel1()->recv_codecs(), testing::IsEmpty());
- ASSERT_THAT(media_send_channel1()->send_codecs(), testing::SizeIs(2));
- EXPECT_TRUE(media_send_channel1()->send_codecs()[0].Matches(kVp8Codec,
- &field_trials_));
- EXPECT_EQ(media_send_channel1()->send_codecs()[0].packetization,
- absl::nullopt);
- EXPECT_TRUE(media_send_channel1()->send_codecs()[1].Matches(vp9_codec,
- &field_trials_));
- EXPECT_EQ(media_send_channel1()->send_codecs()[1].packetization,
+ EXPECT_THAT(media_channel1()->recv_codecs(), testing::IsEmpty());
+ ASSERT_THAT(media_channel1()->send_codecs(), testing::SizeIs(2));
+ EXPECT_TRUE(
+ media_channel1()->send_codecs()[0].Matches(kVp8Codec, &field_trials_));
+ EXPECT_EQ(media_channel1()->send_codecs()[0].packetization, absl::nullopt);
+ EXPECT_TRUE(
+ media_channel1()->send_codecs()[1].Matches(vp9_codec, &field_trials_));
+ EXPECT_EQ(media_channel1()->send_codecs()[1].packetization,
cricket::kPacketizationParamRaw);
}
@@ -2069,23 +2091,21 @@
EXPECT_TRUE(err.empty());
EXPECT_TRUE(channel1_->SetRemoteContent(&video, SdpType::kAnswer, err));
EXPECT_TRUE(err.empty());
- ASSERT_THAT(media_send_channel1()->recv_codecs(), testing::SizeIs(2));
- EXPECT_TRUE(media_send_channel1()->recv_codecs()[0].Matches(kVp8Codec,
- &field_trials_));
- EXPECT_EQ(media_send_channel1()->recv_codecs()[0].packetization,
- absl::nullopt);
- EXPECT_TRUE(media_send_channel1()->recv_codecs()[1].Matches(vp9_codec,
- &field_trials_));
- EXPECT_EQ(media_send_channel1()->recv_codecs()[1].packetization,
+ ASSERT_THAT(media_channel1()->recv_codecs(), testing::SizeIs(2));
+ EXPECT_TRUE(
+ media_channel1()->recv_codecs()[0].Matches(kVp8Codec, &field_trials_));
+ EXPECT_EQ(media_channel1()->recv_codecs()[0].packetization, absl::nullopt);
+ EXPECT_TRUE(
+ media_channel1()->recv_codecs()[1].Matches(vp9_codec, &field_trials_));
+ EXPECT_EQ(media_channel1()->recv_codecs()[1].packetization,
cricket::kPacketizationParamRaw);
- EXPECT_THAT(media_send_channel1()->send_codecs(), testing::SizeIs(2));
- EXPECT_TRUE(media_send_channel1()->send_codecs()[0].Matches(kVp8Codec,
- &field_trials_));
- EXPECT_EQ(media_send_channel1()->send_codecs()[0].packetization,
- absl::nullopt);
- EXPECT_TRUE(media_send_channel1()->send_codecs()[1].Matches(vp9_codec,
- &field_trials_));
- EXPECT_EQ(media_send_channel1()->send_codecs()[1].packetization,
+ EXPECT_THAT(media_channel1()->send_codecs(), testing::SizeIs(2));
+ EXPECT_TRUE(
+ media_channel1()->send_codecs()[0].Matches(kVp8Codec, &field_trials_));
+ EXPECT_EQ(media_channel1()->send_codecs()[0].packetization, absl::nullopt);
+ EXPECT_TRUE(
+ media_channel1()->send_codecs()[1].Matches(vp9_codec, &field_trials_));
+ EXPECT_EQ(media_channel1()->send_codecs()[1].packetization,
cricket::kPacketizationParamRaw);
}
@@ -2103,12 +2123,10 @@
std::string err;
EXPECT_TRUE(channel1_->SetRemoteContent(&remote_video, SdpType::kOffer, err));
EXPECT_TRUE(channel1_->SetLocalContent(&local_video, SdpType::kAnswer, err));
- ASSERT_THAT(media_send_channel1()->recv_codecs(), testing::SizeIs(1));
- EXPECT_EQ(media_send_channel1()->recv_codecs()[0].packetization,
- absl::nullopt);
- ASSERT_THAT(media_send_channel1()->send_codecs(), testing::SizeIs(1));
- EXPECT_EQ(media_send_channel1()->send_codecs()[0].packetization,
- absl::nullopt);
+ ASSERT_THAT(media_channel1()->recv_codecs(), testing::SizeIs(1));
+ EXPECT_EQ(media_channel1()->recv_codecs()[0].packetization, absl::nullopt);
+ ASSERT_THAT(media_channel1()->send_codecs(), testing::SizeIs(1));
+ EXPECT_EQ(media_channel1()->send_codecs()[0].packetization, absl::nullopt);
}
TEST_F(VideoChannelSingleThreadTest, TestSetRemoteAnswerWithoutPacketization) {
@@ -2126,12 +2144,10 @@
EXPECT_TRUE(channel1_->SetLocalContent(&local_video, SdpType::kOffer, err));
EXPECT_TRUE(
channel1_->SetRemoteContent(&remote_video, SdpType::kAnswer, err));
- ASSERT_THAT(media_send_channel1()->recv_codecs(), testing::SizeIs(1));
- EXPECT_EQ(media_send_channel1()->recv_codecs()[0].packetization,
- absl::nullopt);
- ASSERT_THAT(media_send_channel1()->send_codecs(), testing::SizeIs(1));
- EXPECT_EQ(media_send_channel1()->send_codecs()[0].packetization,
- absl::nullopt);
+ ASSERT_THAT(media_channel1()->recv_codecs(), testing::SizeIs(1));
+ EXPECT_EQ(media_channel1()->recv_codecs()[0].packetization, absl::nullopt);
+ ASSERT_THAT(media_channel1()->send_codecs(), testing::SizeIs(1));
+ EXPECT_EQ(media_channel1()->send_codecs()[0].packetization, absl::nullopt);
}
TEST_F(VideoChannelSingleThreadTest,
@@ -2153,10 +2169,10 @@
EXPECT_FALSE(
channel1_->SetRemoteContent(&remote_video, SdpType::kAnswer, err));
EXPECT_FALSE(err.empty());
- ASSERT_THAT(media_send_channel1()->recv_codecs(), testing::SizeIs(1));
- EXPECT_EQ(media_send_channel1()->recv_codecs()[0].packetization,
+ ASSERT_THAT(media_channel1()->recv_codecs(), testing::SizeIs(1));
+ EXPECT_EQ(media_channel1()->recv_codecs()[0].packetization,
cricket::kPacketizationParamRaw);
- EXPECT_THAT(media_send_channel1()->send_codecs(), testing::IsEmpty());
+ EXPECT_THAT(media_channel1()->send_codecs(), testing::IsEmpty());
}
TEST_F(VideoChannelSingleThreadTest,
@@ -2176,10 +2192,9 @@
EXPECT_TRUE(err.empty());
EXPECT_FALSE(channel1_->SetLocalContent(&local_video, SdpType::kAnswer, err));
EXPECT_FALSE(err.empty());
- EXPECT_THAT(media_send_channel1()->recv_codecs(), testing::IsEmpty());
- ASSERT_THAT(media_send_channel1()->send_codecs(), testing::SizeIs(1));
- EXPECT_EQ(media_send_channel1()->send_codecs()[0].packetization,
- absl::nullopt);
+ EXPECT_THAT(media_channel1()->recv_codecs(), testing::IsEmpty());
+ ASSERT_THAT(media_channel1()->send_codecs(), testing::SizeIs(1));
+ EXPECT_EQ(media_channel1()->send_codecs()[0].packetization, absl::nullopt);
}
// VideoChannelDoubleThreadTest
diff --git a/pc/rtc_stats_collector.cc b/pc/rtc_stats_collector.cc
index d500a7b..a9fb3b7 100644
--- a/pc/rtc_stats_collector.cc
+++ b/pc/rtc_stats_collector.cc
@@ -2366,15 +2366,13 @@
if (media_type == cricket::MEDIA_TYPE_AUDIO) {
cricket::VoiceMediaChannel* voice_channel =
- static_cast<cricket::VoiceMediaChannel*>(
- channel->voice_media_send_channel());
+ channel->media_channel()->AsVoiceChannel();
RTC_DCHECK(voice_stats.find(voice_channel) == voice_stats.end());
voice_stats.insert(
std::make_pair(voice_channel, cricket::VoiceMediaInfo()));
} else if (media_type == cricket::MEDIA_TYPE_VIDEO) {
cricket::VideoMediaChannel* video_channel =
- static_cast<cricket::VideoMediaChannel*>(
- channel->video_media_send_channel());
+ channel->media_channel()->AsVideoChannel();
RTC_DCHECK(video_stats.find(video_channel) == video_stats.end());
video_stats.insert(
std::make_pair(video_channel, cricket::VideoMediaInfo()));
@@ -2413,14 +2411,12 @@
cricket::MediaType media_type = transceiver->media_type();
if (media_type == cricket::MEDIA_TYPE_AUDIO) {
cricket::VoiceMediaChannel* voice_channel =
- static_cast<cricket::VoiceMediaChannel*>(
- channel->voice_media_send_channel());
+ channel->media_channel()->AsVoiceChannel();
RTC_DCHECK(voice_stats.find(voice_channel) != voice_stats.end());
voice_media_info = std::move(voice_stats[voice_channel]);
} else if (media_type == cricket::MEDIA_TYPE_VIDEO) {
cricket::VideoMediaChannel* video_channel =
- static_cast<cricket::VideoMediaChannel*>(
- channel->video_media_send_channel());
+ channel->media_channel()->AsVideoChannel();
RTC_DCHECK(video_stats.find(video_channel) != video_stats.end());
video_media_info = std::move(video_stats[video_channel]);
}
diff --git a/pc/rtp_sender_receiver_unittest.cc b/pc/rtp_sender_receiver_unittest.cc
index a189e65..e51b058 100644
--- a/pc/rtp_sender_receiver_unittest.cc
+++ b/pc/rtp_sender_receiver_unittest.cc
@@ -130,6 +130,11 @@
RTC_CHECK(voice_media_channel());
RTC_CHECK(video_media_channel());
+ // Create sender channel objects
+ voice_send_channel_ =
+ std::make_unique<cricket::VoiceMediaSendChannel>(voice_media_channel());
+ video_send_channel_ =
+ std::make_unique<cricket::VideoMediaSendChannel>(video_media_channel());
// Create streams for predefined SSRCs. Streams need to exist in order
// for the senders and receievers to apply parameters to them.
@@ -204,7 +209,7 @@
ASSERT_TRUE(audio_rtp_sender_->SetTrack(audio_track_.get()));
EXPECT_CALL(*set_streams_observer, OnSetStreams());
audio_rtp_sender_->SetStreams({local_stream_->id()});
- audio_rtp_sender_->SetMediaChannel(voice_media_channel()->AsSendChannel());
+ audio_rtp_sender_->SetMediaChannel(voice_send_channel_.get());
audio_rtp_sender_->SetSsrc(kAudioSsrc);
VerifyVoiceChannelInput();
}
@@ -520,6 +525,8 @@
cricket::FakeCall fake_call_;
std::unique_ptr<cricket::FakeVoiceMediaChannel> voice_media_channel_;
std::unique_ptr<cricket::FakeVideoMediaChannel> video_media_channel_;
+ std::unique_ptr<cricket::VoiceMediaSendChannel> voice_send_channel_;
+ std::unique_ptr<cricket::VideoMediaSendChannel> video_send_channel_;
rtc::scoped_refptr<AudioRtpSender> audio_rtp_sender_;
rtc::scoped_refptr<VideoRtpSender> video_rtp_sender_;
rtc::scoped_refptr<AudioRtpReceiver> audio_rtp_receiver_;
diff --git a/pc/test/mock_channel_interface.h b/pc/test/mock_channel_interface.h
index 273e4a1..229fb57 100644
--- a/pc/test/mock_channel_interface.h
+++ b/pc/test/mock_channel_interface.h
@@ -25,25 +25,13 @@
class MockChannelInterface : public cricket::ChannelInterface {
public:
MOCK_METHOD(cricket::MediaType, media_type, (), (const, override));
- MOCK_METHOD(MediaChannel*, media_channel, (), (const, override));
- MOCK_METHOD(MediaChannel*, media_send_channel, (), (const, override));
- MOCK_METHOD(VoiceMediaChannel*,
- voice_media_send_channel,
- (),
- (const, override));
- MOCK_METHOD(VideoMediaChannel*,
- video_media_send_channel,
- (),
- (const, override));
- MOCK_METHOD(MediaChannel*, media_receive_channel, (), (const, override));
- MOCK_METHOD(VoiceMediaChannel*,
- voice_media_receive_channel,
- (),
- (const, override));
- MOCK_METHOD(VideoMediaChannel*,
- video_media_receive_channel,
- (),
- (const, override));
+ MOCK_METHOD(MediaChannel*, media_channel, (), (override));
+ MOCK_METHOD(MediaChannel*, media_send_channel, (), (override));
+ MOCK_METHOD(VoiceMediaChannel*, voice_media_send_channel, (), (override));
+ MOCK_METHOD(VideoMediaChannel*, video_media_send_channel, (), (override));
+ MOCK_METHOD(MediaChannel*, media_receive_channel, (), (override));
+ MOCK_METHOD(VoiceMediaChannel*, voice_media_receive_channel, (), (override));
+ MOCK_METHOD(VideoMediaChannel*, video_media_receive_channel, (), (override));
MOCK_METHOD(absl::string_view, transport_name, (), (const, override));
MOCK_METHOD(const std::string&, mid, (), (const, override));
MOCK_METHOD(void, Enable, (bool), (override));