concurrent_stream_metric_reporter.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef SERVICES_AUDIO_CONCURRENT_STREAM_METRIC_REPORTER_H_
  5. #define SERVICES_AUDIO_CONCURRENT_STREAM_METRIC_REPORTER_H_
  6. namespace audio {
  7. class InputStreamActivityMonitor {
  8. public:
  9. // Called when an input stream starts recording.
  10. virtual void OnInputStreamActive() = 0;
  11. // Called when an input stream stops recording.
  12. virtual void OnInputStreamInactive() = 0;
  13. };
  14. class OutputStreamActivityMonitor {
  15. public:
  16. // Called when an output stream starts playing audio.
  17. virtual void OnOutputStreamActive() = 0;
  18. // Called when an output stream stops playing audio.
  19. virtual void OnOutputStreamInactive() = 0;
  20. };
  21. // ConcurrentStreamMetricReporter monitors input and output streams and reports
  22. // the maximum number of concurrent active OutputStreams observed during active
  23. // InputStream recording. This provides an estimate of how many audio streams
  24. // need to be mixed for echo cancellation.
  25. //
  26. // This class is not thread safe.
  27. class ConcurrentStreamMetricReporter final
  28. : public InputStreamActivityMonitor,
  29. public OutputStreamActivityMonitor {
  30. public:
  31. // InputStreamActivityMonitor implementation.
  32. void OnInputStreamActive() override;
  33. void OnInputStreamInactive() override;
  34. // OutputStreamActivityMonitor implementation.
  35. void OnOutputStreamActive() override;
  36. void OnOutputStreamInactive() override;
  37. private:
  38. int active_input_stream_count_ = 0;
  39. int active_output_stream_count_ = 0;
  40. int max_concurrent_output_streams_metric_ = 0;
  41. };
  42. } // namespace audio
  43. #endif // SERVICES_AUDIO_CONCURRENT_STREAM_METRIC_REPORTER_H_