| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_IPC_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_IPC_H_ |
| 6 #define MEDIA_AUDIO_AUDIO_OUTPUT_IPC_H_ | 6 #define MEDIA_AUDIO_AUDIO_OUTPUT_IPC_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
| 11 #include "base/sync_socket.h" | 11 #include "base/sync_socket.h" |
| 12 #include "media/audio/audio_parameters.h" | 12 #include "media/audio/audio_parameters.h" |
| 13 #include "media/base/media_export.h" | 13 #include "media/base/media_export.h" |
| 14 #include "media/base/output_device.h" | 14 #include "media/base/output_device.h" |
| 15 #include "url/gurl.h" | 15 #include "url/origin.h" |
| 16 | 16 |
| 17 namespace media { | 17 namespace media { |
| 18 | 18 |
| 19 // Current status of the audio output stream in the browser process. Browser | 19 // Current status of the audio output stream in the browser process. Browser |
| 20 // sends information about the current playback state and error to the | 20 // sends information about the current playback state and error to the |
| 21 // renderer process using this type. | 21 // renderer process using this type. |
| 22 enum AudioOutputIPCDelegateState { | 22 enum AudioOutputIPCDelegateState { |
| 23 AUDIO_OUTPUT_IPC_DELEGATE_STATE_PLAYING, | 23 AUDIO_OUTPUT_IPC_DELEGATE_STATE_PLAYING, |
| 24 AUDIO_OUTPUT_IPC_DELEGATE_STATE_PAUSED, | 24 AUDIO_OUTPUT_IPC_DELEGATE_STATE_PAUSED, |
| 25 AUDIO_OUTPUT_IPC_DELEGATE_STATE_ERROR, | 25 AUDIO_OUTPUT_IPC_DELEGATE_STATE_ERROR, |
| 26 AUDIO_OUTPUT_IPC_DELEGATE_STATE_LAST = AUDIO_OUTPUT_IPC_DELEGATE_STATE_ERROR | 26 AUDIO_OUTPUT_IPC_DELEGATE_STATE_LAST = AUDIO_OUTPUT_IPC_DELEGATE_STATE_ERROR |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 // Contains IPC notifications for the state of the server side | 29 // Contains IPC notifications for the state of the server side |
| 30 // (AudioOutputController) audio state changes and when an AudioOutputController | 30 // (AudioOutputController) audio state changes and when an AudioOutputController |
| 31 // has been created. Implemented by AudioOutputDevice. | 31 // has been created. Implemented by AudioOutputDevice. |
| 32 class MEDIA_EXPORT AudioOutputIPCDelegate { | 32 class MEDIA_EXPORT AudioOutputIPCDelegate { |
| 33 public: | 33 public: |
| 34 | |
| 35 // Called when state of an audio stream has changed. | 34 // Called when state of an audio stream has changed. |
| 36 virtual void OnStateChanged(AudioOutputIPCDelegateState state) = 0; | 35 virtual void OnStateChanged(AudioOutputIPCDelegateState state) = 0; |
| 37 | 36 |
| 37 // Called when an authorization request for an output device has been |
| 38 // completed |
| 39 virtual void OnDeviceAuthorized( |
| 40 bool success, |
| 41 const media::AudioParameters& output_params) = 0; |
| 42 |
| 38 // Called when an audio stream has been created. | 43 // Called when an audio stream has been created. |
| 39 // The shared memory |handle| points to a memory section that's used to | 44 // The shared memory |handle| points to a memory section that's used to |
| 40 // transfer audio buffers from the AudioOutputIPCDelegate back to the | 45 // transfer audio buffers from the AudioOutputIPCDelegate back to the |
| 41 // AudioRendererHost. The implementation of OnStreamCreated takes ownership. | 46 // AudioRendererHost. The implementation of OnStreamCreated takes ownership. |
| 42 // The |socket_handle| is used by AudioRendererHost to signal requests for | 47 // The |socket_handle| is used by AudioRendererHost to signal requests for |
| 43 // audio data to be written into the shared memory. The AudioOutputIPCDelegate | 48 // audio data to be written into the shared memory. The AudioOutputIPCDelegate |
| 44 // must read from this socket and provide audio whenever data (search for | 49 // must read from this socket and provide audio whenever data (search for |
| 45 // "pending_bytes") is received. | 50 // "pending_bytes") is received. |
| 46 virtual void OnStreamCreated(base::SharedMemoryHandle handle, | 51 virtual void OnStreamCreated(base::SharedMemoryHandle handle, |
| 47 base::SyncSocket::Handle socket_handle, | 52 base::SyncSocket::Handle socket_handle, |
| 48 int length) = 0; | 53 int length) = 0; |
| 49 | 54 |
| 50 // Called when an attempt to switch the output device has been completed | 55 // Called when an attempt to switch the output device has been completed |
| 51 virtual void OnOutputDeviceSwitched(int request_id, | 56 virtual void OnOutputDeviceSwitched(SwitchOutputDeviceResult result) = 0; |
| 52 SwitchOutputDeviceResult result) = 0; | |
| 53 | 57 |
| 54 // Called when the AudioOutputIPC object is going away and/or when the IPC | 58 // Called when the AudioOutputIPC object is going away and/or when the IPC |
| 55 // channel has been closed and no more ipc requests can be made. | 59 // channel has been closed and no more ipc requests can be made. |
| 56 // Implementations should delete their owned AudioOutputIPC instance | 60 // Implementations should delete their owned AudioOutputIPC instance |
| 57 // immediately. | 61 // immediately. |
| 58 virtual void OnIPCClosed() = 0; | 62 virtual void OnIPCClosed() = 0; |
| 59 | 63 |
| 60 protected: | 64 protected: |
| 61 virtual ~AudioOutputIPCDelegate(); | 65 virtual ~AudioOutputIPCDelegate(); |
| 62 }; | 66 }; |
| 63 | 67 |
| 64 // Provides the IPC functionality for an AudioOutputIPCDelegate (e.g., an | 68 // Provides the IPC functionality for an AudioOutputIPCDelegate (e.g., an |
| 65 // AudioOutputDevice). The implementation should asynchronously deliver the | 69 // AudioOutputDevice). The implementation should asynchronously deliver the |
| 66 // messages to an AudioOutputController object (or create one in the case of | 70 // messages to an AudioOutputController object (or create one in the case of |
| 67 // CreateStream()), that may live in a separate process. | 71 // CreateStream()), that may live in a separate process. |
| 68 class MEDIA_EXPORT AudioOutputIPC { | 72 class MEDIA_EXPORT AudioOutputIPC { |
| 69 public: | 73 public: |
| 70 virtual ~AudioOutputIPC(); | 74 virtual ~AudioOutputIPC(); |
| 71 | 75 |
| 76 // Sends a request to authorize the use of a specific audio output device |
| 77 // in the peer process. |
| 78 // If |session_id| is nonzero, the browser selects the output device |
| 79 // associated with an opened input device indicated by |session_id|. If no |
| 80 // such device is found, the browser attempts to select the device indicated |
| 81 // by |device_id|. If |device_id| is the empty string, the default |
| 82 // audio output device will be selected. |
| 83 // Once the authorization process is complete, the implementation will |
| 84 // notify |delegate| by calling OnDeviceAuthorized(). |
| 85 virtual void RequestDeviceAuthorization( |
| 86 AudioOutputIPCDelegate* delegate, |
| 87 int session_id, |
| 88 const std::string& device_id, |
| 89 const url::Origin& security_origin) = 0; |
| 90 |
| 72 // Sends a request to create an AudioOutputController object in the peer | 91 // Sends a request to create an AudioOutputController object in the peer |
| 73 // process and configures it to use the specified audio |params| including | 92 // process and configures it to use the specified audio |params| including |
| 74 // number of synchronized input channels.|session_id| is used by the browser | 93 // number of synchronized input channels. |
| 75 // to select the correct input device if the input channel in |params| is | 94 // Once the stream has been created, the implementation will notify |
| 76 // valid, otherwise it will be ignored. Once the stream has been created, | 95 // |delegate| by calling OnStreamCreated(). |
| 77 // the implementation will notify |delegate| by calling OnStreamCreated(). | |
| 78 virtual void CreateStream(AudioOutputIPCDelegate* delegate, | 96 virtual void CreateStream(AudioOutputIPCDelegate* delegate, |
| 79 const AudioParameters& params, | 97 const AudioParameters& params) = 0; |
| 80 int session_id) = 0; | |
| 81 | 98 |
| 82 // Starts playing the stream. This should generate a call to | 99 // Starts playing the stream. This should generate a call to |
| 83 // AudioOutputController::Play(). | 100 // AudioOutputController::Play(). |
| 84 virtual void PlayStream() = 0; | 101 virtual void PlayStream() = 0; |
| 85 | 102 |
| 86 // Pauses an audio stream. This should generate a call to | 103 // Pauses an audio stream. This should generate a call to |
| 87 // AudioOutputController::Pause(). | 104 // AudioOutputController::Pause(). |
| 88 virtual void PauseStream() = 0; | 105 virtual void PauseStream() = 0; |
| 89 | 106 |
| 90 // Closes the audio stream which should shut down the corresponding | 107 // Closes the audio stream which should shut down the corresponding |
| 91 // AudioOutputController in the peer process. | 108 // AudioOutputController in the peer process. |
| 92 virtual void CloseStream() = 0; | 109 virtual void CloseStream() = 0; |
| 93 | 110 |
| 94 // Sets the volume of the audio stream. | 111 // Sets the volume of the audio stream. |
| 95 virtual void SetVolume(double volume) = 0; | 112 virtual void SetVolume(double volume) = 0; |
| 96 | 113 |
| 97 // Switches the output device of the audio stream. | 114 // Switches the output device of the audio stream. |
| 98 virtual void SwitchOutputDevice(const std::string& device_id, | 115 virtual void SwitchOutputDevice(const std::string& device_id, |
| 99 const GURL& security_origin, | 116 const url::Origin& security_origin) = 0; |
| 100 int request_id) = 0; | |
| 101 }; | 117 }; |
| 102 | 118 |
| 103 } // namespace media | 119 } // namespace media |
| 104 | 120 |
| 105 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_IPC_H_ | 121 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_IPC_H_ |
| OLD | NEW |