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 private int mMaxWidth; 37 private int mMaxHeight; 38 /** 39 * Generations are incremented once framework receives STREAM_CONFIGURATION_CHANGED event from 40 * HAL module. Framework should throw away outdated configurations and get new configurations 41 * via tv_input_device::get_stream_configurations(). 42 */ 43 private int mGeneration; 44 45 public static final Parcelable.Creator<TvStreamConfig> CREATOR = 46 new Parcelable.Creator<TvStreamConfig>() { 47 @Override 48 public TvStreamConfig createFromParcel(Parcel source) { 49 try { 50 return new Builder(). 51 streamId(source.readInt()). 52 type(source.readInt()). 53 maxWidth(source.readInt()). 54 maxHeight(source.readInt()). 55 generation(source.readInt()).build(); 56 } catch (Exception e) { 57 Log.e(TAG, "Exception creating TvStreamConfig from parcel", e); 58 return null; 59 } 60 } 61 62 @Override 63 public TvStreamConfig[] newArray(int size) { 64 return new TvStreamConfig[size]; 65 } 66 }; 67 68 private TvStreamConfig() {} 69 70 public int getStreamId() { 71 return mStreamId; 72 } 73 74 public int getType() { 75 return mType; 76 } 77 78 public int getMaxWidth() { 79 return mMaxWidth; 80 } 81 82 public int getMaxHeight() { 83 return mMaxHeight; 84 } 85 86 public int getGeneration() { 87 return mGeneration; 88 } 89 90 @Override 91 public String toString() { 92 return "TvStreamConfig {mStreamId=" + mStreamId + ";" + "mType=" + mType + ";mGeneration=" 93 + mGeneration + "}"; 94 } 95 96 // Parcelable 97 @Override 98 public int describeContents() { 99 return 0; 100 } 101 102 @Override 103 public void writeToParcel(Parcel dest, int flags) { 104 dest.writeInt(mStreamId); 105 dest.writeInt(mType); 106 dest.writeInt(mMaxWidth); 107 dest.writeInt(mMaxHeight); 108 dest.writeInt(mGeneration); 109 } 110 111 /** 112 * A helper class for creating a TvStreamConfig object. 113 */ 114 public static final class Builder { 115 private Integer mStreamId; 116 private Integer mType; 117 private Integer mMaxWidth; 118 private Integer mMaxHeight; 119 private Integer mGeneration; 120 121 public Builder() { 122 } 123 124 public Builder streamId(int streamId) { 125 mStreamId = streamId; 126 return this; 127 } 128 129 public Builder type(int type) { 130 mType = type; 131 return this; 132 } 133 134 public Builder maxWidth(int maxWidth) { 135 mMaxWidth = maxWidth; 136 return this; 137 } 138 139 public Builder maxHeight(int maxHeight) { 140 mMaxHeight = maxHeight; 141 return this; 142 } 143 144 public Builder generation(int generation) { 145 mGeneration = generation; 146 return this; 147 } 148 149 public TvStreamConfig build() { 150 if (mStreamId == null || mType == null || mMaxWidth == null || mMaxHeight == null 151 || mGeneration == null) { 152 throw new UnsupportedOperationException(); 153 } 154 155 TvStreamConfig config = new TvStreamConfig(); 156 config.mStreamId = mStreamId; 157 config.mType = mType; 158 config.mMaxWidth = mMaxWidth; 159 config.mMaxHeight = mMaxHeight; 160 config.mGeneration = mGeneration; 161 return config; 162 } 163 } 164 165 @Override 166 public boolean equals(Object obj) { 167 if (obj == null) return false; 168 if (!(obj instanceof TvStreamConfig)) return false; 169 170 TvStreamConfig config = (TvStreamConfig) obj; 171 return config.mGeneration == mGeneration 172 && config.mStreamId == mStreamId 173 && config.mType == mType 174 && config.mMaxWidth == mMaxWidth 175 && config.mMaxHeight == mMaxHeight; 176 } 177} 178