OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "media/cast/test/loopback_transport.h" | 5 #include "media/cast/test/loopback_transport.h" |
6 | 6 |
7 #include "base/single_thread_task_runner.h" | 7 #include "base/single_thread_task_runner.h" |
8 #include "base/time/tick_clock.h" | 8 #include "base/time/tick_clock.h" |
9 #include "media/cast/test/utility/udp_proxy.h" | 9 #include "media/cast/test/utility/udp_proxy.h" |
10 | 10 |
11 namespace media { | 11 namespace media { |
12 namespace cast { | 12 namespace cast { |
13 namespace { | 13 namespace { |
14 | 14 |
15 // Shim that turns forwards packets from a test::PacketPipe to a | 15 // Shim that turns forwards packets from a test::PacketPipe to a |
16 // PacketReceiverCallback. | 16 // PacketReceiverCallback. |
17 class LoopBackPacketPipe : public test::PacketPipe { | 17 class LoopBackPacketPipe : public test::PacketPipe { |
18 public: | 18 public: |
19 LoopBackPacketPipe( | 19 LoopBackPacketPipe( |
20 const transport::PacketReceiverCallback& packet_receiver) | 20 const PacketReceiverCallback& packet_receiver) |
21 : packet_receiver_(packet_receiver) {} | 21 : packet_receiver_(packet_receiver) {} |
22 | 22 |
23 virtual ~LoopBackPacketPipe() {} | 23 virtual ~LoopBackPacketPipe() {} |
24 | 24 |
25 // PacketPipe implementations. | 25 // PacketPipe implementations. |
26 virtual void Send(scoped_ptr<transport::Packet> packet) OVERRIDE { | 26 virtual void Send(scoped_ptr<Packet> packet) OVERRIDE { |
27 packet_receiver_.Run(packet.Pass()); | 27 packet_receiver_.Run(packet.Pass()); |
28 } | 28 } |
29 | 29 |
30 private: | 30 private: |
31 transport::PacketReceiverCallback packet_receiver_; | 31 PacketReceiverCallback packet_receiver_; |
32 | 32 |
33 DISALLOW_COPY_AND_ASSIGN(LoopBackPacketPipe); | 33 DISALLOW_COPY_AND_ASSIGN(LoopBackPacketPipe); |
34 }; | 34 }; |
35 | 35 |
36 } // namespace | 36 } // namespace |
37 | 37 |
38 LoopBackTransport::LoopBackTransport( | 38 LoopBackTransport::LoopBackTransport( |
39 scoped_refptr<CastEnvironment> cast_environment) | 39 scoped_refptr<CastEnvironment> cast_environment) |
40 : cast_environment_(cast_environment) { | 40 : cast_environment_(cast_environment) { |
41 } | 41 } |
42 | 42 |
43 LoopBackTransport::~LoopBackTransport() { | 43 LoopBackTransport::~LoopBackTransport() { |
44 } | 44 } |
45 | 45 |
46 bool LoopBackTransport::SendPacket(transport::PacketRef packet, | 46 bool LoopBackTransport::SendPacket(PacketRef packet, |
47 const base::Closure& cb) { | 47 const base::Closure& cb) { |
48 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 48 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
49 scoped_ptr<Packet> packet_copy(new Packet(packet->data)); | 49 scoped_ptr<Packet> packet_copy(new Packet(packet->data)); |
50 packet_pipe_->Send(packet_copy.Pass()); | 50 packet_pipe_->Send(packet_copy.Pass()); |
51 return true; | 51 return true; |
52 } | 52 } |
53 | 53 |
54 void LoopBackTransport::Initialize( | 54 void LoopBackTransport::Initialize( |
55 scoped_ptr<test::PacketPipe> pipe, | 55 scoped_ptr<test::PacketPipe> pipe, |
56 const transport::PacketReceiverCallback& packet_receiver, | 56 const PacketReceiverCallback& packet_receiver, |
57 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 57 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
58 base::TickClock* clock) { | 58 base::TickClock* clock) { |
59 scoped_ptr<test::PacketPipe> loopback_pipe( | 59 scoped_ptr<test::PacketPipe> loopback_pipe( |
60 new LoopBackPacketPipe(packet_receiver)); | 60 new LoopBackPacketPipe(packet_receiver)); |
61 // Append the loopback pipe to the end. | 61 // Append the loopback pipe to the end. |
62 pipe->AppendToPipe(loopback_pipe.Pass()); | 62 pipe->AppendToPipe(loopback_pipe.Pass()); |
63 packet_pipe_ = pipe.Pass(); | 63 packet_pipe_ = pipe.Pass(); |
64 packet_pipe_->InitOnIOThread(task_runner, clock); | 64 packet_pipe_->InitOnIOThread(task_runner, clock); |
65 } | 65 } |
66 | 66 |
67 } // namespace cast | 67 } // namespace cast |
68 } // namespace media | 68 } // namespace media |
OLD | NEW |