Delete unused downloads page asset.
[chromium-blink-merge.git] / media / base / audio_converter_perftest.cc
blob92bff2913084b427ae96987cf0f5a4bb0cf1e591
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/time/time.h"
6 #include "media/base/audio_converter.h"
7 #include "media/base/fake_audio_render_callback.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "testing/perf/perf_test.h"
11 namespace media {
13 static const int kBenchmarkIterations = 200000;
15 // InputCallback that zero's out the provided AudioBus.
16 class NullInputProvider : public AudioConverter::InputCallback {
17 public:
18 NullInputProvider() {}
19 ~NullInputProvider() override {}
21 double ProvideInput(AudioBus* audio_bus,
22 base::TimeDelta buffer_delay) override {
23 audio_bus->Zero();
24 return 1;
28 void RunConvertBenchmark(const AudioParameters& in_params,
29 const AudioParameters& out_params,
30 bool fifo,
31 const std::string& trace_name) {
32 NullInputProvider fake_input1;
33 NullInputProvider fake_input2;
34 NullInputProvider fake_input3;
35 scoped_ptr<AudioBus> output_bus = AudioBus::Create(out_params);
37 AudioConverter converter(in_params, out_params, !fifo);
38 converter.AddInput(&fake_input1);
39 converter.AddInput(&fake_input2);
40 converter.AddInput(&fake_input3);
42 base::TimeTicks start = base::TimeTicks::Now();
43 for (int i = 0; i < kBenchmarkIterations; ++i) {
44 converter.Convert(output_bus.get());
46 double runs_per_second = kBenchmarkIterations /
47 (base::TimeTicks::Now() - start).InSecondsF();
48 perf_test::PrintResult(
49 "audio_converter", "", trace_name, runs_per_second, "runs/s", true);
52 TEST(AudioConverterPerfTest, ConvertBenchmark) {
53 // Create input and output parameters to convert between the two most common
54 // sets of parameters (as indicated via UMA data).
55 AudioParameters input_params(
56 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, 48000, 16, 2048);
57 AudioParameters output_params(
58 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, 44100, 16, 440);
60 RunConvertBenchmark(input_params, output_params, false, "convert");
63 TEST(AudioConverterPerfTest, ConvertBenchmarkFIFO) {
64 // Create input and output parameters to convert between common buffer sizes
65 // without any resampling for the FIFO vs no FIFO benchmarks.
66 AudioParameters input_params(AudioParameters::AUDIO_PCM_LINEAR,
67 CHANNEL_LAYOUT_STEREO,
68 44100,
69 16,
70 2048);
71 AudioParameters output_params(
72 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, 44100, 16, 440);
74 RunConvertBenchmark(input_params, output_params, true, "convert_fifo_only");
75 RunConvertBenchmark(input_params, output_params, false,
76 "convert_pass_through");
79 } // namespace media