audio_output_ipc.h revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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/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  };
28
29  // Called when state of an audio stream has changed.
30  virtual void OnStateChanged(State state) = 0;
31
32  // Called when an audio stream has been created.
33  // The shared memory |handle| points to a memory section that's used to
34  // transfer audio buffers from the AudioOutputIPCDelegate back to the
35  // AudioRendererHost.  The implementation of OnStreamCreated takes ownership.
36  // The |socket_handle| is used by AudioRendererHost to signal requests for
37  // audio data to be written into the shared memory. The AudioOutputIPCDelegate
38  // must read from this socket and provide audio whenever data (search for
39  // "pending_bytes") is received.
40  virtual void OnStreamCreated(base::SharedMemoryHandle handle,
41                               base::SyncSocket::Handle socket_handle,
42                               int length) = 0;
43
44  // Called when the AudioOutputIPC object is going away and/or when the IPC
45  // channel has been closed and no more ipc requests can be made.
46  // Implementations should delete their owned AudioOutputIPC instance
47  // immediately.
48  virtual void OnIPCClosed() = 0;
49
50 protected:
51  virtual ~AudioOutputIPCDelegate();
52};
53
54// Provides the IPC functionality for an AudioOutputIPCDelegate (e.g., an
55// AudioOutputDevice).  The implementation should asynchronously deliver the
56// messages to an AudioOutputController object (or create one in the case of
57// CreateStream()), that may live in a separate process.
58class MEDIA_EXPORT AudioOutputIPC {
59 public:
60  virtual ~AudioOutputIPC();
61
62  // Sends a request to create an AudioOutputController object in the peer
63  // process and configures it to use the specified audio |params| including
64  // number of synchronized input channels.  Once the stream has been created,
65  // the implementation will notify |delegate| by calling OnStreamCreated().
66  virtual void CreateStream(AudioOutputIPCDelegate* delegate,
67                            const AudioParameters& params) = 0;
68
69  // Starts playing the stream.  This should generate a call to
70  // AudioOutputController::Play().
71  virtual void PlayStream() = 0;
72
73  // Pauses an audio stream.  This should generate a call to
74  // AudioOutputController::Pause().
75  virtual void PauseStream() = 0;
76
77  // Closes the audio stream which should shut down the corresponding
78  // AudioOutputController in the peer process.
79  virtual void CloseStream() = 0;
80
81  // Sets the volume of the audio stream.
82  virtual void SetVolume(double volume) = 0;
83};
84
85}  // namespace media
86
87#endif  // MEDIA_AUDIO_AUDIO_OUTPUT_IPC_H_
88