OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "media/base/seekable_buffer.h" | 5 #include "media/base/seekable_buffer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "media/base/data_buffer.h" | 10 #include "media/base/data_buffer.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 size_t SeekableBuffer::Read(uint8* data, size_t size) { | 37 size_t SeekableBuffer::Read(uint8* data, size_t size) { |
38 DCHECK(data); | 38 DCHECK(data); |
39 return InternalRead(data, size, true); | 39 return InternalRead(data, size, true); |
40 } | 40 } |
41 | 41 |
42 size_t SeekableBuffer::Peek(uint8* data, size_t size) { | 42 size_t SeekableBuffer::Peek(uint8* data, size_t size) { |
43 DCHECK(data); | 43 DCHECK(data); |
44 return InternalRead(data, size, false); | 44 return InternalRead(data, size, false); |
45 } | 45 } |
46 | 46 |
| 47 bool SeekableBuffer::GetCurrentChunk(const uint8** data, size_t* size) const { |
| 48 BufferQueue::iterator current_buffer = current_buffer_; |
| 49 size_t current_buffer_offset = current_buffer_offset_; |
| 50 // Advance position if we are in the end of the current buffer. |
| 51 while (current_buffer != buffers_.end() && |
| 52 current_buffer_offset >= (*current_buffer)->GetDataSize()) { |
| 53 ++current_buffer; |
| 54 current_buffer_offset = 0; |
| 55 } |
| 56 if (current_buffer == buffers_.end()) |
| 57 return false; |
| 58 *data = (*current_buffer)->GetData() + current_buffer_offset; |
| 59 *size = (*current_buffer)->GetDataSize() - current_buffer_offset; |
| 60 return true; |
| 61 } |
| 62 |
47 bool SeekableBuffer::Append(Buffer* buffer_in) { | 63 bool SeekableBuffer::Append(Buffer* buffer_in) { |
48 if (buffers_.empty() && buffer_in->GetTimestamp().InMicroseconds() > 0) { | 64 if (buffers_.empty() && buffer_in->GetTimestamp().InMicroseconds() > 0) { |
49 current_time_ = buffer_in->GetTimestamp(); | 65 current_time_ = buffer_in->GetTimestamp(); |
50 } | 66 } |
51 | 67 |
52 // Since the forward capacity is only used to check the criteria for buffer | 68 // Since the forward capacity is only used to check the criteria for buffer |
53 // full, we always append data to the buffer. | 69 // full, we always append data to the buffer. |
54 buffers_.push_back(scoped_refptr<Buffer>(buffer_in)); | 70 buffers_.push_back(scoped_refptr<Buffer>(buffer_in)); |
55 | 71 |
56 // After we have written the first buffer, update |current_buffer_| to point | 72 // After we have written the first buffer, update |current_buffer_| to point |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 (*buffer)->GetTimestamp().InMicroseconds() > 0) { | 255 (*buffer)->GetTimestamp().InMicroseconds() > 0) { |
240 int64 time_offset = ((*buffer)->GetDuration().InMicroseconds() * | 256 int64 time_offset = ((*buffer)->GetDuration().InMicroseconds() * |
241 offset) / (*buffer)->GetDataSize(); | 257 offset) / (*buffer)->GetDataSize(); |
242 | 258 |
243 current_time_ = (*buffer)->GetTimestamp() + | 259 current_time_ = (*buffer)->GetTimestamp() + |
244 base::TimeDelta::FromMicroseconds(time_offset); | 260 base::TimeDelta::FromMicroseconds(time_offset); |
245 } | 261 } |
246 } | 262 } |
247 | 263 |
248 } // namespace media | 264 } // namespace media |
OLD | NEW |