audio_sink.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #ifndef MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_SINK_H_
  11. #define MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_SINK_H_
  12. #include "api/audio/audio_frame.h"
  13. #include "rtc_base/constructor_magic.h"
  14. namespace webrtc {
  15. namespace test {
  16. // Interface class for an object receiving raw output audio from test
  17. // applications.
  18. class AudioSink {
  19. public:
  20. AudioSink() {}
  21. virtual ~AudioSink() {}
  22. // Writes |num_samples| from |audio| to the AudioSink. Returns true if
  23. // successful, otherwise false.
  24. virtual bool WriteArray(const int16_t* audio, size_t num_samples) = 0;
  25. // Writes |audio_frame| to the AudioSink. Returns true if successful,
  26. // otherwise false.
  27. bool WriteAudioFrame(const AudioFrame& audio_frame) {
  28. return WriteArray(audio_frame.data(), audio_frame.samples_per_channel_ *
  29. audio_frame.num_channels_);
  30. }
  31. private:
  32. RTC_DISALLOW_COPY_AND_ASSIGN(AudioSink);
  33. };
  34. // Forks the output audio to two AudioSink objects.
  35. class AudioSinkFork : public AudioSink {
  36. public:
  37. AudioSinkFork(AudioSink* left, AudioSink* right)
  38. : left_sink_(left), right_sink_(right) {}
  39. bool WriteArray(const int16_t* audio, size_t num_samples) override;
  40. private:
  41. AudioSink* left_sink_;
  42. AudioSink* right_sink_;
  43. RTC_DISALLOW_COPY_AND_ASSIGN(AudioSinkFork);
  44. };
  45. // An AudioSink implementation that does nothing.
  46. class VoidAudioSink : public AudioSink {
  47. public:
  48. VoidAudioSink() = default;
  49. bool WriteArray(const int16_t* audio, size_t num_samples) override;
  50. private:
  51. RTC_DISALLOW_COPY_AND_ASSIGN(VoidAudioSink);
  52. };
  53. } // namespace test
  54. } // namespace webrtc
  55. #endif // MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_SINK_H_