/* * Copyright (c) 2019 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/video_rtp_depacketizer_av1.h" #include <stddef.h> #include <stdint.h> #include <utility> #include "modules/rtp_rtcp/source/leb128.h" #include "modules/rtp_rtcp/source/rtp_video_header.h" #include "rtc_base/byte_buffer.h" #include "rtc_base/checks.h" #include "rtc_base/logging.h" #include "rtc_base/numerics/safe_conversions.h" namespace webrtc { namespace { // AV1 format: // // RTP payload syntax: // 0 1 2 3 4 5 6 7 // +-+-+-+-+-+-+-+-+ // |Z|Y| W |N|-|-|-| (REQUIRED) // +=+=+=+=+=+=+=+=+ (REPEATED W-1 times, or any times if W = 0) // |1| | // +-+ OBU fragment| // |1| | (REQUIRED, leb128 encoded) // +-+ size | // |0| | // +-+-+-+-+-+-+-+-+ // | OBU fragment | // | ... | // +=+=+=+=+=+=+=+=+ // | ... | // +=+=+=+=+=+=+=+=+ if W > 0, last fragment MUST NOT have size field // | OBU fragment | // | ... | // +=+=+=+=+=+=+=+=+ // // // OBU syntax: // 0 1 2 3 4 5 6 7 // +-+-+-+-+-+-+-+-+ // |0| type |X|S|-| (REQUIRED) // +-+-+-+-+-+-+-+-+ // X: | TID |SID|-|-|-| (OPTIONAL) // +-+-+-+-+-+-+-+-+ // |1| | // +-+ OBU payload | // S: |1| | (OPTIONAL, variable length leb128 encoded) // +-+ size | // |0| | // +-+-+-+-+-+-+-+-+ // | OBU payload | // | ... | class ArrayOfArrayViews { … }; class ArrayOfArrayViews::const_iterator { … }; ArrayOfArrayViews::const_iterator ArrayOfArrayViews::begin() const { … } ArrayOfArrayViews::const_iterator ArrayOfArrayViews::end() const { … } void ArrayOfArrayViews::CopyTo(uint8_t* destination, const_iterator first) const { … } struct ObuInfo { … }; // Expect that majority of the frame won't use more than 4 obus. // In a simple stream delta frame consist of single Frame OBU, while key frame // also has Sequence Header OBU. VectorObuInfo; constexpr uint8_t kObuSizePresentBit = …; bool ObuHasExtension(uint8_t obu_header) { … } bool ObuHasSize(uint8_t obu_header) { … } bool RtpStartsWithFragment(uint8_t aggregation_header) { … } bool RtpEndsWithFragment(uint8_t aggregation_header) { … } int RtpNumObus(uint8_t aggregation_header) { … } int RtpStartsNewCodedVideoSequence(uint8_t aggregation_header) { … } // Reorgonizes array of rtp payloads into array of obus: // fills ObuInfo::data field. // Returns empty vector on error. VectorObuInfo ParseObus( rtc::ArrayView<const rtc::ArrayView<const uint8_t>> rtp_payloads) { … } // Calculates sizes for the Obu, i.e. base on ObuInfo::data field calculates // all other fields in the ObuInfo structure. // Returns false if obu found to be misformed. bool CalculateObuSizes(ObuInfo* obu_info) { … } } // namespace rtc::scoped_refptr<EncodedImageBuffer> VideoRtpDepacketizerAv1::AssembleFrame( rtc::ArrayView<const rtc::ArrayView<const uint8_t>> rtp_payloads) { … } absl::optional<VideoRtpDepacketizer::ParsedRtpPayload> VideoRtpDepacketizerAv1::Parse(rtc::CopyOnWriteBuffer rtp_payload) { … } } // namespace webrtc