Shaka Player Embedded
Main Page
Exported Types
+
Tutorials
Basic Tutorial
Network Filters
Internal Docs
+
Internal Class List
Class List
Class Index
Class Hierarchy
+
Class Members
+
All
:
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
~
+
Functions
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
~
+
Variables
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
+
Typedefs
a
b
d
e
f
h
i
l
m
r
s
t
v
Enumerations
+
Enumerator
a
b
c
d
e
k
n
p
t
v
+
Properties
a
b
c
d
e
f
g
h
i
k
l
m
o
p
r
s
t
u
v
w
+
Related Functions
:
a
c
d
g
j
m
o
p
r
s
v
w
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
shaka
src
public
shaka_utils.cc
Go to the documentation of this file.
1
// Copyright 2018 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// https://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#include <glog/logging.h>
16
17
#include <algorithm>
18
19
#include "
shaka/utils.h
"
20
21
namespace
shaka
{
22
23
void
FitVideoToRegion
(
ShakaRect<uint32_t>
frame
,
ShakaRect<uint32_t>
bounds,
24
Rational<uint32_t>
sample_aspect_ratio,
25
VideoFillMode
mode,
ShakaRect<uint32_t>
* src,
26
ShakaRect<uint32_t>
*
dest
) {
27
if
(!sample_aspect_ratio)
28
sample_aspect_ratio =
Rational<uint32_t>
{1, 1};
29
30
switch
(mode) {
31
// Stretch video to fill screen.
32
case
VideoFillMode::Stretch
:
33
*src =
frame
;
34
*dest = bounds;
35
break
;
36
37
// Crop video to maintain aspect ratio while filling the screen.
38
case
VideoFillMode::Zoom
: {
39
*dest = bounds;
40
const
Rational<uint32_t>
bounds_ratio{bounds.
w
, bounds.
h
};
41
// We either use the whole width or the whole height; the other dimension
42
// gets cropped based on the aspect ratio.
43
// Convert number of pixels to image size, then use display aspect ratio.
44
src->
w
= std::min(
45
frame.
w
, (frame.
h
/ sample_aspect_ratio * bounds_ratio).truncate());
46
src->
h
= std::min(
47
frame.
h
, (frame.
w
* sample_aspect_ratio / bounds_ratio).truncate());
48
break
;
49
}
50
51
// Add black boxes around video to maintain aspect ratio.
52
case
VideoFillMode::MaintainRatio
: {
53
*src =
frame
;
54
const
Rational<uint32_t>
aspect_ratio =
55
Rational<uint32_t>
{frame.
w
, frame.
h
} * sample_aspect_ratio;
56
// Get the width based on the height and the display aspect ratio.
57
dest->
w
= std::min(bounds.
w
, (bounds.
h
* aspect_ratio).truncate());
58
dest->
h
= std::min(bounds.
h
, (bounds.
w
/ aspect_ratio).truncate());
59
DCHECK(dest->
w
== bounds.
w
|| dest->
h
== bounds.
h
);
60
break
;
61
}
62
63
default
:
64
LOG(FATAL) <<
"Unknown video fill mode: "
<<
static_cast<
int
>
(mode);
65
}
66
67
// Center the rect within its region.
68
src->
x
= frame.
x
+ (frame.
w
- src->
w
) / 2;
69
src->
y
= frame.
y
+ (frame.
h
- src->
h
) / 2;
70
dest->
x
= bounds.
x
+ (bounds.
w
- dest->
w
) / 2;
71
dest->
y
= bounds.
y
+ (bounds.
h
- dest->
h
) / 2;
72
73
// Should always produce a sub-region of the input bounds.
74
DCHECK_GE(src->
x
, frame.
x
);
75
DCHECK_GE(src->
y
, frame.
y
);
76
DCHECK_LE(src->
x
+ src->
w
, frame.
x
+ frame.
w
);
77
DCHECK_LE(src->
y
+ src->
h
, frame.
y
+ frame.
h
);
78
DCHECK_GE(dest->
x
, bounds.
x
);
79
DCHECK_GE(dest->
y
, bounds.
y
);
80
DCHECK_LE(dest->
x
+ dest->
w
, bounds.
x
+ bounds.
w
);
81
DCHECK_LE(dest->
y
+ dest->
h
, bounds.
y
+ bounds.
h
);
82
}
83
84
}
// namespace shaka
utils.h
dest
const char * dest
Definition:
media_utils.cc:31
shaka::Rational< uint32_t >
shaka::VideoFillMode
VideoFillMode
Definition:
utils.h:41
frame
std::shared_ptr< shaka::media::DecodedFrame > frame
Definition:
apple_video_renderer.cc:27
shaka::ShakaRect
Definition:
utils.h:68
shaka
Definition:
async_results.h:25
shaka::ShakaRect::h
T h
Definition:
utils.h:72
shaka::ShakaRect::y
T y
Definition:
utils.h:70
shaka::ShakaRect::w
T w
Definition:
utils.h:71
shaka::ShakaRect::x
T x
Definition:
utils.h:69
shaka::VideoFillMode::Stretch
shaka::FitVideoToRegion
void FitVideoToRegion(ShakaRect< uint32_t > frame, ShakaRect< uint32_t > bounds, Rational< uint32_t > sample_aspect_ratio, VideoFillMode mode, ShakaRect< uint32_t > *src, ShakaRect< uint32_t > *dest)
Definition:
shaka_utils.cc:23
shaka::VideoFillMode::Zoom
shaka::VideoFillMode::MaintainRatio
Generated by
1.8.13