OLD | NEW |
---|---|
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_receive_stream.h" | 11 #include "webrtc/video/video_receive_stream.h" |
12 | 12 |
13 #include <stdlib.h> | 13 #include <stdlib.h> |
14 | 14 |
15 #include <string> | 15 #include <string> |
16 | 16 |
17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
18 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 18 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
19 #include "webrtc/system_wrappers/interface/clock.h" | 19 #include "webrtc/system_wrappers/interface/clock.h" |
20 #include "webrtc/system_wrappers/interface/logging.h" | 20 #include "webrtc/system_wrappers/interface/logging.h" |
21 #include "webrtc/video/receive_statistics_proxy.h" | 21 #include "webrtc/video/receive_statistics_proxy.h" |
22 #include "webrtc/video_encoder.h" | 22 #include "webrtc/video_encoder.h" |
23 #include "webrtc/video_engine/call_stats.h" | |
23 #include "webrtc/video_receive_stream.h" | 24 #include "webrtc/video_receive_stream.h" |
24 | 25 |
25 namespace webrtc { | 26 namespace webrtc { |
27 | |
28 static bool UseSendSideBwe(const std::vector<RtpExtension>& extensions) { | |
29 for (const auto& extension : extensions) { | |
30 if (extension.name == RtpExtension::kTransportSequenceNumber) | |
31 return true; | |
32 } | |
33 return false; | |
34 } | |
35 | |
26 std::string VideoReceiveStream::Decoder::ToString() const { | 36 std::string VideoReceiveStream::Decoder::ToString() const { |
27 std::stringstream ss; | 37 std::stringstream ss; |
28 ss << "{decoder: " << (decoder != nullptr ? "(VideoDecoder)" : "nullptr"); | 38 ss << "{decoder: " << (decoder != nullptr ? "(VideoDecoder)" : "nullptr"); |
29 ss << ", payload_type: " << payload_type; | 39 ss << ", payload_type: " << payload_type; |
30 ss << ", payload_name: " << payload_name; | 40 ss << ", payload_name: " << payload_name; |
31 ss << ", is_renderer: " << (is_renderer ? "yes" : "no"); | 41 ss << ", is_renderer: " << (is_renderer ? "yes" : "no"); |
32 ss << ", expected_delay_ms: " << expected_delay_ms; | 42 ss << ", expected_delay_ms: " << expected_delay_ms; |
33 ss << '}'; | 43 ss << '}'; |
34 | 44 |
35 return ss.str(); | 45 return ss.str(); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 Call::Config::kDefaultStartBitrateBps / 1000; | 135 Call::Config::kDefaultStartBitrateBps / 1000; |
126 | 136 |
127 return codec; | 137 return codec; |
128 } | 138 } |
129 } // namespace | 139 } // namespace |
130 | 140 |
131 VideoReceiveStream::VideoReceiveStream(int num_cpu_cores, | 141 VideoReceiveStream::VideoReceiveStream(int num_cpu_cores, |
132 ChannelGroup* channel_group, | 142 ChannelGroup* channel_group, |
133 int channel_id, | 143 int channel_id, |
134 const VideoReceiveStream::Config& config, | 144 const VideoReceiveStream::Config& config, |
135 webrtc::VoiceEngine* voice_engine) | 145 webrtc::VoiceEngine* voice_engine, |
146 ProcessThread* process_thread) | |
136 : transport_adapter_(config.rtcp_send_transport), | 147 : transport_adapter_(config.rtcp_send_transport), |
137 encoded_frame_proxy_(config.pre_decode_callback), | 148 encoded_frame_proxy_(config.pre_decode_callback), |
138 config_(config), | 149 config_(config), |
139 clock_(Clock::GetRealTimeClock()), | 150 clock_(Clock::GetRealTimeClock()), |
140 channel_group_(channel_group), | 151 channel_group_(channel_group) { |
141 channel_id_(channel_id) { | |
142 LOG(LS_INFO) << "VideoReceiveStream: " << config_.ToString(); | 152 LOG(LS_INFO) << "VideoReceiveStream: " << config_.ToString(); |
143 RTC_CHECK(channel_group_->CreateReceiveChannel( | |
144 channel_id_, &transport_adapter_, num_cpu_cores, config)); | |
145 | 153 |
146 vie_channel_ = channel_group_->GetChannel(channel_id_); | 154 bool send_side_bwe = UseSendSideBwe(config_.rtp.extensions); |
155 | |
156 RemoteBitrateEstimator* bitrate_estimator = | |
157 channel_group_->GetRemoteBitrateEstimator(send_side_bwe); | |
158 | |
159 vie_channel_.reset(new ViEChannel( | |
160 num_cpu_cores, &transport_adapter_, process_thread, | |
161 channel_group_->GetRtcpIntraFrameObserver(), | |
162 channel_group_->GetBitrateController()->CreateRtcpBandwidthObserver(), | |
163 nullptr, bitrate_estimator, | |
164 channel_group_->GetCallStats()->rtcp_rtt_stats(), channel_group_->pacer(), | |
165 channel_group_->packet_router(), 1, false)); | |
166 | |
167 RTC_CHECK(vie_channel_->Init() == 0); | |
168 | |
169 // Register the channel to receive stats updates. | |
170 channel_group_->GetCallStats()->RegisterStatsObserver( | |
171 vie_channel_->GetStatsObserver()); | |
172 | |
147 | 173 |
148 // TODO(pbos): This is not fine grained enough... | 174 // TODO(pbos): This is not fine grained enough... |
149 vie_channel_->SetProtectionMode(config_.rtp.nack.rtp_history_ms > 0, false, | 175 vie_channel_->SetProtectionMode(config_.rtp.nack.rtp_history_ms > 0, false, |
150 -1, -1); | 176 -1, -1); |
151 RTC_DCHECK(config_.rtp.rtcp_mode != RtcpMode::kOff) | 177 RTC_DCHECK(config_.rtp.rtcp_mode != RtcpMode::kOff) |
152 << "A stream should not be configured with RTCP disabled. This value is " | 178 << "A stream should not be configured with RTCP disabled. This value is " |
153 "reserved for internal usage."; | 179 "reserved for internal usage."; |
154 vie_channel_->SetRTCPMode(config_.rtp.rtcp_mode); | 180 vie_channel_->SetRTCPMode(config_.rtp.rtcp_mode); |
155 | 181 |
156 RTC_DCHECK(config_.rtp.remote_ssrc != 0); | 182 RTC_DCHECK(config_.rtp.remote_ssrc != 0); |
(...skipping 11 matching lines...) Expand all Loading... | |
168 vie_channel_->SetRemoteSSRCType(kViEStreamTypeRtx, it->second.ssrc); | 194 vie_channel_->SetRemoteSSRCType(kViEStreamTypeRtx, it->second.ssrc); |
169 vie_channel_->SetRtxReceivePayloadType(it->second.payload_type, it->first); | 195 vie_channel_->SetRtxReceivePayloadType(it->second.payload_type, it->first); |
170 } | 196 } |
171 // TODO(holmer): When Chrome no longer depends on this being false by default, | 197 // TODO(holmer): When Chrome no longer depends on this being false by default, |
172 // always use the mapping and remove this whole codepath. | 198 // always use the mapping and remove this whole codepath. |
173 vie_channel_->SetUseRtxPayloadMappingOnRestore( | 199 vie_channel_->SetUseRtxPayloadMappingOnRestore( |
174 config_.rtp.use_rtx_payload_mapping_on_restore); | 200 config_.rtp.use_rtx_payload_mapping_on_restore); |
175 | 201 |
176 // TODO(pbos): Remove channel_group_ usage from VideoReceiveStream. This | 202 // TODO(pbos): Remove channel_group_ usage from VideoReceiveStream. This |
177 // should be configured in call.cc. | 203 // should be configured in call.cc. |
178 channel_group_->SetChannelRembStatus(false, config_.rtp.remb, vie_channel_); | 204 channel_group_->SetChannelRembStatus(false, config_.rtp.remb, |
205 vie_channel_.get()); | |
179 | 206 |
180 for (size_t i = 0; i < config_.rtp.extensions.size(); ++i) { | 207 for (size_t i = 0; i < config_.rtp.extensions.size(); ++i) { |
181 const std::string& extension = config_.rtp.extensions[i].name; | 208 const std::string& extension = config_.rtp.extensions[i].name; |
182 int id = config_.rtp.extensions[i].id; | 209 int id = config_.rtp.extensions[i].id; |
183 // One-byte-extension local identifiers are in the range 1-14 inclusive. | 210 // One-byte-extension local identifiers are in the range 1-14 inclusive. |
184 RTC_DCHECK_GE(id, 1); | 211 RTC_DCHECK_GE(id, 1); |
185 RTC_DCHECK_LE(id, 14); | 212 RTC_DCHECK_LE(id, 14); |
186 if (extension == RtpExtension::kTOffset) { | 213 if (extension == RtpExtension::kTOffset) { |
187 RTC_CHECK_EQ(0, vie_channel_->SetReceiveTimestampOffsetStatus(true, id)); | 214 RTC_CHECK_EQ(0, vie_channel_->SetReceiveTimestampOffsetStatus(true, id)); |
188 } else if (extension == RtpExtension::kAbsSendTime) { | 215 } else if (extension == RtpExtension::kAbsSendTime) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 | 286 |
260 VideoReceiveStream::~VideoReceiveStream() { | 287 VideoReceiveStream::~VideoReceiveStream() { |
261 LOG(LS_INFO) << "~VideoReceiveStream: " << config_.ToString(); | 288 LOG(LS_INFO) << "~VideoReceiveStream: " << config_.ToString(); |
262 incoming_video_stream_->Stop(); | 289 incoming_video_stream_->Stop(); |
263 vie_channel_->RegisterPreRenderCallback(nullptr); | 290 vie_channel_->RegisterPreRenderCallback(nullptr); |
264 vie_channel_->RegisterPreDecodeImageCallback(nullptr); | 291 vie_channel_->RegisterPreDecodeImageCallback(nullptr); |
265 | 292 |
266 for (size_t i = 0; i < config_.decoders.size(); ++i) | 293 for (size_t i = 0; i < config_.decoders.size(); ++i) |
267 vie_channel_->DeRegisterExternalDecoder(config_.decoders[i].payload_type); | 294 vie_channel_->DeRegisterExternalDecoder(config_.decoders[i].payload_type); |
268 | 295 |
269 channel_group_->DeleteChannel(channel_id_); | 296 channel_group_->GetCallStats()->DeregisterStatsObserver( |
297 vie_channel_->GetStatsObserver()); | |
298 channel_group_->SetChannelRembStatus(false, false, vie_channel_.get()); | |
299 | |
300 uint32_t remote_ssrc = vie_channel_->GetRemoteSSRC(); | |
301 bool send_side_bwe = UseSendSideBwe(config_.rtp.extensions); | |
302 channel_group_->GetRemoteBitrateEstimator(send_side_bwe)->RemoveStream( | |
303 remote_ssrc); | |
304 // This must be deleted before ReceiveStatisticsProxy, due to callbacks. | |
pbos-webrtc
2015/10/16 12:49:57
Shouldn't ReceiveStatisticsProxy be declared befor
mflodman
2015/10/16 13:31:57
Done.
| |
305 vie_channel_.reset(); | |
270 } | 306 } |
271 | 307 |
272 void VideoReceiveStream::Start() { | 308 void VideoReceiveStream::Start() { |
273 transport_adapter_.Enable(); | 309 transport_adapter_.Enable(); |
274 incoming_video_stream_->Start(); | 310 incoming_video_stream_->Start(); |
275 vie_channel_->StartReceive(); | 311 vie_channel_->StartReceive(); |
276 } | 312 } |
277 | 313 |
278 void VideoReceiveStream::Stop() { | 314 void VideoReceiveStream::Stop() { |
279 incoming_video_stream_->Stop(); | 315 incoming_video_stream_->Stop(); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 return 0; | 368 return 0; |
333 } | 369 } |
334 | 370 |
335 void VideoReceiveStream::SignalNetworkState(NetworkState state) { | 371 void VideoReceiveStream::SignalNetworkState(NetworkState state) { |
336 vie_channel_->SetRTCPMode(state == kNetworkUp ? config_.rtp.rtcp_mode | 372 vie_channel_->SetRTCPMode(state == kNetworkUp ? config_.rtp.rtcp_mode |
337 : RtcpMode::kOff); | 373 : RtcpMode::kOff); |
338 } | 374 } |
339 | 375 |
340 } // namespace internal | 376 } // namespace internal |
341 } // namespace webrtc | 377 } // namespace webrtc |
OLD | NEW |