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