Refactor RtpSender and SSRCDatabase.
* SSRCDatabase doesn't need to be a global instance, so I've changed it to be a "regular" class (i.e. construct via ctor, not maybe via GetSSRCDatabase( + release via ReturnSSRCDatabase())). If we ever have parallel tests running in the same process, they won't have the problem of using the same ssrc database. * Made RtpSender a more const. Also added some todos for myself and holmer to look into clarifying the threading model. * Switched from CriticalSectionWrapper to rtc::CriticalSection * Changed the random seeding to use TickTime::Now().Ticks() since TimeInMicroseconds() could return 0 when the process was starting. This is what TimeInMicroseconds() does anyway but now we don't need to access a global clock object. BUG=webrtc:3062 Review URL: https://codereview.webrtc.org/1623543002 Cr-Commit-Position: refs/heads/master@{#11462}
This commit is contained in:
parent
040b79ff7e
commit
ae695e95a6
@ -21,6 +21,17 @@ namespace webrtc {
|
|||||||
|
|
||||||
class Random {
|
class Random {
|
||||||
public:
|
public:
|
||||||
|
// TODO(tommi): Change this so that the seed can be initialized internally,
|
||||||
|
// e.g. by offering two ways of constructing or offer a static method that
|
||||||
|
// returns a seed that's suitable for initialization.
|
||||||
|
// The problem now is that callers are calling clock_->TimeInMicroseconds()
|
||||||
|
// which calls TickTime::Now().Ticks(), which can return a very low value on
|
||||||
|
// Mac and can result in a seed of 0 after conversion to microseconds.
|
||||||
|
// Besides the quality of the random seed being poor, this also requires
|
||||||
|
// the client to take on extra dependencies to generate a seed.
|
||||||
|
// If we go for a static seed generator in Random, we can use something from
|
||||||
|
// webrtc/base and make sure that it works the same way across platforms.
|
||||||
|
// See also discussion here: https://codereview.webrtc.org/1623543002/
|
||||||
explicit Random(uint64_t seed);
|
explicit Random(uint64_t seed);
|
||||||
|
|
||||||
// Return pseudo-random integer of the specified type.
|
// Return pseudo-random integer of the specified type.
|
||||||
|
|||||||
@ -63,56 +63,46 @@ uint32_t ConvertMsTo24Bits(int64_t time_ms) {
|
|||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
class BitrateAggregator {
|
RTPSender::BitrateAggregator::BitrateAggregator(
|
||||||
public:
|
BitrateStatisticsObserver* bitrate_callback)
|
||||||
explicit BitrateAggregator(BitrateStatisticsObserver* bitrate_callback)
|
|
||||||
: callback_(bitrate_callback),
|
: callback_(bitrate_callback),
|
||||||
total_bitrate_observer_(*this),
|
total_bitrate_observer_(*this),
|
||||||
retransmit_bitrate_observer_(*this),
|
retransmit_bitrate_observer_(*this),
|
||||||
ssrc_(0) {}
|
ssrc_(0) {}
|
||||||
|
|
||||||
void OnStatsUpdated() const {
|
void RTPSender::BitrateAggregator::OnStatsUpdated() const {
|
||||||
if (callback_)
|
if (callback_) {
|
||||||
callback_->Notify(total_bitrate_observer_.statistics(),
|
callback_->Notify(total_bitrate_observer_.statistics(),
|
||||||
retransmit_bitrate_observer_.statistics(),
|
retransmit_bitrate_observer_.statistics(), ssrc_);
|
||||||
ssrc_);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitrate::Observer* total_bitrate_observer() {
|
Bitrate::Observer* RTPSender::BitrateAggregator::total_bitrate_observer() {
|
||||||
return &total_bitrate_observer_;
|
return &total_bitrate_observer_;
|
||||||
}
|
}
|
||||||
Bitrate::Observer* retransmit_bitrate_observer() {
|
Bitrate::Observer* RTPSender::BitrateAggregator::retransmit_bitrate_observer() {
|
||||||
return &retransmit_bitrate_observer_;
|
return &retransmit_bitrate_observer_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_ssrc(uint32_t ssrc) { ssrc_ = ssrc; }
|
void RTPSender::BitrateAggregator::set_ssrc(uint32_t ssrc) {
|
||||||
|
ssrc_ = ssrc;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
RTPSender::BitrateAggregator::BitrateObserver::BitrateObserver(
|
||||||
// We assume that these observers are called on the same thread, which is
|
const BitrateAggregator& aggregator)
|
||||||
// true for RtpSender as they are called on the Process thread.
|
|
||||||
class BitrateObserver : public Bitrate::Observer {
|
|
||||||
public:
|
|
||||||
explicit BitrateObserver(const BitrateAggregator& aggregator)
|
|
||||||
: aggregator_(aggregator) {}
|
: aggregator_(aggregator) {}
|
||||||
|
|
||||||
// Implements Bitrate::Observer.
|
// Implements Bitrate::Observer.
|
||||||
void BitrateUpdated(const BitrateStatistics& stats) override {
|
void RTPSender::BitrateAggregator::BitrateObserver::BitrateUpdated(
|
||||||
|
const BitrateStatistics& stats) {
|
||||||
statistics_ = stats;
|
statistics_ = stats;
|
||||||
aggregator_.OnStatsUpdated();
|
aggregator_.OnStatsUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
BitrateStatistics statistics() const { return statistics_; }
|
const BitrateStatistics&
|
||||||
|
RTPSender::BitrateAggregator::BitrateObserver::statistics() const {
|
||||||
private:
|
return statistics_;
|
||||||
BitrateStatistics statistics_;
|
}
|
||||||
const BitrateAggregator& aggregator_;
|
|
||||||
};
|
|
||||||
|
|
||||||
BitrateStatisticsObserver* const callback_;
|
|
||||||
BitrateObserver total_bitrate_observer_;
|
|
||||||
BitrateObserver retransmit_bitrate_observer_;
|
|
||||||
uint32_t ssrc_;
|
|
||||||
};
|
|
||||||
|
|
||||||
RTPSender::RTPSender(
|
RTPSender::RTPSender(
|
||||||
bool audio,
|
bool audio,
|
||||||
@ -132,8 +122,8 @@ RTPSender::RTPSender(
|
|||||||
clock_delta_ms_(clock_->TimeInMilliseconds() -
|
clock_delta_ms_(clock_->TimeInMilliseconds() -
|
||||||
TickTime::MillisecondTimestamp()),
|
TickTime::MillisecondTimestamp()),
|
||||||
random_(clock_->TimeInMicroseconds()),
|
random_(clock_->TimeInMicroseconds()),
|
||||||
bitrates_(new BitrateAggregator(bitrate_callback)),
|
bitrates_(bitrate_callback),
|
||||||
total_bitrate_sent_(clock, bitrates_->total_bitrate_observer()),
|
total_bitrate_sent_(clock, bitrates_.total_bitrate_observer()),
|
||||||
audio_configured_(audio),
|
audio_configured_(audio),
|
||||||
audio_(audio ? new RTPSenderAudio(clock, this, audio_feedback) : nullptr),
|
audio_(audio ? new RTPSenderAudio(clock, this, audio_feedback) : nullptr),
|
||||||
video_(audio ? nullptr : new RTPSenderVideo(clock, this)),
|
video_(audio ? nullptr : new RTPSenderVideo(clock, this)),
|
||||||
@ -141,7 +131,6 @@ RTPSender::RTPSender(
|
|||||||
transport_sequence_number_allocator_(sequence_number_allocator),
|
transport_sequence_number_allocator_(sequence_number_allocator),
|
||||||
transport_feedback_observer_(transport_feedback_observer),
|
transport_feedback_observer_(transport_feedback_observer),
|
||||||
last_capture_time_ms_sent_(0),
|
last_capture_time_ms_sent_(0),
|
||||||
send_critsect_(CriticalSectionWrapper::CreateCriticalSection()),
|
|
||||||
transport_(transport),
|
transport_(transport),
|
||||||
sending_media_(true), // Default to sending media.
|
sending_media_(true), // Default to sending media.
|
||||||
max_payload_length_(IP_PACKET_SIZE - 28), // Default is IP-v4/UDP.
|
max_payload_length_(IP_PACKET_SIZE - 28), // Default is IP-v4/UDP.
|
||||||
@ -157,7 +146,7 @@ RTPSender::RTPSender(
|
|||||||
// NACK.
|
// NACK.
|
||||||
nack_byte_count_times_(),
|
nack_byte_count_times_(),
|
||||||
nack_byte_count_(),
|
nack_byte_count_(),
|
||||||
nack_bitrate_(clock, bitrates_->retransmit_bitrate_observer()),
|
nack_bitrate_(clock, bitrates_.retransmit_bitrate_observer()),
|
||||||
packet_history_(clock),
|
packet_history_(clock),
|
||||||
// Statistics
|
// Statistics
|
||||||
statistics_crit_(CriticalSectionWrapper::CreateCriticalSection()),
|
statistics_crit_(CriticalSectionWrapper::CreateCriticalSection()),
|
||||||
@ -168,7 +157,7 @@ RTPSender::RTPSender(
|
|||||||
// RTP variables
|
// RTP variables
|
||||||
start_timestamp_forced_(false),
|
start_timestamp_forced_(false),
|
||||||
start_timestamp_(0),
|
start_timestamp_(0),
|
||||||
ssrc_db_(*SSRCDatabase::GetSSRCDatabase()),
|
ssrc_db_(SSRCDatabase::GetSSRCDatabase()),
|
||||||
remote_ssrc_(0),
|
remote_ssrc_(0),
|
||||||
sequence_number_forced_(false),
|
sequence_number_forced_(false),
|
||||||
ssrc_forced_(false),
|
ssrc_forced_(false),
|
||||||
@ -184,21 +173,35 @@ RTPSender::RTPSender(
|
|||||||
target_bitrate_(0) {
|
target_bitrate_(0) {
|
||||||
memset(nack_byte_count_times_, 0, sizeof(nack_byte_count_times_));
|
memset(nack_byte_count_times_, 0, sizeof(nack_byte_count_times_));
|
||||||
memset(nack_byte_count_, 0, sizeof(nack_byte_count_));
|
memset(nack_byte_count_, 0, sizeof(nack_byte_count_));
|
||||||
// We need to seed the random generator.
|
// We need to seed the random generator for BuildPaddingPacket() below.
|
||||||
|
// TODO(holmer,tommi): Note that TimeInMilliseconds might return 0 on Mac
|
||||||
|
// early on in the process.
|
||||||
srand(static_cast<uint32_t>(clock_->TimeInMilliseconds()));
|
srand(static_cast<uint32_t>(clock_->TimeInMilliseconds()));
|
||||||
ssrc_ = ssrc_db_.CreateSSRC(); // Can't be 0.
|
ssrc_ = ssrc_db_->CreateSSRC();
|
||||||
ssrc_rtx_ = ssrc_db_.CreateSSRC(); // Can't be 0.
|
RTC_DCHECK(ssrc_ != 0);
|
||||||
bitrates_->set_ssrc(ssrc_);
|
ssrc_rtx_ = ssrc_db_->CreateSSRC();
|
||||||
|
RTC_DCHECK(ssrc_rtx_ != 0);
|
||||||
|
|
||||||
|
bitrates_.set_ssrc(ssrc_);
|
||||||
// Random start, 16 bits. Can't be 0.
|
// Random start, 16 bits. Can't be 0.
|
||||||
sequence_number_rtx_ = random_.Rand(1, kMaxInitRtpSeqNumber);
|
sequence_number_rtx_ = random_.Rand(1, kMaxInitRtpSeqNumber);
|
||||||
sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber);
|
sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
RTPSender::~RTPSender() {
|
RTPSender::~RTPSender() {
|
||||||
|
// TODO(tommi): Use a thread checker to ensure the object is created and
|
||||||
|
// deleted on the same thread. At the moment this isn't possible due to
|
||||||
|
// voe::ChannelOwner in voice engine. To reproduce, run:
|
||||||
|
// voe_auto_test --automated --gtest_filter=*MixManyChannelsForStressOpus
|
||||||
|
|
||||||
|
// TODO(tommi,holmer): We don't grab locks in the dtor before accessing member
|
||||||
|
// variables but we grab them in all other methods. (what's the design?)
|
||||||
|
// Start documenting what thread we're on in what method so that it's easier
|
||||||
|
// to understand performance attributes and possibly remove locks.
|
||||||
if (remote_ssrc_ != 0) {
|
if (remote_ssrc_ != 0) {
|
||||||
ssrc_db_.ReturnSSRC(remote_ssrc_);
|
ssrc_db_->ReturnSSRC(remote_ssrc_);
|
||||||
}
|
}
|
||||||
ssrc_db_.ReturnSSRC(ssrc_);
|
ssrc_db_->ReturnSSRC(ssrc_);
|
||||||
|
|
||||||
SSRCDatabase::ReturnSSRCDatabase();
|
SSRCDatabase::ReturnSSRCDatabase();
|
||||||
while (!payload_type_map_.empty()) {
|
while (!payload_type_map_.empty()) {
|
||||||
@ -246,7 +249,7 @@ int32_t RTPSender::SetTransmissionTimeOffset(int32_t transmission_time_offset) {
|
|||||||
transmission_time_offset < -(0x800000 - 1)) { // Word24.
|
transmission_time_offset < -(0x800000 - 1)) { // Word24.
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
transmission_time_offset_ = transmission_time_offset;
|
transmission_time_offset_ = transmission_time_offset;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -255,25 +258,25 @@ int32_t RTPSender::SetAbsoluteSendTime(uint32_t absolute_send_time) {
|
|||||||
if (absolute_send_time > 0xffffff) { // UWord24.
|
if (absolute_send_time > 0xffffff) { // UWord24.
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
absolute_send_time_ = absolute_send_time;
|
absolute_send_time_ = absolute_send_time;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RTPSender::SetVideoRotation(VideoRotation rotation) {
|
void RTPSender::SetVideoRotation(VideoRotation rotation) {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
rotation_ = rotation;
|
rotation_ = rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t RTPSender::SetTransportSequenceNumber(uint16_t sequence_number) {
|
int32_t RTPSender::SetTransportSequenceNumber(uint16_t sequence_number) {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
transport_sequence_number_ = sequence_number;
|
transport_sequence_number_ = sequence_number;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t RTPSender::RegisterRtpHeaderExtension(RTPExtensionType type,
|
int32_t RTPSender::RegisterRtpHeaderExtension(RTPExtensionType type,
|
||||||
uint8_t id) {
|
uint8_t id) {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
if (type == kRtpExtensionVideoRotation) {
|
if (type == kRtpExtensionVideoRotation) {
|
||||||
cvo_mode_ = kCVOInactive;
|
cvo_mode_ = kCVOInactive;
|
||||||
return rtp_header_extension_map_.RegisterInactive(type, id);
|
return rtp_header_extension_map_.RegisterInactive(type, id);
|
||||||
@ -282,17 +285,17 @@ int32_t RTPSender::RegisterRtpHeaderExtension(RTPExtensionType type,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool RTPSender::IsRtpHeaderExtensionRegistered(RTPExtensionType type) {
|
bool RTPSender::IsRtpHeaderExtensionRegistered(RTPExtensionType type) {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
return rtp_header_extension_map_.IsRegistered(type);
|
return rtp_header_extension_map_.IsRegistered(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t RTPSender::DeregisterRtpHeaderExtension(RTPExtensionType type) {
|
int32_t RTPSender::DeregisterRtpHeaderExtension(RTPExtensionType type) {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
return rtp_header_extension_map_.Deregister(type);
|
return rtp_header_extension_map_.Deregister(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t RTPSender::RtpHeaderExtensionTotalLength() const {
|
size_t RTPSender::RtpHeaderExtensionTotalLength() const {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
return rtp_header_extension_map_.GetTotalLengthInBytes();
|
return rtp_header_extension_map_.GetTotalLengthInBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,7 +306,7 @@ int32_t RTPSender::RegisterPayload(
|
|||||||
size_t channels,
|
size_t channels,
|
||||||
uint32_t rate) {
|
uint32_t rate) {
|
||||||
assert(payload_name);
|
assert(payload_name);
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
|
|
||||||
std::map<int8_t, RtpUtility::Payload*>::iterator it =
|
std::map<int8_t, RtpUtility::Payload*>::iterator it =
|
||||||
payload_type_map_.find(payload_number);
|
payload_type_map_.find(payload_number);
|
||||||
@ -346,7 +349,7 @@ int32_t RTPSender::RegisterPayload(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t RTPSender::DeRegisterSendPayload(int8_t payload_type) {
|
int32_t RTPSender::DeRegisterSendPayload(int8_t payload_type) {
|
||||||
CriticalSectionScoped lock(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
|
|
||||||
std::map<int8_t, RtpUtility::Payload*>::iterator it =
|
std::map<int8_t, RtpUtility::Payload*>::iterator it =
|
||||||
payload_type_map_.find(payload_type);
|
payload_type_map_.find(payload_type);
|
||||||
@ -361,12 +364,12 @@ int32_t RTPSender::DeRegisterSendPayload(int8_t payload_type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RTPSender::SetSendPayloadType(int8_t payload_type) {
|
void RTPSender::SetSendPayloadType(int8_t payload_type) {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
payload_type_ = payload_type;
|
payload_type_ = payload_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t RTPSender::SendPayloadType() const {
|
int8_t RTPSender::SendPayloadType() const {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
return payload_type_;
|
return payload_type_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -379,7 +382,7 @@ int32_t RTPSender::SetMaxPayloadLength(size_t max_payload_length,
|
|||||||
// Sanity check.
|
// Sanity check.
|
||||||
RTC_DCHECK(max_payload_length >= 100 && max_payload_length <= IP_PACKET_SIZE)
|
RTC_DCHECK(max_payload_length >= 100 && max_payload_length <= IP_PACKET_SIZE)
|
||||||
<< "Invalid max payload length: " << max_payload_length;
|
<< "Invalid max payload length: " << max_payload_length;
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
max_payload_length_ = max_payload_length;
|
max_payload_length_ = max_payload_length;
|
||||||
packet_over_head_ = packet_over_head;
|
packet_over_head_ = packet_over_head;
|
||||||
return 0;
|
return 0;
|
||||||
@ -388,7 +391,7 @@ int32_t RTPSender::SetMaxPayloadLength(size_t max_payload_length,
|
|||||||
size_t RTPSender::MaxDataPayloadLength() const {
|
size_t RTPSender::MaxDataPayloadLength() const {
|
||||||
int rtx;
|
int rtx;
|
||||||
{
|
{
|
||||||
CriticalSectionScoped rtx_lock(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
rtx = rtx_;
|
rtx = rtx_;
|
||||||
}
|
}
|
||||||
if (audio_configured_) {
|
if (audio_configured_) {
|
||||||
@ -407,28 +410,28 @@ size_t RTPSender::MaxPayloadLength() const {
|
|||||||
uint16_t RTPSender::PacketOverHead() const { return packet_over_head_; }
|
uint16_t RTPSender::PacketOverHead() const { return packet_over_head_; }
|
||||||
|
|
||||||
void RTPSender::SetRtxStatus(int mode) {
|
void RTPSender::SetRtxStatus(int mode) {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
rtx_ = mode;
|
rtx_ = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
int RTPSender::RtxStatus() const {
|
int RTPSender::RtxStatus() const {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
return rtx_;
|
return rtx_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RTPSender::SetRtxSsrc(uint32_t ssrc) {
|
void RTPSender::SetRtxSsrc(uint32_t ssrc) {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
ssrc_rtx_ = ssrc;
|
ssrc_rtx_ = ssrc;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t RTPSender::RtxSsrc() const {
|
uint32_t RTPSender::RtxSsrc() const {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
return ssrc_rtx_;
|
return ssrc_rtx_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RTPSender::SetRtxPayloadType(int payload_type,
|
void RTPSender::SetRtxPayloadType(int payload_type,
|
||||||
int associated_payload_type) {
|
int associated_payload_type) {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
RTC_DCHECK_LE(payload_type, 127);
|
RTC_DCHECK_LE(payload_type, 127);
|
||||||
RTC_DCHECK_LE(associated_payload_type, 127);
|
RTC_DCHECK_LE(associated_payload_type, 127);
|
||||||
if (payload_type < 0) {
|
if (payload_type < 0) {
|
||||||
@ -441,7 +444,7 @@ void RTPSender::SetRtxPayloadType(int payload_type,
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::pair<int, int> RTPSender::RtxPayloadType() const {
|
std::pair<int, int> RTPSender::RtxPayloadType() const {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
for (const auto& kv : rtx_payload_type_map_) {
|
for (const auto& kv : rtx_payload_type_map_) {
|
||||||
if (kv.second == rtx_payload_type_) {
|
if (kv.second == rtx_payload_type_) {
|
||||||
return std::make_pair(rtx_payload_type_, kv.first);
|
return std::make_pair(rtx_payload_type_, kv.first);
|
||||||
@ -452,7 +455,7 @@ std::pair<int, int> RTPSender::RtxPayloadType() const {
|
|||||||
|
|
||||||
int32_t RTPSender::CheckPayloadType(int8_t payload_type,
|
int32_t RTPSender::CheckPayloadType(int8_t payload_type,
|
||||||
RtpVideoCodecTypes* video_type) {
|
RtpVideoCodecTypes* video_type) {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
|
|
||||||
if (payload_type < 0) {
|
if (payload_type < 0) {
|
||||||
LOG(LS_ERROR) << "Invalid payload_type " << payload_type;
|
LOG(LS_ERROR) << "Invalid payload_type " << payload_type;
|
||||||
@ -494,7 +497,7 @@ int32_t RTPSender::CheckPayloadType(int8_t payload_type,
|
|||||||
|
|
||||||
RTPSenderInterface::CVOMode RTPSender::ActivateCVORtpHeaderExtension() {
|
RTPSenderInterface::CVOMode RTPSender::ActivateCVORtpHeaderExtension() {
|
||||||
if (cvo_mode_ == kCVOInactive) {
|
if (cvo_mode_ == kCVOInactive) {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
if (rtp_header_extension_map_.SetActive(kRtpExtensionVideoRotation, true)) {
|
if (rtp_header_extension_map_.SetActive(kRtpExtensionVideoRotation, true)) {
|
||||||
cvo_mode_ = kCVOActivated;
|
cvo_mode_ = kCVOActivated;
|
||||||
}
|
}
|
||||||
@ -513,7 +516,7 @@ int32_t RTPSender::SendOutgoingData(FrameType frame_type,
|
|||||||
uint32_t ssrc;
|
uint32_t ssrc;
|
||||||
{
|
{
|
||||||
// Drop this packet if we're not sending media packets.
|
// Drop this packet if we're not sending media packets.
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
ssrc = ssrc_;
|
ssrc = ssrc_;
|
||||||
if (!sending_media_) {
|
if (!sending_media_) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -565,7 +568,7 @@ int32_t RTPSender::SendOutgoingData(FrameType frame_type,
|
|||||||
|
|
||||||
size_t RTPSender::TrySendRedundantPayloads(size_t bytes_to_send) {
|
size_t RTPSender::TrySendRedundantPayloads(size_t bytes_to_send) {
|
||||||
{
|
{
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
if ((rtx_ & kRtxRedundantPayloads) == 0)
|
if ((rtx_ & kRtxRedundantPayloads) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -627,7 +630,7 @@ size_t RTPSender::SendPadData(size_t bytes,
|
|||||||
int payload_type;
|
int payload_type;
|
||||||
bool over_rtx;
|
bool over_rtx;
|
||||||
{
|
{
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
if (!timestamp_provided) {
|
if (!timestamp_provided) {
|
||||||
timestamp = timestamp_;
|
timestamp = timestamp_;
|
||||||
capture_time_ms = capture_time_ms_;
|
capture_time_ms = capture_time_ms_;
|
||||||
@ -745,7 +748,7 @@ int32_t RTPSender::ReSendPacket(uint16_t packet_id, int64_t min_resend_time) {
|
|||||||
}
|
}
|
||||||
int rtx = kRtxOff;
|
int rtx = kRtxOff;
|
||||||
{
|
{
|
||||||
CriticalSectionScoped lock(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
rtx = rtx_;
|
rtx = rtx_;
|
||||||
}
|
}
|
||||||
if (!PrepareAndSendPacket(data_buffer, length, capture_time_ms,
|
if (!PrepareAndSendPacket(data_buffer, length, capture_time_ms,
|
||||||
@ -843,7 +846,7 @@ bool RTPSender::ProcessNACKBitRate(uint32_t now) {
|
|||||||
const uint32_t kAvgIntervalMs = 1000;
|
const uint32_t kAvgIntervalMs = 1000;
|
||||||
uint32_t target_bitrate = GetTargetBitrate();
|
uint32_t target_bitrate = GetTargetBitrate();
|
||||||
|
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
|
|
||||||
if (target_bitrate == 0) {
|
if (target_bitrate == 0) {
|
||||||
return true;
|
return true;
|
||||||
@ -868,7 +871,7 @@ bool RTPSender::ProcessNACKBitRate(uint32_t now) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RTPSender::UpdateNACKBitRate(uint32_t bytes, int64_t now) {
|
void RTPSender::UpdateNACKBitRate(uint32_t bytes, int64_t now) {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
if (bytes == 0)
|
if (bytes == 0)
|
||||||
return;
|
return;
|
||||||
nack_bitrate_.Update(bytes);
|
nack_bitrate_.Update(bytes);
|
||||||
@ -904,7 +907,7 @@ bool RTPSender::TimeToSendPacket(uint16_t sequence_number,
|
|||||||
}
|
}
|
||||||
int rtx;
|
int rtx;
|
||||||
{
|
{
|
||||||
CriticalSectionScoped lock(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
rtx = rtx_;
|
rtx = rtx_;
|
||||||
}
|
}
|
||||||
return PrepareAndSendPacket(data_buffer,
|
return PrepareAndSendPacket(data_buffer,
|
||||||
@ -962,7 +965,7 @@ bool RTPSender::PrepareAndSendPacket(uint8_t* buffer,
|
|||||||
|
|
||||||
bool ret = SendPacketToNetwork(buffer_to_send_ptr, length, options);
|
bool ret = SendPacketToNetwork(buffer_to_send_ptr, length, options);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
CriticalSectionScoped lock(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
media_has_been_sent_ = true;
|
media_has_been_sent_ = true;
|
||||||
}
|
}
|
||||||
UpdateRtpStats(buffer_to_send_ptr, length, rtp_header, send_over_rtx,
|
UpdateRtpStats(buffer_to_send_ptr, length, rtp_header, send_over_rtx,
|
||||||
@ -1022,7 +1025,7 @@ size_t RTPSender::TimeToSendPadding(size_t bytes) {
|
|||||||
if (audio_configured_ || bytes == 0)
|
if (audio_configured_ || bytes == 0)
|
||||||
return 0;
|
return 0;
|
||||||
{
|
{
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
if (!sending_media_)
|
if (!sending_media_)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1108,7 +1111,7 @@ int32_t RTPSender::SendToNetwork(uint8_t* buffer,
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
{
|
{
|
||||||
CriticalSectionScoped lock(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
media_has_been_sent_ = true;
|
media_has_been_sent_ = true;
|
||||||
}
|
}
|
||||||
UpdateRtpStats(buffer, length, rtp_header, false, false);
|
UpdateRtpStats(buffer, length, rtp_header, false, false);
|
||||||
@ -1123,7 +1126,7 @@ void RTPSender::UpdateDelayStatistics(int64_t capture_time_ms, int64_t now_ms) {
|
|||||||
int avg_delay_ms = 0;
|
int avg_delay_ms = 0;
|
||||||
int max_delay_ms = 0;
|
int max_delay_ms = 0;
|
||||||
{
|
{
|
||||||
CriticalSectionScoped lock(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
ssrc = ssrc_;
|
ssrc = ssrc_;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@ -1149,7 +1152,7 @@ void RTPSender::UpdateDelayStatistics(int64_t capture_time_ms, int64_t now_ms) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RTPSender::ProcessBitrate() {
|
void RTPSender::ProcessBitrate() {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
total_bitrate_sent_.Process();
|
total_bitrate_sent_.Process();
|
||||||
nack_bitrate_.Process();
|
nack_bitrate_.Process();
|
||||||
if (audio_configured_) {
|
if (audio_configured_) {
|
||||||
@ -1159,7 +1162,7 @@ void RTPSender::ProcessBitrate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t RTPSender::RTPHeaderLength() const {
|
size_t RTPSender::RTPHeaderLength() const {
|
||||||
CriticalSectionScoped lock(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
size_t rtp_header_length = kRtpHeaderLength;
|
size_t rtp_header_length = kRtpHeaderLength;
|
||||||
rtp_header_length += sizeof(uint32_t) * csrcs_.size();
|
rtp_header_length += sizeof(uint32_t) * csrcs_.size();
|
||||||
rtp_header_length += RtpHeaderExtensionTotalLength();
|
rtp_header_length += RtpHeaderExtensionTotalLength();
|
||||||
@ -1167,7 +1170,7 @@ size_t RTPSender::RTPHeaderLength() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint16_t RTPSender::AllocateSequenceNumber(uint16_t packets_to_send) {
|
uint16_t RTPSender::AllocateSequenceNumber(uint16_t packets_to_send) {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
uint16_t first_allocated_sequence_number = sequence_number_;
|
uint16_t first_allocated_sequence_number = sequence_number_;
|
||||||
sequence_number_ += packets_to_send;
|
sequence_number_ += packets_to_send;
|
||||||
return first_allocated_sequence_number;
|
return first_allocated_sequence_number;
|
||||||
@ -1226,7 +1229,7 @@ int32_t RTPSender::BuildRTPheader(uint8_t* data_buffer,
|
|||||||
bool timestamp_provided,
|
bool timestamp_provided,
|
||||||
bool inc_sequence_number) {
|
bool inc_sequence_number) {
|
||||||
assert(payload_type >= 0);
|
assert(payload_type >= 0);
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
|
|
||||||
if (timestamp_provided) {
|
if (timestamp_provided) {
|
||||||
timestamp_ = start_timestamp_ + capture_timestamp;
|
timestamp_ = start_timestamp_ + capture_timestamp;
|
||||||
@ -1533,7 +1536,7 @@ void RTPSender::UpdateTransmissionTimeOffset(uint8_t* rtp_packet,
|
|||||||
const RTPHeader& rtp_header,
|
const RTPHeader& rtp_header,
|
||||||
int64_t time_diff_ms) const {
|
int64_t time_diff_ms) const {
|
||||||
size_t offset;
|
size_t offset;
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
switch (VerifyExtension(kRtpExtensionTransmissionTimeOffset, rtp_packet,
|
switch (VerifyExtension(kRtpExtensionTransmissionTimeOffset, rtp_packet,
|
||||||
rtp_packet_length, rtp_header,
|
rtp_packet_length, rtp_header,
|
||||||
kTransmissionTimeOffsetLength, &offset)) {
|
kTransmissionTimeOffsetLength, &offset)) {
|
||||||
@ -1559,7 +1562,7 @@ bool RTPSender::UpdateAudioLevel(uint8_t* rtp_packet,
|
|||||||
bool is_voiced,
|
bool is_voiced,
|
||||||
uint8_t dBov) const {
|
uint8_t dBov) const {
|
||||||
size_t offset;
|
size_t offset;
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
|
|
||||||
switch (VerifyExtension(kRtpExtensionAudioLevel, rtp_packet,
|
switch (VerifyExtension(kRtpExtensionAudioLevel, rtp_packet,
|
||||||
rtp_packet_length, rtp_header, kAudioLevelLength,
|
rtp_packet_length, rtp_header, kAudioLevelLength,
|
||||||
@ -1584,7 +1587,7 @@ bool RTPSender::UpdateVideoRotation(uint8_t* rtp_packet,
|
|||||||
const RTPHeader& rtp_header,
|
const RTPHeader& rtp_header,
|
||||||
VideoRotation rotation) const {
|
VideoRotation rotation) const {
|
||||||
size_t offset;
|
size_t offset;
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
|
|
||||||
switch (VerifyExtension(kRtpExtensionVideoRotation, rtp_packet,
|
switch (VerifyExtension(kRtpExtensionVideoRotation, rtp_packet,
|
||||||
rtp_packet_length, rtp_header, kVideoRotationLength,
|
rtp_packet_length, rtp_header, kVideoRotationLength,
|
||||||
@ -1609,7 +1612,7 @@ void RTPSender::UpdateAbsoluteSendTime(uint8_t* rtp_packet,
|
|||||||
const RTPHeader& rtp_header,
|
const RTPHeader& rtp_header,
|
||||||
int64_t now_ms) const {
|
int64_t now_ms) const {
|
||||||
size_t offset;
|
size_t offset;
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
|
|
||||||
switch (VerifyExtension(kRtpExtensionAbsoluteSendTime, rtp_packet,
|
switch (VerifyExtension(kRtpExtensionAbsoluteSendTime, rtp_packet,
|
||||||
rtp_packet_length, rtp_header,
|
rtp_packet_length, rtp_header,
|
||||||
@ -1636,7 +1639,7 @@ uint16_t RTPSender::UpdateTransportSequenceNumber(
|
|||||||
size_t rtp_packet_length,
|
size_t rtp_packet_length,
|
||||||
const RTPHeader& rtp_header) const {
|
const RTPHeader& rtp_header) const {
|
||||||
size_t offset;
|
size_t offset;
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
|
|
||||||
switch (VerifyExtension(kRtpExtensionTransportSequenceNumber, rtp_packet,
|
switch (VerifyExtension(kRtpExtensionTransportSequenceNumber, rtp_packet,
|
||||||
rtp_packet_length, rtp_header,
|
rtp_packet_length, rtp_header,
|
||||||
@ -1665,12 +1668,13 @@ void RTPSender::SetSendingStatus(bool enabled) {
|
|||||||
// Will be ignored if it's already configured via API.
|
// Will be ignored if it's already configured via API.
|
||||||
SetStartTimestamp(RTPtime, false);
|
SetStartTimestamp(RTPtime, false);
|
||||||
} else {
|
} else {
|
||||||
CriticalSectionScoped lock(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
if (!ssrc_forced_) {
|
if (!ssrc_forced_) {
|
||||||
// Generate a new SSRC.
|
// Generate a new SSRC.
|
||||||
ssrc_db_.ReturnSSRC(ssrc_);
|
ssrc_db_->ReturnSSRC(ssrc_);
|
||||||
ssrc_ = ssrc_db_.CreateSSRC(); // Can't be 0.
|
ssrc_ = ssrc_db_->CreateSSRC();
|
||||||
bitrates_->set_ssrc(ssrc_);
|
RTC_DCHECK(ssrc_ != 0);
|
||||||
|
bitrates_.set_ssrc(ssrc_);
|
||||||
}
|
}
|
||||||
// Don't initialize seq number if SSRC passed externally.
|
// Don't initialize seq number if SSRC passed externally.
|
||||||
if (!sequence_number_forced_ && !ssrc_forced_) {
|
if (!sequence_number_forced_ && !ssrc_forced_) {
|
||||||
@ -1681,22 +1685,22 @@ void RTPSender::SetSendingStatus(bool enabled) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RTPSender::SetSendingMediaStatus(bool enabled) {
|
void RTPSender::SetSendingMediaStatus(bool enabled) {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
sending_media_ = enabled;
|
sending_media_ = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RTPSender::SendingMedia() const {
|
bool RTPSender::SendingMedia() const {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
return sending_media_;
|
return sending_media_;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t RTPSender::Timestamp() const {
|
uint32_t RTPSender::Timestamp() const {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
return timestamp_;
|
return timestamp_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RTPSender::SetStartTimestamp(uint32_t timestamp, bool force) {
|
void RTPSender::SetStartTimestamp(uint32_t timestamp, bool force) {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
if (force) {
|
if (force) {
|
||||||
start_timestamp_forced_ = true;
|
start_timestamp_forced_ = true;
|
||||||
start_timestamp_ = timestamp;
|
start_timestamp_ = timestamp;
|
||||||
@ -1708,58 +1712,59 @@ void RTPSender::SetStartTimestamp(uint32_t timestamp, bool force) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t RTPSender::StartTimestamp() const {
|
uint32_t RTPSender::StartTimestamp() const {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
return start_timestamp_;
|
return start_timestamp_;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t RTPSender::GenerateNewSSRC() {
|
uint32_t RTPSender::GenerateNewSSRC() {
|
||||||
// If configured via API, return 0.
|
// If configured via API, return 0.
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
|
|
||||||
if (ssrc_forced_) {
|
if (ssrc_forced_) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
ssrc_ = ssrc_db_.CreateSSRC(); // Can't be 0.
|
ssrc_ = ssrc_db_->CreateSSRC();
|
||||||
bitrates_->set_ssrc(ssrc_);
|
RTC_DCHECK(ssrc_ != 0);
|
||||||
|
bitrates_.set_ssrc(ssrc_);
|
||||||
return ssrc_;
|
return ssrc_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RTPSender::SetSSRC(uint32_t ssrc) {
|
void RTPSender::SetSSRC(uint32_t ssrc) {
|
||||||
// This is configured via the API.
|
// This is configured via the API.
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
|
|
||||||
if (ssrc_ == ssrc && ssrc_forced_) {
|
if (ssrc_ == ssrc && ssrc_forced_) {
|
||||||
return; // Since it's same ssrc, don't reset anything.
|
return; // Since it's same ssrc, don't reset anything.
|
||||||
}
|
}
|
||||||
ssrc_forced_ = true;
|
ssrc_forced_ = true;
|
||||||
ssrc_db_.ReturnSSRC(ssrc_);
|
ssrc_db_->ReturnSSRC(ssrc_);
|
||||||
ssrc_db_.RegisterSSRC(ssrc);
|
ssrc_db_->RegisterSSRC(ssrc);
|
||||||
ssrc_ = ssrc;
|
ssrc_ = ssrc;
|
||||||
bitrates_->set_ssrc(ssrc_);
|
bitrates_.set_ssrc(ssrc_);
|
||||||
if (!sequence_number_forced_) {
|
if (!sequence_number_forced_) {
|
||||||
sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber);
|
sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t RTPSender::SSRC() const {
|
uint32_t RTPSender::SSRC() const {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
return ssrc_;
|
return ssrc_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RTPSender::SetCsrcs(const std::vector<uint32_t>& csrcs) {
|
void RTPSender::SetCsrcs(const std::vector<uint32_t>& csrcs) {
|
||||||
assert(csrcs.size() <= kRtpCsrcSize);
|
assert(csrcs.size() <= kRtpCsrcSize);
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
csrcs_ = csrcs;
|
csrcs_ = csrcs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RTPSender::SetSequenceNumber(uint16_t seq) {
|
void RTPSender::SetSequenceNumber(uint16_t seq) {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
sequence_number_forced_ = true;
|
sequence_number_forced_ = true;
|
||||||
sequence_number_ = seq;
|
sequence_number_ = seq;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t RTPSender::SequenceNumber() const {
|
uint16_t RTPSender::SequenceNumber() const {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
return sequence_number_;
|
return sequence_number_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1836,7 +1841,7 @@ int32_t RTPSender::SetFecParameters(
|
|||||||
|
|
||||||
void RTPSender::BuildRtxPacket(uint8_t* buffer, size_t* length,
|
void RTPSender::BuildRtxPacket(uint8_t* buffer, size_t* length,
|
||||||
uint8_t* buffer_rtx) {
|
uint8_t* buffer_rtx) {
|
||||||
CriticalSectionScoped cs(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
uint8_t* data_buffer_rtx = buffer_rtx;
|
uint8_t* data_buffer_rtx = buffer_rtx;
|
||||||
// Add RTX header.
|
// Add RTX header.
|
||||||
RtpUtility::RtpHeaderParser rtp_parser(
|
RtpUtility::RtpHeaderParser rtp_parser(
|
||||||
@ -1890,7 +1895,7 @@ uint32_t RTPSender::BitrateSent() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RTPSender::SetRtpState(const RtpState& rtp_state) {
|
void RTPSender::SetRtpState(const RtpState& rtp_state) {
|
||||||
CriticalSectionScoped lock(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
sequence_number_ = rtp_state.sequence_number;
|
sequence_number_ = rtp_state.sequence_number;
|
||||||
sequence_number_forced_ = true;
|
sequence_number_forced_ = true;
|
||||||
timestamp_ = rtp_state.timestamp;
|
timestamp_ = rtp_state.timestamp;
|
||||||
@ -1900,7 +1905,7 @@ void RTPSender::SetRtpState(const RtpState& rtp_state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RtpState RTPSender::GetRtpState() const {
|
RtpState RTPSender::GetRtpState() const {
|
||||||
CriticalSectionScoped lock(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
|
|
||||||
RtpState state;
|
RtpState state;
|
||||||
state.sequence_number = sequence_number_;
|
state.sequence_number = sequence_number_;
|
||||||
@ -1914,12 +1919,12 @@ RtpState RTPSender::GetRtpState() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RTPSender::SetRtxRtpState(const RtpState& rtp_state) {
|
void RTPSender::SetRtxRtpState(const RtpState& rtp_state) {
|
||||||
CriticalSectionScoped lock(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
sequence_number_rtx_ = rtp_state.sequence_number;
|
sequence_number_rtx_ = rtp_state.sequence_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
RtpState RTPSender::GetRtxRtpState() const {
|
RtpState RTPSender::GetRtxRtpState() const {
|
||||||
CriticalSectionScoped lock(send_critsect_.get());
|
rtc::CritScope lock(&send_critsect_);
|
||||||
|
|
||||||
RtpState state;
|
RtpState state;
|
||||||
state.sequence_number = sequence_number_rtx_;
|
state.sequence_number = sequence_number_rtx_;
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "webrtc/base/criticalsection.h"
|
||||||
#include "webrtc/base/random.h"
|
#include "webrtc/base/random.h"
|
||||||
#include "webrtc/base/thread_annotations.h"
|
#include "webrtc/base/thread_annotations.h"
|
||||||
#include "webrtc/common_types.h"
|
#include "webrtc/common_types.h"
|
||||||
@ -30,8 +31,6 @@
|
|||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
class BitrateAggregator;
|
|
||||||
class CriticalSectionWrapper;
|
|
||||||
class RTPSenderAudio;
|
class RTPSenderAudio;
|
||||||
class RTPSenderVideo;
|
class RTPSenderVideo;
|
||||||
class RtcEventLog;
|
class RtcEventLog;
|
||||||
@ -196,7 +195,7 @@ class RTPSender : public RTPSenderInterface {
|
|||||||
const RTPHeader& rtp_header,
|
const RTPHeader& rtp_header,
|
||||||
size_t extension_length_bytes,
|
size_t extension_length_bytes,
|
||||||
size_t* extension_offset) const
|
size_t* extension_offset) const
|
||||||
EXCLUSIVE_LOCKS_REQUIRED(send_critsect_.get());
|
EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
|
||||||
|
|
||||||
bool UpdateAudioLevel(uint8_t* rtp_packet,
|
bool UpdateAudioLevel(uint8_t* rtp_packet,
|
||||||
size_t rtp_packet_length,
|
size_t rtp_packet_length,
|
||||||
@ -386,22 +385,54 @@ class RTPSender : public RTPSenderInterface {
|
|||||||
bool is_retransmit);
|
bool is_retransmit);
|
||||||
bool IsFecPacket(const uint8_t* buffer, const RTPHeader& header) const;
|
bool IsFecPacket(const uint8_t* buffer, const RTPHeader& header) const;
|
||||||
|
|
||||||
Clock* clock_;
|
class BitrateAggregator {
|
||||||
int64_t clock_delta_ms_;
|
public:
|
||||||
|
explicit BitrateAggregator(BitrateStatisticsObserver* bitrate_callback);
|
||||||
|
|
||||||
|
void OnStatsUpdated() const;
|
||||||
|
|
||||||
|
Bitrate::Observer* total_bitrate_observer();
|
||||||
|
Bitrate::Observer* retransmit_bitrate_observer();
|
||||||
|
void set_ssrc(uint32_t ssrc);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// We assume that these observers are called on the same thread, which is
|
||||||
|
// true for RtpSender as they are called on the Process thread.
|
||||||
|
class BitrateObserver : public Bitrate::Observer {
|
||||||
|
public:
|
||||||
|
explicit BitrateObserver(const BitrateAggregator& aggregator);
|
||||||
|
|
||||||
|
// Implements Bitrate::Observer.
|
||||||
|
void BitrateUpdated(const BitrateStatistics& stats) override;
|
||||||
|
const BitrateStatistics& statistics() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
BitrateStatistics statistics_;
|
||||||
|
const BitrateAggregator& aggregator_;
|
||||||
|
};
|
||||||
|
|
||||||
|
BitrateStatisticsObserver* const callback_;
|
||||||
|
BitrateObserver total_bitrate_observer_;
|
||||||
|
BitrateObserver retransmit_bitrate_observer_;
|
||||||
|
uint32_t ssrc_;
|
||||||
|
};
|
||||||
|
|
||||||
|
Clock* const clock_;
|
||||||
|
const int64_t clock_delta_ms_;
|
||||||
Random random_ GUARDED_BY(send_critsect_);
|
Random random_ GUARDED_BY(send_critsect_);
|
||||||
|
|
||||||
rtc::scoped_ptr<BitrateAggregator> bitrates_;
|
BitrateAggregator bitrates_;
|
||||||
Bitrate total_bitrate_sent_;
|
Bitrate total_bitrate_sent_;
|
||||||
|
|
||||||
const bool audio_configured_;
|
const bool audio_configured_;
|
||||||
rtc::scoped_ptr<RTPSenderAudio> audio_;
|
const rtc::scoped_ptr<RTPSenderAudio> audio_;
|
||||||
rtc::scoped_ptr<RTPSenderVideo> video_;
|
const rtc::scoped_ptr<RTPSenderVideo> video_;
|
||||||
|
|
||||||
RtpPacketSender* const paced_sender_;
|
RtpPacketSender* const paced_sender_;
|
||||||
TransportSequenceNumberAllocator* const transport_sequence_number_allocator_;
|
TransportSequenceNumberAllocator* const transport_sequence_number_allocator_;
|
||||||
TransportFeedbackObserver* const transport_feedback_observer_;
|
TransportFeedbackObserver* const transport_feedback_observer_;
|
||||||
int64_t last_capture_time_ms_sent_;
|
int64_t last_capture_time_ms_sent_;
|
||||||
rtc::scoped_ptr<CriticalSectionWrapper> send_critsect_;
|
rtc::CriticalSection send_critsect_;
|
||||||
|
|
||||||
Transport *transport_;
|
Transport *transport_;
|
||||||
bool sending_media_ GUARDED_BY(send_critsect_);
|
bool sending_media_ GUARDED_BY(send_critsect_);
|
||||||
@ -440,7 +471,7 @@ class RTPSender : public RTPSenderInterface {
|
|||||||
// RTP variables
|
// RTP variables
|
||||||
bool start_timestamp_forced_ GUARDED_BY(send_critsect_);
|
bool start_timestamp_forced_ GUARDED_BY(send_critsect_);
|
||||||
uint32_t start_timestamp_ GUARDED_BY(send_critsect_);
|
uint32_t start_timestamp_ GUARDED_BY(send_critsect_);
|
||||||
SSRCDatabase& ssrc_db_ GUARDED_BY(send_critsect_);
|
SSRCDatabase* const ssrc_db_;
|
||||||
uint32_t remote_ssrc_ GUARDED_BY(send_critsect_);
|
uint32_t remote_ssrc_ GUARDED_BY(send_critsect_);
|
||||||
bool sequence_number_forced_ GUARDED_BY(send_critsect_);
|
bool sequence_number_forced_ GUARDED_BY(send_critsect_);
|
||||||
uint16_t sequence_number_ GUARDED_BY(send_critsect_);
|
uint16_t sequence_number_ GUARDED_BY(send_critsect_);
|
||||||
|
|||||||
@ -11,15 +11,9 @@
|
|||||||
#include "webrtc/modules/rtp_rtcp/source/ssrc_database.h"
|
#include "webrtc/modules/rtp_rtcp/source/ssrc_database.h"
|
||||||
|
|
||||||
#include "webrtc/base/checks.h"
|
#include "webrtc/base/checks.h"
|
||||||
#include "webrtc/system_wrappers/include/clock.h"
|
#include "webrtc/system_wrappers/include/tick_util.h"
|
||||||
#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
|
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace {
|
|
||||||
uint64_t Seed() {
|
|
||||||
return Clock::GetRealTimeClock()->TimeInMicroseconds();
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
SSRCDatabase* SSRCDatabase::GetSSRCDatabase() {
|
SSRCDatabase* SSRCDatabase::GetSSRCDatabase() {
|
||||||
return GetStaticInstance<SSRCDatabase>(kAddRef);
|
return GetStaticInstance<SSRCDatabase>(kAddRef);
|
||||||
@ -30,7 +24,7 @@ void SSRCDatabase::ReturnSSRCDatabase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t SSRCDatabase::CreateSSRC() {
|
uint32_t SSRCDatabase::CreateSSRC() {
|
||||||
CriticalSectionScoped lock(crit_.get());
|
rtc::CritScope lock(&crit_);
|
||||||
|
|
||||||
while (true) { // Try until get a new ssrc.
|
while (true) { // Try until get a new ssrc.
|
||||||
// 0 and 0xffffffff are invalid values for SSRC.
|
// 0 and 0xffffffff are invalid values for SSRC.
|
||||||
@ -42,19 +36,17 @@ uint32_t SSRCDatabase::CreateSSRC() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SSRCDatabase::RegisterSSRC(uint32_t ssrc) {
|
void SSRCDatabase::RegisterSSRC(uint32_t ssrc) {
|
||||||
CriticalSectionScoped lock(crit_.get());
|
rtc::CritScope lock(&crit_);
|
||||||
ssrcs_.insert(ssrc);
|
ssrcs_.insert(ssrc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSRCDatabase::ReturnSSRC(uint32_t ssrc) {
|
void SSRCDatabase::ReturnSSRC(uint32_t ssrc) {
|
||||||
CriticalSectionScoped lock(crit_.get());
|
rtc::CritScope lock(&crit_);
|
||||||
ssrcs_.erase(ssrc);
|
ssrcs_.erase(ssrc);
|
||||||
}
|
}
|
||||||
|
|
||||||
SSRCDatabase::SSRCDatabase()
|
SSRCDatabase::SSRCDatabase() : random_(TickTime::Now().Ticks()) {}
|
||||||
: crit_(CriticalSectionWrapper::CreateCriticalSection()), random_(Seed()) {}
|
|
||||||
|
|
||||||
SSRCDatabase::~SSRCDatabase() {
|
SSRCDatabase::~SSRCDatabase() {}
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|||||||
@ -13,14 +13,21 @@
|
|||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
|
#include "webrtc/base/criticalsection.h"
|
||||||
#include "webrtc/base/random.h"
|
#include "webrtc/base/random.h"
|
||||||
#include "webrtc/base/scoped_ptr.h"
|
#include "webrtc/base/thread_annotations.h"
|
||||||
#include "webrtc/system_wrappers/include/static_instance.h"
|
#include "webrtc/system_wrappers/include/static_instance.h"
|
||||||
#include "webrtc/typedefs.h"
|
#include "webrtc/typedefs.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
class CriticalSectionWrapper;
|
|
||||||
|
|
||||||
|
// TODO(tommi, holmer): Look into whether we can eliminate locking in this
|
||||||
|
// class or the class itself completely once voice engine doesn't rely on it.
|
||||||
|
// At the moment voe_auto_test requires locking, but it's not clear if that's
|
||||||
|
// an issue with the test code or if it reflects real world usage or if that's
|
||||||
|
// the best design performance wise.
|
||||||
|
// If we do decide to keep the class, we should at least get rid of using
|
||||||
|
// StaticInstance.
|
||||||
class SSRCDatabase {
|
class SSRCDatabase {
|
||||||
public:
|
public:
|
||||||
static SSRCDatabase* GetSSRCDatabase();
|
static SSRCDatabase* GetSSRCDatabase();
|
||||||
@ -32,19 +39,23 @@ class SSRCDatabase {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
SSRCDatabase();
|
SSRCDatabase();
|
||||||
virtual ~SSRCDatabase();
|
~SSRCDatabase();
|
||||||
|
|
||||||
static SSRCDatabase* CreateInstance() { return new SSRCDatabase(); }
|
static SSRCDatabase* CreateInstance() { return new SSRCDatabase(); }
|
||||||
|
|
||||||
private:
|
|
||||||
// Friend function to allow the SSRC destructor to be accessed from the
|
// Friend function to allow the SSRC destructor to be accessed from the
|
||||||
// template class.
|
// template class.
|
||||||
friend SSRCDatabase* GetStaticInstance<SSRCDatabase>(
|
friend SSRCDatabase* GetStaticInstance<SSRCDatabase>(
|
||||||
CountOperation count_operation);
|
CountOperation count_operation);
|
||||||
|
|
||||||
rtc::scoped_ptr<CriticalSectionWrapper> crit_;
|
private:
|
||||||
|
rtc::CriticalSection crit_;
|
||||||
Random random_ GUARDED_BY(crit_);
|
Random random_ GUARDED_BY(crit_);
|
||||||
std::set<uint32_t> ssrcs_ GUARDED_BY(crit_);
|
std::set<uint32_t> ssrcs_ GUARDED_BY(crit_);
|
||||||
|
// TODO(tommi): Use a thread checker to ensure the object is created and
|
||||||
|
// deleted on the same thread. At the moment this isn't possible due to
|
||||||
|
// voe::ChannelOwner in voice engine. To reproduce, run:
|
||||||
|
// voe_auto_test --automated --gtest_filter=*MixManyChannelsForStressOpus
|
||||||
};
|
};
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user