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_OUTPUT_IPC_H_
6#define MEDIA_AUDIO_AUDIO_OUTPUT_IPC_H_
7
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"
12
13namespace media {
14
15// Contains IPC notifications for the state of the server side
16// (AudioOutputController) audio state changes and when an AudioOutputController
17// has been created.  Implemented by AudioOutputDevice.
18class MEDIA_EXPORT AudioOutputIPCDelegate {
19 public:
20  // Current status of the audio output stream in the browser process. Browser
21  // sends information about the current playback state and error to the
22  // renderer process using this type.
23  enum State {
24    kPlaying,
25    kPaused,
26    kError,
27    kStateLast = kError
28  };
29
30  // Called when state of an audio stream has changed.
31  virtual void OnStateChanged(State state) = 0;
32
33  // Called when an audio stream has been created.
34  // The shared memory |handle| points to a memory section that's used to
35  // transfer audio buffers from the AudioOutputIPCDelegate back to the
36  // AudioRendererHost.  The implementation of OnStreamCreated takes ownership.
37  // The |socket_handle| is used by AudioRendererHost to signal requests for
38  // audio data to be written into the shared memory. The AudioOutputIPCDelegate
39  // must read from this socket and provide audio whenever data (search for
40  // "pending_bytes") is received.
41  virtual void OnStreamCreated(base::SharedMemoryHandle handle,
42                               base::SyncSocket::Handle socket_handle,
43                               int length) = 0;
44
45  // Called when the AudioOutputIPC object is going away and/or when the IPC
46  // channel has been closed and no more ipc requests can be made.
47  // Implementations should delete their owned AudioOutputIPC instance
48  // immediately.
49  virtual void OnIPCClosed() = 0;
50
51 protected:
52  virtual ~AudioOutputIPCDelegate();
53};
54
55// Provides the IPC functionality for an AudioOutputIPCDelegate (e.g., an
56// AudioOutputDevice).  The implementation should asynchronously deliver the
57// messages to an AudioOutputController object (or create one in the case of
58// CreateStream()), that may live in a separate process.
59class MEDIA_EXPORT AudioOutputIPC {
60 public:
61  virtual ~AudioOutputIPC();
62
63  // Sends a request to create an AudioOutputController object in the peer
64  // process and configures it to use the specified audio |params| including
65  // number of synchronized input channels.|session_id| is used by the browser
66  // to select the correct input device if the input channel in |params| is
67  // valid, otherwise it will be ignored.  Once the stream has been created,
68  // the implementation will notify |delegate| by calling OnStreamCreated().
69  virtual void CreateStream(AudioOutputIPCDelegate* delegate,
70                            const AudioParameters& params,
71                            int session_id) = 0;
72
73  // Starts playing the stream.  This should generate a call to
74  // AudioOutputController::Play().
75  virtual void PlayStream() = 0;
76
77  // Pauses an audio stream.  This should generate a call to
78  // AudioOutputController::Pause().
79  virtual void PauseStream() = 0;
80
81  // Closes the audio stream which should shut down the corresponding
82  // AudioOutputController in the peer process.
83  virtual void CloseStream() = 0;
84
85  // Sets the volume of the audio stream.
86  virtual void SetVolume(double volume) = 0;
87};
88
89}  // namespace media
90
91#endif  // MEDIA_AUDIO_AUDIO_OUTPUT_IPC_H_
92