Chromium Code Reviews| Index: content/browser/renderer_host/media/audio_renderer_host.h |
| diff --git a/content/browser/renderer_host/media/audio_renderer_host.h b/content/browser/renderer_host/media/audio_renderer_host.h |
| index 44daef21f836cf0ee8da944de1d83fab60b04799..319db843a909e59728257bcd744f684601c3d2ef 100644 |
| --- a/content/browser/renderer_host/media/audio_renderer_host.h |
| +++ b/content/browser/renderer_host/media/audio_renderer_host.h |
| @@ -40,6 +40,7 @@ |
| #include <map> |
| #include "base/gtest_prod_util.h" |
| +#include "base/lazy_instance.h" |
| #include "base/memory/ref_counted.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/process.h" |
| @@ -66,11 +67,29 @@ class CONTENT_EXPORT AudioRendererHost |
| : public BrowserMessageFilter, |
| public media::AudioOutputController::EventHandler { |
| public: |
| + // Interface to be implemented by audio mirroring destinations. See |
| + // comments for StartMirroring() and StopMirroring() below. |
| + class MirroringDestination |
| + : public base::RefCountedThreadSafe<MirroringDestination> { |
|
tommi (sloooow) - chröme
2012/12/18 13:41:26
Can we avoid reference counting here? Instead use
miu
2012/12/19 00:22:57
With the breaking-out of the mirroring functionali
|
| + public: |
| + // Create a consumer of audio data in the format specified by |params|, and |
| + // connect it as an input to mirroring. When Close() is called, the input |
| + // is disconnected and the object becomes invalid. |
| + virtual media::AudioOutputStream* AddInput( |
| + const media::AudioParameters& params) = 0; |
| + |
| + protected: |
| + friend class base::RefCountedThreadSafe<MirroringDestination>; |
| + virtual ~MirroringDestination(); |
| + }; |
| + |
| // Called from UI thread from the owner of this object. |
| - AudioRendererHost(media::AudioManager* audio_manager, |
| + AudioRendererHost(int render_process_id, |
| + media::AudioManager* audio_manager, |
| MediaObserver* media_observer); |
| // BrowserMessageFilter implementation. |
| + virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
| virtual void OnChannelClosing() OVERRIDE; |
| virtual void OnDestruct() const OVERRIDE; |
| virtual bool OnMessageReceived(const IPC::Message& message, |
| @@ -83,6 +102,18 @@ class CONTENT_EXPORT AudioRendererHost |
| virtual void OnError(media::AudioOutputController* controller, |
| int error_code) OVERRIDE; |
| + // Start/stop mirroring all audio output streams associated with |
| + // |render_process_id| + |render_view_id| to |destination|. Any call to |
| + // StartMirroring() must be paired with a later call to StopMirroring() since |
| + // a reference is held on the MirroringDestination while the mirroring session |
| + // is active. |
| + static void StartMirroring( |
|
DaleCurtis
2012/12/17 20:00:47
I worry somewhat about what seems to be the boltin
tommi (sloooow) - chröme
2012/12/18 13:41:26
+1. Maybe a Mirror object of sorts per render vie
miu
2012/12/19 00:22:57
Yeah, now that you guys have pointed it out, I agr
|
| + int render_process_id, int render_view_id, |
| + const scoped_refptr<MirroringDestination>& destination); |
| + static void StopMirroring( |
| + int render_process_id, int render_view_id, |
| + const scoped_refptr<MirroringDestination>& destination); |
| + |
| private: |
| friend class AudioRendererHostTest; |
| friend class BrowserThread; |
| @@ -93,6 +124,8 @@ class CONTENT_EXPORT AudioRendererHost |
| struct AudioEntry; |
| typedef std::map<int, AudioEntry*> AudioEntryMap; |
| + typedef std::map<int, scoped_refptr<MirroringDestination> > MirrorSessionMap; |
| + typedef std::map<int, AudioRendererHost*> ActiveHostMap; |
| virtual ~AudioRendererHost(); |
| @@ -164,12 +197,35 @@ class CONTENT_EXPORT AudioRendererHost |
| media::AudioOutputController* LookupControllerByIdForTesting(int stream_id); |
| + // Global look-up for the AudioRendererHost instance owned by the |
| + // RenderProcessHost specified by |render_process_id|. |
| + static AudioRendererHost* FromRenderProcessID(int render_process_id); |
| + |
| + // Implementations for StartMirroring() and StopMirroring() that are run on |
| + // the IO BrowserThread. |
| + static void DoStartMirroring( |
| + int render_process_id, int render_view_id, |
| + const scoped_refptr<MirroringDestination>& destination); |
| + static void DoStopMirroring( |
| + int render_process_id, int render_view_id, |
| + const scoped_refptr<MirroringDestination>& destination); |
| + |
| + // ID of the RenderProcessHost that owns this instance. |
| + const int render_process_id_; |
| + |
| // A map of stream IDs to audio sources. |
| AudioEntryMap audio_entries_; |
| + // A map of render view IDs to the destination for active mirroring sessions. |
| + MirrorSessionMap mirror_sessions_; |
| + |
| media::AudioManager* audio_manager_; |
| MediaObserver* media_observer_; |
| + // Global look-up map for currently-active (i.e., IPC channel is open) |
| + // AudioRendererHosts. |
| + static base::LazyInstance<ActiveHostMap>::Leaky g_host_map_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); |
| }; |