blob: 05e6fe8e7c9b59168aad6a772a3260d805725036 [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"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "rtc_base/constructormagic.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020016#include "typedefs.h" // NOLINT(build/include)
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) {
Yves Gerey665174f2018-06-19 15:03:05 +020035 return WriteArray(audio_frame.data(), audio_frame.samples_per_channel_ *
36 audio_frame.num_channels_);
henrik.lundin@webrtc.org496a9842014-06-19 10:02:11 +000037 }
38
39 private:
henrikg3c089d72015-09-16 05:37:44 -070040 RTC_DISALLOW_COPY_AND_ASSIGN(AudioSink);
henrik.lundin@webrtc.org496a9842014-06-19 10:02:11 +000041};
42
henrik.lundin@webrtc.orgc8e98182014-06-26 19:07:04 +000043// Forks the output audio to two AudioSink objects.
44class AudioSinkFork : public AudioSink {
45 public:
46 AudioSinkFork(AudioSink* left, AudioSink* right)
47 : left_sink_(left), right_sink_(right) {}
48
aleloi0e0be0a2016-08-10 04:55:20 -070049 bool WriteArray(const int16_t* audio, size_t num_samples) override;
henrik.lundin@webrtc.orgc8e98182014-06-26 19:07:04 +000050
51 private:
52 AudioSink* left_sink_;
53 AudioSink* right_sink_;
54
henrikg3c089d72015-09-16 05:37:44 -070055 RTC_DISALLOW_COPY_AND_ASSIGN(AudioSinkFork);
henrik.lundin@webrtc.orgc8e98182014-06-26 19:07:04 +000056};
aleloi0e0be0a2016-08-10 04:55:20 -070057
henrik.lundina05d3c82017-04-26 09:32:07 -070058// An AudioSink implementation that does nothing.
59class VoidAudioSink : public AudioSink {
60 public:
61 VoidAudioSink() = default;
62 bool WriteArray(const int16_t* audio, size_t num_samples) override;
63
64 private:
65 RTC_DISALLOW_COPY_AND_ASSIGN(VoidAudioSink);
66};
67
henrik.lundin@webrtc.org496a9842014-06-19 10:02:11 +000068} // namespace test
69} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020070#endif // MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_SINK_H_