niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
stefan@webrtc.org | 07b45a5 | 2012-02-02 08:37:48 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
pbos@webrtc.org | f5d4cb1 | 2013-05-17 13:44:48 +0000 | [diff] [blame] | 11 | #include "webrtc/video_engine/vie_encoder.h" |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 12 | |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 13 | #include <assert.h> |
| 14 | |
stefan@webrtc.org | c3cc375 | 2013-06-04 09:36:56 +0000 | [diff] [blame] | 15 | #include <algorithm> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 16 | |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 17 | #include "webrtc/base/checks.h" |
sprang@webrtc.org | 4070935 | 2013-11-26 11:41:59 +0000 | [diff] [blame] | 18 | #include "webrtc/common_video/interface/video_image.h" |
pbos@webrtc.org | f5d4cb1 | 2013-05-17 13:44:48 +0000 | [diff] [blame] | 19 | #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 20 | #include "webrtc/frame_callback.h" |
pbos@webrtc.org | f5d4cb1 | 2013-05-17 13:44:48 +0000 | [diff] [blame] | 21 | #include "webrtc/modules/pacing/include/paced_sender.h" |
| 22 | #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h" |
| 23 | #include "webrtc/modules/utility/interface/process_thread.h" |
| 24 | #include "webrtc/modules/video_coding/codecs/interface/video_codec_interface.h" |
| 25 | #include "webrtc/modules/video_coding/main/interface/video_coding.h" |
| 26 | #include "webrtc/modules/video_coding/main/interface/video_coding_defines.h" |
sprang@webrtc.org | 4070935 | 2013-11-26 11:41:59 +0000 | [diff] [blame] | 27 | #include "webrtc/modules/video_coding/main/source/encoded_frame.h" |
stefan@webrtc.org | 88e0dda | 2014-07-04 09:20:42 +0000 | [diff] [blame] | 28 | #include "webrtc/system_wrappers/interface/clock.h" |
pbos@webrtc.org | f5d4cb1 | 2013-05-17 13:44:48 +0000 | [diff] [blame] | 29 | #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
| 30 | #include "webrtc/system_wrappers/interface/logging.h" |
asapersson@webrtc.org | 96dc685 | 2014-11-03 14:40:38 +0000 | [diff] [blame] | 31 | #include "webrtc/system_wrappers/interface/metrics.h" |
pbos@webrtc.org | f5d4cb1 | 2013-05-17 13:44:48 +0000 | [diff] [blame] | 32 | #include "webrtc/system_wrappers/interface/tick_util.h" |
pbos@webrtc.org | f5d4cb1 | 2013-05-17 13:44:48 +0000 | [diff] [blame] | 33 | #include "webrtc/system_wrappers/interface/trace_event.h" |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 34 | #include "webrtc/video/send_statistics_proxy.h" |
pbos@webrtc.org | f5d4cb1 | 2013-05-17 13:44:48 +0000 | [diff] [blame] | 35 | #include "webrtc/video_engine/include/vie_codec.h" |
| 36 | #include "webrtc/video_engine/include/vie_image_process.h" |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 37 | #include "webrtc/video_engine/payload_router.h" |
pbos@webrtc.org | f5d4cb1 | 2013-05-17 13:44:48 +0000 | [diff] [blame] | 38 | #include "webrtc/video_engine/vie_defines.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | namespace webrtc { |
| 41 | |
pwestin@webrtc.org | 52b4e88 | 2013-05-02 19:02:17 +0000 | [diff] [blame] | 42 | // Margin on when we pause the encoder when the pacing buffer overflows relative |
| 43 | // to the configured buffer delay. |
| 44 | static const float kEncoderPausePacerMargin = 2.0f; |
| 45 | |
pwestin@webrtc.org | 91563e4 | 2013-04-25 22:20:08 +0000 | [diff] [blame] | 46 | // Don't stop the encoder unless the delay is above this configured value. |
| 47 | static const int kMinPacingDelayMs = 200; |
| 48 | |
stefan@webrtc.org | bfacda6 | 2013-03-27 16:36:01 +0000 | [diff] [blame] | 49 | // Allow packets to be transmitted in up to 2 times max video bitrate if the |
| 50 | // bandwidth estimate allows it. |
| 51 | // TODO(holmer): Expose transmission start, min and max bitrates in the |
| 52 | // VideoEngine API and remove the kTransmissionMaxBitrateMultiplier. |
| 53 | static const int kTransmissionMaxBitrateMultiplier = 2; |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 54 | |
stefan@webrtc.org | 3e00505 | 2013-10-18 15:05:29 +0000 | [diff] [blame] | 55 | static const float kStopPaddingThresholdMs = 2000; |
| 56 | |
stefan@webrtc.org | b2c8a95 | 2013-09-06 13:58:01 +0000 | [diff] [blame] | 57 | std::vector<uint32_t> AllocateStreamBitrates( |
| 58 | uint32_t total_bitrate, |
| 59 | const SimulcastStream* stream_configs, |
| 60 | size_t number_of_streams) { |
| 61 | if (number_of_streams == 0) { |
| 62 | std::vector<uint32_t> stream_bitrates(1, 0); |
| 63 | stream_bitrates[0] = total_bitrate; |
| 64 | return stream_bitrates; |
| 65 | } |
| 66 | std::vector<uint32_t> stream_bitrates(number_of_streams, 0); |
| 67 | uint32_t bitrate_remainder = total_bitrate; |
| 68 | for (size_t i = 0; i < stream_bitrates.size() && bitrate_remainder > 0; ++i) { |
| 69 | if (stream_configs[i].maxBitrate * 1000 > bitrate_remainder) { |
| 70 | stream_bitrates[i] = bitrate_remainder; |
| 71 | } else { |
| 72 | stream_bitrates[i] = stream_configs[i].maxBitrate * 1000; |
| 73 | } |
| 74 | bitrate_remainder -= stream_bitrates[i]; |
| 75 | } |
| 76 | return stream_bitrates; |
| 77 | } |
| 78 | |
stefan@webrtc.org | 439be29 | 2012-02-16 14:45:37 +0000 | [diff] [blame] | 79 | class QMVideoSettingsCallback : public VCMQMSettingsCallback { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 80 | public: |
marpan@webrtc.org | efd01fd | 2012-04-18 15:56:34 +0000 | [diff] [blame] | 81 | explicit QMVideoSettingsCallback(VideoProcessingModule* vpm); |
mflodman@webrtc.org | 6879c8a | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 82 | |
stefan@webrtc.org | 439be29 | 2012-02-16 14:45:37 +0000 | [diff] [blame] | 83 | ~QMVideoSettingsCallback(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 84 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 85 | // Update VPM with QM (quality modes: frame size & frame rate) settings. |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 86 | int32_t SetVideoQMSettings(const uint32_t frame_rate, |
| 87 | const uint32_t width, |
| 88 | const uint32_t height); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 90 | private: |
| 91 | VideoProcessingModule* vpm_; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 92 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 93 | |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 94 | class ViEBitrateObserver : public BitrateObserver { |
| 95 | public: |
mflodman@webrtc.org | f5e99db | 2012-06-27 09:49:37 +0000 | [diff] [blame] | 96 | explicit ViEBitrateObserver(ViEEncoder* owner) |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 97 | : owner_(owner) { |
| 98 | } |
mflodman@webrtc.org | 6879c8a | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 99 | virtual ~ViEBitrateObserver() {} |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 100 | // Implements BitrateObserver. |
stefan@webrtc.org | edeea91 | 2014-12-08 19:46:23 +0000 | [diff] [blame] | 101 | virtual void OnNetworkChanged(uint32_t bitrate_bps, |
| 102 | uint8_t fraction_lost, |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 103 | int64_t rtt) { |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 104 | owner_->OnNetworkChanged(bitrate_bps, fraction_lost, rtt); |
| 105 | } |
| 106 | private: |
| 107 | ViEEncoder* owner_; |
| 108 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 109 | |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 110 | class ViEPacedSenderCallback : public PacedSender::Callback { |
| 111 | public: |
| 112 | explicit ViEPacedSenderCallback(ViEEncoder* owner) |
| 113 | : owner_(owner) { |
| 114 | } |
mflodman@webrtc.org | 6879c8a | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 115 | virtual ~ViEPacedSenderCallback() {} |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 116 | virtual bool TimeToSendPacket(uint32_t ssrc, |
| 117 | uint16_t sequence_number, |
| 118 | int64_t capture_time_ms, |
| 119 | bool retransmission) { |
stefan@webrtc.org | 9b82f5a | 2013-11-13 15:29:21 +0000 | [diff] [blame] | 120 | return owner_->TimeToSendPacket(ssrc, sequence_number, capture_time_ms, |
| 121 | retransmission); |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 122 | } |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 123 | virtual size_t TimeToSendPadding(size_t bytes) { |
stefan@webrtc.org | 508a84b | 2013-06-17 12:53:37 +0000 | [diff] [blame] | 124 | return owner_->TimeToSendPadding(bytes); |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 125 | } |
| 126 | private: |
| 127 | ViEEncoder* owner_; |
| 128 | }; |
| 129 | |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 130 | ViEEncoder::ViEEncoder(int32_t engine_id, |
| 131 | int32_t channel_id, |
| 132 | uint32_t number_of_cores, |
andresp@webrtc.org | 7707d06 | 2013-05-13 10:50:50 +0000 | [diff] [blame] | 133 | const Config& config, |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 134 | ProcessThread& module_process_thread, |
| 135 | BitrateController* bitrate_controller) |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 136 | : engine_id_(engine_id), |
| 137 | channel_id_(channel_id), |
| 138 | number_of_cores_(number_of_cores), |
stefan@webrtc.org | 34c5da6 | 2014-04-11 14:08:35 +0000 | [diff] [blame] | 139 | vcm_(*webrtc::VideoCodingModule::Create()), |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 140 | vpm_(*webrtc::VideoProcessingModule::Create(ViEModuleId(engine_id, |
| 141 | channel_id))), |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 142 | send_payload_router_(NULL), |
mflodman@webrtc.org | d32c447 | 2011-12-22 14:17:53 +0000 | [diff] [blame] | 143 | callback_cs_(CriticalSectionWrapper::CreateCriticalSection()), |
| 144 | data_cs_(CriticalSectionWrapper::CreateCriticalSection()), |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 145 | bitrate_controller_(bitrate_controller), |
stefan@webrtc.org | 3e00505 | 2013-10-18 15:05:29 +0000 | [diff] [blame] | 146 | time_of_last_incoming_frame_ms_(0), |
stefan@webrtc.org | 508a84b | 2013-06-17 12:53:37 +0000 | [diff] [blame] | 147 | send_padding_(false), |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 +0000 | [diff] [blame] | 148 | min_transmit_bitrate_kbps_(0), |
stefan@webrtc.org | bfacda6 | 2013-03-27 16:36:01 +0000 | [diff] [blame] | 149 | target_delay_ms_(0), |
| 150 | network_is_transmitting_(true), |
| 151 | encoder_paused_(false), |
pwestin@webrtc.org | 52b4e88 | 2013-05-02 19:02:17 +0000 | [diff] [blame] | 152 | encoder_paused_and_dropped_frame_(false), |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 153 | fec_enabled_(false), |
| 154 | nack_enabled_(false), |
| 155 | codec_observer_(NULL), |
| 156 | effect_filter_(NULL), |
| 157 | module_process_thread_(module_process_thread), |
| 158 | has_received_sli_(false), |
| 159 | picture_id_sli_(0), |
| 160 | has_received_rpsi_(false), |
| 161 | picture_id_rpsi_(0), |
henrik.lundin@webrtc.org | 7ea4f24 | 2013-10-02 13:34:26 +0000 | [diff] [blame] | 162 | qm_callback_(NULL), |
henrik.lundin@webrtc.org | ce8e093 | 2013-11-18 12:18:43 +0000 | [diff] [blame] | 163 | video_suspended_(false), |
asapersson@webrtc.org | 96dc685 | 2014-11-03 14:40:38 +0000 | [diff] [blame] | 164 | pre_encode_callback_(NULL), |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 165 | start_ms_(Clock::GetRealTimeClock()->TimeInMilliseconds()), |
| 166 | send_statistics_proxy_(NULL) { |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 167 | RtpRtcp::Configuration configuration; |
| 168 | configuration.id = ViEModuleId(engine_id_, channel_id_); |
| 169 | configuration.audio = false; // Video. |
| 170 | |
| 171 | default_rtp_rtcp_.reset(RtpRtcp::CreateRtpRtcp(configuration)); |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 172 | bitrate_observer_.reset(new ViEBitrateObserver(this)); |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 173 | pacing_callback_.reset(new ViEPacedSenderCallback(this)); |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 174 | paced_sender_.reset(new PacedSender( |
| 175 | Clock::GetRealTimeClock(), |
| 176 | pacing_callback_.get(), |
| 177 | kDefaultStartBitrateKbps, |
| 178 | PacedSender::kDefaultPaceMultiplier * kDefaultStartBitrateKbps, |
| 179 | 0)); |
wu@webrtc.org | 5d8c102 | 2012-04-10 16:54:05 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | bool ViEEncoder::Init() { |
| 183 | if (vcm_.InitializeSender() != 0) { |
wu@webrtc.org | 5d8c102 | 2012-04-10 16:54:05 +0000 | [diff] [blame] | 184 | return false; |
| 185 | } |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 186 | vpm_.EnableTemporalDecimation(true); |
| 187 | |
| 188 | // Enable/disable content analysis: off by default for now. |
| 189 | vpm_.EnableContentAnalysis(false); |
| 190 | |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 191 | if (module_process_thread_.RegisterModule(&vcm_) != 0 || |
| 192 | module_process_thread_.RegisterModule(default_rtp_rtcp_.get()) != 0 || |
| 193 | module_process_thread_.RegisterModule(paced_sender_.get()) != 0) { |
wu@webrtc.org | 5d8c102 | 2012-04-10 16:54:05 +0000 | [diff] [blame] | 194 | return false; |
| 195 | } |
stefan@webrtc.org | 9784512 | 2012-04-13 07:47:05 +0000 | [diff] [blame] | 196 | if (qm_callback_) { |
| 197 | delete qm_callback_; |
| 198 | } |
marpan@webrtc.org | efd01fd | 2012-04-18 15:56:34 +0000 | [diff] [blame] | 199 | qm_callback_ = new QMVideoSettingsCallback(&vpm_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 200 | |
| 201 | #ifdef VIDEOCODEC_VP8 |
andresp@webrtc.org | a84b0a6 | 2014-08-14 16:46:46 +0000 | [diff] [blame] | 202 | VideoCodecType codec_type = webrtc::kVideoCodecVP8; |
| 203 | #else |
| 204 | VideoCodecType codec_type = webrtc::kVideoCodecI420; |
| 205 | #endif |
| 206 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 207 | VideoCodec video_codec; |
andresp@webrtc.org | a84b0a6 | 2014-08-14 16:46:46 +0000 | [diff] [blame] | 208 | if (vcm_.Codec(codec_type, &video_codec) != VCM_OK) { |
wu@webrtc.org | 5d8c102 | 2012-04-10 16:54:05 +0000 | [diff] [blame] | 209 | return false; |
| 210 | } |
stefan@webrtc.org | ae2563a | 2014-02-13 13:48:38 +0000 | [diff] [blame] | 211 | { |
| 212 | CriticalSectionScoped cs(data_cs_.get()); |
| 213 | send_padding_ = video_codec.numberOfSimulcastStreams > 1; |
| 214 | } |
wu@webrtc.org | 5d8c102 | 2012-04-10 16:54:05 +0000 | [diff] [blame] | 215 | if (vcm_.RegisterSendCodec(&video_codec, number_of_cores_, |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 216 | default_rtp_rtcp_->MaxDataPayloadLength()) != 0) { |
wu@webrtc.org | 5d8c102 | 2012-04-10 16:54:05 +0000 | [diff] [blame] | 217 | return false; |
| 218 | } |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 219 | if (default_rtp_rtcp_->RegisterSendPayload(video_codec) != 0) { |
wu@webrtc.org | 5d8c102 | 2012-04-10 16:54:05 +0000 | [diff] [blame] | 220 | return false; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 221 | } |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 222 | if (vcm_.RegisterTransportCallback(this) != 0) { |
wu@webrtc.org | 5d8c102 | 2012-04-10 16:54:05 +0000 | [diff] [blame] | 223 | return false; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 224 | } |
| 225 | if (vcm_.RegisterSendStatisticsCallback(this) != 0) { |
wu@webrtc.org | 5d8c102 | 2012-04-10 16:54:05 +0000 | [diff] [blame] | 226 | return false; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 227 | } |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 228 | if (vcm_.RegisterVideoQMCallback(qm_callback_) != 0) { |
wu@webrtc.org | 5d8c102 | 2012-04-10 16:54:05 +0000 | [diff] [blame] | 229 | return false; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 230 | } |
wu@webrtc.org | 5d8c102 | 2012-04-10 16:54:05 +0000 | [diff] [blame] | 231 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 232 | } |
| 233 | |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 234 | void ViEEncoder::SetSendPayloadRouter(PayloadRouter* send_payload_router) { |
| 235 | DCHECK(send_payload_router_ == NULL); |
| 236 | send_payload_router_ = send_payload_router; |
| 237 | } |
| 238 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 239 | ViEEncoder::~ViEEncoder() { |
asapersson@webrtc.org | 96dc685 | 2014-11-03 14:40:38 +0000 | [diff] [blame] | 240 | UpdateHistograms(); |
stefan@webrtc.org | bf41508 | 2012-11-29 09:18:53 +0000 | [diff] [blame] | 241 | if (bitrate_controller_) { |
| 242 | bitrate_controller_->RemoveBitrateObserver(bitrate_observer_.get()); |
| 243 | } |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 244 | module_process_thread_.DeRegisterModule(&vcm_); |
| 245 | module_process_thread_.DeRegisterModule(&vpm_); |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 246 | module_process_thread_.DeRegisterModule(default_rtp_rtcp_.get()); |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 247 | module_process_thread_.DeRegisterModule(paced_sender_.get()); |
mflodman@webrtc.org | 6648093 | 2013-03-01 14:51:23 +0000 | [diff] [blame] | 248 | VideoCodingModule::Destroy(&vcm_); |
| 249 | VideoProcessingModule::Destroy(&vpm_); |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 250 | delete qm_callback_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 251 | } |
| 252 | |
asapersson@webrtc.org | 96dc685 | 2014-11-03 14:40:38 +0000 | [diff] [blame] | 253 | void ViEEncoder::UpdateHistograms() { |
asapersson@webrtc.org | 83b5200 | 2014-11-28 10:17:13 +0000 | [diff] [blame] | 254 | int64_t elapsed_sec = |
| 255 | (Clock::GetRealTimeClock()->TimeInMilliseconds() - start_ms_) / 1000; |
| 256 | if (elapsed_sec < metrics::kMinRunTimeInSeconds) { |
asapersson@webrtc.org | 96dc685 | 2014-11-03 14:40:38 +0000 | [diff] [blame] | 257 | return; |
| 258 | } |
| 259 | webrtc::VCMFrameCount frames; |
| 260 | if (vcm_.SentFrameCount(frames) != VCM_OK) { |
| 261 | return; |
| 262 | } |
| 263 | uint32_t total_frames = frames.numKeyFrames + frames.numDeltaFrames; |
| 264 | if (total_frames > 0) { |
| 265 | RTC_HISTOGRAM_COUNTS_1000("WebRTC.Video.KeyFramesSentInPermille", |
| 266 | static_cast<int>( |
| 267 | (frames.numKeyFrames * 1000.0f / total_frames) + 0.5f)); |
| 268 | } |
| 269 | } |
| 270 | |
mflodman@webrtc.org | 9ec883e | 2012-03-05 17:12:41 +0000 | [diff] [blame] | 271 | int ViEEncoder::Owner() const { |
| 272 | return channel_id_; |
| 273 | } |
| 274 | |
stefan@webrtc.org | bfacda6 | 2013-03-27 16:36:01 +0000 | [diff] [blame] | 275 | void ViEEncoder::SetNetworkTransmissionState(bool is_transmitting) { |
stefan@webrtc.org | bfacda6 | 2013-03-27 16:36:01 +0000 | [diff] [blame] | 276 | { |
| 277 | CriticalSectionScoped cs(data_cs_.get()); |
| 278 | network_is_transmitting_ = is_transmitting; |
| 279 | } |
| 280 | if (is_transmitting) { |
| 281 | paced_sender_->Resume(); |
| 282 | } else { |
| 283 | paced_sender_->Pause(); |
| 284 | } |
| 285 | } |
| 286 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 287 | void ViEEncoder::Pause() { |
mflodman@webrtc.org | d32c447 | 2011-12-22 14:17:53 +0000 | [diff] [blame] | 288 | CriticalSectionScoped cs(data_cs_.get()); |
stefan@webrtc.org | bfacda6 | 2013-03-27 16:36:01 +0000 | [diff] [blame] | 289 | encoder_paused_ = true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 290 | } |
| 291 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 292 | void ViEEncoder::Restart() { |
mflodman@webrtc.org | d32c447 | 2011-12-22 14:17:53 +0000 | [diff] [blame] | 293 | CriticalSectionScoped cs(data_cs_.get()); |
stefan@webrtc.org | bfacda6 | 2013-03-27 16:36:01 +0000 | [diff] [blame] | 294 | encoder_paused_ = false; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 295 | } |
| 296 | |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 297 | uint8_t ViEEncoder::NumberOfCodecs() { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 298 | return vcm_.NumberOfCodecs(); |
| 299 | } |
| 300 | |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 301 | int32_t ViEEncoder::GetCodec(uint8_t list_index, VideoCodec* video_codec) { |
mflodman@webrtc.org | f5e99db | 2012-06-27 09:49:37 +0000 | [diff] [blame] | 302 | if (vcm_.Codec(list_index, video_codec) != 0) { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 303 | return -1; |
| 304 | } |
| 305 | return 0; |
| 306 | } |
| 307 | |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 308 | int32_t ViEEncoder::RegisterExternalEncoder(webrtc::VideoEncoder* encoder, |
| 309 | uint8_t pl_type, |
| 310 | bool internal_source) { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 311 | if (encoder == NULL) |
| 312 | return -1; |
| 313 | |
stefan@webrtc.org | fcd8585 | 2013-01-09 08:35:40 +0000 | [diff] [blame] | 314 | if (vcm_.RegisterExternalEncoder(encoder, pl_type, internal_source) != |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 315 | VCM_OK) { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 316 | return -1; |
| 317 | } |
| 318 | return 0; |
| 319 | } |
| 320 | |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 321 | int32_t ViEEncoder::DeRegisterExternalEncoder(uint8_t pl_type) { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 322 | webrtc::VideoCodec current_send_codec; |
| 323 | if (vcm_.SendCodec(¤t_send_codec) == VCM_OK) { |
stefan@webrtc.org | 3d0b0d6 | 2013-03-19 10:04:57 +0000 | [diff] [blame] | 324 | uint32_t current_bitrate_bps = 0; |
| 325 | if (vcm_.Bitrate(¤t_bitrate_bps) != 0) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 326 | LOG(LS_WARNING) << "Failed to get the current encoder target bitrate."; |
stefan@webrtc.org | 439be29 | 2012-02-16 14:45:37 +0000 | [diff] [blame] | 327 | } |
stefan@webrtc.org | 3d0b0d6 | 2013-03-19 10:04:57 +0000 | [diff] [blame] | 328 | current_send_codec.startBitrate = (current_bitrate_bps + 500) / 1000; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | if (vcm_.RegisterExternalEncoder(NULL, pl_type) != VCM_OK) { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 332 | return -1; |
| 333 | } |
| 334 | |
stefan@webrtc.org | 508a84b | 2013-06-17 12:53:37 +0000 | [diff] [blame] | 335 | // If the external encoder is the current send codec, use vcm internal |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 336 | // encoder. |
| 337 | if (current_send_codec.plType == pl_type) { |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 338 | uint16_t max_data_payload_length = |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 339 | default_rtp_rtcp_->MaxDataPayloadLength(); |
stefan@webrtc.org | ae2563a | 2014-02-13 13:48:38 +0000 | [diff] [blame] | 340 | { |
| 341 | CriticalSectionScoped cs(data_cs_.get()); |
| 342 | send_padding_ = current_send_codec.numberOfSimulcastStreams > 1; |
| 343 | } |
fischman@webrtc.org | 64e0405 | 2014-03-07 18:00:05 +0000 | [diff] [blame] | 344 | // TODO(mflodman): Unfortunately the VideoCodec that VCM has cached a |
| 345 | // raw pointer to an |extra_options| that's long gone. Clearing it here is |
| 346 | // a hack to prevent the following code from crashing. This should be fixed |
| 347 | // for realz. https://code.google.com/p/chromium/issues/detail?id=348222 |
| 348 | current_send_codec.extra_options = NULL; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 349 | if (vcm_.RegisterSendCodec(¤t_send_codec, number_of_cores_, |
| 350 | max_data_payload_length) != VCM_OK) { |
stefan@webrtc.org | 4070b1d | 2014-07-16 11:20:40 +0000 | [diff] [blame] | 351 | LOG(LS_INFO) << "De-registered the currently used external encoder (" |
| 352 | << static_cast<int>(pl_type) << ") and therefore tried to " |
| 353 | << "register the corresponding internal encoder, but none " |
| 354 | << "was supported."; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 355 | } |
| 356 | } |
| 357 | return 0; |
| 358 | } |
| 359 | |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 360 | int32_t ViEEncoder::SetEncoder(const webrtc::VideoCodec& video_codec) { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 361 | // Setting target width and height for VPM. |
| 362 | if (vpm_.SetTargetResolution(video_codec.width, video_codec.height, |
| 363 | video_codec.maxFramerate) != VPM_OK) { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 364 | return -1; |
| 365 | } |
| 366 | |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 367 | if (default_rtp_rtcp_->RegisterSendPayload(video_codec) != 0) { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 368 | return -1; |
| 369 | } |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 370 | // Convert from kbps to bps. |
stefan@webrtc.org | b2c8a95 | 2013-09-06 13:58:01 +0000 | [diff] [blame] | 371 | std::vector<uint32_t> stream_bitrates = AllocateStreamBitrates( |
| 372 | video_codec.startBitrate * 1000, |
| 373 | video_codec.simulcastStream, |
| 374 | video_codec.numberOfSimulcastStreams); |
| 375 | default_rtp_rtcp_->SetTargetSendBitrate(stream_bitrates); |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 376 | |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 377 | uint16_t max_data_payload_length = |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 378 | default_rtp_rtcp_->MaxDataPayloadLength(); |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 379 | |
stefan@webrtc.org | 9075d51 | 2014-02-14 09:45:58 +0000 | [diff] [blame] | 380 | { |
| 381 | CriticalSectionScoped cs(data_cs_.get()); |
| 382 | send_padding_ = video_codec.numberOfSimulcastStreams > 1; |
| 383 | } |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 384 | if (vcm_.RegisterSendCodec(&video_codec, number_of_cores_, |
| 385 | max_data_payload_length) != VCM_OK) { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 386 | return -1; |
| 387 | } |
| 388 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 389 | // Set this module as sending right away, let the slave module in the channel |
| 390 | // start and stop sending. |
andresp@webrtc.org | a84b0a6 | 2014-08-14 16:46:46 +0000 | [diff] [blame] | 391 | if (default_rtp_rtcp_->SetSendingStatus(true) != 0) { |
| 392 | return -1; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 393 | } |
andresp@webrtc.org | a84b0a6 | 2014-08-14 16:46:46 +0000 | [diff] [blame] | 394 | |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 395 | bitrate_controller_->SetBitrateObserver(bitrate_observer_.get(), |
| 396 | video_codec.startBitrate * 1000, |
| 397 | video_codec.minBitrate * 1000, |
stefan@webrtc.org | bfacda6 | 2013-03-27 16:36:01 +0000 | [diff] [blame] | 398 | kTransmissionMaxBitrateMultiplier * |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 399 | video_codec.maxBitrate * 1000); |
sprang@webrtc.org | 9b79197 | 2014-12-18 11:53:59 +0000 | [diff] [blame] | 400 | bitrate_controller_->SetCodecMode(video_codec.mode); |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 401 | |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 +0000 | [diff] [blame] | 402 | CriticalSectionScoped crit(data_cs_.get()); |
| 403 | int pad_up_to_bitrate_kbps = video_codec.startBitrate; |
| 404 | if (pad_up_to_bitrate_kbps < min_transmit_bitrate_kbps_) |
| 405 | pad_up_to_bitrate_kbps = min_transmit_bitrate_kbps_; |
| 406 | |
stefan@webrtc.org | 88e0dda | 2014-07-04 09:20:42 +0000 | [diff] [blame] | 407 | paced_sender_->UpdateBitrate( |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 408 | video_codec.startBitrate, |
stefan@webrtc.org | 88e0dda | 2014-07-04 09:20:42 +0000 | [diff] [blame] | 409 | PacedSender::kDefaultPaceMultiplier * video_codec.startBitrate, |
| 410 | pad_up_to_bitrate_kbps); |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 +0000 | [diff] [blame] | 411 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 412 | return 0; |
| 413 | } |
| 414 | |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 415 | int32_t ViEEncoder::GetEncoder(VideoCodec* video_codec) { |
mflodman@webrtc.org | f5e99db | 2012-06-27 09:49:37 +0000 | [diff] [blame] | 416 | if (vcm_.SendCodec(video_codec) != 0) { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 417 | return -1; |
| 418 | } |
| 419 | return 0; |
| 420 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 421 | |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 422 | int32_t ViEEncoder::GetCodecConfigParameters( |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 423 | unsigned char config_parameters[kConfigParameterSize], |
| 424 | unsigned char& config_parameters_size) { |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 425 | int32_t num_parameters = |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 426 | vcm_.CodecConfigParameters(config_parameters, kConfigParameterSize); |
| 427 | if (num_parameters <= 0) { |
| 428 | config_parameters_size = 0; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 429 | return -1; |
| 430 | } |
| 431 | config_parameters_size = static_cast<unsigned char>(num_parameters); |
| 432 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 433 | } |
| 434 | |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 435 | int32_t ViEEncoder::ScaleInputImage(bool enable) { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 436 | VideoFrameResampling resampling_mode = kFastRescaling; |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 437 | // TODO(mflodman) What? |
| 438 | if (enable) { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 439 | // kInterpolation is currently not supported. |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 440 | LOG_F(LS_ERROR) << "Not supported."; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 441 | return -1; |
| 442 | } |
| 443 | vpm_.SetInputFrameResampleMode(resampling_mode); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 444 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 445 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 446 | } |
| 447 | |
stefan@webrtc.org | 9b82f5a | 2013-11-13 15:29:21 +0000 | [diff] [blame] | 448 | bool ViEEncoder::TimeToSendPacket(uint32_t ssrc, |
| 449 | uint16_t sequence_number, |
| 450 | int64_t capture_time_ms, |
| 451 | bool retransmission) { |
hclam@chromium.org | 2e402ce | 2013-06-20 20:18:31 +0000 | [diff] [blame] | 452 | return default_rtp_rtcp_->TimeToSendPacket(ssrc, sequence_number, |
stefan@webrtc.org | 9b82f5a | 2013-11-13 15:29:21 +0000 | [diff] [blame] | 453 | capture_time_ms, retransmission); |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 454 | } |
| 455 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 456 | size_t ViEEncoder::TimeToSendPadding(size_t bytes) { |
henrik.lundin@webrtc.org | 331d440 | 2013-11-21 14:05:40 +0000 | [diff] [blame] | 457 | bool send_padding; |
| 458 | { |
| 459 | CriticalSectionScoped cs(data_cs_.get()); |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 +0000 | [diff] [blame] | 460 | send_padding = |
| 461 | send_padding_ || video_suspended_ || min_transmit_bitrate_kbps_ > 0; |
henrik.lundin@webrtc.org | 331d440 | 2013-11-21 14:05:40 +0000 | [diff] [blame] | 462 | } |
| 463 | if (send_padding) { |
stefan@webrtc.org | 508a84b | 2013-06-17 12:53:37 +0000 | [diff] [blame] | 464 | return default_rtp_rtcp_->TimeToSendPadding(bytes); |
| 465 | } |
| 466 | return 0; |
| 467 | } |
| 468 | |
stefan@webrtc.org | bfacda6 | 2013-03-27 16:36:01 +0000 | [diff] [blame] | 469 | bool ViEEncoder::EncoderPaused() const { |
pwestin@webrtc.org | 91563e4 | 2013-04-25 22:20:08 +0000 | [diff] [blame] | 470 | // Pause video if paused by caller or as long as the network is down or the |
| 471 | // pacer queue has grown too large in buffered mode. |
| 472 | if (encoder_paused_) { |
| 473 | return true; |
| 474 | } |
| 475 | if (target_delay_ms_ > 0) { |
| 476 | // Buffered mode. |
| 477 | // TODO(pwestin): Workaround until nack is configured as a time and not |
| 478 | // number of packets. |
| 479 | return paced_sender_->QueueInMs() >= |
pwestin@webrtc.org | 52b4e88 | 2013-05-02 19:02:17 +0000 | [diff] [blame] | 480 | std::max(static_cast<int>(target_delay_ms_ * kEncoderPausePacerMargin), |
| 481 | kMinPacingDelayMs); |
pwestin@webrtc.org | 91563e4 | 2013-04-25 22:20:08 +0000 | [diff] [blame] | 482 | } |
sprang@webrtc.org | dcebf2d | 2014-11-04 16:27:16 +0000 | [diff] [blame] | 483 | if (paced_sender_->ExpectedQueueTimeMs() > |
| 484 | PacedSender::kDefaultMaxQueueLengthMs) { |
| 485 | // Too much data in pacer queue, drop frame. |
| 486 | return true; |
| 487 | } |
pwestin@webrtc.org | 91563e4 | 2013-04-25 22:20:08 +0000 | [diff] [blame] | 488 | return !network_is_transmitting_; |
stefan@webrtc.org | bfacda6 | 2013-03-27 16:36:01 +0000 | [diff] [blame] | 489 | } |
| 490 | |
sprang@webrtc.org | dcebf2d | 2014-11-04 16:27:16 +0000 | [diff] [blame] | 491 | void ViEEncoder::TraceFrameDropStart() { |
| 492 | // Start trace event only on the first frame after encoder is paused. |
| 493 | if (!encoder_paused_and_dropped_frame_) { |
| 494 | TRACE_EVENT_ASYNC_BEGIN0("webrtc", "EncoderPaused", this); |
| 495 | } |
| 496 | encoder_paused_and_dropped_frame_ = true; |
| 497 | return; |
| 498 | } |
| 499 | |
| 500 | void ViEEncoder::TraceFrameDropEnd() { |
| 501 | // End trace event on first frame after encoder resumes, if frame was dropped. |
| 502 | if (encoder_paused_and_dropped_frame_) { |
| 503 | TRACE_EVENT_ASYNC_END0("webrtc", "EncoderPaused", this); |
| 504 | } |
| 505 | encoder_paused_and_dropped_frame_ = false; |
| 506 | } |
| 507 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 508 | RtpRtcp* ViEEncoder::SendRtpRtcpModule() { |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 509 | return default_rtp_rtcp_.get(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 510 | } |
| 511 | |
mflodman@webrtc.org | 8baed51 | 2012-06-21 12:11:50 +0000 | [diff] [blame] | 512 | void ViEEncoder::DeliverFrame(int id, |
mikhal@webrtc.org | 9fedff7 | 2012-10-24 18:33:04 +0000 | [diff] [blame] | 513 | I420VideoFrame* video_frame, |
pbos@webrtc.org | 9334ac2 | 2014-11-24 08:25:50 +0000 | [diff] [blame] | 514 | const std::vector<uint32_t>& csrcs) { |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 515 | DCHECK(send_payload_router_ != NULL); |
| 516 | if (!default_rtp_rtcp_->SendingMedia() || !send_payload_router_->active()) { |
| 517 | // We've paused or we have no channels attached, don't waste resources on |
| 518 | // encoding. |
wuchengli@chromium.org | ac4b87c | 2014-03-19 03:44:20 +0000 | [diff] [blame] | 519 | return; |
| 520 | } |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 521 | { |
mflodman@webrtc.org | d32c447 | 2011-12-22 14:17:53 +0000 | [diff] [blame] | 522 | CriticalSectionScoped cs(data_cs_.get()); |
stefan@webrtc.org | 3e00505 | 2013-10-18 15:05:29 +0000 | [diff] [blame] | 523 | time_of_last_incoming_frame_ms_ = TickTime::MillisecondTimestamp(); |
pwestin@webrtc.org | 52b4e88 | 2013-05-02 19:02:17 +0000 | [diff] [blame] | 524 | if (EncoderPaused()) { |
sprang@webrtc.org | dcebf2d | 2014-11-04 16:27:16 +0000 | [diff] [blame] | 525 | TraceFrameDropStart(); |
pwestin@webrtc.org | 52b4e88 | 2013-05-02 19:02:17 +0000 | [diff] [blame] | 526 | return; |
| 527 | } |
sprang@webrtc.org | dcebf2d | 2014-11-04 16:27:16 +0000 | [diff] [blame] | 528 | TraceFrameDropEnd(); |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 529 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 530 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 531 | // Convert render time, in ms, to RTP timestamp. |
mflodman@webrtc.org | 8baed51 | 2012-06-21 12:11:50 +0000 | [diff] [blame] | 532 | const int kMsToRtpTimestamp = 90; |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 533 | const uint32_t time_stamp = |
mflodman@webrtc.org | 8baed51 | 2012-06-21 12:11:50 +0000 | [diff] [blame] | 534 | kMsToRtpTimestamp * |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 535 | static_cast<uint32_t>(video_frame->render_time_ms()); |
hclam@chromium.org | 806dc3b | 2013-04-09 19:54:10 +0000 | [diff] [blame] | 536 | |
hclam@chromium.org | 1a7b9b9 | 2013-07-08 21:31:18 +0000 | [diff] [blame] | 537 | TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame->render_time_ms(), |
| 538 | "Encode"); |
mikhal@webrtc.org | 9fedff7 | 2012-10-24 18:33:04 +0000 | [diff] [blame] | 539 | video_frame->set_timestamp(time_stamp); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 540 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 541 | // Make sure the CSRC list is correct. |
pbos@webrtc.org | 9334ac2 | 2014-11-24 08:25:50 +0000 | [diff] [blame] | 542 | if (csrcs.size() > 0) { |
| 543 | std::vector<uint32_t> temp_csrcs(csrcs.size()); |
| 544 | for (size_t i = 0; i < csrcs.size(); i++) { |
| 545 | if (csrcs[i] == 1) { |
| 546 | temp_csrcs[i] = default_rtp_rtcp_->SSRC(); |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 547 | } else { |
pbos@webrtc.org | 9334ac2 | 2014-11-24 08:25:50 +0000 | [diff] [blame] | 548 | temp_csrcs[i] = csrcs[i]; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 549 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 550 | } |
pbos@webrtc.org | 9334ac2 | 2014-11-24 08:25:50 +0000 | [diff] [blame] | 551 | default_rtp_rtcp_->SetCsrcs(temp_csrcs); |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 552 | } |
wuchengli@chromium.org | f425b55 | 2014-06-20 12:04:05 +0000 | [diff] [blame] | 553 | |
pwestin@webrtc.org | 2f476ed | 2012-10-30 16:21:52 +0000 | [diff] [blame] | 554 | I420VideoFrame* decimated_frame = NULL; |
wuchengli@chromium.org | f425b55 | 2014-06-20 12:04:05 +0000 | [diff] [blame] | 555 | // TODO(wuchengli): support texture frames. |
| 556 | if (video_frame->native_handle() == NULL) { |
| 557 | { |
| 558 | CriticalSectionScoped cs(callback_cs_.get()); |
| 559 | if (effect_filter_) { |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 560 | size_t length = |
wuchengli@chromium.org | f425b55 | 2014-06-20 12:04:05 +0000 | [diff] [blame] | 561 | CalcBufferSize(kI420, video_frame->width(), video_frame->height()); |
| 562 | scoped_ptr<uint8_t[]> video_buffer(new uint8_t[length]); |
| 563 | ExtractBuffer(*video_frame, length, video_buffer.get()); |
| 564 | effect_filter_->Transform(length, |
| 565 | video_buffer.get(), |
| 566 | video_frame->ntp_time_ms(), |
| 567 | video_frame->timestamp(), |
| 568 | video_frame->width(), |
| 569 | video_frame->height()); |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | // Pass frame via preprocessor. |
| 574 | const int ret = vpm_.PreprocessFrame(*video_frame, &decimated_frame); |
| 575 | if (ret == 1) { |
| 576 | // Drop this frame. |
| 577 | return; |
| 578 | } |
| 579 | if (ret != VPM_OK) { |
| 580 | return; |
| 581 | } |
pwestin@webrtc.org | 2f476ed | 2012-10-30 16:21:52 +0000 | [diff] [blame] | 582 | } |
wuchengli@chromium.org | f425b55 | 2014-06-20 12:04:05 +0000 | [diff] [blame] | 583 | // If the frame was not resampled or scaled => use original. |
pwestin@webrtc.org | 2f476ed | 2012-10-30 16:21:52 +0000 | [diff] [blame] | 584 | if (decimated_frame == NULL) { |
| 585 | decimated_frame = video_frame; |
| 586 | } |
pbos@webrtc.org | fe1ef93 | 2013-10-21 10:34:43 +0000 | [diff] [blame] | 587 | |
| 588 | { |
| 589 | CriticalSectionScoped cs(callback_cs_.get()); |
| 590 | if (pre_encode_callback_) |
| 591 | pre_encode_callback_->FrameCallback(decimated_frame); |
| 592 | } |
| 593 | |
wuchengli@chromium.org | f425b55 | 2014-06-20 12:04:05 +0000 | [diff] [blame] | 594 | if (video_frame->native_handle() != NULL) { |
| 595 | // TODO(wuchengli): add texture support. http://crbug.com/362437 |
| 596 | return; |
| 597 | } |
| 598 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 599 | #ifdef VIDEOCODEC_VP8 |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 600 | if (vcm_.SendCodec() == webrtc::kVideoCodecVP8) { |
| 601 | webrtc::CodecSpecificInfo codec_specific_info; |
| 602 | codec_specific_info.codecType = webrtc::kVideoCodecVP8; |
stefan@webrtc.org | 7af12be | 2014-07-09 14:46:31 +0000 | [diff] [blame] | 603 | { |
| 604 | CriticalSectionScoped cs(data_cs_.get()); |
| 605 | codec_specific_info.codecSpecific.VP8.hasReceivedRPSI = |
| 606 | has_received_rpsi_; |
| 607 | codec_specific_info.codecSpecific.VP8.hasReceivedSLI = |
| 608 | has_received_sli_; |
| 609 | codec_specific_info.codecSpecific.VP8.pictureIdRPSI = |
| 610 | picture_id_rpsi_; |
| 611 | codec_specific_info.codecSpecific.VP8.pictureIdSLI = |
| 612 | picture_id_sli_; |
| 613 | has_received_sli_ = false; |
| 614 | has_received_rpsi_ = false; |
| 615 | } |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 616 | |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 617 | vcm_.AddVideoFrame(*decimated_frame, vpm_.ContentMetrics(), |
| 618 | &codec_specific_info); |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 619 | return; |
| 620 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 621 | #endif |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 622 | vcm_.AddVideoFrame(*decimated_frame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 623 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 624 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 625 | void ViEEncoder::DelayChanged(int id, int frame_delay) { |
stefan@webrtc.org | 7da3459 | 2013-04-09 14:56:29 +0000 | [diff] [blame] | 626 | default_rtp_rtcp_->SetCameraDelay(frame_delay); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 627 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 628 | |
mflodman@webrtc.org | 8baed51 | 2012-06-21 12:11:50 +0000 | [diff] [blame] | 629 | int ViEEncoder::GetPreferedFrameSettings(int* width, |
| 630 | int* height, |
| 631 | int* frame_rate) { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 632 | webrtc::VideoCodec video_codec; |
| 633 | memset(&video_codec, 0, sizeof(video_codec)); |
| 634 | if (vcm_.SendCodec(&video_codec) != VCM_OK) { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 635 | return -1; |
| 636 | } |
| 637 | |
mflodman@webrtc.org | 8baed51 | 2012-06-21 12:11:50 +0000 | [diff] [blame] | 638 | *width = video_codec.width; |
| 639 | *height = video_codec.height; |
| 640 | *frame_rate = video_codec.maxFramerate; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 641 | return 0; |
| 642 | } |
| 643 | |
pwestin@webrtc.org | ce33035 | 2012-04-12 06:59:14 +0000 | [diff] [blame] | 644 | int ViEEncoder::SendKeyFrame() { |
stefan@webrtc.org | c530043 | 2012-10-08 07:06:53 +0000 | [diff] [blame] | 645 | return vcm_.IntraFrameRequest(0); |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 646 | } |
| 647 | |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 648 | int32_t ViEEncoder::SendCodecStatistics( |
| 649 | uint32_t* num_key_frames, uint32_t* num_delta_frames) { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 650 | webrtc::VCMFrameCount sent_frames; |
| 651 | if (vcm_.SentFrameCount(sent_frames) != VCM_OK) { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 652 | return -1; |
| 653 | } |
mflodman@webrtc.org | f5e99db | 2012-06-27 09:49:37 +0000 | [diff] [blame] | 654 | *num_key_frames = sent_frames.numKeyFrames; |
| 655 | *num_delta_frames = sent_frames.numDeltaFrames; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 656 | return 0; |
| 657 | } |
| 658 | |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 659 | int64_t ViEEncoder::PacerQueuingDelayMs() const { |
jiayl@webrtc.org | 9fd8d87 | 2014-02-27 22:32:40 +0000 | [diff] [blame] | 660 | return paced_sender_->QueueInMs(); |
| 661 | } |
| 662 | |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 663 | int ViEEncoder::CodecTargetBitrate(uint32_t* bitrate) const { |
stefan@webrtc.org | 439be29 | 2012-02-16 14:45:37 +0000 | [diff] [blame] | 664 | if (vcm_.Bitrate(bitrate) != 0) |
| 665 | return -1; |
| 666 | return 0; |
stefan@webrtc.org | 07b45a5 | 2012-02-02 08:37:48 +0000 | [diff] [blame] | 667 | } |
| 668 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 669 | int32_t ViEEncoder::UpdateProtectionMethod(bool enable_nack) { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 670 | bool fec_enabled = false; |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 671 | uint8_t dummy_ptype_red = 0; |
| 672 | uint8_t dummy_ptypeFEC = 0; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 673 | |
| 674 | // Updated protection method to VCM to get correct packetization sizes. |
| 675 | // FEC has larger overhead than NACK -> set FEC if used. |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 676 | int32_t error = default_rtp_rtcp_->GenericFECStatus(fec_enabled, |
| 677 | dummy_ptype_red, |
| 678 | dummy_ptypeFEC); |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 679 | if (error) { |
| 680 | return -1; |
| 681 | } |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 682 | if (fec_enabled_ == fec_enabled && nack_enabled_ == enable_nack) { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 683 | // No change needed, we're already in correct state. |
| 684 | return 0; |
| 685 | } |
| 686 | fec_enabled_ = fec_enabled; |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 687 | nack_enabled_ = enable_nack; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 688 | |
| 689 | // Set Video Protection for VCM. |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 690 | if (fec_enabled && nack_enabled_) { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 691 | vcm_.SetVideoProtection(webrtc::kProtectionNackFEC, true); |
| 692 | } else { |
| 693 | vcm_.SetVideoProtection(webrtc::kProtectionFEC, fec_enabled_); |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 694 | vcm_.SetVideoProtection(webrtc::kProtectionNackSender, nack_enabled_); |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 695 | vcm_.SetVideoProtection(webrtc::kProtectionNackFEC, false); |
| 696 | } |
| 697 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 698 | if (fec_enabled_ || nack_enabled_) { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 699 | vcm_.RegisterProtectionCallback(this); |
| 700 | // The send codec must be registered to set correct MTU. |
| 701 | webrtc::VideoCodec codec; |
| 702 | if (vcm_.SendCodec(&codec) == 0) { |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 703 | uint16_t max_pay_load = default_rtp_rtcp_->MaxDataPayloadLength(); |
stefan@webrtc.org | 3d0b0d6 | 2013-03-19 10:04:57 +0000 | [diff] [blame] | 704 | uint32_t current_bitrate_bps = 0; |
| 705 | if (vcm_.Bitrate(¤t_bitrate_bps) != 0) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 706 | LOG_F(LS_WARNING) << |
| 707 | "Failed to get the current encoder target bitrate."; |
stefan@webrtc.org | 439be29 | 2012-02-16 14:45:37 +0000 | [diff] [blame] | 708 | } |
stefan@webrtc.org | 3d0b0d6 | 2013-03-19 10:04:57 +0000 | [diff] [blame] | 709 | // Convert to start bitrate in kbps. |
| 710 | codec.startBitrate = (current_bitrate_bps + 500) / 1000; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 711 | if (vcm_.RegisterSendCodec(&codec, number_of_cores_, max_pay_load) != 0) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 712 | return -1; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 713 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 714 | } |
| 715 | return 0; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 716 | } else { |
| 717 | // FEC and NACK are disabled. |
| 718 | vcm_.RegisterProtectionCallback(NULL); |
| 719 | } |
| 720 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 721 | } |
| 722 | |
mikhal@webrtc.org | ef9f76a | 2013-02-15 23:22:18 +0000 | [diff] [blame] | 723 | void ViEEncoder::SetSenderBufferingMode(int target_delay_ms) { |
stefan@webrtc.org | bfacda6 | 2013-03-27 16:36:01 +0000 | [diff] [blame] | 724 | { |
| 725 | CriticalSectionScoped cs(data_cs_.get()); |
| 726 | target_delay_ms_ = target_delay_ms; |
| 727 | } |
mikhal@webrtc.org | 3d305c6 | 2013-02-10 18:42:55 +0000 | [diff] [blame] | 728 | if (target_delay_ms > 0) { |
stefan@webrtc.org | bfacda6 | 2013-03-27 16:36:01 +0000 | [diff] [blame] | 729 | // Disable external frame-droppers. |
| 730 | vcm_.EnableFrameDropper(false); |
| 731 | vpm_.EnableTemporalDecimation(false); |
mikhal@webrtc.org | 3d305c6 | 2013-02-10 18:42:55 +0000 | [diff] [blame] | 732 | } else { |
mikhal@webrtc.org | ef9f76a | 2013-02-15 23:22:18 +0000 | [diff] [blame] | 733 | // Real-time mode - enable frame droppers. |
mikhal@webrtc.org | 3d305c6 | 2013-02-10 18:42:55 +0000 | [diff] [blame] | 734 | vpm_.EnableTemporalDecimation(true); |
| 735 | vcm_.EnableFrameDropper(true); |
| 736 | } |
| 737 | } |
| 738 | |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 739 | int32_t ViEEncoder::SendData( |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 740 | const uint8_t payload_type, |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 741 | const EncodedImage& encoded_image, |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 742 | const webrtc::RTPFragmentationHeader& fragmentation_header, |
| 743 | const RTPVideoHeader* rtp_video_hdr) { |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 744 | DCHECK(send_payload_router_ != NULL); |
| 745 | |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 746 | if (send_statistics_proxy_ != NULL) { |
| 747 | send_statistics_proxy_->OnSendEncodedImage(encoded_image, rtp_video_hdr); |
| 748 | } |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 749 | |
| 750 | return send_payload_router_->RoutePayload( |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 751 | VCMEncodedFrame::ConvertFrameType(encoded_image._frameType), payload_type, |
| 752 | encoded_image._timeStamp, encoded_image.capture_time_ms_, |
| 753 | encoded_image._buffer, encoded_image._length, &fragmentation_header, |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 754 | rtp_video_hdr) ? 0 : -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 755 | } |
| 756 | |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 757 | int32_t ViEEncoder::ProtectionRequest( |
stefan@webrtc.org | e0d6fa4 | 2012-03-20 22:10:56 +0000 | [diff] [blame] | 758 | const FecProtectionParams* delta_fec_params, |
| 759 | const FecProtectionParams* key_fec_params, |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 760 | uint32_t* sent_video_rate_bps, |
| 761 | uint32_t* sent_nack_rate_bps, |
| 762 | uint32_t* sent_fec_rate_bps) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 763 | default_rtp_rtcp_->SetFecParameters(delta_fec_params, key_fec_params); |
| 764 | default_rtp_rtcp_->BitrateSent(NULL, sent_video_rate_bps, sent_fec_rate_bps, |
stefan@webrtc.org | f4c8286 | 2011-12-13 15:38:14 +0000 | [diff] [blame] | 765 | sent_nack_rate_bps); |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 766 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 767 | } |
| 768 | |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 769 | int32_t ViEEncoder::SendStatistics(const uint32_t bit_rate, |
| 770 | const uint32_t frame_rate) { |
sprang@webrtc.org | 9b79197 | 2014-12-18 11:53:59 +0000 | [diff] [blame] | 771 | bitrate_controller_->SetBitrateSent(bit_rate); |
mflodman@webrtc.org | d32c447 | 2011-12-22 14:17:53 +0000 | [diff] [blame] | 772 | CriticalSectionScoped cs(callback_cs_.get()); |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 773 | if (codec_observer_) { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 774 | codec_observer_->OutgoingRate(channel_id_, frame_rate, bit_rate); |
| 775 | } |
| 776 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 777 | } |
| 778 | |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 779 | int32_t ViEEncoder::RegisterCodecObserver(ViEEncoderObserver* observer) { |
mflodman@webrtc.org | d32c447 | 2011-12-22 14:17:53 +0000 | [diff] [blame] | 780 | CriticalSectionScoped cs(callback_cs_.get()); |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 781 | if (observer && codec_observer_) { |
| 782 | LOG_F(LS_ERROR) << "Observer already set."; |
| 783 | return -1; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 784 | } |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 785 | codec_observer_ = observer; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 786 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 787 | } |
| 788 | |
andrew@webrtc.org | 9663686 | 2012-09-20 23:33:17 +0000 | [diff] [blame] | 789 | void ViEEncoder::OnReceivedSLI(uint32_t /*ssrc*/, |
| 790 | uint8_t picture_id) { |
stefan@webrtc.org | 7af12be | 2014-07-09 14:46:31 +0000 | [diff] [blame] | 791 | CriticalSectionScoped cs(data_cs_.get()); |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 792 | picture_id_sli_ = picture_id; |
| 793 | has_received_sli_ = true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 794 | } |
| 795 | |
andrew@webrtc.org | 9663686 | 2012-09-20 23:33:17 +0000 | [diff] [blame] | 796 | void ViEEncoder::OnReceivedRPSI(uint32_t /*ssrc*/, |
| 797 | uint64_t picture_id) { |
stefan@webrtc.org | 7af12be | 2014-07-09 14:46:31 +0000 | [diff] [blame] | 798 | CriticalSectionScoped cs(data_cs_.get()); |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 799 | picture_id_rpsi_ = picture_id; |
| 800 | has_received_rpsi_ = true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 801 | } |
| 802 | |
mflodman@webrtc.org | d6ec386 | 2012-10-25 11:30:29 +0000 | [diff] [blame] | 803 | void ViEEncoder::OnReceivedIntraFrameRequest(uint32_t ssrc) { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 804 | // Key frame request from remote side, signal to VCM. |
justinlin@chromium.org | 7bfb3a3 | 2013-05-13 22:59:00 +0000 | [diff] [blame] | 805 | TRACE_EVENT0("webrtc", "OnKeyFrameRequest"); |
pwestin@webrtc.org | 1da1ce0 | 2011-10-13 15:19:55 +0000 | [diff] [blame] | 806 | |
mflodman@webrtc.org | d6ec386 | 2012-10-25 11:30:29 +0000 | [diff] [blame] | 807 | int idx = 0; |
| 808 | { |
| 809 | CriticalSectionScoped cs(data_cs_.get()); |
| 810 | std::map<unsigned int, int>::iterator stream_it = ssrc_streams_.find(ssrc); |
| 811 | if (stream_it == ssrc_streams_.end()) { |
mflodman@webrtc.org | d73527c | 2012-12-20 09:26:17 +0000 | [diff] [blame] | 812 | LOG_F(LS_WARNING) << "ssrc not found: " << ssrc << ", map size " |
| 813 | << ssrc_streams_.size(); |
mflodman@webrtc.org | d6ec386 | 2012-10-25 11:30:29 +0000 | [diff] [blame] | 814 | return; |
| 815 | } |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 816 | std::map<unsigned int, int64_t>::iterator time_it = |
mflodman@webrtc.org | d6ec386 | 2012-10-25 11:30:29 +0000 | [diff] [blame] | 817 | time_last_intra_request_ms_.find(ssrc); |
| 818 | if (time_it == time_last_intra_request_ms_.end()) { |
| 819 | time_last_intra_request_ms_[ssrc] = 0; |
| 820 | } |
| 821 | |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 822 | int64_t now = TickTime::MillisecondTimestamp(); |
mflodman@webrtc.org | d6ec386 | 2012-10-25 11:30:29 +0000 | [diff] [blame] | 823 | if (time_last_intra_request_ms_[ssrc] + kViEMinKeyRequestIntervalMs > now) { |
mflodman@webrtc.org | d6ec386 | 2012-10-25 11:30:29 +0000 | [diff] [blame] | 824 | return; |
| 825 | } |
| 826 | time_last_intra_request_ms_[ssrc] = now; |
| 827 | idx = stream_it->second; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 828 | } |
mflodman@webrtc.org | d6ec386 | 2012-10-25 11:30:29 +0000 | [diff] [blame] | 829 | // Release the critsect before triggering key frame. |
| 830 | vcm_.IntraFrameRequest(idx); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 831 | } |
| 832 | |
mflodman@webrtc.org | aca2629 | 2012-10-05 16:17:41 +0000 | [diff] [blame] | 833 | void ViEEncoder::OnLocalSsrcChanged(uint32_t old_ssrc, uint32_t new_ssrc) { |
mflodman@webrtc.org | d6ec386 | 2012-10-25 11:30:29 +0000 | [diff] [blame] | 834 | CriticalSectionScoped cs(data_cs_.get()); |
| 835 | std::map<unsigned int, int>::iterator it = ssrc_streams_.find(old_ssrc); |
| 836 | if (it == ssrc_streams_.end()) { |
| 837 | return; |
| 838 | } |
| 839 | |
| 840 | ssrc_streams_[new_ssrc] = it->second; |
| 841 | ssrc_streams_.erase(it); |
| 842 | |
| 843 | std::map<unsigned int, int64_t>::iterator time_it = |
| 844 | time_last_intra_request_ms_.find(old_ssrc); |
| 845 | int64_t last_intra_request_ms = 0; |
| 846 | if (time_it != time_last_intra_request_ms_.end()) { |
| 847 | last_intra_request_ms = time_it->second; |
| 848 | time_last_intra_request_ms_.erase(time_it); |
| 849 | } |
| 850 | time_last_intra_request_ms_[new_ssrc] = last_intra_request_ms; |
| 851 | } |
| 852 | |
| 853 | bool ViEEncoder::SetSsrcs(const std::list<unsigned int>& ssrcs) { |
| 854 | VideoCodec codec; |
| 855 | if (vcm_.SendCodec(&codec) != 0) |
| 856 | return false; |
| 857 | |
| 858 | if (codec.numberOfSimulcastStreams > 0 && |
| 859 | ssrcs.size() != codec.numberOfSimulcastStreams) { |
| 860 | return false; |
| 861 | } |
| 862 | |
| 863 | CriticalSectionScoped cs(data_cs_.get()); |
| 864 | ssrc_streams_.clear(); |
| 865 | time_last_intra_request_ms_.clear(); |
| 866 | int idx = 0; |
| 867 | for (std::list<unsigned int>::const_iterator it = ssrcs.begin(); |
| 868 | it != ssrcs.end(); ++it, ++idx) { |
| 869 | unsigned int ssrc = *it; |
| 870 | ssrc_streams_[ssrc] = idx; |
| 871 | } |
| 872 | return true; |
mflodman@webrtc.org | aca2629 | 2012-10-05 16:17:41 +0000 | [diff] [blame] | 873 | } |
| 874 | |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 +0000 | [diff] [blame] | 875 | void ViEEncoder::SetMinTransmitBitrate(int min_transmit_bitrate_kbps) { |
| 876 | assert(min_transmit_bitrate_kbps >= 0); |
| 877 | CriticalSectionScoped crit(data_cs_.get()); |
| 878 | min_transmit_bitrate_kbps_ = min_transmit_bitrate_kbps; |
| 879 | } |
| 880 | |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 881 | // Called from ViEBitrateObserver. |
stefan@webrtc.org | edeea91 | 2014-12-08 19:46:23 +0000 | [diff] [blame] | 882 | void ViEEncoder::OnNetworkChanged(uint32_t bitrate_bps, |
| 883 | uint8_t fraction_lost, |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 884 | int64_t round_trip_time_ms) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 885 | LOG(LS_VERBOSE) << "OnNetworkChanged, bitrate" << bitrate_bps |
| 886 | << " packet loss " << fraction_lost |
| 887 | << " rtt " << round_trip_time_ms; |
stefan@webrtc.org | abc9d5b | 2013-03-18 17:00:51 +0000 | [diff] [blame] | 888 | vcm_.SetChannelParameters(bitrate_bps, fraction_lost, round_trip_time_ms); |
henrik.lundin@webrtc.org | ce8e093 | 2013-11-18 12:18:43 +0000 | [diff] [blame] | 889 | bool video_is_suspended = vcm_.VideoSuspended(); |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 890 | int bitrate_kbps = bitrate_bps / 1000; |
stefan@webrtc.org | 508a84b | 2013-06-17 12:53:37 +0000 | [diff] [blame] | 891 | VideoCodec send_codec; |
| 892 | if (vcm_.SendCodec(&send_codec) != 0) { |
| 893 | return; |
| 894 | } |
stefan@webrtc.org | b2c8a95 | 2013-09-06 13:58:01 +0000 | [diff] [blame] | 895 | SimulcastStream* stream_configs = send_codec.simulcastStream; |
| 896 | // Allocate the bandwidth between the streams. |
| 897 | std::vector<uint32_t> stream_bitrates = AllocateStreamBitrates( |
| 898 | bitrate_bps, |
| 899 | stream_configs, |
| 900 | send_codec.numberOfSimulcastStreams); |
| 901 | // Find the max amount of padding we can allow ourselves to send at this |
| 902 | // point, based on which streams are currently active and what our current |
| 903 | // available bandwidth is. |
stefan@webrtc.org | b400aa7 | 2013-10-16 13:03:10 +0000 | [diff] [blame] | 904 | int pad_up_to_bitrate_kbps = 0; |
| 905 | if (send_codec.numberOfSimulcastStreams == 0) { |
stefan@webrtc.org | b400aa7 | 2013-10-16 13:03:10 +0000 | [diff] [blame] | 906 | pad_up_to_bitrate_kbps = send_codec.minBitrate; |
| 907 | } else { |
stefan@webrtc.org | b400aa7 | 2013-10-16 13:03:10 +0000 | [diff] [blame] | 908 | pad_up_to_bitrate_kbps = |
| 909 | stream_configs[send_codec.numberOfSimulcastStreams - 1].minBitrate; |
| 910 | for (int i = 0; i < send_codec.numberOfSimulcastStreams - 1; ++i) { |
| 911 | pad_up_to_bitrate_kbps += stream_configs[i].targetBitrate; |
| 912 | } |
stefan@webrtc.org | b2c8a95 | 2013-09-06 13:58:01 +0000 | [diff] [blame] | 913 | } |
pbos@webrtc.org | 709e297 | 2014-03-19 10:59:52 +0000 | [diff] [blame] | 914 | |
| 915 | // Disable padding if only sending one stream and video isn't suspended and |
| 916 | // min-transmit bitrate isn't used (applied later). |
| 917 | if (!video_is_suspended && send_codec.numberOfSimulcastStreams <= 1) |
stefan@webrtc.org | b400aa7 | 2013-10-16 13:03:10 +0000 | [diff] [blame] | 918 | pad_up_to_bitrate_kbps = 0; |
stefan@webrtc.org | 3e00505 | 2013-10-18 15:05:29 +0000 | [diff] [blame] | 919 | |
| 920 | { |
stefan@webrtc.org | 3e00505 | 2013-10-18 15:05:29 +0000 | [diff] [blame] | 921 | CriticalSectionScoped cs(data_cs_.get()); |
pbos@webrtc.org | 709e297 | 2014-03-19 10:59:52 +0000 | [diff] [blame] | 922 | // The amount of padding should decay to zero if no frames are being |
| 923 | // captured unless a min-transmit bitrate is used. |
stefan@webrtc.org | 3e00505 | 2013-10-18 15:05:29 +0000 | [diff] [blame] | 924 | int64_t now_ms = TickTime::MillisecondTimestamp(); |
| 925 | if (now_ms - time_of_last_incoming_frame_ms_ > kStopPaddingThresholdMs) |
pbos@webrtc.org | 709e297 | 2014-03-19 10:59:52 +0000 | [diff] [blame] | 926 | pad_up_to_bitrate_kbps = 0; |
stefan@webrtc.org | 3e00505 | 2013-10-18 15:05:29 +0000 | [diff] [blame] | 927 | |
pbos@webrtc.org | 709e297 | 2014-03-19 10:59:52 +0000 | [diff] [blame] | 928 | // Pad up to min bitrate. |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 +0000 | [diff] [blame] | 929 | if (pad_up_to_bitrate_kbps < min_transmit_bitrate_kbps_) |
| 930 | pad_up_to_bitrate_kbps = min_transmit_bitrate_kbps_; |
pbos@webrtc.org | 709e297 | 2014-03-19 10:59:52 +0000 | [diff] [blame] | 931 | |
| 932 | // Padding may never exceed bitrate estimate. |
| 933 | if (pad_up_to_bitrate_kbps > bitrate_kbps) |
| 934 | pad_up_to_bitrate_kbps = bitrate_kbps; |
| 935 | |
stefan@webrtc.org | 88e0dda | 2014-07-04 09:20:42 +0000 | [diff] [blame] | 936 | paced_sender_->UpdateBitrate( |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 937 | bitrate_kbps, |
stefan@webrtc.org | 88e0dda | 2014-07-04 09:20:42 +0000 | [diff] [blame] | 938 | PacedSender::kDefaultPaceMultiplier * bitrate_kbps, |
| 939 | pad_up_to_bitrate_kbps); |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 +0000 | [diff] [blame] | 940 | default_rtp_rtcp_->SetTargetSendBitrate(stream_bitrates); |
pbos@webrtc.org | 484ee96 | 2013-11-21 18:44:23 +0000 | [diff] [blame] | 941 | if (video_suspended_ == video_is_suspended) |
| 942 | return; |
| 943 | video_suspended_ = video_is_suspended; |
| 944 | } |
pbos@webrtc.org | 709e297 | 2014-03-19 10:59:52 +0000 | [diff] [blame] | 945 | |
| 946 | // Video suspend-state changed, inform codec observer. |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 +0000 | [diff] [blame] | 947 | CriticalSectionScoped crit(callback_cs_.get()); |
pbos@webrtc.org | 484ee96 | 2013-11-21 18:44:23 +0000 | [diff] [blame] | 948 | if (codec_observer_) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 949 | LOG(LS_INFO) << "Video suspended " << video_is_suspended |
| 950 | << " for channel " << channel_id_; |
henrik.lundin@webrtc.org | 9fe3603 | 2013-11-21 23:00:40 +0000 | [diff] [blame] | 951 | codec_observer_->SuspendChange(channel_id_, video_is_suspended); |
henrik.lundin@webrtc.org | 7ea4f24 | 2013-10-02 13:34:26 +0000 | [diff] [blame] | 952 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 953 | } |
| 954 | |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 955 | PacedSender* ViEEncoder::GetPacedSender() { |
| 956 | return paced_sender_.get(); |
| 957 | } |
| 958 | |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 959 | int32_t ViEEncoder::RegisterEffectFilter(ViEEffectFilter* effect_filter) { |
mflodman@webrtc.org | d32c447 | 2011-12-22 14:17:53 +0000 | [diff] [blame] | 960 | CriticalSectionScoped cs(callback_cs_.get()); |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 961 | if (effect_filter != NULL && effect_filter_ != NULL) { |
| 962 | LOG_F(LS_ERROR) << "Filter already set."; |
| 963 | return -1; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 964 | } |
| 965 | effect_filter_ = effect_filter; |
| 966 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 967 | } |
| 968 | |
mikhal@webrtc.org | e41bbdf | 2012-08-28 16:15:16 +0000 | [diff] [blame] | 969 | int ViEEncoder::StartDebugRecording(const char* fileNameUTF8) { |
| 970 | return vcm_.StartDebugRecording(fileNameUTF8); |
| 971 | } |
| 972 | |
| 973 | int ViEEncoder::StopDebugRecording() { |
| 974 | return vcm_.StopDebugRecording(); |
| 975 | } |
| 976 | |
henrik.lundin@webrtc.org | ce8e093 | 2013-11-18 12:18:43 +0000 | [diff] [blame] | 977 | void ViEEncoder::SuspendBelowMinBitrate() { |
| 978 | vcm_.SuspendBelowMinBitrate(); |
henrik.lundin@webrtc.org | 1a3a6e5 | 2013-10-28 10:16:14 +0000 | [diff] [blame] | 979 | bitrate_controller_->EnforceMinBitrate(false); |
henrik.lundin@webrtc.org | 7ea4f24 | 2013-10-02 13:34:26 +0000 | [diff] [blame] | 980 | } |
| 981 | |
pbos@webrtc.org | fe1ef93 | 2013-10-21 10:34:43 +0000 | [diff] [blame] | 982 | void ViEEncoder::RegisterPreEncodeCallback( |
| 983 | I420FrameCallback* pre_encode_callback) { |
| 984 | CriticalSectionScoped cs(callback_cs_.get()); |
| 985 | pre_encode_callback_ = pre_encode_callback; |
| 986 | } |
| 987 | |
| 988 | void ViEEncoder::DeRegisterPreEncodeCallback() { |
| 989 | CriticalSectionScoped cs(callback_cs_.get()); |
| 990 | pre_encode_callback_ = NULL; |
| 991 | } |
| 992 | |
sprang@webrtc.org | 4070935 | 2013-11-26 11:41:59 +0000 | [diff] [blame] | 993 | void ViEEncoder::RegisterPostEncodeImageCallback( |
| 994 | EncodedImageCallback* post_encode_callback) { |
| 995 | vcm_.RegisterPostEncodeImageCallback(post_encode_callback); |
| 996 | } |
| 997 | |
| 998 | void ViEEncoder::DeRegisterPostEncodeImageCallback() { |
| 999 | vcm_.RegisterPostEncodeImageCallback(NULL); |
| 1000 | } |
| 1001 | |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 1002 | void ViEEncoder::RegisterSendStatisticsProxy( |
| 1003 | SendStatisticsProxy* send_statistics_proxy) { |
| 1004 | send_statistics_proxy_ = send_statistics_proxy; |
| 1005 | } |
| 1006 | |
marpan@webrtc.org | efd01fd | 2012-04-18 15:56:34 +0000 | [diff] [blame] | 1007 | QMVideoSettingsCallback::QMVideoSettingsCallback(VideoProcessingModule* vpm) |
| 1008 | : vpm_(vpm) { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 1009 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1010 | |
stefan@webrtc.org | 439be29 | 2012-02-16 14:45:37 +0000 | [diff] [blame] | 1011 | QMVideoSettingsCallback::~QMVideoSettingsCallback() { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 1012 | } |
| 1013 | |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 1014 | int32_t QMVideoSettingsCallback::SetVideoQMSettings( |
| 1015 | const uint32_t frame_rate, |
| 1016 | const uint32_t width, |
| 1017 | const uint32_t height) { |
marpan@webrtc.org | cf706c2 | 2012-03-27 21:04:13 +0000 | [diff] [blame] | 1018 | return vpm_->SetTargetResolution(width, height, frame_rate); |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 1019 | } |
| 1020 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 1021 | } // namespace webrtc |