xref: /aosp_15_r20/external/webrtc/modules/audio_coding/neteq/tools/constant_pcm_packet_source.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2014 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_CONSTANT_PCM_PACKET_SOURCE_H_
12 #define MODULES_AUDIO_CODING_NETEQ_TOOLS_CONSTANT_PCM_PACKET_SOURCE_H_
13 
14 #include <stdio.h>
15 
16 #include <string>
17 
18 #include "modules/audio_coding/neteq/tools/packet_source.h"
19 
20 namespace webrtc {
21 namespace test {
22 
23 // This class implements a packet source that delivers PCM16b encoded packets
24 // with a constant sample value. The payload length, constant sample value,
25 // sample rate, and payload type are all set in the constructor.
26 class ConstantPcmPacketSource : public PacketSource {
27  public:
28   ConstantPcmPacketSource(size_t payload_len_samples,
29                           int16_t sample_value,
30                           int sample_rate_hz,
31                           int payload_type);
32 
33   ConstantPcmPacketSource(const ConstantPcmPacketSource&) = delete;
34   ConstantPcmPacketSource& operator=(const ConstantPcmPacketSource&) = delete;
35 
36   std::unique_ptr<Packet> NextPacket() override;
37 
38  private:
39   void WriteHeader(uint8_t* packet_memory);
40 
41   const size_t kHeaderLenBytes = 12;
42   const size_t payload_len_samples_;
43   const size_t packet_len_bytes_;
44   uint8_t encoded_sample_[2];
45   const int samples_per_ms_;
46   double next_arrival_time_ms_;
47   const int payload_type_;
48   uint16_t seq_number_;
49   uint32_t timestamp_;
50   const uint32_t payload_ssrc_;
51 };
52 
53 }  // namespace test
54 }  // namespace webrtc
55 #endif  // MODULES_AUDIO_CODING_NETEQ_TOOLS_CONSTANT_PCM_PACKET_SOURCE_H_
56