OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 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 |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #include "webrtc/modules/audio_coding/neteq/tools/neteq_replacement_input.h" |
| 12 |
| 13 #include "webrtc/base/checks.h" |
| 14 #include "webrtc/modules/audio_coding/neteq/tools/fake_decode_from_file.h" |
| 15 |
| 16 namespace webrtc { |
| 17 namespace test { |
| 18 |
| 19 NetEqReplacementInput::NetEqReplacementInput( |
| 20 std::unique_ptr<NetEqInput> source, |
| 21 uint8_t replacement_payload_type, |
| 22 const std::set<uint8_t>& comfort_noise_types, |
| 23 const std::set<uint8_t>& forbidden_types) |
| 24 : source_(std::move(source)), |
| 25 replacement_payload_type_(replacement_payload_type), |
| 26 comfort_noise_types_(comfort_noise_types), |
| 27 forbidden_types_(forbidden_types) { |
| 28 RTC_CHECK(source_); |
| 29 packet_ = source_->PopPacket(); |
| 30 ReplacePacket(); |
| 31 RTC_CHECK(packet_); |
| 32 } |
| 33 |
| 34 rtc::Optional<int64_t> NetEqReplacementInput::NextPacketTime() const { |
| 35 return packet_ |
| 36 ? rtc::Optional<int64_t>(static_cast<int64_t>(packet_->time_ms)) |
| 37 : rtc::Optional<int64_t>(); |
| 38 } |
| 39 |
| 40 rtc::Optional<int64_t> NetEqReplacementInput::NextOutputEventTime() const { |
| 41 return source_->NextOutputEventTime(); |
| 42 } |
| 43 |
| 44 std::unique_ptr<NetEqInput::PacketData> NetEqReplacementInput::PopPacket() { |
| 45 std::unique_ptr<PacketData> to_return = std::move(packet_); |
| 46 packet_ = source_->PopPacket(); |
| 47 ReplacePacket(); |
| 48 return to_return; |
| 49 } |
| 50 |
| 51 void NetEqReplacementInput::AdvanceOutputEvent() { |
| 52 source_->AdvanceOutputEvent(); |
| 53 } |
| 54 |
| 55 bool NetEqReplacementInput::ended() const { |
| 56 return source_->ended(); |
| 57 } |
| 58 |
| 59 rtc::Optional<RTPHeader> NetEqReplacementInput::NextHeader() const { |
| 60 return source_->NextHeader(); |
| 61 } |
| 62 |
| 63 void NetEqReplacementInput::ReplacePacket() { |
| 64 if (!source_->NextPacketTime()) { |
| 65 // End of input. Cannot do proper replacement on the very last packet, so we |
| 66 // delete it instead. |
| 67 packet_.reset(); |
| 68 return; |
| 69 } |
| 70 |
| 71 RTC_DCHECK(packet_); |
| 72 |
| 73 RTC_CHECK_EQ(forbidden_types_.count(packet_->header.header.payloadType), 0u) |
| 74 << "Payload type " << static_cast<int>(packet_->header.header.payloadType) |
| 75 << " is forbidden."; |
| 76 |
| 77 // Check if this packet is comfort noise. |
| 78 if (comfort_noise_types_.count(packet_->header.header.payloadType) != 0) { |
| 79 // If CNG, simply insert a zero-energy one-byte payload. |
| 80 uint8_t cng_payload[1] = {127}; // Max attenuation of CNG. |
| 81 packet_->payload.SetData(cng_payload); |
| 82 return; |
| 83 } |
| 84 |
| 85 rtc::Optional<RTPHeader> next_hdr = source_->NextHeader(); |
| 86 RTC_DCHECK(next_hdr); |
| 87 uint8_t payload[8]; |
| 88 uint32_t input_frame_size_timestamps = |
| 89 next_hdr->timestamp - packet_->header.header.timestamp; |
| 90 FakeDecodeFromFile::PrepareEncoded(packet_->header.header.timestamp, |
| 91 input_frame_size_timestamps, payload); |
| 92 packet_->payload.SetData(payload); |
| 93 packet_->header.header.payloadType = replacement_payload_type_; |
| 94 return; |
| 95 } |
| 96 |
| 97 } // namespace test |
| 98 } // namespace webrtc |
OLD | NEW |