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 ed89e93dd2165314d45bfcfd35f73066df356157..6a078e775c0b14a619da2e75f9793e94a179781a 100644 |
| --- a/content/browser/renderer_host/media/audio_renderer_host.h |
| +++ b/content/browser/renderer_host/media/audio_renderer_host.h |
| @@ -17,6 +17,9 @@ |
| // |
| // Renderer AudioRendererHost |
| // | | |
| +// | RequestDeviceAuthorization > | |
| +// | < NotifyDeviceAuthorized | |
| +// | | |
| // | CreateStream > | |
| // | < NotifyStreamCreated | |
| // | | |
| @@ -39,6 +42,7 @@ |
| #include <map> |
| #include <string> |
| +#include <utility> |
| #include "base/atomic_ref_count.h" |
| #include "base/gtest_prod_util.h" |
| @@ -46,6 +50,7 @@ |
| #include "base/memory/scoped_ptr.h" |
| #include "base/process/process.h" |
| #include "base/sequenced_task_runner_helpers.h" |
| +#include "content/browser/renderer_host/media/audio_output_device_enumerator.h" |
| #include "content/common/content_export.h" |
| #include "content/public/browser/browser_message_filter.h" |
| #include "content/public/browser/browser_thread.h" |
| @@ -110,22 +115,42 @@ class CONTENT_EXPORT AudioRendererHost : public BrowserMessageFilter { |
| class AudioEntry; |
| typedef std::map<int, AudioEntry*> AudioEntryMap; |
| + // Internal callback type for access requests to output devices. |
| + // |have_access| is true only if there is permission to access the device. |
| + typedef base::Callback<void(bool have_access)> OutputDeviceAccessCB; |
| + |
| + // Internal callback type for information requests about an output device. |
| + // |success| indicates the operation was successful. If true, |device_info| |
| + // contains data about the device. |
| + typedef base::Callback<void(bool success, |
| + const AudioOutputDeviceInfo& device_info)> |
| + OutputDeviceInfoCB; |
| + |
| ~AudioRendererHost() override; |
| // Methods called on IO thread ---------------------------------------------- |
| // Audio related IPC message handlers. |
| - // Creates an audio output stream with the specified format whose data is |
| - // produced by an entity in the RenderFrame referenced by |render_frame_id|. |
| + // Request permission to use an output device for use by a stream produced |
| + // in the RenderFrame referenced by |render_frame_id|. |
| // |session_id| is used for unified IO to find out which input device to be |
| // opened for the stream. For clients that do not use unified IO, |
| - // |session_id| will be ignored. |
| + // |session_id| will be ignored and the given |device_id| and |
| + // |security_origin| will be used to select the output device. |
| + // Upon completion of the process, the peer is notified with the device output |
| + // parameters via the NotifyDeviceAuthorized message. |
| + void OnRequestDeviceAuthorization(int stream_id, |
| + int render_frame_id, |
| + int session_id, |
| + const std::string& device_id, |
| + const GURL& security_origin); |
| + |
| + // Creates an audio output stream with the specified format. |
| // Upon success/failure, the peer is notified via the NotifyStreamCreated |
| // message. |
| void OnCreateStream(int stream_id, |
| int render_frame_id, |
| - int session_id, |
| const media::AudioParameters& params); |
| // Play the audio stream referenced by |stream_id|. |
| @@ -144,33 +169,28 @@ class CONTENT_EXPORT AudioRendererHost : public BrowserMessageFilter { |
| void OnSwitchOutputDevice(int stream_id, |
| int render_frame_id, |
| const std::string& device_id, |
| - const GURL& security_origin, |
| - int request_id); |
| - |
| - void OutputDeviceAccessChecked(scoped_ptr<MediaStreamUIProxy> ui_proxy, |
| - int stream_id, |
| - const std::string& device_id, |
| - const GURL& security_origin, |
| - int render_frame_id, |
| - int request_id, |
| - bool have_access); |
| - |
| - void StartTranslateOutputDeviceName(int stream_id, |
| - const std::string& device_id, |
| - const GURL& security_origin, |
| - int request_id); |
| - |
| - void FinishTranslateOutputDeviceName(int stream_id, |
| - const std::string& device_id, |
| - const GURL& security_origin, |
| - int request_id, |
| - media::AudioDeviceNames*); |
| + const GURL& security_origin); |
| - void DoSwitchOutputDevice(int stream_id, |
| - const std::string& raw_device_id, |
| - int request_id); |
| + // Helper methods. |
| - void DoOutputDeviceSwitched(int stream_id, int request_id); |
| + // Proceed with device authorization after checking permissions. |
| + void RequestDeviceAuthorizationAccessChecked(int stream_id, |
|
DaleCurtis
2015/09/12 01:17:19
Perhaps something simpler like RequestDeviceAuthor
Guido Urdaneta
2015/09/14 11:35:48
Done. Now OnDeviceAuthorized()
|
| + const std::string& device_id, |
| + const GURL& security_origin, |
| + bool have_access); |
| + |
| + // Proceed with device authorization after translating device ID. |
| + void RequestDeviceAuthorizationTranslated( |
| + int stream_id, |
| + bool device_found, |
| + const AudioOutputDeviceInfo& device_info); |
| + |
| + // Start the actual creation of an audio stream, after the device |
| + // authorization process is complete. |
| + void DoCreateStream(int stream_id, |
| + int render_frame_id, |
| + const media::AudioParameters& params, |
| + const std::string& device_unique_id); |
| // Complete the process of creating an audio stream. This will set up the |
| // shared memory or shared socket in low latency mode and send the |
| @@ -180,6 +200,22 @@ class CONTENT_EXPORT AudioRendererHost : public BrowserMessageFilter { |
| // Send playing/paused status to the renderer. |
| void DoNotifyStreamStateChanged(int stream_id, bool is_playing); |
| + // Proceed with output device switching after checking permissions. |
| + void SwitchOutputDeviceAccessChecked(int stream_id, |
| + const std::string& device_id, |
| + const GURL& security_origin, |
| + bool have_access); |
| + |
| + // Proceed with output device switching after translating device ID. |
| + void SwitchOutputDeviceTranslated(int stream_id, |
| + bool device_found, |
| + const AudioOutputDeviceInfo& device_info); |
| + |
| + // Finish handling the output device switch request, after the device has |
| + // been switched. |
| + void OutputDeviceSwitched(int stream_id, |
| + const media::AudioParameters& output_params); |
| + |
| RenderProcessHost::AudioOutputControllerList DoGetOutputControllers() const; |
| // Send an error message to the renderer. |
| @@ -203,6 +239,32 @@ class CONTENT_EXPORT AudioRendererHost : public BrowserMessageFilter { |
| // Checks that the renderer process supplies a URL it is allowed to use |
| bool IsURLAllowed(const GURL& url); |
| + // Check if the renderer process has access to the requested output device. |
| + void CheckOutputDeviceAccess(int render_frame_id, |
| + const std::string& device_id, |
| + const GURL& security_origin, |
| + const OutputDeviceAccessCB& callback); |
| + |
| + // Invoke |callback| after permission to use a device has been checked. |
| + void AccessChecked(scoped_ptr<MediaStreamUIProxy> ui_proxy, |
| + const OutputDeviceAccessCB& callback, |
| + bool have_access); |
| + |
| + // Check if the renderer process has access to the requested output device. |
| + void TranslateDeviceID(const std::string& device_id, |
| + const GURL& security_origin, |
| + const OutputDeviceInfoCB& callback); |
| + |
| + void FinishTranslateDeviceID( |
| + const std::string& device_id, |
| + const GURL& security_origin, |
| + const OutputDeviceInfoCB& callback, |
| + const AudioOutputDeviceEnumeration& device_infos); |
| + |
| + // Helper method to check if the authorization procedure for stream |
| + // |stream_id| has started. |
| + bool IsAuthorizationStarted(int stream_id); |
| + |
| // ID of the RenderProcessHost that owns this instance. |
| const int render_process_id_; |
| @@ -219,9 +281,15 @@ class CONTENT_EXPORT AudioRendererHost : public BrowserMessageFilter { |
| // The number of streams in the playing state. |
| base::AtomicRefCount num_playing_streams_; |
| - // Salt required to translate renderer device IDs to raw device IDs |
| + // Salt required to translate renderer device IDs to raw device unique IDs |
| ResourceContext::SaltCallback salt_callback_; |
| + // Map of device authorizations for streams that are not yet created |
| + // The key is the stream ID, and the value is a pair. The pair's first element |
| + // is a bool that is true if the authorization process completes successfully. |
| + // The second element contains the unique ID of the authorized device. |
| + std::map<int, std::pair<bool, std::string>> authorizations_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); |
| }; |