OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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> | 8 #include <deque> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/time/tick_clock.h" | 12 #include "base/time/tick_clock.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 | 14 |
15 namespace media { | 15 namespace media { |
16 namespace cast { | 16 namespace cast { |
17 | 17 |
18 class CongestionControl { | 18 class CongestionControl { |
19 public: | 19 public: |
20 CongestionControl(base::TickClock* clock, | |
21 uint32 max_bitrate_configured, | |
22 uint32 min_bitrate_configured, | |
23 size_t max_unacked_frames); | |
24 | |
25 virtual ~CongestionControl(); | 20 virtual ~CongestionControl(); |
26 | 21 |
27 void UpdateRtt(base::TimeDelta rtt); | 22 // Called with latest measured rtt value. |
| 23 virtual void UpdateRtt(base::TimeDelta rtt) = 0; |
28 | 24 |
29 // Called when an encoded frame is sent to the transport. | 25 // Called when an encoded frame is sent to the transport. |
30 void SendFrameToTransport(uint32 frame_id, | 26 virtual void SendFrameToTransport(uint32 frame_id, |
31 size_t frame_size, | 27 size_t frame_size, |
32 base::TimeTicks when); | 28 base::TimeTicks when) = 0; |
33 | |
34 // Called when we receive an ACK for a frame. | 29 // Called when we receive an ACK for a frame. |
35 void AckFrame(uint32 frame_id, base::TimeTicks when); | 30 virtual void AckFrame(uint32 frame_id, base::TimeTicks when) = 0; |
36 | 31 |
37 // Returns the bitrate we should use for the next frame. | 32 // Returns the bitrate we should use for the next frame. |
38 uint32 GetBitrate(base::TimeTicks playout_time, | 33 virtual uint32 GetBitrate(base::TimeTicks playout_time, |
39 base::TimeDelta playout_delay); | 34 base::TimeDelta playout_delay) = 0; |
| 35 }; |
40 | 36 |
41 private: | 37 CongestionControl* NewAdaptiveCongestionControl( |
42 struct FrameStats { | 38 base::TickClock* clock, |
43 FrameStats(); | 39 uint32 max_bitrate_configured, |
44 // Time this frame was sent to the transport. | 40 uint32 min_bitrate_configured, |
45 base::TimeTicks sent_time; | 41 size_t max_unacked_frames); |
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 | 42 |
52 // Calculate how much "dead air" (idle time) there is between two frames. | 43 CongestionControl* NewFixedCongestionControl(uint32 bitrate); |
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 // Calculate a 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 obviously can't be less than |sent_time| (if known). | |
67 base::TimeTicks EstimatedSendingTime(uint32 frame_id, double bitrate); | |
68 | |
69 base::TickClock* const clock_; // Not owned by this class. | |
70 const uint32 max_bitrate_configured_; | |
71 const uint32 min_bitrate_configured_; | |
72 std::deque<FrameStats> frame_stats_; | |
73 uint32 last_frame_stats_; | |
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_; | |
80 | |
81 DISALLOW_COPY_AND_ASSIGN(CongestionControl); | |
82 }; | |
83 | 44 |
84 } // namespace cast | 45 } // namespace cast |
85 } // namespace media | 46 } // namespace media |
86 | 47 |
87 #endif // MEDIA_CAST_CONGESTION_CONTROL_CONGESTION_CONTROL_H_ | 48 #endif // MEDIA_CAST_CONGESTION_CONTROL_CONGESTION_CONTROL_H_ |
OLD | NEW |