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_SENDER_VIDEO_SENDER_H_ | 5 #ifndef MEDIA_CAST_SENDER_VIDEO_SENDER_H_ |
6 #define MEDIA_CAST_SENDER_VIDEO_SENDER_H_ | 6 #define MEDIA_CAST_SENDER_VIDEO_SENDER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 // Note: It is invalid to call this method if InitializationResult() returns | 54 // Note: It is invalid to call this method if InitializationResult() returns |
55 // anything but STATUS_VIDEO_INITIALIZED. | 55 // anything but STATUS_VIDEO_INITIALIZED. |
56 void InsertRawVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame, | 56 void InsertRawVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame, |
57 const base::TimeTicks& capture_time); | 57 const base::TimeTicks& capture_time); |
58 | 58 |
59 protected: | 59 protected: |
60 // Protected for testability. | 60 // Protected for testability. |
61 void OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback); | 61 void OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback); |
62 | 62 |
63 private: | 63 private: |
64 // Schedule and execute periodic checks for re-sending packets. If no | |
65 // acknowledgements have been received for "too long," VideoSender will | |
66 // speculatively re-send certain packets of an unacked frame to kick-start | |
67 // re-transmission. This is a last resort tactic to prevent the session from | |
68 // getting stuck after a long outage. | |
69 void ScheduleNextResendCheck(); | |
70 void ResendCheck(); | |
71 void ResendForKickstart(); | |
72 | |
73 // Returns true if there are too many frames in flight, as defined by the | 64 // Returns true if there are too many frames in flight, as defined by the |
74 // configured target playout delay plus simple logic. When this is true, | 65 // configured target playout delay plus simple logic. When this is true, |
75 // InsertRawVideoFrame() will silenty drop frames instead of sending them to | 66 // InsertRawVideoFrame() will silenty drop frames instead of sending them to |
76 // the video encoder. | 67 // the video encoder. |
77 bool AreTooManyFramesInFlight() const; | 68 bool AreTooManyFramesInFlight() const; |
78 | 69 |
79 // Called by the |video_encoder_| with the next EncodeFrame to send. | 70 // Called by the |video_encoder_| with the next EncodeFrame to send. |
80 void SendEncodedVideoFrame(int requested_bitrate_before_encode, | 71 void SendEncodedVideoFrame(int requested_bitrate_before_encode, |
81 scoped_ptr<EncodedFrame> encoded_frame); | 72 scoped_ptr<EncodedFrame> encoded_frame); |
82 // If this value is non zero then a fixed value is used for bitrate. | 73 // If this value is non zero then a fixed value is used for bitrate. |
83 // If external video encoder is used then bitrate will be fixed to | 74 // If external video encoder is used then bitrate will be fixed to |
84 // (min_bitrate + max_bitrate) / 2. | 75 // (min_bitrate + max_bitrate) / 2. |
85 const size_t fixed_bitrate_; | 76 const size_t fixed_bitrate_; |
86 | 77 |
87 // Encodes media::VideoFrame images into EncodedFrames. Per configuration, | 78 // Encodes media::VideoFrame images into EncodedFrames. Per configuration, |
88 // this will point to either the internal software-based encoder or a proxy to | 79 // this will point to either the internal software-based encoder or a proxy to |
89 // a hardware-based encoder. | 80 // a hardware-based encoder. |
90 scoped_ptr<VideoEncoder> video_encoder_; | 81 scoped_ptr<VideoEncoder> video_encoder_; |
91 | 82 |
92 // Counts how many RTCP reports are being "aggressively" sent (i.e., one per | |
93 // frame) at the start of the session. Once a threshold is reached, RTCP | |
94 // reports are instead sent at the configured interval + random drift. | |
95 int num_aggressive_rtcp_reports_sent_; | |
96 | |
97 // The number of frames currently being processed in |video_encoder_|. | 83 // The number of frames currently being processed in |video_encoder_|. |
98 int frames_in_encoder_; | 84 int frames_in_encoder_; |
99 | 85 |
100 // This is "null" until the first frame is sent. Thereafter, this tracks the | |
101 // last time any frame was sent or re-sent. | |
102 base::TimeTicks last_send_time_; | |
103 | |
104 // The ID of the last frame sent. Logic throughout VideoSender assumes this | |
105 // can safely wrap-around. This member is invalid until | |
106 // |!last_send_time_.is_null()|. | |
107 uint32 last_sent_frame_id_; | |
108 | |
109 // The ID of the latest (not necessarily the last) frame that has been | |
110 // acknowledged. Logic throughout VideoSender assumes this can safely | |
111 // wrap-around. This member is invalid until |!last_send_time_.is_null()|. | |
112 uint32 latest_acked_frame_id_; | |
113 | |
114 // Counts the number of duplicate ACK that are being received. When this | |
115 // number reaches a threshold, the sender will take this as a sign that the | |
116 // receiver hasn't yet received the first packet of the next frame. In this | |
117 // case, VideoSender will trigger a re-send of the next frame. | |
118 int duplicate_ack_counter_; | |
119 | |
120 // When we get close to the max number of un-acked frames, we set lower | 86 // When we get close to the max number of un-acked frames, we set lower |
121 // the bitrate drastically to ensure that we catch up. Without this we | 87 // the bitrate drastically to ensure that we catch up. Without this we |
122 // risk getting stuck in a catch-up state forever. | 88 // risk getting stuck in a catch-up state forever. |
123 CongestionControl congestion_control_; | 89 CongestionControl congestion_control_; |
124 | 90 |
125 // If this sender is ready for use, this is STATUS_VIDEO_INITIALIZED. | |
126 CastInitializationStatus cast_initialization_status_; | |
127 | |
128 // This is a "good enough" mapping for finding the RTP timestamp associated | |
129 // with a video frame. The key is the lowest 8 bits of frame id (which is | |
130 // what is sent via RTCP). This map is used for logging purposes. | |
131 RtpTimestamp frame_id_to_rtp_timestamp_[256]; | |
132 | |
133 // NOTE: Weak pointers must be invalidated before all other member variables. | 91 // NOTE: Weak pointers must be invalidated before all other member variables. |
134 base::WeakPtrFactory<VideoSender> weak_factory_; | 92 base::WeakPtrFactory<VideoSender> weak_factory_; |
135 | 93 |
136 DISALLOW_COPY_AND_ASSIGN(VideoSender); | 94 DISALLOW_COPY_AND_ASSIGN(VideoSender); |
137 }; | 95 }; |
138 | 96 |
139 } // namespace cast | 97 } // namespace cast |
140 } // namespace media | 98 } // namespace media |
141 | 99 |
142 #endif // MEDIA_CAST_SENDER_VIDEO_SENDER_H_ | 100 #endif // MEDIA_CAST_SENDER_VIDEO_SENDER_H_ |
OLD | NEW |