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 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 | 574 |
575 int NetEqImpl::InsertPacketInternal(const WebRtcRTPHeader& rtp_header, | 575 int NetEqImpl::InsertPacketInternal(const WebRtcRTPHeader& rtp_header, |
576 rtc::ArrayView<const uint8_t> payload, | 576 rtc::ArrayView<const uint8_t> payload, |
577 uint32_t receive_timestamp) { | 577 uint32_t receive_timestamp) { |
578 if (payload.empty()) { | 578 if (payload.empty()) { |
579 LOG_F(LS_ERROR) << "payload is empty"; | 579 LOG_F(LS_ERROR) << "payload is empty"; |
580 return kInvalidPointer; | 580 return kInvalidPointer; |
581 } | 581 } |
582 | 582 |
583 PacketList packet_list; | 583 PacketList packet_list; |
584 RTPHeader main_header; | |
585 { | 584 { |
586 // Convert to Packet. | 585 // Convert to Packet. |
587 // Create |packet| within this separate scope, since it should not be used | 586 // Create |packet| within this separate scope, since it should not be used |
588 // directly once it's been inserted in the packet list. This way, |packet| | 587 // directly once it's been inserted in the packet list. This way, |packet| |
589 // is not defined outside of this block. | 588 // is not defined outside of this block. |
590 Packet* packet = new Packet; | 589 Packet* packet = new Packet; |
591 packet->header.markerBit = false; | 590 packet->payload_type = rtp_header.header.payloadType; |
592 packet->header.payloadType = rtp_header.header.payloadType; | 591 packet->sequence_number = rtp_header.header.sequenceNumber; |
593 packet->header.sequenceNumber = rtp_header.header.sequenceNumber; | 592 packet->timestamp = rtp_header.header.timestamp; |
594 packet->header.timestamp = rtp_header.header.timestamp; | |
595 packet->header.ssrc = rtp_header.header.ssrc; | |
596 packet->header.numCSRCs = 0; | |
597 packet->payload.SetData(payload.data(), payload.size()); | 593 packet->payload.SetData(payload.data(), payload.size()); |
598 // Waiting time will be set upon inserting the packet in the buffer. | 594 // Waiting time will be set upon inserting the packet in the buffer. |
599 RTC_DCHECK(!packet->waiting_time); | 595 RTC_DCHECK(!packet->waiting_time); |
600 // Insert packet in a packet list. | 596 // Insert packet in a packet list. |
601 packet_list.push_back(packet); | 597 packet_list.push_back(packet); |
602 // Save main payloads header for later. | |
603 memcpy(&main_header, &packet->header, sizeof(main_header)); | |
604 } | 598 } |
605 | 599 |
606 bool update_sample_rate_and_channels = false; | 600 bool update_sample_rate_and_channels = false; |
607 // Reinitialize NetEq if it's needed (changed SSRC or first call). | 601 // Reinitialize NetEq if it's needed (changed SSRC or first call). |
608 if ((main_header.ssrc != ssrc_) || first_packet_) { | 602 if ((rtp_header.header.ssrc != ssrc_) || first_packet_) { |
609 // Note: |first_packet_| will be cleared further down in this method, once | 603 // Note: |first_packet_| will be cleared further down in this method, once |
610 // the packet has been successfully inserted into the packet buffer. | 604 // the packet has been successfully inserted into the packet buffer. |
611 | 605 |
612 rtcp_.Init(main_header.sequenceNumber); | 606 rtcp_.Init(rtp_header.header.sequenceNumber); |
613 | 607 |
614 // Flush the packet buffer and DTMF buffer. | 608 // Flush the packet buffer and DTMF buffer. |
615 packet_buffer_->Flush(); | 609 packet_buffer_->Flush(); |
616 dtmf_buffer_->Flush(); | 610 dtmf_buffer_->Flush(); |
617 | 611 |
618 // Store new SSRC. | 612 // Store new SSRC. |
619 ssrc_ = main_header.ssrc; | 613 ssrc_ = rtp_header.header.ssrc; |
620 | 614 |
621 // Update audio buffer timestamp. | 615 // Update audio buffer timestamp. |
622 sync_buffer_->IncreaseEndTimestamp(main_header.timestamp - timestamp_); | 616 sync_buffer_->IncreaseEndTimestamp(rtp_header.header.timestamp - |
| 617 timestamp_); |
623 | 618 |
624 // Update codecs. | 619 // Update codecs. |
625 timestamp_ = main_header.timestamp; | 620 timestamp_ = rtp_header.header.timestamp; |
626 | 621 |
627 // Reset timestamp scaling. | 622 // Reset timestamp scaling. |
628 timestamp_scaler_->Reset(); | 623 timestamp_scaler_->Reset(); |
629 | 624 |
630 // Trigger an update of sampling rate and the number of channels. | 625 // Trigger an update of sampling rate and the number of channels. |
631 update_sample_rate_and_channels = true; | 626 update_sample_rate_and_channels = true; |
632 } | 627 } |
633 | 628 |
634 // Update RTCP statistics, only for regular packets. | 629 // Update RTCP statistics, only for regular packets. |
635 rtcp_.Update(main_header, receive_timestamp); | 630 rtcp_.Update(rtp_header.header, receive_timestamp); |
| 631 |
| 632 if (nack_enabled_) { |
| 633 RTC_DCHECK(nack_); |
| 634 if (update_sample_rate_and_channels) { |
| 635 nack_->Reset(); |
| 636 } |
| 637 nack_->UpdateLastReceivedPacket(rtp_header.header.sequenceNumber, |
| 638 rtp_header.header.timestamp); |
| 639 } |
636 | 640 |
637 // Check for RED payload type, and separate payloads into several packets. | 641 // Check for RED payload type, and separate payloads into several packets. |
638 if (decoder_database_->IsRed(main_header.payloadType)) { | 642 if (decoder_database_->IsRed(rtp_header.header.payloadType)) { |
639 if (!red_payload_splitter_->SplitRed(&packet_list)) { | 643 if (!red_payload_splitter_->SplitRed(&packet_list)) { |
640 PacketBuffer::DeleteAllPackets(&packet_list); | 644 PacketBuffer::DeleteAllPackets(&packet_list); |
641 return kRedundancySplitError; | 645 return kRedundancySplitError; |
642 } | 646 } |
643 // Only accept a few RED payloads of the same type as the main data, | 647 // Only accept a few RED payloads of the same type as the main data, |
644 // DTMF events and CNG. | 648 // DTMF events and CNG. |
645 red_payload_splitter_->CheckRedPayloads(&packet_list, *decoder_database_); | 649 red_payload_splitter_->CheckRedPayloads(&packet_list, *decoder_database_); |
646 // Update the stored main payload header since the main payload has now | |
647 // changed. | |
648 memcpy(&main_header, &packet_list.front()->header, sizeof(main_header)); | |
649 } | 650 } |
650 | 651 |
651 // Check payload types. | 652 // Check payload types. |
652 if (decoder_database_->CheckPayloadTypes(packet_list) == | 653 if (decoder_database_->CheckPayloadTypes(packet_list) == |
653 DecoderDatabase::kDecoderNotFound) { | 654 DecoderDatabase::kDecoderNotFound) { |
654 PacketBuffer::DeleteAllPackets(&packet_list); | 655 PacketBuffer::DeleteAllPackets(&packet_list); |
655 return kUnknownRtpPayloadType; | 656 return kUnknownRtpPayloadType; |
656 } | 657 } |
657 | 658 |
| 659 RTC_DCHECK(!packet_list.empty()); |
| 660 // Store these for later use, since the first packet may very well disappear |
| 661 // before we need these values. |
| 662 const uint32_t main_timestamp = packet_list.front()->timestamp; |
| 663 const uint8_t main_payload_type = packet_list.front()->payload_type; |
| 664 const uint16_t main_sequence_number = packet_list.front()->sequence_number; |
| 665 |
658 // Scale timestamp to internal domain (only for some codecs). | 666 // Scale timestamp to internal domain (only for some codecs). |
659 timestamp_scaler_->ToInternal(&packet_list); | 667 timestamp_scaler_->ToInternal(&packet_list); |
660 | 668 |
661 // Process DTMF payloads. Cycle through the list of packets, and pick out any | 669 // Process DTMF payloads. Cycle through the list of packets, and pick out any |
662 // DTMF payloads found. | 670 // DTMF payloads found. |
663 PacketList::iterator it = packet_list.begin(); | 671 PacketList::iterator it = packet_list.begin(); |
664 while (it != packet_list.end()) { | 672 while (it != packet_list.end()) { |
665 Packet* current_packet = (*it); | 673 Packet* current_packet = (*it); |
666 assert(current_packet); | 674 assert(current_packet); |
667 assert(!current_packet->payload.empty()); | 675 assert(!current_packet->payload.empty()); |
668 if (decoder_database_->IsDtmf(current_packet->header.payloadType)) { | 676 if (decoder_database_->IsDtmf(current_packet->payload_type)) { |
669 DtmfEvent event; | 677 DtmfEvent event; |
670 int ret = DtmfBuffer::ParseEvent(current_packet->header.timestamp, | 678 int ret = DtmfBuffer::ParseEvent(current_packet->timestamp, |
671 current_packet->payload.data(), | 679 current_packet->payload.data(), |
672 current_packet->payload.size(), &event); | 680 current_packet->payload.size(), &event); |
673 if (ret != DtmfBuffer::kOK) { | 681 if (ret != DtmfBuffer::kOK) { |
674 PacketBuffer::DeleteAllPackets(&packet_list); | 682 PacketBuffer::DeleteAllPackets(&packet_list); |
675 return kDtmfParsingError; | 683 return kDtmfParsingError; |
676 } | 684 } |
677 if (dtmf_buffer_->InsertEvent(event) != DtmfBuffer::kOK) { | 685 if (dtmf_buffer_->InsertEvent(event) != DtmfBuffer::kOK) { |
678 PacketBuffer::DeleteAllPackets(&packet_list); | 686 PacketBuffer::DeleteAllPackets(&packet_list); |
679 return kDtmfInsertError; | 687 return kDtmfInsertError; |
680 } | 688 } |
681 delete current_packet; | 689 delete current_packet; |
682 it = packet_list.erase(it); | 690 it = packet_list.erase(it); |
683 } else { | 691 } else { |
684 ++it; | 692 ++it; |
685 } | 693 } |
686 } | 694 } |
687 | 695 |
688 // Update bandwidth estimate, if the packet is not comfort noise. | 696 // Update bandwidth estimate, if the packet is not comfort noise. |
689 if (!packet_list.empty() && | 697 if (!packet_list.empty() && |
690 !decoder_database_->IsComfortNoise(main_header.payloadType)) { | 698 !decoder_database_->IsComfortNoise(main_payload_type)) { |
691 // The list can be empty here if we got nothing but DTMF payloads. | 699 // The list can be empty here if we got nothing but DTMF payloads. |
692 AudioDecoder* decoder = | 700 AudioDecoder* decoder = decoder_database_->GetDecoder(main_payload_type); |
693 decoder_database_->GetDecoder(main_header.payloadType); | 701 RTC_DCHECK(decoder); // Should always get a valid object, since we have |
694 assert(decoder); // Should always get a valid object, since we have | 702 // already checked that the payload types are known. |
695 // already checked that the payload types are known. | |
696 decoder->IncomingPacket(packet_list.front()->payload.data(), | 703 decoder->IncomingPacket(packet_list.front()->payload.data(), |
697 packet_list.front()->payload.size(), | 704 packet_list.front()->payload.size(), |
698 packet_list.front()->header.sequenceNumber, | 705 packet_list.front()->sequence_number, |
699 packet_list.front()->header.timestamp, | 706 packet_list.front()->timestamp, |
700 receive_timestamp); | 707 receive_timestamp); |
701 } | 708 } |
702 | 709 |
703 PacketList parsed_packet_list; | 710 PacketList parsed_packet_list; |
704 while (!packet_list.empty()) { | 711 while (!packet_list.empty()) { |
705 std::unique_ptr<Packet> packet(packet_list.front()); | 712 std::unique_ptr<Packet> packet(packet_list.front()); |
706 packet_list.pop_front(); | 713 packet_list.pop_front(); |
707 const DecoderDatabase::DecoderInfo* info = | 714 const DecoderDatabase::DecoderInfo* info = |
708 decoder_database_->GetDecoderInfo(packet->header.payloadType); | 715 decoder_database_->GetDecoderInfo(packet->payload_type); |
709 if (!info) { | 716 if (!info) { |
710 LOG(LS_WARNING) << "SplitAudio unknown payload type"; | 717 LOG(LS_WARNING) << "SplitAudio unknown payload type"; |
711 return kUnknownRtpPayloadType; | 718 return kUnknownRtpPayloadType; |
712 } | 719 } |
713 | 720 |
714 if (info->IsComfortNoise()) { | 721 if (info->IsComfortNoise()) { |
715 // Carry comfort noise packets along. | 722 // Carry comfort noise packets along. |
716 parsed_packet_list.push_back(packet.release()); | 723 parsed_packet_list.push_back(packet.release()); |
717 } else { | 724 } else { |
718 std::vector<AudioDecoder::ParseResult> results = | 725 std::vector<AudioDecoder::ParseResult> results = |
719 info->GetDecoder()->ParsePayload(std::move(packet->payload), | 726 info->GetDecoder()->ParsePayload(std::move(packet->payload), |
720 packet->header.timestamp); | 727 packet->timestamp); |
721 const RTPHeader& original_header = packet->header; | 728 const auto sequence_number = packet->sequence_number; |
| 729 const auto payload_type = packet->payload_type; |
722 const Packet::Priority original_priority = packet->priority; | 730 const Packet::Priority original_priority = packet->priority; |
723 for (auto& result : results) { | 731 for (auto& result : results) { |
724 RTC_DCHECK(result.frame); | 732 RTC_DCHECK(result.frame); |
725 // Reuse the packet if possible. | 733 // Reuse the packet if possible. |
726 if (!packet) { | 734 if (!packet) { |
727 packet.reset(new Packet); | 735 packet.reset(new Packet); |
728 packet->header = original_header; | 736 packet->sequence_number = sequence_number; |
| 737 packet->payload_type = payload_type; |
729 } | 738 } |
730 packet->header.timestamp = result.timestamp; | 739 packet->timestamp = result.timestamp; |
731 RTC_DCHECK_GE(result.priority, 0); | 740 RTC_DCHECK_GE(result.priority, 0); |
732 packet->priority.codec_level = result.priority; | 741 packet->priority.codec_level = result.priority; |
733 packet->priority.red_level = original_priority.red_level; | 742 packet->priority.red_level = original_priority.red_level; |
734 packet->frame = std::move(result.frame); | 743 packet->frame = std::move(result.frame); |
735 parsed_packet_list.push_back(packet.release()); | 744 parsed_packet_list.push_back(packet.release()); |
736 } | 745 } |
737 } | 746 } |
738 } | 747 } |
739 | 748 |
740 if (nack_enabled_) { | |
741 RTC_DCHECK(nack_); | |
742 if (update_sample_rate_and_channels) { | |
743 nack_->Reset(); | |
744 } | |
745 nack_->UpdateLastReceivedPacket( | |
746 parsed_packet_list.front()->header.sequenceNumber, | |
747 parsed_packet_list.front()->header.timestamp); | |
748 } | |
749 | |
750 // Insert packets in buffer. | 749 // Insert packets in buffer. |
751 const size_t buffer_length_before_insert = | 750 const size_t buffer_length_before_insert = |
752 packet_buffer_->NumPacketsInBuffer(); | 751 packet_buffer_->NumPacketsInBuffer(); |
753 const int ret = packet_buffer_->InsertPacketList( | 752 const int ret = packet_buffer_->InsertPacketList( |
754 &parsed_packet_list, *decoder_database_, ¤t_rtp_payload_type_, | 753 &parsed_packet_list, *decoder_database_, ¤t_rtp_payload_type_, |
755 ¤t_cng_rtp_payload_type_); | 754 ¤t_cng_rtp_payload_type_); |
756 if (ret == PacketBuffer::kFlushed) { | 755 if (ret == PacketBuffer::kFlushed) { |
757 // Reset DSP timestamp etc. if packet buffer flushed. | 756 // Reset DSP timestamp etc. if packet buffer flushed. |
758 new_codec_ = true; | 757 new_codec_ = true; |
759 update_sample_rate_and_channels = true; | 758 update_sample_rate_and_channels = true; |
(...skipping 14 matching lines...) Expand all Loading... |
774 << " is unknown where it shouldn't be"; | 773 << " is unknown where it shouldn't be"; |
775 } | 774 } |
776 | 775 |
777 if (update_sample_rate_and_channels && !packet_buffer_->Empty()) { | 776 if (update_sample_rate_and_channels && !packet_buffer_->Empty()) { |
778 // We do not use |current_rtp_payload_type_| to |set payload_type|, but | 777 // We do not use |current_rtp_payload_type_| to |set payload_type|, but |
779 // get the next RTP header from |packet_buffer_| to obtain the payload type. | 778 // get the next RTP header from |packet_buffer_| to obtain the payload type. |
780 // The reason for it is the following corner case. If NetEq receives a | 779 // The reason for it is the following corner case. If NetEq receives a |
781 // CNG packet with a sample rate different than the current CNG then it | 780 // CNG packet with a sample rate different than the current CNG then it |
782 // flushes its buffer, assuming send codec must have been changed. However, | 781 // flushes its buffer, assuming send codec must have been changed. However, |
783 // payload type of the hypothetically new send codec is not known. | 782 // payload type of the hypothetically new send codec is not known. |
784 const RTPHeader* rtp_header = packet_buffer_->NextRtpHeader(); | 783 const Packet* next_packet = packet_buffer_->PeekNextPacket(); |
785 assert(rtp_header); | 784 RTC_DCHECK(next_packet); |
786 int payload_type = rtp_header->payloadType; | 785 const int payload_type = next_packet->payload_type; |
787 size_t channels = 1; | 786 size_t channels = 1; |
788 if (!decoder_database_->IsComfortNoise(payload_type)) { | 787 if (!decoder_database_->IsComfortNoise(payload_type)) { |
789 AudioDecoder* decoder = decoder_database_->GetDecoder(payload_type); | 788 AudioDecoder* decoder = decoder_database_->GetDecoder(payload_type); |
790 assert(decoder); // Payloads are already checked to be valid. | 789 assert(decoder); // Payloads are already checked to be valid. |
791 channels = decoder->Channels(); | 790 channels = decoder->Channels(); |
792 } | 791 } |
793 const DecoderDatabase::DecoderInfo* decoder_info = | 792 const DecoderDatabase::DecoderInfo* decoder_info = |
794 decoder_database_->GetDecoderInfo(payload_type); | 793 decoder_database_->GetDecoderInfo(payload_type); |
795 assert(decoder_info); | 794 assert(decoder_info); |
796 if (decoder_info->SampleRateHz() != fs_hz_ || | 795 if (decoder_info->SampleRateHz() != fs_hz_ || |
797 channels != algorithm_buffer_->Channels()) { | 796 channels != algorithm_buffer_->Channels()) { |
798 SetSampleRateAndChannels(decoder_info->SampleRateHz(), | 797 SetSampleRateAndChannels(decoder_info->SampleRateHz(), |
799 channels); | 798 channels); |
800 } | 799 } |
801 if (nack_enabled_) { | 800 if (nack_enabled_) { |
802 RTC_DCHECK(nack_); | 801 RTC_DCHECK(nack_); |
803 // Update the sample rate even if the rate is not new, because of Reset(). | 802 // Update the sample rate even if the rate is not new, because of Reset(). |
804 nack_->UpdateSampleRate(fs_hz_); | 803 nack_->UpdateSampleRate(fs_hz_); |
805 } | 804 } |
806 } | 805 } |
807 | 806 |
808 // TODO(hlundin): Move this code to DelayManager class. | 807 // TODO(hlundin): Move this code to DelayManager class. |
809 const DecoderDatabase::DecoderInfo* dec_info = | 808 const DecoderDatabase::DecoderInfo* dec_info = |
810 decoder_database_->GetDecoderInfo(main_header.payloadType); | 809 decoder_database_->GetDecoderInfo(main_payload_type); |
811 assert(dec_info); // Already checked that the payload type is known. | 810 assert(dec_info); // Already checked that the payload type is known. |
812 delay_manager_->LastDecodedWasCngOrDtmf(dec_info->IsComfortNoise() || | 811 delay_manager_->LastDecodedWasCngOrDtmf(dec_info->IsComfortNoise() || |
813 dec_info->IsDtmf()); | 812 dec_info->IsDtmf()); |
814 if (delay_manager_->last_pack_cng_or_dtmf() == 0) { | 813 if (delay_manager_->last_pack_cng_or_dtmf() == 0) { |
815 // Calculate the total speech length carried in each packet. | 814 // Calculate the total speech length carried in each packet. |
816 const size_t buffer_length_after_insert = | 815 const size_t buffer_length_after_insert = |
817 packet_buffer_->NumPacketsInBuffer(); | 816 packet_buffer_->NumPacketsInBuffer(); |
818 | 817 |
819 if (buffer_length_after_insert > buffer_length_before_insert) { | 818 if (buffer_length_after_insert > buffer_length_before_insert) { |
820 const size_t packet_length_samples = | 819 const size_t packet_length_samples = |
821 (buffer_length_after_insert - buffer_length_before_insert) * | 820 (buffer_length_after_insert - buffer_length_before_insert) * |
822 decoder_frame_length_; | 821 decoder_frame_length_; |
823 if (packet_length_samples != decision_logic_->packet_length_samples()) { | 822 if (packet_length_samples != decision_logic_->packet_length_samples()) { |
824 decision_logic_->set_packet_length_samples(packet_length_samples); | 823 decision_logic_->set_packet_length_samples(packet_length_samples); |
825 delay_manager_->SetPacketAudioLength( | 824 delay_manager_->SetPacketAudioLength( |
826 rtc::checked_cast<int>((1000 * packet_length_samples) / fs_hz_)); | 825 rtc::checked_cast<int>((1000 * packet_length_samples) / fs_hz_)); |
827 } | 826 } |
828 } | 827 } |
829 | 828 |
830 // Update statistics. | 829 // Update statistics. |
831 if ((int32_t) (main_header.timestamp - timestamp_) >= 0 && | 830 if ((int32_t)(main_timestamp - timestamp_) >= 0 && !new_codec_) { |
832 !new_codec_) { | |
833 // Only update statistics if incoming packet is not older than last played | 831 // Only update statistics if incoming packet is not older than last played |
834 // out packet, and if new codec flag is not set. | 832 // out packet, and if new codec flag is not set. |
835 delay_manager_->Update(main_header.sequenceNumber, main_header.timestamp, | 833 delay_manager_->Update(main_sequence_number, main_timestamp, fs_hz_); |
836 fs_hz_); | |
837 } | 834 } |
838 } else if (delay_manager_->last_pack_cng_or_dtmf() == -1) { | 835 } else if (delay_manager_->last_pack_cng_or_dtmf() == -1) { |
839 // This is first "normal" packet after CNG or DTMF. | 836 // This is first "normal" packet after CNG or DTMF. |
840 // Reset packet time counter and measure time until next packet, | 837 // Reset packet time counter and measure time until next packet, |
841 // but don't update statistics. | 838 // but don't update statistics. |
842 delay_manager_->set_last_pack_cng_or_dtmf(0); | 839 delay_manager_->set_last_pack_cng_or_dtmf(0); |
843 delay_manager_->ResetPacketIatCount(); | 840 delay_manager_->ResetPacketIatCount(); |
844 } | 841 } |
845 return 0; | 842 return 0; |
846 } | 843 } |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1084 // Initialize output variables. | 1081 // Initialize output variables. |
1085 *play_dtmf = false; | 1082 *play_dtmf = false; |
1086 *operation = kUndefined; | 1083 *operation = kUndefined; |
1087 | 1084 |
1088 assert(sync_buffer_.get()); | 1085 assert(sync_buffer_.get()); |
1089 uint32_t end_timestamp = sync_buffer_->end_timestamp(); | 1086 uint32_t end_timestamp = sync_buffer_->end_timestamp(); |
1090 if (!new_codec_) { | 1087 if (!new_codec_) { |
1091 const uint32_t five_seconds_samples = 5 * fs_hz_; | 1088 const uint32_t five_seconds_samples = 5 * fs_hz_; |
1092 packet_buffer_->DiscardOldPackets(end_timestamp, five_seconds_samples); | 1089 packet_buffer_->DiscardOldPackets(end_timestamp, five_seconds_samples); |
1093 } | 1090 } |
1094 const RTPHeader* header = packet_buffer_->NextRtpHeader(); | 1091 const Packet* packet = packet_buffer_->PeekNextPacket(); |
1095 | 1092 |
1096 RTC_DCHECK(!generated_noise_stopwatch_ || | 1093 RTC_DCHECK(!generated_noise_stopwatch_ || |
1097 generated_noise_stopwatch_->ElapsedTicks() >= 1); | 1094 generated_noise_stopwatch_->ElapsedTicks() >= 1); |
1098 uint64_t generated_noise_samples = | 1095 uint64_t generated_noise_samples = |
1099 generated_noise_stopwatch_ | 1096 generated_noise_stopwatch_ |
1100 ? (generated_noise_stopwatch_->ElapsedTicks() - 1) * | 1097 ? (generated_noise_stopwatch_->ElapsedTicks() - 1) * |
1101 output_size_samples_ + | 1098 output_size_samples_ + |
1102 decision_logic_->noise_fast_forward() | 1099 decision_logic_->noise_fast_forward() |
1103 : 0; | 1100 : 0; |
1104 | 1101 |
1105 if (decision_logic_->CngRfc3389On() || last_mode_ == kModeRfc3389Cng) { | 1102 if (decision_logic_->CngRfc3389On() || last_mode_ == kModeRfc3389Cng) { |
1106 // Because of timestamp peculiarities, we have to "manually" disallow using | 1103 // Because of timestamp peculiarities, we have to "manually" disallow using |
1107 // a CNG packet with the same timestamp as the one that was last played. | 1104 // a CNG packet with the same timestamp as the one that was last played. |
1108 // This can happen when using redundancy and will cause the timing to shift. | 1105 // This can happen when using redundancy and will cause the timing to shift. |
1109 while (header && decoder_database_->IsComfortNoise(header->payloadType) && | 1106 while (packet && decoder_database_->IsComfortNoise(packet->payload_type) && |
1110 (end_timestamp >= header->timestamp || | 1107 (end_timestamp >= packet->timestamp || |
1111 end_timestamp + generated_noise_samples > header->timestamp)) { | 1108 end_timestamp + generated_noise_samples > packet->timestamp)) { |
1112 // Don't use this packet, discard it. | 1109 // Don't use this packet, discard it. |
1113 if (packet_buffer_->DiscardNextPacket() != PacketBuffer::kOK) { | 1110 if (packet_buffer_->DiscardNextPacket() != PacketBuffer::kOK) { |
1114 assert(false); // Must be ok by design. | 1111 assert(false); // Must be ok by design. |
1115 } | 1112 } |
1116 // Check buffer again. | 1113 // Check buffer again. |
1117 if (!new_codec_) { | 1114 if (!new_codec_) { |
1118 packet_buffer_->DiscardOldPackets(end_timestamp, 5 * fs_hz_); | 1115 packet_buffer_->DiscardOldPackets(end_timestamp, 5 * fs_hz_); |
1119 } | 1116 } |
1120 header = packet_buffer_->NextRtpHeader(); | 1117 packet = packet_buffer_->PeekNextPacket(); |
1121 } | 1118 } |
1122 } | 1119 } |
1123 | 1120 |
1124 assert(expand_.get()); | 1121 assert(expand_.get()); |
1125 const int samples_left = static_cast<int>(sync_buffer_->FutureLength() - | 1122 const int samples_left = static_cast<int>(sync_buffer_->FutureLength() - |
1126 expand_->overlap_length()); | 1123 expand_->overlap_length()); |
1127 if (last_mode_ == kModeAccelerateSuccess || | 1124 if (last_mode_ == kModeAccelerateSuccess || |
1128 last_mode_ == kModeAccelerateLowEnergy || | 1125 last_mode_ == kModeAccelerateLowEnergy || |
1129 last_mode_ == kModePreemptiveExpandSuccess || | 1126 last_mode_ == kModePreemptiveExpandSuccess || |
1130 last_mode_ == kModePreemptiveExpandLowEnergy) { | 1127 last_mode_ == kModePreemptiveExpandLowEnergy) { |
(...skipping 12 matching lines...) Expand all Loading... |
1143 | 1140 |
1144 // Get instruction. | 1141 // Get instruction. |
1145 assert(sync_buffer_.get()); | 1142 assert(sync_buffer_.get()); |
1146 assert(expand_.get()); | 1143 assert(expand_.get()); |
1147 generated_noise_samples = | 1144 generated_noise_samples = |
1148 generated_noise_stopwatch_ | 1145 generated_noise_stopwatch_ |
1149 ? generated_noise_stopwatch_->ElapsedTicks() * output_size_samples_ + | 1146 ? generated_noise_stopwatch_->ElapsedTicks() * output_size_samples_ + |
1150 decision_logic_->noise_fast_forward() | 1147 decision_logic_->noise_fast_forward() |
1151 : 0; | 1148 : 0; |
1152 *operation = decision_logic_->GetDecision( | 1149 *operation = decision_logic_->GetDecision( |
1153 *sync_buffer_, *expand_, decoder_frame_length_, header, last_mode_, | 1150 *sync_buffer_, *expand_, decoder_frame_length_, packet, last_mode_, |
1154 *play_dtmf, generated_noise_samples, &reset_decoder_); | 1151 *play_dtmf, generated_noise_samples, &reset_decoder_); |
1155 | 1152 |
1156 // Check if we already have enough samples in the |sync_buffer_|. If so, | 1153 // Check if we already have enough samples in the |sync_buffer_|. If so, |
1157 // change decision to normal, unless the decision was merge, accelerate, or | 1154 // change decision to normal, unless the decision was merge, accelerate, or |
1158 // preemptive expand. | 1155 // preemptive expand. |
1159 if (samples_left >= rtc::checked_cast<int>(output_size_samples_) && | 1156 if (samples_left >= rtc::checked_cast<int>(output_size_samples_) && |
1160 *operation != kMerge && | 1157 *operation != kMerge && |
1161 *operation != kAccelerate && | 1158 *operation != kAccelerate && |
1162 *operation != kFastAccelerate && | 1159 *operation != kFastAccelerate && |
1163 *operation != kPreemptiveExpand) { | 1160 *operation != kPreemptiveExpand) { |
1164 *operation = kNormal; | 1161 *operation = kNormal; |
1165 return 0; | 1162 return 0; |
1166 } | 1163 } |
1167 | 1164 |
1168 decision_logic_->ExpandDecision(*operation); | 1165 decision_logic_->ExpandDecision(*operation); |
1169 | 1166 |
1170 // Check conditions for reset. | 1167 // Check conditions for reset. |
1171 if (new_codec_ || *operation == kUndefined) { | 1168 if (new_codec_ || *operation == kUndefined) { |
1172 // The only valid reason to get kUndefined is that new_codec_ is set. | 1169 // The only valid reason to get kUndefined is that new_codec_ is set. |
1173 assert(new_codec_); | 1170 assert(new_codec_); |
1174 if (*play_dtmf && !header) { | 1171 if (*play_dtmf && !packet) { |
1175 timestamp_ = dtmf_event->timestamp; | 1172 timestamp_ = dtmf_event->timestamp; |
1176 } else { | 1173 } else { |
1177 if (!header) { | 1174 if (!packet) { |
1178 LOG(LS_ERROR) << "Packet missing where it shouldn't."; | 1175 LOG(LS_ERROR) << "Packet missing where it shouldn't."; |
1179 return -1; | 1176 return -1; |
1180 } | 1177 } |
1181 timestamp_ = header->timestamp; | 1178 timestamp_ = packet->timestamp; |
1182 if (*operation == kRfc3389CngNoPacket && | 1179 if (*operation == kRfc3389CngNoPacket && |
1183 decoder_database_->IsComfortNoise(header->payloadType)) { | 1180 decoder_database_->IsComfortNoise(packet->payload_type)) { |
1184 // Change decision to CNG packet, since we do have a CNG packet, but it | 1181 // Change decision to CNG packet, since we do have a CNG packet, but it |
1185 // was considered too early to use. Now, use it anyway. | 1182 // was considered too early to use. Now, use it anyway. |
1186 *operation = kRfc3389Cng; | 1183 *operation = kRfc3389Cng; |
1187 } else if (*operation != kRfc3389Cng) { | 1184 } else if (*operation != kRfc3389Cng) { |
1188 *operation = kNormal; | 1185 *operation = kNormal; |
1189 } | 1186 } |
1190 } | 1187 } |
1191 // Adjust |sync_buffer_| timestamp before setting |end_timestamp| to the | 1188 // Adjust |sync_buffer_| timestamp before setting |end_timestamp| to the |
1192 // new value. | 1189 // new value. |
1193 sync_buffer_->IncreaseEndTimestamp(timestamp_ - end_timestamp); | 1190 sync_buffer_->IncreaseEndTimestamp(timestamp_ - end_timestamp); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1287 std::max(merge_->RequiredFutureSamples(), required_samples); | 1284 std::max(merge_->RequiredFutureSamples(), required_samples); |
1288 break; | 1285 break; |
1289 } | 1286 } |
1290 default: { | 1287 default: { |
1291 // Do nothing. | 1288 // Do nothing. |
1292 } | 1289 } |
1293 } | 1290 } |
1294 | 1291 |
1295 // Get packets from buffer. | 1292 // Get packets from buffer. |
1296 int extracted_samples = 0; | 1293 int extracted_samples = 0; |
1297 if (header && | 1294 if (packet && *operation != kAlternativePlc && |
1298 *operation != kAlternativePlc && | |
1299 *operation != kAlternativePlcIncreaseTimestamp && | 1295 *operation != kAlternativePlcIncreaseTimestamp && |
1300 *operation != kAudioRepetition && | 1296 *operation != kAudioRepetition && |
1301 *operation != kAudioRepetitionIncreaseTimestamp) { | 1297 *operation != kAudioRepetitionIncreaseTimestamp) { |
1302 sync_buffer_->IncreaseEndTimestamp(header->timestamp - end_timestamp); | 1298 sync_buffer_->IncreaseEndTimestamp(packet->timestamp - end_timestamp); |
1303 if (decision_logic_->CngOff()) { | 1299 if (decision_logic_->CngOff()) { |
1304 // Adjustment of timestamp only corresponds to an actual packet loss | 1300 // Adjustment of timestamp only corresponds to an actual packet loss |
1305 // if comfort noise is not played. If comfort noise was just played, | 1301 // if comfort noise is not played. If comfort noise was just played, |
1306 // this adjustment of timestamp is only done to get back in sync with the | 1302 // this adjustment of timestamp is only done to get back in sync with the |
1307 // stream timestamp; no loss to report. | 1303 // stream timestamp; no loss to report. |
1308 stats_.LostSamples(header->timestamp - end_timestamp); | 1304 stats_.LostSamples(packet->timestamp - end_timestamp); |
1309 } | 1305 } |
1310 | 1306 |
1311 if (*operation != kRfc3389Cng) { | 1307 if (*operation != kRfc3389Cng) { |
1312 // We are about to decode and use a non-CNG packet. | 1308 // We are about to decode and use a non-CNG packet. |
1313 decision_logic_->SetCngOff(); | 1309 decision_logic_->SetCngOff(); |
1314 } | 1310 } |
1315 | 1311 |
1316 extracted_samples = ExtractPackets(required_samples, packet_list); | 1312 extracted_samples = ExtractPackets(required_samples, packet_list); |
1317 if (extracted_samples < 0) { | 1313 if (extracted_samples < 0) { |
1318 return kPacketBufferCorruption; | 1314 return kPacketBufferCorruption; |
(...skipping 23 matching lines...) Expand all Loading... |
1342 int* decoded_length, | 1338 int* decoded_length, |
1343 AudioDecoder::SpeechType* speech_type) { | 1339 AudioDecoder::SpeechType* speech_type) { |
1344 *speech_type = AudioDecoder::kSpeech; | 1340 *speech_type = AudioDecoder::kSpeech; |
1345 | 1341 |
1346 // When packet_list is empty, we may be in kCodecInternalCng mode, and for | 1342 // When packet_list is empty, we may be in kCodecInternalCng mode, and for |
1347 // that we use current active decoder. | 1343 // that we use current active decoder. |
1348 AudioDecoder* decoder = decoder_database_->GetActiveDecoder(); | 1344 AudioDecoder* decoder = decoder_database_->GetActiveDecoder(); |
1349 | 1345 |
1350 if (!packet_list->empty()) { | 1346 if (!packet_list->empty()) { |
1351 const Packet* packet = packet_list->front(); | 1347 const Packet* packet = packet_list->front(); |
1352 uint8_t payload_type = packet->header.payloadType; | 1348 uint8_t payload_type = packet->payload_type; |
1353 if (!decoder_database_->IsComfortNoise(payload_type)) { | 1349 if (!decoder_database_->IsComfortNoise(payload_type)) { |
1354 decoder = decoder_database_->GetDecoder(payload_type); | 1350 decoder = decoder_database_->GetDecoder(payload_type); |
1355 assert(decoder); | 1351 assert(decoder); |
1356 if (!decoder) { | 1352 if (!decoder) { |
1357 LOG(LS_WARNING) << "Unknown payload type " | 1353 LOG(LS_WARNING) << "Unknown payload type " |
1358 << static_cast<int>(payload_type); | 1354 << static_cast<int>(payload_type); |
1359 PacketBuffer::DeleteAllPackets(packet_list); | 1355 PacketBuffer::DeleteAllPackets(packet_list); |
1360 return kDecoderNotFound; | 1356 return kDecoderNotFound; |
1361 } | 1357 } |
1362 bool decoder_changed; | 1358 bool decoder_changed; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1478 | 1474 |
1479 int NetEqImpl::DecodeLoop(PacketList* packet_list, const Operations& operation, | 1475 int NetEqImpl::DecodeLoop(PacketList* packet_list, const Operations& operation, |
1480 AudioDecoder* decoder, int* decoded_length, | 1476 AudioDecoder* decoder, int* decoded_length, |
1481 AudioDecoder::SpeechType* speech_type) { | 1477 AudioDecoder::SpeechType* speech_type) { |
1482 Packet* packet = NULL; | 1478 Packet* packet = NULL; |
1483 if (!packet_list->empty()) { | 1479 if (!packet_list->empty()) { |
1484 packet = packet_list->front(); | 1480 packet = packet_list->front(); |
1485 } | 1481 } |
1486 | 1482 |
1487 // Do decoding. | 1483 // Do decoding. |
1488 while (packet && | 1484 while (packet && !decoder_database_->IsComfortNoise(packet->payload_type)) { |
1489 !decoder_database_->IsComfortNoise(packet->header.payloadType)) { | |
1490 assert(decoder); // At this point, we must have a decoder object. | 1485 assert(decoder); // At this point, we must have a decoder object. |
1491 // The number of channels in the |sync_buffer_| should be the same as the | 1486 // The number of channels in the |sync_buffer_| should be the same as the |
1492 // number decoder channels. | 1487 // number decoder channels. |
1493 assert(sync_buffer_->Channels() == decoder->Channels()); | 1488 assert(sync_buffer_->Channels() == decoder->Channels()); |
1494 assert(decoded_buffer_length_ >= kMaxFrameSize * decoder->Channels()); | 1489 assert(decoded_buffer_length_ >= kMaxFrameSize * decoder->Channels()); |
1495 assert(operation == kNormal || operation == kAccelerate || | 1490 assert(operation == kNormal || operation == kAccelerate || |
1496 operation == kFastAccelerate || operation == kMerge || | 1491 operation == kFastAccelerate || operation == kMerge || |
1497 operation == kPreemptiveExpand); | 1492 operation == kPreemptiveExpand); |
1498 packet_list->pop_front(); | 1493 packet_list->pop_front(); |
1499 auto opt_result = packet->frame->Decode( | 1494 auto opt_result = packet->frame->Decode( |
(...skipping 28 matching lines...) Expand all Loading... |
1528 packet = packet_list->front(); | 1523 packet = packet_list->front(); |
1529 } else { | 1524 } else { |
1530 packet = NULL; | 1525 packet = NULL; |
1531 } | 1526 } |
1532 } // End of decode loop. | 1527 } // End of decode loop. |
1533 | 1528 |
1534 // If the list is not empty at this point, either a decoding error terminated | 1529 // If the list is not empty at this point, either a decoding error terminated |
1535 // the while-loop, or list must hold exactly one CNG packet. | 1530 // the while-loop, or list must hold exactly one CNG packet. |
1536 assert(packet_list->empty() || *decoded_length < 0 || | 1531 assert(packet_list->empty() || *decoded_length < 0 || |
1537 (packet_list->size() == 1 && packet && | 1532 (packet_list->size() == 1 && packet && |
1538 decoder_database_->IsComfortNoise(packet->header.payloadType))); | 1533 decoder_database_->IsComfortNoise(packet->payload_type))); |
1539 return 0; | 1534 return 0; |
1540 } | 1535 } |
1541 | 1536 |
1542 void NetEqImpl::DoNormal(const int16_t* decoded_buffer, size_t decoded_length, | 1537 void NetEqImpl::DoNormal(const int16_t* decoded_buffer, size_t decoded_length, |
1543 AudioDecoder::SpeechType speech_type, bool play_dtmf) { | 1538 AudioDecoder::SpeechType speech_type, bool play_dtmf) { |
1544 assert(normal_.get()); | 1539 assert(normal_.get()); |
1545 assert(mute_factor_array_.get()); | 1540 assert(mute_factor_array_.get()); |
1546 normal_->Process(decoded_buffer, decoded_length, last_mode_, | 1541 normal_->Process(decoded_buffer, decoded_length, last_mode_, |
1547 mute_factor_array_.get(), algorithm_buffer_.get()); | 1542 mute_factor_array_.get(), algorithm_buffer_.get()); |
1548 if (decoded_length != 0) { | 1543 if (decoded_length != 0) { |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1770 expand_->Reset(); | 1765 expand_->Reset(); |
1771 return 0; | 1766 return 0; |
1772 } | 1767 } |
1773 | 1768 |
1774 int NetEqImpl::DoRfc3389Cng(PacketList* packet_list, bool play_dtmf) { | 1769 int NetEqImpl::DoRfc3389Cng(PacketList* packet_list, bool play_dtmf) { |
1775 if (!packet_list->empty()) { | 1770 if (!packet_list->empty()) { |
1776 // Must have exactly one SID frame at this point. | 1771 // Must have exactly one SID frame at this point. |
1777 assert(packet_list->size() == 1); | 1772 assert(packet_list->size() == 1); |
1778 Packet* packet = packet_list->front(); | 1773 Packet* packet = packet_list->front(); |
1779 packet_list->pop_front(); | 1774 packet_list->pop_front(); |
1780 if (!decoder_database_->IsComfortNoise(packet->header.payloadType)) { | 1775 if (!decoder_database_->IsComfortNoise(packet->payload_type)) { |
1781 LOG(LS_ERROR) << "Trying to decode non-CNG payload as CNG."; | 1776 LOG(LS_ERROR) << "Trying to decode non-CNG payload as CNG."; |
1782 return kOtherError; | 1777 return kOtherError; |
1783 } | 1778 } |
1784 // UpdateParameters() deletes |packet|. | 1779 // UpdateParameters() deletes |packet|. |
1785 if (comfort_noise_->UpdateParameters(packet) == | 1780 if (comfort_noise_->UpdateParameters(packet) == |
1786 ComfortNoise::kInternalError) { | 1781 ComfortNoise::kInternalError) { |
1787 algorithm_buffer_->Zeros(output_size_samples_); | 1782 algorithm_buffer_->Zeros(output_size_samples_); |
1788 return -comfort_noise_->internal_error_code(); | 1783 return -comfort_noise_->internal_error_code(); |
1789 } | 1784 } |
1790 } | 1785 } |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1946 } | 1941 } |
1947 | 1942 |
1948 int NetEqImpl::ExtractPackets(size_t required_samples, | 1943 int NetEqImpl::ExtractPackets(size_t required_samples, |
1949 PacketList* packet_list) { | 1944 PacketList* packet_list) { |
1950 bool first_packet = true; | 1945 bool first_packet = true; |
1951 uint8_t prev_payload_type = 0; | 1946 uint8_t prev_payload_type = 0; |
1952 uint32_t prev_timestamp = 0; | 1947 uint32_t prev_timestamp = 0; |
1953 uint16_t prev_sequence_number = 0; | 1948 uint16_t prev_sequence_number = 0; |
1954 bool next_packet_available = false; | 1949 bool next_packet_available = false; |
1955 | 1950 |
1956 const RTPHeader* header = packet_buffer_->NextRtpHeader(); | 1951 const Packet* next_packet = packet_buffer_->PeekNextPacket(); |
1957 assert(header); | 1952 RTC_DCHECK(next_packet); |
1958 if (!header) { | 1953 if (!next_packet) { |
1959 LOG(LS_ERROR) << "Packet buffer unexpectedly empty."; | 1954 LOG(LS_ERROR) << "Packet buffer unexpectedly empty."; |
1960 return -1; | 1955 return -1; |
1961 } | 1956 } |
1962 uint32_t first_timestamp = header->timestamp; | 1957 uint32_t first_timestamp = next_packet->timestamp; |
1963 size_t extracted_samples = 0; | 1958 size_t extracted_samples = 0; |
1964 | 1959 |
1965 // Packet extraction loop. | 1960 // Packet extraction loop. |
1966 do { | 1961 do { |
1967 timestamp_ = header->timestamp; | 1962 timestamp_ = next_packet->timestamp; |
1968 size_t discard_count = 0; | 1963 size_t discard_count = 0; |
1969 Packet* packet = packet_buffer_->GetNextPacket(&discard_count); | 1964 Packet* packet = packet_buffer_->GetNextPacket(&discard_count); |
1970 // |header| may be invalid after the |packet_buffer_| operation. | 1965 // |next_packet| may be invalid after the |packet_buffer_| operation. |
1971 header = NULL; | 1966 next_packet = NULL; |
1972 if (!packet) { | 1967 if (!packet) { |
1973 LOG(LS_ERROR) << "Should always be able to extract a packet here"; | 1968 LOG(LS_ERROR) << "Should always be able to extract a packet here"; |
1974 assert(false); // Should always be able to extract a packet here. | 1969 assert(false); // Should always be able to extract a packet here. |
1975 return -1; | 1970 return -1; |
1976 } | 1971 } |
1977 stats_.PacketsDiscarded(discard_count); | 1972 stats_.PacketsDiscarded(discard_count); |
1978 stats_.StoreWaitingTime(packet->waiting_time->ElapsedMs()); | 1973 stats_.StoreWaitingTime(packet->waiting_time->ElapsedMs()); |
1979 RTC_DCHECK(!packet->empty()); | 1974 RTC_DCHECK(!packet->empty()); |
1980 packet_list->push_back(packet); // Store packet in list. | 1975 packet_list->push_back(packet); // Store packet in list. |
1981 | 1976 |
1982 if (first_packet) { | 1977 if (first_packet) { |
1983 first_packet = false; | 1978 first_packet = false; |
1984 if (nack_enabled_) { | 1979 if (nack_enabled_) { |
1985 RTC_DCHECK(nack_); | 1980 RTC_DCHECK(nack_); |
1986 // TODO(henrik.lundin): Should we update this for all decoded packets? | 1981 // TODO(henrik.lundin): Should we update this for all decoded packets? |
1987 nack_->UpdateLastDecodedPacket(packet->header.sequenceNumber, | 1982 nack_->UpdateLastDecodedPacket(packet->sequence_number, |
1988 packet->header.timestamp); | 1983 packet->timestamp); |
1989 } | 1984 } |
1990 prev_sequence_number = packet->header.sequenceNumber; | 1985 prev_sequence_number = packet->sequence_number; |
1991 prev_timestamp = packet->header.timestamp; | 1986 prev_timestamp = packet->timestamp; |
1992 prev_payload_type = packet->header.payloadType; | 1987 prev_payload_type = packet->payload_type; |
1993 } | 1988 } |
1994 | 1989 |
1995 // Store number of extracted samples. | 1990 // Store number of extracted samples. |
1996 size_t packet_duration = 0; | 1991 size_t packet_duration = 0; |
1997 if (packet->frame) { | 1992 if (packet->frame) { |
1998 packet_duration = packet->frame->Duration(); | 1993 packet_duration = packet->frame->Duration(); |
1999 // TODO(ossu): Is this the correct way to track Opus FEC packets? | 1994 // TODO(ossu): Is this the correct way to track Opus FEC packets? |
2000 if (packet->priority.codec_level > 0) { | 1995 if (packet->priority.codec_level > 0) { |
2001 stats_.SecondaryDecodedSamples(rtc::checked_cast<int>(packet_duration)); | 1996 stats_.SecondaryDecodedSamples(rtc::checked_cast<int>(packet_duration)); |
2002 } | 1997 } |
2003 } else if (!decoder_database_->IsComfortNoise(packet->header.payloadType)) { | 1998 } else if (!decoder_database_->IsComfortNoise(packet->payload_type)) { |
2004 LOG(LS_WARNING) << "Unknown payload type " | 1999 LOG(LS_WARNING) << "Unknown payload type " |
2005 << static_cast<int>(packet->header.payloadType); | 2000 << static_cast<int>(packet->payload_type); |
2006 RTC_NOTREACHED(); | 2001 RTC_NOTREACHED(); |
2007 } | 2002 } |
2008 | 2003 |
2009 if (packet_duration == 0) { | 2004 if (packet_duration == 0) { |
2010 // Decoder did not return a packet duration. Assume that the packet | 2005 // Decoder did not return a packet duration. Assume that the packet |
2011 // contains the same number of samples as the previous one. | 2006 // contains the same number of samples as the previous one. |
2012 packet_duration = decoder_frame_length_; | 2007 packet_duration = decoder_frame_length_; |
2013 } | 2008 } |
2014 extracted_samples = packet->header.timestamp - first_timestamp + | 2009 extracted_samples = packet->timestamp - first_timestamp + packet_duration; |
2015 packet_duration; | |
2016 | 2010 |
2017 // Check what packet is available next. | 2011 // Check what packet is available next. |
2018 header = packet_buffer_->NextRtpHeader(); | 2012 next_packet = packet_buffer_->PeekNextPacket(); |
2019 next_packet_available = false; | 2013 next_packet_available = false; |
2020 if (header && prev_payload_type == header->payloadType) { | 2014 if (next_packet && prev_payload_type == next_packet->payload_type) { |
2021 int16_t seq_no_diff = header->sequenceNumber - prev_sequence_number; | 2015 int16_t seq_no_diff = next_packet->sequence_number - prev_sequence_number; |
2022 size_t ts_diff = header->timestamp - prev_timestamp; | 2016 size_t ts_diff = next_packet->timestamp - prev_timestamp; |
2023 if (seq_no_diff == 1 || | 2017 if (seq_no_diff == 1 || |
2024 (seq_no_diff == 0 && ts_diff == decoder_frame_length_)) { | 2018 (seq_no_diff == 0 && ts_diff == decoder_frame_length_)) { |
2025 // The next sequence number is available, or the next part of a packet | 2019 // The next sequence number is available, or the next part of a packet |
2026 // that was split into pieces upon insertion. | 2020 // that was split into pieces upon insertion. |
2027 next_packet_available = true; | 2021 next_packet_available = true; |
2028 } | 2022 } |
2029 prev_sequence_number = header->sequenceNumber; | 2023 prev_sequence_number = next_packet->sequence_number; |
2030 } | 2024 } |
2031 } while (extracted_samples < required_samples && next_packet_available); | 2025 } while (extracted_samples < required_samples && next_packet_available); |
2032 | 2026 |
2033 if (extracted_samples > 0) { | 2027 if (extracted_samples > 0) { |
2034 // Delete old packets only when we are going to decode something. Otherwise, | 2028 // Delete old packets only when we are going to decode something. Otherwise, |
2035 // we could end up in the situation where we never decode anything, since | 2029 // we could end up in the situation where we never decode anything, since |
2036 // all incoming packets are considered too old but the buffer will also | 2030 // all incoming packets are considered too old but the buffer will also |
2037 // never be flooded and flushed. | 2031 // never be flooded and flushed. |
2038 packet_buffer_->DiscardAllOldPackets(timestamp_); | 2032 packet_buffer_->DiscardAllOldPackets(timestamp_); |
2039 } | 2033 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2138 } | 2132 } |
2139 } | 2133 } |
2140 | 2134 |
2141 void NetEqImpl::CreateDecisionLogic() { | 2135 void NetEqImpl::CreateDecisionLogic() { |
2142 decision_logic_.reset(DecisionLogic::Create( | 2136 decision_logic_.reset(DecisionLogic::Create( |
2143 fs_hz_, output_size_samples_, playout_mode_, decoder_database_.get(), | 2137 fs_hz_, output_size_samples_, playout_mode_, decoder_database_.get(), |
2144 *packet_buffer_.get(), delay_manager_.get(), buffer_level_filter_.get(), | 2138 *packet_buffer_.get(), delay_manager_.get(), buffer_level_filter_.get(), |
2145 tick_timer_.get())); | 2139 tick_timer_.get())); |
2146 } | 2140 } |
2147 } // namespace webrtc | 2141 } // namespace webrtc |
OLD | NEW |