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 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
521 // directly once it's been inserted in the packet list. This way, |packet| | 521 // directly once it's been inserted in the packet list. This way, |packet| |
522 // is not defined outside of this block. | 522 // is not defined outside of this block. |
523 Packet* packet = new Packet; | 523 Packet* packet = new Packet; |
524 packet->header.markerBit = false; | 524 packet->header.markerBit = false; |
525 packet->header.payloadType = rtp_header.header.payloadType; | 525 packet->header.payloadType = rtp_header.header.payloadType; |
526 packet->header.sequenceNumber = rtp_header.header.sequenceNumber; | 526 packet->header.sequenceNumber = rtp_header.header.sequenceNumber; |
527 packet->header.timestamp = rtp_header.header.timestamp; | 527 packet->header.timestamp = rtp_header.header.timestamp; |
528 packet->header.ssrc = rtp_header.header.ssrc; | 528 packet->header.ssrc = rtp_header.header.ssrc; |
529 packet->header.numCSRCs = 0; | 529 packet->header.numCSRCs = 0; |
530 packet->payload.SetData(payload.data(), payload.size()); | 530 packet->payload.SetData(payload.data(), payload.size()); |
531 packet->primary = true; | |
532 // Waiting time will be set upon inserting the packet in the buffer. | 531 // Waiting time will be set upon inserting the packet in the buffer. |
533 RTC_DCHECK(!packet->waiting_time); | 532 RTC_DCHECK(!packet->waiting_time); |
534 // Insert packet in a packet list. | 533 // Insert packet in a packet list. |
535 packet_list.push_back(packet); | 534 packet_list.push_back(packet); |
536 // Save main payloads header for later. | 535 // Save main payloads header for later. |
537 memcpy(&main_header, &packet->header, sizeof(main_header)); | 536 memcpy(&main_header, &packet->header, sizeof(main_header)); |
538 } | 537 } |
539 | 538 |
540 bool update_sample_rate_and_channels = false; | 539 bool update_sample_rate_and_channels = false; |
541 // Reinitialize NetEq if it's needed (changed SSRC or first call). | 540 // Reinitialize NetEq if it's needed (changed SSRC or first call). |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
612 PacketBuffer::DeleteAllPackets(&packet_list); | 611 PacketBuffer::DeleteAllPackets(&packet_list); |
613 return kDtmfInsertError; | 612 return kDtmfInsertError; |
614 } | 613 } |
615 delete current_packet; | 614 delete current_packet; |
616 it = packet_list.erase(it); | 615 it = packet_list.erase(it); |
617 } else { | 616 } else { |
618 ++it; | 617 ++it; |
619 } | 618 } |
620 } | 619 } |
621 | 620 |
622 // Check for FEC in packets, and separate payloads into several packets. | |
623 int ret = payload_splitter_->SplitFec(&packet_list, decoder_database_.get()); | |
624 if (ret != PayloadSplitter::kOK) { | |
625 PacketBuffer::DeleteAllPackets(&packet_list); | |
626 switch (ret) { | |
627 case PayloadSplitter::kUnknownPayloadType: | |
628 return kUnknownRtpPayloadType; | |
629 default: | |
630 return kOtherError; | |
631 } | |
632 } | |
633 | |
634 // Update bandwidth estimate, if the packet is not comfort noise. | 621 // Update bandwidth estimate, if the packet is not comfort noise. |
635 if (!packet_list.empty() && | 622 if (!packet_list.empty() && |
636 !decoder_database_->IsComfortNoise(main_header.payloadType)) { | 623 !decoder_database_->IsComfortNoise(main_header.payloadType)) { |
637 // The list can be empty here if we got nothing but DTMF payloads. | 624 // The list can be empty here if we got nothing but DTMF payloads. |
638 AudioDecoder* decoder = | 625 AudioDecoder* decoder = |
639 decoder_database_->GetDecoder(main_header.payloadType); | 626 decoder_database_->GetDecoder(main_header.payloadType); |
640 assert(decoder); // Should always get a valid object, since we have | 627 assert(decoder); // Should always get a valid object, since we have |
641 // already checked that the payload types are known. | 628 // already checked that the payload types are known. |
642 decoder->IncomingPacket(packet_list.front()->payload.data(), | 629 decoder->IncomingPacket(packet_list.front()->payload.data(), |
643 packet_list.front()->payload.size(), | 630 packet_list.front()->payload.size(), |
(...skipping 11 matching lines...) Expand all Loading... | |
655 if (!info) { | 642 if (!info) { |
656 LOG(LS_WARNING) << "SplitAudio unknown payload type"; | 643 LOG(LS_WARNING) << "SplitAudio unknown payload type"; |
657 return kUnknownRtpPayloadType; | 644 return kUnknownRtpPayloadType; |
658 } | 645 } |
659 | 646 |
660 if (info->IsComfortNoise()) { | 647 if (info->IsComfortNoise()) { |
661 // Carry comfort noise packets along. | 648 // Carry comfort noise packets along. |
662 parsed_packet_list.push_back(packet.release()); | 649 parsed_packet_list.push_back(packet.release()); |
663 } else { | 650 } else { |
664 std::vector<AudioDecoder::ParseResult> results = | 651 std::vector<AudioDecoder::ParseResult> results = |
665 info->GetDecoder()->ParsePayload( | 652 info->GetDecoder()->ParsePayload(&packet->payload, |
666 &packet->payload, packet->header.timestamp, packet->primary); | 653 packet->header.timestamp); |
667 | 654 |
668 // Reuse the packet if possible | 655 // Reuse the packet if possible |
669 if (results.size() == 1) { | 656 if (results.size() == 1) { |
670 auto& result = results[0]; | 657 auto& result = results[0]; |
671 RTC_DCHECK(result.frame); | 658 RTC_DCHECK(result.frame); |
672 packet->header.timestamp = result.timestamp; | 659 packet->header.timestamp = result.timestamp; |
673 packet->primary = result.primary; | 660 packet->priority.codec_level = result.priority; |
674 packet->frame = std::move(result.frame); | 661 packet->frame = std::move(result.frame); |
675 parsed_packet_list.push_back(packet.release()); | 662 parsed_packet_list.push_back(packet.release()); |
676 } else { | 663 } else { |
677 for (auto& result : results) { | 664 for (auto& result : results) { |
678 // If you can't parse, return an empty list instead! | 665 // If you can't parse, return an empty list instead! |
679 RTC_DCHECK(result.frame); | 666 RTC_DCHECK(result.frame); |
680 std::unique_ptr<Packet> parsed_packet(new Packet); | 667 std::unique_ptr<Packet> parsed_packet(new Packet); |
681 parsed_packet->header = packet->header; | 668 parsed_packet->header = packet->header; |
682 parsed_packet->header.timestamp = result.timestamp; | 669 parsed_packet->header.timestamp = result.timestamp; |
683 // TODO(ossu): Move from primary to some sort of priority level. | 670 parsed_packet->priority.codec_level = result.priority; |
684 parsed_packet->primary = result.primary; | 671 parsed_packet->priority.red_level = packet->priority.red_level; |
685 parsed_packet->frame = std::move(result.frame); | 672 parsed_packet->frame = std::move(result.frame); |
686 parsed_packet_list.push_back(parsed_packet.release()); | 673 parsed_packet_list.push_back(parsed_packet.release()); |
687 } | 674 } |
688 } | 675 } |
689 } | 676 } |
690 } | 677 } |
691 | 678 |
692 if (nack_enabled_) { | 679 if (nack_enabled_) { |
693 RTC_DCHECK(nack_); | 680 RTC_DCHECK(nack_); |
694 if (update_sample_rate_and_channels) { | 681 if (update_sample_rate_and_channels) { |
695 nack_->Reset(); | 682 nack_->Reset(); |
696 } | 683 } |
697 nack_->UpdateLastReceivedPacket( | 684 nack_->UpdateLastReceivedPacket( |
698 parsed_packet_list.front()->header.sequenceNumber, | 685 parsed_packet_list.front()->header.sequenceNumber, |
699 parsed_packet_list.front()->header.timestamp); | 686 parsed_packet_list.front()->header.timestamp); |
700 } | 687 } |
701 | 688 |
702 // Insert packets in buffer. | 689 // Insert packets in buffer. |
703 const size_t buffer_length_before_insert = | 690 const size_t buffer_length_before_insert = |
704 packet_buffer_->NumPacketsInBuffer(); | 691 packet_buffer_->NumPacketsInBuffer(); |
705 ret = packet_buffer_->InsertPacketList( | 692 int ret = packet_buffer_->InsertPacketList( |
kwiberg-webrtc
2016/09/19 11:07:49
const?
ossu
2016/09/19 11:41:01
Acknowledged.
| |
706 &parsed_packet_list, *decoder_database_, ¤t_rtp_payload_type_, | 693 &parsed_packet_list, *decoder_database_, ¤t_rtp_payload_type_, |
707 ¤t_cng_rtp_payload_type_); | 694 ¤t_cng_rtp_payload_type_); |
708 if (ret == PacketBuffer::kFlushed) { | 695 if (ret == PacketBuffer::kFlushed) { |
709 // Reset DSP timestamp etc. if packet buffer flushed. | 696 // Reset DSP timestamp etc. if packet buffer flushed. |
710 new_codec_ = true; | 697 new_codec_ = true; |
711 update_sample_rate_and_channels = true; | 698 update_sample_rate_and_channels = true; |
712 } else if (ret != PacketBuffer::kOK) { | 699 } else if (ret != PacketBuffer::kOK) { |
713 PacketBuffer::DeleteAllPackets(&parsed_packet_list); | 700 PacketBuffer::DeleteAllPackets(&parsed_packet_list); |
714 return kOtherError; | 701 return kOtherError; |
715 } | 702 } |
(...skipping 1226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1942 prev_timestamp = packet->header.timestamp; | 1929 prev_timestamp = packet->header.timestamp; |
1943 prev_payload_type = packet->header.payloadType; | 1930 prev_payload_type = packet->header.payloadType; |
1944 } | 1931 } |
1945 | 1932 |
1946 // Store number of extracted samples. | 1933 // Store number of extracted samples. |
1947 size_t packet_duration = 0; | 1934 size_t packet_duration = 0; |
1948 if (packet->frame) { | 1935 if (packet->frame) { |
1949 packet_duration = packet->frame->Duration(); | 1936 packet_duration = packet->frame->Duration(); |
1950 // TODO(ossu): Is this the correct way to track samples decoded from a | 1937 // TODO(ossu): Is this the correct way to track samples decoded from a |
1951 // redundant packet? | 1938 // redundant packet? |
1952 if (packet_duration > 0 && !packet->primary) { | 1939 if (packet->priority != Packet::kHighestPriority) { |
1953 stats_.SecondaryDecodedSamples(packet_duration); | 1940 stats_.SecondaryDecodedSamples(packet_duration); |
1954 } | 1941 } |
1955 } else if (!decoder_database_->IsComfortNoise(packet->header.payloadType)) { | 1942 } else if (!decoder_database_->IsComfortNoise(packet->header.payloadType)) { |
1956 LOG(LS_WARNING) << "Unknown payload type " | 1943 LOG(LS_WARNING) << "Unknown payload type " |
1957 << static_cast<int>(packet->header.payloadType); | 1944 << static_cast<int>(packet->header.payloadType); |
1958 RTC_NOTREACHED(); | 1945 RTC_NOTREACHED(); |
1959 } | 1946 } |
1960 | 1947 |
1961 if (packet_duration == 0) { | 1948 if (packet_duration == 0) { |
1962 // Decoder did not return a packet duration. Assume that the packet | 1949 // Decoder did not return a packet duration. Assume that the packet |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2091 } | 2078 } |
2092 } | 2079 } |
2093 | 2080 |
2094 void NetEqImpl::CreateDecisionLogic() { | 2081 void NetEqImpl::CreateDecisionLogic() { |
2095 decision_logic_.reset(DecisionLogic::Create( | 2082 decision_logic_.reset(DecisionLogic::Create( |
2096 fs_hz_, output_size_samples_, playout_mode_, decoder_database_.get(), | 2083 fs_hz_, output_size_samples_, playout_mode_, decoder_database_.get(), |
2097 *packet_buffer_.get(), delay_manager_.get(), buffer_level_filter_.get(), | 2084 *packet_buffer_.get(), delay_manager_.get(), buffer_level_filter_.get(), |
2098 tick_timer_.get())); | 2085 tick_timer_.get())); |
2099 } | 2086 } |
2100 } // namespace webrtc | 2087 } // namespace webrtc |
OLD | NEW |