blob: f1e530d3a7586dfac75fb06c192755ec4d75389c [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
leozwang@webrtc.org39e96592012-03-01 18:22:48 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
nisseb1f2ff92017-06-09 04:01:55 -070011#include "webrtc/video/rtp_video_stream_receiver.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
mflodman@webrtc.org4fd55272013-02-06 17:46:39 +000013#include <vector>
philipelfd5a20f2016-11-15 00:57:57 -080014#include <utility>
mflodman@webrtc.org4fd55272013-02-06 17:46:39 +000015
mflodman4cd27902016-08-05 06:28:45 -070016#include "webrtc/base/checks.h"
tommidea489f2017-03-03 03:20:24 -080017#include "webrtc/base/location.h"
Peter Boström415d2cd2015-10-26 11:35:17 +010018#include "webrtc/base/logging.h"
mflodmancfc8e3b2016-05-03 21:22:04 -070019#include "webrtc/common_types.h"
Peter Boström9c017252016-02-26 16:26:20 +010020#include "webrtc/config.h"
philipel022b54e2016-12-20 04:15:59 -080021#include "webrtc/media/base/mediaconstants.h"
mflodmanc0e58a32016-04-25 01:26:26 -070022#include "webrtc/modules/pacing/packet_router.h"
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000023#include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010024#include "webrtc/modules/rtp_rtcp/include/receive_statistics.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010025#include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h"
26#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010027#include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h"
28#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
brandtrd55c3f62016-10-31 04:51:33 -070029#include "webrtc/modules/rtp_rtcp/include/ulpfec_receiver.h"
nisse38cc1d62017-02-13 05:59:46 -080030#include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h"
31#include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h"
philipelfd5a20f2016-11-15 00:57:57 -080032#include "webrtc/modules/video_coding/frame_object.h"
philipel022b54e2016-12-20 04:15:59 -080033#include "webrtc/modules/video_coding/h264_sprop_parameter_sets.h"
philipelfd5a20f2016-11-15 00:57:57 -080034#include "webrtc/modules/video_coding/h264_sps_pps_tracker.h"
35#include "webrtc/modules/video_coding/packet_buffer.h"
Peter Boström0b250722016-04-22 18:23:15 +020036#include "webrtc/modules/video_coding/video_coding_impl.h"
philipelfd5a20f2016-11-15 00:57:57 -080037#include "webrtc/system_wrappers/include/field_trial.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010038#include "webrtc/system_wrappers/include/metrics.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010039#include "webrtc/system_wrappers/include/timestamp_extrapolator.h"
mflodmancfc8e3b2016-05-03 21:22:04 -070040#include "webrtc/video/receive_statistics_proxy.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000041
42namespace webrtc {
43
philipelfd5a20f2016-11-15 00:57:57 -080044namespace {
45constexpr int kPacketBufferStartSize = 32;
46constexpr int kPacketBufferMaxSixe = 2048;
47}
48
mflodmanc0e58a32016-04-25 01:26:26 -070049std::unique_ptr<RtpRtcp> CreateRtpRtcpModule(
50 ReceiveStatistics* receive_statistics,
51 Transport* outgoing_transport,
52 RtcpRttStats* rtt_stats,
53 RtcpPacketTypeCounterObserver* rtcp_packet_type_counter_observer,
nisse15389c02017-01-24 02:36:58 -080054 TransportSequenceNumberAllocator* transport_sequence_number_allocator) {
mflodmanc0e58a32016-04-25 01:26:26 -070055 RtpRtcp::Configuration configuration;
56 configuration.audio = false;
57 configuration.receiver_only = true;
58 configuration.receive_statistics = receive_statistics;
59 configuration.outgoing_transport = outgoing_transport;
60 configuration.intra_frame_callback = nullptr;
61 configuration.rtt_stats = rtt_stats;
62 configuration.rtcp_packet_type_counter_observer =
63 rtcp_packet_type_counter_observer;
mflodmanc0e58a32016-04-25 01:26:26 -070064 configuration.transport_sequence_number_allocator =
65 transport_sequence_number_allocator;
66 configuration.send_bitrate_observer = nullptr;
67 configuration.send_frame_count_observer = nullptr;
68 configuration.send_side_delay_observer = nullptr;
asapersson35151f32016-05-02 23:44:01 -070069 configuration.send_packet_observer = nullptr;
mflodmanc0e58a32016-04-25 01:26:26 -070070 configuration.bandwidth_callback = nullptr;
71 configuration.transport_feedback_callback = nullptr;
72
73 std::unique_ptr<RtpRtcp> rtp_rtcp(RtpRtcp::CreateRtpRtcp(configuration));
mflodmanc0e58a32016-04-25 01:26:26 -070074 rtp_rtcp->SetRTCPStatus(RtcpMode::kCompound);
75
76 return rtp_rtcp;
77}
78
stefan@webrtc.orgeb24b042014-10-14 11:40:13 +000079static const int kPacketLogIntervalMs = 10000;
80
nisseb1f2ff92017-06-09 04:01:55 -070081RtpVideoStreamReceiver::RtpVideoStreamReceiver(
mflodmanfa666592016-04-28 23:15:33 -070082 Transport* transport,
83 RtcpRttStats* rtt_stats,
mflodmancfc8e3b2016-05-03 21:22:04 -070084 PacketRouter* packet_router,
Tommi733b5472016-06-10 17:58:01 +020085 const VideoReceiveStream::Config* config,
mflodmandc7d0d22016-05-06 05:32:22 -070086 ReceiveStatisticsProxy* receive_stats_proxy,
Erik Språng737336d2016-07-29 12:59:36 +020087 ProcessThread* process_thread,
philipelfd5a20f2016-11-15 00:57:57 -080088 NackSender* nack_sender,
89 KeyFrameRequestSender* keyframe_request_sender,
90 video_coding::OnCompleteFrameCallback* complete_frame_callback,
91 VCMTiming* timing)
Tommi97888bd2016-01-21 23:24:59 +010092 : clock_(Clock::GetRealTimeClock()),
Tommi733b5472016-06-10 17:58:01 +020093 config_(*config),
mflodmanc0e58a32016-04-25 01:26:26 -070094 packet_router_(packet_router),
mflodmandc7d0d22016-05-06 05:32:22 -070095 process_thread_(process_thread),
Peter Boström4fa7eca2016-03-02 15:05:53 +010096 ntp_estimator_(clock_),
Peter Boström4fa7eca2016-03-02 15:05:53 +010097 rtp_header_parser_(RtpHeaderParser::Create()),
98 rtp_receiver_(RtpReceiver::CreateVideoReceiver(clock_,
99 this,
mflodmanfa666592016-04-28 23:15:33 -0700100 this,
Peter Boström4fa7eca2016-03-02 15:05:53 +0100101 &rtp_payload_registry_)),
102 rtp_receive_statistics_(ReceiveStatistics::Create(clock_)),
brandtrd55c3f62016-10-31 04:51:33 -0700103 ulpfec_receiver_(UlpfecReceiver::Create(this)),
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000104 receiving_(false),
solenberg@webrtc.org3fb8f7b2014-03-24 20:28:11 +0000105 restored_packet_in_use_(false),
mflodmanc0e58a32016-04-25 01:26:26 -0700106 last_packet_log_ms_(-1),
107 rtp_rtcp_(CreateRtpRtcpModule(rtp_receive_statistics_.get(),
108 transport,
109 rtt_stats,
mflodmancfc8e3b2016-05-03 21:22:04 -0700110 receive_stats_proxy,
nisse15389c02017-01-24 02:36:58 -0800111 packet_router)),
philipelfd5a20f2016-11-15 00:57:57 -0800112 complete_frame_callback_(complete_frame_callback),
113 keyframe_request_sender_(keyframe_request_sender),
philipel2c53b132017-05-16 08:06:30 -0700114 timing_(timing),
115 has_received_frame_(false) {
nissefdbfdc92017-03-31 05:44:52 -0700116 packet_router_->AddReceiveRtpModule(rtp_rtcp_.get());
mflodmancfc8e3b2016-05-03 21:22:04 -0700117 rtp_receive_statistics_->RegisterRtpStatisticsCallback(receive_stats_proxy);
118 rtp_receive_statistics_->RegisterRtcpStatisticsCallback(receive_stats_proxy);
119
Tommi733b5472016-06-10 17:58:01 +0200120 RTC_DCHECK(config_.rtp.rtcp_mode != RtcpMode::kOff)
mflodmancfc8e3b2016-05-03 21:22:04 -0700121 << "A stream should not be configured with RTCP disabled. This value is "
122 "reserved for internal usage.";
mflodmandc7d0d22016-05-06 05:32:22 -0700123 RTC_DCHECK(config_.rtp.remote_ssrc != 0);
124 // TODO(pbos): What's an appropriate local_ssrc for receive-only streams?
125 RTC_DCHECK(config_.rtp.local_ssrc != 0);
126 RTC_DCHECK(config_.rtp.remote_ssrc != config_.rtp.local_ssrc);
127
Tommi733b5472016-06-10 17:58:01 +0200128 rtp_rtcp_->SetRTCPStatus(config_.rtp.rtcp_mode);
129 rtp_rtcp_->SetSSRC(config_.rtp.local_ssrc);
stefanb4ab3812017-06-09 06:12:11 -0700130 rtp_rtcp_->SetRemoteSSRC(config_.rtp.remote_ssrc);
mflodmanc0e58a32016-04-25 01:26:26 -0700131 rtp_rtcp_->SetKeyFrameRequestMethod(kKeyFrameReqPliRtcp);
mflodmandc7d0d22016-05-06 05:32:22 -0700132
Tommi733b5472016-06-10 17:58:01 +0200133 for (size_t i = 0; i < config_.rtp.extensions.size(); ++i) {
134 EnableReceiveRtpHeaderExtension(config_.rtp.extensions[i].uri,
135 config_.rtp.extensions[i].id);
mflodmandc7d0d22016-05-06 05:32:22 -0700136 }
mflodmancfc8e3b2016-05-03 21:22:04 -0700137
138 static const int kMaxPacketAgeToNack = 450;
Tommi733b5472016-06-10 17:58:01 +0200139 const int max_reordering_threshold = (config_.rtp.nack.rtp_history_ms > 0)
140 ? kMaxPacketAgeToNack
141 : kDefaultMaxReorderingThreshold;
mflodmancfc8e3b2016-05-03 21:22:04 -0700142 rtp_receive_statistics_->SetMaxReorderingThreshold(max_reordering_threshold);
mflodmandc7d0d22016-05-06 05:32:22 -0700143
brandtr14742122017-01-27 04:53:07 -0800144 if (config_.rtp.rtx_ssrc) {
145 rtp_payload_registry_.SetRtxSsrc(config_.rtp.rtx_ssrc);
mflodmandc7d0d22016-05-06 05:32:22 -0700146
brandtr14742122017-01-27 04:53:07 -0800147 for (const auto& kv : config_.rtp.rtx_payload_types) {
148 RTC_DCHECK(kv.second != 0);
149 rtp_payload_registry_.SetRtxPayloadType(kv.second, kv.first);
150 }
mflodmandc7d0d22016-05-06 05:32:22 -0700151 }
152
brandtrf7c6d722016-12-08 08:25:47 -0800153 if (IsUlpfecEnabled()) {
mflodmandc7d0d22016-05-06 05:32:22 -0700154 VideoCodec ulpfec_codec = {};
155 ulpfec_codec.codecType = kVideoCodecULPFEC;
156 strncpy(ulpfec_codec.plName, "ulpfec", sizeof(ulpfec_codec.plName));
brandtrb5f2c3f2016-10-04 23:28:39 -0700157 ulpfec_codec.plType = config_.rtp.ulpfec.ulpfec_payload_type;
johan07e276c2016-12-13 02:23:03 -0800158 RTC_CHECK(AddReceiveCodec(ulpfec_codec));
brandtre6f98c72016-11-11 03:28:30 -0800159 }
mflodmandc7d0d22016-05-06 05:32:22 -0700160
brandtre6f98c72016-11-11 03:28:30 -0800161 if (IsRedEnabled()) {
mflodmandc7d0d22016-05-06 05:32:22 -0700162 VideoCodec red_codec = {};
163 red_codec.codecType = kVideoCodecRED;
164 strncpy(red_codec.plName, "red", sizeof(red_codec.plName));
brandtrb5f2c3f2016-10-04 23:28:39 -0700165 red_codec.plType = config_.rtp.ulpfec.red_payload_type;
johan07e276c2016-12-13 02:23:03 -0800166 RTC_CHECK(AddReceiveCodec(red_codec));
brandtrb5f2c3f2016-10-04 23:28:39 -0700167 if (config_.rtp.ulpfec.red_rtx_payload_type != -1) {
mflodmandc7d0d22016-05-06 05:32:22 -0700168 rtp_payload_registry_.SetRtxPayloadType(
brandtrb5f2c3f2016-10-04 23:28:39 -0700169 config_.rtp.ulpfec.red_rtx_payload_type,
170 config_.rtp.ulpfec.red_payload_type);
mflodmandc7d0d22016-05-06 05:32:22 -0700171 }
172 }
173
Tommi733b5472016-06-10 17:58:01 +0200174 if (config_.rtp.rtcp_xr.receiver_reference_time_report)
mflodmandc7d0d22016-05-06 05:32:22 -0700175 rtp_rtcp_->SetRtcpXrRrtrStatus(true);
176
177 // Stats callback for CNAME changes.
178 rtp_rtcp_->RegisterRtcpStatisticsCallback(receive_stats_proxy);
179
tommidea489f2017-03-03 03:20:24 -0800180 process_thread_->RegisterModule(rtp_rtcp_.get(), RTC_FROM_HERE);
philipelfd5a20f2016-11-15 00:57:57 -0800181
tommif284b7f2017-02-27 01:59:36 -0800182 if (config_.rtp.nack.rtp_history_ms != 0) {
183 nack_module_.reset(
184 new NackModule(clock_, nack_sender, keyframe_request_sender));
tommidea489f2017-03-03 03:20:24 -0800185 process_thread_->RegisterModule(nack_module_.get(), RTC_FROM_HERE);
tommif284b7f2017-02-27 01:59:36 -0800186 }
philipelfd5a20f2016-11-15 00:57:57 -0800187
philipela45102f2017-02-22 05:30:39 -0800188 packet_buffer_ = video_coding::PacketBuffer::Create(
189 clock_, kPacketBufferStartSize, kPacketBufferMaxSixe, this);
190 reference_finder_.reset(new video_coding::RtpFrameReferenceFinder(this));
mflodmanc0e58a32016-04-25 01:26:26 -0700191}
niklase@google.com470e71d2011-07-07 08:21:25 +0000192
nisseb1f2ff92017-06-09 04:01:55 -0700193RtpVideoStreamReceiver::~RtpVideoStreamReceiver() {
tommif284b7f2017-02-27 01:59:36 -0800194 if (nack_module_) {
195 process_thread_->DeRegisterModule(nack_module_.get());
196 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000197
tommif284b7f2017-02-27 01:59:36 -0800198 process_thread_->DeRegisterModule(rtp_rtcp_.get());
philipelfd5a20f2016-11-15 00:57:57 -0800199
nissefdbfdc92017-03-31 05:44:52 -0700200 packet_router_->RemoveReceiveRtpModule(rtp_rtcp_.get());
mflodmandc7d0d22016-05-06 05:32:22 -0700201 UpdateHistograms();
asapersson@webrtc.org0800db72015-01-15 07:40:20 +0000202}
203
nisseb1f2ff92017-06-09 04:01:55 -0700204bool RtpVideoStreamReceiver::AddReceiveCodec(
philipel022b54e2016-12-20 04:15:59 -0800205 const VideoCodec& video_codec,
206 const std::map<std::string, std::string>& codec_params) {
207 pt_codec_params_.insert(make_pair(video_codec.plType, codec_params));
208 return AddReceiveCodec(video_codec);
209}
210
nisseb1f2ff92017-06-09 04:01:55 -0700211bool RtpVideoStreamReceiver::AddReceiveCodec(const VideoCodec& video_codec) {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000212 int8_t old_pltype = -1;
magjed56124bd2016-11-24 09:34:46 -0800213 if (rtp_payload_registry_.ReceivePayloadType(video_codec, &old_pltype) !=
214 -1) {
Peter Boström4fa7eca2016-03-02 15:05:53 +0100215 rtp_payload_registry_.DeRegisterReceivePayload(old_pltype);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000216 }
magjed56124bd2016-11-24 09:34:46 -0800217 return rtp_payload_registry_.RegisterReceivePayload(video_codec) == 0;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000218}
219
nisseb1f2ff92017-06-09 04:01:55 -0700220uint32_t RtpVideoStreamReceiver::GetRemoteSsrc() const {
stefanb4ab3812017-06-09 06:12:11 -0700221 return config_.rtp.remote_ssrc;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000222}
223
nisseb1f2ff92017-06-09 04:01:55 -0700224int RtpVideoStreamReceiver::GetCsrcs(uint32_t* csrcs) const {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000225 return rtp_receiver_->CSRCs(csrcs);
226}
227
nisseb1f2ff92017-06-09 04:01:55 -0700228RtpReceiver* RtpVideoStreamReceiver::GetRtpReceiver() const {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000229 return rtp_receiver_.get();
230}
231
nisseb1f2ff92017-06-09 04:01:55 -0700232int32_t RtpVideoStreamReceiver::OnReceivedPayloadData(
mflodmanfa666592016-04-28 23:15:33 -0700233 const uint8_t* payload_data,
Peter Boström02083222016-06-14 12:52:54 +0200234 size_t payload_size,
mflodmanfa666592016-04-28 23:15:33 -0700235 const WebRtcRTPHeader* rtp_header) {
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000236 WebRtcRTPHeader rtp_header_with_ntp = *rtp_header;
wu@webrtc.org88abf112014-05-14 16:53:51 +0000237 rtp_header_with_ntp.ntp_time_ms =
Peter Boström4fa7eca2016-03-02 15:05:53 +0100238 ntp_estimator_.Estimate(rtp_header->header.timestamp);
philipela45102f2017-02-22 05:30:39 -0800239 VCMPacket packet(payload_data, payload_size, rtp_header_with_ntp);
tommif284b7f2017-02-27 01:59:36 -0800240 packet.timesNacked =
241 nack_module_ ? nack_module_->OnReceivedPacket(packet) : -1;
philipelfd5a20f2016-11-15 00:57:57 -0800242
philipel54ca9192017-03-21 05:45:18 -0700243 // In the case of a video stream without picture ids and no rtx the
244 // RtpFrameReferenceFinder will need to know about padding to
245 // correctly calculate frame references.
246 if (packet.sizeBytes == 0) {
247 reference_finder_->PaddingReceived(packet.seqNum);
philipel2c9f9f22017-06-13 02:47:28 -0700248 packet_buffer_->PaddingReceived(packet.seqNum);
philipel54ca9192017-03-21 05:45:18 -0700249 return 0;
250 }
251
philipela45102f2017-02-22 05:30:39 -0800252 if (packet.codec == kVideoCodecH264) {
253 // Only when we start to receive packets will we know what payload type
254 // that will be used. When we know the payload type insert the correct
255 // sps/pps into the tracker.
256 if (packet.payloadType != last_payload_type_) {
257 last_payload_type_ = packet.payloadType;
258 InsertSpsPpsIntoTracker(packet.payloadType);
philipelfd5a20f2016-11-15 00:57:57 -0800259 }
260
philipela45102f2017-02-22 05:30:39 -0800261 switch (tracker_.CopyAndFixBitstream(&packet)) {
262 case video_coding::H264SpsPpsTracker::kRequestKeyframe:
263 keyframe_request_sender_->RequestKeyFrame();
264 FALLTHROUGH();
265 case video_coding::H264SpsPpsTracker::kDrop:
266 return 0;
267 case video_coding::H264SpsPpsTracker::kInsert:
268 break;
269 }
270
philipelfd5a20f2016-11-15 00:57:57 -0800271 } else {
philipela45102f2017-02-22 05:30:39 -0800272 uint8_t* data = new uint8_t[packet.sizeBytes];
273 memcpy(data, packet.dataPtr, packet.sizeBytes);
274 packet.dataPtr = data;
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000275 }
philipela45102f2017-02-22 05:30:39 -0800276
277 packet_buffer_->InsertPacket(&packet);
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000278 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000279}
280
nissed2ef3142017-05-11 08:00:58 -0700281// TODO(nisse): Try to delete this method. Obstacles: It is used by
nisse30e89312017-05-29 08:16:37 -0700282// ParseAndHandleEncapsulatingHeader, for handling Rtx packets, and
283// for callbacks from |ulpfec_receiver_|.
nisseb1f2ff92017-06-09 04:01:55 -0700284void RtpVideoStreamReceiver::OnRecoveredPacket(const uint8_t* rtp_packet,
285 size_t rtp_packet_length) {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000286 RTPHeader header;
287 if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length, &header)) {
nisse30e89312017-05-29 08:16:37 -0700288 return;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000289 }
290 header.payload_type_frequency = kVideoPayloadTypeFrequency;
stefan@webrtc.org01581da2014-09-04 06:48:14 +0000291 bool in_order = IsPacketInOrder(header);
nisse30e89312017-05-29 08:16:37 -0700292 ReceivePacket(rtp_packet, rtp_packet_length, header, in_order);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000293}
294
mflodmanfa666592016-04-28 23:15:33 -0700295// TODO(pbos): Remove as soon as audio can handle a changing payload type
296// without this callback.
nisseb1f2ff92017-06-09 04:01:55 -0700297int32_t RtpVideoStreamReceiver::OnInitializeDecoder(
mflodmanfa666592016-04-28 23:15:33 -0700298 const int8_t payload_type,
299 const char payload_name[RTP_PAYLOAD_NAME_SIZE],
300 const int frequency,
301 const size_t channels,
302 const uint32_t rate) {
303 RTC_NOTREACHED();
304 return 0;
305}
306
nissed2ef3142017-05-11 08:00:58 -0700307// This method handles both regular RTP packets and packets recovered
308// via FlexFEC.
nisseb1f2ff92017-06-09 04:01:55 -0700309void RtpVideoStreamReceiver::OnRtpPacket(const RtpPacketReceived& packet) {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000310 {
Tommi97888bd2016-01-21 23:24:59 +0100311 rtc::CritScope lock(&receive_cs_);
braveyao@webrtc.orgb6433b72013-07-26 09:02:46 +0000312 if (!receiving_) {
nisse38cc1d62017-02-13 05:59:46 -0800313 return;
braveyao@webrtc.orgb6433b72013-07-26 09:02:46 +0000314 }
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000315
nissed2ef3142017-05-11 08:00:58 -0700316 if (!packet.recovered()) {
317 int64_t now_ms = clock_->TimeInMilliseconds();
stefan@webrtc.orgeb24b042014-10-14 11:40:13 +0000318
nissed2ef3142017-05-11 08:00:58 -0700319 // Periodically log the RTP header of incoming packets.
320 if (now_ms - last_packet_log_ms_ > kPacketLogIntervalMs) {
321 std::stringstream ss;
322 ss << "Packet received on SSRC: " << packet.Ssrc()
323 << " with payload type: " << static_cast<int>(packet.PayloadType())
324 << ", timestamp: " << packet.Timestamp()
325 << ", sequence number: " << packet.SequenceNumber()
326 << ", arrival time: " << packet.arrival_time_ms();
327 int32_t time_offset;
328 if (packet.GetExtension<TransmissionOffset>(&time_offset)) {
329 ss << ", toffset: " << time_offset;
330 }
331 uint32_t send_time;
332 if (packet.GetExtension<AbsoluteSendTime>(&send_time)) {
333 ss << ", abs send time: " << send_time;
334 }
335 LOG(LS_INFO) << ss.str();
336 last_packet_log_ms_ = now_ms;
nisse38cc1d62017-02-13 05:59:46 -0800337 }
stefan@webrtc.orgeb24b042014-10-14 11:40:13 +0000338 }
339 }
wu@webrtc.orga9890802013-12-13 00:21:03 +0000340
nisse38cc1d62017-02-13 05:59:46 -0800341 // TODO(nisse): Delete use of GetHeader, but needs refactoring of
342 // ReceivePacket and IncomingPacket methods below.
343 RTPHeader header;
344 packet.GetHeader(&header);
345
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000346 header.payload_type_frequency = kVideoPayloadTypeFrequency;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000347
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000348 bool in_order = IsPacketInOrder(header);
nissed2ef3142017-05-11 08:00:58 -0700349 if (!packet.recovered()) {
350 // TODO(nisse): Why isn't this done for recovered packets?
351 rtp_payload_registry_.SetIncomingPayloadType(header);
352 }
nisse38cc1d62017-02-13 05:59:46 -0800353 ReceivePacket(packet.data(), packet.size(), header, in_order);
asapersson@webrtc.org1457b472014-05-26 13:06:04 +0000354 // Update receive statistics after ReceivePacket.
355 // Receive statistics will be reset if the payload type changes (make sure
356 // that the first packet is included in the stats).
nissed2ef3142017-05-11 08:00:58 -0700357 if (!packet.recovered()) {
358 // TODO(nisse): We should pass a recovered flag to stats, to aid
359 // fixing bug bugs.webrtc.org/6339.
360 rtp_receive_statistics_->IncomingPacket(
361 header, packet.size(), IsPacketRetransmitted(header, in_order));
362 }
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000363}
364
nisseb1f2ff92017-06-09 04:01:55 -0700365int32_t RtpVideoStreamReceiver::RequestKeyFrame() {
mflodmancfc8e3b2016-05-03 21:22:04 -0700366 return rtp_rtcp_->RequestKeyFrame();
367}
368
nisseb1f2ff92017-06-09 04:01:55 -0700369bool RtpVideoStreamReceiver::IsUlpfecEnabled() const {
brandtre6f98c72016-11-11 03:28:30 -0800370 return config_.rtp.ulpfec.ulpfec_payload_type != -1;
371}
372
nisseb1f2ff92017-06-09 04:01:55 -0700373bool RtpVideoStreamReceiver::IsRedEnabled() const {
brandtre6f98c72016-11-11 03:28:30 -0800374 return config_.rtp.ulpfec.red_payload_type != -1;
mflodmandc7d0d22016-05-06 05:32:22 -0700375}
376
nisseb1f2ff92017-06-09 04:01:55 -0700377bool RtpVideoStreamReceiver::IsRetransmissionsEnabled() const {
mflodmandc7d0d22016-05-06 05:32:22 -0700378 return config_.rtp.nack.rtp_history_ms > 0;
379}
380
nisseb1f2ff92017-06-09 04:01:55 -0700381void RtpVideoStreamReceiver::RequestPacketRetransmit(
mflodmandc7d0d22016-05-06 05:32:22 -0700382 const std::vector<uint16_t>& sequence_numbers) {
383 rtp_rtcp_->SendNack(sequence_numbers);
384}
385
nisseb1f2ff92017-06-09 04:01:55 -0700386int32_t RtpVideoStreamReceiver::ResendPackets(const uint16_t* sequence_numbers,
387 uint16_t length) {
mflodmancfc8e3b2016-05-03 21:22:04 -0700388 return rtp_rtcp_->SendNACK(sequence_numbers, length);
389}
390
nisseb1f2ff92017-06-09 04:01:55 -0700391void RtpVideoStreamReceiver::OnReceivedFrame(
philipelfd5a20f2016-11-15 00:57:57 -0800392 std::unique_ptr<video_coding::RtpFrameObject> frame) {
philipel2c53b132017-05-16 08:06:30 -0700393 if (!has_received_frame_) {
394 has_received_frame_ = true;
395 if (frame->FrameType() != kVideoFrameKey)
396 keyframe_request_sender_->RequestKeyFrame();
397 }
398
philipelbd26ba72017-01-29 04:04:47 -0800399 if (!frame->delayed_by_retransmission())
400 timing_->IncomingTimestamp(frame->timestamp, clock_->TimeInMilliseconds());
philipelfd5a20f2016-11-15 00:57:57 -0800401 reference_finder_->ManageFrame(std::move(frame));
402}
403
nisseb1f2ff92017-06-09 04:01:55 -0700404void RtpVideoStreamReceiver::OnCompleteFrame(
philipelfd5a20f2016-11-15 00:57:57 -0800405 std::unique_ptr<video_coding::FrameObject> frame) {
406 {
407 rtc::CritScope lock(&last_seq_num_cs_);
408 video_coding::RtpFrameObject* rtp_frame =
409 static_cast<video_coding::RtpFrameObject*>(frame.get());
410 last_seq_num_for_pic_id_[rtp_frame->picture_id] = rtp_frame->last_seq_num();
411 }
412 complete_frame_callback_->OnCompleteFrame(std::move(frame));
413}
414
nisseb1f2ff92017-06-09 04:01:55 -0700415void RtpVideoStreamReceiver::OnRttUpdate(int64_t avg_rtt_ms,
416 int64_t max_rtt_ms) {
tommif284b7f2017-02-27 01:59:36 -0800417 if (nack_module_)
418 nack_module_->UpdateRtt(max_rtt_ms);
philipelfd5a20f2016-11-15 00:57:57 -0800419}
420
nisseb1f2ff92017-06-09 04:01:55 -0700421rtc::Optional<int64_t> RtpVideoStreamReceiver::LastReceivedPacketMs() const {
philipel3184f8e2017-05-18 08:08:53 -0700422 return packet_buffer_->LastReceivedPacketMs();
423}
424
nisseb1f2ff92017-06-09 04:01:55 -0700425rtc::Optional<int64_t> RtpVideoStreamReceiver::LastReceivedKeyframePacketMs()
426 const {
philipel3184f8e2017-05-18 08:08:53 -0700427 return packet_buffer_->LastReceivedKeyframePacketMs();
428}
429
nisseb1f2ff92017-06-09 04:01:55 -0700430void RtpVideoStreamReceiver::ReceivePacket(const uint8_t* packet,
431 size_t packet_length,
432 const RTPHeader& header,
433 bool in_order) {
Peter Boström4fa7eca2016-03-02 15:05:53 +0100434 if (rtp_payload_registry_.IsEncapsulated(header)) {
nisse30e89312017-05-29 08:16:37 -0700435 ParseAndHandleEncapsulatingHeader(packet, packet_length, header);
436 return;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000437 }
438 const uint8_t* payload = packet + header.headerLength;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000439 assert(packet_length >= header.headerLength);
440 size_t payload_length = packet_length - header.headerLength;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000441 PayloadUnion payload_specific;
Peter Boström4fa7eca2016-03-02 15:05:53 +0100442 if (!rtp_payload_registry_.GetPayloadSpecifics(header.payloadType,
443 &payload_specific)) {
nisse30e89312017-05-29 08:16:37 -0700444 return;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000445 }
nisse30e89312017-05-29 08:16:37 -0700446 rtp_receiver_->IncomingRtpPacket(header, payload, payload_length,
447 payload_specific, in_order);
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000448}
449
nisseb1f2ff92017-06-09 04:01:55 -0700450void RtpVideoStreamReceiver::ParseAndHandleEncapsulatingHeader(
mflodmanfa666592016-04-28 23:15:33 -0700451 const uint8_t* packet, size_t packet_length, const RTPHeader& header) {
Peter Boström4fa7eca2016-03-02 15:05:53 +0100452 if (rtp_payload_registry_.IsRed(header)) {
453 int8_t ulpfec_pt = rtp_payload_registry_.ulpfec_payload_type();
asapersson@webrtc.org37c05592015-01-28 13:58:27 +0000454 if (packet[header.headerLength] == ulpfec_pt) {
asapersson@webrtc.org273fbbb2015-01-27 12:17:29 +0000455 rtp_receive_statistics_->FecPacketReceived(header, packet_length);
Peter Boström0b250722016-04-22 18:23:15 +0200456 // Notify video_receiver about received FEC packets to avoid NACKing these
457 // packets.
asapersson@webrtc.org37c05592015-01-28 13:58:27 +0000458 NotifyReceiverOfFecPacket(header);
459 }
brandtrd55c3f62016-10-31 04:51:33 -0700460 if (ulpfec_receiver_->AddReceivedRedPacket(header, packet, packet_length,
461 ulpfec_pt) != 0) {
nisse30e89312017-05-29 08:16:37 -0700462 return;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000463 }
nisse30e89312017-05-29 08:16:37 -0700464 ulpfec_receiver_->ProcessReceivedFec();
Peter Boström4fa7eca2016-03-02 15:05:53 +0100465 } else if (rtp_payload_registry_.IsRtx(header)) {
stefan@webrtc.org7c6ff2d2014-03-19 18:14:52 +0000466 if (header.headerLength + header.paddingLength == packet_length) {
467 // This is an empty packet and should be silently dropped before trying to
468 // parse the RTX header.
nisse30e89312017-05-29 08:16:37 -0700469 return;
stefan@webrtc.org7c6ff2d2014-03-19 18:14:52 +0000470 }
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000471 // Remove the RTX header and parse the original RTP header.
472 if (packet_length < header.headerLength)
nisse30e89312017-05-29 08:16:37 -0700473 return;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000474 if (packet_length > sizeof(restored_packet_))
nisse30e89312017-05-29 08:16:37 -0700475 return;
Tommi97888bd2016-01-21 23:24:59 +0100476 rtc::CritScope lock(&receive_cs_);
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000477 if (restored_packet_in_use_) {
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +0000478 LOG(LS_WARNING) << "Multiple RTX headers detected, dropping packet.";
nisse30e89312017-05-29 08:16:37 -0700479 return;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000480 }
Peter Boström4fa7eca2016-03-02 15:05:53 +0100481 if (!rtp_payload_registry_.RestoreOriginalPacket(
stefanb4ab3812017-06-09 06:12:11 -0700482 restored_packet_, packet, &packet_length, config_.rtp.remote_ssrc,
noahric65220a72015-10-14 11:29:49 -0700483 header)) {
Stefan Holmer10880012016-02-03 13:29:59 +0100484 LOG(LS_WARNING) << "Incoming RTX packet: Invalid RTP header ssrc: "
485 << header.ssrc << " payload type: "
486 << static_cast<int>(header.payloadType);
nisse30e89312017-05-29 08:16:37 -0700487 return;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000488 }
489 restored_packet_in_use_ = true;
nisse30e89312017-05-29 08:16:37 -0700490 OnRecoveredPacket(restored_packet_, packet_length);
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000491 restored_packet_in_use_ = false;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000492 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000493}
494
nisseb1f2ff92017-06-09 04:01:55 -0700495void RtpVideoStreamReceiver::NotifyReceiverOfFecPacket(
496 const RTPHeader& header) {
asapersson@webrtc.org37c05592015-01-28 13:58:27 +0000497 int8_t last_media_payload_type =
Peter Boström4fa7eca2016-03-02 15:05:53 +0100498 rtp_payload_registry_.last_received_media_payload_type();
asapersson@webrtc.org37c05592015-01-28 13:58:27 +0000499 if (last_media_payload_type < 0) {
500 LOG(LS_WARNING) << "Failed to get last media payload type.";
501 return;
502 }
503 // Fake an empty media packet.
504 WebRtcRTPHeader rtp_header = {};
505 rtp_header.header = header;
506 rtp_header.header.payloadType = last_media_payload_type;
507 rtp_header.header.paddingLength = 0;
508 PayloadUnion payload_specific;
Peter Boström4fa7eca2016-03-02 15:05:53 +0100509 if (!rtp_payload_registry_.GetPayloadSpecifics(last_media_payload_type,
510 &payload_specific)) {
asapersson@webrtc.org37c05592015-01-28 13:58:27 +0000511 LOG(LS_WARNING) << "Failed to get payload specifics.";
512 return;
513 }
514 rtp_header.type.Video.codec = payload_specific.Video.videoCodecType;
guoweis@webrtc.orgfdd10572015-03-12 20:50:57 +0000515 rtp_header.type.Video.rotation = kVideoRotation_0;
516 if (header.extension.hasVideoRotation) {
magjed71eb61c2016-09-08 03:24:58 -0700517 rtp_header.type.Video.rotation = header.extension.videoRotation;
guoweis@webrtc.orgfdd10572015-03-12 20:50:57 +0000518 }
ilnik00d802b2017-04-11 10:34:31 -0700519 rtp_header.type.Video.content_type = VideoContentType::UNSPECIFIED;
520 if (header.extension.hasVideoContentType) {
521 rtp_header.type.Video.content_type = header.extension.videoContentType;
522 }
isheriff6b4b5f32016-06-08 00:24:21 -0700523 rtp_header.type.Video.playout_delay = header.extension.playout_delay;
524
Peter Boström74f6e9e2016-04-04 17:56:10 +0200525 OnReceivedPayloadData(nullptr, 0, &rtp_header);
asapersson@webrtc.org37c05592015-01-28 13:58:27 +0000526}
527
nisseb1f2ff92017-06-09 04:01:55 -0700528bool RtpVideoStreamReceiver::DeliverRtcp(const uint8_t* rtcp_packet,
529 size_t rtcp_packet_length) {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000530 {
Tommi97888bd2016-01-21 23:24:59 +0100531 rtc::CritScope lock(&receive_cs_);
braveyao@webrtc.orgb6433b72013-07-26 09:02:46 +0000532 if (!receiving_) {
Peter Boströmd1d66ba2016-02-08 14:07:14 +0100533 return false;
braveyao@webrtc.orgb6433b72013-07-26 09:02:46 +0000534 }
Peter Boström4fa7eca2016-03-02 15:05:53 +0100535 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000536
Per83d09102016-04-15 14:59:13 +0200537 rtp_rtcp_->IncomingRtcpPacket(rtcp_packet, rtcp_packet_length);
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000538
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000539 int64_t rtt = 0;
Per83d09102016-04-15 14:59:13 +0200540 rtp_rtcp_->RTT(rtp_receiver_->SSRC(), &rtt, nullptr, nullptr, nullptr);
minyue@webrtc.org2c0cdbc2014-10-09 10:52:43 +0000541 if (rtt == 0) {
542 // Waiting for valid rtt.
Peter Boströmd1d66ba2016-02-08 14:07:14 +0100543 return true;
minyue@webrtc.org2c0cdbc2014-10-09 10:52:43 +0000544 }
545 uint32_t ntp_secs = 0;
546 uint32_t ntp_frac = 0;
547 uint32_t rtp_timestamp = 0;
Per83d09102016-04-15 14:59:13 +0200548 if (rtp_rtcp_->RemoteNTP(&ntp_secs, &ntp_frac, nullptr, nullptr,
549 &rtp_timestamp) != 0) {
minyue@webrtc.org2c0cdbc2014-10-09 10:52:43 +0000550 // Waiting for RTCP.
Peter Boströmd1d66ba2016-02-08 14:07:14 +0100551 return true;
minyue@webrtc.org2c0cdbc2014-10-09 10:52:43 +0000552 }
Peter Boström4fa7eca2016-03-02 15:05:53 +0100553 ntp_estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp);
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000554
Peter Boströmd1d66ba2016-02-08 14:07:14 +0100555 return true;
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000556}
557
nisseb1f2ff92017-06-09 04:01:55 -0700558void RtpVideoStreamReceiver::FrameContinuous(uint16_t picture_id) {
tommif284b7f2017-02-27 01:59:36 -0800559 if (!nack_module_)
560 return;
561
philipela45102f2017-02-22 05:30:39 -0800562 int seq_num = -1;
563 {
564 rtc::CritScope lock(&last_seq_num_cs_);
565 auto seq_num_it = last_seq_num_for_pic_id_.find(picture_id);
566 if (seq_num_it != last_seq_num_for_pic_id_.end())
567 seq_num = seq_num_it->second;
philipelfd5a20f2016-11-15 00:57:57 -0800568 }
philipela45102f2017-02-22 05:30:39 -0800569 if (seq_num != -1)
570 nack_module_->ClearUpTo(seq_num);
philipelfd5a20f2016-11-15 00:57:57 -0800571}
572
nisseb1f2ff92017-06-09 04:01:55 -0700573void RtpVideoStreamReceiver::FrameDecoded(uint16_t picture_id) {
philipela45102f2017-02-22 05:30:39 -0800574 int seq_num = -1;
575 {
576 rtc::CritScope lock(&last_seq_num_cs_);
577 auto seq_num_it = last_seq_num_for_pic_id_.find(picture_id);
578 if (seq_num_it != last_seq_num_for_pic_id_.end()) {
579 seq_num = seq_num_it->second;
580 last_seq_num_for_pic_id_.erase(last_seq_num_for_pic_id_.begin(),
581 ++seq_num_it);
philipelfd5a20f2016-11-15 00:57:57 -0800582 }
philipela45102f2017-02-22 05:30:39 -0800583 }
584 if (seq_num != -1) {
585 packet_buffer_->ClearTo(seq_num);
586 reference_finder_->ClearTo(seq_num);
philipelfd5a20f2016-11-15 00:57:57 -0800587 }
588}
589
nisseb1f2ff92017-06-09 04:01:55 -0700590void RtpVideoStreamReceiver::SignalNetworkState(NetworkState state) {
mflodmandc7d0d22016-05-06 05:32:22 -0700591 rtp_rtcp_->SetRTCPStatus(state == kNetworkUp ? config_.rtp.rtcp_mode
592 : RtcpMode::kOff);
593}
594
nisseb1f2ff92017-06-09 04:01:55 -0700595void RtpVideoStreamReceiver::StartReceive() {
Tommi97888bd2016-01-21 23:24:59 +0100596 rtc::CritScope lock(&receive_cs_);
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000597 receiving_ = true;
598}
599
nisseb1f2ff92017-06-09 04:01:55 -0700600void RtpVideoStreamReceiver::StopReceive() {
Tommi97888bd2016-01-21 23:24:59 +0100601 rtc::CritScope lock(&receive_cs_);
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000602 receiving_ = false;
603}
604
nisseb1f2ff92017-06-09 04:01:55 -0700605bool RtpVideoStreamReceiver::IsPacketInOrder(const RTPHeader& header) const {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000606 StreamStatistician* statistician =
607 rtp_receive_statistics_->GetStatistician(header.ssrc);
608 if (!statistician)
609 return false;
610 return statistician->IsPacketInOrder(header.sequenceNumber);
611}
612
nisseb1f2ff92017-06-09 04:01:55 -0700613bool RtpVideoStreamReceiver::IsPacketRetransmitted(const RTPHeader& header,
614 bool in_order) const {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000615 // Retransmissions are handled separately if RTX is enabled.
Peter Boström4fa7eca2016-03-02 15:05:53 +0100616 if (rtp_payload_registry_.RtxEnabled())
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000617 return false;
618 StreamStatistician* statistician =
619 rtp_receive_statistics_->GetStatistician(header.ssrc);
620 if (!statistician)
621 return false;
622 // Check if this is a retransmission.
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000623 int64_t min_rtt = 0;
stefanb4ab3812017-06-09 06:12:11 -0700624 rtp_rtcp_->RTT(config_.rtp.remote_ssrc, nullptr, nullptr, &min_rtt, nullptr);
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000625 return !in_order &&
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000626 statistician->IsRetransmitOfOldPacket(header, min_rtt);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000627}
mflodmandc7d0d22016-05-06 05:32:22 -0700628
nisseb1f2ff92017-06-09 04:01:55 -0700629void RtpVideoStreamReceiver::UpdateHistograms() {
brandtrd55c3f62016-10-31 04:51:33 -0700630 FecPacketCounter counter = ulpfec_receiver_->GetPacketCounter();
asapersson0c43f772016-11-30 01:42:26 -0800631 if (counter.first_packet_time_ms == -1)
632 return;
633
634 int64_t elapsed_sec =
635 (clock_->TimeInMilliseconds() - counter.first_packet_time_ms) / 1000;
636 if (elapsed_sec < metrics::kMinRunTimeInSeconds)
637 return;
638
mflodmandc7d0d22016-05-06 05:32:22 -0700639 if (counter.num_packets > 0) {
asapersson1d02d3e2016-09-09 22:40:25 -0700640 RTC_HISTOGRAM_PERCENTAGE(
mflodmandc7d0d22016-05-06 05:32:22 -0700641 "WebRTC.Video.ReceivedFecPacketsInPercent",
642 static_cast<int>(counter.num_fec_packets * 100 / counter.num_packets));
643 }
644 if (counter.num_fec_packets > 0) {
asapersson1d02d3e2016-09-09 22:40:25 -0700645 RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.RecoveredMediaPacketsInPercentOfFec",
646 static_cast<int>(counter.num_recovered_packets *
647 100 / counter.num_fec_packets));
mflodmandc7d0d22016-05-06 05:32:22 -0700648 }
649}
650
nisseb1f2ff92017-06-09 04:01:55 -0700651void RtpVideoStreamReceiver::EnableReceiveRtpHeaderExtension(
mflodmandc7d0d22016-05-06 05:32:22 -0700652 const std::string& extension, int id) {
653 // One-byte-extension local identifiers are in the range 1-14 inclusive.
654 RTC_DCHECK_GE(id, 1);
655 RTC_DCHECK_LE(id, 14);
656 RTC_DCHECK(RtpExtension::IsSupportedForVideo(extension));
657 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension(
658 StringToRtpExtensionType(extension), id));
659}
660
nisseb1f2ff92017-06-09 04:01:55 -0700661void RtpVideoStreamReceiver::InsertSpsPpsIntoTracker(uint8_t payload_type) {
philipel022b54e2016-12-20 04:15:59 -0800662 auto codec_params_it = pt_codec_params_.find(payload_type);
663 if (codec_params_it == pt_codec_params_.end())
664 return;
665
666 LOG(LS_INFO) << "Found out of band supplied codec parameters for"
johan62d02c32017-01-24 04:38:27 -0800667 << " payload type: " << static_cast<int>(payload_type);
philipel022b54e2016-12-20 04:15:59 -0800668
669 H264SpropParameterSets sprop_decoder;
670 auto sprop_base64_it =
671 codec_params_it->second.find(cricket::kH264FmtpSpropParameterSets);
672
673 if (sprop_base64_it == codec_params_it->second.end())
674 return;
675
johan62d02c32017-01-24 04:38:27 -0800676 if (!sprop_decoder.DecodeSprop(sprop_base64_it->second.c_str()))
philipel022b54e2016-12-20 04:15:59 -0800677 return;
678
johand2b092f2017-01-24 02:38:17 -0800679 tracker_.InsertSpsPpsNalus(sprop_decoder.sps_nalu(),
680 sprop_decoder.pps_nalu());
philipel022b54e2016-12-20 04:15:59 -0800681}
682
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000683} // namespace webrtc