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.
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
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.
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."
27 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_MIRRORING_MANAGER_H_
28 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_MIRRORING_MANAGER_H_
33 #include "base/basictypes.h"
34 #include "content/common/content_export.h"
35 #include "media/audio/audio_source_diverter.h"
38 class AudioOutputStream
;
43 class CONTENT_EXPORT AudioMirroringManager
{
45 // Interface for diverting audio data to an alternative AudioOutputStream.
46 typedef media::AudioSourceDiverter Diverter
;
48 // Interface to be implemented by audio mirroring destinations. See comments
49 // for StartMirroring() and StopMirroring() below.
50 class MirroringDestination
{
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
56 virtual media::AudioOutputStream
* AddInput(
57 const media::AudioParameters
& params
) = 0;
60 virtual ~MirroringDestination() {}
63 AudioMirroringManager();
65 virtual ~AudioMirroringManager();
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.
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
,
76 virtual void RemoveDiverter(int render_process_id
, int render_view_id
,
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
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
);
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
;
93 // Note: Objects in these maps are not owned.
94 typedef std::multimap
<Target
, Diverter
*> DiverterMap
;
95 typedef std::map
<Target
, MirroringDestination
*> SessionMap
;
97 // Currently-active divertable audio streams.
98 DiverterMap diverters_
;
100 // Currently-active mirroring sessions.
101 SessionMap sessions_
;
103 DISALLOW_COPY_AND_ASSIGN(AudioMirroringManager
);
106 } // namespace content
108 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_MIRRORING_MANAGER_H_