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_VIDEO_SENDER_VIDEO_SENDER_H_ | 5 #ifndef MEDIA_CAST_VIDEO_SENDER_VIDEO_SENDER_H_ |
6 #define MEDIA_CAST_VIDEO_SENDER_VIDEO_SENDER_H_ | 6 #define MEDIA_CAST_VIDEO_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 26 matching lines...) Expand all Loading... |
37 // Additionally it posts a bunch of delayed tasks to the main thread for various | 37 // Additionally it posts a bunch of delayed tasks to the main thread for various |
38 // timeouts. | 38 // timeouts. |
39 class VideoSender : public RtcpSenderFeedback, | 39 class VideoSender : public RtcpSenderFeedback, |
40 public base::NonThreadSafe, | 40 public base::NonThreadSafe, |
41 public base::SupportsWeakPtr<VideoSender> { | 41 public base::SupportsWeakPtr<VideoSender> { |
42 public: | 42 public: |
43 VideoSender(scoped_refptr<CastEnvironment> cast_environment, | 43 VideoSender(scoped_refptr<CastEnvironment> cast_environment, |
44 const VideoSenderConfig& video_config, | 44 const VideoSenderConfig& video_config, |
45 const CreateVideoEncodeAcceleratorCallback& create_vea_cb, | 45 const CreateVideoEncodeAcceleratorCallback& create_vea_cb, |
46 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb, | 46 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb, |
47 const CastInitializationCallback& cast_initialization_cb, | |
48 transport::CastTransportSender* const transport_sender); | 47 transport::CastTransportSender* const transport_sender); |
49 | 48 |
50 virtual ~VideoSender(); | 49 virtual ~VideoSender(); |
51 | 50 |
| 51 CastInitializationStatus InitializationResult() const { |
| 52 return cast_initialization_status_; |
| 53 } |
| 54 |
52 // The video_frame must be valid until the closure callback is called. | 55 // The video_frame must be valid until the closure callback is called. |
53 // The closure callback is called from the video encoder thread as soon as | 56 // The closure callback is called from the video encoder thread as soon as |
54 // the encoder is done with the frame; it does not mean that the encoded frame | 57 // the encoder is done with the frame; it does not mean that the encoded frame |
55 // has been sent out. | 58 // has been sent out. |
| 59 // |
| 60 // Note: It is invalid to call this method if InitializationResult() returns |
| 61 // anything but STATUS_VIDEO_INITIALIZED. |
56 void InsertRawVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame, | 62 void InsertRawVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame, |
57 const base::TimeTicks& capture_time); | 63 const base::TimeTicks& capture_time); |
58 | 64 |
59 // Only called from the main cast thread. | 65 // Only called from the main cast thread. |
60 void IncomingRtcpPacket(scoped_ptr<Packet> packet); | 66 void IncomingRtcpPacket(scoped_ptr<Packet> packet); |
61 | 67 |
62 protected: | 68 protected: |
63 // Protected for testability. | 69 // Protected for testability. |
64 virtual void OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback) | 70 virtual void OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback) |
65 OVERRIDE; | 71 OVERRIDE; |
(...skipping 17 matching lines...) Expand all Loading... |
83 | 89 |
84 // Monitor how many frames that are silently dropped by the video sender | 90 // Monitor how many frames that are silently dropped by the video sender |
85 // per time unit. | 91 // per time unit. |
86 void ScheduleNextSkippedFramesCheck(); | 92 void ScheduleNextSkippedFramesCheck(); |
87 void SkippedFramesCheck(); | 93 void SkippedFramesCheck(); |
88 | 94 |
89 void ResendFrame(uint32 resend_frame_id); | 95 void ResendFrame(uint32 resend_frame_id); |
90 void ReceivedAck(uint32 acked_frame_id); | 96 void ReceivedAck(uint32 acked_frame_id); |
91 void UpdateFramesInFlight(); | 97 void UpdateFramesInFlight(); |
92 | 98 |
93 void SendEncodedVideoFrameMainThread( | 99 // Called by the |video_encoder_| with the next EncodeFrame to send. |
94 int requested_bitrate_before_encode, | 100 void SendEncodedVideoFrame(int requested_bitrate_before_encode, |
95 scoped_ptr<transport::EncodedFrame> encoded_frame); | 101 scoped_ptr<transport::EncodedFrame> encoded_frame); |
96 | 102 |
97 void InitializeTimers(); | 103 void InitializeTimers(); |
98 | 104 |
99 void UpdateBitrate(int32 new_bitrate); | 105 void UpdateBitrate(int32 new_bitrate); |
100 | 106 |
101 base::TimeDelta rtp_max_delay_; | 107 base::TimeDelta rtp_max_delay_; |
102 const int max_frame_rate_; | 108 const int max_frame_rate_; |
103 | 109 |
104 scoped_refptr<CastEnvironment> cast_environment_; | 110 scoped_refptr<CastEnvironment> cast_environment_; |
105 transport::CastTransportSender* const transport_sender_; | 111 transport::CastTransportSender* const transport_sender_; |
106 | 112 |
107 RtpTimestampHelper rtp_timestamp_helper_; | 113 RtpTimestampHelper rtp_timestamp_helper_; |
108 scoped_ptr<VideoEncoder> video_encoder_; | 114 scoped_ptr<VideoEncoder> video_encoder_; |
109 scoped_ptr<Rtcp> rtcp_; | 115 scoped_ptr<Rtcp> rtcp_; |
110 int num_aggressive_rtcp_reports_sent_; | 116 int num_aggressive_rtcp_reports_sent_; |
111 uint8 max_unacked_frames_; | 117 uint8 max_unacked_frames_; |
112 int last_acked_frame_id_; | 118 int last_acked_frame_id_; |
113 int last_sent_frame_id_; | 119 int last_sent_frame_id_; |
114 int frames_in_encoder_; | 120 int frames_in_encoder_; |
115 int duplicate_ack_; | 121 int duplicate_ack_; |
116 base::TimeTicks last_send_time_; | 122 base::TimeTicks last_send_time_; |
117 base::TimeTicks last_checked_skip_count_time_; | 123 base::TimeTicks last_checked_skip_count_time_; |
118 int last_skip_count_; | 124 int last_skip_count_; |
119 int current_requested_bitrate_; | 125 int current_requested_bitrate_; |
120 // When we get close to the max number of un-acked frames, we set lower | 126 // 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 | 127 // the bitrate drastically to ensure that we catch up. Without this we |
122 // risk getting stuck in a catch-up state forever. | 128 // risk getting stuck in a catch-up state forever. |
123 CongestionControl congestion_control_; | 129 CongestionControl congestion_control_; |
124 | 130 |
| 131 // If this sender is ready for use, this is STATUS_VIDEO_INITIALIZED. |
| 132 CastInitializationStatus cast_initialization_status_; |
| 133 |
125 // This is a "good enough" mapping for finding the RTP timestamp associated | 134 // This is a "good enough" mapping for finding the RTP timestamp associated |
126 // with a video frame. The key is the lowest 8 bits of frame id (which is | 135 // with a video frame. The key is the lowest 8 bits of frame id (which is |
127 // what is sent via RTCP). This map is used for logging purposes. The only | 136 // what is sent via RTCP). This map is used for logging purposes. The only |
128 // time when this mapping will be incorrect is when it receives an ACK for a | 137 // time when this mapping will be incorrect is when it receives an ACK for a |
129 // old enough frame such that 8-bit wrap around has already occurred, which | 138 // old enough frame such that 8-bit wrap around has already occurred, which |
130 // should be pretty rare. | 139 // should be pretty rare. |
131 RtpTimestamp frame_id_to_rtp_timestamp_[256]; | 140 RtpTimestamp frame_id_to_rtp_timestamp_[256]; |
132 | 141 |
133 bool initialized_; | 142 bool initialized_; |
134 // Indicator for receiver acknowledgments. | 143 // Indicator for receiver acknowledgments. |
135 bool active_session_; | 144 bool active_session_; |
136 | 145 |
137 // NOTE: Weak pointers must be invalidated before all other member variables. | 146 // NOTE: Weak pointers must be invalidated before all other member variables. |
138 base::WeakPtrFactory<VideoSender> weak_factory_; | 147 base::WeakPtrFactory<VideoSender> weak_factory_; |
139 | 148 |
140 DISALLOW_COPY_AND_ASSIGN(VideoSender); | 149 DISALLOW_COPY_AND_ASSIGN(VideoSender); |
141 }; | 150 }; |
142 | 151 |
143 } // namespace cast | 152 } // namespace cast |
144 } // namespace media | 153 } // namespace media |
145 | 154 |
146 #endif // MEDIA_CAST_VIDEO_SENDER_VIDEO_SENDER_H_ | 155 #endif // MEDIA_CAST_VIDEO_SENDER_VIDEO_SENDER_H_ |
OLD | NEW |