encode_neteq_input.h (2531B)
1 /* 2 * Copyright (c) 2016 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_NETEQ_TOOLS_ENCODE_NETEQ_INPUT_H_ 12 #define MODULES_AUDIO_CODING_NETEQ_TOOLS_ENCODE_NETEQ_INPUT_H_ 13 14 #include <cstddef> 15 #include <cstdint> 16 #include <memory> 17 #include <optional> 18 19 #include "api/array_view.h" 20 #include "api/audio_codecs/audio_encoder.h" 21 #include "modules/audio_coding/neteq/tools/neteq_input.h" 22 #include "modules/rtp_rtcp/source/rtp_packet_received.h" 23 24 namespace webrtc { 25 namespace test { 26 27 // This class provides a NetEqInput that takes audio from a generator object and 28 // encodes it using a given audio encoder. 29 class EncodeNetEqInput : public NetEqInput { 30 public: 31 // Generator class, to be provided to the EncodeNetEqInput constructor. 32 class Generator { 33 public: 34 virtual ~Generator() = default; 35 // Returns the next num_samples values from the signal generator. 36 virtual ArrayView<const int16_t> Generate(size_t num_samples) = 0; 37 }; 38 39 // The source will end after the given input duration. 40 EncodeNetEqInput(std::unique_ptr<Generator> generator, 41 std::unique_ptr<AudioEncoder> encoder, 42 int64_t input_duration_ms); 43 ~EncodeNetEqInput() override; 44 45 std::optional<int64_t> NextPacketTime() const override; 46 47 std::optional<int64_t> NextOutputEventTime() const override; 48 49 std::optional<SetMinimumDelayInfo> NextSetMinimumDelayInfo() const override { 50 return std::nullopt; 51 } 52 53 std::unique_ptr<RtpPacketReceived> PopPacket() override; 54 55 void AdvanceOutputEvent() override; 56 57 void AdvanceSetMinimumDelay() override {} 58 59 bool ended() const override; 60 61 const RtpPacketReceived* NextPacket() const override; 62 63 private: 64 static constexpr int64_t kOutputPeriodMs = 10; 65 66 void CreatePacket(); 67 68 std::unique_ptr<Generator> generator_; 69 std::unique_ptr<AudioEncoder> encoder_; 70 std::unique_ptr<RtpPacketReceived> packet_data_; 71 uint32_t rtp_timestamp_ = 0; 72 int16_t sequence_number_ = 0; 73 int64_t next_packet_time_ms_ = 0; 74 int64_t next_output_event_ms_ = 0; 75 const int64_t input_duration_ms_; 76 }; 77 78 } // namespace test 79 } // namespace webrtc 80 #endif // MODULES_AUDIO_CODING_NETEQ_TOOLS_ENCODE_NETEQ_INPUT_H_