Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / media / base / audio_renderer_sink.h
blob753135d0c261516e348098cbc147ea8cd559ff56
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.
5 #ifndef MEDIA_BASE_AUDIO_RENDERER_SINK_H_
6 #define MEDIA_BASE_AUDIO_RENDERER_SINK_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/logging.h"
14 #include "base/memory/ref_counted.h"
15 #include "media/audio/audio_output_ipc.h"
16 #include "media/audio/audio_parameters.h"
17 #include "media/base/audio_bus.h"
18 #include "media/base/media_export.h"
19 #include "url/gurl.h"
21 namespace base {
22 class SingleThreadTaskRunner;
25 namespace media {
27 typedef base::Callback<void(SwitchOutputDeviceResult)> SwitchOutputDeviceCB;
29 // AudioRendererSink is an interface representing the end-point for
30 // rendered audio. An implementation is expected to
31 // periodically call Render() on a callback object.
33 class AudioRendererSink
34 : public base::RefCountedThreadSafe<media::AudioRendererSink> {
35 public:
36 class RenderCallback {
37 public:
38 // Attempts to completely fill all channels of |dest|, returns actual
39 // number of frames filled.
40 virtual int Render(AudioBus* dest, int audio_delay_milliseconds) = 0;
42 // Signals an error has occurred.
43 virtual void OnRenderError() = 0;
45 protected:
46 virtual ~RenderCallback() {}
49 // Sets important information about the audio stream format.
50 // It must be called before any of the other methods.
51 virtual void Initialize(const AudioParameters& params,
52 RenderCallback* callback) = 0;
54 // Starts audio playback.
55 virtual void Start() = 0;
57 // Stops audio playback.
58 virtual void Stop() = 0;
60 // Pauses playback.
61 virtual void Pause() = 0;
63 // Resumes playback after calling Pause().
64 virtual void Play() = 0;
66 // Sets the playback volume, with range [0.0, 1.0] inclusive.
67 // Returns |true| on success.
68 virtual bool SetVolume(double volume) = 0;
70 // Attempts to switch the audio output device.
71 // Once the attempt is finished, |callback| is invoked with the
72 // result of the operation passed as a parameter. The result is a value from
73 // the media::SwitchOutputDeviceResult enum.
74 // There is no guarantee about the thread where |callback| will
75 // be invoked, so users are advised to use media::BindToCurrentLoop() to
76 // ensure that |callback| runs on the correct thread.
77 // Note also that copy constructors and destructors for arguments bound to
78 // |callback| may run on arbitrary threads as |callback| is moved across
79 // threads. It is advisable to bind arguments such that they are released by
80 // |callback| when it runs in order to avoid surprises.
81 virtual void SwitchOutputDevice(const std::string& device_id,
82 const GURL& security_origin,
83 const SwitchOutputDeviceCB& callback) = 0;
85 protected:
86 friend class base::RefCountedThreadSafe<AudioRendererSink>;
87 virtual ~AudioRendererSink() {}
90 } // namespace media
92 #endif // MEDIA_BASE_AUDIO_RENDERER_SINK_H_