1// Copyright 2018 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
5syntax = "proto2";
6
7option optimize_for = LITE_RUNTIME;
8
9package chromecast.media.mixer_service;
10
11enum ContentType {
12  CONTENT_TYPE_MEDIA = 0;
13  CONTENT_TYPE_ALARM = 1;
14  CONTENT_TYPE_COMMUNICATION = 2;
15  CONTENT_TYPE_OTHER = 3;
16}
17
18enum SampleFormat {
19  // Interleaved formats:
20  SAMPLE_FORMAT_INT16_I = 0;
21  SAMPLE_FORMAT_INT32_I = 1;
22  SAMPLE_FORMAT_FLOAT_I = 2;
23  // Planar formats:
24  SAMPLE_FORMAT_INT16_P = 3;
25  SAMPLE_FORMAT_INT32_P = 4;
26  SAMPLE_FORMAT_FLOAT_P = 5;
27}
28
29enum ChannelLayout {
30  CHANNEL_LAYOUT_NONE = 0;
31  CHANNEL_LAYOUT_MONO = 1;
32  CHANNEL_LAYOUT_STEREO = 2;
33  CHANNEL_LAYOUT_5_1 = 3;
34  // CHANNEL_LAYOUT_BITSTREAM not supported.
35  reserved 4;
36  CHANNEL_LAYOUT_DISCRETE = 5;
37}
38
39message OutputStreamParams {
40  enum StreamType {
41    STREAM_TYPE_DEFAULT = 0;
42    STREAM_TYPE_SFX = 1;
43  }
44  optional StreamType stream_type = 1;
45
46  optional ContentType content_type = 2;
47  optional SampleFormat sample_format = 3;
48
49  optional string device_id = 4;
50
51  optional int32 sample_rate = 5;
52  optional int32 num_channels = 6;
53  optional ChannelLayout channel_layout = 7;
54  optional sint32 channel_selection = 8 [default = -1];
55
56  optional int32 fill_size_frames = 9;
57  optional int32 start_threshold_frames = 10;
58  optional int32 max_buffered_frames = 11;
59
60  optional int32 fade_frames = 12;
61
62  // If |true|, playback will not start until a start timestamp has been
63  // provided via a SetStartTimestamp message.
64  optional bool use_start_timestamp = 13;
65
66  // If |true|, this stream will not be included in the mixer's stream counts.
67  optional bool ignore_for_stream_count = 14;
68
69  // If |true|, the receiver will not close the stream after a period of
70  // inactivity.
71  optional bool never_timeout_connection = 15;
72
73  // If present, volume limits apply to this stream based on the |focus_type|
74  // instead of the |content_type|.
75  optional ContentType focus_type = 16;
76}
77
78// Indicates that we want to start playing the sample with PTS |start_pts|
79// at audio clock timestamp |start_timestamp| in microseconds. May be sent
80// multiple times to restart playback at a new timestamp (ie for hard
81// corrections).
82message SetStartTimestamp {
83  optional int64 start_timestamp = 1;
84  optional int64 start_pts = 2;
85}
86
87// Informs the mixer how fast the PTS increases per frame. For example if the
88// playback rate is 2.0, then each frame increases the PTS by 2.0 / sample_rate
89// seconds.
90message SetPlaybackRate {
91  optional float playback_rate = 1;
92}
93
94// Changes the volume multiplier for an audio output stream.
95message StreamVolume {
96  optional float volume = 1;
97}
98
99// Immediately pauses/resumes playback for an audio output stream.
100message SetPaused {
101  optional bool paused = 1;
102}
103
104// Sets (or simulates setting) the audio clock rate. If the provided rate is
105// not supported, the rate will be clamped to the supported range.
106message SetAudioClockRate {
107  optional double rate = 1;
108}
109
110// Indicates that previously pushed audio data has been queued for playback,
111// and the next audio data that is pushed to the mixer will start playing at
112// |next_playback_timestamp|.
113message BufferPushResult {
114  optional fixed64 next_playback_timestamp = 1;
115}
116
117// Indicates that EOS for an audio output stream has been played out.
118message EosPlayedOut {}
119
120// Indicates that an audio output stream is ready for playback (ie, has enough
121// audio data to exceed the start threshold, and has output delay information).
122message ReadyForPlayback {
123  optional fixed64 delay_microseconds = 1;
124}
125
126// Indicates current stream config for a loopback / redirected audio stream.
127// Sent whenever the config changes; will be sent at least once before any audio
128// data is sent.
129message StreamConfig {
130  optional SampleFormat sample_format = 1;
131  optional int32 sample_rate = 2;
132  optional int32 num_channels = 3;
133  optional int32 data_size = 4;  // Expected size of audio data in bytes.
134}
135
136// Sent to indicate that the mixer should stream loopback audio data back over
137// this connection.
138message LoopbackDataRequest {}
139
140// Sent when a loopback audio stream is interrupted (ie, is discontinuous).
141message StreamInterruption {
142  enum InterruptionReason {
143    INTERRUPTED_UNKNOWN = 0;
144    INTERRUPTED_DISCONNECTED = 1;    // Disconnected from mixer.
145    INTERRUPTED_UNDERRUN = 2;        // Mixer output underrun.
146    INTERRUPTED_CONFIG_CHANGE = 3;   // Mixer output config changed.
147    INTERRUPTED_OUTPUT_STOPPED = 4;  // Mixer stopped playing out audio.
148  }
149
150  optional InterruptionReason reason = 1;
151}
152
153// Sent to indicate that the mixer should redirect specific audio output
154// stream data back over this connection.
155message RedirectionRequest {
156  optional int32 order = 1;
157  optional int32 num_channels = 2;
158  optional ChannelLayout channel_layout = 3;
159  optional bool apply_volume = 4;
160  optional int64 extra_delay_microseconds = 5;
161}
162
163// Sets the patterns to determine which audio output streams should be
164// redirected.
165message RedirectedStreamPatterns {
166  message Pattern {
167    optional ContentType content_type = 1;
168    optional string device_id_pattern = 2;
169  }
170  repeated Pattern patterns = 1;
171}
172
173// Sets volume multiplier for all streams of a given content type.
174message SetDeviceVolume {
175  optional ContentType content_type = 1;
176  optional float volume_multiplier = 2;
177}
178
179// Sets mute state all streams of a given content type.
180message SetDeviceMuted {
181  optional ContentType content_type = 1;
182  optional bool muted = 2;
183}
184
185// Sets the maximum effective volume multiplier for a given content type.
186message SetVolumeLimit {
187  optional ContentType content_type = 1;
188  optional float max_volume_multiplier = 2;
189}
190
191// Sends arbitrary config data to a specific postprocessor.
192message ConfigurePostprocessor {
193  optional string name = 1;
194  optional bytes config = 2;
195}
196
197// Instructs the mixer to reload postprocessors based on the config file.
198message ReloadPostprocessors {}
199
200// Asks the mixer to send / stop sending stream count updates.
201message RequestStreamCount {
202  optional bool subscribe = 1;
203}
204
205// Indicates how many output streams are currently being handled by the mixer.
206message StreamCount {
207  optional int32 primary = 1;
208  optional int32 sfx = 2;
209}
210
211// Sets the desired number of output channels used by the mixer.
212message NumOutputChannels {
213  optional int32 channels = 1;
214}
215
216// Indicates an error on an audio stream.
217message Error {
218  enum Type {
219    INVALID_STREAM_ERROR = 0;
220    XRUN_ERROR = 1;  // Underrun or overrun.
221  }
222  optional Type type = 1;
223  optional string message = 2;
224}
225
226message MixerUnderrun {
227  // Keep in sync with OutputStreamConnection::Delegate::MixerUnderrunType
228  enum Type {
229    // An underrun was detected on mixer input.
230    INPUT_UNDERRUN = 0;
231    // An underrun was detected on mixer output.
232    OUTPUT_UNDERRUN = 1;
233  };
234  optional Type type = 1;
235}
236
237message Generic {
238  optional OutputStreamParams output_stream_params = 1;
239  optional SetStartTimestamp set_start_timestamp = 2;
240  optional SetPlaybackRate set_playback_rate = 3;
241  optional StreamVolume set_stream_volume = 4;
242  optional SetPaused set_paused = 5;
243  optional BufferPushResult push_result = 6;
244  optional EosPlayedOut eos_played_out = 7;
245  optional ReadyForPlayback ready_for_playback = 8;
246  optional StreamConfig stream_config = 9;
247  optional LoopbackDataRequest loopback_request = 10;
248  optional RedirectionRequest redirection_request = 11;
249  optional RedirectedStreamPatterns redirected_stream_patterns = 12;
250  optional SetDeviceVolume set_device_volume = 13;
251  optional SetDeviceMuted set_device_muted = 14;
252  optional SetVolumeLimit set_volume_limit = 15;
253  optional ConfigurePostprocessor configure_postprocessor = 16;
254  optional ReloadPostprocessors reload_postprocessors = 17;
255  optional RequestStreamCount request_stream_count = 18;
256  optional StreamCount stream_count = 19;
257  optional Error error = 20;
258  optional NumOutputChannels set_num_output_channels = 21;
259  optional StreamInterruption stream_interruption = 22;
260  optional SetAudioClockRate set_audio_clock_rate = 23;
261  optional MixerUnderrun mixer_underrun = 24;
262}
263