webrtc视频卡顿分析-编码发送

编码流程伪代码

TaskQueue::ProcessQueuedMessages
{
	ViEEncoder::EncodeTask::Run
	{
    	if (--vie_encoder_->posted_frames_waiting_for_encode_ == 0) //可能丢帧,编码不及时
    	{
    		ViEEncoder::EncodeVideoFrame
			{
				    pre_encode_callback_->OnFrame(video_frame); //本地渲染
				    if (pending_encoder_reconfiguration_)
				    {
    					ReconfigureEncoder();  //初始化编码器
 					 }
 					 if (EncoderPaused()) 
 					 {
   						TraceFrameDropStart();  //丢帧,带宽检测,超出后丢帧
  					 	return;
					 }
				 	VideoSender::AddVideoFrame //编码
				 	{
				 		if (_mediaOpt.DropFrame())    //丢帧,
				 		{
							_encoder->OnDroppedFrame();
   							return VCM_OK;
						}
						VCMGenericEncoder::Encode
						{
							H264EncoderImpl::Encode//执行编码
							{
								encoder_params.bEnableFrameSkip //编码器设置时,允许丢帧
							}
						}
				 	}
				 }
			}
    	}
	}
}

主要有几个丢帧的地方
1、在编码线程刚刚开始执行的时候, 如果因为线程处理能力受限导致的堆积,会丢帧
if (–vie_encoder_->posted_frames_waiting_for_encode_ == 0)

2、在ViEEncoder::EncodeVideoFrame中, if (EncoderPaused()) 丢帧

bool ViEEncoder::EncoderPaused() const
{
  RTC_DCHECK_RUN_ON(&encoder_queue_);
  // Pause video if paused by caller or as long as the network is down or the
  // pacer queue has grown too large in buffered mode.
  // If the pacer queue has grown too large or the network is down,
  // last_observed_bitrate_bps_ will be 0.
  return last_observed_bitrate_bps_ == 0;
}

3、在VideoSender::AddVideoFrame 中, if (_mediaOpt.DropFrame()) 丢帧

4、编码的时候编码器设置时,openh264允许丢帧encoder_params.bEnableFrameSkip

你可能感兴趣的:(webrtc)