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

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

Issue 2342443005: Moved Opus-specific payload splitting into AudioDecoderOpus. (Closed)
Patch Set: Priority levels are ints, kHighestPriority is gone. Also small cleanups. Created 4 years, 3 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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 } 276 }
277 return kFail; 277 return kFail;
278 } 278 }
279 return kOK; 279 return kOK;
280 } 280 }
281 281
282 int NetEqImpl::RemovePayloadType(uint8_t rtp_payload_type) { 282 int NetEqImpl::RemovePayloadType(uint8_t rtp_payload_type) {
283 rtc::CritScope lock(&crit_sect_); 283 rtc::CritScope lock(&crit_sect_);
284 int ret = decoder_database_->Remove(rtp_payload_type); 284 int ret = decoder_database_->Remove(rtp_payload_type);
285 if (ret == DecoderDatabase::kOK) { 285 if (ret == DecoderDatabase::kOK) {
286 packet_buffer_->DiscardPacketsWithPayloadType(rtp_payload_type); 286 packet_buffer_->DiscardPacketsWithPayloadType(rtp_payload_type);
hlundin-webrtc 2016/09/20 07:02:24 This is very courteous...
ossu 2016/09/20 13:51:56 Thanks?
287 return kOK; 287 return kOK;
288 } else if (ret == DecoderDatabase::kDecoderNotFound) { 288 } else if (ret == DecoderDatabase::kDecoderNotFound) {
289 error_code_ = kDecoderNotFound; 289 error_code_ = kDecoderNotFound;
290 } else { 290 } else {
291 error_code_ = kOtherError; 291 error_code_ = kOtherError;
292 } 292 }
293 return kFail; 293 return kFail;
294 } 294 }
295 295
296 bool NetEqImpl::SetMinimumDelay(int delay_ms) { 296 bool NetEqImpl::SetMinimumDelay(int delay_ms) {
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 // directly once it's been inserted in the packet list. This way, |packet| 522 // directly once it's been inserted in the packet list. This way, |packet|
523 // is not defined outside of this block. 523 // is not defined outside of this block.
524 Packet* packet = new Packet; 524 Packet* packet = new Packet;
525 packet->header.markerBit = false; 525 packet->header.markerBit = false;
526 packet->header.payloadType = rtp_header.header.payloadType; 526 packet->header.payloadType = rtp_header.header.payloadType;
527 packet->header.sequenceNumber = rtp_header.header.sequenceNumber; 527 packet->header.sequenceNumber = rtp_header.header.sequenceNumber;
528 packet->header.timestamp = rtp_header.header.timestamp; 528 packet->header.timestamp = rtp_header.header.timestamp;
529 packet->header.ssrc = rtp_header.header.ssrc; 529 packet->header.ssrc = rtp_header.header.ssrc;
530 packet->header.numCSRCs = 0; 530 packet->header.numCSRCs = 0;
531 packet->payload.SetData(payload.data(), payload.size()); 531 packet->payload.SetData(payload.data(), payload.size());
532 packet->primary = true;
533 // Waiting time will be set upon inserting the packet in the buffer. 532 // Waiting time will be set upon inserting the packet in the buffer.
534 RTC_DCHECK(!packet->waiting_time); 533 RTC_DCHECK(!packet->waiting_time);
535 // Insert packet in a packet list. 534 // Insert packet in a packet list.
536 packet_list.push_back(packet); 535 packet_list.push_back(packet);
537 // Save main payloads header for later. 536 // Save main payloads header for later.
538 memcpy(&main_header, &packet->header, sizeof(main_header)); 537 memcpy(&main_header, &packet->header, sizeof(main_header));
539 } 538 }
540 539
541 bool update_sample_rate_and_channels = false; 540 bool update_sample_rate_and_channels = false;
542 // Reinitialize NetEq if it's needed (changed SSRC or first call). 541 // Reinitialize NetEq if it's needed (changed SSRC or first call).
(...skipping 21 matching lines...) Expand all
564 563
565 // Trigger an update of sampling rate and the number of channels. 564 // Trigger an update of sampling rate and the number of channels.
566 update_sample_rate_and_channels = true; 565 update_sample_rate_and_channels = true;
567 } 566 }
568 567
569 // Update RTCP statistics, only for regular packets. 568 // Update RTCP statistics, only for regular packets.
570 rtcp_.Update(main_header, receive_timestamp); 569 rtcp_.Update(main_header, receive_timestamp);
571 570
572 // Check for RED payload type, and separate payloads into several packets. 571 // Check for RED payload type, and separate payloads into several packets.
573 if (decoder_database_->IsRed(main_header.payloadType)) { 572 if (decoder_database_->IsRed(main_header.payloadType)) {
574 if (payload_splitter_->SplitRed(&packet_list) != PayloadSplitter::kOK) { 573 if (!payload_splitter_->SplitRed(&packet_list)) {
575 PacketBuffer::DeleteAllPackets(&packet_list); 574 PacketBuffer::DeleteAllPackets(&packet_list);
576 return kRedundancySplitError; 575 return kRedundancySplitError;
577 } 576 }
578 // Only accept a few RED payloads of the same type as the main data, 577 // Only accept a few RED payloads of the same type as the main data,
579 // DTMF events and CNG. 578 // DTMF events and CNG.
580 payload_splitter_->CheckRedPayloads(&packet_list, *decoder_database_); 579 payload_splitter_->CheckRedPayloads(&packet_list, *decoder_database_);
581 // Update the stored main payload header since the main payload has now 580 // Update the stored main payload header since the main payload has now
582 // changed. 581 // changed.
583 memcpy(&main_header, &packet_list.front()->header, sizeof(main_header)); 582 memcpy(&main_header, &packet_list.front()->header, sizeof(main_header));
584 } 583 }
(...skipping 28 matching lines...) Expand all
613 PacketBuffer::DeleteAllPackets(&packet_list); 612 PacketBuffer::DeleteAllPackets(&packet_list);
614 return kDtmfInsertError; 613 return kDtmfInsertError;
615 } 614 }
616 delete current_packet; 615 delete current_packet;
617 it = packet_list.erase(it); 616 it = packet_list.erase(it);
618 } else { 617 } else {
619 ++it; 618 ++it;
620 } 619 }
621 } 620 }
622 621
623 // Check for FEC in packets, and separate payloads into several packets.
624 int ret = payload_splitter_->SplitFec(&packet_list, decoder_database_.get());
625 if (ret != PayloadSplitter::kOK) {
626 PacketBuffer::DeleteAllPackets(&packet_list);
627 switch (ret) {
628 case PayloadSplitter::kUnknownPayloadType:
629 return kUnknownRtpPayloadType;
630 default:
631 return kOtherError;
632 }
633 }
634
635 // Update bandwidth estimate, if the packet is not comfort noise. 622 // Update bandwidth estimate, if the packet is not comfort noise.
636 if (!packet_list.empty() && 623 if (!packet_list.empty() &&
637 !decoder_database_->IsComfortNoise(main_header.payloadType)) { 624 !decoder_database_->IsComfortNoise(main_header.payloadType)) {
638 // The list can be empty here if we got nothing but DTMF payloads. 625 // The list can be empty here if we got nothing but DTMF payloads.
639 AudioDecoder* decoder = 626 AudioDecoder* decoder =
640 decoder_database_->GetDecoder(main_header.payloadType); 627 decoder_database_->GetDecoder(main_header.payloadType);
641 assert(decoder); // Should always get a valid object, since we have 628 assert(decoder); // Should always get a valid object, since we have
642 // already checked that the payload types are known. 629 // already checked that the payload types are known.
643 decoder->IncomingPacket(packet_list.front()->payload.data(), 630 decoder->IncomingPacket(packet_list.front()->payload.data(),
644 packet_list.front()->payload.size(), 631 packet_list.front()->payload.size(),
(...skipping 12 matching lines...) Expand all
657 LOG(LS_WARNING) << "SplitAudio unknown payload type"; 644 LOG(LS_WARNING) << "SplitAudio unknown payload type";
658 return kUnknownRtpPayloadType; 645 return kUnknownRtpPayloadType;
659 } 646 }
660 647
661 if (info->IsComfortNoise()) { 648 if (info->IsComfortNoise()) {
662 // Carry comfort noise packets along. 649 // Carry comfort noise packets along.
663 parsed_packet_list.push_back(packet.release()); 650 parsed_packet_list.push_back(packet.release());
664 } else { 651 } else {
665 std::vector<AudioDecoder::ParseResult> results = 652 std::vector<AudioDecoder::ParseResult> results =
666 info->GetDecoder()->ParsePayload(std::move(packet->payload), 653 info->GetDecoder()->ParsePayload(std::move(packet->payload),
667 packet->header.timestamp, 654 packet->header.timestamp);
668 packet->primary);
669 const RTPHeader& original_header = packet->header; 655 const RTPHeader& original_header = packet->header;
656 const Packet::Priority original_priority = packet->priority;
670 for (auto& result : results) { 657 for (auto& result : results) {
671 RTC_DCHECK(result.frame); 658 RTC_DCHECK(result.frame);
672 // Reuse the packet if possible. 659 // Reuse the packet if possible.
673 if (!packet) { 660 if (!packet) {
674 packet.reset(new Packet); 661 packet.reset(new Packet);
675 packet->header = original_header; 662 packet->header = original_header;
676 } 663 }
677 packet->header.timestamp = result.timestamp; 664 packet->header.timestamp = result.timestamp;
678 // TODO(ossu): Move from primary to some sort of priority level. 665 packet->priority.codec_level = result.priority;
679 packet->primary = result.primary; 666 packet->priority.red_level = original_priority.red_level;
680 packet->frame = std::move(result.frame); 667 packet->frame = std::move(result.frame);
681 parsed_packet_list.push_back(packet.release()); 668 parsed_packet_list.push_back(packet.release());
682 } 669 }
683 } 670 }
684 } 671 }
685 672
686 if (nack_enabled_) { 673 if (nack_enabled_) {
687 RTC_DCHECK(nack_); 674 RTC_DCHECK(nack_);
688 if (update_sample_rate_and_channels) { 675 if (update_sample_rate_and_channels) {
689 nack_->Reset(); 676 nack_->Reset();
690 } 677 }
691 nack_->UpdateLastReceivedPacket( 678 nack_->UpdateLastReceivedPacket(
692 parsed_packet_list.front()->header.sequenceNumber, 679 parsed_packet_list.front()->header.sequenceNumber,
693 parsed_packet_list.front()->header.timestamp); 680 parsed_packet_list.front()->header.timestamp);
694 } 681 }
695 682
696 // Insert packets in buffer. 683 // Insert packets in buffer.
697 const size_t buffer_length_before_insert = 684 const size_t buffer_length_before_insert =
698 packet_buffer_->NumPacketsInBuffer(); 685 packet_buffer_->NumPacketsInBuffer();
699 ret = packet_buffer_->InsertPacketList( 686 const int ret = packet_buffer_->InsertPacketList(
700 &parsed_packet_list, *decoder_database_, &current_rtp_payload_type_, 687 &parsed_packet_list, *decoder_database_, &current_rtp_payload_type_,
701 &current_cng_rtp_payload_type_); 688 &current_cng_rtp_payload_type_);
702 if (ret == PacketBuffer::kFlushed) { 689 if (ret == PacketBuffer::kFlushed) {
703 // Reset DSP timestamp etc. if packet buffer flushed. 690 // Reset DSP timestamp etc. if packet buffer flushed.
704 new_codec_ = true; 691 new_codec_ = true;
705 update_sample_rate_and_channels = true; 692 update_sample_rate_and_channels = true;
706 } else if (ret != PacketBuffer::kOK) { 693 } else if (ret != PacketBuffer::kOK) {
707 PacketBuffer::DeleteAllPackets(&parsed_packet_list); 694 PacketBuffer::DeleteAllPackets(&parsed_packet_list);
708 return kOtherError; 695 return kOtherError;
709 } 696 }
(...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1934 } 1921 }
1935 prev_sequence_number = packet->header.sequenceNumber; 1922 prev_sequence_number = packet->header.sequenceNumber;
1936 prev_timestamp = packet->header.timestamp; 1923 prev_timestamp = packet->header.timestamp;
1937 prev_payload_type = packet->header.payloadType; 1924 prev_payload_type = packet->header.payloadType;
1938 } 1925 }
1939 1926
1940 // Store number of extracted samples. 1927 // Store number of extracted samples.
1941 size_t packet_duration = 0; 1928 size_t packet_duration = 0;
1942 if (packet->frame) { 1929 if (packet->frame) {
1943 packet_duration = packet->frame->Duration(); 1930 packet_duration = packet->frame->Duration();
1944 // TODO(ossu): Is this the correct way to track samples decoded from a 1931 // TODO(ossu): Is this the correct way to track Opus FEC packets?
1945 // redundant packet? 1932 if (packet->priority.codec_level > 0) {
1946 if (packet_duration > 0 && !packet->primary) {
1947 stats_.SecondaryDecodedSamples(rtc::checked_cast<int>(packet_duration)); 1933 stats_.SecondaryDecodedSamples(rtc::checked_cast<int>(packet_duration));
1948 } 1934 }
1949 } else if (!decoder_database_->IsComfortNoise(packet->header.payloadType)) { 1935 } else if (!decoder_database_->IsComfortNoise(packet->header.payloadType)) {
1950 LOG(LS_WARNING) << "Unknown payload type " 1936 LOG(LS_WARNING) << "Unknown payload type "
1951 << static_cast<int>(packet->header.payloadType); 1937 << static_cast<int>(packet->header.payloadType);
1952 RTC_NOTREACHED(); 1938 RTC_NOTREACHED();
1953 } 1939 }
1954 1940
1955 if (packet_duration == 0) { 1941 if (packet_duration == 0) {
1956 // Decoder did not return a packet duration. Assume that the packet 1942 // Decoder did not return a packet duration. Assume that the packet
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
2084 } 2070 }
2085 } 2071 }
2086 2072
2087 void NetEqImpl::CreateDecisionLogic() { 2073 void NetEqImpl::CreateDecisionLogic() {
2088 decision_logic_.reset(DecisionLogic::Create( 2074 decision_logic_.reset(DecisionLogic::Create(
2089 fs_hz_, output_size_samples_, playout_mode_, decoder_database_.get(), 2075 fs_hz_, output_size_samples_, playout_mode_, decoder_database_.get(),
2090 *packet_buffer_.get(), delay_manager_.get(), buffer_level_filter_.get(), 2076 *packet_buffer_.get(), delay_manager_.get(), buffer_level_filter_.get(),
2091 tick_timer_.get())); 2077 tick_timer_.get()));
2092 } 2078 }
2093 } // namespace webrtc 2079 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698