aboutsummaryrefslogtreecommitdiff
path: root/media/base
diff options
context:
space:
mode:
Diffstat (limited to 'media/base')
-rw-r--r--media/base/codec.cc35
-rw-r--r--media/base/codec.h17
-rw-r--r--media/base/codec_unittest.cc25
-rw-r--r--media/base/fake_media_engine.cc21
-rw-r--r--media/base/fake_media_engine.h20
-rw-r--r--media/base/fake_network_interface.h8
-rw-r--r--media/base/media_channel.cc130
-rw-r--r--media/base/media_channel.h101
-rw-r--r--media/base/media_constants.cc5
-rw-r--r--media/base/media_constants.h8
-rw-r--r--media/base/turn_utils.h2
-rw-r--r--media/base/video_source_base.cc49
-rw-r--r--media/base/video_source_base.h36
13 files changed, 263 insertions, 194 deletions
diff --git a/media/base/codec.cc b/media/base/codec.cc
index e8a591e44b..cb6913e76a 100644
--- a/media/base/codec.cc
+++ b/media/base/codec.cc
@@ -58,18 +58,6 @@ bool IsSameCodecSpecific(const std::string& name1,
return true;
}
-bool IsCodecInList(
- const webrtc::SdpVideoFormat& format,
- const std::vector<webrtc::SdpVideoFormat>& existing_formats) {
- for (auto existing_format : existing_formats) {
- if (IsSameCodec(format.name, format.parameters, existing_format.name,
- existing_format.parameters)) {
- return true;
- }
- }
- return false;
-}
-
} // namespace
FeedbackParams::FeedbackParams() = default;
@@ -396,25 +384,6 @@ bool VideoCodec::ValidateCodecFormat() const {
return true;
}
-RtpDataCodec::RtpDataCodec(int id, const std::string& name)
- : Codec(id, name, kDataCodecClockrate) {}
-
-RtpDataCodec::RtpDataCodec() : Codec() {
- clockrate = kDataCodecClockrate;
-}
-
-RtpDataCodec::RtpDataCodec(const RtpDataCodec& c) = default;
-RtpDataCodec::RtpDataCodec(RtpDataCodec&& c) = default;
-RtpDataCodec& RtpDataCodec::operator=(const RtpDataCodec& c) = default;
-RtpDataCodec& RtpDataCodec::operator=(RtpDataCodec&& c) = default;
-
-std::string RtpDataCodec::ToString() const {
- char buf[256];
- rtc::SimpleStringBuilder sb(buf);
- sb << "RtpDataCodec[" << id << ":" << name << "]";
- return sb.str();
-}
-
bool HasLntf(const Codec& codec) {
return codec.HasFeedbackParam(
FeedbackParam(kRtcpFbParamLntf, kParamValueEmpty));
@@ -452,6 +421,8 @@ const VideoCodec* FindMatchingCodec(
return nullptr;
}
+// TODO(crbug.com/1187565): Remove once downstream projects stopped using this
+// method in favor of SdpVideoFormat::IsSameCodec().
bool IsSameCodec(const std::string& name1,
const CodecParameterMap& params1,
const std::string& name2,
@@ -493,7 +464,7 @@ void AddH264ConstrainedBaselineProfileToSupportedFormats(
std::copy_if(cbr_supported_formats.begin(), cbr_supported_formats.end(),
std::back_inserter(*supported_formats),
[supported_formats](const webrtc::SdpVideoFormat& format) {
- return !IsCodecInList(format, *supported_formats);
+ return !format.IsCodecInList(*supported_formats);
});
if (supported_formats->size() > original_size) {
diff --git a/media/base/codec.h b/media/base/codec.h
index c3be2334ce..c7c99bf732 100644
--- a/media/base/codec.h
+++ b/media/base/codec.h
@@ -202,23 +202,6 @@ struct RTC_EXPORT VideoCodec : public Codec {
void SetDefaultParameters();
};
-struct RtpDataCodec : public Codec {
- RtpDataCodec(int id, const std::string& name);
- RtpDataCodec();
- RtpDataCodec(const RtpDataCodec& c);
- RtpDataCodec(RtpDataCodec&& c);
- ~RtpDataCodec() override = default;
-
- RtpDataCodec& operator=(const RtpDataCodec& c);
- RtpDataCodec& operator=(RtpDataCodec&& c);
-
- std::string ToString() const;
-};
-
-// For backwards compatibility
-// TODO(bugs.webrtc.org/10597): Remove when no longer needed.
-typedef RtpDataCodec DataCodec;
-
// Get the codec setting associated with |payload_type|. If there
// is no codec associated with that payload type it returns nullptr.
template <class Codec>
diff --git a/media/base/codec_unittest.cc b/media/base/codec_unittest.cc
index 3586760a14..23bae7b7fe 100644
--- a/media/base/codec_unittest.cc
+++ b/media/base/codec_unittest.cc
@@ -19,7 +19,6 @@
using cricket::AudioCodec;
using cricket::Codec;
-using cricket::DataCodec;
using cricket::FeedbackParam;
using cricket::kCodecParamAssociatedPayloadType;
using cricket::kCodecParamMaxBitrate;
@@ -31,7 +30,8 @@ class TestCodec : public Codec {
TestCodec(int id, const std::string& name, int clockrate)
: Codec(id, name, clockrate) {}
TestCodec() : Codec() {}
- TestCodec(const TestCodec& c) : Codec(c) {}
+ TestCodec(const TestCodec& c) = default;
+ TestCodec& operator=(const TestCodec& c) = default;
};
TEST(CodecTest, TestCodecOperators) {
@@ -303,27 +303,6 @@ TEST(CodecTest, TestH264CodecMatches) {
}
}
-TEST(CodecTest, TestDataCodecMatches) {
- // Test a codec with a static payload type.
- DataCodec c0(34, "D");
- EXPECT_TRUE(c0.Matches(DataCodec(34, "")));
- EXPECT_FALSE(c0.Matches(DataCodec(96, "D")));
- EXPECT_FALSE(c0.Matches(DataCodec(96, "")));
-
- // Test a codec with a dynamic payload type.
- DataCodec c1(96, "D");
- EXPECT_TRUE(c1.Matches(DataCodec(96, "D")));
- EXPECT_TRUE(c1.Matches(DataCodec(97, "D")));
- EXPECT_TRUE(c1.Matches(DataCodec(96, "d")));
- EXPECT_TRUE(c1.Matches(DataCodec(97, "d")));
- EXPECT_TRUE(c1.Matches(DataCodec(35, "d")));
- EXPECT_TRUE(c1.Matches(DataCodec(42, "d")));
- EXPECT_TRUE(c1.Matches(DataCodec(63, "d")));
- EXPECT_FALSE(c1.Matches(DataCodec(96, "")));
- EXPECT_FALSE(c1.Matches(DataCodec(95, "D")));
- EXPECT_FALSE(c1.Matches(DataCodec(34, "D")));
-}
-
TEST(CodecTest, TestSetParamGetParamAndRemoveParam) {
AudioCodec codec;
codec.SetParam("a", "1");
diff --git a/media/base/fake_media_engine.cc b/media/base/fake_media_engine.cc
index c96b5a4caf..aa8e2325b6 100644
--- a/media/base/fake_media_engine.cc
+++ b/media/base/fake_media_engine.cc
@@ -18,6 +18,7 @@
#include "rtc_base/checks.h"
namespace cricket {
+using webrtc::TaskQueueBase;
FakeVoiceMediaChannel::DtmfInfo::DtmfInfo(uint32_t ssrc,
int event_code,
@@ -49,8 +50,11 @@ AudioSource* FakeVoiceMediaChannel::VoiceChannelAudioSink::source() const {
}
FakeVoiceMediaChannel::FakeVoiceMediaChannel(FakeVoiceEngine* engine,
- const AudioOptions& options)
- : engine_(engine), max_bps_(-1) {
+ const AudioOptions& options,
+ TaskQueueBase* network_thread)
+ : RtpHelper<VoiceMediaChannel>(network_thread),
+ engine_(engine),
+ max_bps_(-1) {
output_scalings_[0] = 1.0; // For default channel.
SetOptions(options);
}
@@ -253,8 +257,11 @@ bool CompareDtmfInfo(const FakeVoiceMediaChannel::DtmfInfo& info,
}
FakeVideoMediaChannel::FakeVideoMediaChannel(FakeVideoEngine* engine,
- const VideoOptions& options)
- : engine_(engine), max_bps_(-1) {
+ const VideoOptions& options,
+ TaskQueueBase* network_thread)
+ : RtpHelper<VideoMediaChannel>(network_thread),
+ engine_(engine),
+ max_bps_(-1) {
SetOptions(options);
}
FakeVideoMediaChannel::~FakeVideoMediaChannel() {
@@ -440,7 +447,8 @@ VoiceMediaChannel* FakeVoiceEngine::CreateMediaChannel(
return nullptr;
}
- FakeVoiceMediaChannel* ch = new FakeVoiceMediaChannel(this, options);
+ FakeVoiceMediaChannel* ch =
+ new FakeVoiceMediaChannel(this, options, call->network_thread());
channels_.push_back(ch);
return ch;
}
@@ -506,7 +514,8 @@ VideoMediaChannel* FakeVideoEngine::CreateMediaChannel(
return nullptr;
}
- FakeVideoMediaChannel* ch = new FakeVideoMediaChannel(this, options);
+ FakeVideoMediaChannel* ch =
+ new FakeVideoMediaChannel(this, options, call->network_thread());
channels_.emplace_back(ch);
return ch;
}
diff --git a/media/base/fake_media_engine.h b/media/base/fake_media_engine.h
index d683b7e1d7..e4f7b6659f 100644
--- a/media/base/fake_media_engine.h
+++ b/media/base/fake_media_engine.h
@@ -11,6 +11,7 @@
#ifndef MEDIA_BASE_FAKE_MEDIA_ENGINE_H_
#define MEDIA_BASE_FAKE_MEDIA_ENGINE_H_
+#include <atomic>
#include <list>
#include <map>
#include <memory>
@@ -42,8 +43,9 @@ class FakeVoiceEngine;
template <class Base>
class RtpHelper : public Base {
public:
- RtpHelper()
- : sending_(false),
+ explicit RtpHelper(webrtc::TaskQueueBase* network_thread)
+ : Base(network_thread),
+ sending_(false),
playout_(false),
fail_set_send_codecs_(false),
fail_set_recv_codecs_(false),
@@ -283,7 +285,10 @@ class RtpHelper : public Base {
bool fail_set_recv_codecs() const { return fail_set_recv_codecs_; }
private:
- bool sending_;
+ // TODO(bugs.webrtc.org/12783): This flag is used from more than one thread.
+ // As a workaround for tsan, it's currently std::atomic but that might not
+ // be the appropriate fix.
+ std::atomic<bool> sending_;
bool playout_;
std::vector<RtpExtension> recv_extensions_;
std::vector<RtpExtension> send_extensions_;
@@ -314,8 +319,9 @@ class FakeVoiceMediaChannel : public RtpHelper<VoiceMediaChannel> {
int event_code;
int duration;
};
- explicit FakeVoiceMediaChannel(FakeVoiceEngine* engine,
- const AudioOptions& options);
+ FakeVoiceMediaChannel(FakeVoiceEngine* engine,
+ const AudioOptions& options,
+ webrtc::TaskQueueBase* network_thread);
~FakeVoiceMediaChannel();
const std::vector<AudioCodec>& recv_codecs() const;
const std::vector<AudioCodec>& send_codecs() const;
@@ -406,7 +412,9 @@ bool CompareDtmfInfo(const FakeVoiceMediaChannel::DtmfInfo& info,
class FakeVideoMediaChannel : public RtpHelper<VideoMediaChannel> {
public:
- FakeVideoMediaChannel(FakeVideoEngine* engine, const VideoOptions& options);
+ FakeVideoMediaChannel(FakeVideoEngine* engine,
+ const VideoOptions& options,
+ webrtc::TaskQueueBase* network_thread);
~FakeVideoMediaChannel();
diff --git a/media/base/fake_network_interface.h b/media/base/fake_network_interface.h
index 02d53f6781..4023037731 100644
--- a/media/base/fake_network_interface.h
+++ b/media/base/fake_network_interface.h
@@ -83,14 +83,12 @@ class FakeNetworkInterface : public MediaChannel::NetworkInterface,
return static_cast<int>(sent_ssrcs_.size());
}
- // Note: callers are responsible for deleting the returned buffer.
- const rtc::CopyOnWriteBuffer* GetRtpPacket(int index)
- RTC_LOCKS_EXCLUDED(mutex_) {
+ rtc::CopyOnWriteBuffer GetRtpPacket(int index) RTC_LOCKS_EXCLUDED(mutex_) {
webrtc::MutexLock lock(&mutex_);
if (index >= static_cast<int>(rtp_packets_.size())) {
- return NULL;
+ return {};
}
- return new rtc::CopyOnWriteBuffer(rtp_packets_[index]);
+ return rtp_packets_[index];
}
int NumRtcpPackets() RTC_LOCKS_EXCLUDED(mutex_) {
diff --git a/media/base/media_channel.cc b/media/base/media_channel.cc
index d2370d2ccf..01b043b828 100644
--- a/media/base/media_channel.cc
+++ b/media/base/media_channel.cc
@@ -10,21 +10,40 @@
#include "media/base/media_channel.h"
+#include "media/base/rtp_utils.h"
+#include "rtc_base/task_utils/to_queued_task.h"
+
namespace cricket {
+using webrtc::FrameDecryptorInterface;
+using webrtc::FrameEncryptorInterface;
+using webrtc::FrameTransformerInterface;
+using webrtc::PendingTaskSafetyFlag;
+using webrtc::TaskQueueBase;
+using webrtc::ToQueuedTask;
+using webrtc::VideoTrackInterface;
VideoOptions::VideoOptions()
- : content_hint(webrtc::VideoTrackInterface::ContentHint::kNone) {}
+ : content_hint(VideoTrackInterface::ContentHint::kNone) {}
VideoOptions::~VideoOptions() = default;
-MediaChannel::MediaChannel(const MediaConfig& config)
- : enable_dscp_(config.enable_dscp) {}
+MediaChannel::MediaChannel(const MediaConfig& config,
+ TaskQueueBase* network_thread)
+ : enable_dscp_(config.enable_dscp),
+ network_safety_(PendingTaskSafetyFlag::CreateDetachedInactive()),
+ network_thread_(network_thread) {}
-MediaChannel::MediaChannel() : enable_dscp_(false) {}
+MediaChannel::MediaChannel(TaskQueueBase* network_thread)
+ : enable_dscp_(false),
+ network_safety_(PendingTaskSafetyFlag::CreateDetachedInactive()),
+ network_thread_(network_thread) {}
-MediaChannel::~MediaChannel() {}
+MediaChannel::~MediaChannel() {
+ RTC_DCHECK(!network_interface_);
+}
void MediaChannel::SetInterface(NetworkInterface* iface) {
- webrtc::MutexLock lock(&network_interface_mutex_);
+ RTC_DCHECK_RUN_ON(network_thread_);
+ iface ? network_safety_->SetAlive() : network_safety_->SetNotAlive();
network_interface_ = iface;
UpdateDscp();
}
@@ -35,13 +54,13 @@ int MediaChannel::GetRtpSendTimeExtnId() const {
void MediaChannel::SetFrameEncryptor(
uint32_t ssrc,
- rtc::scoped_refptr<webrtc::FrameEncryptorInterface> frame_encryptor) {
+ rtc::scoped_refptr<FrameEncryptorInterface> frame_encryptor) {
// Placeholder should be pure virtual once internal supports it.
}
void MediaChannel::SetFrameDecryptor(
uint32_t ssrc,
- rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor) {
+ rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor) {
// Placeholder should be pure virtual once internal supports it.
}
@@ -59,9 +78,8 @@ bool MediaChannel::SendRtcp(rtc::CopyOnWriteBuffer* packet,
int MediaChannel::SetOption(NetworkInterface::SocketType type,
rtc::Socket::Option opt,
- int option)
- RTC_LOCKS_EXCLUDED(network_interface_mutex_) {
- webrtc::MutexLock lock(&network_interface_mutex_);
+ int option) {
+ RTC_DCHECK_RUN_ON(network_thread_);
return SetOptionLocked(type, opt, option);
}
@@ -79,11 +97,11 @@ bool MediaChannel::ExtmapAllowMixed() const {
void MediaChannel::SetEncoderToPacketizerFrameTransformer(
uint32_t ssrc,
- rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer) {}
+ rtc::scoped_refptr<FrameTransformerInterface> frame_transformer) {}
void MediaChannel::SetDepacketizerToDecoderFrameTransformer(
uint32_t ssrc,
- rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer) {}
+ rtc::scoped_refptr<FrameTransformerInterface> frame_transformer) {}
int MediaChannel::SetOptionLocked(NetworkInterface::SocketType type,
rtc::Socket::Option opt,
@@ -100,35 +118,45 @@ bool MediaChannel::DscpEnabled() const {
// This is the DSCP value used for both RTP and RTCP channels if DSCP is
// enabled. It can be changed at any time via |SetPreferredDscp|.
rtc::DiffServCodePoint MediaChannel::PreferredDscp() const {
- webrtc::MutexLock lock(&network_interface_mutex_);
+ RTC_DCHECK_RUN_ON(network_thread_);
return preferred_dscp_;
}
-int MediaChannel::SetPreferredDscp(rtc::DiffServCodePoint preferred_dscp) {
- webrtc::MutexLock lock(&network_interface_mutex_);
- if (preferred_dscp == preferred_dscp_) {
- return 0;
+void MediaChannel::SetPreferredDscp(rtc::DiffServCodePoint new_dscp) {
+ if (!network_thread_->IsCurrent()) {
+ // This is currently the common path as the derived channel classes
+ // get called on the worker thread. There are still some tests though
+ // that call directly on the network thread.
+ network_thread_->PostTask(ToQueuedTask(
+ network_safety_, [this, new_dscp]() { SetPreferredDscp(new_dscp); }));
+ return;
}
- preferred_dscp_ = preferred_dscp;
- return UpdateDscp();
+
+ RTC_DCHECK_RUN_ON(network_thread_);
+ if (new_dscp == preferred_dscp_)
+ return;
+
+ preferred_dscp_ = new_dscp;
+ UpdateDscp();
+}
+
+rtc::scoped_refptr<PendingTaskSafetyFlag> MediaChannel::network_safety() {
+ return network_safety_;
}
-int MediaChannel::UpdateDscp() {
+void MediaChannel::UpdateDscp() {
rtc::DiffServCodePoint value =
enable_dscp_ ? preferred_dscp_ : rtc::DSCP_DEFAULT;
int ret =
SetOptionLocked(NetworkInterface::ST_RTP, rtc::Socket::OPT_DSCP, value);
- if (ret == 0) {
- ret = SetOptionLocked(NetworkInterface::ST_RTCP, rtc::Socket::OPT_DSCP,
- value);
- }
- return ret;
+ if (ret == 0)
+ SetOptionLocked(NetworkInterface::ST_RTCP, rtc::Socket::OPT_DSCP, value);
}
bool MediaChannel::DoSendPacket(rtc::CopyOnWriteBuffer* packet,
bool rtcp,
const rtc::PacketOptions& options) {
- webrtc::MutexLock lock(&network_interface_mutex_);
+ RTC_DCHECK_RUN_ON(network_thread_);
if (!network_interface_)
return false;
@@ -136,6 +164,54 @@ bool MediaChannel::DoSendPacket(rtc::CopyOnWriteBuffer* packet,
: network_interface_->SendRtcp(packet, options);
}
+void MediaChannel::SendRtp(const uint8_t* data,
+ size_t len,
+ const webrtc::PacketOptions& options) {
+ auto send =
+ [this, packet_id = options.packet_id,
+ included_in_feedback = options.included_in_feedback,
+ included_in_allocation = options.included_in_allocation,
+ packet = rtc::CopyOnWriteBuffer(data, len, kMaxRtpPacketLen)]() mutable {
+ rtc::PacketOptions rtc_options;
+ rtc_options.packet_id = packet_id;
+ if (DscpEnabled()) {
+ rtc_options.dscp = PreferredDscp();
+ }
+ rtc_options.info_signaled_after_sent.included_in_feedback =
+ included_in_feedback;
+ rtc_options.info_signaled_after_sent.included_in_allocation =
+ included_in_allocation;
+ SendPacket(&packet, rtc_options);
+ };
+
+ // TODO(bugs.webrtc.org/11993): ModuleRtpRtcpImpl2 and related classes (e.g.
+ // RTCPSender) aren't aware of the network thread and may trigger calls to
+ // this function from different threads. Update those classes to keep
+ // network traffic on the network thread.
+ if (network_thread_->IsCurrent()) {
+ send();
+ } else {
+ network_thread_->PostTask(ToQueuedTask(network_safety_, std::move(send)));
+ }
+}
+
+void MediaChannel::SendRtcp(const uint8_t* data, size_t len) {
+ auto send = [this, packet = rtc::CopyOnWriteBuffer(
+ data, len, kMaxRtpPacketLen)]() mutable {
+ rtc::PacketOptions rtc_options;
+ if (DscpEnabled()) {
+ rtc_options.dscp = PreferredDscp();
+ }
+ SendRtcp(&packet, rtc_options);
+ };
+
+ if (network_thread_->IsCurrent()) {
+ send();
+ } else {
+ network_thread_->PostTask(ToQueuedTask(network_safety_, std::move(send)));
+ }
+}
+
MediaSenderInfo::MediaSenderInfo() = default;
MediaSenderInfo::~MediaSenderInfo() = default;
diff --git a/media/base/media_channel.h b/media/base/media_channel.h
index 8a67c2a6e5..a4a925e912 100644
--- a/media/base/media_channel.h
+++ b/media/base/media_channel.h
@@ -26,6 +26,7 @@
#include "api/media_stream_interface.h"
#include "api/rtc_error.h"
#include "api/rtp_parameters.h"
+#include "api/transport/data_channel_transport_interface.h"
#include "api/transport/rtp/rtp_source.h"
#include "api/video/video_content_type.h"
#include "api/video/video_sink_interface.h"
@@ -50,7 +51,7 @@
#include "rtc_base/socket.h"
#include "rtc_base/string_encode.h"
#include "rtc_base/strings/string_builder.h"
-#include "rtc_base/synchronization/mutex.h"
+#include "rtc_base/task_utils/pending_task_safety_flag.h"
namespace rtc {
class Timing;
@@ -168,15 +169,15 @@ class MediaChannel {
virtual ~NetworkInterface() {}
};
- explicit MediaChannel(const MediaConfig& config);
- MediaChannel();
+ MediaChannel(const MediaConfig& config,
+ webrtc::TaskQueueBase* network_thread);
+ explicit MediaChannel(webrtc::TaskQueueBase* network_thread);
virtual ~MediaChannel();
virtual cricket::MediaType media_type() const = 0;
// Sets the abstract interface class for sending RTP/RTCP data.
- virtual void SetInterface(NetworkInterface* iface)
- RTC_LOCKS_EXCLUDED(network_interface_mutex_);
+ virtual void SetInterface(NetworkInterface* iface);
// Called on the network when an RTP packet is received.
virtual void OnPacketReceived(rtc::CopyOnWriteBuffer packet,
int64_t packet_time_us) = 0;
@@ -248,7 +249,7 @@ class MediaChannel {
int SetOption(NetworkInterface::SocketType type,
rtc::Socket::Option opt,
- int option) RTC_LOCKS_EXCLUDED(network_interface_mutex_);
+ int option);
// Corresponds to the SDP attribute extmap-allow-mixed, see RFC8285.
// Set to true if it's allowed to mix one- and two-byte RTP header extensions
@@ -272,38 +273,42 @@ class MediaChannel {
protected:
int SetOptionLocked(NetworkInterface::SocketType type,
rtc::Socket::Option opt,
- int option)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(network_interface_mutex_);
+ int option) RTC_RUN_ON(network_thread_);
bool DscpEnabled() const;
// This is the DSCP value used for both RTP and RTCP channels if DSCP is
// enabled. It can be changed at any time via |SetPreferredDscp|.
- rtc::DiffServCodePoint PreferredDscp() const
- RTC_LOCKS_EXCLUDED(network_interface_mutex_);
+ rtc::DiffServCodePoint PreferredDscp() const;
+ void SetPreferredDscp(rtc::DiffServCodePoint new_dscp);
- int SetPreferredDscp(rtc::DiffServCodePoint preferred_dscp)
- RTC_LOCKS_EXCLUDED(network_interface_mutex_);
+ rtc::scoped_refptr<webrtc::PendingTaskSafetyFlag> network_safety();
+
+ // Utility implementation for derived classes (video/voice) that applies
+ // the packet options and passes the data onwards to `SendPacket`.
+ void SendRtp(const uint8_t* data,
+ size_t len,
+ const webrtc::PacketOptions& options);
+
+ void SendRtcp(const uint8_t* data, size_t len);
private:
// Apply the preferred DSCP setting to the underlying network interface RTP
// and RTCP channels. If DSCP is disabled, then apply the default DSCP value.
- int UpdateDscp() RTC_EXCLUSIVE_LOCKS_REQUIRED(network_interface_mutex_);
+ void UpdateDscp() RTC_RUN_ON(network_thread_);
bool DoSendPacket(rtc::CopyOnWriteBuffer* packet,
bool rtcp,
- const rtc::PacketOptions& options)
- RTC_LOCKS_EXCLUDED(network_interface_mutex_);
+ const rtc::PacketOptions& options);
const bool enable_dscp_;
- // |network_interface_| can be accessed from the worker_thread and
- // from any MediaEngine threads. This critical section is to protect accessing
- // of network_interface_ object.
- mutable webrtc::Mutex network_interface_mutex_;
- NetworkInterface* network_interface_
- RTC_GUARDED_BY(network_interface_mutex_) = nullptr;
- rtc::DiffServCodePoint preferred_dscp_
- RTC_GUARDED_BY(network_interface_mutex_) = rtc::DSCP_DEFAULT;
+ const rtc::scoped_refptr<webrtc::PendingTaskSafetyFlag> network_safety_
+ RTC_PT_GUARDED_BY(network_thread_);
+ webrtc::TaskQueueBase* const network_thread_;
+ NetworkInterface* network_interface_ RTC_GUARDED_BY(network_thread_) =
+ nullptr;
+ rtc::DiffServCodePoint preferred_dscp_ RTC_GUARDED_BY(network_thread_) =
+ rtc::DSCP_DEFAULT;
bool extmap_allow_mixed_ = false;
};
@@ -761,9 +766,11 @@ struct AudioRecvParameters : RtpParameters<AudioCodec> {};
class VoiceMediaChannel : public MediaChannel, public Delayable {
public:
- VoiceMediaChannel() {}
- explicit VoiceMediaChannel(const MediaConfig& config)
- : MediaChannel(config) {}
+ explicit VoiceMediaChannel(webrtc::TaskQueueBase* network_thread)
+ : MediaChannel(network_thread) {}
+ VoiceMediaChannel(const MediaConfig& config,
+ webrtc::TaskQueueBase* network_thread)
+ : MediaChannel(config, network_thread) {}
~VoiceMediaChannel() override {}
cricket::MediaType media_type() const override;
@@ -831,9 +838,11 @@ struct VideoRecvParameters : RtpParameters<VideoCodec> {};
class VideoMediaChannel : public MediaChannel, public Delayable {
public:
- VideoMediaChannel() {}
- explicit VideoMediaChannel(const MediaConfig& config)
- : MediaChannel(config) {}
+ explicit VideoMediaChannel(webrtc::TaskQueueBase* network_thread)
+ : MediaChannel(network_thread) {}
+ VideoMediaChannel(const MediaConfig& config,
+ webrtc::TaskQueueBase* network_thread)
+ : MediaChannel(config, network_thread) {}
~VideoMediaChannel() override {}
cricket::MediaType media_type() const override;
@@ -884,15 +893,6 @@ class VideoMediaChannel : public MediaChannel, public Delayable {
virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
};
-enum DataMessageType {
- // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
- // values.
- DMT_NONE = 0,
- DMT_CONTROL = 1,
- DMT_BINARY = 2,
- DMT_TEXT = 3,
-};
-
// Info about data received in DataMediaChannel. For use in
// DataMediaChannel::SignalDataReceived and in all of the signals that
// signal fires, on up the chain.
@@ -901,34 +901,11 @@ struct ReceiveDataParams {
// SCTP data channels use SIDs.
int sid = 0;
// The type of message (binary, text, or control).
- DataMessageType type = DMT_TEXT;
+ webrtc::DataMessageType type = webrtc::DataMessageType::kText;
// A per-stream value incremented per packet in the stream.
int seq_num = 0;
};
-struct SendDataParams {
- // The in-packet stream indentifier.
- int sid = 0;
- // The type of message (binary, text, or control).
- DataMessageType type = DMT_TEXT;
-
- // TODO(pthatcher): Make |ordered| and |reliable| true by default?
- // For SCTP, whether to send messages flagged as ordered or not.
- // If false, messages can be received out of order.
- bool ordered = false;
- // For SCTP, whether the messages are sent reliably or not.
- // If false, messages may be lost.
- bool reliable = false;
- // For SCTP, if reliable == false, provide partial reliability by
- // resending up to this many times. Either count or millis
- // is supported, not both at the same time.
- int max_rtx_count = 0;
- // For SCTP, if reliable == false, provide partial reliability by
- // resending for up to this many milliseconds. Either count or millis
- // is supported, not both at the same time.
- int max_rtx_ms = 0;
-};
-
enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
} // namespace cricket
diff --git a/media/base/media_constants.cc b/media/base/media_constants.cc
index 2ac382510b..17a8a83bd0 100644
--- a/media/base/media_constants.cc
+++ b/media/base/media_constants.cc
@@ -13,8 +13,6 @@
namespace cricket {
const int kVideoCodecClockrate = 90000;
-const int kDataCodecClockrate = 90000;
-const int kRtpDataMaxBandwidth = 30720; // bps
const int kVideoMtu = 1200;
const int kVideoRtpSendBufferSize = 65536;
@@ -97,9 +95,6 @@ const char kCodecParamMinBitrate[] = "x-google-min-bitrate";
const char kCodecParamStartBitrate[] = "x-google-start-bitrate";
const char kCodecParamMaxQuantization[] = "x-google-max-quantization";
-const int kGoogleRtpDataCodecPlType = 109;
-const char kGoogleRtpDataCodecName[] = "google-data";
-
const char kComfortNoiseCodecName[] = "CN";
const char kVp8CodecName[] = "VP8";
diff --git a/media/base/media_constants.h b/media/base/media_constants.h
index 16b97caacb..bf7f0c3047 100644
--- a/media/base/media_constants.h
+++ b/media/base/media_constants.h
@@ -20,8 +20,6 @@
namespace cricket {
extern const int kVideoCodecClockrate;
-extern const int kDataCodecClockrate;
-extern const int kRtpDataMaxBandwidth; // bps
extern const int kVideoMtu;
extern const int kVideoRtpSendBufferSize;
@@ -119,12 +117,6 @@ extern const char kCodecParamMinBitrate[];
extern const char kCodecParamStartBitrate[];
extern const char kCodecParamMaxQuantization[];
-// We put the data codec names here so callers of DataEngine::CreateChannel
-// don't have to import rtpdataengine.h to get the codec names they want to
-// pass in.
-extern const int kGoogleRtpDataCodecPlType;
-extern const char kGoogleRtpDataCodecName[];
-
extern const char kComfortNoiseCodecName[];
RTC_EXPORT extern const char kVp8CodecName[];
diff --git a/media/base/turn_utils.h b/media/base/turn_utils.h
index ed8e282ba7..82e492c028 100644
--- a/media/base/turn_utils.h
+++ b/media/base/turn_utils.h
@@ -18,8 +18,6 @@
namespace cricket {
-struct PacketOptions;
-
// Finds data location within a TURN Channel Message or TURN Send Indication
// message.
bool RTC_EXPORT UnwrapTurnPacket(const uint8_t* packet,
diff --git a/media/base/video_source_base.cc b/media/base/video_source_base.cc
index d057a24ad8..2454902069 100644
--- a/media/base/video_source_base.cc
+++ b/media/base/video_source_base.cc
@@ -10,6 +10,8 @@
#include "media/base/video_source_base.h"
+#include <algorithm>
+
#include "absl/algorithm/container.h"
#include "rtc_base/checks.h"
@@ -52,4 +54,51 @@ VideoSourceBase::SinkPair* VideoSourceBase::FindSinkPair(
return nullptr;
}
+VideoSourceBaseGuarded::VideoSourceBaseGuarded() = default;
+VideoSourceBaseGuarded::~VideoSourceBaseGuarded() = default;
+
+void VideoSourceBaseGuarded::AddOrUpdateSink(
+ VideoSinkInterface<webrtc::VideoFrame>* sink,
+ const VideoSinkWants& wants) {
+ RTC_DCHECK_RUN_ON(&source_sequence_);
+ RTC_DCHECK(sink != nullptr);
+
+ SinkPair* sink_pair = FindSinkPair(sink);
+ if (!sink_pair) {
+ sinks_.push_back(SinkPair(sink, wants));
+ } else {
+ sink_pair->wants = wants;
+ }
+}
+
+void VideoSourceBaseGuarded::RemoveSink(
+ VideoSinkInterface<webrtc::VideoFrame>* sink) {
+ RTC_DCHECK_RUN_ON(&source_sequence_);
+ RTC_DCHECK(sink != nullptr);
+ RTC_DCHECK(FindSinkPair(sink));
+ sinks_.erase(std::remove_if(sinks_.begin(), sinks_.end(),
+ [sink](const SinkPair& sink_pair) {
+ return sink_pair.sink == sink;
+ }),
+ sinks_.end());
+}
+
+VideoSourceBaseGuarded::SinkPair* VideoSourceBaseGuarded::FindSinkPair(
+ const VideoSinkInterface<webrtc::VideoFrame>* sink) {
+ RTC_DCHECK_RUN_ON(&source_sequence_);
+ auto sink_pair_it = absl::c_find_if(
+ sinks_,
+ [sink](const SinkPair& sink_pair) { return sink_pair.sink == sink; });
+ if (sink_pair_it != sinks_.end()) {
+ return &*sink_pair_it;
+ }
+ return nullptr;
+}
+
+const std::vector<VideoSourceBaseGuarded::SinkPair>&
+VideoSourceBaseGuarded::sink_pairs() const {
+ RTC_DCHECK_RUN_ON(&source_sequence_);
+ return sinks_;
+}
+
} // namespace rtc
diff --git a/media/base/video_source_base.h b/media/base/video_source_base.h
index 59b7dab164..2644723aa7 100644
--- a/media/base/video_source_base.h
+++ b/media/base/video_source_base.h
@@ -17,10 +17,14 @@
#include "api/video/video_frame.h"
#include "api/video/video_sink_interface.h"
#include "api/video/video_source_interface.h"
+#include "rtc_base/system/no_unique_address.h"
namespace rtc {
-// VideoSourceBase is not thread safe.
+// VideoSourceBase is not thread safe. Before using this class, consider using
+// VideoSourceBaseGuarded below instead, which is an identical implementation
+// but applies a sequence checker to help protect internal state.
+// TODO(bugs.webrtc.org/12780): Delete this class.
class VideoSourceBase : public VideoSourceInterface<webrtc::VideoFrame> {
public:
VideoSourceBase();
@@ -44,6 +48,36 @@ class VideoSourceBase : public VideoSourceInterface<webrtc::VideoFrame> {
std::vector<SinkPair> sinks_;
};
+// VideoSourceBaseGuarded assumes that operations related to sinks, occur on the
+// same TQ/thread that the object was constructed on.
+class VideoSourceBaseGuarded : public VideoSourceInterface<webrtc::VideoFrame> {
+ public:
+ VideoSourceBaseGuarded();
+ ~VideoSourceBaseGuarded() override;
+
+ void AddOrUpdateSink(VideoSinkInterface<webrtc::VideoFrame>* sink,
+ const VideoSinkWants& wants) override;
+ void RemoveSink(VideoSinkInterface<webrtc::VideoFrame>* sink) override;
+
+ protected:
+ struct SinkPair {
+ SinkPair(VideoSinkInterface<webrtc::VideoFrame>* sink, VideoSinkWants wants)
+ : sink(sink), wants(wants) {}
+ VideoSinkInterface<webrtc::VideoFrame>* sink;
+ VideoSinkWants wants;
+ };
+
+ SinkPair* FindSinkPair(const VideoSinkInterface<webrtc::VideoFrame>* sink);
+ const std::vector<SinkPair>& sink_pairs() const;
+
+ // Keep the `source_sequence_` checker protected to allow sub classes the
+ // ability to call Detach() if/when appropriate.
+ RTC_NO_UNIQUE_ADDRESS webrtc::SequenceChecker source_sequence_;
+
+ private:
+ std::vector<SinkPair> sinks_ RTC_GUARDED_BY(&source_sequence_);
+};
+
} // namespace rtc
#endif // MEDIA_BASE_VIDEO_SOURCE_BASE_H_