blob: 17b9e67a91b592cc00b199d7ceeba88652cfc2a6 [file] [log] [blame]
henrik.lundin@webrtc.org496a9842014-06-19 10:02:11 +00001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_SINK_H_
12#define MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_SINK_H_
henrik.lundin@webrtc.org496a9842014-06-19 10:02:11 +000013
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "modules/include/module_common_types.h"
15#include "rtc_base/constructormagic.h"
16#include "typedefs.h"
henrik.lundin@webrtc.org496a9842014-06-19 10:02:11 +000017
18namespace webrtc {
19namespace test {
20
21// Interface class for an object receiving raw output audio from test
22// applications.
23class AudioSink {
24 public:
henrik.lundin@webrtc.org9158df22014-06-19 12:34:31 +000025 AudioSink() {}
henrik.lundin@webrtc.org496a9842014-06-19 10:02:11 +000026 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(
yujo36b1a5f2017-06-12 12:45:32 -070036 audio_frame.data(),
henrik.lundin@webrtc.org496a9842014-06-19 10:02:11 +000037 audio_frame.samples_per_channel_ * audio_frame.num_channels_);
38 }
39
40 private:
henrikg3c089d72015-09-16 05:37:44 -070041 RTC_DISALLOW_COPY_AND_ASSIGN(AudioSink);
henrik.lundin@webrtc.org496a9842014-06-19 10:02:11 +000042};
43
henrik.lundin@webrtc.orgc8e98182014-06-26 19:07:04 +000044// Forks the output audio to two AudioSink objects.
45class AudioSinkFork : public AudioSink {
46 public:
47 AudioSinkFork(AudioSink* left, AudioSink* right)
48 : left_sink_(left), right_sink_(right) {}
49
aleloi0e0be0a2016-08-10 04:55:20 -070050 bool WriteArray(const int16_t* audio, size_t num_samples) override;
henrik.lundin@webrtc.orgc8e98182014-06-26 19:07:04 +000051
52 private:
53 AudioSink* left_sink_;
54 AudioSink* right_sink_;
55
henrikg3c089d72015-09-16 05:37:44 -070056 RTC_DISALLOW_COPY_AND_ASSIGN(AudioSinkFork);
henrik.lundin@webrtc.orgc8e98182014-06-26 19:07:04 +000057};
aleloi0e0be0a2016-08-10 04:55:20 -070058
henrik.lundina05d3c82017-04-26 09:32:07 -070059// An AudioSink implementation that does nothing.
60class 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.org496a9842014-06-19 10:02:11 +000069} // namespace test
70} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020071#endif // MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_SINK_H_