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 27 matching lines...) Expand all Loading... |
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 std::unique_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_ = std::move(new_buffer); |
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. |
53 memmove(buffer_.get(), front(), used_); | 53 memmove(buffer_.get(), front(), used_); |
54 offset_ = 0; | 54 offset_ = 0; |
55 } | 55 } |
56 | 56 |
57 memcpy(front() + used_, data, size); | 57 memcpy(front() + used_, data, size); |
58 used_ += size; | 58 used_ += size; |
(...skipping 17 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 |