Merge "Add RestartEvent in Filter"

This commit is contained in:
Amy Zhang
2020-11-16 22:04:41 +00:00
committed by Android (Google) Code Review
4 changed files with 105 additions and 0 deletions

View File

@@ -5438,6 +5438,10 @@ package android.media.tv.tuner.filter {
method @NonNull public android.media.tv.tuner.filter.RecordSettings.Builder setTsIndexMask(int);
}
public final class RestartEvent extends android.media.tv.tuner.filter.FilterEvent {
method public int getStartId();
}
public final class ScramblingStatusEvent extends android.media.tv.tuner.filter.FilterEvent {
method public int getScramblingStatus();
}

View File

@@ -0,0 +1,52 @@
/*
* Copyright 2020 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.filter;
import android.annotation.SystemApi;
/**
* An Event that the client would reveice after stopping, reconfiguring and restarting a filter.
*
* <p>After stopping and restarting the filter, the client has to discard all coming events until
* it receive {@link RestartedEvent} to avoid using the events from the previous configuration.
*
* <p>Recofiguring must happen after stopping the filter.
*
* @hide
*/
@SystemApi
public final class RestartEvent extends FilterEvent {
private final int mStartId;
// This constructor is used by JNI code only
private RestartEvent(int startId) {
mStartId = startId;
}
/**
* Gets the start id.
*
* <p>An unique ID to mark the start point of receiving the valid filter events after
* reconfiguring. It must be sent at least once in the first event after the filter is
* restarted.
*
* <p>0 is reserved for the newly opened filter's first start. It's optional to be received.
*/
public int getStartId() {
return mStartId;
}
}

View File

@@ -714,6 +714,34 @@ jobjectArray FilterCallback::getTemiEvent(
return arr;
}
jobjectArray FilterCallback::getScramblingStatusEvent(
jobjectArray& arr, const std::vector<DemuxFilterEventExt::Event>& eventsExt) {
JNIEnv *env = AndroidRuntime::getJNIEnv();
jclass eventClazz = env->FindClass("android/media/tv/tuner/filter/ScramblingStatusEvent");
jmethodID eventInit = env->GetMethodID(eventClazz, "<init>", "(I)V");
for (int i = 0; i < eventsExt.size(); i++) {
auto scramblingStatus = eventsExt[i].scramblingStatus();
jobject obj = env->NewObject(eventClazz, eventInit, static_cast<jint>(scramblingStatus));
env->SetObjectArrayElement(arr, i, obj);
}
return arr;
}
jobjectArray FilterCallback::getRestartEvent(
jobjectArray& arr, const std::vector<DemuxFilterEventExt::Event>& eventsExt) {
JNIEnv *env = AndroidRuntime::getJNIEnv();
jclass eventClazz = env->FindClass("android/media/tv/tuner/filter/RestartEvent");
jmethodID eventInit = env->GetMethodID(eventClazz, "<init>", "(I)V");
for (int i = 0; i < eventsExt.size(); i++) {
auto startId = eventsExt[i].startId();
jobject obj = env->NewObject(eventClazz, eventInit, static_cast<jint>(startId));
env->SetObjectArrayElement(arr, i, obj);
}
return arr;
}
Return<void> FilterCallback::onFilterEvent_1_1(const DemuxFilterEvent& filterEvent,
const DemuxFilterEventExt& filterEventExt) {
ALOGD("FilterCallback::onFilterEvent_1_1");
@@ -725,6 +753,23 @@ Return<void> FilterCallback::onFilterEvent_1_1(const DemuxFilterEvent& filterEve
jclass eventClazz = env->FindClass("android/media/tv/tuner/filter/FilterEvent");
jobjectArray array = env->NewObjectArray(events.size(), eventClazz, NULL);
if (events.empty() && !eventsExt.empty()) {
auto eventExt = eventsExt[0];
switch (eventExt.getDiscriminator()) {
case DemuxFilterEventExt::Event::hidl_discriminator::scramblingStatus: {
array = getScramblingStatusEvent(array, eventsExt);
break;
}
case DemuxFilterEventExt::Event::hidl_discriminator::startId: {
array = getRestartEvent(array, eventsExt);
break;
}
default: {
break;
}
}
}
if (!events.empty()) {
auto event = events[0];
switch (event.getDiscriminator()) {

View File

@@ -186,6 +186,10 @@ private:
jobjectArray& arr, const std::vector<DemuxFilterEvent::Event>& events);
jobjectArray getTemiEvent(
jobjectArray& arr, const std::vector<DemuxFilterEvent::Event>& events);
jobjectArray getScramblingStatusEvent(
jobjectArray& arr, const std::vector<DemuxFilterEventExt::Event>& eventsExt);
jobjectArray getRestartEvent(
jobjectArray& arr, const std::vector<DemuxFilterEventExt::Event>& eventsExt);
};
struct FrontendCallback : public IFrontendCallback {