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