Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(457)

Side by Side Diff: webrtc/modules/audio_coding/neteq/neteq_impl.cc

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

Powered by Google App Engine
This is Rietveld 408576698