Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: webrtc/video/video_send_stream.cc

Issue 1394243006: Move ownership of send ViEChannels and ViEEncoder to VideoSendStream. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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/video_send_stream.h" 11 #include "webrtc/video/video_send_stream.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <sstream> 14 #include <sstream>
15 #include <string> 15 #include <string>
16 #include <vector> 16 #include <vector>
17 17
18 #include "webrtc/base/checks.h" 18 #include "webrtc/base/checks.h"
19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" 19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
20 #include "webrtc/modules/pacing/include/packet_router.h" 20 #include "webrtc/modules/pacing/include/packet_router.h"
21 #include "webrtc/system_wrappers/interface/logging.h" 21 #include "webrtc/system_wrappers/interface/logging.h"
22 #include "webrtc/system_wrappers/interface/trace_event.h" 22 #include "webrtc/system_wrappers/interface/trace_event.h"
23 #include "webrtc/video/video_capture_input.h" 23 #include "webrtc/video/video_capture_input.h"
24 #include "webrtc/video_engine/call_stats.h"
25 #include "webrtc/video_engine/payload_router.h"
24 #include "webrtc/video_engine/vie_channel.h" 26 #include "webrtc/video_engine/vie_channel.h"
25 #include "webrtc/video_engine/vie_channel_group.h" 27 #include "webrtc/video_engine/vie_channel_group.h"
26 #include "webrtc/video_engine/vie_defines.h" 28 #include "webrtc/video_engine/vie_defines.h"
27 #include "webrtc/video_engine/vie_encoder.h" 29 #include "webrtc/video_engine/vie_encoder.h"
28 #include "webrtc/video_send_stream.h" 30 #include "webrtc/video_send_stream.h"
29 31
30 namespace webrtc { 32 namespace webrtc {
33
34 class BitrateAllocator;
35 class PacedSender;
36 class RtcpIntraFrameObserver;
37 class TransportFeedbackObserver;
38
31 std::string 39 std::string
32 VideoSendStream::Config::EncoderSettings::ToString() const { 40 VideoSendStream::Config::EncoderSettings::ToString() const {
33 std::stringstream ss; 41 std::stringstream ss;
34 ss << "{payload_name: " << payload_name; 42 ss << "{payload_name: " << payload_name;
35 ss << ", payload_type: " << payload_type; 43 ss << ", payload_type: " << payload_type;
36 ss << ", encoder: " << (encoder != nullptr ? "(VideoEncoder)" : "nullptr"); 44 ss << ", encoder: " << (encoder != nullptr ? "(VideoEncoder)" : "nullptr");
37 ss << '}'; 45 ss << '}';
38 return ss.str(); 46 return ss.str();
39 } 47 }
40 48
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 int channel_id, 115 int channel_id,
108 const VideoSendStream::Config& config, 116 const VideoSendStream::Config& config,
109 const VideoEncoderConfig& encoder_config, 117 const VideoEncoderConfig& encoder_config,
110 const std::map<uint32_t, RtpState>& suspended_ssrcs) 118 const std::map<uint32_t, RtpState>& suspended_ssrcs)
111 : transport_adapter_(config.send_transport), 119 : transport_adapter_(config.send_transport),
112 encoded_frame_proxy_(config.post_encode_callback), 120 encoded_frame_proxy_(config.post_encode_callback),
113 config_(config), 121 config_(config),
114 suspended_ssrcs_(suspended_ssrcs), 122 suspended_ssrcs_(suspended_ssrcs),
115 module_process_thread_(module_process_thread), 123 module_process_thread_(module_process_thread),
116 channel_group_(channel_group), 124 channel_group_(channel_group),
117 channel_id_(channel_id),
118 use_config_bitrate_(true), 125 use_config_bitrate_(true),
119 stats_proxy_(Clock::GetRealTimeClock(), config) { 126 stats_proxy_(Clock::GetRealTimeClock(), config) {
120 RTC_DCHECK(!config_.rtp.ssrcs.empty()); 127 RTC_DCHECK(!config_.rtp.ssrcs.empty());
121 RTC_CHECK(channel_group->CreateSendChannel( 128
122 channel_id_, &transport_adapter_, &stats_proxy_, 129 // Set up Call-wide sequence numbers, if configured for this send stream.
123 config.pre_encode_callback, num_cpu_cores, config_)); 130 TransportFeedbackObserver* transport_feedback_observer = nullptr;
124 vie_channel_ = channel_group_->GetChannel(channel_id_); 131 for (const RtpExtension& extension : config.rtp.extensions) {
125 vie_encoder_ = channel_group_->GetEncoder(channel_id_); 132 if (extension.name == RtpExtension::kTransportSequenceNumber) {
133 transport_feedback_observer =
134 channel_group_->GetTransportFeedbackObserver();
135 break;
136 }
137 }
138
139 const std::vector<uint32_t>& ssrcs = config.rtp.ssrcs;
140 RTC_DCHECK(!ssrcs.empty());
stefan-webrtc 2015/10/15 11:33:45 No need to DCHECK this here and on line 127.
mflodman 2015/10/15 14:39:22 Thanks, copy paste generated from channel group.
141
142 vie_encoder_.reset(new ViEEncoder(
143 channel_id, num_cpu_cores, module_process_thread_, &stats_proxy_,
144 config.pre_encode_callback, channel_group_->pacer(),
pbos-webrtc 2015/10/15 12:07:55 Do we want pacer/allocator through constructor ins
mflodman 2015/10/15 14:39:21 Kept it as is for now, since I need to leave for t
145 channel_group_->bitrate_allocator()));
146 RTC_CHECK(vie_encoder_->Init());
147
148 vie_channel_.reset(new ViEChannel(
149 num_cpu_cores, config.send_transport, module_process_thread_,
150 channel_group_->GetRtcpIntraFrameObserver(),
151 channel_group_->GetBitrateController()->CreateRtcpBandwidthObserver(),
152 transport_feedback_observer,
153 channel_group_->GetRemoteBitrateEstimator(),
154 channel_group_->GetCallStats()->rtcp_rtt_stats(), channel_group_->pacer(),
155 channel_group_->packet_router(), ssrcs.size(), true));
156 RTC_CHECK(vie_channel_->Init() == 0);
pbos-webrtc 2015/10/15 12:07:55 Can we make this one a bool while we're at it?
mflodman 2015/10/15 14:39:22 I did that change, but reverted. I'm not a big fan
157
158 vie_encoder_->StartThreadsAndSetSharedMembers(
159 vie_channel_->send_payload_router(),
160 vie_channel_->vcm_protection_callback());
161
162 std::vector<uint32_t> first_ssrc(1, ssrcs[0]);
163 vie_encoder_->SetSsrcs(first_ssrc);
stefan-webrtc 2015/10/15 11:33:45 It's not entirely clear to me why we only set the
pbos-webrtc 2015/10/15 12:07:55 Pref setting all the ssrcs, and then vie_encoder_
mflodman 2015/10/15 14:39:21 This is just copy paste, I can try to figure out a
126 164
127 for (size_t i = 0; i < config_.rtp.extensions.size(); ++i) { 165 for (size_t i = 0; i < config_.rtp.extensions.size(); ++i) {
128 const std::string& extension = config_.rtp.extensions[i].name; 166 const std::string& extension = config_.rtp.extensions[i].name;
129 int id = config_.rtp.extensions[i].id; 167 int id = config_.rtp.extensions[i].id;
130 // One-byte-extension local identifiers are in the range 1-14 inclusive. 168 // One-byte-extension local identifiers are in the range 1-14 inclusive.
131 RTC_DCHECK_GE(id, 1); 169 RTC_DCHECK_GE(id, 1);
132 RTC_DCHECK_LE(id, 14); 170 RTC_DCHECK_LE(id, 14);
133 if (extension == RtpExtension::kTOffset) { 171 if (extension == RtpExtension::kTOffset) {
134 RTC_CHECK_EQ(0, vie_channel_->SetSendTimestampOffsetStatus(true, id)); 172 RTC_CHECK_EQ(0, vie_channel_->SetSendTimestampOffsetStatus(true, id));
135 } else if (extension == RtpExtension::kAbsSendTime) { 173 } else if (extension == RtpExtension::kAbsSendTime) {
136 RTC_CHECK_EQ(0, vie_channel_->SetSendAbsoluteSendTimeStatus(true, id)); 174 RTC_CHECK_EQ(0, vie_channel_->SetSendAbsoluteSendTimeStatus(true, id));
137 } else if (extension == RtpExtension::kVideoRotation) { 175 } else if (extension == RtpExtension::kVideoRotation) {
138 RTC_CHECK_EQ(0, vie_channel_->SetSendVideoRotationStatus(true, id)); 176 RTC_CHECK_EQ(0, vie_channel_->SetSendVideoRotationStatus(true, id));
139 } else if (extension == RtpExtension::kTransportSequenceNumber) { 177 } else if (extension == RtpExtension::kTransportSequenceNumber) {
140 RTC_CHECK_EQ(0, vie_channel_->SetSendTransportSequenceNumber(true, id)); 178 RTC_CHECK_EQ(0, vie_channel_->SetSendTransportSequenceNumber(true, id));
141 } else { 179 } else {
142 RTC_NOTREACHED() << "Registering unsupported RTP extension."; 180 RTC_NOTREACHED() << "Registering unsupported RTP extension.";
143 } 181 }
144 } 182 }
145 183
146 // TODO(pbos): Consider configuring REMB in Call. 184 // TODO(pbos): Consider configuring REMB in Call.
147 channel_group_->SetChannelRembStatus(true, false, vie_channel_); 185 channel_group_->SetChannelRembStatus(true, false, vie_channel_.get());
148 186
149 // Enable NACK, FEC or both. 187 // Enable NACK, FEC or both.
150 const bool enable_protection_nack = config_.rtp.nack.rtp_history_ms > 0; 188 const bool enable_protection_nack = config_.rtp.nack.rtp_history_ms > 0;
151 const bool enable_protection_fec = config_.rtp.fec.red_payload_type != -1; 189 const bool enable_protection_fec = config_.rtp.fec.red_payload_type != -1;
152 // TODO(changbin): Should set RTX for RED mapping in RTP sender in future. 190 // TODO(changbin): Should set RTX for RED mapping in RTP sender in future.
153 vie_channel_->SetProtectionMode(enable_protection_nack, enable_protection_fec, 191 vie_channel_->SetProtectionMode(enable_protection_nack, enable_protection_fec,
154 config_.rtp.fec.red_payload_type, 192 config_.rtp.fec.red_payload_type,
155 config_.rtp.fec.ulpfec_payload_type); 193 config_.rtp.fec.ulpfec_payload_type);
156 vie_encoder_->UpdateProtectionMethod(enable_protection_nack, 194 vie_encoder_->UpdateProtectionMethod(enable_protection_nack,
157 enable_protection_fec); 195 enable_protection_fec);
158 196
159 ConfigureSsrcs(); 197 ConfigureSsrcs();
160 198
161 vie_channel_->SetRTCPCName(config_.rtp.c_name.c_str()); 199 vie_channel_->SetRTCPCName(config_.rtp.c_name.c_str());
162 200
163 input_.reset(new internal::VideoCaptureInput( 201 input_.reset(new internal::VideoCaptureInput(
164 module_process_thread_, vie_encoder_, config_.local_renderer, 202 module_process_thread_, vie_encoder_.get(), config_.local_renderer,
165 &stats_proxy_, this, config_.encoding_time_observer)); 203 &stats_proxy_, this, config_.encoding_time_observer));
166 204
167 // 28 to match packet overhead in ModuleRtpRtcpImpl. 205 // 28 to match packet overhead in ModuleRtpRtcpImpl.
168 RTC_DCHECK_LE(config_.rtp.max_packet_size, static_cast<size_t>(0xFFFF - 28)); 206 RTC_DCHECK_LE(config_.rtp.max_packet_size, static_cast<size_t>(0xFFFF - 28));
169 vie_channel_->SetMTU(static_cast<uint16_t>(config_.rtp.max_packet_size + 28)); 207 vie_channel_->SetMTU(static_cast<uint16_t>(config_.rtp.max_packet_size + 28));
170 208
171 RTC_DCHECK(config.encoder_settings.encoder != nullptr); 209 RTC_DCHECK(config.encoder_settings.encoder != nullptr);
172 RTC_DCHECK_GE(config.encoder_settings.payload_type, 0); 210 RTC_DCHECK_GE(config.encoder_settings.payload_type, 0);
173 RTC_DCHECK_LE(config.encoder_settings.payload_type, 127); 211 RTC_DCHECK_LE(config.encoder_settings.payload_type, 127);
174 RTC_CHECK_EQ(0, vie_encoder_->RegisterExternalEncoder( 212 RTC_CHECK_EQ(0, vie_encoder_->RegisterExternalEncoder(
175 config.encoder_settings.encoder, 213 config.encoder_settings.encoder,
176 config.encoder_settings.payload_type, 214 config.encoder_settings.payload_type,
177 config.encoder_settings.internal_source)); 215 config.encoder_settings.internal_source));
178 216
179 RTC_CHECK(ReconfigureVideoEncoder(encoder_config)); 217 RTC_CHECK(ReconfigureVideoEncoder(encoder_config));
180 218
181 vie_channel_->RegisterSendSideDelayObserver(&stats_proxy_); 219 vie_channel_->RegisterSendSideDelayObserver(&stats_proxy_);
182 220
183 if (config_.post_encode_callback) 221 if (config_.post_encode_callback)
184 vie_encoder_->RegisterPostEncodeImageCallback(&encoded_frame_proxy_); 222 vie_encoder_->RegisterPostEncodeImageCallback(&encoded_frame_proxy_);
185 223
186 if (config_.suspend_below_min_bitrate) 224 if (config_.suspend_below_min_bitrate)
187 vie_encoder_->SuspendBelowMinBitrate(); 225 vie_encoder_->SuspendBelowMinBitrate();
188 226
227 channel_group_->AddEncoder(ssrcs, vie_encoder_.get());
228
189 vie_channel_->RegisterSendChannelRtcpStatisticsCallback(&stats_proxy_); 229 vie_channel_->RegisterSendChannelRtcpStatisticsCallback(&stats_proxy_);
190 vie_channel_->RegisterSendChannelRtpStatisticsCallback(&stats_proxy_); 230 vie_channel_->RegisterSendChannelRtpStatisticsCallback(&stats_proxy_);
191 vie_channel_->RegisterRtcpPacketTypeCounterObserver(&stats_proxy_); 231 vie_channel_->RegisterRtcpPacketTypeCounterObserver(&stats_proxy_);
192 vie_channel_->RegisterSendBitrateObserver(&stats_proxy_); 232 vie_channel_->RegisterSendBitrateObserver(&stats_proxy_);
193 vie_channel_->RegisterSendFrameCountObserver(&stats_proxy_); 233 vie_channel_->RegisterSendFrameCountObserver(&stats_proxy_);
194 } 234 }
195 235
196 VideoSendStream::~VideoSendStream() { 236 VideoSendStream::~VideoSendStream() {
197 vie_channel_->RegisterSendFrameCountObserver(nullptr); 237 vie_channel_->RegisterSendFrameCountObserver(nullptr);
198 vie_channel_->RegisterSendBitrateObserver(nullptr); 238 vie_channel_->RegisterSendBitrateObserver(nullptr);
199 vie_channel_->RegisterRtcpPacketTypeCounterObserver(nullptr); 239 vie_channel_->RegisterRtcpPacketTypeCounterObserver(nullptr);
200 vie_channel_->RegisterSendChannelRtpStatisticsCallback(nullptr); 240 vie_channel_->RegisterSendChannelRtpStatisticsCallback(nullptr);
201 vie_channel_->RegisterSendChannelRtcpStatisticsCallback(nullptr); 241 vie_channel_->RegisterSendChannelRtcpStatisticsCallback(nullptr);
202 242
203 // Remove capture input (thread) so that it's not running after the current 243 // Remove capture input (thread) so that it's not running after the current
204 // channel is deleted. 244 // channel is deleted.
205 input_.reset(); 245 input_.reset();
206 246
207 vie_encoder_->DeRegisterExternalEncoder( 247 vie_encoder_->DeRegisterExternalEncoder(
208 config_.encoder_settings.payload_type); 248 config_.encoder_settings.payload_type);
209 249
210 channel_group_->DeleteChannel(channel_id_); 250 channel_group_->GetCallStats()->DeregisterStatsObserver(
251 vie_channel_->GetStatsObserver());
252 channel_group_->SetChannelRembStatus(false, false, vie_channel_.get());
253
254 // Remove the feedback, stop all encoding threads and processing. This must be
255 // done before deleting the channel.
256 channel_group_->RemoveEncoder(vie_encoder_.get());
257 vie_encoder_->StopThreadsAndRemoveSharedMembers();
258
259 unsigned int remote_ssrc = 0;
pbos-webrtc 2015/10/15 12:07:55 Is this not an uint32_t?
mflodman 2015/10/15 14:39:21 Yes, should be. Copy paste from ChannelManager.
260 vie_channel_->GetRemoteSSRC(&remote_ssrc);
pbos-webrtc 2015/10/15 12:07:55 Can this fail? If so should we remove the stream z
mflodman 2015/10/15 14:39:21 No, it can't fail.
261
262 channel_group_->GetRemoteBitrateEstimator()->RemoveStream(remote_ssrc);
211 } 263 }
212 264
213 VideoCaptureInput* VideoSendStream::Input() { 265 VideoCaptureInput* VideoSendStream::Input() {
214 return input_.get(); 266 return input_.get();
215 } 267 }
216 268
217 void VideoSendStream::Start() { 269 void VideoSendStream::Start() {
218 transport_adapter_.Enable(); 270 transport_adapter_.Enable();
219 vie_encoder_->Pause(); 271 vie_encoder_->Pause();
220 if (vie_channel_->StartSend() == 0) { 272 if (vie_channel_->StartSend() == 0) {
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 vie_channel_->IsSendingFecEnabled()); 548 vie_channel_->IsSendingFecEnabled());
497 549
498 // Restart the media flow 550 // Restart the media flow
499 vie_encoder_->Restart(); 551 vie_encoder_->Restart();
500 552
501 return true; 553 return true;
502 } 554 }
503 555
504 } // namespace internal 556 } // namespace internal
505 } // namespace webrtc 557 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698