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 11 #ifndef MODULES_AUDIO_CODING_ACM2_ACM_SEND_TEST_H_ 12 #define MODULES_AUDIO_CODING_ACM2_ACM_SEND_TEST_H_ 13 14 #include <memory> 15 #include <vector> 16 17 #include "api/audio/audio_frame.h" 18 #include "modules/audio_coding/include/audio_coding_module.h" 19 #include "modules/audio_coding/neteq/tools/packet_source.h" 20 #include "rtc_base/constructor_magic.h" 21 #include "system_wrappers/include/clock.h" 22 23 namespace webrtc { 24 class AudioEncoder; 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); 36 ~AcmSendTestOldApi() override; 37 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 45 // Registers an external send codec. 46 void RegisterExternalCodec( 47 std::unique_ptr<AudioEncoder> external_speech_encoder); 48 49 // Inherited from PacketSource. 50 std::unique_ptr<Packet> NextPacket() override; 51 52 // Inherited from AudioPacketizationCallback. 53 int32_t SendData(AudioFrameType frame_type, 54 uint8_t payload_type, 55 uint32_t timestamp, 56 const uint8_t* payload_data, 57 size_t payload_len_bytes, 58 int64_t absolute_capture_timestamp_ms) override; 59 acm()60 AudioCodingModule* acm() { return acm_.get(); } 61 62 private: 63 static const int kBlockSizeMs = 10; 64 65 // Creates a Packet object from the last packet produced by ACM (and received 66 // through the SendData method as a callback). 67 std::unique_ptr<Packet> CreatePacket(); 68 69 SimulatedClock clock_; 70 std::unique_ptr<AudioCodingModule> acm_; 71 InputAudioFile* audio_source_; 72 int source_rate_hz_; 73 const size_t input_block_size_samples_; 74 AudioFrame input_frame_; 75 bool codec_registered_; 76 int test_duration_ms_; 77 // The following member variables are set whenever SendData() is called. 78 AudioFrameType frame_type_; 79 int payload_type_; 80 uint32_t timestamp_; 81 uint16_t sequence_number_; 82 std::vector<uint8_t> last_payload_vec_; 83 bool data_to_send_; 84 85 RTC_DISALLOW_COPY_AND_ASSIGN(AcmSendTestOldApi); 86 }; 87 88 } // namespace test 89 } // namespace webrtc 90 #endif // MODULES_AUDIO_CODING_ACM2_ACM_SEND_TEST_H_ 91