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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 SendStatisticsProxy* stats_proxy, | 84 SendStatisticsProxy* stats_proxy, |
85 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, | 85 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, |
86 OveruseFrameDetector* overuse_detector, | 86 OveruseFrameDetector* overuse_detector, |
87 PacedSender* pacer, | 87 PacedSender* pacer, |
88 PayloadRouter* payload_router, | 88 PayloadRouter* payload_router, |
89 EncodedImageCallback* post_encode_callback) | 89 EncodedImageCallback* post_encode_callback) |
90 : number_of_cores_(number_of_cores), | 90 : number_of_cores_(number_of_cores), |
91 ssrcs_(ssrcs), | 91 ssrcs_(ssrcs), |
92 vp_(VideoProcessing::Create()), | 92 vp_(VideoProcessing::Create()), |
93 qm_callback_(new QMVideoSettingsCallback(vp_.get())), | 93 qm_callback_(new QMVideoSettingsCallback(vp_.get())), |
94 vcm_(VideoCodingModule::Create(Clock::GetRealTimeClock(), | 94 video_sender_(Clock::GetRealTimeClock(), this, this, qm_callback_.get()), |
95 this, | |
96 qm_callback_.get())), | |
97 stats_proxy_(stats_proxy), | 95 stats_proxy_(stats_proxy), |
98 pre_encode_callback_(pre_encode_callback), | 96 pre_encode_callback_(pre_encode_callback), |
99 overuse_detector_(overuse_detector), | 97 overuse_detector_(overuse_detector), |
100 pacer_(pacer), | 98 pacer_(pacer), |
101 send_payload_router_(payload_router), | 99 send_payload_router_(payload_router), |
102 post_encode_callback_(post_encode_callback), | 100 post_encode_callback_(post_encode_callback), |
103 time_of_last_frame_activity_ms_(0), | 101 time_of_last_frame_activity_ms_(0), |
104 encoder_config_(), | 102 encoder_config_(), |
105 min_transmit_bitrate_bps_(0), | 103 min_transmit_bitrate_bps_(0), |
106 last_observed_bitrate_bps_(0), | 104 last_observed_bitrate_bps_(0), |
107 network_is_transmitting_(true), | 105 network_is_transmitting_(true), |
108 encoder_paused_(false), | 106 encoder_paused_(false), |
109 encoder_paused_and_dropped_frame_(false), | 107 encoder_paused_and_dropped_frame_(false), |
110 time_last_intra_request_ms_(ssrcs.size(), -1), | 108 time_last_intra_request_ms_(ssrcs.size(), -1), |
111 module_process_thread_(module_process_thread), | 109 module_process_thread_(module_process_thread), |
112 has_received_sli_(false), | 110 has_received_sli_(false), |
113 picture_id_sli_(0), | 111 picture_id_sli_(0), |
114 has_received_rpsi_(false), | 112 has_received_rpsi_(false), |
115 picture_id_rpsi_(0), | 113 picture_id_rpsi_(0), |
116 video_suspended_(false) { | 114 video_suspended_(false) { |
117 module_process_thread_->RegisterModule(vcm_.get()); | 115 module_process_thread_->RegisterModule(&video_sender_); |
118 } | 116 } |
119 | 117 |
120 bool ViEEncoder::Init() { | 118 bool ViEEncoder::Init() { |
121 vp_->EnableTemporalDecimation(true); | 119 vp_->EnableTemporalDecimation(true); |
122 | 120 |
123 // Enable/disable content analysis: off by default for now. | 121 // Enable/disable content analysis: off by default for now. |
124 vp_->EnableContentAnalysis(false); | 122 vp_->EnableContentAnalysis(false); |
125 | 123 |
126 vcm_->RegisterPostEncodeImageCallback(this); | |
127 | |
128 // TODO(perkj): Remove |RegisterTransportCallback| as soon as we don't use | 124 // TODO(perkj): Remove |RegisterTransportCallback| as soon as we don't use |
129 // VCMPacketizationCallback::OnEncoderImplementationName. | 125 // VCMPacketizationCallback::OnEncoderImplementationName. |
130 if (vcm_->RegisterTransportCallback(this) != 0) { | 126 if (video_sender_.RegisterTransportCallback(this) != 0) { |
131 return false; | 127 return false; |
132 } | 128 } |
133 if (vcm_->RegisterSendStatisticsCallback(this) != 0) { | 129 if (video_sender_.RegisterSendStatisticsCallback(this) != 0) { |
134 return false; | 130 return false; |
135 } | 131 } |
136 return true; | 132 return true; |
137 } | 133 } |
138 | 134 |
139 VideoCodingModule* ViEEncoder::vcm() const { | 135 vcm::VideoSender* ViEEncoder::video_sender() { |
140 return vcm_.get(); | 136 return &video_sender_; |
141 } | 137 } |
142 | 138 |
143 ViEEncoder::~ViEEncoder() { | 139 ViEEncoder::~ViEEncoder() { |
144 module_process_thread_->DeRegisterModule(vcm_.get()); | 140 module_process_thread_->DeRegisterModule(&video_sender_); |
145 } | 141 } |
146 | 142 |
147 void ViEEncoder::SetNetworkTransmissionState(bool is_transmitting) { | 143 void ViEEncoder::SetNetworkTransmissionState(bool is_transmitting) { |
148 { | 144 { |
149 rtc::CritScope lock(&data_cs_); | 145 rtc::CritScope lock(&data_cs_); |
150 network_is_transmitting_ = is_transmitting; | 146 network_is_transmitting_ = is_transmitting; |
151 } | 147 } |
152 } | 148 } |
153 | 149 |
154 void ViEEncoder::Pause() { | 150 void ViEEncoder::Pause() { |
155 rtc::CritScope lock(&data_cs_); | 151 rtc::CritScope lock(&data_cs_); |
156 encoder_paused_ = true; | 152 encoder_paused_ = true; |
157 } | 153 } |
158 | 154 |
159 void ViEEncoder::Restart() { | 155 void ViEEncoder::Restart() { |
160 rtc::CritScope lock(&data_cs_); | 156 rtc::CritScope lock(&data_cs_); |
161 encoder_paused_ = false; | 157 encoder_paused_ = false; |
162 } | 158 } |
163 | 159 |
164 int32_t ViEEncoder::RegisterExternalEncoder(webrtc::VideoEncoder* encoder, | 160 int32_t ViEEncoder::RegisterExternalEncoder(webrtc::VideoEncoder* encoder, |
165 uint8_t pl_type, | 161 uint8_t pl_type, |
166 bool internal_source) { | 162 bool internal_source) { |
167 if (vcm_->RegisterExternalEncoder(encoder, pl_type, internal_source) != | 163 video_sender_.RegisterExternalEncoder(encoder, pl_type, internal_source); |
168 VCM_OK) { | |
169 return -1; | |
170 } | |
171 return 0; | 164 return 0; |
172 } | 165 } |
173 | 166 |
174 int32_t ViEEncoder::DeRegisterExternalEncoder(uint8_t pl_type) { | 167 int32_t ViEEncoder::DeRegisterExternalEncoder(uint8_t pl_type) { |
175 if (vcm_->RegisterExternalEncoder(nullptr, pl_type) != VCM_OK) { | 168 video_sender_.RegisterExternalEncoder(nullptr, pl_type, false); |
176 return -1; | |
177 } | |
178 return 0; | 169 return 0; |
179 } | 170 } |
180 void ViEEncoder::SetEncoder(const webrtc::VideoCodec& video_codec, | 171 void ViEEncoder::SetEncoder(const webrtc::VideoCodec& video_codec, |
181 int min_transmit_bitrate_bps) { | 172 int min_transmit_bitrate_bps) { |
182 RTC_DCHECK(send_payload_router_); | 173 RTC_DCHECK(send_payload_router_); |
183 // Setting target width and height for VPM. | 174 // Setting target width and height for VPM. |
184 RTC_CHECK_EQ(VPM_OK, | 175 RTC_CHECK_EQ(VPM_OK, |
185 vp_->SetTargetResolution(video_codec.width, video_codec.height, | 176 vp_->SetTargetResolution(video_codec.width, video_codec.height, |
186 video_codec.maxFramerate)); | 177 video_codec.maxFramerate)); |
187 | 178 |
188 // Cache codec before calling AddBitrateObserver (which calls OnBitrateUpdated | 179 // Cache codec before calling AddBitrateObserver (which calls OnBitrateUpdated |
189 // that makes use of the number of simulcast streams configured). | 180 // that makes use of the number of simulcast streams configured). |
190 { | 181 { |
191 rtc::CritScope lock(&data_cs_); | 182 rtc::CritScope lock(&data_cs_); |
192 encoder_config_ = video_codec; | 183 encoder_config_ = video_codec; |
193 encoder_paused_ = true; | 184 encoder_paused_ = true; |
194 min_transmit_bitrate_bps_ = min_transmit_bitrate_bps; | 185 min_transmit_bitrate_bps_ = min_transmit_bitrate_bps; |
195 } | 186 } |
196 | 187 |
197 size_t max_data_payload_length = send_payload_router_->MaxPayloadLength(); | 188 size_t max_data_payload_length = send_payload_router_->MaxPayloadLength(); |
198 bool success = vcm_->RegisterSendCodec( | 189 bool success = video_sender_.RegisterSendCodec( |
199 &video_codec, number_of_cores_, | 190 &video_codec, number_of_cores_, |
200 static_cast<uint32_t>(max_data_payload_length)) == VCM_OK; | 191 static_cast<uint32_t>(max_data_payload_length)) == VCM_OK; |
201 if (!success) { | 192 if (!success) { |
202 LOG(LS_ERROR) << "Failed to configure encoder."; | 193 LOG(LS_ERROR) << "Failed to configure encoder."; |
203 RTC_DCHECK(success); | 194 RTC_DCHECK(success); |
204 } | 195 } |
205 | 196 |
206 send_payload_router_->SetSendingRtpModules( | 197 send_payload_router_->SetSendingRtpModules( |
207 video_codec.numberOfSimulcastStreams); | 198 video_codec.numberOfSimulcastStreams); |
208 | 199 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 bool send_padding = encoder_config_.numberOfSimulcastStreams > 1 || | 232 bool send_padding = encoder_config_.numberOfSimulcastStreams > 1 || |
242 video_suspended_ || min_transmit_bitrate_bps_ > 0; | 233 video_suspended_ || min_transmit_bitrate_bps_ > 0; |
243 if (!send_padding) | 234 if (!send_padding) |
244 return 0; | 235 return 0; |
245 time_of_last_frame_activity_ms = time_of_last_frame_activity_ms_; | 236 time_of_last_frame_activity_ms = time_of_last_frame_activity_ms_; |
246 min_transmit_bitrate_bps = min_transmit_bitrate_bps_; | 237 min_transmit_bitrate_bps = min_transmit_bitrate_bps_; |
247 bitrate_bps = last_observed_bitrate_bps_; | 238 bitrate_bps = last_observed_bitrate_bps_; |
248 send_codec = encoder_config_; | 239 send_codec = encoder_config_; |
249 } | 240 } |
250 | 241 |
251 bool video_is_suspended = vcm_->VideoSuspended(); | 242 bool video_is_suspended = video_sender_.VideoSuspended(); |
252 | 243 |
253 // Find the max amount of padding we can allow ourselves to send at this | 244 // Find the max amount of padding we can allow ourselves to send at this |
254 // point, based on which streams are currently active and what our current | 245 // point, based on which streams are currently active and what our current |
255 // available bandwidth is. | 246 // available bandwidth is. |
256 int pad_up_to_bitrate_bps = 0; | 247 int pad_up_to_bitrate_bps = 0; |
257 if (send_codec.numberOfSimulcastStreams == 0) { | 248 if (send_codec.numberOfSimulcastStreams == 0) { |
258 pad_up_to_bitrate_bps = send_codec.minBitrate * 1000; | 249 pad_up_to_bitrate_bps = send_codec.minBitrate * 1000; |
259 } else { | 250 } else { |
260 SimulcastStream* stream_configs = send_codec.simulcastStream; | 251 SimulcastStream* stream_configs = send_codec.simulcastStream; |
261 pad_up_to_bitrate_bps = | 252 pad_up_to_bitrate_bps = |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 codec_specific_info.codecSpecific.VP8.hasReceivedSLI = | 354 codec_specific_info.codecSpecific.VP8.hasReceivedSLI = |
364 has_received_sli_; | 355 has_received_sli_; |
365 codec_specific_info.codecSpecific.VP8.pictureIdRPSI = | 356 codec_specific_info.codecSpecific.VP8.pictureIdRPSI = |
366 picture_id_rpsi_; | 357 picture_id_rpsi_; |
367 codec_specific_info.codecSpecific.VP8.pictureIdSLI = | 358 codec_specific_info.codecSpecific.VP8.pictureIdSLI = |
368 picture_id_sli_; | 359 picture_id_sli_; |
369 has_received_sli_ = false; | 360 has_received_sli_ = false; |
370 has_received_rpsi_ = false; | 361 has_received_rpsi_ = false; |
371 } | 362 } |
372 | 363 |
373 vcm_->AddVideoFrame(*frame_to_send, vp_->GetContentMetrics(), | 364 video_sender_.AddVideoFrame(*frame_to_send, vp_->GetContentMetrics(), |
374 &codec_specific_info); | 365 &codec_specific_info); |
375 return; | 366 return; |
376 } | 367 } |
377 vcm_->AddVideoFrame(*frame_to_send); | 368 video_sender_.AddVideoFrame(*frame_to_send, nullptr, nullptr); |
378 } | 369 } |
379 | 370 |
380 void ViEEncoder::SendKeyFrame() { | 371 void ViEEncoder::SendKeyFrame() { |
381 vcm_->IntraFrameRequest(0); | 372 video_sender_.IntraFrameRequest(0); |
382 } | |
383 | |
384 uint32_t ViEEncoder::LastObservedBitrateBps() const { | |
385 rtc::CritScope lock(&data_cs_); | |
386 return last_observed_bitrate_bps_; | |
387 } | |
388 | |
389 int ViEEncoder::CodecTargetBitrate(uint32_t* bitrate) const { | |
390 if (vcm_->Bitrate(bitrate) != 0) | |
391 return -1; | |
392 return 0; | |
393 } | 373 } |
394 | 374 |
395 void ViEEncoder::SetProtectionMethod(bool nack, bool fec) { | 375 void ViEEncoder::SetProtectionMethod(bool nack, bool fec) { |
396 // Set Video Protection for VCM. | 376 // Set Video Protection for VCM. |
397 VCMVideoProtection protection_mode; | 377 VCMVideoProtection protection_mode; |
398 if (fec) { | 378 if (fec) { |
399 protection_mode = | 379 protection_mode = |
400 nack ? webrtc::kProtectionNackFEC : kProtectionFEC; | 380 nack ? webrtc::kProtectionNackFEC : kProtectionFEC; |
401 } else { | 381 } else { |
402 protection_mode = nack ? kProtectionNack : kProtectionNone; | 382 protection_mode = nack ? kProtectionNack : kProtectionNone; |
403 } | 383 } |
404 vcm_->SetVideoProtection(protection_mode, true); | 384 video_sender_.SetVideoProtection(protection_mode); |
405 } | 385 } |
406 | 386 |
407 void ViEEncoder::OnSetRates(uint32_t bitrate_bps, int framerate) { | 387 void ViEEncoder::OnSetRates(uint32_t bitrate_bps, int framerate) { |
408 if (stats_proxy_) | 388 if (stats_proxy_) |
409 stats_proxy_->OnSetRates(bitrate_bps, framerate); | 389 stats_proxy_->OnSetRates(bitrate_bps, framerate); |
410 } | 390 } |
411 | 391 |
412 void ViEEncoder::OnEncoderImplementationName(const char* implementation_name) { | 392 void ViEEncoder::OnEncoderImplementationName(const char* implementation_name) { |
413 if (stats_proxy_) | 393 if (stats_proxy_) |
414 stats_proxy_->OnEncoderImplementationName(implementation_name); | 394 stats_proxy_->OnEncoderImplementationName(implementation_name); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 continue; | 473 continue; |
494 int64_t now_ms = TickTime::MillisecondTimestamp(); | 474 int64_t now_ms = TickTime::MillisecondTimestamp(); |
495 { | 475 { |
496 rtc::CritScope lock(&data_cs_); | 476 rtc::CritScope lock(&data_cs_); |
497 if (time_last_intra_request_ms_[i] + kMinKeyFrameRequestIntervalMs > | 477 if (time_last_intra_request_ms_[i] + kMinKeyFrameRequestIntervalMs > |
498 now_ms) { | 478 now_ms) { |
499 return; | 479 return; |
500 } | 480 } |
501 time_last_intra_request_ms_[i] = now_ms; | 481 time_last_intra_request_ms_[i] = now_ms; |
502 } | 482 } |
503 vcm_->IntraFrameRequest(static_cast<int>(i)); | 483 video_sender_.IntraFrameRequest(static_cast<int>(i)); |
504 return; | 484 return; |
505 } | 485 } |
506 RTC_NOTREACHED() << "Should not receive keyframe requests on unknown SSRCs."; | 486 RTC_NOTREACHED() << "Should not receive keyframe requests on unknown SSRCs."; |
507 } | 487 } |
508 | 488 |
509 void ViEEncoder::OnBitrateUpdated(uint32_t bitrate_bps, | 489 void ViEEncoder::OnBitrateUpdated(uint32_t bitrate_bps, |
510 uint8_t fraction_lost, | 490 uint8_t fraction_lost, |
511 int64_t round_trip_time_ms) { | 491 int64_t round_trip_time_ms) { |
512 LOG(LS_VERBOSE) << "OnBitrateUpdated, bitrate" << bitrate_bps | 492 LOG(LS_VERBOSE) << "OnBitrateUpdated, bitrate" << bitrate_bps |
513 << " packet loss " << static_cast<int>(fraction_lost) | 493 << " packet loss " << static_cast<int>(fraction_lost) |
514 << " rtt " << round_trip_time_ms; | 494 << " rtt " << round_trip_time_ms; |
515 RTC_DCHECK(send_payload_router_); | 495 RTC_DCHECK(send_payload_router_); |
516 vcm_->SetChannelParameters(bitrate_bps, fraction_lost, round_trip_time_ms); | 496 video_sender_.SetChannelParameters(bitrate_bps, fraction_lost, |
517 bool video_is_suspended = vcm_->VideoSuspended(); | 497 round_trip_time_ms); |
| 498 bool video_is_suspended = video_sender_.VideoSuspended(); |
518 bool video_suspension_changed; | 499 bool video_suspension_changed; |
519 VideoCodec send_codec; | 500 VideoCodec send_codec; |
520 { | 501 { |
521 rtc::CritScope lock(&data_cs_); | 502 rtc::CritScope lock(&data_cs_); |
522 last_observed_bitrate_bps_ = bitrate_bps; | 503 last_observed_bitrate_bps_ = bitrate_bps; |
523 video_suspension_changed = video_suspended_ != video_is_suspended; | 504 video_suspension_changed = video_suspended_ != video_is_suspended; |
524 video_suspended_ = video_is_suspended; | 505 video_suspended_ = video_is_suspended; |
525 send_codec = encoder_config_; | 506 send_codec = encoder_config_; |
526 } | 507 } |
527 | 508 |
(...skipping 24 matching lines...) Expand all Loading... |
552 const uint32_t width, | 533 const uint32_t width, |
553 const uint32_t height) { | 534 const uint32_t height) { |
554 return vp_->SetTargetResolution(width, height, frame_rate); | 535 return vp_->SetTargetResolution(width, height, frame_rate); |
555 } | 536 } |
556 | 537 |
557 void QMVideoSettingsCallback::SetTargetFramerate(int frame_rate) { | 538 void QMVideoSettingsCallback::SetTargetFramerate(int frame_rate) { |
558 vp_->SetTargetFramerate(frame_rate); | 539 vp_->SetTargetFramerate(frame_rate); |
559 } | 540 } |
560 | 541 |
561 } // namespace webrtc | 542 } // namespace webrtc |
OLD | NEW |