TvStreamConfig.java revision 230204967978b65731f1dd85278aaadb26322a7f
1/* 2 * Copyright (C) 2014 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 17package android.media.tv; 18 19import android.annotation.SystemApi; 20import android.os.Parcel; 21import android.os.Parcelable; 22import android.util.Log; 23 24/** 25 * @hide 26 */ 27@SystemApi 28public class TvStreamConfig implements Parcelable { 29 static final String TAG = TvStreamConfig.class.getSimpleName(); 30 31 public final static int STREAM_TYPE_INDEPENDENT_VIDEO_SOURCE = 1; 32 public final static int STREAM_TYPE_BUFFER_PRODUCER = 2; 33 34 private int mStreamId; 35 private int mType; 36 // TODO: Revisit if max widht/height really make sense. 37 private int mMaxWidth; 38 private int mMaxHeight; 39 /** 40 * Generations are incremented once framework receives STREAM_CONFIGURATION_CHANGED event from 41 * HAL module. Framework should throw away outdated configurations and get new configurations 42 * via tv_input_device::get_stream_configurations(). 43 */ 44 private int mGeneration; 45 46 public static final Parcelable.Creator<TvStreamConfig> CREATOR = 47 new Parcelable.Creator<TvStreamConfig>() { 48 @Override 49 public TvStreamConfig createFromParcel(Parcel source) { 50 try { 51 return new Builder(). 52 streamId(source.readInt()). 53 type(source.readInt()). 54 maxWidth(source.readInt()). 55 maxHeight(source.readInt()). 56 generation(source.readInt()).build(); 57 } catch (Exception e) { 58 Log.e(TAG, "Exception creating TvStreamConfig from parcel", e); 59 return null; 60 } 61 } 62 63 @Override 64 public TvStreamConfig[] newArray(int size) { 65 return new TvStreamConfig[size]; 66 } 67 }; 68 69 private TvStreamConfig() {} 70 71 public int getStreamId() { 72 return mStreamId; 73 } 74 75 public int getType() { 76 return mType; 77 } 78 79 public int getMaxWidth() { 80 return mMaxWidth; 81 } 82 83 public int getMaxHeight() { 84 return mMaxHeight; 85 } 86 87 public int getGeneration() { 88 return mGeneration; 89 } 90 91 // Parcelable 92 @Override 93 public int describeContents() { 94 return 0; 95 } 96 97 @Override 98 public void writeToParcel(Parcel dest, int flags) { 99 dest.writeInt(mStreamId); 100 dest.writeInt(mType); 101 dest.writeInt(mMaxWidth); 102 dest.writeInt(mMaxHeight); 103 dest.writeInt(mGeneration); 104 } 105 106 /** 107 * A helper class for creating a TvStreamConfig object. 108 */ 109 public static final class Builder { 110 private Integer mStreamId; 111 private Integer mType; 112 private Integer mMaxWidth; 113 private Integer mMaxHeight; 114 private Integer mGeneration; 115 116 public Builder() { 117 } 118 119 public Builder streamId(int streamId) { 120 mStreamId = streamId; 121 return this; 122 } 123 124 public Builder type(int type) { 125 mType = type; 126 return this; 127 } 128 129 public Builder maxWidth(int maxWidth) { 130 mMaxWidth = maxWidth; 131 return this; 132 } 133 134 public Builder maxHeight(int maxHeight) { 135 mMaxHeight = maxHeight; 136 return this; 137 } 138 139 public Builder generation(int generation) { 140 mGeneration = generation; 141 return this; 142 } 143 144 public TvStreamConfig build() { 145 if (mStreamId == null || mType == null || mMaxWidth == null || mMaxHeight == null 146 || mGeneration == null) { 147 throw new UnsupportedOperationException(); 148 } 149 150 TvStreamConfig config = new TvStreamConfig(); 151 config.mStreamId = mStreamId; 152 config.mType = mType; 153 config.mMaxWidth = mMaxWidth; 154 config.mMaxHeight = mMaxHeight; 155 config.mGeneration = mGeneration; 156 return config; 157 } 158 } 159} 160