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.client.core; 18 19 import com.android.media.audiotestharness.common.Defaults; 20 import com.android.media.audiotestharness.proto.AudioFormatOuterClass.AudioFormat; 21 22 import java.io.IOException; 23 import java.io.InputStream; 24 25 /** 26 * {@link InputStream} that provides access to raw audio samples returned by a Audio Capture Session 27 * while also providing access to helper methods to interact with the session. 28 */ 29 public abstract class AudioCaptureStream extends InputStream { 30 31 /** 32 * Read method that reads a number of audio samples, up to the max into the provided array 33 * starting at offset. These samples are expected to be signed 16-bit values and thus are 34 * provided as an array of short values. 35 * 36 * <p>This method blocks until at least one complete sample is read, and ensures that no 37 * incomplete samples are read. 38 * 39 * @param samples the array to read into. 40 * @param offset the offset to use when writing into samples. 41 * @param len the maximum number of samples to read. 42 * @return the number of samples read into the provided array. 43 */ read(short[] samples, int offset, int len)44 public abstract int read(short[] samples, int offset, int len) throws IOException; 45 46 /** 47 * Returns the {@link AudioFormat} corresponding to this {@link AudioCaptureStream}, thus the 48 * raw data exposed by this stream will be raw PCM samples matching this format. 49 */ getAudioFormat()50 public AudioFormat getAudioFormat() { 51 return Defaults.AUDIO_FORMAT; 52 } 53 } 54