audio_output_ipc.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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 must clear any references to the AudioOutputIPC object
47  // at this point.
48  virtual void OnIPCClosed() = 0;
49
50 protected:
51  virtual ~AudioOutputIPCDelegate();
52};
53
54// Provides IPC functionality for an AudioOutputDevice.  The implementation
55// should asynchronously deliver the messages to an AudioOutputController object
56// (or create one in the case of CreateStream()), that may live in a separate
57// process.
58class MEDIA_EXPORT AudioOutputIPC {
59 public:
60  // Registers an AudioOutputIPCDelegate and returns a |stream_id| that must
61  // be used with all other IPC functions in this interface.
62  virtual int AddDelegate(AudioOutputIPCDelegate* delegate) = 0;
63
64  // Unregisters a delegate that was previously registered via a call to
65  // AddDelegate().  The audio stream should be in a closed state prior to
66  // calling this function.
67  virtual void RemoveDelegate(int stream_id) = 0;
68
69  // Sends a request to create an AudioOutputController object in the peer
70  // process, identify it by |stream_id| and configure it to use the specified
71  // audio |params| and number of synchronized input channels.
72  // Once the stream has been created, the implementation must
73  // generate a notification to the AudioOutputIPCDelegate and call
74  // OnStreamCreated().
75  virtual void CreateStream(int stream_id,
76                            const AudioParameters& params,
77                            int input_channels) = 0;
78
79  // Starts playing the stream.  This should generate a call to
80  // AudioOutputController::Play().
81  virtual void PlayStream(int stream_id) = 0;
82
83  // Pauses an audio stream.  This should generate a call to
84  // AudioOutputController::Pause().
85  virtual void PauseStream(int stream_id) = 0;
86
87  // "Flushes" the audio device. This should generate a call to
88  // AudioOutputController::Flush().
89  // TODO(tommi): This is currently neither implemented nor called.  Remove?
90  virtual void FlushStream(int stream_id) = 0;
91
92  // Closes the audio stream and deletes the matching AudioOutputController
93  // instance.  Prior to deleting the AudioOutputController object, a call to
94  // AudioOutputController::Close must be made.
95  virtual void CloseStream(int stream_id) = 0;
96
97  // Sets the volume of the audio stream.
98  virtual void SetVolume(int stream_id, double volume) = 0;
99
100 protected:
101  virtual ~AudioOutputIPC();
102};
103
104}  // namespace media
105
106#endif  // MEDIA_AUDIO_AUDIO_OUTPUT_IPC_H_
107