blob: 5cbdb6e268da642d5aad83c5fd309873a1bb05c4 [file] [log] [blame]
Tim Yaoe8c0d4a2019-11-27 14:47:35 -08001// Copyright 2019 Amlogic, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15syntax = "proto3";
16
17package audio_service;
18
19import "google/protobuf/timestamp.proto";
20import "google/protobuf/empty.proto";
21
22service AudioService {
23 rpc Device_common_close(google.protobuf.Empty) returns (StatusReturn) {}
24
25 ////////////////////////////
26 // Device API
27 ////////////////////////////
28
29 // check to see if the audio hardware interface has been initialized.
30 // returns 0 on success, -ENODEV on failure.
31 rpc Device_init_check(google.protobuf.Empty) returns (StatusReturn) {}
32
33 // set the audio volume of a voice call. Range is between 0.0 and 1.0
34 rpc Device_set_voice_volume(Volume) returns (StatusReturn) {}
35
36 // set the audio volume for all audio activities other than voice call.
37 // Range between 0.0 and 1.0. If any value other than 0 is returned,
38 // the software mixer will emulate this capability.
39 rpc Device_set_master_volume(Volume) returns (StatusReturn) {}
40
41 // Get the current master volume value for the HAL, if the HAL supports
42 // master volume control. AudioFlinger will query this value from the
43 // primary audio HAL when the service starts and use the value for setting
44 // the initial master volume across all HALs. HALs which do not support
45 // this method may leave it set to NULL.
46 rpc Device_get_master_volume(google.protobuf.Empty) returns (StatusReturn) {}
47
48 // set_mode is called when the audio mode changes. AUDIO_MODE_NORMAL mode
49 // is for standard audio playback, AUDIO_MODE_RINGTONE when a ringtone is
50 // playing, and AUDIO_MODE_IN_CALL when a call is in progress.
51 rpc Device_set_mode(Mode) returns (StatusReturn) {}
52
53 // mic mute
54 rpc Device_set_mic_mute(Mute) returns (StatusReturn) {}
55 rpc Device_get_mic_mute(google.protobuf.Empty) returns (StatusReturn) {}
56
57 // set/get global audio parameters
58 rpc Device_set_parameters(Kv_pairs) returns (StatusReturn) {}
59 rpc Device_get_parameters(Keys) returns (StatusReturn) {}
60
61 // Returns audio input buffer size according to parameters passed or
62 // 0 if one of the parameters is not supported.
63 // See also get_buffer_size which is for a particular stream.
64 rpc Device_get_input_buffer_size(AudioConfig) returns (StatusReturn) {}
65
66 // This method creates and opens the audio hardware output stream.
67 // The "address" parameter qualifies the "devices" audio device type if needed.
68 // The format format depends on the device type:
69 // - Bluetooth devices use the MAC address of the device in the form "00:11:22:AA:BB:CC"
70 // - USB devices use the ALSA card and device numbers in the form "card=X;device=Y"
71 // - Other devices may use a number or any other string.
72 rpc Device_open_output_stream(OpenOutputStream) returns (StatusReturn) {}
73 rpc Device_close_output_stream(Stream) returns (StatusReturn) {}
74
75 // This method creates and opens the audio hardware input stream
76 rpc Device_open_input_stream(OpenInputStream) returns (StatusReturn) {}
77 rpc Device_close_input_stream(Stream) returns (StatusReturn) {}
78
79 rpc Device_dump(google.protobuf.Empty) returns (StatusReturn) {}
80
81 // set the audio mute status for all audio activities. If any value other
82 // than 0 is returned, the software mixer will emulate this capability.
83 rpc Device_set_master_mute(Mute) returns (StatusReturn) {}
84 rpc Device_get_master_mute(google.protobuf.Empty) returns (StatusReturn) {}
85
86 // Routing control
87 // Creates an audio patch between several source and sink ports.
88 // The handle is allocated by the HAL and should be unique for this
89 // audio HAL module.
90 rpc Device_create_audio_patch(CreateAudioPatch) returns (StatusReturn) {}
91 rpc Device_release_audio_patch(Handle) returns (StatusReturn) {}
92
93 // Set audio port configuration
94 rpc Device_set_audio_port_config(AudioPortConfig) returns (StatusReturn) {}
95
96 ////////////////////////////
97 // Stream API
98 ////////////////////////////
99
100 // Return the sampling rate in Hz - eg. 44100.
101 rpc Stream_get_sample_rate(Stream) returns (StatusReturn) {}
102
103 // currently unused - use set_parameters with key
104 // AUDIO_PARAMETER_STREAM_SAMPLING_RATE
105 // int (*set_sample_rate)(struct audio_stream *stream, uint32_t rate);
106 // OBSOLETE
107
108 // Return size of input/output buffer in bytes for this stream - eg. 4800.
109 // It should be a multiple of the frame size. See also get_input_buffer_size.
110 rpc Stream_get_buffer_size(Stream) returns (StatusReturn) {}
111
112 // Return the channel mask -
113 // e.g. AUDIO_CHANNEL_OUT_STEREO or AUDIO_CHANNEL_IN_STEREO
114 rpc Stream_get_channels(Stream) returns (StatusReturn) {}
115
116 // Return the audio format - e.g. AUDIO_FORMAT_PCM_16_BIT
117 rpc Stream_get_format(Stream) returns (StatusReturn) {}
118
119 // currently unused - use set_parameters with key
120 // AUDIO_PARAMETER_STREAM_FORMAT
121 // int (*set_format)(struct audio_stream *stream, audio_format_t format);
122 // OBSOLETE
123
124 // Put the audio hardware input/output into standby mode.
125 // Driver should exit from standby mode at the next I/O operation.
126 // Returns 0 on success and <0 on failure.
127 rpc Stream_standby(Stream) returns (StatusReturn) {}
128
129 // Return the set of device(s) which this stream is connected to
130 rpc Stream_get_device(Stream) returns (StatusReturn) {}
131
132 // Currently unused - set_device() corresponds to set_parameters() with key
133 // AUDIO_PARAMETER_STREAM_ROUTING for both input and output.
134 // AUDIO_PARAMETER_STREAM_INPUT_SOURCE is an additional information used by
135 // input streams only.
136 // int (*set_device)(struct audio_stream *stream, audio_devices_t device);
137 // OBSOLETE
138
139 // set/get audio stream parameters. The function accepts a list of
140 // parameter key value pairs in the form: key1=value1;key2=value2;...
141 //
142 // Some keys are reserved for standard parameters (See AudioParameter class)
143 //
144 // If the implementation does not accept a parameter change while
145 // the output is active but the parameter is acceptable otherwise, it must
146 // return -ENOSYS.
147 //
148 // The audio flinger will put the stream in standby and then change the
149 // parameter value.
150 rpc Stream_set_parameters(StreamSetParameters) returns (StatusReturn) {}
151
152 rpc Stream_get_parameters(StreamGetParameters) returns (StatusReturn) {}
153
154 ////////////////////////////
155 // Stream Common MMAP API
156 ////////////////////////////
157 // Called by the framework to start a stream operating in mmap mode.
158 // create_mmap_buffer must be called before calling start()
159 //
160 // note Function only implemented by streams operating in mmap mode.
161 //
162 // param[in] stream the stream object.
163 // return 0 in case of success.
164 // -ENOSYS if called out of sequence or on non mmap stream
165 // TBD
166
167 // Called by the framework to stop a stream operating in mmap mode.
168 // Must be called after start()
169 //
170 // note Function only implemented by streams operating in mmap mode.
171 //
172 // param[in] stream the stream object.
173 // return 0 in case of success.
174 // -ENOSYS if called out of sequence or on non mmap stream
175 // TBD
176
177 // Called by the framework to retrieve information on the mmap buffer used for audio
178 // samples transfer.
179 //
180 // note Function only implemented by streams operating in mmap mode.
181 //
182 // param[in] stream the stream object.
183 // param[in] min_size_frames minimum buffer size requested. The actual buffer
184 // size returned in struct audio_mmap_buffer_info can be larger.
185 // param[out] info address at which the mmap buffer information should be returned.
186 //
187 // return 0 if the buffer was allocated.
188 // -ENODEV in case of initialization error
189 // -EINVAL if the requested buffer size is too large
190 // -ENOSYS if called out of sequence (e.g. buffer already allocated)
191 // int (*create_mmap_buffer)(const struct audio_stream_out *stream,
192 // int32_t min_size_frames,
193 // struct audio_mmap_buffer_info *info);
194 // TBD
195
196 // Called by the framework to read current read/write position in the mmap buffer
197 // with associated time stamp.
198 //
199 // note Function only implemented by streams operating in mmap mode.
200 //
201 // param[in] stream the stream object.
202 // param[out] position address at which the mmap read/write position should be returned.
203 //
204 // return 0 if the position is successfully returned.
205 // -ENODATA if the position cannot be retrieved
206 // -ENOSYS if called before create_mmap_buffer()
207 // int (*get_mmap_position)(const struct audio_stream_out *stream,
208 // struct audio_mmap_position *position);
209 // TBD
210
211 ////////////////////////////
212 // Stream Out API
213 ////////////////////////////
214
215 // Return the audio hardware driver estimated latency in milliseconds.
216 rpc StreamOut_get_latency(Stream) returns (StatusReturn) {}
217
218 // Use this method in situations where audio mixing is done in the
219 // hardware. This method serves as a direct interface with hardware,
220 // allowing you to directly set the volume as apposed to via the framework.
221 // This method might produce multiple PCM outputs or hardware accelerated
222 // codecs, such as MP3 or AAC.
223 rpc StreamOut_set_volume(StreamOutSetVolume) returns (StatusReturn) {}
224
225 // Write audio buffer to driver. Returns number of bytes written, or a
226 // negative status_t. If at least one frame was written successfully prior to the error,
227 // it is suggested that the driver return that successful (short) byte count
228 // and then return an error in the subsequent call.
229 //
230 // If set_callback() has previously been called to enable non-blocking mode
231 // the write() is not allowed to block. It must write only the number of
232 // bytes that currently fit in the driver/hardware buffer and then return
233 // this byte count. If this is less than the requested write size the
234 // callback function must be called when more space is available in the
235 // driver/hardware buffer.
236 rpc StreamOut_write(StreamReadWrite) returns (StatusReturn) {}
237
238 // return the number of audio frames written by the audio dsp to DAC since
239 // the output has exited standby
240 rpc StreamOut_get_render_position(Stream) returns (StatusReturn) {}
241
242 // get the local time at which the next write to the audio driver will be presented.
243 // The units are microseconds, where the epoch is decided by the local audio HAL.
244 rpc StreamOut_get_next_write_timestamp(Stream) returns (StatusReturn) {}
245
246 // set the callback function for notifying completion of non-blocking
247 // write and drain.
248 // Calling this function implies that all future write() and drain()
249 // must be non-blocking and use the callback to signal completion.
250 // int (*set_callback)(struct audio_stream_out *stream,
251 // stream_callback_t callback, void *cookie);
252 // TBD
253
254 // Notifies to the audio driver to stop playback however the queued buffers are
255 // retained by the hardware. Useful for implementing pause/resume. Empty implementation
256 // if not supported however should be implemented for hardware with non-trivial
257 // latency. In the pause state audio hardware could still be using power. User may
258 // consider calling suspend after a timeout.
259 //
260 // Implementation of this function is mandatory for offloaded playback.
261 rpc StreamOut_pause(Stream) returns (StatusReturn) {}
262
263 // Notifies to the audio driver to resume playback following a pause.
264 // Returns error if called without matching pause.
265 //
266 // Implementation of this function is mandatory for offloaded playback.
267 rpc StreamOut_resume(Stream) returns (StatusReturn) {}
268
269 // Requests notification when data buffered by the driver/hardware has
270 // been played. If set_callback() has previously been called to enable
271 // non-blocking mode, the drain() must not block, instead it should return
272 // quickly and completion of the drain is notified through the callback.
273 // If set_callback() has not been called, the drain() must block until
274 // completion.
275 // If type==AUDIO_DRAIN_ALL, the drain completes when all previously written
276 // data has been played.
277 // If type==AUDIO_DRAIN_EARLY_NOTIFY, the drain completes shortly before all
278 // data for the current track has played to allow time for the framework
279 // to perform a gapless track switch.
280 //
281 // Drain must return immediately on stop() and flush() call
282 //
283 // Implementation of this function is mandatory for offloaded playback.
284 // int (*drain)(struct audio_stream_out* stream, audio_drain_type_t type );
285 // TBD
286
287 // Notifies to the audio driver to flush the queued data. Stream must already
288 // be paused before calling flush().
289 //
290 // Implementation of this function is mandatory for offloaded playback.
291 rpc StreamOut_flush(Stream) returns (StatusReturn) {}
292
293 // Return a recent count of the number of audio frames presented to an external observer.
294 // This excludes frames which have been written but are still in the pipeline.
295 // The count is not reset to zero when output enters standby.
296 // Also returns the value of CLOCK_MONOTONIC as of this presentation count.
297 // The returned count is expected to be 'recent',
298 // but does not need to be the most recent possible value.
299 // However, the associated time should correspond to whatever count is returned.
300 // Example: assume that N+M frames have been presented, where M is a 'small' number.
301 // Then it is permissible to return N instead of N+M,
302 // and the timestamp should correspond to N rather than N+M.
303 // The terms 'recent' and 'small' are not defined.
304 // They reflect the quality of the implementation.
305 //
306 // 3.0 and higher only.
307 rpc StreamOut_get_presentation_position(Stream) returns (GetFrameTimestampReturn) {}
308
309 // Called when the metadata of the stream's source has been changed.
310 // @param source_metadata Description of the audio that is played by the clients.
311 //
312 // void (*update_source_metadata)(struct audio_stream_out *stream,
313 // const struct source_metadata* source_metadata);
314 // TBD
315
316 ////////////////////////////
317 // Stream In API
318 ////////////////////////////
319 // set the input gain for the audio driver. This method is for
320 // for future use */
321 // int (*set_gain)(struct audio_stream_in *stream, float gain);
322 rpc StreamIn_set_gain(StreamGain) returns (StatusReturn) {}
323
324 // Read audio buffer in from audio driver. Returns number of bytes read, or a
325 // negative status_t. If at least one frame was read prior to the error,
326 // read should return that byte count and then return an error in the subsequent call.
327 rpc StreamIn_read(StreamReadWrite) returns (StatusReturn) {}
328
329 // Return the amount of input frames lost in the audio driver since the
330 // last call of this function.
331 // Audio driver is expected to reset the value to 0 and restart counting
332 // upon returning the current value by this function call.
333 // Such loss typically occurs when the user space process is blocked
334 // longer than the capacity of audio driver buffers.
335 //
336 // Unit: the number of input audio frames
337 // uint32_t (*get_input_frames_lost)(struct audio_stream_in *stream);
338 rpc StreamIn_get_input_frames_lost(Stream) returns (StatusReturn) {}
339
340 // Return a recent count of the number of audio frames received and
341 // the clock time associated with that frame count.
342 //
343 // frames is the total frame count received. This should be as early in
344 // the capture pipeline as possible. In general,
345 // frames should be non-negative and should not go "backwards".
346 //
347 // time is the clock MONOTONIC time when frames was measured. In general,
348 // time should be a positive quantity and should not go "backwards".
349 //
350 // The status returned is 0 on success, -ENOSYS if the device is not
351 // ready/available, or -EINVAL if the arguments are null or otherwise invalid.
352 rpc StreamIn_get_capture_position(Stream) returns (GetCapturePositionReturn) {}
353
354 // Called by the framework to read active microphones
355 //
356 // param[in] stream the stream object.
357 // param[out] mic_array Pointer to first element on array with microphone info
358 // param[out] mic_count When called, this holds the value of the max number of elements
359 // allowed in the mic_array. The actual number of elements written
360 // is returned here.
361 // if mic_count is passed as zero, mic_array will not be populated,
362 // and mic_count will return the actual number of active microphones.
363 //
364 // return 0 if the microphone array is successfully filled.
365 // -ENOSYS if there is an error filling the data
366 // int (*get_active_microphones)(const struct audio_stream_in *stream,
367 // struct audio_microphone_characteristic_t *mic_array,
368 // size_t *mic_count);
369 // TBD
370
371 // Called when the metadata of the stream's sink has been changed.
372 // @param sink_metadata Description of the audio that is recorded by the clients.
373 // void (*update_sink_metadata)(struct audio_stream_in *stream,
374 // const struct sink_metadata* sink_metadata);
375 // TBD
376
377 ////////////////////////////
378 // Misc API
379 ////////////////////////////
380 rpc Service_ping(google.protobuf.Empty) returns (StatusReturn) {}
381}
382
383message StatusReturn {
384 int32 ret = 1;
385 oneof status_oneof {
386 bool status_bool = 2;
387 int32 status_32 = 3;
388 int64 status_64 = 4;
389 float status_float = 5;
390 string status_string = 6;
391 }
392}
393
394message Volume {
395 float vol = 1;
396}
397
398message Mode {
399 int32 mode = 1;
400}
401
402message Mute {
403 bool mute = 1;
404}
405
406message Kv_pairs {
407 string params = 1;
408}
409
410message Keys {
411 string keys = 1;
412}
413
414message Handle {
415 int32 handle = 1;
416}
417
418message OpenOutputStream {
419 string name = 1;
420 uint32 size = 2;
421 uint32 handle = 3;
422 uint32 devices = 4;
423 uint32 flags = 5;
424 AudioConfig config = 6;
425 string address = 7;
426}
427
428message AudioConfig {
429 uint32 sample_rate = 1;
430 uint32 channel_mask = 2;
431 uint32 format = 3;
432 uint32 frame_count = 4;
433}
434
435message Stream {
436 string name = 1;
437}
438
439message OpenInputStream {
440 string name = 1;
441 uint32 size = 2;
442 int32 handle = 3;
443 uint32 devices = 4;
444 AudioConfig config = 5;
445 uint32 flags = 6;
446 string address = 7;
447 uint32 source = 8;
448}
449
450message CreateAudioPatch {
451 repeated AudioPortConfig sources = 1;
452 repeated AudioPortConfig sinks = 2;
453}
454
455message AudioPortConfig {
456 uint32 id = 1; // port unique ID
457 uint32 role = 2; // sink or source
458 uint32 type = 3; // device, mix ...
459 uint32 config_mask = 4; // e.g AUDIO_PORT_CONFIG_ALL
460 uint32 sample_rate = 5; // sampling rate in Hz
461 uint32 channel_mask = 6; // channel mask if applicable
462 uint32 format = 7; // format if applicable
463 AudioGainConfig gain = 8; // gain to apply if applicable
464 uint32 flags = 9; // framework only: HW_AV_SYNC, DIRECT, ...
465 oneof ext {
466 AudioPortConfigDeviceExt device = 10; // device specific info
467 AudioPortConfigMixExt mix = 11; // mix specific info
468 AudioPortConfigSessionExt session = 12; // session specific info
469 }
470}
471
472message AudioGainConfig {
473 int32 index = 1; // index of the corresponding audio_gain in the audio_port gains[] table
474 uint32 mode = 2; // mode requested for this command
475 uint32 channel_mask = 3; // channels which gain value follows. N/A in joint mode
476 repeated int32 values = 4; // values[sizeof(audio_channel_mask_t) * 8]; gain values in millibels
477 // for each channel ordered from LSb to MSb in
478 // channel mask. The number of values is 1 in joint
479 // mode or popcount(channel_mask)
480 uint32 ramp_duration_ms = 5; // ramp duration in ms
481}
482
483message AudioPortConfigDeviceExt {
484 uint32 hw_module = 1; // module the device is attached to
485 uint32 type = 2; // device type (e.g AUDIO_DEVICE_OUT_SPEAKER)
486 string address = 3; // address[AUDIO_DEVICE_MAX_ADDRESS_LEN], device address. "" if N/A
487}
488
489message AudioPortConfigMixExt {
490 uint32 hw_module = 1; // module the device is attached to
491 int32 handle = 2; // I/O handle of the input/output stream
492 uint32 stream_source = 3; // audio_stream_type_t or audio_source_t
493}
494
495message AudioPortConfigSessionExt {
496 int32 session = 1; // audio session
497}
498
499message StreamSetParameters {
500 string name = 1; // Stream
501 string kv_pairs = 2; // Parameters
502}
503
504message StreamGetParameters {
505 string name = 1; // Stream
506 string keys = 2; // keys
507}
508
509message StreamAudioEffect {
510 string name = 1; // Stream
511 uint32 effect = 2; // effect
512}
513
514message StreamOutSetVolume {
515 string name = 1; // Stream
516 float left = 2; // left channel volume
517 float right = 3; // right channel volume
518}
519
520message StreamReadWrite {
521 string name = 1; // Stream
522 uint32 size = 2; // size
523}
524
525message GetFrameTimestampReturn {
526 int32 ret = 1;
527 uint64 frames = 2;
528 google.protobuf.Timestamp timestamp = 3;
529}
530
531message StreamGain {
532 string name = 1;
533 float gain = 2;
534}
535
536message GetCapturePositionReturn {
537 int32 ret = 1;
538 uint64 frames = 2;
539 uint64 time = 3;
540}