tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

rtp_util.cc (1955B)


      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_util.h"
     12 
     13 #include <cstddef>
     14 #include <cstdint>
     15 
     16 #include "api/array_view.h"
     17 #include "modules/rtp_rtcp/source/byte_io.h"
     18 #include "rtc_base/checks.h"
     19 
     20 namespace webrtc {
     21 namespace {
     22 
     23 constexpr uint8_t kRtpVersion = 2;
     24 constexpr size_t kMinRtpPacketLen = 12;
     25 constexpr size_t kMinRtcpPacketLen = 4;
     26 
     27 bool HasCorrectRtpVersion(ArrayView<const uint8_t> packet) {
     28  return packet[0] >> 6 == kRtpVersion;
     29 }
     30 
     31 // For additional details, see http://tools.ietf.org/html/rfc5761#section-4
     32 bool PayloadTypeIsReservedForRtcp(uint8_t payload_type) {
     33  return 64 <= payload_type && payload_type < 96;
     34 }
     35 
     36 }  // namespace
     37 
     38 bool IsRtpPacket(ArrayView<const uint8_t> packet) {
     39  return packet.size() >= kMinRtpPacketLen && HasCorrectRtpVersion(packet) &&
     40         !PayloadTypeIsReservedForRtcp(packet[1] & 0x7F);
     41 }
     42 
     43 bool IsRtcpPacket(ArrayView<const uint8_t> packet) {
     44  return packet.size() >= kMinRtcpPacketLen && HasCorrectRtpVersion(packet) &&
     45         PayloadTypeIsReservedForRtcp(packet[1] & 0x7F);
     46 }
     47 
     48 int ParseRtpPayloadType(ArrayView<const uint8_t> rtp_packet) {
     49  RTC_DCHECK(IsRtpPacket(rtp_packet));
     50  return rtp_packet[1] & 0x7F;
     51 }
     52 
     53 uint16_t ParseRtpSequenceNumber(ArrayView<const uint8_t> rtp_packet) {
     54  RTC_DCHECK(IsRtpPacket(rtp_packet));
     55  return ByteReader<uint16_t>::ReadBigEndian(rtp_packet.data() + 2);
     56 }
     57 
     58 uint32_t ParseRtpSsrc(ArrayView<const uint8_t> rtp_packet) {
     59  RTC_DCHECK(IsRtpPacket(rtp_packet));
     60  return ByteReader<uint32_t>::ReadBigEndian(rtp_packet.data() + 8);
     61 }
     62 
     63 }  // namespace webrtc