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.proto.AudioDeviceOuterClass.AudioDevice;
20 import com.android.media.audiotestharness.proto.AudioFormatOuterClass.AudioFormat;
21 
22 import java.io.File;
23 import java.io.IOException;
24 import java.io.OutputStream;
25 
26 /**
27  * Provides methods for interacting with an {@link AudioDevice} to start capturing, stop capturing,
28  * close the capture device, and get metadata corresponding to the capture device or capture format.
29  */
30 public interface AudioCapturer extends AutoCloseable {
31 
32     /**
33      * Starts capturing from the underlying audio device and publishes the resulting raw audio
34      * samples to the attached outputs.
35      */
open()36     void open() throws IOException;
37 
38     /**
39      * {@inheritDoc}
40      *
41      * <p>Stops capturing audio from the underlying audio device and frees the resources allocated
42      * for capture. After this method is called the Capturer is 'disposed' and cannot be reused,
43      * instead a new Capturer should be allocated by the {@link AudioSystemService}.
44      */
45     @Override
close()46     void close() throws IOException;
47 
48     /** Attaches a specified {@link File} as an output for this capturer. */
attachOutput(File file)49     void attachOutput(File file);
50 
51     /** Attaches a specified {@link OutputStream} as an output for this capturer. */
attachOutput(OutputStream outputStream)52     void attachOutput(OutputStream outputStream);
53 
54     /**
55      * Returns the {@link AudioFormat} corresponding to the raw audio samples produced by this
56      * capturer.
57      */
getAudioFormat()58     AudioFormat getAudioFormat();
59 
60     /** Returns the {@link AudioDevice} that this capturer captures from. */
getAudioDevice()61     AudioDevice getAudioDevice();
62 }
63