OLD | NEW |
(Empty) | |
| 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 |
| 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 #include "media/audio/audio_source_diverter.h" |
| 36 |
| 37 namespace media { |
| 38 class AudioOutputStream; |
| 39 } |
| 40 |
| 41 namespace content { |
| 42 |
| 43 class CONTENT_EXPORT AudioMirroringManager { |
| 44 public: |
| 45 // Interface for diverting audio data to an alternative AudioOutputStream. |
| 46 typedef media::AudioSourceDiverter Diverter; |
| 47 |
| 48 // Interface to be implemented by audio mirroring destinations. See comments |
| 49 // for StartMirroring() and StopMirroring() below. |
| 50 class MirroringDestination { |
| 51 public: |
| 52 // 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 // returned AudioOutputStream, the input is disconnected and the object |
| 55 // becomes invalid. |
| 56 virtual media::AudioOutputStream* AddInput( |
| 57 const media::AudioParameters& params) = 0; |
| 58 |
| 59 protected: |
| 60 virtual ~MirroringDestination() {} |
| 61 }; |
| 62 |
| 63 AudioMirroringManager(); |
| 64 |
| 65 virtual ~AudioMirroringManager(); |
| 66 |
| 67 // Add/Remove a diverter for an audio stream with a known RenderView target |
| 68 // (represented by |render_process_id| + |render_view_id|). Multiple |
| 69 // diverters may be added for the same target. |diverter| must live until |
| 70 // after RemoveDiverter() is called. |
| 71 // |
| 72 // Re-entrancy warning: These methods should not be called by a Diverter |
| 73 // during a Start/StopDiverting() invocation. |
| 74 virtual void AddDiverter(int render_process_id, int render_view_id, |
| 75 Diverter* diverter); |
| 76 virtual void RemoveDiverter(int render_process_id, int render_view_id, |
| 77 Diverter* diverter); |
| 78 |
| 79 // Start/stop mirroring all audio output streams associated with a RenderView |
| 80 // target (represented by |render_process_id| + |render_view_id|) to |
| 81 // |destination|. |destination| must live until after StopMirroring() is |
| 82 // called. |
| 83 virtual void StartMirroring(int render_process_id, int render_view_id, |
| 84 MirroringDestination* destination); |
| 85 virtual void StopMirroring(int render_process_id, int render_view_id, |
| 86 MirroringDestination* destination); |
| 87 |
| 88 private: |
| 89 // A mirroring target is a RenderView identified by a |
| 90 // <render_process_id, render_view_id> pair. |
| 91 typedef std::pair<int, int> Target; |
| 92 |
| 93 // Note: Objects in these maps are not owned. |
| 94 typedef std::multimap<Target, Diverter*> DiverterMap; |
| 95 typedef std::map<Target, MirroringDestination*> SessionMap; |
| 96 |
| 97 // Currently-active divertable audio streams. |
| 98 DiverterMap diverters_; |
| 99 |
| 100 // Currently-active mirroring sessions. |
| 101 SessionMap sessions_; |
| 102 |
| 103 DISALLOW_COPY_AND_ASSIGN(AudioMirroringManager); |
| 104 }; |
| 105 |
| 106 } // namespace content |
| 107 |
| 108 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_MIRRORING_MANAGER_H_ |
OLD | NEW |