blob: 24d230b8233d1326e4be6867f15c44ab678e6fdd [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"
Steve Anton10542f22019-01-11 09:11:00 -080020#include "rtc_base/constructor_magic.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "system_wrappers/include/clock.h"
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000022
23namespace webrtc {
kwiberg12cfc9b2015-09-08 05:57:53 -070024class AudioEncoder;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000025
26namespace test {
27class InputAudioFile;
28class Packet;
29
30class AcmSendTestOldApi : public AudioPacketizationCallback,
31 public PacketSource {
32 public:
33 AcmSendTestOldApi(InputAudioFile* audio_source,
34 int source_rate_hz,
35 int test_duration_ms);
kwiberg65fc8b92016-08-29 10:05:24 -070036 ~AcmSendTestOldApi() override;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000037
38 // Registers the send codec. Returns true on success, false otherwise.
39 bool RegisterCodec(const char* payload_name,
40 int sampling_freq_hz,
41 int channels,
42 int payload_type,
43 int frame_size_samples);
44
Karl Wiberg801500c2018-08-16 15:01:12 +020045 // Registers an external send codec.
46 void RegisterExternalCodec(
47 std::unique_ptr<AudioEncoder> external_speech_encoder);
Karl Wiberg7e0c7d42015-05-18 14:52:29 +020048
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000049 // Inherited from PacketSource.
henrik.lundin46ba49c2016-05-24 22:50:47 -070050 std::unique_ptr<Packet> NextPacket() override;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000051
52 // Inherited from AudioPacketizationCallback.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000053 int32_t SendData(FrameType frame_type,
54 uint8_t payload_type,
55 uint32_t timestamp,
56 const uint8_t* payload_data,
57 size_t payload_len_bytes,
58 const RTPFragmentationHeader* fragmentation) override;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000059
minyue@webrtc.org7dba7862015-01-20 16:01:50 +000060 AudioCodingModule* acm() { return acm_.get(); }
61
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000062 private:
63 static const int kBlockSizeMs = 10;
64
65 // Creates a Packet object from the last packet produced by ACM (and received
henrik.lundin46ba49c2016-05-24 22:50:47 -070066 // through the SendData method as a callback).
67 std::unique_ptr<Packet> CreatePacket();
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000068
69 SimulatedClock clock_;
kwiberg16c5a962016-02-15 02:27:22 -080070 std::unique_ptr<AudioCodingModule> acm_;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000071 InputAudioFile* audio_source_;
72 int source_rate_hz_;
Peter Kastingdce40cf2015-08-24 14:52:23 -070073 const size_t input_block_size_samples_;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000074 AudioFrame input_frame_;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000075 bool codec_registered_;
76 int test_duration_ms_;
77 // The following member variables are set whenever SendData() is called.
78 FrameType frame_type_;
79 int payload_type_;
80 uint32_t timestamp_;
81 uint16_t sequence_number_;
82 std::vector<uint8_t> last_payload_vec_;
henrik.lundin@webrtc.orgf56c1622015-03-02 12:29:30 +000083 bool data_to_send_;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000084
henrikg3c089d72015-09-16 05:37:44 -070085 RTC_DISALLOW_COPY_AND_ASSIGN(AcmSendTestOldApi);
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_