OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_CAST_TRANSPORT_PACING_PACED_SENDER_H_ | 5 #ifndef MEDIA_CAST_TRANSPORT_PACING_PACED_SENDER_H_ |
6 #define MEDIA_CAST_TRANSPORT_PACING_PACED_SENDER_H_ | 6 #define MEDIA_CAST_TRANSPORT_PACING_PACED_SENDER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/threading/non_thread_safe.h" | 14 #include "base/threading/non_thread_safe.h" |
15 #include "base/time/default_tick_clock.h" | 15 #include "base/time/default_tick_clock.h" |
16 #include "base/time/tick_clock.h" | 16 #include "base/time/tick_clock.h" |
17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
18 #include "media/cast/cast_config.h" // PacketSender | 18 #include "media/cast/cast_config.h" |
19 #include "media/cast/transport/cast_transport_config.h" | 19 #include "media/cast/cast_environment.h" |
20 | 20 |
21 namespace media { | 21 namespace media { |
22 namespace cast { | 22 namespace cast { |
23 namespace transport { | 23 namespace transport { |
24 | 24 |
25 // We have this pure virtual class to enable mocking. | 25 // We have this pure virtual class to enable mocking. |
26 class PacedPacketSender { | 26 class PacedPacketSender { |
27 public: | 27 public: |
28 // Inform the pacer / sender of the total number of packets. | 28 // Inform the pacer / sender of the total number of packets. |
29 virtual bool SendPackets(const PacketList& packets) = 0; | 29 virtual bool SendPackets(const PacketList& packets) = 0; |
30 | 30 |
31 virtual bool ResendPackets(const PacketList& packets) = 0; | 31 virtual bool ResendPackets(const PacketList& packets) = 0; |
32 | 32 |
33 virtual bool SendRtcpPacket(const Packet& packet) = 0; | 33 virtual bool SendRtcpPacket(const Packet& packet) = 0; |
34 | 34 |
35 virtual ~PacedPacketSender() {} | 35 virtual ~PacedPacketSender() {} |
36 }; | 36 }; |
37 | 37 |
38 class PacedSender : public PacedPacketSender, | 38 class PacedSender : public PacedPacketSender, |
39 public base::NonThreadSafe, | 39 public base::NonThreadSafe, |
40 public base::SupportsWeakPtr<PacedSender> { | 40 public base::SupportsWeakPtr<PacedSender> { |
41 public: | 41 public: |
42 PacedSender(base::TickClock* clock, | 42 PacedSender(scoped_refptr<CastEnvironment> cast_environment, |
43 PacketSender* transport, | 43 PacketSender* transport); |
44 scoped_refptr<base::TaskRunner> transport_task_runner); | |
45 virtual ~PacedSender(); | 44 virtual ~PacedSender(); |
46 | 45 |
47 virtual bool SendPackets(const PacketList& packets) OVERRIDE; | 46 virtual bool SendPackets(const PacketList& packets) OVERRIDE; |
48 | 47 |
49 virtual bool ResendPackets(const PacketList& packets) OVERRIDE; | 48 virtual bool ResendPackets(const PacketList& packets) OVERRIDE; |
50 | 49 |
51 virtual bool SendRtcpPacket(const Packet& packet) OVERRIDE; | 50 virtual bool SendRtcpPacket(const Packet& packet) OVERRIDE; |
52 | 51 |
53 protected: | 52 protected: |
54 // Schedule a delayed task on the main cast thread when it's time to send the | 53 // Schedule a delayed task on the main cast thread when it's time to send the |
55 // next packet burst. | 54 // next packet burst. |
56 void ScheduleNextSend(); | 55 void ScheduleNextSend(); |
57 | 56 |
58 // Process any pending packets in the queue(s). | 57 // Process any pending packets in the queue(s). |
59 void SendNextPacketBurst(); | 58 void SendNextPacketBurst(); |
60 | 59 |
61 private: | 60 private: |
62 bool SendPacketsToTransport(const PacketList& packets, | 61 bool SendPacketsToTransport(const PacketList& packets, |
63 PacketList* packets_not_sent); | 62 PacketList* packets_not_sent); |
64 void SendStoredPackets(); | 63 void SendStoredPackets(); |
65 void UpdateBurstSize(size_t num_of_packets); | 64 void UpdateBurstSize(size_t num_of_packets); |
66 | 65 |
67 // Not owned by this class. | 66 scoped_refptr<CastEnvironment> cast_environment_; |
68 base::TickClock* const clock_; | |
69 PacketSender* transport_; | 67 PacketSender* transport_; |
70 scoped_refptr<base::TaskRunner> transport_task_runner_; | |
71 | 68 |
72 size_t burst_size_; | 69 size_t burst_size_; |
73 size_t packets_sent_in_burst_; | 70 size_t packets_sent_in_burst_; |
74 base::TimeTicks time_last_process_; | 71 base::TimeTicks time_last_process_; |
75 // Note: We can't combine the |packet_list_| and the |resend_packet_list_| | 72 // Note: We can't combine the |packet_list_| and the |resend_packet_list_| |
76 // since then we might get reordering of the retransmitted packets. | 73 // since then we might get reordering of the retransmitted packets. |
77 PacketList packet_list_; | 74 PacketList packet_list_; |
78 PacketList resend_packet_list_; | 75 PacketList resend_packet_list_; |
79 | 76 |
80 base::WeakPtrFactory<PacedSender> weak_factory_; | 77 base::WeakPtrFactory<PacedSender> weak_factory_; |
81 | 78 |
82 DISALLOW_COPY_AND_ASSIGN(PacedSender); | 79 DISALLOW_COPY_AND_ASSIGN(PacedSender); |
83 }; | 80 }; |
84 | 81 |
85 } // namespace transport | 82 } // namespace transport |
86 } // namespace cast | 83 } // namespace cast |
87 } // namespace media | 84 } // namespace media |
88 | 85 |
89 #endif // MEDIA_CAST_TRANSPORT_PACING_PACED_SENDER_H_ | 86 #endif // MEDIA_CAST_TRANSPORT_PACING_PACED_SENDER_H_ |
OLD | NEW |