| OLD | NEW |
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 static const int kTimePerFrameMs = 10; | 47 static const int kTimePerFrameMs = 10; |
| 48 static const uint8_t kNumberOfChannels = 1; | 48 static const uint8_t kNumberOfChannels = 1; |
| 49 static const int kSamplesPerSecond = 44000; | 49 static const int kSamplesPerSecond = 44000; |
| 50 static const int kTotalDelayMs = 0; | 50 static const int kTotalDelayMs = 0; |
| 51 static const int kClockDriftMs = 0; | 51 static const int kClockDriftMs = 0; |
| 52 static const uint32_t kMaxVolume = 14392; | 52 static const uint32_t kMaxVolume = 14392; |
| 53 | 53 |
| 54 enum { | 54 enum { |
| 55 MSG_START_PROCESS, | 55 MSG_START_PROCESS, |
| 56 MSG_RUN_PROCESS, | 56 MSG_RUN_PROCESS, |
| 57 MSG_STOP_PROCESS, | |
| 58 }; | 57 }; |
| 59 | 58 |
| 60 FakeAudioCaptureModule::FakeAudioCaptureModule( | 59 FakeAudioCaptureModule::FakeAudioCaptureModule( |
| 61 rtc::Thread* process_thread) | 60 rtc::Thread* process_thread) |
| 62 : last_process_time_ms_(0), | 61 : last_process_time_ms_(0), |
| 63 audio_callback_(NULL), | 62 audio_callback_(NULL), |
| 64 recording_(false), | 63 recording_(false), |
| 65 playing_(false), | 64 playing_(false), |
| 66 play_is_initialized_(false), | 65 play_is_initialized_(false), |
| 67 rec_is_initialized_(false), | 66 rec_is_initialized_(false), |
| 68 current_mic_level_(kMaxVolume), | 67 current_mic_level_(kMaxVolume), |
| 69 started_(false), | 68 started_(false), |
| 70 next_frame_time_(0), | 69 next_frame_time_(0), |
| 71 process_thread_(process_thread), | 70 process_thread_(process_thread), |
| 72 frames_received_(0) { | 71 frames_received_(0) { |
| 73 } | 72 } |
| 74 | 73 |
| 75 FakeAudioCaptureModule::~FakeAudioCaptureModule() { | 74 FakeAudioCaptureModule::~FakeAudioCaptureModule() { |
| 76 // Ensure that thread stops calling ProcessFrame(). | 75 // Ensure that thread stops calling ProcessFrame(). |
| 77 process_thread_->Send(this, MSG_STOP_PROCESS); | 76 process_thread_->Clear(this); |
| 78 } | 77 } |
| 79 | 78 |
| 80 rtc::scoped_refptr<FakeAudioCaptureModule> FakeAudioCaptureModule::Create( | 79 rtc::scoped_refptr<FakeAudioCaptureModule> FakeAudioCaptureModule::Create( |
| 81 rtc::Thread* process_thread) { | 80 rtc::Thread* process_thread) { |
| 82 if (process_thread == NULL) return NULL; | 81 if (process_thread == NULL) return NULL; |
| 83 | 82 |
| 84 rtc::scoped_refptr<FakeAudioCaptureModule> capture_module( | 83 rtc::scoped_refptr<FakeAudioCaptureModule> capture_module( |
| 85 new rtc::RefCountedObject<FakeAudioCaptureModule>(process_thread)); | 84 new rtc::RefCountedObject<FakeAudioCaptureModule>(process_thread)); |
| 86 if (!capture_module->Initialize()) { | 85 if (!capture_module->Initialize()) { |
| 87 return NULL; | 86 return NULL; |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 } | 593 } |
| 595 | 594 |
| 596 void FakeAudioCaptureModule::OnMessage(rtc::Message* msg) { | 595 void FakeAudioCaptureModule::OnMessage(rtc::Message* msg) { |
| 597 switch (msg->message_id) { | 596 switch (msg->message_id) { |
| 598 case MSG_START_PROCESS: | 597 case MSG_START_PROCESS: |
| 599 StartProcessP(); | 598 StartProcessP(); |
| 600 break; | 599 break; |
| 601 case MSG_RUN_PROCESS: | 600 case MSG_RUN_PROCESS: |
| 602 ProcessFrameP(); | 601 ProcessFrameP(); |
| 603 break; | 602 break; |
| 604 case MSG_STOP_PROCESS: | |
| 605 StopProcessP(); | |
| 606 break; | |
| 607 default: | 603 default: |
| 608 // All existing messages should be caught. Getting here should never | 604 // All existing messages should be caught. Getting here should never |
| 609 // happen. | 605 // happen. |
| 610 ASSERT(false); | 606 ASSERT(false); |
| 611 } | 607 } |
| 612 } | 608 } |
| 613 | 609 |
| 614 bool FakeAudioCaptureModule::Initialize() { | 610 bool FakeAudioCaptureModule::Initialize() { |
| 615 // Set the send buffer samples high enough that it would not occur on the | 611 // Set the send buffer samples high enough that it would not occur on the |
| 616 // remote side unless a packet containing a sample of that magnitude has been | 612 // remote side unless a packet containing a sample of that magnitude has been |
| (...skipping 28 matching lines...) Expand all Loading... |
| 645 } | 641 } |
| 646 | 642 |
| 647 bool FakeAudioCaptureModule::ShouldStartProcessing() { | 643 bool FakeAudioCaptureModule::ShouldStartProcessing() { |
| 648 return recording_ || playing_; | 644 return recording_ || playing_; |
| 649 } | 645 } |
| 650 | 646 |
| 651 void FakeAudioCaptureModule::UpdateProcessing(bool start) { | 647 void FakeAudioCaptureModule::UpdateProcessing(bool start) { |
| 652 if (start) { | 648 if (start) { |
| 653 process_thread_->Post(this, MSG_START_PROCESS); | 649 process_thread_->Post(this, MSG_START_PROCESS); |
| 654 } else { | 650 } else { |
| 655 process_thread_->Send(this, MSG_STOP_PROCESS); | 651 process_thread_->Clear(this); |
| 652 started_ = false; |
| 656 } | 653 } |
| 657 } | 654 } |
| 658 | 655 |
| 659 void FakeAudioCaptureModule::StartProcessP() { | 656 void FakeAudioCaptureModule::StartProcessP() { |
| 660 ASSERT(rtc::Thread::Current() == process_thread_); | 657 ASSERT(rtc::Thread::Current() == process_thread_); |
| 661 if (started_) { | 658 if (started_) { |
| 662 // Already started. | 659 // Already started. |
| 663 return; | 660 return; |
| 664 } | 661 } |
| 665 ProcessFrameP(); | 662 ProcessFrameP(); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 kNumberOfChannels, | 737 kNumberOfChannels, |
| 741 kSamplesPerSecond, kTotalDelayMs, | 738 kSamplesPerSecond, kTotalDelayMs, |
| 742 kClockDriftMs, current_mic_level, | 739 kClockDriftMs, current_mic_level, |
| 743 key_pressed, | 740 key_pressed, |
| 744 current_mic_level) != 0) { | 741 current_mic_level) != 0) { |
| 745 ASSERT(false); | 742 ASSERT(false); |
| 746 } | 743 } |
| 747 SetMicrophoneVolume(current_mic_level); | 744 SetMicrophoneVolume(current_mic_level); |
| 748 } | 745 } |
| 749 | 746 |
| 750 void FakeAudioCaptureModule::StopProcessP() { | |
| 751 ASSERT(rtc::Thread::Current() == process_thread_); | |
| 752 started_ = false; | |
| 753 process_thread_->Clear(this); | |
| 754 } | |
| OLD | NEW |