Auto instantiate RBE depending on whether AST or TOF is available in incoming packet stream.

BUG=
R=mflodman@webrtc.org, stefan@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/5409004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@5293 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
solenberg@webrtc.org
2013-12-13 23:57:54 +00:00
parent e1bc6c8d8b
commit 341e91441a
19 changed files with 412 additions and 105 deletions

View File

@ -92,7 +92,6 @@ ViEChannel::ViEChannel(int32_t channel_id,
bandwidth_observer_(bandwidth_observer),
send_timestamp_extension_id_(kInvalidRtpExtensionId),
absolute_send_time_extension_id_(kInvalidRtpExtensionId),
receive_absolute_send_time_enabled_(false),
external_transport_(NULL),
decoder_reset_(true),
wait_for_key_frame_(false),
@ -934,14 +933,9 @@ int ViEChannel::SetSendAbsoluteSendTimeStatus(bool enable, int id) {
}
int ViEChannel::SetReceiveAbsoluteSendTimeStatus(bool enable, int id) {
receive_absolute_send_time_enabled_ = enable;
return vie_receiver_.SetReceiveAbsoluteSendTimeStatus(enable, id) ? 0 : -1;
}
bool ViEChannel::GetReceiveAbsoluteSendTimeStatus() const {
return receive_absolute_send_time_enabled_;
}
void ViEChannel::SetRtcpXrRrtrStatus(bool enable) {
CriticalSectionScoped cs(rtp_rtcp_cs_.get());
rtp_rtcp_->SetRtcpXrRrtrStatus(enable);

View File

@ -396,7 +396,6 @@ class ViEChannel
scoped_ptr<RtcpBandwidthObserver> bandwidth_observer_;
int send_timestamp_extension_id_;
int absolute_send_time_extension_id_;
bool receive_absolute_send_time_enabled_;
bool using_packet_spread_;
Transport* external_transport_;

View File

@ -16,6 +16,7 @@
#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
#include "webrtc/modules/utility/interface/process_thread.h"
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
#include "webrtc/system_wrappers/interface/trace.h"
#include "webrtc/video_engine/call_stats.h"
#include "webrtc/video_engine/encoder_state_feedback.h"
#include "webrtc/video_engine/vie_channel.h"
@ -25,18 +26,22 @@
namespace webrtc {
namespace {
static const uint32_t kTimeOffsetSwitchThreshold = 30;
class WrappingBitrateEstimator : public RemoteBitrateEstimator {
public:
WrappingBitrateEstimator(RemoteBitrateObserver* observer, Clock* clock,
ProcessThread* process_thread)
WrappingBitrateEstimator(int engine_id, RemoteBitrateObserver* observer,
Clock* clock, ProcessThread* process_thread)
: observer_(observer),
clock_(clock),
process_thread_(process_thread),
crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
engine_id_(engine_id),
min_bitrate_bps_(30000),
rbe_(RemoteBitrateEstimatorFactory().Create(observer_, clock_,
min_bitrate_bps_)),
receive_absolute_send_time_(false) {
using_absolute_send_time_(false),
packets_since_absolute_send_time_(0) {
assert(process_thread_ != NULL);
process_thread_->RegisterModule(rbe_.get());
}
@ -44,29 +49,11 @@ class WrappingBitrateEstimator : public RemoteBitrateEstimator {
process_thread_->DeRegisterModule(rbe_.get());
}
void SetReceiveAbsoluteSendTimeStatus(bool enable) {
CriticalSectionScoped cs(crit_sect_.get());
if (enable == receive_absolute_send_time_) {
return;
}
process_thread_->DeRegisterModule(rbe_.get());
if (enable) {
rbe_.reset(AbsoluteSendTimeRemoteBitrateEstimatorFactory().Create(
observer_, clock_, min_bitrate_bps_));
} else {
rbe_.reset(RemoteBitrateEstimatorFactory().Create(observer_, clock_,
min_bitrate_bps_));
}
process_thread_->RegisterModule(rbe_.get());
receive_absolute_send_time_ = enable;
}
virtual void IncomingPacket(int64_t arrival_time_ms,
int payload_size,
const RTPHeader& header) {
CriticalSectionScoped cs(crit_sect_.get());
PickEstimator(header);
rbe_->IncomingPacket(arrival_time_ms, payload_size, header);
}
@ -97,25 +84,60 @@ class WrappingBitrateEstimator : public RemoteBitrateEstimator {
}
private:
// Instantiate RBE for Time Offset or Absolute Send Time extensions.
void PickEstimator(const RTPHeader& header) {
if (header.extension.hasAbsoluteSendTime) {
// If we see AST in header, switch RBE strategy immediately.
if (!using_absolute_send_time_) {
process_thread_->DeRegisterModule(rbe_.get());
WEBRTC_TRACE(kTraceStateInfo, kTraceVideo, ViEId(engine_id_),
"WrappingBitrateEstimator: Switching to absolute send time RBE.");
rbe_.reset(AbsoluteSendTimeRemoteBitrateEstimatorFactory().Create(
observer_, clock_, min_bitrate_bps_));
process_thread_->RegisterModule(rbe_.get());
using_absolute_send_time_ = true;
}
packets_since_absolute_send_time_ = 0;
} else {
// When we don't see AST, wait for a few packets before going back to TOF.
if (using_absolute_send_time_) {
++packets_since_absolute_send_time_;
if (packets_since_absolute_send_time_ >= kTimeOffsetSwitchThreshold) {
process_thread_->DeRegisterModule(rbe_.get());
WEBRTC_TRACE(kTraceStateInfo, kTraceVideo, ViEId(engine_id_),
"WrappingBitrateEstimator: Switching to transmission time offset "
"RBE.");
rbe_.reset(RemoteBitrateEstimatorFactory().Create(observer_, clock_,
min_bitrate_bps_));
process_thread_->RegisterModule(rbe_.get());
using_absolute_send_time_ = false;
}
}
}
}
RemoteBitrateObserver* observer_;
Clock* clock_;
ProcessThread* process_thread_;
scoped_ptr<CriticalSectionWrapper> crit_sect_;
const int engine_id_;
const uint32_t min_bitrate_bps_;
scoped_ptr<RemoteBitrateEstimator> rbe_;
bool receive_absolute_send_time_;
bool using_absolute_send_time_;
uint32_t packets_since_absolute_send_time_;
DISALLOW_IMPLICIT_CONSTRUCTORS(WrappingBitrateEstimator);
};
} // namespace
ChannelGroup::ChannelGroup(ProcessThread* process_thread,
ChannelGroup::ChannelGroup(int engine_id, ProcessThread* process_thread,
const Config& config)
: remb_(new VieRemb()),
bitrate_controller_(BitrateController::CreateBitrateController(true)),
call_stats_(new CallStats()),
remote_bitrate_estimator_(new WrappingBitrateEstimator(remb_.get(),
Clock::GetRealTimeClock(), process_thread)),
remote_bitrate_estimator_(new WrappingBitrateEstimator(engine_id,
remb_.get(), Clock::GetRealTimeClock(),
process_thread)),
encoder_state_feedback_(new EncoderStateFeedback()),
process_thread_(process_thread) {
call_stats_->RegisterStatsObserver(remote_bitrate_estimator_.get());
@ -186,9 +208,4 @@ bool ChannelGroup::SetChannelRembStatus(int channel_id, bool sender,
}
return true;
}
void ChannelGroup::SetReceiveAbsoluteSendTimeStatus(bool enable) {
static_cast<WrappingBitrateEstimator*>(remote_bitrate_estimator_.get())->
SetReceiveAbsoluteSendTimeStatus(enable);
}
} // namespace webrtc

View File

@ -31,7 +31,7 @@ class VieRemb;
// group are assumed to send/receive data to the same end-point.
class ChannelGroup {
public:
ChannelGroup(ProcessThread* process_thread,
ChannelGroup(int engine_id, ProcessThread* process_thread,
const Config& config);
~ChannelGroup();
@ -42,7 +42,6 @@ class ChannelGroup {
bool SetChannelRembStatus(int channel_id, bool sender, bool receiver,
ViEChannel* channel);
void SetReceiveAbsoluteSendTimeStatus(bool enable);
BitrateController* GetBitrateController();
CallStats* GetCallStats();

View File

@ -89,7 +89,7 @@ int ViEChannelManager::CreateChannel(int* channel_id) {
}
// Create a new channel group and add this channel.
ChannelGroup* group = new ChannelGroup(module_process_thread_,
ChannelGroup* group = new ChannelGroup(engine_id_, module_process_thread_,
config_);
BitrateController* bitrate_controller = group->GetBitrateController();
ViEEncoder* vie_encoder = new ViEEncoder(engine_id_, new_channel_id,
@ -366,35 +366,6 @@ bool ViEChannelManager::SetRembStatus(int channel_id, bool sender,
return group->SetChannelRembStatus(channel_id, sender, receiver, channel);
}
bool ViEChannelManager::SetReceiveAbsoluteSendTimeStatus(int channel_id,
bool enable,
int id) {
CriticalSectionScoped cs(channel_id_critsect_);
ViEChannel* channel = ViEChannelPtr(channel_id);
if (!channel) {
return false;
}
if (channel->SetReceiveAbsoluteSendTimeStatus(enable, id) != 0) {
return false;
}
// Enable absolute send time extension on the group if at least one of the
// channels use it.
ChannelGroup* group = FindGroup(channel_id);
assert(group);
bool any_enabled = false;
for (ChannelMap::const_iterator c_it = channel_map_.begin();
c_it != channel_map_.end(); ++c_it) {
if (group->HasChannel(c_it->first) &&
c_it->second->GetReceiveAbsoluteSendTimeStatus()) {
any_enabled = true;
break;
}
}
group->SetReceiveAbsoluteSendTimeStatus(any_enabled);
return true;
}
void ViEChannelManager::UpdateSsrcs(int channel_id,
const std::list<unsigned int>& ssrcs) {
CriticalSectionScoped cs(channel_id_critsect_);

View File

@ -74,10 +74,6 @@ class ViEChannelManager: private ViEManagerBase {
// Adds a channel to include when sending REMB.
bool SetRembStatus(int channel_id, bool sender, bool receiver);
// Switches a channel and its associated group to use (or not) the absolute
// send time header extension with |id|.
bool SetReceiveAbsoluteSendTimeStatus(int channel_id, bool enable, int id);
// Updates the SSRCs for a channel. If one of the SSRCs already is registered,
// it will simply be ignored and no error is returned.
void UpdateSsrcs(int channel_id, const std::list<unsigned int>& ssrcs);

View File

@ -796,8 +796,16 @@ int ViERTP_RTCPImpl::SetReceiveAbsoluteSendTimeStatus(int video_channel,
ViEId(shared_data_->instance_id(), video_channel),
"ViERTP_RTCPImpl::SetReceiveAbsoluteSendTimeStatus(%d, %d, %d)",
video_channel, enable, id);
if (!shared_data_->channel_manager()->SetReceiveAbsoluteSendTimeStatus(
video_channel, enable, id)) {
ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
ViEChannel* vie_channel = cs.Channel(video_channel);
if (!vie_channel) {
WEBRTC_TRACE(kTraceError, kTraceVideo,
ViEId(shared_data_->instance_id(), video_channel),
"%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
return -1;
}
if (vie_channel->SetReceiveAbsoluteSendTimeStatus(enable, id) != 0) {
shared_data_->SetLastError(kViERtpRtcpUnknownError);
return -1;
}