Chromium Code Reviews| 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 | |
| 16 // view" message. Among other actions, it registers the | |
| 17 // AudioOutputController 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(); | |
|
DaleCurtis
2013/01/02 21:56:44
Instead of being a static-memory / singleton patte
miu
2013/01/03 22:30:42
Done.
| |
| 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 | |
| 95 // called. | |
| 96 virtual void StartMirroring(int render_process_id, int render_view_id, | |
| 97 MirroringDestination* destination); | |
| 98 virtual void StopMirroring(int render_process_id, int render_view_id, | |
| 99 MirroringDestination* destination); | |
| 100 | |
| 101 protected: | |
| 102 friend struct StaticMemorySingletonTraits<AudioMirroringManager>; | |
| 103 friend class AudioMirroringManagerTest; | |
| 104 | |
| 105 AudioMirroringManager(); | |
| 106 virtual ~AudioMirroringManager(); | |
| 107 | |
| 108 private: | |
| 109 // A mirroring target is a RenderView identified by a | |
| 110 // <render_process_id, render_view_id> pair. | |
| 111 typedef std::pair<int, int> Target; | |
| 112 | |
| 113 // Note: Objects in these maps are not owned. | |
| 114 typedef std::multimap<Target, Diverter*> DiverterMap; | |
| 115 typedef std::map<Target, MirroringDestination*> SessionMap; | |
| 116 | |
| 117 // Currently-active divertable audio streams. | |
| 118 DiverterMap diverters_; | |
| 119 | |
| 120 // Currently-active mirroring sessions. | |
| 121 SessionMap sessions_; | |
| 122 | |
| 123 DISALLOW_COPY_AND_ASSIGN(AudioMirroringManager); | |
| 124 }; | |
| 125 | |
| 126 } // namespace content | |
| 127 | |
| 128 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_MIRRORING_MANAGER_H_ | |
| OLD | NEW |