Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / media / audio / audio_output_ipc.h
blob211550844648912eba43679478ef3e1bd21a2391
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 "url/gurl.h"
16 namespace media {
18 // Result of an audio output device switch operation
19 enum SwitchOutputDeviceResult {
20 SWITCH_OUTPUT_DEVICE_RESULT_SUCCESS = 0,
21 SWITCH_OUTPUT_DEVICE_RESULT_ERROR_NOT_FOUND,
22 SWITCH_OUTPUT_DEVICE_RESULT_ERROR_NOT_AUTHORIZED,
23 SWITCH_OUTPUT_DEVICE_RESULT_ERROR_OBSOLETE,
24 SWITCH_OUTPUT_DEVICE_RESULT_ERROR_NOT_SUPPORTED,
25 SWITCH_OUTPUT_DEVICE_RESULT_LAST =
26 SWITCH_OUTPUT_DEVICE_RESULT_ERROR_NOT_SUPPORTED,
29 // Current status of the audio output stream in the browser process. Browser
30 // sends information about the current playback state and error to the
31 // renderer process using this type.
32 enum AudioOutputIPCDelegateState {
33 AUDIO_OUTPUT_IPC_DELEGATE_STATE_PLAYING,
34 AUDIO_OUTPUT_IPC_DELEGATE_STATE_PAUSED,
35 AUDIO_OUTPUT_IPC_DELEGATE_STATE_ERROR,
36 AUDIO_OUTPUT_IPC_DELEGATE_STATE_LAST = AUDIO_OUTPUT_IPC_DELEGATE_STATE_ERROR
39 // Contains IPC notifications for the state of the server side
40 // (AudioOutputController) audio state changes and when an AudioOutputController
41 // has been created. Implemented by AudioOutputDevice.
42 class MEDIA_EXPORT AudioOutputIPCDelegate {
43 public:
45 // Called when state of an audio stream has changed.
46 virtual void OnStateChanged(AudioOutputIPCDelegateState state) = 0;
48 // Called when an audio stream has been created.
49 // The shared memory |handle| points to a memory section that's used to
50 // transfer audio buffers from the AudioOutputIPCDelegate back to the
51 // AudioRendererHost. The implementation of OnStreamCreated takes ownership.
52 // The |socket_handle| is used by AudioRendererHost to signal requests for
53 // audio data to be written into the shared memory. The AudioOutputIPCDelegate
54 // must read from this socket and provide audio whenever data (search for
55 // "pending_bytes") is received.
56 virtual void OnStreamCreated(base::SharedMemoryHandle handle,
57 base::SyncSocket::Handle socket_handle,
58 int length) = 0;
60 // Called when an attempt to switch the output device has been completed
61 virtual void OnOutputDeviceSwitched(int request_id,
62 SwitchOutputDeviceResult result) = 0;
64 // Called when the AudioOutputIPC object is going away and/or when the IPC
65 // channel has been closed and no more ipc requests can be made.
66 // Implementations should delete their owned AudioOutputIPC instance
67 // immediately.
68 virtual void OnIPCClosed() = 0;
70 protected:
71 virtual ~AudioOutputIPCDelegate();
74 // Provides the IPC functionality for an AudioOutputIPCDelegate (e.g., an
75 // AudioOutputDevice). The implementation should asynchronously deliver the
76 // messages to an AudioOutputController object (or create one in the case of
77 // CreateStream()), that may live in a separate process.
78 class MEDIA_EXPORT AudioOutputIPC {
79 public:
80 virtual ~AudioOutputIPC();
82 // Sends a request to create an AudioOutputController object in the peer
83 // process and configures it to use the specified audio |params| including
84 // number of synchronized input channels.|session_id| is used by the browser
85 // to select the correct input device if the input channel in |params| is
86 // valid, otherwise it will be ignored. Once the stream has been created,
87 // the implementation will notify |delegate| by calling OnStreamCreated().
88 virtual void CreateStream(AudioOutputIPCDelegate* delegate,
89 const AudioParameters& params,
90 int session_id) = 0;
92 // Starts playing the stream. This should generate a call to
93 // AudioOutputController::Play().
94 virtual void PlayStream() = 0;
96 // Pauses an audio stream. This should generate a call to
97 // AudioOutputController::Pause().
98 virtual void PauseStream() = 0;
100 // Closes the audio stream which should shut down the corresponding
101 // AudioOutputController in the peer process.
102 virtual void CloseStream() = 0;
104 // Sets the volume of the audio stream.
105 virtual void SetVolume(double volume) = 0;
107 // Switches the output device of the audio stream.
108 virtual void SwitchOutputDevice(const std::string& device_id,
109 const GURL& security_origin,
110 int request_id) = 0;
113 } // namespace media
115 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_IPC_H_