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.
4
5#include "media/base/test_data_util.h"
6#include "media/filters/pipeline_integration_test_base.h"
7#include "testing/perf/perf_test.h"
8
9namespace media {
10
11static const int kBenchmarkIterationsAudio = 200;
12static const int kBenchmarkIterationsVideo = 20;
13
14static void RunPlaybackBenchmark(const std::string& filename,
15                                 const std::string& name,
16                                 int iterations,
17                                 bool audio_only) {
18  double time_seconds = 0.0;
19
20  for (int i = 0; i < iterations; ++i) {
21    PipelineIntegrationTestBase pipeline;
22
23    ASSERT_TRUE(pipeline.Start(GetTestDataFilePath(filename),
24                               PIPELINE_OK,
25                               PipelineIntegrationTestBase::kClockless));
26
27    base::TimeTicks start = base::TimeTicks::HighResNow();
28    pipeline.Play();
29
30    ASSERT_TRUE(pipeline.WaitUntilOnEnded());
31
32    // Call Stop() to ensure that the rendering is complete.
33    pipeline.Stop();
34
35    if (audio_only) {
36      time_seconds += pipeline.GetAudioTime().InSecondsF();
37    } else {
38      time_seconds += (base::TimeTicks::HighResNow() - start).InSecondsF();
39    }
40  }
41
42  perf_test::PrintResult(name,
43                         "",
44                         filename,
45                         iterations / time_seconds,
46                         "runs/s",
47                         true);
48}
49
50static void RunVideoPlaybackBenchmark(const std::string& filename,
51                                      const std::string name) {
52  RunPlaybackBenchmark(filename, name, kBenchmarkIterationsVideo, false);
53}
54
55static void RunAudioPlaybackBenchmark(const std::string& filename,
56                                      const std::string& name) {
57  RunPlaybackBenchmark(filename, name, kBenchmarkIterationsAudio, true);
58}
59
60TEST(PipelineIntegrationPerfTest, AudioPlaybackBenchmark) {
61  RunAudioPlaybackBenchmark("sfx_f32le.wav", "clockless_playback");
62  RunAudioPlaybackBenchmark("sfx_s24le.wav", "clockless_playback");
63  RunAudioPlaybackBenchmark("sfx_s16le.wav", "clockless_playback");
64  RunAudioPlaybackBenchmark("sfx_u8.wav", "clockless_playback");
65#if defined(USE_PROPRIETARY_CODECS)
66  RunAudioPlaybackBenchmark("sfx.mp3", "clockless_playback");
67#endif
68}
69
70TEST(PipelineIntegrationPerfTest, VP8PlaybackBenchmark) {
71  RunVideoPlaybackBenchmark("bear_silent.webm", "clockless_video_playback_vp8");
72}
73
74TEST(PipelineIntegrationPerfTest, VP9PlaybackBenchmark) {
75  RunVideoPlaybackBenchmark("bear-vp9.webm", "clockless_video_playback_vp9");
76}
77
78TEST(PipelineIntegrationPerfTest, TheoraPlaybackBenchmark) {
79  RunVideoPlaybackBenchmark("bear_silent.ogv",
80                            "clockless_video_playback_theora");
81}
82
83#if defined(USE_PROPRIETARY_CODECS)
84TEST(PipelineIntegrationPerfTest, MP4PlaybackBenchmark) {
85  RunVideoPlaybackBenchmark("bear_silent.mp4", "clockless_video_playback_mp4");
86}
87#endif
88
89}  // namespace media
90