cdm_helpers.cc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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/cdm_helpers.h"
  5. #include "base/check.h"
  6. #include "ui/gfx/color_space.h"
  7. namespace media {
  8. namespace {
  9. // See ISO 23001-8:2016, section 7. Value 2 means "Unspecified".
  10. constexpr cdm::ColorSpace kUnspecifiedColorSpace = {2, 2, 2,
  11. cdm::ColorRange::kInvalid};
  12. gfx::ColorSpace::RangeID ToGfxColorSpaceRange(cdm::ColorRange range) {
  13. switch (range) {
  14. case cdm::ColorRange::kInvalid:
  15. return gfx::ColorSpace::RangeID::INVALID;
  16. case cdm::ColorRange::kLimited:
  17. return gfx::ColorSpace::RangeID::LIMITED;
  18. case cdm::ColorRange::kFull:
  19. return gfx::ColorSpace::RangeID::FULL;
  20. case cdm::ColorRange::kDerived:
  21. return gfx::ColorSpace::RangeID::DERIVED;
  22. }
  23. }
  24. } // namespace
  25. DecryptedBlockImpl::DecryptedBlockImpl() : buffer_(nullptr), timestamp_(0) {}
  26. DecryptedBlockImpl::~DecryptedBlockImpl() {
  27. if (buffer_)
  28. buffer_->Destroy();
  29. }
  30. void DecryptedBlockImpl::SetDecryptedBuffer(cdm::Buffer* buffer) {
  31. buffer_ = buffer;
  32. }
  33. cdm::Buffer* DecryptedBlockImpl::DecryptedBuffer() {
  34. return buffer_;
  35. }
  36. void DecryptedBlockImpl::SetTimestamp(int64_t timestamp) {
  37. timestamp_ = timestamp;
  38. }
  39. int64_t DecryptedBlockImpl::Timestamp() const {
  40. return timestamp_;
  41. }
  42. VideoFrameImpl::VideoFrameImpl()
  43. : format_(cdm::kUnknownVideoFormat),
  44. color_space_(kUnspecifiedColorSpace),
  45. frame_buffer_(nullptr),
  46. timestamp_(0) {
  47. for (uint32_t i = 0; i < cdm::kMaxPlanes; ++i) {
  48. plane_offsets_[i] = 0;
  49. strides_[i] = 0;
  50. }
  51. }
  52. VideoFrameImpl::~VideoFrameImpl() {
  53. if (frame_buffer_)
  54. frame_buffer_->Destroy();
  55. }
  56. void VideoFrameImpl::SetFormat(cdm::VideoFormat format) {
  57. format_ = format;
  58. }
  59. cdm::VideoFormat VideoFrameImpl::Format() const {
  60. return format_;
  61. }
  62. void VideoFrameImpl::SetSize(cdm::Size size) {
  63. size_ = size;
  64. }
  65. cdm::Size VideoFrameImpl::Size() const {
  66. return size_;
  67. }
  68. void VideoFrameImpl::SetFrameBuffer(cdm::Buffer* frame_buffer) {
  69. frame_buffer_ = frame_buffer;
  70. }
  71. cdm::Buffer* VideoFrameImpl::FrameBuffer() {
  72. return frame_buffer_;
  73. }
  74. void VideoFrameImpl::SetPlaneOffset(cdm::VideoPlane plane, uint32_t offset) {
  75. DCHECK(plane < cdm::kMaxPlanes);
  76. plane_offsets_[plane] = offset;
  77. }
  78. uint32_t VideoFrameImpl::PlaneOffset(cdm::VideoPlane plane) {
  79. DCHECK(plane < cdm::kMaxPlanes);
  80. return plane_offsets_[plane];
  81. }
  82. void VideoFrameImpl::SetStride(cdm::VideoPlane plane, uint32_t stride) {
  83. DCHECK(plane < cdm::kMaxPlanes);
  84. strides_[plane] = stride;
  85. }
  86. uint32_t VideoFrameImpl::Stride(cdm::VideoPlane plane) {
  87. DCHECK(plane < cdm::kMaxPlanes);
  88. return strides_[plane];
  89. }
  90. void VideoFrameImpl::SetTimestamp(int64_t timestamp) {
  91. timestamp_ = timestamp;
  92. }
  93. int64_t VideoFrameImpl::Timestamp() const {
  94. return timestamp_;
  95. }
  96. void VideoFrameImpl::SetColorSpace(cdm::ColorSpace color_space) {
  97. color_space_ = color_space;
  98. }
  99. media::VideoColorSpace VideoFrameImpl::MediaColorSpace() const {
  100. return media::VideoColorSpace(
  101. color_space_.primary_id, color_space_.transfer_id, color_space_.matrix_id,
  102. ToGfxColorSpaceRange(color_space_.range));
  103. }
  104. AudioFramesImpl::AudioFramesImpl()
  105. : buffer_(nullptr), format_(cdm::kUnknownAudioFormat) {}
  106. AudioFramesImpl::~AudioFramesImpl() {
  107. if (buffer_)
  108. buffer_->Destroy();
  109. }
  110. void AudioFramesImpl::SetFrameBuffer(cdm::Buffer* buffer) {
  111. buffer_ = buffer;
  112. }
  113. cdm::Buffer* AudioFramesImpl::FrameBuffer() {
  114. return buffer_;
  115. }
  116. void AudioFramesImpl::SetFormat(cdm::AudioFormat format) {
  117. format_ = format;
  118. }
  119. cdm::AudioFormat AudioFramesImpl::Format() const {
  120. return format_;
  121. }
  122. cdm::Buffer* AudioFramesImpl::PassFrameBuffer() {
  123. cdm::Buffer* temp_buffer = buffer_;
  124. buffer_ = nullptr;
  125. return temp_buffer;
  126. }
  127. } // namespace media