Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(487)

Unified Diff: media/base/demuxer_perftest.cc

Issue 2710133003: Replace FFmpegDemuxer thread per element with base::TaskScheduler. (Closed)
Patch Set: Give WeakPtr to URLProtocol. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/base/demuxer_perftest.cc
diff --git a/media/base/demuxer_perftest.cc b/media/base/demuxer_perftest.cc
index 45b449912b66321977428dc4c39a6743dc406ff1..b04db50b47e65cd30e295ae24f2249045a247ae0 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,32 @@ 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().RunUntilIdle();
}
- 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)

Powered by Google App Engine
This is Rietveld 408576698