| OLD | NEW |
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2004 Google Inc. | 3 * Copyright 2004 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 14 matching lines...) Expand all Loading... |
| 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #include "talk/session/media/audiomonitor.h" | 28 #include "talk/session/media/audiomonitor.h" |
| 29 #include "talk/session/media/currentspeakermonitor.h" | 29 #include "talk/session/media/currentspeakermonitor.h" |
| 30 #include "webrtc/base/gunit.h" | 30 #include "webrtc/base/gunit.h" |
| 31 #include "webrtc/base/thread.h" | 31 #include "webrtc/base/thread.h" |
| 32 | 32 |
| 33 namespace cricket { | 33 namespace cricket { |
| 34 | 34 |
| 35 static const uint32 kSsrc1 = 1001; | 35 static const uint32_t kSsrc1 = 1001; |
| 36 static const uint32 kSsrc2 = 1002; | 36 static const uint32_t kSsrc2 = 1002; |
| 37 static const uint32 kMinTimeBetweenSwitches = 10; | 37 static const uint32_t kMinTimeBetweenSwitches = 10; |
| 38 // Due to limited system clock resolution, the CurrentSpeakerMonitor may | 38 // Due to limited system clock resolution, the CurrentSpeakerMonitor may |
| 39 // actually require more or less time between switches than that specified | 39 // actually require more or less time between switches than that specified |
| 40 // in the call to set_min_time_between_switches. To be safe, we sleep for | 40 // in the call to set_min_time_between_switches. To be safe, we sleep for |
| 41 // 90 ms more than the min time between switches before checking for a switch. | 41 // 90 ms more than the min time between switches before checking for a switch. |
| 42 // I am assuming system clocks do not have a coarser resolution than 90 ms. | 42 // I am assuming system clocks do not have a coarser resolution than 90 ms. |
| 43 static const uint32 kSleepTimeBetweenSwitches = 100; | 43 static const uint32_t kSleepTimeBetweenSwitches = 100; |
| 44 | 44 |
| 45 class CurrentSpeakerMonitorTest : public testing::Test, | 45 class CurrentSpeakerMonitorTest : public testing::Test, |
| 46 public sigslot::has_slots<> { | 46 public sigslot::has_slots<> { |
| 47 public: | 47 public: |
| 48 CurrentSpeakerMonitorTest() { | 48 CurrentSpeakerMonitorTest() { |
| 49 monitor_ = new CurrentSpeakerMonitor(&source_, NULL); | 49 monitor_ = new CurrentSpeakerMonitor(&source_, NULL); |
| 50 // Shrink the minimum time betweeen switches to 10 ms so we don't have to | 50 // Shrink the minimum time betweeen switches to 10 ms so we don't have to |
| 51 // slow down our tests. | 51 // slow down our tests. |
| 52 monitor_->set_min_time_between_switches(kMinTimeBetweenSwitches); | 52 monitor_->set_min_time_between_switches(kMinTimeBetweenSwitches); |
| 53 monitor_->SignalUpdate.connect(this, &CurrentSpeakerMonitorTest::OnUpdate); | 53 monitor_->SignalUpdate.connect(this, &CurrentSpeakerMonitorTest::OnUpdate); |
| 54 current_speaker_ = 0; | 54 current_speaker_ = 0; |
| 55 num_changes_ = 0; | 55 num_changes_ = 0; |
| 56 monitor_->Start(); | 56 monitor_->Start(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 ~CurrentSpeakerMonitorTest() { | 59 ~CurrentSpeakerMonitorTest() { |
| 60 delete monitor_; | 60 delete monitor_; |
| 61 } | 61 } |
| 62 | 62 |
| 63 void SignalAudioMonitor(const AudioInfo& info) { | 63 void SignalAudioMonitor(const AudioInfo& info) { |
| 64 source_.SignalAudioMonitor(&source_, info); | 64 source_.SignalAudioMonitor(&source_, info); |
| 65 } | 65 } |
| 66 | 66 |
| 67 protected: | 67 protected: |
| 68 AudioSourceContext source_; | 68 AudioSourceContext source_; |
| 69 CurrentSpeakerMonitor* monitor_; | 69 CurrentSpeakerMonitor* monitor_; |
| 70 int num_changes_; | 70 int num_changes_; |
| 71 uint32 current_speaker_; | 71 uint32_t current_speaker_; |
| 72 | 72 |
| 73 void OnUpdate(CurrentSpeakerMonitor* monitor, uint32 current_speaker) { | 73 void OnUpdate(CurrentSpeakerMonitor* monitor, uint32_t current_speaker) { |
| 74 current_speaker_ = current_speaker; | 74 current_speaker_ = current_speaker; |
| 75 num_changes_++; | 75 num_changes_++; |
| 76 } | 76 } |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 static void InitAudioInfo(AudioInfo* info, int input_level, int output_level) { | 79 static void InitAudioInfo(AudioInfo* info, int input_level, int output_level) { |
| 80 info->input_level = input_level; | 80 info->input_level = input_level; |
| 81 info->output_level = output_level; | 81 info->output_level = output_level; |
| 82 } | 82 } |
| 83 | 83 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 info.active_streams.push_back(std::make_pair(kSsrc1, 3)); | 217 info.active_streams.push_back(std::make_pair(kSsrc1, 3)); |
| 218 info.active_streams.push_back(std::make_pair(kSsrc2, 0)); | 218 info.active_streams.push_back(std::make_pair(kSsrc2, 0)); |
| 219 SignalAudioMonitor(info); | 219 SignalAudioMonitor(info); |
| 220 | 220 |
| 221 // At this point, we should have concluded that SSRC2 stopped speaking. | 221 // At this point, we should have concluded that SSRC2 stopped speaking. |
| 222 EXPECT_EQ(current_speaker_, kSsrc1); | 222 EXPECT_EQ(current_speaker_, kSsrc1); |
| 223 EXPECT_EQ(num_changes_, 2); | 223 EXPECT_EQ(num_changes_, 2); |
| 224 } | 224 } |
| 225 | 225 |
| 226 } // namespace cricket | 226 } // namespace cricket |
| OLD | NEW |