1 // Copyright 2013 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_PACING_PACED_SENDER_H_
6 #define MEDIA_CAST_PACING_PACED_SENDER_H_
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/non_thread_safe.h"
15 #include "base/time/default_tick_clock.h"
16 #include "base/time/tick_clock.h"
17 #include "base/time/time.h"
18 #include "media/cast/cast_config.h"
19 #include "media/cast/cast_environment.h"
24 // We have this pure virtual class to enable mocking.
25 class PacedPacketSender
{
27 // Inform the pacer / sender of the total number of packets.
28 virtual bool SendPackets(const PacketList
& packets
) = 0;
30 virtual bool ResendPackets(const PacketList
& packets
) = 0;
32 virtual bool SendRtcpPacket(const Packet
& packet
) = 0;
34 virtual ~PacedPacketSender() {}
37 class PacedSender
: public PacedPacketSender
,
38 public base::NonThreadSafe
,
39 public base::SupportsWeakPtr
<PacedSender
> {
41 PacedSender(scoped_refptr
<CastEnvironment
> cast_environment
,
42 PacketSender
* transport
);
43 virtual ~PacedSender();
45 virtual bool SendPackets(const PacketList
& packets
) OVERRIDE
;
47 virtual bool ResendPackets(const PacketList
& packets
) OVERRIDE
;
49 virtual bool SendRtcpPacket(const Packet
& packet
) OVERRIDE
;
52 // Schedule a delayed task on the main cast thread when it's time to send the
54 void ScheduleNextSend();
56 // Process any pending packets in the queue(s).
57 void SendNextPacketBurst();
60 bool SendPacketsToTransport(const PacketList
& packets
,
61 PacketList
* packets_not_sent
);
62 void SendStoredPackets();
63 void UpdateBurstSize(size_t num_of_packets
);
65 scoped_refptr
<CastEnvironment
> cast_environment_
;
67 size_t packets_sent_in_burst_
;
68 base::TimeTicks time_last_process_
;
69 // Note: We can't combine the |packet_list_| and the |resend_packet_list_|
70 // since then we might get reordering of the retransmitted packets.
71 PacketList packet_list_
;
72 PacketList resend_packet_list_
;
73 PacketSender
* transport_
;
75 base::WeakPtrFactory
<PacedSender
> weak_factory_
;
77 DISALLOW_COPY_AND_ASSIGN(PacedSender
);
83 #endif // MEDIA_CAST_PACING_PACED_SENDER_H_