1 /* 2 * Copyright (C) 2021 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.media.tv; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.net.Uri; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 25 /** 26 * A response for Timeline from broadcast signal. 27 */ 28 public final class TimelineResponse extends BroadcastInfoResponse implements Parcelable { 29 private static final @TvInputManager.BroadcastInfoType int RESPONSE_TYPE = 30 TvInputManager.BROADCAST_INFO_TYPE_TIMELINE; 31 32 public static final @NonNull Parcelable.Creator<TimelineResponse> CREATOR = 33 new Parcelable.Creator<TimelineResponse>() { 34 @Override 35 public TimelineResponse createFromParcel(Parcel source) { 36 source.readInt(); 37 return createFromParcelBody(source); 38 } 39 40 @Override 41 public TimelineResponse[] newArray(int size) { 42 return new TimelineResponse[size]; 43 } 44 }; 45 46 private final String mSelector; 47 private final int mUnitsPerTick; 48 private final int mUnitsPerSecond; 49 private final long mWallClock; 50 private final long mTicks; 51 createFromParcelBody(Parcel in)52 static TimelineResponse createFromParcelBody(Parcel in) { 53 return new TimelineResponse(in); 54 } 55 TimelineResponse(int requestId, int sequence, @ResponseResult int responseResult, @Nullable String selector, int unitsPerTick, int unitsPerSecond, long wallClock, long ticks)56 public TimelineResponse(int requestId, int sequence, 57 @ResponseResult int responseResult, @Nullable String selector, int unitsPerTick, 58 int unitsPerSecond, long wallClock, long ticks) { 59 super(RESPONSE_TYPE, requestId, sequence, responseResult); 60 mSelector = selector; 61 mUnitsPerTick = unitsPerTick; 62 mUnitsPerSecond = unitsPerSecond; 63 mWallClock = wallClock; 64 mTicks = ticks; 65 } 66 TimelineResponse(Parcel source)67 TimelineResponse(Parcel source) { 68 super(RESPONSE_TYPE, source); 69 mSelector = source.readString(); 70 mUnitsPerTick = source.readInt(); 71 mUnitsPerSecond = source.readInt(); 72 mWallClock = source.readLong(); 73 mTicks = source.readLong(); 74 } 75 76 /** 77 * Gets the Timeline Selector of the response. 78 * The Timeline Selector is a URI that specifies the source of a Timeline 79 * by indicating its type and information needed to locate the signalling 80 * that conveys Time Values on it. 81 */ 82 @Nullable getSelector()83 public Uri getSelector() { 84 return Uri.parse(mSelector); 85 } 86 87 /** 88 * Gets the UnitsPerTick of the response. 89 */ getUnitsPerTick()90 public int getUnitsPerTick() { 91 return mUnitsPerTick; 92 } 93 94 /** 95 * Gets the UnitsPerSecond of the response. 96 */ getUnitsPerSecond()97 public int getUnitsPerSecond() { 98 return mUnitsPerSecond; 99 } 100 101 /** 102 * Gets the System time (UTC) of the response. 103 */ getWallClock()104 public long getWallClock() { 105 return mWallClock; 106 } 107 108 /** 109 * Gets the Ticks of the response. 110 * A Time Value is a measure of a moment in time for a particular Timeline. 111 * Time Values are represented by an integer number of ticks (positive or negative). 112 */ getTicks()113 public long getTicks() { 114 return mTicks; 115 } 116 117 @Override describeContents()118 public int describeContents() { 119 return 0; 120 } 121 122 @Override writeToParcel(@onNull Parcel dest, int flags)123 public void writeToParcel(@NonNull Parcel dest, int flags) { 124 super.writeToParcel(dest, flags); 125 dest.writeString(mSelector); 126 dest.writeInt(mUnitsPerTick); 127 dest.writeInt(mUnitsPerSecond); 128 dest.writeLong(mWallClock); 129 dest.writeLong(mTicks); 130 } 131 } 132