1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
media / cdm / cdm_helpers.cc [blame]
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif
#include "media/cdm/cdm_helpers.h"
#include "base/check.h"
#include "ui/gfx/color_space.h"
namespace media {
namespace {
// See ISO 23001-8:2016, section 7. Value 2 means "Unspecified".
constexpr cdm::ColorSpace kUnspecifiedColorSpace = {2, 2, 2,
cdm::ColorRange::kInvalid};
gfx::ColorSpace::RangeID ToGfxColorSpaceRange(cdm::ColorRange range) {
switch (range) {
case cdm::ColorRange::kInvalid:
return gfx::ColorSpace::RangeID::INVALID;
case cdm::ColorRange::kLimited:
return gfx::ColorSpace::RangeID::LIMITED;
case cdm::ColorRange::kFull:
return gfx::ColorSpace::RangeID::FULL;
case cdm::ColorRange::kDerived:
return gfx::ColorSpace::RangeID::DERIVED;
}
}
} // namespace
DecryptedBlockImpl::DecryptedBlockImpl() : buffer_(nullptr), timestamp_(0) {}
DecryptedBlockImpl::~DecryptedBlockImpl() {
if (buffer_)
buffer_.ExtractAsDangling()->Destroy();
}
void DecryptedBlockImpl::SetDecryptedBuffer(cdm::Buffer* buffer) {
buffer_ = buffer;
}
cdm::Buffer* DecryptedBlockImpl::DecryptedBuffer() {
return buffer_;
}
void DecryptedBlockImpl::SetTimestamp(int64_t timestamp) {
timestamp_ = timestamp;
}
int64_t DecryptedBlockImpl::Timestamp() const {
return timestamp_;
}
VideoFrameImpl::VideoFrameImpl()
: format_(cdm::kUnknownVideoFormat),
color_space_(kUnspecifiedColorSpace),
frame_buffer_(nullptr),
timestamp_(0) {
for (uint32_t i = 0; i < cdm::kMaxPlanes; ++i) {
plane_offsets_[i] = 0;
strides_[i] = 0;
}
}
VideoFrameImpl::~VideoFrameImpl() {
if (frame_buffer_)
frame_buffer_.ExtractAsDangling()->Destroy();
}
void VideoFrameImpl::SetFormat(cdm::VideoFormat format) {
format_ = format;
}
cdm::VideoFormat VideoFrameImpl::Format() const {
return format_;
}
void VideoFrameImpl::SetSize(cdm::Size size) {
size_ = size;
}
cdm::Size VideoFrameImpl::Size() const {
return size_;
}
void VideoFrameImpl::SetFrameBuffer(cdm::Buffer* frame_buffer) {
frame_buffer_ = frame_buffer;
}
cdm::Buffer* VideoFrameImpl::FrameBuffer() {
return frame_buffer_;
}
void VideoFrameImpl::SetPlaneOffset(cdm::VideoPlane plane, uint32_t offset) {
DCHECK(plane < cdm::kMaxPlanes);
plane_offsets_[plane] = offset;
}
uint32_t VideoFrameImpl::PlaneOffset(cdm::VideoPlane plane) {
DCHECK(plane < cdm::kMaxPlanes);
return plane_offsets_[plane];
}
void VideoFrameImpl::SetStride(cdm::VideoPlane plane, uint32_t stride) {
DCHECK(plane < cdm::kMaxPlanes);
strides_[plane] = stride;
}
uint32_t VideoFrameImpl::Stride(cdm::VideoPlane plane) {
DCHECK(plane < cdm::kMaxPlanes);
return strides_[plane];
}
void VideoFrameImpl::SetTimestamp(int64_t timestamp) {
timestamp_ = timestamp;
}
int64_t VideoFrameImpl::Timestamp() const {
return timestamp_;
}
void VideoFrameImpl::SetColorSpace(cdm::ColorSpace color_space) {
color_space_ = color_space;
}
media::VideoColorSpace VideoFrameImpl::MediaColorSpace() const {
return media::VideoColorSpace(
color_space_.primary_id, color_space_.transfer_id, color_space_.matrix_id,
ToGfxColorSpaceRange(color_space_.range));
}
AudioFramesImpl::AudioFramesImpl()
: buffer_(nullptr), format_(cdm::kUnknownAudioFormat) {}
AudioFramesImpl::~AudioFramesImpl() {
if (buffer_)
buffer_.ExtractAsDangling()->Destroy();
}
void AudioFramesImpl::SetFrameBuffer(cdm::Buffer* buffer) {
buffer_ = buffer;
}
cdm::Buffer* AudioFramesImpl::FrameBuffer() {
return buffer_;
}
void AudioFramesImpl::SetFormat(cdm::AudioFormat format) {
format_ = format;
}
cdm::AudioFormat AudioFramesImpl::Format() const {
return format_;
}
cdm::Buffer* AudioFramesImpl::PassFrameBuffer() {
cdm::Buffer* temp_buffer = buffer_;
buffer_ = nullptr;
return temp_buffer;
}
} // namespace media