Home | History | Annotate | Download | only in filters
      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 
      9 namespace media {
     10 
     11 static const int kBenchmarkIterationsAudio = 200;
     12 static const int kBenchmarkIterationsVideo = 20;
     13 
     14 static 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 
     50 static void RunVideoPlaybackBenchmark(const std::string& filename,
     51                                       const std::string name) {
     52   RunPlaybackBenchmark(filename, name, kBenchmarkIterationsVideo, false);
     53 }
     54 
     55 static void RunAudioPlaybackBenchmark(const std::string& filename,
     56                                       const std::string& name) {
     57   RunPlaybackBenchmark(filename, name, kBenchmarkIterationsAudio, true);
     58 }
     59 
     60 TEST(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 
     70 TEST(PipelineIntegrationPerfTest, VP8PlaybackBenchmark) {
     71   RunVideoPlaybackBenchmark("bear-640x360.webm",
     72                             "clockless_video_playback_vp8");
     73   RunVideoPlaybackBenchmark("bear-320x240.webm",
     74                             "clockless_video_playback_vp8");
     75 }
     76 
     77 TEST(PipelineIntegrationPerfTest, VP9PlaybackBenchmark) {
     78   RunVideoPlaybackBenchmark("bear-vp9.webm", "clockless_video_playback_vp9");
     79 }
     80 
     81 TEST(PipelineIntegrationPerfTest, TheoraPlaybackBenchmark) {
     82   RunVideoPlaybackBenchmark("bear.ogv", "clockless_video_playback_theora");
     83 }
     84 
     85 #if defined(USE_PROPRIETARY_CODECS)
     86 TEST(PipelineIntegrationPerfTest, MP4PlaybackBenchmark) {
     87   RunVideoPlaybackBenchmark("bear-1280x720.mp4",
     88                             "clockless_video_playback_mp4");
     89 }
     90 #endif
     91 
     92 }  // namespace media
     93