• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <memory>
15 
16 #include "api/audio_codecs/audio_encoder.h"
17 #include "modules/audio_coding/neteq/tools/neteq_input.h"
18 
19 namespace webrtc {
20 namespace test {
21 
22 // This class provides a NetEqInput that takes audio from a generator object and
23 // encodes it using a given audio encoder.
24 class EncodeNetEqInput : public NetEqInput {
25  public:
26   // Generator class, to be provided to the EncodeNetEqInput constructor.
27   class Generator {
28    public:
29     virtual ~Generator() = default;
30     // Returns the next num_samples values from the signal generator.
31     virtual rtc::ArrayView<const int16_t> Generate(size_t num_samples) = 0;
32   };
33 
34   // The source will end after the given input duration.
35   EncodeNetEqInput(std::unique_ptr<Generator> generator,
36                    std::unique_ptr<AudioEncoder> encoder,
37                    int64_t input_duration_ms);
38   ~EncodeNetEqInput() override;
39 
40   absl::optional<int64_t> NextPacketTime() const override;
41 
42   absl::optional<int64_t> NextOutputEventTime() const override;
43 
44   std::unique_ptr<PacketData> PopPacket() override;
45 
46   void AdvanceOutputEvent() override;
47 
48   bool ended() const override;
49 
50   absl::optional<RTPHeader> NextHeader() const override;
51 
52  private:
53   static constexpr int64_t kOutputPeriodMs = 10;
54 
55   void CreatePacket();
56 
57   std::unique_ptr<Generator> generator_;
58   std::unique_ptr<AudioEncoder> encoder_;
59   std::unique_ptr<PacketData> packet_data_;
60   uint32_t rtp_timestamp_ = 0;
61   int16_t sequence_number_ = 0;
62   int64_t next_packet_time_ms_ = 0;
63   int64_t next_output_event_ms_ = 0;
64   const int64_t input_duration_ms_;
65 };
66 
67 }  // namespace test
68 }  // namespace webrtc
69 #endif  // MODULES_AUDIO_CODING_NETEQ_TOOLS_ENCODE_NETEQ_INPUT_H_
70