TvStreamConfig.java revision 21aa3467cd14260418cc47334b656adf841a567c
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 @Override 92 public String toString() { 93 StringBuilder b = new StringBuilder(128); 94 b.append("TvStreamConfig {"); 95 b.append("mStreamId=").append(mStreamId).append(";"); 96 b.append("mType=").append(mType).append(";"); 97 b.append("mGeneration=").append(mGeneration).append("}"); 98 return b.toString(); 99 } 100 101 // Parcelable 102 @Override 103 public int describeContents() { 104 return 0; 105 } 106 107 @Override 108 public void writeToParcel(Parcel dest, int flags) { 109 dest.writeInt(mStreamId); 110 dest.writeInt(mType); 111 dest.writeInt(mMaxWidth); 112 dest.writeInt(mMaxHeight); 113 dest.writeInt(mGeneration); 114 } 115 116 /** 117 * A helper class for creating a TvStreamConfig object. 118 */ 119 public static final class Builder { 120 private Integer mStreamId; 121 private Integer mType; 122 private Integer mMaxWidth; 123 private Integer mMaxHeight; 124 private Integer mGeneration; 125 126 public Builder() { 127 } 128 129 public Builder streamId(int streamId) { 130 mStreamId = streamId; 131 return this; 132 } 133 134 public Builder type(int type) { 135 mType = type; 136 return this; 137 } 138 139 public Builder maxWidth(int maxWidth) { 140 mMaxWidth = maxWidth; 141 return this; 142 } 143 144 public Builder maxHeight(int maxHeight) { 145 mMaxHeight = maxHeight; 146 return this; 147 } 148 149 public Builder generation(int generation) { 150 mGeneration = generation; 151 return this; 152 } 153 154 public TvStreamConfig build() { 155 if (mStreamId == null || mType == null || mMaxWidth == null || mMaxHeight == null 156 || mGeneration == null) { 157 throw new UnsupportedOperationException(); 158 } 159 160 TvStreamConfig config = new TvStreamConfig(); 161 config.mStreamId = mStreamId; 162 config.mType = mType; 163 config.mMaxWidth = mMaxWidth; 164 config.mMaxHeight = mMaxHeight; 165 config.mGeneration = mGeneration; 166 return config; 167 } 168 } 169} 170