niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
tina.legrand@webrtc.org | 16b6b90 | 2012-04-12 11:02:38 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_CODING_TEST_ENCODEDECODETEST_H_ |
| 12 | #define MODULES_AUDIO_CODING_TEST_ENCODEDECODETEST_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 14 | #include <stdio.h> |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 15 | #include <string.h> |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 16 | |
Ali Tofigh | 714e3cb | 2022-07-20 12:53:07 +0200 | [diff] [blame] | 17 | #include "absl/strings/string_view.h" |
Henrik Lundin | 84f7569 | 2023-02-01 12:07:10 +0000 | [diff] [blame] | 18 | #include "modules/audio_coding/acm2/acm_receiver.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "modules/audio_coding/include/audio_coding_module.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "modules/audio_coding/test/PCMFile.h" |
| 21 | #include "modules/audio_coding/test/RTPFile.h" |
Fredrik Solenberg | bbf21a3 | 2018-04-12 22:44:09 +0200 | [diff] [blame] | 22 | #include "modules/include/module_common_types.h" |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | |
| 26 | #define MAX_INCOMING_PAYLOAD 8096 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 28 | // TestPacketization callback which writes the encoded payloads to file |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 29 | class TestPacketization : public AudioPacketizationCallback { |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 30 | public: |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 31 | TestPacketization(RTPStream* rtpStream, uint16_t frequency); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 32 | ~TestPacketization(); |
Ali Tofigh | 6223809 | 2022-01-25 13:27:19 +0100 | [diff] [blame] | 33 | int32_t SendData(AudioFrameType frameType, |
| 34 | uint8_t payloadType, |
| 35 | uint32_t timeStamp, |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 36 | const uint8_t* payloadData, |
Ali Tofigh | 6223809 | 2022-01-25 13:27:19 +0100 | [diff] [blame] | 37 | size_t payloadSize, |
Minyue Li | ff0e4db | 2020-01-23 13:45:50 +0100 | [diff] [blame] | 38 | int64_t absolute_capture_timestamp_ms) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 40 | private: |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 41 | static void MakeRTPheader(uint8_t* rtpHeader, |
| 42 | uint8_t payloadType, |
| 43 | int16_t seqNo, |
| 44 | uint32_t timeStamp, |
| 45 | uint32_t ssrc); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 46 | RTPStream* _rtpStream; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 47 | int32_t _frequency; |
| 48 | int16_t _seqNo; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 51 | class Sender { |
| 52 | public: |
| 53 | Sender(); |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 54 | void Setup(AudioCodingModule* acm, |
| 55 | RTPStream* rtpStream, |
Ali Tofigh | 714e3cb | 2022-07-20 12:53:07 +0200 | [diff] [blame] | 56 | absl::string_view in_file_name, |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 57 | int in_sample_rate, |
| 58 | int payload_type, |
| 59 | SdpAudioFormat format); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 60 | void Teardown(); |
| 61 | void Run(); |
| 62 | bool Add10MsData(); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 63 | |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 64 | protected: |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 65 | AudioCodingModule* _acm; |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 66 | |
| 67 | private: |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 68 | PCMFile _pcmFile; |
| 69 | AudioFrame _audioFrame; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 70 | TestPacketization* _packetization; |
| 71 | }; |
| 72 | |
| 73 | class Receiver { |
| 74 | public: |
| 75 | Receiver(); |
Mirko Bonadei | c4dd730 | 2019-02-25 09:12:02 +0100 | [diff] [blame] | 76 | virtual ~Receiver() {} |
Henrik Lundin | 84f7569 | 2023-02-01 12:07:10 +0000 | [diff] [blame] | 77 | void Setup(acm2::AcmReceiver* acm_receiver, |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 78 | RTPStream* rtpStream, |
Ali Tofigh | 714e3cb | 2022-07-20 12:53:07 +0200 | [diff] [blame] | 79 | absl::string_view out_file_name, |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 80 | size_t channels, |
| 81 | int file_num); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 82 | void Teardown(); |
| 83 | void Run(); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 84 | virtual bool IncomingPacket(); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 85 | bool PlayoutData(); |
| 86 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 87 | private: |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 88 | PCMFile _pcmFile; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 89 | int16_t* _playoutBuffer; |
| 90 | uint16_t _playoutLengthSmpls; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 91 | int32_t _frequency; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 92 | bool _firstTime; |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 93 | |
| 94 | protected: |
Henrik Lundin | 84f7569 | 2023-02-01 12:07:10 +0000 | [diff] [blame] | 95 | acm2::AcmReceiver* _acm_receiver; |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 96 | uint8_t _incomingPayload[MAX_INCOMING_PAYLOAD]; |
| 97 | RTPStream* _rtpStream; |
Niels Möller | bf47495 | 2019-02-18 12:00:06 +0100 | [diff] [blame] | 98 | RTPHeader _rtpHeader; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 99 | size_t _realPayloadSizeBytes; |
| 100 | size_t _payloadSizeBytes; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 101 | uint32_t _nextTime; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 102 | }; |
| 103 | |
Karl Wiberg | 3ff52ff | 2018-10-01 12:31:22 +0200 | [diff] [blame] | 104 | class EncodeDecodeTest { |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 105 | public: |
Fredrik Solenberg | 657b296 | 2018-12-05 10:30:25 +0100 | [diff] [blame] | 106 | EncodeDecodeTest(); |
Karl Wiberg | 3ff52ff | 2018-10-01 12:31:22 +0200 | [diff] [blame] | 107 | void Perform(); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 108 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 109 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 110 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 111 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 112 | #endif // MODULES_AUDIO_CODING_TEST_ENCODEDECODETEST_H_ |