OLD | NEW |
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" |
| 14 #include "base/single_thread_task_runner.h" |
13 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
14 #include "base/time/time.h" | 16 #include "base/time/time.h" |
15 #include "build/build_config.h" | 17 #include "build/build_config.h" |
16 #include "media/base/media.h" | 18 #include "media/base/media.h" |
17 #include "media/base/media_log.h" | 19 #include "media/base/media_log.h" |
18 #include "media/base/media_tracks.h" | 20 #include "media/base/media_tracks.h" |
19 #include "media/base/test_data_util.h" | 21 #include "media/base/test_data_util.h" |
20 #include "media/base/timestamp_constants.h" | 22 #include "media/base/timestamp_constants.h" |
21 #include "media/filters/ffmpeg_demuxer.h" | 23 #include "media/filters/ffmpeg_demuxer.h" |
22 #include "media/filters/file_data_source.h" | 24 #include "media/filters/file_data_source.h" |
(...skipping 18 matching lines...) Expand all Loading... |
41 const media::TextTrackConfig& config) override {} | 43 const media::TextTrackConfig& config) override {} |
42 void RemoveTextStream(media::DemuxerStream* text_stream) override {} | 44 void RemoveTextStream(media::DemuxerStream* text_stream) override {} |
43 | 45 |
44 private: | 46 private: |
45 DISALLOW_COPY_AND_ASSIGN(DemuxerHostImpl); | 47 DISALLOW_COPY_AND_ASSIGN(DemuxerHostImpl); |
46 }; | 48 }; |
47 | 49 |
48 static void QuitLoopWithStatus(base::MessageLoop* message_loop, | 50 static void QuitLoopWithStatus(base::MessageLoop* message_loop, |
49 media::PipelineStatus status) { | 51 media::PipelineStatus status) { |
50 CHECK_EQ(status, media::PIPELINE_OK); | 52 CHECK_EQ(status, media::PIPELINE_OK); |
51 message_loop->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 53 message_loop->task_runner()->PostTask( |
| 54 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
52 } | 55 } |
53 | 56 |
54 static void OnEncryptedMediaInitData(EmeInitDataType init_data_type, | 57 static void OnEncryptedMediaInitData(EmeInitDataType init_data_type, |
55 const std::vector<uint8_t>& init_data) { | 58 const std::vector<uint8_t>& init_data) { |
56 VLOG(0) << "File is encrypted."; | 59 VLOG(0) << "File is encrypted."; |
57 } | 60 } |
58 | 61 |
59 static void OnMediaTracksUpdated(std::unique_ptr<MediaTracks> tracks) { | 62 static void OnMediaTracksUpdated(std::unique_ptr<MediaTracks> tracks) { |
60 VLOG(0) << "Got media tracks info, tracks = " << tracks->tracks().size(); | 63 VLOG(0) << "Got media tracks info, tracks = " << tracks->tracks().size(); |
61 } | 64 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 StreamReader::~StreamReader() {} | 124 StreamReader::~StreamReader() {} |
122 | 125 |
123 void StreamReader::Read() { | 126 void StreamReader::Read() { |
124 int index = GetNextStreamIndexToRead(); | 127 int index = GetNextStreamIndexToRead(); |
125 bool end_of_stream = false; | 128 bool end_of_stream = false; |
126 base::TimeDelta timestamp; | 129 base::TimeDelta timestamp; |
127 | 130 |
128 streams_[index]->Read(base::Bind( | 131 streams_[index]->Read(base::Bind( |
129 &StreamReader::OnReadDone, base::Unretained(this), | 132 &StreamReader::OnReadDone, base::Unretained(this), |
130 base::MessageLoop::current(), &end_of_stream, ×tamp)); | 133 base::MessageLoop::current(), &end_of_stream, ×tamp)); |
131 base::MessageLoop::current()->Run(); | 134 base::RunLoop().Run(); |
132 | 135 |
133 CHECK(end_of_stream || timestamp != media::kNoTimestamp()); | 136 CHECK(end_of_stream || timestamp != media::kNoTimestamp()); |
134 end_of_stream_[index] = end_of_stream; | 137 end_of_stream_[index] = end_of_stream; |
135 last_read_timestamp_[index] = timestamp; | 138 last_read_timestamp_[index] = timestamp; |
136 counts_[index]++; | 139 counts_[index]++; |
137 } | 140 } |
138 | 141 |
139 bool StreamReader::IsDone() { | 142 bool StreamReader::IsDone() { |
140 for (size_t i = 0; i < end_of_stream_.size(); ++i) { | 143 for (size_t i = 0; i < end_of_stream_.size(); ++i) { |
141 if (!end_of_stream_[i]) | 144 if (!end_of_stream_[i]) |
142 return false; | 145 return false; |
143 } | 146 } |
144 return true; | 147 return true; |
145 } | 148 } |
146 | 149 |
147 void StreamReader::OnReadDone( | 150 void StreamReader::OnReadDone( |
148 base::MessageLoop* message_loop, | 151 base::MessageLoop* message_loop, |
149 bool* end_of_stream, | 152 bool* end_of_stream, |
150 base::TimeDelta* timestamp, | 153 base::TimeDelta* timestamp, |
151 media::DemuxerStream::Status status, | 154 media::DemuxerStream::Status status, |
152 const scoped_refptr<media::DecoderBuffer>& buffer) { | 155 const scoped_refptr<media::DecoderBuffer>& buffer) { |
153 CHECK_EQ(status, media::DemuxerStream::kOk); | 156 CHECK_EQ(status, media::DemuxerStream::kOk); |
154 CHECK(buffer.get()); | 157 CHECK(buffer.get()); |
155 *end_of_stream = buffer->end_of_stream(); | 158 *end_of_stream = buffer->end_of_stream(); |
156 *timestamp = *end_of_stream ? media::kNoTimestamp() : buffer->timestamp(); | 159 *timestamp = *end_of_stream ? media::kNoTimestamp() : buffer->timestamp(); |
157 message_loop->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 160 message_loop->task_runner()->PostTask( |
| 161 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
158 } | 162 } |
159 | 163 |
160 int StreamReader::GetNextStreamIndexToRead() { | 164 int StreamReader::GetNextStreamIndexToRead() { |
161 int index = -1; | 165 int index = -1; |
162 for (int i = 0; i < number_of_streams(); ++i) { | 166 for (int i = 0; i < number_of_streams(); ++i) { |
163 // Ignore streams at EOS. | 167 // Ignore streams at EOS. |
164 if (end_of_stream_[i]) | 168 if (end_of_stream_[i]) |
165 continue; | 169 continue; |
166 | 170 |
167 // Use a stream if it hasn't been read from yet. | 171 // Use a stream if it hasn't been read from yet. |
(...skipping 23 matching lines...) Expand all Loading... |
191 base::Bind(&OnEncryptedMediaInitData); | 195 base::Bind(&OnEncryptedMediaInitData); |
192 Demuxer::MediaTracksUpdatedCB tracks_updated_cb = | 196 Demuxer::MediaTracksUpdatedCB tracks_updated_cb = |
193 base::Bind(&OnMediaTracksUpdated); | 197 base::Bind(&OnMediaTracksUpdated); |
194 FFmpegDemuxer demuxer(message_loop.task_runner(), &data_source, | 198 FFmpegDemuxer demuxer(message_loop.task_runner(), &data_source, |
195 encrypted_media_init_data_cb, tracks_updated_cb, | 199 encrypted_media_init_data_cb, tracks_updated_cb, |
196 new MediaLog()); | 200 new MediaLog()); |
197 | 201 |
198 demuxer.Initialize(&demuxer_host, | 202 demuxer.Initialize(&demuxer_host, |
199 base::Bind(&QuitLoopWithStatus, &message_loop), | 203 base::Bind(&QuitLoopWithStatus, &message_loop), |
200 false); | 204 false); |
201 message_loop.Run(); | 205 base::RunLoop().Run(); |
202 StreamReader stream_reader(&demuxer, false); | 206 StreamReader stream_reader(&demuxer, false); |
203 | 207 |
204 // Benchmark. | 208 // Benchmark. |
205 base::TimeTicks start = base::TimeTicks::Now(); | 209 base::TimeTicks start = base::TimeTicks::Now(); |
206 while (!stream_reader.IsDone()) { | 210 while (!stream_reader.IsDone()) { |
207 stream_reader.Read(); | 211 stream_reader.Read(); |
208 } | 212 } |
209 base::TimeTicks end = base::TimeTicks::Now(); | 213 base::TimeTicks end = base::TimeTicks::Now(); |
210 total_time += (end - start).InSecondsF(); | 214 total_time += (end - start).InSecondsF(); |
211 demuxer.Stop(); | 215 demuxer.Stop(); |
212 QuitLoopWithStatus(&message_loop, PIPELINE_OK); | 216 QuitLoopWithStatus(&message_loop, PIPELINE_OK); |
213 message_loop.Run(); | 217 base::RunLoop().Run(); |
214 } | 218 } |
215 | 219 |
216 perf_test::PrintResult("demuxer_bench", | 220 perf_test::PrintResult("demuxer_bench", |
217 "", | 221 "", |
218 filename, | 222 filename, |
219 kBenchmarkIterations / total_time, | 223 kBenchmarkIterations / total_time, |
220 "runs/s", | 224 "runs/s", |
221 true); | 225 true); |
222 } | 226 } |
223 | 227 |
(...skipping 13 matching lines...) Expand all Loading... |
237 #endif | 241 #endif |
238 #if defined(OS_CHROMEOS) | 242 #if defined(OS_CHROMEOS) |
239 RunDemuxerBenchmark("bear.flac"); | 243 RunDemuxerBenchmark("bear.flac"); |
240 #endif | 244 #endif |
241 #if defined(USE_PROPRIETARY_CODECS) && defined(OS_CHROMEOS) | 245 #if defined(USE_PROPRIETARY_CODECS) && defined(OS_CHROMEOS) |
242 RunDemuxerBenchmark("bear.avi"); | 246 RunDemuxerBenchmark("bear.avi"); |
243 #endif | 247 #endif |
244 } | 248 } |
245 | 249 |
246 } // namespace media | 250 } // namespace media |
OLD | NEW |