Linux: Depend on liberation-fonts package for RPMs.
[chromium-blink-merge.git] / media / audio / audio_output_ipc.h
blob6a16d813865ec32bdf4cd525d1572a650fca0c15
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.
5 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_IPC_H_
6 #define MEDIA_AUDIO_AUDIO_OUTPUT_IPC_H_
8 #include <string>
10 #include "base/memory/shared_memory.h"
11 #include "base/sync_socket.h"
12 #include "media/audio/audio_parameters.h"
13 #include "media/base/media_export.h"
14 #include "media/base/output_device.h"
15 #include "url/origin.h"
17 namespace media {
19 // Current status of the audio output stream in the browser process. Browser
20 // sends information about the current playback state and error to the
21 // renderer process using this type.
22 enum AudioOutputIPCDelegateState {
23 AUDIO_OUTPUT_IPC_DELEGATE_STATE_PLAYING,
24 AUDIO_OUTPUT_IPC_DELEGATE_STATE_PAUSED,
25 AUDIO_OUTPUT_IPC_DELEGATE_STATE_ERROR,
26 AUDIO_OUTPUT_IPC_DELEGATE_STATE_LAST = AUDIO_OUTPUT_IPC_DELEGATE_STATE_ERROR
29 // Contains IPC notifications for the state of the server side
30 // (AudioOutputController) audio state changes and when an AudioOutputController
31 // has been created. Implemented by AudioOutputDevice.
32 class MEDIA_EXPORT AudioOutputIPCDelegate {
33 public:
34 // Called when state of an audio stream has changed.
35 virtual void OnStateChanged(AudioOutputIPCDelegateState state) = 0;
37 // Called when an authorization request for an output device has been
38 // completed
39 virtual void OnDeviceAuthorized(
40 bool success,
41 const media::AudioParameters& output_params) = 0;
43 // Called when an audio stream has been created.
44 // The shared memory |handle| points to a memory section that's used to
45 // transfer audio buffers from the AudioOutputIPCDelegate back to the
46 // AudioRendererHost. The implementation of OnStreamCreated takes ownership.
47 // The |socket_handle| is used by AudioRendererHost to signal requests for
48 // audio data to be written into the shared memory. The AudioOutputIPCDelegate
49 // must read from this socket and provide audio whenever data (search for
50 // "pending_bytes") is received.
51 virtual void OnStreamCreated(base::SharedMemoryHandle handle,
52 base::SyncSocket::Handle socket_handle,
53 int length) = 0;
55 // Called when an attempt to switch the output device has been completed
56 virtual void OnOutputDeviceSwitched(SwitchOutputDeviceResult result) = 0;
58 // Called when the AudioOutputIPC object is going away and/or when the IPC
59 // channel has been closed and no more ipc requests can be made.
60 // Implementations should delete their owned AudioOutputIPC instance
61 // immediately.
62 virtual void OnIPCClosed() = 0;
64 protected:
65 virtual ~AudioOutputIPCDelegate();
68 // Provides the IPC functionality for an AudioOutputIPCDelegate (e.g., an
69 // AudioOutputDevice). The implementation should asynchronously deliver the
70 // messages to an AudioOutputController object (or create one in the case of
71 // CreateStream()), that may live in a separate process.
72 class MEDIA_EXPORT AudioOutputIPC {
73 public:
74 virtual ~AudioOutputIPC();
76 // Sends a request to authorize the use of a specific audio output device
77 // in the peer process.
78 // If |session_id| is nonzero, the browser selects the output device
79 // associated with an opened input device indicated by |session_id|. If no
80 // such device is found, the browser attempts to select the device indicated
81 // by |device_id|. If |device_id| is the empty string, the default
82 // audio output device will be selected.
83 // Once the authorization process is complete, the implementation will
84 // notify |delegate| by calling OnDeviceAuthorized().
85 virtual void RequestDeviceAuthorization(
86 AudioOutputIPCDelegate* delegate,
87 int session_id,
88 const std::string& device_id,
89 const url::Origin& security_origin) = 0;
91 // Sends a request to create an AudioOutputController object in the peer
92 // process and configures it to use the specified audio |params| including
93 // number of synchronized input channels.
94 // Once the stream has been created, the implementation will notify
95 // |delegate| by calling OnStreamCreated().
96 virtual void CreateStream(AudioOutputIPCDelegate* delegate,
97 const AudioParameters& params) = 0;
99 // Starts playing the stream. This should generate a call to
100 // AudioOutputController::Play().
101 virtual void PlayStream() = 0;
103 // Pauses an audio stream. This should generate a call to
104 // AudioOutputController::Pause().
105 virtual void PauseStream() = 0;
107 // Closes the audio stream which should shut down the corresponding
108 // AudioOutputController in the peer process.
109 virtual void CloseStream() = 0;
111 // Sets the volume of the audio stream.
112 virtual void SetVolume(double volume) = 0;
114 // Switches the output device of the audio stream.
115 virtual void SwitchOutputDevice(const std::string& device_id,
116 const url::Origin& security_origin) = 0;
119 } // namespace media
121 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_IPC_H_