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

Side by Side Diff: webrtc/modules/audio_coding/test/PCMFile.cc

Issue 1513223002: Reduce the runtime of some ACM tests in modules_tests (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing win64 build Created 5 years 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
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
11 #include "PCMFile.h" 11 #include "webrtc/modules/audio_coding/test/PCMFile.h"
12 12
13 #include <ctype.h> 13 #include <ctype.h>
14 #include <stdio.h> 14 #include <stdio.h>
15 #include <string.h> 15 #include <string.h>
16 16
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "webrtc/modules/include/module_common_types.h" 18 #include "webrtc/modules/include/module_common_types.h"
19 19
20 namespace webrtc { 20 namespace webrtc {
21 21
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 rewinded_ = true; 130 rewinded_ = true;
131 } else { 131 } else {
132 end_of_file_ = true; 132 end_of_file_ = true;
133 } 133 }
134 } 134 }
135 audio_frame.samples_per_channel_ = samples_10ms_; 135 audio_frame.samples_per_channel_ = samples_10ms_;
136 audio_frame.sample_rate_hz_ = frequency_; 136 audio_frame.sample_rate_hz_ = frequency_;
137 audio_frame.num_channels_ = channels; 137 audio_frame.num_channels_ = channels;
138 audio_frame.timestamp_ = timestamp_; 138 audio_frame.timestamp_ = timestamp_;
139 timestamp_ += samples_10ms_; 139 timestamp_ += samples_10ms_;
140 ++blocks_read_;
141 if (num_10ms_blocks_to_read_ && blocks_read_ >= *num_10ms_blocks_to_read_)
142 end_of_file_ = true;
140 return samples_10ms_; 143 return samples_10ms_;
141 } 144 }
142 145
143 void PCMFile::Write10MsData(AudioFrame& audio_frame) { 146 void PCMFile::Write10MsData(AudioFrame& audio_frame) {
144 if (audio_frame.num_channels_ == 1) { 147 if (audio_frame.num_channels_ == 1) {
145 if (!save_stereo_) { 148 if (!save_stereo_) {
146 if (fwrite(audio_frame.data_, sizeof(uint16_t), 149 if (fwrite(audio_frame.data_, sizeof(uint16_t),
147 audio_frame.samples_per_channel_, pcm_file_) != 150 audio_frame.samples_per_channel_, pcm_file_) !=
148 static_cast<size_t>(audio_frame.samples_per_channel_)) { 151 static_cast<size_t>(audio_frame.samples_per_channel_)) {
149 return; 152 return;
(...skipping 25 matching lines...) Expand all
175 void PCMFile::Write10MsData(int16_t* playout_buffer, size_t length_smpls) { 178 void PCMFile::Write10MsData(int16_t* playout_buffer, size_t length_smpls) {
176 if (fwrite(playout_buffer, sizeof(uint16_t), length_smpls, pcm_file_) != 179 if (fwrite(playout_buffer, sizeof(uint16_t), length_smpls, pcm_file_) !=
177 length_smpls) { 180 length_smpls) {
178 return; 181 return;
179 } 182 }
180 } 183 }
181 184
182 void PCMFile::Close() { 185 void PCMFile::Close() {
183 fclose(pcm_file_); 186 fclose(pcm_file_);
184 pcm_file_ = NULL; 187 pcm_file_ = NULL;
188 blocks_read_ = 0;
189 }
190
191 void PCMFile::FastForward(int num_10ms_blocks) {
192 const int channels = read_stereo_ ? 2 : 1;
193 long num_bytes_to_move =
194 num_10ms_blocks * sizeof(int16_t) * samples_10ms_ * channels;
195 int error = fseek(pcm_file_, num_bytes_to_move, SEEK_CUR);
196 RTC_DCHECK_EQ(error, 0);
185 } 197 }
186 198
187 void PCMFile::Rewind() { 199 void PCMFile::Rewind() {
188 rewind(pcm_file_); 200 rewind(pcm_file_);
189 end_of_file_ = false; 201 end_of_file_ = false;
202 blocks_read_ = 0;
190 } 203 }
191 204
192 bool PCMFile::Rewinded() { 205 bool PCMFile::Rewinded() {
193 return rewinded_; 206 return rewinded_;
194 } 207 }
195 208
196 void PCMFile::SaveStereo(bool is_stereo) { 209 void PCMFile::SaveStereo(bool is_stereo) {
197 save_stereo_ = is_stereo; 210 save_stereo_ = is_stereo;
198 } 211 }
199 212
200 void PCMFile::ReadStereo(bool is_stereo) { 213 void PCMFile::ReadStereo(bool is_stereo) {
201 read_stereo_ = is_stereo; 214 read_stereo_ = is_stereo;
202 } 215 }
203 216
217 void PCMFile::SetNum10MsBlocksToRead(int value) {
218 num_10ms_blocks_to_read_ = rtc::Optional<int>(value);
219 }
220
204 } // namespace webrtc 221 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/test/PCMFile.h ('k') | webrtc/modules/audio_coding/test/TestAllCodecs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698