OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 channels_(static_cast<size_t>(FLAGS_channels)), | 213 channels_(static_cast<size_t>(FLAGS_channels)), |
214 decoded_time_ms_(0), | 214 decoded_time_ms_(0), |
215 decodable_time_ms_(0), | 215 decodable_time_ms_(0), |
216 drift_factor_(FLAGS_drift_factor), | 216 drift_factor_(FLAGS_drift_factor), |
217 packet_loss_rate_(FLAGS_packet_loss_rate), | 217 packet_loss_rate_(FLAGS_packet_loss_rate), |
218 block_duration_ms_(block_duration_ms), | 218 block_duration_ms_(block_duration_ms), |
219 in_sampling_khz_(in_sampling_khz), | 219 in_sampling_khz_(in_sampling_khz), |
220 out_sampling_khz_(out_sampling_khz), | 220 out_sampling_khz_(out_sampling_khz), |
221 in_size_samples_( | 221 in_size_samples_( |
222 static_cast<size_t>(in_sampling_khz_ * block_duration_ms_)), | 222 static_cast<size_t>(in_sampling_khz_ * block_duration_ms_)), |
223 out_size_samples_(static_cast<size_t>(out_sampling_khz_ * kOutputSizeMs)), | |
224 payload_size_bytes_(0), | 223 payload_size_bytes_(0), |
225 max_payload_bytes_(0), | 224 max_payload_bytes_(0), |
226 in_file_(new ResampleInputAudioFile(FLAGS_in_filename, | 225 in_file_(new ResampleInputAudioFile(FLAGS_in_filename, |
227 FLAGS_input_sample_rate, | 226 FLAGS_input_sample_rate, |
228 in_sampling_khz * 1000)), | 227 in_sampling_khz * 1000)), |
229 rtp_generator_( | 228 rtp_generator_( |
230 new RtpGenerator(in_sampling_khz_, 0, 0, decodable_time_ms_)), | 229 new RtpGenerator(in_sampling_khz_, 0, 0, decodable_time_ms_)), |
231 total_payload_size_bytes_(0) { | 230 total_payload_size_bytes_(0) { |
232 const std::string out_filename = FLAGS_out_filename; | 231 const std::string out_filename = FLAGS_out_filename; |
233 const std::string log_filename = out_filename + ".log"; | 232 const std::string log_filename = out_filename + ".log"; |
234 log_file_.open(log_filename.c_str(), std::ofstream::out); | 233 log_file_.open(log_filename.c_str(), std::ofstream::out); |
235 RTC_CHECK(log_file_.is_open()); | 234 RTC_CHECK(log_file_.is_open()); |
236 | 235 |
237 if (out_filename.size() >= 4 && | 236 if (out_filename.size() >= 4 && |
238 out_filename.substr(out_filename.size() - 4) == ".wav") { | 237 out_filename.substr(out_filename.size() - 4) == ".wav") { |
239 // Open a wav file. | 238 // Open a wav file. |
240 output_.reset( | 239 output_.reset( |
241 new webrtc::test::OutputWavFile(out_filename, 1000 * out_sampling_khz)); | 240 new webrtc::test::OutputWavFile(out_filename, 1000 * out_sampling_khz)); |
242 } else { | 241 } else { |
243 // Open a pcm file. | 242 // Open a pcm file. |
244 output_.reset(new webrtc::test::OutputAudioFile(out_filename)); | 243 output_.reset(new webrtc::test::OutputAudioFile(out_filename)); |
245 } | 244 } |
246 | 245 |
247 NetEq::Config config; | 246 NetEq::Config config; |
248 config.sample_rate_hz = out_sampling_khz_ * 1000; | 247 config.sample_rate_hz = out_sampling_khz_ * 1000; |
249 neteq_.reset(NetEq::Create(config)); | 248 neteq_.reset(NetEq::Create(config)); |
250 max_payload_bytes_ = in_size_samples_ * channels_ * sizeof(int16_t); | 249 max_payload_bytes_ = in_size_samples_ * channels_ * sizeof(int16_t); |
251 in_data_.reset(new int16_t[in_size_samples_ * channels_]); | 250 in_data_.reset(new int16_t[in_size_samples_ * channels_]); |
252 out_data_.reset(new int16_t[out_size_samples_ * channels_]); | |
253 } | 251 } |
254 | 252 |
255 NetEqQualityTest::~NetEqQualityTest() { | 253 NetEqQualityTest::~NetEqQualityTest() { |
256 log_file_.close(); | 254 log_file_.close(); |
257 } | 255 } |
258 | 256 |
259 bool NoLoss::Lost() { | 257 bool NoLoss::Lost() { |
260 return false; | 258 return false; |
261 } | 259 } |
262 | 260 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 Log() << "was sent."; | 384 Log() << "was sent."; |
387 } else { | 385 } else { |
388 Log() << "was lost."; | 386 Log() << "was lost."; |
389 } | 387 } |
390 } | 388 } |
391 Log() << std::endl; | 389 Log() << std::endl; |
392 return packet_input_time_ms; | 390 return packet_input_time_ms; |
393 } | 391 } |
394 | 392 |
395 int NetEqQualityTest::DecodeBlock() { | 393 int NetEqQualityTest::DecodeBlock() { |
396 size_t channels; | 394 int ret = neteq_->GetAudio(&out_frame_, NULL); |
397 size_t samples; | |
398 int ret = neteq_->GetAudio(out_size_samples_ * channels_, &out_data_[0], | |
399 &samples, &channels, NULL); | |
400 | 395 |
401 if (ret != NetEq::kOK) { | 396 if (ret != NetEq::kOK) { |
402 return -1; | 397 return -1; |
403 } else { | 398 } else { |
404 assert(channels == channels_); | 399 RTC_DCHECK_EQ(out_frame_.num_channels_, channels_); |
405 assert(samples == static_cast<size_t>(kOutputSizeMs * out_sampling_khz_)); | 400 RTC_DCHECK_EQ(out_frame_.samples_per_channel_, |
406 RTC_CHECK(output_->WriteArray(out_data_.get(), samples * channels)); | 401 static_cast<size_t>(kOutputSizeMs * out_sampling_khz_)); |
407 return static_cast<int>(samples); | 402 RTC_CHECK(output_->WriteArray( |
| 403 out_frame_.data_, |
| 404 out_frame_.samples_per_channel_ * out_frame_.num_channels_)); |
| 405 return static_cast<int>(out_frame_.samples_per_channel_); |
408 } | 406 } |
409 } | 407 } |
410 | 408 |
411 void NetEqQualityTest::Simulate() { | 409 void NetEqQualityTest::Simulate() { |
412 int audio_size_samples; | 410 int audio_size_samples; |
413 | 411 |
414 while (decoded_time_ms_ < FLAGS_runtime_ms) { | 412 while (decoded_time_ms_ < FLAGS_runtime_ms) { |
415 // Assume 10 packets in packets buffer. | 413 // Assume 10 packets in packets buffer. |
416 while (decodable_time_ms_ - 10 * block_duration_ms_ < decoded_time_ms_) { | 414 while (decodable_time_ms_ - 10 * block_duration_ms_ < decoded_time_ms_) { |
417 ASSERT_TRUE(in_file_->Read(in_size_samples_ * channels_, &in_data_[0])); | 415 ASSERT_TRUE(in_file_->Read(in_size_samples_ * channels_, &in_data_[0])); |
(...skipping 10 matching lines...) Expand all Loading... |
428 } | 426 } |
429 } | 427 } |
430 Log() << "Average bit rate was " | 428 Log() << "Average bit rate was " |
431 << 8.0f * total_payload_size_bytes_ / FLAGS_runtime_ms | 429 << 8.0f * total_payload_size_bytes_ / FLAGS_runtime_ms |
432 << " kbps" | 430 << " kbps" |
433 << std::endl; | 431 << std::endl; |
434 } | 432 } |
435 | 433 |
436 } // namespace test | 434 } // namespace test |
437 } // namespace webrtc | 435 } // namespace webrtc |
OLD | NEW |