| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 } else { | 632 } else { |
| 633 if (process_thread_) { | 633 if (process_thread_) { |
| 634 process_thread_->Stop(); | 634 process_thread_->Stop(); |
| 635 process_thread_.reset(nullptr); | 635 process_thread_.reset(nullptr); |
| 636 } | 636 } |
| 637 started_ = false; | 637 started_ = false; |
| 638 } | 638 } |
| 639 } | 639 } |
| 640 | 640 |
| 641 void FakeAudioCaptureModule::StartProcessP() { | 641 void FakeAudioCaptureModule::StartProcessP() { |
| 642 ASSERT(process_thread_->IsCurrent()); | 642 RTC_CHECK(process_thread_->IsCurrent()); |
| 643 if (started_) { | 643 if (started_) { |
| 644 // Already started. | 644 // Already started. |
| 645 return; | 645 return; |
| 646 } | 646 } |
| 647 ProcessFrameP(); | 647 ProcessFrameP(); |
| 648 } | 648 } |
| 649 | 649 |
| 650 void FakeAudioCaptureModule::ProcessFrameP() { | 650 void FakeAudioCaptureModule::ProcessFrameP() { |
| 651 ASSERT(process_thread_->IsCurrent()); | 651 RTC_CHECK(process_thread_->IsCurrent()); |
| 652 if (!started_) { | 652 if (!started_) { |
| 653 next_frame_time_ = rtc::TimeMillis(); | 653 next_frame_time_ = rtc::TimeMillis(); |
| 654 started_ = true; | 654 started_ = true; |
| 655 } | 655 } |
| 656 | 656 |
| 657 { | 657 { |
| 658 rtc::CritScope cs(&crit_); | 658 rtc::CritScope cs(&crit_); |
| 659 // Receive and send frames every kTimePerFrameMs. | 659 // Receive and send frames every kTimePerFrameMs. |
| 660 if (playing_) { | 660 if (playing_) { |
| 661 ReceiveFrameP(); | 661 ReceiveFrameP(); |
| 662 } | 662 } |
| 663 if (recording_) { | 663 if (recording_) { |
| 664 SendFrameP(); | 664 SendFrameP(); |
| 665 } | 665 } |
| 666 } | 666 } |
| 667 | 667 |
| 668 next_frame_time_ += kTimePerFrameMs; | 668 next_frame_time_ += kTimePerFrameMs; |
| 669 const int64_t current_time = rtc::TimeMillis(); | 669 const int64_t current_time = rtc::TimeMillis(); |
| 670 const int64_t wait_time = | 670 const int64_t wait_time = |
| 671 (next_frame_time_ > current_time) ? next_frame_time_ - current_time : 0; | 671 (next_frame_time_ > current_time) ? next_frame_time_ - current_time : 0; |
| 672 process_thread_->PostDelayed(RTC_FROM_HERE, wait_time, this, MSG_RUN_PROCESS); | 672 process_thread_->PostDelayed(RTC_FROM_HERE, wait_time, this, MSG_RUN_PROCESS); |
| 673 } | 673 } |
| 674 | 674 |
| 675 void FakeAudioCaptureModule::ReceiveFrameP() { | 675 void FakeAudioCaptureModule::ReceiveFrameP() { |
| 676 ASSERT(process_thread_->IsCurrent()); | 676 RTC_CHECK(process_thread_->IsCurrent()); |
| 677 { | 677 { |
| 678 rtc::CritScope cs(&crit_callback_); | 678 rtc::CritScope cs(&crit_callback_); |
| 679 if (!audio_callback_) { | 679 if (!audio_callback_) { |
| 680 return; | 680 return; |
| 681 } | 681 } |
| 682 ResetRecBuffer(); | 682 ResetRecBuffer(); |
| 683 size_t nSamplesOut = 0; | 683 size_t nSamplesOut = 0; |
| 684 int64_t elapsed_time_ms = 0; | 684 int64_t elapsed_time_ms = 0; |
| 685 int64_t ntp_time_ms = 0; | 685 int64_t ntp_time_ms = 0; |
| 686 if (audio_callback_->NeedMorePlayData(kNumberSamples, kNumberBytesPerSample, | 686 if (audio_callback_->NeedMorePlayData(kNumberSamples, kNumberBytesPerSample, |
| 687 kNumberOfChannels, kSamplesPerSecond, | 687 kNumberOfChannels, kSamplesPerSecond, |
| 688 rec_buffer_, nSamplesOut, | 688 rec_buffer_, nSamplesOut, |
| 689 &elapsed_time_ms, &ntp_time_ms) != 0) { | 689 &elapsed_time_ms, &ntp_time_ms) != 0) { |
| 690 RTC_NOTREACHED(); | 690 RTC_NOTREACHED(); |
| 691 } | 691 } |
| 692 ASSERT(nSamplesOut == kNumberSamples); | 692 RTC_CHECK(nSamplesOut == kNumberSamples); |
| 693 } | 693 } |
| 694 // The SetBuffer() function ensures that after decoding, the audio buffer | 694 // The SetBuffer() function ensures that after decoding, the audio buffer |
| 695 // should contain samples of similar magnitude (there is likely to be some | 695 // should contain samples of similar magnitude (there is likely to be some |
| 696 // distortion due to the audio pipeline). If one sample is detected to | 696 // distortion due to the audio pipeline). If one sample is detected to |
| 697 // have the same or greater magnitude somewhere in the frame, an actual frame | 697 // have the same or greater magnitude somewhere in the frame, an actual frame |
| 698 // has been received from the remote side (i.e. faked frames are not being | 698 // has been received from the remote side (i.e. faked frames are not being |
| 699 // pulled). | 699 // pulled). |
| 700 if (CheckRecBuffer(kHighSampleValue)) { | 700 if (CheckRecBuffer(kHighSampleValue)) { |
| 701 rtc::CritScope cs(&crit_); | 701 rtc::CritScope cs(&crit_); |
| 702 ++frames_received_; | 702 ++frames_received_; |
| 703 } | 703 } |
| 704 } | 704 } |
| 705 | 705 |
| 706 void FakeAudioCaptureModule::SendFrameP() { | 706 void FakeAudioCaptureModule::SendFrameP() { |
| 707 ASSERT(process_thread_->IsCurrent()); | 707 RTC_CHECK(process_thread_->IsCurrent()); |
| 708 rtc::CritScope cs(&crit_callback_); | 708 rtc::CritScope cs(&crit_callback_); |
| 709 if (!audio_callback_) { | 709 if (!audio_callback_) { |
| 710 return; | 710 return; |
| 711 } | 711 } |
| 712 bool key_pressed = false; | 712 bool key_pressed = false; |
| 713 uint32_t current_mic_level = 0; | 713 uint32_t current_mic_level = 0; |
| 714 MicrophoneVolume(¤t_mic_level); | 714 MicrophoneVolume(¤t_mic_level); |
| 715 if (audio_callback_->RecordedDataIsAvailable(send_buffer_, kNumberSamples, | 715 if (audio_callback_->RecordedDataIsAvailable(send_buffer_, kNumberSamples, |
| 716 kNumberBytesPerSample, | 716 kNumberBytesPerSample, |
| 717 kNumberOfChannels, | 717 kNumberOfChannels, |
| 718 kSamplesPerSecond, kTotalDelayMs, | 718 kSamplesPerSecond, kTotalDelayMs, |
| 719 kClockDriftMs, current_mic_level, | 719 kClockDriftMs, current_mic_level, |
| 720 key_pressed, | 720 key_pressed, |
| 721 current_mic_level) != 0) { | 721 current_mic_level) != 0) { |
| 722 RTC_NOTREACHED(); | 722 RTC_NOTREACHED(); |
| 723 } | 723 } |
| 724 SetMicrophoneVolume(current_mic_level); | 724 SetMicrophoneVolume(current_mic_level); |
| 725 } | 725 } |
| OLD | NEW |