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 android.bluetooth; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.SystemApi; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 25 import java.util.ArrayList; 26 import java.util.HashMap; 27 import java.util.List; 28 import java.util.Map; 29 30 /** 31 * A parcelable collection of buffer constraints by codec type. 32 * 33 * @hide 34 */ 35 @SystemApi 36 public final class BufferConstraints implements Parcelable { 37 public static final int BUFFER_CODEC_MAX_NUM = 32; 38 39 private static final String TAG = "BufferConstraints"; 40 41 private Map<Integer, BufferConstraint> mBufferConstraints; 42 private List<BufferConstraint> mBufferConstraintList; 43 BufferConstraints(@onNull List<BufferConstraint> bufferConstraintList)44 public BufferConstraints(@NonNull List<BufferConstraint> bufferConstraintList) { 45 46 mBufferConstraintList = new ArrayList<BufferConstraint>(bufferConstraintList); 47 mBufferConstraints = new HashMap<Integer, BufferConstraint>(); 48 for (int i = 0; i < BUFFER_CODEC_MAX_NUM; i++) { 49 mBufferConstraints.put(i, bufferConstraintList.get(i)); 50 } 51 } 52 BufferConstraints(Parcel in)53 BufferConstraints(Parcel in) { 54 mBufferConstraintList = new ArrayList<BufferConstraint>(); 55 mBufferConstraints = new HashMap<Integer, BufferConstraint>(); 56 in.readList(mBufferConstraintList, BufferConstraint.class.getClassLoader()); 57 for (int i = 0; i < mBufferConstraintList.size(); i++) { 58 mBufferConstraints.put(i, mBufferConstraintList.get(i)); 59 } 60 } 61 62 public static final @NonNull Parcelable.Creator<BufferConstraints> CREATOR = 63 new Parcelable.Creator<BufferConstraints>() { 64 public BufferConstraints createFromParcel(Parcel in) { 65 return new BufferConstraints(in); 66 } 67 68 public BufferConstraints[] newArray(int size) { 69 return new BufferConstraints[size]; 70 } 71 }; 72 73 @Override writeToParcel(@onNull Parcel out, int flags)74 public void writeToParcel(@NonNull Parcel out, int flags) { 75 out.writeList(mBufferConstraintList); 76 } 77 78 @Override describeContents()79 public int describeContents() { 80 return 0; 81 } 82 83 /** 84 * Get the buffer constraints by codec type. 85 * 86 * @param codec Audio codec 87 * @return buffer constraints by codec type. 88 * @hide 89 */ 90 @SystemApi forCodec(@luetoothCodecConfig.SourceCodecType int codec)91 public @Nullable BufferConstraint forCodec(@BluetoothCodecConfig.SourceCodecType int codec) { 92 return mBufferConstraints.get(codec); 93 } 94 } 95