| 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 |
| 11 #include "webrtc/video_engine/vie_encoder.h" | 11 #include "webrtc/video_engine/vie_encoder.h" |
| 12 | 12 |
| 13 #include <assert.h> | 13 #include <assert.h> |
| 14 | 14 |
| 15 #include <algorithm> | 15 #include <algorithm> |
| 16 | 16 |
| 17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
| 18 #include "webrtc/common_video/interface/video_image.h" | 18 #include "webrtc/common_video/interface/video_image.h" |
| 19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
| 20 #include "webrtc/frame_callback.h" | 20 #include "webrtc/frame_callback.h" |
| 21 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
| 21 #include "webrtc/modules/pacing/include/paced_sender.h" | 22 #include "webrtc/modules/pacing/include/paced_sender.h" |
| 22 #include "webrtc/modules/utility/interface/process_thread.h" | 23 #include "webrtc/modules/utility/interface/process_thread.h" |
| 23 #include "webrtc/modules/video_coding/codecs/interface/video_codec_interface.h" | 24 #include "webrtc/modules/video_coding/codecs/interface/video_codec_interface.h" |
| 24 #include "webrtc/modules/video_coding/main/interface/video_coding.h" | 25 #include "webrtc/modules/video_coding/main/interface/video_coding.h" |
| 25 #include "webrtc/modules/video_coding/main/interface/video_coding_defines.h" | 26 #include "webrtc/modules/video_coding/main/interface/video_coding_defines.h" |
| 26 #include "webrtc/modules/video_coding/main/source/encoded_frame.h" | 27 #include "webrtc/modules/video_coding/main/source/encoded_frame.h" |
| 27 #include "webrtc/system_wrappers/interface/clock.h" | 28 #include "webrtc/system_wrappers/interface/clock.h" |
| 28 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" | 29 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
| 29 #include "webrtc/system_wrappers/interface/logging.h" | 30 #include "webrtc/system_wrappers/interface/logging.h" |
| 30 #include "webrtc/system_wrappers/interface/metrics.h" | 31 #include "webrtc/system_wrappers/interface/metrics.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 owner_->OnNetworkChanged(bitrate_bps, fraction_lost, rtt); | 99 owner_->OnNetworkChanged(bitrate_bps, fraction_lost, rtt); |
| 99 } | 100 } |
| 100 private: | 101 private: |
| 101 ViEEncoder* owner_; | 102 ViEEncoder* owner_; |
| 102 }; | 103 }; |
| 103 | 104 |
| 104 ViEEncoder::ViEEncoder(int32_t channel_id, | 105 ViEEncoder::ViEEncoder(int32_t channel_id, |
| 105 uint32_t number_of_cores, | 106 uint32_t number_of_cores, |
| 106 ProcessThread& module_process_thread, | 107 ProcessThread& module_process_thread, |
| 107 PacedSender* pacer, | 108 PacedSender* pacer, |
| 108 BitrateAllocator* bitrate_allocator, | 109 BitrateAllocator* bitrate_allocator) |
| 109 BitrateController* bitrate_controller) | |
| 110 : channel_id_(channel_id), | 110 : channel_id_(channel_id), |
| 111 number_of_cores_(number_of_cores), | 111 number_of_cores_(number_of_cores), |
| 112 vpm_(VideoProcessingModule::Create(ViEModuleId(-1, channel_id))), | 112 vpm_(VideoProcessingModule::Create(ViEModuleId(-1, channel_id))), |
| 113 qm_callback_(new QMVideoSettingsCallback(vpm_.get())), | 113 qm_callback_(new QMVideoSettingsCallback(vpm_.get())), |
| 114 vcm_(VideoCodingModule::Create(Clock::GetRealTimeClock(), | 114 vcm_(VideoCodingModule::Create(Clock::GetRealTimeClock(), |
| 115 this, | 115 this, |
| 116 qm_callback_.get())), | 116 qm_callback_.get())), |
| 117 send_payload_router_(NULL), | 117 send_payload_router_(NULL), |
| 118 callback_cs_(CriticalSectionWrapper::CreateCriticalSection()), | 118 callback_cs_(CriticalSectionWrapper::CreateCriticalSection()), |
| 119 data_cs_(CriticalSectionWrapper::CreateCriticalSection()), | 119 data_cs_(CriticalSectionWrapper::CreateCriticalSection()), |
| 120 pacer_(pacer), | 120 pacer_(pacer), |
| 121 bitrate_allocator_(bitrate_allocator), | 121 bitrate_allocator_(bitrate_allocator), |
| 122 bitrate_controller_(bitrate_controller), | |
| 123 time_of_last_frame_activity_ms_(0), | 122 time_of_last_frame_activity_ms_(0), |
| 124 simulcast_enabled_(false), | 123 simulcast_enabled_(false), |
| 125 min_transmit_bitrate_kbps_(0), | 124 min_transmit_bitrate_kbps_(0), |
| 126 last_observed_bitrate_bps_(0), | 125 last_observed_bitrate_bps_(0), |
| 127 target_delay_ms_(0), | 126 target_delay_ms_(0), |
| 128 network_is_transmitting_(true), | 127 network_is_transmitting_(true), |
| 129 encoder_paused_(false), | 128 encoder_paused_(false), |
| 130 encoder_paused_and_dropped_frame_(false), | 129 encoder_paused_and_dropped_frame_(false), |
| 131 fec_enabled_(false), | 130 fec_enabled_(false), |
| 132 nack_enabled_(false), | 131 nack_enabled_(false), |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 return -1; | 261 return -1; |
| 263 } | 262 } |
| 264 | 263 |
| 265 { | 264 { |
| 266 CriticalSectionScoped cs(data_cs_.get()); | 265 CriticalSectionScoped cs(data_cs_.get()); |
| 267 simulcast_enabled_ = video_codec.numberOfSimulcastStreams > 1; | 266 simulcast_enabled_ = video_codec.numberOfSimulcastStreams > 1; |
| 268 } | 267 } |
| 269 | 268 |
| 270 // Add a bitrate observer to the allocator and update the start, max and | 269 // Add a bitrate observer to the allocator and update the start, max and |
| 271 // min bitrates of the bitrate controller as needed. | 270 // min bitrates of the bitrate controller as needed. |
| 272 int allocated_bitrate_bps; | 271 int allocated_bitrate_bps = bitrate_allocator_->AddBitrateObserver( |
| 273 int new_bwe_candidate_bps = bitrate_allocator_->AddBitrateObserver( | 272 bitrate_observer_.get(), video_codec.minBitrate * 1000, |
| 274 bitrate_observer_.get(), video_codec.startBitrate * 1000, | 273 video_codec.maxBitrate * 1000); |
| 275 video_codec.minBitrate * 1000, video_codec.maxBitrate * 1000, | |
| 276 &allocated_bitrate_bps); | |
| 277 | |
| 278 // Only set the start/min/max bitrate of the bitrate controller if the start | |
| 279 // bitrate is greater than zero. The new API sets these via the channel group | |
| 280 // and passes a zero start bitrate to SetSendCodec. | |
| 281 // TODO(holmer): Remove this when the new API has been launched. | |
| 282 if (video_codec.startBitrate > 0) { | |
| 283 if (new_bwe_candidate_bps > 0) { | |
| 284 uint32_t current_bwe_bps = 0; | |
| 285 bitrate_controller_->AvailableBandwidth(¤t_bwe_bps); | |
| 286 bitrate_controller_->SetStartBitrate(std::max( | |
| 287 static_cast<uint32_t>(new_bwe_candidate_bps), current_bwe_bps)); | |
| 288 } | |
| 289 | |
| 290 int new_bwe_min_bps = 0; | |
| 291 int new_bwe_max_bps = 0; | |
| 292 bitrate_allocator_->GetMinMaxBitrateSumBps(&new_bwe_min_bps, | |
| 293 &new_bwe_max_bps); | |
| 294 bitrate_controller_->SetMinMaxBitrate(new_bwe_min_bps, new_bwe_max_bps); | |
| 295 } | |
| 296 | 274 |
| 297 webrtc::VideoCodec modified_video_codec = video_codec; | 275 webrtc::VideoCodec modified_video_codec = video_codec; |
| 298 modified_video_codec.startBitrate = allocated_bitrate_bps / 1000; | 276 modified_video_codec.startBitrate = allocated_bitrate_bps / 1000; |
| 299 | 277 |
| 300 size_t max_data_payload_length = send_payload_router_->MaxPayloadLength(); | 278 size_t max_data_payload_length = send_payload_router_->MaxPayloadLength(); |
| 301 if (vcm_->RegisterSendCodec(&modified_video_codec, number_of_cores_, | 279 if (vcm_->RegisterSendCodec(&modified_video_codec, number_of_cores_, |
| 302 static_cast<uint32_t>(max_data_payload_length)) != | 280 static_cast<uint32_t>(max_data_payload_length)) != |
| 303 VCM_OK) { | 281 VCM_OK) { |
| 304 return -1; | 282 return -1; |
| 305 } | 283 } |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 const uint32_t width, | 787 const uint32_t width, |
| 810 const uint32_t height) { | 788 const uint32_t height) { |
| 811 return vpm_->SetTargetResolution(width, height, frame_rate); | 789 return vpm_->SetTargetResolution(width, height, frame_rate); |
| 812 } | 790 } |
| 813 | 791 |
| 814 void QMVideoSettingsCallback::SetTargetFramerate(int frame_rate) { | 792 void QMVideoSettingsCallback::SetTargetFramerate(int frame_rate) { |
| 815 vpm_->SetTargetFramerate(frame_rate); | 793 vpm_->SetTargetFramerate(frame_rate); |
| 816 } | 794 } |
| 817 | 795 |
| 818 } // namespace webrtc | 796 } // namespace webrtc |
| OLD | NEW |