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