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