| 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 SetSampleRateAndChannels(fs, 1); // Default is 1 channel. | 124 SetSampleRateAndChannels(fs, 1); // Default is 1 channel. |
| 125 } | 125 } |
| 126 RTC_DCHECK(!vad_->enabled()); | 126 RTC_DCHECK(!vad_->enabled()); |
| 127 if (config.enable_post_decode_vad) { | 127 if (config.enable_post_decode_vad) { |
| 128 vad_->Enable(); | 128 vad_->Enable(); |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 | 131 |
| 132 NetEqImpl::~NetEqImpl() = default; | 132 NetEqImpl::~NetEqImpl() = default; |
| 133 | 133 |
| 134 int NetEqImpl::InsertPacket(const WebRtcRTPHeader& rtp_header, | 134 int NetEqImpl::InsertPacket(const RTPHeader& rtp_header, |
| 135 rtc::ArrayView<const uint8_t> payload, | 135 rtc::ArrayView<const uint8_t> payload, |
| 136 uint32_t receive_timestamp) { | 136 uint32_t receive_timestamp) { |
| 137 rtc::MsanCheckInitialized(payload); | 137 rtc::MsanCheckInitialized(payload); |
| 138 TRACE_EVENT0("webrtc", "NetEqImpl::InsertPacket"); | 138 TRACE_EVENT0("webrtc", "NetEqImpl::InsertPacket"); |
| 139 rtc::CritScope lock(&crit_sect_); | 139 rtc::CritScope lock(&crit_sect_); |
| 140 int error = | 140 int error = |
| 141 InsertPacketInternal(rtp_header, payload, receive_timestamp); | 141 InsertPacketInternal(rtp_header, payload, receive_timestamp); |
| 142 if (error != 0) { | 142 if (error != 0) { |
| 143 error_code_ = error; | 143 error_code_ = error; |
| 144 return kFail; | 144 return kFail; |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 return sync_buffer_.get(); | 574 return sync_buffer_.get(); |
| 575 } | 575 } |
| 576 | 576 |
| 577 Operations NetEqImpl::last_operation_for_test() const { | 577 Operations NetEqImpl::last_operation_for_test() const { |
| 578 rtc::CritScope lock(&crit_sect_); | 578 rtc::CritScope lock(&crit_sect_); |
| 579 return last_operation_; | 579 return last_operation_; |
| 580 } | 580 } |
| 581 | 581 |
| 582 // Methods below this line are private. | 582 // Methods below this line are private. |
| 583 | 583 |
| 584 int NetEqImpl::InsertPacketInternal(const WebRtcRTPHeader& rtp_header, | 584 int NetEqImpl::InsertPacketInternal(const RTPHeader& rtp_header, |
| 585 rtc::ArrayView<const uint8_t> payload, | 585 rtc::ArrayView<const uint8_t> payload, |
| 586 uint32_t receive_timestamp) { | 586 uint32_t receive_timestamp) { |
| 587 if (payload.empty()) { | 587 if (payload.empty()) { |
| 588 LOG_F(LS_ERROR) << "payload is empty"; | 588 LOG_F(LS_ERROR) << "payload is empty"; |
| 589 return kInvalidPointer; | 589 return kInvalidPointer; |
| 590 } | 590 } |
| 591 | 591 |
| 592 PacketList packet_list; | 592 PacketList packet_list; |
| 593 // Insert packet in a packet list. | 593 // Insert packet in a packet list. |
| 594 packet_list.push_back([&rtp_header, &payload] { | 594 packet_list.push_back([&rtp_header, &payload] { |
| 595 // Convert to Packet. | 595 // Convert to Packet. |
| 596 Packet packet; | 596 Packet packet; |
| 597 packet.payload_type = rtp_header.header.payloadType; | 597 packet.payload_type = rtp_header.payloadType; |
| 598 packet.sequence_number = rtp_header.header.sequenceNumber; | 598 packet.sequence_number = rtp_header.sequenceNumber; |
| 599 packet.timestamp = rtp_header.header.timestamp; | 599 packet.timestamp = rtp_header.timestamp; |
| 600 packet.payload.SetData(payload.data(), payload.size()); | 600 packet.payload.SetData(payload.data(), payload.size()); |
| 601 // Waiting time will be set upon inserting the packet in the buffer. | 601 // Waiting time will be set upon inserting the packet in the buffer. |
| 602 RTC_DCHECK(!packet.waiting_time); | 602 RTC_DCHECK(!packet.waiting_time); |
| 603 return packet; | 603 return packet; |
| 604 }()); | 604 }()); |
| 605 | 605 |
| 606 bool update_sample_rate_and_channels = first_packet_ || | 606 bool update_sample_rate_and_channels = |
| 607 (rtp_header.header.ssrc != ssrc_); | 607 first_packet_ || (rtp_header.ssrc != ssrc_); |
| 608 | 608 |
| 609 if (update_sample_rate_and_channels) { | 609 if (update_sample_rate_and_channels) { |
| 610 // Reset timestamp scaling. | 610 // Reset timestamp scaling. |
| 611 timestamp_scaler_->Reset(); | 611 timestamp_scaler_->Reset(); |
| 612 } | 612 } |
| 613 | 613 |
| 614 if (!decoder_database_->IsRed(rtp_header.header.payloadType)) { | 614 if (!decoder_database_->IsRed(rtp_header.payloadType)) { |
| 615 // Scale timestamp to internal domain (only for some codecs). | 615 // Scale timestamp to internal domain (only for some codecs). |
| 616 timestamp_scaler_->ToInternal(&packet_list); | 616 timestamp_scaler_->ToInternal(&packet_list); |
| 617 } | 617 } |
| 618 | 618 |
| 619 // Store these for later use, since the first packet may very well disappear | 619 // Store these for later use, since the first packet may very well disappear |
| 620 // before we need these values. | 620 // before we need these values. |
| 621 uint32_t main_timestamp = packet_list.front().timestamp; | 621 uint32_t main_timestamp = packet_list.front().timestamp; |
| 622 uint8_t main_payload_type = packet_list.front().payload_type; | 622 uint8_t main_payload_type = packet_list.front().payload_type; |
| 623 uint16_t main_sequence_number = packet_list.front().sequence_number; | 623 uint16_t main_sequence_number = packet_list.front().sequence_number; |
| 624 | 624 |
| 625 // Reinitialize NetEq if it's needed (changed SSRC or first call). | 625 // Reinitialize NetEq if it's needed (changed SSRC or first call). |
| 626 if (update_sample_rate_and_channels) { | 626 if (update_sample_rate_and_channels) { |
| 627 // Note: |first_packet_| will be cleared further down in this method, once | 627 // Note: |first_packet_| will be cleared further down in this method, once |
| 628 // the packet has been successfully inserted into the packet buffer. | 628 // the packet has been successfully inserted into the packet buffer. |
| 629 | 629 |
| 630 rtcp_.Init(rtp_header.header.sequenceNumber); | 630 rtcp_.Init(rtp_header.sequenceNumber); |
| 631 | 631 |
| 632 // Flush the packet buffer and DTMF buffer. | 632 // Flush the packet buffer and DTMF buffer. |
| 633 packet_buffer_->Flush(); | 633 packet_buffer_->Flush(); |
| 634 dtmf_buffer_->Flush(); | 634 dtmf_buffer_->Flush(); |
| 635 | 635 |
| 636 // Store new SSRC. | 636 // Store new SSRC. |
| 637 ssrc_ = rtp_header.header.ssrc; | 637 ssrc_ = rtp_header.ssrc; |
| 638 | 638 |
| 639 // Update audio buffer timestamp. | 639 // Update audio buffer timestamp. |
| 640 sync_buffer_->IncreaseEndTimestamp(main_timestamp - timestamp_); | 640 sync_buffer_->IncreaseEndTimestamp(main_timestamp - timestamp_); |
| 641 | 641 |
| 642 // Update codecs. | 642 // Update codecs. |
| 643 timestamp_ = main_timestamp; | 643 timestamp_ = main_timestamp; |
| 644 } | 644 } |
| 645 | 645 |
| 646 // Update RTCP statistics, only for regular packets. | 646 // Update RTCP statistics, only for regular packets. |
| 647 rtcp_.Update(rtp_header.header, receive_timestamp); | 647 rtcp_.Update(rtp_header, receive_timestamp); |
| 648 | 648 |
| 649 if (nack_enabled_) { | 649 if (nack_enabled_) { |
| 650 RTC_DCHECK(nack_); | 650 RTC_DCHECK(nack_); |
| 651 if (update_sample_rate_and_channels) { | 651 if (update_sample_rate_and_channels) { |
| 652 nack_->Reset(); | 652 nack_->Reset(); |
| 653 } | 653 } |
| 654 nack_->UpdateLastReceivedPacket(rtp_header.header.sequenceNumber, | 654 nack_->UpdateLastReceivedPacket(rtp_header.sequenceNumber, |
| 655 rtp_header.header.timestamp); | 655 rtp_header.timestamp); |
| 656 } | 656 } |
| 657 | 657 |
| 658 // Check for RED payload type, and separate payloads into several packets. | 658 // Check for RED payload type, and separate payloads into several packets. |
| 659 if (decoder_database_->IsRed(rtp_header.header.payloadType)) { | 659 if (decoder_database_->IsRed(rtp_header.payloadType)) { |
| 660 if (!red_payload_splitter_->SplitRed(&packet_list)) { | 660 if (!red_payload_splitter_->SplitRed(&packet_list)) { |
| 661 return kRedundancySplitError; | 661 return kRedundancySplitError; |
| 662 } | 662 } |
| 663 // Only accept a few RED payloads of the same type as the main data, | 663 // Only accept a few RED payloads of the same type as the main data, |
| 664 // DTMF events and CNG. | 664 // DTMF events and CNG. |
| 665 red_payload_splitter_->CheckRedPayloads(&packet_list, *decoder_database_); | 665 red_payload_splitter_->CheckRedPayloads(&packet_list, *decoder_database_); |
| 666 } | 666 } |
| 667 | 667 |
| 668 // Check payload types. | 668 // Check payload types. |
| 669 if (decoder_database_->CheckPayloadTypes(packet_list) == | 669 if (decoder_database_->CheckPayloadTypes(packet_list) == |
| 670 DecoderDatabase::kDecoderNotFound) { | 670 DecoderDatabase::kDecoderNotFound) { |
| 671 return kUnknownRtpPayloadType; | 671 return kUnknownRtpPayloadType; |
| 672 } | 672 } |
| 673 | 673 |
| 674 RTC_DCHECK(!packet_list.empty()); | 674 RTC_DCHECK(!packet_list.empty()); |
| 675 | 675 |
| 676 // Update main_timestamp, if new packets appear in the list | 676 // Update main_timestamp, if new packets appear in the list |
| 677 // after RED splitting. | 677 // after RED splitting. |
| 678 if (decoder_database_->IsRed(rtp_header.header.payloadType)) { | 678 if (decoder_database_->IsRed(rtp_header.payloadType)) { |
| 679 timestamp_scaler_->ToInternal(&packet_list); | 679 timestamp_scaler_->ToInternal(&packet_list); |
| 680 main_timestamp = packet_list.front().timestamp; | 680 main_timestamp = packet_list.front().timestamp; |
| 681 main_payload_type = packet_list.front().payload_type; | 681 main_payload_type = packet_list.front().payload_type; |
| 682 main_sequence_number = packet_list.front().sequence_number; | 682 main_sequence_number = packet_list.front().sequence_number; |
| 683 } | 683 } |
| 684 | 684 |
| 685 // Process DTMF payloads. Cycle through the list of packets, and pick out any | 685 // Process DTMF payloads. Cycle through the list of packets, and pick out any |
| 686 // DTMF payloads found. | 686 // DTMF payloads found. |
| 687 PacketList::iterator it = packet_list.begin(); | 687 PacketList::iterator it = packet_list.begin(); |
| 688 while (it != packet_list.end()) { | 688 while (it != packet_list.end()) { |
| (...skipping 1460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2149 } | 2149 } |
| 2150 } | 2150 } |
| 2151 | 2151 |
| 2152 void NetEqImpl::CreateDecisionLogic() { | 2152 void NetEqImpl::CreateDecisionLogic() { |
| 2153 decision_logic_.reset(DecisionLogic::Create( | 2153 decision_logic_.reset(DecisionLogic::Create( |
| 2154 fs_hz_, output_size_samples_, playout_mode_, decoder_database_.get(), | 2154 fs_hz_, output_size_samples_, playout_mode_, decoder_database_.get(), |
| 2155 *packet_buffer_.get(), delay_manager_.get(), buffer_level_filter_.get(), | 2155 *packet_buffer_.get(), delay_manager_.get(), buffer_level_filter_.get(), |
| 2156 tick_timer_.get())); | 2156 tick_timer_.get())); |
| 2157 } | 2157 } |
| 2158 } // namespace webrtc | 2158 } // namespace webrtc |
| OLD | NEW |