Chromium Code Reviews| 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. |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 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. |
| 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( | |
| 85 const media::AudioParameters& params) = 0; | |
| 86 | |
| 87 virtual bool IsDuplication() = 0; | |
|
miu
2016/04/21 00:15:24
I was looking at how AudioMirroringManager uses th
qiangchen
2016/04/28 00:00:56
Done.
| |
| 88 | |
| 82 protected: | 89 protected: |
| 83 virtual ~MirroringDestination() {} | 90 virtual ~MirroringDestination() {} |
| 84 }; | 91 }; |
| 85 | 92 |
| 86 // Note: Use GetInstance() for non-test code. | 93 // Note: Use GetInstance() for non-test code. |
| 87 AudioMirroringManager(); | 94 AudioMirroringManager(); |
| 88 virtual ~AudioMirroringManager(); | 95 virtual ~AudioMirroringManager(); |
| 89 | 96 |
| 90 // Returns the global instance. | 97 // Returns the global instance. |
| 91 static AudioMirroringManager* GetInstance(); | 98 static AudioMirroringManager* GetInstance(); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 113 // The source render frame associated with the audio stream. | 120 // The source render frame associated with the audio stream. |
| 114 SourceFrameRef source_render_frame; | 121 SourceFrameRef source_render_frame; |
| 115 | 122 |
| 116 // The diverter for re-routing the audio stream. | 123 // The diverter for re-routing the audio stream. |
| 117 Diverter* diverter; | 124 Diverter* diverter; |
| 118 | 125 |
| 119 // If not NULL, the audio stream is currently being diverted to this | 126 // If not NULL, the audio stream is currently being diverted to this |
| 120 // destination. | 127 // destination. |
| 121 MirroringDestination* destination; | 128 MirroringDestination* destination; |
| 122 | 129 |
| 130 // The destinations to which audio stream is duplicated. | |
| 131 std::map<MirroringDestination*, media::AudioPushSink*> dup_destinations; | |
| 132 | |
| 123 StreamRoutingState(const SourceFrameRef& source_frame, | 133 StreamRoutingState(const SourceFrameRef& source_frame, |
| 124 Diverter* stream_diverter); | 134 Diverter* stream_diverter); |
| 125 StreamRoutingState(const StreamRoutingState& other); | 135 StreamRoutingState(const StreamRoutingState& other); |
| 126 ~StreamRoutingState(); | 136 ~StreamRoutingState(); |
| 127 }; | 137 }; |
| 128 | 138 |
| 129 typedef std::vector<StreamRoutingState> StreamRoutes; | 139 typedef std::vector<StreamRoutingState> StreamRoutes; |
| 130 typedef std::vector<MirroringDestination*> Destinations; | 140 typedef std::vector<MirroringDestination*> Destinations; |
| 131 | 141 |
| 132 // Helper to find a destination other than |old_destination| for the given | 142 // Helper to find a destination other than |old_destination| for the given |
| 133 // |candidates| to be diverted to. | 143 // |candidates| to be diverted to. |
| 134 void InitiateQueriesToFindNewDestination( | 144 void InitiateQueriesToFindNewDestination( |
| 135 MirroringDestination* old_destination, | 145 MirroringDestination* old_destination, |
| 136 const std::set<SourceFrameRef>& candidates); | 146 const std::set<SourceFrameRef>& candidates); |
| 137 | 147 |
| 138 // MirroringDestination query callback. |matches| contains all RenderFrame | 148 // MirroringDestination query callback. |matches| contains all RenderFrame |
| 139 // sources that will be diverted to |destination|. If |add_only| is false, | 149 // sources that will be diverted to |destination|. If |add_only| is false, |
| 140 // then any Diverters currently routed to |destination| but not found in | 150 // then any Diverters currently routed to |destination| but not found in |
| 141 // |matches| will be stopped. | 151 // |matches| will be stopped. |
| 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); |
| 145 | 155 |
| 156 // MirroringDestination query callback. |matches| contains all RenderFrame | |
| 157 // sources that will be duplicated to |destination|. If |add_only| is false, | |
| 158 // then any Diverters currently duplicating to |destination| but not found in | |
| 159 // |matches| will be stopped. | |
| 160 void UpdateRoutesToDupDestination(MirroringDestination* destination, | |
| 161 bool add_only, | |
| 162 const std::set<SourceFrameRef>& matches); | |
| 163 | |
| 146 // Starts diverting audio to the |new_destination|, if not NULL. Otherwise, | 164 // Starts diverting audio to the |new_destination|, if not NULL. Otherwise, |
| 147 // stops diverting audio. | 165 // stops diverting audio. |
| 148 static void ChangeRoute(StreamRoutingState* route, | 166 static void ChangeRoute(StreamRoutingState* route, |
| 149 MirroringDestination* new_destination); | 167 MirroringDestination* new_destination); |
| 150 | 168 |
| 151 // Routing table. Contains one entry for each Diverter. | 169 // Routing table. Contains one entry for each Diverter. |
| 152 StreamRoutes routes_; | 170 StreamRoutes routes_; |
| 153 | 171 |
| 154 // All active mirroring sessions. | 172 // All active mirroring sessions. |
| 155 Destinations sessions_; | 173 Destinations sessions_; |
| 156 | 174 |
| 157 // Used to check that all AudioMirroringManager code runs on the same thread. | 175 // Used to check that all AudioMirroringManager code runs on the same thread. |
| 158 base::ThreadChecker thread_checker_; | 176 base::ThreadChecker thread_checker_; |
| 159 | 177 |
| 160 DISALLOW_COPY_AND_ASSIGN(AudioMirroringManager); | 178 DISALLOW_COPY_AND_ASSIGN(AudioMirroringManager); |
| 161 }; | 179 }; |
| 162 | 180 |
| 163 } // namespace content | 181 } // namespace content |
| 164 | 182 |
| 165 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_AUDIO_MIRRORING_MANAGER_H_ | 183 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_AUDIO_MIRRORING_MANAGER_H_ |
| OLD | NEW |