| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // demuxer_bench is a standalone benchmarking tool for FFmpegDemuxer. It | 5 // demuxer_bench is a standalone benchmarking tool for FFmpegDemuxer. It | 
| 6 // simulates the reading requirements for playback by reading from the stream | 6 // simulates the reading requirements for playback by reading from the stream | 
| 7 // that has the earliest timestamp. | 7 // that has the earliest timestamp. | 
| 8 | 8 | 
| 9 #include <iostream> | 9 #include <iostream> | 
| 10 | 10 | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 30 | 30 | 
| 31   // DataSourceHost implementation. | 31   // DataSourceHost implementation. | 
| 32   virtual void SetTotalBytes(int64 total_bytes) OVERRIDE {} | 32   virtual void SetTotalBytes(int64 total_bytes) OVERRIDE {} | 
| 33   virtual void AddBufferedByteRange(int64 start, int64 end) OVERRIDE {} | 33   virtual void AddBufferedByteRange(int64 start, int64 end) OVERRIDE {} | 
| 34   virtual void AddBufferedTimeRange(base::TimeDelta start, | 34   virtual void AddBufferedTimeRange(base::TimeDelta start, | 
| 35                                     base::TimeDelta end) OVERRIDE {} | 35                                     base::TimeDelta end) OVERRIDE {} | 
| 36 | 36 | 
| 37   // DemuxerHost implementation. | 37   // DemuxerHost implementation. | 
| 38   virtual void SetDuration(base::TimeDelta duration) OVERRIDE {} | 38   virtual void SetDuration(base::TimeDelta duration) OVERRIDE {} | 
| 39   virtual void OnDemuxerError(media::PipelineStatus error) OVERRIDE {} | 39   virtual void OnDemuxerError(media::PipelineStatus error) OVERRIDE {} | 
|  | 40   virtual void AddTextStream(media::DemuxerStream* text_stream, | 
|  | 41                              media::TextKind kind, | 
|  | 42                              const std::string& label, | 
|  | 43                              const std::string& language) OVERRIDE {} | 
| 40 | 44 | 
| 41  private: | 45  private: | 
| 42   DISALLOW_COPY_AND_ASSIGN(DemuxerHostImpl); | 46   DISALLOW_COPY_AND_ASSIGN(DemuxerHostImpl); | 
| 43 }; | 47 }; | 
| 44 | 48 | 
| 45 void QuitLoopWithStatus(base::MessageLoop* message_loop, | 49 void QuitLoopWithStatus(base::MessageLoop* message_loop, | 
| 46                         media::PipelineStatus status) { | 50                         media::PipelineStatus status) { | 
| 47   CHECK_EQ(status, media::PIPELINE_OK); | 51   CHECK_EQ(status, media::PIPELINE_OK); | 
| 48   message_loop->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 52   message_loop->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 
| 49 } | 53 } | 
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 191   base::FilePath file_path(cmd_line->GetArgs()[0]); | 195   base::FilePath file_path(cmd_line->GetArgs()[0]); | 
| 192 | 196 | 
| 193   // Setup. | 197   // Setup. | 
| 194   media::FileDataSource data_source; | 198   media::FileDataSource data_source; | 
| 195   CHECK(data_source.Initialize(file_path)); | 199   CHECK(data_source.Initialize(file_path)); | 
| 196 | 200 | 
| 197   media::Demuxer::NeedKeyCB need_key_cb = base::Bind(&NeedKey); | 201   media::Demuxer::NeedKeyCB need_key_cb = base::Bind(&NeedKey); | 
| 198   media::FFmpegDemuxer demuxer(message_loop.message_loop_proxy(), | 202   media::FFmpegDemuxer demuxer(message_loop.message_loop_proxy(), | 
| 199                                &data_source, | 203                                &data_source, | 
| 200                                need_key_cb, | 204                                need_key_cb, | 
|  | 205                                true,  // enable inband text tracks | 
| 201                                new media::MediaLog()); | 206                                new media::MediaLog()); | 
| 202 | 207 | 
| 203   demuxer.Initialize(&demuxer_host, base::Bind( | 208   demuxer.Initialize(&demuxer_host, base::Bind( | 
| 204       &QuitLoopWithStatus, &message_loop)); | 209       &QuitLoopWithStatus, &message_loop)); | 
| 205   message_loop.Run(); | 210   message_loop.Run(); | 
| 206 | 211 | 
| 207   StreamReader stream_reader( | 212   StreamReader stream_reader( | 
| 208       &demuxer, cmd_line->HasSwitch(switches::kEnableBitstreamConverter)); | 213       &demuxer, cmd_line->HasSwitch(switches::kEnableBitstreamConverter)); | 
| 209 | 214 | 
| 210   // Benchmark. | 215   // Benchmark. | 
| 211   base::TimeTicks start = base::TimeTicks::HighResNow(); | 216   base::TimeTicks start = base::TimeTicks::HighResNow(); | 
| 212   while (!stream_reader.IsDone()) { | 217   while (!stream_reader.IsDone()) { | 
| 213     stream_reader.Read(); | 218     stream_reader.Read(); | 
| 214   } | 219   } | 
| 215   base::TimeTicks end = base::TimeTicks::HighResNow(); | 220   base::TimeTicks end = base::TimeTicks::HighResNow(); | 
| 216 | 221 | 
| 217   // Results. | 222   // Results. | 
| 218   std::cout << "Time: " << (end - start).InMillisecondsF() << " ms\n"; | 223   std::cout << "Time: " << (end - start).InMillisecondsF() << " ms\n"; | 
| 219   for (int i = 0; i < stream_reader.number_of_streams(); ++i) { | 224   for (int i = 0; i < stream_reader.number_of_streams(); ++i) { | 
| 220     media::DemuxerStream* stream = stream_reader.streams()[i]; | 225     media::DemuxerStream* stream = stream_reader.streams()[i]; | 
| 221     std::cout << "Stream #" << i << ": "; | 226     std::cout << "Stream #" << i << ": "; | 
| 222 | 227 | 
| 223     if (stream->type() == media::DemuxerStream::AUDIO) { | 228     if (stream->type() == media::DemuxerStream::AUDIO) { | 
| 224       std::cout << "audio"; | 229       std::cout << "audio"; | 
| 225     } else if (stream->type() == media::DemuxerStream::VIDEO) { | 230     } else if (stream->type() == media::DemuxerStream::VIDEO) { | 
| 226       std::cout << "video"; | 231       std::cout << "video"; | 
|  | 232     } else if (stream->type() == media::DemuxerStream::TEXT) { | 
|  | 233       std::cout << "text"; | 
| 227     } else { | 234     } else { | 
| 228       std::cout << "unknown"; | 235       std::cout << "unknown"; | 
| 229     } | 236     } | 
| 230 | 237 | 
| 231     std::cout << ", " << stream_reader.counts()[i] << " packets" << std::endl; | 238     std::cout << ", " << stream_reader.counts()[i] << " packets" << std::endl; | 
| 232   } | 239   } | 
| 233 | 240 | 
| 234   // Teardown. | 241   // Teardown. | 
| 235   demuxer.Stop(base::Bind( | 242   demuxer.Stop(base::Bind( | 
| 236       &QuitLoopWithStatus, &message_loop, media::PIPELINE_OK)); | 243       &QuitLoopWithStatus, &message_loop, media::PIPELINE_OK)); | 
| 237   message_loop.Run(); | 244   message_loop.Run(); | 
| 238 | 245 | 
| 239   return 0; | 246   return 0; | 
| 240 } | 247 } | 
| OLD | NEW | 
|---|