Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: webrtc/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h

Issue 1335353005: Remove channel ids from various interfaces. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/scoped_ptr.h" 16 #include "webrtc/base/scoped_ptr.h"
17 #include "webrtc/common_types.h" 17 #include "webrtc/common_types.h"
18 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
18 #include "webrtc/system_wrappers/interface/atomic32.h" 19 #include "webrtc/system_wrappers/interface/atomic32.h"
19 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" 20 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
20 #include "webrtc/system_wrappers/interface/event_wrapper.h" 21 #include "webrtc/system_wrappers/interface/event_wrapper.h"
21 #include "webrtc/system_wrappers/interface/sleep.h" 22 #include "webrtc/system_wrappers/interface/sleep.h"
22 #include "webrtc/system_wrappers/interface/thread_wrapper.h" 23 #include "webrtc/system_wrappers/interface/thread_wrapper.h"
23 #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"
24 25
25 class TestErrorObserver; 26 class TestErrorObserver;
26 27
27 class LoopBackTransport : public webrtc::Transport { 28 class LoopBackTransport : public webrtc::Transport {
28 public: 29 public:
29 LoopBackTransport(webrtc::VoENetwork* voe_network) 30 LoopBackTransport(webrtc::VoENetwork* voe_network, int channel)
30 : crit_(webrtc::CriticalSectionWrapper::CreateCriticalSection()), 31 : crit_(webrtc::CriticalSectionWrapper::CreateCriticalSection()),
31 packet_event_(webrtc::EventWrapper::Create()), 32 packet_event_(webrtc::EventWrapper::Create()),
32 thread_(webrtc::ThreadWrapper::CreateThread( 33 thread_(webrtc::ThreadWrapper::CreateThread(NetworkProcess,
33 NetworkProcess, this, "LoopBackTransport")), 34 this,
34 voe_network_(voe_network), transmitted_packets_(0) { 35 "LoopBackTransport")),
36 channel_(channel),
37 voe_network_(voe_network),
38 transmitted_packets_(0) {
35 thread_->Start(); 39 thread_->Start();
36 } 40 }
37 41
38 ~LoopBackTransport() { thread_->Stop(); } 42 ~LoopBackTransport() { thread_->Stop(); }
39 43
40 int SendPacket(int channel, const void* data, size_t len) override { 44 int SendPacket(const void* data, size_t len) override {
41 StorePacket(Packet::Rtp, channel, data, len); 45 StorePacket(Packet::Rtp, data, len);
42 return static_cast<int>(len); 46 return static_cast<int>(len);
43 } 47 }
44 48
45 int SendRTCPPacket(int channel, const void* data, size_t len) override { 49 int SendRTCPPacket(const void* data, size_t len) override {
46 StorePacket(Packet::Rtcp, channel, data, len); 50 StorePacket(Packet::Rtcp, data, len);
47 return static_cast<int>(len); 51 return static_cast<int>(len);
48 } 52 }
49 53
50 void WaitForTransmittedPackets(int32_t packet_count) { 54 void WaitForTransmittedPackets(int32_t packet_count) {
51 enum { 55 enum {
52 kSleepIntervalMs = 10 56 kSleepIntervalMs = 10
53 }; 57 };
54 int32_t limit = transmitted_packets_.Value() + packet_count; 58 int32_t limit = transmitted_packets_.Value() + packet_count;
55 while (transmitted_packets_.Value() < limit) { 59 while (transmitted_packets_.Value() < limit) {
56 webrtc::SleepMs(kSleepIntervalMs); 60 webrtc::SleepMs(kSleepIntervalMs);
57 } 61 }
58 } 62 }
59 63
64 void AddChannel(uint32_t ssrc, int channel) {
65 webrtc::CriticalSectionScoped lock(crit_.get());
66 channels_[ssrc] = channel;
67 }
68
60 private: 69 private:
61 struct Packet { 70 struct Packet {
62 enum Type { Rtp, Rtcp, } type; 71 enum Type { Rtp, Rtcp, } type;
63 72
64 Packet() : len(0) {} 73 Packet() : len(0) {}
65 Packet(Type type, int channel, const void* data, size_t len) 74 Packet(Type type, const void* data, size_t len)
66 : type(type), channel(channel), len(len) { 75 : type(type), len(len) {
67 assert(len <= 1500); 76 assert(len <= 1500);
68 memcpy(this->data, data, len); 77 memcpy(this->data, data, len);
69 } 78 }
70 79
71 int channel;
72 uint8_t data[1500]; 80 uint8_t data[1500];
73 size_t len; 81 size_t len;
74 }; 82 };
75 83
76 void StorePacket(Packet::Type type, int channel, 84 void StorePacket(Packet::Type type,
77 const void* data, 85 const void* data,
78 size_t len) { 86 size_t len) {
79 { 87 {
80 webrtc::CriticalSectionScoped lock(crit_.get()); 88 webrtc::CriticalSectionScoped lock(crit_.get());
81 packet_queue_.push_back(Packet(type, channel, data, len)); 89 packet_queue_.push_back(Packet(type, data, len));
82 } 90 }
83 packet_event_->Set(); 91 packet_event_->Set();
84 } 92 }
85 93
86 static bool NetworkProcess(void* transport) { 94 static bool NetworkProcess(void* transport) {
87 return static_cast<LoopBackTransport*>(transport)->SendPackets(); 95 return static_cast<LoopBackTransport*>(transport)->SendPackets();
88 } 96 }
89 97
90 bool SendPackets() { 98 bool SendPackets() {
91 switch (packet_event_->Wait(10)) { 99 switch (packet_event_->Wait(10)) {
92 case webrtc::kEventSignaled: 100 case webrtc::kEventSignaled:
93 break; 101 break;
94 case webrtc::kEventTimeout: 102 case webrtc::kEventTimeout:
95 break; 103 break;
96 case webrtc::kEventError: 104 case webrtc::kEventError:
97 // TODO(pbos): Log a warning here? 105 // TODO(pbos): Log a warning here?
98 return true; 106 return true;
99 } 107 }
100 108
101 while (true) { 109 while (true) {
102 Packet p; 110 Packet p;
111 int channel = channel_;
103 { 112 {
104 webrtc::CriticalSectionScoped lock(crit_.get()); 113 webrtc::CriticalSectionScoped lock(crit_.get());
105 if (packet_queue_.empty()) 114 if (packet_queue_.empty())
106 break; 115 break;
107 p = packet_queue_.front(); 116 p = packet_queue_.front();
108 packet_queue_.pop_front(); 117 packet_queue_.pop_front();
118
119 if (p.type == Packet::Rtp) {
120 uint32_t ssrc =
121 webrtc::ByteReader<uint32_t>::ReadBigEndian(&p.data[8]);
122 if (channels_[ssrc] != 0)
123 channel = channels_[ssrc];
124 }
125 // TODO(pbos): Add RTCP SSRC muxing/demuxing if anything requires it.
109 } 126 }
110 127
128 // Minimum RTP header size.
129 if (p.len < 12)
130 continue;
131
111 switch (p.type) { 132 switch (p.type) {
112 case Packet::Rtp: 133 case Packet::Rtp:
113 voe_network_->ReceivedRTPPacket(p.channel, p.data, p.len, 134 voe_network_->ReceivedRTPPacket(channel, p.data, p.len,
114 webrtc::PacketTime()); 135 webrtc::PacketTime());
115 break; 136 break;
116 case Packet::Rtcp: 137 case Packet::Rtcp:
117 voe_network_->ReceivedRTCPPacket(p.channel, p.data, p.len); 138 voe_network_->ReceivedRTCPPacket(channel, p.data, p.len);
118 break; 139 break;
119 } 140 }
120 ++transmitted_packets_; 141 ++transmitted_packets_;
121 } 142 }
122 return true; 143 return true;
123 } 144 }
124 145
125 const rtc::scoped_ptr<webrtc::CriticalSectionWrapper> crit_; 146 const rtc::scoped_ptr<webrtc::CriticalSectionWrapper> crit_;
126 const rtc::scoped_ptr<webrtc::EventWrapper> packet_event_; 147 const rtc::scoped_ptr<webrtc::EventWrapper> packet_event_;
127 const rtc::scoped_ptr<webrtc::ThreadWrapper> thread_; 148 const rtc::scoped_ptr<webrtc::ThreadWrapper> thread_;
128 std::deque<Packet> packet_queue_ GUARDED_BY(crit_.get()); 149 std::deque<Packet> packet_queue_ GUARDED_BY(crit_.get());
150 const int channel_;
151 std::map<uint32_t, int> channels_ GUARDED_BY(crit_.get());
129 webrtc::VoENetwork* const voe_network_; 152 webrtc::VoENetwork* const voe_network_;
130 webrtc::Atomic32 transmitted_packets_; 153 webrtc::Atomic32 transmitted_packets_;
131 }; 154 };
132 155
133 // This fixture initializes the voice engine in addition to the work 156 // This fixture initializes the voice engine in addition to the work
134 // done by the before-initialization fixture. It also registers an error 157 // done by the before-initialization fixture. It also registers an error
135 // observer which will fail tests on error callbacks. This fixture is 158 // observer which will fail tests on error callbacks. This fixture is
136 // useful to tests that want to run before we have started any form of 159 // useful to tests that want to run before we have started any form of
137 // streaming through the voice engine. 160 // streaming through the voice engine.
138 class AfterInitializationFixture : public BeforeInitializationFixture { 161 class AfterInitializationFixture : public BeforeInitializationFixture {
139 public: 162 public:
140 AfterInitializationFixture(); 163 AfterInitializationFixture();
141 virtual ~AfterInitializationFixture(); 164 virtual ~AfterInitializationFixture();
142 165
143 protected: 166 protected:
144 rtc::scoped_ptr<TestErrorObserver> error_observer_; 167 rtc::scoped_ptr<TestErrorObserver> error_observer_;
145 }; 168 };
146 169
147 #endif // SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_STANDARD_TEST_BASE_AFTER_INIT_H_ 170 #endif // SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_STANDARD_TEST_BASE_AFTER_INIT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698