| 363 | } |
| 364 | |
| 365 | void RdApplication::InitAudioCapture() { |
| 366 | if (settings_->capture_.capture_audio_type_ != Capture::CaptureAudioType::kAudioGlobal) { |
| 367 | return; |
| 368 | } |
| 369 | |
| 370 | audio_capture_plugin_ = plugin_manager_->GetAudioCapturePlugin(); |
| 371 | audio_encoder_plugin_ = plugin_manager_->GetAudioEncoderPlugin(); |
| 372 | if (!audio_capture_plugin_ || !audio_encoder_plugin_) { |
| 373 | return; |
| 374 | } |
| 375 | |
| 376 | msg_listener_->Listen<CaptureAudioFrame>([=, this] (const CaptureAudioFrame& frame) { |
| 377 | if (!HasConnectedPeer()) { |
| 378 | return; |
| 379 | } |
| 380 | |
| 381 | int samples = (int)frame.samples_; |
| 382 | int channels = (int)frame.channels_; |
| 383 | int bits = (int)frame.bits_; |
| 384 | |
| 385 | if (frame.full_data_) { |
| 386 | audio_encoder_plugin_->Encode(frame.full_data_, samples, channels, bits); |
| 387 | |
| 388 | auto stat = RdStatistics::Instance(); |
| 389 | stat->audio_samples_ = samples; |
| 390 | stat->audio_channels_ = channels; |
| 391 | stat->audio_bits_ = bits; |
| 392 | |
| 393 | // plugins |
| 394 | { |
| 395 | auto data = frame.full_data_; |
| 396 | context_->PostStreamPluginTask([=, this]() { |
| 397 | plugin_manager_->VisitStreamPlugins([=, this](GrStreamPlugin *plugin) { |
| 398 | plugin->OnRawAudioData(data, samples, channels, bits); |
| 399 | }); |
| 400 | }); |
| 401 | } |
| 402 | // statistics |
| 403 | { |
| 404 | auto current_time = TimeUtil::GetCurrentTimestamp(); |
| 405 | if (last_post_audio_time_ == 0) { |
| 406 | last_post_audio_time_ = current_time; |
| 407 | } |
| 408 | auto diff = current_time - last_post_audio_time_; |
| 409 | last_post_audio_time_ = current_time; |
| 410 | statistics_->AppendAudioFrameGap(diff); |
| 411 | } |
| 412 | } |
| 413 | else if (frame.left_ch_data_ && frame.right_ch_data_) { |
| 414 | PostGlobalTask([=, this]() { |
| 415 | auto bytes = 960; |
| 416 | auto single_bytes = bytes/2; |
| 417 | if (fft_left_.size() != single_bytes) { |
| 418 | fft_left_.resize(single_bytes); |
| 419 | } |
| 420 | if (fft_right_.size() != single_bytes) { |
| 421 | fft_right_.resize(single_bytes); |
| 422 | } |
nothing calls this directly
no test coverage detected