audio_input_ipc.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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.
4
5#ifndef MEDIA_AUDIO_AUDIO_INPUT_IPC_H_
6#define MEDIA_AUDIO_AUDIO_INPUT_IPC_H_
7
8#include "base/shared_memory.h"
9#include "base/sync_socket.h"
10#include "media/audio/audio_parameters.h"
11#include "media/base/media_export.h"
12
13namespace media {
14
15// Contains IPC notifications for the state of the server side
16// (AudioInputController) audio state changes and when an AudioInputController
17// has been created.  Implemented by AudioInputDevice.
18class MEDIA_EXPORT AudioInputIPCDelegate {
19 public:
20  // Valid states for the input stream.
21  enum State {
22    kRecording,
23    kStopped,
24    kError
25  };
26
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,
37                               int length,
38                               int total_segments) = 0;
39
40  // Called when state of an audio stream has changed.
41  virtual void OnStateChanged(State state) = 0;
42
43  // Called when the input stream volume has changed.
44  virtual void OnVolume(double volume) = 0;
45
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 must clear any references to the AudioInputIPC object
49  // at this point.
50  virtual void OnIPCClosed() = 0;
51
52 protected:
53  virtual ~AudioInputIPCDelegate();
54};
55
56// Provides IPC functionality for an AudioInputDevice.  The implementation
57// should asynchronously deliver the messages to an AudioInputController object
58// (or create one in the case of CreateStream()), that may live in a separate
59// process.
60class MEDIA_EXPORT AudioInputIPC {
61 public:
62  // Registers an AudioInputIPCDelegate and returns a |stream_id| that
63  // must be used with all other IPC functions in this interface.
64  virtual int AddDelegate(AudioInputIPCDelegate* delegate) = 0;
65
66  // Unregisters a delegate that was previously registered via a call to
67  // AddDelegate().  The audio stream should be in a closed state prior to
68  // calling this function.
69  virtual void RemoveDelegate(int stream_id) = 0;
70
71  // Sends a request to create an AudioInputController object in the peer
72  // process, identify it by |stream_id| and configure it to use the specified
73  // audio |params|.  The |total_segments| indidates number of equal-lengthed
74  // segments in the shared memory buffer.
75  // Once the stream has been created, the implementation must
76  // generate a notification to the AudioInputIPCDelegate and call
77  // OnStreamCreated().
78  virtual void CreateStream(int stream_id,
79                            int session_id,
80                            const AudioParameters& params,
81                            bool automatic_gain_control,
82                            uint32 total_segments) = 0;
83
84  // Corresponds to a call to AudioInputController::Record() on the server side.
85  virtual void RecordStream(int stream_id) = 0;
86
87  // Sets the volume of the audio stream.
88  virtual void SetVolume(int stream_id, double volume) = 0;
89
90  // Closes the audio stream and deletes the matching AudioInputController
91  // instance.  Prior to deleting the AudioInputController object, a call to
92  // AudioInputController::Close must be made.
93  virtual void CloseStream(int stream_id) = 0;
94
95 protected:
96  virtual ~AudioInputIPC();
97};
98
99}  // namespace media
100
101#endif  // MEDIA_AUDIO_AUDIO_INPUT_IPC_H_
102