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 |
(...skipping 23 matching lines...) Expand all Loading... |
34 // 2. The sort order of the PacketKey determines the order that packets | 34 // 2. The sort order of the PacketKey determines the order that packets |
35 // are sent out. Using the capture_time as the first member basically | 35 // are sent out. Using the capture_time as the first member basically |
36 // means that older packets are sent first. | 36 // means that older packets are sent first. |
37 typedef std::pair<base::TimeTicks, std::pair<uint32, uint16> > PacketKey; | 37 typedef std::pair<base::TimeTicks, std::pair<uint32, uint16> > PacketKey; |
38 typedef std::vector<std::pair<PacketKey, PacketRef> > SendPacketVector; | 38 typedef std::vector<std::pair<PacketKey, PacketRef> > SendPacketVector; |
39 | 39 |
40 // We have this pure virtual class to enable mocking. | 40 // We have this pure virtual class to enable mocking. |
41 class PacedPacketSender { | 41 class PacedPacketSender { |
42 public: | 42 public: |
43 virtual bool SendPackets(const SendPacketVector& packets) = 0; | 43 virtual bool SendPackets(const SendPacketVector& packets) = 0; |
44 virtual bool ResendPackets(const SendPacketVector& packets) = 0; | 44 virtual bool ResendPackets(const SendPacketVector& packets, |
| 45 base::TimeDelta dedupe_window) = 0; |
45 virtual bool SendRtcpPacket(uint32 ssrc, PacketRef packet) = 0; | 46 virtual bool SendRtcpPacket(uint32 ssrc, PacketRef packet) = 0; |
46 virtual void CancelSendingPacket(const PacketKey& packet_key) = 0; | 47 virtual void CancelSendingPacket(const PacketKey& packet_key) = 0; |
47 | 48 |
48 virtual ~PacedPacketSender() {} | 49 virtual ~PacedPacketSender() {} |
49 | 50 |
50 static PacketKey MakePacketKey(const base::TimeTicks& ticks, | 51 static PacketKey MakePacketKey(const base::TimeTicks& ticks, |
51 uint32 ssrc, | 52 uint32 ssrc, |
52 uint16 packet_id); | 53 uint16 packet_id); |
53 }; | 54 }; |
54 | 55 |
(...skipping 10 matching lines...) Expand all Loading... |
65 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner); | 66 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner); |
66 | 67 |
67 virtual ~PacedSender(); | 68 virtual ~PacedSender(); |
68 | 69 |
69 // These must be called before non-RTCP packets are sent. | 70 // These must be called before non-RTCP packets are sent. |
70 void RegisterAudioSsrc(uint32 audio_ssrc); | 71 void RegisterAudioSsrc(uint32 audio_ssrc); |
71 void RegisterVideoSsrc(uint32 video_ssrc); | 72 void RegisterVideoSsrc(uint32 video_ssrc); |
72 | 73 |
73 // PacedPacketSender implementation. | 74 // PacedPacketSender implementation. |
74 virtual bool SendPackets(const SendPacketVector& packets) OVERRIDE; | 75 virtual bool SendPackets(const SendPacketVector& packets) OVERRIDE; |
75 virtual bool ResendPackets(const SendPacketVector& packets) OVERRIDE; | 76 virtual bool ResendPackets(const SendPacketVector& packets, |
| 77 base::TimeDelta dedupe_window) OVERRIDE; |
76 virtual bool SendRtcpPacket(uint32 ssrc, PacketRef packet) OVERRIDE; | 78 virtual bool SendRtcpPacket(uint32 ssrc, PacketRef packet) OVERRIDE; |
77 virtual void CancelSendingPacket(const PacketKey& packet_key) OVERRIDE; | 79 virtual void CancelSendingPacket(const PacketKey& packet_key) OVERRIDE; |
78 | 80 |
79 private: | 81 private: |
80 // Actually sends the packets to the transport. | 82 // Actually sends the packets to the transport. |
81 void SendStoredPackets(); | 83 void SendStoredPackets(); |
82 void LogPacketEvent(const Packet& packet, bool retransmit); | 84 void LogPacketEvent(const Packet& packet, CastLoggingEvent event); |
83 | 85 |
84 enum PacketType { | 86 enum PacketType { |
85 PacketType_RTCP, | 87 PacketType_RTCP, |
86 PacketType_Resend, | 88 PacketType_Resend, |
87 PacketType_Normal | 89 PacketType_Normal |
88 }; | 90 }; |
89 enum State { | 91 enum State { |
90 // In an unblocked state, we can send more packets. | 92 // In an unblocked state, we can send more packets. |
91 // We have to check the current time against |burst_end_| to see if we are | 93 // We have to check the current time against |burst_end_| to see if we are |
92 // appending to the current burst or if we can start a new one. | 94 // appending to the current burst or if we can start a new one. |
93 State_Unblocked, | 95 State_Unblocked, |
94 // In this state, we are waiting for a callback from the udp transport. | 96 // In this state, we are waiting for a callback from the udp transport. |
95 // This happens when the OS-level buffer is full. Once we receive the | 97 // This happens when the OS-level buffer is full. Once we receive the |
96 // callback, we go to State_Unblocked and see if we can write more packets | 98 // callback, we go to State_Unblocked and see if we can write more packets |
97 // to the current burst. (Or the next burst if enough time has passed.) | 99 // to the current burst. (Or the next burst if enough time has passed.) |
98 State_TransportBlocked, | 100 State_TransportBlocked, |
99 // Once we've written enough packets for a time slice, we go into this | 101 // Once we've written enough packets for a time slice, we go into this |
100 // state and PostDelayTask a call to ourselves to wake up when we can | 102 // state and PostDelayTask a call to ourselves to wake up when we can |
101 // send more data. | 103 // send more data. |
102 State_BurstFull | 104 State_BurstFull |
103 }; | 105 }; |
104 | 106 |
105 bool empty() const; | 107 bool empty() const; |
106 size_t size() const; | 108 size_t size() const; |
107 | 109 |
108 // Returns the next packet to send. RTCP packets have highest priority, | 110 // Returns the next packet to send. RTCP packets have highest priority, |
109 // resend packets have second highest priority and then comes everything | 111 // resend packets have second highest priority and then comes everything |
110 // else. | 112 // else. |
111 PacketRef GetNextPacket(PacketType* packet_type); | 113 PacketRef GetNextPacket(PacketType* packet_type, |
| 114 PacketKey* packet_key); |
112 | 115 |
113 base::TickClock* const clock_; // Not owned by this class. | 116 base::TickClock* const clock_; // Not owned by this class. |
114 LoggingImpl* const logging_; // Not owned by this class. | 117 LoggingImpl* const logging_; // Not owned by this class. |
115 PacketSender* transport_; // Not owned by this class. | 118 PacketSender* transport_; // Not owned by this class. |
116 scoped_refptr<base::SingleThreadTaskRunner> transport_task_runner_; | 119 scoped_refptr<base::SingleThreadTaskRunner> transport_task_runner_; |
117 uint32 audio_ssrc_; | 120 uint32 audio_ssrc_; |
118 uint32 video_ssrc_; | 121 uint32 video_ssrc_; |
119 std::map<PacketKey, std::pair<PacketType, PacketRef> > packet_list_; | 122 std::map<PacketKey, std::pair<PacketType, PacketRef> > packet_list_; |
| 123 std::map<PacketKey, base::TimeTicks> sent_time_; |
| 124 std::map<PacketKey, base::TimeTicks> sent_time_buffer_; |
120 | 125 |
121 // Maximum burst size for the next three bursts. | 126 // Maximum burst size for the next three bursts. |
122 size_t max_burst_size_; | 127 size_t max_burst_size_; |
123 size_t next_max_burst_size_; | 128 size_t next_max_burst_size_; |
124 size_t next_next_max_burst_size_; | 129 size_t next_next_max_burst_size_; |
125 // Number of packets already sent in the current burst. | 130 // Number of packets already sent in the current burst. |
126 size_t current_burst_size_; | 131 size_t current_burst_size_; |
127 // This is when the current burst ends. | 132 // This is when the current burst ends. |
128 base::TimeTicks burst_end_; | 133 base::TimeTicks burst_end_; |
129 | 134 |
130 State state_; | 135 State state_; |
131 | 136 |
132 // NOTE: Weak pointers must be invalidated before all other member variables. | 137 // NOTE: Weak pointers must be invalidated before all other member variables. |
133 base::WeakPtrFactory<PacedSender> weak_factory_; | 138 base::WeakPtrFactory<PacedSender> weak_factory_; |
134 | 139 |
135 DISALLOW_COPY_AND_ASSIGN(PacedSender); | 140 DISALLOW_COPY_AND_ASSIGN(PacedSender); |
136 }; | 141 }; |
137 | 142 |
138 } // namespace transport | 143 } // namespace transport |
139 } // namespace cast | 144 } // namespace cast |
140 } // namespace media | 145 } // namespace media |
141 | 146 |
142 #endif // MEDIA_CAST_TRANSPORT_PACING_PACED_SENDER_H_ | 147 #endif // MEDIA_CAST_TRANSPORT_PACING_PACED_SENDER_H_ |
OLD | NEW |