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

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: Removed header leftovers. 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
« no previous file with comments | « webrtc/video/video_send_stream.h ('k') | webrtc/video_engine/vie_channel.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
141 vie_encoder_.reset(new ViEEncoder(
142 channel_id, num_cpu_cores, module_process_thread_, &stats_proxy_,
143 config.pre_encode_callback, channel_group_->pacer(),
144 channel_group_->bitrate_allocator()));
145 RTC_CHECK(vie_encoder_->Init());
146
147 vie_channel_.reset(new ViEChannel(
148 num_cpu_cores, config.send_transport, module_process_thread_,
149 channel_group_->GetRtcpIntraFrameObserver(),
150 channel_group_->GetBitrateController()->CreateRtcpBandwidthObserver(),
151 transport_feedback_observer,
152 channel_group_->GetRemoteBitrateEstimator(),
153 channel_group_->GetCallStats()->rtcp_rtt_stats(), channel_group_->pacer(),
154 channel_group_->packet_router(), ssrcs.size(), true));
155 RTC_CHECK(vie_channel_->Init() == 0);
156
157 vie_encoder_->StartThreadsAndSetSharedMembers(
158 vie_channel_->send_payload_router(),
159 vie_channel_->vcm_protection_callback());
160
161 std::vector<uint32_t> first_ssrc(1, ssrcs[0]);
162 vie_encoder_->SetSsrcs(first_ssrc);
126 163
127 for (size_t i = 0; i < config_.rtp.extensions.size(); ++i) { 164 for (size_t i = 0; i < config_.rtp.extensions.size(); ++i) {
128 const std::string& extension = config_.rtp.extensions[i].name; 165 const std::string& extension = config_.rtp.extensions[i].name;
129 int id = config_.rtp.extensions[i].id; 166 int id = config_.rtp.extensions[i].id;
130 // One-byte-extension local identifiers are in the range 1-14 inclusive. 167 // One-byte-extension local identifiers are in the range 1-14 inclusive.
131 RTC_DCHECK_GE(id, 1); 168 RTC_DCHECK_GE(id, 1);
132 RTC_DCHECK_LE(id, 14); 169 RTC_DCHECK_LE(id, 14);
133 if (extension == RtpExtension::kTOffset) { 170 if (extension == RtpExtension::kTOffset) {
134 RTC_CHECK_EQ(0, vie_channel_->SetSendTimestampOffsetStatus(true, id)); 171 RTC_CHECK_EQ(0, vie_channel_->SetSendTimestampOffsetStatus(true, id));
135 } else if (extension == RtpExtension::kAbsSendTime) { 172 } else if (extension == RtpExtension::kAbsSendTime) {
136 RTC_CHECK_EQ(0, vie_channel_->SetSendAbsoluteSendTimeStatus(true, id)); 173 RTC_CHECK_EQ(0, vie_channel_->SetSendAbsoluteSendTimeStatus(true, id));
137 } else if (extension == RtpExtension::kVideoRotation) { 174 } else if (extension == RtpExtension::kVideoRotation) {
138 RTC_CHECK_EQ(0, vie_channel_->SetSendVideoRotationStatus(true, id)); 175 RTC_CHECK_EQ(0, vie_channel_->SetSendVideoRotationStatus(true, id));
139 } else if (extension == RtpExtension::kTransportSequenceNumber) { 176 } else if (extension == RtpExtension::kTransportSequenceNumber) {
140 RTC_CHECK_EQ(0, vie_channel_->SetSendTransportSequenceNumber(true, id)); 177 RTC_CHECK_EQ(0, vie_channel_->SetSendTransportSequenceNumber(true, id));
141 } else { 178 } else {
142 RTC_NOTREACHED() << "Registering unsupported RTP extension."; 179 RTC_NOTREACHED() << "Registering unsupported RTP extension.";
143 } 180 }
144 } 181 }
145 182
146 // TODO(pbos): Consider configuring REMB in Call. 183 // TODO(pbos): Consider configuring REMB in Call.
147 channel_group_->SetChannelRembStatus(true, false, vie_channel_); 184 channel_group_->SetChannelRembStatus(true, false, vie_channel_.get());
148 185
149 // Enable NACK, FEC or both. 186 // Enable NACK, FEC or both.
150 const bool enable_protection_nack = config_.rtp.nack.rtp_history_ms > 0; 187 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; 188 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. 189 // TODO(changbin): Should set RTX for RED mapping in RTP sender in future.
153 vie_channel_->SetProtectionMode(enable_protection_nack, enable_protection_fec, 190 vie_channel_->SetProtectionMode(enable_protection_nack, enable_protection_fec,
154 config_.rtp.fec.red_payload_type, 191 config_.rtp.fec.red_payload_type,
155 config_.rtp.fec.ulpfec_payload_type); 192 config_.rtp.fec.ulpfec_payload_type);
156 vie_encoder_->UpdateProtectionMethod(enable_protection_nack, 193 vie_encoder_->UpdateProtectionMethod(enable_protection_nack,
157 enable_protection_fec); 194 enable_protection_fec);
158 195
159 ConfigureSsrcs(); 196 ConfigureSsrcs();
160 197
161 vie_channel_->SetRTCPCName(config_.rtp.c_name.c_str()); 198 vie_channel_->SetRTCPCName(config_.rtp.c_name.c_str());
162 199
163 input_.reset(new internal::VideoCaptureInput( 200 input_.reset(new internal::VideoCaptureInput(
164 module_process_thread_, vie_encoder_, config_.local_renderer, 201 module_process_thread_, vie_encoder_.get(), config_.local_renderer,
165 &stats_proxy_, this, config_.encoding_time_observer)); 202 &stats_proxy_, this, config_.encoding_time_observer));
166 203
167 // 28 to match packet overhead in ModuleRtpRtcpImpl. 204 // 28 to match packet overhead in ModuleRtpRtcpImpl.
168 RTC_DCHECK_LE(config_.rtp.max_packet_size, static_cast<size_t>(0xFFFF - 28)); 205 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)); 206 vie_channel_->SetMTU(static_cast<uint16_t>(config_.rtp.max_packet_size + 28));
170 207
171 RTC_DCHECK(config.encoder_settings.encoder != nullptr); 208 RTC_DCHECK(config.encoder_settings.encoder != nullptr);
172 RTC_DCHECK_GE(config.encoder_settings.payload_type, 0); 209 RTC_DCHECK_GE(config.encoder_settings.payload_type, 0);
173 RTC_DCHECK_LE(config.encoder_settings.payload_type, 127); 210 RTC_DCHECK_LE(config.encoder_settings.payload_type, 127);
174 RTC_CHECK_EQ(0, vie_encoder_->RegisterExternalEncoder( 211 RTC_CHECK_EQ(0, vie_encoder_->RegisterExternalEncoder(
175 config.encoder_settings.encoder, 212 config.encoder_settings.encoder,
176 config.encoder_settings.payload_type, 213 config.encoder_settings.payload_type,
177 config.encoder_settings.internal_source)); 214 config.encoder_settings.internal_source));
178 215
179 RTC_CHECK(ReconfigureVideoEncoder(encoder_config)); 216 RTC_CHECK(ReconfigureVideoEncoder(encoder_config));
180 217
181 vie_channel_->RegisterSendSideDelayObserver(&stats_proxy_); 218 vie_channel_->RegisterSendSideDelayObserver(&stats_proxy_);
182 219
183 if (config_.post_encode_callback) 220 if (config_.post_encode_callback)
184 vie_encoder_->RegisterPostEncodeImageCallback(&encoded_frame_proxy_); 221 vie_encoder_->RegisterPostEncodeImageCallback(&encoded_frame_proxy_);
185 222
186 if (config_.suspend_below_min_bitrate) 223 if (config_.suspend_below_min_bitrate)
187 vie_encoder_->SuspendBelowMinBitrate(); 224 vie_encoder_->SuspendBelowMinBitrate();
188 225
226 channel_group_->AddEncoder(ssrcs, vie_encoder_.get());
227
189 vie_channel_->RegisterSendChannelRtcpStatisticsCallback(&stats_proxy_); 228 vie_channel_->RegisterSendChannelRtcpStatisticsCallback(&stats_proxy_);
190 vie_channel_->RegisterSendChannelRtpStatisticsCallback(&stats_proxy_); 229 vie_channel_->RegisterSendChannelRtpStatisticsCallback(&stats_proxy_);
191 vie_channel_->RegisterRtcpPacketTypeCounterObserver(&stats_proxy_); 230 vie_channel_->RegisterRtcpPacketTypeCounterObserver(&stats_proxy_);
192 vie_channel_->RegisterSendBitrateObserver(&stats_proxy_); 231 vie_channel_->RegisterSendBitrateObserver(&stats_proxy_);
193 vie_channel_->RegisterSendFrameCountObserver(&stats_proxy_); 232 vie_channel_->RegisterSendFrameCountObserver(&stats_proxy_);
194 } 233 }
195 234
196 VideoSendStream::~VideoSendStream() { 235 VideoSendStream::~VideoSendStream() {
197 vie_channel_->RegisterSendFrameCountObserver(nullptr); 236 vie_channel_->RegisterSendFrameCountObserver(nullptr);
198 vie_channel_->RegisterSendBitrateObserver(nullptr); 237 vie_channel_->RegisterSendBitrateObserver(nullptr);
199 vie_channel_->RegisterRtcpPacketTypeCounterObserver(nullptr); 238 vie_channel_->RegisterRtcpPacketTypeCounterObserver(nullptr);
200 vie_channel_->RegisterSendChannelRtpStatisticsCallback(nullptr); 239 vie_channel_->RegisterSendChannelRtpStatisticsCallback(nullptr);
201 vie_channel_->RegisterSendChannelRtcpStatisticsCallback(nullptr); 240 vie_channel_->RegisterSendChannelRtcpStatisticsCallback(nullptr);
202 241
203 // Remove capture input (thread) so that it's not running after the current 242 // Remove capture input (thread) so that it's not running after the current
204 // channel is deleted. 243 // channel is deleted.
205 input_.reset(); 244 input_.reset();
206 245
207 vie_encoder_->DeRegisterExternalEncoder( 246 vie_encoder_->DeRegisterExternalEncoder(
208 config_.encoder_settings.payload_type); 247 config_.encoder_settings.payload_type);
209 248
210 channel_group_->DeleteChannel(channel_id_); 249 channel_group_->GetCallStats()->DeregisterStatsObserver(
250 vie_channel_->GetStatsObserver());
251 channel_group_->SetChannelRembStatus(false, false, vie_channel_.get());
252
253 // Remove the feedback, stop all encoding threads and processing. This must be
254 // done before deleting the channel.
255 channel_group_->RemoveEncoder(vie_encoder_.get());
256 vie_encoder_->StopThreadsAndRemoveSharedMembers();
257
258 uint32_t remote_ssrc = vie_channel_->GetRemoteSSRC();
259 channel_group_->GetRemoteBitrateEstimator()->RemoveStream(remote_ssrc);
211 } 260 }
212 261
213 VideoCaptureInput* VideoSendStream::Input() { 262 VideoCaptureInput* VideoSendStream::Input() {
214 return input_.get(); 263 return input_.get();
215 } 264 }
216 265
217 void VideoSendStream::Start() { 266 void VideoSendStream::Start() {
218 transport_adapter_.Enable(); 267 transport_adapter_.Enable();
219 vie_encoder_->Pause(); 268 vie_encoder_->Pause();
220 if (vie_channel_->StartSend() == 0) { 269 if (vie_channel_->StartSend() == 0) {
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 vie_channel_->IsSendingFecEnabled()); 545 vie_channel_->IsSendingFecEnabled());
497 546
498 // Restart the media flow 547 // Restart the media flow
499 vie_encoder_->Restart(); 548 vie_encoder_->Restart();
500 549
501 return true; 550 return true;
502 } 551 }
503 552
504 } // namespace internal 553 } // namespace internal
505 } // namespace webrtc 554 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/video_send_stream.h ('k') | webrtc/video_engine/vie_channel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698