1.为了平滑渲染,造成延时
FrameBuffer::StartWaitForNextFrameOnQueue()
|
FrameBuffer::FindNextFrame
在FindNextFrame里面有计算渲染时间
if (frame->RenderTime() == -1) {
frame->SetRenderTime(timing_->RenderTimeMs(frame->Timestamp(), now_ms));
}
int64_t VCMTiming::RenderTimeMsInternal(uint32_t frame_timestamp,
int64_t now_ms) const {
constexpr int kLowLatencyRendererMaxPlayoutDelayMs = 500;
if (min_playout_delay_ms_ == 0 &&
(max_playout_delay_ms_ == 0 ||
(low_latency_renderer_enabled_ &&
max_playout_delay_ms_ <= kLowLatencyRendererMaxPlayoutDelayMs))) {
// Render as soon as possible or with low-latency renderer algorithm.
return 0;
}
// Note that TimestampExtrapolator::ExtrapolateLocalTime is not a const
// method; it mutates the object's wraparound state.
int64_t estimated_complete_time_ms =
ts_extrapolator_->ExtrapolateLocalTime(frame_timestamp);
if (estimated_complete_time_ms == -1) {
estimated_complete_time_ms = now_ms;
}
// Make sure the actual delay stays in the range of `min_playout_delay_ms_`
// and `max_playout_delay_ms_`.
int actual_delay = std::max(current_delay_ms_, min_playout_delay_ms_);
actual_delay = std::min(actual_delay, max_playout_delay_ms_);
return estimated_complete_time_ms + actual_delay;
}
一帧视频的预期渲染时间是发送端发送时间+网络延时时间+解码时间+渲染模块耗时时间
发送端发送时间:可以根据发送报文的时间戳+接收第一帧视频的系统时间推算出来。
- 但是我们注意到一个条件:
- (low_latency_renderer_enabled_ &&
max_playout_delay_ms_ <= kLowLatencyRendererMaxPlayoutDelayMs)
低延时渲染,并且最大延时设置小于低延时阀。
我们来对比一下,在非低延时和低延时情况,其他条件相同
经过公网服务器传输,非低延时情况是 120ms 延时
经过公网服务器传输,低延时情况是 40ms 延时