| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 int init_data_size) { | 47 int init_data_size) { |
| 48 LOG(INFO) << "File is encrypted."; | 48 LOG(INFO) << "File is encrypted."; |
| 49 } | 49 } |
| 50 | 50 |
| 51 typedef std::vector<scoped_refptr<media::DemuxerStream> > Streams; | 51 typedef std::vector<scoped_refptr<media::DemuxerStream> > Streams; |
| 52 | 52 |
| 53 // Simulates playback reading requirements by reading from each stream | 53 // Simulates playback reading requirements by reading from each stream |
| 54 // present in |demuxer| in as-close-to-monotonically-increasing timestamp order. | 54 // present in |demuxer| in as-close-to-monotonically-increasing timestamp order. |
| 55 class StreamReader { | 55 class StreamReader { |
| 56 public: | 56 public: |
| 57 explicit StreamReader(const scoped_refptr<media::Demuxer>& demuxer); | 57 explicit StreamReader(media::Demuxer* demuxer); |
| 58 ~StreamReader(); | 58 ~StreamReader(); |
| 59 | 59 |
| 60 // Performs a single step read. | 60 // Performs a single step read. |
| 61 void Read(); | 61 void Read(); |
| 62 | 62 |
| 63 // Returns true when all streams have reached end of stream. | 63 // Returns true when all streams have reached end of stream. |
| 64 bool IsDone(); | 64 bool IsDone(); |
| 65 | 65 |
| 66 int number_of_streams() { return streams_.size(); } | 66 int number_of_streams() { return streams_.size(); } |
| 67 const Streams& streams() { return streams_; } | 67 const Streams& streams() { return streams_; } |
| 68 const std::vector<int>& counts() { return counts_; } | 68 const std::vector<int>& counts() { return counts_; } |
| 69 | 69 |
| 70 private: | 70 private: |
| 71 void OnReadDone(MessageLoop* message_loop, | 71 void OnReadDone(MessageLoop* message_loop, |
| 72 bool* end_of_stream, | 72 bool* end_of_stream, |
| 73 base::TimeDelta* timestamp, | 73 base::TimeDelta* timestamp, |
| 74 media::DemuxerStream::Status status, | 74 media::DemuxerStream::Status status, |
| 75 const scoped_refptr<media::DecoderBuffer>& buffer); | 75 const scoped_refptr<media::DecoderBuffer>& buffer); |
| 76 int GetNextStreamIndexToRead(); | 76 int GetNextStreamIndexToRead(); |
| 77 | 77 |
| 78 Streams streams_; | 78 Streams streams_; |
| 79 std::vector<bool> end_of_stream_; | 79 std::vector<bool> end_of_stream_; |
| 80 std::vector<base::TimeDelta> last_read_timestamp_; | 80 std::vector<base::TimeDelta> last_read_timestamp_; |
| 81 std::vector<int> counts_; | 81 std::vector<int> counts_; |
| 82 | 82 |
| 83 DISALLOW_COPY_AND_ASSIGN(StreamReader); | 83 DISALLOW_COPY_AND_ASSIGN(StreamReader); |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 StreamReader::StreamReader(const scoped_refptr<media::Demuxer> &demuxer) { | 86 StreamReader::StreamReader(media::Demuxer* demuxer) { |
| 87 scoped_refptr<media::DemuxerStream> stream; | 87 scoped_refptr<media::DemuxerStream> stream; |
| 88 stream = demuxer->GetStream(media::DemuxerStream::AUDIO); | 88 stream = demuxer->GetStream(media::DemuxerStream::AUDIO); |
| 89 if (stream) { | 89 if (stream) { |
| 90 streams_.push_back(stream); | 90 streams_.push_back(stream); |
| 91 end_of_stream_.push_back(false); | 91 end_of_stream_.push_back(false); |
| 92 last_read_timestamp_.push_back(media::kNoTimestamp()); | 92 last_read_timestamp_.push_back(media::kNoTimestamp()); |
| 93 counts_.push_back(0); | 93 counts_.push_back(0); |
| 94 } | 94 } |
| 95 | 95 |
| 96 stream = demuxer->GetStream(media::DemuxerStream::VIDEO); | 96 stream = demuxer->GetStream(media::DemuxerStream::VIDEO); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 MessageLoop message_loop; | 176 MessageLoop message_loop; |
| 177 DemuxerHostImpl demuxer_host; | 177 DemuxerHostImpl demuxer_host; |
| 178 base::FilePath file_path(cmd_line->GetArgs()[0]); | 178 base::FilePath file_path(cmd_line->GetArgs()[0]); |
| 179 | 179 |
| 180 // Setup. | 180 // Setup. |
| 181 scoped_refptr<media::FileDataSource> data_source = | 181 scoped_refptr<media::FileDataSource> data_source = |
| 182 new media::FileDataSource(); | 182 new media::FileDataSource(); |
| 183 CHECK(data_source->Initialize(file_path)); | 183 CHECK(data_source->Initialize(file_path)); |
| 184 | 184 |
| 185 media::FFmpegNeedKeyCB need_key_cb = base::Bind(&NeedKey); | 185 media::FFmpegNeedKeyCB need_key_cb = base::Bind(&NeedKey); |
| 186 scoped_refptr<media::FFmpegDemuxer> demuxer = | 186 scoped_ptr<media::FFmpegDemuxer> demuxer(new media::FFmpegDemuxer( |
| 187 new media::FFmpegDemuxer(message_loop.message_loop_proxy(), data_source, | 187 message_loop.message_loop_proxy(), data_source, need_key_cb)); |
| 188 need_key_cb); | |
| 189 | 188 |
| 190 demuxer->Initialize(&demuxer_host, base::Bind( | 189 demuxer->Initialize(&demuxer_host, base::Bind( |
| 191 &QuitLoopWithStatus, &message_loop)); | 190 &QuitLoopWithStatus, &message_loop)); |
| 192 message_loop.Run(); | 191 message_loop.Run(); |
| 193 | 192 |
| 194 StreamReader stream_reader(demuxer); | 193 StreamReader stream_reader(demuxer.get()); |
| 195 | 194 |
| 196 // Benchmark. | 195 // Benchmark. |
| 197 base::TimeTicks start = base::TimeTicks::HighResNow(); | 196 base::TimeTicks start = base::TimeTicks::HighResNow(); |
| 198 while (!stream_reader.IsDone()) { | 197 while (!stream_reader.IsDone()) { |
| 199 stream_reader.Read(); | 198 stream_reader.Read(); |
| 200 } | 199 } |
| 201 base::TimeTicks end = base::TimeTicks::HighResNow(); | 200 base::TimeTicks end = base::TimeTicks::HighResNow(); |
| 202 | 201 |
| 203 // Results. | 202 // Results. |
| 204 std::cout << "Time: " << (end - start).InMillisecondsF() << " ms\n"; | 203 std::cout << "Time: " << (end - start).InMillisecondsF() << " ms\n"; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 217 std::cout << ", " << stream_reader.counts()[i] << " packets" << std::endl; | 216 std::cout << ", " << stream_reader.counts()[i] << " packets" << std::endl; |
| 218 } | 217 } |
| 219 | 218 |
| 220 // Teardown. | 219 // Teardown. |
| 221 demuxer->Stop(base::Bind( | 220 demuxer->Stop(base::Bind( |
| 222 &QuitLoopWithStatus, &message_loop, media::PIPELINE_OK)); | 221 &QuitLoopWithStatus, &message_loop, media::PIPELINE_OK)); |
| 223 message_loop.Run(); | 222 message_loop.Run(); |
| 224 | 223 |
| 225 return 0; | 224 return 0; |
| 226 } | 225 } |
| OLD | NEW |