#ifndef MEDIA_CAST_TRANSPORT_TRANSPORT_UDP_TRANSPORT_H_
#define MEDIA_CAST_TRANSPORT_TRANSPORT_UDP_TRANSPORT_H_
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "media/cast/cast_environment.h"
#include "media/cast/transport/cast_transport_config.h"
#include "media/cast/transport/cast_transport_sender.h"
#include "net/base/ip_endpoint.h"
#include "net/udp/udp_socket.h"
namespace net {
class IOBuffer;
class IPEndPoint;
class NetLog;
}
namespace media {
namespace cast {
namespace transport {
class UdpTransport : public PacketSender {
public:
UdpTransport(
net::NetLog* net_log,
const scoped_refptr<base::SingleThreadTaskRunner>& io_thread_proxy,
const net::IPEndPoint& local_end_point,
const net::IPEndPoint& remote_end_point,
const CastTransportStatusCallback& status_callback);
virtual ~UdpTransport();
void StartReceiving(const PacketReceiverCallback& packet_receiver);
virtual bool SendPacket(const Packet& packet) OVERRIDE;
private:
void ReceiveNextPacket(int length_or_status);
void OnSent(const scoped_refptr<net::IOBuffer>& buf, int result);
const scoped_refptr<base::SingleThreadTaskRunner> io_thread_proxy_;
const net::IPEndPoint local_addr_;
net::IPEndPoint remote_addr_;
const scoped_ptr<net::UDPSocket> udp_socket_;
bool send_pending_;
bool client_connected_;
scoped_ptr<Packet> next_packet_;
scoped_refptr<net::WrappedIOBuffer> recv_buf_;
net::IPEndPoint recv_addr_;
PacketReceiverCallback packet_receiver_;
const CastTransportStatusCallback status_callback_;
base::WeakPtrFactory<UdpTransport> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(UdpTransport);
};
}
}
}
#endif