| 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_output_stream.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; |
| 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 std::map<MirroringDestination*, media::AudioPushSink*> dup_destinations; |
| 131 |
| 123 StreamRoutingState(const SourceFrameRef& source_frame, | 132 StreamRoutingState(const SourceFrameRef& source_frame, |
| 124 Diverter* stream_diverter); | 133 Diverter* stream_diverter); |
| 125 StreamRoutingState(const StreamRoutingState& other); | 134 StreamRoutingState(const StreamRoutingState& other); |
| 126 ~StreamRoutingState(); | 135 ~StreamRoutingState(); |
| 127 }; | 136 }; |
| 128 | 137 |
| 129 typedef std::vector<StreamRoutingState> StreamRoutes; | 138 typedef std::vector<StreamRoutingState> StreamRoutes; |
| 130 typedef std::vector<MirroringDestination*> Destinations; | 139 typedef std::vector<MirroringDestination*> Destinations; |
| 131 | 140 |
| 132 // Helper to find a destination other than |old_destination| for the given | 141 // Helper to find a destination other than |old_destination| for the given |
| 133 // |candidates| to be diverted to. | 142 // |candidates| to be diverted to. |
| 134 void InitiateQueriesToFindNewDestination( | 143 void InitiateQueriesToFindNewDestination( |
| 135 MirroringDestination* old_destination, | 144 MirroringDestination* old_destination, |
| 136 const std::set<SourceFrameRef>& candidates); | 145 const std::set<SourceFrameRef>& candidates); |
| 137 | 146 |
| 138 // MirroringDestination query callback. |matches| contains all RenderFrame | 147 // MirroringDestination query callback. |matches| contains all RenderFrame |
| 139 // sources that will be diverted to |destination|. If |add_only| is false, | 148 // sources that will be diverted to |destination|. If |add_only| is false, |
| 140 // then any Diverters currently routed to |destination| but not found in | 149 // then any Diverters currently routed to |destination| but not found in |
| 141 // |matches| will be stopped. | 150 // |matches| will be stopped. |
| 142 void UpdateRoutesToDestination(MirroringDestination* destination, | 151 void UpdateRoutesToDestination(MirroringDestination* destination, |
| 143 bool add_only, | 152 bool add_only, |
| 144 const std::set<SourceFrameRef>& matches); | 153 const std::set<SourceFrameRef>& matches); |
| 145 | 154 |
| 155 void UpdateRoutesToDupDestination(MirroringDestination* destination, |
| 156 bool add_only, |
| 157 const std::set<SourceFrameRef>& matches); |
| 158 |
| 146 // Starts diverting audio to the |new_destination|, if not NULL. Otherwise, | 159 // Starts diverting audio to the |new_destination|, if not NULL. Otherwise, |
| 147 // stops diverting audio. | 160 // stops diverting audio. |
| 148 static void ChangeRoute(StreamRoutingState* route, | 161 static void ChangeRoute(StreamRoutingState* route, |
| 149 MirroringDestination* new_destination); | 162 MirroringDestination* new_destination); |
| 150 | 163 |
| 151 // Routing table. Contains one entry for each Diverter. | 164 // Routing table. Contains one entry for each Diverter. |
| 152 StreamRoutes routes_; | 165 StreamRoutes routes_; |
| 153 | 166 |
| 154 // All active mirroring sessions. | 167 // All active mirroring sessions. |
| 155 Destinations sessions_; | 168 Destinations sessions_; |
| 156 | 169 |
| 157 // Used to check that all AudioMirroringManager code runs on the same thread. | 170 // Used to check that all AudioMirroringManager code runs on the same thread. |
| 158 base::ThreadChecker thread_checker_; | 171 base::ThreadChecker thread_checker_; |
| 159 | 172 |
| 160 DISALLOW_COPY_AND_ASSIGN(AudioMirroringManager); | 173 DISALLOW_COPY_AND_ASSIGN(AudioMirroringManager); |
| 161 }; | 174 }; |
| 162 | 175 |
| 163 } // namespace content | 176 } // namespace content |
| 164 | 177 |
| 165 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_AUDIO_MIRRORING_MANAGER_H_ | 178 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_AUDIO_MIRRORING_MANAGER_H_ |
| OLD | NEW |