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 <memory> |
| 12 |
| 13 #include "webrtc/base/array_view.h" |
| 14 #include "webrtc/modules/audio_coding/codecs/pcm16b/audio_encoder_pcm16b.h" |
| 15 #include "webrtc/modules/audio_coding/neteq/tools/audio_checksum.h" |
| 16 #include "webrtc/modules/audio_coding/neteq/tools/encode_neteq_input.h" |
| 17 #include "webrtc/modules/audio_coding/neteq/tools/neteq_test.h" |
| 18 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
| 19 #include "webrtc/test/testsupport/fileutils.h" |
| 20 |
| 21 namespace webrtc { |
| 22 namespace test { |
| 23 namespace { |
| 24 constexpr int kPayloadType = 95; |
| 25 |
| 26 class FuzzRtpInput : public NetEqInput { |
| 27 public: |
| 28 explicit FuzzRtpInput(rtc::ArrayView<const uint8_t> data) : data_(data) { |
| 29 std::unique_ptr<InputAudioFile> audio_input( |
| 30 new InputAudioFile(ResourcePath("audio_coding/testfile32kHz", "pcm"))); |
| 31 AudioEncoderPcm16B::Config config; |
| 32 config.payload_type = kPayloadType; |
| 33 config.sample_rate_hz = 32000; |
| 34 std::unique_ptr<AudioEncoder> encoder(new AudioEncoderPcm16B(config)); |
| 35 input_.reset(new EncodeNetEqInput(std::move(audio_input), |
| 36 std::move(encoder), |
| 37 std::numeric_limits<int64_t>::max())); |
| 38 packet_ = input_->PopPacket(); |
| 39 FuzzHeader(); |
| 40 } |
| 41 |
| 42 rtc::Optional<int64_t> NextPacketTime() const override { |
| 43 return rtc::Optional<int64_t>(packet_->time_ms); |
| 44 } |
| 45 |
| 46 rtc::Optional<int64_t> NextOutputEventTime() const override { |
| 47 return input_->NextOutputEventTime(); |
| 48 } |
| 49 |
| 50 std::unique_ptr<PacketData> PopPacket() override { |
| 51 RTC_DCHECK(packet_); |
| 52 std::unique_ptr<PacketData> packet_to_return = std::move(packet_); |
| 53 packet_ = input_->PopPacket(); |
| 54 FuzzHeader(); |
| 55 return packet_to_return; |
| 56 } |
| 57 |
| 58 void AdvanceOutputEvent() override { return input_->AdvanceOutputEvent(); } |
| 59 |
| 60 bool ended() const override { return ended_; } |
| 61 |
| 62 rtc::Optional<RTPHeader> NextHeader() const override { |
| 63 RTC_DCHECK(packet_); |
| 64 return rtc::Optional<RTPHeader>(packet_->header.header); |
| 65 } |
| 66 |
| 67 private: |
| 68 void FuzzHeader() { |
| 69 constexpr size_t kNumBytesToFuzz = 11; |
| 70 if (data_ix_ + kNumBytesToFuzz > data_.size()) { |
| 71 ended_ = true; |
| 72 return; |
| 73 } |
| 74 RTC_DCHECK(packet_); |
| 75 const size_t start_ix = data_ix_; |
| 76 packet_->header.header.payloadType = |
| 77 ByteReader<uint8_t>::ReadLittleEndian(&data_[data_ix_]); |
| 78 packet_->header.header.payloadType &= 0x7F; |
| 79 data_ix_ += sizeof(uint8_t); |
| 80 packet_->header.header.sequenceNumber = |
| 81 ByteReader<uint16_t>::ReadLittleEndian(&data_[data_ix_]); |
| 82 data_ix_ += sizeof(uint16_t); |
| 83 packet_->header.header.timestamp = |
| 84 ByteReader<uint32_t>::ReadLittleEndian(&data_[data_ix_]); |
| 85 data_ix_ += sizeof(uint32_t); |
| 86 packet_->header.header.ssrc = |
| 87 ByteReader<uint32_t>::ReadLittleEndian(&data_[data_ix_]); |
| 88 data_ix_ += sizeof(uint32_t); |
| 89 RTC_CHECK_EQ(data_ix_ - start_ix, kNumBytesToFuzz); |
| 90 } |
| 91 |
| 92 bool ended_ = false; |
| 93 rtc::ArrayView<const uint8_t> data_; |
| 94 size_t data_ix_ = 0; |
| 95 std::unique_ptr<EncodeNetEqInput> input_; |
| 96 std::unique_ptr<PacketData> packet_; |
| 97 }; |
| 98 } // namespace |
| 99 |
| 100 void FuzzOneInputTest(const uint8_t* data, size_t size) { |
| 101 std::unique_ptr<FuzzRtpInput> input( |
| 102 new FuzzRtpInput(rtc::ArrayView<const uint8_t>(data, size))); |
| 103 std::unique_ptr<AudioChecksum> output(new AudioChecksum); |
| 104 NetEqTestErrorCallback dummy_callback; // Does nothing with error callbacks. |
| 105 NetEq::Config config; |
| 106 NetEqTest::DecoderMap codecs; |
| 107 codecs[0] = std::make_pair(NetEqDecoder::kDecoderPCMu, "pcmu"); |
| 108 codecs[8] = std::make_pair(NetEqDecoder::kDecoderPCMa, "pcma"); |
| 109 codecs[102] = std::make_pair(NetEqDecoder::kDecoderILBC, "ilbc"); |
| 110 codecs[103] = std::make_pair(NetEqDecoder::kDecoderISAC, "isac"); |
| 111 codecs[104] = std::make_pair(NetEqDecoder::kDecoderISACswb, "isac-swb"); |
| 112 codecs[111] = std::make_pair(NetEqDecoder::kDecoderOpus, "opus"); |
| 113 codecs[93] = std::make_pair(NetEqDecoder::kDecoderPCM16B, "pcm16-nb"); |
| 114 codecs[94] = std::make_pair(NetEqDecoder::kDecoderPCM16Bwb, "pcm16-wb"); |
| 115 codecs[96] = |
| 116 std::make_pair(NetEqDecoder::kDecoderPCM16Bswb48kHz, "pcm16-swb48"); |
| 117 codecs[9] = std::make_pair(NetEqDecoder::kDecoderG722, "g722"); |
| 118 codecs[106] = std::make_pair(NetEqDecoder::kDecoderAVT, "avt"); |
| 119 codecs[117] = std::make_pair(NetEqDecoder::kDecoderRED, "red"); |
| 120 codecs[13] = std::make_pair(NetEqDecoder::kDecoderCNGnb, "cng-nb"); |
| 121 codecs[98] = std::make_pair(NetEqDecoder::kDecoderCNGwb, "cng-wb"); |
| 122 codecs[99] = std::make_pair(NetEqDecoder::kDecoderCNGswb32kHz, "cng-swb32"); |
| 123 codecs[100] = std::make_pair(NetEqDecoder::kDecoderCNGswb48kHz, "cng-swb48"); |
| 124 // This is the payload type that will be used for encoding. |
| 125 codecs[kPayloadType] = |
| 126 std::make_pair(NetEqDecoder::kDecoderPCM16Bswb32kHz, "pcm16-swb32"); |
| 127 NetEqTest::ExtDecoderMap ext_codecs; |
| 128 |
| 129 NetEqTest test(config, codecs, ext_codecs, std::move(input), |
| 130 std::move(output), &dummy_callback); |
| 131 test.Run(); |
| 132 } |
| 133 |
| 134 } // namespace test |
| 135 |
| 136 void FuzzOneInput(const uint8_t* data, size_t size) { |
| 137 test::FuzzOneInputTest(data, size); |
| 138 } |
| 139 |
| 140 } // namespace webrtc |
OLD | NEW |