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 312 matching lines...) Loading... | |
323 return kNotImplemented; | 323 return kNotImplemented; |
324 } | 324 } |
325 | 325 |
326 int NetEqImpl::CurrentDelayMs() const { | 326 int NetEqImpl::CurrentDelayMs() const { |
327 rtc::CritScope lock(&crit_sect_); | 327 rtc::CritScope lock(&crit_sect_); |
328 if (fs_hz_ == 0) | 328 if (fs_hz_ == 0) |
329 return 0; | 329 return 0; |
330 // Sum up the samples in the packet buffer with the future length of the sync | 330 // Sum up the samples in the packet buffer with the future length of the sync |
331 // buffer, and divide the sum by the sample rate. | 331 // buffer, and divide the sum by the sample rate. |
332 const size_t delay_samples = | 332 const size_t delay_samples = |
333 packet_buffer_->NumSamplesInBuffer(decoder_database_.get(), | 333 packet_buffer_->NumSamplesInBuffer(decoder_frame_length_) + |
334 decoder_frame_length_) + | |
335 sync_buffer_->FutureLength(); | 334 sync_buffer_->FutureLength(); |
336 // The division below will truncate. | 335 // The division below will truncate. |
337 const int delay_ms = | 336 const int delay_ms = |
338 static_cast<int>(delay_samples) / rtc::CheckedDivExact(fs_hz_, 1000); | 337 static_cast<int>(delay_samples) / rtc::CheckedDivExact(fs_hz_, 1000); |
339 return delay_ms; | 338 return delay_ms; |
340 } | 339 } |
341 | 340 |
342 int NetEqImpl::FilteredCurrentDelayMs() const { | 341 int NetEqImpl::FilteredCurrentDelayMs() const { |
343 rtc::CritScope lock(&crit_sect_); | 342 rtc::CritScope lock(&crit_sect_); |
344 // Calculate the filtered packet buffer level in samples. The value from | 343 // Calculate the filtered packet buffer level in samples. The value from |
(...skipping 24 matching lines...) Loading... | |
369 // TODO(henrik.lundin) Delete. | 368 // TODO(henrik.lundin) Delete. |
370 NetEqPlayoutMode NetEqImpl::PlayoutMode() const { | 369 NetEqPlayoutMode NetEqImpl::PlayoutMode() const { |
371 rtc::CritScope lock(&crit_sect_); | 370 rtc::CritScope lock(&crit_sect_); |
372 return playout_mode_; | 371 return playout_mode_; |
373 } | 372 } |
374 | 373 |
375 int NetEqImpl::NetworkStatistics(NetEqNetworkStatistics* stats) { | 374 int NetEqImpl::NetworkStatistics(NetEqNetworkStatistics* stats) { |
376 rtc::CritScope lock(&crit_sect_); | 375 rtc::CritScope lock(&crit_sect_); |
377 assert(decoder_database_.get()); | 376 assert(decoder_database_.get()); |
378 const size_t total_samples_in_buffers = | 377 const size_t total_samples_in_buffers = |
379 packet_buffer_->NumSamplesInBuffer(decoder_database_.get(), | 378 packet_buffer_->NumSamplesInBuffer(decoder_frame_length_) + |
380 decoder_frame_length_) + | |
381 sync_buffer_->FutureLength(); | 379 sync_buffer_->FutureLength(); |
382 assert(delay_manager_.get()); | 380 assert(delay_manager_.get()); |
383 assert(decision_logic_.get()); | 381 assert(decision_logic_.get()); |
384 stats_.GetNetworkStatistics(fs_hz_, total_samples_in_buffers, | 382 stats_.GetNetworkStatistics(fs_hz_, total_samples_in_buffers, |
385 decoder_frame_length_, *delay_manager_.get(), | 383 decoder_frame_length_, *delay_manager_.get(), |
386 *decision_logic_.get(), stats); | 384 *decision_logic_.get(), stats); |
387 return 0; | 385 return 0; |
388 } | 386 } |
389 | 387 |
390 void NetEqImpl::GetRtcpStatistics(RtcpStatistics* stats) { | 388 void NetEqImpl::GetRtcpStatistics(RtcpStatistics* stats) { |
(...skipping 264 matching lines...) Loading... | |
655 decoder_database_->GetDecoder(main_header.payloadType); | 653 decoder_database_->GetDecoder(main_header.payloadType); |
656 assert(decoder); // Should always get a valid object, since we have | 654 assert(decoder); // Should always get a valid object, since we have |
657 // already checked that the payload types are known. | 655 // already checked that the payload types are known. |
658 decoder->IncomingPacket(packet_list.front()->payload.data(), | 656 decoder->IncomingPacket(packet_list.front()->payload.data(), |
659 packet_list.front()->payload.size(), | 657 packet_list.front()->payload.size(), |
660 packet_list.front()->header.sequenceNumber, | 658 packet_list.front()->header.sequenceNumber, |
661 packet_list.front()->header.timestamp, | 659 packet_list.front()->header.timestamp, |
662 receive_timestamp); | 660 receive_timestamp); |
663 } | 661 } |
664 | 662 |
663 PacketList parsed_packet_list; | |
664 while (!packet_list.empty()) { | |
665 std::unique_ptr<Packet> packet(packet_list.front()); | |
666 packet_list.pop_front(); | |
667 const DecoderDatabase::DecoderInfo* info = | |
668 decoder_database_->GetDecoderInfo(packet->header.payloadType); | |
669 if (!info) { | |
670 LOG(LS_WARNING) << "SplitAudio unknown payload type"; | |
671 return kUnknownRtpPayloadType; | |
672 } | |
673 | |
674 if (info->IsComfortNoise()) { | |
675 // Carry comfort noise packets along. | |
676 parsed_packet_list.push_back(packet.release()); | |
677 } else { | |
678 std::vector<AudioDecoder::ParseResult> results = | |
679 info->GetDecoder()->ParsePayload( | |
680 &packet->payload, packet->header.timestamp, packet->primary); | |
681 | |
682 // Reuse the packet if possible | |
683 if (results.size() == 1) { | |
684 auto& result = results[0]; | |
685 RTC_DCHECK(result.frame); | |
686 packet->header.timestamp = result.timestamp; | |
687 packet->primary = result.primary; | |
688 packet->frame = std::move(result.frame); | |
689 parsed_packet_list.push_back(packet.release()); | |
690 } else { | |
691 for (auto& result : results) { | |
692 // If you can't parse, return an empty list instead! | |
kwiberg-webrtc
2016/09/15 12:00:59
Not sure I understand this comment.
ossu
2016/09/15 13:07:55
Me neither.
| |
693 RTC_DCHECK(result.frame); | |
694 std::unique_ptr<Packet> parsed_packet(new Packet); | |
695 parsed_packet->header = packet->header; | |
696 parsed_packet->header.timestamp = result.timestamp; | |
697 // TODO(ossu): Move from primary to some sort of priority level. | |
698 parsed_packet->primary = result.primary; | |
699 parsed_packet->frame = std::move(result.frame); | |
700 parsed_packet_list.push_back(parsed_packet.release()); | |
701 } | |
702 } | |
kwiberg-webrtc
2016/09/15 12:00:59
Can you eliminate the special case? E.g. by checki
ossu
2016/09/15 13:07:55
Acknowledged.
| |
703 } | |
704 } | |
705 | |
665 if (nack_enabled_) { | 706 if (nack_enabled_) { |
666 RTC_DCHECK(nack_); | 707 RTC_DCHECK(nack_); |
667 if (update_sample_rate_and_channels) { | 708 if (update_sample_rate_and_channels) { |
668 nack_->Reset(); | 709 nack_->Reset(); |
669 } | 710 } |
670 nack_->UpdateLastReceivedPacket(packet_list.front()->header.sequenceNumber, | 711 nack_->UpdateLastReceivedPacket( |
671 packet_list.front()->header.timestamp); | 712 parsed_packet_list.front()->header.sequenceNumber, |
713 parsed_packet_list.front()->header.timestamp); | |
672 } | 714 } |
673 | 715 |
674 // Insert packets in buffer. | 716 // Insert packets in buffer. |
675 const size_t buffer_length_before_insert = | 717 const size_t buffer_length_before_insert = |
676 packet_buffer_->NumPacketsInBuffer(); | 718 packet_buffer_->NumPacketsInBuffer(); |
677 ret = packet_buffer_->InsertPacketList( | 719 ret = packet_buffer_->InsertPacketList( |
678 &packet_list, | 720 &parsed_packet_list, *decoder_database_, ¤t_rtp_payload_type_, |
679 *decoder_database_, | |
680 ¤t_rtp_payload_type_, | |
681 ¤t_cng_rtp_payload_type_); | 721 ¤t_cng_rtp_payload_type_); |
682 if (ret == PacketBuffer::kFlushed) { | 722 if (ret == PacketBuffer::kFlushed) { |
683 // Reset DSP timestamp etc. if packet buffer flushed. | 723 // Reset DSP timestamp etc. if packet buffer flushed. |
684 new_codec_ = true; | 724 new_codec_ = true; |
685 update_sample_rate_and_channels = true; | 725 update_sample_rate_and_channels = true; |
686 } else if (ret != PacketBuffer::kOK) { | 726 } else if (ret != PacketBuffer::kOK) { |
687 PacketBuffer::DeleteAllPackets(&packet_list); | 727 PacketBuffer::DeleteAllPackets(&parsed_packet_list); |
688 return kOtherError; | 728 return kOtherError; |
689 } | 729 } |
690 | 730 |
691 if (first_packet_) { | 731 if (first_packet_) { |
692 first_packet_ = false; | 732 first_packet_ = false; |
693 // Update the codec on the next GetAudio call. | 733 // Update the codec on the next GetAudio call. |
694 new_codec_ = true; | 734 new_codec_ = true; |
695 } | 735 } |
696 | 736 |
697 if (current_rtp_payload_type_) { | 737 if (current_rtp_payload_type_) { |
(...skipping 716 matching lines...) Loading... | |
1414 !decoder_database_->IsComfortNoise(packet->header.payloadType)) { | 1454 !decoder_database_->IsComfortNoise(packet->header.payloadType)) { |
1415 assert(decoder); // At this point, we must have a decoder object. | 1455 assert(decoder); // At this point, we must have a decoder object. |
1416 // The number of channels in the |sync_buffer_| should be the same as the | 1456 // The number of channels in the |sync_buffer_| should be the same as the |
1417 // number decoder channels. | 1457 // number decoder channels. |
1418 assert(sync_buffer_->Channels() == decoder->Channels()); | 1458 assert(sync_buffer_->Channels() == decoder->Channels()); |
1419 assert(decoded_buffer_length_ >= kMaxFrameSize * decoder->Channels()); | 1459 assert(decoded_buffer_length_ >= kMaxFrameSize * decoder->Channels()); |
1420 assert(operation == kNormal || operation == kAccelerate || | 1460 assert(operation == kNormal || operation == kAccelerate || |
1421 operation == kFastAccelerate || operation == kMerge || | 1461 operation == kFastAccelerate || operation == kMerge || |
1422 operation == kPreemptiveExpand); | 1462 operation == kPreemptiveExpand); |
1423 packet_list->pop_front(); | 1463 packet_list->pop_front(); |
1424 const size_t payload_length = packet->payload.size(); | 1464 auto opt_result = packet->frame->Decode( |
1425 int decode_length; | 1465 rtc::ArrayView<int16_t>(&decoded_buffer_[*decoded_length], |
1426 if (!packet->primary) { | 1466 decoded_buffer_length_ - *decoded_length)); |
1427 // This is a redundant payload; call the special decoder method. | |
1428 decode_length = decoder->DecodeRedundant( | |
1429 packet->payload.data(), packet->payload.size(), fs_hz_, | |
1430 (decoded_buffer_length_ - *decoded_length) * sizeof(int16_t), | |
1431 &decoded_buffer_[*decoded_length], speech_type); | |
1432 } else { | |
1433 decode_length = decoder->Decode( | |
1434 packet->payload.data(), packet->payload.size(), fs_hz_, | |
1435 (decoded_buffer_length_ - *decoded_length) * sizeof(int16_t), | |
1436 &decoded_buffer_[*decoded_length], speech_type); | |
1437 } | |
1438 | |
1439 delete packet; | 1467 delete packet; |
1440 packet = NULL; | 1468 packet = NULL; |
1441 if (decode_length > 0) { | 1469 if (opt_result) { |
1442 *decoded_length += decode_length; | 1470 const auto& result = *opt_result; |
1443 // Update |decoder_frame_length_| with number of samples per channel. | 1471 *speech_type = result.speech_type; |
1444 decoder_frame_length_ = | 1472 if (result.num_decoded_samples > 0) { |
1445 static_cast<size_t>(decode_length) / decoder->Channels(); | 1473 *decoded_length += result.num_decoded_samples; |
1446 } else if (decode_length < 0) { | 1474 // Update |decoder_frame_length_| with number of samples per channel. |
1475 decoder_frame_length_ = | |
1476 result.num_decoded_samples / decoder->Channels(); | |
1477 } | |
1478 } else { | |
1447 // Error. | 1479 // Error. |
1448 LOG(LS_WARNING) << "Decode " << decode_length << " " << payload_length; | 1480 // TODO(ossu): What to put here? |
1481 LOG(LS_WARNING) << "Decode error"; | |
1449 *decoded_length = -1; | 1482 *decoded_length = -1; |
1450 PacketBuffer::DeleteAllPackets(packet_list); | 1483 PacketBuffer::DeleteAllPackets(packet_list); |
1451 break; | 1484 break; |
1452 } | 1485 } |
1453 if (*decoded_length > static_cast<int>(decoded_buffer_length_)) { | 1486 if (*decoded_length > static_cast<int>(decoded_buffer_length_)) { |
1454 // Guard against overflow. | 1487 // Guard against overflow. |
1455 LOG(LS_WARNING) << "Decoded too much."; | 1488 LOG(LS_WARNING) << "Decoded too much."; |
1456 PacketBuffer::DeleteAllPackets(packet_list); | 1489 PacketBuffer::DeleteAllPackets(packet_list); |
1457 return kDecodedTooMuch; | 1490 return kDecodedTooMuch; |
1458 } | 1491 } |
(...skipping 442 matching lines...) Loading... | |
1901 Packet* packet = packet_buffer_->GetNextPacket(&discard_count); | 1934 Packet* packet = packet_buffer_->GetNextPacket(&discard_count); |
1902 // |header| may be invalid after the |packet_buffer_| operation. | 1935 // |header| may be invalid after the |packet_buffer_| operation. |
1903 header = NULL; | 1936 header = NULL; |
1904 if (!packet) { | 1937 if (!packet) { |
1905 LOG(LS_ERROR) << "Should always be able to extract a packet here"; | 1938 LOG(LS_ERROR) << "Should always be able to extract a packet here"; |
1906 assert(false); // Should always be able to extract a packet here. | 1939 assert(false); // Should always be able to extract a packet here. |
1907 return -1; | 1940 return -1; |
1908 } | 1941 } |
1909 stats_.PacketsDiscarded(discard_count); | 1942 stats_.PacketsDiscarded(discard_count); |
1910 stats_.StoreWaitingTime(packet->waiting_time->ElapsedMs()); | 1943 stats_.StoreWaitingTime(packet->waiting_time->ElapsedMs()); |
1911 assert(!packet->payload.empty()); | 1944 RTC_DCHECK(!packet->empty()); |
1912 packet_list->push_back(packet); // Store packet in list. | 1945 packet_list->push_back(packet); // Store packet in list. |
1913 | 1946 |
1914 if (first_packet) { | 1947 if (first_packet) { |
1915 first_packet = false; | 1948 first_packet = false; |
1916 if (nack_enabled_) { | 1949 if (nack_enabled_) { |
1917 RTC_DCHECK(nack_); | 1950 RTC_DCHECK(nack_); |
1918 // TODO(henrik.lundin): Should we update this for all decoded packets? | 1951 // TODO(henrik.lundin): Should we update this for all decoded packets? |
1919 nack_->UpdateLastDecodedPacket(packet->header.sequenceNumber, | 1952 nack_->UpdateLastDecodedPacket(packet->header.sequenceNumber, |
1920 packet->header.timestamp); | 1953 packet->header.timestamp); |
1921 } | 1954 } |
1922 prev_sequence_number = packet->header.sequenceNumber; | 1955 prev_sequence_number = packet->header.sequenceNumber; |
1923 prev_timestamp = packet->header.timestamp; | 1956 prev_timestamp = packet->header.timestamp; |
1924 prev_payload_type = packet->header.payloadType; | 1957 prev_payload_type = packet->header.payloadType; |
1925 } | 1958 } |
1926 | 1959 |
1927 // Store number of extracted samples. | 1960 // Store number of extracted samples. |
1928 int packet_duration = 0; | 1961 size_t packet_duration = 0; |
1929 AudioDecoder* decoder = decoder_database_->GetDecoder( | 1962 if (packet->frame) { |
1930 packet->header.payloadType); | 1963 packet_duration = packet->frame->Duration(); |
1931 if (decoder) { | 1964 // TODO(ossu): Is this the correct way to track samples decoded from a |
1932 if (packet->primary) { | 1965 // redundant packet? |
1933 packet_duration = decoder->PacketDuration(packet->payload.data(), | 1966 if (packet_duration > 0 && !packet->primary) { |
1934 packet->payload.size()); | |
1935 } else { | |
1936 packet_duration = decoder->PacketDurationRedundant( | |
1937 packet->payload.data(), packet->payload.size()); | |
1938 stats_.SecondaryDecodedSamples(packet_duration); | 1967 stats_.SecondaryDecodedSamples(packet_duration); |
1939 } | 1968 } |
1940 } else if (!decoder_database_->IsComfortNoise(packet->header.payloadType)) { | 1969 } else if (!decoder_database_->IsComfortNoise(packet->header.payloadType)) { |
1941 LOG(LS_WARNING) << "Unknown payload type " | 1970 LOG(LS_WARNING) << "Unknown payload type " |
1942 << static_cast<int>(packet->header.payloadType); | 1971 << static_cast<int>(packet->header.payloadType); |
1943 assert(false); | 1972 RTC_NOTREACHED(); |
1944 } | 1973 } |
1945 if (packet_duration <= 0) { | 1974 |
1975 if (packet_duration == 0) { | |
1946 // Decoder did not return a packet duration. Assume that the packet | 1976 // Decoder did not return a packet duration. Assume that the packet |
1947 // contains the same number of samples as the previous one. | 1977 // contains the same number of samples as the previous one. |
1948 packet_duration = rtc::checked_cast<int>(decoder_frame_length_); | 1978 packet_duration = decoder_frame_length_; |
1949 } | 1979 } |
1950 extracted_samples = packet->header.timestamp - first_timestamp + | 1980 extracted_samples = packet->header.timestamp - first_timestamp + |
1951 packet_duration; | 1981 packet_duration; |
1952 | 1982 |
1953 // Check what packet is available next. | 1983 // Check what packet is available next. |
1954 header = packet_buffer_->NextRtpHeader(); | 1984 header = packet_buffer_->NextRtpHeader(); |
1955 next_packet_available = false; | 1985 next_packet_available = false; |
1956 if (header && prev_payload_type == header->payloadType) { | 1986 if (header && prev_payload_type == header->payloadType) { |
1957 int16_t seq_no_diff = header->sequenceNumber - prev_sequence_number; | 1987 int16_t seq_no_diff = header->sequenceNumber - prev_sequence_number; |
1958 size_t ts_diff = header->timestamp - prev_timestamp; | 1988 size_t ts_diff = header->timestamp - prev_timestamp; |
(...skipping 116 matching lines...) Loading... | |
2075 } | 2105 } |
2076 } | 2106 } |
2077 | 2107 |
2078 void NetEqImpl::CreateDecisionLogic() { | 2108 void NetEqImpl::CreateDecisionLogic() { |
2079 decision_logic_.reset(DecisionLogic::Create( | 2109 decision_logic_.reset(DecisionLogic::Create( |
2080 fs_hz_, output_size_samples_, playout_mode_, decoder_database_.get(), | 2110 fs_hz_, output_size_samples_, playout_mode_, decoder_database_.get(), |
2081 *packet_buffer_.get(), delay_manager_.get(), buffer_level_filter_.get(), | 2111 *packet_buffer_.get(), delay_manager_.get(), buffer_level_filter_.get(), |
2082 tick_timer_.get())); | 2112 tick_timer_.get())); |
2083 } | 2113 } |
2084 } // namespace webrtc | 2114 } // namespace webrtc |
OLD | NEW |