| 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 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 webrtc::Trace::ReturnTrace(); | 375 webrtc::Trace::ReturnTrace(); |
| 376 exit(1); | 376 exit(1); |
| 377 } | 377 } |
| 378 } | 378 } |
| 379 return payload_len; | 379 return payload_len; |
| 380 } | 380 } |
| 381 | 381 |
| 382 } // namespace | 382 } // namespace |
| 383 | 383 |
| 384 int main(int argc, char* argv[]) { | 384 int main(int argc, char* argv[]) { |
| 385 static const int kMaxChannels = 5; | |
| 386 static const size_t kMaxSamplesPerMs = 48000 / 1000; | |
| 387 static const int kOutputBlockSizeMs = 10; | 385 static const int kOutputBlockSizeMs = 10; |
| 388 | 386 |
| 389 std::string program_name = argv[0]; | 387 std::string program_name = argv[0]; |
| 390 std::string usage = "Tool for decoding an RTP dump file using NetEq.\n" | 388 std::string usage = "Tool for decoding an RTP dump file using NetEq.\n" |
| 391 "Run " + program_name + " --helpshort for usage.\n" | 389 "Run " + program_name + " --helpshort for usage.\n" |
| 392 "Example usage:\n" + program_name + | 390 "Example usage:\n" + program_name + |
| 393 " input.rtp output.{pcm, wav}\n"; | 391 " input.rtp output.{pcm, wav}\n"; |
| 394 google::SetUsageMessage(usage); | 392 google::SetUsageMessage(usage); |
| 395 google::ParseCommandLineFlags(&argc, &argv, true); | 393 google::ParseCommandLineFlags(&argc, &argv, true); |
| 396 | 394 |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 } else { | 597 } else { |
| 600 // Set next input time to the maximum value of int64_t to prevent the | 598 // Set next input time to the maximum value of int64_t to prevent the |
| 601 // time_now_ms from becoming stuck at the final value. | 599 // time_now_ms from becoming stuck at the final value. |
| 602 next_input_time_ms = std::numeric_limits<int64_t>::max(); | 600 next_input_time_ms = std::numeric_limits<int64_t>::max(); |
| 603 packet_available = false; | 601 packet_available = false; |
| 604 } | 602 } |
| 605 } | 603 } |
| 606 | 604 |
| 607 // Check if it is time to get output audio. | 605 // Check if it is time to get output audio. |
| 608 while (time_now_ms >= next_output_time_ms && output_event_available) { | 606 while (time_now_ms >= next_output_time_ms && output_event_available) { |
| 609 static const size_t kOutDataLen = | 607 webrtc::AudioFrame out_frame; |
| 610 kOutputBlockSizeMs * kMaxSamplesPerMs * kMaxChannels; | 608 int error = neteq->GetAudio(&out_frame, NULL); |
| 611 int16_t out_data[kOutDataLen]; | |
| 612 size_t num_channels; | |
| 613 size_t samples_per_channel; | |
| 614 int error = neteq->GetAudio(kOutDataLen, out_data, &samples_per_channel, | |
| 615 &num_channels, NULL); | |
| 616 if (error != NetEq::kOK) { | 609 if (error != NetEq::kOK) { |
| 617 std::cerr << "GetAudio returned error code " << | 610 std::cerr << "GetAudio returned error code " << |
| 618 neteq->LastError() << std::endl; | 611 neteq->LastError() << std::endl; |
| 619 } else { | 612 } else { |
| 620 // Calculate sample rate from output size. | 613 sample_rate_hz = out_frame.sample_rate_hz_; |
| 621 sample_rate_hz = rtc::checked_cast<int>( | |
| 622 1000 * samples_per_channel / kOutputBlockSizeMs); | |
| 623 } | 614 } |
| 624 | 615 |
| 625 // Write to file. | 616 // Write to file. |
| 626 // TODO(hlundin): Make writing to file optional. | 617 // TODO(hlundin): Make writing to file optional. |
| 627 size_t write_len = samples_per_channel * num_channels; | 618 if (!output->WriteArray(out_frame.data_, out_frame.samples_per_channel_ * |
| 628 if (!output->WriteArray(out_data, write_len)) { | 619 out_frame.num_channels_)) { |
| 629 std::cerr << "Error while writing to file" << std::endl; | 620 std::cerr << "Error while writing to file" << std::endl; |
| 630 webrtc::Trace::ReturnTrace(); | 621 webrtc::Trace::ReturnTrace(); |
| 631 exit(1); | 622 exit(1); |
| 632 } | 623 } |
| 633 if (is_rtp_dump) { | 624 if (is_rtp_dump) { |
| 634 next_output_time_ms += kOutputBlockSizeMs; | 625 next_output_time_ms += kOutputBlockSizeMs; |
| 635 if (!packet_available) | 626 if (!packet_available) |
| 636 output_event_available = false; | 627 output_event_available = false; |
| 637 } else { | 628 } else { |
| 638 next_output_time_ms = event_log_source->NextAudioOutputEventMs(); | 629 next_output_time_ms = event_log_source->NextAudioOutputEventMs(); |
| 639 if (next_output_time_ms == std::numeric_limits<int64_t>::max()) | 630 if (next_output_time_ms == std::numeric_limits<int64_t>::max()) |
| 640 output_event_available = false; | 631 output_event_available = false; |
| 641 } | 632 } |
| 642 } | 633 } |
| 643 } | 634 } |
| 644 printf("Simulation done\n"); | 635 printf("Simulation done\n"); |
| 645 printf("Produced %i ms of audio\n", | 636 printf("Produced %i ms of audio\n", |
| 646 static_cast<int>(time_now_ms - start_time_ms)); | 637 static_cast<int>(time_now_ms - start_time_ms)); |
| 647 | 638 |
| 648 delete neteq; | 639 delete neteq; |
| 649 webrtc::Trace::ReturnTrace(); | 640 webrtc::Trace::ReturnTrace(); |
| 650 return 0; | 641 return 0; |
| 651 } | 642 } |
| OLD | NEW |