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_CONGESTION_CONTROL_CONGESTION_CONTROL_H_ | 5 #ifndef MEDIA_CAST_CONGESTION_CONTROL_CONGESTION_CONTROL_H_ |
6 #define MEDIA_CAST_CONGESTION_CONTROL_CONGESTION_CONTROL_H_ | 6 #define MEDIA_CAST_CONGESTION_CONTROL_CONGESTION_CONTROL_H_ |
7 | 7 |
| 8 #include <deque> |
| 9 |
8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
10 #include "base/time/tick_clock.h" | 12 #include "base/time/tick_clock.h" |
11 #include "base/time/time.h" | 13 #include "base/time/time.h" |
12 | 14 |
13 namespace media { | 15 namespace media { |
14 namespace cast { | 16 namespace cast { |
15 | 17 |
16 class CongestionControl { | 18 class CongestionControl { |
17 public: | 19 public: |
18 CongestionControl(base::TickClock* clock, | 20 CongestionControl(base::TickClock* clock, |
19 float congestion_control_back_off, | |
20 uint32 max_bitrate_configured, | 21 uint32 max_bitrate_configured, |
21 uint32 min_bitrate_configured, | 22 uint32 min_bitrate_configured, |
22 uint32 start_bitrate); | 23 size_t max_unacked_frames); |
23 | 24 |
24 virtual ~CongestionControl(); | 25 virtual ~CongestionControl(); |
25 | 26 |
26 // Don't call OnAck if the same message contain a NACK. | 27 void UpdateRtt(base::TimeDelta rtt); |
27 // Returns true if the bitrate have changed. | |
28 bool OnAck(base::TimeDelta rtt_ms, uint32* new_bitrate); | |
29 | 28 |
30 // Returns true if the bitrate have changed. | 29 // Called when an encoded frame is sent to the transport. |
31 bool OnNack(base::TimeDelta rtt_ms, uint32* new_bitrate); | 30 void SendFrameToTransport(uint32 frame_id, |
| 31 size_t frame_size, |
| 32 base::TimeTicks when); |
| 33 |
| 34 // Called when we receive an ACK for a frame. |
| 35 void AckFrame(uint32 frame_id, base::TimeTicks when); |
| 36 |
| 37 // Returns the bitrate we should use for the next frame. |
| 38 uint32 GetBitrate(base::TimeTicks playout_time, |
| 39 base::TimeDelta playout_delay); |
32 | 40 |
33 private: | 41 private: |
| 42 struct FrameStats { |
| 43 FrameStats(); |
| 44 // Time this frame was sent to the transport. |
| 45 base::TimeTicks sent_time; |
| 46 // Time this frame was acked. |
| 47 base::TimeTicks ack_time; |
| 48 // Size of encoded frame in bits. |
| 49 size_t frame_size; |
| 50 }; |
| 51 |
| 52 // Calculate how much "dead air" (idle time) there is between two frames. |
| 53 static base::TimeDelta DeadTime(const FrameStats& a, const FrameStats& b); |
| 54 // Get the FrameStats for a given |frame_id|. |
| 55 // Note: Older FrameStats will be removed automatically. |
| 56 FrameStats* GetFrameStats(uint32 frame_id); |
| 57 // Calculata safe bitrate. This is based on how much we've been |
| 58 // sending in the past. |
| 59 double CalculateSafeBitrate(); |
| 60 |
| 61 // For a given frame, calculate when it might be acked. |
| 62 // (Or return the time it was acked, if it was.) |
| 63 base::TimeTicks EstimatedAckTime(uint32 frame_id, double bitrate); |
| 64 // Calculate when we start sending the data for a given frame. |
| 65 // This is done by calculating when we were done sending the previous |
| 66 // frame, but obvoiusly can't be less than |sent_time| (if known). |
| 67 base::TimeTicks EstimatedSendingTime(uint32 frame_id, double bitrate); |
| 68 |
34 base::TickClock* const clock_; // Not owned by this class. | 69 base::TickClock* const clock_; // Not owned by this class. |
35 const float congestion_control_back_off_; | |
36 const uint32 max_bitrate_configured_; | 70 const uint32 max_bitrate_configured_; |
37 const uint32 min_bitrate_configured_; | 71 const uint32 min_bitrate_configured_; |
38 uint32 bitrate_; | 72 std::deque<FrameStats> frame_stats_; |
39 base::TimeTicks time_last_increase_; | 73 uint32 last_frame_stats_; |
40 base::TimeTicks time_last_decrease_; | 74 uint32 last_acked_frame_; |
| 75 uint32 last_encoded_frame_; |
| 76 base::TimeDelta rtt_; |
| 77 size_t history_size_; |
| 78 size_t acked_bits_in_history_; |
| 79 base::TimeDelta dead_time_in_history_; |
41 | 80 |
42 DISALLOW_COPY_AND_ASSIGN(CongestionControl); | 81 DISALLOW_COPY_AND_ASSIGN(CongestionControl); |
43 }; | 82 }; |
44 | 83 |
45 } // namespace cast | 84 } // namespace cast |
46 } // namespace media | 85 } // namespace media |
47 | 86 |
48 #endif // MEDIA_CAST_CONGESTION_CONTROL_CONGESTION_CONTROL_H_ | 87 #endif // MEDIA_CAST_CONGESTION_CONTROL_CONGESTION_CONTROL_H_ |
OLD | NEW |