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

Side by Side Diff: webrtc/modules/audio_processing/test/process_test.cc

Issue 1888593004: Delete all use of tick_util.h. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 8 months 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 <math.h> 11 #include <math.h>
12 #include <stdio.h> 12 #include <stdio.h>
13 #include <string.h> 13 #include <string.h>
14 #ifdef WEBRTC_ANDROID 14 #ifdef WEBRTC_ANDROID
15 #include <sys/stat.h> 15 #include <sys/stat.h>
16 #endif 16 #endif
17 17
18 #include <algorithm> 18 #include <algorithm>
19 #include <memory> 19 #include <memory>
20 20
21 #include "webrtc/base/format_macros.h" 21 #include "webrtc/base/format_macros.h"
22 #include "webrtc/base/timeutils.h"
22 #include "webrtc/common.h" 23 #include "webrtc/common.h"
23 #include "webrtc/modules/audio_processing/include/audio_processing.h" 24 #include "webrtc/modules/audio_processing/include/audio_processing.h"
24 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" 25 #include "webrtc/modules/audio_processing/test/protobuf_utils.h"
25 #include "webrtc/modules/audio_processing/test/test_utils.h" 26 #include "webrtc/modules/audio_processing/test/test_utils.h"
26 #include "webrtc/modules/include/module_common_types.h" 27 #include "webrtc/modules/include/module_common_types.h"
27 #include "webrtc/system_wrappers/include/cpu_features_wrapper.h" 28 #include "webrtc/system_wrappers/include/cpu_features_wrapper.h"
28 #include "webrtc/system_wrappers/include/tick_util.h"
29 #include "webrtc/test/testsupport/fileutils.h" 29 #include "webrtc/test/testsupport/fileutils.h"
30 #include "webrtc/test/testsupport/perf_test.h" 30 #include "webrtc/test/testsupport/perf_test.h"
31 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD 31 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD
32 #include "gtest/gtest.h" 32 #include "gtest/gtest.h"
33 #include "external/webrtc/webrtc/modules/audio_processing/debug.pb.h" 33 #include "external/webrtc/webrtc/modules/audio_processing/debug.pb.h"
34 #else 34 #else
35 #include "testing/gtest/include/gtest/gtest.h" 35 #include "testing/gtest/include/gtest/gtest.h"
36 #include "webrtc/modules/audio_processing/debug.pb.h" 36 #include "webrtc/modules/audio_processing/debug.pb.h"
37 #endif 37 #endif
38 38
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 } 551 }
552 552
553 if (aecm_echo_path_out_filename != NULL) { 553 if (aecm_echo_path_out_filename != NULL) {
554 aecm_echo_path_out_file = OpenFile(aecm_echo_path_out_filename, "wb"); 554 aecm_echo_path_out_file = OpenFile(aecm_echo_path_out_filename, "wb");
555 } 555 }
556 556
557 size_t read_count = 0; 557 size_t read_count = 0;
558 int reverse_count = 0; 558 int reverse_count = 0;
559 int primary_count = 0; 559 int primary_count = 0;
560 int near_read_bytes = 0; 560 int near_read_bytes = 0;
561 TickInterval acc_ticks; 561 int64_t acc_ticks = 0;
562 562
563 AudioFrame far_frame; 563 AudioFrame far_frame;
564 AudioFrame near_frame; 564 AudioFrame near_frame;
565 565
566 int delay_ms = 0; 566 int delay_ms = 0;
567 int drift_samples = 0; 567 int drift_samples = 0;
568 int capture_level = 127; 568 int capture_level = 127;
569 int8_t stream_has_voice = 0; 569 int8_t stream_has_voice = 0;
570 float ns_speech_prob = 0.0f; 570 float ns_speech_prob = 0.0f;
571 571
572 TickTime t0 = TickTime::Now(); 572 int64_t t0 = rtc::TimeNanos();
573 TickTime t1 = t0; 573 int64_t t1 = t0;
574 int64_t max_time_us = 0; 574 int64_t max_time_us = 0;
575 int64_t max_time_reverse_us = 0; 575 int64_t max_time_reverse_us = 0;
576 int64_t min_time_us = 1e6; 576 int64_t min_time_us = 1e6;
577 int64_t min_time_reverse_us = 1e6; 577 int64_t min_time_reverse_us = 1e6;
578 578
579 // TODO(ajm): Ideally we would refactor this block into separate functions, 579 // TODO(ajm): Ideally we would refactor this block into separate functions,
580 // but for now we want to share the variables. 580 // but for now we want to share the variables.
581 if (pb_file) { 581 if (pb_file) {
582 Event event_msg; 582 Event event_msg;
583 std::unique_ptr<ChannelBuffer<float> > reverse_cb; 583 std::unique_ptr<ChannelBuffer<float> > reverse_cb;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 } else { 665 } else {
666 for (int i = 0; i < msg.channel_size(); ++i) { 666 for (int i = 0; i < msg.channel_size(); ++i) {
667 memcpy(reverse_cb->channels()[i], 667 memcpy(reverse_cb->channels()[i],
668 msg.channel(i).data(), 668 msg.channel(i).data(),
669 reverse_cb->num_frames() * 669 reverse_cb->num_frames() *
670 sizeof(reverse_cb->channels()[i][0])); 670 sizeof(reverse_cb->channels()[i][0]));
671 } 671 }
672 } 672 }
673 673
674 if (perf_testing) { 674 if (perf_testing) {
675 t0 = TickTime::Now(); 675 t0 = rtc::TimeNanos();
676 } 676 }
677 677
678 if (msg.has_data()) { 678 if (msg.has_data()) {
679 ASSERT_EQ(apm->kNoError, 679 ASSERT_EQ(apm->kNoError,
680 apm->ProcessReverseStream(&far_frame)); 680 apm->ProcessReverseStream(&far_frame));
681 } else { 681 } else {
682 ASSERT_EQ(apm->kNoError, 682 ASSERT_EQ(apm->kNoError,
683 apm->AnalyzeReverseStream( 683 apm->AnalyzeReverseStream(
684 reverse_cb->channels(), 684 reverse_cb->channels(),
685 far_frame.samples_per_channel_, 685 far_frame.samples_per_channel_,
686 far_frame.sample_rate_hz_, 686 far_frame.sample_rate_hz_,
687 LayoutFromChannels(far_frame.num_channels_))); 687 LayoutFromChannels(far_frame.num_channels_)));
688 } 688 }
689 689
690 if (perf_testing) { 690 if (perf_testing) {
691 t1 = TickTime::Now(); 691 t1 = rtc::TimeNanos();
692 TickInterval tick_diff = t1 - t0; 692 int64_t tick_diff = t1 - t0;
stefan-webrtc 2016/04/19 09:19:12 tick_diff is a bad variable name now.
nisse-webrtc 2016/04/19 12:19:25 Renaming tick_diff --> diff_nanos and acc_ticks --
693 acc_ticks += tick_diff; 693 acc_ticks += tick_diff;
694 if (tick_diff.Microseconds() > max_time_reverse_us) { 694 int64_t diff_us = tick_diff / rtc::kNumNanosecsPerMicrosec;
695 max_time_reverse_us = tick_diff.Microseconds(); 695 if (diff_us > max_time_reverse_us) {
696 max_time_reverse_us = diff_us;
696 } 697 }
697 if (tick_diff.Microseconds() < min_time_reverse_us) { 698 if (diff_us < min_time_reverse_us) {
698 min_time_reverse_us = tick_diff.Microseconds(); 699 min_time_reverse_us = diff_us;
699 } 700 }
700 } 701 }
701 702
702 } else if (event_msg.type() == Event::STREAM) { 703 } else if (event_msg.type() == Event::STREAM) {
703 ASSERT_TRUE(event_msg.has_stream()); 704 ASSERT_TRUE(event_msg.has_stream());
704 const Stream msg = event_msg.stream(); 705 const Stream msg = event_msg.stream();
705 primary_count++; 706 primary_count++;
706 707
707 // ProcessStream could have changed this for the output frame. 708 // ProcessStream could have changed this for the output frame.
708 near_frame.num_channels_ = apm->num_input_channels(); 709 near_frame.num_channels_ = apm->num_input_channels();
(...skipping 17 matching lines...) Expand all
726 } 727 }
727 728
728 if (progress && primary_count % 100 == 0) { 729 if (progress && primary_count % 100 == 0) {
729 near_read_bytes = std::min(near_read_bytes, near_size_bytes); 730 near_read_bytes = std::min(near_read_bytes, near_size_bytes);
730 printf("%.0f%% complete\r", 731 printf("%.0f%% complete\r",
731 (near_read_bytes * 100.0) / near_size_bytes); 732 (near_read_bytes * 100.0) / near_size_bytes);
732 fflush(stdout); 733 fflush(stdout);
733 } 734 }
734 735
735 if (perf_testing) { 736 if (perf_testing) {
736 t0 = TickTime::Now(); 737 t0 = rtc::TimeNanos();
737 } 738 }
738 739
739 ASSERT_EQ(apm->kNoError, 740 ASSERT_EQ(apm->kNoError,
740 apm->gain_control()->set_stream_analog_level(msg.level())); 741 apm->gain_control()->set_stream_analog_level(msg.level()));
741 delay_ms = msg.delay() + extra_delay_ms; 742 delay_ms = msg.delay() + extra_delay_ms;
742 if (override_delay_ms) { 743 if (override_delay_ms) {
743 delay_ms = override_delay_ms; 744 delay_ms = override_delay_ms;
744 } 745 }
745 ASSERT_EQ(apm->kNoError, 746 ASSERT_EQ(apm->kNoError,
746 apm->set_stream_delay_ms(delay_ms)); 747 apm->set_stream_delay_ms(delay_ms));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 785
785 if (ns_prob_file != NULL) { 786 if (ns_prob_file != NULL) {
786 ns_speech_prob = apm->noise_suppression()->speech_probability(); 787 ns_speech_prob = apm->noise_suppression()->speech_probability();
787 ASSERT_EQ(1u, fwrite(&ns_speech_prob, 788 ASSERT_EQ(1u, fwrite(&ns_speech_prob,
788 sizeof(ns_speech_prob), 789 sizeof(ns_speech_prob),
789 1, 790 1,
790 ns_prob_file)); 791 ns_prob_file));
791 } 792 }
792 793
793 if (perf_testing) { 794 if (perf_testing) {
794 t1 = TickTime::Now(); 795 t1 = rtc::TimeNanos();
795 TickInterval tick_diff = t1 - t0; 796 int64_t tick_diff = t1 - t0;
stefan-webrtc 2016/04/19 09:19:12 diff_nanos? Same below
796 acc_ticks += tick_diff; 797 acc_ticks += tick_diff;
797 if (tick_diff.Microseconds() > max_time_us) { 798 int64_t diff_us = tick_diff / rtc::kNumNanosecsPerMicrosec;
798 max_time_us = tick_diff.Microseconds(); 799 if (diff_us > max_time_us) {
800 max_time_us = diff_us;
799 } 801 }
800 if (tick_diff.Microseconds() < min_time_us) { 802 if (diff_us < min_time_us) {
801 min_time_us = tick_diff.Microseconds(); 803 min_time_us = diff_us;
802 } 804 }
803 } 805 }
804 806
805 const size_t samples_per_channel = output_sample_rate / 100; 807 const size_t samples_per_channel = output_sample_rate / 100;
806 if (msg.has_input_data()) { 808 if (msg.has_input_data()) {
807 if (raw_output && !output_raw_file) { 809 if (raw_output && !output_raw_file) {
808 output_raw_file.reset(new RawFile(out_filename + ".pcm")); 810 output_raw_file.reset(new RawFile(out_filename + ".pcm"));
809 } 811 }
810 WriteIntData(near_frame.data_, 812 WriteIntData(near_frame.data_,
811 apm->num_output_channels() * samples_per_channel, 813 apm->num_output_channels() * samples_per_channel,
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 // not reaching end-of-file. 916 // not reaching end-of-file.
915 EXPECT_EQ(0, fseek(near_file, read_count * sizeof(int16_t), 917 EXPECT_EQ(0, fseek(near_file, read_count * sizeof(int16_t),
916 SEEK_CUR)); 918 SEEK_CUR));
917 break; // This is expected. 919 break; // This is expected.
918 } 920 }
919 } else { 921 } else {
920 ASSERT_EQ(size, read_count); 922 ASSERT_EQ(size, read_count);
921 } 923 }
922 924
923 if (perf_testing) { 925 if (perf_testing) {
924 t0 = TickTime::Now(); 926 t0 = rtc::TimeNanos();
925 } 927 }
926 928
927 ASSERT_EQ(apm->kNoError, 929 ASSERT_EQ(apm->kNoError,
928 apm->ProcessReverseStream(&far_frame)); 930 apm->ProcessReverseStream(&far_frame));
929 931
930 if (perf_testing) { 932 if (perf_testing) {
931 t1 = TickTime::Now(); 933 t1 = rtc::TimeNanos();
932 TickInterval tick_diff = t1 - t0; 934 int64_t tick_diff = t1 - t0;
933 acc_ticks += tick_diff; 935 acc_ticks += tick_diff;
934 if (tick_diff.Microseconds() > max_time_reverse_us) { 936 int64_t diff_us = tick_diff / rtc::kNumNanosecsPerMicrosec;
935 max_time_reverse_us = tick_diff.Microseconds(); 937 if (diff_us > max_time_reverse_us) {
938 max_time_reverse_us = diff_us;
936 } 939 }
937 if (tick_diff.Microseconds() < min_time_reverse_us) { 940 if (diff_us < min_time_reverse_us) {
938 min_time_reverse_us = tick_diff.Microseconds(); 941 min_time_reverse_us = diff_us;
939 } 942 }
940 } 943 }
941 944
942 } else if (event == kCaptureEvent) { 945 } else if (event == kCaptureEvent) {
943 primary_count++; 946 primary_count++;
944 near_frame.num_channels_ = num_capture_input_channels; 947 near_frame.num_channels_ = num_capture_input_channels;
945 948
946 size_t size = samples_per_channel * num_capture_input_channels; 949 size_t size = samples_per_channel * num_capture_input_channels;
947 read_count = fread(near_frame.data_, 950 read_count = fread(near_frame.data_,
948 sizeof(int16_t), 951 sizeof(int16_t),
(...skipping 22 matching lines...) Expand all
971 ASSERT_EQ(1u, 974 ASSERT_EQ(1u,
972 fread(&drift_samples, sizeof(drift_samples), 1, drift_file)); 975 fread(&drift_samples, sizeof(drift_samples), 1, drift_file));
973 } 976 }
974 977
975 if (apm->gain_control()->is_enabled() && 978 if (apm->gain_control()->is_enabled() &&
976 apm->gain_control()->mode() == GainControl::kAdaptiveAnalog) { 979 apm->gain_control()->mode() == GainControl::kAdaptiveAnalog) {
977 SimulateMic(capture_level, &near_frame); 980 SimulateMic(capture_level, &near_frame);
978 } 981 }
979 982
980 if (perf_testing) { 983 if (perf_testing) {
981 t0 = TickTime::Now(); 984 t0 = rtc::TimeNanos();
982 } 985 }
983 986
984 const int capture_level_in = capture_level; 987 const int capture_level_in = capture_level;
985 ASSERT_EQ(apm->kNoError, 988 ASSERT_EQ(apm->kNoError,
986 apm->gain_control()->set_stream_analog_level(capture_level)); 989 apm->gain_control()->set_stream_analog_level(capture_level));
987 delay_ms += extra_delay_ms; 990 delay_ms += extra_delay_ms;
988 if (override_delay_ms) { 991 if (override_delay_ms) {
989 delay_ms = override_delay_ms; 992 delay_ms = override_delay_ms;
990 } 993 }
991 ASSERT_EQ(apm->kNoError, 994 ASSERT_EQ(apm->kNoError,
(...skipping 27 matching lines...) Expand all
1019 sizeof(ns_speech_prob), 1022 sizeof(ns_speech_prob),
1020 1, 1023 1,
1021 ns_prob_file)); 1024 ns_prob_file));
1022 } 1025 }
1023 1026
1024 if (apm->gain_control()->mode() != GainControl::kAdaptiveAnalog) { 1027 if (apm->gain_control()->mode() != GainControl::kAdaptiveAnalog) {
1025 ASSERT_EQ(capture_level_in, capture_level); 1028 ASSERT_EQ(capture_level_in, capture_level);
1026 } 1029 }
1027 1030
1028 if (perf_testing) { 1031 if (perf_testing) {
1029 t1 = TickTime::Now(); 1032 t1 = rtc::TimeNanos();
1030 TickInterval tick_diff = t1 - t0; 1033 int64_t tick_diff = t1 - t0;
1031 acc_ticks += tick_diff; 1034 acc_ticks += tick_diff;
1032 if (tick_diff.Microseconds() > max_time_us) { 1035 int64_t diff_us = tick_diff / rtc::kNumNanosecsPerMicrosec;
1033 max_time_us = tick_diff.Microseconds(); 1036 if (diff_us > max_time_us) {
1037 max_time_us = diff_us;
1034 } 1038 }
1035 if (tick_diff.Microseconds() < min_time_us) { 1039 if (diff_us < min_time_us) {
1036 min_time_us = tick_diff.Microseconds(); 1040 min_time_us = diff_us;
1037 } 1041 }
1038 } 1042 }
1039 1043
1040 if (raw_output && !output_raw_file) { 1044 if (raw_output && !output_raw_file) {
1041 output_raw_file.reset(new RawFile(out_filename + ".pcm")); 1045 output_raw_file.reset(new RawFile(out_filename + ".pcm"));
1042 } 1046 }
1043 if (!raw_output && !output_wav_file) { 1047 if (!raw_output && !output_wav_file) {
1044 output_wav_file.reset(new WavWriter(out_filename + ".wav", 1048 output_wav_file.reset(new WavWriter(out_filename + ".wav",
1045 sample_rate_hz, 1049 sample_rate_hz,
1046 num_capture_output_channels)); 1050 num_capture_output_channels));
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 EXPECT_NE(0, feof(event_file)) << "Event file not fully processed"; 1123 EXPECT_NE(0, feof(event_file)) << "Event file not fully processed";
1120 read_count = fread(&temp_int8, sizeof(temp_int8), 1, delay_file); 1124 read_count = fread(&temp_int8, sizeof(temp_int8), 1, delay_file);
1121 EXPECT_NE(0, feof(delay_file)) << "Delay file not fully processed"; 1125 EXPECT_NE(0, feof(delay_file)) << "Delay file not fully processed";
1122 read_count = fread(&temp_int8, sizeof(temp_int8), 1, drift_file); 1126 read_count = fread(&temp_int8, sizeof(temp_int8), 1, drift_file);
1123 EXPECT_NE(0, feof(drift_file)) << "Drift file not fully processed"; 1127 EXPECT_NE(0, feof(drift_file)) << "Drift file not fully processed";
1124 } 1128 }
1125 } 1129 }
1126 1130
1127 if (perf_testing) { 1131 if (perf_testing) {
1128 if (primary_count > 0) { 1132 if (primary_count > 0) {
1129 int64_t exec_time = acc_ticks.Milliseconds(); 1133 int64_t exec_time = acc_ticks / rtc::kNumNanosecsPerMillisec;
1130 printf("\nTotal time: %.3f s, file time: %.2f s\n", 1134 printf("\nTotal time: %.3f s, file time: %.2f s\n",
1131 exec_time * 0.001, primary_count * 0.01); 1135 exec_time * 0.001, primary_count * 0.01);
1132 printf("Time per frame: %.3f ms (average), %.3f ms (max)," 1136 printf("Time per frame: %.3f ms (average), %.3f ms (max),"
1133 " %.3f ms (min)\n", 1137 " %.3f ms (min)\n",
1134 (exec_time * 1.0) / primary_count, 1138 (exec_time * 1.0) / primary_count,
1135 (max_time_us + max_time_reverse_us) / 1000.0, 1139 (max_time_us + max_time_reverse_us) / 1000.0,
1136 (min_time_us + min_time_reverse_us) / 1000.0); 1140 (min_time_us + min_time_reverse_us) / 1000.0);
1137 // Record the results with Perf test tools. 1141 // Record the results with Perf test tools.
1138 webrtc::test::PrintResult("audioproc", "", "time_per_10ms_frame", 1142 webrtc::test::PrintResult("audioproc", "", "time_per_10ms_frame",
1139 (exec_time * 1000) / primary_count, "us", false); 1143 (exec_time * 1000) / primary_count, "us", false);
1140 } else { 1144 } else {
1141 printf("Warning: no capture frames\n"); 1145 printf("Warning: no capture frames\n");
1142 } 1146 }
1143 } 1147 }
1144 } 1148 }
1145 1149
1146 } // namespace 1150 } // namespace
1147 } // namespace webrtc 1151 } // namespace webrtc
1148 1152
1149 int main(int argc, char* argv[]) { 1153 int main(int argc, char* argv[]) {
1150 webrtc::void_main(argc, argv); 1154 webrtc::void_main(argc, argv);
1151 1155
1152 // Optional, but removes memory leak noise from Valgrind. 1156 // Optional, but removes memory leak noise from Valgrind.
1153 google::protobuf::ShutdownProtobufLibrary(); 1157 google::protobuf::ShutdownProtobufLibrary();
1154 return 0; 1158 return 0;
1155 } 1159 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698