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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 virtual void OnNetworkChanged(uint32_t bitrate_bps, | 98 virtual void OnNetworkChanged(uint32_t bitrate_bps, |
99 uint8_t fraction_lost, | 99 uint8_t fraction_lost, |
100 int64_t rtt) { | 100 int64_t rtt) { |
101 owner_->OnNetworkChanged(bitrate_bps, fraction_lost, rtt); | 101 owner_->OnNetworkChanged(bitrate_bps, fraction_lost, rtt); |
102 } | 102 } |
103 private: | 103 private: |
104 ViEEncoder* owner_; | 104 ViEEncoder* owner_; |
105 }; | 105 }; |
106 | 106 |
107 ViEEncoder::ViEEncoder(uint32_t number_of_cores, | 107 ViEEncoder::ViEEncoder(uint32_t number_of_cores, |
108 const std::vector<uint32_t>& ssrcs, | |
108 ProcessThread* module_process_thread, | 109 ProcessThread* module_process_thread, |
109 SendStatisticsProxy* stats_proxy, | 110 SendStatisticsProxy* stats_proxy, |
110 I420FrameCallback* pre_encode_callback, | 111 I420FrameCallback* pre_encode_callback, |
111 OveruseFrameDetector* overuse_detector, | 112 OveruseFrameDetector* overuse_detector, |
112 PacedSender* pacer, | 113 PacedSender* pacer, |
113 PayloadRouter* payload_router, | 114 PayloadRouter* payload_router, |
114 BitrateAllocator* bitrate_allocator) | 115 BitrateAllocator* bitrate_allocator) |
115 : number_of_cores_(number_of_cores), | 116 : number_of_cores_(number_of_cores), |
117 ssrcs_(ssrcs), | |
116 vp_(VideoProcessing::Create()), | 118 vp_(VideoProcessing::Create()), |
117 qm_callback_(new QMVideoSettingsCallback(vp_.get())), | 119 qm_callback_(new QMVideoSettingsCallback(vp_.get())), |
118 vcm_(VideoCodingModule::Create(Clock::GetRealTimeClock(), | 120 vcm_(VideoCodingModule::Create(Clock::GetRealTimeClock(), |
119 this, | 121 this, |
120 qm_callback_.get())), | 122 qm_callback_.get())), |
121 stats_proxy_(stats_proxy), | 123 stats_proxy_(stats_proxy), |
122 pre_encode_callback_(pre_encode_callback), | 124 pre_encode_callback_(pre_encode_callback), |
123 overuse_detector_(overuse_detector), | 125 overuse_detector_(overuse_detector), |
124 pacer_(pacer), | 126 pacer_(pacer), |
125 send_payload_router_(payload_router), | 127 send_payload_router_(payload_router), |
126 bitrate_allocator_(bitrate_allocator), | 128 bitrate_allocator_(bitrate_allocator), |
127 time_of_last_frame_activity_ms_(0), | 129 time_of_last_frame_activity_ms_(0), |
128 encoder_config_(), | 130 encoder_config_(), |
129 min_transmit_bitrate_kbps_(0), | 131 min_transmit_bitrate_kbps_(0), |
130 last_observed_bitrate_bps_(0), | 132 last_observed_bitrate_bps_(0), |
131 target_delay_ms_(0), | 133 target_delay_ms_(0), |
132 network_is_transmitting_(true), | 134 network_is_transmitting_(true), |
133 encoder_paused_(false), | 135 encoder_paused_(false), |
134 encoder_paused_and_dropped_frame_(false), | 136 encoder_paused_and_dropped_frame_(false), |
137 time_last_intra_request_ms_(ssrcs.size(), -1), | |
135 module_process_thread_(module_process_thread), | 138 module_process_thread_(module_process_thread), |
136 has_received_sli_(false), | 139 has_received_sli_(false), |
137 picture_id_sli_(0), | 140 picture_id_sli_(0), |
138 has_received_rpsi_(false), | 141 has_received_rpsi_(false), |
139 picture_id_rpsi_(0), | 142 picture_id_rpsi_(0), |
140 video_suspended_(false) { | 143 video_suspended_(false) { |
141 bitrate_observer_.reset(new ViEBitrateObserver(this)); | 144 bitrate_observer_.reset(new ViEBitrateObserver(this)); |
142 module_process_thread_->RegisterModule(vcm_.get()); | 145 module_process_thread_->RegisterModule(vcm_.get()); |
143 } | 146 } |
144 | 147 |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
488 uint64_t picture_id) { | 491 uint64_t picture_id) { |
489 rtc::CritScope lock(&data_cs_); | 492 rtc::CritScope lock(&data_cs_); |
490 picture_id_rpsi_ = picture_id; | 493 picture_id_rpsi_ = picture_id; |
491 has_received_rpsi_ = true; | 494 has_received_rpsi_ = true; |
492 } | 495 } |
493 | 496 |
494 void ViEEncoder::OnReceivedIntraFrameRequest(uint32_t ssrc) { | 497 void ViEEncoder::OnReceivedIntraFrameRequest(uint32_t ssrc) { |
495 // Key frame request from remote side, signal to VCM. | 498 // Key frame request from remote side, signal to VCM. |
496 TRACE_EVENT0("webrtc", "OnKeyFrameRequest"); | 499 TRACE_EVENT0("webrtc", "OnKeyFrameRequest"); |
497 | 500 |
498 int idx = 0; | 501 for (size_t i = 0; i < ssrcs_.size(); ++i) { |
499 { | 502 if (ssrcs_[i] != ssrc) |
500 rtc::CritScope lock(&data_cs_); | 503 continue; |
501 auto stream_it = ssrc_streams_.find(ssrc); | 504 int64_t now_ms = TickTime::MillisecondTimestamp(); |
502 if (stream_it == ssrc_streams_.end()) { | 505 { |
503 LOG_F(LS_WARNING) << "ssrc not found: " << ssrc << ", map size " | 506 rtc::CritScope lock(&data_cs_); |
504 << ssrc_streams_.size(); | 507 if (time_last_intra_request_ms_[i] + kMinKeyFrameRequestIntervalMs > |
danilchap
2016/02/19 19:25:56
no check if time_last_intra_request_ms_[i] is vali
pbos-webrtc
2016/02/19 19:30:07
We're relying on now_ms >= 0 (pretty much everywhe
danilchap
2016/02/19 19:39:36
Just want to be sure being implicit here is intend
| |
505 return; | 508 now_ms) { |
509 return; | |
510 } | |
511 time_last_intra_request_ms_[i] = now_ms; | |
506 } | 512 } |
507 std::map<unsigned int, int64_t>::iterator time_it = | 513 vcm_->IntraFrameRequest(static_cast<int>(i)); |
508 time_last_intra_request_ms_.find(ssrc); | 514 return; |
509 if (time_it == time_last_intra_request_ms_.end()) { | |
510 time_last_intra_request_ms_[ssrc] = 0; | |
511 } | |
512 | |
513 int64_t now = TickTime::MillisecondTimestamp(); | |
514 if (time_last_intra_request_ms_[ssrc] + kMinKeyFrameRequestIntervalMs | |
515 > now) { | |
516 return; | |
517 } | |
518 time_last_intra_request_ms_[ssrc] = now; | |
519 idx = stream_it->second; | |
520 } | 515 } |
521 // Release the critsect before triggering key frame. | 516 RTC_NOTREACHED() << "Should not receive keyframe requests on unknown SSRCs."; |
522 vcm_->IntraFrameRequest(idx); | |
523 } | 517 } |
524 | 518 |
525 void ViEEncoder::OnLocalSsrcChanged(uint32_t old_ssrc, uint32_t new_ssrc) { | 519 void ViEEncoder::OnLocalSsrcChanged(uint32_t old_ssrc, uint32_t new_ssrc) { |
526 rtc::CritScope lock(&data_cs_); | 520 RTC_NOTREACHED(); |
527 std::map<unsigned int, int>::iterator it = ssrc_streams_.find(old_ssrc); | |
528 if (it == ssrc_streams_.end()) { | |
529 return; | |
530 } | |
531 | |
532 ssrc_streams_[new_ssrc] = it->second; | |
533 ssrc_streams_.erase(it); | |
534 | |
535 std::map<unsigned int, int64_t>::iterator time_it = | |
536 time_last_intra_request_ms_.find(old_ssrc); | |
537 int64_t last_intra_request_ms = 0; | |
538 if (time_it != time_last_intra_request_ms_.end()) { | |
539 last_intra_request_ms = time_it->second; | |
540 time_last_intra_request_ms_.erase(time_it); | |
541 } | |
542 time_last_intra_request_ms_[new_ssrc] = last_intra_request_ms; | |
543 } | |
544 | |
545 void ViEEncoder::SetSsrcs(const std::vector<uint32_t>& ssrcs) { | |
546 rtc::CritScope lock(&data_cs_); | |
547 ssrc_streams_.clear(); | |
548 time_last_intra_request_ms_.clear(); | |
549 int idx = 0; | |
550 for (uint32_t ssrc : ssrcs) { | |
551 ssrc_streams_[ssrc] = idx++; | |
552 } | |
553 } | 521 } |
554 | 522 |
555 void ViEEncoder::SetMinTransmitBitrate(int min_transmit_bitrate_kbps) { | 523 void ViEEncoder::SetMinTransmitBitrate(int min_transmit_bitrate_kbps) { |
556 assert(min_transmit_bitrate_kbps >= 0); | 524 assert(min_transmit_bitrate_kbps >= 0); |
557 rtc::CritScope lock(&data_cs_); | 525 rtc::CritScope lock(&data_cs_); |
558 min_transmit_bitrate_kbps_ = min_transmit_bitrate_kbps; | 526 min_transmit_bitrate_kbps_ = min_transmit_bitrate_kbps; |
559 } | 527 } |
560 | 528 |
561 // Called from ViEBitrateObserver. | 529 // Called from ViEBitrateObserver. |
562 void ViEEncoder::OnNetworkChanged(uint32_t bitrate_bps, | 530 void ViEEncoder::OnNetworkChanged(uint32_t bitrate_bps, |
563 uint8_t fraction_lost, | 531 uint8_t fraction_lost, |
564 int64_t round_trip_time_ms) { | 532 int64_t round_trip_time_ms) { |
565 LOG(LS_VERBOSE) << "OnNetworkChanged, bitrate" << bitrate_bps | 533 LOG(LS_VERBOSE) << "OnNetworkChanged, bitrate" << bitrate_bps |
566 << " packet loss " << static_cast<int>(fraction_lost) | 534 << " packet loss " << static_cast<int>(fraction_lost) |
567 << " rtt " << round_trip_time_ms; | 535 << " rtt " << round_trip_time_ms; |
568 RTC_DCHECK(send_payload_router_ != NULL); | 536 RTC_DCHECK(send_payload_router_ != NULL); |
569 vcm_->SetChannelParameters(bitrate_bps, fraction_lost, round_trip_time_ms); | 537 vcm_->SetChannelParameters(bitrate_bps, fraction_lost, round_trip_time_ms); |
570 bool video_is_suspended = vcm_->VideoSuspended(); | 538 bool video_is_suspended = vcm_->VideoSuspended(); |
571 bool video_suspension_changed; | 539 bool video_suspension_changed; |
572 VideoCodec send_codec; | 540 VideoCodec send_codec; |
573 uint32_t first_ssrc; | |
574 { | 541 { |
575 rtc::CritScope lock(&data_cs_); | 542 rtc::CritScope lock(&data_cs_); |
576 last_observed_bitrate_bps_ = bitrate_bps; | 543 last_observed_bitrate_bps_ = bitrate_bps; |
577 video_suspension_changed = video_suspended_ != video_is_suspended; | 544 video_suspension_changed = video_suspended_ != video_is_suspended; |
578 video_suspended_ = video_is_suspended; | 545 video_suspended_ = video_is_suspended; |
579 send_codec = encoder_config_; | 546 send_codec = encoder_config_; |
580 first_ssrc = ssrc_streams_.begin()->first; | |
581 } | 547 } |
582 | 548 |
583 SimulcastStream* stream_configs = send_codec.simulcastStream; | 549 SimulcastStream* stream_configs = send_codec.simulcastStream; |
584 // Allocate the bandwidth between the streams. | 550 // Allocate the bandwidth between the streams. |
585 std::vector<uint32_t> stream_bitrates = AllocateStreamBitrates( | 551 std::vector<uint32_t> stream_bitrates = AllocateStreamBitrates( |
586 bitrate_bps, stream_configs, send_codec.numberOfSimulcastStreams); | 552 bitrate_bps, stream_configs, send_codec.numberOfSimulcastStreams); |
587 send_payload_router_->SetTargetSendBitrates(stream_bitrates); | 553 send_payload_router_->SetTargetSendBitrates(stream_bitrates); |
588 | 554 |
589 if (!video_suspension_changed) | 555 if (!video_suspension_changed) |
590 return; | 556 return; |
591 // Video suspend-state changed, inform codec observer. | 557 // Video suspend-state changed, inform codec observer. |
592 LOG(LS_INFO) << "Video suspend state changed " << video_is_suspended | 558 LOG(LS_INFO) << "Video suspend state changed " << video_is_suspended |
593 << " for ssrc " << first_ssrc; | 559 << " for ssrc " << ssrcs_[0]; |
594 if (stats_proxy_) | 560 if (stats_proxy_) |
595 stats_proxy_->OnSuspendChange(video_is_suspended); | 561 stats_proxy_->OnSuspendChange(video_is_suspended); |
596 } | 562 } |
597 | 563 |
598 void ViEEncoder::SuspendBelowMinBitrate() { | 564 void ViEEncoder::SuspendBelowMinBitrate() { |
599 vcm_->SuspendBelowMinBitrate(); | 565 vcm_->SuspendBelowMinBitrate(); |
600 bitrate_allocator_->EnforceMinBitrate(false); | 566 bitrate_allocator_->EnforceMinBitrate(false); |
601 } | 567 } |
602 | 568 |
603 void ViEEncoder::RegisterPostEncodeImageCallback( | 569 void ViEEncoder::RegisterPostEncodeImageCallback( |
(...skipping 13 matching lines...) Expand all Loading... | |
617 const uint32_t width, | 583 const uint32_t width, |
618 const uint32_t height) { | 584 const uint32_t height) { |
619 return vp_->SetTargetResolution(width, height, frame_rate); | 585 return vp_->SetTargetResolution(width, height, frame_rate); |
620 } | 586 } |
621 | 587 |
622 void QMVideoSettingsCallback::SetTargetFramerate(int frame_rate) { | 588 void QMVideoSettingsCallback::SetTargetFramerate(int frame_rate) { |
623 vp_->SetTargetFramerate(frame_rate); | 589 vp_->SetTargetFramerate(frame_rate); |
624 } | 590 } |
625 | 591 |
626 } // namespace webrtc | 592 } // namespace webrtc |
OLD | NEW |