tor-browser

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

rtp_generator.cc (2152B)


      1 /*
      2 *  Copyright (c) 2013 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/audio_coding/neteq/tools/rtp_generator.h"
     12 
     13 #include <cstddef>
     14 #include <cstdint>
     15 
     16 #include "api/rtp_headers.h"
     17 #include "rtc_base/checks.h"
     18 
     19 namespace webrtc {
     20 namespace test {
     21 
     22 uint32_t RtpGenerator::GetRtpHeader(uint8_t payload_type,
     23                                    size_t payload_length_samples,
     24                                    RTPHeader* rtp_header) {
     25  RTC_DCHECK(rtp_header);
     26  if (!rtp_header) {
     27    return 0;
     28  }
     29  rtp_header->sequenceNumber = seq_number_++;
     30  rtp_header->timestamp = timestamp_;
     31  timestamp_ += static_cast<uint32_t>(payload_length_samples);
     32  rtp_header->payloadType = payload_type;
     33  rtp_header->markerBit = false;
     34  rtp_header->ssrc = ssrc_;
     35  rtp_header->numCSRCs = 0;
     36 
     37  uint32_t this_send_time = next_send_time_ms_;
     38  RTC_DCHECK_GT(samples_per_ms_, 0);
     39  next_send_time_ms_ +=
     40      ((1.0 + drift_factor_) * payload_length_samples) / samples_per_ms_;
     41  return this_send_time;
     42 }
     43 
     44 void RtpGenerator::set_drift_factor(double factor) {
     45  if (factor > -1.0) {
     46    drift_factor_ = factor;
     47  }
     48 }
     49 
     50 uint32_t TimestampJumpRtpGenerator::GetRtpHeader(uint8_t payload_type,
     51                                                 size_t payload_length_samples,
     52                                                 RTPHeader* rtp_header) {
     53  uint32_t ret = RtpGenerator::GetRtpHeader(payload_type,
     54                                            payload_length_samples, rtp_header);
     55  if (timestamp_ - static_cast<uint32_t>(payload_length_samples) <=
     56          jump_from_timestamp_ &&
     57      timestamp_ > jump_from_timestamp_) {
     58    // We just moved across the `jump_from_timestamp_` timestamp. Do the jump.
     59    timestamp_ = jump_to_timestamp_;
     60  }
     61  return ret;
     62 }
     63 
     64 }  // namespace test
     65 }  // namespace webrtc