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 24 matching lines...) Expand all Loading... | |
35 EncodedImageCallback* sink) | 35 EncodedImageCallback* sink) |
36 : number_of_cores_(number_of_cores), | 36 : number_of_cores_(number_of_cores), |
37 sink_(sink), | 37 sink_(sink), |
38 vp_(VideoProcessing::Create()), | 38 vp_(VideoProcessing::Create()), |
39 video_sender_(Clock::GetRealTimeClock(), this, this, this), | 39 video_sender_(Clock::GetRealTimeClock(), this, this, this), |
40 stats_proxy_(stats_proxy), | 40 stats_proxy_(stats_proxy), |
41 overuse_detector_(overuse_detector), | 41 overuse_detector_(overuse_detector), |
42 time_of_last_frame_activity_ms_(0), | 42 time_of_last_frame_activity_ms_(0), |
43 encoder_config_(), | 43 encoder_config_(), |
44 last_observed_bitrate_bps_(0), | 44 last_observed_bitrate_bps_(0), |
45 encoder_paused_(true), | |
46 encoder_paused_and_dropped_frame_(false), | 45 encoder_paused_and_dropped_frame_(false), |
47 module_process_thread_(module_process_thread), | 46 module_process_thread_(module_process_thread), |
48 has_received_sli_(false), | 47 has_received_sli_(false), |
49 picture_id_sli_(0), | 48 picture_id_sli_(0), |
50 has_received_rpsi_(false), | 49 has_received_rpsi_(false), |
51 picture_id_rpsi_(0), | 50 picture_id_rpsi_(0), |
52 video_suspended_(false) { | 51 video_suspended_(false) { |
53 module_process_thread_->RegisterModule(&video_sender_); | 52 module_process_thread_->RegisterModule(&video_sender_); |
54 vp_->EnableTemporalDecimation(true); | 53 vp_->EnableTemporalDecimation(true); |
55 } | 54 } |
56 | 55 |
57 vcm::VideoSender* ViEEncoder::video_sender() { | 56 vcm::VideoSender* ViEEncoder::video_sender() { |
58 return &video_sender_; | 57 return &video_sender_; |
59 } | 58 } |
60 | 59 |
61 ViEEncoder::~ViEEncoder() { | 60 ViEEncoder::~ViEEncoder() { |
62 module_process_thread_->DeRegisterModule(&video_sender_); | 61 module_process_thread_->DeRegisterModule(&video_sender_); |
63 } | 62 } |
64 | 63 |
65 void ViEEncoder::Pause() { | |
66 rtc::CritScope lock(&data_cs_); | |
67 encoder_paused_ = true; | |
68 } | |
69 | |
70 void ViEEncoder::Start() { | |
71 rtc::CritScope lock(&data_cs_); | |
72 encoder_paused_ = false; | |
73 } | |
74 | |
75 int32_t ViEEncoder::RegisterExternalEncoder(webrtc::VideoEncoder* encoder, | 64 int32_t ViEEncoder::RegisterExternalEncoder(webrtc::VideoEncoder* encoder, |
76 uint8_t pl_type, | 65 uint8_t pl_type, |
77 bool internal_source) { | 66 bool internal_source) { |
78 video_sender_.RegisterExternalEncoder(encoder, pl_type, internal_source); | 67 video_sender_.RegisterExternalEncoder(encoder, pl_type, internal_source); |
79 return 0; | 68 return 0; |
80 } | 69 } |
81 | 70 |
82 int32_t ViEEncoder::DeRegisterExternalEncoder(uint8_t pl_type) { | 71 int32_t ViEEncoder::DeRegisterExternalEncoder(uint8_t pl_type) { |
83 video_sender_.RegisterExternalEncoder(nullptr, pl_type, false); | 72 video_sender_.RegisterExternalEncoder(nullptr, pl_type, false); |
84 return 0; | 73 return 0; |
85 } | 74 } |
86 | 75 |
87 void ViEEncoder::SetEncoder(const webrtc::VideoCodec& video_codec, | 76 void ViEEncoder::SetEncoder(const webrtc::VideoCodec& video_codec, |
88 size_t max_data_payload_length) { | 77 size_t max_data_payload_length) { |
78 LOG(LS_INFO) << "SetEncoder" << video_codec.startBitrate; | |
89 // Setting target width and height for VPM. | 79 // Setting target width and height for VPM. |
90 RTC_CHECK_EQ(VPM_OK, | 80 RTC_CHECK_EQ(VPM_OK, |
91 vp_->SetTargetResolution(video_codec.width, video_codec.height, | 81 vp_->SetTargetResolution(video_codec.width, video_codec.height, |
92 video_codec.maxFramerate)); | 82 video_codec.maxFramerate)); |
93 | 83 uint32_t last_observed_bitrate_bps = 0; |
94 // Cache codec before calling AddBitrateObserver (which calls OnBitrateUpdated | |
95 // that makes use of the number of simulcast streams configured). | |
96 { | 84 { |
97 rtc::CritScope lock(&data_cs_); | 85 rtc::CritScope lock(&data_cs_); |
98 encoder_config_ = video_codec; | 86 encoder_config_ = video_codec; |
87 last_observed_bitrate_bps = last_observed_bitrate_bps_; | |
99 } | 88 } |
100 | 89 |
101 bool success = video_sender_.RegisterSendCodec( | 90 bool success = video_sender_.RegisterSendCodec( |
102 &video_codec, number_of_cores_, | 91 &video_codec, number_of_cores_, |
103 static_cast<uint32_t>(max_data_payload_length)) == VCM_OK; | 92 static_cast<uint32_t>(max_data_payload_length)) == VCM_OK; |
93 | |
94 // Set the currently known channel parameters to ensure that if the encoder | |
95 // should currently be paused, it stays paused. | |
96 video_sender_.SetChannelParameters(last_observed_bitrate_bps, 0, 0); | |
pbos-webrtc
2016/06/16 13:16:28
Can we skip 0, 0? Maybe by storing the last observ
| |
97 | |
104 if (!success) { | 98 if (!success) { |
105 LOG(LS_ERROR) << "Failed to configure encoder."; | 99 LOG(LS_ERROR) << "Failed to configure encoder."; |
106 RTC_DCHECK(success); | 100 RTC_DCHECK(success); |
107 } | 101 } |
108 | 102 |
109 if (stats_proxy_) { | 103 if (stats_proxy_) { |
110 VideoEncoderConfig::ContentType content_type = | 104 VideoEncoderConfig::ContentType content_type = |
111 VideoEncoderConfig::ContentType::kRealtimeVideo; | 105 VideoEncoderConfig::ContentType::kRealtimeVideo; |
112 switch (video_codec.mode) { | 106 switch (video_codec.mode) { |
113 case kRealtimeVideo: | 107 case kRealtimeVideo: |
114 content_type = VideoEncoderConfig::ContentType::kRealtimeVideo; | 108 content_type = VideoEncoderConfig::ContentType::kRealtimeVideo; |
115 break; | 109 break; |
116 case kScreensharing: | 110 case kScreensharing: |
117 content_type = VideoEncoderConfig::ContentType::kScreen; | 111 content_type = VideoEncoderConfig::ContentType::kScreen; |
118 break; | 112 break; |
119 default: | 113 default: |
120 RTC_NOTREACHED(); | 114 RTC_NOTREACHED(); |
121 break; | 115 break; |
122 } | 116 } |
123 stats_proxy_->SetContentType(content_type); | 117 stats_proxy_->SetContentType(content_type); |
124 } | 118 } |
125 } | 119 } |
126 | 120 |
127 bool ViEEncoder::EncoderPaused() const { | 121 bool ViEEncoder::EncoderPaused() const { |
128 // Pause video if paused by caller or as long as the network is down or the | 122 // Pause video if paused by caller or as long as the network is down or the |
129 // pacer queue has grown too large in buffered mode. | 123 // pacer queue has grown too large in buffered mode. |
130 // If the pacer queue has grown to large or the network is down, | 124 // If the pacer queue has grown too large or the network is down, |
131 // last_observed_bitrate_bps_ will be 0. | 125 // last_observed_bitrate_bps_ will be 0. |
132 return encoder_paused_ || video_suspended_ || last_observed_bitrate_bps_ == 0; | 126 return video_suspended_ || last_observed_bitrate_bps_ == 0; |
133 } | 127 } |
134 | 128 |
135 void ViEEncoder::TraceFrameDropStart() { | 129 void ViEEncoder::TraceFrameDropStart() { |
136 // Start trace event only on the first frame after encoder is paused. | 130 // Start trace event only on the first frame after encoder is paused. |
137 if (!encoder_paused_and_dropped_frame_) { | 131 if (!encoder_paused_and_dropped_frame_) { |
138 TRACE_EVENT_ASYNC_BEGIN0("webrtc", "EncoderPaused", this); | 132 TRACE_EVENT_ASYNC_BEGIN0("webrtc", "EncoderPaused", this); |
139 } | 133 } |
140 encoder_paused_and_dropped_frame_ = true; | 134 encoder_paused_and_dropped_frame_ = true; |
141 return; | 135 return; |
142 } | 136 } |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 video_suspended_ = video_is_suspended; | 266 video_suspended_ = video_is_suspended; |
273 } | 267 } |
274 | 268 |
275 if (stats_proxy_ && video_suspension_changed) { | 269 if (stats_proxy_ && video_suspension_changed) { |
276 LOG(LS_INFO) << "Video suspend state changed " << video_is_suspended; | 270 LOG(LS_INFO) << "Video suspend state changed " << video_is_suspended; |
277 stats_proxy_->OnSuspendChange(video_is_suspended); | 271 stats_proxy_->OnSuspendChange(video_is_suspended); |
278 } | 272 } |
279 } | 273 } |
280 | 274 |
281 } // namespace webrtc | 275 } // namespace webrtc |
OLD | NEW |