frame_combiner.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2017 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_MIXER_FRAME_COMBINER_H_
  11. #define MODULES_AUDIO_MIXER_FRAME_COMBINER_H_
  12. #include <memory>
  13. #include <vector>
  14. #include "api/audio/audio_frame.h"
  15. #include "modules/audio_processing/agc2/limiter.h"
  16. namespace webrtc {
  17. class ApmDataDumper;
  18. class FrameCombiner {
  19. public:
  20. enum class LimiterType { kNoLimiter, kApmAgcLimiter, kApmAgc2Limiter };
  21. explicit FrameCombiner(bool use_limiter);
  22. ~FrameCombiner();
  23. // Combine several frames into one. Assumes sample_rate,
  24. // samples_per_channel of the input frames match the parameters. The
  25. // parameters 'number_of_channels' and 'sample_rate' are needed
  26. // because 'mix_list' can be empty. The parameter
  27. // 'number_of_streams' is used for determining whether to pass the
  28. // data through a limiter.
  29. void Combine(const std::vector<AudioFrame*>& mix_list,
  30. size_t number_of_channels,
  31. int sample_rate,
  32. size_t number_of_streams,
  33. AudioFrame* audio_frame_for_mixing);
  34. // Stereo, 48 kHz, 10 ms.
  35. static constexpr size_t kMaximumNumberOfChannels = 8;
  36. static constexpr size_t kMaximumChannelSize = 48 * 10;
  37. using MixingBuffer = std::array<std::array<float, kMaximumChannelSize>,
  38. kMaximumNumberOfChannels>;
  39. private:
  40. void LogMixingStats(const std::vector<AudioFrame*>& mix_list,
  41. int sample_rate,
  42. size_t number_of_streams) const;
  43. std::unique_ptr<ApmDataDumper> data_dumper_;
  44. std::unique_ptr<MixingBuffer> mixing_buffer_;
  45. Limiter limiter_;
  46. const bool use_limiter_;
  47. mutable int uma_logging_counter_ = 0;
  48. };
  49. } // namespace webrtc
  50. #endif // MODULES_AUDIO_MIXER_FRAME_COMBINER_H_