tor-browser

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

rtp_utils.h (2692B)


      1 /*
      2 *  Copyright (c) 2011 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 #ifndef MEDIA_BASE_RTP_UTILS_H_
     12 #define MEDIA_BASE_RTP_UTILS_H_
     13 
     14 #include <cstddef>
     15 #include <cstdint>
     16 
     17 #include "absl/strings/string_view.h"
     18 #include "api/array_view.h"
     19 #include "rtc_base/async_packet_socket.h"
     20 #include "rtc_base/system/rtc_export.h"
     21 
     22 namespace webrtc {
     23 
     24 const size_t kMinRtpPacketLen = 12;
     25 const size_t kMaxRtpPacketLen = 2048;
     26 const size_t kMinRtcpPacketLen = 4;
     27 
     28 enum RtcpTypes {
     29  kRtcpTypeSR = 200,     // Sender report payload type.
     30  kRtcpTypeRR = 201,     // Receiver report payload type.
     31  kRtcpTypeSDES = 202,   // SDES payload type.
     32  kRtcpTypeBye = 203,    // BYE payload type.
     33  kRtcpTypeApp = 204,    // APP payload type.
     34  kRtcpTypeRTPFB = 205,  // Transport layer Feedback message payload type.
     35  kRtcpTypePSFB = 206,   // Payload-specific Feedback message payload type.
     36 };
     37 
     38 enum class RtpPacketType {
     39  kRtp,
     40  kRtcp,
     41  kUnknown,
     42 };
     43 
     44 bool GetRtcpType(const void* data, size_t len, int* value);
     45 bool GetRtcpSsrc(const void* data, size_t len, uint32_t* value);
     46 
     47 // Checks the packet header to determine if it can be an RTP or RTCP packet.
     48 RtpPacketType InferRtpPacketType(ArrayView<const uint8_t> packet);
     49 // True if |payload type| is 0-127.
     50 bool IsValidRtpPayloadType(int payload_type);
     51 
     52 // True if `size` is appropriate for the indicated packet type.
     53 bool IsValidRtpPacketSize(RtpPacketType packet_type, size_t size);
     54 
     55 // Returns "RTCP", "RTP" or "Unknown" according to `packet_type`.
     56 absl::string_view RtpPacketTypeToString(RtpPacketType packet_type);
     57 
     58 // Verifies that a packet has a valid RTP header.
     59 bool RTC_EXPORT ValidateRtpHeader(ArrayView<const uint8_t> rtp,
     60                                  size_t* header_length);
     61 
     62 // Helper method which updates the absolute send time extension if present.
     63 bool UpdateRtpAbsSendTimeExtension(ArrayView<uint8_t> rtp,
     64                                   int extension_id,
     65                                   uint64_t time_us);
     66 
     67 // Applies specified `options` to the packet. It updates the absolute send time
     68 // extension header if it is present present then updates HMAC.
     69 bool RTC_EXPORT
     70 ApplyPacketOptions(ArrayView<uint8_t> data,
     71                   const PacketTimeUpdateParams& packet_time_params,
     72                   uint64_t time_us);
     73 
     74 }  //  namespace webrtc
     75 
     76 
     77 #endif  // MEDIA_BASE_RTP_UTILS_H_