VCM: Setting buffering delay in timing
Review URL: https://webrtc-codereview.appspot.com/1338004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3921 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
dd807ac474
commit
6faba6edc9
@ -793,9 +793,9 @@ VCMFrameBufferEnum VCMJitterBuffer::InsertPacket(VCMEncodedFrame* encoded_frame,
|
||||
return ret;
|
||||
}
|
||||
|
||||
void VCMJitterBuffer::SetMaxJitterEstimate(uint32_t initial_delay_ms) {
|
||||
void VCMJitterBuffer::SetMaxJitterEstimate(bool enable) {
|
||||
CriticalSectionScoped cs(crit_sect_);
|
||||
jitter_estimate_.SetMaxJitterEstimate(initial_delay_ms);
|
||||
jitter_estimate_.SetMaxJitterEstimate(enable);
|
||||
}
|
||||
|
||||
uint32_t VCMJitterBuffer::EstimatedJitterMs() {
|
||||
|
@ -135,7 +135,7 @@ class VCMJitterBuffer {
|
||||
// Enable a max filter on the jitter estimate by setting an initial
|
||||
// non-zero delay. When set to zero (default), the last jitter
|
||||
// estimate will be used.
|
||||
void SetMaxJitterEstimate(uint32_t initial_delay_ms);
|
||||
void SetMaxJitterEstimate(bool enable);
|
||||
|
||||
// Returns the estimated jitter in milliseconds.
|
||||
uint32_t EstimatedJitterMs();
|
||||
|
@ -177,12 +177,9 @@ TEST_F(TestRunningJitterBuffer, JitterEstimateMode) {
|
||||
InsertFrame(kVideoFrameDelta);
|
||||
EXPECT_FALSE(request_key_frame);
|
||||
EXPECT_GT(20u, jitter_buffer_->EstimatedJitterMs());
|
||||
// Set kMaxEstimate with a 2 seconds initial delay.
|
||||
jitter_buffer_->SetMaxJitterEstimate(2000u);
|
||||
EXPECT_EQ(2000u, jitter_buffer_->EstimatedJitterMs());
|
||||
jitter_buffer_->SetMaxJitterEstimate(true);
|
||||
InsertFrame(kVideoFrameDelta);
|
||||
EXPECT_FALSE(request_key_frame);
|
||||
EXPECT_EQ(2000u, jitter_buffer_->EstimatedJitterMs());
|
||||
// Jitter cannot decrease.
|
||||
InsertFrames(2, kVideoFrameDelta);
|
||||
EXPECT_FALSE(request_key_frame);
|
||||
|
@ -20,8 +20,6 @@
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
enum { kInitialMaxJitterEstimate = 0 };
|
||||
|
||||
VCMJitterEstimator::VCMJitterEstimator(int32_t vcmId, int32_t receiverId) :
|
||||
_vcmId(vcmId),
|
||||
_receiverId(receiverId),
|
||||
@ -37,7 +35,7 @@ _noiseStdDevs(2.33), // ~Less than 1% chance
|
||||
_noiseStdDevOffset(30.0), // ...of getting 30 ms freezes
|
||||
_rttFilter(vcmId, receiverId),
|
||||
_jitterEstimateMode(kLastEstimate),
|
||||
_maxJitterEstimateMs(kInitialMaxJitterEstimate)
|
||||
_maxJitterEstimateMs(0)
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
@ -407,15 +405,12 @@ VCMJitterEstimator::UpdateMaxFrameSize(uint32_t frameSizeBytes)
|
||||
}
|
||||
}
|
||||
|
||||
void VCMJitterEstimator::SetMaxJitterEstimate(uint32_t initial_delay_ms)
|
||||
{
|
||||
if (initial_delay_ms > 0) {
|
||||
_maxJitterEstimateMs = initial_delay_ms;
|
||||
_jitterEstimateMode = kMaxEstimate;
|
||||
} else {
|
||||
_maxJitterEstimateMs = kInitialMaxJitterEstimate;
|
||||
_jitterEstimateMode = kLastEstimate;
|
||||
}
|
||||
void VCMJitterEstimator::SetMaxJitterEstimate(bool enable) {
|
||||
if (enable) {
|
||||
_jitterEstimateMode = kMaxEstimate;
|
||||
} else {
|
||||
_jitterEstimateMode = kLastEstimate;
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the current filtered estimate if available,
|
||||
|
@ -64,10 +64,9 @@ public:
|
||||
|
||||
void UpdateMaxFrameSize(uint32_t frameSizeBytes);
|
||||
|
||||
// Set a max filter on the jitter estimate by setting an initial
|
||||
// non-zero delay. When set to zero (default), the last jitter
|
||||
// estimate will be used.
|
||||
void SetMaxJitterEstimate(uint32_t initial_delay_ms);
|
||||
// Set a max filter on the jitter estimate. When disabled (default), the
|
||||
// last jitter estimate will be used.
|
||||
void SetMaxJitterEstimate(bool enable);
|
||||
|
||||
// A constant describing the delay from the jitter buffer
|
||||
// to the delay on the receiving side which is not accounted
|
||||
|
@ -430,11 +430,11 @@ int VCMReceiver::SetMinReceiverDelay(int desired_delay_ms) {
|
||||
if (desired_delay_ms < 0 || desired_delay_ms > kMaxReceiverDelayMs) {
|
||||
return -1;
|
||||
}
|
||||
jitter_buffer_.SetMaxJitterEstimate(desired_delay_ms);
|
||||
// Enable a max filter on the jitter estimate for non-zero delays.
|
||||
jitter_buffer_.SetMaxJitterEstimate(desired_delay_ms > 0);
|
||||
max_video_delay_ms_ = desired_delay_ms + kMaxVideoDelayMs;
|
||||
timing_->SetMaxVideoDelay(max_video_delay_ms_);
|
||||
// Initializing timing to the desired delay.
|
||||
timing_->SetRequiredDelay(desired_delay_ms);
|
||||
timing_->SetMinimumTotalDelay(desired_delay_ms);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -120,12 +120,6 @@ void VCMTiming::UpdateCurrentDelay(uint32_t frameTimestamp)
|
||||
CriticalSectionScoped cs(_critSect);
|
||||
uint32_t targetDelayMs = TargetDelayInternal();
|
||||
|
||||
// Make sure we try to sync with audio
|
||||
if (targetDelayMs < _minTotalDelayMs)
|
||||
{
|
||||
targetDelayMs = _minTotalDelayMs;
|
||||
}
|
||||
|
||||
if (_currentDelayMs == 0)
|
||||
{
|
||||
// Not initialized, set current delay to target.
|
||||
@ -159,14 +153,9 @@ void VCMTiming::UpdateCurrentDelay(uint32_t frameTimestamp)
|
||||
// to reordering and should be ignored.
|
||||
return;
|
||||
}
|
||||
else if (delayDiffMs < -maxChangeMs)
|
||||
{
|
||||
delayDiffMs = -maxChangeMs;
|
||||
}
|
||||
else if (delayDiffMs > maxChangeMs)
|
||||
{
|
||||
delayDiffMs = maxChangeMs;
|
||||
}
|
||||
delayDiffMs = std::max(delayDiffMs, -maxChangeMs);
|
||||
delayDiffMs = std::min(delayDiffMs, maxChangeMs);
|
||||
|
||||
_currentDelayMs = _currentDelayMs + static_cast<int32_t>(delayDiffMs);
|
||||
}
|
||||
_prevFrameTimestamp = frameTimestamp;
|
||||
@ -177,18 +166,14 @@ void VCMTiming::UpdateCurrentDelay(int64_t renderTimeMs,
|
||||
{
|
||||
CriticalSectionScoped cs(_critSect);
|
||||
uint32_t targetDelayMs = TargetDelayInternal();
|
||||
// Make sure we try to sync with audio
|
||||
if (targetDelayMs < _minTotalDelayMs)
|
||||
{
|
||||
targetDelayMs = _minTotalDelayMs;
|
||||
}
|
||||
|
||||
int64_t delayedMs = actualDecodeTimeMs -
|
||||
(renderTimeMs - MaxDecodeTimeMs() - _renderDelayMs);
|
||||
if (delayedMs < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (_currentDelayMs + delayedMs <= targetDelayMs)
|
||||
if (_currentDelayMs + delayedMs <= targetDelayMs)
|
||||
{
|
||||
_currentDelayMs += static_cast<uint32_t>(delayedMs);
|
||||
}
|
||||
@ -274,7 +259,10 @@ VCMTiming::RenderTimeMsInternal(uint32_t frameTimestamp, int64_t nowMs) const
|
||||
{
|
||||
estimatedCompleteTimeMs = nowMs;
|
||||
}
|
||||
return estimatedCompleteTimeMs + _currentDelayMs;
|
||||
|
||||
// Make sure that we have at least the total minimum delay.
|
||||
uint32_t actual_delay = std::max(_currentDelayMs, _minTotalDelayMs);
|
||||
return estimatedCompleteTimeMs + actual_delay;
|
||||
}
|
||||
|
||||
// Must be called from inside a critical section
|
||||
|
Loading…
Reference in New Issue
Block a user