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
3 // found in the LICENSE file.
5 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_IPC_H_
6 #define MEDIA_AUDIO_AUDIO_OUTPUT_IPC_H_
10 #include "base/memory/shared_memory.h"
11 #include "base/sync_socket.h"
12 #include "media/audio/audio_parameters.h"
13 #include "media/base/media_export.h"
14 #include "media/base/output_device.h"
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
21 // renderer process using this type.
22 enum AudioOutputIPCDelegateState
{
23 AUDIO_OUTPUT_IPC_DELEGATE_STATE_PLAYING
,
24 AUDIO_OUTPUT_IPC_DELEGATE_STATE_PAUSED
,
25 AUDIO_OUTPUT_IPC_DELEGATE_STATE_ERROR
,
26 AUDIO_OUTPUT_IPC_DELEGATE_STATE_LAST
= AUDIO_OUTPUT_IPC_DELEGATE_STATE_ERROR
29 // Contains IPC notifications for the state of the server side
30 // (AudioOutputController) audio state changes and when an AudioOutputController
31 // has been created. Implemented by AudioOutputDevice.
32 class MEDIA_EXPORT AudioOutputIPCDelegate
{
35 // Called when state of an audio stream has changed.
36 virtual void OnStateChanged(AudioOutputIPCDelegateState state
) = 0;
38 // Called when an audio stream has been created.
39 // The shared memory |handle| points to a memory section that's used to
40 // transfer audio buffers from the AudioOutputIPCDelegate back to the
41 // AudioRendererHost. The implementation of OnStreamCreated takes ownership.
42 // The |socket_handle| is used by AudioRendererHost to signal requests for
43 // audio data to be written into the shared memory. The AudioOutputIPCDelegate
44 // must read from this socket and provide audio whenever data (search for
45 // "pending_bytes") is received.
46 virtual void OnStreamCreated(base::SharedMemoryHandle handle
,
47 base::SyncSocket::Handle socket_handle
,
50 // Called when an attempt to switch the output device has been completed
51 virtual void OnOutputDeviceSwitched(int request_id
,
52 SwitchOutputDeviceResult result
) = 0;
54 // 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.
56 // Implementations should delete their owned AudioOutputIPC instance
58 virtual void OnIPCClosed() = 0;
61 virtual ~AudioOutputIPCDelegate();
64 // Provides the IPC functionality for an AudioOutputIPCDelegate (e.g., an
65 // AudioOutputDevice). The implementation should asynchronously deliver the
66 // messages to an AudioOutputController object (or create one in the case of
67 // CreateStream()), that may live in a separate process.
68 class MEDIA_EXPORT AudioOutputIPC
{
70 virtual ~AudioOutputIPC();
72 // Sends a request to create an AudioOutputController object in the peer
73 // process and configures it to use the specified audio |params| including
74 // number of synchronized input channels.|session_id| is used by the browser
75 // to select the correct input device if the input channel in |params| is
76 // valid, otherwise it will be ignored. Once the stream has been created,
77 // the implementation will notify |delegate| by calling OnStreamCreated().
78 virtual void CreateStream(AudioOutputIPCDelegate
* delegate
,
79 const AudioParameters
& params
,
82 // Starts playing the stream. This should generate a call to
83 // AudioOutputController::Play().
84 virtual void PlayStream() = 0;
86 // Pauses an audio stream. This should generate a call to
87 // AudioOutputController::Pause().
88 virtual void PauseStream() = 0;
90 // Closes the audio stream which should shut down the corresponding
91 // AudioOutputController in the peer process.
92 virtual void CloseStream() = 0;
94 // Sets the volume of the audio stream.
95 virtual void SetVolume(double volume
) = 0;
97 // Switches the output device of the audio stream.
98 virtual void SwitchOutputDevice(const std::string
& device_id
,
99 const GURL
& security_origin
,
105 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_IPC_H_