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
170
171
172
ash / components / arc / mojom / video_encode_accelerator_mojom_traits.cc [blame]
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/components/arc/mojom/video_encode_accelerator_mojom_traits.h"
#include <optional>
#include "ash/components/arc/mojom/video_accelerator_mojom_traits.h"
namespace mojo {
// static
arc::mojom::VideoFrameStorageType
EnumTraits<arc::mojom::VideoFrameStorageType,
media::VideoEncodeAccelerator::Config::StorageType>::
ToMojom(media::VideoEncodeAccelerator::Config::StorageType input) {
NOTIMPLEMENTED();
return arc::mojom::VideoFrameStorageType::SHMEM;
}
bool EnumTraits<arc::mojom::VideoFrameStorageType,
media::VideoEncodeAccelerator::Config::StorageType>::
FromMojom(arc::mojom::VideoFrameStorageType input,
media::VideoEncodeAccelerator::Config::StorageType* output) {
switch (input) {
case arc::mojom::VideoFrameStorageType::SHMEM:
*output = media::VideoEncodeAccelerator::Config::StorageType::kShmem;
return true;
case arc::mojom::VideoFrameStorageType::DMABUF:
*output =
media::VideoEncodeAccelerator::Config::StorageType::kGpuMemoryBuffer;
return true;
}
return false;
}
// static
uint32_t
StructTraits<arc::mojom::ConstantBitrateDataView, arc::mojom::ConstantBitrate>::
target(const arc::mojom::ConstantBitrate& input) {
return input.target;
}
// static
uint32_t
StructTraits<arc::mojom::VariableBitrateDataView, arc::mojom::VariableBitrate>::
target(const arc::mojom::VariableBitrate& input) {
return input.target;
}
// static
uint32_t
StructTraits<arc::mojom::VariableBitrateDataView, arc::mojom::VariableBitrate>::
peak(const arc::mojom::VariableBitrate& input) {
return input.peak;
}
// static
arc::mojom::BitrateDataView::Tag
UnionTraits<arc::mojom::BitrateDataView, media::Bitrate>::GetTag(
const media::Bitrate& input) {
switch (input.mode()) {
case media::Bitrate::Mode::kConstant:
return arc::mojom::BitrateDataView::Tag::kConstant;
case media::Bitrate::Mode::kVariable:
return arc::mojom::BitrateDataView::Tag::kVariable;
case media::Bitrate::Mode::kExternal:
// Ash encoder doesn't need to support external rate control.
NOTREACHED();
}
NOTREACHED();
}
// static
arc::mojom::ConstantBitrate
UnionTraits<arc::mojom::BitrateDataView, media::Bitrate>::constant(
const media::Bitrate& input) {
arc::mojom::ConstantBitrate constant_bitrate;
constant_bitrate.target = input.target_bps();
return constant_bitrate;
}
// static
arc::mojom::VariableBitrate
UnionTraits<arc::mojom::BitrateDataView, media::Bitrate>::variable(
const media::Bitrate& input) {
arc::mojom::VariableBitrate variable_bitrate;
variable_bitrate.target = input.target_bps();
variable_bitrate.peak = input.peak_bps();
return variable_bitrate;
}
// static
bool UnionTraits<arc::mojom::BitrateDataView, media::Bitrate>::Read(
arc::mojom::BitrateDataView input,
media::Bitrate* output) {
switch (input.tag()) {
case arc::mojom::BitrateDataView::Tag::kConstant: {
arc::mojom::ConstantBitrateDataView constant_bitrate;
input.GetConstantDataView(&constant_bitrate);
*output = media::Bitrate::ConstantBitrate(constant_bitrate.target());
return true;
}
case arc::mojom::BitrateDataView::Tag::kVariable: {
arc::mojom::VariableBitrateDataView variable_bitrate;
input.GetVariableDataView(&variable_bitrate);
*output = media::Bitrate::VariableBitrate(variable_bitrate.target(),
variable_bitrate.peak());
return true;
}
default:
NOTREACHED();
}
}
// static
bool StructTraits<arc::mojom::VideoEncodeAcceleratorConfigDataView,
media::VideoEncodeAccelerator::Config>::
Read(arc::mojom::VideoEncodeAcceleratorConfigDataView input,
media::VideoEncodeAccelerator::Config* output) {
media::VideoPixelFormat input_format;
if (!input.ReadInputFormat(&input_format))
return false;
gfx::Size input_visible_size;
if (!input.ReadInputVisibleSize(&input_visible_size))
return false;
media::VideoCodecProfile output_profile;
if (!input.ReadOutputProfile(&output_profile))
return false;
std::optional<uint32_t> initial_framerate;
if (input.has_initial_framerate_deprecated()) {
initial_framerate = input.initial_framerate();
}
std::optional<uint8_t> h264_output_level;
if (input.has_h264_output_level()) {
h264_output_level = input.h264_output_level();
}
media::VideoEncodeAccelerator::Config::StorageType storage_type;
if (!input.ReadStorageType(&storage_type))
return false;
std::optional<media::Bitrate> bitrate;
if (!input.ReadBitrate(&bitrate))
return false;
if (bitrate.has_value()) {
DCHECK((bitrate->mode() == media::Bitrate::Mode::kVariable) ||
(bitrate->peak_bps() == 0u));
DCHECK((bitrate->mode() == media::Bitrate::Mode::kConstant) ||
(bitrate->peak_bps() >= bitrate->target_bps()));
} else {
bitrate =
media::Bitrate::ConstantBitrate(input.initial_bitrate_deprecated());
}
*output = media::VideoEncodeAccelerator::Config(
input_format, input_visible_size, output_profile, *bitrate,
initial_framerate.value_or(
media::VideoEncodeAccelerator::kDefaultFramerate),
storage_type,
media::VideoEncodeAccelerator::Config::ContentType::kCamera);
output->h264_output_level = h264_output_level;
return true;
}
} // namespace mojo