| 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" | 13 #include "base/run_loop.h" |
| 14 #include "base/single_thread_task_runner.h" | |
| 15 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 18 #include "media/base/media.h" | 18 #include "media/base/media.h" |
| 19 #include "media/base/media_log.h" | 19 #include "media/base/media_log.h" |
| 20 #include "media/base/media_tracks.h" | 20 #include "media/base/media_tracks.h" |
| 21 #include "media/base/test_data_util.h" | 21 #include "media/base/test_data_util.h" |
| 22 #include "media/base/timestamp_constants.h" | 22 #include "media/base/timestamp_constants.h" |
| 23 #include "media/filters/ffmpeg_demuxer.h" | 23 #include "media/filters/ffmpeg_demuxer.h" |
| 24 #include "media/filters/file_data_source.h" | 24 #include "media/filters/file_data_source.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 void Read(); | 76 void Read(); |
| 77 | 77 |
| 78 // Returns true when all streams have reached end of stream. | 78 // Returns true when all streams have reached end of stream. |
| 79 bool IsDone(); | 79 bool IsDone(); |
| 80 | 80 |
| 81 int number_of_streams() { return static_cast<int>(streams_.size()); } | 81 int number_of_streams() { return static_cast<int>(streams_.size()); } |
| 82 const Streams& streams() { return streams_; } | 82 const Streams& streams() { return streams_; } |
| 83 const std::vector<int>& counts() { return counts_; } | 83 const std::vector<int>& counts() { return counts_; } |
| 84 | 84 |
| 85 private: | 85 private: |
| 86 void OnReadDone(base::MessageLoop* message_loop, | 86 void OnReadDone(scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 87 const base::Closure& quit_when_idle_closure, |
| 87 bool* end_of_stream, | 88 bool* end_of_stream, |
| 88 base::TimeDelta* timestamp, | 89 base::TimeDelta* timestamp, |
| 89 media::DemuxerStream::Status status, | 90 media::DemuxerStream::Status status, |
| 90 const scoped_refptr<media::DecoderBuffer>& buffer); | 91 const scoped_refptr<media::DecoderBuffer>& buffer); |
| 91 int GetNextStreamIndexToRead(); | 92 int GetNextStreamIndexToRead(); |
| 92 | 93 |
| 93 Streams streams_; | 94 Streams streams_; |
| 94 std::vector<bool> end_of_stream_; | 95 std::vector<bool> end_of_stream_; |
| 95 std::vector<base::TimeDelta> last_read_timestamp_; | 96 std::vector<base::TimeDelta> last_read_timestamp_; |
| 96 std::vector<int> counts_; | 97 std::vector<int> counts_; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 121 } | 122 } |
| 122 } | 123 } |
| 123 | 124 |
| 124 StreamReader::~StreamReader() {} | 125 StreamReader::~StreamReader() {} |
| 125 | 126 |
| 126 void StreamReader::Read() { | 127 void StreamReader::Read() { |
| 127 int index = GetNextStreamIndexToRead(); | 128 int index = GetNextStreamIndexToRead(); |
| 128 bool end_of_stream = false; | 129 bool end_of_stream = false; |
| 129 base::TimeDelta timestamp; | 130 base::TimeDelta timestamp; |
| 130 | 131 |
| 131 streams_[index]->Read(base::Bind( | 132 base::RunLoop run_loop; |
| 132 &StreamReader::OnReadDone, base::Unretained(this), | 133 streams_[index]->Read( |
| 133 base::MessageLoop::current(), &end_of_stream, ×tamp)); | 134 base::Bind(&StreamReader::OnReadDone, base::Unretained(this), |
| 134 base::RunLoop().Run(); | 135 base::ThreadTaskRunnerHandle::Get(), |
| 136 run_loop.QuitWhenIdleClosure(), &end_of_stream, ×tamp)); |
| 137 run_loop.Run(); |
| 135 | 138 |
| 136 CHECK(end_of_stream || timestamp != media::kNoTimestamp); | 139 CHECK(end_of_stream || timestamp != media::kNoTimestamp); |
| 137 end_of_stream_[index] = end_of_stream; | 140 end_of_stream_[index] = end_of_stream; |
| 138 last_read_timestamp_[index] = timestamp; | 141 last_read_timestamp_[index] = timestamp; |
| 139 counts_[index]++; | 142 counts_[index]++; |
| 140 } | 143 } |
| 141 | 144 |
| 142 bool StreamReader::IsDone() { | 145 bool StreamReader::IsDone() { |
| 143 for (size_t i = 0; i < end_of_stream_.size(); ++i) { | 146 for (size_t i = 0; i < end_of_stream_.size(); ++i) { |
| 144 if (!end_of_stream_[i]) | 147 if (!end_of_stream_[i]) |
| 145 return false; | 148 return false; |
| 146 } | 149 } |
| 147 return true; | 150 return true; |
| 148 } | 151 } |
| 149 | 152 |
| 150 void StreamReader::OnReadDone( | 153 void StreamReader::OnReadDone( |
| 151 base::MessageLoop* message_loop, | 154 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 155 const base::Closure& quit_when_idle_closure, |
| 152 bool* end_of_stream, | 156 bool* end_of_stream, |
| 153 base::TimeDelta* timestamp, | 157 base::TimeDelta* timestamp, |
| 154 media::DemuxerStream::Status status, | 158 media::DemuxerStream::Status status, |
| 155 const scoped_refptr<media::DecoderBuffer>& buffer) { | 159 const scoped_refptr<media::DecoderBuffer>& buffer) { |
| 156 CHECK_EQ(status, media::DemuxerStream::kOk); | 160 CHECK_EQ(status, media::DemuxerStream::kOk); |
| 157 CHECK(buffer.get()); | 161 CHECK(buffer.get()); |
| 158 *end_of_stream = buffer->end_of_stream(); | 162 *end_of_stream = buffer->end_of_stream(); |
| 159 *timestamp = *end_of_stream ? media::kNoTimestamp : buffer->timestamp(); | 163 *timestamp = *end_of_stream ? media::kNoTimestamp : buffer->timestamp(); |
| 160 message_loop->task_runner()->PostTask( | 164 task_runner->PostTask(FROM_HERE, quit_when_idle_closure); |
| 161 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | |
| 162 } | 165 } |
| 163 | 166 |
| 164 int StreamReader::GetNextStreamIndexToRead() { | 167 int StreamReader::GetNextStreamIndexToRead() { |
| 165 int index = -1; | 168 int index = -1; |
| 166 for (int i = 0; i < number_of_streams(); ++i) { | 169 for (int i = 0; i < number_of_streams(); ++i) { |
| 167 // Ignore streams at EOS. | 170 // Ignore streams at EOS. |
| 168 if (end_of_stream_[i]) | 171 if (end_of_stream_[i]) |
| 169 continue; | 172 continue; |
| 170 | 173 |
| 171 // Use a stream if it hasn't been read from yet. | 174 // Use a stream if it hasn't been read from yet. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 #endif | 244 #endif |
| 242 #if defined(OS_CHROMEOS) | 245 #if defined(OS_CHROMEOS) |
| 243 RunDemuxerBenchmark("bear.flac"); | 246 RunDemuxerBenchmark("bear.flac"); |
| 244 #endif | 247 #endif |
| 245 #if defined(USE_PROPRIETARY_CODECS) && defined(OS_CHROMEOS) | 248 #if defined(USE_PROPRIETARY_CODECS) && defined(OS_CHROMEOS) |
| 246 RunDemuxerBenchmark("bear.avi"); | 249 RunDemuxerBenchmark("bear.avi"); |
| 247 #endif | 250 #endif |
| 248 } | 251 } |
| 249 | 252 |
| 250 } // namespace media | 253 } // namespace media |
| OLD | NEW |