henrik.lundin@webrtc.org | 496a984 | 2014-06-19 10:02:11 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_SINK_H_ |
| 12 | #define MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_SINK_H_ |
henrik.lundin@webrtc.org | 496a984 | 2014-06-19 10:02:11 +0000 | [diff] [blame] | 13 | |
Fredrik Solenberg | bbf21a3 | 2018-04-12 22:44:09 +0200 | [diff] [blame] | 14 | #include "api/audio/audio_frame.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame^] | 15 | #include "rtc_base/constructor_magic.h" |
henrik.lundin@webrtc.org | 496a984 | 2014-06-19 10:02:11 +0000 | [diff] [blame] | 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: |
henrik.lundin@webrtc.org | 9158df2 | 2014-06-19 12:34:31 +0000 | [diff] [blame] | 24 | AudioSink() {} |
henrik.lundin@webrtc.org | 496a984 | 2014-06-19 10:02:11 +0000 | [diff] [blame] | 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. |
| 33 | bool WriteAudioFrame(const AudioFrame& audio_frame) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 34 | return WriteArray(audio_frame.data(), audio_frame.samples_per_channel_ * |
| 35 | audio_frame.num_channels_); |
henrik.lundin@webrtc.org | 496a984 | 2014-06-19 10:02:11 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | private: |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 39 | RTC_DISALLOW_COPY_AND_ASSIGN(AudioSink); |
henrik.lundin@webrtc.org | 496a984 | 2014-06-19 10:02:11 +0000 | [diff] [blame] | 40 | }; |
| 41 | |
henrik.lundin@webrtc.org | c8e9818 | 2014-06-26 19:07:04 +0000 | [diff] [blame] | 42 | // Forks the output audio to two AudioSink objects. |
| 43 | class AudioSinkFork : public AudioSink { |
| 44 | public: |
| 45 | AudioSinkFork(AudioSink* left, AudioSink* right) |
| 46 | : left_sink_(left), right_sink_(right) {} |
| 47 | |
aleloi | 0e0be0a | 2016-08-10 04:55:20 -0700 | [diff] [blame] | 48 | bool WriteArray(const int16_t* audio, size_t num_samples) override; |
henrik.lundin@webrtc.org | c8e9818 | 2014-06-26 19:07:04 +0000 | [diff] [blame] | 49 | |
| 50 | private: |
| 51 | AudioSink* left_sink_; |
| 52 | AudioSink* right_sink_; |
| 53 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 54 | RTC_DISALLOW_COPY_AND_ASSIGN(AudioSinkFork); |
henrik.lundin@webrtc.org | c8e9818 | 2014-06-26 19:07:04 +0000 | [diff] [blame] | 55 | }; |
aleloi | 0e0be0a | 2016-08-10 04:55:20 -0700 | [diff] [blame] | 56 | |
henrik.lundin | a05d3c8 | 2017-04-26 09:32:07 -0700 | [diff] [blame] | 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 | |
henrik.lundin@webrtc.org | 496a984 | 2014-06-19 10:02:11 +0000 | [diff] [blame] | 67 | } // namespace test |
| 68 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 69 | #endif // MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_SINK_H_ |