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 payload_.reset(new uint8_t[max_payload_bytes_]); | 251 payload_.reset(new uint8_t[max_payload_bytes_]); |
253 out_data_.reset(new int16_t[out_size_samples_ * channels_]); | |
254 } | 252 } |
255 | 253 |
256 NetEqQualityTest::~NetEqQualityTest() { | 254 NetEqQualityTest::~NetEqQualityTest() { |
257 log_file_.close(); | 255 log_file_.close(); |
258 } | 256 } |
259 | 257 |
260 bool NoLoss::Lost() { | 258 bool NoLoss::Lost() { |
261 return false; | 259 return false; |
262 } | 260 } |
263 | 261 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 Log() << "was sent."; | 385 Log() << "was sent."; |
388 } else { | 386 } else { |
389 Log() << "was lost."; | 387 Log() << "was lost."; |
390 } | 388 } |
391 } | 389 } |
392 Log() << std::endl; | 390 Log() << std::endl; |
393 return packet_input_time_ms; | 391 return packet_input_time_ms; |
394 } | 392 } |
395 | 393 |
396 int NetEqQualityTest::DecodeBlock() { | 394 int NetEqQualityTest::DecodeBlock() { |
397 size_t channels; | 395 int ret = neteq_->GetAudio(&out_frame_, NULL); |
398 size_t samples; | |
399 int ret = neteq_->GetAudio(out_size_samples_ * channels_, &out_data_[0], | |
400 &samples, &channels, NULL); | |
401 | 396 |
402 if (ret != NetEq::kOK) { | 397 if (ret != NetEq::kOK) { |
403 return -1; | 398 return -1; |
404 } else { | 399 } else { |
405 assert(channels == channels_); | 400 RTC_DCHECK_EQ(out_frame_.num_channels_, channels_); |
406 assert(samples == static_cast<size_t>(kOutputSizeMs * out_sampling_khz_)); | 401 RTC_DCHECK_EQ(out_frame_.samples_per_channel_, |
407 RTC_CHECK(output_->WriteArray(out_data_.get(), samples * channels)); | 402 static_cast<size_t>(kOutputSizeMs * out_sampling_khz_)); |
408 return static_cast<int>(samples); | 403 RTC_CHECK(output_->WriteArray( |
| 404 out_frame_.data_, |
| 405 out_frame_.samples_per_channel_ * out_frame_.num_channels_)); |
| 406 return static_cast<int>(out_frame_.samples_per_channel_); |
409 } | 407 } |
410 } | 408 } |
411 | 409 |
412 void NetEqQualityTest::Simulate() { | 410 void NetEqQualityTest::Simulate() { |
413 int audio_size_samples; | 411 int audio_size_samples; |
414 | 412 |
415 while (decoded_time_ms_ < FLAGS_runtime_ms) { | 413 while (decoded_time_ms_ < FLAGS_runtime_ms) { |
416 // Assume 10 packets in packets buffer. | 414 // Assume 10 packets in packets buffer. |
417 while (decodable_time_ms_ - 10 * block_duration_ms_ < decoded_time_ms_) { | 415 while (decodable_time_ms_ - 10 * block_duration_ms_ < decoded_time_ms_) { |
418 ASSERT_TRUE(in_file_->Read(in_size_samples_ * channels_, &in_data_[0])); | 416 ASSERT_TRUE(in_file_->Read(in_size_samples_ * channels_, &in_data_[0])); |
419 payload_size_bytes_ = EncodeBlock(&in_data_[0], | 417 payload_size_bytes_ = EncodeBlock(&in_data_[0], |
420 in_size_samples_, &payload_[0], | 418 in_size_samples_, &payload_[0], |
421 max_payload_bytes_); | 419 max_payload_bytes_); |
422 total_payload_size_bytes_ += payload_size_bytes_; | 420 total_payload_size_bytes_ += payload_size_bytes_; |
423 decodable_time_ms_ = Transmit() + block_duration_ms_; | 421 decodable_time_ms_ = Transmit() + block_duration_ms_; |
424 } | 422 } |
425 audio_size_samples = DecodeBlock(); | 423 audio_size_samples = DecodeBlock(); |
426 if (audio_size_samples > 0) { | 424 if (audio_size_samples > 0) { |
427 decoded_time_ms_ += audio_size_samples / out_sampling_khz_; | 425 decoded_time_ms_ += audio_size_samples / out_sampling_khz_; |
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 |