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" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 DISALLOW_COPY_AND_ASSIGN(StreamReader); | 98 DISALLOW_COPY_AND_ASSIGN(StreamReader); |
99 }; | 99 }; |
100 | 100 |
101 StreamReader::StreamReader(media::Demuxer* demuxer, | 101 StreamReader::StreamReader(media::Demuxer* demuxer, |
102 bool enable_bitstream_converter) { | 102 bool enable_bitstream_converter) { |
103 media::DemuxerStream* stream = | 103 media::DemuxerStream* stream = |
104 demuxer->GetStream(media::DemuxerStream::AUDIO); | 104 demuxer->GetStream(media::DemuxerStream::AUDIO); |
105 if (stream) { | 105 if (stream) { |
106 streams_.push_back(stream); | 106 streams_.push_back(stream); |
107 end_of_stream_.push_back(false); | 107 end_of_stream_.push_back(false); |
108 last_read_timestamp_.push_back(media::kNoTimestamp()); | 108 last_read_timestamp_.push_back(media::kNoTimestamp); |
109 counts_.push_back(0); | 109 counts_.push_back(0); |
110 } | 110 } |
111 | 111 |
112 stream = demuxer->GetStream(media::DemuxerStream::VIDEO); | 112 stream = demuxer->GetStream(media::DemuxerStream::VIDEO); |
113 if (stream) { | 113 if (stream) { |
114 streams_.push_back(stream); | 114 streams_.push_back(stream); |
115 end_of_stream_.push_back(false); | 115 end_of_stream_.push_back(false); |
116 last_read_timestamp_.push_back(media::kNoTimestamp()); | 116 last_read_timestamp_.push_back(media::kNoTimestamp); |
117 counts_.push_back(0); | 117 counts_.push_back(0); |
118 | 118 |
119 if (enable_bitstream_converter) | 119 if (enable_bitstream_converter) |
120 stream->EnableBitstreamConverter(); | 120 stream->EnableBitstreamConverter(); |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 StreamReader::~StreamReader() {} | 124 StreamReader::~StreamReader() {} |
125 | 125 |
126 void StreamReader::Read() { | 126 void StreamReader::Read() { |
127 int index = GetNextStreamIndexToRead(); | 127 int index = GetNextStreamIndexToRead(); |
128 bool end_of_stream = false; | 128 bool end_of_stream = false; |
129 base::TimeDelta timestamp; | 129 base::TimeDelta timestamp; |
130 | 130 |
131 streams_[index]->Read(base::Bind( | 131 streams_[index]->Read(base::Bind( |
132 &StreamReader::OnReadDone, base::Unretained(this), | 132 &StreamReader::OnReadDone, base::Unretained(this), |
133 base::MessageLoop::current(), &end_of_stream, ×tamp)); | 133 base::MessageLoop::current(), &end_of_stream, ×tamp)); |
134 base::RunLoop().Run(); | 134 base::RunLoop().Run(); |
135 | 135 |
136 CHECK(end_of_stream || timestamp != media::kNoTimestamp()); | 136 CHECK(end_of_stream || timestamp != media::kNoTimestamp); |
137 end_of_stream_[index] = end_of_stream; | 137 end_of_stream_[index] = end_of_stream; |
138 last_read_timestamp_[index] = timestamp; | 138 last_read_timestamp_[index] = timestamp; |
139 counts_[index]++; | 139 counts_[index]++; |
140 } | 140 } |
141 | 141 |
142 bool StreamReader::IsDone() { | 142 bool StreamReader::IsDone() { |
143 for (size_t i = 0; i < end_of_stream_.size(); ++i) { | 143 for (size_t i = 0; i < end_of_stream_.size(); ++i) { |
144 if (!end_of_stream_[i]) | 144 if (!end_of_stream_[i]) |
145 return false; | 145 return false; |
146 } | 146 } |
147 return true; | 147 return true; |
148 } | 148 } |
149 | 149 |
150 void StreamReader::OnReadDone( | 150 void StreamReader::OnReadDone( |
151 base::MessageLoop* message_loop, | 151 base::MessageLoop* message_loop, |
152 bool* end_of_stream, | 152 bool* end_of_stream, |
153 base::TimeDelta* timestamp, | 153 base::TimeDelta* timestamp, |
154 media::DemuxerStream::Status status, | 154 media::DemuxerStream::Status status, |
155 const scoped_refptr<media::DecoderBuffer>& buffer) { | 155 const scoped_refptr<media::DecoderBuffer>& buffer) { |
156 CHECK_EQ(status, media::DemuxerStream::kOk); | 156 CHECK_EQ(status, media::DemuxerStream::kOk); |
157 CHECK(buffer.get()); | 157 CHECK(buffer.get()); |
158 *end_of_stream = buffer->end_of_stream(); | 158 *end_of_stream = buffer->end_of_stream(); |
159 *timestamp = *end_of_stream ? media::kNoTimestamp() : buffer->timestamp(); | 159 *timestamp = *end_of_stream ? media::kNoTimestamp : buffer->timestamp(); |
160 message_loop->task_runner()->PostTask( | 160 message_loop->task_runner()->PostTask( |
161 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 161 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
162 } | 162 } |
163 | 163 |
164 int StreamReader::GetNextStreamIndexToRead() { | 164 int StreamReader::GetNextStreamIndexToRead() { |
165 int index = -1; | 165 int index = -1; |
166 for (int i = 0; i < number_of_streams(); ++i) { | 166 for (int i = 0; i < number_of_streams(); ++i) { |
167 // Ignore streams at EOS. | 167 // Ignore streams at EOS. |
168 if (end_of_stream_[i]) | 168 if (end_of_stream_[i]) |
169 continue; | 169 continue; |
170 | 170 |
171 // Use a stream if it hasn't been read from yet. | 171 // Use a stream if it hasn't been read from yet. |
172 if (last_read_timestamp_[i] == media::kNoTimestamp()) | 172 if (last_read_timestamp_[i] == media::kNoTimestamp) |
173 return i; | 173 return i; |
174 | 174 |
175 if (index < 0 || | 175 if (index < 0 || |
176 last_read_timestamp_[i] < last_read_timestamp_[index]) { | 176 last_read_timestamp_[i] < last_read_timestamp_[index]) { |
177 index = i; | 177 index = i; |
178 } | 178 } |
179 } | 179 } |
180 CHECK_GE(index, 0) << "Couldn't find a stream to read"; | 180 CHECK_GE(index, 0) << "Couldn't find a stream to read"; |
181 return index; | 181 return index; |
182 } | 182 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 #endif | 241 #endif |
242 #if defined(OS_CHROMEOS) | 242 #if defined(OS_CHROMEOS) |
243 RunDemuxerBenchmark("bear.flac"); | 243 RunDemuxerBenchmark("bear.flac"); |
244 #endif | 244 #endif |
245 #if defined(USE_PROPRIETARY_CODECS) && defined(OS_CHROMEOS) | 245 #if defined(USE_PROPRIETARY_CODECS) && defined(OS_CHROMEOS) |
246 RunDemuxerBenchmark("bear.avi"); | 246 RunDemuxerBenchmark("bear.avi"); |
247 #endif | 247 #endif |
248 } | 248 } |
249 | 249 |
250 } // namespace media | 250 } // namespace media |
OLD | NEW |