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.
5 #ifndef MEDIA_CAST_TRANSPORT_TRANSPORT_UDP_TRANSPORT_H_
6 #define MEDIA_CAST_TRANSPORT_TRANSPORT_UDP_TRANSPORT_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "media/cast/cast_environment.h"
12 #include "media/cast/transport/cast_transport_config.h"
13 #include "media/cast/transport/cast_transport_sender.h"
14 #include "net/base/ip_endpoint.h"
15 #include "net/udp/udp_socket.h"
26 // This class implements UDP transport mechanism for Cast.
27 class UdpTransport : public PacketSender {
29 // Construct a UDP transport.
30 // All methods must be called on |io_thread_proxy|.
31 // |local_end_point| specifies the address and port to bind and listen
32 // to incoming packets. If the value is 0.0.0.0:0 then a bind is not
34 // |remote_end_point| specifies the address and port to send packets
35 // to. If the value is 0.0.0.0:0 the the end point is set to the source
36 // address of the first packet received.
38 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread_proxy,
39 const net::IPEndPoint& local_end_point,
40 const net::IPEndPoint& remote_end_point,
41 const CastTransportStatusCallback& status_callback);
42 virtual ~UdpTransport();
44 // Start receiving packets. Packets are submitted to |packet_receiver|.
45 void StartReceiving(const PacketReceiverCallback& packet_receiver);
47 // PacketSender implementations.
48 virtual bool SendPacket(const Packet& packet) OVERRIDE;
51 void ReceiveOnePacket();
52 void OnReceived(int result);
53 void OnSent(const scoped_refptr<net::IOBuffer>& buf, int result);
55 scoped_refptr<base::SingleThreadTaskRunner> io_thread_proxy_;
56 net::IPEndPoint local_addr_;
57 net::IPEndPoint remote_addr_;
58 scoped_ptr<net::UDPSocket> udp_socket_;
60 scoped_refptr<net::IOBuffer> recv_buf_;
61 net::IPEndPoint recv_addr_;
62 PacketReceiverCallback packet_receiver_;
63 const CastTransportStatusCallback& status_callback_;
64 base::WeakPtrFactory<UdpTransport> weak_factory_;
66 DISALLOW_COPY_AND_ASSIGN(UdpTransport);
69 } // namespace transport
73 #endif // MEDIA_CAST_TRANSPORT_TRANSPORT_UDP_TRANSPORT_H_