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