OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // This test generate synthetic data. For audio it's a sinusoid waveform with | 5 // This test generate synthetic data. For audio it's a sinusoid waveform with |
6 // frequency kSoundFrequency and different amplitudes. For video it's a pattern | 6 // frequency kSoundFrequency and different amplitudes. For video it's a pattern |
7 // that is shifting by one pixel per frame, each pixels neighbors right and down | 7 // that is shifting by one pixel per frame, each pixels neighbors right and down |
8 // is this pixels value +1, since the pixel value is 8 bit it will wrap | 8 // is this pixels value +1, since the pixel value is 8 bit it will wrap |
9 // frequently within the image. Visually this will create diagonally color bands | 9 // frequently within the image. Visually this will create diagonally color bands |
10 // that moves across the screen | 10 // that moves across the screen |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 164 |
165 } // namespace | 165 } // namespace |
166 | 166 |
167 // Shim that turns forwards packets from a test::PacketPipe to a | 167 // Shim that turns forwards packets from a test::PacketPipe to a |
168 // PacketReceiverCallback. | 168 // PacketReceiverCallback. |
169 class LoopBackPacketPipe : public test::PacketPipe { | 169 class LoopBackPacketPipe : public test::PacketPipe { |
170 public: | 170 public: |
171 LoopBackPacketPipe(const PacketReceiverCallback& packet_receiver) | 171 LoopBackPacketPipe(const PacketReceiverCallback& packet_receiver) |
172 : packet_receiver_(packet_receiver) {} | 172 : packet_receiver_(packet_receiver) {} |
173 | 173 |
174 virtual ~LoopBackPacketPipe() {} | 174 ~LoopBackPacketPipe() override {} |
175 | 175 |
176 // PacketPipe implementations. | 176 // PacketPipe implementations. |
177 virtual void Send(scoped_ptr<Packet> packet) override { | 177 void Send(scoped_ptr<Packet> packet) override { |
178 packet_receiver_.Run(packet.Pass()); | 178 packet_receiver_.Run(packet.Pass()); |
179 } | 179 } |
180 | 180 |
181 private: | 181 private: |
182 PacketReceiverCallback packet_receiver_; | 182 PacketReceiverCallback packet_receiver_; |
183 }; | 183 }; |
184 | 184 |
185 // Class that sends the packet direct from sender into the receiver with the | 185 // Class that sends the packet direct from sender into the receiver with the |
186 // ability to drop packets between the two. | 186 // ability to drop packets between the two. |
187 class LoopBackTransport : public PacketSender { | 187 class LoopBackTransport : public PacketSender { |
(...skipping 11 matching lines...) Expand all Loading... |
199 scoped_ptr<test::PacketPipe> loopback_pipe( | 199 scoped_ptr<test::PacketPipe> loopback_pipe( |
200 new LoopBackPacketPipe(packet_receiver)); | 200 new LoopBackPacketPipe(packet_receiver)); |
201 if (packet_pipe_) { | 201 if (packet_pipe_) { |
202 packet_pipe_->AppendToPipe(loopback_pipe.Pass()); | 202 packet_pipe_->AppendToPipe(loopback_pipe.Pass()); |
203 } else { | 203 } else { |
204 packet_pipe_ = loopback_pipe.Pass(); | 204 packet_pipe_ = loopback_pipe.Pass(); |
205 } | 205 } |
206 packet_pipe_->InitOnIOThread(task_runner, clock); | 206 packet_pipe_->InitOnIOThread(task_runner, clock); |
207 } | 207 } |
208 | 208 |
209 virtual bool SendPacket(PacketRef packet, | 209 bool SendPacket(PacketRef packet, const base::Closure& cb) override { |
210 const base::Closure& cb) override { | |
211 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 210 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
212 if (!send_packets_) | 211 if (!send_packets_) |
213 return true; | 212 return true; |
214 | 213 |
215 bytes_sent_ += packet->data.size(); | 214 bytes_sent_ += packet->data.size(); |
216 if (drop_packets_belonging_to_odd_frames_) { | 215 if (drop_packets_belonging_to_odd_frames_) { |
217 uint32 frame_id = packet->data[13]; | 216 uint32 frame_id = packet->data[13]; |
218 if (frame_id % 2 == 1) | 217 if (frame_id % 2 == 1) |
219 return true; | 218 return true; |
220 } | 219 } |
221 | 220 |
222 scoped_ptr<Packet> packet_copy(new Packet(packet->data)); | 221 scoped_ptr<Packet> packet_copy(new Packet(packet->data)); |
223 packet_pipe_->Send(packet_copy.Pass()); | 222 packet_pipe_->Send(packet_copy.Pass()); |
224 return true; | 223 return true; |
225 } | 224 } |
226 | 225 |
227 virtual int64 GetBytesSent() override { | 226 int64 GetBytesSent() override { return bytes_sent_; } |
228 return bytes_sent_; | |
229 } | |
230 | 227 |
231 void SetSendPackets(bool send_packets) { send_packets_ = send_packets; } | 228 void SetSendPackets(bool send_packets) { send_packets_ = send_packets; } |
232 | 229 |
233 void DropAllPacketsBelongingToOddFrames() { | 230 void DropAllPacketsBelongingToOddFrames() { |
234 drop_packets_belonging_to_odd_frames_ = true; | 231 drop_packets_belonging_to_odd_frames_ = true; |
235 } | 232 } |
236 | 233 |
237 void SetPacketPipe(scoped_ptr<test::PacketPipe> pipe) { | 234 void SetPacketPipe(scoped_ptr<test::PacketPipe> pipe) { |
238 // Append the loopback pipe to the end. | 235 // Append the loopback pipe to the end. |
239 pipe->AppendToPipe(packet_pipe_.Pass()); | 236 pipe->AppendToPipe(packet_pipe_.Pass()); |
(...skipping 1268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1508 EXPECT_LT(jump, 220u); | 1505 EXPECT_LT(jump, 220u); |
1509 } | 1506 } |
1510 | 1507 |
1511 // TODO(pwestin): Add repeatable packet loss test. | 1508 // TODO(pwestin): Add repeatable packet loss test. |
1512 // TODO(pwestin): Add test for misaligned send get calls. | 1509 // TODO(pwestin): Add test for misaligned send get calls. |
1513 // TODO(pwestin): Add more tests that does not resample. | 1510 // TODO(pwestin): Add more tests that does not resample. |
1514 // TODO(pwestin): Add test when we have starvation for our RunTask. | 1511 // TODO(pwestin): Add test when we have starvation for our RunTask. |
1515 | 1512 |
1516 } // namespace cast | 1513 } // namespace cast |
1517 } // namespace media | 1514 } // namespace media |
OLD | NEW |