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 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 554 // Create |packet| within this separate scope, since it should not be used | 554 // Create |packet| within this separate scope, since it should not be used |
| 555 // directly once it's been inserted in the packet list. This way, |packet| | 555 // directly once it's been inserted in the packet list. This way, |packet| |
| 556 // is not defined outside of this block. | 556 // is not defined outside of this block. |
| 557 Packet* packet = new Packet; | 557 Packet* packet = new Packet; |
| 558 packet->header.markerBit = false; | 558 packet->header.markerBit = false; |
| 559 packet->header.payloadType = rtp_header.header.payloadType; | 559 packet->header.payloadType = rtp_header.header.payloadType; |
| 560 packet->header.sequenceNumber = rtp_header.header.sequenceNumber; | 560 packet->header.sequenceNumber = rtp_header.header.sequenceNumber; |
| 561 packet->header.timestamp = rtp_header.header.timestamp; | 561 packet->header.timestamp = rtp_header.header.timestamp; |
| 562 packet->header.ssrc = rtp_header.header.ssrc; | 562 packet->header.ssrc = rtp_header.header.ssrc; |
| 563 packet->header.numCSRCs = 0; | 563 packet->header.numCSRCs = 0; |
| 564 packet->payload_length = payload.size(); | 564 packet->payload = rtc::Buffer(payload.data(), payload.size()); |
|
kwiberg-webrtc
2016/08/30 16:04:36
You're copying data into an existing buffer, so
ossu
2016/08/30 16:27:13
Good point. Yeah, I was expecting the copy constru
kwiberg-webrtc
2016/08/30 16:37:05
Yes, we explicitly don't want a copy constructor.
| |
| 565 packet->primary = true; | 565 packet->primary = true; |
| 566 // Waiting time will be set upon inserting the packet in the buffer. | 566 // Waiting time will be set upon inserting the packet in the buffer. |
| 567 RTC_DCHECK(!packet->waiting_time); | 567 RTC_DCHECK(!packet->waiting_time); |
| 568 packet->payload = new uint8_t[packet->payload_length]; | |
| 569 packet->sync_packet = is_sync_packet; | 568 packet->sync_packet = is_sync_packet; |
| 570 if (!packet->payload) { | |
| 571 LOG_F(LS_ERROR) << "Payload pointer is NULL."; | |
| 572 } | |
| 573 assert(!payload.empty()); // Already checked above. | |
| 574 memcpy(packet->payload, payload.data(), packet->payload_length); | |
| 575 // Insert packet in a packet list. | 569 // Insert packet in a packet list. |
| 576 packet_list.push_back(packet); | 570 packet_list.push_back(packet); |
| 577 // Save main payloads header for later. | 571 // Save main payloads header for later. |
| 578 memcpy(&main_header, &packet->header, sizeof(main_header)); | 572 memcpy(&main_header, &packet->header, sizeof(main_header)); |
| 579 } | 573 } |
| 580 | 574 |
| 581 bool update_sample_rate_and_channels = false; | 575 bool update_sample_rate_and_channels = false; |
| 582 // Reinitialize NetEq if it's needed (changed SSRC or first call). | 576 // Reinitialize NetEq if it's needed (changed SSRC or first call). |
| 583 if ((main_header.ssrc != ssrc_) || first_packet_) { | 577 if ((main_header.ssrc != ssrc_) || first_packet_) { |
| 584 // Note: |first_packet_| will be cleared further down in this method, once | 578 // Note: |first_packet_| will be cleared further down in this method, once |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 634 | 628 |
| 635 // Scale timestamp to internal domain (only for some codecs). | 629 // Scale timestamp to internal domain (only for some codecs). |
| 636 timestamp_scaler_->ToInternal(&packet_list); | 630 timestamp_scaler_->ToInternal(&packet_list); |
| 637 | 631 |
| 638 // Process DTMF payloads. Cycle through the list of packets, and pick out any | 632 // Process DTMF payloads. Cycle through the list of packets, and pick out any |
| 639 // DTMF payloads found. | 633 // DTMF payloads found. |
| 640 PacketList::iterator it = packet_list.begin(); | 634 PacketList::iterator it = packet_list.begin(); |
| 641 while (it != packet_list.end()) { | 635 while (it != packet_list.end()) { |
| 642 Packet* current_packet = (*it); | 636 Packet* current_packet = (*it); |
| 643 assert(current_packet); | 637 assert(current_packet); |
| 644 assert(current_packet->payload); | 638 assert(!current_packet->payload.empty()); |
| 645 if (decoder_database_->IsDtmf(current_packet->header.payloadType)) { | 639 if (decoder_database_->IsDtmf(current_packet->header.payloadType)) { |
| 646 assert(!current_packet->sync_packet); // We had a sanity check for this. | 640 assert(!current_packet->sync_packet); // We had a sanity check for this. |
| 647 DtmfEvent event; | 641 DtmfEvent event; |
| 648 int ret = DtmfBuffer::ParseEvent( | 642 int ret = DtmfBuffer::ParseEvent(current_packet->header.timestamp, |
| 649 current_packet->header.timestamp, | 643 current_packet->payload.data(), |
| 650 current_packet->payload, | 644 current_packet->payload.size(), &event); |
| 651 current_packet->payload_length, | |
| 652 &event); | |
| 653 if (ret != DtmfBuffer::kOK) { | 645 if (ret != DtmfBuffer::kOK) { |
| 654 PacketBuffer::DeleteAllPackets(&packet_list); | 646 PacketBuffer::DeleteAllPackets(&packet_list); |
| 655 return kDtmfParsingError; | 647 return kDtmfParsingError; |
| 656 } | 648 } |
| 657 if (dtmf_buffer_->InsertEvent(event) != DtmfBuffer::kOK) { | 649 if (dtmf_buffer_->InsertEvent(event) != DtmfBuffer::kOK) { |
| 658 PacketBuffer::DeleteAllPackets(&packet_list); | 650 PacketBuffer::DeleteAllPackets(&packet_list); |
| 659 return kDtmfInsertError; | 651 return kDtmfInsertError; |
| 660 } | 652 } |
| 661 // TODO(hlundin): Let the destructor of Packet handle the payload. | |
| 662 delete [] current_packet->payload; | |
|
kwiberg-webrtc
2016/08/30 16:04:36
Whatever happens, this CL is going to earn you a h
ossu
2016/08/30 16:27:14
Yay! \o/
| |
| 663 delete current_packet; | 653 delete current_packet; |
| 664 it = packet_list.erase(it); | 654 it = packet_list.erase(it); |
| 665 } else { | 655 } else { |
| 666 ++it; | 656 ++it; |
| 667 } | 657 } |
| 668 } | 658 } |
| 669 | 659 |
| 670 // Check for FEC in packets, and separate payloads into several packets. | 660 // Check for FEC in packets, and separate payloads into several packets. |
| 671 int ret = payload_splitter_->SplitFec(&packet_list, decoder_database_.get()); | 661 int ret = payload_splitter_->SplitFec(&packet_list, decoder_database_.get()); |
| 672 if (ret != PayloadSplitter::kOK) { | 662 if (ret != PayloadSplitter::kOK) { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 697 | 687 |
| 698 // Update bandwidth estimate, if the packet is not sync-packet nor comfort | 688 // Update bandwidth estimate, if the packet is not sync-packet nor comfort |
| 699 // noise. | 689 // noise. |
| 700 if (!packet_list.empty() && !packet_list.front()->sync_packet && | 690 if (!packet_list.empty() && !packet_list.front()->sync_packet && |
| 701 !decoder_database_->IsComfortNoise(main_header.payloadType)) { | 691 !decoder_database_->IsComfortNoise(main_header.payloadType)) { |
| 702 // The list can be empty here if we got nothing but DTMF payloads. | 692 // The list can be empty here if we got nothing but DTMF payloads. |
| 703 AudioDecoder* decoder = | 693 AudioDecoder* decoder = |
| 704 decoder_database_->GetDecoder(main_header.payloadType); | 694 decoder_database_->GetDecoder(main_header.payloadType); |
| 705 assert(decoder); // Should always get a valid object, since we have | 695 assert(decoder); // Should always get a valid object, since we have |
| 706 // already checked that the payload types are known. | 696 // already checked that the payload types are known. |
| 707 decoder->IncomingPacket(packet_list.front()->payload, | 697 decoder->IncomingPacket(packet_list.front()->payload.data(), |
| 708 packet_list.front()->payload_length, | 698 packet_list.front()->payload.size(), |
| 709 packet_list.front()->header.sequenceNumber, | 699 packet_list.front()->header.sequenceNumber, |
| 710 packet_list.front()->header.timestamp, | 700 packet_list.front()->header.timestamp, |
| 711 receive_timestamp); | 701 receive_timestamp); |
| 712 } | 702 } |
| 713 | 703 |
| 714 if (nack_enabled_) { | 704 if (nack_enabled_) { |
| 715 RTC_DCHECK(nack_); | 705 RTC_DCHECK(nack_); |
| 716 if (update_sample_rate_and_channels) { | 706 if (update_sample_rate_and_channels) { |
| 717 nack_->Reset(); | 707 nack_->Reset(); |
| 718 } | 708 } |
| (...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1462 !decoder_database_->IsComfortNoise(packet->header.payloadType)) { | 1452 !decoder_database_->IsComfortNoise(packet->header.payloadType)) { |
| 1463 assert(decoder); // At this point, we must have a decoder object. | 1453 assert(decoder); // At this point, we must have a decoder object. |
| 1464 // The number of channels in the |sync_buffer_| should be the same as the | 1454 // The number of channels in the |sync_buffer_| should be the same as the |
| 1465 // number decoder channels. | 1455 // number decoder channels. |
| 1466 assert(sync_buffer_->Channels() == decoder->Channels()); | 1456 assert(sync_buffer_->Channels() == decoder->Channels()); |
| 1467 assert(decoded_buffer_length_ >= kMaxFrameSize * decoder->Channels()); | 1457 assert(decoded_buffer_length_ >= kMaxFrameSize * decoder->Channels()); |
| 1468 assert(operation == kNormal || operation == kAccelerate || | 1458 assert(operation == kNormal || operation == kAccelerate || |
| 1469 operation == kFastAccelerate || operation == kMerge || | 1459 operation == kFastAccelerate || operation == kMerge || |
| 1470 operation == kPreemptiveExpand); | 1460 operation == kPreemptiveExpand); |
| 1471 packet_list->pop_front(); | 1461 packet_list->pop_front(); |
| 1472 size_t payload_length = packet->payload_length; | 1462 const size_t payload_length = packet->payload.size(); |
| 1473 int decode_length; | 1463 int decode_length; |
| 1474 if (packet->sync_packet) { | 1464 if (packet->sync_packet) { |
| 1475 // Decode to silence with the same frame size as the last decode. | 1465 // Decode to silence with the same frame size as the last decode. |
| 1476 memset(&decoded_buffer_[*decoded_length], 0, | 1466 memset(&decoded_buffer_[*decoded_length], 0, |
| 1477 decoder_frame_length_ * decoder->Channels() * | 1467 decoder_frame_length_ * decoder->Channels() * |
| 1478 sizeof(decoded_buffer_[0])); | 1468 sizeof(decoded_buffer_[0])); |
| 1479 decode_length = rtc::checked_cast<int>(decoder_frame_length_); | 1469 decode_length = rtc::checked_cast<int>(decoder_frame_length_); |
| 1480 } else if (!packet->primary) { | 1470 } else if (!packet->primary) { |
| 1481 // This is a redundant payload; call the special decoder method. | 1471 // This is a redundant payload; call the special decoder method. |
| 1482 decode_length = decoder->DecodeRedundant( | 1472 decode_length = decoder->DecodeRedundant( |
| 1483 packet->payload, packet->payload_length, fs_hz_, | 1473 packet->payload.data(), packet->payload.size(), fs_hz_, |
| 1484 (decoded_buffer_length_ - *decoded_length) * sizeof(int16_t), | 1474 (decoded_buffer_length_ - *decoded_length) * sizeof(int16_t), |
| 1485 &decoded_buffer_[*decoded_length], speech_type); | 1475 &decoded_buffer_[*decoded_length], speech_type); |
| 1486 } else { | 1476 } else { |
| 1487 decode_length = | 1477 decode_length = decoder->Decode( |
| 1488 decoder->Decode( | 1478 packet->payload.data(), packet->payload.size(), fs_hz_, |
| 1489 packet->payload, packet->payload_length, fs_hz_, | 1479 (decoded_buffer_length_ - *decoded_length) * sizeof(int16_t), |
| 1490 (decoded_buffer_length_ - *decoded_length) * sizeof(int16_t), | 1480 &decoded_buffer_[*decoded_length], speech_type); |
| 1491 &decoded_buffer_[*decoded_length], speech_type); | |
| 1492 } | 1481 } |
| 1493 | 1482 |
| 1494 delete[] packet->payload; | |
| 1495 delete packet; | 1483 delete packet; |
| 1496 packet = NULL; | 1484 packet = NULL; |
| 1497 if (decode_length > 0) { | 1485 if (decode_length > 0) { |
| 1498 *decoded_length += decode_length; | 1486 *decoded_length += decode_length; |
| 1499 // Update |decoder_frame_length_| with number of samples per channel. | 1487 // Update |decoder_frame_length_| with number of samples per channel. |
| 1500 decoder_frame_length_ = | 1488 decoder_frame_length_ = |
| 1501 static_cast<size_t>(decode_length) / decoder->Channels(); | 1489 static_cast<size_t>(decode_length) / decoder->Channels(); |
| 1502 } else if (decode_length < 0) { | 1490 } else if (decode_length < 0) { |
| 1503 // Error. | 1491 // Error. |
| 1504 LOG(LS_WARNING) << "Decode " << decode_length << " " << payload_length; | 1492 LOG(LS_WARNING) << "Decode " << decode_length << " " << payload_length; |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1957 Packet* packet = packet_buffer_->GetNextPacket(&discard_count); | 1945 Packet* packet = packet_buffer_->GetNextPacket(&discard_count); |
| 1958 // |header| may be invalid after the |packet_buffer_| operation. | 1946 // |header| may be invalid after the |packet_buffer_| operation. |
| 1959 header = NULL; | 1947 header = NULL; |
| 1960 if (!packet) { | 1948 if (!packet) { |
| 1961 LOG(LS_ERROR) << "Should always be able to extract a packet here"; | 1949 LOG(LS_ERROR) << "Should always be able to extract a packet here"; |
| 1962 assert(false); // Should always be able to extract a packet here. | 1950 assert(false); // Should always be able to extract a packet here. |
| 1963 return -1; | 1951 return -1; |
| 1964 } | 1952 } |
| 1965 stats_.PacketsDiscarded(discard_count); | 1953 stats_.PacketsDiscarded(discard_count); |
| 1966 stats_.StoreWaitingTime(packet->waiting_time->ElapsedMs()); | 1954 stats_.StoreWaitingTime(packet->waiting_time->ElapsedMs()); |
| 1967 assert(packet->payload_length > 0); | 1955 assert(!packet->payload.empty()); |
| 1968 packet_list->push_back(packet); // Store packet in list. | 1956 packet_list->push_back(packet); // Store packet in list. |
| 1969 | 1957 |
| 1970 if (first_packet) { | 1958 if (first_packet) { |
| 1971 first_packet = false; | 1959 first_packet = false; |
| 1972 if (nack_enabled_) { | 1960 if (nack_enabled_) { |
| 1973 RTC_DCHECK(nack_); | 1961 RTC_DCHECK(nack_); |
| 1974 // TODO(henrik.lundin): Should we update this for all decoded packets? | 1962 // TODO(henrik.lundin): Should we update this for all decoded packets? |
| 1975 nack_->UpdateLastDecodedPacket(packet->header.sequenceNumber, | 1963 nack_->UpdateLastDecodedPacket(packet->header.sequenceNumber, |
| 1976 packet->header.timestamp); | 1964 packet->header.timestamp); |
| 1977 } | 1965 } |
| 1978 prev_sequence_number = packet->header.sequenceNumber; | 1966 prev_sequence_number = packet->header.sequenceNumber; |
| 1979 prev_timestamp = packet->header.timestamp; | 1967 prev_timestamp = packet->header.timestamp; |
| 1980 prev_payload_type = packet->header.payloadType; | 1968 prev_payload_type = packet->header.payloadType; |
| 1981 } | 1969 } |
| 1982 | 1970 |
| 1983 // Store number of extracted samples. | 1971 // Store number of extracted samples. |
| 1984 int packet_duration = 0; | 1972 int packet_duration = 0; |
| 1985 AudioDecoder* decoder = decoder_database_->GetDecoder( | 1973 AudioDecoder* decoder = decoder_database_->GetDecoder( |
| 1986 packet->header.payloadType); | 1974 packet->header.payloadType); |
| 1987 if (decoder) { | 1975 if (decoder) { |
| 1988 if (packet->sync_packet) { | 1976 if (packet->sync_packet) { |
| 1989 packet_duration = rtc::checked_cast<int>(decoder_frame_length_); | 1977 packet_duration = rtc::checked_cast<int>(decoder_frame_length_); |
| 1990 } else { | 1978 } else { |
| 1991 if (packet->primary) { | 1979 if (packet->primary) { |
| 1992 packet_duration = decoder->PacketDuration(packet->payload, | 1980 packet_duration = decoder->PacketDuration(packet->payload.data(), |
| 1993 packet->payload_length); | 1981 packet->payload.size()); |
| 1994 } else { | 1982 } else { |
| 1995 packet_duration = decoder-> | 1983 packet_duration = decoder->PacketDurationRedundant( |
| 1996 PacketDurationRedundant(packet->payload, packet->payload_length); | 1984 packet->payload.data(), packet->payload.size()); |
| 1997 stats_.SecondaryDecodedSamples(packet_duration); | 1985 stats_.SecondaryDecodedSamples(packet_duration); |
| 1998 } | 1986 } |
| 1999 } | 1987 } |
| 2000 } else if (!decoder_database_->IsComfortNoise(packet->header.payloadType)) { | 1988 } else if (!decoder_database_->IsComfortNoise(packet->header.payloadType)) { |
| 2001 LOG(LS_WARNING) << "Unknown payload type " | 1989 LOG(LS_WARNING) << "Unknown payload type " |
| 2002 << static_cast<int>(packet->header.payloadType); | 1990 << static_cast<int>(packet->header.payloadType); |
| 2003 assert(false); | 1991 assert(false); |
| 2004 } | 1992 } |
| 2005 if (packet_duration <= 0) { | 1993 if (packet_duration <= 0) { |
| 2006 // Decoder did not return a packet duration. Assume that the packet | 1994 // Decoder did not return a packet duration. Assume that the packet |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2135 } | 2123 } |
| 2136 } | 2124 } |
| 2137 | 2125 |
| 2138 void NetEqImpl::CreateDecisionLogic() { | 2126 void NetEqImpl::CreateDecisionLogic() { |
| 2139 decision_logic_.reset(DecisionLogic::Create( | 2127 decision_logic_.reset(DecisionLogic::Create( |
| 2140 fs_hz_, output_size_samples_, playout_mode_, decoder_database_.get(), | 2128 fs_hz_, output_size_samples_, playout_mode_, decoder_database_.get(), |
| 2141 *packet_buffer_.get(), delay_manager_.get(), buffer_level_filter_.get(), | 2129 *packet_buffer_.get(), delay_manager_.get(), buffer_level_filter_.get(), |
| 2142 tick_timer_.get())); | 2130 tick_timer_.get())); |
| 2143 } | 2131 } |
| 2144 } // namespace webrtc | 2132 } // namespace webrtc |
| OLD | NEW |