diff options
| author | 2019-12-26 15:15:46 -0800 | |
|---|---|---|
| committer | 2019-12-26 17:47:03 -0800 | |
| commit | 793e570c3a3e7b72f1ed4cc234c8f530fe06387c (patch) | |
| tree | becc526e06c7c0c38cf17f7d0ef66e0365d8faa3 | |
| parent | d3ce0c025daf53103a15b57d26f113a026c2a48a (diff) | |
Complete Filter & DVR APIs
Test: make;
Change-Id: I32ada63c20760d010f3ddaefe7eb189deff19150
| -rw-r--r-- | media/java/android/media/tv/tuner/Tuner.java | 154 | ||||
| -rw-r--r-- | media/jni/android_media_tv_Tuner.cpp | 86 |
2 files changed, 197 insertions, 43 deletions
diff --git a/media/java/android/media/tv/tuner/Tuner.java b/media/java/android/media/tv/tuner/Tuner.java index 0ac0c7292c7f..457a09175d43 100644 --- a/media/java/android/media/tv/tuner/Tuner.java +++ b/media/java/android/media/tv/tuner/Tuner.java @@ -102,6 +102,7 @@ public final class Tuner implements AutoCloseable { private native int nativeTune(int type, FrontendSettings settings); private native int nativeStopTune(); private native int nativeScan(int settingsType, FrontendSettings settings, int scanType); + private native int nativeStopScan(); private native int nativeSetLnb(int lnbId); private native int nativeSetLna(boolean enable); private native FrontendStatus[] nativeGetFrontendStatus(int[] statusTypes); @@ -286,6 +287,16 @@ public final class Tuner implements AutoCloseable { } /** + * Stops a previous scanning. + * + * If the method completes successfully, the frontend stop previous scanning. + * @hide + */ + public int stopScan() { + return nativeStopScan(); + } + + /** * Sets Low-Noise Block downconverter (LNB) for satellite frontend. * * This assigns a hardware LNB resource to the satellite tuner. It can be @@ -356,10 +367,13 @@ public final class Tuner implements AutoCloseable { int mId; private native int nativeConfigureFilter(int type, int subType, FilterSettings settings); - private native boolean nativeStartFilter(); - private native boolean nativeStopFilter(); - private native boolean nativeFlushFilter(); + private native int nativeGetId(); + private native int nativeSetDataSource(Filter source); + private native int nativeStartFilter(); + private native int nativeStopFilter(); + private native int nativeFlushFilter(); private native int nativeRead(byte[] buffer, int offset, int size); + private native int nativeClose(); private Filter(int id) { mId = id; @@ -372,6 +386,12 @@ public final class Tuner implements AutoCloseable { } } + /** + * Configures the filter. + * + * @param settings the settings of the filter. + * @return result status of the operation. + */ public int configure(FilterSettings settings) { int subType = -1; if (settings.mSettings != null) { @@ -380,15 +400,56 @@ public final class Tuner implements AutoCloseable { return nativeConfigureFilter(settings.getType(), subType, settings); } - public boolean start() { + /** + * Gets the filter Id. + * + * @return the hardware resource Id for the filter. + */ + public int getId() { + return nativeGetId(); + } + + /** + * Sets the filter's data source. + * + * A filter uses demux as data source by default. If the data was packetized + * by multiple protocols, multiple filters may need to work together to + * extract all protocols' header. Then a filter's data source can be output + * from another filter. + * + * @param source the filter instance which provides data input. Switch to + * use demux as data source if the filter instance is NULL. + * @return result status of the operation. + */ + public int setDataSource(@Nullable Filter source) { + return nativeSetDataSource(source); + } + + /** + * Starts the filter. + * + * @return result status of the operation. + */ + public int start() { return nativeStartFilter(); } - public boolean stop() { + + /** + * Stops the filter. + * + * @return result status of the operation. + */ + public int stop() { return nativeStopFilter(); } - public boolean flush() { + /** + * Flushes the filter. + * + * @return result status of the operation. + */ + public int flush() { return nativeFlushFilter(); } @@ -396,6 +457,15 @@ public final class Tuner implements AutoCloseable { size = Math.min(size, buffer.length - offset); return nativeRead(buffer, offset, size); } + + /** + * Release the Filter instance. + * + * @return result status of the operation. + */ + public int close() { + return nativeClose(); + } } private Filter openFilter(@FilterType int mainType, @FilterSubtype int subType, int bufferSize, @@ -554,33 +624,85 @@ public final class Tuner implements AutoCloseable { private long mNativeContext; private DvrCallback mCallback; - private native boolean nativeAttachFilter(Filter filter); - private native boolean nativeDetachFilter(Filter filter); + private native int nativeAttachFilter(Filter filter); + private native int nativeDetachFilter(Filter filter); private native int nativeConfigureDvr(DvrSettings settings); - private native boolean nativeStartDvr(); - private native boolean nativeStopDvr(); - private native boolean nativeFlushDvr(); + private native int nativeStartDvr(); + private native int nativeStopDvr(); + private native int nativeFlushDvr(); + private native int nativeClose(); private Dvr() {} - public boolean attachFilter(Filter filter) { + /** + * Attaches a filter to DVR interface for recording. + * + * @param filter the filter to be attached. + * @return result status of the operation. + */ + public int attachFilter(Filter filter) { return nativeAttachFilter(filter); } - public boolean detachFilter(Filter filter) { + + /** + * Detaches a filter from DVR interface. + * + * @param filter the filter to be detached. + * @return result status of the operation. + */ + public int detachFilter(Filter filter) { return nativeDetachFilter(filter); } + + /** + * Configures the DVR. + * + * @param settings the settings of the DVR interface. + * @return result status of the operation. + */ public int configure(DvrSettings settings) { return nativeConfigureDvr(settings); } - public boolean start() { + + /** + * Starts DVR. + * + * Starts consuming playback data or producing data for recording. + * + * @return result status of the operation. + */ + public int start() { return nativeStartDvr(); } - public boolean stop() { + + /** + * Stops DVR. + * + * Stops consuming playback data or producing data for recording. + * + * @return result status of the operation. + */ + public int stop() { return nativeStopDvr(); } - public boolean flush() { + + /** + * Flushed DVR data. + * + * @return result status of the operation. + */ + public int flush() { return nativeFlushDvr(); } + + /** + * closes the DVR instance to release resources. + * + * @return result status of the operation. + */ + public int close() { + return nativeClose(); + } } private Dvr openDvr(int type, int bufferSize) { diff --git a/media/jni/android_media_tv_Tuner.cpp b/media/jni/android_media_tv_Tuner.cpp index 3fd14deffbdc..9876289147ee 100644 --- a/media/jni/android_media_tv_Tuner.cpp +++ b/media/jni/android_media_tv_Tuner.cpp @@ -609,7 +609,7 @@ static int android_media_tv_Tuner_tune(JNIEnv *env, jobject thiz, jint type, job return tuner->tune(getFrontendSettings(env, type, settings)); } -static int android_media_tv_Tuner_stop_tune(JNIEnv, jobject) { +static int android_media_tv_Tuner_stop_tune(JNIEnv*, jobject) { return 0; } @@ -620,11 +620,15 @@ static int android_media_tv_Tuner_scan( env, settingsType, settings), static_cast<FrontendScanType>(scanType)); } -static int android_media_tv_Tuner_set_lnb(JNIEnv, jobject, jint) { +static int android_media_tv_Tuner_stop_scan(JNIEnv*, jobject) { return 0; } -static int android_media_tv_Tuner_set_lna(JNIEnv, jobject, jint, jboolean) { +static int android_media_tv_Tuner_set_lnb(JNIEnv*, jobject, jint) { + return 0; +} + +static int android_media_tv_Tuner_set_lna(JNIEnv*, jobject, jint, jboolean) { return 0; } @@ -747,31 +751,42 @@ static int android_media_tv_Tuner_configure_filter( return (int)res; } -static bool android_media_tv_Tuner_start_filter(JNIEnv *env, jobject filter) { +static int android_media_tv_Tuner_get_filter_id(JNIEnv*, jobject) { + return 0; +} + +static int android_media_tv_Tuner_set_filter_data_source(JNIEnv*, jobject, jobject) { + return 0; +} + +static int android_media_tv_Tuner_start_filter(JNIEnv *env, jobject filter) { sp<IFilter> filterSp = getFilter(env, filter)->getIFilter(); if (filterSp == NULL) { ALOGD("Failed to start filter: filter not found"); return false; } - return filterSp->start() == Result::SUCCESS; + Result r = filterSp->start(); + return (int) r; } -static bool android_media_tv_Tuner_stop_filter(JNIEnv *env, jobject filter) { +static int android_media_tv_Tuner_stop_filter(JNIEnv *env, jobject filter) { sp<IFilter> filterSp = getFilter(env, filter)->getIFilter(); if (filterSp == NULL) { ALOGD("Failed to stop filter: filter not found"); return false; } - return filterSp->stop() == Result::SUCCESS; + Result r = filterSp->stop(); + return (int) r; } -static bool android_media_tv_Tuner_flush_filter(JNIEnv *env, jobject filter) { +static int android_media_tv_Tuner_flush_filter(JNIEnv *env, jobject filter) { sp<IFilter> filterSp = getFilter(env, filter)->getIFilter(); if (filterSp == NULL) { ALOGD("Failed to flush filter: filter not found"); return false; } - return filterSp->flush() == Result::SUCCESS; + Result r = filterSp->flush(); + return (int) r; } static int android_media_tv_Tuner_read_filter_fmq( @@ -784,6 +799,10 @@ static int android_media_tv_Tuner_read_filter_fmq( return copyData(env, filterSp, buffer, offset, size); } +static int android_media_tv_Tuner_close_filter(JNIEnv*, jobject) { + return 0; +} + static jobject android_media_tv_Tuner_open_descrambler(JNIEnv *env, jobject thiz) { sp<JTuner> tuner = getTuner(env, thiz); return tuner->openDescrambler(); @@ -824,24 +843,24 @@ static jobject android_media_tv_Tuner_open_dvr(JNIEnv *env, jobject thiz, jint t return tuner->openDvr(static_cast<DvrType>(type), bufferSize); } -static bool android_media_tv_Tuner_attach_filter(JNIEnv *env, jobject dvr, jobject filter) { +static int android_media_tv_Tuner_attach_filter(JNIEnv *env, jobject dvr, jobject filter) { sp<IDvr> dvrSp = getDvr(env, dvr)->getIDvr(); sp<IFilter> filterSp = getFilter(env, filter)->getIFilter(); if (dvrSp == NULL || filterSp == NULL) { return false; } Result result = dvrSp->attachFilter(filterSp); - return result == Result::SUCCESS; + return (int) result; } -static bool android_media_tv_Tuner_detach_filter(JNIEnv *env, jobject dvr, jobject filter) { +static int android_media_tv_Tuner_detach_filter(JNIEnv *env, jobject dvr, jobject filter) { sp<IDvr> dvrSp = getDvr(env, dvr)->getIDvr(); sp<IFilter> filterSp = getFilter(env, filter)->getIFilter(); if (dvrSp == NULL || filterSp == NULL) { return false; } Result result = dvrSp->detachFilter(filterSp); - return result == Result::SUCCESS; + return (int) result; } static int android_media_tv_Tuner_configure_dvr(JNIEnv *env, jobject dvr, jobject settings) { @@ -854,31 +873,38 @@ static int android_media_tv_Tuner_configure_dvr(JNIEnv *env, jobject dvr, jobjec return (int)result; } -static bool android_media_tv_Tuner_start_dvr(JNIEnv *env, jobject dvr) { +static int android_media_tv_Tuner_start_dvr(JNIEnv *env, jobject dvr) { sp<IDvr> dvrSp = getDvr(env, dvr)->getIDvr(); if (dvrSp == NULL) { ALOGD("Failed to start dvr: dvr not found"); return false; } - return dvrSp->start() == Result::SUCCESS; + Result result = dvrSp->start(); + return (int) result; } -static bool android_media_tv_Tuner_stop_dvr(JNIEnv *env, jobject dvr) { +static int android_media_tv_Tuner_stop_dvr(JNIEnv *env, jobject dvr) { sp<IDvr> dvrSp = getDvr(env, dvr)->getIDvr(); if (dvrSp == NULL) { ALOGD("Failed to stop dvr: dvr not found"); return false; } - return dvrSp->stop() == Result::SUCCESS; + Result result = dvrSp->stop(); + return (int) result; } -static bool android_media_tv_Tuner_flush_dvr(JNIEnv *env, jobject dvr) { +static int android_media_tv_Tuner_flush_dvr(JNIEnv *env, jobject dvr) { sp<IDvr> dvrSp = getDvr(env, dvr)->getIDvr(); if (dvrSp == NULL) { ALOGD("Failed to flush dvr: dvr not found"); return false; } - return dvrSp->flush() == Result::SUCCESS; + Result result = dvrSp->flush(); + return (int) result; +} + +static int android_media_tv_Tuner_close_dvr(JNIEnv*, jobject) { + return 0; } static const JNINativeMethod gTunerMethods[] = { @@ -893,6 +919,7 @@ static const JNINativeMethod gTunerMethods[] = { { "nativeStopTune", "()I", (void *)android_media_tv_Tuner_stop_tune }, { "nativeScan", "(ILandroid/media/tv/tuner/FrontendSettings;I)I", (void *)android_media_tv_Tuner_scan }, + { "nativeStopScan", "()I", (void *)android_media_tv_Tuner_stop_scan }, { "nativeSetLnb", "(I)I", (void *)android_media_tv_Tuner_set_lnb }, { "nativeSetLna", "(Z)I", (void *)android_media_tv_Tuner_set_lna }, { "nativeGetFrontendStatus", "([I)[Landroid/media/tv/tuner/FrontendStatus;", @@ -912,10 +939,14 @@ static const JNINativeMethod gTunerMethods[] = { static const JNINativeMethod gFilterMethods[] = { { "nativeConfigureFilter", "(IILandroid/media/tv/tuner/FilterSettings;)I", (void *)android_media_tv_Tuner_configure_filter }, - { "nativeStartFilter", "()Z", (void *)android_media_tv_Tuner_start_filter }, - { "nativeStopFilter", "()Z", (void *)android_media_tv_Tuner_stop_filter }, - { "nativeFlushFilter", "()Z", (void *)android_media_tv_Tuner_flush_filter }, + { "nativeGetId", "()I", (void *)android_media_tv_Tuner_get_filter_id }, + { "nativeSetDataSource", "(Landroid/media/tv/tuner/Tuner$Filter;)I", + (void *)android_media_tv_Tuner_set_filter_data_source }, + { "nativeStartFilter", "()I", (void *)android_media_tv_Tuner_start_filter }, + { "nativeStopFilter", "()I", (void *)android_media_tv_Tuner_stop_filter }, + { "nativeFlushFilter", "()I", (void *)android_media_tv_Tuner_flush_filter }, { "nativeRead", "([BII)I", (void *)android_media_tv_Tuner_read_filter_fmq }, + { "nativeCloseFilter", "()I", (void *)android_media_tv_Tuner_close_filter }, }; static const JNINativeMethod gDescramblerMethods[] = { @@ -928,15 +959,16 @@ static const JNINativeMethod gDescramblerMethods[] = { }; static const JNINativeMethod gDvrMethods[] = { - { "nativeAttachFilter", "(Landroid/media/tv/tuner/Tuner$Filter;)Z", + { "nativeAttachFilter", "(Landroid/media/tv/tuner/Tuner$Filter;)I", (void *)android_media_tv_Tuner_attach_filter }, - { "nativeDetachFilter", "(Landroid/media/tv/tuner/Tuner$Filter;)Z", + { "nativeDetachFilter", "(Landroid/media/tv/tuner/Tuner$Filter;)I", (void *)android_media_tv_Tuner_detach_filter }, { "nativeConfigureDvr", "(Landroid/media/tv/tuner/DvrSettings;)I", (void *)android_media_tv_Tuner_configure_dvr }, - { "nativeStartDvr", "()Z", (void *)android_media_tv_Tuner_start_dvr }, - { "nativeStopDvr", "()Z", (void *)android_media_tv_Tuner_stop_dvr }, - { "nativeFlushDvr", "()Z", (void *)android_media_tv_Tuner_flush_dvr }, + { "nativeStartDvr", "()I", (void *)android_media_tv_Tuner_start_dvr }, + { "nativeStopDvr", "()I", (void *)android_media_tv_Tuner_stop_dvr }, + { "nativeFlushDvr", "()I", (void *)android_media_tv_Tuner_flush_dvr }, + { "nativeClose", "()I", (void *)android_media_tv_Tuner_close_dvr }, }; static bool register_android_media_tv_Tuner(JNIEnv *env) { |