Index: media/cast/transport/transport/transport.h |
diff --git a/media/cast/transport/transport/transport.h b/media/cast/transport/transport/transport.h |
index 9e691967b0c5a2fb8bf2c15c95198462d20631bc..2fe73c2cd7c886c0067bc87edbf0feb176aa6196 100644 |
--- a/media/cast/transport/transport/transport.h |
+++ b/media/cast/transport/transport/transport.h |
@@ -1,54 +1,69 @@ |
// Copyright 2013 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+// TODO(hclam): This file should be renamed to udp_transport.h. |
mikhal1
2014/01/07 20:50:06
Why not rename it in this cl?
Alpha Left Google
2014/01/08 00:37:11
Done.
|
-#ifndef MEDIA_CAST_TEST_TRANSPORT_TRANSPORT_H_ |
-#define MEDIA_CAST_TEST_TRANSPORT_TRANSPORT_H_ |
+#ifndef MEDIA_CAST_TRANSPORT_TRANSPORT_TRANSPORT_H_ |
+#define MEDIA_CAST_TRANSPORT_TRANSPORT_TRANSPORT_H_ |
+#include "base/memory/ref_counted.h" |
#include "base/memory/scoped_ptr.h" |
+#include "base/memory/weak_ptr.h" |
#include "media/cast/cast_config.h" |
#include "media/cast/cast_environment.h" |
+#include "net/base/ip_endpoint.h" |
#include "net/udp/udp_server_socket.h" |
+namespace net { |
+class IOBuffer; |
+class IPEndPoint; |
+} // namespace net |
namespace media { |
namespace cast { |
namespace transport { |
-class LocalUdpTransportData; |
-class LocalPacketSender; |
- |
-// Helper class for Cast test applications. |
-class Transport { |
+// This class implements UDP transport mechanism for Cast. |
+class UdpTransport : public PacketSender { |
public: |
- Transport(scoped_refptr<base::TaskRunner> io_thread_proxy); |
- ~Transport(); |
- |
- // Specifies the ports and IP address to receive packets on. |
- // Will start listening immediately. |
- void SetLocalReceiver(PacketReceiver* packet_receiver, |
- std::string ip_address, |
- std::string local_ip_address, |
- int port); |
- |
- // Specifies the destination port and IP address. |
- void SetSendDestination(std::string ip_address, int port); |
+ // Construct a UDP transport. |
+ // All methods must be called on |io_thread_proxy|. |
+ // |local_end_point| specifies the address and port to bind and listen |
+ // to incoming packets. |
+ // |remote_end_point| specifies the address and port to send packets |
+ // to. If the value is 0.0.0.0:0 the the end point is set to the source |
+ // address of the first packet received. |
+ UdpTransport(const scoped_refptr<base::TaskRunner>& io_thread_proxy, |
+ const net::IPEndPoint& local_end_point, |
+ const net::IPEndPoint& remote_end_point); |
+ ~UdpTransport(); |
- PacketSender* packet_sender(); |
+ // Start receiving packets. Packets are submitted to |packet_receiver|. |
+ void StartReceiving(PacketReceiver* packet_receiver); |
- void StopReceiving(); |
+ // PacketSender implementations. |
+ virtual bool SendPackets(const PacketList& packets) OVERRIDE; |
+ virtual bool SendPacket(const Packet& packet) OVERRIDE; |
private: |
- scoped_ptr<net::UDPServerSocket> udp_socket_; |
- scoped_refptr<LocalUdpTransportData> local_udp_transport_data_; |
- scoped_refptr<LocalPacketSender> packet_sender_; |
+ void ReceiveOnePacket(); |
+ void OnReceived(int result); |
+ void OnSent(const scoped_refptr<net::IOBuffer>& buf, int result); |
+ |
scoped_refptr<base::TaskRunner> io_thread_proxy_; |
+ net::IPEndPoint local_addr_; |
+ net::IPEndPoint remote_addr_; |
+ scoped_ptr<net::UDPServerSocket> udp_socket_; |
+ scoped_refptr<net::IOBuffer> recv_buf_; |
+ net::IPEndPoint recv_addr_; |
+ PacketReceiver* packet_receiver_; |
+ base::WeakPtrFactory<UdpTransport> weak_factory_; |
- DISALLOW_COPY_AND_ASSIGN(Transport); |
+ DISALLOW_COPY_AND_ASSIGN(UdpTransport); |
}; |
} // namespace transport |
} // namespace cast |
} // namespace media |
-#endif // MEDIA_CAST_TEST_TRANSPORT_TRANSPORT_H_ |
+#endif // MEDIA_CAST_TRANSPORT_TRANSPORT_TRANSPORT_H_ |