| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 rtp_rtcp->SetSendingStatus(false); | 75 rtp_rtcp->SetSendingStatus(false); |
| 76 rtp_rtcp->SetSendingMediaStatus(false); | 76 rtp_rtcp->SetSendingMediaStatus(false); |
| 77 rtp_rtcp->SetRTCPStatus(RtcpMode::kCompound); | 77 rtp_rtcp->SetRTCPStatus(RtcpMode::kCompound); |
| 78 | 78 |
| 79 return rtp_rtcp; | 79 return rtp_rtcp; |
| 80 } | 80 } |
| 81 | 81 |
| 82 static const int kPacketLogIntervalMs = 10000; | 82 static const int kPacketLogIntervalMs = 10000; |
| 83 | 83 |
| 84 RtpStreamReceiver::RtpStreamReceiver( | 84 RtpStreamReceiver::RtpStreamReceiver( |
| 85 vcm::VideoReceiver* video_receiver, | |
| 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 packet_router_(packet_router), | 98 packet_router_(packet_router), |
| 101 remb_(remb), | 99 remb_(remb), |
| 102 process_thread_(process_thread), | 100 process_thread_(process_thread), |
| 103 ntp_estimator_(clock_), | 101 ntp_estimator_(clock_), |
| 104 rtp_header_parser_(RtpHeaderParser::Create()), | 102 rtp_header_parser_(RtpHeaderParser::Create()), |
| 105 rtp_receiver_(RtpReceiver::CreateVideoReceiver(clock_, | 103 rtp_receiver_(RtpReceiver::CreateVideoReceiver(clock_, |
| 106 this, | 104 this, |
| 107 this, | 105 this, |
| 108 &rtp_payload_registry_)), | 106 &rtp_payload_registry_)), |
| 109 rtp_receive_statistics_(ReceiveStatistics::Create(clock_)), | 107 rtp_receive_statistics_(ReceiveStatistics::Create(clock_)), |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 } | 179 } |
| 182 | 180 |
| 183 if (config_.rtp.rtcp_xr.receiver_reference_time_report) | 181 if (config_.rtp.rtcp_xr.receiver_reference_time_report) |
| 184 rtp_rtcp_->SetRtcpXrRrtrStatus(true); | 182 rtp_rtcp_->SetRtcpXrRrtrStatus(true); |
| 185 | 183 |
| 186 // Stats callback for CNAME changes. | 184 // Stats callback for CNAME changes. |
| 187 rtp_rtcp_->RegisterRtcpStatisticsCallback(receive_stats_proxy); | 185 rtp_rtcp_->RegisterRtcpStatisticsCallback(receive_stats_proxy); |
| 188 | 186 |
| 189 process_thread_->RegisterModule(rtp_rtcp_.get()); | 187 process_thread_->RegisterModule(rtp_rtcp_.get()); |
| 190 | 188 |
| 191 jitter_buffer_experiment_ = | 189 nack_module_.reset( |
| 192 field_trial::FindFullName("WebRTC-NewVideoJitterBuffer") == "Enabled"; | 190 new NackModule(clock_, nack_sender, keyframe_request_sender)); |
| 191 if (config_.rtp.nack.rtp_history_ms == 0) |
| 192 nack_module_->Stop(); |
| 193 process_thread_->RegisterModule(nack_module_.get()); |
| 193 | 194 |
| 194 if (jitter_buffer_experiment_) { | 195 packet_buffer_ = video_coding::PacketBuffer::Create( |
| 195 nack_module_.reset( | 196 clock_, kPacketBufferStartSize, kPacketBufferMaxSixe, this); |
| 196 new NackModule(clock_, nack_sender, keyframe_request_sender)); | 197 reference_finder_.reset(new video_coding::RtpFrameReferenceFinder(this)); |
| 197 process_thread_->RegisterModule(nack_module_.get()); | |
| 198 | |
| 199 packet_buffer_ = video_coding::PacketBuffer::Create( | |
| 200 clock_, kPacketBufferStartSize, kPacketBufferMaxSixe, this); | |
| 201 reference_finder_.reset(new video_coding::RtpFrameReferenceFinder(this)); | |
| 202 } | |
| 203 } | 198 } |
| 204 | 199 |
| 205 RtpStreamReceiver::~RtpStreamReceiver() { | 200 RtpStreamReceiver::~RtpStreamReceiver() { |
| 206 process_thread_->DeRegisterModule(rtp_rtcp_.get()); | 201 process_thread_->DeRegisterModule(rtp_rtcp_.get()); |
| 207 | 202 |
| 208 if (jitter_buffer_experiment_) | 203 process_thread_->DeRegisterModule(nack_module_.get()); |
| 209 process_thread_->DeRegisterModule(nack_module_.get()); | |
| 210 | 204 |
| 211 packet_router_->RemoveRtpModule(rtp_rtcp_.get()); | 205 packet_router_->RemoveRtpModule(rtp_rtcp_.get()); |
| 212 rtp_rtcp_->SetREMBStatus(false); | 206 rtp_rtcp_->SetREMBStatus(false); |
| 213 if (config_.rtp.remb) { | 207 if (config_.rtp.remb) { |
| 214 remb_->RemoveReceiveChannel(rtp_rtcp_.get()); | 208 remb_->RemoveReceiveChannel(rtp_rtcp_.get()); |
| 215 } | 209 } |
| 216 UpdateHistograms(); | 210 UpdateHistograms(); |
| 217 } | 211 } |
| 218 | 212 |
| 219 bool RtpStreamReceiver::AddReceiveCodec( | 213 bool RtpStreamReceiver::AddReceiveCodec( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 244 return rtp_receiver_.get(); | 238 return rtp_receiver_.get(); |
| 245 } | 239 } |
| 246 | 240 |
| 247 int32_t RtpStreamReceiver::OnReceivedPayloadData( | 241 int32_t RtpStreamReceiver::OnReceivedPayloadData( |
| 248 const uint8_t* payload_data, | 242 const uint8_t* payload_data, |
| 249 size_t payload_size, | 243 size_t payload_size, |
| 250 const WebRtcRTPHeader* rtp_header) { | 244 const WebRtcRTPHeader* rtp_header) { |
| 251 WebRtcRTPHeader rtp_header_with_ntp = *rtp_header; | 245 WebRtcRTPHeader rtp_header_with_ntp = *rtp_header; |
| 252 rtp_header_with_ntp.ntp_time_ms = | 246 rtp_header_with_ntp.ntp_time_ms = |
| 253 ntp_estimator_.Estimate(rtp_header->header.timestamp); | 247 ntp_estimator_.Estimate(rtp_header->header.timestamp); |
| 254 if (jitter_buffer_experiment_) { | 248 VCMPacket packet(payload_data, payload_size, rtp_header_with_ntp); |
| 255 VCMPacket packet(payload_data, payload_size, rtp_header_with_ntp); | 249 packet.timesNacked = nack_module_->OnReceivedPacket(packet); |
| 256 packet.timesNacked = nack_module_->OnReceivedPacket(packet); | |
| 257 | 250 |
| 258 if (packet.codec == kVideoCodecH264) { | 251 if (packet.codec == kVideoCodecH264) { |
| 259 // Only when we start to receive packets will we know what payload type | 252 // Only when we start to receive packets will we know what payload type |
| 260 // that will be used. When we know the payload type insert the correct | 253 // that will be used. When we know the payload type insert the correct |
| 261 // sps/pps into the tracker. | 254 // sps/pps into the tracker. |
| 262 if (packet.payloadType != last_payload_type_) { | 255 if (packet.payloadType != last_payload_type_) { |
| 263 last_payload_type_ = packet.payloadType; | 256 last_payload_type_ = packet.payloadType; |
| 264 InsertSpsPpsIntoTracker(packet.payloadType); | 257 InsertSpsPpsIntoTracker(packet.payloadType); |
| 265 } | |
| 266 | |
| 267 switch (tracker_.CopyAndFixBitstream(&packet)) { | |
| 268 case video_coding::H264SpsPpsTracker::kRequestKeyframe: | |
| 269 keyframe_request_sender_->RequestKeyFrame(); | |
| 270 FALLTHROUGH(); | |
| 271 case video_coding::H264SpsPpsTracker::kDrop: | |
| 272 return 0; | |
| 273 case video_coding::H264SpsPpsTracker::kInsert: | |
| 274 break; | |
| 275 } | |
| 276 } else { | |
| 277 uint8_t* data = new uint8_t[packet.sizeBytes]; | |
| 278 memcpy(data, packet.dataPtr, packet.sizeBytes); | |
| 279 packet.dataPtr = data; | |
| 280 } | 258 } |
| 281 | 259 |
| 282 packet_buffer_->InsertPacket(&packet); | 260 switch (tracker_.CopyAndFixBitstream(&packet)) { |
| 261 case video_coding::H264SpsPpsTracker::kRequestKeyframe: |
| 262 keyframe_request_sender_->RequestKeyFrame(); |
| 263 FALLTHROUGH(); |
| 264 case video_coding::H264SpsPpsTracker::kDrop: |
| 265 return 0; |
| 266 case video_coding::H264SpsPpsTracker::kInsert: |
| 267 break; |
| 268 } |
| 269 |
| 283 } else { | 270 } else { |
| 284 RTC_DCHECK(video_receiver_); | 271 uint8_t* data = new uint8_t[packet.sizeBytes]; |
| 285 if (video_receiver_->IncomingPacket(payload_data, payload_size, | 272 memcpy(data, packet.dataPtr, packet.sizeBytes); |
| 286 rtp_header_with_ntp) != 0) { | 273 packet.dataPtr = data; |
| 287 // Check this... | |
| 288 return -1; | |
| 289 } | |
| 290 } | 274 } |
| 275 |
| 276 packet_buffer_->InsertPacket(&packet); |
| 291 return 0; | 277 return 0; |
| 292 } | 278 } |
| 293 | 279 |
| 294 bool RtpStreamReceiver::OnRecoveredPacket(const uint8_t* rtp_packet, | 280 bool RtpStreamReceiver::OnRecoveredPacket(const uint8_t* rtp_packet, |
| 295 size_t rtp_packet_length) { | 281 size_t rtp_packet_length) { |
| 296 RTPHeader header; | 282 RTPHeader header; |
| 297 if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length, &header)) { | 283 if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length, &header)) { |
| 298 return false; | 284 return false; |
| 299 } | 285 } |
| 300 header.payload_type_frequency = kVideoPayloadTypeFrequency; | 286 header.payload_type_frequency = kVideoPayloadTypeFrequency; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 { | 398 { |
| 413 rtc::CritScope lock(&last_seq_num_cs_); | 399 rtc::CritScope lock(&last_seq_num_cs_); |
| 414 video_coding::RtpFrameObject* rtp_frame = | 400 video_coding::RtpFrameObject* rtp_frame = |
| 415 static_cast<video_coding::RtpFrameObject*>(frame.get()); | 401 static_cast<video_coding::RtpFrameObject*>(frame.get()); |
| 416 last_seq_num_for_pic_id_[rtp_frame->picture_id] = rtp_frame->last_seq_num(); | 402 last_seq_num_for_pic_id_[rtp_frame->picture_id] = rtp_frame->last_seq_num(); |
| 417 } | 403 } |
| 418 complete_frame_callback_->OnCompleteFrame(std::move(frame)); | 404 complete_frame_callback_->OnCompleteFrame(std::move(frame)); |
| 419 } | 405 } |
| 420 | 406 |
| 421 void RtpStreamReceiver::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { | 407 void RtpStreamReceiver::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { |
| 422 if (jitter_buffer_experiment_) | 408 nack_module_->UpdateRtt(max_rtt_ms); |
| 423 nack_module_->UpdateRtt(max_rtt_ms); | |
| 424 } | 409 } |
| 425 | 410 |
| 426 // TODO(nisse): Drop return value. | 411 // TODO(nisse): Drop return value. |
| 427 bool RtpStreamReceiver::ReceivePacket(const uint8_t* packet, | 412 bool RtpStreamReceiver::ReceivePacket(const uint8_t* packet, |
| 428 size_t packet_length, | 413 size_t packet_length, |
| 429 const RTPHeader& header, | 414 const RTPHeader& header, |
| 430 bool in_order) { | 415 bool in_order) { |
| 431 if (rtp_payload_registry_.IsEncapsulated(header)) { | 416 if (rtp_payload_registry_.IsEncapsulated(header)) { |
| 432 return ParseAndHandleEncapsulatingHeader(packet, packet_length, header); | 417 return ParseAndHandleEncapsulatingHeader(packet, packet_length, header); |
| 433 } | 418 } |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 &rtp_timestamp) != 0) { | 527 &rtp_timestamp) != 0) { |
| 543 // Waiting for RTCP. | 528 // Waiting for RTCP. |
| 544 return true; | 529 return true; |
| 545 } | 530 } |
| 546 ntp_estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp); | 531 ntp_estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp); |
| 547 | 532 |
| 548 return true; | 533 return true; |
| 549 } | 534 } |
| 550 | 535 |
| 551 void RtpStreamReceiver::FrameContinuous(uint16_t picture_id) { | 536 void RtpStreamReceiver::FrameContinuous(uint16_t picture_id) { |
| 552 if (jitter_buffer_experiment_) { | 537 int seq_num = -1; |
| 553 int seq_num = -1; | 538 { |
| 554 { | 539 rtc::CritScope lock(&last_seq_num_cs_); |
| 555 rtc::CritScope lock(&last_seq_num_cs_); | 540 auto seq_num_it = last_seq_num_for_pic_id_.find(picture_id); |
| 556 auto seq_num_it = last_seq_num_for_pic_id_.find(picture_id); | 541 if (seq_num_it != last_seq_num_for_pic_id_.end()) |
| 557 if (seq_num_it != last_seq_num_for_pic_id_.end()) | 542 seq_num = seq_num_it->second; |
| 558 seq_num = seq_num_it->second; | |
| 559 } | |
| 560 if (seq_num != -1) | |
| 561 nack_module_->ClearUpTo(seq_num); | |
| 562 } | 543 } |
| 544 if (seq_num != -1) |
| 545 nack_module_->ClearUpTo(seq_num); |
| 563 } | 546 } |
| 564 | 547 |
| 565 void RtpStreamReceiver::FrameDecoded(uint16_t picture_id) { | 548 void RtpStreamReceiver::FrameDecoded(uint16_t picture_id) { |
| 566 if (jitter_buffer_experiment_) { | 549 int seq_num = -1; |
| 567 int seq_num = -1; | 550 { |
| 568 { | 551 rtc::CritScope lock(&last_seq_num_cs_); |
| 569 rtc::CritScope lock(&last_seq_num_cs_); | 552 auto seq_num_it = last_seq_num_for_pic_id_.find(picture_id); |
| 570 auto seq_num_it = last_seq_num_for_pic_id_.find(picture_id); | 553 if (seq_num_it != last_seq_num_for_pic_id_.end()) { |
| 571 if (seq_num_it != last_seq_num_for_pic_id_.end()) { | 554 seq_num = seq_num_it->second; |
| 572 seq_num = seq_num_it->second; | 555 last_seq_num_for_pic_id_.erase(last_seq_num_for_pic_id_.begin(), |
| 573 last_seq_num_for_pic_id_.erase(last_seq_num_for_pic_id_.begin(), | 556 ++seq_num_it); |
| 574 ++seq_num_it); | |
| 575 } | |
| 576 } | 557 } |
| 577 if (seq_num != -1) { | 558 } |
| 578 packet_buffer_->ClearTo(seq_num); | 559 if (seq_num != -1) { |
| 579 reference_finder_->ClearTo(seq_num); | 560 packet_buffer_->ClearTo(seq_num); |
| 580 } | 561 reference_finder_->ClearTo(seq_num); |
| 581 } | 562 } |
| 582 } | 563 } |
| 583 | 564 |
| 584 void RtpStreamReceiver::SignalNetworkState(NetworkState state) { | 565 void RtpStreamReceiver::SignalNetworkState(NetworkState state) { |
| 585 rtp_rtcp_->SetRTCPStatus(state == kNetworkUp ? config_.rtp.rtcp_mode | 566 rtp_rtcp_->SetRTCPStatus(state == kNetworkUp ? config_.rtp.rtcp_mode |
| 586 : RtcpMode::kOff); | 567 : RtcpMode::kOff); |
| 587 } | 568 } |
| 588 | 569 |
| 589 void RtpStreamReceiver::StartReceive() { | 570 void RtpStreamReceiver::StartReceive() { |
| 590 rtc::CritScope lock(&receive_cs_); | 571 rtc::CritScope lock(&receive_cs_); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 return; | 649 return; |
| 669 | 650 |
| 670 if (!sprop_decoder.DecodeSprop(sprop_base64_it->second.c_str())) | 651 if (!sprop_decoder.DecodeSprop(sprop_base64_it->second.c_str())) |
| 671 return; | 652 return; |
| 672 | 653 |
| 673 tracker_.InsertSpsPpsNalus(sprop_decoder.sps_nalu(), | 654 tracker_.InsertSpsPpsNalus(sprop_decoder.sps_nalu(), |
| 674 sprop_decoder.pps_nalu()); | 655 sprop_decoder.pps_nalu()); |
| 675 } | 656 } |
| 676 | 657 |
| 677 } // namespace webrtc | 658 } // namespace webrtc |
| OLD | NEW |