OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 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 |
11 #ifndef SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_STANDARD_TEST_BASE_AFTER_INIT_H_ | 11 #ifndef SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_STANDARD_TEST_BASE_AFTER_INIT_H_ |
12 #define SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_STANDARD_TEST_BASE_AFTER_INIT_H_ | 12 #define SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_STANDARD_TEST_BASE_AFTER_INIT_H_ |
13 | 13 |
14 #include <deque> | 14 #include <deque> |
15 | 15 |
| 16 #include "webrtc/base/criticalsection.h" |
16 #include "webrtc/base/platform_thread.h" | 17 #include "webrtc/base/platform_thread.h" |
17 #include "webrtc/base/scoped_ptr.h" | 18 #include "webrtc/base/scoped_ptr.h" |
18 #include "webrtc/common_types.h" | 19 #include "webrtc/common_types.h" |
19 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 20 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
20 #include "webrtc/system_wrappers/include/atomic32.h" | 21 #include "webrtc/system_wrappers/include/atomic32.h" |
21 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | |
22 #include "webrtc/system_wrappers/include/event_wrapper.h" | 22 #include "webrtc/system_wrappers/include/event_wrapper.h" |
23 #include "webrtc/system_wrappers/include/sleep.h" | 23 #include "webrtc/system_wrappers/include/sleep.h" |
24 #include "webrtc/voice_engine/test/auto_test/fixtures/before_initialization_fixt
ure.h" | 24 #include "webrtc/voice_engine/test/auto_test/fixtures/before_initialization_fixt
ure.h" |
25 | 25 |
26 class TestErrorObserver; | 26 class TestErrorObserver; |
27 | 27 |
28 class LoopBackTransport : public webrtc::Transport { | 28 class LoopBackTransport : public webrtc::Transport { |
29 public: | 29 public: |
30 LoopBackTransport(webrtc::VoENetwork* voe_network, int channel) | 30 LoopBackTransport(webrtc::VoENetwork* voe_network, int channel) |
31 : crit_(webrtc::CriticalSectionWrapper::CreateCriticalSection()), | 31 : packet_event_(webrtc::EventWrapper::Create()), |
32 packet_event_(webrtc::EventWrapper::Create()), | |
33 thread_(NetworkProcess, this, "LoopBackTransport"), | 32 thread_(NetworkProcess, this, "LoopBackTransport"), |
34 channel_(channel), | 33 channel_(channel), |
35 voe_network_(voe_network), | 34 voe_network_(voe_network), |
36 transmitted_packets_(0) { | 35 transmitted_packets_(0) { |
37 thread_.Start(); | 36 thread_.Start(); |
38 } | 37 } |
39 | 38 |
40 ~LoopBackTransport() { thread_.Stop(); } | 39 ~LoopBackTransport() { thread_.Stop(); } |
41 | 40 |
42 bool SendRtp(const uint8_t* data, | 41 bool SendRtp(const uint8_t* data, |
(...skipping 12 matching lines...) Expand all Loading... |
55 enum { | 54 enum { |
56 kSleepIntervalMs = 10 | 55 kSleepIntervalMs = 10 |
57 }; | 56 }; |
58 int32_t limit = transmitted_packets_.Value() + packet_count; | 57 int32_t limit = transmitted_packets_.Value() + packet_count; |
59 while (transmitted_packets_.Value() < limit) { | 58 while (transmitted_packets_.Value() < limit) { |
60 webrtc::SleepMs(kSleepIntervalMs); | 59 webrtc::SleepMs(kSleepIntervalMs); |
61 } | 60 } |
62 } | 61 } |
63 | 62 |
64 void AddChannel(uint32_t ssrc, int channel) { | 63 void AddChannel(uint32_t ssrc, int channel) { |
65 webrtc::CriticalSectionScoped lock(crit_.get()); | 64 rtc::CritScope lock(&crit_); |
66 channels_[ssrc] = channel; | 65 channels_[ssrc] = channel; |
67 } | 66 } |
68 | 67 |
69 private: | 68 private: |
70 struct Packet { | 69 struct Packet { |
71 enum Type { Rtp, Rtcp, } type; | 70 enum Type { Rtp, Rtcp, } type; |
72 | 71 |
73 Packet() : len(0) {} | 72 Packet() : len(0) {} |
74 Packet(Type type, const void* data, size_t len) | 73 Packet(Type type, const void* data, size_t len) |
75 : type(type), len(len) { | 74 : type(type), len(len) { |
76 assert(len <= 1500); | 75 assert(len <= 1500); |
77 memcpy(this->data, data, len); | 76 memcpy(this->data, data, len); |
78 } | 77 } |
79 | 78 |
80 uint8_t data[1500]; | 79 uint8_t data[1500]; |
81 size_t len; | 80 size_t len; |
82 }; | 81 }; |
83 | 82 |
84 void StorePacket(Packet::Type type, | 83 void StorePacket(Packet::Type type, |
85 const void* data, | 84 const void* data, |
86 size_t len) { | 85 size_t len) { |
87 { | 86 { |
88 webrtc::CriticalSectionScoped lock(crit_.get()); | 87 rtc::CritScope lock(&crit_); |
89 packet_queue_.push_back(Packet(type, data, len)); | 88 packet_queue_.push_back(Packet(type, data, len)); |
90 } | 89 } |
91 packet_event_->Set(); | 90 packet_event_->Set(); |
92 } | 91 } |
93 | 92 |
94 static bool NetworkProcess(void* transport) { | 93 static bool NetworkProcess(void* transport) { |
95 return static_cast<LoopBackTransport*>(transport)->SendPackets(); | 94 return static_cast<LoopBackTransport*>(transport)->SendPackets(); |
96 } | 95 } |
97 | 96 |
98 bool SendPackets() { | 97 bool SendPackets() { |
99 switch (packet_event_->Wait(10)) { | 98 switch (packet_event_->Wait(10)) { |
100 case webrtc::kEventSignaled: | 99 case webrtc::kEventSignaled: |
101 break; | 100 break; |
102 case webrtc::kEventTimeout: | 101 case webrtc::kEventTimeout: |
103 break; | 102 break; |
104 case webrtc::kEventError: | 103 case webrtc::kEventError: |
105 // TODO(pbos): Log a warning here? | 104 // TODO(pbos): Log a warning here? |
106 return true; | 105 return true; |
107 } | 106 } |
108 | 107 |
109 while (true) { | 108 while (true) { |
110 Packet p; | 109 Packet p; |
111 int channel = channel_; | 110 int channel = channel_; |
112 { | 111 { |
113 webrtc::CriticalSectionScoped lock(crit_.get()); | 112 rtc::CritScope lock(&crit_); |
114 if (packet_queue_.empty()) | 113 if (packet_queue_.empty()) |
115 break; | 114 break; |
116 p = packet_queue_.front(); | 115 p = packet_queue_.front(); |
117 packet_queue_.pop_front(); | 116 packet_queue_.pop_front(); |
118 | 117 |
119 if (p.type == Packet::Rtp) { | 118 if (p.type == Packet::Rtp) { |
120 uint32_t ssrc = | 119 uint32_t ssrc = |
121 webrtc::ByteReader<uint32_t>::ReadBigEndian(&p.data[8]); | 120 webrtc::ByteReader<uint32_t>::ReadBigEndian(&p.data[8]); |
122 if (channels_[ssrc] != 0) | 121 if (channels_[ssrc] != 0) |
123 channel = channels_[ssrc]; | 122 channel = channels_[ssrc]; |
(...skipping 12 matching lines...) Expand all Loading... |
136 break; | 135 break; |
137 case Packet::Rtcp: | 136 case Packet::Rtcp: |
138 voe_network_->ReceivedRTCPPacket(channel, p.data, p.len); | 137 voe_network_->ReceivedRTCPPacket(channel, p.data, p.len); |
139 break; | 138 break; |
140 } | 139 } |
141 ++transmitted_packets_; | 140 ++transmitted_packets_; |
142 } | 141 } |
143 return true; | 142 return true; |
144 } | 143 } |
145 | 144 |
146 const rtc::scoped_ptr<webrtc::CriticalSectionWrapper> crit_; | 145 mutable rtc::CriticalSection crit_; |
147 const rtc::scoped_ptr<webrtc::EventWrapper> packet_event_; | 146 const rtc::scoped_ptr<webrtc::EventWrapper> packet_event_; |
148 rtc::PlatformThread thread_; | 147 rtc::PlatformThread thread_; |
149 std::deque<Packet> packet_queue_ GUARDED_BY(crit_.get()); | 148 std::deque<Packet> packet_queue_ GUARDED_BY(crit_); |
150 const int channel_; | 149 const int channel_; |
151 std::map<uint32_t, int> channels_ GUARDED_BY(crit_.get()); | 150 std::map<uint32_t, int> channels_ GUARDED_BY(crit_); |
152 webrtc::VoENetwork* const voe_network_; | 151 webrtc::VoENetwork* const voe_network_; |
153 webrtc::Atomic32 transmitted_packets_; | 152 webrtc::Atomic32 transmitted_packets_; |
154 }; | 153 }; |
155 | 154 |
156 // This fixture initializes the voice engine in addition to the work | 155 // This fixture initializes the voice engine in addition to the work |
157 // done by the before-initialization fixture. It also registers an error | 156 // done by the before-initialization fixture. It also registers an error |
158 // observer which will fail tests on error callbacks. This fixture is | 157 // observer which will fail tests on error callbacks. This fixture is |
159 // useful to tests that want to run before we have started any form of | 158 // useful to tests that want to run before we have started any form of |
160 // streaming through the voice engine. | 159 // streaming through the voice engine. |
161 class AfterInitializationFixture : public BeforeInitializationFixture { | 160 class AfterInitializationFixture : public BeforeInitializationFixture { |
162 public: | 161 public: |
163 AfterInitializationFixture(); | 162 AfterInitializationFixture(); |
164 virtual ~AfterInitializationFixture(); | 163 virtual ~AfterInitializationFixture(); |
165 | 164 |
166 protected: | 165 protected: |
167 rtc::scoped_ptr<TestErrorObserver> error_observer_; | 166 rtc::scoped_ptr<TestErrorObserver> error_observer_; |
168 }; | 167 }; |
169 | 168 |
170 #endif // SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_STANDARD_TEST_BASE_AFTER_INIT_H_ | 169 #endif // SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_STANDARD_TEST_BASE_AFTER_INIT_H_ |
OLD | NEW |