null_audio_sink.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright (c) 2012 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 MEDIA_AUDIO_NULL_AUDIO_SINK_H_
  5. #define MEDIA_AUDIO_NULL_AUDIO_SINK_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/memory/raw_ptr.h"
  9. #include "base/time/time.h"
  10. #include "media/base/audio_renderer_sink.h"
  11. namespace base {
  12. class SingleThreadTaskRunner;
  13. }
  14. namespace media {
  15. class AudioBus;
  16. class AudioHash;
  17. class FakeAudioWorker;
  18. class MEDIA_EXPORT NullAudioSink : public SwitchableAudioRendererSink {
  19. public:
  20. explicit NullAudioSink(
  21. const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
  22. NullAudioSink(const NullAudioSink&) = delete;
  23. NullAudioSink& operator=(const NullAudioSink&) = delete;
  24. // AudioRendererSink implementation.
  25. void Initialize(const AudioParameters& params,
  26. RenderCallback* callback) override;
  27. void Start() override;
  28. void Stop() override;
  29. void Pause() override;
  30. void Play() override;
  31. void Flush() override;
  32. bool SetVolume(double volume) override;
  33. OutputDeviceInfo GetOutputDeviceInfo() override;
  34. void GetOutputDeviceInfoAsync(OutputDeviceInfoCB info_cb) override;
  35. bool IsOptimizedForHardwareParameters() override;
  36. bool CurrentThreadIsRenderingThread() override;
  37. void SwitchOutputDevice(const std::string& device_id,
  38. OutputDeviceStatusCB callback) override;
  39. // Enables audio frame hashing. Must be called prior to Initialize().
  40. void StartAudioHashForTesting();
  41. // Returns the hash of all audio frames seen since construction.
  42. std::string GetAudioHashForTesting();
  43. protected:
  44. ~NullAudioSink() override;
  45. private:
  46. // Task that periodically calls Render() to consume audio data.
  47. void CallRender(base::TimeTicks ideal_time, base::TimeTicks now);
  48. bool initialized_;
  49. bool started_;
  50. bool playing_;
  51. raw_ptr<RenderCallback> callback_;
  52. // Controls whether or not a running hash is computed for audio frames.
  53. std::unique_ptr<AudioHash> audio_hash_;
  54. scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
  55. std::unique_ptr<FakeAudioWorker> fake_worker_;
  56. base::TimeDelta fixed_data_delay_;
  57. std::unique_ptr<AudioBus> audio_bus_;
  58. };
  59. } // namespace media
  60. #endif // MEDIA_AUDIO_NULL_AUDIO_SINK_H_