• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_NETEQ_TOOLS_AUDIO_SINK_H_
12 #define MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_SINK_H_
13 
14 #include "api/audio/audio_frame.h"
15 #include "rtc_base/constructor_magic.h"
16 
17 namespace webrtc {
18 namespace test {
19 
20 // Interface class for an object receiving raw output audio from test
21 // applications.
22 class AudioSink {
23  public:
AudioSink()24   AudioSink() {}
~AudioSink()25   virtual ~AudioSink() {}
26 
27   // Writes |num_samples| from |audio| to the AudioSink. Returns true if
28   // successful, otherwise false.
29   virtual bool WriteArray(const int16_t* audio, size_t num_samples) = 0;
30 
31   // Writes |audio_frame| to the AudioSink. Returns true if successful,
32   // otherwise false.
WriteAudioFrame(const AudioFrame & audio_frame)33   bool WriteAudioFrame(const AudioFrame& audio_frame) {
34     return WriteArray(audio_frame.data(), audio_frame.samples_per_channel_ *
35                                               audio_frame.num_channels_);
36   }
37 
38  private:
39   RTC_DISALLOW_COPY_AND_ASSIGN(AudioSink);
40 };
41 
42 // Forks the output audio to two AudioSink objects.
43 class AudioSinkFork : public AudioSink {
44  public:
AudioSinkFork(AudioSink * left,AudioSink * right)45   AudioSinkFork(AudioSink* left, AudioSink* right)
46       : left_sink_(left), right_sink_(right) {}
47 
48   bool WriteArray(const int16_t* audio, size_t num_samples) override;
49 
50  private:
51   AudioSink* left_sink_;
52   AudioSink* right_sink_;
53 
54   RTC_DISALLOW_COPY_AND_ASSIGN(AudioSinkFork);
55 };
56 
57 // An AudioSink implementation that does nothing.
58 class VoidAudioSink : public AudioSink {
59  public:
60   VoidAudioSink() = default;
61   bool WriteArray(const int16_t* audio, size_t num_samples) override;
62 
63  private:
64   RTC_DISALLOW_COPY_AND_ASSIGN(VoidAudioSink);
65 };
66 
67 }  // namespace test
68 }  // namespace webrtc
69 #endif  // MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_SINK_H_
70