audio_input_stream_data_interceptor.cc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Copyright 2017 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. #include "media/audio/audio_input_stream_data_interceptor.h"
  5. #include <utility>
  6. #include "media/audio/audio_debug_recording_helper.h"
  7. namespace media {
  8. AudioInputStreamDataInterceptor::AudioInputStreamDataInterceptor(
  9. CreateDebugRecorderCB create_debug_recorder_cb,
  10. AudioInputStream* stream)
  11. : create_debug_recorder_cb_(std::move(create_debug_recorder_cb)),
  12. stream_(stream) {
  13. DCHECK(create_debug_recorder_cb_);
  14. DCHECK(stream_);
  15. }
  16. AudioInputStreamDataInterceptor::~AudioInputStreamDataInterceptor() {
  17. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  18. }
  19. // Implementation of AudioInputStream.
  20. AudioInputStream::OpenOutcome AudioInputStreamDataInterceptor::Open() {
  21. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  22. return stream_->Open();
  23. }
  24. void AudioInputStreamDataInterceptor::Start(
  25. AudioInputStream::AudioInputCallback* callback) {
  26. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  27. callback_ = callback;
  28. debug_recorder_ = create_debug_recorder_cb_.Run();
  29. stream_->Start(this);
  30. }
  31. void AudioInputStreamDataInterceptor::Stop() {
  32. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  33. stream_->Stop();
  34. debug_recorder_.reset();
  35. callback_ = nullptr;
  36. }
  37. void AudioInputStreamDataInterceptor::Close() {
  38. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  39. stream_->Close();
  40. delete this;
  41. }
  42. double AudioInputStreamDataInterceptor::GetMaxVolume() {
  43. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  44. return stream_->GetMaxVolume();
  45. }
  46. void AudioInputStreamDataInterceptor::SetVolume(double volume) {
  47. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  48. stream_->SetVolume(volume);
  49. }
  50. double AudioInputStreamDataInterceptor::GetVolume() {
  51. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  52. return stream_->GetVolume();
  53. }
  54. bool AudioInputStreamDataInterceptor::IsMuted() {
  55. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  56. return stream_->IsMuted();
  57. }
  58. bool AudioInputStreamDataInterceptor::SetAutomaticGainControl(bool enabled) {
  59. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  60. return stream_->SetAutomaticGainControl(enabled);
  61. }
  62. bool AudioInputStreamDataInterceptor::GetAutomaticGainControl() {
  63. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  64. return stream_->GetAutomaticGainControl();
  65. }
  66. void AudioInputStreamDataInterceptor::SetOutputDeviceForAec(
  67. const std::string& output_device_id) {
  68. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  69. return stream_->SetOutputDeviceForAec(output_device_id);
  70. }
  71. void AudioInputStreamDataInterceptor::OnData(const AudioBus* source,
  72. base::TimeTicks capture_time,
  73. double volume) {
  74. callback_->OnData(source, capture_time, volume);
  75. debug_recorder_->OnData(source);
  76. }
  77. void AudioInputStreamDataInterceptor::OnError() {
  78. callback_->OnError();
  79. }
  80. } // namespace media