henrik.lundin@webrtc.org | 0e6e4d2 | 2014-09-23 12:05:34 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_CODING_ACM2_ACM_SEND_TEST_H_ |
| 12 | #define MODULES_AUDIO_CODING_ACM2_ACM_SEND_TEST_H_ |
henrik.lundin@webrtc.org | 0e6e4d2 | 2014-09-23 12:05:34 +0000 | [diff] [blame] | 13 | |
kwiberg | 16c5a96 | 2016-02-15 02:27:22 -0800 | [diff] [blame] | 14 | #include <memory> |
henrik.lundin@webrtc.org | 0e6e4d2 | 2014-09-23 12:05:34 +0000 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
Ali Tofigh | 714e3cb | 2022-07-20 12:53:07 +0200 | [diff] [blame] | 17 | #include "absl/strings/string_view.h" |
Fredrik Solenberg | bbf21a3 | 2018-04-12 22:44:09 +0200 | [diff] [blame] | 18 | #include "api/audio/audio_frame.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "modules/audio_coding/include/audio_coding_module.h" |
| 20 | #include "modules/audio_coding/neteq/tools/packet_source.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "system_wrappers/include/clock.h" |
henrik.lundin@webrtc.org | 0e6e4d2 | 2014-09-23 12:05:34 +0000 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
kwiberg | 12cfc9b | 2015-09-08 05:57:53 -0700 | [diff] [blame] | 24 | class AudioEncoder; |
henrik.lundin@webrtc.org | 0e6e4d2 | 2014-09-23 12:05:34 +0000 | [diff] [blame] | 25 | |
| 26 | namespace test { |
| 27 | class InputAudioFile; |
| 28 | class Packet; |
| 29 | |
| 30 | class AcmSendTestOldApi : public AudioPacketizationCallback, |
| 31 | public PacketSource { |
| 32 | public: |
| 33 | AcmSendTestOldApi(InputAudioFile* audio_source, |
| 34 | int source_rate_hz, |
| 35 | int test_duration_ms); |
kwiberg | 65fc8b9 | 2016-08-29 10:05:24 -0700 | [diff] [blame] | 36 | ~AcmSendTestOldApi() override; |
henrik.lundin@webrtc.org | 0e6e4d2 | 2014-09-23 12:05:34 +0000 | [diff] [blame] | 37 | |
Byoungchan Lee | 604fd2f | 2022-01-21 09:49:39 +0900 | [diff] [blame] | 38 | AcmSendTestOldApi(const AcmSendTestOldApi&) = delete; |
| 39 | AcmSendTestOldApi& operator=(const AcmSendTestOldApi&) = delete; |
| 40 | |
henrik.lundin@webrtc.org | 0e6e4d2 | 2014-09-23 12:05:34 +0000 | [diff] [blame] | 41 | // Registers the send codec. Returns true on success, false otherwise. |
Ali Tofigh | 714e3cb | 2022-07-20 12:53:07 +0200 | [diff] [blame] | 42 | bool RegisterCodec(absl::string_view payload_name, |
henrik.lundin@webrtc.org | 0e6e4d2 | 2014-09-23 12:05:34 +0000 | [diff] [blame] | 43 | int sampling_freq_hz, |
| 44 | int channels, |
| 45 | int payload_type, |
| 46 | int frame_size_samples); |
| 47 | |
Karl Wiberg | 801500c | 2018-08-16 15:01:12 +0200 | [diff] [blame] | 48 | // Registers an external send codec. |
| 49 | void RegisterExternalCodec( |
| 50 | std::unique_ptr<AudioEncoder> external_speech_encoder); |
Karl Wiberg | 7e0c7d4 | 2015-05-18 14:52:29 +0200 | [diff] [blame] | 51 | |
henrik.lundin@webrtc.org | 0e6e4d2 | 2014-09-23 12:05:34 +0000 | [diff] [blame] | 52 | // Inherited from PacketSource. |
henrik.lundin | 46ba49c | 2016-05-24 22:50:47 -0700 | [diff] [blame] | 53 | std::unique_ptr<Packet> NextPacket() override; |
henrik.lundin@webrtc.org | 0e6e4d2 | 2014-09-23 12:05:34 +0000 | [diff] [blame] | 54 | |
| 55 | // Inherited from AudioPacketizationCallback. |
Niels Möller | 87e2d78 | 2019-03-07 10:18:23 +0100 | [diff] [blame] | 56 | int32_t SendData(AudioFrameType frame_type, |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 57 | uint8_t payload_type, |
| 58 | uint32_t timestamp, |
| 59 | const uint8_t* payload_data, |
Minyue Li | ff0e4db | 2020-01-23 13:45:50 +0100 | [diff] [blame] | 60 | size_t payload_len_bytes, |
| 61 | int64_t absolute_capture_timestamp_ms) override; |
henrik.lundin@webrtc.org | 0e6e4d2 | 2014-09-23 12:05:34 +0000 | [diff] [blame] | 62 | |
minyue@webrtc.org | 7dba786 | 2015-01-20 16:01:50 +0000 | [diff] [blame] | 63 | AudioCodingModule* acm() { return acm_.get(); } |
| 64 | |
henrik.lundin@webrtc.org | 0e6e4d2 | 2014-09-23 12:05:34 +0000 | [diff] [blame] | 65 | private: |
| 66 | static const int kBlockSizeMs = 10; |
| 67 | |
| 68 | // Creates a Packet object from the last packet produced by ACM (and received |
henrik.lundin | 46ba49c | 2016-05-24 22:50:47 -0700 | [diff] [blame] | 69 | // through the SendData method as a callback). |
| 70 | std::unique_ptr<Packet> CreatePacket(); |
henrik.lundin@webrtc.org | 0e6e4d2 | 2014-09-23 12:05:34 +0000 | [diff] [blame] | 71 | |
| 72 | SimulatedClock clock_; |
kwiberg | 16c5a96 | 2016-02-15 02:27:22 -0800 | [diff] [blame] | 73 | std::unique_ptr<AudioCodingModule> acm_; |
henrik.lundin@webrtc.org | 0e6e4d2 | 2014-09-23 12:05:34 +0000 | [diff] [blame] | 74 | InputAudioFile* audio_source_; |
| 75 | int source_rate_hz_; |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 76 | const size_t input_block_size_samples_; |
henrik.lundin@webrtc.org | 0e6e4d2 | 2014-09-23 12:05:34 +0000 | [diff] [blame] | 77 | AudioFrame input_frame_; |
henrik.lundin@webrtc.org | 0e6e4d2 | 2014-09-23 12:05:34 +0000 | [diff] [blame] | 78 | bool codec_registered_; |
| 79 | int test_duration_ms_; |
| 80 | // The following member variables are set whenever SendData() is called. |
Niels Möller | 87e2d78 | 2019-03-07 10:18:23 +0100 | [diff] [blame] | 81 | AudioFrameType frame_type_; |
henrik.lundin@webrtc.org | 0e6e4d2 | 2014-09-23 12:05:34 +0000 | [diff] [blame] | 82 | int payload_type_; |
| 83 | uint32_t timestamp_; |
| 84 | uint16_t sequence_number_; |
| 85 | std::vector<uint8_t> last_payload_vec_; |
henrik.lundin@webrtc.org | f56c162 | 2015-03-02 12:29:30 +0000 | [diff] [blame] | 86 | bool data_to_send_; |
henrik.lundin@webrtc.org | 0e6e4d2 | 2014-09-23 12:05:34 +0000 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | } // namespace test |
| 90 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 91 | #endif // MODULES_AUDIO_CODING_ACM2_ACM_SEND_TEST_H_ |