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// IPC messages for the audio.
6// Multiply-included message file, hence no include guard.
7
8#include "base/basictypes.h"
9#include "base/memory/shared_memory.h"
10#include "base/sync_socket.h"
11#include "content/common/content_export.h"
12#include "content/common/media/media_param_traits.h"
13#include "ipc/ipc_message_macros.h"
14#include "media/audio/audio_buffers_state.h"
15#include "media/audio/audio_input_ipc.h"
16#include "media/audio/audio_output_ipc.h"
17#include "media/audio/audio_parameters.h"
18
19#undef IPC_MESSAGE_EXPORT
20#define IPC_MESSAGE_EXPORT CONTENT_EXPORT
21#define IPC_MESSAGE_START AudioMsgStart
22
23IPC_ENUM_TRAITS_MAX_VALUE(media::AudioInputIPCDelegate::State,
24                          media::AudioInputIPCDelegate::kStateLast)
25
26IPC_ENUM_TRAITS_MAX_VALUE(media::AudioOutputIPCDelegate::State,
27                          media::AudioOutputIPCDelegate::kStateLast)
28
29IPC_STRUCT_BEGIN(AudioInputHostMsg_CreateStream_Config)
30  IPC_STRUCT_MEMBER(media::AudioParameters, params)
31  IPC_STRUCT_MEMBER(bool, automatic_gain_control)
32  IPC_STRUCT_MEMBER(uint32, shared_memory_count)
33IPC_STRUCT_END()
34
35// Messages sent from the browser to the renderer.
36
37// Tell the renderer process that an audio stream has been created.
38// The renderer process is given a shared memory handle for the audio data
39// buffer it shares with the browser process. It is also given a SyncSocket that
40// it uses to communicate with the browser process about the state of the
41// buffered audio data.
42#if defined(OS_WIN)
43IPC_MESSAGE_CONTROL4(AudioMsg_NotifyStreamCreated,
44                     int /* stream id */,
45                     base::SharedMemoryHandle /* handle */,
46                     base::SyncSocket::Handle /* socket handle */,
47                     uint32 /* length */)
48#else
49IPC_MESSAGE_CONTROL4(AudioMsg_NotifyStreamCreated,
50                     int /* stream id */,
51                     base::SharedMemoryHandle /* handle */,
52                     base::FileDescriptor /* socket handle */,
53                     uint32 /* length */)
54#endif
55
56// Tell the renderer process that an audio input stream has been created.
57// The renderer process would be given a SyncSocket that it should read
58// from from then on. It is also given number of segments in shared memory.
59#if defined(OS_WIN)
60IPC_MESSAGE_CONTROL5(AudioInputMsg_NotifyStreamCreated,
61                     int /* stream id */,
62                     base::SharedMemoryHandle /* handle */,
63                     base::SyncSocket::Handle /* socket handle */,
64                     uint32 /* length */,
65                     uint32 /* segment count */)
66#else
67IPC_MESSAGE_CONTROL5(AudioInputMsg_NotifyStreamCreated,
68                     int /* stream id */,
69                     base::SharedMemoryHandle /* handle */,
70                     base::FileDescriptor /* socket handle */,
71                     uint32 /* length */,
72                     uint32 /* segment count */)
73#endif
74
75// Notification message sent from AudioRendererHost to renderer after an output
76// device change has occurred.
77IPC_MESSAGE_CONTROL3(AudioMsg_NotifyDeviceChanged,
78                     int /* stream_id */,
79                     int /* new_buffer_size */,
80                     int /* new_sample_rate */)
81
82// Notification message sent from AudioRendererHost to renderer for state
83// update after the renderer has requested a Create/Start/Close.
84IPC_MESSAGE_CONTROL2(AudioMsg_NotifyStreamStateChanged,
85                     int /* stream id */,
86                     media::AudioOutputIPCDelegate::State /* new state */)
87
88// Notification message sent from browser to renderer for state update.
89IPC_MESSAGE_CONTROL2(AudioInputMsg_NotifyStreamStateChanged,
90                     int /* stream id */,
91                     media::AudioInputIPCDelegate::State /* new state */)
92
93IPC_MESSAGE_CONTROL2(AudioInputMsg_NotifyStreamVolume,
94                     int /* stream id */,
95                     double /* volume */)
96
97// Messages sent from the renderer to the browser.
98
99// Request that is sent to the browser for creating an audio output stream.
100// |render_view_id| is the routing ID for the render view producing the audio
101// data.
102IPC_MESSAGE_CONTROL5(AudioHostMsg_CreateStream,
103                     int /* stream_id */,
104                     int /* render_view_id */,
105                     int /* render_frame_id */,
106                     int /* session_id */,
107                     media::AudioParameters /* params */)
108
109// Request that is sent to the browser for creating an audio input stream.
110// |render_view_id| is the routing ID for the render view consuming the audio
111// data.
112IPC_MESSAGE_CONTROL4(AudioInputHostMsg_CreateStream,
113                     int /* stream_id */,
114                     int /* render_view_id */,
115                     int /* session_id */,
116                     AudioInputHostMsg_CreateStream_Config)
117
118// Start buffering and play the audio stream specified by stream_id.
119IPC_MESSAGE_CONTROL1(AudioHostMsg_PlayStream,
120                     int /* stream_id */)
121
122// Start recording the audio input stream specified by stream_id.
123IPC_MESSAGE_CONTROL1(AudioInputHostMsg_RecordStream,
124                     int /* stream_id */)
125
126// Pause the audio stream specified by stream_id.
127IPC_MESSAGE_CONTROL1(AudioHostMsg_PauseStream,
128                     int /* stream_id */)
129
130// Close an audio stream specified by stream_id.
131IPC_MESSAGE_CONTROL1(AudioHostMsg_CloseStream,
132                     int /* stream_id */)
133
134// Close an audio input stream specified by stream_id.
135IPC_MESSAGE_CONTROL1(AudioInputHostMsg_CloseStream,
136                     int /* stream_id */)
137
138// Set audio volume of the stream specified by stream_id.
139// TODO(hclam): change this to vector if we have channel numbers other than 2.
140IPC_MESSAGE_CONTROL2(AudioHostMsg_SetVolume,
141                     int /* stream_id */,
142                     double /* volume */)
143
144// Set audio volume of the input stream specified by stream_id.
145IPC_MESSAGE_CONTROL2(AudioInputHostMsg_SetVolume,
146                     int /* stream_id */,
147                     double /* volume */)
148