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 // This is the base class for an object that send frames to a receiver. | 5 // This is the base class for an object that send frames to a receiver. |
6 // TODO(hclam): Refactor such that there is no separate AudioSender vs. | 6 // TODO(hclam): Refactor such that there is no separate AudioSender vs. |
7 // VideoSender, and the functionality of both is rolled into this class. | 7 // VideoSender, and the functionality of both is rolled into this class. |
8 | 8 |
9 #ifndef MEDIA_CAST_SENDER_FRAME_SENDER_H_ | 9 #ifndef MEDIA_CAST_SENDER_FRAME_SENDER_H_ |
10 #define MEDIA_CAST_SENDER_FRAME_SENDER_H_ | 10 #define MEDIA_CAST_SENDER_FRAME_SENDER_H_ |
(...skipping 16 matching lines...) Expand all Loading... |
27 CastTransportSender* const transport_sender, | 27 CastTransportSender* const transport_sender, |
28 base::TimeDelta rtcp_interval, | 28 base::TimeDelta rtcp_interval, |
29 int rtp_timebase, | 29 int rtp_timebase, |
30 uint32 ssrc, | 30 uint32 ssrc, |
31 double max_frame_rate, | 31 double max_frame_rate, |
32 base::TimeDelta min_playout_delay, | 32 base::TimeDelta min_playout_delay, |
33 base::TimeDelta max_playout_delay, | 33 base::TimeDelta max_playout_delay, |
34 CongestionControl* congestion_control); | 34 CongestionControl* congestion_control); |
35 virtual ~FrameSender(); | 35 virtual ~FrameSender(); |
36 | 36 |
| 37 int rtp_timebase() const { return rtp_timebase_; } |
| 38 |
37 // Calling this function is only valid if the receiver supports the | 39 // Calling this function is only valid if the receiver supports the |
38 // "extra_playout_delay", rtp extension. | 40 // "extra_playout_delay", rtp extension. |
39 void SetTargetPlayoutDelay(base::TimeDelta new_target_playout_delay); | 41 void SetTargetPlayoutDelay(base::TimeDelta new_target_playout_delay); |
40 | 42 |
41 base::TimeDelta GetTargetPlayoutDelay() const { | 43 base::TimeDelta GetTargetPlayoutDelay() const { |
42 return target_playout_delay_; | 44 return target_playout_delay_; |
43 } | 45 } |
44 | 46 |
45 // Called by the encoder with the next EncodeFrame to send. | 47 // Called by the encoder with the next EncodeFrame to send. |
46 void SendEncodedFrame(int requested_bitrate_before_encode, | 48 void SendEncodedFrame(int requested_bitrate_before_encode, |
47 scoped_ptr<EncodedFrame> encoded_frame); | 49 scoped_ptr<EncodedFrame> encoded_frame); |
48 | 50 |
49 protected: | 51 protected: |
50 // Returns the number of frames in the encoder's backlog. | 52 // Returns the number of frames in the encoder's backlog. |
51 virtual int GetNumberOfFramesInEncoder() const = 0; | 53 virtual int GetNumberOfFramesInEncoder() const = 0; |
52 | 54 |
| 55 // Returns the duration of the data in the encoder's backlog plus the duration |
| 56 // of sent, unacknowledged frames. |
| 57 virtual base::TimeDelta GetInFlightMediaDuration() const = 0; |
| 58 |
53 // Called when we get an ACK for a frame. | 59 // Called when we get an ACK for a frame. |
54 virtual void OnAck(uint32 frame_id) = 0; | 60 virtual void OnAck(uint32 frame_id) = 0; |
55 | 61 |
56 protected: | 62 protected: |
57 // Schedule and execute periodic sending of RTCP report. | 63 // Schedule and execute periodic sending of RTCP report. |
58 void ScheduleNextRtcpReport(); | 64 void ScheduleNextRtcpReport(); |
59 void SendRtcpReport(bool schedule_future_reports); | 65 void SendRtcpReport(bool schedule_future_reports); |
60 | 66 |
61 void OnMeasuredRoundTripTime(base::TimeDelta rtt); | 67 void OnMeasuredRoundTripTime(base::TimeDelta rtt); |
62 | 68 |
(...skipping 14 matching lines...) Expand all Loading... |
77 // speculatively re-send certain packets of an unacked frame to kick-start | 83 // speculatively re-send certain packets of an unacked frame to kick-start |
78 // re-transmission. This is a last resort tactic to prevent the session from | 84 // re-transmission. This is a last resort tactic to prevent the session from |
79 // getting stuck after a long outage. | 85 // getting stuck after a long outage. |
80 void ScheduleNextResendCheck(); | 86 void ScheduleNextResendCheck(); |
81 void ResendCheck(); | 87 void ResendCheck(); |
82 void ResendForKickstart(); | 88 void ResendForKickstart(); |
83 | 89 |
84 // Protected for testability. | 90 // Protected for testability. |
85 void OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback); | 91 void OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback); |
86 | 92 |
87 // Returns true if there are too many frames in flight, or if the media | 93 // Returns true if too many frames would be in-flight by encoding and sending |
88 // duration of the frames in flight would be too high by sending the next | 94 // the next frame having the given |frame_duration|. |
89 // frame. The latter metric is determined from the given |capture_time| | 95 bool ShouldDropNextFrame(base::TimeDelta frame_duration) const; |
90 // for the next frame to be encoded and sent. | |
91 bool ShouldDropNextFrame(base::TimeTicks capture_time) const; | |
92 | 96 |
93 // Record or retrieve a recent history of each frame's timestamps. | 97 // Record or retrieve a recent history of each frame's timestamps. |
94 // Warning: If a frame ID too far in the past is requested, the getters will | 98 // Warning: If a frame ID too far in the past is requested, the getters will |
95 // silently succeed but return incorrect values. Be sure to respect | 99 // silently succeed but return incorrect values. Be sure to respect |
96 // media::cast::kMaxUnackedFrames. | 100 // media::cast::kMaxUnackedFrames. |
97 void RecordLatestFrameTimestamps(uint32 frame_id, | 101 void RecordLatestFrameTimestamps(uint32 frame_id, |
98 base::TimeTicks reference_time, | 102 base::TimeTicks reference_time, |
99 RtpTimestamp rtp_timestamp); | 103 RtpTimestamp rtp_timestamp); |
100 base::TimeTicks GetRecordedReferenceTime(uint32 frame_id) const; | 104 base::TimeTicks GetRecordedReferenceTime(uint32 frame_id) const; |
101 RtpTimestamp GetRecordedRtpTimestamp(uint32 frame_id) const; | 105 RtpTimestamp GetRecordedRtpTimestamp(uint32 frame_id) const; |
102 | 106 |
| 107 // Returns the number of frames that were sent but not yet acknowledged. |
| 108 int GetUnacknowledgedFrameCount() const; |
| 109 |
103 const base::TimeDelta rtcp_interval_; | 110 const base::TimeDelta rtcp_interval_; |
104 | 111 |
105 // The total amount of time between a frame's capture/recording on the sender | 112 // The total amount of time between a frame's capture/recording on the sender |
106 // and its playback on the receiver (i.e., shown to a user). This is fixed as | 113 // and its playback on the receiver (i.e., shown to a user). This is fixed as |
107 // a value large enough to give the system sufficient time to encode, | 114 // a value large enough to give the system sufficient time to encode, |
108 // transmit/retransmit, receive, decode, and render; given its run-time | 115 // transmit/retransmit, receive, decode, and render; given its run-time |
109 // environment (sender/receiver hardware performance, network conditions, | 116 // environment (sender/receiver hardware performance, network conditions, |
110 // etc.). | 117 // etc.). |
111 base::TimeDelta target_playout_delay_; | 118 base::TimeDelta target_playout_delay_; |
112 base::TimeDelta min_playout_delay_; | 119 base::TimeDelta min_playout_delay_; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 // Counts the number of duplicate ACK that are being received. When this | 151 // Counts the number of duplicate ACK that are being received. When this |
145 // number reaches a threshold, the sender will take this as a sign that the | 152 // number reaches a threshold, the sender will take this as a sign that the |
146 // receiver hasn't yet received the first packet of the next frame. In this | 153 // receiver hasn't yet received the first packet of the next frame. In this |
147 // case, VideoSender will trigger a re-send of the next frame. | 154 // case, VideoSender will trigger a re-send of the next frame. |
148 int duplicate_ack_counter_; | 155 int duplicate_ack_counter_; |
149 | 156 |
150 // If this sender is ready for use, this is STATUS_AUDIO_INITIALIZED or | 157 // If this sender is ready for use, this is STATUS_AUDIO_INITIALIZED or |
151 // STATUS_VIDEO_INITIALIZED. | 158 // STATUS_VIDEO_INITIALIZED. |
152 CastInitializationStatus cast_initialization_status_; | 159 CastInitializationStatus cast_initialization_status_; |
153 | 160 |
154 // RTP timestamp increment representing one second. | |
155 const int rtp_timebase_; | |
156 | |
157 // This object controls how we change the bitrate to make sure the | 161 // This object controls how we change the bitrate to make sure the |
158 // buffer doesn't overflow. | 162 // buffer doesn't overflow. |
159 scoped_ptr<CongestionControl> congestion_control_; | 163 scoped_ptr<CongestionControl> congestion_control_; |
160 | 164 |
161 // The most recently measured round trip time. | 165 // The most recently measured round trip time. |
162 base::TimeDelta current_round_trip_time_; | 166 base::TimeDelta current_round_trip_time_; |
163 | 167 |
164 private: | 168 private: |
| 169 // Returns the maximum media duration currently allowed in-flight. This |
| 170 // fluctuates in response to the currently-measured network latency. |
| 171 base::TimeDelta GetAllowedInFlightMediaDuration() const; |
| 172 |
| 173 // RTP timestamp increment representing one second. |
| 174 const int rtp_timebase_; |
| 175 |
165 const bool is_audio_; | 176 const bool is_audio_; |
166 | 177 |
167 // Ring buffers to keep track of recent frame timestamps (both in terms of | 178 // Ring buffers to keep track of recent frame timestamps (both in terms of |
168 // local reference time and RTP media time). These should only be accessed | 179 // local reference time and RTP media time). These should only be accessed |
169 // through the Record/GetXXX() methods. | 180 // through the Record/GetXXX() methods. |
170 base::TimeTicks frame_reference_times_[256]; | 181 base::TimeTicks frame_reference_times_[256]; |
171 RtpTimestamp frame_rtp_timestamps_[256]; | 182 RtpTimestamp frame_rtp_timestamps_[256]; |
172 | 183 |
173 // NOTE: Weak pointers must be invalidated before all other member variables. | 184 // NOTE: Weak pointers must be invalidated before all other member variables. |
174 base::WeakPtrFactory<FrameSender> weak_factory_; | 185 base::WeakPtrFactory<FrameSender> weak_factory_; |
175 | 186 |
176 DISALLOW_COPY_AND_ASSIGN(FrameSender); | 187 DISALLOW_COPY_AND_ASSIGN(FrameSender); |
177 }; | 188 }; |
178 | 189 |
179 } // namespace cast | 190 } // namespace cast |
180 } // namespace media | 191 } // namespace media |
181 | 192 |
182 #endif // MEDIA_CAST_SENDER_FRAME_SENDER_H_ | 193 #endif // MEDIA_CAST_SENDER_FRAME_SENDER_H_ |
OLD | NEW |