OLD | NEW |
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 // AudioOutputDispatcherImpl is an implementation of AudioOutputDispatcher. | 5 // AudioOutputDispatcherImpl is an implementation of AudioOutputDispatcher. |
6 // | 6 // |
7 // To avoid opening and closing audio devices more frequently than necessary, | 7 // To avoid opening and closing audio devices more frequently than necessary, |
8 // each dispatcher has a pool of inactive physical streams. A stream is closed | 8 // each dispatcher has a pool of inactive physical streams. A stream is closed |
9 // only if it hasn't been used for a certain period of time (specified via the | 9 // only if it hasn't been used for a certain period of time (specified via the |
10 // constructor). | 10 // constructor). |
(...skipping 22 matching lines...) Expand all Loading... |
33 public: | 33 public: |
34 // |close_delay| specifies delay after the stream is idle until the audio | 34 // |close_delay| specifies delay after the stream is idle until the audio |
35 // device is closed. | 35 // device is closed. |
36 AudioOutputDispatcherImpl(AudioManager* audio_manager, | 36 AudioOutputDispatcherImpl(AudioManager* audio_manager, |
37 const AudioParameters& params, | 37 const AudioParameters& params, |
38 const std::string& output_device_id, | 38 const std::string& output_device_id, |
39 const base::TimeDelta& close_delay); | 39 const base::TimeDelta& close_delay); |
40 | 40 |
41 // Opens a new physical stream if there are no pending streams in | 41 // Opens a new physical stream if there are no pending streams in |
42 // |idle_streams_|. Do not call Close() or Stop() if this method fails. | 42 // |idle_streams_|. Do not call Close() or Stop() if this method fails. |
43 virtual bool OpenStream() override; | 43 bool OpenStream() override; |
44 | 44 |
45 // If there are pending streams in |idle_streams_| then it reuses one of | 45 // If there are pending streams in |idle_streams_| then it reuses one of |
46 // them, otherwise creates a new one. | 46 // them, otherwise creates a new one. |
47 virtual bool StartStream(AudioOutputStream::AudioSourceCallback* callback, | 47 bool StartStream(AudioOutputStream::AudioSourceCallback* callback, |
48 AudioOutputProxy* stream_proxy) override; | 48 AudioOutputProxy* stream_proxy) override; |
49 | 49 |
50 // Stops the stream assigned to the specified proxy and moves it into | 50 // Stops the stream assigned to the specified proxy and moves it into |
51 // |idle_streams_| for reuse by other proxies. | 51 // |idle_streams_| for reuse by other proxies. |
52 virtual void StopStream(AudioOutputProxy* stream_proxy) override; | 52 void StopStream(AudioOutputProxy* stream_proxy) override; |
53 | 53 |
54 virtual void StreamVolumeSet(AudioOutputProxy* stream_proxy, | 54 void StreamVolumeSet(AudioOutputProxy* stream_proxy, double volume) override; |
55 double volume) override; | |
56 | 55 |
57 // Closes |idle_streams_| until the number of |idle_streams_| is equal to the | 56 // Closes |idle_streams_| until the number of |idle_streams_| is equal to the |
58 // |idle_proxies_| count. If there are no |idle_proxies_| a single stream is | 57 // |idle_proxies_| count. If there are no |idle_proxies_| a single stream is |
59 // kept alive until |close_timer_| fires. | 58 // kept alive until |close_timer_| fires. |
60 virtual void CloseStream(AudioOutputProxy* stream_proxy) override; | 59 void CloseStream(AudioOutputProxy* stream_proxy) override; |
61 | 60 |
62 virtual void Shutdown() override; | 61 void Shutdown() override; |
63 | 62 |
64 private: | 63 private: |
65 friend class base::RefCountedThreadSafe<AudioOutputDispatcherImpl>; | 64 friend class base::RefCountedThreadSafe<AudioOutputDispatcherImpl>; |
66 virtual ~AudioOutputDispatcherImpl(); | 65 ~AudioOutputDispatcherImpl() override; |
67 | 66 |
68 // Creates a new physical output stream, opens it and pushes to | 67 // Creates a new physical output stream, opens it and pushes to |
69 // |idle_streams_|. Returns false if the stream couldn't be created or | 68 // |idle_streams_|. Returns false if the stream couldn't be created or |
70 // opened. | 69 // opened. |
71 bool CreateAndOpenStream(); | 70 bool CreateAndOpenStream(); |
72 | 71 |
73 // Closes all |idle_streams_|. | 72 // Closes all |idle_streams_|. |
74 void CloseAllIdleStreams(); | 73 void CloseAllIdleStreams(); |
75 // Similar to CloseAllIdleStreams(), but keeps |keep_alive| streams alive. | 74 // Similar to CloseAllIdleStreams(), but keeps |keep_alive| streams alive. |
76 void CloseIdleStreams(size_t keep_alive); | 75 void CloseIdleStreams(size_t keep_alive); |
(...skipping 13 matching lines...) Expand all Loading... |
90 typedef std::map<AudioOutputStream*, int> AudioStreamIDMap; | 89 typedef std::map<AudioOutputStream*, int> AudioStreamIDMap; |
91 AudioStreamIDMap audio_stream_ids_; | 90 AudioStreamIDMap audio_stream_ids_; |
92 int audio_stream_id_; | 91 int audio_stream_id_; |
93 | 92 |
94 DISALLOW_COPY_AND_ASSIGN(AudioOutputDispatcherImpl); | 93 DISALLOW_COPY_AND_ASSIGN(AudioOutputDispatcherImpl); |
95 }; | 94 }; |
96 | 95 |
97 } // namespace media | 96 } // namespace media |
98 | 97 |
99 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_IMPL_H_ | 98 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_IMPL_H_ |
OLD | NEW |