Chromium Code Reviews| 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); |
|
Alpha Left Google
2014/06/10 22:20:39
nit: This should be Rtt to be consistent with the
hubbe
2014/06/11 00:04:15
Done.
Alpha Left Google
2014/06/11 01:16:28
I mean UpdateRtt instead of UpdateRTT. The variabl
| |
| 27 // Returns true if the bitrate have changed. | 28 void SendFrameToTransport(uint32 frame_id, |
|
Alpha Left Google
2014/06/10 22:20:39
Please document this method. When should this be c
hubbe
2014/06/11 00:04:15
Done.
| |
| 28 bool OnAck(base::TimeDelta rtt_ms, uint32* new_bitrate); | 29 size_t frame_size, |
| 30 base::TimeTicks when); | |
| 31 void AckFrame(uint32 frame_id, base::TimeTicks when); | |
|
Alpha Left Google
2014/06/10 22:20:39
Please document. A one line is sufficient.
hubbe
2014/06/11 00:04:15
Done.
| |
| 29 | 32 |
| 30 // Returns true if the bitrate have changed. | 33 // Returns the bitrate we should use for the next frame. |
| 31 bool OnNack(base::TimeDelta rtt_ms, uint32* new_bitrate); | 34 uint32 GetBitrate(base::TimeTicks playout_time, |
| 35 base::TimeDelta playout_delay); | |
| 32 | 36 |
| 33 private: | 37 private: |
| 38 struct FrameStats { | |
| 39 FrameStats(); | |
| 40 // Time this frame was sent to the transport. | |
| 41 base::TimeTicks sent_time; | |
| 42 // Time this frame was acked. | |
| 43 base::TimeTicks ack_time; | |
| 44 // Size of encoded frame in bits. | |
| 45 size_t frame_size; | |
| 46 }; | |
| 47 | |
| 48 // Calculate how much "dead air" there is between two frames. | |
|
Alpha Left Google
2014/06/10 22:20:39
Please be more descriptive of what "dead air" mean
hubbe
2014/06/11 00:04:15
Done.
| |
| 49 static base::TimeDelta DeadTime(const FrameStats& a, const FrameStats& b); | |
| 50 // Get the FrameStats for a given |frame_id|. | |
| 51 // Note: Older FrameStats will be removed automatically. | |
| 52 FrameStats* GetFrameStats(uint32 frame_id); | |
| 53 // Calculata safe bitrate. This is based on how much we've been | |
| 54 // sending in the past. | |
| 55 double CalculateSafeBitrate(); | |
| 56 | |
| 57 // For a given frame, calculate when it might be acked. | |
| 58 // (Or return the time it was acked, if it was.) | |
| 59 base::TimeTicks EstimatedAckTime(uint32 frame_id, double bitrate); | |
| 60 // Calculate when we start sending the data for a given frame. | |
| 61 // This is done by calculating when we were done sending the previous | |
| 62 // frame, but obvoiusly can't be less than |sent_time| (if known). | |
| 63 base::TimeTicks EstimatedSendingTime(uint32 frame_id, double bitrate); | |
| 64 | |
| 34 base::TickClock* const clock_; // Not owned by this class. | 65 base::TickClock* const clock_; // Not owned by this class. |
| 35 const float congestion_control_back_off_; | |
| 36 const uint32 max_bitrate_configured_; | 66 const uint32 max_bitrate_configured_; |
| 37 const uint32 min_bitrate_configured_; | 67 const uint32 min_bitrate_configured_; |
| 38 uint32 bitrate_; | 68 std::deque<FrameStats> frame_stats_; |
| 39 base::TimeTicks time_last_increase_; | 69 uint32 last_frame_stats_; |
| 40 base::TimeTicks time_last_decrease_; | 70 uint32 last_acked_frame_; |
| 71 uint32 last_encoded_frame_; | |
| 72 base::TimeDelta rtt_; | |
| 73 size_t history_size_; | |
| 74 size_t acked_bits_in_history_; | |
| 75 base::TimeDelta dead_time_in_history_; | |
| 41 | 76 |
| 42 DISALLOW_COPY_AND_ASSIGN(CongestionControl); | 77 DISALLOW_COPY_AND_ASSIGN(CongestionControl); |
| 43 }; | 78 }; |
| 44 | 79 |
| 45 } // namespace cast | 80 } // namespace cast |
| 46 } // namespace media | 81 } // namespace media |
| 47 | 82 |
| 48 #endif // MEDIA_CAST_CONGESTION_CONTROL_CONGESTION_CONTROL_H_ | 83 #endif // MEDIA_CAST_CONGESTION_CONTROL_CONGESTION_CONTROL_H_ |
| OLD | NEW |