OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 rtp_rtcp->SetSendingStatus(false); | 74 rtp_rtcp->SetSendingStatus(false); |
75 rtp_rtcp->SetSendingMediaStatus(false); | 75 rtp_rtcp->SetSendingMediaStatus(false); |
76 rtp_rtcp->SetRTCPStatus(RtcpMode::kCompound); | 76 rtp_rtcp->SetRTCPStatus(RtcpMode::kCompound); |
77 | 77 |
78 return rtp_rtcp; | 78 return rtp_rtcp; |
79 } | 79 } |
80 | 80 |
81 static const int kPacketLogIntervalMs = 10000; | 81 static const int kPacketLogIntervalMs = 10000; |
82 | 82 |
83 RtpStreamReceiver::RtpStreamReceiver( | 83 RtpStreamReceiver::RtpStreamReceiver( |
84 vcm::VideoReceiver* video_receiver, | |
85 RemoteBitrateEstimator* remote_bitrate_estimator, | 84 RemoteBitrateEstimator* remote_bitrate_estimator, |
86 Transport* transport, | 85 Transport* transport, |
87 RtcpRttStats* rtt_stats, | 86 RtcpRttStats* rtt_stats, |
88 PacketRouter* packet_router, | 87 PacketRouter* packet_router, |
89 VieRemb* remb, | 88 VieRemb* remb, |
90 const VideoReceiveStream::Config* config, | 89 const VideoReceiveStream::Config* config, |
91 ReceiveStatisticsProxy* receive_stats_proxy, | 90 ReceiveStatisticsProxy* receive_stats_proxy, |
92 ProcessThread* process_thread, | 91 ProcessThread* process_thread, |
93 NackSender* nack_sender, | 92 NackSender* nack_sender, |
94 KeyFrameRequestSender* keyframe_request_sender, | 93 KeyFrameRequestSender* keyframe_request_sender, |
95 video_coding::OnCompleteFrameCallback* complete_frame_callback, | 94 video_coding::OnCompleteFrameCallback* complete_frame_callback, |
96 VCMTiming* timing) | 95 VCMTiming* timing) |
97 : clock_(Clock::GetRealTimeClock()), | 96 : clock_(Clock::GetRealTimeClock()), |
98 config_(*config), | 97 config_(*config), |
99 video_receiver_(video_receiver), | |
100 remote_bitrate_estimator_(remote_bitrate_estimator), | 98 remote_bitrate_estimator_(remote_bitrate_estimator), |
101 packet_router_(packet_router), | 99 packet_router_(packet_router), |
102 remb_(remb), | 100 remb_(remb), |
103 process_thread_(process_thread), | 101 process_thread_(process_thread), |
104 ntp_estimator_(clock_), | 102 ntp_estimator_(clock_), |
105 rtp_header_parser_(RtpHeaderParser::Create()), | 103 rtp_header_parser_(RtpHeaderParser::Create()), |
106 rtp_receiver_(RtpReceiver::CreateVideoReceiver(clock_, | 104 rtp_receiver_(RtpReceiver::CreateVideoReceiver(clock_, |
107 this, | 105 this, |
108 this, | 106 this, |
109 &rtp_payload_registry_)), | 107 &rtp_payload_registry_)), |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 } | 182 } |
185 | 183 |
186 if (config_.rtp.rtcp_xr.receiver_reference_time_report) | 184 if (config_.rtp.rtcp_xr.receiver_reference_time_report) |
187 rtp_rtcp_->SetRtcpXrRrtrStatus(true); | 185 rtp_rtcp_->SetRtcpXrRrtrStatus(true); |
188 | 186 |
189 // Stats callback for CNAME changes. | 187 // Stats callback for CNAME changes. |
190 rtp_rtcp_->RegisterRtcpStatisticsCallback(receive_stats_proxy); | 188 rtp_rtcp_->RegisterRtcpStatisticsCallback(receive_stats_proxy); |
191 | 189 |
192 process_thread_->RegisterModule(rtp_rtcp_.get()); | 190 process_thread_->RegisterModule(rtp_rtcp_.get()); |
193 | 191 |
194 jitter_buffer_experiment_ = | 192 nack_module_.reset( |
195 field_trial::FindFullName("WebRTC-NewVideoJitterBuffer") == "Enabled"; | 193 new NackModule(clock_, nack_sender, keyframe_request_sender)); |
| 194 if (config_.rtp.nack.rtp_history_ms == 0) |
| 195 nack_module_->Stop(); |
| 196 process_thread_->RegisterModule(nack_module_.get()); |
196 | 197 |
197 if (jitter_buffer_experiment_) { | 198 packet_buffer_ = video_coding::PacketBuffer::Create( |
198 nack_module_.reset( | 199 clock_, kPacketBufferStartSize, kPacketBufferMaxSixe, this); |
199 new NackModule(clock_, nack_sender, keyframe_request_sender)); | 200 reference_finder_.reset(new video_coding::RtpFrameReferenceFinder(this)); |
200 process_thread_->RegisterModule(nack_module_.get()); | |
201 | |
202 packet_buffer_ = video_coding::PacketBuffer::Create( | |
203 clock_, kPacketBufferStartSize, kPacketBufferMaxSixe, this); | |
204 reference_finder_.reset(new video_coding::RtpFrameReferenceFinder(this)); | |
205 } | |
206 } | 201 } |
207 | 202 |
208 RtpStreamReceiver::~RtpStreamReceiver() { | 203 RtpStreamReceiver::~RtpStreamReceiver() { |
209 process_thread_->DeRegisterModule(rtp_rtcp_.get()); | 204 process_thread_->DeRegisterModule(rtp_rtcp_.get()); |
210 | 205 |
211 if (jitter_buffer_experiment_) | 206 process_thread_->DeRegisterModule(nack_module_.get()); |
212 process_thread_->DeRegisterModule(nack_module_.get()); | |
213 | 207 |
214 packet_router_->RemoveRtpModule(rtp_rtcp_.get()); | 208 packet_router_->RemoveRtpModule(rtp_rtcp_.get()); |
215 rtp_rtcp_->SetREMBStatus(false); | 209 rtp_rtcp_->SetREMBStatus(false); |
216 if (config_.rtp.remb) { | 210 if (config_.rtp.remb) { |
217 remb_->RemoveReceiveChannel(rtp_rtcp_.get()); | 211 remb_->RemoveReceiveChannel(rtp_rtcp_.get()); |
218 } | 212 } |
219 UpdateHistograms(); | 213 UpdateHistograms(); |
220 } | 214 } |
221 | 215 |
222 bool RtpStreamReceiver::AddReceiveCodec( | 216 bool RtpStreamReceiver::AddReceiveCodec( |
(...skipping 24 matching lines...) Expand all Loading... |
247 return rtp_receiver_.get(); | 241 return rtp_receiver_.get(); |
248 } | 242 } |
249 | 243 |
250 int32_t RtpStreamReceiver::OnReceivedPayloadData( | 244 int32_t RtpStreamReceiver::OnReceivedPayloadData( |
251 const uint8_t* payload_data, | 245 const uint8_t* payload_data, |
252 size_t payload_size, | 246 size_t payload_size, |
253 const WebRtcRTPHeader* rtp_header) { | 247 const WebRtcRTPHeader* rtp_header) { |
254 WebRtcRTPHeader rtp_header_with_ntp = *rtp_header; | 248 WebRtcRTPHeader rtp_header_with_ntp = *rtp_header; |
255 rtp_header_with_ntp.ntp_time_ms = | 249 rtp_header_with_ntp.ntp_time_ms = |
256 ntp_estimator_.Estimate(rtp_header->header.timestamp); | 250 ntp_estimator_.Estimate(rtp_header->header.timestamp); |
257 if (jitter_buffer_experiment_) { | 251 VCMPacket packet(payload_data, payload_size, rtp_header_with_ntp); |
258 VCMPacket packet(payload_data, payload_size, rtp_header_with_ntp); | 252 timing_->IncomingTimestamp(packet.timestamp, clock_->TimeInMilliseconds()); |
259 timing_->IncomingTimestamp(packet.timestamp, clock_->TimeInMilliseconds()); | 253 packet.timesNacked = nack_module_->OnReceivedPacket(packet); |
260 packet.timesNacked = nack_module_->OnReceivedPacket(packet); | |
261 | 254 |
262 if (packet.codec == kVideoCodecH264) { | 255 if (packet.codec == kVideoCodecH264) { |
263 // Only when we start to receive packets will we know what payload type | 256 // Only when we start to receive packets will we know what payload type |
264 // that will be used. When we know the payload type insert the correct | 257 // that will be used. When we know the payload type insert the correct |
265 // sps/pps into the tracker. | 258 // sps/pps into the tracker. |
266 if (packet.payloadType != last_payload_type_) { | 259 if (packet.payloadType != last_payload_type_) { |
267 last_payload_type_ = packet.payloadType; | 260 last_payload_type_ = packet.payloadType; |
268 InsertSpsPpsIntoTracker(packet.payloadType); | 261 InsertSpsPpsIntoTracker(packet.payloadType); |
269 } | |
270 | |
271 switch (tracker_.CopyAndFixBitstream(&packet)) { | |
272 case video_coding::H264SpsPpsTracker::kRequestKeyframe: | |
273 keyframe_request_sender_->RequestKeyFrame(); | |
274 FALLTHROUGH(); | |
275 case video_coding::H264SpsPpsTracker::kDrop: | |
276 return 0; | |
277 case video_coding::H264SpsPpsTracker::kInsert: | |
278 break; | |
279 } | |
280 } else { | |
281 uint8_t* data = new uint8_t[packet.sizeBytes]; | |
282 memcpy(data, packet.dataPtr, packet.sizeBytes); | |
283 packet.dataPtr = data; | |
284 } | 262 } |
285 | 263 |
286 packet_buffer_->InsertPacket(&packet); | 264 switch (tracker_.CopyAndFixBitstream(&packet)) { |
| 265 case video_coding::H264SpsPpsTracker::kRequestKeyframe: |
| 266 keyframe_request_sender_->RequestKeyFrame(); |
| 267 FALLTHROUGH(); |
| 268 case video_coding::H264SpsPpsTracker::kDrop: |
| 269 return 0; |
| 270 case video_coding::H264SpsPpsTracker::kInsert: |
| 271 break; |
| 272 } |
| 273 |
287 } else { | 274 } else { |
288 RTC_DCHECK(video_receiver_); | 275 uint8_t* data = new uint8_t[packet.sizeBytes]; |
289 if (video_receiver_->IncomingPacket(payload_data, payload_size, | 276 memcpy(data, packet.dataPtr, packet.sizeBytes); |
290 rtp_header_with_ntp) != 0) { | 277 packet.dataPtr = data; |
291 // Check this... | |
292 return -1; | |
293 } | |
294 } | 278 } |
| 279 |
| 280 packet_buffer_->InsertPacket(&packet); |
295 return 0; | 281 return 0; |
296 } | 282 } |
297 | 283 |
298 bool RtpStreamReceiver::OnRecoveredPacket(const uint8_t* rtp_packet, | 284 bool RtpStreamReceiver::OnRecoveredPacket(const uint8_t* rtp_packet, |
299 size_t rtp_packet_length) { | 285 size_t rtp_packet_length) { |
300 RTPHeader header; | 286 RTPHeader header; |
301 if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length, &header)) { | 287 if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length, &header)) { |
302 return false; | 288 return false; |
303 } | 289 } |
304 header.payload_type_frequency = kVideoPayloadTypeFrequency; | 290 header.payload_type_frequency = kVideoPayloadTypeFrequency; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 { | 407 { |
422 rtc::CritScope lock(&last_seq_num_cs_); | 408 rtc::CritScope lock(&last_seq_num_cs_); |
423 video_coding::RtpFrameObject* rtp_frame = | 409 video_coding::RtpFrameObject* rtp_frame = |
424 static_cast<video_coding::RtpFrameObject*>(frame.get()); | 410 static_cast<video_coding::RtpFrameObject*>(frame.get()); |
425 last_seq_num_for_pic_id_[rtp_frame->picture_id] = rtp_frame->last_seq_num(); | 411 last_seq_num_for_pic_id_[rtp_frame->picture_id] = rtp_frame->last_seq_num(); |
426 } | 412 } |
427 complete_frame_callback_->OnCompleteFrame(std::move(frame)); | 413 complete_frame_callback_->OnCompleteFrame(std::move(frame)); |
428 } | 414 } |
429 | 415 |
430 void RtpStreamReceiver::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { | 416 void RtpStreamReceiver::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { |
431 if (jitter_buffer_experiment_) | 417 nack_module_->UpdateRtt(max_rtt_ms); |
432 nack_module_->UpdateRtt(max_rtt_ms); | |
433 } | 418 } |
434 | 419 |
435 bool RtpStreamReceiver::ReceivePacket(const uint8_t* packet, | 420 bool RtpStreamReceiver::ReceivePacket(const uint8_t* packet, |
436 size_t packet_length, | 421 size_t packet_length, |
437 const RTPHeader& header, | 422 const RTPHeader& header, |
438 bool in_order) { | 423 bool in_order) { |
439 if (rtp_payload_registry_.IsEncapsulated(header)) { | 424 if (rtp_payload_registry_.IsEncapsulated(header)) { |
440 return ParseAndHandleEncapsulatingHeader(packet, packet_length, header); | 425 return ParseAndHandleEncapsulatingHeader(packet, packet_length, header); |
441 } | 426 } |
442 const uint8_t* payload = packet + header.headerLength; | 427 const uint8_t* payload = packet + header.headerLength; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 &rtp_timestamp) != 0) { | 535 &rtp_timestamp) != 0) { |
551 // Waiting for RTCP. | 536 // Waiting for RTCP. |
552 return true; | 537 return true; |
553 } | 538 } |
554 ntp_estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp); | 539 ntp_estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp); |
555 | 540 |
556 return true; | 541 return true; |
557 } | 542 } |
558 | 543 |
559 void RtpStreamReceiver::FrameContinuous(uint16_t picture_id) { | 544 void RtpStreamReceiver::FrameContinuous(uint16_t picture_id) { |
560 if (jitter_buffer_experiment_) { | 545 int seq_num = -1; |
561 int seq_num = -1; | 546 { |
562 { | 547 rtc::CritScope lock(&last_seq_num_cs_); |
563 rtc::CritScope lock(&last_seq_num_cs_); | 548 auto seq_num_it = last_seq_num_for_pic_id_.find(picture_id); |
564 auto seq_num_it = last_seq_num_for_pic_id_.find(picture_id); | 549 if (seq_num_it != last_seq_num_for_pic_id_.end()) |
565 if (seq_num_it != last_seq_num_for_pic_id_.end()) | 550 seq_num = seq_num_it->second; |
566 seq_num = seq_num_it->second; | |
567 } | |
568 if (seq_num != -1) | |
569 nack_module_->ClearUpTo(seq_num); | |
570 } | 551 } |
| 552 if (seq_num != -1) |
| 553 nack_module_->ClearUpTo(seq_num); |
571 } | 554 } |
572 | 555 |
573 void RtpStreamReceiver::FrameDecoded(uint16_t picture_id) { | 556 void RtpStreamReceiver::FrameDecoded(uint16_t picture_id) { |
574 if (jitter_buffer_experiment_) { | 557 int seq_num = -1; |
575 int seq_num = -1; | 558 { |
576 { | 559 rtc::CritScope lock(&last_seq_num_cs_); |
577 rtc::CritScope lock(&last_seq_num_cs_); | 560 auto seq_num_it = last_seq_num_for_pic_id_.find(picture_id); |
578 auto seq_num_it = last_seq_num_for_pic_id_.find(picture_id); | 561 if (seq_num_it != last_seq_num_for_pic_id_.end()) { |
579 if (seq_num_it != last_seq_num_for_pic_id_.end()) { | 562 seq_num = seq_num_it->second; |
580 seq_num = seq_num_it->second; | 563 last_seq_num_for_pic_id_.erase(last_seq_num_for_pic_id_.begin(), |
581 last_seq_num_for_pic_id_.erase(last_seq_num_for_pic_id_.begin(), | 564 ++seq_num_it); |
582 ++seq_num_it); | |
583 } | |
584 } | 565 } |
585 if (seq_num != -1) { | 566 } |
586 packet_buffer_->ClearTo(seq_num); | 567 if (seq_num != -1) { |
587 reference_finder_->ClearTo(seq_num); | 568 packet_buffer_->ClearTo(seq_num); |
588 } | 569 reference_finder_->ClearTo(seq_num); |
589 } | 570 } |
590 } | 571 } |
591 | 572 |
592 void RtpStreamReceiver::SignalNetworkState(NetworkState state) { | 573 void RtpStreamReceiver::SignalNetworkState(NetworkState state) { |
593 rtp_rtcp_->SetRTCPStatus(state == kNetworkUp ? config_.rtp.rtcp_mode | 574 rtp_rtcp_->SetRTCPStatus(state == kNetworkUp ? config_.rtp.rtcp_mode |
594 : RtcpMode::kOff); | 575 : RtcpMode::kOff); |
595 } | 576 } |
596 | 577 |
597 void RtpStreamReceiver::StartReceive() { | 578 void RtpStreamReceiver::StartReceive() { |
598 rtc::CritScope lock(&receive_cs_); | 579 rtc::CritScope lock(&receive_cs_); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 return; | 657 return; |
677 | 658 |
678 if (!sprop_decoder.DecodeSprop(sprop_base64_it->second.c_str())) | 659 if (!sprop_decoder.DecodeSprop(sprop_base64_it->second.c_str())) |
679 return; | 660 return; |
680 | 661 |
681 tracker_.InsertSpsPpsNalus(sprop_decoder.sps_nalu(), | 662 tracker_.InsertSpsPpsNalus(sprop_decoder.sps_nalu(), |
682 sprop_decoder.pps_nalu()); | 663 sprop_decoder.pps_nalu()); |
683 } | 664 } |
684 | 665 |
685 } // namespace webrtc | 666 } // namespace webrtc |
OLD | NEW |