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.
42IPC_MESSAGE_CONTROL4(
43   AudioMsg_NotifyStreamCreated,
44   int /* stream id */,
45   base::SharedMemoryHandle /* handle */,
46   base::SyncSocket::TransitDescriptor /* socket descriptor */,
47   uint32 /* length */)
48
49// Tell the renderer process that an audio input stream has been created.
50// The renderer process would be given a SyncSocket that it should read
51// from from then on. It is also given number of segments in shared memory.
52IPC_MESSAGE_CONTROL5(
53   AudioInputMsg_NotifyStreamCreated,
54   int /* stream id */,
55   base::SharedMemoryHandle /* handle */,
56   base::SyncSocket::TransitDescriptor /* socket descriptor */,
57   uint32 /* length */,
58   uint32 /* segment count */)
59
60// Notification message sent from AudioRendererHost to renderer after an output
61// device change has occurred.
62IPC_MESSAGE_CONTROL3(AudioMsg_NotifyDeviceChanged,
63                     int /* stream_id */,
64                     int /* new_buffer_size */,
65                     int /* new_sample_rate */)
66
67// Notification message sent from AudioRendererHost to renderer for state
68// update after the renderer has requested a Create/Start/Close.
69IPC_MESSAGE_CONTROL2(AudioMsg_NotifyStreamStateChanged,
70                     int /* stream id */,
71                     media::AudioOutputIPCDelegate::State /* new state */)
72
73// Notification message sent from browser to renderer for state update.
74IPC_MESSAGE_CONTROL2(AudioInputMsg_NotifyStreamStateChanged,
75                     int /* stream id */,
76                     media::AudioInputIPCDelegate::State /* new state */)
77
78IPC_MESSAGE_CONTROL2(AudioInputMsg_NotifyStreamVolume,
79                     int /* stream id */,
80                     double /* volume */)
81
82// Messages sent from the renderer to the browser.
83
84// Request that is sent to the browser for creating an audio output stream.
85// |render_view_id| is the routing ID for the render view producing the audio
86// data.
87IPC_MESSAGE_CONTROL5(AudioHostMsg_CreateStream,
88                     int /* stream_id */,
89                     int /* render_view_id */,
90                     int /* render_frame_id */,
91                     int /* session_id */,
92                     media::AudioParameters /* params */)
93
94// Request that is sent to the browser for creating an audio input stream.
95// |render_view_id| is the routing ID for the render view consuming the audio
96// data.
97IPC_MESSAGE_CONTROL4(AudioInputHostMsg_CreateStream,
98                     int /* stream_id */,
99                     int /* render_view_id */,
100                     int /* session_id */,
101                     AudioInputHostMsg_CreateStream_Config)
102
103// Start buffering and play the audio stream specified by stream_id.
104IPC_MESSAGE_CONTROL1(AudioHostMsg_PlayStream,
105                     int /* stream_id */)
106
107// Start recording the audio input stream specified by stream_id.
108IPC_MESSAGE_CONTROL1(AudioInputHostMsg_RecordStream,
109                     int /* stream_id */)
110
111// Pause the audio stream specified by stream_id.
112IPC_MESSAGE_CONTROL1(AudioHostMsg_PauseStream,
113                     int /* stream_id */)
114
115// Close an audio stream specified by stream_id.
116IPC_MESSAGE_CONTROL1(AudioHostMsg_CloseStream,
117                     int /* stream_id */)
118
119// Close an audio input stream specified by stream_id.
120IPC_MESSAGE_CONTROL1(AudioInputHostMsg_CloseStream,
121                     int /* stream_id */)
122
123// Set audio volume of the stream specified by stream_id.
124// TODO(hclam): change this to vector if we have channel numbers other than 2.
125IPC_MESSAGE_CONTROL2(AudioHostMsg_SetVolume,
126                     int /* stream_id */,
127                     double /* volume */)
128
129// Set audio volume of the input stream specified by stream_id.
130IPC_MESSAGE_CONTROL2(AudioInputHostMsg_SetVolume,
131                     int /* stream_id */,
132                     double /* volume */)
133