Chromium Code Reviews| Index: media/base/demuxer_perftest.cc |
| diff --git a/media/base/demuxer_perftest.cc b/media/base/demuxer_perftest.cc |
| index adfde41002e92b4e49a849cf8b7197f41fa76f32..3485e97589198a2f5821fea77e1508bd0121f0ba 100644 |
| --- a/media/base/demuxer_perftest.cc |
| +++ b/media/base/demuxer_perftest.cc |
| @@ -12,6 +12,7 @@ |
| #include "base/message_loop/message_loop.h" |
| #include "base/run_loop.h" |
| #include "base/strings/string_number_conversions.h" |
| +#include "base/test/scoped_task_scheduler.h" |
| #include "base/threading/thread_task_runner_handle.h" |
| #include "base/time/time.h" |
| #include "build/build_config.h" |
| @@ -48,20 +49,19 @@ class DemuxerHostImpl : public media::DemuxerHost { |
| DISALLOW_COPY_AND_ASSIGN(DemuxerHostImpl); |
| }; |
| -static void QuitLoopWithStatus(base::MessageLoop* message_loop, |
| +static void QuitLoopWithStatus(base::Closure quit_cb, |
| media::PipelineStatus status) { |
| CHECK_EQ(status, media::PIPELINE_OK); |
| - message_loop->task_runner()->PostTask( |
| - FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
| + quit_cb.Run(); |
| } |
| static void OnEncryptedMediaInitData(EmeInitDataType init_data_type, |
| const std::vector<uint8_t>& init_data) { |
| - VLOG(0) << "File is encrypted."; |
| + DVLOG(1) << "File is encrypted."; |
| } |
| static void OnMediaTracksUpdated(std::unique_ptr<MediaTracks> tracks) { |
| - VLOG(0) << "Got media tracks info, tracks = " << tracks->tracks().size(); |
| + DVLOG(1) << "Got media tracks info, tracks = " << tracks->tracks().size(); |
| } |
| typedef std::vector<media::DemuxerStream* > Streams; |
| @@ -177,10 +177,10 @@ int StreamReader::GetNextStreamIndexToRead() { |
| static void RunDemuxerBenchmark(const std::string& filename) { |
| base::FilePath file_path(GetTestDataFilePath(filename)); |
| - double total_time = 0.0; |
| + base::TimeDelta total_time; |
| for (int i = 0; i < kBenchmarkIterations; ++i) { |
| // Setup. |
| - base::MessageLoop message_loop; |
| + base::test::ScopedTaskScheduler scoped_task_scheduler; |
| DemuxerHostImpl demuxer_host; |
| FileDataSource data_source; |
| ASSERT_TRUE(data_source.Initialize(file_path)); |
| @@ -189,34 +189,38 @@ static void RunDemuxerBenchmark(const std::string& filename) { |
| base::Bind(&OnEncryptedMediaInitData); |
| Demuxer::MediaTracksUpdatedCB tracks_updated_cb = |
| base::Bind(&OnMediaTracksUpdated); |
| - FFmpegDemuxer demuxer(message_loop.task_runner(), &data_source, |
| + FFmpegDemuxer demuxer(base::ThreadTaskRunnerHandle::Get(), &data_source, |
| encrypted_media_init_data_cb, tracks_updated_cb, |
| new MediaLog()); |
| - demuxer.Initialize(&demuxer_host, |
| - base::Bind(&QuitLoopWithStatus, &message_loop), |
| - false); |
| - base::RunLoop().Run(); |
| + { |
| + base::RunLoop run_loop; |
| + demuxer.Initialize( |
| + &demuxer_host, |
| + base::Bind(&QuitLoopWithStatus, run_loop.QuitClosure()), false); |
| + run_loop.Run(); |
| + } |
| + |
| StreamReader stream_reader(&demuxer, false); |
| // Benchmark. |
| base::TimeTicks start = base::TimeTicks::Now(); |
| - while (!stream_reader.IsDone()) { |
| + while (!stream_reader.IsDone()) |
| stream_reader.Read(); |
| - } |
| - base::TimeTicks end = base::TimeTicks::Now(); |
| - total_time += (end - start).InSecondsF(); |
| + total_time += base::TimeTicks::Now() - start; |
| demuxer.Stop(); |
| - QuitLoopWithStatus(&message_loop, PIPELINE_OK); |
| - base::RunLoop().Run(); |
| + |
| + { |
| + base::RunLoop run_loop; |
| + base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| + run_loop.QuitClosure()); |
| + run_loop.Run(); |
|
gab
2017/02/26 18:01:35
This whole block can be replaced by base::RunLoop(
DaleCurtis
2017/02/27 21:26:30
Done.
|
| + } |
| } |
| - perf_test::PrintResult("demuxer_bench", |
| - "", |
| - filename, |
| - kBenchmarkIterations / total_time, |
| - "runs/s", |
| - true); |
| + perf_test::PrintResult("demuxer_bench", "", filename, |
| + kBenchmarkIterations / total_time.InSecondsF(), |
| + "runs/s", true); |
| } |
| #if defined(OS_WIN) |