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

Side by Side 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, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/test/scoped_task_scheduler.h"
15 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
16 #include "base/time/time.h" 17 #include "base/time/time.h"
17 #include "build/build_config.h" 18 #include "build/build_config.h"
18 #include "media/base/media.h" 19 #include "media/base/media.h"
19 #include "media/base/media_log.h" 20 #include "media/base/media_log.h"
20 #include "media/base/media_tracks.h" 21 #include "media/base/media_tracks.h"
21 #include "media/base/test_data_util.h" 22 #include "media/base/test_data_util.h"
22 #include "media/base/timestamp_constants.h" 23 #include "media/base/timestamp_constants.h"
23 #include "media/filters/ffmpeg_demuxer.h" 24 #include "media/filters/ffmpeg_demuxer.h"
24 #include "media/filters/file_data_source.h" 25 #include "media/filters/file_data_source.h"
(...skipping 16 matching lines...) Expand all
41 void SetDuration(base::TimeDelta duration) override {} 42 void SetDuration(base::TimeDelta duration) override {}
42 void OnDemuxerError(media::PipelineStatus error) override {} 43 void OnDemuxerError(media::PipelineStatus error) override {}
43 void AddTextStream(media::DemuxerStream* text_stream, 44 void AddTextStream(media::DemuxerStream* text_stream,
44 const media::TextTrackConfig& config) override {} 45 const media::TextTrackConfig& config) override {}
45 void RemoveTextStream(media::DemuxerStream* text_stream) override {} 46 void RemoveTextStream(media::DemuxerStream* text_stream) override {}
46 47
47 private: 48 private:
48 DISALLOW_COPY_AND_ASSIGN(DemuxerHostImpl); 49 DISALLOW_COPY_AND_ASSIGN(DemuxerHostImpl);
49 }; 50 };
50 51
51 static void QuitLoopWithStatus(base::MessageLoop* message_loop, 52 static void QuitLoopWithStatus(base::Closure quit_cb,
52 media::PipelineStatus status) { 53 media::PipelineStatus status) {
53 CHECK_EQ(status, media::PIPELINE_OK); 54 CHECK_EQ(status, media::PIPELINE_OK);
54 message_loop->task_runner()->PostTask( 55 quit_cb.Run();
55 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
56 } 56 }
57 57
58 static void OnEncryptedMediaInitData(EmeInitDataType init_data_type, 58 static void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
59 const std::vector<uint8_t>& init_data) { 59 const std::vector<uint8_t>& init_data) {
60 VLOG(0) << "File is encrypted."; 60 DVLOG(1) << "File is encrypted.";
61 } 61 }
62 62
63 static void OnMediaTracksUpdated(std::unique_ptr<MediaTracks> tracks) { 63 static void OnMediaTracksUpdated(std::unique_ptr<MediaTracks> tracks) {
64 VLOG(0) << "Got media tracks info, tracks = " << tracks->tracks().size(); 64 DVLOG(1) << "Got media tracks info, tracks = " << tracks->tracks().size();
65 } 65 }
66 66
67 typedef std::vector<media::DemuxerStream* > Streams; 67 typedef std::vector<media::DemuxerStream* > Streams;
68 68
69 // Simulates playback reading requirements by reading from each stream 69 // Simulates playback reading requirements by reading from each stream
70 // present in |demuxer| in as-close-to-monotonically-increasing timestamp order. 70 // present in |demuxer| in as-close-to-monotonically-increasing timestamp order.
71 class StreamReader { 71 class StreamReader {
72 public: 72 public:
73 StreamReader(media::Demuxer* demuxer, bool enable_bitstream_converter); 73 StreamReader(media::Demuxer* demuxer, bool enable_bitstream_converter);
74 ~StreamReader(); 74 ~StreamReader();
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 last_read_timestamp_[i] < last_read_timestamp_[index]) { 170 last_read_timestamp_[i] < last_read_timestamp_[index]) {
171 index = i; 171 index = i;
172 } 172 }
173 } 173 }
174 CHECK_GE(index, 0) << "Couldn't find a stream to read"; 174 CHECK_GE(index, 0) << "Couldn't find a stream to read";
175 return index; 175 return index;
176 } 176 }
177 177
178 static void RunDemuxerBenchmark(const std::string& filename) { 178 static void RunDemuxerBenchmark(const std::string& filename) {
179 base::FilePath file_path(GetTestDataFilePath(filename)); 179 base::FilePath file_path(GetTestDataFilePath(filename));
180 double total_time = 0.0; 180 base::TimeDelta total_time;
181 for (int i = 0; i < kBenchmarkIterations; ++i) { 181 for (int i = 0; i < kBenchmarkIterations; ++i) {
182 // Setup. 182 // Setup.
183 base::MessageLoop message_loop; 183 base::test::ScopedTaskScheduler scoped_task_scheduler;
184 DemuxerHostImpl demuxer_host; 184 DemuxerHostImpl demuxer_host;
185 FileDataSource data_source; 185 FileDataSource data_source;
186 ASSERT_TRUE(data_source.Initialize(file_path)); 186 ASSERT_TRUE(data_source.Initialize(file_path));
187 187
188 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb = 188 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb =
189 base::Bind(&OnEncryptedMediaInitData); 189 base::Bind(&OnEncryptedMediaInitData);
190 Demuxer::MediaTracksUpdatedCB tracks_updated_cb = 190 Demuxer::MediaTracksUpdatedCB tracks_updated_cb =
191 base::Bind(&OnMediaTracksUpdated); 191 base::Bind(&OnMediaTracksUpdated);
192 FFmpegDemuxer demuxer(message_loop.task_runner(), &data_source, 192 FFmpegDemuxer demuxer(base::ThreadTaskRunnerHandle::Get(), &data_source,
193 encrypted_media_init_data_cb, tracks_updated_cb, 193 encrypted_media_init_data_cb, tracks_updated_cb,
194 new MediaLog()); 194 new MediaLog());
195 195
196 demuxer.Initialize(&demuxer_host, 196 {
197 base::Bind(&QuitLoopWithStatus, &message_loop), 197 base::RunLoop run_loop;
198 false); 198 demuxer.Initialize(
199 base::RunLoop().Run(); 199 &demuxer_host,
200 base::Bind(&QuitLoopWithStatus, run_loop.QuitClosure()), false);
201 run_loop.Run();
202 }
203
200 StreamReader stream_reader(&demuxer, false); 204 StreamReader stream_reader(&demuxer, false);
201 205
202 // Benchmark. 206 // Benchmark.
203 base::TimeTicks start = base::TimeTicks::Now(); 207 base::TimeTicks start = base::TimeTicks::Now();
204 while (!stream_reader.IsDone()) { 208 while (!stream_reader.IsDone())
205 stream_reader.Read(); 209 stream_reader.Read();
206 } 210 total_time += base::TimeTicks::Now() - start;
207 base::TimeTicks end = base::TimeTicks::Now();
208 total_time += (end - start).InSecondsF();
209 demuxer.Stop(); 211 demuxer.Stop();
210 QuitLoopWithStatus(&message_loop, PIPELINE_OK); 212 base::RunLoop().RunUntilIdle();
211 base::RunLoop().Run();
212 } 213 }
213 214
214 perf_test::PrintResult("demuxer_bench", 215 perf_test::PrintResult("demuxer_bench", "", filename,
215 "", 216 kBenchmarkIterations / total_time.InSecondsF(),
216 filename, 217 "runs/s", true);
217 kBenchmarkIterations / total_time,
218 "runs/s",
219 true);
220 } 218 }
221 219
222 #if defined(OS_WIN) 220 #if defined(OS_WIN)
223 // http://crbug.com/399002 221 // http://crbug.com/399002
224 #define MAYBE_Demuxer DISABLED_Demuxer 222 #define MAYBE_Demuxer DISABLED_Demuxer
225 #else 223 #else
226 #define MAYBE_Demuxer Demuxer 224 #define MAYBE_Demuxer Demuxer
227 #endif 225 #endif
228 TEST(DemuxerPerfTest, MAYBE_Demuxer) { 226 TEST(DemuxerPerfTest, MAYBE_Demuxer) {
229 RunDemuxerBenchmark("bear.ogv"); 227 RunDemuxerBenchmark("bear.ogv");
230 RunDemuxerBenchmark("bear-640x360.webm"); 228 RunDemuxerBenchmark("bear-640x360.webm");
231 RunDemuxerBenchmark("sfx_s16le.wav"); 229 RunDemuxerBenchmark("sfx_s16le.wav");
232 RunDemuxerBenchmark("bear.flac"); 230 RunDemuxerBenchmark("bear.flac");
233 #if BUILDFLAG(USE_PROPRIETARY_CODECS) 231 #if BUILDFLAG(USE_PROPRIETARY_CODECS)
234 RunDemuxerBenchmark("bear-1280x720.mp4"); 232 RunDemuxerBenchmark("bear-1280x720.mp4");
235 RunDemuxerBenchmark("sfx.mp3"); 233 RunDemuxerBenchmark("sfx.mp3");
236 #endif 234 #endif
237 #if BUILDFLAG(USE_PROPRIETARY_CODECS) && defined(OS_CHROMEOS) 235 #if BUILDFLAG(USE_PROPRIETARY_CODECS) && defined(OS_CHROMEOS)
238 RunDemuxerBenchmark("bear.avi"); 236 RunDemuxerBenchmark("bear.avi");
239 #endif 237 #endif
240 } 238 }
241 239
242 } // namespace media 240 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698