OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "webrtc/modules/video_coding/include/video_coding.h" | 21 #include "webrtc/modules/video_coding/include/video_coding.h" |
22 #include "webrtc/modules/video_coding/include/video_coding_defines.h" | 22 #include "webrtc/modules/video_coding/include/video_coding_defines.h" |
23 #include "webrtc/system_wrappers/include/metrics.h" | 23 #include "webrtc/system_wrappers/include/metrics.h" |
24 #include "webrtc/video/overuse_frame_detector.h" | 24 #include "webrtc/video/overuse_frame_detector.h" |
25 #include "webrtc/video/send_statistics_proxy.h" | 25 #include "webrtc/video/send_statistics_proxy.h" |
26 #include "webrtc/video_frame.h" | 26 #include "webrtc/video_frame.h" |
27 | 27 |
28 namespace webrtc { | 28 namespace webrtc { |
29 | 29 |
30 ViEEncoder::ViEEncoder(uint32_t number_of_cores, | 30 ViEEncoder::ViEEncoder(uint32_t number_of_cores, |
31 ProcessThread* module_process_thread, | |
32 SendStatisticsProxy* stats_proxy, | 31 SendStatisticsProxy* stats_proxy, |
33 OveruseFrameDetector* overuse_detector, | 32 OveruseFrameDetector* overuse_detector, |
34 EncodedImageCallback* sink) | 33 EncodedImageCallback* sink) |
35 : number_of_cores_(number_of_cores), | 34 : number_of_cores_(number_of_cores), |
36 sink_(sink), | 35 sink_(sink), |
37 vp_(VideoProcessing::Create()), | 36 vp_(VideoProcessing::Create()), |
38 video_sender_(Clock::GetRealTimeClock(), this, this, this), | 37 video_sender_(Clock::GetRealTimeClock(), this, this, this), |
39 stats_proxy_(stats_proxy), | 38 stats_proxy_(stats_proxy), |
40 overuse_detector_(overuse_detector), | 39 overuse_detector_(overuse_detector), |
41 time_of_last_frame_activity_ms_(std::numeric_limits<int64_t>::max()), | |
42 encoder_config_(), | 40 encoder_config_(), |
43 last_observed_bitrate_bps_(0), | 41 last_observed_bitrate_bps_(0), |
44 encoder_paused_and_dropped_frame_(false), | 42 encoder_paused_and_dropped_frame_(false), |
45 module_process_thread_(module_process_thread), | 43 module_process_thread_(nullptr), |
46 has_received_sli_(false), | 44 has_received_sli_(false), |
47 picture_id_sli_(0), | 45 picture_id_sli_(0), |
48 has_received_rpsi_(false), | 46 has_received_rpsi_(false), |
49 picture_id_rpsi_(0), | 47 picture_id_rpsi_(0), |
50 video_suspended_(false) { | 48 video_suspended_(false) { |
51 module_process_thread_->RegisterModule(&video_sender_); | |
52 vp_->EnableTemporalDecimation(true); | 49 vp_->EnableTemporalDecimation(true); |
53 } | 50 } |
54 | 51 |
55 vcm::VideoSender* ViEEncoder::video_sender() { | 52 vcm::VideoSender* ViEEncoder::video_sender() { |
56 return &video_sender_; | 53 return &video_sender_; |
57 } | 54 } |
58 | 55 |
59 ViEEncoder::~ViEEncoder() { | 56 ViEEncoder::~ViEEncoder() {} |
| 57 |
| 58 void ViEEncoder::RegisterProcessThread(ProcessThread* module_process_thread) { |
| 59 RTC_DCHECK(!module_process_thread_); |
| 60 module_process_thread_ = module_process_thread; |
| 61 module_process_thread_->RegisterModule(&video_sender_); |
| 62 } |
| 63 void ViEEncoder::DeRegisterProcessThread() { |
60 module_process_thread_->DeRegisterModule(&video_sender_); | 64 module_process_thread_->DeRegisterModule(&video_sender_); |
61 } | 65 } |
62 | 66 |
63 int32_t ViEEncoder::RegisterExternalEncoder(webrtc::VideoEncoder* encoder, | 67 int32_t ViEEncoder::RegisterExternalEncoder(webrtc::VideoEncoder* encoder, |
64 uint8_t pl_type, | 68 uint8_t pl_type, |
65 bool internal_source) { | 69 bool internal_source) { |
66 video_sender_.RegisterExternalEncoder(encoder, pl_type, internal_source); | 70 video_sender_.RegisterExternalEncoder(encoder, pl_type, internal_source); |
67 return 0; | 71 return 0; |
68 } | 72 } |
69 | 73 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 if (encoder_paused_and_dropped_frame_) { | 136 if (encoder_paused_and_dropped_frame_) { |
133 TRACE_EVENT_ASYNC_END0("webrtc", "EncoderPaused", this); | 137 TRACE_EVENT_ASYNC_END0("webrtc", "EncoderPaused", this); |
134 } | 138 } |
135 encoder_paused_and_dropped_frame_ = false; | 139 encoder_paused_and_dropped_frame_ = false; |
136 } | 140 } |
137 | 141 |
138 void ViEEncoder::EncodeVideoFrame(const VideoFrame& video_frame) { | 142 void ViEEncoder::EncodeVideoFrame(const VideoFrame& video_frame) { |
139 VideoCodecType codec_type; | 143 VideoCodecType codec_type; |
140 { | 144 { |
141 rtc::CritScope lock(&data_cs_); | 145 rtc::CritScope lock(&data_cs_); |
142 time_of_last_frame_activity_ms_ = rtc::TimeMillis(); | |
143 if (EncoderPaused()) { | 146 if (EncoderPaused()) { |
144 TraceFrameDropStart(); | 147 TraceFrameDropStart(); |
145 return; | 148 return; |
146 } | 149 } |
147 TraceFrameDropEnd(); | 150 TraceFrameDropEnd(); |
148 codec_type = encoder_config_.codecType; | 151 codec_type = encoder_config_.codecType; |
149 } | 152 } |
150 | 153 |
151 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(), | 154 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(), |
152 "Encode"); | 155 "Encode"); |
(...skipping 28 matching lines...) Expand all Loading... |
181 video_sender_.AddVideoFrame(*frame_to_send, &codec_specific_info); | 184 video_sender_.AddVideoFrame(*frame_to_send, &codec_specific_info); |
182 return; | 185 return; |
183 } | 186 } |
184 video_sender_.AddVideoFrame(*frame_to_send, nullptr); | 187 video_sender_.AddVideoFrame(*frame_to_send, nullptr); |
185 } | 188 } |
186 | 189 |
187 void ViEEncoder::SendKeyFrame() { | 190 void ViEEncoder::SendKeyFrame() { |
188 video_sender_.IntraFrameRequest(0); | 191 video_sender_.IntraFrameRequest(0); |
189 } | 192 } |
190 | 193 |
191 int64_t ViEEncoder::time_of_last_frame_activity_ms() { | |
192 rtc::CritScope lock(&data_cs_); | |
193 return time_of_last_frame_activity_ms_; | |
194 } | |
195 | |
196 void ViEEncoder::OnSetRates(uint32_t bitrate_bps, int framerate) { | 194 void ViEEncoder::OnSetRates(uint32_t bitrate_bps, int framerate) { |
197 if (stats_proxy_) | 195 if (stats_proxy_) |
198 stats_proxy_->OnSetRates(bitrate_bps, framerate); | 196 stats_proxy_->OnSetRates(bitrate_bps, framerate); |
199 } | 197 } |
200 | 198 |
201 int32_t ViEEncoder::Encoded(const EncodedImage& encoded_image, | 199 int32_t ViEEncoder::Encoded(const EncodedImage& encoded_image, |
202 const CodecSpecificInfo* codec_specific_info, | 200 const CodecSpecificInfo* codec_specific_info, |
203 const RTPFragmentationHeader* fragmentation) { | 201 const RTPFragmentationHeader* fragmentation) { |
204 { | |
205 rtc::CritScope lock(&data_cs_); | |
206 time_of_last_frame_activity_ms_ = rtc::TimeMillis(); | |
207 } | |
208 if (stats_proxy_) { | 202 if (stats_proxy_) { |
209 stats_proxy_->OnSendEncodedImage(encoded_image, codec_specific_info); | 203 stats_proxy_->OnSendEncodedImage(encoded_image, codec_specific_info); |
210 } | 204 } |
211 | 205 |
212 int success = | 206 int success = |
213 sink_->Encoded(encoded_image, codec_specific_info, fragmentation); | 207 sink_->Encoded(encoded_image, codec_specific_info, fragmentation); |
214 | 208 |
215 overuse_detector_->FrameSent(encoded_image._timeStamp); | 209 overuse_detector_->FrameSent(encoded_image._timeStamp); |
216 return success; | 210 return success; |
217 } | 211 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 << " rtt " << round_trip_time_ms; | 243 << " rtt " << round_trip_time_ms; |
250 video_sender_.SetChannelParameters(bitrate_bps, fraction_lost, | 244 video_sender_.SetChannelParameters(bitrate_bps, fraction_lost, |
251 round_trip_time_ms); | 245 round_trip_time_ms); |
252 bool video_suspension_changed; | 246 bool video_suspension_changed; |
253 bool video_is_suspended = bitrate_bps == 0; | 247 bool video_is_suspended = bitrate_bps == 0; |
254 { | 248 { |
255 rtc::CritScope lock(&data_cs_); | 249 rtc::CritScope lock(&data_cs_); |
256 last_observed_bitrate_bps_ = bitrate_bps; | 250 last_observed_bitrate_bps_ = bitrate_bps; |
257 video_suspension_changed = video_suspended_ != video_is_suspended; | 251 video_suspension_changed = video_suspended_ != video_is_suspended; |
258 video_suspended_ = video_is_suspended; | 252 video_suspended_ = video_is_suspended; |
259 // Set |time_of_last_frame_activity_ms_| to now if this is the first time | |
260 // the encoder is supposed to produce encoded frames. | |
261 // TODO(perkj): Remove this hack. It is here to avoid a race that the | |
262 // encoder report that it has timed out before it has processed the first | |
263 // frame. | |
264 if (last_observed_bitrate_bps_ != 0 && | |
265 time_of_last_frame_activity_ms_ == | |
266 std::numeric_limits<int64_t>::max()) { | |
267 time_of_last_frame_activity_ms_ = rtc::TimeMillis(); | |
268 } | |
269 } | 253 } |
270 | 254 |
271 if (stats_proxy_ && video_suspension_changed) { | 255 if (stats_proxy_ && video_suspension_changed) { |
272 LOG(LS_INFO) << "Video suspend state changed to: " | 256 LOG(LS_INFO) << "Video suspend state changed to: " |
273 << (video_is_suspended ? "suspended" : "not suspended"); | 257 << (video_is_suspended ? "suspended" : "not suspended"); |
274 stats_proxy_->OnSuspendChange(video_is_suspended); | 258 stats_proxy_->OnSuspendChange(video_is_suspended); |
275 } | 259 } |
276 } | 260 } |
277 | 261 |
278 } // namespace webrtc | 262 } // namespace webrtc |
OLD | NEW |