| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/byte_queue.h" | 5 #include "media/base/byte_queue.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 | 8 |
| 9 namespace media { | 9 namespace media { |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 // Check to see if we need a bigger buffer. | 33 // Check to see if we need a bigger buffer. |
| 34 if (size_needed > size_) { | 34 if (size_needed > size_) { |
| 35 size_t new_size = 2 * size_; | 35 size_t new_size = 2 * size_; |
| 36 while (size_needed > new_size && new_size > size_) | 36 while (size_needed > new_size && new_size > size_) |
| 37 new_size *= 2; | 37 new_size *= 2; |
| 38 | 38 |
| 39 // Sanity check to make sure we didn't overflow. | 39 // Sanity check to make sure we didn't overflow. |
| 40 CHECK_GT(new_size, size_); | 40 CHECK_GT(new_size, size_); |
| 41 | 41 |
| 42 scoped_ptr<uint8_t[]> new_buffer(new uint8_t[new_size]); | 42 std::unique_ptr<uint8_t[]> new_buffer(new uint8_t[new_size]); |
| 43 | 43 |
| 44 // Copy the data from the old buffer to the start of the new one. | 44 // Copy the data from the old buffer to the start of the new one. |
| 45 if (used_ > 0) | 45 if (used_ > 0) |
| 46 memcpy(new_buffer.get(), front(), used_); | 46 memcpy(new_buffer.get(), front(), used_); |
| 47 | 47 |
| 48 buffer_.reset(new_buffer.release()); | 48 buffer_.reset(new_buffer.release()); |
| 49 size_ = new_size; | 49 size_ = new_size; |
| 50 offset_ = 0; | 50 offset_ = 0; |
| 51 } else if ((offset_ + used_ + size) > size_) { | 51 } else if ((offset_ + used_ + size) > size_) { |
| 52 // The buffer is big enough, but we need to move the data in the queue. | 52 // The buffer is big enough, but we need to move the data in the queue. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 76 DCHECK_EQ(used_, 0); | 76 DCHECK_EQ(used_, 0); |
| 77 offset_ = 0; | 77 offset_ = 0; |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 | 80 |
| 81 uint8_t* ByteQueue::front() const { | 81 uint8_t* ByteQueue::front() const { |
| 82 return buffer_.get() + offset_; | 82 return buffer_.get() + offset_; |
| 83 } | 83 } |
| 84 | 84 |
| 85 } // namespace media | 85 } // namespace media |
| OLD | NEW |