blob: 6aea0f1b52014fd812d8118b71b9d1cc92d0a2f7 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/audio_coding/include/audio_coding_module.h"
18#include "modules/audio_coding/neteq/tools/packet_source.h"
19#include "rtc_base/constructormagic.h"
20#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
37 // Registers the send codec. Returns true on success, false otherwise.
38 bool RegisterCodec(const char* payload_name,
39 int sampling_freq_hz,
40 int channels,
41 int payload_type,
42 int frame_size_samples);
43
Karl Wiberg7e0c7d42015-05-18 14:52:29 +020044 // Registers an external send codec. Returns true on success, false otherwise.
kwiberg12cfc9b2015-09-08 05:57:53 -070045 bool RegisterExternalCodec(AudioEncoder* external_speech_encoder);
Karl Wiberg7e0c7d42015-05-18 14:52:29 +020046
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000047 // Inherited from PacketSource.
henrik.lundin46ba49c2016-05-24 22:50:47 -070048 std::unique_ptr<Packet> NextPacket() override;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000049
50 // Inherited from AudioPacketizationCallback.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000051 int32_t SendData(FrameType frame_type,
52 uint8_t payload_type,
53 uint32_t timestamp,
54 const uint8_t* payload_data,
55 size_t payload_len_bytes,
56 const RTPFragmentationHeader* fragmentation) override;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000057
minyue@webrtc.org7dba7862015-01-20 16:01:50 +000058 AudioCodingModule* acm() { return acm_.get(); }
59
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000060 private:
61 static const int kBlockSizeMs = 10;
62
63 // Creates a Packet object from the last packet produced by ACM (and received
henrik.lundin46ba49c2016-05-24 22:50:47 -070064 // through the SendData method as a callback).
65 std::unique_ptr<Packet> CreatePacket();
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000066
67 SimulatedClock clock_;
kwiberg16c5a962016-02-15 02:27:22 -080068 std::unique_ptr<AudioCodingModule> acm_;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000069 InputAudioFile* audio_source_;
70 int source_rate_hz_;
Peter Kastingdce40cf2015-08-24 14:52:23 -070071 const size_t input_block_size_samples_;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000072 AudioFrame input_frame_;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000073 bool codec_registered_;
74 int test_duration_ms_;
75 // The following member variables are set whenever SendData() is called.
76 FrameType frame_type_;
77 int payload_type_;
78 uint32_t timestamp_;
79 uint16_t sequence_number_;
80 std::vector<uint8_t> last_payload_vec_;
henrik.lundin@webrtc.orgf56c1622015-03-02 12:29:30 +000081 bool data_to_send_;
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000082
henrikg3c089d72015-09-16 05:37:44 -070083 RTC_DISALLOW_COPY_AND_ASSIGN(AcmSendTestOldApi);
henrik.lundin@webrtc.org0e6e4d22014-09-23 12:05:34 +000084};
85
86} // namespace test
87} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020088#endif // MODULES_AUDIO_CODING_ACM2_ACM_SEND_TEST_H_