OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 // | |
5 // AudioMirroringManager is a singleton object that maintains a set of active | |
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 | |
8 // BrowserThread. | |
9 // | |
10 // How it works: | |
11 // | |
12 // 1. AudioRendererHost gets a CreateStream message from the render process | |
13 // and, among other things, creates an AudioOutputController to control the | |
14 // audio data flow between the render and browser processes. | |
15 // 2. At some point, AudioRendererHost receives an "associate with render view " | |
tommi (sloooow) - chröme
2012/12/19 12:27:54
80+
miu
2012/12/28 23:03:49
Done.
| |
16 // message. Among other actions, it registers the AudioOutputController | |
17 // with AudioMirroringManager (as a Diverter). | |
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 | |
20 // begin the mirroring session. This causes AudioMirroringManager to | |
21 // instruct any matching Diverters to divert their audio data to the | |
22 // MirroringDestination. | |
23 // | |
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." | |
26 | |
27 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_MIRRORING_MANAGER_H_ | |
28 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_MIRRORING_MANAGER_H_ | |
29 | |
30 #include <map> | |
31 #include <utility> | |
32 | |
33 #include "base/basictypes.h" | |
34 #include "content/common/content_export.h" | |
35 | |
36 template <typename T> struct StaticMemorySingletonTraits; | |
37 | |
38 namespace media { | |
39 class AudioOutputStream; | |
40 class AudioParameters; | |
41 } | |
42 | |
43 namespace content { | |
44 | |
45 class CONTENT_EXPORT AudioMirroringManager { | |
46 public: | |
47 // Interface for diverting audio data to an alternative AudioOutputStream. | |
48 class Diverter { | |
49 public: | |
50 // Returns the audio parameters of the the divertable audio data. | |
51 virtual const media::AudioParameters& GetAudioParameters() = 0; | |
52 | |
53 // Start providing audio data to the given |stream|, which is in an unopened | |
54 // state. |stream| is under the control of the Diverter until | |
55 // StopDiverting() is called. | |
56 virtual void StartDiverting(media::AudioOutputStream* stream) = 0; | |
57 | |
58 // Stops diverting audio data to the stream. The Diverter is responsible | |
59 // for closing the stream. | |
60 virtual void StopDiverting() = 0; | |
61 | |
62 protected: | |
63 virtual ~Diverter(); | |
64 }; | |
65 | |
66 // Interface to be implemented by audio mirroring destinations. See comments | |
67 // for StartMirroring() and StopMirroring() below. | |
68 class MirroringDestination { | |
69 public: | |
70 // Create a consumer of audio data in the format specified by |params|, and | |
71 // connect it as an input to mirroring. When Close() is called on the | |
72 // returned AudioOutputStream, the input is disconnected and the object | |
73 // becomes invalid. | |
74 virtual media::AudioOutputStream* AddInput( | |
75 const media::AudioParameters& params) = 0; | |
76 | |
77 protected: | |
78 virtual ~MirroringDestination(); | |
79 }; | |
80 | |
81 static AudioMirroringManager* GetInstance(); | |
82 | |
83 // Add/Remove a diverter for an audio stream with a known RenderView target | |
84 // (represented by |render_process_id| + |render_view_id|). Multiple | |
85 // diverters may be added for the same target. |diverter| must live until | |
86 // after RemoveDiverter() is called. | |
87 virtual void AddDiverter(int render_process_id, int render_view_id, | |
88 Diverter* diverter); | |
89 virtual void RemoveDiverter(int render_process_id, int render_view_id, | |
90 Diverter* diverter); | |
91 | |
92 // Start/stop mirroring all audio output streams associated with a RenderView | |
93 // target (represented by |render_process_id| + |render_view_id|) to | |
94 // |destination|. |destination| must live until after StopMirroring() is call ed. | |
tommi (sloooow) - chröme
2012/12/19 12:27:54
80+
miu
2012/12/28 23:03:49
Done.
| |
95 virtual void StartMirroring(int render_process_id, int render_view_id, | |
96 MirroringDestination* destination); | |
97 virtual void StopMirroring(int render_process_id, int render_view_id, | |
98 MirroringDestination* destination); | |
99 | |
100 protected: | |
101 friend struct StaticMemorySingletonTraits<AudioMirroringManager>; | |
102 | |
103 AudioMirroringManager(); | |
104 virtual ~AudioMirroringManager(); | |
105 | |
106 // Inject an alternative implementation for unit testing, to be returned by | |
107 // GetInstance(). | |
108 static void SetInstanceForTesting(AudioMirroringManager* test_instance); | |
tommi (sloooow) - chröme
2012/12/19 12:27:54
is there no better way to support testing?
This a
miu
2012/12/28 23:03:49
Done. Used dependency injection via the AudioRend
| |
109 | |
110 private: | |
111 // A mirroring target is a RenderView identified by a | |
112 // <render_process_id, render_view_id> pair. | |
113 typedef std::pair<int, int> Target; | |
tommi (sloooow) - chröme
2012/12/19 12:27:54
why not just define a struct? Remembering first a
miu
2012/12/28 23:03:49
Two reasons:
1. It's only used as a key in the ma
| |
114 | |
115 // Note: Objects in these maps are not owned. | |
116 typedef std::multimap<Target, Diverter*> DiverterMap; | |
117 typedef std::map<Target, MirroringDestination*> SessionMap; | |
118 | |
119 // Currently-active divertable audio streams. | |
120 DiverterMap diverters_; | |
121 | |
122 // Currently-active mirroring sessions. | |
123 SessionMap sessions_; | |
124 | |
125 // If not-NULL, this is returned in calls to GetInstance(). | |
126 static AudioMirroringManager* test_instance_; | |
127 | |
128 DISALLOW_COPY_AND_ASSIGN(AudioMirroringManager); | |
129 }; | |
130 | |
131 } // namespace content | |
132 | |
133 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_MIRRORING_MANAGER_H_ | |
OLD | NEW |