-
Notifications
You must be signed in to change notification settings - Fork 121
/
video_encoder_active_map.cc
65 lines (51 loc) · 2.13 KB
/
video_encoder_active_map.cc
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
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "remoting/codec/video_encoder_active_map.h"
#include <algorithm>
#include <utility>
#include <string.h>
#include "base/check_op.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_region.h"
using DesktopRegionIterator = webrtc::DesktopRegion::Iterator;
namespace {
// Defines the dimension of a macro block. This is used to compute the active
// map for an encoder. This size is the same for VP8, VP9, and AV1 encoders.
constexpr int kMacroBlockSize = 16;
} // namespace
namespace remoting {
VideoEncoderActiveMap::VideoEncoderActiveMap() = default;
VideoEncoderActiveMap::~VideoEncoderActiveMap() = default;
void VideoEncoderActiveMap::Initialize(const webrtc::DesktopSize& size) {
active_map_size_.set((size.width() + kMacroBlockSize - 1) / kMacroBlockSize,
(size.height() + kMacroBlockSize - 1) / kMacroBlockSize);
active_map_ = std::make_unique<uint8_t[]>(active_map_size_.width() *
active_map_size_.height());
Clear();
}
void VideoEncoderActiveMap::Clear() {
DCHECK(active_map_);
memset(active_map_.get(), 0,
active_map_size_.width() * active_map_size_.height());
}
void VideoEncoderActiveMap::Update(
const webrtc::DesktopRegion& updated_region) {
for (DesktopRegionIterator r(updated_region); !r.IsAtEnd(); r.Advance()) {
const webrtc::DesktopRect& rect = r.rect();
int left = rect.left() / kMacroBlockSize;
int right = (rect.right() - 1) / kMacroBlockSize;
int top = rect.top() / kMacroBlockSize;
int bottom = (rect.bottom() - 1) / kMacroBlockSize;
DCHECK_LT(right, active_map_size_.width());
DCHECK_LT(bottom, active_map_size_.height());
uint8_t* map = active_map_.get() + top * active_map_size_.width();
for (int y = top; y <= bottom; ++y) {
for (int x = left; x <= right; ++x) {
map[x] = 1;
}
map += active_map_size_.width();
}
}
}
} // namespace remoting