summaryrefslogtreecommitdiffstats
path: root/media/audio/audio_input_ipc.h
blob: 044ee9935469fb07a5792483743c852a4246cd6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_AUDIO_AUDIO_INPUT_IPC_H_
#define MEDIA_AUDIO_AUDIO_INPUT_IPC_H_

#include "base/shared_memory.h"
#include "base/sync_socket.h"
#include "media/audio/audio_parameters.h"
#include "media/base/media_export.h"

namespace media {

// Contains IPC notifications for the state of the server side
// (AudioInputController) audio state changes and when an AudioInputController
// has been created.  Implemented by AudioInputDevice.
class MEDIA_EXPORT AudioInputIPCDelegate {
 public:
  // Valid states for the input stream.
  enum State {
    kRecording,
    kStopped,
    kError
  };

  // Called when an AudioInputController has been created.
  // The shared memory |handle| points to a memory section that's used to
  // transfer data between the AudioInputDevice and AudioInputController
  // objects.  The implementation of OnStreamCreated takes ownership.
  // The |socket_handle| is used by the AudioInputController to signal
  // notifications that more data is available and can optionally provide
  // parameter changes back.  The AudioInputDevice must read from this socket
  // and process the shared memory whenever data is read from the socket.
  virtual void OnStreamCreated(base::SharedMemoryHandle handle,
                               base::SyncSocket::Handle socket_handle,
                               int length,
                               int total_segments) = 0;

  // Called when state of an audio stream has changed.
  virtual void OnStateChanged(State state) = 0;

  // Called when the input stream volume has changed.
  virtual void OnVolume(double volume) = 0;

  // Called when the AudioInputIPC object is going away and/or when the
  // IPC channel has been closed and no more IPC requests can be made.
  // Implementations must clear any references to the AudioInputIPC object
  // at this point.
  virtual void OnIPCClosed() = 0;

 protected:
  virtual ~AudioInputIPCDelegate();
};

// Provides IPC functionality for an AudioInputDevice.  The implementation
// should asynchronously deliver the messages to an AudioInputController object
// (or create one in the case of CreateStream()), that may live in a separate
// process.
class MEDIA_EXPORT AudioInputIPC {
 public:
  // Registers an AudioInputIPCDelegate and returns a |stream_id| that
  // must be used with all other IPC functions in this interface.
  virtual int AddDelegate(AudioInputIPCDelegate* delegate) = 0;

  // Unregisters a delegate that was previously registered via a call to
  // AddDelegate().  The audio stream should be in a closed state prior to
  // calling this function.
  virtual void RemoveDelegate(int stream_id) = 0;

  // Sends a request to create an AudioInputController object in the peer
  // process, identify it by |stream_id| and configure it to use the specified
  // audio |params|.  The |total_segments| indidates number of equal-lengthed
  // segments in the shared memory buffer.
  // Once the stream has been created, the implementation must
  // generate a notification to the AudioInputIPCDelegate and call
  // OnStreamCreated().
  virtual void CreateStream(int stream_id,
                            int session_id,
                            const AudioParameters& params,
                            bool automatic_gain_control,
                            uint32 total_segments) = 0;

  // Corresponds to a call to AudioInputController::Record() on the server side.
  virtual void RecordStream(int stream_id) = 0;

  // Sets the volume of the audio stream.
  virtual void SetVolume(int stream_id, double volume) = 0;

  // Closes the audio stream and deletes the matching AudioInputController
  // instance.  Prior to deleting the AudioInputController object, a call to
  // AudioInputController::Close must be made.
  virtual void CloseStream(int stream_id) = 0;

 protected:
  virtual ~AudioInputIPC();
};

}  // namespace media

#endif  // MEDIA_AUDIO_AUDIO_INPUT_IPC_H_