OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/cdm/simple_cdm_buffer.h" | 5 #include "media/cdm/simple_cdm_buffer.h" |
6 | 6 |
| 7 #include <limits> |
| 8 |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/numerics/safe_conversions.h" |
8 | 11 |
9 namespace media { | 12 namespace media { |
10 | 13 |
11 // static | 14 // static |
12 SimpleCdmBuffer* SimpleCdmBuffer::Create(uint32_t capacity) { | 15 SimpleCdmBuffer* SimpleCdmBuffer::Create(size_t capacity) { |
13 DCHECK(capacity); | 16 DCHECK(capacity); |
14 return new SimpleCdmBuffer(capacity); | 17 |
| 18 // cdm::Buffer interface limits capacity to uint32. |
| 19 DCHECK_LE(capacity, std::numeric_limits<uint32_t>::max()); |
| 20 return new SimpleCdmBuffer(base::checked_cast<uint32_t>(capacity)); |
15 } | 21 } |
16 | 22 |
17 SimpleCdmBuffer::SimpleCdmBuffer(uint32_t capacity) | 23 SimpleCdmBuffer::SimpleCdmBuffer(uint32_t capacity) |
18 : buffer_(capacity), size_(0) {} | 24 : buffer_(capacity), size_(0) {} |
19 | 25 |
20 SimpleCdmBuffer::~SimpleCdmBuffer() {} | 26 SimpleCdmBuffer::~SimpleCdmBuffer() {} |
21 | 27 |
22 void SimpleCdmBuffer::Destroy() { | 28 void SimpleCdmBuffer::Destroy() { |
23 delete this; | 29 delete this; |
24 } | 30 } |
25 | 31 |
26 uint32_t SimpleCdmBuffer::Capacity() const { | 32 uint32_t SimpleCdmBuffer::Capacity() const { |
27 return buffer_.size(); | 33 return buffer_.size(); |
28 } | 34 } |
29 | 35 |
30 uint8_t* SimpleCdmBuffer::Data() { | 36 uint8_t* SimpleCdmBuffer::Data() { |
31 return buffer_.data(); | 37 return buffer_.data(); |
32 } | 38 } |
33 | 39 |
34 void SimpleCdmBuffer::SetSize(uint32_t size) { | 40 void SimpleCdmBuffer::SetSize(uint32_t size) { |
35 DCHECK(size <= Capacity()); | 41 DCHECK(size <= Capacity()); |
36 size_ = size > Capacity() ? 0 : size; | 42 size_ = size > Capacity() ? 0 : size; |
37 } | 43 } |
38 | 44 |
39 uint32_t SimpleCdmBuffer::Size() const { | 45 uint32_t SimpleCdmBuffer::Size() const { |
40 return size_; | 46 return size_; |
41 } | 47 } |
42 | 48 |
43 } // namespace media | 49 } // namespace media |
OLD | NEW |