1 /* 2 * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "modules/rtp_rtcp/source/rtp_packetizer_av1_test_helper.h" 12 13 #include <stdint.h> 14 15 #include <initializer_list> 16 #include <vector> 17 18 namespace webrtc { 19 Av1Obu(uint8_t obu_type)20Av1Obu::Av1Obu(uint8_t obu_type) : header_(obu_type | kAv1ObuSizePresentBit) {} 21 WithExtension(uint8_t extension)22Av1Obu& Av1Obu::WithExtension(uint8_t extension) { 23 extension_ = extension; 24 header_ |= kAv1ObuExtensionPresentBit; 25 return *this; 26 } WithoutSize()27Av1Obu& Av1Obu::WithoutSize() { 28 header_ &= ~kAv1ObuSizePresentBit; 29 return *this; 30 } WithPayload(std::vector<uint8_t> payload)31Av1Obu& Av1Obu::WithPayload(std::vector<uint8_t> payload) { 32 payload_ = std::move(payload); 33 return *this; 34 } 35 BuildAv1Frame(std::initializer_list<Av1Obu> obus)36std::vector<uint8_t> BuildAv1Frame(std::initializer_list<Av1Obu> obus) { 37 std::vector<uint8_t> raw; 38 for (const Av1Obu& obu : obus) { 39 raw.push_back(obu.header_); 40 if (obu.header_ & kAv1ObuExtensionPresentBit) { 41 raw.push_back(obu.extension_); 42 } 43 if (obu.header_ & kAv1ObuSizePresentBit) { 44 // write size in leb128 format. 45 size_t payload_size = obu.payload_.size(); 46 while (payload_size >= 0x80) { 47 raw.push_back(0x80 | (payload_size & 0x7F)); 48 payload_size >>= 7; 49 } 50 raw.push_back(payload_size); 51 } 52 raw.insert(raw.end(), obu.payload_.begin(), obu.payload_.end()); 53 } 54 return raw; 55 } 56 57 } // namespace webrtc 58