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