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 // AudioOutputDispatcher is a single-threaded base class that dispatches
6 // creation and deletion of audio output streams. AudioOutputProxy objects use
7 // this class to allocate and recycle actual audio output streams. When playback
8 // is started, the proxy calls StartStream() to get an output stream that it
9 // uses to play audio. When playback is stopped, the proxy returns the stream
10 // back to the dispatcher by calling StopStream().
12 // AudioManagerBase creates one specialization of AudioOutputDispatcher on the
13 // audio thread for each possible set of audio parameters. I.e streams with
14 // different parameters are managed independently. The AudioOutputDispatcher
15 // instance is then deleted on the audio thread when the AudioManager shuts
18 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_
19 #define MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_
25 #include "base/basictypes.h"
26 #include "base/memory/ref_counted.h"
27 #include "base/timer/timer.h"
28 #include "media/audio/audio_io.h"
29 #include "media/audio/audio_manager.h"
30 #include "media/audio/audio_parameters.h"
33 class SingleThreadTaskRunner;
38 class AudioOutputProxy;
40 class MEDIA_EXPORT AudioOutputDispatcher
41 : public base::RefCountedThreadSafe<AudioOutputDispatcher> {
43 AudioOutputDispatcher(AudioManager* audio_manager,
44 const AudioParameters& params,
45 const std::string& device_id);
47 // Called by AudioOutputProxy to open the stream.
48 // Returns false, if it fails to open it.
49 virtual bool OpenStream() = 0;
51 // Called by AudioOutputProxy when the stream is started.
52 // Uses |callback| to get source data and report errors, if any.
53 // Does *not* take ownership of this callback.
54 // Returns true if started successfully, false otherwise.
55 virtual bool StartStream(AudioOutputStream::AudioSourceCallback* callback,
56 AudioOutputProxy* stream_proxy) = 0;
58 // Called by AudioOutputProxy when the stream is stopped.
59 // Ownership of the |stream_proxy| is passed to the dispatcher.
60 virtual void StopStream(AudioOutputProxy* stream_proxy) = 0;
62 // Called by AudioOutputProxy when the volume is set.
63 virtual void StreamVolumeSet(AudioOutputProxy* stream_proxy,
66 // Called by AudioOutputProxy when the stream is closed.
67 virtual void CloseStream(AudioOutputProxy* stream_proxy) = 0;
69 // Called on the audio thread when the AudioManager is shutting down.
70 virtual void Shutdown() = 0;
72 const std::string& device_id() const { return device_id_; }
75 virtual void SetMediaStreamProperties(const std::string& app_id,
76 const std::string& app_class);
80 friend class base::RefCountedThreadSafe<AudioOutputDispatcher>;
81 virtual ~AudioOutputDispatcher();
83 // A no-reference-held pointer (we don't want circular references) back to the
84 // AudioManager that owns this object.
85 AudioManager* audio_manager_;
86 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
87 const AudioParameters params_;
88 std::string device_id_;
92 std::string app_class_;
96 DISALLOW_COPY_AND_ASSIGN(AudioOutputDispatcher);
101 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_