simple_cdm_buffer.cc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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
  3. // found in the LICENSE file.
  4. #include "media/cdm/simple_cdm_buffer.h"
  5. #include <limits>
  6. #include "base/check_op.h"
  7. #include "base/numerics/safe_conversions.h"
  8. namespace media {
  9. // static
  10. SimpleCdmBuffer* SimpleCdmBuffer::Create(size_t capacity) {
  11. DCHECK(capacity);
  12. // cdm::Buffer interface limits capacity to uint32.
  13. DCHECK_LE(capacity, std::numeric_limits<uint32_t>::max());
  14. return new SimpleCdmBuffer(base::checked_cast<uint32_t>(capacity));
  15. }
  16. SimpleCdmBuffer::SimpleCdmBuffer(uint32_t capacity)
  17. : buffer_(capacity), size_(0) {}
  18. SimpleCdmBuffer::~SimpleCdmBuffer() = default;
  19. void SimpleCdmBuffer::Destroy() {
  20. delete this;
  21. }
  22. uint32_t SimpleCdmBuffer::Capacity() const {
  23. return buffer_.size();
  24. }
  25. uint8_t* SimpleCdmBuffer::Data() {
  26. return buffer_.data();
  27. }
  28. void SimpleCdmBuffer::SetSize(uint32_t size) {
  29. DCHECK(size <= Capacity());
  30. size_ = size > Capacity() ? 0 : size;
  31. }
  32. uint32_t SimpleCdmBuffer::Size() const {
  33. return size_;
  34. }
  35. } // namespace media