OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 // AudioMirroringManager is a singleton object that maintains a set of active | 5 // AudioMirroringManager is a singleton object that maintains a set of active |
6 // audio mirroring destinations and auto-connects/disconnects audio streams | 6 // audio mirroring destinations and auto-connects/disconnects audio streams |
7 // to/from those destinations. It is meant to be used exclusively on the IO | 7 // to/from those destinations. It is meant to be used exclusively on the IO |
8 // thread. | 8 // thread. |
9 // | 9 // |
10 // How it works: | 10 // How it works: |
(...skipping 14 matching lines...) Expand all Loading... | |
25 // request a "refresh" query on a MirroringDestination, and this will | 25 // request a "refresh" query on a MirroringDestination, and this will |
26 // result in AudioMirroringManager starting/stopping only those Diverters | 26 // result in AudioMirroringManager starting/stopping only those Diverters |
27 // that are not correctly routed to the destination. | 27 // that are not correctly routed to the destination. |
28 // 3c. When a mirroring session is stopped, the remaining destinations will be | 28 // 3c. When a mirroring session is stopped, the remaining destinations will be |
29 // queried to determine whether diverting should continue to a different | 29 // queried to determine whether diverting should continue to a different |
30 // destination. | 30 // destination. |
31 | 31 |
32 #ifndef CONTENT_BROWSER_MEDIA_CAPTURE_AUDIO_MIRRORING_MANAGER_H_ | 32 #ifndef CONTENT_BROWSER_MEDIA_CAPTURE_AUDIO_MIRRORING_MANAGER_H_ |
33 #define CONTENT_BROWSER_MEDIA_CAPTURE_AUDIO_MIRRORING_MANAGER_H_ | 33 #define CONTENT_BROWSER_MEDIA_CAPTURE_AUDIO_MIRRORING_MANAGER_H_ |
34 | 34 |
35 #include <map> | |
35 #include <set> | 36 #include <set> |
36 #include <utility> | 37 #include <utility> |
37 #include <vector> | 38 #include <vector> |
38 | 39 |
39 #include "base/callback_forward.h" | 40 #include "base/callback_forward.h" |
40 #include "base/macros.h" | 41 #include "base/macros.h" |
41 #include "base/threading/thread_checker.h" | 42 #include "base/threading/thread_checker.h" |
42 #include "content/common/content_export.h" | 43 #include "content/common/content_export.h" |
43 #include "media/audio/audio_source_diverter.h" | 44 #include "media/audio/audio_source_diverter.h" |
45 #include "media/audio/virtual_audio_sink.h" | |
44 | 46 |
45 namespace media { | 47 namespace media { |
46 class AudioOutputStream; | 48 class AudioOutputStream; |
47 } | 49 } |
48 | 50 |
49 namespace content { | 51 namespace content { |
50 | 52 |
51 class CONTENT_EXPORT AudioMirroringManager { | 53 class CONTENT_EXPORT AudioMirroringManager { |
52 public: | 54 public: |
53 // Interface for diverting audio data to an alternative AudioOutputStream. | 55 // Interface for diverting audio data to an alternative AudioOutputStream. |
54 typedef media::AudioSourceDiverter Diverter; | 56 typedef media::AudioSourceDiverter Diverter; |
55 | 57 |
56 // A SourceFrameRef is a RenderFrameHost identified by a <render_process_id, | 58 // A SourceFrameRef is a RenderFrameHost identified by a <render_process_id, |
57 // render_frame_id> pair. | 59 // render_frame_id> pair. |
58 typedef std::pair<int, int> SourceFrameRef; | 60 typedef std::pair<int, int> SourceFrameRef; |
59 | 61 |
60 // Interface to be implemented by audio mirroring destinations. See comments | 62 // Interface to be implemented by audio mirroring destinations. See comments |
61 // for StartMirroring() and StopMirroring() below. | 63 // for StartMirroring() and StopMirroring() below. |
62 class MirroringDestination { | 64 class MirroringDestination { |
63 public: | 65 public: |
64 // Asynchronously query whether this MirroringDestination wants to consume | 66 // Asynchronously query whether this MirroringDestination wants to consume |
65 // audio sourced from each of the |candidates|. |results_callback| is run | 67 // audio sourced from each of the |candidates|. |results_callback| is run |
66 // to indicate which of them (or none) should have audio routed to this | 68 // to indicate which of them (or none) should have audio routed to this |
67 // MirroringDestination. |results_callback| must be run on the same thread | 69 // MirroringDestination. |results_callback| must be run on the same thread |
68 // as the one that called QueryForMatches(). | 70 // as the one that called QueryForMatches(). |
69 typedef base::Callback<void(const std::set<SourceFrameRef>&)> | 71 typedef base::Callback<void(const std::set<SourceFrameRef>&, bool)> |
miu
2016/05/02 20:06:13
Please document what this new bool argument is for
qiangchen
2016/05/03 16:58:23
Done.
| |
70 MatchesCallback; | 72 MatchesCallback; |
71 virtual void QueryForMatches( | 73 virtual void QueryForMatches( |
72 const std::set<SourceFrameRef>& candidates, | 74 const std::set<SourceFrameRef>& candidates, |
73 const MatchesCallback& results_callback) = 0; | 75 const MatchesCallback& results_callback) = 0; |
74 | 76 |
75 // Create a consumer of audio data in the format specified by |params|, and | 77 // Create a consumer of audio data in the format specified by |params|, and |
76 // connect it as an input to mirroring. When Close() is called on the | 78 // connect it as an input to mirroring. When Close() is called on the |
77 // returned AudioOutputStream, the input is disconnected and the object | 79 // returned AudioOutputStream, the input is disconnected and the object |
78 // becomes invalid. | 80 // becomes invalid. |
miu
2016/05/02 20:06:12
Comment should add: This is used to provide the Mi
qiangchen
2016/05/03 16:58:23
Done.
| |
79 virtual media::AudioOutputStream* AddInput( | 81 virtual media::AudioOutputStream* AddInput( |
80 const media::AudioParameters& params) = 0; | 82 const media::AudioParameters& params) = 0; |
81 | 83 |
84 virtual media::AudioPushSink* AddPushInput( | |
miu
2016/05/02 20:06:12
Need comment here. It should mention this is the
qiangchen
2016/05/03 16:58:23
Done.
| |
85 const media::AudioParameters& params) = 0; | |
86 | |
82 protected: | 87 protected: |
83 virtual ~MirroringDestination() {} | 88 virtual ~MirroringDestination() {} |
84 }; | 89 }; |
85 | 90 |
86 // Note: Use GetInstance() for non-test code. | 91 // Note: Use GetInstance() for non-test code. |
87 AudioMirroringManager(); | 92 AudioMirroringManager(); |
88 virtual ~AudioMirroringManager(); | 93 virtual ~AudioMirroringManager(); |
89 | 94 |
90 // Returns the global instance. | 95 // Returns the global instance. |
91 static AudioMirroringManager* GetInstance(); | 96 static AudioMirroringManager* GetInstance(); |
(...skipping 21 matching lines...) Expand all Loading... | |
113 // The source render frame associated with the audio stream. | 118 // The source render frame associated with the audio stream. |
114 SourceFrameRef source_render_frame; | 119 SourceFrameRef source_render_frame; |
115 | 120 |
116 // The diverter for re-routing the audio stream. | 121 // The diverter for re-routing the audio stream. |
117 Diverter* diverter; | 122 Diverter* diverter; |
118 | 123 |
119 // If not NULL, the audio stream is currently being diverted to this | 124 // If not NULL, the audio stream is currently being diverted to this |
120 // destination. | 125 // destination. |
121 MirroringDestination* destination; | 126 MirroringDestination* destination; |
122 | 127 |
128 // The destinations to which audio stream is duplicated. | |
miu
2016/05/02 20:06:13
Comment should mention that AudioPushSink is owned
qiangchen
2016/05/03 16:58:23
Done.
| |
129 std::map<MirroringDestination*, media::AudioPushSink*> dup_destinations; | |
miu
2016/05/02 20:06:12
naming nit: How about "duplications" instead? (si
qiangchen
2016/05/03 16:58:23
Done.
| |
130 | |
123 StreamRoutingState(const SourceFrameRef& source_frame, | 131 StreamRoutingState(const SourceFrameRef& source_frame, |
124 Diverter* stream_diverter); | 132 Diverter* stream_diverter); |
125 StreamRoutingState(const StreamRoutingState& other); | 133 StreamRoutingState(const StreamRoutingState& other); |
126 ~StreamRoutingState(); | 134 ~StreamRoutingState(); |
127 }; | 135 }; |
128 | 136 |
129 typedef std::vector<StreamRoutingState> StreamRoutes; | 137 typedef std::vector<StreamRoutingState> StreamRoutes; |
130 typedef std::vector<MirroringDestination*> Destinations; | 138 typedef std::vector<MirroringDestination*> Destinations; |
131 | 139 |
132 // Helper to find a destination other than |old_destination| for the given | 140 // Helper to find a destination other than |old_destination| for the given |
133 // |candidates| to be diverted to. | 141 // |candidates| to be diverted to. |
134 void InitiateQueriesToFindNewDestination( | 142 void InitiateQueriesToFindNewDestination( |
135 MirroringDestination* old_destination, | 143 MirroringDestination* old_destination, |
136 const std::set<SourceFrameRef>& candidates); | 144 const std::set<SourceFrameRef>& candidates); |
137 | 145 |
138 // MirroringDestination query callback. |matches| contains all RenderFrame | 146 // MirroringDestination query callback. |matches| contains all RenderFrame |
139 // sources that will be diverted to |destination|. If |add_only| is false, | 147 // sources that will be diverted or dupliated to |destination|. |
miu
2016/05/02 20:06:13
typo: s/dupliated/duplicated/
qiangchen
2016/05/03 16:58:23
Done.
| |
140 // then any Diverters currently routed to |destination| but not found in | 148 // If |add_only| is false, then any Diverters currently routed to |
141 // |matches| will be stopped. | 149 // |destination| but not found in |matches| will be stopped. |
150 // If |is_duplicate| is true, the audio source will be duplicate to the | |
miu
2016/05/02 20:06:12
nit: s/audio source will be duplicate to/audio dat
qiangchen
2016/05/03 16:58:23
Done.
| |
151 // destination, otherwise we will divert audio. | |
142 void UpdateRoutesToDestination(MirroringDestination* destination, | 152 void UpdateRoutesToDestination(MirroringDestination* destination, |
143 bool add_only, | 153 bool add_only, |
144 const std::set<SourceFrameRef>& matches); | 154 const std::set<SourceFrameRef>& matches, |
155 bool is_duplicate); | |
156 | |
157 // |matches| contains all RenderFrame sources that will be diverted to | |
158 // |destination|. If |add_only| is false, then any Diverters currently routed | |
159 // to |destination| but not found in |matches| will be stopped. | |
160 void UpdateRoutesToDivertDestination(MirroringDestination* destination, | |
161 bool add_only, | |
162 const std::set<SourceFrameRef>& matches); | |
163 | |
164 // |matches| contains all RenderFrame sources that will be duplicated to | |
165 // |destination|. If |add_only| is false, then any Diverters currently | |
166 // duplicating to |destination| but not found in |matches| will be stopped. | |
167 void UpdateRoutesToDuplicateDestination( | |
168 MirroringDestination* destination, | |
169 bool add_only, | |
170 const std::set<SourceFrameRef>& matches); | |
145 | 171 |
146 // Starts diverting audio to the |new_destination|, if not NULL. Otherwise, | 172 // Starts diverting audio to the |new_destination|, if not NULL. Otherwise, |
147 // stops diverting audio. | 173 // stops diverting audio. |
148 static void ChangeRoute(StreamRoutingState* route, | 174 static void ChangeRoute(StreamRoutingState* route, |
149 MirroringDestination* new_destination); | 175 MirroringDestination* new_destination); |
150 | 176 |
151 // Routing table. Contains one entry for each Diverter. | 177 // Routing table. Contains one entry for each Diverter. |
152 StreamRoutes routes_; | 178 StreamRoutes routes_; |
153 | 179 |
154 // All active mirroring sessions. | 180 // All active mirroring sessions. |
155 Destinations sessions_; | 181 Destinations sessions_; |
156 | 182 |
157 // Used to check that all AudioMirroringManager code runs on the same thread. | 183 // Used to check that all AudioMirroringManager code runs on the same thread. |
158 base::ThreadChecker thread_checker_; | 184 base::ThreadChecker thread_checker_; |
159 | 185 |
160 DISALLOW_COPY_AND_ASSIGN(AudioMirroringManager); | 186 DISALLOW_COPY_AND_ASSIGN(AudioMirroringManager); |
161 }; | 187 }; |
162 | 188 |
163 } // namespace content | 189 } // namespace content |
164 | 190 |
165 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_AUDIO_MIRRORING_MANAGER_H_ | 191 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_AUDIO_MIRRORING_MANAGER_H_ |
OLD | NEW |