Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: media/audio/audio_output_dispatcher.h

Issue 2570923002: Makes AudioOutputDispatcher non-ref-counted. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // AudioOutputDispatcher is a single-threaded base class that dispatches 5 // AudioOutputDispatcher is a single-threaded base class that dispatches
6 // creation and deletion of audio output streams. AudioOutputProxy objects use 6 // creation and deletion of audio output streams. AudioOutputProxy objects use
7 // this class to allocate and recycle actual audio output streams. When playback 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 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 9 // uses to play audio. When playback is stopped, the proxy returns the stream
10 // back to the dispatcher by calling StopStream(). 10 // back to the dispatcher by calling StopStream().
11 // 11 //
12 // AudioManagerBase creates one specialization of AudioOutputDispatcher on the 12 // AudioManagerBase creates one specialization of AudioOutputDispatcher on the
13 // audio thread for each possible set of audio parameters. I.e streams with 13 // audio thread for each possible set of audio parameters. I.e streams with
14 // different parameters are managed independently. The AudioOutputDispatcher 14 // different parameters are managed independently. The AudioOutputDispatcher
15 // instance is then deleted on the audio thread when the AudioManager shuts 15 // instance is then deleted on the audio thread when the AudioManager shuts
16 // down. 16 // down.
17 17
18 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_ 18 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_
19 #define MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_ 19 #define MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_
20 20
21 #include "base/macros.h" 21 #include "base/macros.h"
22 #include "base/memory/ref_counted.h"
23 #include "media/audio/audio_io.h" 22 #include "media/audio/audio_io.h"
24 #include "media/audio/audio_manager.h" 23 #include "media/audio/audio_manager.h"
25 #include "media/base/audio_parameters.h" 24 #include "media/base/audio_parameters.h"
26 25
27 namespace base { 26 namespace base {
28 class SingleThreadTaskRunner; 27 class SingleThreadTaskRunner;
29 } 28 }
30 29
31 namespace media { 30 namespace media {
32 31
33 class AudioOutputProxy; 32 class AudioOutputProxy;
34 33
35 class MEDIA_EXPORT AudioOutputDispatcher 34 class MEDIA_EXPORT AudioOutputDispatcher {
36 : public base::RefCountedThreadSafe<AudioOutputDispatcher> {
37 public: 35 public:
38 AudioOutputDispatcher(AudioManager* audio_manager, 36 AudioOutputDispatcher(AudioManager* audio_manager,
39 const AudioParameters& params, 37 const AudioParameters& params,
40 const std::string& device_id); 38 const std::string& device_id);
39 virtual ~AudioOutputDispatcher();
41 40
42 // Called by AudioOutputProxy to open the stream. 41 // Called by AudioOutputProxy to open the stream.
43 // Returns false, if it fails to open it. 42 // Returns false, if it fails to open it.
44 virtual bool OpenStream() = 0; 43 virtual bool OpenStream() = 0;
45 44
46 // Called by AudioOutputProxy when the stream is started. 45 // Called by AudioOutputProxy when the stream is started.
47 // Uses |callback| to get source data and report errors, if any. 46 // Uses |callback| to get source data and report errors, if any.
48 // Does *not* take ownership of this callback. 47 // Does *not* take ownership of this callback.
49 // Returns true if started successfully, false otherwise. 48 // Returns true if started successfully, false otherwise.
50 virtual bool StartStream(AudioOutputStream::AudioSourceCallback* callback, 49 virtual bool StartStream(AudioOutputStream::AudioSourceCallback* callback,
51 AudioOutputProxy* stream_proxy) = 0; 50 AudioOutputProxy* stream_proxy) = 0;
52 51
53 // Called by AudioOutputProxy when the stream is stopped. 52 // Called by AudioOutputProxy when the stream is stopped.
54 // Ownership of the |stream_proxy| is passed to the dispatcher. 53 // Ownership of the |stream_proxy| is passed to the dispatcher.
55 virtual void StopStream(AudioOutputProxy* stream_proxy) = 0; 54 virtual void StopStream(AudioOutputProxy* stream_proxy) = 0;
56 55
57 // Called by AudioOutputProxy when the volume is set. 56 // Called by AudioOutputProxy when the volume is set.
58 virtual void StreamVolumeSet(AudioOutputProxy* stream_proxy, 57 virtual void StreamVolumeSet(AudioOutputProxy* stream_proxy,
59 double volume) = 0; 58 double volume) = 0;
60 59
61 // Called by AudioOutputProxy when the stream is closed. 60 // Called by AudioOutputProxy when the stream is closed.
62 virtual void CloseStream(AudioOutputProxy* stream_proxy) = 0; 61 virtual void CloseStream(AudioOutputProxy* stream_proxy) = 0;
63 62
64 // Called on the audio thread when the AudioManager is shutting down.
65 virtual void Shutdown() = 0;
66
67 const std::string& device_id() const { return device_id_; } 63 const std::string& device_id() const { return device_id_; }
68 64
69 protected: 65 protected:
70 friend class base::RefCountedThreadSafe<AudioOutputDispatcher>;
71 virtual ~AudioOutputDispatcher();
72
73 // A no-reference-held pointer (we don't want circular references) back to the 66 // A no-reference-held pointer (we don't want circular references) back to the
74 // AudioManager that owns this object. 67 // AudioManager that owns this object.
75 AudioManager* audio_manager_; 68 AudioManager* audio_manager_;
76 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 69 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
77 const AudioParameters params_; 70 const AudioParameters params_;
78 std::string device_id_; 71 std::string device_id_;
79 72
80 private: 73 private:
81 DISALLOW_COPY_AND_ASSIGN(AudioOutputDispatcher); 74 DISALLOW_COPY_AND_ASSIGN(AudioOutputDispatcher);
82 }; 75 };
83 76
84 } // namespace media 77 } // namespace media
85 78
86 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_ 79 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698