| 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 class AudioOutputProxy; | 33 class AudioOutputProxy; |
| 34 | 34 |
| 35 class MEDIA_EXPORT AudioOutputDispatcherImpl : public AudioOutputDispatcher { | 35 class MEDIA_EXPORT AudioOutputDispatcherImpl : public AudioOutputDispatcher { |
| 36 public: | 36 public: |
| 37 // |close_delay| specifies delay after the stream is idle until the audio | 37 // |close_delay| specifies delay after the stream is idle until the audio |
| 38 // device is closed. | 38 // device is closed. |
| 39 AudioOutputDispatcherImpl(AudioManager* audio_manager, | 39 AudioOutputDispatcherImpl(AudioManager* audio_manager, |
| 40 const AudioParameters& params, | 40 const AudioParameters& params, |
| 41 const std::string& output_device_id, | 41 const std::string& output_device_id, |
| 42 const base::TimeDelta& close_delay); | 42 const base::TimeDelta& close_delay); |
| 43 ~AudioOutputDispatcherImpl() override; |
| 43 | 44 |
| 44 // Opens a new physical stream if there are no pending streams in | 45 // Opens a new physical stream if there are no pending streams in |
| 45 // |idle_streams_|. Do not call Close() or Stop() if this method fails. | 46 // |idle_streams_|. Do not call Close() or Stop() if this method fails. |
| 46 bool OpenStream() override; | 47 bool OpenStream() override; |
| 47 | 48 |
| 48 // If there are pending streams in |idle_streams_| then it reuses one of | 49 // If there are pending streams in |idle_streams_| then it reuses one of |
| 49 // them, otherwise creates a new one. | 50 // them, otherwise creates a new one. |
| 50 bool StartStream(AudioOutputStream::AudioSourceCallback* callback, | 51 bool StartStream(AudioOutputStream::AudioSourceCallback* callback, |
| 51 AudioOutputProxy* stream_proxy) override; | 52 AudioOutputProxy* stream_proxy) override; |
| 52 | 53 |
| 53 // Stops the stream assigned to the specified proxy and moves it into | 54 // Stops the stream assigned to the specified proxy and moves it into |
| 54 // |idle_streams_| for reuse by other proxies. | 55 // |idle_streams_| for reuse by other proxies. |
| 55 void StopStream(AudioOutputProxy* stream_proxy) override; | 56 void StopStream(AudioOutputProxy* stream_proxy) override; |
| 56 | 57 |
| 57 void StreamVolumeSet(AudioOutputProxy* stream_proxy, double volume) override; | 58 void StreamVolumeSet(AudioOutputProxy* stream_proxy, double volume) override; |
| 58 | 59 |
| 59 // Closes |idle_streams_| until the number of |idle_streams_| is equal to the | 60 // Closes |idle_streams_| until the number of |idle_streams_| is equal to the |
| 60 // |idle_proxies_| count. If there are no |idle_proxies_| a single stream is | 61 // |idle_proxies_| count. If there are no |idle_proxies_| a single stream is |
| 61 // kept alive until |close_timer_| fires. | 62 // kept alive until |close_timer_| fires. |
| 62 void CloseStream(AudioOutputProxy* stream_proxy) override; | 63 void CloseStream(AudioOutputProxy* stream_proxy) override; |
| 63 | 64 |
| 64 void Shutdown() override; | |
| 65 | |
| 66 // Returns true if there are any open AudioOutputProxy objects. | 65 // Returns true if there are any open AudioOutputProxy objects. |
| 67 bool HasOutputProxies() const; | 66 bool HasOutputProxies() const; |
| 68 | 67 |
| 69 // Closes all |idle_streams_|. | 68 // Closes all |idle_streams_|. |
| 70 void CloseAllIdleStreams(); | 69 void CloseAllIdleStreams(); |
| 71 | 70 |
| 72 private: | 71 private: |
| 73 friend class base::RefCountedThreadSafe<AudioOutputDispatcherImpl>; | |
| 74 ~AudioOutputDispatcherImpl() override; | |
| 75 | |
| 76 // Creates a new physical output stream, opens it and pushes to | 72 // Creates a new physical output stream, opens it and pushes to |
| 77 // |idle_streams_|. Returns false if the stream couldn't be created or | 73 // |idle_streams_|. Returns false if the stream couldn't be created or |
| 78 // opened. | 74 // opened. |
| 79 bool CreateAndOpenStream(); | 75 bool CreateAndOpenStream(); |
| 80 | 76 |
| 81 // Similar to CloseAllIdleStreams(), but keeps |keep_alive| streams alive. | 77 // Similar to CloseAllIdleStreams(), but keeps |keep_alive| streams alive. |
| 82 void CloseIdleStreams(size_t keep_alive); | 78 void CloseIdleStreams(size_t keep_alive); |
| 83 | 79 |
| 84 size_t idle_proxies_; | 80 size_t idle_proxies_; |
| 85 std::vector<AudioOutputStream*> idle_streams_; | 81 std::vector<AudioOutputStream*> idle_streams_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 96 typedef std::map<AudioOutputStream*, int> AudioStreamIDMap; | 92 typedef std::map<AudioOutputStream*, int> AudioStreamIDMap; |
| 97 AudioStreamIDMap audio_stream_ids_; | 93 AudioStreamIDMap audio_stream_ids_; |
| 98 int audio_stream_id_; | 94 int audio_stream_id_; |
| 99 | 95 |
| 100 DISALLOW_COPY_AND_ASSIGN(AudioOutputDispatcherImpl); | 96 DISALLOW_COPY_AND_ASSIGN(AudioOutputDispatcherImpl); |
| 101 }; | 97 }; |
| 102 | 98 |
| 103 } // namespace media | 99 } // namespace media |
| 104 | 100 |
| 105 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_IMPL_H_ | 101 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_IMPL_H_ |
| OLD | NEW |