Mark Dvr class @SystemApi

split it into two subclasses

Test: make;
Bug: 139308734
Change-Id: I7264f4d92b33664dbf4207368d1a98b207377912
This commit is contained in:
shubang
2020-01-13 19:18:53 -08:00
parent 21783aca6c
commit c798780a07
8 changed files with 300 additions and 149 deletions

View File

@@ -4691,6 +4691,8 @@ package android.media.tv.tuner {
ctor public Tuner(@NonNull android.content.Context);
method @RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER) public void clearOnTuneEventListener();
method @Nullable @RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER) public android.media.tv.tuner.Tuner.Descrambler openDescrambler();
method @Nullable @RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER) public android.media.tv.tuner.dvr.DvrPlayback openDvrPlayback(long, @Nullable java.util.concurrent.Executor, @Nullable android.media.tv.tuner.dvr.OnPlaybackStatusChangedListener);
method @Nullable @RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER) public android.media.tv.tuner.dvr.DvrRecorder openDvrRecorder(long, @Nullable java.util.concurrent.Executor, @Nullable android.media.tv.tuner.dvr.OnRecordStatusChangedListener);
method @Nullable @RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER) public android.media.tv.tuner.filter.Filter openFilter(int, int, long, @Nullable java.util.concurrent.Executor, @Nullable android.media.tv.tuner.filter.FilterCallback);
method @RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER) public void setOnTuneEventListener(@NonNull java.util.concurrent.Executor, @NonNull android.media.tv.tuner.frontend.OnTuneEventListener);
method @RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER) public int stopTune();
@@ -4714,6 +4716,34 @@ package android.media.tv.tuner {
package android.media.tv.tuner.dvr {
public class Dvr implements java.lang.AutoCloseable {
ctor protected Dvr(int);
method public int attachFilter(@NonNull android.media.tv.tuner.filter.Filter);
method public void close();
method public int configure(@NonNull android.media.tv.tuner.dvr.DvrSettings);
method public int detachFilter(@NonNull android.media.tv.tuner.filter.Filter);
method public int flush();
method public void setFileDescriptor(@NonNull android.os.ParcelFileDescriptor);
method public int start();
method public int stop();
field public static final int TYPE_PLAYBACK = 1; // 0x1
field public static final int TYPE_RECORD = 0; // 0x0
}
public class DvrPlayback extends android.media.tv.tuner.dvr.Dvr {
method public long read(long);
method public long read(@NonNull byte[], long, long);
field public static final int PLAYBACK_STATUS_ALMOST_EMPTY = 2; // 0x2
field public static final int PLAYBACK_STATUS_ALMOST_FULL = 4; // 0x4
field public static final int PLAYBACK_STATUS_EMPTY = 1; // 0x1
field public static final int PLAYBACK_STATUS_FULL = 8; // 0x8
}
public class DvrRecorder extends android.media.tv.tuner.dvr.Dvr {
method public long write(long);
method public long write(@NonNull byte[], long, long);
}
public class DvrSettings {
method @NonNull @RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER) public static android.media.tv.tuner.dvr.DvrSettings.Builder builder(@NonNull android.content.Context);
method public int getDataFormat();
@@ -4721,13 +4751,10 @@ package android.media.tv.tuner.dvr {
method public long getLowThreshold();
method public long getPacketSize();
method public int getStatusMask();
method public int getType();
field public static final int DATA_FORMAT_ES = 2; // 0x2
field public static final int DATA_FORMAT_PES = 1; // 0x1
field public static final int DATA_FORMAT_SHV_TLV = 3; // 0x3
field public static final int DATA_FORMAT_TS = 0; // 0x0
field public static final int TYPE_PLAYBACK = 1; // 0x1
field public static final int TYPE_RECORD = 0; // 0x0
}
public static final class DvrSettings.Builder {
@@ -4738,7 +4765,14 @@ package android.media.tv.tuner.dvr {
method @NonNull public android.media.tv.tuner.dvr.DvrSettings.Builder setLowThreshold(long);
method @NonNull public android.media.tv.tuner.dvr.DvrSettings.Builder setPacketSize(long);
method @NonNull public android.media.tv.tuner.dvr.DvrSettings.Builder setStatusMask(int);
method @NonNull public android.media.tv.tuner.dvr.DvrSettings.Builder setType(int);
}
public interface OnPlaybackStatusChangedListener {
method public void onPlaybackStatusChanged(int);
}
public interface OnRecordStatusChangedListener {
method public void onRecordStatusChanged(int);
}
}

View File

@@ -24,9 +24,10 @@ import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.content.Context;
import android.media.tv.tuner.TunerConstants.Result;
import android.media.tv.tuner.dvr.Dvr;
import android.media.tv.tuner.dvr.DvrCallback;
import android.media.tv.tuner.dvr.DvrSettings;
import android.media.tv.tuner.dvr.DvrPlayback;
import android.media.tv.tuner.dvr.DvrRecorder;
import android.media.tv.tuner.dvr.OnPlaybackStatusChangedListener;
import android.media.tv.tuner.dvr.OnRecordStatusChangedListener;
import android.media.tv.tuner.filter.Filter;
import android.media.tv.tuner.filter.Filter.Subtype;
import android.media.tv.tuner.filter.Filter.Type;
@@ -166,7 +167,8 @@ public final class Tuner implements AutoCloseable {
private native Descrambler nativeOpenDescrambler();
private native Dvr nativeOpenDvr(int type, long bufferSize);
private native DvrRecorder nativeOpenDvrRecorder(long bufferSize);
private native DvrPlayback nativeOpenDvrPlayback(long bufferSize);
private static native DemuxCapabilities nativeGetDemuxCapabilities();
@@ -639,24 +641,44 @@ public final class Tuner implements AutoCloseable {
}
/**
* Open a DVR (Digital Video Record) instance.
* Open a DVR (Digital Video Record) recorder instance.
*
* @param type the DVR type to be opened.
* @param bufferSize the buffer size of the output in bytes. It's used to hold output data of
* the attached filters.
* @param executor the executor on which callback will be invoked. The default event handler
* executor is used if it's {@code null}.
* @param cb the callback to receive notifications from DVR.
* @return the opened DVR object. {@code null} if the operation failed.
*
* @hide
* @param l the listener to receive notifications from DVR recorder.
* @return the opened DVR recorder object. {@code null} if the operation failed.
*/
@RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER)
@Nullable
public Dvr openDvr(@DvrSettings.Type int type, @BytesLong long bufferSize,
@CallbackExecutor @Nullable Executor executor, DvrCallback cb) {
public DvrRecorder openDvrRecorder(
@BytesLong long bufferSize,
@CallbackExecutor @Nullable Executor executor,
@Nullable OnRecordStatusChangedListener l) {
TunerUtils.checkTunerPermission(mContext);
Dvr dvr = nativeOpenDvr(type, bufferSize);
DvrRecorder dvr = nativeOpenDvrRecorder(bufferSize);
return dvr;
}
/**
* Open a DVR (Digital Video Record) playback instance.
*
* @param bufferSize the buffer size of the output in bytes. It's used to hold output data of
* the attached filters.
* @param executor the executor on which callback will be invoked. The default event handler
* executor is used if it's {@code null}.
* @param l the listener to receive notifications from DVR recorder.
* @return the opened DVR playback object. {@code null} if the operation failed.
*/
@RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER)
@Nullable
public DvrPlayback openDvrPlayback(
@BytesLong long bufferSize,
@CallbackExecutor @Nullable Executor executor,
@Nullable OnPlaybackStatusChangedListener l) {
TunerUtils.checkTunerPermission(mContext);
DvrPlayback dvr = nativeOpenDvrPlayback(bufferSize);
return dvr;
}
}

View File

@@ -16,9 +16,9 @@
package android.media.tv.tuner.dvr;
import android.annotation.BytesLong;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.hardware.tv.tuner.V1_0.Constants;
import android.media.tv.tuner.TunerConstants.Result;
import android.media.tv.tuner.filter.Filter;
@@ -33,40 +33,26 @@ import java.lang.annotation.RetentionPolicy;
*
* @hide
*/
public class Dvr {
@SystemApi
public class Dvr implements AutoCloseable {
/** @hide */
@IntDef(prefix = "TYPE_", value = {TYPE_RECORD, TYPE_PLAYBACK})
@Retention(RetentionPolicy.SOURCE)
@IntDef(prefix = "PLAYBACK_STATUS_",
value = {PLAYBACK_STATUS_EMPTY, PLAYBACK_STATUS_ALMOST_EMPTY,
PLAYBACK_STATUS_ALMOST_FULL, PLAYBACK_STATUS_FULL})
@interface PlaybackStatus {}
public @interface Type {}
/**
* The space of the playback is empty.
* DVR for recording.
*/
public static final int PLAYBACK_STATUS_EMPTY = Constants.PlaybackStatus.SPACE_EMPTY;
public static final int TYPE_RECORD = Constants.DvrType.RECORD;
/**
* The space of the playback is almost empty.
*
* <p> the threshold is set in {@link DvrSettings}.
* DVR for playback of recorded programs.
*/
public static final int PLAYBACK_STATUS_ALMOST_EMPTY =
Constants.PlaybackStatus.SPACE_ALMOST_EMPTY;
/**
* The space of the playback is almost full.
*
* <p> the threshold is set in {@link DvrSettings}.
*/
public static final int PLAYBACK_STATUS_ALMOST_FULL =
Constants.PlaybackStatus.SPACE_ALMOST_FULL;
/**
* The space of the playback is full.
*/
public static final int PLAYBACK_STATUS_FULL = Constants.PlaybackStatus.SPACE_FULL;
public static final int TYPE_PLAYBACK = Constants.DvrType.PLAYBACK;
private long mNativeContext;
private DvrCallback mCallback;
final int mType;
long mNativeContext;
private native int nativeAttachFilter(Filter filter);
private native int nativeDetachFilter(Filter filter);
@@ -76,12 +62,10 @@ public class Dvr {
private native int nativeFlushDvr();
private native int nativeClose();
private native void nativeSetFileDescriptor(int fd);
private native int nativeRead(long size);
private native int nativeRead(byte[] bytes, long offset, long size);
private native int nativeWrite(long size);
private native int nativeWrite(byte[] bytes, long offset, long size);
private Dvr() {}
protected Dvr(int type) {
mType = type;
}
/**
* Attaches a filter to DVR interface for recording.
@@ -154,12 +138,9 @@ public class Dvr {
/**
* Closes the DVR instance to release resources.
*
* @return result status of the operation.
*/
@Result
public int close() {
return nativeClose();
public void close() {
nativeClose();
}
/**
@@ -171,51 +152,8 @@ public class Dvr {
nativeSetFileDescriptor(fd.getFd());
}
/**
* Reads data from the file for DVR playback.
*
* @param size the maximum number of bytes to read.
* @return the number of bytes read.
*/
public int read(@BytesLong long size) {
return nativeRead(size);
}
/**
* Reads data from the buffer for DVR playback and copies to the given byte array.
*
* @param bytes the byte array to store the data.
* @param offset the index of the first byte in {@code bytes} to copy to.
* @param size the maximum number of bytes to read.
* @return the number of bytes read.
*/
public int read(@NonNull byte[] bytes, @BytesLong long offset, @BytesLong long size) {
if (size + offset > bytes.length) {
throw new ArrayIndexOutOfBoundsException(
"Array length=" + bytes.length + ", offset=" + offset + ", size=" + size);
}
return nativeRead(bytes, offset, size);
}
/**
* Writes recording data to file.
*
* @param size the maximum number of bytes to write.
* @return the number of bytes written.
*/
public int write(@BytesLong long size) {
return nativeWrite(size);
}
/**
* Writes recording data to buffer.
*
* @param bytes the byte array stores the data to be written to DVR.
* @param offset the index of the first byte in {@code bytes} to be written to DVR.
* @param size the maximum number of bytes to write.
* @return the number of bytes written.
*/
public int write(@NonNull byte[] bytes, @BytesLong long offset, @BytesLong long size) {
return nativeWrite(bytes, offset, size);
@Type
int getType() {
return mType;
}
}

View File

@@ -0,0 +1,106 @@
/*
* 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.dvr;
import android.annotation.BytesLong;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.hardware.tv.tuner.V1_0.Constants;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Digital Video Record (DVR) class which provides playback control on Demux's input buffer.
*
* <p>It's used to play recorded programs.
*
* @hide
*/
@SystemApi
public class DvrPlayback extends Dvr {
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@IntDef(prefix = "PLAYBACK_STATUS_",
value = {PLAYBACK_STATUS_EMPTY, PLAYBACK_STATUS_ALMOST_EMPTY,
PLAYBACK_STATUS_ALMOST_FULL, PLAYBACK_STATUS_FULL})
@interface PlaybackStatus {}
/**
* The space of the playback is empty.
*/
public static final int PLAYBACK_STATUS_EMPTY = Constants.PlaybackStatus.SPACE_EMPTY;
/**
* The space of the playback is almost empty.
*
* <p> the threshold is set in {@link DvrSettings}.
*/
public static final int PLAYBACK_STATUS_ALMOST_EMPTY =
Constants.PlaybackStatus.SPACE_ALMOST_EMPTY;
/**
* The space of the playback is almost full.
*
* <p> the threshold is set in {@link DvrSettings}.
*/
public static final int PLAYBACK_STATUS_ALMOST_FULL =
Constants.PlaybackStatus.SPACE_ALMOST_FULL;
/**
* The space of the playback is full.
*/
public static final int PLAYBACK_STATUS_FULL = Constants.PlaybackStatus.SPACE_FULL;
private native long nativeRead(long size);
private native long nativeRead(byte[] bytes, long offset, long size);
private DvrPlayback() {
super(Dvr.TYPE_PLAYBACK);
}
/**
* Reads data from the file for DVR playback.
*
* @param size the maximum number of bytes to read.
* @return the number of bytes read.
*/
@BytesLong
public long read(@BytesLong long size) {
return nativeRead(size);
}
/**
* Reads data from the buffer for DVR playback and copies to the given byte array.
*
* @param bytes the byte array to store the data.
* @param offset the index of the first byte in {@code bytes} to copy to.
* @param size the maximum number of bytes to read.
* @return the number of bytes read.
*/
@BytesLong
public long read(@NonNull byte[] bytes, @BytesLong long offset, @BytesLong long size) {
if (size + offset > bytes.length) {
throw new ArrayIndexOutOfBoundsException(
"Array length=" + bytes.length + ", offset=" + offset + ", size=" + size);
}
return nativeRead(bytes, offset, size);
}
}

View File

@@ -0,0 +1,60 @@
/*
* 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.dvr;
import android.annotation.BytesLong;
import android.annotation.NonNull;
import android.annotation.SystemApi;
/**
* Digital Video Record (DVR) recorder class which provides record control on Demux's output buffer.
*
* @hide
*/
@SystemApi
public class DvrRecorder extends Dvr {
private native long nativeWrite(long size);
private native long nativeWrite(byte[] bytes, long offset, long size);
private DvrRecorder() {
super(Dvr.TYPE_RECORD);
}
/**
* Writes recording data to file.
*
* @param size the maximum number of bytes to write.
* @return the number of bytes written.
*/
@BytesLong
public long write(@BytesLong long size) {
return nativeWrite(size);
}
/**
* Writes recording data to buffer.
*
* @param bytes the byte array stores the data to be written to DVR.
* @param offset the index of the first byte in {@code bytes} to be written to DVR.
* @param size the maximum number of bytes to write.
* @return the number of bytes written.
*/
@BytesLong
public long write(@NonNull byte[] bytes, @BytesLong long offset, @BytesLong long size) {
return nativeWrite(bytes, offset, size);
}
}

View File

@@ -61,22 +61,7 @@ public class DvrSettings {
public static final int DATA_FORMAT_SHV_TLV = Constants.DataFormat.SHV_TLV;
/** @hide */
@IntDef(prefix = "TYPE_", value = {TYPE_RECORD, TYPE_PLAYBACK})
@Retention(RetentionPolicy.SOURCE)
public @interface Type {}
/**
* DVR for recording.
*/
public static final int TYPE_RECORD = Constants.DvrType.RECORD;
/**
* DVR for playback of recorded programs.
*/
public static final int TYPE_PLAYBACK = Constants.DvrType.PLAYBACK;
@FilterStatus
@Filter.Status
private final int mStatusMask;
@BytesLong
private final long mLowThreshold;
@@ -86,24 +71,20 @@ public class DvrSettings {
private final long mPacketSize;
@DataFormat
private final int mDataFormat;
@Type
private final int mType;
private DvrSettings(@FilterStatus int statusMask, @BytesLong long lowThreshold,
@BytesLong long highThreshold, @BytesLong long packetSize, @DataFormat int dataFormat,
@Type int type) {
private DvrSettings(@Filter.Status int statusMask, @BytesLong long lowThreshold,
@BytesLong long highThreshold, @BytesLong long packetSize, @DataFormat int dataFormat) {
mStatusMask = statusMask;
mLowThreshold = lowThreshold;
mHighThreshold = highThreshold;
mPacketSize = packetSize;
mDataFormat = dataFormat;
mType = type;
}
/**
* Gets status mask.
*/
@FilterStatus
@Filter.Status
public int getStatusMask() {
return mStatusMask;
}
@@ -140,14 +121,6 @@ public class DvrSettings {
return mDataFormat;
}
/**
* Gets settings type.
*/
@Type
public int getType() {
return mType;
}
/**
* Creates a builder for {@link DvrSettings}.
*
@@ -170,8 +143,6 @@ public class DvrSettings {
private long mPacketSize;
@DataFormat
private int mDataFormat;
@Type
private int mType;
/**
* Sets status mask.
@@ -218,22 +189,13 @@ public class DvrSettings {
return this;
}
/**
* Sets settings type.
*/
@NonNull
public Builder setType(@Type int type) {
this.mType = type;
return this;
}
/**
* Builds a {@link DvrSettings} object.
*/
@NonNull
public DvrSettings build() {
return new DvrSettings(
mStatusMask, mLowThreshold, mHighThreshold, mPacketSize, mDataFormat, mType);
mStatusMask, mLowThreshold, mHighThreshold, mPacketSize, mDataFormat);
}
}
}

View File

@@ -0,0 +1,32 @@
/*
* 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.dvr;
import android.annotation.SystemApi;
/**
* Listener interface for receiving information from DVR playback.
*
* @hide
*/
@SystemApi
public interface OnPlaybackStatusChangedListener {
/**
* Invoked when playback status changed.
*/
void onPlaybackStatusChanged(@DvrPlayback.PlaybackStatus int status);
}

View File

@@ -16,21 +16,18 @@
package android.media.tv.tuner.dvr;
import android.media.tv.tuner.dvr.Dvr.PlaybackStatus;
import android.annotation.SystemApi;
import android.media.tv.tuner.filter.Filter;
/**
* Callback interface for receiving information from DVR interfaces.
* Listener interface for receiving information from DVR recorder.
*
* @hide
*/
public interface DvrCallback {
@SystemApi
public interface OnRecordStatusChangedListener {
/**
* Invoked when record status changed.
*/
void onRecordStatusChanged(@Filter.Status int status);
/**
* Invoked when playback status changed.
*/
void onPlaybackStatusChanged(@PlaybackStatus int status);
}