Home | History | Annotate | Download | only in media
      1 /*
      2  * Copyright (C) 2016 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 package android.support.car.media;
     17 
     18 import android.media.AudioRecord;
     19 import android.support.car.CarNotConnectedException;
     20 
     21 /**
     22  * Enables applications to use the microphone.
     23  */
     24 public abstract class CarAudioRecord {
     25     /**
     26      * Get the buffer size specified in {@link CarAudioManager#createCarAudioRecord(int)}.
     27      * @return Buffer size in bytes.
     28      */
     29     public abstract int getBufferSize() throws CarNotConnectedException;
     30 
     31     /**
     32      * Start audio recording.
     33      */
     34     public abstract void startRecording() throws CarNotConnectedException;
     35 
     36     /**
     37      * Stop audio recording. Calling stop multiple times is a safe operation.
     38      */
     39     public abstract void stop();
     40 
     41     /**
     42      * Release native resource allocated for this instance. {@link CarAudioRecord} can no longer
     43      * be used after release is called.
     44      */
     45     public abstract void release();
     46 
     47     /** See {@link AudioRecord#getRecordingState() }. */
     48     public abstract int getRecordingState() throws CarNotConnectedException;
     49 
     50     /** See {@link AudioRecord#getState() }. */
     51     public abstract int getState() throws CarNotConnectedException;
     52 
     53     /** See {@link AudioRecord#getAudioSessionId() }. */
     54     public abstract int getAudioSessionId() throws CarNotConnectedException;
     55 
     56     /**
     57      * Read recorded audio. Be sure to start audio recording with {@link #startRecording()}
     58      * before this.
     59      * @param audioData
     60      * @param offsetInBytes
     61      * @param sizeInBytes
     62      * @return Number of bytes read. Returns {@link android.media.AudioRecord#ERROR} on error.
     63      * @throws IllegalStateException if audio recording was not started.
     64      */
     65     public abstract int read(byte[] audioData, int offsetInBytes, int sizeInBytes)
     66             throws IllegalStateException, CarNotConnectedException;
     67 }
     68