audio_renderer.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_BASE_AUDIO_RENDERER_H_
  5. #define MEDIA_BASE_AUDIO_RENDERER_H_
  6. #include "base/callback.h"
  7. #include "base/time/time.h"
  8. #include "media/base/buffering_state.h"
  9. #include "media/base/media_export.h"
  10. #include "media/base/pipeline_status.h"
  11. #include "third_party/abseil-cpp/absl/types/optional.h"
  12. namespace media {
  13. class CdmContext;
  14. class DemuxerStream;
  15. class RendererClient;
  16. class TimeSource;
  17. class MEDIA_EXPORT AudioRenderer {
  18. public:
  19. AudioRenderer();
  20. AudioRenderer(const AudioRenderer&) = delete;
  21. AudioRenderer& operator=(const AudioRenderer&) = delete;
  22. // Stop all operations and fire all pending callbacks.
  23. virtual ~AudioRenderer();
  24. // Initialize an AudioRenderer with |stream|, executing |init_cb| upon
  25. // completion. If initialization fails, only |init_cb|
  26. // (not RendererClient::OnError) will be called.
  27. //
  28. // |cdm_context| can be used to handle encrypted streams. May be null if the
  29. // stream is not encrypted.
  30. //
  31. // AudioRenderer may be reinitialized for playback of a different demuxer
  32. // stream by calling Initialize again when the renderer is in a flushed
  33. // state (i.e. after Flush call, but before StartPlaying). This is used for
  34. // media track switching.
  35. virtual void Initialize(DemuxerStream* stream,
  36. CdmContext* cdm_context,
  37. RendererClient* client,
  38. PipelineStatusCallback init_cb) = 0;
  39. // Returns the TimeSource associated with audio rendering.
  40. virtual TimeSource* GetTimeSource() = 0;
  41. // Discard any audio data, executing |callback| when completed.
  42. //
  43. // Clients should expect |buffering_state_cb| to be called with
  44. // BUFFERING_HAVE_NOTHING while flushing is in progress.
  45. virtual void Flush(base::OnceClosure callback) = 0;
  46. // Starts playback by reading from |stream| and decoding and rendering audio.
  47. //
  48. // Only valid to call after a successful Initialize() or Flush().
  49. virtual void StartPlaying() = 0;
  50. // Sets the output volume.
  51. virtual void SetVolume(float volume) = 0;
  52. // Set a hint indicating target latency. See comment in renderer.h.
  53. // |latency_hint| may be nullopt to indicate the hint has been cleared
  54. // (restore UA default).
  55. virtual void SetLatencyHint(absl::optional<base::TimeDelta> latency_hint) = 0;
  56. // Sets a flag indicating that the AudioRenderer should use or avoid pitch
  57. // preservation when playing back at speeds other than 1.0.
  58. virtual void SetPreservesPitch(bool preserves_pitch) = 0;
  59. // Sets a flag indicating whether the audio stream was played with user
  60. // activation.
  61. virtual void SetWasPlayedWithUserActivation(
  62. bool was_played_with_user_activation) = 0;
  63. };
  64. } // namespace media
  65. #endif // MEDIA_BASE_AUDIO_RENDERER_H_