Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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/rtp_video_stream_receiver.h" | 11 #include "webrtc/video/rtp_video_stream_receiver.h" |
| 12 | 12 |
| 13 #include <algorithm> | |
| 13 #include <utility> | 14 #include <utility> |
| 14 #include <vector> | 15 #include <vector> |
| 15 | 16 |
| 16 #include "webrtc/common_types.h" | 17 #include "webrtc/common_types.h" |
| 17 #include "webrtc/config.h" | 18 #include "webrtc/config.h" |
| 18 #include "webrtc/media/base/mediaconstants.h" | 19 #include "webrtc/media/base/mediaconstants.h" |
| 19 #include "webrtc/modules/pacing/packet_router.h" | 20 #include "webrtc/modules/pacing/packet_router.h" |
| 20 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat or.h" | 21 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat or.h" |
| 21 #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" | 22 #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" |
| 22 #include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h" | 23 #include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 new NackModule(clock_, nack_sender, keyframe_request_sender)); | 185 new NackModule(clock_, nack_sender, keyframe_request_sender)); |
| 185 process_thread_->RegisterModule(nack_module_.get(), RTC_FROM_HERE); | 186 process_thread_->RegisterModule(nack_module_.get(), RTC_FROM_HERE); |
| 186 } | 187 } |
| 187 | 188 |
| 188 packet_buffer_ = video_coding::PacketBuffer::Create( | 189 packet_buffer_ = video_coding::PacketBuffer::Create( |
| 189 clock_, kPacketBufferStartSize, kPacketBufferMaxSixe, this); | 190 clock_, kPacketBufferStartSize, kPacketBufferMaxSixe, this); |
| 190 reference_finder_.reset(new video_coding::RtpFrameReferenceFinder(this)); | 191 reference_finder_.reset(new video_coding::RtpFrameReferenceFinder(this)); |
| 191 } | 192 } |
| 192 | 193 |
| 193 RtpVideoStreamReceiver::~RtpVideoStreamReceiver() { | 194 RtpVideoStreamReceiver::~RtpVideoStreamReceiver() { |
| 195 RTC_DCHECK(secondary_sinks_.empty()); | |
| 196 | |
| 194 if (nack_module_) { | 197 if (nack_module_) { |
| 195 process_thread_->DeRegisterModule(nack_module_.get()); | 198 process_thread_->DeRegisterModule(nack_module_.get()); |
| 196 } | 199 } |
| 197 | 200 |
| 198 process_thread_->DeRegisterModule(rtp_rtcp_.get()); | 201 process_thread_->DeRegisterModule(rtp_rtcp_.get()); |
| 199 | 202 |
| 200 packet_router_->RemoveReceiveRtpModule(rtp_rtcp_.get()); | 203 packet_router_->RemoveReceiveRtpModule(rtp_rtcp_.get()); |
| 201 UpdateHistograms(); | 204 UpdateHistograms(); |
| 202 } | 205 } |
| 203 | 206 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 const int frequency, | 304 const int frequency, |
| 302 const size_t channels, | 305 const size_t channels, |
| 303 const uint32_t rate) { | 306 const uint32_t rate) { |
| 304 RTC_NOTREACHED(); | 307 RTC_NOTREACHED(); |
| 305 return 0; | 308 return 0; |
| 306 } | 309 } |
| 307 | 310 |
| 308 // This method handles both regular RTP packets and packets recovered | 311 // This method handles both regular RTP packets and packets recovered |
| 309 // via FlexFEC. | 312 // via FlexFEC. |
| 310 void RtpVideoStreamReceiver::OnRtpPacket(const RtpPacketReceived& packet) { | 313 void RtpVideoStreamReceiver::OnRtpPacket(const RtpPacketReceived& packet) { |
| 314 RTC_DCHECK_RUN_ON(&worker_thread_checker_); | |
|
eladalon
2017/08/01 08:19:38
This will not work for video_loopback, because Dir
brandtr
2017/08/01 08:34:15
Nice! This addition makes the code faster to read.
| |
| 315 | |
| 311 { | 316 { |
| 312 rtc::CritScope lock(&receive_cs_); | 317 rtc::CritScope lock(&receive_cs_); |
| 313 if (!receiving_) { | 318 if (!receiving_) { |
| 314 return; | 319 return; |
| 315 } | 320 } |
| 316 | 321 |
| 317 if (!packet.recovered()) { | 322 if (!packet.recovered()) { |
| 318 int64_t now_ms = clock_->TimeInMilliseconds(); | 323 int64_t now_ms = clock_->TimeInMilliseconds(); |
| 319 | 324 |
| 320 // Periodically log the RTP header of incoming packets. | 325 // Periodically log the RTP header of incoming packets. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 354 ReceivePacket(packet.data(), packet.size(), header, in_order); | 359 ReceivePacket(packet.data(), packet.size(), header, in_order); |
| 355 // Update receive statistics after ReceivePacket. | 360 // Update receive statistics after ReceivePacket. |
| 356 // Receive statistics will be reset if the payload type changes (make sure | 361 // Receive statistics will be reset if the payload type changes (make sure |
| 357 // that the first packet is included in the stats). | 362 // that the first packet is included in the stats). |
| 358 if (!packet.recovered()) { | 363 if (!packet.recovered()) { |
| 359 // TODO(nisse): We should pass a recovered flag to stats, to aid | 364 // TODO(nisse): We should pass a recovered flag to stats, to aid |
| 360 // fixing bug bugs.webrtc.org/6339. | 365 // fixing bug bugs.webrtc.org/6339. |
| 361 rtp_receive_statistics_->IncomingPacket( | 366 rtp_receive_statistics_->IncomingPacket( |
| 362 header, packet.size(), IsPacketRetransmitted(header, in_order)); | 367 header, packet.size(), IsPacketRetransmitted(header, in_order)); |
| 363 } | 368 } |
| 369 | |
| 370 for (auto* secondary_sink : secondary_sinks_) { | |
|
brandtr
2017/08/01 08:34:15
RtpPacketSinkInterface* ?
eladalon
2017/08/01 09:30:28
Done.
| |
| 371 secondary_sink->OnRtpPacket(packet); | |
| 372 } | |
| 364 } | 373 } |
| 365 | 374 |
| 366 int32_t RtpVideoStreamReceiver::RequestKeyFrame() { | 375 int32_t RtpVideoStreamReceiver::RequestKeyFrame() { |
| 367 return rtp_rtcp_->RequestKeyFrame(); | 376 return rtp_rtcp_->RequestKeyFrame(); |
| 368 } | 377 } |
| 369 | 378 |
| 370 bool RtpVideoStreamReceiver::IsUlpfecEnabled() const { | 379 bool RtpVideoStreamReceiver::IsUlpfecEnabled() const { |
| 371 return config_.rtp.ulpfec.ulpfec_payload_type != -1; | 380 return config_.rtp.ulpfec.ulpfec_payload_type != -1; |
| 372 } | 381 } |
| 373 | 382 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 421 | 430 |
| 422 rtc::Optional<int64_t> RtpVideoStreamReceiver::LastReceivedPacketMs() const { | 431 rtc::Optional<int64_t> RtpVideoStreamReceiver::LastReceivedPacketMs() const { |
| 423 return packet_buffer_->LastReceivedPacketMs(); | 432 return packet_buffer_->LastReceivedPacketMs(); |
| 424 } | 433 } |
| 425 | 434 |
| 426 rtc::Optional<int64_t> RtpVideoStreamReceiver::LastReceivedKeyframePacketMs() | 435 rtc::Optional<int64_t> RtpVideoStreamReceiver::LastReceivedKeyframePacketMs() |
| 427 const { | 436 const { |
| 428 return packet_buffer_->LastReceivedKeyframePacketMs(); | 437 return packet_buffer_->LastReceivedKeyframePacketMs(); |
| 429 } | 438 } |
| 430 | 439 |
| 440 void RtpVideoStreamReceiver::AddSecondarySink(RtpPacketSinkInterface* sink) { | |
| 441 RTC_DCHECK_RUN_ON(&worker_thread_checker_); | |
| 442 RTC_DCHECK(std::find(secondary_sinks_.cbegin(), secondary_sinks_.cend(), | |
| 443 sink) == secondary_sinks_.cend()); | |
| 444 secondary_sinks_.push_back(sink); | |
| 445 } | |
| 446 | |
| 447 void RtpVideoStreamReceiver::RemoveSecondarySink( | |
| 448 const RtpPacketSinkInterface* sink) { | |
| 449 RTC_DCHECK_RUN_ON(&worker_thread_checker_); | |
| 450 auto it = std::find(secondary_sinks_.begin(), secondary_sinks_.end(), sink); | |
| 451 if (it == secondary_sinks_.end()) { | |
| 452 // We might be rolling-back a call whose setup failed mid-way. In such a | |
| 453 // case, it's simpler to remove "everything" rather than remember what | |
| 454 // has already been added. | |
| 455 LOG(LS_WARNING) << "Removal of unknown sink."; | |
| 456 return; | |
| 457 } | |
| 458 secondary_sinks_.erase(it); | |
| 459 } | |
| 460 | |
| 431 void RtpVideoStreamReceiver::ReceivePacket(const uint8_t* packet, | 461 void RtpVideoStreamReceiver::ReceivePacket(const uint8_t* packet, |
| 432 size_t packet_length, | 462 size_t packet_length, |
| 433 const RTPHeader& header, | 463 const RTPHeader& header, |
| 434 bool in_order) { | 464 bool in_order) { |
| 435 if (rtp_payload_registry_.IsEncapsulated(header)) { | 465 if (rtp_payload_registry_.IsEncapsulated(header)) { |
| 436 ParseAndHandleEncapsulatingHeader(packet, packet_length, header); | 466 ParseAndHandleEncapsulatingHeader(packet, packet_length, header); |
| 437 return; | 467 return; |
| 438 } | 468 } |
| 439 const uint8_t* payload = packet + header.headerLength; | 469 const uint8_t* payload = packet + header.headerLength; |
| 440 assert(packet_length >= header.headerLength); | 470 assert(packet_length >= header.headerLength); |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 680 return; | 710 return; |
| 681 | 711 |
| 682 if (!sprop_decoder.DecodeSprop(sprop_base64_it->second.c_str())) | 712 if (!sprop_decoder.DecodeSprop(sprop_base64_it->second.c_str())) |
| 683 return; | 713 return; |
| 684 | 714 |
| 685 tracker_.InsertSpsPpsNalus(sprop_decoder.sps_nalu(), | 715 tracker_.InsertSpsPpsNalus(sprop_decoder.sps_nalu(), |
| 686 sprop_decoder.pps_nalu()); | 716 sprop_decoder.pps_nalu()); |
| 687 } | 717 } |
| 688 | 718 |
| 689 } // namespace webrtc | 719 } // namespace webrtc |
| OLD | NEW |