blob: 3d62bcef44affda39612881745ecb9e040376295 (
plain)
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
|
/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "modules/rtp_rtcp/source/rtp_packetizer_av1_test_helper.h"
#include <stdint.h>
#include <initializer_list>
#include <vector>
namespace webrtc {
Av1Obu::Av1Obu(uint8_t obu_type) : header_(obu_type | kAv1ObuSizePresentBit) {}
Av1Obu& Av1Obu::WithExtension(uint8_t extension) {
extension_ = extension;
header_ |= kAv1ObuExtensionPresentBit;
return *this;
}
Av1Obu& Av1Obu::WithoutSize() {
header_ &= ~kAv1ObuSizePresentBit;
return *this;
}
Av1Obu& Av1Obu::WithPayload(std::vector<uint8_t> payload) {
payload_ = std::move(payload);
return *this;
}
std::vector<uint8_t> BuildAv1Frame(std::initializer_list<Av1Obu> obus) {
std::vector<uint8_t> raw;
for (const Av1Obu& obu : obus) {
raw.push_back(obu.header_);
if (obu.header_ & kAv1ObuExtensionPresentBit) {
raw.push_back(obu.extension_);
}
if (obu.header_ & kAv1ObuSizePresentBit) {
// write size in leb128 format.
size_t payload_size = obu.payload_.size();
while (payload_size >= 0x80) {
raw.push_back(0x80 | (payload_size & 0x7F));
payload_size >>= 7;
}
raw.push_back(payload_size);
}
raw.insert(raw.end(), obu.payload_.begin(), obu.payload_.end());
}
return raw;
}
} // namespace webrtc
|