blob: 68825ebbbf8b0051eba527270a9e0518c186409f [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
Fredrik Solenbergbbf21a32018-04-12 22:44:09 +020014#include "api/audio/audio_frame.h"
Steve Anton10542f22019-01-11 09:11:00 -080015#include "rtc_base/constructor_magic.h"
henrik.lundin@webrtc.org496a9842014-06-19 10:02:11 +000016
17namespace webrtc {
18namespace test {
19
20// Interface class for an object receiving raw output audio from test
21// applications.
22class AudioSink {
23 public:
henrik.lundin@webrtc.org9158df22014-06-19 12:34:31 +000024 AudioSink() {}
henrik.lundin@webrtc.org496a9842014-06-19 10:02:11 +000025 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 Gerey665174f2018-06-19 15:03:05 +020034 return WriteArray(audio_frame.data(), audio_frame.samples_per_channel_ *
35 audio_frame.num_channels_);
henrik.lundin@webrtc.org496a9842014-06-19 10:02:11 +000036 }
37
38 private:
henrikg3c089d72015-09-16 05:37:44 -070039 RTC_DISALLOW_COPY_AND_ASSIGN(AudioSink);
henrik.lundin@webrtc.org496a9842014-06-19 10:02:11 +000040};
41
henrik.lundin@webrtc.orgc8e98182014-06-26 19:07:04 +000042// Forks the output audio to two AudioSink objects.
43class AudioSinkFork : public AudioSink {
44 public:
45 AudioSinkFork(AudioSink* left, AudioSink* right)
46 : left_sink_(left), right_sink_(right) {}
47
aleloi0e0be0a2016-08-10 04:55:20 -070048 bool WriteArray(const int16_t* audio, size_t num_samples) override;
henrik.lundin@webrtc.orgc8e98182014-06-26 19:07:04 +000049
50 private:
51 AudioSink* left_sink_;
52 AudioSink* right_sink_;
53
henrikg3c089d72015-09-16 05:37:44 -070054 RTC_DISALLOW_COPY_AND_ASSIGN(AudioSinkFork);
henrik.lundin@webrtc.orgc8e98182014-06-26 19:07:04 +000055};
aleloi0e0be0a2016-08-10 04:55:20 -070056
henrik.lundina05d3c82017-04-26 09:32:07 -070057// An AudioSink implementation that does nothing.
58class 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.org496a9842014-06-19 10:02:11 +000067} // namespace test
68} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020069#endif // MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_SINK_H_