webrtc-m79-音频相关 internal::Call 中的 config_.audio_state 的来源

1 代码

std::unique_ptr<Call> PeerConnectionFactory::CreateCall_w(
    RtcEventLog* event_log) {
  RTC_DCHECK_RUN_ON(worker_thread_);

  webrtc::Call::Config call_config(event_log);
  if (!channel_manager_->media_engine() || !call_factory_) {
    return nullptr;
  }
  call_config.audio_state =
      channel_manager_->media_engine()->voice().GetAudioState(); // 注意这里

  FieldTrialParameter<DataRate> min_bandwidth("min", DataRate::kbps(30));
  FieldTrialParameter<DataRate> start_bandwidth("start", DataRate::kbps(300));
  FieldTrialParameter<DataRate> max_bandwidth("max", DataRate::kbps(2000));
  ParseFieldTrial({&min_bandwidth, &start_bandwidth, &max_bandwidth},
                  field_trial::FindFullName("WebRTC-PcFactoryDefaultBitrates"));

  call_config.bitrate_config.min_bitrate_bps =
      rtc::saturated_cast<int>(min_bandwidth->bps());
  call_config.bitrate_config.start_bitrate_bps =
      rtc::saturated_cast<int>(start_bandwidth->bps());
  call_config.bitrate_config.max_bitrate_bps =
      rtc::saturated_cast<int>(max_bandwidth->bps());

  call_config.fec_controller_factory = fec_controller_factory_.get();
  call_config.task_queue_factory = task_queue_factory_.get();
  call_config.network_state_predictor_factory =
      network_state_predictor_factory_.get();

  if (field_trial::IsEnabled("WebRTC-Bwe-InjectedCongestionController")) {
    RTC_LOG(LS_INFO) << "Using injected network controller factory";
    call_config.network_controller_factory =
        injected_network_controller_factory_.get();
  } else {
    RTC_LOG(LS_INFO) << "Using default network controller factory";
  }

  return std::unique_ptr<Call>(call_factory_->CreateCall(call_config)); //注意这里
}



					void WebRtcVoiceEngine::Init() {
					  RTC_DCHECK(worker_thread_checker_.IsCurrent());
					  RTC_LOG(LS_INFO) << "WebRtcVoiceEngine::Init";
					
					  // TaskQueue expects to be created/destroyed on the same thread.
					  low_priority_worker_queue_.reset(
					      new rtc::TaskQueue(task_queue_factory_->CreateTaskQueue(
					          "rtc-low-prio", webrtc::TaskQueueFactory::Priority::LOW)));
					
					  // Load our audio codec lists.
					  RTC_LOG(LS_INFO) << "Supported send codecs in order of preference:";
					  send_codecs_ = CollectCodecs(encoder_factory_->GetSupportedEncoders());
					  for (const AudioCodec& codec : send_codecs_) {
					    RTC_LOG(LS_INFO) << ToString(codec);
					  }
					
					  RTC_LOG(LS_INFO) << "Supported recv codecs in order of preference:";
					  recv_codecs_ = CollectCodecs(decoder_factory_->GetSupportedDecoders());
					  for (const AudioCodec& codec : recv_codecs_) {
					    RTC_LOG(LS_INFO) << ToString(codec);
					  }
					
					#if defined(WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE)
					  // No ADM supplied? Create a default one.
					  if (!adm_) {
					    adm_ = webrtc::AudioDeviceModule::Create( // 返回的是指向 webrtc::AudioDeviceModuleImpl 的智能指针
					        webrtc::AudioDeviceModule::kPlatformDefaultAudio, task_queue_factory_);
					  }
					#endif  // WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE
					  RTC_CHECK(adm());
					  webrtc::adm_helpers::Init(adm());
					  webrtc::apm_helpers::Init(apm());
					
					  // Set up AudioState.
					  {
					    webrtc::AudioState::Config config;
					    if (audio_mixer_) {
					      config.audio_mixer = audio_mixer_;
					    } else {
					      config.audio_mixer = webrtc::AudioMixerImpl::Create();// 
					    }
					    config.audio_processing = apm_;
					    config.audio_device_module = adm_; // 
					    audio_state_ = webrtc::AudioState::Create(config); // AudioState::Create 返回的是指向 webrtc::internal::AudioState 的智能指针
					  }
					
					  // Connect the ADM to our audio path.
					  adm()->RegisterAudioCallback(audio_state()->audio_transport());
					
					  // Set default engine options.
					  {
					    AudioOptions options;
					    options.echo_cancellation = true;
					    options.auto_gain_control = true;
					    options.noise_suppression = true;
					    options.highpass_filter = true;
					    options.stereo_swapping = false;
					    options.audio_jitter_buffer_max_packets = 200;
					    options.audio_jitter_buffer_fast_accelerate = false;
					    options.audio_jitter_buffer_min_delay_ms = 0;
					    options.audio_jitter_buffer_enable_rtx_handling = false;
					    options.typing_detection = true;
					    options.experimental_agc = false;
					    options.experimental_ns = false;
					    options.residual_echo_detector = true;
					    bool error = ApplyOptions(options);
					    RTC_DCHECK(error);
					  }
					
					  initialized_ = true;
					}
					
	
						rtc::scoped_refptr<AudioMixerImpl> AudioMixerImpl::Create() {
					  return Create(std::unique_ptr<DefaultOutputRateCalculator>(
					                    new DefaultOutputRateCalculator()),
					                true);
					}
					
					rtc::scoped_refptr<AudioMixerImpl> AudioMixerImpl::Create(
					    std::unique_ptr<OutputRateCalculator> output_rate_calculator,
					    bool use_limiter) {
					  return rtc::scoped_refptr<AudioMixerImpl>( //注意这里
					      new rtc::RefCountedObject<AudioMixerImpl>(
					          std::move(output_rate_calculator), use_limiter));
					}				
					
					
					
					rtc::scoped_refptr<AudioState> AudioState::Create(
					    const AudioState::Config& config) {
					  return new rtc::RefCountedObject<internal::AudioState>(config); // 
					}


					rtc::scoped_refptr<webrtc::AudioState> WebRtcVoiceEngine::GetAudioState()
					    const {
					  RTC_DCHECK(worker_thread_checker_.IsCurrent());
					  return audio_state_;// rtc::scoped_refptr<webrtc::AudioState> audio_state_
					} // audio_state_ 实际上指向的是 webrtc::internal::AudioState 




Call* CallFactory::CreateCall(const Call::Config& config) {
  absl::optional<webrtc::BuiltInNetworkBehaviorConfig> send_degradation_config =
      ParseDegradationConfig(true);
  absl::optional<webrtc::BuiltInNetworkBehaviorConfig>
      receive_degradation_config = ParseDegradationConfig(false);

  if (send_degradation_config || receive_degradation_config) {
    return new DegradedCall(std::unique_ptr<Call>(Call::Create(config)),
                            send_degradation_config, receive_degradation_config,
                            config.task_queue_factory);
  }

  return Call::Create(config); //
}


Call* Call::Create(const Call::Config& config) {
  return Create(config, Clock::GetRealTimeClock(),
                ProcessThread::Create("ModuleProcessThread"),
                ProcessThread::Create("PacerThread"));
}


Call* Call::Create(const Call::Config& config,
                   Clock* clock,
                   std::unique_ptr<ProcessThread> call_thread,
                   std::unique_ptr<ProcessThread> pacer_thread) {
  RTC_DCHECK(config.task_queue_factory);
  return new internal::Call(
      clock, config, // 将 config 传递进去
      std::make_unique<RtpTransportControllerSend>(
          clock, config.event_log, config.network_state_predictor_factory,
          config.network_controller_factory, config.bitrate_config,
          std::move(pacer_thread), config.task_queue_factory),
      std::move(call_thread), config.task_queue_factory);
}


Call::Call(Clock* clock,
           const Call::Config& config, // 
           std::unique_ptr<RtpTransportControllerSendInterface> transport_send,
           std::unique_ptr<ProcessThread> module_process_thread,
           TaskQueueFactory* task_queue_factory)
    : clock_(clock),
      task_queue_factory_(task_queue_factory),
      num_cpu_cores_(CpuInfo::DetectNumberOfCores()),
      module_process_thread_(std::move(module_process_thread)),
      call_stats_(new CallStats(clock_, module_process_thread_.get())),
      bitrate_allocator_(new BitrateAllocator(this)),
      config_(config), //
      audio_network_state_(kNetworkDown),
      video_network_state_(kNetworkDown),
      aggregate_network_up_(false),
      receive_crit_(RWLockWrapper::CreateRWLock()),
      send_crit_(RWLockWrapper::CreateRWLock()),
      event_log_(config.event_log),
      received_bytes_per_second_counter_(clock_, nullptr, true),
      received_audio_bytes_per_second_counter_(clock_, nullptr, true),
      received_video_bytes_per_second_counter_(clock_, nullptr, true),
      received_rtcp_bytes_per_second_counter_(clock_, nullptr, true),
      last_bandwidth_bps_(0),
      min_allocated_send_bitrate_bps_(0),
      configured_max_padding_bitrate_bps_(0),
      estimated_send_bitrate_kbps_counter_(clock_, nullptr, true),
      pacer_bitrate_kbps_counter_(clock_, nullptr, true),
      receive_side_cc_(clock_, transport_send->packet_router()),
      receive_time_calculator_(ReceiveTimeCalculator::CreateFromFieldTrial()),
      video_send_delay_stats_(new SendDelayStats(clock_)),
      start_ms_(clock_->TimeInMilliseconds()),
      transport_send_ptr_(transport_send.get()),
      transport_send_(std::move(transport_send)) {
  RTC_DCHECK(config.event_log != nullptr);
  worker_sequence_checker_.Detach();

  call_stats_->RegisterStatsObserver(&receive_side_cc_);

  module_process_thread_->RegisterModule(
      receive_side_cc_.GetRemoteBitrateEstimator(true), RTC_FROM_HERE);
  module_process_thread_->RegisterModule(call_stats_.get(), RTC_FROM_HERE);
  module_process_thread_->RegisterModule(&receive_side_cc_, RTC_FROM_HERE);
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值