xref: /aosp_15_r20/external/webrtc/modules/audio_coding/test/EncodeDecodeTest.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_TEST_ENCODEDECODETEST_H_
12 #define MODULES_AUDIO_CODING_TEST_ENCODEDECODETEST_H_
13 
14 #include <stdio.h>
15 #include <string.h>
16 
17 #include "absl/strings/string_view.h"
18 #include "modules/audio_coding/include/audio_coding_module.h"
19 #include "modules/audio_coding/test/PCMFile.h"
20 #include "modules/audio_coding/test/RTPFile.h"
21 #include "modules/include/module_common_types.h"
22 
23 namespace webrtc {
24 
25 #define MAX_INCOMING_PAYLOAD 8096
26 
27 // TestPacketization callback which writes the encoded payloads to file
28 class TestPacketization : public AudioPacketizationCallback {
29  public:
30   TestPacketization(RTPStream* rtpStream, uint16_t frequency);
31   ~TestPacketization();
32   int32_t SendData(AudioFrameType frameType,
33                    uint8_t payloadType,
34                    uint32_t timeStamp,
35                    const uint8_t* payloadData,
36                    size_t payloadSize,
37                    int64_t absolute_capture_timestamp_ms) override;
38 
39  private:
40   static void MakeRTPheader(uint8_t* rtpHeader,
41                             uint8_t payloadType,
42                             int16_t seqNo,
43                             uint32_t timeStamp,
44                             uint32_t ssrc);
45   RTPStream* _rtpStream;
46   int32_t _frequency;
47   int16_t _seqNo;
48 };
49 
50 class Sender {
51  public:
52   Sender();
53   void Setup(AudioCodingModule* acm,
54              RTPStream* rtpStream,
55              absl::string_view in_file_name,
56              int in_sample_rate,
57              int payload_type,
58              SdpAudioFormat format);
59   void Teardown();
60   void Run();
61   bool Add10MsData();
62 
63  protected:
64   AudioCodingModule* _acm;
65 
66  private:
67   PCMFile _pcmFile;
68   AudioFrame _audioFrame;
69   TestPacketization* _packetization;
70 };
71 
72 class Receiver {
73  public:
74   Receiver();
~Receiver()75   virtual ~Receiver() {}
76   void Setup(AudioCodingModule* acm,
77              RTPStream* rtpStream,
78              absl::string_view out_file_name,
79              size_t channels,
80              int file_num);
81   void Teardown();
82   void Run();
83   virtual bool IncomingPacket();
84   bool PlayoutData();
85 
86  private:
87   PCMFile _pcmFile;
88   int16_t* _playoutBuffer;
89   uint16_t _playoutLengthSmpls;
90   int32_t _frequency;
91   bool _firstTime;
92 
93  protected:
94   AudioCodingModule* _acm;
95   uint8_t _incomingPayload[MAX_INCOMING_PAYLOAD];
96   RTPStream* _rtpStream;
97   RTPHeader _rtpHeader;
98   size_t _realPayloadSizeBytes;
99   size_t _payloadSizeBytes;
100   uint32_t _nextTime;
101 };
102 
103 class EncodeDecodeTest {
104  public:
105   EncodeDecodeTest();
106   void Perform();
107 };
108 
109 }  // namespace webrtc
110 
111 #endif  // MODULES_AUDIO_CODING_TEST_ENCODEDECODETEST_H_
112