#ifndef MEDIA_CAST_TRANSPORT_PACING_PACED_SENDER_H_
#define MEDIA_CAST_TRANSPORT_PACING_PACED_SENDER_H_
#include <list>
#include <vector>
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/non_thread_safe.h"
#include "base/time/default_tick_clock.h"
#include "base/time/tick_clock.h"
#include "base/time/time.h"
#include "media/cast/transport/cast_transport_config.h"
#include "media/cast/transport/transport/udp_transport.h"
namespace media {
namespace cast {
class LoggingImpl;
namespace transport {
class PacedPacketSender {
public:
virtual bool SendPackets(const PacketList& packets) = 0;
virtual bool ResendPackets(const PacketList& packets) = 0;
virtual bool SendRtcpPacket(const Packet& packet) = 0;
virtual ~PacedPacketSender() {}
};
class PacedSender : public PacedPacketSender,
public base::NonThreadSafe,
public base::SupportsWeakPtr<PacedSender> {
public:
PacedSender(
base::TickClock* clock,
LoggingImpl* logging,
PacketSender* external_transport,
const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner);
virtual ~PacedSender();
void RegisterAudioSsrc(uint32 audio_ssrc);
void RegisterVideoSsrc(uint32 video_ssrc);
virtual bool SendPackets(const PacketList& packets) OVERRIDE;
virtual bool ResendPackets(const PacketList& packets) OVERRIDE;
virtual bool SendRtcpPacket(const Packet& packet) OVERRIDE;
protected:
void ScheduleNextSend();
void SendNextPacketBurst();
private:
bool SendPacketsToTransport(const PacketList& packets,
PacketList* packets_not_sent,
bool retransmit);
bool TransmitPackets(const PacketList& packets);
void SendStoredPackets();
void UpdateBurstSize(size_t num_of_packets);
void LogPacketEvent(const Packet& packet, bool retransmit);
base::TickClock* const clock_;
LoggingImpl* const logging_;
PacketSender* transport_;
scoped_refptr<base::SingleThreadTaskRunner> transport_task_runner_;
uint32 audio_ssrc_;
uint32 video_ssrc_;
size_t burst_size_;
size_t packets_sent_in_burst_;
base::TimeTicks time_last_process_;
PacketList packet_list_;
PacketList resend_packet_list_;
base::WeakPtrFactory<PacedSender> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(PacedSender);
};
}
}
}
#endif