| 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 } | 192 } |
| 193 | 193 |
| 194 if (config_.rtp.rtcp_xr.receiver_reference_time_report) | 194 if (config_.rtp.rtcp_xr.receiver_reference_time_report) |
| 195 rtp_rtcp_->SetRtcpXrRrtrStatus(true); | 195 rtp_rtcp_->SetRtcpXrRrtrStatus(true); |
| 196 | 196 |
| 197 // Stats callback for CNAME changes. | 197 // Stats callback for CNAME changes. |
| 198 rtp_rtcp_->RegisterRtcpStatisticsCallback(receive_stats_proxy); | 198 rtp_rtcp_->RegisterRtcpStatisticsCallback(receive_stats_proxy); |
| 199 | 199 |
| 200 process_thread_->RegisterModule(rtp_rtcp_.get()); | 200 process_thread_->RegisterModule(rtp_rtcp_.get()); |
| 201 | 201 |
| 202 jitter_buffer_experiment_ = | 202 nack_module_.reset( |
| 203 field_trial::FindFullName("WebRTC-NewVideoJitterBuffer") == "Enabled"; | 203 new NackModule(clock_, nack_sender, keyframe_request_sender)); |
| 204 if (config_.rtp.nack.rtp_history_ms == 0) |
| 205 nack_module_->Stop(); |
| 206 process_thread_->RegisterModule(nack_module_.get()); |
| 204 | 207 |
| 205 if (jitter_buffer_experiment_) { | 208 packet_buffer_ = video_coding::PacketBuffer::Create( |
| 206 nack_module_.reset( | 209 clock_, kPacketBufferStartSize, kPacketBufferMaxSixe, this); |
| 207 new NackModule(clock_, nack_sender, keyframe_request_sender)); | 210 reference_finder_.reset(new video_coding::RtpFrameReferenceFinder(this)); |
| 208 process_thread_->RegisterModule(nack_module_.get()); | |
| 209 | |
| 210 packet_buffer_ = video_coding::PacketBuffer::Create( | |
| 211 clock_, kPacketBufferStartSize, kPacketBufferMaxSixe, this); | |
| 212 reference_finder_.reset(new video_coding::RtpFrameReferenceFinder(this)); | |
| 213 } | |
| 214 } | 211 } |
| 215 | 212 |
| 216 RtpStreamReceiver::~RtpStreamReceiver() { | 213 RtpStreamReceiver::~RtpStreamReceiver() { |
| 217 process_thread_->DeRegisterModule(rtp_rtcp_.get()); | 214 process_thread_->DeRegisterModule(rtp_rtcp_.get()); |
| 218 | 215 |
| 219 if (jitter_buffer_experiment_) | 216 process_thread_->DeRegisterModule(nack_module_.get()); |
| 220 process_thread_->DeRegisterModule(nack_module_.get()); | |
| 221 | 217 |
| 222 packet_router_->RemoveRtpModule(rtp_rtcp_.get()); | 218 packet_router_->RemoveRtpModule(rtp_rtcp_.get()); |
| 223 rtp_rtcp_->SetREMBStatus(false); | 219 rtp_rtcp_->SetREMBStatus(false); |
| 224 remb_->RemoveReceiveChannel(rtp_rtcp_.get()); | 220 remb_->RemoveReceiveChannel(rtp_rtcp_.get()); |
| 225 UpdateHistograms(); | 221 UpdateHistograms(); |
| 226 } | 222 } |
| 227 | 223 |
| 228 bool RtpStreamReceiver::AddReceiveCodec( | 224 bool RtpStreamReceiver::AddReceiveCodec( |
| 229 const VideoCodec& video_codec, | 225 const VideoCodec& video_codec, |
| 230 const std::map<std::string, std::string>& codec_params) { | 226 const std::map<std::string, std::string>& codec_params) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 254 } | 250 } |
| 255 | 251 |
| 256 int32_t RtpStreamReceiver::OnReceivedPayloadData( | 252 int32_t RtpStreamReceiver::OnReceivedPayloadData( |
| 257 const uint8_t* payload_data, | 253 const uint8_t* payload_data, |
| 258 size_t payload_size, | 254 size_t payload_size, |
| 259 const WebRtcRTPHeader* rtp_header) { | 255 const WebRtcRTPHeader* rtp_header) { |
| 260 RTC_DCHECK(video_receiver_); | 256 RTC_DCHECK(video_receiver_); |
| 261 WebRtcRTPHeader rtp_header_with_ntp = *rtp_header; | 257 WebRtcRTPHeader rtp_header_with_ntp = *rtp_header; |
| 262 rtp_header_with_ntp.ntp_time_ms = | 258 rtp_header_with_ntp.ntp_time_ms = |
| 263 ntp_estimator_.Estimate(rtp_header->header.timestamp); | 259 ntp_estimator_.Estimate(rtp_header->header.timestamp); |
| 264 if (jitter_buffer_experiment_) { | 260 VCMPacket packet(payload_data, payload_size, rtp_header_with_ntp); |
| 265 VCMPacket packet(payload_data, payload_size, rtp_header_with_ntp); | 261 timing_->IncomingTimestamp(packet.timestamp, clock_->TimeInMilliseconds()); |
| 266 timing_->IncomingTimestamp(packet.timestamp, clock_->TimeInMilliseconds()); | 262 packet.timesNacked = nack_module_->OnReceivedPacket(packet); |
| 267 packet.timesNacked = nack_module_->OnReceivedPacket(packet); | |
| 268 | 263 |
| 269 if (packet.codec == kVideoCodecH264) { | 264 if (packet.codec == kVideoCodecH264) { |
| 270 // Only when we start to receive packets will we know what payload type | 265 // Only when we start to receive packets will we know what payload type |
| 271 // that will be used. When we know the payload type insert the correct | 266 // that will be used. When we know the payload type insert the correct |
| 272 // sps/pps into the tracker. | 267 // sps/pps into the tracker. |
| 273 if (packet.payloadType != last_payload_type_) { | 268 if (packet.payloadType != last_payload_type_) { |
| 274 last_payload_type_ = packet.payloadType; | 269 last_payload_type_ = packet.payloadType; |
| 275 InsertSpsPpsIntoTracker(packet.payloadType); | 270 InsertSpsPpsIntoTracker(packet.payloadType); |
| 276 } | |
| 277 | |
| 278 switch (tracker_.CopyAndFixBitstream(&packet)) { | |
| 279 case video_coding::H264SpsPpsTracker::kRequestKeyframe: | |
| 280 keyframe_request_sender_->RequestKeyFrame(); | |
| 281 FALLTHROUGH(); | |
| 282 case video_coding::H264SpsPpsTracker::kDrop: | |
| 283 return 0; | |
| 284 case video_coding::H264SpsPpsTracker::kInsert: | |
| 285 break; | |
| 286 } | |
| 287 } else { | |
| 288 uint8_t* data = new uint8_t[packet.sizeBytes]; | |
| 289 memcpy(data, packet.dataPtr, packet.sizeBytes); | |
| 290 packet.dataPtr = data; | |
| 291 } | 271 } |
| 292 | 272 |
| 293 packet_buffer_->InsertPacket(&packet); | 273 switch (tracker_.CopyAndFixBitstream(&packet)) { |
| 274 case video_coding::H264SpsPpsTracker::kRequestKeyframe: |
| 275 keyframe_request_sender_->RequestKeyFrame(); |
| 276 FALLTHROUGH(); |
| 277 case video_coding::H264SpsPpsTracker::kDrop: |
| 278 return 0; |
| 279 case video_coding::H264SpsPpsTracker::kInsert: |
| 280 break; |
| 281 } |
| 294 } else { | 282 } else { |
| 295 if (video_receiver_->IncomingPacket(payload_data, payload_size, | 283 uint8_t* data = new uint8_t[packet.sizeBytes]; |
| 296 rtp_header_with_ntp) != 0) { | 284 memcpy(data, packet.dataPtr, packet.sizeBytes); |
| 297 // Check this... | 285 packet.dataPtr = data; |
| 298 return -1; | |
| 299 } | |
| 300 } | 286 } |
| 287 |
| 288 packet_buffer_->InsertPacket(&packet); |
| 301 return 0; | 289 return 0; |
| 302 } | 290 } |
| 303 | 291 |
| 304 bool RtpStreamReceiver::OnRecoveredPacket(const uint8_t* rtp_packet, | 292 bool RtpStreamReceiver::OnRecoveredPacket(const uint8_t* rtp_packet, |
| 305 size_t rtp_packet_length) { | 293 size_t rtp_packet_length) { |
| 306 RTPHeader header; | 294 RTPHeader header; |
| 307 if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length, &header)) { | 295 if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length, &header)) { |
| 308 return false; | 296 return false; |
| 309 } | 297 } |
| 310 header.payload_type_frequency = kVideoPayloadTypeFrequency; | 298 header.payload_type_frequency = kVideoPayloadTypeFrequency; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 { | 415 { |
| 428 rtc::CritScope lock(&last_seq_num_cs_); | 416 rtc::CritScope lock(&last_seq_num_cs_); |
| 429 video_coding::RtpFrameObject* rtp_frame = | 417 video_coding::RtpFrameObject* rtp_frame = |
| 430 static_cast<video_coding::RtpFrameObject*>(frame.get()); | 418 static_cast<video_coding::RtpFrameObject*>(frame.get()); |
| 431 last_seq_num_for_pic_id_[rtp_frame->picture_id] = rtp_frame->last_seq_num(); | 419 last_seq_num_for_pic_id_[rtp_frame->picture_id] = rtp_frame->last_seq_num(); |
| 432 } | 420 } |
| 433 complete_frame_callback_->OnCompleteFrame(std::move(frame)); | 421 complete_frame_callback_->OnCompleteFrame(std::move(frame)); |
| 434 } | 422 } |
| 435 | 423 |
| 436 void RtpStreamReceiver::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { | 424 void RtpStreamReceiver::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { |
| 437 if (jitter_buffer_experiment_) | 425 nack_module_->UpdateRtt(max_rtt_ms); |
| 438 nack_module_->UpdateRtt(max_rtt_ms); | |
| 439 } | 426 } |
| 440 | 427 |
| 441 bool RtpStreamReceiver::ReceivePacket(const uint8_t* packet, | 428 bool RtpStreamReceiver::ReceivePacket(const uint8_t* packet, |
| 442 size_t packet_length, | 429 size_t packet_length, |
| 443 const RTPHeader& header, | 430 const RTPHeader& header, |
| 444 bool in_order) { | 431 bool in_order) { |
| 445 if (rtp_payload_registry_.IsEncapsulated(header)) { | 432 if (rtp_payload_registry_.IsEncapsulated(header)) { |
| 446 return ParseAndHandleEncapsulatingHeader(packet, packet_length, header); | 433 return ParseAndHandleEncapsulatingHeader(packet, packet_length, header); |
| 447 } | 434 } |
| 448 const uint8_t* payload = packet + header.headerLength; | 435 const uint8_t* payload = packet + header.headerLength; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 &rtp_timestamp) != 0) { | 543 &rtp_timestamp) != 0) { |
| 557 // Waiting for RTCP. | 544 // Waiting for RTCP. |
| 558 return true; | 545 return true; |
| 559 } | 546 } |
| 560 ntp_estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp); | 547 ntp_estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp); |
| 561 | 548 |
| 562 return true; | 549 return true; |
| 563 } | 550 } |
| 564 | 551 |
| 565 void RtpStreamReceiver::FrameContinuous(uint16_t picture_id) { | 552 void RtpStreamReceiver::FrameContinuous(uint16_t picture_id) { |
| 566 if (jitter_buffer_experiment_) { | 553 int seq_num = -1; |
| 567 int seq_num = -1; | 554 { |
| 568 { | 555 rtc::CritScope lock(&last_seq_num_cs_); |
| 569 rtc::CritScope lock(&last_seq_num_cs_); | 556 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); | 557 if (seq_num_it != last_seq_num_for_pic_id_.end()) |
| 571 if (seq_num_it != last_seq_num_for_pic_id_.end()) | 558 seq_num = seq_num_it->second; |
| 572 seq_num = seq_num_it->second; | |
| 573 } | |
| 574 if (seq_num != -1) | |
| 575 nack_module_->ClearUpTo(seq_num); | |
| 576 } | 559 } |
| 560 if (seq_num != -1) |
| 561 nack_module_->ClearUpTo(seq_num); |
| 577 } | 562 } |
| 578 | 563 |
| 579 void RtpStreamReceiver::FrameDecoded(uint16_t picture_id) { | 564 void RtpStreamReceiver::FrameDecoded(uint16_t picture_id) { |
| 580 if (jitter_buffer_experiment_) { | 565 int seq_num = -1; |
| 581 int seq_num = -1; | 566 { |
| 582 { | 567 rtc::CritScope lock(&last_seq_num_cs_); |
| 583 rtc::CritScope lock(&last_seq_num_cs_); | 568 auto seq_num_it = last_seq_num_for_pic_id_.find(picture_id); |
| 584 auto seq_num_it = last_seq_num_for_pic_id_.find(picture_id); | 569 if (seq_num_it != last_seq_num_for_pic_id_.end()) { |
| 585 if (seq_num_it != last_seq_num_for_pic_id_.end()) { | 570 seq_num = seq_num_it->second; |
| 586 seq_num = seq_num_it->second; | 571 last_seq_num_for_pic_id_.erase(last_seq_num_for_pic_id_.begin(), |
| 587 last_seq_num_for_pic_id_.erase(last_seq_num_for_pic_id_.begin(), | 572 ++seq_num_it); |
| 588 ++seq_num_it); | |
| 589 } | |
| 590 } | 573 } |
| 591 if (seq_num != -1) { | 574 } |
| 592 packet_buffer_->ClearTo(seq_num); | 575 if (seq_num != -1) { |
| 593 reference_finder_->ClearTo(seq_num); | 576 packet_buffer_->ClearTo(seq_num); |
| 594 } | 577 reference_finder_->ClearTo(seq_num); |
| 595 } | 578 } |
| 596 } | 579 } |
| 597 | 580 |
| 598 void RtpStreamReceiver::SignalNetworkState(NetworkState state) { | 581 void RtpStreamReceiver::SignalNetworkState(NetworkState state) { |
| 599 rtp_rtcp_->SetRTCPStatus(state == kNetworkUp ? config_.rtp.rtcp_mode | 582 rtp_rtcp_->SetRTCPStatus(state == kNetworkUp ? config_.rtp.rtcp_mode |
| 600 : RtcpMode::kOff); | 583 : RtcpMode::kOff); |
| 601 } | 584 } |
| 602 | 585 |
| 603 void RtpStreamReceiver::StartReceive() { | 586 void RtpStreamReceiver::StartReceive() { |
| 604 rtc::CritScope lock(&receive_cs_); | 587 rtc::CritScope lock(&receive_cs_); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 if (sprop_base64_it == codec_params_it->second.end()) | 664 if (sprop_base64_it == codec_params_it->second.end()) |
| 682 return; | 665 return; |
| 683 | 666 |
| 684 if (!sprop_decoder.DecodeSprop(sprop_base64_it->second)) | 667 if (!sprop_decoder.DecodeSprop(sprop_base64_it->second)) |
| 685 return; | 668 return; |
| 686 | 669 |
| 687 tracker_.InsertSpsPps(sprop_decoder.sps_nalu(), sprop_decoder.pps_nalu()); | 670 tracker_.InsertSpsPps(sprop_decoder.sps_nalu(), sprop_decoder.pps_nalu()); |
| 688 } | 671 } |
| 689 | 672 |
| 690 } // namespace webrtc | 673 } // namespace webrtc |
| OLD | NEW |