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"
18 // Result of an audio output device switch operation
19 enum SwitchOutputDeviceResult
{
20 SWITCH_OUTPUT_DEVICE_RESULT_SUCCESS
= 0,
21 SWITCH_OUTPUT_DEVICE_RESULT_ERROR_NOT_FOUND
,
22 SWITCH_OUTPUT_DEVICE_RESULT_ERROR_NOT_AUTHORIZED
,
23 SWITCH_OUTPUT_DEVICE_RESULT_ERROR_OBSOLETE
,
24 SWITCH_OUTPUT_DEVICE_RESULT_ERROR_NOT_SUPPORTED
,
25 SWITCH_OUTPUT_DEVICE_RESULT_LAST
=
26 SWITCH_OUTPUT_DEVICE_RESULT_ERROR_NOT_SUPPORTED
,
29 // Current status of the audio output stream in the browser process. Browser
30 // sends information about the current playback state and error to the
31 // renderer process using this type.
32 enum AudioOutputIPCDelegateState
{
33 AUDIO_OUTPUT_IPC_DELEGATE_STATE_PLAYING
,
34 AUDIO_OUTPUT_IPC_DELEGATE_STATE_PAUSED
,
35 AUDIO_OUTPUT_IPC_DELEGATE_STATE_ERROR
,
36 AUDIO_OUTPUT_IPC_DELEGATE_STATE_LAST
= AUDIO_OUTPUT_IPC_DELEGATE_STATE_ERROR
39 // Contains IPC notifications for the state of the server side
40 // (AudioOutputController) audio state changes and when an AudioOutputController
41 // has been created. Implemented by AudioOutputDevice.
42 class MEDIA_EXPORT AudioOutputIPCDelegate
{
45 // Called when state of an audio stream has changed.
46 virtual void OnStateChanged(AudioOutputIPCDelegateState state
) = 0;
48 // Called when an audio stream has been created.
49 // The shared memory |handle| points to a memory section that's used to
50 // transfer audio buffers from the AudioOutputIPCDelegate back to the
51 // AudioRendererHost. The implementation of OnStreamCreated takes ownership.
52 // The |socket_handle| is used by AudioRendererHost to signal requests for
53 // audio data to be written into the shared memory. The AudioOutputIPCDelegate
54 // must read from this socket and provide audio whenever data (search for
55 // "pending_bytes") is received.
56 virtual void OnStreamCreated(base::SharedMemoryHandle handle
,
57 base::SyncSocket::Handle socket_handle
,
60 // Called when the AudioOutputIPC object is going away and/or when the IPC
61 // channel has been closed and no more ipc requests can be made.
62 // Implementations should delete their owned AudioOutputIPC instance
64 virtual void OnIPCClosed() = 0;
67 virtual ~AudioOutputIPCDelegate();
70 // Provides the IPC functionality for an AudioOutputIPCDelegate (e.g., an
71 // AudioOutputDevice). The implementation should asynchronously deliver the
72 // messages to an AudioOutputController object (or create one in the case of
73 // CreateStream()), that may live in a separate process.
74 class MEDIA_EXPORT AudioOutputIPC
{
76 virtual ~AudioOutputIPC();
78 // Sends a request to create an AudioOutputController object in the peer
79 // process and configures it to use the specified audio |params| including
80 // number of synchronized input channels.|session_id| is used by the browser
81 // to select the correct input device if the input channel in |params| is
82 // valid, otherwise it will be ignored. Once the stream has been created,
83 // the implementation will notify |delegate| by calling OnStreamCreated().
84 virtual void CreateStream(AudioOutputIPCDelegate
* delegate
,
85 const AudioParameters
& params
,
88 // Starts playing the stream. This should generate a call to
89 // AudioOutputController::Play().
90 virtual void PlayStream() = 0;
92 // Pauses an audio stream. This should generate a call to
93 // AudioOutputController::Pause().
94 virtual void PauseStream() = 0;
96 // Closes the audio stream which should shut down the corresponding
97 // AudioOutputController in the peer process.
98 virtual void CloseStream() = 0;
100 // Sets the volume of the audio stream.
101 virtual void SetVolume(double volume
) = 0;
106 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_IPC_H_