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