clockless_audio_sink.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2013 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_CLOCKLESS_AUDIO_SINK_H_
  5. #define MEDIA_AUDIO_CLOCKLESS_AUDIO_SINK_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/time/time.h"
  9. #include "media/base/audio_renderer_sink.h"
  10. namespace media {
  11. class ClocklessAudioSinkThread;
  12. // Implementation of an AudioRendererSink that consumes the audio as fast as
  13. // possible. This class does not support multiple Play()/Pause() events.
  14. class MEDIA_EXPORT ClocklessAudioSink : public AudioRendererSink {
  15. public:
  16. ClocklessAudioSink();
  17. explicit ClocklessAudioSink(const OutputDeviceInfo& device_info);
  18. ClocklessAudioSink(const ClocklessAudioSink&) = delete;
  19. ClocklessAudioSink& operator=(const ClocklessAudioSink&) = delete;
  20. // AudioRendererSink implementation.
  21. void Initialize(const AudioParameters& params,
  22. RenderCallback* callback) override;
  23. void Start() override;
  24. void Stop() override;
  25. void Flush() override;
  26. void Pause() override;
  27. void Play() override;
  28. bool SetVolume(double volume) override;
  29. OutputDeviceInfo GetOutputDeviceInfo() override;
  30. void GetOutputDeviceInfoAsync(OutputDeviceInfoCB info_cb) override;
  31. bool IsOptimizedForHardwareParameters() override;
  32. bool CurrentThreadIsRenderingThread() override;
  33. // Returns the time taken to consume all the audio.
  34. base::TimeDelta render_time() { return playback_time_; }
  35. // Enables audio frame hashing. Must be called prior to Initialize().
  36. void StartAudioHashForTesting();
  37. // Returns the hash of all audio frames seen since construction.
  38. std::string GetAudioHashForTesting();
  39. void SetIsOptimizedForHardwareParametersForTesting(bool value);
  40. protected:
  41. ~ClocklessAudioSink() override;
  42. private:
  43. const OutputDeviceInfo device_info_;
  44. std::unique_ptr<ClocklessAudioSinkThread> thread_;
  45. bool initialized_;
  46. bool playing_;
  47. bool hashing_;
  48. bool is_optimized_for_hw_params_;
  49. // Time taken in last set of Render() calls.
  50. base::TimeDelta playback_time_;
  51. };
  52. } // namespace media
  53. #endif // MEDIA_AUDIO_CLOCKLESS_AUDIO_SINK_H_