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_INPUT_IPC_H_
6 #define MEDIA_AUDIO_AUDIO_INPUT_IPC_H_
8 #include "base/memory/shared_memory.h"
9 #include "base/sync_socket.h"
10 #include "media/audio/audio_parameters.h"
11 #include "media/base/media_export.h"
15 enum AudioInputIPCDelegateState
{
16 AUDIO_INPUT_IPC_DELEGATE_STATE_RECORDING
,
17 AUDIO_INPUT_IPC_DELEGATE_STATE_STOPPED
,
18 AUDIO_INPUT_IPC_DELEGATE_STATE_ERROR
,
19 AUDIO_INPUT_IPC_DELEGATE_STATE_LAST
= AUDIO_INPUT_IPC_DELEGATE_STATE_ERROR
,
22 // Contains IPC notifications for the state of the server side
23 // (AudioInputController) audio state changes and when an AudioInputController
24 // has been created. Implemented by AudioInputDevice.
25 class MEDIA_EXPORT AudioInputIPCDelegate
{
27 // Called when an AudioInputController has been created.
28 // The shared memory |handle| points to a memory section that's used to
29 // transfer data between the AudioInputDevice and AudioInputController
30 // objects. The implementation of OnStreamCreated takes ownership.
31 // The |socket_handle| is used by the AudioInputController to signal
32 // notifications that more data is available and can optionally provide
33 // parameter changes back. The AudioInputDevice must read from this socket
34 // and process the shared memory whenever data is read from the socket.
35 virtual void OnStreamCreated(base::SharedMemoryHandle handle
,
36 base::SyncSocket::Handle socket_handle
,
38 int total_segments
) = 0;
40 // Called when state of an audio stream has changed.
41 virtual void OnStateChanged(AudioInputIPCDelegateState state
) = 0;
43 // Called when the input stream volume has changed.
44 virtual void OnVolume(double volume
) = 0;
46 // Called when the AudioInputIPC object is going away and/or when the
47 // IPC channel has been closed and no more IPC requests can be made.
48 // Implementations should delete their owned AudioInputIPC instance
50 virtual void OnIPCClosed() = 0;
53 virtual ~AudioInputIPCDelegate();
56 // Provides IPC functionality for an AudioInputIPCDelegate (e.g., an
57 // AudioInputDevice). The implementation should asynchronously deliver the
58 // messages to an AudioInputController object (or create one in the case of
59 // CreateStream()), that may live in a separate process.
60 class MEDIA_EXPORT AudioInputIPC
{
62 virtual ~AudioInputIPC();
64 // Sends a request to create an AudioInputController object in the peer
65 // process, and configures it to use the specified audio |params|. The
66 // |total_segments| indidates number of equal-lengthed segments in the shared
67 // memory buffer. Once the stream has been created, the implementation will
68 // notify |delegate| by calling OnStreamCreated().
69 virtual void CreateStream(AudioInputIPCDelegate
* delegate
,
71 const AudioParameters
& params
,
72 bool automatic_gain_control
,
73 uint32 total_segments
) = 0;
75 // Corresponds to a call to AudioInputController::Record() on the server side.
76 virtual void RecordStream() = 0;
78 // Sets the volume of the audio stream.
79 virtual void SetVolume(double volume
) = 0;
81 // Closes the audio stream, which should shut down the corresponding
82 // AudioInputController in the peer process.
83 virtual void CloseStream() = 0;
88 #endif // MEDIA_AUDIO_AUDIO_INPUT_IPC_H_