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

Side by Side Diff: webrtc/modules/audio_coding/neteq/tools/fake_decode_from_file.cc

Issue 2845013003: NetEq tests: BUILD target reorg (Closed)
Patch Set: Fixing win compile errors Created 3 years, 7 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
« no previous file with comments | « webrtc/modules/audio_coding/BUILD.gn ('k') | webrtc/modules/audio_processing/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 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 11 matching lines...) Expand all
22 int sample_rate_hz, 22 int sample_rate_hz,
23 int16_t* decoded, 23 int16_t* decoded,
24 SpeechType* speech_type) { 24 SpeechType* speech_type) {
25 if (encoded_len == 0) { 25 if (encoded_len == 0) {
26 // Decoder is asked to produce codec-internal comfort noise. 26 // Decoder is asked to produce codec-internal comfort noise.
27 RTC_DCHECK(!encoded); // NetEq always sends nullptr in this case. 27 RTC_DCHECK(!encoded); // NetEq always sends nullptr in this case.
28 RTC_DCHECK(cng_mode_); 28 RTC_DCHECK(cng_mode_);
29 RTC_DCHECK_GT(last_decoded_length_, 0); 29 RTC_DCHECK_GT(last_decoded_length_, 0);
30 std::fill_n(decoded, last_decoded_length_, 0); 30 std::fill_n(decoded, last_decoded_length_, 0);
31 *speech_type = kComfortNoise; 31 *speech_type = kComfortNoise;
32 return last_decoded_length_; 32 return rtc::dchecked_cast<int>(last_decoded_length_);
33 } 33 }
34 34
35 RTC_CHECK_GE(encoded_len, 12); 35 RTC_CHECK_GE(encoded_len, 12);
36 uint32_t timestamp_to_decode = 36 uint32_t timestamp_to_decode =
37 ByteReader<uint32_t>::ReadLittleEndian(encoded); 37 ByteReader<uint32_t>::ReadLittleEndian(encoded);
38 uint32_t samples_to_decode = 38 uint32_t samples_to_decode =
39 ByteReader<uint32_t>::ReadLittleEndian(&encoded[4]); 39 ByteReader<uint32_t>::ReadLittleEndian(&encoded[4]);
40 if (samples_to_decode == 0) { 40 if (samples_to_decode == 0) {
41 // Number of samples in packet is unknown. 41 // Number of samples in packet is unknown.
42 if (last_decoded_length_ > 0) { 42 if (last_decoded_length_ > 0) {
43 // Use length of last decoded packet, but since this is the total for all 43 // Use length of last decoded packet, but since this is the total for all
44 // channels, we have to divide by 2 in the stereo case. 44 // channels, we have to divide by 2 in the stereo case.
45 samples_to_decode = rtc::CheckedDivExact( 45 samples_to_decode = rtc::dchecked_cast<int>(rtc::CheckedDivExact(
46 last_decoded_length_, static_cast<size_t>(stereo_ ? 2uL : 1uL)); 46 last_decoded_length_, static_cast<size_t>(stereo_ ? 2uL : 1uL)));
47 } else { 47 } else {
48 // This is the first packet to decode, and we do not know the length of 48 // This is the first packet to decode, and we do not know the length of
49 // it. Set it to 10 ms. 49 // it. Set it to 10 ms.
50 samples_to_decode = rtc::CheckedDivExact(sample_rate_hz, 100); 50 samples_to_decode = rtc::CheckedDivExact(sample_rate_hz, 100);
51 } 51 }
52 } 52 }
53 53
54 if (next_timestamp_from_input_ && 54 if (next_timestamp_from_input_ &&
55 timestamp_to_decode != *next_timestamp_from_input_) { 55 timestamp_to_decode != *next_timestamp_from_input_) {
56 // A gap in the timestamp sequence is detected. Skip the same number of 56 // A gap in the timestamp sequence is detected. Skip the same number of
57 // samples from the file. 57 // samples from the file.
58 uint32_t jump = timestamp_to_decode - *next_timestamp_from_input_; 58 uint32_t jump = timestamp_to_decode - *next_timestamp_from_input_;
59 RTC_CHECK(input_->Seek(jump)); 59 RTC_CHECK(input_->Seek(jump));
60 } 60 }
61 61
62 next_timestamp_from_input_ = 62 next_timestamp_from_input_ =
63 rtc::Optional<uint32_t>(timestamp_to_decode + samples_to_decode); 63 rtc::Optional<uint32_t>(timestamp_to_decode + samples_to_decode);
64 64
65 uint32_t original_payload_size_bytes = 65 uint32_t original_payload_size_bytes =
66 ByteReader<uint32_t>::ReadLittleEndian(&encoded[8]); 66 ByteReader<uint32_t>::ReadLittleEndian(&encoded[8]);
67 if (original_payload_size_bytes == 1) { 67 if (original_payload_size_bytes == 1) {
68 // This is a comfort noise payload. 68 // This is a comfort noise payload.
69 RTC_DCHECK_GT(last_decoded_length_, 0); 69 RTC_DCHECK_GT(last_decoded_length_, 0);
70 std::fill_n(decoded, last_decoded_length_, 0); 70 std::fill_n(decoded, last_decoded_length_, 0);
71 *speech_type = kComfortNoise; 71 *speech_type = kComfortNoise;
72 cng_mode_ = true; 72 cng_mode_ = true;
73 return last_decoded_length_; 73 return rtc::dchecked_cast<int>(last_decoded_length_);
74 } 74 }
75 75
76 cng_mode_ = false; 76 cng_mode_ = false;
77 RTC_CHECK(input_->Read(static_cast<size_t>(samples_to_decode), decoded)); 77 RTC_CHECK(input_->Read(static_cast<size_t>(samples_to_decode), decoded));
78 78
79 if (stereo_) { 79 if (stereo_) {
80 InputAudioFile::DuplicateInterleaved(decoded, samples_to_decode, 2, 80 InputAudioFile::DuplicateInterleaved(decoded, samples_to_decode, 2,
81 decoded); 81 decoded);
82 samples_to_decode *= 2; 82 samples_to_decode *= 2;
83 } 83 }
84 84
85 *speech_type = kSpeech; 85 *speech_type = kSpeech;
86 return last_decoded_length_ = samples_to_decode; 86 last_decoded_length_ = samples_to_decode;
87 return rtc::dchecked_cast<int>(last_decoded_length_);
87 } 88 }
88 89
89 void FakeDecodeFromFile::PrepareEncoded(uint32_t timestamp, 90 void FakeDecodeFromFile::PrepareEncoded(uint32_t timestamp,
90 size_t samples, 91 size_t samples,
91 size_t original_payload_size_bytes, 92 size_t original_payload_size_bytes,
92 rtc::ArrayView<uint8_t> encoded) { 93 rtc::ArrayView<uint8_t> encoded) {
93 RTC_CHECK_GE(encoded.size(), 12); 94 RTC_CHECK_GE(encoded.size(), 12);
94 ByteWriter<uint32_t>::WriteLittleEndian(&encoded[0], timestamp); 95 ByteWriter<uint32_t>::WriteLittleEndian(&encoded[0], timestamp);
95 ByteWriter<uint32_t>::WriteLittleEndian(&encoded[4], 96 ByteWriter<uint32_t>::WriteLittleEndian(&encoded[4],
96 rtc::checked_cast<uint32_t>(samples)); 97 rtc::checked_cast<uint32_t>(samples));
97 ByteWriter<uint32_t>::WriteLittleEndian( 98 ByteWriter<uint32_t>::WriteLittleEndian(
98 &encoded[8], rtc::checked_cast<uint32_t>(original_payload_size_bytes)); 99 &encoded[8], rtc::checked_cast<uint32_t>(original_payload_size_bytes));
99 } 100 }
100 101
101 } // namespace test 102 } // namespace test
102 } // namespace webrtc 103 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/BUILD.gn ('k') | webrtc/modules/audio_processing/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698