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

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

Issue 2621993002: Makes AudioOutputProxy -> AudioOutputDispatcher reference weak. (Closed)
Patch Set: adds StopPhysicalStream Created 3 years, 11 months 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
« no previous file with comments | « media/audio/audio_output_dispatcher.h ('k') | media/audio/audio_output_dispatcher_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // 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 24 matching lines...) Expand all
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 ~AudioOutputDispatcherImpl() override;
44 44
45 // Opens a new physical stream if there are no pending streams in 45 // AudioOutputDispatcher implementation.
46 // |idle_streams_|. Do not call Close() or Stop() if this method fails. 46 AudioOutputProxy* CreateStreamProxy() override;
47 bool OpenStream() override; 47 bool OpenStream() override;
48
49 // If there are pending streams in |idle_streams_| then it reuses one of
50 // them, otherwise creates a new one.
51 bool StartStream(AudioOutputStream::AudioSourceCallback* callback, 48 bool StartStream(AudioOutputStream::AudioSourceCallback* callback,
52 AudioOutputProxy* stream_proxy) override; 49 AudioOutputProxy* stream_proxy) override;
53
54 // Stops the stream assigned to the specified proxy and moves it into
55 // |idle_streams_| for reuse by other proxies.
56 void StopStream(AudioOutputProxy* stream_proxy) override; 50 void StopStream(AudioOutputProxy* stream_proxy) override;
57
58 void StreamVolumeSet(AudioOutputProxy* stream_proxy, double volume) override; 51 void StreamVolumeSet(AudioOutputProxy* stream_proxy, double volume) override;
59
60 // Closes |idle_streams_| until the number of |idle_streams_| is equal to the
61 // |idle_proxies_| count. If there are no |idle_proxies_| a single stream is
62 // kept alive until |close_timer_| fires.
63 void CloseStream(AudioOutputProxy* stream_proxy) override; 52 void CloseStream(AudioOutputProxy* stream_proxy) override;
64 53
65 // Returns true if there are any open AudioOutputProxy objects. 54 // Returns true if there are any open AudioOutputProxy objects.
66 bool HasOutputProxies() const; 55 bool HasOutputProxies() const;
67 56
68 // Closes all |idle_streams_|. 57 // Closes all |idle_streams_|.
69 void CloseAllIdleStreams(); 58 void CloseAllIdleStreams();
70 59
71 private: 60 private:
72 // Creates a new physical output stream, opens it and pushes to 61 // Creates a new physical output stream, opens it and pushes to
73 // |idle_streams_|. Returns false if the stream couldn't be created or 62 // |idle_streams_|. Returns false if the stream couldn't be created or
74 // opened. 63 // opened.
75 bool CreateAndOpenStream(); 64 bool CreateAndOpenStream();
76 65
77 // Similar to CloseAllIdleStreams(), but keeps |keep_alive| streams alive. 66 // Similar to CloseAllIdleStreams(), but keeps |keep_alive| streams alive.
78 void CloseIdleStreams(size_t keep_alive); 67 void CloseIdleStreams(size_t keep_alive);
79 68
69 void StopPhysicalStream(AudioOutputStream* stream);
70
80 size_t idle_proxies_; 71 size_t idle_proxies_;
81 std::vector<AudioOutputStream*> idle_streams_; 72 std::vector<AudioOutputStream*> idle_streams_;
82 73
83 // When streams are stopped they're added to |idle_streams_|, if no stream is 74 // When streams are stopped they're added to |idle_streams_|, if no stream is
84 // reused before |close_delay_| elapses |close_timer_| will run 75 // reused before |close_delay_| elapses |close_timer_| will run
85 // CloseIdleStreams(). 76 // CloseIdleStreams().
86 base::DelayTimer close_timer_; 77 base::DelayTimer close_timer_;
87 78
88 typedef std::map<AudioOutputProxy*, AudioOutputStream*> AudioStreamMap; 79 typedef std::map<AudioOutputProxy*, AudioOutputStream*> AudioStreamMap;
89 AudioStreamMap proxy_to_physical_map_; 80 AudioStreamMap proxy_to_physical_map_;
90 81
91 std::unique_ptr<AudioLog> audio_log_; 82 std::unique_ptr<AudioLog> audio_log_;
92 typedef std::map<AudioOutputStream*, int> AudioStreamIDMap; 83 typedef std::map<AudioOutputStream*, int> AudioStreamIDMap;
93 AudioStreamIDMap audio_stream_ids_; 84 AudioStreamIDMap audio_stream_ids_;
94 int audio_stream_id_; 85 int audio_stream_id_;
95 86
87 base::WeakPtrFactory<AudioOutputDispatcherImpl> weak_factory_;
96 DISALLOW_COPY_AND_ASSIGN(AudioOutputDispatcherImpl); 88 DISALLOW_COPY_AND_ASSIGN(AudioOutputDispatcherImpl);
97 }; 89 };
98 90
99 } // namespace media 91 } // namespace media
100 92
101 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_IMPL_H_ 93 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_IMPL_H_
OLDNEW
« no previous file with comments | « media/audio/audio_output_dispatcher.h ('k') | media/audio/audio_output_dispatcher_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698