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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "modules/include/module_common_types.h" |
| 15 | #include "rtc_base/constructormagic.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame^] | 16 | #include "typedefs.h" // NOLINT(build/include) |
henrik.lundin@webrtc.org | 496a984 | 2014-06-19 10:02:11 +0000 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
| 19 | namespace test { |
| 20 | |
| 21 | // Interface class for an object receiving raw output audio from test |
| 22 | // applications. |
| 23 | class AudioSink { |
| 24 | public: |
henrik.lundin@webrtc.org | 9158df2 | 2014-06-19 12:34:31 +0000 | [diff] [blame] | 25 | AudioSink() {} |
henrik.lundin@webrtc.org | 496a984 | 2014-06-19 10:02:11 +0000 | [diff] [blame] | 26 | virtual ~AudioSink() {} |
| 27 | |
| 28 | // Writes |num_samples| from |audio| to the AudioSink. Returns true if |
| 29 | // successful, otherwise false. |
| 30 | virtual bool WriteArray(const int16_t* audio, size_t num_samples) = 0; |
| 31 | |
| 32 | // Writes |audio_frame| to the AudioSink. Returns true if successful, |
| 33 | // otherwise false. |
| 34 | bool WriteAudioFrame(const AudioFrame& audio_frame) { |
| 35 | return WriteArray( |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 36 | audio_frame.data(), |
henrik.lundin@webrtc.org | 496a984 | 2014-06-19 10:02:11 +0000 | [diff] [blame] | 37 | audio_frame.samples_per_channel_ * audio_frame.num_channels_); |
| 38 | } |
| 39 | |
| 40 | private: |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 41 | RTC_DISALLOW_COPY_AND_ASSIGN(AudioSink); |
henrik.lundin@webrtc.org | 496a984 | 2014-06-19 10:02:11 +0000 | [diff] [blame] | 42 | }; |
| 43 | |
henrik.lundin@webrtc.org | c8e9818 | 2014-06-26 19:07:04 +0000 | [diff] [blame] | 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 | |
aleloi | 0e0be0a | 2016-08-10 04:55:20 -0700 | [diff] [blame] | 50 | 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] | 51 | |
| 52 | private: |
| 53 | AudioSink* left_sink_; |
| 54 | AudioSink* right_sink_; |
| 55 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 56 | RTC_DISALLOW_COPY_AND_ASSIGN(AudioSinkFork); |
henrik.lundin@webrtc.org | c8e9818 | 2014-06-26 19:07:04 +0000 | [diff] [blame] | 57 | }; |
aleloi | 0e0be0a | 2016-08-10 04:55:20 -0700 | [diff] [blame] | 58 | |
henrik.lundin | a05d3c8 | 2017-04-26 09:32:07 -0700 | [diff] [blame] | 59 | // An AudioSink implementation that does nothing. |
| 60 | class VoidAudioSink : public AudioSink { |
| 61 | public: |
| 62 | VoidAudioSink() = default; |
| 63 | bool WriteArray(const int16_t* audio, size_t num_samples) override; |
| 64 | |
| 65 | private: |
| 66 | RTC_DISALLOW_COPY_AND_ASSIGN(VoidAudioSink); |
| 67 | }; |
| 68 | |
henrik.lundin@webrtc.org | 496a984 | 2014-06-19 10:02:11 +0000 | [diff] [blame] | 69 | } // namespace test |
| 70 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 71 | #endif // MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_SINK_H_ |