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