Move simple RtpRtcp calls to VideoSendStream.

Moves RtpRtcp module pointers into VideoSendStream and uses them for
simple calls that were only forwarded by ViEChannel.

BUG=webrtc:5494
R=stefan@webrtc.org

Review URL: https://codereview.webrtc.org/1693553002 .

Cr-Commit-Position: refs/heads/master@{#11709}
This commit is contained in:
Peter Boström 2016-02-22 15:14:01 +01:00
parent 2e67ae1222
commit 723ead844b
5 changed files with 59 additions and 167 deletions

View File

@ -179,7 +179,7 @@ VideoReceiveStream::VideoReceiveStream(
false),
vie_receiver_(vie_channel_.vie_receiver()),
vie_sync_(vcm_.get()),
rtp_rtcp_(vie_channel_.rtp_rtcp()) {
rtp_rtcp_(vie_channel_.rtp_rtcp().front()) {
LOG(LS_INFO) << "VideoReceiveStream: " << config_.ToString();
RTC_DCHECK(process_thread_);

View File

@ -197,6 +197,7 @@ VideoSendStream::VideoSendStream(
&payload_router_,
bitrate_allocator),
vcm_(vie_encoder_.vcm()),
rtp_rtcp_modules_(vie_channel_.rtp_rtcp()),
input_(&vie_encoder_,
config_.local_renderer,
&stats_proxy_,
@ -236,9 +237,8 @@ VideoSendStream::VideoSendStream(
}
}
RtpRtcp* rtp_module = vie_channel_.rtp_rtcp();
remb_->AddRembSender(rtp_module);
rtp_module->SetREMBStatus(true);
remb_->AddRembSender(rtp_rtcp_modules_[0]);
rtp_rtcp_modules_[0]->SetREMBStatus(true);
// Enable NACK, FEC or both.
const bool enable_protection_nack = config_.rtp.nack.rtp_history_ms > 0;
@ -257,18 +257,25 @@ VideoSendStream::VideoSendStream(
}
// TODO(changbin): Should set RTX for RED mapping in RTP sender in future.
vie_channel_.SetProtectionMode(enable_protection_nack, enable_protection_fec,
config_.rtp.fec.red_payload_type,
config_.rtp.fec.ulpfec_payload_type);
config_.rtp.fec.red_payload_type,
config_.rtp.fec.ulpfec_payload_type);
vie_encoder_.SetProtectionMethod(enable_protection_nack,
enable_protection_fec);
enable_protection_fec);
ConfigureSsrcs();
vie_channel_.SetRTCPCName(config_.rtp.c_name.c_str());
// TODO(pbos): Should we set CNAME on all RTP modules?
rtp_rtcp_modules_.front()->SetCNAME(config_.rtp.c_name.c_str());
// 28 to match packet overhead in ModuleRtpRtcpImpl.
RTC_DCHECK_LE(config_.rtp.max_packet_size, static_cast<size_t>(0xFFFF - 28));
vie_channel_.SetMTU(static_cast<uint16_t>(config_.rtp.max_packet_size + 28));
static const size_t kRtpPacketSizeOverhead = 28;
RTC_DCHECK_LE(config_.rtp.max_packet_size, 0xFFFFu + kRtpPacketSizeOverhead);
const uint16_t mtu = static_cast<uint16_t>(config_.rtp.max_packet_size +
kRtpPacketSizeOverhead);
for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) {
rtp_rtcp->RegisterRtcpStatisticsCallback(&stats_proxy_);
rtp_rtcp->RegisterSendChannelRtpStatisticsCallback(&stats_proxy_);
rtp_rtcp->SetMaxTransferUnit(mtu);
}
RTC_DCHECK(config.encoder_settings.encoder != nullptr);
RTC_DCHECK_GE(config.encoder_settings.payload_type, 0);
@ -288,8 +295,6 @@ VideoSendStream::VideoSendStream(
if (config_.suspend_below_min_bitrate)
vie_encoder_.SuspendBelowMinBitrate();
vie_channel_.RegisterSendChannelRtcpStatisticsCallback(&stats_proxy_);
vie_channel_.RegisterSendChannelRtpStatisticsCallback(&stats_proxy_);
vie_channel_.RegisterRtcpPacketTypeCounterObserver(&stats_proxy_);
vie_channel_.RegisterSendBitrateObserver(&stats_proxy_);
vie_channel_.RegisterSendFrameCountObserver(&stats_proxy_);
@ -305,17 +310,12 @@ VideoSendStream::~VideoSendStream() {
vie_channel_.RegisterSendFrameCountObserver(nullptr);
vie_channel_.RegisterSendBitrateObserver(nullptr);
vie_channel_.RegisterRtcpPacketTypeCounterObserver(nullptr);
vie_channel_.RegisterSendChannelRtpStatisticsCallback(nullptr);
vie_channel_.RegisterSendChannelRtcpStatisticsCallback(nullptr);
vie_encoder_.DeRegisterExternalEncoder(
config_.encoder_settings.payload_type);
vie_encoder_.DeRegisterExternalEncoder(config_.encoder_settings.payload_type);
call_stats_->DeregisterStatsObserver(vie_channel_.GetStatsObserver());
RtpRtcp* rtp_module = vie_channel_.rtp_rtcp();
rtp_module->SetREMBStatus(false);
remb_->RemoveRembSender(rtp_module);
rtp_rtcp_modules_[0]->SetREMBStatus(false);
remb_->RemoveRembSender(rtp_rtcp_modules_[0]);
// ViEChannel outlives ViEEncoder so remove encoder from feedback before
// destruction.
@ -509,38 +509,46 @@ void VideoSendStream::NormalUsage() {
}
void VideoSendStream::ConfigureSsrcs() {
vie_channel_.SetSSRC(config_.rtp.ssrcs.front(), kViEStreamTypeNormal, 0);
// Configure regular SSRCs.
for (size_t i = 0; i < config_.rtp.ssrcs.size(); ++i) {
uint32_t ssrc = config_.rtp.ssrcs[i];
vie_channel_.SetSSRC(ssrc, kViEStreamTypeNormal,
static_cast<unsigned char>(i));
RtpRtcp* const rtp_rtcp = rtp_rtcp_modules_[i];
rtp_rtcp->SetSSRC(ssrc);
// Restore RTP state if previous existed.
RtpStateMap::iterator it = suspended_ssrcs_.find(ssrc);
if (it != suspended_ssrcs_.end())
vie_channel_.SetRtpStateForSsrc(ssrc, it->second);
rtp_rtcp->SetRtpStateForSsrc(ssrc, it->second);
}
if (config_.rtp.rtx.ssrcs.empty()) {
// Set up RTX if available.
if (config_.rtp.rtx.ssrcs.empty())
return;
}
// Set up RTX.
// Configure RTX SSRCs.
RTC_DCHECK_EQ(config_.rtp.rtx.ssrcs.size(), config_.rtp.ssrcs.size());
for (size_t i = 0; i < config_.rtp.rtx.ssrcs.size(); ++i) {
uint32_t ssrc = config_.rtp.rtx.ssrcs[i];
vie_channel_.SetSSRC(config_.rtp.rtx.ssrcs[i], kViEStreamTypeRtx,
static_cast<unsigned char>(i));
RtpRtcp* const rtp_rtcp = rtp_rtcp_modules_[i];
rtp_rtcp->SetRtxSsrc(ssrc);
RtpStateMap::iterator it = suspended_ssrcs_.find(ssrc);
if (it != suspended_ssrcs_.end())
vie_channel_.SetRtpStateForSsrc(ssrc, it->second);
rtp_rtcp->SetRtpStateForSsrc(ssrc, it->second);
}
// Configure RTX payload types.
RTC_DCHECK_GE(config_.rtp.rtx.payload_type, 0);
vie_channel_.SetRtxSendPayloadType(config_.rtp.rtx.payload_type,
config_.encoder_settings.payload_type);
for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) {
rtp_rtcp->SetRtxSendPayloadType(config_.rtp.rtx.payload_type,
config_.encoder_settings.payload_type);
rtp_rtcp->SetRtxSendStatus(kRtxRetransmitted | kRtxRedundantPayloads);
}
if (config_.rtp.fec.red_payload_type != -1 &&
config_.rtp.fec.red_rtx_payload_type != -1) {
vie_channel_.SetRtxSendPayloadType(config_.rtp.fec.red_rtx_payload_type,
config_.rtp.fec.red_payload_type);
for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) {
rtp_rtcp->SetRtxSendPayloadType(config_.rtp.fec.red_rtx_payload_type,
config_.rtp.fec.red_payload_type);
}
}
}
@ -563,11 +571,15 @@ void VideoSendStream::SignalNetworkState(NetworkState state) {
// When network goes up, enable RTCP status before setting transmission state.
// When it goes down, disable RTCP afterwards. This ensures that any packets
// sent due to the network state changed will not be dropped.
if (state == kNetworkUp)
vie_channel_.SetRTCPMode(config_.rtp.rtcp_mode);
if (state == kNetworkUp) {
for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_)
rtp_rtcp->SetRTCPStatus(config_.rtp.rtcp_mode);
}
vie_encoder_.SetNetworkTransmissionState(state == kNetworkUp);
if (state == kNetworkDown)
vie_channel_.SetRTCPMode(RtcpMode::kOff);
if (state == kNetworkDown) {
for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_)
rtp_rtcp->SetRTCPStatus(RtcpMode::kOff);
}
}
int VideoSendStream::GetPaddingNeededBps() const {

View File

@ -16,7 +16,6 @@
#include "webrtc/call.h"
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "webrtc/video/encoded_frame_callback_adapter.h"
#include "webrtc/video/encoder_state_feedback.h"
#include "webrtc/video/payload_router.h"
@ -33,6 +32,7 @@ class BitrateAllocator;
class CallStats;
class CongestionController;
class ProcessThread;
class RtpRtcp;
class ViEChannel;
class ViEEncoder;
class VieRemb;
@ -96,6 +96,10 @@ class VideoSendStream : public webrtc::VideoSendStream,
ViEReceiver* const vie_receiver_;
ViEEncoder vie_encoder_;
VideoCodingModule* const vcm_;
// TODO(pbos): Move RtpRtcp ownership to VideoSendStream.
// RtpRtcp modules, currently owned by ViEChannel but ownership should
// eventually move here.
const std::vector<RtpRtcp*> rtp_rtcp_modules_;
VideoCaptureInput input_;
};
} // namespace internal

View File

@ -378,12 +378,6 @@ int32_t ViEChannel::SetSendCodec(const VideoCodec& video_codec,
return 0;
}
void ViEChannel::SetRTCPMode(const RtcpMode rtcp_mode) {
RTC_DCHECK(sender_);
for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_)
rtp_rtcp->SetRTCPStatus(rtcp_mode);
}
void ViEChannel::SetProtectionMode(bool enable_nack,
bool enable_fec,
int payload_type_red,
@ -453,19 +447,6 @@ void ViEChannel::ProcessNACKRequest(const bool enable) {
}
}
bool ViEChannel::IsSendingFecEnabled() {
bool fec_enabled = false;
uint8_t pltype_red = 0;
uint8_t pltype_fec = 0;
for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) {
rtp_rtcp->GenericFECStatus(&fec_enabled, &pltype_red, &pltype_fec);
if (fec_enabled)
return true;
}
return false;
}
int ViEChannel::GetRequiredNackListSize(int target_delay_ms) {
// The max size of the nack list should be large enough to accommodate the
// the number of packets (frames) resulting from the increased delay.
@ -538,49 +519,6 @@ int ViEChannel::SetSendTransportSequenceNumber(bool enable, int id) {
return error;
}
int32_t ViEChannel::SetSSRC(const uint32_t SSRC,
const StreamType usage,
const uint8_t simulcast_idx) {
RTC_DCHECK(sender_);
RtpRtcp* rtp_rtcp = rtp_rtcp_modules_[simulcast_idx];
if (usage == kViEStreamTypeRtx) {
rtp_rtcp->SetRtxSsrc(SSRC);
} else {
rtp_rtcp->SetSSRC(SSRC);
}
return 0;
}
int32_t ViEChannel::GetLocalSSRC(uint8_t idx, unsigned int* ssrc) {
RTC_DCHECK_LE(idx, rtp_rtcp_modules_.size());
*ssrc = rtp_rtcp_modules_[idx]->SSRC();
return 0;
}
int ViEChannel::SetRtxSendPayloadType(int payload_type,
int associated_payload_type) {
RTC_DCHECK(sender_);
for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_)
rtp_rtcp->SetRtxSendPayloadType(payload_type, associated_payload_type);
SetRtxSendStatus(true);
return 0;
}
void ViEChannel::SetRtxSendStatus(bool enable) {
int rtx_settings =
enable ? kRtxRetransmitted | kRtxRedundantPayloads : kRtxOff;
for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_)
rtp_rtcp->SetRtxSendStatus(rtx_settings);
}
void ViEChannel::SetRtpStateForSsrc(uint32_t ssrc, const RtpState& rtp_state) {
RTC_DCHECK(!rtp_rtcp_modules_[0]->Sending());
for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) {
if (rtp_rtcp->SetRtpStateForSsrc(ssrc, rtp_state))
return;
}
}
RtpState ViEChannel::GetRtpStateForSsrc(uint32_t ssrc) const {
RTC_DCHECK(!rtp_rtcp_modules_[0]->Sending());
RtpState rtp_state;
@ -592,23 +530,6 @@ RtpState ViEChannel::GetRtpStateForSsrc(uint32_t ssrc) const {
return rtp_state;
}
// TODO(pbos): Set CNAME on all modules.
int32_t ViEChannel::SetRTCPCName(const char* rtcp_cname) {
RTC_DCHECK(!rtp_rtcp_modules_[0]->Sending());
return rtp_rtcp_modules_[0]->SetCNAME(rtcp_cname);
}
int32_t ViEChannel::GetRemoteRTCPCName(char rtcp_cname[]) {
uint32_t remoteSSRC = vie_receiver_.GetRemoteSsrc();
return rtp_rtcp_modules_[0]->RemoteCNAME(remoteSSRC, rtcp_cname);
}
void ViEChannel::RegisterSendChannelRtcpStatisticsCallback(
RtcpStatisticsCallback* callback) {
for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_)
rtp_rtcp->RegisterRtcpStatisticsCallback(callback);
}
void ViEChannel::RegisterRtcpPacketTypeCounterObserver(
RtcpPacketTypeCounterObserver* observer) {
rtcp_packet_type_counter_observer_.Set(observer);
@ -646,12 +567,6 @@ void ViEChannel::GetReceiveStreamDataCounters(
}
}
void ViEChannel::RegisterSendChannelRtpStatisticsCallback(
StreamDataCountersCallback* callback) {
for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_)
rtp_rtcp->RegisterSendChannelRtpStatisticsCallback(callback);
}
void ViEChannel::GetSendRtcpPacketTypeCounter(
RtcpPacketTypeCounter* packet_counter) const {
std::map<uint32_t, RtcpPacketTypeCounter> counter_map =
@ -717,15 +632,8 @@ int32_t ViEChannel::StopSend() {
return 0;
}
int32_t ViEChannel::SetMTU(uint16_t mtu) {
RTC_DCHECK(sender_);
for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_)
rtp_rtcp->SetMaxTransferUnit(mtu);
return 0;
}
RtpRtcp* ViEChannel::rtp_rtcp() {
return rtp_rtcp_modules_[0];
const std::vector<RtpRtcp*>& ViEChannel::rtp_rtcp() const {
return rtp_rtcp_modules_;
}
ViEReceiver* ViEChannel::vie_receiver() {

View File

@ -84,40 +84,17 @@ class ViEChannel : public VCMFrameTypeCallback,
// type has changed and we should start a new RTP stream.
int32_t SetSendCodec(const VideoCodec& video_codec, bool new_stream = true);
void SetRTCPMode(const RtcpMode rtcp_mode);
void SetProtectionMode(bool enable_nack,
bool enable_fec,
int payload_type_red,
int payload_type_fec);
bool IsSendingFecEnabled();
int SetSendTimestampOffsetStatus(bool enable, int id);
int SetSendAbsoluteSendTimeStatus(bool enable, int id);
int SetSendVideoRotationStatus(bool enable, int id);
int SetSendTransportSequenceNumber(bool enable, int id);
// Sets SSRC for outgoing stream.
int32_t SetSSRC(const uint32_t SSRC,
const StreamType usage,
const unsigned char simulcast_idx);
// Gets SSRC for outgoing stream number |idx|.
int32_t GetLocalSSRC(uint8_t idx, unsigned int* ssrc);
int SetRtxSendPayloadType(int payload_type, int associated_payload_type);
void SetRtpStateForSsrc(uint32_t ssrc, const RtpState& rtp_state);
RtpState GetRtpStateForSsrc(uint32_t ssrc) const;
// Sets the CName for the outgoing stream on the channel.
int32_t SetRTCPCName(const char* rtcp_cname);
// Gets the CName of the incoming stream.
int32_t GetRemoteRTCPCName(char rtcp_cname[]);
// Called on receipt of RTCP report block from remote side.
void RegisterSendChannelRtcpStatisticsCallback(
RtcpStatisticsCallback* callback);
// Gets send statistics for the rtp and rtx stream.
void GetSendStreamDataCounters(StreamDataCounters* rtp_counters,
StreamDataCounters* rtx_counters) const;
@ -126,10 +103,6 @@ class ViEChannel : public VCMFrameTypeCallback,
void GetReceiveStreamDataCounters(StreamDataCounters* rtp_counters,
StreamDataCounters* rtx_counters) const;
// Called on update of RTP statistics.
void RegisterSendChannelRtpStatisticsCallback(
StreamDataCountersCallback* callback);
void GetSendRtcpPacketTypeCounter(
RtcpPacketTypeCounter* packet_counter) const;
@ -153,12 +126,8 @@ class ViEChannel : public VCMFrameTypeCallback,
int32_t StartSend();
int32_t StopSend();
// Sets the maximum transfer unit size for the network link, i.e. including
// IP, UDP and RTP headers.
int32_t SetMTU(uint16_t mtu);
// Gets the modules used by the channel.
RtpRtcp* rtp_rtcp();
const std::vector<RtpRtcp*>& rtp_rtcp() const;
ViEReceiver* vie_receiver();
VCMProtectionCallback* vcm_protection_callback();
@ -244,7 +213,6 @@ class ViEChannel : public VCMFrameTypeCallback,
void ProcessNACKRequest(const bool enable);
// Compute NACK list parameters for the buffering mode.
int GetRequiredNackListSize(int target_delay_ms);
void SetRtxSendStatus(bool enable);
void UpdateHistograms();