1 /* 2 * Copyright (C) 2018 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 package com.android.tv.tuner.api; 17 18 import android.util.Log; 19 import com.android.tv.tuner.data.Channel; 20 21 22 /** Channel information gathered from a <em>scan</em> */ 23 public final class ScanChannel { 24 private static final String TAG = "ScanChannel"; 25 public final int type; 26 public final Channel.DeliverySystemType deliverySystemType; 27 public final int frequency; 28 public final String modulation; 29 public final String filename; 30 /** 31 * Radio frequency (channel) number specified at 32 * https://en.wikipedia.org/wiki/North_American_television_frequencies This can be {@code null} 33 * for cases like cable signal. 34 */ 35 public final Integer radioFrequencyNumber; 36 forTuner( String deliverySystemType, int frequency, String modulation, Integer radioFrequencyNumber)37 public static ScanChannel forTuner( 38 String deliverySystemType, int frequency, String modulation, 39 Integer radioFrequencyNumber) { 40 return new ScanChannel( 41 Channel.TunerType.TYPE_TUNER_VALUE, lookupDeliveryStringToInt(deliverySystemType), 42 frequency, modulation, null, radioFrequencyNumber); 43 } 44 forFile(int frequency, String filename)45 public static ScanChannel forFile(int frequency, String filename) { 46 return new ScanChannel(Channel.TunerType.TYPE_FILE_VALUE, 47 Channel.DeliverySystemType.DELIVERY_SYSTEM_UNDEFINED, frequency, "file:", 48 filename, null); 49 } 50 ScanChannel( int type, Channel.DeliverySystemType deliverySystemType, int frequency, String modulation, String filename, Integer radioFrequencyNumber)51 private ScanChannel( 52 int type, 53 Channel.DeliverySystemType deliverySystemType, 54 int frequency, 55 String modulation, 56 String filename, 57 Integer radioFrequencyNumber) { 58 this.type = type; 59 this.deliverySystemType = deliverySystemType; 60 this.frequency = frequency; 61 this.modulation = modulation; 62 this.filename = filename; 63 this.radioFrequencyNumber = radioFrequencyNumber; 64 } 65 lookupDeliveryStringToInt(String deliverySystemType)66 private static Channel.DeliverySystemType lookupDeliveryStringToInt(String deliverySystemType) { 67 Channel.DeliverySystemType ret; 68 switch (deliverySystemType) { 69 case "A": 70 ret = Channel.DeliverySystemType.DELIVERY_SYSTEM_ATSC; 71 break; 72 case "C": 73 ret = Channel.DeliverySystemType.DELIVERY_SYSTEM_DVBC; 74 break; 75 case "S": 76 ret = Channel.DeliverySystemType.DELIVERY_SYSTEM_DVBS; 77 break; 78 case "S2": 79 ret = Channel.DeliverySystemType.DELIVERY_SYSTEM_DVBS2; 80 break; 81 case "T": 82 ret = Channel.DeliverySystemType.DELIVERY_SYSTEM_DVBT; 83 break; 84 case "T2": 85 ret = Channel.DeliverySystemType.DELIVERY_SYSTEM_DVBT2; 86 break; 87 default: 88 Log.e(TAG, "Unknown delivery system type"); 89 ret = Channel.DeliverySystemType.DELIVERY_SYSTEM_UNDEFINED; 90 break; 91 } 92 return ret; 93 } 94 } 95