Merge "Create a utils class and handle filter subtypes"
This commit is contained in:
committed by
Android (Google) Code Review
commit
d3ab322a12
@@ -17,8 +17,7 @@
|
||||
package android.media.tv.tuner;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.hardware.tv.tuner.V1_0.Constants;
|
||||
import android.media.tv.tuner.TunerConstants.FilterSettingsType;
|
||||
import android.media.tv.tuner.TunerConstants.FilterType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -38,7 +37,8 @@ public abstract class FilterSettings {
|
||||
/**
|
||||
* Gets filter settings type
|
||||
*/
|
||||
@FilterSettingsType public abstract int getType();
|
||||
@FilterType
|
||||
public abstract int getType();
|
||||
|
||||
// TODO: more builders and getters
|
||||
|
||||
@@ -55,7 +55,7 @@ public abstract class FilterSettings {
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return TunerConstants.FILTER_SETTINGS_TS;
|
||||
return TunerConstants.FILTER_TYPE_TS;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,7 +109,7 @@ public abstract class FilterSettings {
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return TunerConstants.FILTER_SETTINGS_MMTP;
|
||||
return TunerConstants.FILTER_TYPE_MMTP;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ public abstract class FilterSettings {
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return TunerConstants.FILTER_SETTINGS_IP;
|
||||
return TunerConstants.FILTER_TYPE_IP;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ public abstract class FilterSettings {
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return TunerConstants.FILTER_SETTINGS_TLV;
|
||||
return TunerConstants.FILTER_TYPE_TLV;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ public abstract class FilterSettings {
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return TunerConstants.FILTER_SETTINGS_ALP;
|
||||
return TunerConstants.FILTER_TYPE_ALP;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,24 +197,7 @@ public abstract class FilterSettings {
|
||||
public static class SectionSettings extends Settings {
|
||||
|
||||
private SectionSettings(int mainType) {
|
||||
super(SectionSettings.findType(mainType));
|
||||
}
|
||||
|
||||
private static int findType(int mainType) {
|
||||
switch (mainType) {
|
||||
case TunerConstants.FILTER_SETTINGS_TS:
|
||||
return Constants.DemuxTsFilterType.SECTION;
|
||||
case TunerConstants.FILTER_SETTINGS_MMTP:
|
||||
return Constants.DemuxMmtpFilterType.SECTION;
|
||||
case TunerConstants.FILTER_SETTINGS_IP:
|
||||
return Constants.DemuxIpFilterType.SECTION;
|
||||
case TunerConstants.FILTER_SETTINGS_TLV:
|
||||
return Constants.DemuxTlvFilterType.SECTION;
|
||||
case TunerConstants.FILTER_SETTINGS_ALP:
|
||||
return Constants.DemuxAlpFilterType.SECTION;
|
||||
}
|
||||
// UNDEFINED
|
||||
return 0;
|
||||
super(TunerUtils.getFilterSubtype(mainType, TunerConstants.FILTER_SUBTYPE_SECTION));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,22 +234,11 @@ public abstract class FilterSettings {
|
||||
private boolean mIsRaw;
|
||||
|
||||
private PesSettings(int mainType, int streamId, boolean isRaw) {
|
||||
super(PesSettings.findType(mainType));
|
||||
super(TunerUtils.getFilterSubtype(mainType, TunerConstants.FILTER_SUBTYPE_PES));
|
||||
mStreamId = streamId;
|
||||
mIsRaw = isRaw;
|
||||
}
|
||||
|
||||
private static int findType(int mainType) {
|
||||
switch (mainType) {
|
||||
case TunerConstants.FILTER_SETTINGS_TS:
|
||||
return Constants.DemuxTsFilterType.PES;
|
||||
case TunerConstants.FILTER_SETTINGS_MMTP:
|
||||
return Constants.DemuxMmtpFilterType.PES;
|
||||
}
|
||||
// UNDEFINED
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a builder for PesSettings.
|
||||
*/
|
||||
@@ -319,22 +291,11 @@ public abstract class FilterSettings {
|
||||
private boolean mIsPassthrough;
|
||||
|
||||
private AvSettings(int mainType, boolean isAudio) {
|
||||
super(AvSettings.findType(mainType, isAudio));
|
||||
}
|
||||
|
||||
private static int findType(int mainType, boolean isAudio) {
|
||||
switch (mainType) {
|
||||
case TunerConstants.FILTER_SETTINGS_TS:
|
||||
return isAudio
|
||||
? Constants.DemuxTsFilterType.AUDIO
|
||||
: Constants.DemuxTsFilterType.VIDEO;
|
||||
case TunerConstants.FILTER_SETTINGS_MMTP:
|
||||
return isAudio
|
||||
? Constants.DemuxMmtpFilterType.AUDIO
|
||||
: Constants.DemuxMmtpFilterType.VIDEO;
|
||||
}
|
||||
// UNDEFINED
|
||||
return 0;
|
||||
super(TunerUtils.getFilterSubtype(
|
||||
mainType,
|
||||
isAudio
|
||||
? TunerConstants.FILTER_SUBTYPE_AUDIO
|
||||
: TunerConstants.FILTER_SUBTYPE_VIDEO));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,15 +306,7 @@ public abstract class FilterSettings {
|
||||
private int mDownloadId;
|
||||
|
||||
public DownloadSettings(int mainType) {
|
||||
super(DownloadSettings.findType(mainType));
|
||||
}
|
||||
|
||||
private static int findType(int mainType) {
|
||||
if (mainType == TunerConstants.FILTER_SETTINGS_MMTP) {
|
||||
return Constants.DemuxMmtpFilterType.DOWNLOAD;
|
||||
}
|
||||
// UNDEFINED
|
||||
return 0;
|
||||
super(TunerUtils.getFilterSubtype(mainType, TunerConstants.FILTER_SUBTYPE_DOWNLOAD));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,18 +318,7 @@ public abstract class FilterSettings {
|
||||
private int mIndexMask;
|
||||
|
||||
public RecordSettings(int mainType) {
|
||||
super(RecordSettings.findType(mainType));
|
||||
}
|
||||
|
||||
private static int findType(int mainType) {
|
||||
switch (mainType) {
|
||||
case TunerConstants.FILTER_SETTINGS_TS:
|
||||
return Constants.DemuxTsFilterType.RECORD;
|
||||
case TunerConstants.FILTER_SETTINGS_MMTP:
|
||||
return Constants.DemuxMmtpFilterType.RECORD;
|
||||
}
|
||||
// UNDEFINED
|
||||
return 0;
|
||||
super(TunerUtils.getFilterSubtype(mainType, TunerConstants.FILTER_SUBTYPE_RECORD));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,9 @@ import android.annotation.Nullable;
|
||||
import android.annotation.RequiresPermission;
|
||||
import android.annotation.SystemApi;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.media.tv.tuner.TunerConstants.DemuxPidType;
|
||||
import android.media.tv.tuner.TunerConstants.FilterSubtype;
|
||||
import android.media.tv.tuner.TunerConstants.FilterType;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
@@ -43,7 +44,6 @@ public final class Tuner implements AutoCloseable {
|
||||
private static final String TAG = "MediaTvTuner";
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private static final String PERMISSION = android.Manifest.permission.ACCESS_TV_TUNER;
|
||||
private static final int MSG_ON_FRONTEND_EVENT = 1;
|
||||
private static final int MSG_ON_FILTER_EVENT = 2;
|
||||
private static final int MSG_ON_FILTER_STATUS = 3;
|
||||
@@ -73,13 +73,6 @@ public final class Tuner implements AutoCloseable {
|
||||
nativeSetup();
|
||||
}
|
||||
|
||||
private void checkPermission() {
|
||||
if (mContext.checkCallingOrSelfPermission(PERMISSION)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
throw new SecurityException("Caller must have " + PERMISSION + " permission.");
|
||||
}
|
||||
}
|
||||
|
||||
private long mNativeContext; // used by native jMediaTuner
|
||||
|
||||
/** @hide */
|
||||
@@ -255,7 +248,7 @@ public final class Tuner implements AutoCloseable {
|
||||
*/
|
||||
@RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER)
|
||||
public int tune(@NonNull FrontendSettings settings) {
|
||||
checkPermission();
|
||||
TunerUtils.checkTunerPermission(mContext);
|
||||
return nativeTune(settings.getType(), settings);
|
||||
}
|
||||
|
||||
@@ -370,8 +363,10 @@ public final class Tuner implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
private Filter openFilter(int type, int subType, int bufferSize, FilterCallback cb) {
|
||||
Filter filter = nativeOpenFilter(type, subType, bufferSize);
|
||||
private Filter openFilter(@FilterType int mainType, @FilterSubtype int subType, int bufferSize,
|
||||
FilterCallback cb) {
|
||||
Filter filter = nativeOpenFilter(
|
||||
mainType, TunerUtils.getFilterSubtype(mainType, subType), bufferSize);
|
||||
if (filter != null) {
|
||||
filter.mCallback = cb;
|
||||
if (mHandler == null) {
|
||||
@@ -459,7 +454,7 @@ public final class Tuner implements AutoCloseable {
|
||||
@RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER)
|
||||
@Nullable
|
||||
public Descrambler openDescrambler() {
|
||||
checkPermission();
|
||||
TunerUtils.checkTunerPermission(mContext);
|
||||
return nativeOpenDescrambler();
|
||||
}
|
||||
|
||||
|
||||
@@ -91,15 +91,40 @@ final class TunerConstants {
|
||||
public static final int FRONTEND_SETTINGS_ISDBT = 9;
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({FILTER_SETTINGS_TS, FILTER_SETTINGS_MMTP, FILTER_SETTINGS_IP, FILTER_SETTINGS_TLV,
|
||||
FILTER_SETTINGS_ALP})
|
||||
public @interface FilterSettingsType {}
|
||||
@IntDef({FILTER_TYPE_TS, FILTER_TYPE_MMTP, FILTER_TYPE_IP, FILTER_TYPE_TLV, FILTER_TYPE_ALP})
|
||||
public @interface FilterType {}
|
||||
|
||||
public static final int FILTER_SETTINGS_TS = Constants.DemuxFilterMainType.TS;
|
||||
public static final int FILTER_SETTINGS_MMTP = Constants.DemuxFilterMainType.MMTP;
|
||||
public static final int FILTER_SETTINGS_IP = Constants.DemuxFilterMainType.IP;
|
||||
public static final int FILTER_SETTINGS_TLV = Constants.DemuxFilterMainType.TLV;
|
||||
public static final int FILTER_SETTINGS_ALP = Constants.DemuxFilterMainType.ALP;
|
||||
public static final int FILTER_TYPE_TS = Constants.DemuxFilterMainType.TS;
|
||||
public static final int FILTER_TYPE_MMTP = Constants.DemuxFilterMainType.MMTP;
|
||||
public static final int FILTER_TYPE_IP = Constants.DemuxFilterMainType.IP;
|
||||
public static final int FILTER_TYPE_TLV = Constants.DemuxFilterMainType.TLV;
|
||||
public static final int FILTER_TYPE_ALP = Constants.DemuxFilterMainType.ALP;
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({FILTER_SUBTYPE_UNDEFINED, FILTER_SUBTYPE_SECTION, FILTER_SUBTYPE_PES,
|
||||
FILTER_SUBTYPE_AUDIO, FILTER_SUBTYPE_VIDEO, FILTER_SUBTYPE_DOWNLOAD,
|
||||
FILTER_SUBTYPE_RECORD, FILTER_SUBTYPE_TS, FILTER_SUBTYPE_PCR, FILTER_SUBTYPE_TEMI,
|
||||
FILTER_SUBTYPE_MMPT, FILTER_SUBTYPE_NTP, FILTER_SUBTYPE_IP_PAYLOAD, FILTER_SUBTYPE_IP,
|
||||
FILTER_SUBTYPE_PAYLOAD_THROUGH, FILTER_SUBTYPE_TLV, FILTER_SUBTYPE_PTP, })
|
||||
public @interface FilterSubtype {}
|
||||
|
||||
public static final int FILTER_SUBTYPE_UNDEFINED = 0;
|
||||
public static final int FILTER_SUBTYPE_SECTION = 1;
|
||||
public static final int FILTER_SUBTYPE_PES = 2;
|
||||
public static final int FILTER_SUBTYPE_AUDIO = 3;
|
||||
public static final int FILTER_SUBTYPE_VIDEO = 4;
|
||||
public static final int FILTER_SUBTYPE_DOWNLOAD = 5;
|
||||
public static final int FILTER_SUBTYPE_RECORD = 6;
|
||||
public static final int FILTER_SUBTYPE_TS = 7;
|
||||
public static final int FILTER_SUBTYPE_PCR = 8;
|
||||
public static final int FILTER_SUBTYPE_TEMI = 9;
|
||||
public static final int FILTER_SUBTYPE_MMPT = 10;
|
||||
public static final int FILTER_SUBTYPE_NTP = 11;
|
||||
public static final int FILTER_SUBTYPE_IP_PAYLOAD = 12;
|
||||
public static final int FILTER_SUBTYPE_IP = 13;
|
||||
public static final int FILTER_SUBTYPE_PAYLOAD_THROUGH = 14;
|
||||
public static final int FILTER_SUBTYPE_TLV = 15;
|
||||
public static final int FILTER_SUBTYPE_PTP = 16;
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({DVR_SETTINGS_RECORD, DVR_SETTINGS_PLAYBACK})
|
||||
|
||||
135
media/java/android/media/tv/tuner/TunerUtils.java
Normal file
135
media/java/android/media/tv/tuner/TunerUtils.java
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.media.tv.tuner;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.hardware.tv.tuner.V1_0.Constants;
|
||||
import android.media.tv.tuner.TunerConstants.FilterSubtype;
|
||||
import android.media.tv.tuner.TunerConstants.FilterType;
|
||||
|
||||
/**
|
||||
* Utility class for tuner framework.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public final class TunerUtils {
|
||||
private static final String PERMISSION = android.Manifest.permission.ACCESS_TV_TUNER;
|
||||
|
||||
static void checkTunerPermission(Context context) {
|
||||
if (context.checkCallingOrSelfPermission(PERMISSION)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
throw new SecurityException("Caller must have " + PERMISSION + " permission.");
|
||||
}
|
||||
}
|
||||
|
||||
static int getFilterSubtype(@FilterType int mainType, @FilterSubtype int subtype) {
|
||||
if (mainType == TunerConstants.FILTER_TYPE_TS) {
|
||||
switch (subtype) {
|
||||
case TunerConstants.FILTER_SUBTYPE_UNDEFINED:
|
||||
return Constants.DemuxTsFilterType.UNDEFINED;
|
||||
case TunerConstants.FILTER_SUBTYPE_SECTION:
|
||||
return Constants.DemuxTsFilterType.SECTION;
|
||||
case TunerConstants.FILTER_SUBTYPE_PES:
|
||||
return Constants.DemuxTsFilterType.PES;
|
||||
case TunerConstants.FILTER_SUBTYPE_TS:
|
||||
return Constants.DemuxTsFilterType.TS;
|
||||
case TunerConstants.FILTER_SUBTYPE_AUDIO:
|
||||
return Constants.DemuxTsFilterType.AUDIO;
|
||||
case TunerConstants.FILTER_SUBTYPE_VIDEO:
|
||||
return Constants.DemuxTsFilterType.VIDEO;
|
||||
case TunerConstants.FILTER_SUBTYPE_PCR:
|
||||
return Constants.DemuxTsFilterType.PCR;
|
||||
case TunerConstants.FILTER_SUBTYPE_RECORD:
|
||||
return Constants.DemuxTsFilterType.RECORD;
|
||||
case TunerConstants.FILTER_SUBTYPE_TEMI:
|
||||
return Constants.DemuxTsFilterType.TEMI;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (mainType == TunerConstants.FILTER_TYPE_MMTP) {
|
||||
switch (subtype) {
|
||||
case TunerConstants.FILTER_SUBTYPE_UNDEFINED:
|
||||
return Constants.DemuxMmtpFilterType.UNDEFINED;
|
||||
case TunerConstants.FILTER_SUBTYPE_SECTION:
|
||||
return Constants.DemuxMmtpFilterType.SECTION;
|
||||
case TunerConstants.FILTER_SUBTYPE_PES:
|
||||
return Constants.DemuxMmtpFilterType.PES;
|
||||
case TunerConstants.FILTER_SUBTYPE_MMPT:
|
||||
return Constants.DemuxMmtpFilterType.MMTP;
|
||||
case TunerConstants.FILTER_SUBTYPE_AUDIO:
|
||||
return Constants.DemuxMmtpFilterType.AUDIO;
|
||||
case TunerConstants.FILTER_SUBTYPE_VIDEO:
|
||||
return Constants.DemuxMmtpFilterType.VIDEO;
|
||||
case TunerConstants.FILTER_SUBTYPE_RECORD:
|
||||
return Constants.DemuxMmtpFilterType.RECORD;
|
||||
case TunerConstants.FILTER_SUBTYPE_DOWNLOAD:
|
||||
return Constants.DemuxMmtpFilterType.DOWNLOAD;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
} else if (mainType == TunerConstants.FILTER_TYPE_IP) {
|
||||
switch (subtype) {
|
||||
case TunerConstants.FILTER_SUBTYPE_UNDEFINED:
|
||||
return Constants.DemuxIpFilterType.UNDEFINED;
|
||||
case TunerConstants.FILTER_SUBTYPE_SECTION:
|
||||
return Constants.DemuxIpFilterType.SECTION;
|
||||
case TunerConstants.FILTER_SUBTYPE_NTP:
|
||||
return Constants.DemuxIpFilterType.NTP;
|
||||
case TunerConstants.FILTER_SUBTYPE_IP_PAYLOAD:
|
||||
return Constants.DemuxIpFilterType.IP_PAYLOAD;
|
||||
case TunerConstants.FILTER_SUBTYPE_IP:
|
||||
return Constants.DemuxIpFilterType.IP;
|
||||
case TunerConstants.FILTER_SUBTYPE_PAYLOAD_THROUGH:
|
||||
return Constants.DemuxIpFilterType.PAYLOAD_THROUGH;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (mainType == TunerConstants.FILTER_TYPE_TLV) {
|
||||
switch (subtype) {
|
||||
case TunerConstants.FILTER_SUBTYPE_UNDEFINED:
|
||||
return Constants.DemuxTlvFilterType.UNDEFINED;
|
||||
case TunerConstants.FILTER_SUBTYPE_SECTION:
|
||||
return Constants.DemuxTlvFilterType.SECTION;
|
||||
case TunerConstants.FILTER_SUBTYPE_TLV:
|
||||
return Constants.DemuxTlvFilterType.TLV;
|
||||
case TunerConstants.FILTER_SUBTYPE_PAYLOAD_THROUGH:
|
||||
return Constants.DemuxTlvFilterType.PAYLOAD_THROUGH;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (mainType == TunerConstants.FILTER_TYPE_ALP) {
|
||||
switch (subtype) {
|
||||
case TunerConstants.FILTER_SUBTYPE_UNDEFINED:
|
||||
return Constants.DemuxAlpFilterType.UNDEFINED;
|
||||
case TunerConstants.FILTER_SUBTYPE_SECTION:
|
||||
return Constants.DemuxAlpFilterType.SECTION;
|
||||
case TunerConstants.FILTER_SUBTYPE_PTP:
|
||||
return Constants.DemuxAlpFilterType.PTP;
|
||||
case TunerConstants.FILTER_SUBTYPE_PAYLOAD_THROUGH:
|
||||
return Constants.DemuxAlpFilterType.PAYLOAD_THROUGH;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid filter types. Main type=" + mainType + ", subtype=" + subtype);
|
||||
}
|
||||
|
||||
private TunerUtils() {}
|
||||
}
|
||||
Reference in New Issue
Block a user