audio_mixer.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (c) 2011 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 API_AUDIO_AUDIO_MIXER_H_
  11. #define API_AUDIO_AUDIO_MIXER_H_
  12. #include <memory>
  13. #include "api/audio/audio_frame.h"
  14. #include "rtc_base/ref_count.h"
  15. namespace webrtc {
  16. // WORK IN PROGRESS
  17. // This class is under development and is not yet intended for for use outside
  18. // of WebRtc/Libjingle.
  19. class AudioMixer : public rtc::RefCountInterface {
  20. public:
  21. // A callback class that all mixer participants must inherit from/implement.
  22. class Source {
  23. public:
  24. enum class AudioFrameInfo {
  25. kNormal, // The samples in audio_frame are valid and should be used.
  26. kMuted, // The samples in audio_frame should not be used, but
  27. // should be implicitly interpreted as zero. Other
  28. // fields in audio_frame may be read and should
  29. // contain meaningful values.
  30. kError, // The audio_frame will not be used.
  31. };
  32. // Overwrites |audio_frame|. The data_ field is overwritten with
  33. // 10 ms of new audio (either 1 or 2 interleaved channels) at
  34. // |sample_rate_hz|. All fields in |audio_frame| must be updated.
  35. virtual AudioFrameInfo GetAudioFrameWithInfo(int sample_rate_hz,
  36. AudioFrame* audio_frame) = 0;
  37. // A way for a mixer implementation to distinguish participants.
  38. virtual int Ssrc() const = 0;
  39. // A way for this source to say that GetAudioFrameWithInfo called
  40. // with this sample rate or higher will not cause quality loss.
  41. virtual int PreferredSampleRate() const = 0;
  42. virtual ~Source() {}
  43. };
  44. // Returns true if adding was successful. A source is never added
  45. // twice. Addition and removal can happen on different threads.
  46. virtual bool AddSource(Source* audio_source) = 0;
  47. // Removal is never attempted if a source has not been successfully
  48. // added to the mixer.
  49. virtual void RemoveSource(Source* audio_source) = 0;
  50. // Performs mixing by asking registered audio sources for audio. The
  51. // mixed result is placed in the provided AudioFrame. This method
  52. // will only be called from a single thread. The channels argument
  53. // specifies the number of channels of the mix result. The mixer
  54. // should mix at a rate that doesn't cause quality loss of the
  55. // sources' audio. The mixing rate is one of the rates listed in
  56. // AudioProcessing::NativeRate. All fields in
  57. // |audio_frame_for_mixing| must be updated.
  58. virtual void Mix(size_t number_of_channels,
  59. AudioFrame* audio_frame_for_mixing) = 0;
  60. protected:
  61. // Since the mixer is reference counted, the destructor may be
  62. // called from any thread.
  63. ~AudioMixer() override {}
  64. };
  65. } // namespace webrtc
  66. #endif // API_AUDIO_AUDIO_MIXER_H_