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 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/gtest_prod_util.h" | 6 #include "base/gtest_prod_util.h" |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "media/base/data_buffer.h" | 8 #include "media/base/data_buffer.h" |
9 #include "media/base/mock_callback.h" | 9 #include "media/base/mock_callback.h" |
10 #include "media/base/mock_filter_host.h" | 10 #include "media/base/mock_filter_host.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 } | 177 } |
178 | 178 |
179 // Attempts to consume |size| bytes from |renderer_|'s internal buffer, | 179 // Attempts to consume |size| bytes from |renderer_|'s internal buffer, |
180 // returning true if all |size| bytes were consumed, false if less than | 180 // returning true if all |size| bytes were consumed, false if less than |
181 // |size| bytes were consumed. | 181 // |size| bytes were consumed. |
182 // | 182 // |
183 // |muted| is optional and if passed will get set if the byte value of | 183 // |muted| is optional and if passed will get set if the byte value of |
184 // the consumed data is muted audio. | 184 // the consumed data is muted audio. |
185 bool ConsumeBufferedData(uint32 size, bool* muted) { | 185 bool ConsumeBufferedData(uint32 size, bool* muted) { |
186 scoped_array<uint8> buffer(new uint8[size]); | 186 scoped_array<uint8> buffer(new uint8[size]); |
187 uint32 bytes_read = renderer_->FillBuffer(buffer.get(), size, | 187 uint32 bytes_per_frame = (decoder_->bits_per_channel() / 8) * |
188 base::TimeDelta()); | 188 ChannelLayoutToChannelCount(decoder_->channel_layout()); |
189 if (bytes_read > 0 && muted) { | 189 uint32 requested_frames = size / bytes_per_frame; |
| 190 uint32 frames_read = renderer_->FillBuffer( |
| 191 buffer.get(), requested_frames, base::TimeDelta()); |
| 192 |
| 193 if (frames_read > 0 && muted) { |
190 *muted = (buffer[0] == kMutedAudio); | 194 *muted = (buffer[0] == kMutedAudio); |
191 } | 195 } |
192 return (bytes_read == size); | 196 return (frames_read == requested_frames); |
193 } | 197 } |
194 | 198 |
195 uint32 bytes_buffered() { | 199 uint32 bytes_buffered() { |
196 return renderer_->algorithm_->bytes_buffered(); | 200 return renderer_->algorithm_->bytes_buffered(); |
197 } | 201 } |
198 | 202 |
199 uint32 buffer_capacity() { | 203 uint32 buffer_capacity() { |
200 return renderer_->algorithm_->QueueCapacity(); | 204 return renderer_->algorithm_->QueueCapacity(); |
201 } | 205 } |
202 | 206 |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 EXPECT_TRUE(ConsumeBufferedData(bytes_buffered() / 2, NULL)); | 434 EXPECT_TRUE(ConsumeBufferedData(bytes_buffered() / 2, NULL)); |
431 | 435 |
432 renderer_->Pause(NewExpectedClosure()); | 436 renderer_->Pause(NewExpectedClosure()); |
433 | 437 |
434 AbortPendingRead(); | 438 AbortPendingRead(); |
435 | 439 |
436 Seek(base::TimeDelta::FromSeconds(1)); | 440 Seek(base::TimeDelta::FromSeconds(1)); |
437 } | 441 } |
438 | 442 |
439 } // namespace media | 443 } // namespace media |
OLD | NEW |