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