Chromium Code Reviews| 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 { | 584 // Insert packet in a packet list. |
| 585 packet_list.push_back([&rtp_header, &payload] { | |
| 585 // Convert to Packet. | 586 // Convert to Packet. |
| 586 // Create |packet| within this separate scope, since it should not be used | 587 Packet packet; |
| 587 // directly once it's been inserted in the packet list. This way, |packet| | 588 packet.payload_type = rtp_header.header.payloadType; |
| 588 // is not defined outside of this block. | 589 packet.sequence_number = rtp_header.header.sequenceNumber; |
| 589 Packet* packet = new Packet; | 590 packet.timestamp = rtp_header.header.timestamp; |
| 590 packet->payload_type = rtp_header.header.payloadType; | 591 packet.payload.SetData(payload.data(), payload.size()); |
| 591 packet->sequence_number = rtp_header.header.sequenceNumber; | |
| 592 packet->timestamp = rtp_header.header.timestamp; | |
| 593 packet->payload.SetData(payload.data(), payload.size()); | |
| 594 // Waiting time will be set upon inserting the packet in the buffer. | 592 // Waiting time will be set upon inserting the packet in the buffer. |
| 595 RTC_DCHECK(!packet->waiting_time); | 593 RTC_DCHECK(!packet.waiting_time); |
| 596 // Insert packet in a packet list. | 594 return packet; |
| 597 packet_list.push_back(packet); | 595 }()); |
| 598 } | |
| 599 | 596 |
| 600 bool update_sample_rate_and_channels = false; | 597 bool update_sample_rate_and_channels = false; |
| 601 // Reinitialize NetEq if it's needed (changed SSRC or first call). | 598 // Reinitialize NetEq if it's needed (changed SSRC or first call). |
| 602 if ((rtp_header.header.ssrc != ssrc_) || first_packet_) { | 599 if ((rtp_header.header.ssrc != ssrc_) || first_packet_) { |
| 603 // Note: |first_packet_| will be cleared further down in this method, once | 600 // Note: |first_packet_| will be cleared further down in this method, once |
| 604 // the packet has been successfully inserted into the packet buffer. | 601 // the packet has been successfully inserted into the packet buffer. |
| 605 | 602 |
| 606 rtcp_.Init(rtp_header.header.sequenceNumber); | 603 rtcp_.Init(rtp_header.header.sequenceNumber); |
| 607 | 604 |
| 608 // Flush the packet buffer and DTMF buffer. | 605 // Flush the packet buffer and DTMF buffer. |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 634 if (update_sample_rate_and_channels) { | 631 if (update_sample_rate_and_channels) { |
| 635 nack_->Reset(); | 632 nack_->Reset(); |
| 636 } | 633 } |
| 637 nack_->UpdateLastReceivedPacket(rtp_header.header.sequenceNumber, | 634 nack_->UpdateLastReceivedPacket(rtp_header.header.sequenceNumber, |
| 638 rtp_header.header.timestamp); | 635 rtp_header.header.timestamp); |
| 639 } | 636 } |
| 640 | 637 |
| 641 // Check for RED payload type, and separate payloads into several packets. | 638 // Check for RED payload type, and separate payloads into several packets. |
| 642 if (decoder_database_->IsRed(rtp_header.header.payloadType)) { | 639 if (decoder_database_->IsRed(rtp_header.header.payloadType)) { |
| 643 if (!red_payload_splitter_->SplitRed(&packet_list)) { | 640 if (!red_payload_splitter_->SplitRed(&packet_list)) { |
| 644 PacketBuffer::DeleteAllPackets(&packet_list); | |
| 645 return kRedundancySplitError; | 641 return kRedundancySplitError; |
| 646 } | 642 } |
| 647 // Only accept a few RED payloads of the same type as the main data, | 643 // Only accept a few RED payloads of the same type as the main data, |
| 648 // DTMF events and CNG. | 644 // DTMF events and CNG. |
| 649 red_payload_splitter_->CheckRedPayloads(&packet_list, *decoder_database_); | 645 red_payload_splitter_->CheckRedPayloads(&packet_list, *decoder_database_); |
| 650 } | 646 } |
| 651 | 647 |
| 652 // Check payload types. | 648 // Check payload types. |
| 653 if (decoder_database_->CheckPayloadTypes(packet_list) == | 649 if (decoder_database_->CheckPayloadTypes(packet_list) == |
| 654 DecoderDatabase::kDecoderNotFound) { | 650 DecoderDatabase::kDecoderNotFound) { |
| 655 PacketBuffer::DeleteAllPackets(&packet_list); | |
| 656 return kUnknownRtpPayloadType; | 651 return kUnknownRtpPayloadType; |
| 657 } | 652 } |
| 658 | 653 |
| 659 RTC_DCHECK(!packet_list.empty()); | 654 RTC_DCHECK(!packet_list.empty()); |
| 660 // Store these for later use, since the first packet may very well disappear | 655 // Store these for later use, since the first packet may very well disappear |
| 661 // before we need these values. | 656 // before we need these values. |
| 662 const uint32_t main_timestamp = packet_list.front()->timestamp; | 657 const uint32_t main_timestamp = packet_list.front().timestamp; |
| 663 const uint8_t main_payload_type = packet_list.front()->payload_type; | 658 const uint8_t main_payload_type = packet_list.front().payload_type; |
| 664 const uint16_t main_sequence_number = packet_list.front()->sequence_number; | 659 const uint16_t main_sequence_number = packet_list.front().sequence_number; |
| 665 | 660 |
| 666 // Scale timestamp to internal domain (only for some codecs). | 661 // Scale timestamp to internal domain (only for some codecs). |
| 667 timestamp_scaler_->ToInternal(&packet_list); | 662 timestamp_scaler_->ToInternal(&packet_list); |
| 668 | 663 |
| 669 // Process DTMF payloads. Cycle through the list of packets, and pick out any | 664 // Process DTMF payloads. Cycle through the list of packets, and pick out any |
| 670 // DTMF payloads found. | 665 // DTMF payloads found. |
| 671 PacketList::iterator it = packet_list.begin(); | 666 PacketList::iterator it = packet_list.begin(); |
| 672 while (it != packet_list.end()) { | 667 while (it != packet_list.end()) { |
| 673 Packet* current_packet = (*it); | 668 Packet& current_packet = (*it); |
|
hlundin-webrtc
2016/10/21 13:53:33
const Packet&
ossu
2016/10/24 12:18:28
Done.
| |
| 674 assert(current_packet); | 669 RTC_DCHECK(!current_packet.payload.empty()); |
| 675 assert(!current_packet->payload.empty()); | 670 if (decoder_database_->IsDtmf(current_packet.payload_type)) { |
| 676 if (decoder_database_->IsDtmf(current_packet->payload_type)) { | |
| 677 DtmfEvent event; | 671 DtmfEvent event; |
| 678 int ret = DtmfBuffer::ParseEvent(current_packet->timestamp, | 672 int ret = DtmfBuffer::ParseEvent(current_packet.timestamp, |
| 679 current_packet->payload.data(), | 673 current_packet.payload.data(), |
| 680 current_packet->payload.size(), &event); | 674 current_packet.payload.size(), &event); |
| 681 if (ret != DtmfBuffer::kOK) { | 675 if (ret != DtmfBuffer::kOK) { |
| 682 PacketBuffer::DeleteAllPackets(&packet_list); | |
| 683 return kDtmfParsingError; | 676 return kDtmfParsingError; |
| 684 } | 677 } |
| 685 if (dtmf_buffer_->InsertEvent(event) != DtmfBuffer::kOK) { | 678 if (dtmf_buffer_->InsertEvent(event) != DtmfBuffer::kOK) { |
| 686 PacketBuffer::DeleteAllPackets(&packet_list); | |
| 687 return kDtmfInsertError; | 679 return kDtmfInsertError; |
| 688 } | 680 } |
| 689 delete current_packet; | |
| 690 it = packet_list.erase(it); | 681 it = packet_list.erase(it); |
| 691 } else { | 682 } else { |
| 692 ++it; | 683 ++it; |
| 693 } | 684 } |
| 694 } | 685 } |
| 695 | 686 |
| 696 // Update bandwidth estimate, if the packet is not comfort noise. | 687 // Update bandwidth estimate, if the packet is not comfort noise. |
| 697 if (!packet_list.empty() && | 688 if (!packet_list.empty() && |
| 698 !decoder_database_->IsComfortNoise(main_payload_type)) { | 689 !decoder_database_->IsComfortNoise(main_payload_type)) { |
| 699 // The list can be empty here if we got nothing but DTMF payloads. | 690 // The list can be empty here if we got nothing but DTMF payloads. |
| 700 AudioDecoder* decoder = decoder_database_->GetDecoder(main_payload_type); | 691 AudioDecoder* decoder = decoder_database_->GetDecoder(main_payload_type); |
| 701 RTC_DCHECK(decoder); // Should always get a valid object, since we have | 692 RTC_DCHECK(decoder); // Should always get a valid object, since we have |
| 702 // already checked that the payload types are known. | 693 // already checked that the payload types are known. |
| 703 decoder->IncomingPacket(packet_list.front()->payload.data(), | 694 decoder->IncomingPacket(packet_list.front().payload.data(), |
| 704 packet_list.front()->payload.size(), | 695 packet_list.front().payload.size(), |
| 705 packet_list.front()->sequence_number, | 696 packet_list.front().sequence_number, |
| 706 packet_list.front()->timestamp, | 697 packet_list.front().timestamp, |
| 707 receive_timestamp); | 698 receive_timestamp); |
| 708 } | 699 } |
| 709 | 700 |
| 710 PacketList parsed_packet_list; | 701 PacketList parsed_packet_list; |
| 711 while (!packet_list.empty()) { | 702 while (!packet_list.empty()) { |
| 712 std::unique_ptr<Packet> packet(packet_list.front()); | 703 Packet& packet = packet_list.front(); |
| 713 packet_list.pop_front(); | |
| 714 const DecoderDatabase::DecoderInfo* info = | 704 const DecoderDatabase::DecoderInfo* info = |
| 715 decoder_database_->GetDecoderInfo(packet->payload_type); | 705 decoder_database_->GetDecoderInfo(packet.payload_type); |
| 716 if (!info) { | 706 if (!info) { |
| 717 LOG(LS_WARNING) << "SplitAudio unknown payload type"; | 707 LOG(LS_WARNING) << "SplitAudio unknown payload type"; |
| 718 return kUnknownRtpPayloadType; | 708 return kUnknownRtpPayloadType; |
| 719 } | 709 } |
| 720 | 710 |
| 721 if (info->IsComfortNoise()) { | 711 if (info->IsComfortNoise()) { |
| 722 // Carry comfort noise packets along. | 712 // Carry comfort noise packets along. |
| 723 parsed_packet_list.push_back(packet.release()); | 713 parsed_packet_list.splice(parsed_packet_list.end(), packet_list, |
| 714 packet_list.begin()); | |
| 724 } else { | 715 } else { |
| 716 const auto sequence_number = packet.sequence_number; | |
| 717 const auto payload_type = packet.payload_type; | |
| 718 const Packet::Priority original_priority = packet.priority; | |
| 719 auto packet_from_result = [&] (AudioDecoder::ParseResult& result) { | |
| 720 Packet new_packet; | |
| 721 new_packet.sequence_number = sequence_number; | |
| 722 new_packet.payload_type = payload_type; | |
| 723 new_packet.timestamp = result.timestamp; | |
| 724 new_packet.priority.codec_level = result.priority; | |
| 725 new_packet.priority.red_level = original_priority.red_level; | |
| 726 new_packet.frame = std::move(result.frame); | |
| 727 return new_packet; | |
| 728 }; | |
| 729 | |
| 725 std::vector<AudioDecoder::ParseResult> results = | 730 std::vector<AudioDecoder::ParseResult> results = |
| 726 info->GetDecoder()->ParsePayload(std::move(packet->payload), | 731 info->GetDecoder()->ParsePayload(std::move(packet.payload), |
| 727 packet->timestamp); | 732 packet.timestamp); |
| 728 const auto sequence_number = packet->sequence_number; | 733 if (results.empty()) { |
| 729 const auto payload_type = packet->payload_type; | 734 packet_list.pop_front(); |
| 730 const Packet::Priority original_priority = packet->priority; | 735 } else { |
| 731 for (auto& result : results) { | 736 bool first = true; |
| 732 RTC_DCHECK(result.frame); | 737 for (auto& result : results) { |
| 733 // Reuse the packet if possible. | 738 RTC_DCHECK(result.frame); |
| 734 if (!packet) { | 739 RTC_DCHECK_GE(result.priority, 0); |
| 735 packet.reset(new Packet); | 740 if (first) { |
| 736 packet->sequence_number = sequence_number; | 741 // Re-use the node and move it to parsed_packet_list. |
| 737 packet->payload_type = payload_type; | 742 packet_list.front() = packet_from_result(result); |
| 743 parsed_packet_list.splice(parsed_packet_list.end(), packet_list, | |
| 744 packet_list.begin()); | |
| 745 first = false; | |
| 746 } else { | |
| 747 parsed_packet_list.push_back(packet_from_result(result)); | |
| 748 } | |
| 738 } | 749 } |
| 739 packet->timestamp = result.timestamp; | |
| 740 RTC_DCHECK_GE(result.priority, 0); | |
| 741 packet->priority.codec_level = result.priority; | |
| 742 packet->priority.red_level = original_priority.red_level; | |
| 743 packet->frame = std::move(result.frame); | |
| 744 parsed_packet_list.push_back(packet.release()); | |
| 745 } | 750 } |
| 746 } | 751 } |
| 747 } | 752 } |
| 748 | 753 |
| 749 // Insert packets in buffer. | 754 // Insert packets in buffer. |
| 750 const size_t buffer_length_before_insert = | 755 const size_t buffer_length_before_insert = |
| 751 packet_buffer_->NumPacketsInBuffer(); | 756 packet_buffer_->NumPacketsInBuffer(); |
| 752 const int ret = packet_buffer_->InsertPacketList( | 757 const int ret = packet_buffer_->InsertPacketList( |
| 753 &parsed_packet_list, *decoder_database_, ¤t_rtp_payload_type_, | 758 &parsed_packet_list, *decoder_database_, ¤t_rtp_payload_type_, |
| 754 ¤t_cng_rtp_payload_type_); | 759 ¤t_cng_rtp_payload_type_); |
| 755 if (ret == PacketBuffer::kFlushed) { | 760 if (ret == PacketBuffer::kFlushed) { |
| 756 // Reset DSP timestamp etc. if packet buffer flushed. | 761 // Reset DSP timestamp etc. if packet buffer flushed. |
| 757 new_codec_ = true; | 762 new_codec_ = true; |
| 758 update_sample_rate_and_channels = true; | 763 update_sample_rate_and_channels = true; |
| 759 } else if (ret != PacketBuffer::kOK) { | 764 } else if (ret != PacketBuffer::kOK) { |
| 760 PacketBuffer::DeleteAllPackets(&parsed_packet_list); | |
| 761 return kOtherError; | 765 return kOtherError; |
| 762 } | 766 } |
| 763 | 767 |
| 764 if (first_packet_) { | 768 if (first_packet_) { |
| 765 first_packet_ = false; | 769 first_packet_ = false; |
| 766 // Update the codec on the next GetAudio call. | 770 // Update the codec on the next GetAudio call. |
| 767 new_codec_ = true; | 771 new_codec_ = true; |
| 768 } | 772 } |
| 769 | 773 |
| 770 if (current_rtp_payload_type_) { | 774 if (current_rtp_payload_type_) { |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1337 int NetEqImpl::Decode(PacketList* packet_list, Operations* operation, | 1341 int NetEqImpl::Decode(PacketList* packet_list, Operations* operation, |
| 1338 int* decoded_length, | 1342 int* decoded_length, |
| 1339 AudioDecoder::SpeechType* speech_type) { | 1343 AudioDecoder::SpeechType* speech_type) { |
| 1340 *speech_type = AudioDecoder::kSpeech; | 1344 *speech_type = AudioDecoder::kSpeech; |
| 1341 | 1345 |
| 1342 // When packet_list is empty, we may be in kCodecInternalCng mode, and for | 1346 // When packet_list is empty, we may be in kCodecInternalCng mode, and for |
| 1343 // that we use current active decoder. | 1347 // that we use current active decoder. |
| 1344 AudioDecoder* decoder = decoder_database_->GetActiveDecoder(); | 1348 AudioDecoder* decoder = decoder_database_->GetActiveDecoder(); |
| 1345 | 1349 |
| 1346 if (!packet_list->empty()) { | 1350 if (!packet_list->empty()) { |
| 1347 const Packet* packet = packet_list->front(); | 1351 const Packet& packet = packet_list->front(); |
| 1348 uint8_t payload_type = packet->payload_type; | 1352 uint8_t payload_type = packet.payload_type; |
| 1349 if (!decoder_database_->IsComfortNoise(payload_type)) { | 1353 if (!decoder_database_->IsComfortNoise(payload_type)) { |
| 1350 decoder = decoder_database_->GetDecoder(payload_type); | 1354 decoder = decoder_database_->GetDecoder(payload_type); |
| 1351 assert(decoder); | 1355 assert(decoder); |
| 1352 if (!decoder) { | 1356 if (!decoder) { |
| 1353 LOG(LS_WARNING) << "Unknown payload type " | 1357 LOG(LS_WARNING) << "Unknown payload type " |
| 1354 << static_cast<int>(payload_type); | 1358 << static_cast<int>(payload_type); |
| 1355 PacketBuffer::DeleteAllPackets(packet_list); | 1359 packet_list->clear(); |
| 1356 return kDecoderNotFound; | 1360 return kDecoderNotFound; |
| 1357 } | 1361 } |
| 1358 bool decoder_changed; | 1362 bool decoder_changed; |
| 1359 decoder_database_->SetActiveDecoder(payload_type, &decoder_changed); | 1363 decoder_database_->SetActiveDecoder(payload_type, &decoder_changed); |
| 1360 if (decoder_changed) { | 1364 if (decoder_changed) { |
| 1361 // We have a new decoder. Re-init some values. | 1365 // We have a new decoder. Re-init some values. |
| 1362 const DecoderDatabase::DecoderInfo* decoder_info = decoder_database_ | 1366 const DecoderDatabase::DecoderInfo* decoder_info = decoder_database_ |
| 1363 ->GetDecoderInfo(payload_type); | 1367 ->GetDecoderInfo(payload_type); |
| 1364 assert(decoder_info); | 1368 assert(decoder_info); |
| 1365 if (!decoder_info) { | 1369 if (!decoder_info) { |
| 1366 LOG(LS_WARNING) << "Unknown payload type " | 1370 LOG(LS_WARNING) << "Unknown payload type " |
| 1367 << static_cast<int>(payload_type); | 1371 << static_cast<int>(payload_type); |
| 1368 PacketBuffer::DeleteAllPackets(packet_list); | 1372 packet_list->clear(); |
| 1369 return kDecoderNotFound; | 1373 return kDecoderNotFound; |
| 1370 } | 1374 } |
| 1371 // If sampling rate or number of channels has changed, we need to make | 1375 // If sampling rate or number of channels has changed, we need to make |
| 1372 // a reset. | 1376 // a reset. |
| 1373 if (decoder_info->SampleRateHz() != fs_hz_ || | 1377 if (decoder_info->SampleRateHz() != fs_hz_ || |
| 1374 decoder->Channels() != algorithm_buffer_->Channels()) { | 1378 decoder->Channels() != algorithm_buffer_->Channels()) { |
| 1375 // TODO(tlegrand): Add unittest to cover this event. | 1379 // TODO(tlegrand): Add unittest to cover this event. |
| 1376 SetSampleRateAndChannels(decoder_info->SampleRateHz(), | 1380 SetSampleRateAndChannels(decoder_info->SampleRateHz(), |
| 1377 decoder->Channels()); | 1381 decoder->Channels()); |
| 1378 } | 1382 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1468 LOG(LS_WARNING) << "Decoded too much CNG."; | 1472 LOG(LS_WARNING) << "Decoded too much CNG."; |
| 1469 return kDecodedTooMuch; | 1473 return kDecodedTooMuch; |
| 1470 } | 1474 } |
| 1471 } | 1475 } |
| 1472 return 0; | 1476 return 0; |
| 1473 } | 1477 } |
| 1474 | 1478 |
| 1475 int NetEqImpl::DecodeLoop(PacketList* packet_list, const Operations& operation, | 1479 int NetEqImpl::DecodeLoop(PacketList* packet_list, const Operations& operation, |
| 1476 AudioDecoder* decoder, int* decoded_length, | 1480 AudioDecoder* decoder, int* decoded_length, |
| 1477 AudioDecoder::SpeechType* speech_type) { | 1481 AudioDecoder::SpeechType* speech_type) { |
| 1478 Packet* packet = NULL; | |
| 1479 if (!packet_list->empty()) { | |
| 1480 packet = packet_list->front(); | |
| 1481 } | |
| 1482 | |
| 1483 // Do decoding. | 1482 // Do decoding. |
| 1484 while (packet && !decoder_database_->IsComfortNoise(packet->payload_type)) { | 1483 while ( |
| 1484 !packet_list->empty() && | |
| 1485 !decoder_database_->IsComfortNoise(packet_list->front().payload_type)) { | |
| 1485 assert(decoder); // At this point, we must have a decoder object. | 1486 assert(decoder); // At this point, we must have a decoder object. |
| 1486 // The number of channels in the |sync_buffer_| should be the same as the | 1487 // The number of channels in the |sync_buffer_| should be the same as the |
| 1487 // number decoder channels. | 1488 // number decoder channels. |
| 1488 assert(sync_buffer_->Channels() == decoder->Channels()); | 1489 assert(sync_buffer_->Channels() == decoder->Channels()); |
| 1489 assert(decoded_buffer_length_ >= kMaxFrameSize * decoder->Channels()); | 1490 assert(decoded_buffer_length_ >= kMaxFrameSize * decoder->Channels()); |
| 1490 assert(operation == kNormal || operation == kAccelerate || | 1491 assert(operation == kNormal || operation == kAccelerate || |
| 1491 operation == kFastAccelerate || operation == kMerge || | 1492 operation == kFastAccelerate || operation == kMerge || |
| 1492 operation == kPreemptiveExpand); | 1493 operation == kPreemptiveExpand); |
| 1493 packet_list->pop_front(); | 1494 |
| 1494 auto opt_result = packet->frame->Decode( | 1495 auto opt_result = packet_list->front().frame->Decode( |
| 1495 rtc::ArrayView<int16_t>(&decoded_buffer_[*decoded_length], | 1496 rtc::ArrayView<int16_t>(&decoded_buffer_[*decoded_length], |
| 1496 decoded_buffer_length_ - *decoded_length)); | 1497 decoded_buffer_length_ - *decoded_length)); |
| 1497 delete packet; | 1498 packet_list->pop_front(); |
| 1498 packet = NULL; | |
| 1499 if (opt_result) { | 1499 if (opt_result) { |
| 1500 const auto& result = *opt_result; | 1500 const auto& result = *opt_result; |
| 1501 *speech_type = result.speech_type; | 1501 *speech_type = result.speech_type; |
| 1502 if (result.num_decoded_samples > 0) { | 1502 if (result.num_decoded_samples > 0) { |
| 1503 *decoded_length += rtc::checked_cast<int>(result.num_decoded_samples); | 1503 *decoded_length += rtc::checked_cast<int>(result.num_decoded_samples); |
| 1504 // Update |decoder_frame_length_| with number of samples per channel. | 1504 // Update |decoder_frame_length_| with number of samples per channel. |
| 1505 decoder_frame_length_ = | 1505 decoder_frame_length_ = |
| 1506 result.num_decoded_samples / decoder->Channels(); | 1506 result.num_decoded_samples / decoder->Channels(); |
| 1507 } | 1507 } |
| 1508 } else { | 1508 } else { |
| 1509 // Error. | 1509 // Error. |
| 1510 // TODO(ossu): What to put here? | 1510 // TODO(ossu): What to put here? |
| 1511 LOG(LS_WARNING) << "Decode error"; | 1511 LOG(LS_WARNING) << "Decode error"; |
| 1512 *decoded_length = -1; | 1512 *decoded_length = -1; |
| 1513 PacketBuffer::DeleteAllPackets(packet_list); | 1513 packet_list->clear(); |
| 1514 break; | 1514 break; |
| 1515 } | 1515 } |
| 1516 if (*decoded_length > rtc::checked_cast<int>(decoded_buffer_length_)) { | 1516 if (*decoded_length > rtc::checked_cast<int>(decoded_buffer_length_)) { |
| 1517 // Guard against overflow. | 1517 // Guard against overflow. |
| 1518 LOG(LS_WARNING) << "Decoded too much."; | 1518 LOG(LS_WARNING) << "Decoded too much."; |
| 1519 PacketBuffer::DeleteAllPackets(packet_list); | 1519 packet_list->clear(); |
| 1520 return kDecodedTooMuch; | 1520 return kDecodedTooMuch; |
| 1521 } | 1521 } |
| 1522 if (!packet_list->empty()) { | |
| 1523 packet = packet_list->front(); | |
| 1524 } else { | |
| 1525 packet = NULL; | |
| 1526 } | |
| 1527 } // End of decode loop. | 1522 } // End of decode loop. |
| 1528 | 1523 |
| 1529 // If the list is not empty at this point, either a decoding error terminated | 1524 // If the list is not empty at this point, either a decoding error terminated |
| 1530 // the while-loop, or list must hold exactly one CNG packet. | 1525 // the while-loop, or list must hold exactly one CNG packet. |
| 1531 assert(packet_list->empty() || *decoded_length < 0 || | 1526 assert( |
| 1532 (packet_list->size() == 1 && packet && | 1527 packet_list->empty() || *decoded_length < 0 || |
| 1533 decoder_database_->IsComfortNoise(packet->payload_type))); | 1528 (packet_list->size() == 1 && |
| 1529 decoder_database_->IsComfortNoise(packet_list->front().payload_type))); | |
| 1534 return 0; | 1530 return 0; |
| 1535 } | 1531 } |
| 1536 | 1532 |
| 1537 void NetEqImpl::DoNormal(const int16_t* decoded_buffer, size_t decoded_length, | 1533 void NetEqImpl::DoNormal(const int16_t* decoded_buffer, size_t decoded_length, |
| 1538 AudioDecoder::SpeechType speech_type, bool play_dtmf) { | 1534 AudioDecoder::SpeechType speech_type, bool play_dtmf) { |
| 1539 assert(normal_.get()); | 1535 assert(normal_.get()); |
| 1540 assert(mute_factor_array_.get()); | 1536 assert(mute_factor_array_.get()); |
| 1541 normal_->Process(decoded_buffer, decoded_length, last_mode_, | 1537 normal_->Process(decoded_buffer, decoded_length, last_mode_, |
| 1542 mute_factor_array_.get(), algorithm_buffer_.get()); | 1538 mute_factor_array_.get(), algorithm_buffer_.get()); |
| 1543 if (decoded_length != 0) { | 1539 if (decoded_length != 0) { |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1763 dtmf_tone_generator_->Reset(); | 1759 dtmf_tone_generator_->Reset(); |
| 1764 } | 1760 } |
| 1765 expand_->Reset(); | 1761 expand_->Reset(); |
| 1766 return 0; | 1762 return 0; |
| 1767 } | 1763 } |
| 1768 | 1764 |
| 1769 int NetEqImpl::DoRfc3389Cng(PacketList* packet_list, bool play_dtmf) { | 1765 int NetEqImpl::DoRfc3389Cng(PacketList* packet_list, bool play_dtmf) { |
| 1770 if (!packet_list->empty()) { | 1766 if (!packet_list->empty()) { |
| 1771 // Must have exactly one SID frame at this point. | 1767 // Must have exactly one SID frame at this point. |
| 1772 assert(packet_list->size() == 1); | 1768 assert(packet_list->size() == 1); |
| 1773 Packet* packet = packet_list->front(); | 1769 const Packet& packet = packet_list->front(); |
| 1774 packet_list->pop_front(); | 1770 if (!decoder_database_->IsComfortNoise(packet.payload_type)) { |
| 1775 if (!decoder_database_->IsComfortNoise(packet->payload_type)) { | |
| 1776 LOG(LS_ERROR) << "Trying to decode non-CNG payload as CNG."; | 1771 LOG(LS_ERROR) << "Trying to decode non-CNG payload as CNG."; |
| 1777 return kOtherError; | 1772 return kOtherError; |
| 1778 } | 1773 } |
| 1779 // UpdateParameters() deletes |packet|. | |
| 1780 if (comfort_noise_->UpdateParameters(packet) == | 1774 if (comfort_noise_->UpdateParameters(packet) == |
| 1781 ComfortNoise::kInternalError) { | 1775 ComfortNoise::kInternalError) { |
| 1782 algorithm_buffer_->Zeros(output_size_samples_); | 1776 algorithm_buffer_->Zeros(output_size_samples_); |
| 1783 return -comfort_noise_->internal_error_code(); | 1777 return -comfort_noise_->internal_error_code(); |
| 1784 } | 1778 } |
| 1785 } | 1779 } |
| 1786 int cn_return = comfort_noise_->Generate(output_size_samples_, | 1780 int cn_return = comfort_noise_->Generate(output_size_samples_, |
| 1787 algorithm_buffer_.get()); | 1781 algorithm_buffer_.get()); |
| 1788 expand_->Reset(); | 1782 expand_->Reset(); |
| 1789 last_mode_ = kModeRfc3389Cng; | 1783 last_mode_ = kModeRfc3389Cng; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1953 if (!next_packet) { | 1947 if (!next_packet) { |
| 1954 LOG(LS_ERROR) << "Packet buffer unexpectedly empty."; | 1948 LOG(LS_ERROR) << "Packet buffer unexpectedly empty."; |
| 1955 return -1; | 1949 return -1; |
| 1956 } | 1950 } |
| 1957 uint32_t first_timestamp = next_packet->timestamp; | 1951 uint32_t first_timestamp = next_packet->timestamp; |
| 1958 size_t extracted_samples = 0; | 1952 size_t extracted_samples = 0; |
| 1959 | 1953 |
| 1960 // Packet extraction loop. | 1954 // Packet extraction loop. |
| 1961 do { | 1955 do { |
| 1962 timestamp_ = next_packet->timestamp; | 1956 timestamp_ = next_packet->timestamp; |
| 1963 size_t discard_count = 0; | 1957 rtc::Optional<Packet> packet = packet_buffer_->GetNextPacket(); |
| 1964 Packet* packet = packet_buffer_->GetNextPacket(&discard_count); | |
| 1965 // |next_packet| may be invalid after the |packet_buffer_| operation. | 1958 // |next_packet| may be invalid after the |packet_buffer_| operation. |
| 1966 next_packet = NULL; | 1959 next_packet = nullptr; |
| 1967 if (!packet) { | 1960 if (!packet) { |
| 1968 LOG(LS_ERROR) << "Should always be able to extract a packet here"; | 1961 LOG(LS_ERROR) << "Should always be able to extract a packet here"; |
| 1969 assert(false); // Should always be able to extract a packet here. | 1962 assert(false); // Should always be able to extract a packet here. |
| 1970 return -1; | 1963 return -1; |
| 1971 } | 1964 } |
| 1972 stats_.PacketsDiscarded(discard_count); | |
| 1973 stats_.StoreWaitingTime(packet->waiting_time->ElapsedMs()); | 1965 stats_.StoreWaitingTime(packet->waiting_time->ElapsedMs()); |
| 1974 RTC_DCHECK(!packet->empty()); | 1966 RTC_DCHECK(!packet->empty()); |
| 1975 packet_list->push_back(packet); // Store packet in list. | |
| 1976 | 1967 |
| 1977 if (first_packet) { | 1968 if (first_packet) { |
| 1978 first_packet = false; | 1969 first_packet = false; |
| 1979 if (nack_enabled_) { | 1970 if (nack_enabled_) { |
| 1980 RTC_DCHECK(nack_); | 1971 RTC_DCHECK(nack_); |
| 1981 // TODO(henrik.lundin): Should we update this for all decoded packets? | 1972 // TODO(henrik.lundin): Should we update this for all decoded packets? |
| 1982 nack_->UpdateLastDecodedPacket(packet->sequence_number, | 1973 nack_->UpdateLastDecodedPacket(packet->sequence_number, |
| 1983 packet->timestamp); | 1974 packet->timestamp); |
| 1984 } | 1975 } |
| 1985 prev_sequence_number = packet->sequence_number; | 1976 prev_sequence_number = packet->sequence_number; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 2001 RTC_NOTREACHED(); | 1992 RTC_NOTREACHED(); |
| 2002 } | 1993 } |
| 2003 | 1994 |
| 2004 if (packet_duration == 0) { | 1995 if (packet_duration == 0) { |
| 2005 // Decoder did not return a packet duration. Assume that the packet | 1996 // Decoder did not return a packet duration. Assume that the packet |
| 2006 // contains the same number of samples as the previous one. | 1997 // contains the same number of samples as the previous one. |
| 2007 packet_duration = decoder_frame_length_; | 1998 packet_duration = decoder_frame_length_; |
| 2008 } | 1999 } |
| 2009 extracted_samples = packet->timestamp - first_timestamp + packet_duration; | 2000 extracted_samples = packet->timestamp - first_timestamp + packet_duration; |
| 2010 | 2001 |
| 2002 packet_list->push_back(std::move(*packet)); // Store packet in list. | |
| 2003 packet = rtc::Optional<Packet>(); // Ensure it's never used after the move. | |
| 2004 | |
| 2011 // Check what packet is available next. | 2005 // Check what packet is available next. |
| 2012 next_packet = packet_buffer_->PeekNextPacket(); | 2006 next_packet = packet_buffer_->PeekNextPacket(); |
| 2013 next_packet_available = false; | 2007 next_packet_available = false; |
| 2014 if (next_packet && prev_payload_type == next_packet->payload_type) { | 2008 if (next_packet && prev_payload_type == next_packet->payload_type) { |
| 2015 int16_t seq_no_diff = next_packet->sequence_number - prev_sequence_number; | 2009 int16_t seq_no_diff = next_packet->sequence_number - prev_sequence_number; |
| 2016 size_t ts_diff = next_packet->timestamp - prev_timestamp; | 2010 size_t ts_diff = next_packet->timestamp - prev_timestamp; |
| 2017 if (seq_no_diff == 1 || | 2011 if (seq_no_diff == 1 || |
| 2018 (seq_no_diff == 0 && ts_diff == decoder_frame_length_)) { | 2012 (seq_no_diff == 0 && ts_diff == decoder_frame_length_)) { |
| 2019 // The next sequence number is available, or the next part of a packet | 2013 // The next sequence number is available, or the next part of a packet |
| 2020 // that was split into pieces upon insertion. | 2014 // that was split into pieces upon insertion. |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2132 } | 2126 } |
| 2133 } | 2127 } |
| 2134 | 2128 |
| 2135 void NetEqImpl::CreateDecisionLogic() { | 2129 void NetEqImpl::CreateDecisionLogic() { |
| 2136 decision_logic_.reset(DecisionLogic::Create( | 2130 decision_logic_.reset(DecisionLogic::Create( |
| 2137 fs_hz_, output_size_samples_, playout_mode_, decoder_database_.get(), | 2131 fs_hz_, output_size_samples_, playout_mode_, decoder_database_.get(), |
| 2138 *packet_buffer_.get(), delay_manager_.get(), buffer_level_filter_.get(), | 2132 *packet_buffer_.get(), delay_manager_.get(), buffer_level_filter_.get(), |
| 2139 tick_timer_.get())); | 2133 tick_timer_.get())); |
| 2140 } | 2134 } |
| 2141 } // namespace webrtc | 2135 } // namespace webrtc |
| OLD | NEW |