niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
leozwang@webrtc.org | 39e9659 | 2012-03-01 18:22:48 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "video/rtp_video_stream_receiver.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 13 | #include <utility> |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 14 | #include <vector> |
mflodman@webrtc.org | 4fd5527 | 2013-02-06 17:46:39 +0000 | [diff] [blame] | 15 | |
Steve Anton | bd631a0 | 2019-03-28 10:51:27 -0700 | [diff] [blame] | 16 | #include "absl/algorithm/container.h" |
Niels Möller | 2ff1f2a | 2018-08-09 16:16:34 +0200 | [diff] [blame] | 17 | #include "absl/memory/memory.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 18 | #include "media/base/media_constants.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "modules/pacing/packet_router.h" |
| 20 | #include "modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h" |
| 21 | #include "modules/rtp_rtcp/include/receive_statistics.h" |
| 22 | #include "modules/rtp_rtcp/include/rtp_cvo.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 23 | #include "modules/rtp_rtcp/include/rtp_rtcp.h" |
| 24 | #include "modules/rtp_rtcp/include/ulpfec_receiver.h" |
Niels Möller | 2ff1f2a | 2018-08-09 16:16:34 +0200 | [diff] [blame] | 25 | #include "modules/rtp_rtcp/source/rtp_format.h" |
philipel | b3e42a4 | 2018-09-13 10:57:14 +0200 | [diff] [blame] | 26 | #include "modules/rtp_rtcp/source/rtp_generic_frame_descriptor_extension.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 27 | #include "modules/rtp_rtcp/source/rtp_header_extensions.h" |
| 28 | #include "modules/rtp_rtcp/source/rtp_packet_received.h" |
Niels Möller | 2ff1f2a | 2018-08-09 16:16:34 +0200 | [diff] [blame] | 29 | #include "modules/rtp_rtcp/source/rtp_rtcp_config.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 30 | #include "modules/video_coding/frame_object.h" |
| 31 | #include "modules/video_coding/h264_sprop_parameter_sets.h" |
| 32 | #include "modules/video_coding/h264_sps_pps_tracker.h" |
Ilya Nikolaevskiy | 8643b78 | 2018-06-07 16:15:40 +0200 | [diff] [blame] | 33 | #include "modules/video_coding/nack_module.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 34 | #include "modules/video_coding/packet_buffer.h" |
| 35 | #include "modules/video_coding/video_coding_impl.h" |
| 36 | #include "rtc_base/checks.h" |
| 37 | #include "rtc_base/location.h" |
| 38 | #include "rtc_base/logging.h" |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 39 | #include "rtc_base/strings/string_builder.h" |
Karl Wiberg | 80ba333 | 2018-02-05 10:33:35 +0100 | [diff] [blame] | 40 | #include "rtc_base/system/fallthrough.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 41 | #include "system_wrappers/include/field_trial.h" |
| 42 | #include "system_wrappers/include/metrics.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 43 | #include "video/receive_statistics_proxy.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 44 | |
| 45 | namespace webrtc { |
| 46 | |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 47 | namespace { |
philipel | 3bf97cf | 2017-08-10 18:10:59 +0200 | [diff] [blame] | 48 | // TODO(philipel): Change kPacketBufferStartSize back to 32 in M63 see: |
| 49 | // crbug.com/752886 |
| 50 | constexpr int kPacketBufferStartSize = 512; |
Johannes Kron | 201596f | 2018-10-22 14:33:39 +0200 | [diff] [blame] | 51 | constexpr int kPacketBufferMaxSize = 2048; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 52 | } // namespace |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 53 | |
mflodman | c0e58a3 | 2016-04-25 01:26:26 -0700 | [diff] [blame] | 54 | std::unique_ptr<RtpRtcp> CreateRtpRtcpModule( |
Sebastian Jansson | 8026d60 | 2019-03-04 19:39:01 +0100 | [diff] [blame] | 55 | Clock* clock, |
mflodman | c0e58a3 | 2016-04-25 01:26:26 -0700 | [diff] [blame] | 56 | ReceiveStatistics* receive_statistics, |
| 57 | Transport* outgoing_transport, |
| 58 | RtcpRttStats* rtt_stats, |
| 59 | RtcpPacketTypeCounterObserver* rtcp_packet_type_counter_observer, |
nisse | 15389c0 | 2017-01-24 02:36:58 -0800 | [diff] [blame] | 60 | TransportSequenceNumberAllocator* transport_sequence_number_allocator) { |
mflodman | c0e58a3 | 2016-04-25 01:26:26 -0700 | [diff] [blame] | 61 | RtpRtcp::Configuration configuration; |
Sebastian Jansson | 8026d60 | 2019-03-04 19:39:01 +0100 | [diff] [blame] | 62 | configuration.clock = clock; |
mflodman | c0e58a3 | 2016-04-25 01:26:26 -0700 | [diff] [blame] | 63 | configuration.audio = false; |
| 64 | configuration.receiver_only = true; |
| 65 | configuration.receive_statistics = receive_statistics; |
| 66 | configuration.outgoing_transport = outgoing_transport; |
| 67 | configuration.intra_frame_callback = nullptr; |
| 68 | configuration.rtt_stats = rtt_stats; |
| 69 | configuration.rtcp_packet_type_counter_observer = |
| 70 | rtcp_packet_type_counter_observer; |
mflodman | c0e58a3 | 2016-04-25 01:26:26 -0700 | [diff] [blame] | 71 | configuration.transport_sequence_number_allocator = |
| 72 | transport_sequence_number_allocator; |
| 73 | configuration.send_bitrate_observer = nullptr; |
mflodman | c0e58a3 | 2016-04-25 01:26:26 -0700 | [diff] [blame] | 74 | configuration.send_side_delay_observer = nullptr; |
asapersson | 35151f3 | 2016-05-02 23:44:01 -0700 | [diff] [blame] | 75 | configuration.send_packet_observer = nullptr; |
mflodman | c0e58a3 | 2016-04-25 01:26:26 -0700 | [diff] [blame] | 76 | configuration.bandwidth_callback = nullptr; |
| 77 | configuration.transport_feedback_callback = nullptr; |
| 78 | |
Danil Chapovalov | c44f6cc | 2019-03-06 11:31:09 +0100 | [diff] [blame] | 79 | std::unique_ptr<RtpRtcp> rtp_rtcp = RtpRtcp::Create(configuration); |
mflodman | c0e58a3 | 2016-04-25 01:26:26 -0700 | [diff] [blame] | 80 | rtp_rtcp->SetRTCPStatus(RtcpMode::kCompound); |
| 81 | |
| 82 | return rtp_rtcp; |
| 83 | } |
| 84 | |
stefan@webrtc.org | eb24b04 | 2014-10-14 11:40:13 +0000 | [diff] [blame] | 85 | static const int kPacketLogIntervalMs = 10000; |
| 86 | |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 87 | RtpVideoStreamReceiver::RtpVideoStreamReceiver( |
Sebastian Jansson | 8026d60 | 2019-03-04 19:39:01 +0100 | [diff] [blame] | 88 | Clock* clock, |
mflodman | fa66659 | 2016-04-28 23:15:33 -0700 | [diff] [blame] | 89 | Transport* transport, |
| 90 | RtcpRttStats* rtt_stats, |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 91 | PacketRouter* packet_router, |
Tommi | 733b547 | 2016-06-10 17:58:01 +0200 | [diff] [blame] | 92 | const VideoReceiveStream::Config* config, |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 93 | ReceiveStatistics* rtp_receive_statistics, |
mflodman | dc7d0d2 | 2016-05-06 05:32:22 -0700 | [diff] [blame] | 94 | ReceiveStatisticsProxy* receive_stats_proxy, |
Erik Språng | 737336d | 2016-07-29 12:59:36 +0200 | [diff] [blame] | 95 | ProcessThread* process_thread, |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 96 | NackSender* nack_sender, |
| 97 | KeyFrameRequestSender* keyframe_request_sender, |
Benjamin Wright | 192eeec | 2018-10-17 17:27:25 -0700 | [diff] [blame] | 98 | video_coding::OnCompleteFrameCallback* complete_frame_callback, |
| 99 | rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor) |
Sebastian Jansson | 8026d60 | 2019-03-04 19:39:01 +0100 | [diff] [blame] | 100 | : clock_(clock), |
Tommi | 733b547 | 2016-06-10 17:58:01 +0200 | [diff] [blame] | 101 | config_(*config), |
mflodman | c0e58a3 | 2016-04-25 01:26:26 -0700 | [diff] [blame] | 102 | packet_router_(packet_router), |
mflodman | dc7d0d2 | 2016-05-06 05:32:22 -0700 | [diff] [blame] | 103 | process_thread_(process_thread), |
Sebastian Jansson | 8026d60 | 2019-03-04 19:39:01 +0100 | [diff] [blame] | 104 | ntp_estimator_(clock), |
Niels Möller | b0573bc | 2017-09-25 10:47:00 +0200 | [diff] [blame] | 105 | rtp_header_extensions_(config_.rtp.extensions), |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 106 | rtp_receive_statistics_(rtp_receive_statistics), |
brandtr | d726a3f | 2017-06-29 02:45:35 -0700 | [diff] [blame] | 107 | ulpfec_receiver_(UlpfecReceiver::Create(config->rtp.remote_ssrc, this)), |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 108 | receiving_(false), |
mflodman | c0e58a3 | 2016-04-25 01:26:26 -0700 | [diff] [blame] | 109 | last_packet_log_ms_(-1), |
Sebastian Jansson | 8026d60 | 2019-03-04 19:39:01 +0100 | [diff] [blame] | 110 | rtp_rtcp_(CreateRtpRtcpModule(clock, |
| 111 | rtp_receive_statistics_, |
mflodman | c0e58a3 | 2016-04-25 01:26:26 -0700 | [diff] [blame] | 112 | transport, |
| 113 | rtt_stats, |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 114 | receive_stats_proxy, |
nisse | 15389c0 | 2017-01-24 02:36:58 -0800 | [diff] [blame] | 115 | packet_router)), |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 116 | complete_frame_callback_(complete_frame_callback), |
| 117 | keyframe_request_sender_(keyframe_request_sender), |
Benjamin Wright | 52426ed | 2019-03-01 11:01:59 -0800 | [diff] [blame] | 118 | has_received_frame_(false), |
| 119 | frames_decryptable_(false) { |
eladalon | 822ff2b | 2017-08-01 06:30:28 -0700 | [diff] [blame] | 120 | constexpr bool remb_candidate = true; |
| 121 | packet_router_->AddReceiveRtpModule(rtp_rtcp_.get(), remb_candidate); |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 122 | |
Tommi | 733b547 | 2016-06-10 17:58:01 +0200 | [diff] [blame] | 123 | RTC_DCHECK(config_.rtp.rtcp_mode != RtcpMode::kOff) |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 124 | << "A stream should not be configured with RTCP disabled. This value is " |
| 125 | "reserved for internal usage."; |
mflodman | dc7d0d2 | 2016-05-06 05:32:22 -0700 | [diff] [blame] | 126 | RTC_DCHECK(config_.rtp.remote_ssrc != 0); |
| 127 | // TODO(pbos): What's an appropriate local_ssrc for receive-only streams? |
| 128 | RTC_DCHECK(config_.rtp.local_ssrc != 0); |
| 129 | RTC_DCHECK(config_.rtp.remote_ssrc != config_.rtp.local_ssrc); |
| 130 | |
Tommi | 733b547 | 2016-06-10 17:58:01 +0200 | [diff] [blame] | 131 | rtp_rtcp_->SetRTCPStatus(config_.rtp.rtcp_mode); |
| 132 | rtp_rtcp_->SetSSRC(config_.rtp.local_ssrc); |
stefan | b4ab381 | 2017-06-09 06:12:11 -0700 | [diff] [blame] | 133 | rtp_rtcp_->SetRemoteSSRC(config_.rtp.remote_ssrc); |
mflodman | c0e58a3 | 2016-04-25 01:26:26 -0700 | [diff] [blame] | 134 | rtp_rtcp_->SetKeyFrameRequestMethod(kKeyFrameReqPliRtcp); |
mflodman | dc7d0d2 | 2016-05-06 05:32:22 -0700 | [diff] [blame] | 135 | |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 136 | static const int kMaxPacketAgeToNack = 450; |
Tommi | 733b547 | 2016-06-10 17:58:01 +0200 | [diff] [blame] | 137 | const int max_reordering_threshold = (config_.rtp.nack.rtp_history_ms > 0) |
| 138 | ? kMaxPacketAgeToNack |
| 139 | : kDefaultMaxReorderingThreshold; |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 140 | rtp_receive_statistics_->SetMaxReorderingThreshold(max_reordering_threshold); |
mflodman | dc7d0d2 | 2016-05-06 05:32:22 -0700 | [diff] [blame] | 141 | |
Tommi | 733b547 | 2016-06-10 17:58:01 +0200 | [diff] [blame] | 142 | if (config_.rtp.rtcp_xr.receiver_reference_time_report) |
mflodman | dc7d0d2 | 2016-05-06 05:32:22 -0700 | [diff] [blame] | 143 | rtp_rtcp_->SetRtcpXrRrtrStatus(true); |
| 144 | |
| 145 | // Stats callback for CNAME changes. |
| 146 | rtp_rtcp_->RegisterRtcpStatisticsCallback(receive_stats_proxy); |
| 147 | |
tommi | dea489f | 2017-03-03 03:20:24 -0800 | [diff] [blame] | 148 | process_thread_->RegisterModule(rtp_rtcp_.get(), RTC_FROM_HERE); |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 149 | |
Elad Alon | 7d6a4c0 | 2019-02-25 13:00:51 +0100 | [diff] [blame] | 150 | if (webrtc::field_trial::IsEnabled("WebRTC-RtcpLossNotification")) { |
| 151 | loss_notification_controller_ = |
| 152 | absl::make_unique<LossNotificationController>(keyframe_request_sender_, |
| 153 | this); |
| 154 | } else if (config_.rtp.nack.rtp_history_ms != 0) { |
Elad Alon | a8f5461 | 2018-11-06 11:21:25 +0100 | [diff] [blame] | 155 | nack_module_ = absl::make_unique<NackModule>(clock_, nack_sender, |
| 156 | keyframe_request_sender); |
tommi | dea489f | 2017-03-03 03:20:24 -0800 | [diff] [blame] | 157 | process_thread_->RegisterModule(nack_module_.get(), RTC_FROM_HERE); |
tommi | f284b7f | 2017-02-27 01:59:36 -0800 | [diff] [blame] | 158 | } |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 159 | |
Johannes Kron | 487e694 | 2018-10-24 00:53:39 +0200 | [diff] [blame] | 160 | // The group here must be a positive power of 2, in which case that is used as |
| 161 | // size. All other values shall result in the default value being used. |
Johannes Kron | 201596f | 2018-10-22 14:33:39 +0200 | [diff] [blame] | 162 | const std::string group_name = |
| 163 | webrtc::field_trial::FindFullName("WebRTC-PacketBufferMaxSize"); |
| 164 | int packet_buffer_max_size = kPacketBufferMaxSize; |
| 165 | if (!group_name.empty() && |
| 166 | (sscanf(group_name.c_str(), "%d", &packet_buffer_max_size) != 1 || |
Johannes Kron | 487e694 | 2018-10-24 00:53:39 +0200 | [diff] [blame] | 167 | packet_buffer_max_size <= 0 || |
| 168 | // Verify that the number is a positive power of 2. |
| 169 | (packet_buffer_max_size & (packet_buffer_max_size - 1)) != 0)) { |
Johannes Kron | 201596f | 2018-10-22 14:33:39 +0200 | [diff] [blame] | 170 | RTC_LOG(LS_WARNING) << "Invalid packet buffer max size: " << group_name; |
| 171 | packet_buffer_max_size = kPacketBufferMaxSize; |
| 172 | } |
| 173 | |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 174 | packet_buffer_ = video_coding::PacketBuffer::Create( |
Johannes Kron | 201596f | 2018-10-22 14:33:39 +0200 | [diff] [blame] | 175 | clock_, kPacketBufferStartSize, packet_buffer_max_size, this); |
Elad Alon | a8f5461 | 2018-11-06 11:21:25 +0100 | [diff] [blame] | 176 | reference_finder_ = |
| 177 | absl::make_unique<video_coding::RtpFrameReferenceFinder>(this); |
Benjamin Wright | a556448 | 2019-04-03 10:44:18 -0700 | [diff] [blame^] | 178 | |
Benjamin Wright | 0076529 | 2018-11-30 16:18:26 -0800 | [diff] [blame] | 179 | // Only construct the encrypted receiver if frame encryption is enabled. |
Benjamin Wright | a556448 | 2019-04-03 10:44:18 -0700 | [diff] [blame^] | 180 | if (config_.crypto_options.sframe.require_frame_encryption) { |
Benjamin Wright | 0076529 | 2018-11-30 16:18:26 -0800 | [diff] [blame] | 181 | buffered_frame_decryptor_ = |
Benjamin Wright | a556448 | 2019-04-03 10:44:18 -0700 | [diff] [blame^] | 182 | absl::make_unique<BufferedFrameDecryptor>(this, this); |
| 183 | if (frame_decryptor != nullptr) { |
| 184 | buffered_frame_decryptor_->SetFrameDecryptor(std::move(frame_decryptor)); |
| 185 | } |
Benjamin Wright | 0076529 | 2018-11-30 16:18:26 -0800 | [diff] [blame] | 186 | } |
mflodman | c0e58a3 | 2016-04-25 01:26:26 -0700 | [diff] [blame] | 187 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 188 | |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 189 | RtpVideoStreamReceiver::~RtpVideoStreamReceiver() { |
eladalon | c0d481a | 2017-08-02 07:39:07 -0700 | [diff] [blame] | 190 | RTC_DCHECK(secondary_sinks_.empty()); |
| 191 | |
tommi | f284b7f | 2017-02-27 01:59:36 -0800 | [diff] [blame] | 192 | if (nack_module_) { |
| 193 | process_thread_->DeRegisterModule(nack_module_.get()); |
| 194 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 195 | |
tommi | f284b7f | 2017-02-27 01:59:36 -0800 | [diff] [blame] | 196 | process_thread_->DeRegisterModule(rtp_rtcp_.get()); |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 197 | |
nisse | fdbfdc9 | 2017-03-31 05:44:52 -0700 | [diff] [blame] | 198 | packet_router_->RemoveReceiveRtpModule(rtp_rtcp_.get()); |
mflodman | dc7d0d2 | 2016-05-06 05:32:22 -0700 | [diff] [blame] | 199 | UpdateHistograms(); |
asapersson@webrtc.org | 0800db7 | 2015-01-15 07:40:20 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Niels Möller | 2ff1f2a | 2018-08-09 16:16:34 +0200 | [diff] [blame] | 202 | void RtpVideoStreamReceiver::AddReceiveCodec( |
philipel | 022b54e | 2016-12-20 04:15:59 -0800 | [diff] [blame] | 203 | const VideoCodec& video_codec, |
| 204 | const std::map<std::string, std::string>& codec_params) { |
Niels Möller | 2ff1f2a | 2018-08-09 16:16:34 +0200 | [diff] [blame] | 205 | pt_codec_type_.emplace(video_codec.plType, video_codec.codecType); |
| 206 | pt_codec_params_.emplace(video_codec.plType, codec_params); |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Niels Möller | df9e9ae | 2018-07-31 08:29:53 +0200 | [diff] [blame] | 209 | absl::optional<Syncable::Info> RtpVideoStreamReceiver::GetSyncInfo() const { |
Niels Möller | 2ff1f2a | 2018-08-09 16:16:34 +0200 | [diff] [blame] | 210 | Syncable::Info info; |
Niels Möller | df9e9ae | 2018-07-31 08:29:53 +0200 | [diff] [blame] | 211 | if (rtp_rtcp_->RemoteNTP(&info.capture_time_ntp_secs, |
| 212 | &info.capture_time_ntp_frac, nullptr, nullptr, |
| 213 | &info.capture_time_source_clock) != 0) { |
| 214 | return absl::nullopt; |
| 215 | } |
Niels Möller | b0d4b41 | 2018-08-28 13:58:15 +0200 | [diff] [blame] | 216 | { |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 217 | rtc::CritScope lock(&rtp_sources_lock_); |
Niels Möller | b0d4b41 | 2018-08-28 13:58:15 +0200 | [diff] [blame] | 218 | if (!last_received_rtp_timestamp_ || !last_received_rtp_system_time_ms_) { |
| 219 | return absl::nullopt; |
| 220 | } |
| 221 | info.latest_received_capture_timestamp = *last_received_rtp_timestamp_; |
| 222 | info.latest_receive_time_ms = *last_received_rtp_system_time_ms_; |
| 223 | } |
Niels Möller | df9e9ae | 2018-07-31 08:29:53 +0200 | [diff] [blame] | 224 | |
| 225 | // Leaves info.current_delay_ms uninitialized. |
| 226 | return info; |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 227 | } |
| 228 | |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 229 | int32_t RtpVideoStreamReceiver::OnReceivedPayloadData( |
mflodman | fa66659 | 2016-04-28 23:15:33 -0700 | [diff] [blame] | 230 | const uint8_t* payload_data, |
Peter Boström | 0208322 | 2016-06-14 12:52:54 +0200 | [diff] [blame] | 231 | size_t payload_size, |
Niels Möller | 125b5d6 | 2019-03-11 16:11:07 +0100 | [diff] [blame] | 232 | const RTPHeader& rtp_header, |
| 233 | const RTPVideoHeader& video_header, |
Niels Möller | 8f7ce22 | 2019-03-21 15:43:58 +0100 | [diff] [blame] | 234 | VideoFrameType frame_type, |
Ying Wang | b32bb95 | 2018-10-31 10:12:27 +0100 | [diff] [blame] | 235 | const absl::optional<RtpGenericFrameDescriptor>& generic_descriptor, |
| 236 | bool is_recovered) { |
Niels Möller | 125b5d6 | 2019-03-11 16:11:07 +0100 | [diff] [blame] | 237 | VCMPacket packet(payload_data, payload_size, rtp_header, video_header, |
| 238 | frame_type, ntp_estimator_.Estimate(rtp_header.timestamp)); |
Elad Alon | 7d6a4c0 | 2019-02-25 13:00:51 +0100 | [diff] [blame] | 239 | packet.generic_descriptor = generic_descriptor; |
| 240 | |
Niels Möller | 8dad9b4 | 2018-08-22 10:36:35 +0200 | [diff] [blame] | 241 | if (nack_module_) { |
Niels Möller | 8f7ce22 | 2019-03-21 15:43:58 +0100 | [diff] [blame] | 242 | const bool is_keyframe = video_header.is_first_packet_in_frame && |
| 243 | frame_type == VideoFrameType::kVideoFrameKey; |
Niels Möller | 8dad9b4 | 2018-08-22 10:36:35 +0200 | [diff] [blame] | 244 | |
| 245 | packet.timesNacked = nack_module_->OnReceivedPacket( |
Niels Möller | 125b5d6 | 2019-03-11 16:11:07 +0100 | [diff] [blame] | 246 | rtp_header.sequenceNumber, is_keyframe, is_recovered); |
Ying Wang | b32bb95 | 2018-10-31 10:12:27 +0100 | [diff] [blame] | 247 | |
Niels Möller | 8dad9b4 | 2018-08-22 10:36:35 +0200 | [diff] [blame] | 248 | } else { |
| 249 | packet.timesNacked = -1; |
| 250 | } |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 251 | packet.receive_time_ms = clock_->TimeInMilliseconds(); |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 252 | |
Elad Alon | 7d6a4c0 | 2019-02-25 13:00:51 +0100 | [diff] [blame] | 253 | if (loss_notification_controller_) { |
| 254 | if (is_recovered) { |
| 255 | // TODO(bugs.webrtc.org/10336): Implement support for reordering. |
| 256 | RTC_LOG(LS_WARNING) |
| 257 | << "LossNotificationController does not support reordering."; |
| 258 | } else { |
| 259 | loss_notification_controller_->OnReceivedPacket(packet); |
| 260 | } |
| 261 | } |
| 262 | |
philipel | 54ca919 | 2017-03-21 05:45:18 -0700 | [diff] [blame] | 263 | if (packet.sizeBytes == 0) { |
Niels Möller | bc01047 | 2018-03-23 13:22:29 +0100 | [diff] [blame] | 264 | NotifyReceiverOfEmptyPacket(packet.seqNum); |
philipel | 54ca919 | 2017-03-21 05:45:18 -0700 | [diff] [blame] | 265 | return 0; |
| 266 | } |
| 267 | |
Niels Möller | d5e02f0 | 2019-02-20 13:12:21 +0100 | [diff] [blame] | 268 | if (packet.codec() == kVideoCodecH264) { |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 269 | // Only when we start to receive packets will we know what payload type |
| 270 | // that will be used. When we know the payload type insert the correct |
| 271 | // sps/pps into the tracker. |
| 272 | if (packet.payloadType != last_payload_type_) { |
| 273 | last_payload_type_ = packet.payloadType; |
| 274 | InsertSpsPpsIntoTracker(packet.payloadType); |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 275 | } |
| 276 | |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 277 | switch (tracker_.CopyAndFixBitstream(&packet)) { |
| 278 | case video_coding::H264SpsPpsTracker::kRequestKeyframe: |
| 279 | keyframe_request_sender_->RequestKeyFrame(); |
Karl Wiberg | 80ba333 | 2018-02-05 10:33:35 +0100 | [diff] [blame] | 280 | RTC_FALLTHROUGH(); |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 281 | case video_coding::H264SpsPpsTracker::kDrop: |
| 282 | return 0; |
| 283 | case video_coding::H264SpsPpsTracker::kInsert: |
| 284 | break; |
| 285 | } |
| 286 | |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 287 | } else { |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 288 | uint8_t* data = new uint8_t[packet.sizeBytes]; |
| 289 | memcpy(data, packet.dataPtr, packet.sizeBytes); |
| 290 | packet.dataPtr = data; |
mflodman@webrtc.org | ad4ee36 | 2011-11-28 22:39:24 +0000 | [diff] [blame] | 291 | } |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 292 | |
| 293 | packet_buffer_->InsertPacket(&packet); |
mflodman@webrtc.org | ad4ee36 | 2011-11-28 22:39:24 +0000 | [diff] [blame] | 294 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 295 | } |
| 296 | |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 297 | void RtpVideoStreamReceiver::OnRecoveredPacket(const uint8_t* rtp_packet, |
| 298 | size_t rtp_packet_length) { |
Niels Möller | b0573bc | 2017-09-25 10:47:00 +0200 | [diff] [blame] | 299 | RtpPacketReceived packet; |
| 300 | if (!packet.Parse(rtp_packet, rtp_packet_length)) |
nisse | 30e8931 | 2017-05-29 08:16:37 -0700 | [diff] [blame] | 301 | return; |
Niels Möller | 2ff1f2a | 2018-08-09 16:16:34 +0200 | [diff] [blame] | 302 | if (packet.PayloadType() == config_.rtp.red_payload_type) { |
| 303 | RTC_LOG(LS_WARNING) << "Discarding recovered packet with RED encapsulation"; |
| 304 | return; |
| 305 | } |
| 306 | |
Niels Möller | b0573bc | 2017-09-25 10:47:00 +0200 | [diff] [blame] | 307 | packet.IdentifyExtensions(rtp_header_extensions_); |
| 308 | packet.set_payload_type_frequency(kVideoPayloadTypeFrequency); |
Niels Möller | 2ff1f2a | 2018-08-09 16:16:34 +0200 | [diff] [blame] | 309 | // TODO(nisse): UlpfecReceiverImpl::ProcessReceivedFec passes both |
| 310 | // original (decapsulated) media packets and recovered packets to |
| 311 | // this callback. We need a way to distinguish, for setting |
| 312 | // packet.recovered() correctly. Ideally, move RED decapsulation out |
| 313 | // of the Ulpfec implementation. |
Niels Möller | b0573bc | 2017-09-25 10:47:00 +0200 | [diff] [blame] | 314 | |
Niels Möller | 2ff1f2a | 2018-08-09 16:16:34 +0200 | [diff] [blame] | 315 | ReceivePacket(packet); |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 316 | } |
| 317 | |
nisse | d2ef314 | 2017-05-11 08:00:58 -0700 | [diff] [blame] | 318 | // This method handles both regular RTP packets and packets recovered |
| 319 | // via FlexFEC. |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 320 | void RtpVideoStreamReceiver::OnRtpPacket(const RtpPacketReceived& packet) { |
eladalon | 8b07305 | 2017-08-25 00:49:08 -0700 | [diff] [blame] | 321 | RTC_DCHECK_CALLED_SEQUENTIALLY(&worker_task_checker_); |
eladalon | c0d481a | 2017-08-02 07:39:07 -0700 | [diff] [blame] | 322 | |
eladalon | 8b07305 | 2017-08-25 00:49:08 -0700 | [diff] [blame] | 323 | if (!receiving_) { |
| 324 | return; |
| 325 | } |
solenberg@webrtc.org | fc32046 | 2014-02-11 15:27:49 +0000 | [diff] [blame] | 326 | |
eladalon | 8b07305 | 2017-08-25 00:49:08 -0700 | [diff] [blame] | 327 | if (!packet.recovered()) { |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 328 | // TODO(nisse): Exclude out-of-order packets? |
eladalon | 8b07305 | 2017-08-25 00:49:08 -0700 | [diff] [blame] | 329 | int64_t now_ms = clock_->TimeInMilliseconds(); |
Niels Möller | b0d4b41 | 2018-08-28 13:58:15 +0200 | [diff] [blame] | 330 | { |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 331 | rtc::CritScope cs(&rtp_sources_lock_); |
Niels Möller | b0d4b41 | 2018-08-28 13:58:15 +0200 | [diff] [blame] | 332 | last_received_rtp_timestamp_ = packet.Timestamp(); |
| 333 | last_received_rtp_system_time_ms_ = now_ms; |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 334 | |
| 335 | std::vector<uint32_t> csrcs = packet.Csrcs(); |
Jonas Oreland | 967f7d5 | 2018-11-06 07:35:06 +0100 | [diff] [blame] | 336 | contributing_sources_.Update(now_ms, csrcs, |
Benjamin Wright | 0076529 | 2018-11-30 16:18:26 -0800 | [diff] [blame] | 337 | /* audio level */ absl::nullopt); |
Niels Möller | b0d4b41 | 2018-08-28 13:58:15 +0200 | [diff] [blame] | 338 | } |
eladalon | 8b07305 | 2017-08-25 00:49:08 -0700 | [diff] [blame] | 339 | // Periodically log the RTP header of incoming packets. |
| 340 | if (now_ms - last_packet_log_ms_ > kPacketLogIntervalMs) { |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 341 | rtc::StringBuilder ss; |
eladalon | 8b07305 | 2017-08-25 00:49:08 -0700 | [diff] [blame] | 342 | ss << "Packet received on SSRC: " << packet.Ssrc() |
| 343 | << " with payload type: " << static_cast<int>(packet.PayloadType()) |
| 344 | << ", timestamp: " << packet.Timestamp() |
| 345 | << ", sequence number: " << packet.SequenceNumber() |
| 346 | << ", arrival time: " << packet.arrival_time_ms(); |
| 347 | int32_t time_offset; |
| 348 | if (packet.GetExtension<TransmissionOffset>(&time_offset)) { |
| 349 | ss << ", toffset: " << time_offset; |
nisse | 38cc1d6 | 2017-02-13 05:59:46 -0800 | [diff] [blame] | 350 | } |
eladalon | 8b07305 | 2017-08-25 00:49:08 -0700 | [diff] [blame] | 351 | uint32_t send_time; |
| 352 | if (packet.GetExtension<AbsoluteSendTime>(&send_time)) { |
| 353 | ss << ", abs send time: " << send_time; |
| 354 | } |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 355 | RTC_LOG(LS_INFO) << ss.str(); |
eladalon | 8b07305 | 2017-08-25 00:49:08 -0700 | [diff] [blame] | 356 | last_packet_log_ms_ = now_ms; |
stefan@webrtc.org | eb24b04 | 2014-10-14 11:40:13 +0000 | [diff] [blame] | 357 | } |
| 358 | } |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 359 | |
Niels Möller | 2ff1f2a | 2018-08-09 16:16:34 +0200 | [diff] [blame] | 360 | ReceivePacket(packet); |
nisse | 38cc1d6 | 2017-02-13 05:59:46 -0800 | [diff] [blame] | 361 | |
asapersson@webrtc.org | 1457b47 | 2014-05-26 13:06:04 +0000 | [diff] [blame] | 362 | // Update receive statistics after ReceivePacket. |
| 363 | // Receive statistics will be reset if the payload type changes (make sure |
| 364 | // that the first packet is included in the stats). |
nisse | d2ef314 | 2017-05-11 08:00:58 -0700 | [diff] [blame] | 365 | if (!packet.recovered()) { |
Niels Möller | 1f3206c | 2018-09-14 08:26:32 +0200 | [diff] [blame] | 366 | rtp_receive_statistics_->OnRtpPacket(packet); |
nisse | d2ef314 | 2017-05-11 08:00:58 -0700 | [diff] [blame] | 367 | } |
eladalon | c0d481a | 2017-08-02 07:39:07 -0700 | [diff] [blame] | 368 | |
| 369 | for (RtpPacketSinkInterface* secondary_sink : secondary_sinks_) { |
| 370 | secondary_sink->OnRtpPacket(packet); |
| 371 | } |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 372 | } |
| 373 | |
Niels Möller | 4168437 | 2019-03-25 15:51:03 +0100 | [diff] [blame] | 374 | void RtpVideoStreamReceiver::RequestKeyFrame() { |
| 375 | rtp_rtcp_->RequestKeyFrame(); |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 376 | } |
| 377 | |
Elad Alon | 7d6a4c0 | 2019-02-25 13:00:51 +0100 | [diff] [blame] | 378 | void RtpVideoStreamReceiver::SendLossNotification( |
| 379 | uint16_t last_decoded_seq_num, |
| 380 | uint16_t last_received_seq_num, |
| 381 | bool decodability_flag) { |
| 382 | rtp_rtcp_->SendLossNotification(last_decoded_seq_num, last_received_seq_num, |
| 383 | decodability_flag); |
| 384 | } |
| 385 | |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 386 | bool RtpVideoStreamReceiver::IsUlpfecEnabled() const { |
nisse | 3b3622f | 2017-09-26 02:49:21 -0700 | [diff] [blame] | 387 | return config_.rtp.ulpfec_payload_type != -1; |
brandtr | e6f98c7 | 2016-11-11 03:28:30 -0800 | [diff] [blame] | 388 | } |
| 389 | |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 390 | bool RtpVideoStreamReceiver::IsRetransmissionsEnabled() const { |
mflodman | dc7d0d2 | 2016-05-06 05:32:22 -0700 | [diff] [blame] | 391 | return config_.rtp.nack.rtp_history_ms > 0; |
| 392 | } |
| 393 | |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 394 | void RtpVideoStreamReceiver::RequestPacketRetransmit( |
mflodman | dc7d0d2 | 2016-05-06 05:32:22 -0700 | [diff] [blame] | 395 | const std::vector<uint16_t>& sequence_numbers) { |
| 396 | rtp_rtcp_->SendNack(sequence_numbers); |
| 397 | } |
| 398 | |
Benjamin Wright | 52426ed | 2019-03-01 11:01:59 -0800 | [diff] [blame] | 399 | bool RtpVideoStreamReceiver::IsDecryptable() const { |
| 400 | return frames_decryptable_.load(); |
| 401 | } |
| 402 | |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 403 | int32_t RtpVideoStreamReceiver::ResendPackets(const uint16_t* sequence_numbers, |
| 404 | uint16_t length) { |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 405 | return rtp_rtcp_->SendNACK(sequence_numbers, length); |
| 406 | } |
| 407 | |
Elad Alon | b4643ad | 2019-02-22 11:19:50 +0100 | [diff] [blame] | 408 | void RtpVideoStreamReceiver::OnAssembledFrame( |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 409 | std::unique_ptr<video_coding::RtpFrameObject> frame) { |
Benjamin Wright | 0076529 | 2018-11-30 16:18:26 -0800 | [diff] [blame] | 410 | RTC_DCHECK_RUN_ON(&network_tc_); |
Elad Alon | 7d6a4c0 | 2019-02-25 13:00:51 +0100 | [diff] [blame] | 411 | RTC_DCHECK(frame); |
| 412 | |
| 413 | absl::optional<RtpGenericFrameDescriptor> descriptor = |
| 414 | frame->GetGenericFrameDescriptor(); |
| 415 | |
| 416 | if (loss_notification_controller_ && descriptor) { |
| 417 | loss_notification_controller_->OnAssembledFrame( |
| 418 | frame->first_seq_num(), descriptor->FrameId(), |
| 419 | descriptor->Discardable().value_or(false), |
| 420 | descriptor->FrameDependenciesDiffs()); |
| 421 | } else if (!has_received_frame_) { |
| 422 | // Request a key frame as soon as possible. |
Niels Möller | 8f7ce22 | 2019-03-21 15:43:58 +0100 | [diff] [blame] | 423 | if (frame->FrameType() != VideoFrameType::kVideoFrameKey) { |
Benjamin Wright | 39feabe | 2018-10-22 13:33:09 -0700 | [diff] [blame] | 424 | keyframe_request_sender_->RequestKeyFrame(); |
| 425 | } |
| 426 | } |
Elad Alon | 7d6a4c0 | 2019-02-25 13:00:51 +0100 | [diff] [blame] | 427 | |
| 428 | has_received_frame_ = true; |
| 429 | |
Benjamin Wright | 0076529 | 2018-11-30 16:18:26 -0800 | [diff] [blame] | 430 | if (buffered_frame_decryptor_ == nullptr) { |
| 431 | reference_finder_->ManageFrame(std::move(frame)); |
| 432 | } else { |
| 433 | buffered_frame_decryptor_->ManageEncryptedFrame(std::move(frame)); |
Benjamin Wright | 192eeec | 2018-10-17 17:27:25 -0700 | [diff] [blame] | 434 | } |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 435 | } |
| 436 | |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 437 | void RtpVideoStreamReceiver::OnCompleteFrame( |
philipel | e7c891f | 2018-02-22 14:35:06 +0100 | [diff] [blame] | 438 | std::unique_ptr<video_coding::EncodedFrame> frame) { |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 439 | { |
| 440 | rtc::CritScope lock(&last_seq_num_cs_); |
| 441 | video_coding::RtpFrameObject* rtp_frame = |
| 442 | static_cast<video_coding::RtpFrameObject*>(frame.get()); |
philipel | 0fa82a6 | 2018-03-19 15:34:53 +0100 | [diff] [blame] | 443 | last_seq_num_for_pic_id_[rtp_frame->id.picture_id] = |
| 444 | rtp_frame->last_seq_num(); |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 445 | } |
| 446 | complete_frame_callback_->OnCompleteFrame(std::move(frame)); |
| 447 | } |
| 448 | |
Benjamin Wright | 0076529 | 2018-11-30 16:18:26 -0800 | [diff] [blame] | 449 | void RtpVideoStreamReceiver::OnDecryptedFrame( |
| 450 | std::unique_ptr<video_coding::RtpFrameObject> frame) { |
| 451 | reference_finder_->ManageFrame(std::move(frame)); |
| 452 | } |
| 453 | |
Benjamin Wright | 52426ed | 2019-03-01 11:01:59 -0800 | [diff] [blame] | 454 | void RtpVideoStreamReceiver::OnDecryptionStatusChange(int status) { |
| 455 | frames_decryptable_.store(status == 0); |
| 456 | } |
| 457 | |
Benjamin Wright | a556448 | 2019-04-03 10:44:18 -0700 | [diff] [blame^] | 458 | void RtpVideoStreamReceiver::SetFrameDecryptor( |
| 459 | rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor) { |
| 460 | RTC_DCHECK_RUN_ON(&network_tc_); |
| 461 | if (buffered_frame_decryptor_ == nullptr) { |
| 462 | buffered_frame_decryptor_ = |
| 463 | absl::make_unique<BufferedFrameDecryptor>(this, this); |
| 464 | } |
| 465 | buffered_frame_decryptor_->SetFrameDecryptor(std::move(frame_decryptor)); |
| 466 | } |
| 467 | |
Tommi | 81de14f | 2018-03-25 22:19:25 +0200 | [diff] [blame] | 468 | void RtpVideoStreamReceiver::UpdateRtt(int64_t max_rtt_ms) { |
tommi | f284b7f | 2017-02-27 01:59:36 -0800 | [diff] [blame] | 469 | if (nack_module_) |
| 470 | nack_module_->UpdateRtt(max_rtt_ms); |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 471 | } |
| 472 | |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 473 | absl::optional<int64_t> RtpVideoStreamReceiver::LastReceivedPacketMs() const { |
philipel | 3184f8e | 2017-05-18 08:08:53 -0700 | [diff] [blame] | 474 | return packet_buffer_->LastReceivedPacketMs(); |
| 475 | } |
| 476 | |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 477 | absl::optional<int64_t> RtpVideoStreamReceiver::LastReceivedKeyframePacketMs() |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 478 | const { |
philipel | 3184f8e | 2017-05-18 08:08:53 -0700 | [diff] [blame] | 479 | return packet_buffer_->LastReceivedKeyframePacketMs(); |
| 480 | } |
| 481 | |
eladalon | c0d481a | 2017-08-02 07:39:07 -0700 | [diff] [blame] | 482 | void RtpVideoStreamReceiver::AddSecondarySink(RtpPacketSinkInterface* sink) { |
eladalon | 8b07305 | 2017-08-25 00:49:08 -0700 | [diff] [blame] | 483 | RTC_DCHECK_CALLED_SEQUENTIALLY(&worker_task_checker_); |
Steve Anton | bd631a0 | 2019-03-28 10:51:27 -0700 | [diff] [blame] | 484 | RTC_DCHECK(!absl::c_linear_search(secondary_sinks_, sink)); |
eladalon | c0d481a | 2017-08-02 07:39:07 -0700 | [diff] [blame] | 485 | secondary_sinks_.push_back(sink); |
| 486 | } |
| 487 | |
| 488 | void RtpVideoStreamReceiver::RemoveSecondarySink( |
| 489 | const RtpPacketSinkInterface* sink) { |
eladalon | 8b07305 | 2017-08-25 00:49:08 -0700 | [diff] [blame] | 490 | RTC_DCHECK_CALLED_SEQUENTIALLY(&worker_task_checker_); |
Steve Anton | bd631a0 | 2019-03-28 10:51:27 -0700 | [diff] [blame] | 491 | auto it = absl::c_find(secondary_sinks_, sink); |
eladalon | c0d481a | 2017-08-02 07:39:07 -0700 | [diff] [blame] | 492 | if (it == secondary_sinks_.end()) { |
| 493 | // We might be rolling-back a call whose setup failed mid-way. In such a |
| 494 | // case, it's simpler to remove "everything" rather than remember what |
| 495 | // has already been added. |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 496 | RTC_LOG(LS_WARNING) << "Removal of unknown sink."; |
eladalon | c0d481a | 2017-08-02 07:39:07 -0700 | [diff] [blame] | 497 | return; |
| 498 | } |
| 499 | secondary_sinks_.erase(it); |
| 500 | } |
| 501 | |
Niels Möller | 2ff1f2a | 2018-08-09 16:16:34 +0200 | [diff] [blame] | 502 | void RtpVideoStreamReceiver::ReceivePacket(const RtpPacketReceived& packet) { |
| 503 | if (packet.payload_size() == 0) { |
Niels Möller | 0b92678 | 2018-08-21 17:49:24 +0200 | [diff] [blame] | 504 | // Padding or keep-alive packet. |
Niels Möller | 2ff1f2a | 2018-08-09 16:16:34 +0200 | [diff] [blame] | 505 | // TODO(nisse): Could drop empty packets earlier, but need to figure out how |
| 506 | // they should be counted in stats. |
Niels Möller | 0b92678 | 2018-08-21 17:49:24 +0200 | [diff] [blame] | 507 | NotifyReceiverOfEmptyPacket(packet.SequenceNumber()); |
nisse | 30e8931 | 2017-05-29 08:16:37 -0700 | [diff] [blame] | 508 | return; |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 509 | } |
Niels Möller | 2ff1f2a | 2018-08-09 16:16:34 +0200 | [diff] [blame] | 510 | if (packet.PayloadType() == config_.rtp.red_payload_type) { |
Niels Möller | 1f3206c | 2018-09-14 08:26:32 +0200 | [diff] [blame] | 511 | ParseAndHandleEncapsulatingHeader(packet); |
Niels Möller | 2ff1f2a | 2018-08-09 16:16:34 +0200 | [diff] [blame] | 512 | return; |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 513 | } |
Niels Möller | 2ff1f2a | 2018-08-09 16:16:34 +0200 | [diff] [blame] | 514 | |
| 515 | const auto codec_type_it = pt_codec_type_.find(packet.PayloadType()); |
| 516 | if (codec_type_it == pt_codec_type_.end()) { |
| 517 | return; |
| 518 | } |
| 519 | auto depacketizer = |
| 520 | absl::WrapUnique(RtpDepacketizer::Create(codec_type_it->second)); |
| 521 | |
| 522 | if (!depacketizer) { |
| 523 | RTC_LOG(LS_ERROR) << "Failed to create depacketizer."; |
| 524 | return; |
| 525 | } |
| 526 | RtpDepacketizer::ParsedPayload parsed_payload; |
| 527 | if (!depacketizer->Parse(&parsed_payload, packet.payload().data(), |
| 528 | packet.payload().size())) { |
| 529 | RTC_LOG(LS_WARNING) << "Failed parsing payload."; |
| 530 | return; |
| 531 | } |
| 532 | |
Niels Möller | 125b5d6 | 2019-03-11 16:11:07 +0100 | [diff] [blame] | 533 | RTPHeader rtp_header; |
| 534 | packet.GetHeader(&rtp_header); |
| 535 | RTPVideoHeader video_header = parsed_payload.video_header(); |
| 536 | video_header.rotation = kVideoRotation_0; |
| 537 | video_header.content_type = VideoContentType::UNSPECIFIED; |
| 538 | video_header.video_timing.flags = VideoSendTiming::kInvalid; |
| 539 | video_header.is_last_packet_in_frame = rtp_header.markerBit; |
| 540 | video_header.frame_marking.temporal_id = kNoTemporalIdx; |
Johnny Lee | 1a1c52b | 2019-02-08 14:25:40 -0500 | [diff] [blame] | 541 | |
Ilya Nikolaevskiy | 5546aef | 2018-12-04 15:54:52 +0100 | [diff] [blame] | 542 | if (parsed_payload.video_header().codec == kVideoCodecVP9) { |
| 543 | const RTPVideoHeaderVP9& codec_header = absl::get<RTPVideoHeaderVP9>( |
| 544 | parsed_payload.video_header().video_type_header); |
Niels Möller | 125b5d6 | 2019-03-11 16:11:07 +0100 | [diff] [blame] | 545 | video_header.is_last_packet_in_frame |= codec_header.end_of_frame; |
| 546 | video_header.is_first_packet_in_frame |= codec_header.beginning_of_frame; |
Ilya Nikolaevskiy | 5546aef | 2018-12-04 15:54:52 +0100 | [diff] [blame] | 547 | } |
Niels Möller | 2ff1f2a | 2018-08-09 16:16:34 +0200 | [diff] [blame] | 548 | |
Niels Möller | 125b5d6 | 2019-03-11 16:11:07 +0100 | [diff] [blame] | 549 | packet.GetExtension<VideoOrientation>(&video_header.rotation); |
| 550 | packet.GetExtension<VideoContentTypeExtension>(&video_header.content_type); |
| 551 | packet.GetExtension<VideoTimingExtension>(&video_header.video_timing); |
| 552 | packet.GetExtension<PlayoutDelayLimits>(&video_header.playout_delay); |
| 553 | packet.GetExtension<FrameMarkingExtension>(&video_header.frame_marking); |
Johnny Lee | 1a1c52b | 2019-02-08 14:25:40 -0500 | [diff] [blame] | 554 | |
Niels Möller | 125b5d6 | 2019-03-11 16:11:07 +0100 | [diff] [blame] | 555 | video_header.color_space = packet.GetExtension<ColorSpaceExtension>(); |
Niels Möller | 8f7ce22 | 2019-03-21 15:43:58 +0100 | [diff] [blame] | 556 | if (video_header.color_space || |
| 557 | parsed_payload.frame_type == VideoFrameType::kVideoFrameKey) { |
Johannes Kron | d0b69a8 | 2018-12-03 14:18:53 +0100 | [diff] [blame] | 558 | // Store color space since it's only transmitted when changed or for key |
| 559 | // frames. Color space will be cleared if a key frame is transmitted without |
| 560 | // color space information. |
Niels Möller | 125b5d6 | 2019-03-11 16:11:07 +0100 | [diff] [blame] | 561 | last_color_space_ = video_header.color_space; |
Johannes Kron | d0b69a8 | 2018-12-03 14:18:53 +0100 | [diff] [blame] | 562 | } else if (last_color_space_) { |
Niels Möller | 125b5d6 | 2019-03-11 16:11:07 +0100 | [diff] [blame] | 563 | video_header.color_space = last_color_space_; |
Johannes Kron | d0b69a8 | 2018-12-03 14:18:53 +0100 | [diff] [blame] | 564 | } |
Johnny Lee | 1a1c52b | 2019-02-08 14:25:40 -0500 | [diff] [blame] | 565 | |
philipel | 2837edc | 2018-10-02 13:55:47 +0200 | [diff] [blame] | 566 | absl::optional<RtpGenericFrameDescriptor> generic_descriptor_wire; |
| 567 | generic_descriptor_wire.emplace(); |
Elad Alon | ccb9b75 | 2019-02-19 13:01:31 +0100 | [diff] [blame] | 568 | const bool generic_descriptor_v00 = |
| 569 | packet.GetExtension<RtpGenericFrameDescriptorExtension00>( |
| 570 | &generic_descriptor_wire.value()); |
| 571 | const bool generic_descriptor_v01 = |
| 572 | packet.GetExtension<RtpGenericFrameDescriptorExtension01>( |
| 573 | &generic_descriptor_wire.value()); |
| 574 | if (generic_descriptor_v00 && generic_descriptor_v01) { |
| 575 | RTC_LOG(LS_WARNING) << "RTP packet had two different GFD versions."; |
| 576 | return; |
| 577 | } |
| 578 | |
| 579 | if (generic_descriptor_v00 || generic_descriptor_v01) { |
| 580 | if (generic_descriptor_v00) { |
| 581 | generic_descriptor_wire->SetByteRepresentation( |
| 582 | packet.GetRawExtension<RtpGenericFrameDescriptorExtension00>()); |
| 583 | } else { |
| 584 | generic_descriptor_wire->SetByteRepresentation( |
| 585 | packet.GetRawExtension<RtpGenericFrameDescriptorExtension01>()); |
| 586 | } |
| 587 | |
Niels Möller | 125b5d6 | 2019-03-11 16:11:07 +0100 | [diff] [blame] | 588 | video_header.is_first_packet_in_frame = |
philipel | 2837edc | 2018-10-02 13:55:47 +0200 | [diff] [blame] | 589 | generic_descriptor_wire->FirstPacketInSubFrame(); |
Niels Möller | 125b5d6 | 2019-03-11 16:11:07 +0100 | [diff] [blame] | 590 | video_header.is_last_packet_in_frame = |
| 591 | rtp_header.markerBit || generic_descriptor_wire->LastPacketInSubFrame(); |
philipel | fab9129 | 2018-10-17 14:36:08 +0200 | [diff] [blame] | 592 | |
| 593 | if (generic_descriptor_wire->FirstPacketInSubFrame()) { |
Niels Möller | 125b5d6 | 2019-03-11 16:11:07 +0100 | [diff] [blame] | 594 | parsed_payload.frame_type = |
philipel | fab9129 | 2018-10-17 14:36:08 +0200 | [diff] [blame] | 595 | generic_descriptor_wire->FrameDependenciesDiffs().empty() |
Niels Möller | 8f7ce22 | 2019-03-21 15:43:58 +0100 | [diff] [blame] | 596 | ? VideoFrameType::kVideoFrameKey |
| 597 | : VideoFrameType::kVideoFrameDelta; |
philipel | fab9129 | 2018-10-17 14:36:08 +0200 | [diff] [blame] | 598 | } |
| 599 | |
Niels Möller | 125b5d6 | 2019-03-11 16:11:07 +0100 | [diff] [blame] | 600 | video_header.width = generic_descriptor_wire->Width(); |
| 601 | video_header.height = generic_descriptor_wire->Height(); |
philipel | 2837edc | 2018-10-02 13:55:47 +0200 | [diff] [blame] | 602 | } else { |
| 603 | generic_descriptor_wire.reset(); |
philipel | b3e42a4 | 2018-09-13 10:57:14 +0200 | [diff] [blame] | 604 | } |
| 605 | |
Niels Möller | 2ff1f2a | 2018-08-09 16:16:34 +0200 | [diff] [blame] | 606 | OnReceivedPayloadData(parsed_payload.payload, parsed_payload.payload_length, |
Niels Möller | 125b5d6 | 2019-03-11 16:11:07 +0100 | [diff] [blame] | 607 | rtp_header, video_header, parsed_payload.frame_type, |
| 608 | generic_descriptor_wire, packet.recovered()); |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 609 | } |
| 610 | |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 611 | void RtpVideoStreamReceiver::ParseAndHandleEncapsulatingHeader( |
Niels Möller | 1f3206c | 2018-09-14 08:26:32 +0200 | [diff] [blame] | 612 | const RtpPacketReceived& packet) { |
eladalon | 8b07305 | 2017-08-25 00:49:08 -0700 | [diff] [blame] | 613 | RTC_DCHECK_CALLED_SEQUENTIALLY(&worker_task_checker_); |
Niels Möller | 1f3206c | 2018-09-14 08:26:32 +0200 | [diff] [blame] | 614 | if (packet.PayloadType() == config_.rtp.red_payload_type && |
| 615 | packet.payload_size() > 0) { |
| 616 | if (packet.payload()[0] == config_.rtp.ulpfec_payload_type) { |
| 617 | rtp_receive_statistics_->FecPacketReceived(packet); |
Peter Boström | 0b25072 | 2016-04-22 18:23:15 +0200 | [diff] [blame] | 618 | // Notify video_receiver about received FEC packets to avoid NACKing these |
| 619 | // packets. |
Niels Möller | 1f3206c | 2018-09-14 08:26:32 +0200 | [diff] [blame] | 620 | NotifyReceiverOfEmptyPacket(packet.SequenceNumber()); |
asapersson@webrtc.org | 37c0559 | 2015-01-28 13:58:27 +0000 | [diff] [blame] | 621 | } |
Niels Möller | 1f3206c | 2018-09-14 08:26:32 +0200 | [diff] [blame] | 622 | RTPHeader header; |
| 623 | packet.GetHeader(&header); |
Niels Möller | 3f027b3 | 2018-03-14 08:04:58 +0100 | [diff] [blame] | 624 | if (ulpfec_receiver_->AddReceivedRedPacket( |
Niels Möller | 1f3206c | 2018-09-14 08:26:32 +0200 | [diff] [blame] | 625 | header, packet.data(), packet.size(), |
| 626 | config_.rtp.ulpfec_payload_type) != 0) { |
nisse | 30e8931 | 2017-05-29 08:16:37 -0700 | [diff] [blame] | 627 | return; |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 628 | } |
nisse | 30e8931 | 2017-05-29 08:16:37 -0700 | [diff] [blame] | 629 | ulpfec_receiver_->ProcessReceivedFec(); |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 630 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 631 | } |
| 632 | |
Niels Möller | bc01047 | 2018-03-23 13:22:29 +0100 | [diff] [blame] | 633 | // In the case of a video stream without picture ids and no rtx the |
| 634 | // RtpFrameReferenceFinder will need to know about padding to |
| 635 | // correctly calculate frame references. |
| 636 | void RtpVideoStreamReceiver::NotifyReceiverOfEmptyPacket(uint16_t seq_num) { |
| 637 | reference_finder_->PaddingReceived(seq_num); |
| 638 | packet_buffer_->PaddingReceived(seq_num); |
Niels Möller | bc01047 | 2018-03-23 13:22:29 +0100 | [diff] [blame] | 639 | if (nack_module_) { |
Ying Wang | b32bb95 | 2018-10-31 10:12:27 +0100 | [diff] [blame] | 640 | nack_module_->OnReceivedPacket(seq_num, /* is_keyframe = */ false, |
| 641 | /* is _recovered = */ false); |
asapersson@webrtc.org | 37c0559 | 2015-01-28 13:58:27 +0000 | [diff] [blame] | 642 | } |
Elad Alon | 7d6a4c0 | 2019-02-25 13:00:51 +0100 | [diff] [blame] | 643 | if (loss_notification_controller_) { |
| 644 | RTC_LOG(LS_WARNING) |
| 645 | << "LossNotificationController does not expect empty packets."; |
| 646 | } |
asapersson@webrtc.org | 37c0559 | 2015-01-28 13:58:27 +0000 | [diff] [blame] | 647 | } |
| 648 | |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 649 | bool RtpVideoStreamReceiver::DeliverRtcp(const uint8_t* rtcp_packet, |
| 650 | size_t rtcp_packet_length) { |
eladalon | 8b07305 | 2017-08-25 00:49:08 -0700 | [diff] [blame] | 651 | RTC_DCHECK_CALLED_SEQUENTIALLY(&worker_task_checker_); |
| 652 | |
| 653 | if (!receiving_) { |
| 654 | return false; |
Peter Boström | 4fa7eca | 2016-03-02 15:05:53 +0100 | [diff] [blame] | 655 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 656 | |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 657 | rtp_rtcp_->IncomingRtcpPacket(rtcp_packet, rtcp_packet_length); |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 658 | |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 659 | int64_t rtt = 0; |
Niels Möller | 2ff1f2a | 2018-08-09 16:16:34 +0200 | [diff] [blame] | 660 | rtp_rtcp_->RTT(config_.rtp.remote_ssrc, &rtt, nullptr, nullptr, nullptr); |
minyue@webrtc.org | 2c0cdbc | 2014-10-09 10:52:43 +0000 | [diff] [blame] | 661 | if (rtt == 0) { |
| 662 | // Waiting for valid rtt. |
Peter Boström | d1d66ba | 2016-02-08 14:07:14 +0100 | [diff] [blame] | 663 | return true; |
minyue@webrtc.org | 2c0cdbc | 2014-10-09 10:52:43 +0000 | [diff] [blame] | 664 | } |
| 665 | uint32_t ntp_secs = 0; |
| 666 | uint32_t ntp_frac = 0; |
| 667 | uint32_t rtp_timestamp = 0; |
Ilya Nikolaevskiy | 7172ea1 | 2017-10-30 11:17:34 +0100 | [diff] [blame] | 668 | uint32_t recieved_ntp_secs = 0; |
| 669 | uint32_t recieved_ntp_frac = 0; |
| 670 | if (rtp_rtcp_->RemoteNTP(&ntp_secs, &ntp_frac, &recieved_ntp_secs, |
| 671 | &recieved_ntp_frac, &rtp_timestamp) != 0) { |
minyue@webrtc.org | 2c0cdbc | 2014-10-09 10:52:43 +0000 | [diff] [blame] | 672 | // Waiting for RTCP. |
Peter Boström | d1d66ba | 2016-02-08 14:07:14 +0100 | [diff] [blame] | 673 | return true; |
minyue@webrtc.org | 2c0cdbc | 2014-10-09 10:52:43 +0000 | [diff] [blame] | 674 | } |
Ilya Nikolaevskiy | 7172ea1 | 2017-10-30 11:17:34 +0100 | [diff] [blame] | 675 | NtpTime recieved_ntp(recieved_ntp_secs, recieved_ntp_frac); |
| 676 | int64_t time_since_recieved = |
| 677 | clock_->CurrentNtpInMilliseconds() - recieved_ntp.ToMs(); |
| 678 | // Don't use old SRs to estimate time. |
| 679 | if (time_since_recieved <= 1) { |
| 680 | ntp_estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp); |
| 681 | } |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 682 | |
Peter Boström | d1d66ba | 2016-02-08 14:07:14 +0100 | [diff] [blame] | 683 | return true; |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 684 | } |
| 685 | |
philipel | d4fac69 | 2017-09-04 07:03:46 -0700 | [diff] [blame] | 686 | void RtpVideoStreamReceiver::FrameContinuous(int64_t picture_id) { |
tommi | f284b7f | 2017-02-27 01:59:36 -0800 | [diff] [blame] | 687 | if (!nack_module_) |
| 688 | return; |
| 689 | |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 690 | int seq_num = -1; |
| 691 | { |
| 692 | rtc::CritScope lock(&last_seq_num_cs_); |
| 693 | auto seq_num_it = last_seq_num_for_pic_id_.find(picture_id); |
| 694 | if (seq_num_it != last_seq_num_for_pic_id_.end()) |
| 695 | seq_num = seq_num_it->second; |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 696 | } |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 697 | if (seq_num != -1) |
| 698 | nack_module_->ClearUpTo(seq_num); |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 699 | } |
| 700 | |
philipel | d4fac69 | 2017-09-04 07:03:46 -0700 | [diff] [blame] | 701 | void RtpVideoStreamReceiver::FrameDecoded(int64_t picture_id) { |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 702 | int seq_num = -1; |
| 703 | { |
| 704 | rtc::CritScope lock(&last_seq_num_cs_); |
| 705 | auto seq_num_it = last_seq_num_for_pic_id_.find(picture_id); |
| 706 | if (seq_num_it != last_seq_num_for_pic_id_.end()) { |
| 707 | seq_num = seq_num_it->second; |
| 708 | last_seq_num_for_pic_id_.erase(last_seq_num_for_pic_id_.begin(), |
| 709 | ++seq_num_it); |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 710 | } |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 711 | } |
| 712 | if (seq_num != -1) { |
| 713 | packet_buffer_->ClearTo(seq_num); |
| 714 | reference_finder_->ClearTo(seq_num); |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 715 | } |
| 716 | } |
| 717 | |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 718 | void RtpVideoStreamReceiver::SignalNetworkState(NetworkState state) { |
mflodman | dc7d0d2 | 2016-05-06 05:32:22 -0700 | [diff] [blame] | 719 | rtp_rtcp_->SetRTCPStatus(state == kNetworkUp ? config_.rtp.rtcp_mode |
| 720 | : RtcpMode::kOff); |
| 721 | } |
| 722 | |
Ilya Nikolaevskiy | d397a0d | 2018-02-21 15:57:09 +0100 | [diff] [blame] | 723 | int RtpVideoStreamReceiver::GetUniqueFramesSeen() const { |
| 724 | return packet_buffer_->GetUniqueFramesSeen(); |
| 725 | } |
| 726 | |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 727 | void RtpVideoStreamReceiver::StartReceive() { |
eladalon | 8b07305 | 2017-08-25 00:49:08 -0700 | [diff] [blame] | 728 | RTC_DCHECK_CALLED_SEQUENTIALLY(&worker_task_checker_); |
mflodman@webrtc.org | ad4ee36 | 2011-11-28 22:39:24 +0000 | [diff] [blame] | 729 | receiving_ = true; |
| 730 | } |
| 731 | |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 732 | void RtpVideoStreamReceiver::StopReceive() { |
eladalon | 8b07305 | 2017-08-25 00:49:08 -0700 | [diff] [blame] | 733 | RTC_DCHECK_CALLED_SEQUENTIALLY(&worker_task_checker_); |
mflodman@webrtc.org | ad4ee36 | 2011-11-28 22:39:24 +0000 | [diff] [blame] | 734 | receiving_ = false; |
| 735 | } |
| 736 | |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 737 | void RtpVideoStreamReceiver::UpdateHistograms() { |
brandtr | d55c3f6 | 2016-10-31 04:51:33 -0700 | [diff] [blame] | 738 | FecPacketCounter counter = ulpfec_receiver_->GetPacketCounter(); |
asapersson | 0c43f77 | 2016-11-30 01:42:26 -0800 | [diff] [blame] | 739 | if (counter.first_packet_time_ms == -1) |
| 740 | return; |
| 741 | |
| 742 | int64_t elapsed_sec = |
| 743 | (clock_->TimeInMilliseconds() - counter.first_packet_time_ms) / 1000; |
| 744 | if (elapsed_sec < metrics::kMinRunTimeInSeconds) |
| 745 | return; |
| 746 | |
mflodman | dc7d0d2 | 2016-05-06 05:32:22 -0700 | [diff] [blame] | 747 | if (counter.num_packets > 0) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 748 | RTC_HISTOGRAM_PERCENTAGE( |
mflodman | dc7d0d2 | 2016-05-06 05:32:22 -0700 | [diff] [blame] | 749 | "WebRTC.Video.ReceivedFecPacketsInPercent", |
| 750 | static_cast<int>(counter.num_fec_packets * 100 / counter.num_packets)); |
| 751 | } |
| 752 | if (counter.num_fec_packets > 0) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 753 | RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.RecoveredMediaPacketsInPercentOfFec", |
| 754 | static_cast<int>(counter.num_recovered_packets * |
| 755 | 100 / counter.num_fec_packets)); |
mflodman | dc7d0d2 | 2016-05-06 05:32:22 -0700 | [diff] [blame] | 756 | } |
| 757 | } |
| 758 | |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 759 | void RtpVideoStreamReceiver::InsertSpsPpsIntoTracker(uint8_t payload_type) { |
philipel | 022b54e | 2016-12-20 04:15:59 -0800 | [diff] [blame] | 760 | auto codec_params_it = pt_codec_params_.find(payload_type); |
| 761 | if (codec_params_it == pt_codec_params_.end()) |
| 762 | return; |
| 763 | |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 764 | RTC_LOG(LS_INFO) << "Found out of band supplied codec parameters for" |
| 765 | << " payload type: " << static_cast<int>(payload_type); |
philipel | 022b54e | 2016-12-20 04:15:59 -0800 | [diff] [blame] | 766 | |
| 767 | H264SpropParameterSets sprop_decoder; |
| 768 | auto sprop_base64_it = |
| 769 | codec_params_it->second.find(cricket::kH264FmtpSpropParameterSets); |
| 770 | |
| 771 | if (sprop_base64_it == codec_params_it->second.end()) |
| 772 | return; |
| 773 | |
johan | 62d02c3 | 2017-01-24 04:38:27 -0800 | [diff] [blame] | 774 | if (!sprop_decoder.DecodeSprop(sprop_base64_it->second.c_str())) |
philipel | 022b54e | 2016-12-20 04:15:59 -0800 | [diff] [blame] | 775 | return; |
| 776 | |
johan | d2b092f | 2017-01-24 02:38:17 -0800 | [diff] [blame] | 777 | tracker_.InsertSpsPpsNalus(sprop_decoder.sps_nalu(), |
| 778 | sprop_decoder.pps_nalu()); |
philipel | 022b54e | 2016-12-20 04:15:59 -0800 | [diff] [blame] | 779 | } |
| 780 | |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 781 | std::vector<webrtc::RtpSource> RtpVideoStreamReceiver::GetSources() const { |
| 782 | int64_t now_ms = rtc::TimeMillis(); |
| 783 | std::vector<RtpSource> sources; |
| 784 | { |
| 785 | rtc::CritScope cs(&rtp_sources_lock_); |
| 786 | sources = contributing_sources_.GetSources(now_ms); |
| 787 | if (last_received_rtp_system_time_ms_ >= |
| 788 | now_ms - ContributingSources::kHistoryMs) { |
| 789 | sources.emplace_back(*last_received_rtp_system_time_ms_, |
| 790 | config_.rtp.remote_ssrc, RtpSourceType::SSRC); |
| 791 | } |
| 792 | } |
| 793 | return sources; |
| 794 | } |
| 795 | |
mflodman@webrtc.org | ad4ee36 | 2011-11-28 22:39:24 +0000 | [diff] [blame] | 796 | } // namespace webrtc |