blob: b14cb80c6a11ee280576d734c0f80e74f75153d0 [file] [log] [blame]
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +00001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_CODING_ACM2_ACM_SEND_TEST_H_
12#define MODULES_AUDIO_CODING_ACM2_ACM_SEND_TEST_H_
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000013
kwiberg16c5a962016-02-15 02:27:22 -080014#include <memory>
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000015#include <vector>
16
Fredrik Solenbergbbf21a32018-04-12 22:44:09 +020017#include "api/audio/audio_frame.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "modules/audio_coding/include/audio_coding_module.h"
19#include "modules/audio_coding/neteq/tools/packet_source.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "system_wrappers/include/clock.h"
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000021
22namespace webrtc {
kwiberg12cfc9b2015-09-08 05:57:53 -070023class AudioEncoder;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000024
25namespace test {
26class InputAudioFile;
27class Packet;
28
29class AcmSendTestOldApi : public AudioPacketizationCallback,
30 public PacketSource {
31 public:
32 AcmSendTestOldApi(InputAudioFile* audio_source,
33 int source_rate_hz,
34 int test_duration_ms);
kwiberg65fc8b92016-08-29 10:05:24 -070035 ~AcmSendTestOldApi() override;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000036
Byoungchan Lee604fd2f2022-01-21 09:49:39 +090037 AcmSendTestOldApi(const AcmSendTestOldApi&) = delete;
38 AcmSendTestOldApi& operator=(const AcmSendTestOldApi&) = delete;
39
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000040 // Registers the send codec. Returns true on success, false otherwise.
41 bool RegisterCodec(const char* payload_name,
42 int sampling_freq_hz,
43 int channels,
44 int payload_type,
45 int frame_size_samples);
46
Karl Wiberg801500c2018-08-16 15:01:12 +020047 // Registers an external send codec.
48 void RegisterExternalCodec(
49 std::unique_ptr<AudioEncoder> external_speech_encoder);
Karl Wiberg7e0c7d42015-05-18 14:52:29 +020050
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000051 // Inherited from PacketSource.
henrik.lundin46ba49c2016-05-24 22:50:47 -070052 std::unique_ptr<Packet> NextPacket() override;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000053
54 // Inherited from AudioPacketizationCallback.
Niels Möller87e2d782019-03-07 10:18:23 +010055 int32_t SendData(AudioFrameType frame_type,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000056 uint8_t payload_type,
57 uint32_t timestamp,
58 const uint8_t* payload_data,
Minyue Liff0e4db2020-01-23 13:45:50 +010059 size_t payload_len_bytes,
60 int64_t absolute_capture_timestamp_ms) override;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000061
minyue@webrtc.org7dba7862015-01-20 16:01:50 +000062 AudioCodingModule* acm() { return acm_.get(); }
63
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000064 private:
65 static const int kBlockSizeMs = 10;
66
67 // Creates a Packet object from the last packet produced by ACM (and received
henrik.lundin46ba49c2016-05-24 22:50:47 -070068 // through the SendData method as a callback).
69 std::unique_ptr<Packet> CreatePacket();
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000070
71 SimulatedClock clock_;
kwiberg16c5a962016-02-15 02:27:22 -080072 std::unique_ptr<AudioCodingModule> acm_;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000073 InputAudioFile* audio_source_;
74 int source_rate_hz_;
Peter Kastingdce40cf2015-08-24 14:52:23 -070075 const size_t input_block_size_samples_;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000076 AudioFrame input_frame_;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000077 bool codec_registered_;
78 int test_duration_ms_;
79 // The following member variables are set whenever SendData() is called.
Niels Möller87e2d782019-03-07 10:18:23 +010080 AudioFrameType frame_type_;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000081 int payload_type_;
82 uint32_t timestamp_;
83 uint16_t sequence_number_;
84 std::vector<uint8_t> last_payload_vec_;
henrik.lundin@webrtc.orgf56c1622015-03-02 12:29:30 +000085 bool data_to_send_;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000086};
87
88} // namespace test
89} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020090#endif // MODULES_AUDIO_CODING_ACM2_ACM_SEND_TEST_H_