OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef MEDIA_CAST_PACING_PACED_SENDER_H_ | |
6 #define MEDIA_CAST_PACING_PACED_SENDER_H_ | |
7 | |
8 #include <list> | |
9 #include <vector> | |
10 | |
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" | |
20 | |
21 namespace media { | |
22 namespace cast { | |
23 | |
24 // We have this pure virtual class to enable mocking. | |
25 class PacedPacketSender { | |
26 public: | |
27 // Inform the pacer / sender of the total number of packets. | |
28 virtual bool SendPackets(const PacketList& packets) = 0; | |
29 | |
30 virtual bool ResendPackets(const PacketList& packets) = 0; | |
31 | |
32 virtual bool SendRtcpPacket(const Packet& packet) = 0; | |
33 | |
34 virtual ~PacedPacketSender() {} | |
35 }; | |
36 | |
37 class PacedSender : public PacedPacketSender, | |
38 public base::NonThreadSafe, | |
39 public base::SupportsWeakPtr<PacedSender> { | |
40 public: | |
41 PacedSender(scoped_refptr<CastEnvironment> cast_environment, | |
42 PacketSender* transport); | |
43 virtual ~PacedSender(); | |
44 | |
45 virtual bool SendPackets(const PacketList& packets) OVERRIDE; | |
46 | |
47 virtual bool ResendPackets(const PacketList& packets) OVERRIDE; | |
48 | |
49 virtual bool SendRtcpPacket(const Packet& packet) OVERRIDE; | |
50 | |
51 protected: | |
52 // Schedule a delayed task on the main cast thread when it's time to send the | |
53 // next packet burst. | |
54 void ScheduleNextSend(); | |
55 | |
56 // Process any pending packets in the queue(s). | |
57 void SendNextPacketBurst(); | |
58 | |
59 private: | |
60 bool SendPacketsToTransport(const PacketList& packets, | |
61 PacketList* packets_not_sent); | |
62 void SendStoredPackets(); | |
63 void UpdateBurstSize(size_t num_of_packets); | |
64 | |
65 scoped_refptr<CastEnvironment> cast_environment_; | |
66 size_t burst_size_; | |
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_; | |
74 | |
75 base::WeakPtrFactory<PacedSender> weak_factory_; | |
76 | |
77 DISALLOW_COPY_AND_ASSIGN(PacedSender); | |
78 }; | |
79 | |
80 } // namespace cast | |
81 } // namespace media | |
82 | |
83 #endif // MEDIA_CAST_PACING_PACED_SENDER_H_ | |
OLD | NEW |