欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

WebRTC研究:sending_

程序员文章站 2022-07-01 17:35:56
...

RTCPSender.sending_ 默认为 false,即当前为接收端:

RTCPSender::RTCPSender(
    bool audio,
    Clock* clock,
    ReceiveStatistics* receive_statistics,
    RtcpPacketTypeCounterObserver* packet_type_counter_observer,
    RtcEventLog* event_log,
    Transport* outgoing_transport)
    :sending_(false),
    ...
    ...
    ...
{
  ...
  ...
  ...
}

当调用 AudioSendStream::Start() 时,sending_ 会变成 true,表示当前为发送端:

void AudioSendStream::Start() 
{
  RTC_DCHECK(thread_checker_.CalledOnValidThread());
  ScopedVoEInterface<VoEBase> base(voice_engine());
  
  //开始发送
  int error = base->StartSend(config_.voe_channel_id);
  if (error != 0) 
  {
    LOG(LS_ERROR) << "AudioSendStream::Start failed with error: " << error;
  }
}

当调用 AudioSendStream::Stop()、亦或者删除 / 销毁 Channel,sending_ 会变成 false,表示当前为接收端:

void AudioSendStream::Stop() 
{
  RTC_DCHECK(thread_checker_.CalledOnValidThread());
  ScopedVoEInterface<VoEBase> base(voice_engine());

  // 停止发送
  int error = base->StopSend(config_.voe_channel_id);
  if (error != 0) 
  {
    LOG(LS_ERROR) << "AudioSendStream::Stop failed with error: " << error;
  }
}