1/*
2 * Copyright (C) 2015 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 com.android.tv.common.recording;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21import java.util.Objects;
22
23/** Static representation of the recording capability of a TvInputService. */
24public final class RecordingCapability implements Parcelable {
25    /** The inputId this capability represents. */
26    public final String inputId;
27
28    /**
29     * The max number of concurrent sessions that require a tuner.
30     *
31     * <p>Both recording and playing live TV requires a Tuner.
32     */
33    public final int maxConcurrentTunedSessions;
34
35    /**
36     * The max number concurrent session that play a stream.
37     *
38     * <p>This is often limited by the number of decoders available. The count includes both playing
39     * live TV and playing a recorded stream.
40     */
41    public final int maxConcurrentPlayingSessions;
42
43    /**
44     * Max number of concurrent sessions all types.
45     *
46     * <p>This may be limited by bandwidth or CPU or other factors.
47     */
48    public final int maxConcurrentSessionsOfAllTypes;
49
50    /** True if a tuned session can support recording and playback from the same resource. */
51    public final boolean playbackWhileRecording;
52
53    private RecordingCapability(
54            String inputId,
55            int maxConcurrentTunedSessions,
56            int maxConcurrentPlayingSessions,
57            int maxConcurrentSessionsOfAllTypes,
58            boolean playbackWhileRecording) {
59        this.inputId = inputId;
60        this.maxConcurrentTunedSessions = maxConcurrentTunedSessions;
61        this.maxConcurrentPlayingSessions = maxConcurrentPlayingSessions;
62        this.maxConcurrentSessionsOfAllTypes = maxConcurrentSessionsOfAllTypes;
63        this.playbackWhileRecording = playbackWhileRecording;
64    }
65
66    protected RecordingCapability(Parcel in) {
67        inputId = in.readString();
68        maxConcurrentTunedSessions = in.readInt();
69        maxConcurrentPlayingSessions = in.readInt();
70        maxConcurrentSessionsOfAllTypes = in.readInt();
71        playbackWhileRecording = in.readByte() != 0;
72    }
73
74    @Override
75    public void writeToParcel(Parcel parcel, int flags) {
76        parcel.writeString(inputId);
77        parcel.writeInt(maxConcurrentTunedSessions);
78        parcel.writeInt(maxConcurrentPlayingSessions);
79        parcel.writeInt(maxConcurrentSessionsOfAllTypes);
80        parcel.writeByte((byte) (playbackWhileRecording ? 1 : 0));
81    }
82
83    @Override
84    public boolean equals(Object o) {
85        if (this == o) {
86            return true;
87        }
88        if (!(o instanceof RecordingCapability)) {
89            return false;
90        }
91        RecordingCapability that = (RecordingCapability) o;
92        return Objects.equals(maxConcurrentTunedSessions, that.maxConcurrentTunedSessions)
93                && Objects.equals(maxConcurrentPlayingSessions, that.maxConcurrentPlayingSessions)
94                && Objects.equals(
95                        maxConcurrentSessionsOfAllTypes, that.maxConcurrentSessionsOfAllTypes)
96                && Objects.equals(playbackWhileRecording, that.playbackWhileRecording)
97                && Objects.equals(inputId, that.inputId);
98    }
99
100    @Override
101    public int hashCode() {
102        return Objects.hash(inputId);
103    }
104
105    @Override
106    public String toString() {
107        return "RecordingCapability{"
108                + "inputId='"
109                + inputId
110                + '\''
111                + ", maxConcurrentTunedSessions="
112                + maxConcurrentTunedSessions
113                + ", maxConcurrentPlayingSessions="
114                + maxConcurrentPlayingSessions
115                + ", maxConcurrentSessionsOfAllTypes="
116                + maxConcurrentSessionsOfAllTypes
117                + ", playbackWhileRecording="
118                + playbackWhileRecording
119                + '}';
120    }
121
122    @Override
123    public int describeContents() {
124        return 0;
125    }
126
127    public static final Creator<RecordingCapability> CREATOR =
128            new Creator<RecordingCapability>() {
129                @Override
130                public RecordingCapability createFromParcel(Parcel in) {
131                    return new RecordingCapability(in);
132                }
133
134                @Override
135                public RecordingCapability[] newArray(int size) {
136                    return new RecordingCapability[size];
137                }
138            };
139
140    public static Builder builder() {
141        return new Builder();
142    }
143
144    public static final class Builder {
145        private String mInputId;
146        private int mMaxConcurrentTunedSessions;
147        private int mMaxConcurrentPlayingSessions;
148        private int mMaxConcurrentSessionsOfAllTypes;
149        private boolean mPlaybackWhileRecording;
150
151        public Builder setInputId(String inputId) {
152            mInputId = inputId;
153            return this;
154        }
155
156        public Builder setMaxConcurrentTunedSessions(int maxConcurrentTunedSessions) {
157            mMaxConcurrentTunedSessions = maxConcurrentTunedSessions;
158            return this;
159        }
160
161        public Builder setMaxConcurrentPlayingSessions(int maxConcurrentPlayingSessions) {
162            mMaxConcurrentPlayingSessions = maxConcurrentPlayingSessions;
163            return this;
164        }
165
166        public Builder setMaxConcurrentSessionsOfAllTypes(int maxConcurrentSessionsOfAllTypes) {
167            mMaxConcurrentSessionsOfAllTypes = maxConcurrentSessionsOfAllTypes;
168            return this;
169        }
170
171        public Builder setPlaybackWhileRecording(boolean playbackWhileRecording) {
172            mPlaybackWhileRecording = playbackWhileRecording;
173            return this;
174        }
175
176        public RecordingCapability build() {
177            return new RecordingCapability(
178                    mInputId,
179                    mMaxConcurrentTunedSessions,
180                    mMaxConcurrentPlayingSessions,
181                    mMaxConcurrentSessionsOfAllTypes,
182                    mPlaybackWhileRecording);
183        }
184    }
185}
186