acm_send_test.h (3239B)
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 <cstddef> 15 #include <cstdint> 16 #include <memory> 17 #include <vector> 18 19 #include "absl/strings/string_view.h" 20 #include "api/audio/audio_frame.h" 21 #include "api/environment/environment.h" 22 #include "modules/audio_coding/include/audio_coding_module.h" 23 #include "modules/audio_coding/include/audio_coding_module_typedefs.h" 24 #include "modules/audio_coding/neteq/tools/packet_source.h" 25 #include "modules/rtp_rtcp/source/rtp_packet_received.h" 26 #include "system_wrappers/include/clock.h" 27 28 namespace webrtc { 29 class AudioEncoder; 30 31 namespace test { 32 class InputAudioFile; 33 34 class AcmSendTestOldApi : public AudioPacketizationCallback, 35 public PacketSource { 36 public: 37 AcmSendTestOldApi(InputAudioFile* audio_source, 38 int source_rate_hz, 39 int test_duration_ms); 40 ~AcmSendTestOldApi() override; 41 42 AcmSendTestOldApi(const AcmSendTestOldApi&) = delete; 43 AcmSendTestOldApi& operator=(const AcmSendTestOldApi&) = delete; 44 45 // Registers the send codec. Returns true on success, false otherwise. 46 bool RegisterCodec(absl::string_view payload_name, 47 int sampling_freq_hz, 48 int channels, 49 int payload_type, 50 int frame_size_samples); 51 52 // Registers an external send codec. 53 void RegisterExternalCodec( 54 std::unique_ptr<AudioEncoder> external_speech_encoder); 55 56 // Inherited from PacketSource. 57 std::unique_ptr<RtpPacketReceived> NextPacket() override; 58 59 // Inherited from AudioPacketizationCallback. 60 int32_t SendData(AudioFrameType frame_type, 61 uint8_t payload_type, 62 uint32_t timestamp, 63 const uint8_t* payload_data, 64 size_t payload_len_bytes, 65 int64_t absolute_capture_timestamp_ms) override; 66 67 AudioCodingModule* acm() { return acm_.get(); } 68 69 private: 70 static const int kBlockSizeMs = 10; 71 72 // Creates a Packet object from the last packet produced by ACM (and received 73 // through the SendData method as a callback). 74 std::unique_ptr<RtpPacketReceived> CreatePacket(); 75 76 SimulatedClock clock_; 77 const Environment env_; 78 std::unique_ptr<AudioCodingModule> acm_; 79 InputAudioFile* audio_source_; 80 int source_rate_hz_; 81 const size_t input_block_size_samples_; 82 AudioFrame input_frame_; 83 bool codec_registered_; 84 int test_duration_ms_; 85 // The following member variables are set whenever SendData() is called. 86 AudioFrameType frame_type_; 87 int payload_type_; 88 uint32_t timestamp_; 89 uint16_t sequence_number_; 90 std::vector<uint8_t> last_payload_vec_; 91 bool data_to_send_; 92 }; 93 94 } // namespace test 95 } // namespace webrtc 96 #endif // MODULES_AUDIO_CODING_ACM2_ACM_SEND_TEST_H_