pipeline_integration_perftest.cc 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #include "media/base/test_data_util.h"
  5. #include "media/media_buildflags.h"
  6. #include "media/test/pipeline_integration_test_base.h"
  7. #include "testing/perf/perf_result_reporter.h"
  8. namespace media {
  9. static const int kBenchmarkIterationsAudio = 200;
  10. static const int kBenchmarkIterationsVideo = 20;
  11. static void RunPlaybackBenchmark(const std::string& filename,
  12. const std::string& metric_suffix,
  13. int iterations,
  14. bool audio_only) {
  15. double time_seconds = 0.0;
  16. for (int i = 0; i < iterations; ++i) {
  17. PipelineIntegrationTestBase pipeline;
  18. ASSERT_EQ(PIPELINE_OK, pipeline.Start(filename));
  19. base::TimeTicks start = base::TimeTicks::Now();
  20. pipeline.Play();
  21. ASSERT_TRUE(pipeline.WaitUntilOnEnded());
  22. // Call Stop() to ensure that the rendering is complete.
  23. pipeline.Stop();
  24. if (audio_only) {
  25. time_seconds += pipeline.GetAudioTime().InSecondsF();
  26. } else {
  27. time_seconds += (base::TimeTicks::Now() - start).InSecondsF();
  28. }
  29. }
  30. perf_test::PerfResultReporter reporter("clockless_video_playback", filename);
  31. reporter.RegisterImportantMetric(metric_suffix, "runs/s");
  32. reporter.AddResult(metric_suffix, iterations / time_seconds);
  33. }
  34. static void RunVideoPlaybackBenchmark(const std::string& filename,
  35. const std::string name) {
  36. RunPlaybackBenchmark(filename, name, kBenchmarkIterationsVideo, false);
  37. }
  38. static void RunAudioPlaybackBenchmark(const std::string& filename,
  39. const std::string& name) {
  40. RunPlaybackBenchmark(filename, name, kBenchmarkIterationsAudio, true);
  41. }
  42. class ClocklessAudioPipelineIntegrationPerfTest
  43. : public testing::TestWithParam<const char*> {};
  44. TEST_P(ClocklessAudioPipelineIntegrationPerfTest, PlaybackBenchmark) {
  45. RunAudioPlaybackBenchmark(GetParam(), "clockless_playback");
  46. }
  47. static const char* kAudioTestFiles[] {
  48. "sfx_s16le.wav", "sfx.ogg", "sfx.mp3",
  49. #if BUILDFLAG(USE_PROPRIETARY_CODECS)
  50. "sfx.m4a",
  51. #endif
  52. };
  53. // For simplicity we only test codecs with above 2% daily usage as measured by
  54. // the Media.AudioCodec histogram.
  55. INSTANTIATE_TEST_SUITE_P(
  56. All,
  57. ClocklessAudioPipelineIntegrationPerfTest,
  58. testing::ValuesIn(kAudioTestFiles));
  59. TEST(PipelineIntegrationPerfTest, VP8PlaybackBenchmark) {
  60. RunVideoPlaybackBenchmark("bear_silent.webm", "_vp8");
  61. }
  62. TEST(PipelineIntegrationPerfTest, VP9PlaybackBenchmark) {
  63. RunVideoPlaybackBenchmark("bear-vp9.webm", "_vp9");
  64. }
  65. #if BUILDFLAG(ENABLE_AV1_DECODER)
  66. TEST(PipelineIntegrationPerfTest, AV1PlaybackBenchmark) {
  67. RunVideoPlaybackBenchmark("bear-av1-640x480.webm", "_av1");
  68. }
  69. #endif
  70. #if BUILDFLAG(USE_PROPRIETARY_CODECS) && BUILDFLAG(ENABLE_FFMPEG_VIDEO_DECODERS)
  71. TEST(PipelineIntegrationPerfTest, MP4PlaybackBenchmark) {
  72. RunVideoPlaybackBenchmark("bear_silent.mp4", "_mp4");
  73. }
  74. #endif
  75. } // namespace media