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 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 config_(config), | 153 config_(config), |
154 process_thread_(process_thread), | 154 process_thread_(process_thread), |
155 clock_(Clock::GetRealTimeClock()), | 155 clock_(Clock::GetRealTimeClock()), |
156 congestion_controller_(congestion_controller), | 156 congestion_controller_(congestion_controller), |
157 call_stats_(call_stats), | 157 call_stats_(call_stats), |
158 vcm_(VideoCodingModule::Create(clock_, nullptr, nullptr)), | 158 vcm_(VideoCodingModule::Create(clock_, nullptr, nullptr)), |
159 incoming_video_stream_( | 159 incoming_video_stream_( |
160 0, | 160 0, |
161 config.renderer ? config.renderer->SmoothsRenderedFrames() : false), | 161 config.renderer ? config.renderer->SmoothsRenderedFrames() : false), |
162 stats_proxy_(config_.rtp.remote_ssrc, clock_), | 162 stats_proxy_(config_.rtp.remote_ssrc, clock_), |
163 vie_channel_(num_cpu_cores, | 163 vie_channel_(&transport_adapter_, |
164 &transport_adapter_, | |
165 process_thread, | 164 process_thread, |
166 nullptr, | 165 nullptr, |
167 vcm_.get(), | 166 vcm_.get(), |
168 nullptr, | 167 nullptr, |
169 nullptr, | 168 nullptr, |
170 nullptr, | 169 nullptr, |
171 congestion_controller_->GetRemoteBitrateEstimator( | 170 congestion_controller_->GetRemoteBitrateEstimator( |
172 UseSendSideBwe(config_)), | 171 UseSendSideBwe(config_)), |
173 call_stats_->rtcp_rtt_stats(), | 172 call_stats_->rtcp_rtt_stats(), |
174 congestion_controller_->pacer(), | 173 congestion_controller_->pacer(), |
175 congestion_controller_->packet_router(), | 174 congestion_controller_->packet_router(), |
176 1, | 175 1, |
177 false) { | 176 false), |
| 177 vie_receiver_(vie_channel_.vie_receiver()), |
| 178 rtp_rtcp_(vie_channel_.rtp_rtcp()) { |
178 LOG(LS_INFO) << "VideoReceiveStream: " << config_.ToString(); | 179 LOG(LS_INFO) << "VideoReceiveStream: " << config_.ToString(); |
179 | 180 |
180 RTC_CHECK(vie_channel_.Init() == 0); | 181 RTC_CHECK(vie_channel_.Init() == 0); |
181 | 182 |
182 // Register the channel to receive stats updates. | 183 // Register the channel to receive stats updates. |
183 call_stats_->RegisterStatsObserver(vie_channel_.GetStatsObserver()); | 184 call_stats_->RegisterStatsObserver(vie_channel_.GetStatsObserver()); |
184 | 185 |
185 // TODO(pbos): This is not fine grained enough... | 186 // TODO(pbos): This is not fine grained enough... |
186 vie_channel_.SetProtectionMode(config_.rtp.nack.rtp_history_ms > 0, false, | 187 vie_channel_.SetProtectionMode(config_.rtp.nack.rtp_history_ms > 0, false, -1, |
187 -1, -1); | 188 -1); |
188 RTC_DCHECK(config_.rtp.rtcp_mode != RtcpMode::kOff) | 189 RTC_DCHECK(config_.rtp.rtcp_mode != RtcpMode::kOff) |
189 << "A stream should not be configured with RTCP disabled. This value is " | 190 << "A stream should not be configured with RTCP disabled. This value is " |
190 "reserved for internal usage."; | 191 "reserved for internal usage."; |
191 vie_channel_.SetRTCPMode(config_.rtp.rtcp_mode); | 192 rtp_rtcp_->SetRTCPStatus(config_.rtp.rtcp_mode); |
192 | 193 |
193 RTC_DCHECK(config_.rtp.remote_ssrc != 0); | 194 RTC_DCHECK(config_.rtp.remote_ssrc != 0); |
194 // TODO(pbos): What's an appropriate local_ssrc for receive-only streams? | 195 // TODO(pbos): What's an appropriate local_ssrc for receive-only streams? |
195 RTC_DCHECK(config_.rtp.local_ssrc != 0); | 196 RTC_DCHECK(config_.rtp.local_ssrc != 0); |
196 RTC_DCHECK(config_.rtp.remote_ssrc != config_.rtp.local_ssrc); | 197 RTC_DCHECK(config_.rtp.remote_ssrc != config_.rtp.local_ssrc); |
| 198 rtp_rtcp_->SetSSRC(config_.rtp.local_ssrc); |
197 | 199 |
198 vie_channel_.SetSSRC(config_.rtp.local_ssrc, kViEStreamTypeNormal, 0); | |
199 // TODO(pbos): Support multiple RTX, per video payload. | 200 // TODO(pbos): Support multiple RTX, per video payload. |
200 Config::Rtp::RtxMap::const_iterator it = config_.rtp.rtx.begin(); | 201 for (const auto& kv : config_.rtp.rtx) { |
201 for (; it != config_.rtp.rtx.end(); ++it) { | 202 RTC_DCHECK(kv.second.ssrc != 0); |
202 RTC_DCHECK(it->second.ssrc != 0); | 203 RTC_DCHECK(kv.second.payload_type != 0); |
203 RTC_DCHECK(it->second.payload_type != 0); | |
204 | 204 |
205 vie_channel_.SetRemoteSSRCType(kViEStreamTypeRtx, it->second.ssrc); | 205 vie_receiver_->SetRtxSsrc(kv.second.ssrc); |
206 vie_channel_.SetRtxReceivePayloadType(it->second.payload_type, it->first); | 206 vie_receiver_->SetRtxPayloadType(kv.second.payload_type, kv.first); |
207 } | 207 } |
208 // TODO(holmer): When Chrome no longer depends on this being false by default, | 208 // TODO(holmer): When Chrome no longer depends on this being false by default, |
209 // always use the mapping and remove this whole codepath. | 209 // always use the mapping and remove this whole codepath. |
210 vie_channel_.SetUseRtxPayloadMappingOnRestore( | 210 vie_receiver_->SetUseRtxPayloadMappingOnRestore( |
211 config_.rtp.use_rtx_payload_mapping_on_restore); | 211 config_.rtp.use_rtx_payload_mapping_on_restore); |
212 | 212 |
213 congestion_controller_->SetChannelRembStatus(false, config_.rtp.remb, | 213 congestion_controller_->SetChannelRembStatus(false, config_.rtp.remb, |
214 vie_channel_.rtp_rtcp()); | 214 rtp_rtcp_); |
215 | 215 |
216 for (size_t i = 0; i < config_.rtp.extensions.size(); ++i) { | 216 for (size_t i = 0; i < config_.rtp.extensions.size(); ++i) { |
217 const std::string& extension = config_.rtp.extensions[i].name; | 217 const std::string& extension = config_.rtp.extensions[i].name; |
218 int id = config_.rtp.extensions[i].id; | 218 int id = config_.rtp.extensions[i].id; |
219 // One-byte-extension local identifiers are in the range 1-14 inclusive. | 219 // One-byte-extension local identifiers are in the range 1-14 inclusive. |
220 RTC_DCHECK_GE(id, 1); | 220 RTC_DCHECK_GE(id, 1); |
221 RTC_DCHECK_LE(id, 14); | 221 RTC_DCHECK_LE(id, 14); |
222 if (extension == RtpExtension::kTOffset) { | 222 if (extension == RtpExtension::kTOffset) { |
223 RTC_CHECK_EQ(0, vie_channel_.SetReceiveTimestampOffsetStatus(true, id)); | 223 RTC_CHECK(vie_receiver_->SetReceiveTimestampOffsetStatus(true, id)); |
224 } else if (extension == RtpExtension::kAbsSendTime) { | 224 } else if (extension == RtpExtension::kAbsSendTime) { |
225 RTC_CHECK_EQ(0, vie_channel_.SetReceiveAbsoluteSendTimeStatus(true, id)); | 225 RTC_CHECK(vie_receiver_->SetReceiveAbsoluteSendTimeStatus(true, id)); |
226 } else if (extension == RtpExtension::kVideoRotation) { | 226 } else if (extension == RtpExtension::kVideoRotation) { |
227 RTC_CHECK_EQ(0, vie_channel_.SetReceiveVideoRotationStatus(true, id)); | 227 RTC_CHECK(vie_receiver_->SetReceiveVideoRotationStatus(true, id)); |
228 } else if (extension == RtpExtension::kTransportSequenceNumber) { | 228 } else if (extension == RtpExtension::kTransportSequenceNumber) { |
229 RTC_CHECK_EQ(0, | 229 RTC_CHECK(vie_receiver_->SetReceiveTransportSequenceNumber(true, id)); |
230 vie_channel_.SetReceiveTransportSequenceNumber(true, id)); | |
231 } else { | 230 } else { |
232 RTC_NOTREACHED() << "Unsupported RTP extension."; | 231 RTC_NOTREACHED() << "Unsupported RTP extension."; |
233 } | 232 } |
234 } | 233 } |
235 | 234 |
236 if (config_.rtp.fec.ulpfec_payload_type != -1) { | 235 if (config_.rtp.fec.ulpfec_payload_type != -1) { |
237 // ULPFEC without RED doesn't make sense. | 236 // ULPFEC without RED doesn't make sense. |
238 RTC_DCHECK(config_.rtp.fec.red_payload_type != -1); | 237 RTC_DCHECK(config_.rtp.fec.red_payload_type != -1); |
239 VideoCodec codec; | 238 VideoCodec codec; |
240 memset(&codec, 0, sizeof(codec)); | 239 memset(&codec, 0, sizeof(codec)); |
241 codec.codecType = kVideoCodecULPFEC; | 240 codec.codecType = kVideoCodecULPFEC; |
242 strncpy(codec.plName, "ulpfec", sizeof(codec.plName)); | 241 strncpy(codec.plName, "ulpfec", sizeof(codec.plName)); |
243 codec.plType = config_.rtp.fec.ulpfec_payload_type; | 242 codec.plType = config_.rtp.fec.ulpfec_payload_type; |
244 RTC_CHECK_EQ(0, vie_channel_.SetReceiveCodec(codec)); | 243 RTC_CHECK(vie_receiver_->SetReceiveCodec(codec)); |
245 } | 244 } |
246 if (config_.rtp.fec.red_payload_type != -1) { | 245 if (config_.rtp.fec.red_payload_type != -1) { |
247 VideoCodec codec; | 246 VideoCodec codec; |
248 memset(&codec, 0, sizeof(codec)); | 247 memset(&codec, 0, sizeof(codec)); |
249 codec.codecType = kVideoCodecRED; | 248 codec.codecType = kVideoCodecRED; |
250 strncpy(codec.plName, "red", sizeof(codec.plName)); | 249 strncpy(codec.plName, "red", sizeof(codec.plName)); |
251 codec.plType = config_.rtp.fec.red_payload_type; | 250 codec.plType = config_.rtp.fec.red_payload_type; |
252 RTC_CHECK_EQ(0, vie_channel_.SetReceiveCodec(codec)); | 251 RTC_CHECK(vie_receiver_->SetReceiveCodec(codec)); |
253 if (config_.rtp.fec.red_rtx_payload_type != -1) { | 252 if (config_.rtp.fec.red_rtx_payload_type != -1) { |
254 vie_channel_.SetRtxReceivePayloadType( | 253 vie_receiver_->SetRtxPayloadType(config_.rtp.fec.red_rtx_payload_type, |
255 config_.rtp.fec.red_rtx_payload_type, | 254 config_.rtp.fec.red_payload_type); |
256 config_.rtp.fec.red_payload_type); | |
257 } | 255 } |
258 } | 256 } |
259 | 257 |
260 if (config.rtp.rtcp_xr.receiver_reference_time_report) | 258 if (config.rtp.rtcp_xr.receiver_reference_time_report) |
261 vie_channel_.SetRtcpXrRrtrStatus(true); | 259 rtp_rtcp_->SetRtcpXrRrtrStatus(true); |
262 | 260 |
263 vie_channel_.RegisterReceiveStatisticsProxy(&stats_proxy_); | 261 vie_channel_.RegisterReceiveStatisticsProxy(&stats_proxy_); |
264 vie_channel_.RegisterReceiveChannelRtcpStatisticsCallback(&stats_proxy_); | 262 vie_receiver_->GetReceiveStatistics()->RegisterRtpStatisticsCallback( |
265 vie_channel_.RegisterReceiveChannelRtpStatisticsCallback(&stats_proxy_); | 263 &stats_proxy_); |
| 264 vie_receiver_->GetReceiveStatistics()->RegisterRtcpStatisticsCallback( |
| 265 &stats_proxy_); |
| 266 // Stats callback for CNAME changes. |
| 267 rtp_rtcp_->RegisterRtcpStatisticsCallback(&stats_proxy_); |
266 vie_channel_.RegisterRtcpPacketTypeCounterObserver(&stats_proxy_); | 268 vie_channel_.RegisterRtcpPacketTypeCounterObserver(&stats_proxy_); |
267 | 269 |
268 RTC_DCHECK(!config_.decoders.empty()); | 270 RTC_DCHECK(!config_.decoders.empty()); |
269 std::set<int> decoder_payload_types; | 271 std::set<int> decoder_payload_types; |
270 for (size_t i = 0; i < config_.decoders.size(); ++i) { | 272 for (size_t i = 0; i < config_.decoders.size(); ++i) { |
271 const Decoder& decoder = config_.decoders[i]; | 273 const Decoder& decoder = config_.decoders[i]; |
272 RTC_CHECK(decoder.decoder); | 274 RTC_CHECK(decoder.decoder); |
273 RTC_CHECK(decoder_payload_types.find(decoder.payload_type) == | 275 RTC_CHECK(decoder_payload_types.find(decoder.payload_type) == |
274 decoder_payload_types.end()) | 276 decoder_payload_types.end()) |
275 << "Duplicate payload type (" << decoder.payload_type | 277 << "Duplicate payload type (" << decoder.payload_type |
276 << ") for different decoders."; | 278 << ") for different decoders."; |
277 decoder_payload_types.insert(decoder.payload_type); | 279 decoder_payload_types.insert(decoder.payload_type); |
278 vie_channel_.RegisterExternalDecoder(decoder.payload_type, | 280 vcm_->RegisterExternalDecoder(decoder.decoder, decoder.payload_type); |
279 decoder.decoder); | |
280 | 281 |
281 VideoCodec codec = CreateDecoderVideoCodec(decoder); | 282 VideoCodec codec = CreateDecoderVideoCodec(decoder); |
282 | 283 |
283 RTC_CHECK_EQ(0, vie_channel_.SetReceiveCodec(codec)); | 284 RTC_CHECK(vie_receiver_->SetReceiveCodec(codec)); |
| 285 RTC_CHECK_EQ(VCM_OK, |
| 286 vcm_->RegisterReceiveCodec(&codec, num_cpu_cores, false)); |
284 } | 287 } |
285 | 288 |
| 289 vcm_->SetRenderDelay(config.render_delay_ms); |
286 incoming_video_stream_.SetExpectedRenderDelay(config.render_delay_ms); | 290 incoming_video_stream_.SetExpectedRenderDelay(config.render_delay_ms); |
287 vie_channel_.SetExpectedRenderDelay(config.render_delay_ms); | 291 vcm_->RegisterPreDecodeImageCallback(this); |
288 incoming_video_stream_.SetExternalCallback(this); | 292 incoming_video_stream_.SetExternalCallback(this); |
289 vie_channel_.SetIncomingVideoStream(&incoming_video_stream_); | 293 vie_channel_.SetIncomingVideoStream(&incoming_video_stream_); |
290 | |
291 vie_channel_.RegisterPreDecodeImageCallback(this); | |
292 vie_channel_.RegisterPreRenderCallback(this); | 294 vie_channel_.RegisterPreRenderCallback(this); |
293 | 295 |
294 process_thread_->RegisterModule(vcm_.get()); | 296 process_thread_->RegisterModule(vcm_.get()); |
295 } | 297 } |
296 | 298 |
297 VideoReceiveStream::~VideoReceiveStream() { | 299 VideoReceiveStream::~VideoReceiveStream() { |
298 LOG(LS_INFO) << "~VideoReceiveStream: " << config_.ToString(); | 300 LOG(LS_INFO) << "~VideoReceiveStream: " << config_.ToString(); |
299 incoming_video_stream_.Stop(); | 301 incoming_video_stream_.Stop(); |
300 process_thread_->DeRegisterModule(vcm_.get()); | 302 process_thread_->DeRegisterModule(vcm_.get()); |
301 vie_channel_.RegisterPreRenderCallback(nullptr); | 303 vie_channel_.RegisterPreRenderCallback(nullptr); |
302 vie_channel_.RegisterPreDecodeImageCallback(nullptr); | 304 vcm_->RegisterPreDecodeImageCallback(nullptr); |
303 | 305 |
304 call_stats_->DeregisterStatsObserver(vie_channel_.GetStatsObserver()); | 306 call_stats_->DeregisterStatsObserver(vie_channel_.GetStatsObserver()); |
305 congestion_controller_->SetChannelRembStatus(false, false, | 307 congestion_controller_->SetChannelRembStatus(false, false, rtp_rtcp_); |
306 vie_channel_.rtp_rtcp()); | |
307 | 308 |
308 uint32_t remote_ssrc = vie_channel_.GetRemoteSSRC(); | |
309 congestion_controller_->GetRemoteBitrateEstimator(UseSendSideBwe(config_)) | 309 congestion_controller_->GetRemoteBitrateEstimator(UseSendSideBwe(config_)) |
310 ->RemoveStream(remote_ssrc); | 310 ->RemoveStream(vie_receiver_->GetRemoteSsrc()); |
311 } | 311 } |
312 | 312 |
313 void VideoReceiveStream::Start() { | 313 void VideoReceiveStream::Start() { |
314 transport_adapter_.Enable(); | 314 transport_adapter_.Enable(); |
315 incoming_video_stream_.Start(); | 315 incoming_video_stream_.Start(); |
316 vie_channel_.StartReceive(); | 316 vie_channel_.StartReceive(); |
317 } | 317 } |
318 | 318 |
319 void VideoReceiveStream::Stop() { | 319 void VideoReceiveStream::Stop() { |
320 incoming_video_stream_.Stop(); | 320 incoming_video_stream_.Stop(); |
(...skipping 10 matching lines...) Expand all Loading... |
331 } else { | 331 } else { |
332 vie_channel_.SetVoiceChannel(-1, nullptr); | 332 vie_channel_.SetVoiceChannel(-1, nullptr); |
333 } | 333 } |
334 } | 334 } |
335 | 335 |
336 VideoReceiveStream::Stats VideoReceiveStream::GetStats() const { | 336 VideoReceiveStream::Stats VideoReceiveStream::GetStats() const { |
337 return stats_proxy_.GetStats(); | 337 return stats_proxy_.GetStats(); |
338 } | 338 } |
339 | 339 |
340 bool VideoReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { | 340 bool VideoReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { |
341 return vie_channel_.ReceivedRTCPPacket(packet, length) == 0; | 341 return vie_receiver_->DeliverRtcp(packet, length); |
342 } | 342 } |
343 | 343 |
344 bool VideoReceiveStream::DeliverRtp(const uint8_t* packet, | 344 bool VideoReceiveStream::DeliverRtp(const uint8_t* packet, |
345 size_t length, | 345 size_t length, |
346 const PacketTime& packet_time) { | 346 const PacketTime& packet_time) { |
347 return vie_channel_.ReceivedRTPPacket(packet, length, packet_time) == 0; | 347 return vie_receiver_->DeliverRtp(packet, length, packet_time); |
348 } | 348 } |
349 | 349 |
350 void VideoReceiveStream::FrameCallback(VideoFrame* video_frame) { | 350 void VideoReceiveStream::FrameCallback(VideoFrame* video_frame) { |
351 stats_proxy_.OnDecodedFrame(); | 351 stats_proxy_.OnDecodedFrame(); |
352 | 352 |
353 // Post processing is not supported if the frame is backed by a texture. | 353 // Post processing is not supported if the frame is backed by a texture. |
354 if (video_frame->native_handle() == NULL) { | 354 if (video_frame->native_handle() == NULL) { |
355 if (config_.pre_render_callback) | 355 if (config_.pre_render_callback) |
356 config_.pre_render_callback->FrameCallback(video_frame); | 356 config_.pre_render_callback->FrameCallback(video_frame); |
357 } | 357 } |
(...skipping 24 matching lines...) Expand all Loading... |
382 stats_proxy_.OnPreDecode(encoded_image, codec_specific_info); | 382 stats_proxy_.OnPreDecode(encoded_image, codec_specific_info); |
383 if (config_.pre_decode_callback) { | 383 if (config_.pre_decode_callback) { |
384 // TODO(asapersson): Remove EncodedFrameCallbackAdapter. | 384 // TODO(asapersson): Remove EncodedFrameCallbackAdapter. |
385 encoded_frame_proxy_.Encoded( | 385 encoded_frame_proxy_.Encoded( |
386 encoded_image, codec_specific_info, fragmentation); | 386 encoded_image, codec_specific_info, fragmentation); |
387 } | 387 } |
388 return 0; | 388 return 0; |
389 } | 389 } |
390 | 390 |
391 void VideoReceiveStream::SignalNetworkState(NetworkState state) { | 391 void VideoReceiveStream::SignalNetworkState(NetworkState state) { |
392 vie_channel_.SetRTCPMode(state == kNetworkUp ? config_.rtp.rtcp_mode | 392 rtp_rtcp_->SetRTCPStatus(state == kNetworkUp ? config_.rtp.rtcp_mode |
393 : RtcpMode::kOff); | 393 : RtcpMode::kOff); |
394 } | 394 } |
395 | 395 |
396 } // namespace internal | 396 } // namespace internal |
397 } // namespace webrtc | 397 } // namespace webrtc |
OLD | NEW |