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

Side by Side Diff: webrtc/modules/audio_coding/codecs/ilbc/ilbc_unittest.cc

Issue 2255203002: iLBC: Handle a case of bad input data (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: bool test 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
(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 "testing/gtest/include/gtest/gtest.h"
12 #include "webrtc/modules/audio_coding/codecs/ilbc/audio_decoder_ilbc.h"
13 #include "webrtc/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.h"
14
15 namespace webrtc {
16
17 TEST(IlbcTest, BadPacket) {
18 // Get a good packet.
19 AudioEncoderIlbc::Config config;
20 config.frame_size_ms = 20; // We need 20 ms rather than the default 30 ms;
21 // otherwise, all possible values of cb_index[2]
22 // are valid.
23 AudioEncoderIlbc encoder(config);
24 std::vector<int16_t> samples(encoder.SampleRateHz() / 100, 4711);
25 rtc::Buffer packet;
26 int num_10ms_chunks = 0;
27 while (packet.size() == 0) {
28 encoder.Encode(0, samples, &packet);
29 num_10ms_chunks += 1;
30 }
31
32 // Break the packet by setting all bits of the unsigned 7-bit number
33 // cb_index[2] to 1, giving it a value of 127. For a 20 ms packet, this is
34 // too large.
35 EXPECT_EQ(38u, packet.size());
36 rtc::Buffer bad_packet(packet.data(), packet.size());
37 bad_packet[29] |= 0x3f; // Bits 1-6.
38 bad_packet[30] |= 0x80; // Bit 0.
39
40 // Decode the bad packet. We expect the decoder to respond by returning -1.
41 AudioDecoderIlbc decoder;
42 std::vector<int16_t> decoded_samples(num_10ms_chunks * samples.size());
43 AudioDecoder::SpeechType speech_type;
44 EXPECT_EQ(-1, decoder.Decode(bad_packet.data(), bad_packet.size(),
45 encoder.SampleRateHz(),
46 sizeof(int16_t) * decoded_samples.size(),
47 decoded_samples.data(), &speech_type));
48
49 // Decode the good packet. This should work, because the failed decoding
50 // should not have left the decoder in a broken state.
51 EXPECT_EQ(static_cast<int>(decoded_samples.size()),
52 decoder.Decode(packet.data(), packet.size(), encoder.SampleRateHz(),
53 sizeof(int16_t) * decoded_samples.size(),
54 decoded_samples.data(), &speech_type));
55 }
56
57 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/codecs/ilbc/ilbc.gypi ('k') | webrtc/modules/audio_coding/codecs/ilbc/test/empty.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698