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 // BrowserThread. | 8 // thread. |
9 // | 9 // |
10 // How it works: | 10 // How it works: |
11 // | 11 // |
12 // 1. AudioRendererHost gets a CreateStream message from the render process | 12 // 1. AudioRendererHost gets a CreateStream message from the render process |
13 // and, among other things, creates an AudioOutputController to control the | 13 // and, among other things, creates an AudioOutputController to control the |
14 // audio data flow between the render and browser processes. | 14 // audio data flow between the render and browser processes. |
15 // 2. At some point, AudioRendererHost receives an "associate with render | 15 // 2. At some point, AudioRendererHost receives an "associate with render |
16 // view" message. Among other actions, it registers the | 16 // view" message. Among other actions, it registers the |
17 // AudioOutputController with AudioMirroringManager (as a Diverter). | 17 // AudioOutputController with AudioMirroringManager (as a Diverter). |
18 // 3. A user request to mirror all the audio for a single RenderView is made. | 18 // 3. A user request to mirror all the audio for a single RenderView is made. |
19 // A MirroringDestination is created, and StartMirroring() is called to | 19 // A MirroringDestination is created, and StartMirroring() is called to |
20 // begin the mirroring session. This causes AudioMirroringManager to | 20 // begin the mirroring session. This causes AudioMirroringManager to |
21 // instruct any matching Diverters to divert their audio data to the | 21 // instruct any matching Diverters to divert their audio data to the |
22 // MirroringDestination. | 22 // MirroringDestination. |
23 // | 23 // |
24 // #2 and #3 above may occur in any order, as it is the job of | 24 // #2 and #3 above may occur in any order, as it is the job of |
25 // AudioMirroringManager to realize when the players can be "matched up." | 25 // AudioMirroringManager to realize when the players can be "matched up." |
26 | 26 |
27 #ifndef CONTENT_BROWSER_MEDIA_CAPTURE_AUDIO_MIRRORING_MANAGER_H_ | 27 #ifndef CONTENT_BROWSER_MEDIA_CAPTURE_AUDIO_MIRRORING_MANAGER_H_ |
28 #define CONTENT_BROWSER_MEDIA_CAPTURE_AUDIO_MIRRORING_MANAGER_H_ | 28 #define CONTENT_BROWSER_MEDIA_CAPTURE_AUDIO_MIRRORING_MANAGER_H_ |
29 | 29 |
30 #include <map> | 30 #include <map> |
31 #include <utility> | 31 #include <utility> |
32 | 32 |
33 #include "base/basictypes.h" | 33 #include "base/basictypes.h" |
| 34 #include "base/threading/thread_checker.h" |
34 #include "content/common/content_export.h" | 35 #include "content/common/content_export.h" |
35 #include "media/audio/audio_source_diverter.h" | 36 #include "media/audio/audio_source_diverter.h" |
36 | 37 |
37 namespace media { | 38 namespace media { |
38 class AudioOutputStream; | 39 class AudioOutputStream; |
39 } | 40 } |
40 | 41 |
41 namespace content { | 42 namespace content { |
42 | 43 |
43 class CONTENT_EXPORT AudioMirroringManager { | 44 class CONTENT_EXPORT AudioMirroringManager { |
44 public: | 45 public: |
45 // Interface for diverting audio data to an alternative AudioOutputStream. | 46 // Interface for diverting audio data to an alternative AudioOutputStream. |
46 typedef media::AudioSourceDiverter Diverter; | 47 typedef media::AudioSourceDiverter Diverter; |
47 | 48 |
48 // Interface to be implemented by audio mirroring destinations. See comments | 49 // Interface to be implemented by audio mirroring destinations. See comments |
49 // for StartMirroring() and StopMirroring() below. | 50 // for StartMirroring() and StopMirroring() below. |
50 class MirroringDestination { | 51 class MirroringDestination { |
51 public: | 52 public: |
52 // Create a consumer of audio data in the format specified by |params|, and | 53 // Create a consumer of audio data in the format specified by |params|, and |
53 // connect it as an input to mirroring. When Close() is called on the | 54 // connect it as an input to mirroring. When Close() is called on the |
54 // returned AudioOutputStream, the input is disconnected and the object | 55 // returned AudioOutputStream, the input is disconnected and the object |
55 // becomes invalid. | 56 // becomes invalid. |
56 virtual media::AudioOutputStream* AddInput( | 57 virtual media::AudioOutputStream* AddInput( |
57 const media::AudioParameters& params) = 0; | 58 const media::AudioParameters& params) = 0; |
58 | 59 |
59 protected: | 60 protected: |
60 virtual ~MirroringDestination() {} | 61 virtual ~MirroringDestination() {} |
61 }; | 62 }; |
62 | 63 |
| 64 // Note: Use GetInstance() for non-test code. |
63 AudioMirroringManager(); | 65 AudioMirroringManager(); |
| 66 virtual ~AudioMirroringManager(); |
64 | 67 |
65 virtual ~AudioMirroringManager(); | 68 // Returns the global instance. |
| 69 static AudioMirroringManager* GetInstance(); |
66 | 70 |
67 // Add/Remove a diverter for an audio stream with a known RenderView target | 71 // Add/Remove a diverter for an audio stream with a known RenderView target |
68 // (represented by |render_process_id| + |render_view_id|). Multiple | 72 // (represented by |render_process_id| + |render_view_id|). Multiple |
69 // diverters may be added for the same target. |diverter| must live until | 73 // diverters may be added for the same target. |diverter| must live until |
70 // after RemoveDiverter() is called. | 74 // after RemoveDiverter() is called. |
71 // | 75 // |
72 // Re-entrancy warning: These methods should not be called by a Diverter | 76 // Re-entrancy warning: These methods should not be called by a Diverter |
73 // during a Start/StopDiverting() invocation. | 77 // during a Start/StopDiverting() invocation. |
74 virtual void AddDiverter(int render_process_id, int render_view_id, | 78 virtual void AddDiverter(int render_process_id, int render_view_id, |
75 Diverter* diverter); | 79 Diverter* diverter); |
(...skipping 17 matching lines...) Expand all Loading... |
93 // Note: Objects in these maps are not owned. | 97 // Note: Objects in these maps are not owned. |
94 typedef std::multimap<Target, Diverter*> DiverterMap; | 98 typedef std::multimap<Target, Diverter*> DiverterMap; |
95 typedef std::map<Target, MirroringDestination*> SessionMap; | 99 typedef std::map<Target, MirroringDestination*> SessionMap; |
96 | 100 |
97 // Currently-active divertable audio streams. | 101 // Currently-active divertable audio streams. |
98 DiverterMap diverters_; | 102 DiverterMap diverters_; |
99 | 103 |
100 // Currently-active mirroring sessions. | 104 // Currently-active mirroring sessions. |
101 SessionMap sessions_; | 105 SessionMap sessions_; |
102 | 106 |
| 107 // Used to check that all AudioMirroringManager code runs on the same thread. |
| 108 base::ThreadChecker thread_checker_; |
| 109 |
103 DISALLOW_COPY_AND_ASSIGN(AudioMirroringManager); | 110 DISALLOW_COPY_AND_ASSIGN(AudioMirroringManager); |
104 }; | 111 }; |
105 | 112 |
106 } // namespace content | 113 } // namespace content |
107 | 114 |
108 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_AUDIO_MIRRORING_MANAGER_H_ | 115 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_AUDIO_MIRRORING_MANAGER_H_ |
OLD | NEW |