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.AudioFormat;
     19 import android.media.AudioRecord;
     20 import android.support.annotation.RestrictTo;
     21 import android.support.car.CarNotConnectedException;
     22 
     23 import static android.support.annotation.RestrictTo.Scope.GROUP_ID;
     24 
     25 /**
     26  * CarAudioRecordEmbedded allows apps to use microphone.
     27  * @hide
     28  */
     29 @RestrictTo(GROUP_ID)
     30 public class CarAudioRecordEmbedded extends CarAudioRecord {
     31 
     32     private final AudioFormat mFormat;
     33     private final int mBufferSize;
     34     private final AudioRecord mAudioRecord;
     35 
     36 
     37     CarAudioRecordEmbedded(AudioFormat format, int bufferSize) {
     38         mFormat = format;
     39         mBufferSize = bufferSize;
     40         mAudioRecord = new AudioRecord.Builder()
     41                 .setAudioFormat(mFormat)
     42                 .setBufferSizeInBytes(mBufferSize)
     43                 .build();
     44     }
     45 
     46     @Override
     47     public int getBufferSize() throws CarNotConnectedException {
     48         return mBufferSize;
     49     }
     50 
     51     @Override
     52     public void startRecording() throws CarNotConnectedException {
     53         mAudioRecord.startRecording();
     54     }
     55 
     56     @Override
     57     public void stop() {
     58         mAudioRecord.stop();
     59     }
     60 
     61     @Override
     62     public void release() {
     63         mAudioRecord.release();
     64     }
     65 
     66     @Override
     67     public int getRecordingState() throws CarNotConnectedException {
     68         return mAudioRecord.getRecordingState();
     69     }
     70 
     71     @Override
     72     public int getState() throws CarNotConnectedException {
     73         return mAudioRecord.getState();
     74     }
     75 
     76     @Override
     77     public int getAudioSessionId() throws CarNotConnectedException {
     78         return mAudioRecord.getAudioSessionId();
     79     }
     80 
     81     @Override
     82     public int read(byte[] audioData, int offsetInBytes, int sizeInBytes)
     83             throws CarNotConnectedException, IllegalStateException {
     84         return mAudioRecord.read(audioData, offsetInBytes, sizeInBytes);
     85     }
     86 }
     87