audio_service.mojom 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // Copyright 2022 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. module crosapi.mojom;
  5. // This interface is created to implement chrome.audio extension API in Lacros.
  6. // Audio api in Lacros is ultimately connected to ash::CrasAudioHandler.
  7. // The structs in this file are mirroring types from
  8. // https://developer.chrome.com/docs/extensions/reference/audio/#type
  9. [Stable, Extensible]
  10. enum StreamType {
  11. [Default] kNone = 0,
  12. kInput = 1,
  13. kOutput = 2,
  14. };
  15. [Stable, Extensible]
  16. enum DeviceType {
  17. [Default] kNone = 0,
  18. kHeadphone = 1,
  19. kMic = 2,
  20. kUsb = 3,
  21. kBluetooth = 4,
  22. kHdmi = 5,
  23. kInternalSpeaker = 6,
  24. kInternalMic = 7,
  25. kFrontMic = 8,
  26. kRearMic = 9,
  27. kKeyboardMic = 10,
  28. kHotword = 11,
  29. kLineout = 12,
  30. kPostMixLoopback = 13,
  31. kPostDspLoopback = 14,
  32. kAlsaLoopback = 15,
  33. kOther = 16,
  34. };
  35. [Stable]
  36. struct AudioDeviceInfo {
  37. // Device name.
  38. string deviceName@0;
  39. // Type of the device.
  40. DeviceType deviceType@1;
  41. // The user-friendly name (e.g. "USB Microphone").
  42. string displayName@2;
  43. // The unique identifier of the audio device.
  44. string id@3;
  45. // True if this device is currently active.
  46. bool isActive@4;
  47. // The sound level of the device, volume for output, gain for input.
  48. int32 level@5;
  49. // The stable/persisted device id string when available.
  50. string? stableDeviceId@6;
  51. // Stream type associated with this device.
  52. StreamType streamType@7;
  53. };
  54. [Stable]
  55. struct DeviceFilter {
  56. [Stable, Extensible]
  57. enum ActiveState {
  58. [Default] kUnset = 0,
  59. kInactive = 1,
  60. kActive = 2,
  61. };
  62. // If set, only audio devices whose active state matches this value will
  63. // satisfy the filter.
  64. ActiveState includedActiveState@0;
  65. // If set, only audio devices whose stream type is included in this list will
  66. // satisfy the filter.
  67. array<StreamType>? includedStreamTypes@1;
  68. };
  69. [Stable]
  70. struct DeviceIdLists {
  71. // List of input devices specified by their ID.
  72. array<string> inputs@0;
  73. // List of output devices specified by their ID.
  74. array<string> outputs@1;
  75. };
  76. [Stable]
  77. struct AudioDeviceProperties {
  78. // The audio device's desired sound level.
  79. // If used with audio input device, represents audio device gain.
  80. // If used with audio output device, represents audio device volume.
  81. int32 level@0;
  82. };
  83. // Interface for audio change observer. Implemented by lacros-chrome. Used by
  84. // ash-chrome to send audio change events.
  85. [Stable, Uuid="aa4fcb30-c406-4133-be23-db3fcc6ca113"]
  86. interface AudioChangeObserver {
  87. // Fired when audio devices change, either new devices being added,
  88. // or existing devices being removed.
  89. // |devices| contains the full list of the devices after update
  90. OnDeviceListChanged@0(array<AudioDeviceInfo> devices);
  91. // Fired when sound level changes for an active audio device.
  92. OnLevelChanged@1(string id, int32 level);
  93. // Fired when the mute state of the audio input or output changes.
  94. OnMuteChanged@2(bool is_input, bool is_muted);
  95. };
  96. // This API provides Lacros with access to audio devices.
  97. // This is used to support chrome.audio extension API in lacros-chrome.
  98. // Implemented in ash-chrome.
  99. //
  100. // Next MinVersion: 1
  101. // Next ID: 6
  102. [Stable, Uuid="495da3b2-8c95-43d3-a508-79474c80e738"]
  103. interface AudioService {
  104. // Gets a list of audio devices filtered based on filter.
  105. // Returns empty optional if ash call failed
  106. // (e.g. CrasAudioHandler not available).
  107. GetDevices@0(DeviceFilter filter) => (array<AudioDeviceInfo>? devices);
  108. // Gets the system-wide mute state for the specified stream type.
  109. // success - method call result.
  110. // True if ash call was successful.
  111. // False if ash call failed (e.g. CrasAudioHandler not available).
  112. // is_muted - mute state for the specified stream type.
  113. GetMute@1(StreamType stream_type) => (bool success, bool is_muted);
  114. // Sets lists of active input and/or output devices.
  115. SetActiveDeviceLists@2(DeviceIdLists ids) => (bool success);
  116. // Sets mute state for a stream type.The mute state will apply to all audio
  117. // devices with the specified audio stream type.
  118. SetMute@3(StreamType stream_type, bool is_muted) => (bool success);
  119. // Sets the properties for the input or output device, specified by id.
  120. SetProperties@4(string id, AudioDeviceProperties properties)
  121. => (bool success);
  122. // Adds an observer for audio change. Multiple observers may be registered.
  123. AddAudioChangeObserver@5(pending_remote<AudioChangeObserver> observer);
  124. };