Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 assert(*frame_size_samples > 0); | 317 assert(*frame_size_samples > 0); |
| 318 if (!replacement_audio_file->Read(*frame_size_samples, | 318 if (!replacement_audio_file->Read(*frame_size_samples, |
| 319 (*replacement_audio).get())) { | 319 (*replacement_audio).get())) { |
| 320 std::cerr << "Could not read replacement audio file." << std::endl; | 320 std::cerr << "Could not read replacement audio file." << std::endl; |
| 321 webrtc::Trace::ReturnTrace(); | 321 webrtc::Trace::ReturnTrace(); |
| 322 exit(1); | 322 exit(1); |
| 323 } | 323 } |
| 324 // Encode it as PCM16. | 324 // Encode it as PCM16. |
| 325 assert((*payload).get()); | 325 assert((*payload).get()); |
| 326 payload_len = WebRtcPcm16b_Encode((*replacement_audio).get(), | 326 payload_len = WebRtcPcm16b_Encode((*replacement_audio).get(), |
| 327 static_cast<int16_t>(*frame_size_samples), | 327 *frame_size_samples, |
| 328 (*payload).get()); | 328 (*payload).get()); |
| 329 assert(payload_len == 2 * *frame_size_samples); | 329 assert(payload_len == 2 * *frame_size_samples); |
| 330 // Change payload type to PCM16. | 330 // Change payload type to PCM16. |
| 331 switch (CodecSampleRate(rtp_header->header.payloadType)) { | 331 switch (CodecSampleRate(rtp_header->header.payloadType)) { |
| 332 case 8000: | 332 case 8000: |
| 333 rtp_header->header.payloadType = static_cast<uint8_t>(FLAGS_pcm16b); | 333 rtp_header->header.payloadType = static_cast<uint8_t>(FLAGS_pcm16b); |
| 334 break; | 334 break; |
| 335 case 16000: | 335 case 16000: |
| 336 rtp_header->header.payloadType = static_cast<uint8_t>(FLAGS_pcm16b_wb); | 336 rtp_header->header.payloadType = static_cast<uint8_t>(FLAGS_pcm16b_wb); |
| 337 break; | 337 break; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 351 exit(1); | 351 exit(1); |
| 352 } | 352 } |
| 353 } | 353 } |
| 354 return payload_len; | 354 return payload_len; |
| 355 } | 355 } |
| 356 | 356 |
| 357 } // namespace | 357 } // namespace |
| 358 | 358 |
| 359 int main(int argc, char* argv[]) { | 359 int main(int argc, char* argv[]) { |
| 360 static const int kMaxChannels = 5; | 360 static const int kMaxChannels = 5; |
| 361 static const int kMaxSamplesPerMs = 48000 / 1000; | 361 static const size_t kMaxSamplesPerMs = 48000 / 1000; |
| 362 static const int kOutputBlockSizeMs = 10; | 362 static const int kOutputBlockSizeMs = 10; |
| 363 | 363 |
| 364 std::string program_name = argv[0]; | 364 std::string program_name = argv[0]; |
| 365 std::string usage = "Tool for decoding an RTP dump file using NetEq.\n" | 365 std::string usage = "Tool for decoding an RTP dump file using NetEq.\n" |
| 366 "Run " + program_name + " --helpshort for usage.\n" | 366 "Run " + program_name + " --helpshort for usage.\n" |
| 367 "Example usage:\n" + program_name + | 367 "Example usage:\n" + program_name + |
| 368 " input.rtp output.{pcm, wav}\n"; | 368 " input.rtp output.{pcm, wav}\n"; |
| 369 google::SetUsageMessage(usage); | 369 google::SetUsageMessage(usage); |
| 370 google::ParseCommandLineFlags(&argc, &argv, true); | 370 google::ParseCommandLineFlags(&argc, &argv, true); |
| 371 | 371 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 if (packet_available != next_packet_available) { | 545 if (packet_available != next_packet_available) { |
| 546 packet_available = !packet_available; | 546 packet_available = !packet_available; |
| 547 next_packet_available = !next_packet_available; | 547 next_packet_available = !next_packet_available; |
| 548 } | 548 } |
| 549 } | 549 } |
| 550 next_input_time_ms = packet->time_ms(); | 550 next_input_time_ms = packet->time_ms(); |
| 551 } | 551 } |
| 552 | 552 |
| 553 // Check if it is time to get output audio. | 553 // Check if it is time to get output audio. |
| 554 if (time_now_ms >= next_output_time_ms) { | 554 if (time_now_ms >= next_output_time_ms) { |
| 555 static const int kOutDataLen = | 555 static const size_t kOutDataLen = |
| 556 kOutputBlockSizeMs * kMaxSamplesPerMs * kMaxChannels; | 556 kOutputBlockSizeMs * kMaxSamplesPerMs * kMaxChannels; |
| 557 int16_t out_data[kOutDataLen]; | 557 int16_t out_data[kOutDataLen]; |
| 558 int num_channels; | 558 int num_channels; |
| 559 int samples_per_channel; | 559 size_t samples_per_channel; |
| 560 int error = neteq->GetAudio(kOutDataLen, out_data, &samples_per_channel, | 560 int error = neteq->GetAudio(kOutDataLen, out_data, &samples_per_channel, |
| 561 &num_channels, NULL); | 561 &num_channels, NULL); |
| 562 if (error != NetEq::kOK) { | 562 if (error != NetEq::kOK) { |
| 563 std::cerr << "GetAudio returned error code " << | 563 std::cerr << "GetAudio returned error code " << |
| 564 neteq->LastError() << std::endl; | 564 neteq->LastError() << std::endl; |
| 565 } else { | 565 } else { |
| 566 // Calculate sample rate from output size. | 566 // Calculate sample rate from output size. |
| 567 sample_rate_hz = 1000 * samples_per_channel / kOutputBlockSizeMs; | 567 sample_rate_hz = |
| 568 static_cast<int>(1000 * samples_per_channel / kOutputBlockSizeMs); | |
|
hlundin-webrtc
2015/08/10 11:30:02
rtc::checked_cast
Peter Kasting
2015/08/17 22:49:47
Done.
| |
| 568 } | 569 } |
| 569 | 570 |
| 570 // Write to file. | 571 // Write to file. |
| 571 // TODO(hlundin): Make writing to file optional. | 572 // TODO(hlundin): Make writing to file optional. |
| 572 size_t write_len = samples_per_channel * num_channels; | 573 size_t write_len = samples_per_channel * num_channels; |
| 573 if (!output->WriteArray(out_data, write_len)) { | 574 if (!output->WriteArray(out_data, write_len)) { |
| 574 std::cerr << "Error while writing to file" << std::endl; | 575 std::cerr << "Error while writing to file" << std::endl; |
| 575 webrtc::Trace::ReturnTrace(); | 576 webrtc::Trace::ReturnTrace(); |
| 576 exit(1); | 577 exit(1); |
| 577 } | 578 } |
| 578 next_output_time_ms += kOutputBlockSizeMs; | 579 next_output_time_ms += kOutputBlockSizeMs; |
| 579 } | 580 } |
| 580 // Advance time to next event. | 581 // Advance time to next event. |
| 581 time_now_ms = std::min(next_input_time_ms, next_output_time_ms); | 582 time_now_ms = std::min(next_input_time_ms, next_output_time_ms); |
| 582 } | 583 } |
| 583 | 584 |
| 584 printf("Simulation done\n"); | 585 printf("Simulation done\n"); |
| 585 printf("Produced %i ms of audio\n", time_now_ms - start_time_ms); | 586 printf("Produced %i ms of audio\n", time_now_ms - start_time_ms); |
| 586 | 587 |
| 587 delete neteq; | 588 delete neteq; |
| 588 webrtc::Trace::ReturnTrace(); | 589 webrtc::Trace::ReturnTrace(); |
| 589 return 0; | 590 return 0; |
| 590 } | 591 } |
| OLD | NEW |