1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.media.audiotestharness.server.core; 18 19 import com.android.media.audiotestharness.common.Defaults; 20 import com.android.media.audiotestharness.proto.AudioDeviceOuterClass.AudioDevice; 21 import com.android.media.audiotestharness.proto.AudioFormatOuterClass.AudioFormat; 22 23 import com.google.common.collect.ImmutableSet; 24 25 import java.io.IOException; 26 27 /** Provides an interface for the system to a native audio system devices. */ 28 public interface AudioSystemService { 29 30 /** 31 * Gets a {@link ImmutableSet} of {@link AudioDevice}s registered within the system. 32 * 33 * @throws IOException if unable to communicate with the underlying audio system. 34 */ getDevices()35 ImmutableSet<AudioDevice> getDevices() throws IOException; 36 37 /** 38 * Creates a new {@link AudioCapturer} for a provided {@link AudioDevice} to capture raw audio 39 * data in the specified {@link AudioFormat}. 40 * 41 * <p>For the provided {@link AudioDevice} the closes possible matching {@link AudioDevice} is 42 * used. For example, if an {@link AudioDevice} with just the capability field set to [CAPTURE] 43 * is provided then the first device found that can capture audio will be used. 44 * 45 * @throws IOException if unable to communicate with the underlying audio system or any errors 46 * occur while attempting to allocate resources for the {@link AudioCapturer}. 47 */ createCapturerFor(AudioDevice device, AudioFormat audioFormat)48 AudioCapturer createCapturerFor(AudioDevice device, AudioFormat audioFormat) throws IOException; 49 50 /** 51 * Creates a new {@link AudioCapturer} for the default {@link AudioDevice} and default {@link 52 * AudioFormat}. 53 * 54 * @throws IOException if unable to communicate with the underlying audio system or any errors 55 * occur while attempting to allocate resources for the {@link AudioCapturer}. 56 */ createDefaultCapturer()57 default AudioCapturer createDefaultCapturer() throws IOException { 58 return createCapturerFor(Defaults.AUDIO_DEVICE, Defaults.AUDIO_FORMAT); 59 } 60 61 /** 62 * Creates a new {@link AudioCapturer} for the provided {@link AudioDevice} with the default 63 * {@link AudioFormat}. 64 * 65 * @throws IOException if unable to communcate with the underlying audio system, any errors 66 * occur while attempting to allocate resources for the {@link AudioCapturer}, or the 67 * provided {@link AudioDevice} cannot be allocated properly. 68 */ createWithDefaultAudioFormat(AudioDevice device)69 default AudioCapturer createWithDefaultAudioFormat(AudioDevice device) throws IOException { 70 return createCapturerFor(device, Defaults.AUDIO_FORMAT); 71 } 72 } 73