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.support.annotation.IntDef; 19 import android.support.annotation.StringDef; 20 import java.lang.annotation.Retention; 21 import java.lang.annotation.RetentionPolicy; 22 23 /** A interface a hardware tuner device. */ 24 public interface Tuner extends AutoCloseable { 25 26 int FILTER_TYPE_OTHER = 0; 27 int FILTER_TYPE_AUDIO = 1; 28 int FILTER_TYPE_VIDEO = 2; 29 int FILTER_TYPE_PCR = 3; 30 String MODULATION_8VSB = "8VSB"; 31 String MODULATION_QAM16 = "QAM16"; 32 String MODULATION_QAM64 = "QAM64"; 33 String MODULATION_QAM256 = "QAM256"; 34 int DELIVERY_SYSTEM_UNDEFINED = 0; 35 int DELIVERY_SYSTEM_ATSC = 1; 36 int DELIVERY_SYSTEM_DVBC = 2; 37 int DELIVERY_SYSTEM_DVBS = 3; 38 int DELIVERY_SYSTEM_DVBS2 = 4; 39 int DELIVERY_SYSTEM_DVBT = 5; 40 int DELIVERY_SYSTEM_DVBT2 = 6; 41 int TUNER_TYPE_BUILT_IN = 1; 42 int TUNER_TYPE_USB = 2; 43 int TUNER_TYPE_NETWORK = 3; 44 int BUILT_IN_TUNER_TYPE_LINUX_DVB = 1; 45 int BUILT_IN_TUNER_TYPE_ARCHER = 100; 46 47 /** Check a delivery system is for DVB or not. */ isDvbDeliverySystem(@eliverySystemType int deliverySystemType)48 static boolean isDvbDeliverySystem(@DeliverySystemType int deliverySystemType) { 49 return deliverySystemType == DELIVERY_SYSTEM_DVBC 50 || deliverySystemType == DELIVERY_SYSTEM_DVBS 51 || deliverySystemType == DELIVERY_SYSTEM_DVBS2 52 || deliverySystemType == DELIVERY_SYSTEM_DVBT 53 || deliverySystemType == DELIVERY_SYSTEM_DVBT2; 54 } 55 isReusable()56 boolean isReusable(); 57 58 /** 59 * Acquires the first available tuner device. If there is a tuner device that is available, the 60 * tuner device will be locked to the current instance. 61 * 62 * @return {@code true} if the operation was successful, {@code false} otherwise 63 */ openFirstAvailable()64 boolean openFirstAvailable(); 65 isDeviceOpen()66 boolean isDeviceOpen(); 67 getDeviceId()68 long getDeviceId(); 69 tune(int frequency, @ModulationType String modulation, String channelNumber)70 boolean tune(int frequency, @ModulationType String modulation, String channelNumber); 71 tune(@eliverySystemType int deliverySystemType, int frequency, @ModulationType String modulation, String channelNumber)72 default boolean tune(@DeliverySystemType int deliverySystemType, int frequency, 73 @ModulationType String modulation, String channelNumber) { 74 return tune(frequency, modulation, channelNumber); 75 } 76 addPidFilter(int pid, @FilterType int filterType)77 boolean addPidFilter(int pid, @FilterType int filterType); 78 stopTune()79 void stopTune(); 80 setHasPendingTune(boolean hasPendingTune)81 void setHasPendingTune(boolean hasPendingTune); 82 getDeliverySystemType()83 int getDeliverySystemType(); getDeliverySystemTypes()84 default int[] getDeliverySystemTypes() { 85 int[] deliverySystemTypes = {DELIVERY_SYSTEM_UNDEFINED}; 86 return deliverySystemTypes; 87 }; 88 readTsStream(byte[] javaBuffer, int javaBufferSize)89 int readTsStream(byte[] javaBuffer, int javaBufferSize); 90 getSignalStrength()91 int getSignalStrength(); 92 93 /** Filter type */ 94 @IntDef({FILTER_TYPE_OTHER, FILTER_TYPE_AUDIO, FILTER_TYPE_VIDEO, FILTER_TYPE_PCR}) 95 @Retention(RetentionPolicy.SOURCE) 96 public @interface FilterType {} 97 98 /** Modulation Type */ 99 @StringDef({MODULATION_8VSB, MODULATION_QAM256, MODULATION_QAM16, MODULATION_QAM64}) 100 @Retention(RetentionPolicy.SOURCE) 101 public @interface ModulationType {} 102 103 /** Delivery System Type */ 104 @IntDef({ 105 DELIVERY_SYSTEM_UNDEFINED, 106 DELIVERY_SYSTEM_ATSC, 107 DELIVERY_SYSTEM_DVBC, 108 DELIVERY_SYSTEM_DVBS, 109 DELIVERY_SYSTEM_DVBS2, 110 DELIVERY_SYSTEM_DVBT, 111 DELIVERY_SYSTEM_DVBT2 112 }) 113 @Retention(RetentionPolicy.SOURCE) 114 public @interface DeliverySystemType {} 115 116 /** Tuner Type */ 117 @IntDef({TUNER_TYPE_BUILT_IN, TUNER_TYPE_USB, TUNER_TYPE_NETWORK}) 118 @Retention(RetentionPolicy.SOURCE) 119 public @interface TunerType {} 120 121 /** Built in tuner type */ 122 @IntDef({ 123 BUILT_IN_TUNER_TYPE_ARCHER, 124 BUILT_IN_TUNER_TYPE_LINUX_DVB 125 }) 126 @Retention(RetentionPolicy.SOURCE) 127 public @interface BuiltInTunerType {} 128 } 129