Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: media/cdm/simple_cdm_buffer.cc

Issue 1802183002: Convert CreateCdmBuffer() to use size_t for |capacity| (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove cast Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/cdm/simple_cdm_buffer.h ('k') | media/mojo/common/mojo_shared_buffer_video_frame.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
OLDNEW
« no previous file with comments | « media/cdm/simple_cdm_buffer.h ('k') | media/mojo/common/mojo_shared_buffer_video_frame.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698