xref: /aosp_15_r20/external/webrtc/modules/audio_coding/neteq/tools/rtp_generator.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2012 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 MODULES_AUDIO_CODING_NETEQ_TOOLS_RTP_GENERATOR_H_
12 #define MODULES_AUDIO_CODING_NETEQ_TOOLS_RTP_GENERATOR_H_
13 
14 #include "api/rtp_headers.h"
15 
16 namespace webrtc {
17 namespace test {
18 
19 // Class for generating RTP headers.
20 class RtpGenerator {
21  public:
22   RtpGenerator(int samples_per_ms,
23                uint16_t start_seq_number = 0,
24                uint32_t start_timestamp = 0,
25                uint32_t start_send_time_ms = 0,
26                uint32_t ssrc = 0x12345678)
seq_number_(start_seq_number)27       : seq_number_(start_seq_number),
28         timestamp_(start_timestamp),
29         next_send_time_ms_(start_send_time_ms),
30         ssrc_(ssrc),
31         samples_per_ms_(samples_per_ms),
32         drift_factor_(0.0) {}
33 
~RtpGenerator()34   virtual ~RtpGenerator() {}
35 
36   RtpGenerator(const RtpGenerator&) = delete;
37   RtpGenerator& operator=(const RtpGenerator&) = delete;
38 
39   // Writes the next RTP header to `rtp_header`, which will be of type
40   // `payload_type`. Returns the send time for this packet (in ms). The value of
41   // `payload_length_samples` determines the send time for the next packet.
42   virtual uint32_t GetRtpHeader(uint8_t payload_type,
43                                 size_t payload_length_samples,
44                                 RTPHeader* rtp_header);
45 
46   void set_drift_factor(double factor);
47 
48  protected:
49   uint16_t seq_number_;
50   uint32_t timestamp_;
51   uint32_t next_send_time_ms_;
52   const uint32_t ssrc_;
53   const int samples_per_ms_;
54   double drift_factor_;
55 };
56 
57 class TimestampJumpRtpGenerator : public RtpGenerator {
58  public:
TimestampJumpRtpGenerator(int samples_per_ms,uint16_t start_seq_number,uint32_t start_timestamp,uint32_t jump_from_timestamp,uint32_t jump_to_timestamp)59   TimestampJumpRtpGenerator(int samples_per_ms,
60                             uint16_t start_seq_number,
61                             uint32_t start_timestamp,
62                             uint32_t jump_from_timestamp,
63                             uint32_t jump_to_timestamp)
64       : RtpGenerator(samples_per_ms, start_seq_number, start_timestamp),
65         jump_from_timestamp_(jump_from_timestamp),
66         jump_to_timestamp_(jump_to_timestamp) {}
67 
68   TimestampJumpRtpGenerator(const TimestampJumpRtpGenerator&) = delete;
69   TimestampJumpRtpGenerator& operator=(const TimestampJumpRtpGenerator&) =
70       delete;
71 
72   uint32_t GetRtpHeader(uint8_t payload_type,
73                         size_t payload_length_samples,
74                         RTPHeader* rtp_header) override;
75 
76  private:
77   uint32_t jump_from_timestamp_;
78   uint32_t jump_to_timestamp_;
79 };
80 
81 }  // namespace test
82 }  // namespace webrtc
83 #endif  // MODULES_AUDIO_CODING_NETEQ_TOOLS_RTP_GENERATOR_H_
84